@notectl/core 2.2.3 → 2.2.5
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/README.md +12 -0
- package/dist/chunks/AlignmentPlugin-BCHxo16v.mjs +2 -0
- package/dist/chunks/AlignmentPlugin-BCHxo16v.mjs.map +1 -0
- package/dist/chunks/{BidiIsolationPlugin-Bm3h9J15.mjs → BidiIsolationPlugin-BddRbDCN.mjs} +2 -2
- package/dist/chunks/{BidiIsolationPlugin-Bm3h9J15.mjs.map → BidiIsolationPlugin-BddRbDCN.mjs.map} +1 -1
- package/dist/chunks/{BlockquotePlugin-CxrCA0vY.mjs → BlockquotePlugin-4V7KV_Sb.mjs} +2 -2
- package/dist/chunks/{BlockquotePlugin-CxrCA0vY.mjs.map → BlockquotePlugin-4V7KV_Sb.mjs.map} +1 -1
- package/dist/chunks/{CaretNavigationPlugin-Bb7W_FMg.mjs → CaretNavigationPlugin-C6XBwp0N.mjs} +2 -2
- package/dist/chunks/{CaretNavigationPlugin-Bb7W_FMg.mjs.map → CaretNavigationPlugin-C6XBwp0N.mjs.map} +1 -1
- package/dist/chunks/{CodeBlockPlugin-CcB0WaIz.mjs → CodeBlockPlugin-DC0-BnNy.mjs} +2 -2
- package/dist/chunks/{CodeBlockPlugin-CcB0WaIz.mjs.map → CodeBlockPlugin-DC0-BnNy.mjs.map} +1 -1
- package/dist/chunks/FontPlugin-DB1_bgam.mjs +2 -0
- package/dist/chunks/{FontPlugin-1VYDwETg.mjs.map → FontPlugin-DB1_bgam.mjs.map} +1 -1
- package/dist/chunks/{FontSizePlugin-L1uDVsKY.mjs → FontSizePlugin-DFvp7Ki9.mjs} +2 -2
- package/dist/chunks/{FontSizePlugin-L1uDVsKY.mjs.map → FontSizePlugin-DFvp7Ki9.mjs.map} +1 -1
- package/dist/chunks/{FormulaPlugin-66Cc9sH2.mjs → FormulaPlugin-BLEcyazj.mjs} +2 -2
- package/dist/chunks/{FormulaPlugin-66Cc9sH2.mjs.map → FormulaPlugin-BLEcyazj.mjs.map} +1 -1
- package/dist/chunks/GapCursorPlugin-Zvxjnr82.mjs +2 -0
- package/dist/chunks/{GapCursorPlugin-B29ieXel.mjs.map → GapCursorPlugin-Zvxjnr82.mjs.map} +1 -1
- package/dist/chunks/{HeadingPlugin-SICF6Tm0.mjs → HeadingPlugin-D9yvG2Aw.mjs} +2 -2
- package/dist/chunks/{HeadingPlugin-SICF6Tm0.mjs.map → HeadingPlugin-D9yvG2Aw.mjs.map} +1 -1
- package/dist/chunks/{HighlightPlugin-B3b_qe68.mjs → HighlightPlugin-D4gh4RP7.mjs} +2 -2
- package/dist/chunks/{HighlightPlugin-B3b_qe68.mjs.map → HighlightPlugin-D4gh4RP7.mjs.map} +1 -1
- package/dist/chunks/HorizontalRulePlugin-0FjHPZuA.mjs +2 -0
- package/dist/chunks/{HorizontalRulePlugin-BrFlrpmb.mjs.map → HorizontalRulePlugin-0FjHPZuA.mjs.map} +1 -1
- package/dist/chunks/{ImagePlugin-eRVtFFou.mjs → ImagePlugin-Cp_RINtc.mjs} +2 -2
- package/dist/chunks/{ImagePlugin-eRVtFFou.mjs.map → ImagePlugin-Cp_RINtc.mjs.map} +1 -1
- package/dist/chunks/{InlineCodePlugin-Cj1EZ3x2.mjs → InlineCodePlugin-DMr4O7c7.mjs} +2 -2
- package/dist/chunks/{InlineCodePlugin-Cj1EZ3x2.mjs.map → InlineCodePlugin-DMr4O7c7.mjs.map} +1 -1
- package/dist/chunks/LinkPlugin-DvZ3MPgL.mjs +2 -0
- package/dist/chunks/{LinkPlugin-B_ysjORS.mjs.map → LinkPlugin-DvZ3MPgL.mjs.map} +1 -1
- package/dist/chunks/{ListPlugin-C0BV8CnQ.mjs → ListPlugin-CVId2dE0.mjs} +2 -2
- package/dist/chunks/{ListPlugin-C0BV8CnQ.mjs.map → ListPlugin-CVId2dE0.mjs.map} +1 -1
- package/dist/chunks/PluginHelpers-KDuTlmXm.mjs +2 -0
- package/dist/chunks/{PluginHelpers-D4quRJ5a.mjs.map → PluginHelpers-KDuTlmXm.mjs.map} +1 -1
- package/dist/chunks/{PrintPlugin-CXDFFzWB.mjs → PrintPlugin-C6gOJT6d.mjs} +2 -2
- package/dist/chunks/{PrintPlugin-CXDFFzWB.mjs.map → PrintPlugin-C6gOJT6d.mjs.map} +1 -1
- package/dist/chunks/{SimpleMark-Bdqjcz0G.mjs → SimpleMark-CaQtFAau.mjs} +2 -2
- package/dist/chunks/{SimpleMark-Bdqjcz0G.mjs.map → SimpleMark-CaQtFAau.mjs.map} +1 -1
- package/dist/chunks/{SmartPastePlugin-BhkoH03E.mjs → SmartPastePlugin-Bi_wpTCV.mjs} +2 -2
- package/dist/chunks/{SmartPastePlugin-BhkoH03E.mjs.map → SmartPastePlugin-Bi_wpTCV.mjs.map} +1 -1
- package/dist/chunks/StrikethroughPlugin-BLKDRWtf.mjs +2 -0
- package/dist/chunks/{StrikethroughPlugin-DRuwEZhu.mjs.map → StrikethroughPlugin-BLKDRWtf.mjs.map} +1 -1
- package/dist/chunks/{SuperSubPlugin-IZ_x8GS-.mjs → SuperSubPlugin-DVP7VnIz.mjs} +2 -2
- package/dist/chunks/{SuperSubPlugin-IZ_x8GS-.mjs.map → SuperSubPlugin-DVP7VnIz.mjs.map} +1 -1
- package/dist/chunks/{TablePlugin-CRp4qSZE.mjs → TablePlugin-D93RR5xH.mjs} +2 -2
- package/dist/chunks/{TablePlugin-CRp4qSZE.mjs.map → TablePlugin-D93RR5xH.mjs.map} +1 -1
- package/dist/chunks/TextColorPlugin-C1qpzEOa.mjs +2 -0
- package/dist/chunks/{TextColorPlugin-CViEiYZk.mjs.map → TextColorPlugin-C1qpzEOa.mjs.map} +1 -1
- package/dist/chunks/TextDirectionPlugin-DHB88HKf.mjs +2 -0
- package/dist/chunks/TextDirectionPlugin-DHB88HKf.mjs.map +1 -0
- package/dist/chunks/{TextFormattingPlugin-CpyZgtLi.mjs → TextFormattingPlugin-Cubp3e7f.mjs} +2 -2
- package/dist/chunks/{TextFormattingPlugin-CpyZgtLi.mjs.map → TextFormattingPlugin-Cubp3e7f.mjs.map} +1 -1
- package/dist/chunks/{ToolbarPlugin-B5UUc6dY.mjs → ToolbarPlugin-CLz2wa2c.mjs} +2 -2
- package/dist/chunks/{ToolbarPlugin-B5UUc6dY.mjs.map → ToolbarPlugin-CLz2wa2c.mjs.map} +1 -1
- package/dist/chunks/{VideoPlugin-mXIDODzC.mjs → VideoPlugin-D9rQZol6.mjs} +2 -2
- package/dist/chunks/{VideoPlugin-mXIDODzC.mjs.map → VideoPlugin-D9rQZol6.mjs.map} +1 -1
- package/dist/chunks/full-Cah3qjCT.mjs +2 -0
- package/dist/chunks/{full-CHkwduuY.mjs.map → full-Cah3qjCT.mjs.map} +1 -1
- package/dist/chunks/minimal-DqATlnAL.mjs +2 -0
- package/dist/chunks/{minimal-D5v-raei.mjs.map → minimal-DqATlnAL.mjs.map} +1 -1
- package/dist/chunks/{src-gVRDR_79.mjs → src-YY6n2SmV.mjs} +2 -2
- package/dist/chunks/{src-gVRDR_79.mjs.map → src-YY6n2SmV.mjs.map} +1 -1
- package/dist/full.mjs +1 -1
- package/dist/notectl-core.mjs +1 -1
- package/dist/notectl-core.umd.js +1 -1
- package/dist/notectl-core.umd.js.map +1 -1
- package/dist/plugins/alignment/AlignmentPlugin.d.ts +5 -0
- package/dist/plugins/alignment/AlignmentPlugin.d.ts.map +1 -1
- package/dist/plugins/alignment.mjs +1 -1
- package/dist/plugins/bidi-isolation.mjs +1 -1
- package/dist/plugins/blockquote.mjs +1 -1
- package/dist/plugins/caret-navigation.mjs +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/font-size.mjs +1 -1
- package/dist/plugins/font.mjs +1 -1
- package/dist/plugins/formula.mjs +1 -1
- package/dist/plugins/gap-cursor.mjs +1 -1
- package/dist/plugins/heading.mjs +1 -1
- package/dist/plugins/highlight.mjs +1 -1
- package/dist/plugins/horizontal-rule.mjs +1 -1
- package/dist/plugins/image.mjs +1 -1
- package/dist/plugins/inline-code.mjs +1 -1
- package/dist/plugins/link.mjs +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/print.mjs +1 -1
- package/dist/plugins/shared/PluginHelpers.d.ts +8 -0
- package/dist/plugins/shared/PluginHelpers.d.ts.map +1 -1
- package/dist/plugins/shared.mjs +1 -1
- package/dist/plugins/smart-paste.mjs +1 -1
- package/dist/plugins/strikethrough.mjs +1 -1
- package/dist/plugins/super-sub.mjs +1 -1
- package/dist/plugins/table/TableNodeViews.d.ts.map +1 -1
- package/dist/plugins/table.mjs +1 -1
- package/dist/plugins/text-color.mjs +1 -1
- package/dist/plugins/text-direction/TextDirectionPlugin.d.ts +0 -1
- package/dist/plugins/text-direction/TextDirectionPlugin.d.ts.map +1 -1
- package/dist/plugins/text-direction.mjs +1 -1
- package/dist/plugins/text-formatting.mjs +1 -1
- package/dist/plugins/toolbar.mjs +1 -1
- package/dist/plugins/video.mjs +1 -1
- package/dist/presets/full.mjs +1 -1
- package/dist/presets/minimal.mjs +1 -1
- package/dist/presets.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunks/AlignmentPlugin-h6sx-yIf.mjs +0 -2
- package/dist/chunks/AlignmentPlugin-h6sx-yIf.mjs.map +0 -1
- package/dist/chunks/FontPlugin-1VYDwETg.mjs +0 -2
- package/dist/chunks/GapCursorPlugin-B29ieXel.mjs +0 -2
- package/dist/chunks/HorizontalRulePlugin-BrFlrpmb.mjs +0 -2
- package/dist/chunks/LinkPlugin-B_ysjORS.mjs +0 -2
- package/dist/chunks/PluginHelpers-D4quRJ5a.mjs +0 -2
- package/dist/chunks/StrikethroughPlugin-DRuwEZhu.mjs +0 -2
- package/dist/chunks/TextColorPlugin-CViEiYZk.mjs +0 -2
- package/dist/chunks/TextDirectionPlugin-CQGkaS2s.mjs +0 -2
- package/dist/chunks/TextDirectionPlugin-CQGkaS2s.mjs.map +0 -1
- package/dist/chunks/full-CHkwduuY.mjs +0 -2
- package/dist/chunks/minimal-D5v-raei.mjs +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlockPlugin-CcB0WaIz.mjs","names":[],"sources":["../../src/editor/styles/code-block.ts","../../src/plugins/code-block/BracketPairing.ts","../../src/plugins/code-block/IndentHelpers.ts","../../src/plugins/code-block/PairStack.ts","../../src/plugins/code-block/AutoPairController.ts","../../src/plugins/code-block/CodeBlockKeyboardHandlers.ts","../../src/plugins/code-block/CodeBlockCommands.ts","../../src/plugins/code-block/CodeBlockDecorations.ts","../../src/plugins/language/LanguageRegistry.ts","../../src/plugins/code-block/CodeBlockTypes.ts","../../src/plugins/code-block/highlighter/RegexTokenizer.ts","../../src/plugins/code-block/CodeBlockHighlighting.ts","../../src/plugins/code-block/CodeBlockLocale.ts","../../src/plugins/code-block/LanguagePicker.ts","../../src/plugins/code-block/CodeBlockNodeView.ts","../../src/plugins/code-block/CodeBlockSchema.ts","../../src/plugins/code-block/CodeBlockService.ts","../../src/plugins/code-block/TokenCache.ts","../../src/plugins/code-block/CodeBlockPlugin.ts"],"sourcesContent":["import { SYNTAX_TOKEN_TYPES } from '../theme/SyntaxTokenTypes.js';\n\n/** Generates per-token CSS rules from the canonical token type list. */\nfunction generateTokenCSS(): string {\n\treturn SYNTAX_TOKEN_TYPES.map(\n\t\t(type) =>\n\t\t\t`.notectl-token--${type} {\\n\\tcolor: var(--notectl-code-token-${type});\\n\\tfont-style: var(--notectl-code-token-${type}-font-style, inherit);\\n\\tfont-weight: var(--notectl-code-token-${type}-font-weight, inherit);\\n}`,\n\t).join('\\n');\n}\n\n/** Code block styles — syntax highlighting container, header, copy button. */\nexport const CODE_BLOCK_CSS = `\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language-btn {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tgap: 4px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 2px 6px;\n\tfont-size: inherit;\n\tfont-family: inherit;\n\ttransition: background 0.15s;\n}\n\n.notectl-code-block__language-btn:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-code-block__language-btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__chevron {\n\tdisplay: inline-flex;\n\talign-items: center;\n\topacity: 0.6;\n}\n\n.notectl-code-block__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Language picker popup */\n.notectl-language-picker {\n\tmin-width: 120px;\n\tmax-height: 200px;\n\toverflow-y: auto;\n\tpadding: 4px;\n\tbackground: var(--notectl-surface-raised, #fff);\n\tborder: 1px solid var(--notectl-border, #e0e0e0);\n\tborder-radius: 6px;\n\tbox-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);\n}\n\n.notectl-language-picker__option {\n\tpadding: 6px 10px;\n\tborder-radius: 4px;\n\tcursor: pointer;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg, #333);\n\twhite-space: nowrap;\n}\n\n.notectl-language-picker__option:hover {\n\tbackground: rgba(128, 128, 128, 0.1);\n}\n\n.notectl-language-picker__option:focus {\n\toutline: none;\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-language-picker__option[aria-selected=\"true\"] {\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary, #2563eb);\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${generateTokenCSS()}\n`;\n","/**\n * BracketPairing: resolves the action that should be taken when the user\n * types a printable character that could trigger auto-pairing, overtype,\n * surround, or quote suppression inside a code block.\n *\n * The resolver is a pure function — it consumes the current state, the\n * incoming char, a token lookup and the auto-pair stack, and returns a\n * typed action that the keyboard / interceptor layer applies. No DOM, no\n * dispatch.\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport {\n\ttype Selection,\n\tisCollapsed,\n\tisTextSelection,\n\tselectionRange,\n} from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { ResolvedPairingConfig, SyntaxToken } from './CodeBlockTypes.js';\nimport type { PairStack } from './PairStack.js';\n\n// --- Pair definitions ---\n\nexport interface PairDefinition {\n\treadonly open: string;\n\treadonly close: string;\n\treadonly kind: 'bracket' | 'quote';\n}\n\nexport const PAIR_DEFINITIONS: readonly PairDefinition[] = [\n\t{ open: '(', close: ')', kind: 'bracket' },\n\t{ open: '[', close: ']', kind: 'bracket' },\n\t{ open: '{', close: '}', kind: 'bracket' },\n\t{ open: '\"', close: '\"', kind: 'quote' },\n\t{ open: \"'\", close: \"'\", kind: 'quote' },\n\t{ open: '`', close: '`', kind: 'quote' },\n];\n\nconst OPEN_TO_PAIR: ReadonlyMap<string, PairDefinition> = new Map(\n\tPAIR_DEFINITIONS.map((d) => [d.open, d]),\n);\nconst CLOSE_TO_PAIR: ReadonlyMap<string, PairDefinition> = new Map(\n\t// For brackets close !== open, for quotes close === open\n\tPAIR_DEFINITIONS.filter((d) => d.kind === 'bracket').map((d) => [d.close, d]),\n);\n\n// --- Action variants ---\n\nexport type PairAction =\n\t| { readonly kind: 'pair'; readonly close: string }\n\t| { readonly kind: 'overtype' }\n\t| { readonly kind: 'wrap'; readonly open: string; readonly close: string }\n\t| { readonly kind: 'passthrough' };\n\n// --- Lookups injected by the caller ---\n\nexport type TokenLookup = (blockId: BlockId, offset: number) => SyntaxToken | undefined;\n\n// --- Resolver ---\n\nexport interface ResolvePairContext {\n\treadonly state: EditorState;\n\treadonly block: BlockNode;\n\treadonly blockId: BlockId;\n\treadonly char: string;\n\treadonly config: ResolvedPairingConfig;\n\treadonly pairStack: PairStack;\n\treadonly getTokenAt: TokenLookup;\n}\n\n/**\n * Decides what to do when the user types `char` inside a code block.\n * Returns a `PairAction` describing the next step.\n */\nexport function resolvePairAction(ctx: ResolvePairContext): PairAction {\n\tconst { state, char, config } = ctx;\n\tif (!isTextSelection(state.selection)) return { kind: 'passthrough' };\n\n\tconst sel = state.selection;\n\tconst definition: PairDefinition | undefined = OPEN_TO_PAIR.get(char);\n\n\t// Wrap takes precedence over suppression when there is a range selection.\n\tif (definition && !isCollapsed(sel) && surroundEnabled(definition, config)) {\n\t\tconst wrap = tryWrapAction(definition, sel, ctx);\n\t\tif (wrap) return wrap;\n\t}\n\n\tif (!isCollapsed(sel)) return { kind: 'passthrough' };\n\n\t// Overtype: user typed a close char that matches the next char and was\n\t// auto-inserted by us.\n\tif (config.overtype && shouldOvertype(ctx, char)) {\n\t\treturn { kind: 'overtype' };\n\t}\n\n\tif (!definition) return { kind: 'passthrough' };\n\n\t// Suppression checks for collapsed-cursor auto-pair.\n\tif (!pairingAllowed(definition, ctx)) return { kind: 'passthrough' };\n\n\treturn { kind: 'pair', close: definition.close };\n}\n\nfunction tryWrapAction(\n\tdef: PairDefinition,\n\tsel: Selection,\n\tctx: ResolvePairContext,\n): PairAction | null {\n\tconst { state } = ctx;\n\tconst order = state.getBlockOrder();\n\tconst range = selectionRange(sel, order);\n\tif (range.from.blockId !== range.to.blockId) return null;\n\tif (range.from.blockId !== ctx.blockId) return null;\n\treturn { kind: 'wrap', open: def.open, close: def.close };\n}\n\nfunction shouldOvertype(ctx: ResolvePairContext, char: string): boolean {\n\tconst closeDef: PairDefinition | undefined = closeDefinitionFor(char);\n\tif (!closeDef) return false;\n\n\tconst sel = ctx.state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tconst text: string = getBlockText(ctx.block);\n\tconst offset: number = sel.anchor.offset;\n\tif (text[offset] !== char) return false;\n\n\t// Only overtype if this exact close char was recorded by an auto-pair.\n\tconst entry = ctx.pairStack.peek(ctx.blockId, offset);\n\treturn Boolean(entry && entry.char === char);\n}\n\n/**\n * Returns the pair definition where `char` is a close char. Quotes are\n * symmetric, so `OPEN_TO_PAIR` is checked first for them.\n */\nfunction closeDefinitionFor(char: string): PairDefinition | undefined {\n\tconst symmetric = OPEN_TO_PAIR.get(char);\n\tif (symmetric?.kind === 'quote') return symmetric;\n\treturn CLOSE_TO_PAIR.get(char);\n}\n\nfunction surroundEnabled(def: PairDefinition, config: ResolvedPairingConfig): boolean {\n\tswitch (config.surround) {\n\t\tcase 'never':\n\t\t\treturn false;\n\t\tcase 'brackets':\n\t\t\treturn def.kind === 'bracket';\n\t\tcase 'quotes':\n\t\t\treturn def.kind === 'quote';\n\t\tcase 'languageDefined':\n\t\t\treturn true;\n\t}\n}\n\nfunction pairingAllowed(def: PairDefinition, ctx: ResolvePairContext): boolean {\n\tconst mode: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never' =\n\t\tdef.kind === 'quote' ? ctx.config.quotes : ctx.config.brackets;\n\tif (mode === 'never') return false;\n\n\tconst sel = ctx.state.selection;\n\tif (!isTextSelection(sel)) return true;\n\tconst text: string = getBlockText(ctx.block);\n\tconst offset: number = sel.anchor.offset;\n\n\tif (def.kind === 'quote' && def.open === \"'\" && isApostropheContext(text, offset)) {\n\t\treturn false;\n\t}\n\n\tif (mode === 'always') return true;\n\tif (mode === 'beforeWhitespace') {\n\t\treturn isFollowingCharCompatibleForPair(text, offset);\n\t}\n\t// languageDefined\n\tif (def.kind === 'quote') {\n\t\tconst token = ctx.getTokenAt(ctx.blockId, offset);\n\t\tif (!token) {\n\t\t\t// Cache miss: fall back to always-allow (safe default).\n\t\t\treturn true;\n\t\t}\n\t\tif (token.type === 'string' || token.type === 'comment') return false;\n\t\treturn true;\n\t}\n\t// Brackets always pair under languageDefined\n\treturn true;\n}\n\n/**\n * VS-Code-style apostrophe suppression: `'` directly after a word char\n * `[A-Za-z0-9_]` is *not* paired (so `don't`, `it's` work).\n */\nfunction isApostropheContext(text: string, offset: number): boolean {\n\tif (offset <= 0) return false;\n\tconst prev = text[offset - 1];\n\tif (!prev) return false;\n\treturn /[A-Za-z0-9_]/.test(prev);\n}\n\nfunction isFollowingCharCompatibleForPair(text: string, offset: number): boolean {\n\tif (offset >= text.length) return true;\n\tconst next = text[offset];\n\tif (!next) return true;\n\tif (/\\s/.test(next)) return true;\n\tif (CLOSE_TO_PAIR.has(next)) return true;\n\treturn false;\n}\n\n/**\n * Wrap-selection helper: given the open/close chars and a selection, returns\n * the offsets where the chars should be inserted in document order.\n */\nexport interface WrapPlan {\n\treadonly fromOffset: number;\n\treadonly toOffset: number;\n}\n\nexport function wrapSelectionPlan(sel: Selection, blockOrder: readonly BlockId[]): WrapPlan {\n\tconst range = selectionRange(sel, blockOrder);\n\treturn { fromOffset: range.from.offset, toOffset: range.to.offset };\n}\n","/**\n * Pure helpers for indent and bracket analysis inside code blocks.\n *\n * All helpers operate on the raw block text plus an offset; no editor state,\n * no transactions. This keeps them trivially testable and reusable from\n * keyboard handlers and the text-input interceptor alike.\n */\n\nexport interface ResolvedIndent {\n\t/** Active indent unit ('\\t' or N spaces). */\n\treadonly unit: string;\n\t/** Whether spaces are used (mirrors config). */\n\treadonly useSpaces: boolean;\n\t/** Effective indent width in characters. */\n\treadonly width: number;\n}\n\nconst OPEN_BRACKETS = new Set(['{', '[', '(']);\nconst CLOSE_BRACKETS_TO_OPEN: Readonly<Record<string, string>> = {\n\t'}': '{',\n\t']': '[',\n\t')': '(',\n};\n\n/** Returns the inclusive line range `[start, end)` covering `offset`. */\nexport function getLineRange(text: string, offset: number): { start: number; end: number } {\n\tconst start: number = text.lastIndexOf('\\n', offset - 1) + 1;\n\tconst nlIndex: number = text.indexOf('\\n', offset);\n\tconst end: number = nlIndex === -1 ? text.length : nlIndex;\n\treturn { start, end };\n}\n\n/** Returns the leading whitespace (tabs/spaces only) of the line covering `offset`. */\nexport function getCurrentLineIndent(text: string, offset: number): string {\n\tconst { start, end } = getLineRange(text, offset);\n\tlet i: number = start;\n\twhile (i < end) {\n\t\tconst ch = text[i];\n\t\tif (ch !== ' ' && ch !== '\\t') break;\n\t\ti++;\n\t}\n\treturn text.slice(start, i);\n}\n\n/**\n * Returns the last non-whitespace character of `text` in the range\n * `[lineStart, cursorOffset)`, or `''` if the entire prefix is whitespace.\n * The cursor itself is excluded.\n */\nexport function lastNonWhitespaceCharBeforeCursor(text: string, cursorOffset: number): string {\n\tconst { start } = getLineRange(text, cursorOffset);\n\tfor (let i = cursorOffset - 1; i >= start; i--) {\n\t\tconst ch = text[i];\n\t\tif (ch && ch !== ' ' && ch !== '\\t') return ch;\n\t}\n\treturn '';\n}\n\n/** True if the prefix `[lineStart, cursorOffset)` contains only whitespace. */\nexport function isWhitespaceOnlyBeforeOffset(text: string, cursorOffset: number): boolean {\n\tconst { start } = getLineRange(text, cursorOffset);\n\tfor (let i = start; i < cursorOffset; i++) {\n\t\tconst ch = text[i];\n\t\tif (ch !== ' ' && ch !== '\\t') return false;\n\t}\n\treturn true;\n}\n\n/**\n * True if the prefix up to `cursorOffset` ends with an open bracket\n * (`{`, `[`, `(`) — ignoring trailing whitespace.\n */\nexport function endsWithOpenBracket(text: string, cursorOffset: number): boolean {\n\tconst last: string = lastNonWhitespaceCharBeforeCursor(text, cursorOffset);\n\treturn OPEN_BRACKETS.has(last);\n}\n\n/**\n * True if the user just typed Enter between a matching open/close pair\n * (e.g. `{|}`, `[|]`, `(|)`). Checks the next char at cursor against the\n * char before the cursor; only matches direct pairs without intervening\n * whitespace.\n */\nexport function isBetweenBracketPair(text: string, cursorOffset: number): boolean {\n\tif (cursorOffset <= 0 || cursorOffset >= text.length) return false;\n\tconst before = text[cursorOffset - 1];\n\tconst after = text[cursorOffset];\n\tif (!before || !after) return false;\n\tconst expectedOpen: string | undefined = CLOSE_BRACKETS_TO_OPEN[after];\n\treturn expectedOpen === before;\n}\n\n/**\n * Returns the unit string for the resolved indent config.\n * `'\\t'` for tabs, `' '.repeat(spaceCount)` for spaces.\n */\nexport function resolveIndentUnit(useSpaces: boolean, spaceCount: number): string {\n\treturn useSpaces ? ' '.repeat(spaceCount) : '\\t';\n}\n\n/**\n * Removes exactly one indent unit from the start of `line`. If `line`\n * does not start with a full unit, removes whatever leading whitespace\n * exists up to the unit length (so a partially-indented line still loses\n * its leading whitespace). Returns `{ removed, rest }`.\n */\nexport function dedentOnce(\n\tline: string,\n\tuseSpaces: boolean,\n\tspaceCount: number,\n): { removed: string; rest: string } {\n\tif (line.length === 0) return { removed: '', rest: line };\n\tif (!useSpaces) {\n\t\tif (line[0] === '\\t') return { removed: '\\t', rest: line.slice(1) };\n\t\t// fall through: try removing up to `spaceCount` leading spaces\n\t}\n\tlet i = 0;\n\twhile (i < spaceCount && line[i] === ' ') i++;\n\treturn { removed: line.slice(0, i), rest: line.slice(i) };\n}\n\n/**\n * Returns the indentation that should be inserted *after* the newline when\n * the user presses Enter on the line covering `cursorOffset`. Combines the\n * line's existing leading whitespace with an extra indent step if the\n * prefix ends with an open bracket and `mode === 'brackets'`.\n */\nexport function nextIndentLevel(\n\ttext: string,\n\tcursorOffset: number,\n\tmode: 'none' | 'keep' | 'brackets',\n\tunit: string,\n): string {\n\tif (mode === 'none') return '';\n\tconst base: string = getCurrentLineIndent(text, cursorOffset);\n\tif (mode === 'keep') return base;\n\tif (endsWithOpenBracket(text, cursorOffset)) return base + unit;\n\treturn base;\n}\n\n/**\n * True if the prefix triggers the 3-line block-pattern: `{|}` (or `[|]`,\n * `(|)`) where cursor is exactly between an open/close pair. Used by the\n * Enter handler to expand the cursor onto its own indented line.\n */\nexport function shouldOpenIndentBlock(text: string, cursorOffset: number): boolean {\n\treturn isBetweenBracketPair(text, cursorOffset);\n}\n","/**\n * Auto-pair tracking stack: records the position of each auto-inserted\n * close character so that overtype (Bracket-Skip) and pair-delete only\n * fire on chars *we* produced — never on chars the user typed themselves.\n *\n * Positions are migrated through `Transaction.mapping` after every state\n * change. The single non-trivial choice is the association bias for\n * `mapResult`: we use `+1` (\"sticky right\") so an insert *at* the close\n * char's position lands left of the close char, matching the user\n * intuition \"I'm typing before this auto-paired `)`\".\n */\n\nimport type { Position } from '../../model/Selection.js';\nimport { createPosition } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { Mapping } from '../../state/Mapping.js';\n\nexport interface PairEntry {\n\treadonly pos: Position;\n\treadonly char: string;\n}\n\n/** Per-block stack of auto-pair entries. */\nexport class PairStack {\n\tprivate readonly buckets = new Map<BlockId, PairEntry[]>();\n\n\t/** Records a new auto-inserted close char at `pos`. */\n\tpush(pos: Position, char: string): void {\n\t\tconst bucket: PairEntry[] = this.buckets.get(pos.blockId) ?? [];\n\t\tbucket.push({ pos, char });\n\t\tthis.buckets.set(pos.blockId, bucket);\n\t}\n\n\t/**\n\t * Finds (and removes) an entry whose position matches `blockId`/`offset`\n\t * exactly. Returns the entry or `undefined` if no match.\n\t */\n\ttake(blockId: BlockId, offset: number): PairEntry | undefined {\n\t\tconst bucket: PairEntry[] | undefined = this.buckets.get(blockId);\n\t\tif (!bucket) return undefined;\n\t\tfor (let i = bucket.length - 1; i >= 0; i--) {\n\t\t\tconst entry: PairEntry | undefined = bucket[i];\n\t\t\tif (entry && entry.pos.offset === offset) {\n\t\t\t\tbucket.splice(i, 1);\n\t\t\t\tif (bucket.length === 0) this.buckets.delete(blockId);\n\t\t\t\treturn entry;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Returns (without removing) an entry whose position matches. */\n\tpeek(blockId: BlockId, offset: number): PairEntry | undefined {\n\t\tconst bucket: PairEntry[] | undefined = this.buckets.get(blockId);\n\t\tif (!bucket) return undefined;\n\t\tfor (let i = bucket.length - 1; i >= 0; i--) {\n\t\t\tconst entry: PairEntry | undefined = bucket[i];\n\t\t\tif (entry && entry.pos.offset === offset) return entry;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Clears all entries for the given block (used on code_block → paragraph). */\n\tclearBlock(blockId: BlockId): void {\n\t\tthis.buckets.delete(blockId);\n\t}\n\n\t/** Drops every recorded entry — used on plugin destroy/HMR. */\n\tclear(): void {\n\t\tthis.buckets.clear();\n\t}\n\n\t/** Number of recorded entries for a block; primarily for diagnostics/tests. */\n\tsizeForBlock(blockId: BlockId): number {\n\t\treturn this.buckets.get(blockId)?.length ?? 0;\n\t}\n\n\t/** Aggregate size across all blocks. */\n\tget size(): number {\n\t\tlet total = 0;\n\t\tfor (const bucket of this.buckets.values()) total += bucket.length;\n\t\treturn total;\n\t}\n\n\t/**\n\t * Migrates every recorded position through `mapping`. Entries that fall\n\t * inside removed content (or whose host block has vanished) are dropped.\n\t * Entries that change block (e.g. via split) get re-bucketed.\n\t */\n\tmigrate(mapping: Mapping): void {\n\t\tif (mapping.isEmpty) return;\n\t\tconst next = new Map<BlockId, PairEntry[]>();\n\t\tfor (const bucket of this.buckets.values()) {\n\t\t\tfor (const entry of bucket) {\n\t\t\t\tconst result = mapping.mapResult(entry.pos, +1);\n\t\t\t\tif (result.deleted) continue;\n\t\t\t\tconst migrated: PairEntry = { pos: result.pos, char: entry.char };\n\t\t\t\tconst bid: BlockId = result.pos.blockId;\n\t\t\t\tconst target: PairEntry[] = next.get(bid) ?? [];\n\t\t\t\ttarget.push(migrated);\n\t\t\t\tnext.set(bid, target);\n\t\t\t}\n\t\t}\n\t\tthis.buckets.clear();\n\t\tfor (const [bid, entries] of next) this.buckets.set(bid, entries);\n\t}\n\n\t/** Builds a position with the same shape as auto-pair entries. */\n\tstatic makePos(blockId: BlockId, offset: number): Position {\n\t\treturn createPosition(blockId, offset);\n\t}\n}\n","/**\n * Owns the auto-pairing behavior of the code-block plugin: bracket/quote\n * pairing, overtype-on-close, selection wrapping, and dedent-on-close-bracket.\n *\n * Encapsulates the mutable pair state ({@link PairStack} plus the deferred\n * push/take queue) so the plugin stays a thin orchestrator. Positions in the\n * deferred queue are expressed in *post-transaction* space and are reconciled\n * in {@link AutoPairController.syncOnStateChange} after the transaction's\n * mapping migration has run.\n */\n\nimport type { CompositionState } from '../../model/CompositionState.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport {\n\tcreateCollapsedSelection,\n\tcreatePosition,\n\tisCollapsed,\n\tisTextSelection,\n\tselectionRange,\n} from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { TextInputInterceptor } from '../Plugin.js';\nimport {\n\ttype PairAction,\n\ttype TokenLookup,\n\tresolvePairAction,\n\twrapSelectionPlan,\n} from './BracketPairing.js';\nimport type { ResolvedIndentConfig, ResolvedPairingConfig } from './CodeBlockTypes.js';\nimport { dedentOnce, getLineRange, isWhitespaceOnlyBeforeOffset } from './IndentHelpers.js';\nimport { PairStack } from './PairStack.js';\n\ninterface AutoPairDeps {\n\treadonly resolvedIndent: ResolvedIndentConfig;\n\treadonly resolvedPairing: ResolvedPairingConfig;\n\treadonly getTokenAt: TokenLookup;\n\t/** Returns the live composition state, or `null` when the editor is not ready. */\n\treadonly getCompositionState: () => CompositionState | null;\n}\n\ntype PendingPairOp =\n\t| {\n\t\t\treadonly kind: 'push';\n\t\t\treadonly blockId: BlockId;\n\t\t\treadonly offset: number;\n\t\t\treadonly char: string;\n\t }\n\t| { readonly kind: 'take'; readonly blockId: BlockId; readonly offset: number };\n\nexport class AutoPairController {\n\tprivate readonly resolvedIndent: ResolvedIndentConfig;\n\tprivate readonly resolvedPairing: ResolvedPairingConfig;\n\tprivate readonly getTokenAt: TokenLookup;\n\tprivate readonly getCompositionState: () => CompositionState | null;\n\n\tprivate readonly pairs = new PairStack();\n\tprivate readonly pendingPairOps: PendingPairOp[] = [];\n\n\tconstructor(deps: AutoPairDeps) {\n\t\tthis.resolvedIndent = deps.resolvedIndent;\n\t\tthis.resolvedPairing = deps.resolvedPairing;\n\t\tthis.getTokenAt = deps.getTokenAt;\n\t\tthis.getCompositionState = deps.getCompositionState;\n\t}\n\n\t/**\n\t * The shared pair-tracking stack. Exposed read-only so the keyboard handlers\n\t * can consult it for Backspace pair-delete; all mutation flows through this\n\t * controller's interceptor and {@link AutoPairController.syncOnStateChange}.\n\t */\n\tget pairStack(): PairStack {\n\t\treturn this.pairs;\n\t}\n\n\tclear(): void {\n\t\tthis.pairs.clear();\n\t\tthis.pendingPairOps.length = 0;\n\t}\n\n\t/**\n\t * Reconciles the pair stack after a transaction has been applied: migrates\n\t * tracked positions through the transaction mapping, applies the deferred\n\t * push/take ops recorded by the interceptor, then drops entries whose host\n\t * block is no longer a code block.\n\t */\n\tsyncOnStateChange(state: EditorState, tr: Transaction): void {\n\t\tif (this.pairs.size > 0 && !tr.mapping.isEmpty) {\n\t\t\tthis.pairs.migrate(tr.mapping);\n\t\t}\n\n\t\t// Apply any pending push/take operations recorded by the interceptor.\n\t\t// Positions in `pendingPairOps` are already expressed in *post-transaction*\n\t\t// space, so they must be applied AFTER the migration above (otherwise the\n\t\t// migration would shift them again).\n\t\tfor (const op of this.pendingPairOps) {\n\t\t\tif (op.kind === 'push') {\n\t\t\t\tthis.pairs.push(createPosition(op.blockId, op.offset), op.char);\n\t\t\t} else {\n\t\t\t\tthis.pairs.take(op.blockId, op.offset);\n\t\t\t}\n\t\t}\n\t\tthis.pendingPairOps.length = 0;\n\n\t\t// Clear entries whose host block is no longer a code block.\n\t\tfor (const step of tr.steps) {\n\t\t\tif (step.type !== 'setBlockType') continue;\n\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\tif (!block || block.type !== 'code_block') {\n\t\t\t\tthis.pairs.clearBlock(step.blockId);\n\t\t\t}\n\t\t}\n\t}\n\n\treadonly handleTextInput: TextInputInterceptor = (\n\t\ttext: string,\n\t\tstate: EditorState,\n\t): Transaction | null => {\n\t\t// Drop any pending pair ops left over from a previously suppressed\n\t\t// transaction. `onStateChange` only fires when a tr reaches `state.apply`;\n\t\t// if middleware blocked the last tr, its queued ops would otherwise leak\n\t\t// into the next successful cycle with stale offsets.\n\t\tthis.pendingPairOps.length = 0;\n\n\t\tconst composition: CompositionState | null = this.getCompositionState();\n\t\tif (!composition) return null;\n\t\tif (composition.isComposing) return null;\n\t\tif (!isTextSelection(state.selection)) return null;\n\t\t// Only single-char inputs trigger pair logic.\n\t\tif (text.length !== 1) return null;\n\n\t\tconst sel = state.selection;\n\t\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\t\tif (!block || block.type !== 'code_block') return null;\n\n\t\t// Dedent-on-close-bracket: typing `}`, `]`, `)` on a whitespace-only line\n\t\t// reduces leading indent by one step before inserting the char.\n\t\tconst dedentTr: Transaction | null = this.tryDedentOnCloseBracket(state, block, text);\n\t\tif (dedentTr) return dedentTr;\n\n\t\tconst action: PairAction = resolvePairAction({\n\t\t\tstate,\n\t\t\tblock,\n\t\t\tblockId: sel.anchor.blockId,\n\t\t\tchar: text,\n\t\t\tconfig: this.resolvedPairing,\n\t\t\tpairStack: this.pairs,\n\t\t\tgetTokenAt: this.getTokenAt,\n\t\t});\n\n\t\tswitch (action.kind) {\n\t\t\tcase 'pair':\n\t\t\t\treturn this.buildAutoPairTransaction(state, sel.anchor.blockId, action.close, text);\n\t\t\tcase 'overtype':\n\t\t\t\treturn this.buildOvertypeTransaction(state, sel.anchor.blockId);\n\t\t\tcase 'wrap':\n\t\t\t\treturn this.buildWrapTransaction(state, sel.anchor.blockId, action.open, action.close);\n\t\t\tcase 'passthrough':\n\t\t\t\treturn null;\n\t\t}\n\t};\n\n\tprivate tryDedentOnCloseBracket(\n\t\tstate: EditorState,\n\t\tblock: BlockNode,\n\t\tchar: string,\n\t): Transaction | null {\n\t\tif (this.resolvedIndent.mode !== 'brackets') return null;\n\t\tif (char !== '}' && char !== ']' && char !== ')') return null;\n\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel) || !isCollapsed(sel)) return null;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst offset: number = sel.anchor.offset;\n\t\tif (!isWhitespaceOnlyBeforeOffset(text, offset)) return null;\n\n\t\tconst { start } = getLineRange(text, offset);\n\t\tif (start === offset) return null; // no leading indent on this line\n\n\t\tconst blockId: BlockId = sel.anchor.blockId;\n\n\t\t// Combined dedent + overtype: when the next non-whitespace char ahead of\n\t\t// the cursor (across any newlines) is a tracked auto-paired close of the\n\t\t// same kind, collapse the gap so the user's typed close consumes the\n\t\t// auto-paired one instead of producing a duplicate.\n\t\tconst trackedClosePos: number | null = this.findTrackedCloseAfter(text, offset, char, blockId);\n\t\tif (trackedClosePos !== null) {\n\t\t\treturn state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(blockId, start, trackedClosePos)\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, start + 1))\n\t\t\t\t.build();\n\t\t}\n\n\t\tconst lineSlice: string = text.slice(start, offset);\n\t\tconst result = dedentOnce(\n\t\t\tlineSlice,\n\t\t\tthis.resolvedIndent.useSpaces,\n\t\t\tthis.resolvedIndent.spaceCount,\n\t\t);\n\t\tif (result.removed.length === 0) return null;\n\n\t\tconst newOffset: number = offset - result.removed.length;\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.deleteTextAt(blockId, newOffset, offset)\n\t\t\t.insertText(blockId, newOffset, char, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, newOffset + 1))\n\t\t\t.build();\n\t}\n\n\t/**\n\t * Scans forward from `offset` through whitespace and newlines for a tracked\n\t * auto-paired close char matching `char`. Returns its position or `null` if\n\t * any other char (or end-of-text) is encountered first.\n\t */\n\tprivate findTrackedCloseAfter(\n\t\ttext: string,\n\t\toffset: number,\n\t\tchar: string,\n\t\tblockId: BlockId,\n\t): number | null {\n\t\tfor (let i = offset; i < text.length; i++) {\n\t\t\tconst ch: string | undefined = text[i];\n\t\t\tif (ch === ' ' || ch === '\\t' || ch === '\\n') continue;\n\t\t\tif (ch === char) {\n\t\t\t\tconst entry = this.pairs.peek(blockId, i);\n\t\t\t\tif (entry && entry.char === char) return i;\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate buildAutoPairTransaction(\n\t\tstate: EditorState,\n\t\tblockId: BlockId,\n\t\tcloseChar: string,\n\t\topenChar: string,\n\t): Transaction {\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel)) {\n\t\t\tthrow new Error('buildAutoPairTransaction requires a text selection');\n\t\t}\n\t\tconst offset: number = sel.anchor.offset;\n\t\tconst inserted = `${openChar}${closeChar}`;\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, offset, inserted, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + 1))\n\t\t\t.build();\n\t\t// Record the auto-inserted close char so overtype/pair-delete can target it.\n\t\t// The position is expressed in post-transaction space; the actual push\n\t\t// happens in `syncOnStateChange` after the mapping migration runs.\n\t\tthis.pendingPairOps.push({\n\t\t\tkind: 'push',\n\t\t\tblockId,\n\t\t\toffset: offset + 1,\n\t\t\tchar: closeChar,\n\t\t});\n\t\treturn tr;\n\t}\n\n\tprivate buildOvertypeTransaction(state: EditorState, blockId: BlockId): Transaction {\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel)) {\n\t\t\tthrow new Error('buildOvertypeTransaction requires a text selection');\n\t\t}\n\t\tconst offset: number = sel.anchor.offset;\n\t\t// Schedule the take so it survives the migration phase (the entry's\n\t\t// position is in pre-transaction space, so migration will preserve it).\n\t\tthis.pendingPairOps.push({ kind: 'take', blockId, offset });\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + 1))\n\t\t\t.build();\n\t}\n\n\tprivate buildWrapTransaction(\n\t\tstate: EditorState,\n\t\tblockId: BlockId,\n\t\topenChar: string,\n\t\tcloseChar: string,\n\t): Transaction {\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel)) {\n\t\t\tthrow new Error('buildWrapTransaction requires a text selection');\n\t\t}\n\t\tconst plan = wrapSelectionPlan(sel, state.getBlockOrder());\n\t\tconst range = selectionRange(sel, state.getBlockOrder());\n\t\tconst wasForward: boolean = range.from === sel.anchor;\n\t\tconst newFrom: number = plan.fromOffset + 1;\n\t\tconst newTo: number = plan.toOffset + 1;\n\t\tconst anchorOff: number = wasForward ? newFrom : newTo;\n\t\tconst headOff: number = wasForward ? newTo : newFrom;\n\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, plan.toOffset, closeChar, [])\n\t\t\t.insertText(blockId, plan.fromOffset, openChar, [])\n\t\t\t.setSelection({\n\t\t\t\tanchor: { blockId, offset: anchorOff },\n\t\t\t\thead: { blockId, offset: headOff },\n\t\t\t})\n\t\t\t.build();\n\t}\n}\n","/**\n * Keyboard handlers for code-block navigation and editing.\n * Handles Enter (with auto-indent + block-pattern), Backspace (with pair-delete),\n * Tab, Shift-Tab (with multi-line range handling), Escape, Arrow keys, and\n * configurable shortcuts (Mod+Enter, toggle).\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { generateBlockId, getBlockLength, getBlockText } from '../../model/Document.js';\nimport {\n\ttype Selection,\n\tcreateCollapsedSelection,\n\tcreateSelection,\n\tisCollapsed,\n\tisForward,\n\tisTextSelection,\n\tselectionRange,\n} from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport type { CodeBlockLocale } from './CodeBlockLocale.js';\nimport type {\n\tCodeBlockConfig,\n\tCodeBlockKeymap,\n\tResolvedIndentConfig,\n\tResolvedPairingConfig,\n} from './CodeBlockTypes.js';\nimport {\n\tdedentOnce,\n\tgetCurrentLineIndent,\n\tgetLineRange,\n\tnextIndentLevel,\n\tresolveIndentUnit,\n\tshouldOpenIndentBlock,\n} from './IndentHelpers.js';\nimport type { PairStack } from './PairStack.js';\n\n// --- Context Guard ---\n\ninterface CodeBlockContext {\n\treadonly state: EditorState;\n\treadonly sel: Selection;\n\treadonly block: BlockNode;\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n}\n\nfunction withCodeBlockContext(\n\tcontext: PluginContext,\n\thandler: (ctx: CodeBlockContext) => boolean,\n): boolean {\n\tconst state: EditorState = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst sel: Selection = state.selection;\n\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\tif (!block || block.type !== 'code_block') return false;\n\n\treturn handler({\n\t\tstate,\n\t\tsel,\n\t\tblock,\n\t\tblockId: sel.anchor.blockId,\n\t\toffset: sel.anchor.offset,\n\t});\n}\n\n/** Dependencies for the keyboard handlers. */\nexport interface CodeBlockKeyboardDeps {\n\treadonly indent: ResolvedIndentConfig;\n\treadonly pairing: ResolvedPairingConfig;\n\treadonly pairStack: PairStack;\n\treadonly locale: () => CodeBlockLocale;\n}\n\n/** Registers all code-block keyboard handlers. */\nexport function registerCodeBlockKeymaps(\n\tcontext: PluginContext,\n\tconfig: CodeBlockConfig,\n\tresolvedKeymap: Readonly<Record<keyof CodeBlockKeymap, string | null>>,\n\tdeps: CodeBlockKeyboardDeps,\n): void {\n\tconst keymap: Record<string, () => boolean> = {\n\t\tEnter: () => handleEnter(context, deps),\n\t\tBackspace: () => handleBackspace(context, deps),\n\t\tTab: () => handleTab(context, deps),\n\t\t'Shift-Tab': () => handleShiftTab(context, deps),\n\t\tEscape: () => handleEscape(context),\n\t\tArrowDown: () => handleArrowDown(context),\n\t\tArrowUp: () => handleArrowUp(context),\n\t\tArrowRight: () => handleArrowRight(context),\n\t\tArrowLeft: () => handleArrowLeft(context),\n\t};\n\n\tconst { insertAfter, toggle } = resolvedKeymap;\n\n\tif (insertAfter) {\n\t\tkeymap[insertAfter] = () => handleModEnter(context);\n\t}\n\tif (toggle) {\n\t\tkeymap[toggle] = () => context.executeCommand('toggleCodeBlock');\n\t}\n\n\tcontext.registerKeymap(keymap, { priority: 'context' });\n\n\t// `config` is kept in the signature for future language-defined indent rules.\n\tvoid config;\n}\n\n// --- Handler Functions ---\n\nfunction handleBackspace(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\t// Pair-delete: backspace between an auto-paired empty pair removes both chars.\n\t\tif (deps.pairing.deletePair && offset > 0) {\n\t\t\tconst text: string = getBlockText(block);\n\t\t\tconst before = text[offset - 1];\n\t\t\tconst after = text[offset];\n\t\t\tif (before && after && isMatchingPair(before, after)) {\n\t\t\t\tconst entry = deps.pairStack.peek(blockId, offset);\n\t\t\t\tif (entry && entry.char === after) {\n\t\t\t\t\tconst tr: Transaction = state\n\t\t\t\t\t\t.transaction('input')\n\t\t\t\t\t\t.deleteTextAt(blockId, offset - 1, offset + 1)\n\t\t\t\t\t\t.setSelection(createCollapsedSelection(blockId, offset - 1))\n\t\t\t\t\t\t.build();\n\t\t\t\t\tcontext.dispatch(tr);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (offset !== 0) return false;\n\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.setBlockType(blockId, nodeType('paragraph'))\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t});\n}\n\nfunction handleEnter(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tif (text.endsWith('\\n') && offset === text.length) {\n\t\t\treturn exitOnDoubleEnter(context, blockId, text);\n\t\t}\n\n\t\tconst unit: string = resolveIndentUnit(deps.indent.useSpaces, deps.indent.spaceCount);\n\n\t\t// Block-pattern: cursor between matching open/close → 3-line layout.\n\t\tif (deps.indent.mode === 'brackets' && shouldOpenIndentBlock(text, offset)) {\n\t\t\tconst baseIndent: string = getCurrentLineIndent(text, offset);\n\t\t\tconst insert = `\\n${baseIndent}${unit}\\n${baseIndent}`;\n\t\t\tconst cursorOffset: number = offset + 1 + baseIndent.length + unit.length;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.insertText(blockId, offset, insert, [])\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, cursorOffset))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\tconst indent: string = nextIndentLevel(text, offset, deps.indent.mode, unit);\n\t\tconst insert = `\\n${indent}`;\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, offset, insert, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + insert.length))\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t});\n}\n\nfunction handleTab(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, sel, block, blockId, offset }) => {\n\t\tconst unit: string = resolveIndentUnit(deps.indent.useSpaces, deps.indent.spaceCount);\n\n\t\tif (isCollapsed(sel)) {\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.insertText(blockId, offset, unit, [])\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, offset + unit.length))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\t// Range selection — must be within this code block.\n\t\tif (sel.anchor.blockId !== blockId || sel.head.blockId !== blockId) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst range = selectionRange(sel, state.getBlockOrder());\n\t\tconst fromOffset: number = range.from.offset;\n\t\tconst toOffset: number = range.to.offset;\n\t\tconst spansLine: boolean = text.slice(fromOffset, toOffset).includes('\\n');\n\n\t\tif (!spansLine) {\n\t\t\t// VS Code-style: replace selection with one indent unit.\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(blockId, fromOffset, toOffset)\n\t\t\t\t.insertText(blockId, fromOffset, unit, [])\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, fromOffset + unit.length))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\t// Multi-line indent.\n\t\tconst result = indentLineRange(text, fromOffset, toOffset, unit);\n\t\tconst builder = state.transaction('input');\n\t\t// Apply in reverse so earlier offsets remain valid after each insert.\n\t\tfor (let i = result.inserts.length - 1; i >= 0; i--) {\n\t\t\tconst insert = result.inserts[i];\n\t\t\tif (!insert) continue;\n\t\t\tbuilder.insertText(blockId, insert.offset, insert.text, []);\n\t\t}\n\t\tconst wasForward: boolean = isForward(sel, state.getBlockOrder());\n\t\tconst newFrom: number = result.lineStart;\n\t\tconst newTo: number = toOffset + result.totalInserted;\n\t\tconst anchorOff: number = wasForward ? newFrom : newTo;\n\t\tconst headOff: number = wasForward ? newTo : newFrom;\n\t\tbuilder.setSelection(\n\t\t\tcreateSelection({ blockId, offset: anchorOff }, { blockId, offset: headOff }),\n\t\t);\n\t\tcontext.dispatch(builder.build());\n\n\t\tif (result.lineCount >= 2) {\n\t\t\tcontext.announce(deps.locale().indentedNLines(result.lineCount));\n\t\t}\n\t\treturn true;\n\t});\n}\n\nfunction handleShiftTab(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, sel, block, blockId, offset }) => {\n\t\tconst text: string = getBlockText(block);\n\n\t\tif (isCollapsed(sel)) {\n\t\t\treturn dedentSingleLine(context, state, blockId, offset, text, deps);\n\t\t}\n\n\t\tif (sel.anchor.blockId !== blockId || sel.head.blockId !== blockId) return false;\n\n\t\tconst range = selectionRange(sel, state.getBlockOrder());\n\t\tconst fromOffset: number = range.from.offset;\n\t\tconst toOffset: number = range.to.offset;\n\t\tconst spansLine: boolean = text.slice(fromOffset, toOffset).includes('\\n');\n\n\t\tif (!spansLine) {\n\t\t\treturn dedentSingleLine(context, state, blockId, offset, text, deps);\n\t\t}\n\n\t\tconst result = dedentLineRange(\n\t\t\ttext,\n\t\t\tfromOffset,\n\t\t\ttoOffset,\n\t\t\tdeps.indent.useSpaces,\n\t\t\tdeps.indent.spaceCount,\n\t\t);\n\t\tif (result.totalRemoved === 0) {\n\t\t\t// Nothing to remove — consume the event so the browser does not move focus.\n\t\t\treturn true;\n\t\t}\n\n\t\tconst builder = state.transaction('input');\n\t\tfor (let i = result.deletes.length - 1; i >= 0; i--) {\n\t\t\tconst del = result.deletes[i];\n\t\t\tif (!del) continue;\n\t\t\tbuilder.deleteTextAt(blockId, del.from, del.to);\n\t\t}\n\t\tconst wasForward: boolean = isForward(sel, state.getBlockOrder());\n\t\tconst newFrom: number = result.lineStart;\n\t\tconst newTo: number = toOffset - result.totalRemoved;\n\t\tconst anchorOff: number = wasForward ? newFrom : Math.max(newFrom, newTo);\n\t\tconst headOff: number = wasForward ? Math.max(newFrom, newTo) : newFrom;\n\t\tbuilder.setSelection(\n\t\t\tcreateSelection({ blockId, offset: anchorOff }, { blockId, offset: headOff }),\n\t\t);\n\t\tcontext.dispatch(builder.build());\n\n\t\tif (result.lineCount >= 2) {\n\t\t\tcontext.announce(deps.locale().dedentedNLines(result.lineCount));\n\t\t}\n\t\treturn true;\n\t});\n}\n\nfunction dedentSingleLine(\n\tcontext: PluginContext,\n\tstate: EditorState,\n\tblockId: BlockId,\n\toffset: number,\n\ttext: string,\n\tdeps: CodeBlockKeyboardDeps,\n): boolean {\n\tconst { start } = getLineRange(text, offset);\n\tconst lineText: string = text.slice(start);\n\tconst removed = dedentOnce(lineText, deps.indent.useSpaces, deps.indent.spaceCount);\n\tif (removed.removed.length === 0) return true;\n\n\tconst tr: Transaction = state\n\t\t.transaction('input')\n\t\t.deleteTextAt(blockId, start, start + removed.removed.length)\n\t\t.setSelection(\n\t\t\tcreateCollapsedSelection(blockId, Math.max(start, offset - removed.removed.length)),\n\t\t)\n\t\t.build();\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/**\n * Exits the code block to the next block or creates a new paragraph.\n * Exported for use by the `exitCodeBlock` command.\n */\nexport function handleEscape(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, blockId }) => {\n\t\tmoveToNextBlockOrInsertParagraph(context, state, blockId);\n\t\treturn true;\n\t});\n}\n\nfunction handleArrowDown(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst nextNewline: number = text.indexOf('\\n', offset);\n\t\tif (nextNewline !== -1) return false;\n\n\t\tmoveToNextBlockOrInsertParagraph(context, state, blockId);\n\t\treturn true;\n\t});\n}\n\nfunction handleArrowUp(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst firstNewline: number = text.indexOf('\\n');\n\t\tif (firstNewline !== -1 && offset > firstNewline) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn moveToPreviousBlockEnd(context, state, blockId);\n\t});\n}\n\nfunction handleArrowRight(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tif (offset !== text.length) return false;\n\n\t\tmoveToNextBlockOrInsertParagraph(context, state, blockId);\n\t\treturn true;\n\t});\n}\n\nfunction handleArrowLeft(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\t\tif (offset !== 0) return false;\n\n\t\treturn moveToPreviousBlockEnd(context, state, blockId);\n\t});\n}\n\nfunction handleModEnter(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ blockId }) => {\n\t\tinsertParagraphAfter(context, blockId);\n\t\treturn true;\n\t});\n}\n\n// --- Multi-line indent helpers ---\n\ninterface IndentRangeResult {\n\treadonly inserts: readonly { offset: number; text: string }[];\n\treadonly totalInserted: number;\n\treadonly lineCount: number;\n\treadonly lineStart: number;\n}\n\nfunction indentLineRange(text: string, from: number, to: number, unit: string): IndentRangeResult {\n\tconst lineStart: number = text.lastIndexOf('\\n', from - 1) + 1;\n\tconst inserts: { offset: number; text: string }[] = [];\n\tlet lineCount = 0;\n\n\tlet pos: number = lineStart;\n\twhile (pos < to) {\n\t\tinserts.push({ offset: pos, text: unit });\n\t\tlineCount++;\n\t\tconst nl: number = text.indexOf('\\n', pos);\n\t\tif (nl === -1 || nl >= to) break;\n\t\tpos = nl + 1;\n\t}\n\n\treturn {\n\t\tinserts,\n\t\ttotalInserted: lineCount * unit.length,\n\t\tlineCount,\n\t\tlineStart,\n\t};\n}\n\ninterface DedentRangeResult {\n\treadonly deletes: readonly { from: number; to: number }[];\n\treadonly totalRemoved: number;\n\treadonly lineCount: number;\n\treadonly lineStart: number;\n}\n\nfunction dedentLineRange(\n\ttext: string,\n\tfrom: number,\n\tto: number,\n\tuseSpaces: boolean,\n\tspaceCount: number,\n): DedentRangeResult {\n\tconst lineStart: number = text.lastIndexOf('\\n', from - 1) + 1;\n\tconst deletes: { from: number; to: number }[] = [];\n\tlet totalRemoved = 0;\n\tlet lineCount = 0;\n\n\tlet pos: number = lineStart;\n\twhile (pos < to) {\n\t\tlineCount++;\n\t\tconst lineSlice: string = text.slice(pos);\n\t\tconst result = dedentOnce(lineSlice, useSpaces, spaceCount);\n\t\tif (result.removed.length > 0) {\n\t\t\tdeletes.push({ from: pos, to: pos + result.removed.length });\n\t\t\ttotalRemoved += result.removed.length;\n\t\t}\n\t\tconst nl: number = text.indexOf('\\n', pos);\n\t\tif (nl === -1 || nl >= to) break;\n\t\tpos = nl + 1;\n\t}\n\n\treturn {\n\t\tdeletes,\n\t\ttotalRemoved,\n\t\tlineCount,\n\t\tlineStart,\n\t};\n}\n\n// --- Other helpers ---\n\nfunction isMatchingPair(open: string, close: string): boolean {\n\tswitch (open) {\n\t\tcase '(':\n\t\t\treturn close === ')';\n\t\tcase '[':\n\t\t\treturn close === ']';\n\t\tcase '{':\n\t\t\treturn close === '}';\n\t\tcase '\"':\n\t\tcase \"'\":\n\t\tcase '`':\n\t\t\treturn close === open;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction insertParagraphAfter(context: PluginContext, bid: BlockId): void {\n\tconst state: EditorState = context.getState();\n\tconst block: BlockNode | undefined = state.getBlock(bid);\n\tif (!block) return;\n\n\tconst blockLength: number = getBlockLength(block);\n\tconst newId: BlockId = generateBlockId();\n\n\tconst tr: Transaction = state\n\t\t.transaction('command')\n\t\t.splitBlock(bid, blockLength, newId)\n\t\t.setBlockType(newId, nodeType('paragraph'))\n\t\t.setSelection(createCollapsedSelection(newId, 0))\n\t\t.build();\n\n\tcontext.dispatch(tr);\n}\n\n/**\n * Moves the cursor to the start of the following block, or appends a fresh\n * paragraph when the code block is the last block. Shared exit tail for\n * Escape / ArrowDown / ArrowRight at the end of the code block.\n */\nfunction moveToNextBlockOrInsertParagraph(\n\tcontext: PluginContext,\n\tstate: EditorState,\n\tbid: BlockId,\n): void {\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst idx: number = blockOrder.indexOf(bid);\n\n\tif (idx < blockOrder.length - 1) {\n\t\tconst nextId: BlockId = blockOrder[idx + 1] as BlockId;\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('command')\n\t\t\t.setSelection(createCollapsedSelection(nextId, 0))\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn;\n\t}\n\n\tinsertParagraphAfter(context, bid);\n}\n\n/**\n * Moves the cursor to the end of the preceding block. Shared tail for\n * ArrowUp / ArrowLeft at the start of the code block. Returns `false` when the\n * code block is already the first block (no movement performed).\n */\nfunction moveToPreviousBlockEnd(context: PluginContext, state: EditorState, bid: BlockId): boolean {\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst idx: number = blockOrder.indexOf(bid);\n\tif (idx <= 0) return false;\n\n\tconst prevId: BlockId = blockOrder[idx - 1] as BlockId;\n\tconst prevBlock: BlockNode | undefined = state.getBlock(prevId);\n\tconst prevLen: number = prevBlock ? getBlockLength(prevBlock) : 0;\n\tconst tr: Transaction = state\n\t\t.transaction('command')\n\t\t.setSelection(createCollapsedSelection(prevId, prevLen))\n\t\t.build();\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\nfunction exitOnDoubleEnter(context: PluginContext, bid: BlockId, text: string): boolean {\n\tconst state: EditorState = context.getState();\n\tconst trimmedLen: number = text.length - 1;\n\tconst newId: BlockId = generateBlockId();\n\n\tconst tr: Transaction = state\n\t\t.transaction('input')\n\t\t.deleteTextAt(bid, trimmedLen, text.length)\n\t\t.splitBlock(bid, trimmedLen, newId)\n\t\t.setBlockType(newId, nodeType('paragraph'))\n\t\t.setSelection(createCollapsedSelection(newId, 0))\n\t\t.build();\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n","/**\n * Command registration and implementations for code blocks.\n * Handles toggle, insert, exit, and mark stripping.\n */\n\nimport {\n\tcreateSelectionForBlockBoundary,\n\tcreateSelectionForDocumentBoundary,\n\textractParentPath,\n\tfindSiblingIndex,\n\tgetSiblings,\n} from '../../commands/CommandHelpers.js';\nimport type { BlockNode, ChildNode } from '../../model/Document.js';\nimport {\n\tcreateEmptyParagraph,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tgetInlineChildren,\n\tisBlockNode,\n\tisTextNode,\n} from '../../model/Document.js';\nimport { findNodePath } from '../../model/NodeResolver.js';\nimport type { EditorSelection } from '../../model/Selection.js';\nimport { createCollapsedSelection, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction, TransactionBuilder } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport { handleEscape } from './CodeBlockKeyboardHandlers.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\n\n/** Registers all code-block commands. */\nexport function registerCodeBlockCommands(context: PluginContext, config: CodeBlockConfig): void {\n\tcontext.registerCommand('toggleCodeBlock', () => toggleCodeBlock(context, config));\n\n\tcontext.registerCommand('insertCodeBlock', () => insertCodeBlock(context, config));\n\n\tcontext.registerCommand('setCodeBlockLanguage', () => false);\n\n\tcontext.registerCommand('setCodeBlockBackground', () => false);\n\n\tcontext.registerCommand('exitCodeBlock', () => handleEscape(context));\n\n\tcontext.registerCommand('deleteCodeBlock', () => deleteCodeBlock(context));\n}\n\n// --- Command Implementations ---\n\nfunction toggleCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block) return false;\n\n\tif (block.type === 'code_block') {\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('command')\n\t\t\t.setBlockType(state.selection.anchor.blockId, nodeType('paragraph'))\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\treturn insertCodeBlock(context, config);\n}\n\nfunction insertCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\tif (!block || block.type === 'code_block') return false;\n\n\tconst attrs: Record<string, string | number | boolean> = {\n\t\tlanguage: config.defaultLanguage ?? '',\n\t\tbackgroundColor: '',\n\t};\n\n\tconst builder: TransactionBuilder = state.transaction('command');\n\tstripAllMarks(builder, block);\n\tbuilder\n\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0));\n\n\tcontext.dispatch(builder.build());\n\treturn true;\n}\n\n/** Deletes the code block at the current cursor position. */\nfunction deleteCodeBlock(context: PluginContext): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block || block.type !== 'code_block') return false;\n\n\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, block.id);\n\tif (!tr) return false;\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/** Builds a transaction that removes a code block and repositions the cursor. */\nexport function createDeleteCodeBlockTransaction(\n\tstate: EditorState,\n\tblockId: BlockId,\n): Transaction | null {\n\tconst path: string[] | undefined = findNodePath(state.doc, blockId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\tconst index: number = findSiblingIndex(siblings, blockId);\n\tif (index < 0) return null;\n\n\tconst builder = state.transaction('command');\n\n\tif (siblings.length === 1) {\n\t\tconst newId: BlockId = generateBlockId();\n\t\tbuilder.insertNode(parentPath, 0, createEmptyParagraph(newId));\n\t\tbuilder.removeNode(parentPath, 1);\n\t\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\t\treturn builder.build();\n\t}\n\n\tbuilder.removeNode(parentPath, index);\n\n\tconst selection: EditorSelection = resolvePostDeleteSelection(state, builder, siblings, index);\n\tbuilder.setSelection(selection);\n\treturn builder.build();\n}\n\n/**\n * Determines the cursor position after a code block has been removed.\n *\n * Fallback chain — the first successful step wins, guaranteeing the caller\n * always receives a valid selection:\n * 1. End of the previous block sibling.\n * 2. Start of the next block sibling.\n * 3. Start of any other selectable block in the document.\n * 4. A freshly inserted empty paragraph at the document root.\n */\nfunction resolvePostDeleteSelection(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\tsiblings: readonly ChildNode[],\n\tremovedIndex: number,\n): EditorSelection {\n\tconst prevSibling = siblings[removedIndex - 1];\n\tif (prevSibling && isBlockNode(prevSibling)) {\n\t\tconst sel = createSelectionForBlockBoundary(state, prevSibling.id, 'end');\n\t\tif (sel) return sel;\n\t}\n\n\tconst nextSibling = siblings[removedIndex + 1];\n\tif (nextSibling && isBlockNode(nextSibling)) {\n\t\tconst sel = createSelectionForBlockBoundary(state, nextSibling.id, 'start');\n\t\tif (sel) return sel;\n\t}\n\n\tconst removed = siblings[removedIndex];\n\tconst excludeId: BlockId | undefined = removed && isBlockNode(removed) ? removed.id : undefined;\n\tconst docSel = createSelectionForDocumentBoundary(state, 'start', excludeId);\n\tif (docSel) return docSel;\n\n\tconst newId: BlockId = generateBlockId();\n\tbuilder.insertNode([], 0, createEmptyParagraph(newId));\n\treturn createCollapsedSelection(newId, 0);\n}\n\n/**\n * Strips all marks from a block's inline content.\n * Used when converting to code_block so no formatting carries over.\n */\nfunction stripAllMarks(builder: TransactionBuilder, block: BlockNode): void {\n\tconst blockLength: number = getBlockLength(block);\n\tif (blockLength === 0) return;\n\n\tconst inlineChildren = getInlineChildren(block);\n\tlet offset = 0;\n\n\tfor (const child of inlineChildren) {\n\t\tif (isTextNode(child)) {\n\t\t\tif (child.text.length > 0) {\n\t\t\t\tfor (const mark of child.marks) {\n\t\t\t\t\tbuilder.removeMark(block.id, offset, offset + child.text.length, mark);\n\t\t\t\t}\n\t\t\t}\n\t\t\toffset += child.text.length;\n\t\t} else {\n\t\t\toffset += 1;\n\t\t}\n\t}\n}\n","/**\n * Builds the decoration set for code blocks: a focus highlight on the block\n * containing the caret plus per-token syntax-highlight decorations sourced from\n * the {@link TokenCache}.\n */\n\nimport type { Decoration } from '../../decorations/Decoration.js';\nimport {\n\tDecorationSet,\n\tinline as inlineDecoration,\n\tnode as nodeDecoration,\n} from '../../decorations/Decoration.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport { isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { SyntaxHighlighter, SyntaxToken } from './CodeBlockTypes.js';\nimport type { TokenCache } from './TokenCache.js';\n\ninterface CodeBlockDecorationDeps {\n\treadonly highlighter: SyntaxHighlighter | null;\n\treadonly tokenCache: TokenCache;\n}\n\n/**\n * Produces the focus + syntax-highlight decorations for all code blocks in\n * `state`. As a side effect, prunes cache entries for blocks that no longer\n * carry highlightable content so the cache tracks the live document.\n */\nexport function createCodeBlockDecorations(\n\tstate: EditorState,\n\tdeps: CodeBlockDecorationDeps,\n): DecorationSet {\n\tconst decorations: Decoration[] = [];\n\n\tconst focusedBlockId: BlockId | null = getFocusedCodeBlockId(state);\n\tif (focusedBlockId) {\n\t\tdecorations.push(nodeDecoration(focusedBlockId, { class: 'notectl-code-block--focused' }));\n\t}\n\n\tif (deps.highlighter) {\n\t\tconst activeBlockIds = new Set<BlockId>();\n\t\tfor (const bid of state.getBlockOrder()) {\n\t\t\tconst block: BlockNode | undefined = state.getBlock(bid);\n\t\t\tif (!block || block.type !== 'code_block') continue;\n\n\t\t\tconst lang: string = (block.attrs?.language as string) ?? '';\n\t\t\tif (!lang) continue;\n\n\t\t\tconst text: string = getBlockText(block);\n\t\t\tif (!text) continue;\n\n\t\t\tactiveBlockIds.add(bid);\n\t\t\tconst tokens: readonly SyntaxToken[] = deps.tokenCache.getTokens(\n\t\t\t\tbid,\n\t\t\t\ttext,\n\t\t\t\tlang,\n\t\t\t\tdeps.highlighter,\n\t\t\t);\n\t\t\tfor (const token of tokens) {\n\t\t\t\tdecorations.push(\n\t\t\t\t\tinlineDecoration(bid, token.from, token.to, {\n\t\t\t\t\t\tclass: `notectl-token--${token.type}`,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tdeps.tokenCache.retain(activeBlockIds);\n\t}\n\n\tif (decorations.length === 0) return DecorationSet.empty;\n\treturn DecorationSet.create(decorations);\n}\n\nfunction getFocusedCodeBlockId(state: EditorState): BlockId | null {\n\tif (!isTextSelection(state.selection)) return null;\n\tconst blockId: BlockId = state.selection.anchor.blockId;\n\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\tif (block?.type === 'code_block') return blockId;\n\treturn null;\n}\n","/**\n * Internal registry that stores LanguageSupport bundles and notifies\n * subscribers with replay semantics for late subscribers.\n */\n\nimport type {\n\tLanguageRegistryListener,\n\tLanguageRegistryService,\n\tLanguageSupport,\n} from './LanguageTypes.js';\n\nexport class LanguageRegistry implements LanguageRegistryService {\n\tprivate readonly bundles = new Map<string, LanguageSupport>();\n\tprivate readonly listeners: LanguageRegistryListener[] = [];\n\n\tregister(support: LanguageSupport): void {\n\t\tthis.bundles.set(support.id, support);\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\t/**\n\t * Subscribes to language registrations.\n\t * The listener is immediately called for all already-registered bundles\n\t * (replay semantics), then called for each future registration.\n\t */\n\tonRegister(listener: LanguageRegistryListener): void {\n\t\tthis.listeners.push(listener);\n\t\tfor (const support of this.bundles.values()) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\tget(id: string): LanguageSupport | undefined {\n\t\treturn this.bundles.get(id);\n\t}\n\n\tgetAll(): readonly LanguageSupport[] {\n\t\treturn [...this.bundles.values()];\n\t}\n}\n","/**\n * Types, interfaces, and constants for the code-block plugin.\n */\n\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { ServiceKey } from '../Plugin.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\tcode_block: {\n\t\t\tlanguage: string;\n\t\t\tbackgroundColor: string;\n\t\t};\n\t}\n}\n\n// --- Syntax Highlighting Types ---\n\nimport type { SyntaxTokenType } from '../../editor/theme/SyntaxTokenTypes.js';\n\nexport interface SyntaxToken {\n\treadonly from: number;\n\treadonly to: number;\n\treadonly type: SyntaxTokenType | (string & {});\n}\n\nexport interface SyntaxHighlighter {\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\tgetSupportedLanguages(): readonly string[];\n\tregisterLanguage?(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n}\n\n// --- Configuration ---\n\n/**\n * Configurable keyboard bindings for CodeBlockPlugin actions.\n * Omit a slot to use the default; set to `null` to disable the binding.\n *\n * Key descriptor format: `'Mod-Enter'`, `'Mod-Shift-M'`, etc.\n * `Mod` resolves to Cmd on macOS, Ctrl on Windows/Linux.\n */\nexport interface CodeBlockKeymap {\n\t/**\n\t * Insert a new paragraph below the code block and move the cursor there.\n\t * @default 'Mod-Enter'\n\t */\n\treadonly insertAfter?: string | null;\n\n\t/**\n\t * Toggle the current block between code block and paragraph.\n\t * @default 'Mod-Shift-M'\n\t */\n\treadonly toggle?: string | null;\n}\n\nexport const DEFAULT_KEYMAP: Readonly<Record<keyof CodeBlockKeymap, string>> = {\n\tinsertAfter: 'Mod-Enter',\n\ttoggle: 'Mod-Shift-M',\n};\n\n/** Auto-indent configuration block. All fields optional. */\nexport interface CodeBlockIndentConfig {\n\t/** Indent mode: `none` disables Enter-driven indent, `keep` only inherits the\n\t * previous line's indent, `brackets` additionally adds an extra step after\n\t * `{`, `[`, `(` and dedents on close chars. Default `'brackets'`. */\n\treadonly mode?: 'none' | 'keep' | 'brackets';\n\t/** Use spaces instead of a literal tab character. Default `false`. */\n\treadonly useSpaces?: boolean;\n\t/** Spaces per indent unit (clamped to [1, 16]). Default `2`. */\n\treadonly spaceCount?: number;\n}\n\n/** Auto-pair configuration block. All fields optional. */\nexport interface CodeBlockPairingConfig {\n\t/** Auto-pair behavior for brackets. Default `'languageDefined'`. */\n\treadonly brackets?: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\t/** Auto-pair behavior for quotes. Default `'languageDefined'`. */\n\treadonly quotes?: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\t/** Skip-over for auto-inserted close chars. Default `true`. */\n\treadonly overtype?: boolean;\n\t/** Backspace removes leftover empty auto-pair. Default `true`. */\n\treadonly deletePair?: boolean;\n\t/** Wrap-selection scope. Default `'languageDefined'` (= brackets + quotes). */\n\treadonly surround?: 'languageDefined' | 'quotes' | 'brackets' | 'never';\n}\n\n/**\n * Fully-resolved indent config seen by the keyboard handlers.\n * Differs from `CodeBlockIndentConfig` only in that all fields are required\n * after the constructor merge + clamp.\n */\nexport interface ResolvedIndentConfig {\n\treadonly mode: 'none' | 'keep' | 'brackets';\n\treadonly useSpaces: boolean;\n\treadonly spaceCount: number;\n}\n\n/** Fully-resolved pairing config — all fields required. */\nexport interface ResolvedPairingConfig {\n\treadonly brackets: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\treadonly quotes: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\treadonly overtype: boolean;\n\treadonly deletePair: boolean;\n\treadonly surround: 'languageDefined' | 'quotes' | 'brackets' | 'never';\n}\n\nexport interface CodeBlockConfig {\n\treadonly highlighter?: SyntaxHighlighter;\n\treadonly defaultLanguage?: string;\n\t/**\n\t * @deprecated Use `indent.useSpaces` instead. Read as a fallback when\n\t * `indent.useSpaces` is unset.\n\t */\n\treadonly useSpaces?: boolean;\n\t/**\n\t * @deprecated Use `indent.spaceCount` instead. Read as a fallback when\n\t * `indent.spaceCount` is unset.\n\t */\n\treadonly spaceCount?: number;\n\treadonly showCopyButton?: boolean;\n\t/** Default body background color (overrides --notectl-code-block-bg). */\n\treadonly background?: string;\n\t/** Default header background color (overrides --notectl-code-block-header-bg). */\n\treadonly headerBackground?: string;\n\t/** Default text color (overrides --notectl-code-block-color). */\n\treadonly textColor?: string;\n\t/** Default header/label text color (overrides --notectl-code-block-header-color). */\n\treadonly headerColor?: string;\n\t/** Customize keyboard bindings for code block actions. */\n\treadonly keymap?: CodeBlockKeymap;\n\t/** Locale override for user-facing strings. */\n\treadonly locale?: import('./CodeBlockLocale.js').CodeBlockLocale;\n\t/** Auto-indent settings. */\n\treadonly indent?: CodeBlockIndentConfig;\n\t/** Bracket-pairing settings. */\n\treadonly pairing?: CodeBlockPairingConfig;\n}\n\nexport const DEFAULT_CONFIG: CodeBlockConfig = {\n\tdefaultLanguage: '',\n\tuseSpaces: false,\n\tspaceCount: 2,\n\tshowCopyButton: true,\n};\n\n/** Default values applied during config merge (see CodeBlockPlugin.constructor). */\nexport const DEFAULT_INDENT: ResolvedIndentConfig = {\n\tmode: 'brackets',\n\tuseSpaces: false,\n\tspaceCount: 2,\n};\n\nexport const DEFAULT_PAIRING: ResolvedPairingConfig = {\n\tbrackets: 'languageDefined',\n\tquotes: 'languageDefined',\n\tovertype: true,\n\tdeletePair: true,\n\tsurround: 'languageDefined',\n};\n\nexport const MIN_SPACE_COUNT = 1;\nexport const MAX_SPACE_COUNT = 16;\n\n// --- Service Types ---\n\nexport interface CodeBlockService {\n\tsetLanguage(blockId: BlockId, language: string): void;\n\tgetLanguage(blockId: BlockId): string;\n\tsetBackground(blockId: BlockId, color: string): void;\n\tgetBackground(blockId: BlockId): string;\n\tisCodeBlock(blockId: BlockId): boolean;\n\tgetSupportedLanguages(): readonly string[];\n}\n\nexport const CODE_BLOCK_SERVICE_KEY = new ServiceKey<CodeBlockService>('codeBlock');\n\n// --- Syntax Highlighter Service ---\n\nexport interface SyntaxHighlighterService {\n\tregisterLanguage(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n\tgetSupportedLanguages(): readonly string[];\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\t/**\n\t * Returns the cached token whose range covers `offset` in `blockId`, or\n\t * `undefined` if no token is registered at that position (e.g. cache miss,\n\t * whitespace between tokens, or block not yet tokenized). Uses binary\n\t * search over the per-block token cache; never triggers a fresh tokenize.\n\t */\n\tgetTokenAt(blockId: BlockId, offset: number): SyntaxToken | undefined;\n}\n\nexport const SYNTAX_HIGHLIGHTER_SERVICE_KEY = new ServiceKey<SyntaxHighlighterService>(\n\t'syntaxHighlighter',\n);\n\n// --- SVG Icon ---\n\nexport const CODE_BLOCK_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z\"/><path d=\"M11 14.17L8.83 12 11 9.83 9.59 8.41 6 12l3.59 3.59L11 14.17zm3.41 1.42L18 12l-3.59-3.59L13 9.83 15.17 12 13 14.17l1.41 1.42z\"/></svg>';\n","/**\n * Regex-based syntax tokenizer.\n * Implements the SyntaxHighlighter interface using linear regex scanning\n * with sticky (`y`-flagged) regexes to avoid O(n) substring allocations per position.\n */\n\nimport type { SyntaxHighlighter, SyntaxToken } from '../CodeBlockTypes.js';\nimport { iterateTokens } from './TokenIteration.js';\nimport type { LanguageDefinition } from './TokenizerTypes.js';\n\nexport class RegexTokenizer implements SyntaxHighlighter {\n\tprivate readonly languageMap = new Map<string, LanguageDefinition>();\n\n\tconstructor(languages?: readonly LanguageDefinition[]) {\n\t\tif (languages) {\n\t\t\tfor (const lang of languages) {\n\t\t\t\tthis.registerLanguageInternal(lang);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Registers a language definition. Overwrites existing definitions for the same name/aliases. */\n\tregisterLanguage(def: LanguageDefinition): void {\n\t\tthis.registerLanguageInternal(def);\n\t}\n\n\t/** Tokenizes code using the specified language. Returns empty array for unknown languages. */\n\ttokenize(code: string, language: string): readonly SyntaxToken[] {\n\t\tconst lang: LanguageDefinition | undefined = this.languageMap.get(language.toLowerCase());\n\t\tif (!lang) return [];\n\n\t\tconst tokens: SyntaxToken[] = [];\n\t\tfor (const token of iterateTokens(code, lang)) {\n\t\t\ttokens.push({ from: token.from, to: token.to, type: token.type });\n\t\t}\n\t\treturn tokens;\n\t}\n\n\t/** Returns all registered language names and aliases. */\n\tgetSupportedLanguages(): readonly string[] {\n\t\tconst names = new Set<string>();\n\t\tfor (const lang of this.languageMap.values()) {\n\t\t\tnames.add(lang.name);\n\t\t\tfor (const alias of lang.aliases) {\n\t\t\t\tnames.add(alias);\n\t\t\t}\n\t\t}\n\t\treturn [...names];\n\t}\n\n\tprivate registerLanguageInternal(def: LanguageDefinition): void {\n\t\tthis.languageMap.set(def.name.toLowerCase(), def);\n\t\tfor (const alias of def.aliases) {\n\t\t\tthis.languageMap.set(alias.toLowerCase(), def);\n\t\t}\n\t}\n}\n","/**\n * Wires up syntax highlighting for the code-block plugin: selects the active\n * highlighter (the configured one or the built-in {@link RegexTokenizer}),\n * registers the language registry with its bundled languages, and exposes the\n * `SyntaxHighlighterService`. The shared {@link TokenCache} is invalidated\n * whenever a new language is registered.\n */\n\nimport type { PluginContext } from '../Plugin.js';\nimport { LanguageRegistry } from '../language/LanguageRegistry.js';\nimport { LANGUAGE_REGISTRY_SERVICE_KEY } from '../language/LanguageTypes.js';\nimport {\n\tJAVA_SUPPORT,\n\tJSON_SUPPORT,\n\tTYPESCRIPT_SUPPORT,\n\tXML_SUPPORT,\n} from '../language/bundles/index.js';\nimport type { CodeBlockConfig, SyntaxHighlighter } from './CodeBlockTypes.js';\nimport { SYNTAX_HIGHLIGHTER_SERVICE_KEY } from './CodeBlockTypes.js';\nimport type { TokenCache } from './TokenCache.js';\nimport { RegexTokenizer } from './highlighter/RegexTokenizer.js';\n\n/**\n * Sets up the highlighter, language registry, and syntax-highlighter service.\n * Returns the active highlighter so the plugin can hand it to the node view and\n * decoration builder.\n */\nexport function setupHighlighting(\n\tcontext: PluginContext,\n\tconfig: CodeBlockConfig,\n\ttokenCache: TokenCache,\n): SyntaxHighlighter {\n\tconst highlighter: SyntaxHighlighter = config.highlighter ?? new RegexTokenizer();\n\n\tconst languageRegistry = new LanguageRegistry();\n\tlanguageRegistry.onRegister((support) => {\n\t\tif (support.highlighting && highlighter.registerLanguage) {\n\t\t\thighlighter.registerLanguage(support.highlighting);\n\t\t\ttokenCache.clear();\n\t\t}\n\t});\n\tcontext.registerService(LANGUAGE_REGISTRY_SERVICE_KEY, languageRegistry);\n\n\tlanguageRegistry.register(JAVA_SUPPORT);\n\tlanguageRegistry.register(JSON_SUPPORT);\n\tlanguageRegistry.register(TYPESCRIPT_SUPPORT);\n\tlanguageRegistry.register(XML_SUPPORT);\n\n\tcontext.registerService(SYNTAX_HIGHLIGHTER_SERVICE_KEY, {\n\t\tregisterLanguage: (def) => {\n\t\t\thighlighter.registerLanguage?.(def);\n\t\t\ttokenCache.clear();\n\t\t},\n\t\tgetSupportedLanguages: () => highlighter.getSupportedLanguages(),\n\t\ttokenize: (code, language) => highlighter.tokenize(code, language),\n\t\tgetTokenAt: (blockId, offset) => tokenCache.findTokenAt(blockId, offset),\n\t});\n\n\treturn highlighter;\n}\n","/** Locale interface and default English locale for the CodeBlockPlugin. */\n\nimport { type LocaleModuleMap, loadLocaleModule } from '../shared/LocaleLoader.js';\n\n// --- Locale Interface ---\n\nexport interface CodeBlockLocale {\n\treadonly label: string;\n\treadonly tooltip: (shortcut?: string) => string;\n\treadonly enteredCodeBlock: string;\n\treadonly leftCodeBlock: string;\n\treadonly copyCodeAria: string;\n\treadonly escToExit: string;\n\treadonly codeBlockAriaLabel: (lang: string) => string;\n\treadonly copiedToClipboard: string;\n\treadonly copyFailed: string;\n\treadonly deleteCodeBlockAria: string;\n\treadonly deletedCodeBlock: string;\n\treadonly selectLanguageAria: string;\n\treadonly languageChanged: (lang: string) => string;\n\treadonly plainText: string;\n\t/** Screen-reader announcement after multi-line Tab indent. */\n\treadonly indentedNLines: (n: number) => string;\n\t/** Screen-reader announcement after multi-line Shift-Tab dedent. */\n\treadonly dedentedNLines: (n: number) => string;\n}\n\n// --- Default English Locale ---\n\nexport const CODE_BLOCK_LOCALE_EN: CodeBlockLocale = {\n\tlabel: 'Code Block',\n\ttooltip: (shortcut?: string) => (shortcut ? `Code Block (${shortcut})` : 'Code Block'),\n\tenteredCodeBlock: 'Entered code block. Press Escape to exit.',\n\tleftCodeBlock: 'Left code block.',\n\tcopyCodeAria: 'Copy code',\n\tescToExit: 'Esc to exit',\n\tcodeBlockAriaLabel: (lang: string) => `${lang} code block. Press Escape to exit.`,\n\tcopiedToClipboard: 'Copied to clipboard',\n\tcopyFailed: 'Failed to copy code',\n\tdeleteCodeBlockAria: 'Delete code block',\n\tdeletedCodeBlock: 'Code block deleted',\n\tselectLanguageAria: 'Select language',\n\tlanguageChanged: (lang: string) => `Language changed to ${lang}`,\n\tplainText: 'plain',\n\tindentedNLines: (n: number) => (n === 1 ? '1 line indented' : `${n} lines indented`),\n\tdedentedNLines: (n: number) => (n === 1 ? '1 line dedented' : `${n} lines dedented`),\n};\n\n// --- Lazy Locale Loader ---\n\nconst localeModules: LocaleModuleMap<CodeBlockLocale> = import.meta.glob<{\n\tdefault: CodeBlockLocale;\n}>('./locales/*.ts', { eager: false });\n\nexport async function loadCodeBlockLocale(lang: string): Promise<CodeBlockLocale> {\n\treturn loadLocaleModule(localeModules, lang, CODE_BLOCK_LOCALE_EN);\n}\n","/**\n * Language picker popup for code blocks.\n * Opens a listbox dropdown anchored to the language button,\n * allowing users to select a syntax highlighting language.\n */\n\nimport { attachListboxKeyboard } from '../shared/PopupKeyboardPatterns.js';\nimport type { PopupServiceAPI } from '../shared/PopupManager.js';\nimport type { CodeBlockLocale } from './CodeBlockLocale.js';\n\n/** Configuration for opening the language picker popup. */\nexport interface LanguagePickerConfig {\n\treadonly anchor: HTMLElement;\n\treadonly languages: readonly string[];\n\treadonly currentLanguage: string;\n\treadonly onSelect: (language: string) => void;\n\treadonly popupManager: PopupServiceAPI;\n\treadonly locale: CodeBlockLocale;\n}\n\nconst OPTION_SELECTOR = '[role=\"option\"]';\n\n/** Opens a language picker popup anchored to the given element. */\nexport function openLanguagePicker(config: LanguagePickerConfig): void {\n\tconst { anchor, languages, currentLanguage, onSelect, popupManager, locale } = config;\n\n\tpopupManager.open({\n\t\tanchor,\n\t\tariaRole: 'listbox',\n\t\tariaLabel: locale.selectLanguageAria,\n\t\tclassName: 'notectl-language-picker',\n\t\tposition: 'below-start',\n\t\trestoreFocusTo: anchor,\n\t\tcontent(container, close) {\n\t\t\tconst normalizedCurrent: string = currentLanguage.toLowerCase();\n\n\t\t\t// \"plain\" option is always first\n\t\t\tappendOption(container, locale.plainText, '', normalizedCurrent === '');\n\n\t\t\t// Language options sorted alphabetically\n\t\t\tconst sorted: readonly string[] = [...languages].sort((a, b) => a.localeCompare(b));\n\t\t\tfor (const lang of sorted) {\n\t\t\t\tappendOption(container, lang, lang, normalizedCurrent === lang.toLowerCase());\n\t\t\t}\n\n\t\t\tattachListboxKeyboard({\n\t\t\t\tcontainer,\n\t\t\t\titemSelector: OPTION_SELECTOR,\n\t\t\t\tonSelect(item) {\n\t\t\t\t\tconst value: string = item.getAttribute('data-language') ?? '';\n\t\t\t\t\tonSelect(value);\n\t\t\t\t\tclose();\n\t\t\t\t},\n\t\t\t\tonClose() {\n\t\t\t\t\tclose();\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tcontainer.addEventListener('click', (e: Event) => {\n\t\t\t\tconst target: HTMLElement | null = (e.target as HTMLElement).closest(OPTION_SELECTOR);\n\t\t\t\tif (!target) return;\n\t\t\t\tconst value: string = target.getAttribute('data-language') ?? '';\n\t\t\t\tonSelect(value);\n\t\t\t\tclose();\n\t\t\t});\n\t\t},\n\t\tonClose() {\n\t\t\tanchor.setAttribute('aria-expanded', 'false');\n\t\t},\n\t});\n\n\tanchor.setAttribute('aria-expanded', 'true');\n}\n\nfunction appendOption(\n\tcontainer: HTMLElement,\n\tlabel: string,\n\tvalue: string,\n\tselected: boolean,\n): void {\n\tconst option: HTMLDivElement = document.createElement('div');\n\toption.className = 'notectl-language-picker__option';\n\toption.setAttribute('role', 'option');\n\toption.setAttribute('data-language', value);\n\toption.setAttribute('aria-selected', String(selected));\n\toption.setAttribute('tabindex', selected ? '0' : '-1');\n\toption.textContent = label;\n\tcontainer.appendChild(option);\n}\n","/**\n * NodeView factory for code blocks.\n * Renders <pre> with a non-editable header (language label + action buttons)\n * and a <code> content area where the Reconciler renders text.\n */\n\nimport type { BlockAttrs, BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { NodeView, NodeViewFactory } from '../../view/NodeView.js';\nimport type { PopupServiceAPI } from '../shared/PopupManager.js';\nimport { createDeleteCodeBlockTransaction } from './CodeBlockCommands.js';\nimport { CODE_BLOCK_LOCALE_EN, type CodeBlockLocale } from './CodeBlockLocale.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\nimport { openLanguagePicker } from './LanguagePicker.js';\n\n/** How long a screen-reader announcement stays in the live region before clearing. */\nconst ANNOUNCE_CLEAR_MS = 1000;\n\n/** Dependencies for the language picker in the code block header. */\nexport interface LanguagePickerDeps {\n\treadonly popupManager: PopupServiceAPI;\n\treadonly getSupportedLanguages: () => readonly string[];\n}\n\nconst COPY_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z\"/></svg>';\n\nconst DELETE_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z\"/></svg>';\n\nconst CHEVRON_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"10\" height=\"10\"><path d=\"M4 6l4 4 4-4\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>';\n\n/**\n * Copies text to the clipboard, rejecting when the Clipboard API is unavailable\n * (e.g. insecure context, missing permissions) or when the write itself fails.\n * Callers must handle rejection to give the user accurate feedback.\n */\nexport function copyTextToClipboard(text: string): Promise<void> {\n\tconst clipboard: Clipboard | undefined = globalThis.navigator?.clipboard;\n\tif (!clipboard || typeof clipboard.writeText !== 'function') {\n\t\treturn Promise.reject(new Error('Clipboard API unavailable'));\n\t}\n\treturn clipboard.writeText(text);\n}\n\n/** Creates a NodeViewFactory for code_block nodes. */\nexport function createCodeBlockNodeViewFactory(\n\tconfig: CodeBlockConfig,\n\tlocale: CodeBlockLocale = CODE_BLOCK_LOCALE_EN,\n\tpickerDeps?: LanguagePickerDeps,\n): NodeViewFactory {\n\treturn (\n\t\tnode: BlockNode,\n\t\tgetState: () => EditorState,\n\t\tdispatch: (tr: Transaction) => void,\n\t): NodeView => {\n\t\t// --- DOM Construction ---\n\t\tconst pre: HTMLElement = document.createElement('pre');\n\t\tpre.className = 'notectl-code-block';\n\t\tpre.setAttribute('data-block-id', node.id);\n\t\tpre.setAttribute('dir', 'ltr');\n\t\tpre.setAttribute('role', 'group');\n\t\tpre.setAttribute('aria-roledescription', 'code block');\n\t\tpre.setAttribute('part', 'code-block');\n\n\t\t// Header (non-editable)\n\t\tconst header: HTMLDivElement = document.createElement('div');\n\t\theader.className = 'notectl-code-block__header';\n\t\theader.setAttribute('contenteditable', 'false');\n\t\theader.setAttribute('part', 'code-block-header');\n\n\t\tconst langBtn: HTMLButtonElement = document.createElement('button');\n\t\tlangBtn.className = 'notectl-code-block__language-btn';\n\t\tlangBtn.type = 'button';\n\t\tlangBtn.setAttribute('aria-haspopup', 'listbox');\n\t\tlangBtn.setAttribute('aria-expanded', 'false');\n\t\tlangBtn.setAttribute('aria-label', locale.selectLanguageAria);\n\n\t\tconst showCopy: boolean = config.showCopyButton !== false;\n\t\tlet copyBtn: HTMLButtonElement | null = null;\n\n\t\tif (showCopy) {\n\t\t\tcopyBtn = document.createElement('button');\n\t\t\tcopyBtn.className = 'notectl-code-block__copy';\n\t\t\tcopyBtn.setAttribute('aria-label', locale.copyCodeAria);\n\t\t\tcopyBtn.setAttribute('data-notectl-no-print', '');\n\t\t\tcopyBtn.type = 'button';\n\t\t\tcopyBtn.innerHTML = COPY_ICON;\n\t\t}\n\n\t\t// Delete button\n\t\tconst deleteBtn: HTMLButtonElement = document.createElement('button');\n\t\tdeleteBtn.className = 'notectl-code-block__delete';\n\t\tdeleteBtn.setAttribute('aria-label', locale.deleteCodeBlockAria);\n\t\tdeleteBtn.title = locale.deleteCodeBlockAria;\n\t\tdeleteBtn.setAttribute('data-notectl-no-print', '');\n\t\tdeleteBtn.type = 'button';\n\t\tdeleteBtn.innerHTML = DELETE_ICON;\n\n\t\t// Screen reader live region for action feedback\n\t\tconst announcer: HTMLSpanElement = document.createElement('span');\n\t\tannouncer.className = 'notectl-sr-only';\n\t\tannouncer.setAttribute('aria-live', 'assertive');\n\t\tannouncer.setAttribute('aria-atomic', 'true');\n\n\t\t// Actions wrapper groups buttons on the right side\n\t\tconst actions: HTMLDivElement = document.createElement('div');\n\t\tactions.className = 'notectl-code-block__actions';\n\t\tif (copyBtn) {\n\t\t\tactions.appendChild(copyBtn);\n\t\t}\n\t\tactions.appendChild(deleteBtn);\n\n\t\theader.appendChild(langBtn);\n\t\theader.appendChild(actions);\n\t\theader.appendChild(announcer);\n\n\t\t// Content area (Reconciler target)\n\t\tconst code: HTMLElement = document.createElement('code');\n\t\tcode.className = 'notectl-code-block__content';\n\t\tcode.setAttribute('part', 'code-block-content');\n\n\t\t// Escape hint (visible only when focused, CSS-driven)\n\t\tconst escHint: HTMLDivElement = document.createElement('div');\n\t\tescHint.className = 'notectl-code-block__esc-hint';\n\t\tescHint.setAttribute('contenteditable', 'false');\n\t\tescHint.setAttribute('aria-hidden', 'true');\n\t\tescHint.setAttribute('data-notectl-no-print', '');\n\t\tescHint.textContent = locale.escToExit;\n\n\t\tpre.appendChild(header);\n\t\tpre.appendChild(code);\n\t\tpre.appendChild(escHint);\n\n\t\t// Apply config-level color overrides as CSS custom properties\n\t\tif (config.background) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-bg', config.background);\n\t\t}\n\t\tif (config.headerBackground) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-bg', config.headerBackground);\n\t\t}\n\t\tif (config.textColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-color', config.textColor);\n\t\t}\n\t\tif (config.headerColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-color', config.headerColor);\n\t\t}\n\n\t\tlet currentNodeId: BlockId = node.id;\n\n\t\t// --- Attribute Application ---\n\n\t\tfunction applyAttrs(n: BlockNode): void {\n\t\t\tconst lang: string = (n.attrs?.language as string) ?? '';\n\t\t\tconst langName: string = lang || locale.plainText;\n\t\t\tlangBtn.innerHTML = '';\n\t\t\tconst labelSpan: HTMLSpanElement = document.createElement('span');\n\t\t\tlabelSpan.className = 'notectl-code-block__language';\n\t\t\tlabelSpan.textContent = langName;\n\t\t\tlangBtn.appendChild(labelSpan);\n\t\t\tif (pickerDeps) {\n\t\t\t\tconst chevron: HTMLSpanElement = document.createElement('span');\n\t\t\t\tchevron.className = 'notectl-code-block__chevron';\n\t\t\t\tchevron.innerHTML = CHEVRON_ICON;\n\t\t\t\tlangBtn.appendChild(chevron);\n\t\t\t}\n\t\t\tpre.setAttribute('aria-label', locale.codeBlockAriaLabel(langName));\n\n\t\t\tif (lang) {\n\t\t\t\tcode.setAttribute('data-language', lang);\n\t\t\t} else {\n\t\t\t\tcode.removeAttribute('data-language');\n\t\t\t}\n\n\t\t\tconst bg: string = (n.attrs?.backgroundColor as string) ?? '';\n\t\t\tsetStyleProperty(pre, 'backgroundColor', bg || '');\n\t\t}\n\n\t\tapplyAttrs(node);\n\n\t\t// --- Copy Button Handler ---\n\n\t\tfunction announce(message: string): void {\n\t\t\tannouncer.textContent = message;\n\t\t\tsetTimeout(() => {\n\t\t\t\tannouncer.textContent = '';\n\t\t\t}, ANNOUNCE_CLEAR_MS);\n\t\t}\n\n\t\tif (copyBtn) {\n\t\t\tcopyBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\t\te.preventDefault();\n\t\t\t\te.stopPropagation();\n\n\t\t\t\tconst state: EditorState = getState();\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(currentNodeId);\n\t\t\t\tif (!block) return;\n\n\t\t\t\tconst text: string = getBlockText(block);\n\t\t\t\tcopyTextToClipboard(text).then(\n\t\t\t\t\t() => announce(locale.copiedToClipboard),\n\t\t\t\t\t() => announce(locale.copyFailed),\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\n\t\t// --- Delete Button Handler ---\n\n\t\tdeleteBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\n\t\t\tconst state: EditorState = getState();\n\t\t\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, currentNodeId);\n\t\t\tif (!tr) return;\n\n\t\t\tannouncer.textContent = locale.deletedCodeBlock;\n\t\t\tdispatch(tr);\n\t\t});\n\n\t\t// --- Language Picker Handler ---\n\n\t\tif (pickerDeps) {\n\t\t\tlangBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\t\te.preventDefault();\n\t\t\t\te.stopPropagation();\n\n\t\t\t\tconst state: EditorState = getState();\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(currentNodeId);\n\t\t\t\tif (!block) return;\n\n\t\t\t\tconst currentLang: string = (block.attrs?.language as string) ?? '';\n\t\t\t\topenLanguagePicker({\n\t\t\t\t\tanchor: langBtn,\n\t\t\t\t\tlanguages: pickerDeps.getSupportedLanguages(),\n\t\t\t\t\tcurrentLanguage: currentLang,\n\t\t\t\t\tlocale,\n\t\t\t\t\tpopupManager: pickerDeps.popupManager,\n\t\t\t\t\tonSelect(language: string) {\n\t\t\t\t\t\tif (language === currentLang) return;\n\n\t\t\t\t\t\tconst latest: EditorState = getState();\n\t\t\t\t\t\tconst latestBlock: BlockNode | undefined = latest.getBlock(currentNodeId);\n\t\t\t\t\t\tif (!latestBlock) return;\n\n\t\t\t\t\t\tconst path: BlockId[] | undefined = latest.getNodePath(currentNodeId);\n\t\t\t\t\t\tif (!path) return;\n\n\t\t\t\t\t\tconst newAttrs: BlockAttrs = { ...latestBlock.attrs, language };\n\t\t\t\t\t\tconst tr: Transaction = latest\n\t\t\t\t\t\t\t.transaction('command')\n\t\t\t\t\t\t\t.setNodeAttr(path, newAttrs)\n\t\t\t\t\t\t\t.build();\n\t\t\t\t\t\tdispatch(tr);\n\n\t\t\t\t\t\tconst langName: string = language || locale.plainText;\n\t\t\t\t\t\tannounce(locale.languageChanged(langName));\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// --- NodeView Interface ---\n\n\t\treturn {\n\t\t\tdom: pre,\n\t\t\tcontentDOM: code,\n\n\t\t\tupdate(updatedNode: BlockNode): boolean {\n\t\t\t\tif (updatedNode.type !== 'code_block') return false;\n\t\t\t\tcurrentNodeId = updatedNode.id;\n\t\t\t\tpre.setAttribute('data-block-id', updatedNode.id);\n\t\t\t\tapplyAttrs(updatedNode);\n\t\t\t\treturn true;\n\t\t\t},\n\n\t\t\tselectNode(): void {\n\t\t\t\tpre.classList.add('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdeselectNode(): void {\n\t\t\t\tpre.classList.remove('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdestroy(): void {\n\t\t\t\t// No cleanup needed\n\t\t\t},\n\t\t};\n\t};\n}\n","/**\n * Static editor registrations for the code-block plugin: the `code_block`\n * NodeSpec, the ```` ```lang ```` input rule, the toolbar item, the mark-guard\n * middleware, the paste interceptor, and the table-cell content patch.\n *\n * These are pure registration helpers with no per-instance state, mirroring the\n * `registerCodeBlockCommands` / `registerCodeBlockKeymaps` pattern.\n */\n\nimport { addDeleteSelectionSteps } from '../../commands/Commands.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { HTMLExportContext } from '../../model/NodeSpec.js';\nimport { createCollapsedSelection, isCollapsed, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { createBlockElement } from '../../view/DomUtils.js';\nimport type { PasteInterceptor, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../shared/ShortcutFormatting.js';\nimport type { CodeBlockLocale } from './CodeBlockLocale.js';\nimport { CODE_BLOCK_ICON } from './CodeBlockTypes.js';\n\nexport function registerCodeBlockNodeSpec(context: PluginContext): void {\n\tcontext.registerNodeSpec({\n\t\ttype: 'code_block',\n\t\tgroup: 'block',\n\t\tcontent: { allow: ['text'] },\n\t\tselectable: true,\n\t\tattrs: {\n\t\t\tlanguage: { default: '' },\n\t\t\tbackgroundColor: { default: '' },\n\t\t},\n\t\ttoDOM(node) {\n\t\t\tconst pre: HTMLElement = createBlockElement('pre', node.id);\n\t\t\tpre.className = 'notectl-code-block';\n\t\t\tpre.setAttribute('dir', 'ltr');\n\t\t\tpre.setAttribute('part', 'code-block');\n\t\t\tconst code: HTMLElement = document.createElement('code');\n\t\t\tcode.className = 'notectl-code-block__content';\n\t\t\tcode.setAttribute('part', 'code-block-content');\n\t\t\tpre.appendChild(code);\n\t\t\treturn pre;\n\t\t},\n\t\ttoHTML(node, content, ctx?: HTMLExportContext) {\n\t\t\tconst lang: string = escapeHTML((node.attrs?.language as string) ?? '');\n\t\t\tconst bg: string = escapeHTML((node.attrs?.backgroundColor as string) ?? '');\n\t\t\tconst langClass: string = lang ? ` class=\"language-${lang}\"` : '';\n\t\t\tconst bgAttr: string = bg\n\t\t\t\t? (ctx?.styleAttr(`background-color: ${bg}`) ?? ` style=\"background-color: ${bg}\"`)\n\t\t\t\t: '';\n\t\t\treturn `<pre dir=\"ltr\"${bgAttr}><code${langClass}>${content || ''}</code></pre>`;\n\t\t},\n\t\tparseHTML: [\n\t\t\t{\n\t\t\t\ttag: 'pre',\n\t\t\t\tgetAttrs(el: HTMLElement) {\n\t\t\t\t\tconst code: HTMLElement | null = el.querySelector('code');\n\t\t\t\t\tconst langClass: string = code?.className.match(/language-(\\S+)/)?.[1] ?? '';\n\t\t\t\t\tconst dataLang: string = code?.getAttribute('data-language') ?? '';\n\t\t\t\t\treturn {\n\t\t\t\t\t\tlanguage: dataLang || langClass,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: {\n\t\t\ttags: ['pre', 'code'],\n\t\t\tattrs: ['data-language', 'class', 'style'],\n\t\t},\n\t});\n}\n\nexport function registerCodeBlockInputRule(context: PluginContext): void {\n\tcontext.registerInputRule({\n\t\tpattern: /^```(\\w*) $/,\n\t\thandler: (state, match, start, _end) => {\n\t\t\tconst sel = state.selection;\n\t\t\tif (!isTextSelection(sel)) return null;\n\t\t\tif (!isCollapsed(sel)) return null;\n\n\t\t\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\t\t\tif (!block || block.type !== 'paragraph') return null;\n\n\t\t\tconst language: string = match[1] ?? '';\n\t\t\tconst attrs: Record<string, string | number | boolean> = {\n\t\t\t\tlanguage,\n\t\t\t\tbackgroundColor: '',\n\t\t\t};\n\n\t\t\treturn state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(sel.anchor.blockId, start, start + match[0].length)\n\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0))\n\t\t\t\t.build();\n\t\t},\n\t});\n}\n\nexport function registerCodeBlockToolbarItem(\n\tcontext: PluginContext,\n\tlocale: CodeBlockLocale,\n\ttoggleKey: string | null,\n): void {\n\tcontext.registerToolbarItem({\n\t\tid: 'code_block',\n\t\tgroup: 'block',\n\t\ticon: CODE_BLOCK_ICON,\n\t\tlabel: locale.label,\n\t\ttooltip: locale.tooltip(toggleKey ? formatShortcut(toggleKey) : undefined),\n\t\tcommand: 'toggleCodeBlock',\n\t\tisActive: (state) => {\n\t\t\tif (!isTextSelection(state.selection)) return false;\n\t\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\t\treturn block?.type === 'code_block';\n\t\t},\n\t});\n}\n\n/** Strips `addMark` steps targeting a code block so inline marks never apply there. */\nexport function registerCodeBlockMarkGuard(context: PluginContext): void {\n\tcontext.registerMiddleware(\n\t\t(tr, state, next) => {\n\t\t\tconst hasMarkInCodeBlock: boolean = tr.steps.some((step) => {\n\t\t\t\tif (step.type !== 'addMark') return false;\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\t\treturn block?.type === 'code_block';\n\t\t\t});\n\n\t\t\tif (!hasMarkInCodeBlock) {\n\t\t\t\tnext(tr);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst filtered = tr.steps.filter((step) => {\n\t\t\t\tif (step.type !== 'addMark') return true;\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\t\treturn block?.type !== 'code_block';\n\t\t\t});\n\n\t\t\tnext({ ...tr, steps: filtered });\n\t\t},\n\t\t{ name: 'code-block:mark-guard', priority: 50 },\n\t);\n}\n\nexport function registerCodeBlockPasteInterceptor(context: PluginContext): void {\n\tconst handleCodeBlockPaste: PasteInterceptor = (\n\t\tplainText: string,\n\t\t_html: string,\n\t\tstate: EditorState,\n\t): Transaction | null => {\n\t\tif (!plainText) return null;\n\t\tif (!isTextSelection(state.selection)) return null;\n\n\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\tif (!block || block.type !== 'code_block') return null;\n\n\t\tconst builder = state.transaction('paste');\n\n\t\tlet insertBlockId: BlockId = state.selection.anchor.blockId;\n\t\tlet insertOffset: number = state.selection.anchor.offset;\n\n\t\tif (!isCollapsed(state.selection)) {\n\t\t\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\t\t\tif (landingId) {\n\t\t\t\tinsertBlockId = landingId;\n\t\t\t\tinsertOffset = 0;\n\t\t\t}\n\t\t}\n\n\t\tbuilder.insertText(insertBlockId, insertOffset, plainText, []);\n\t\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + plainText.length));\n\n\t\treturn builder.build();\n\t};\n\n\tcontext.registerPasteInterceptor(handleCodeBlockPaste, {\n\t\tname: 'code-block:paste',\n\t\tpriority: 10,\n\t});\n}\n\n/** Extends `table_cell` content to allow nested code blocks, if not already allowed. */\nexport function patchTableCellContent(context: PluginContext): void {\n\tconst registry = context.getSchemaRegistry();\n\tconst cellSpec = registry.getNodeSpec('table_cell');\n\tif (!cellSpec?.content) return;\n\n\tconst currentAllow: readonly string[] = cellSpec.content.allow ?? [];\n\tif (currentAllow.includes('code_block')) return;\n\n\tregistry.removeNodeSpec('table_cell');\n\tregistry.registerNodeSpec({\n\t\t...cellSpec,\n\t\tcontent: {\n\t\t\t...cellSpec.content,\n\t\t\tallow: [...currentAllow, 'code_block'],\n\t\t},\n\t});\n}\n","/**\n * Service API for code blocks.\n * Provides language/background getters and setters.\n */\n\nimport type { BlockAttrs, BlockNode } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport type { SyntaxHighlighter } from './CodeBlockTypes.js';\nimport { CODE_BLOCK_SERVICE_KEY } from './CodeBlockTypes.js';\n\n/** Registers the CodeBlockService on the given context. */\nexport function registerCodeBlockService(\n\tcontext: PluginContext,\n\tgetHighlighter: () => SyntaxHighlighter | null,\n\tgetContext: () => PluginContext | null,\n): void {\n\tcontext.registerService(CODE_BLOCK_SERVICE_KEY, {\n\t\tsetLanguage(bid: BlockId, language: string): void {\n\t\t\tsetAttr(context, bid, 'language', language);\n\t\t},\n\n\t\tgetLanguage(bid: BlockId): string {\n\t\t\tconst ctx: PluginContext | null = getContext();\n\t\t\tif (!ctx) return '';\n\t\t\tconst block: BlockNode | undefined = ctx.getState().getBlock(bid);\n\t\t\tif (!block || block.type !== 'code_block') return '';\n\t\t\treturn (block.attrs?.language as string) ?? '';\n\t\t},\n\n\t\tsetBackground(bid: BlockId, color: string): void {\n\t\t\tsetAttr(context, bid, 'backgroundColor', color);\n\t\t},\n\n\t\tgetBackground(bid: BlockId): string {\n\t\t\tconst ctx: PluginContext | null = getContext();\n\t\t\tif (!ctx) return '';\n\t\t\tconst block: BlockNode | undefined = ctx.getState().getBlock(bid);\n\t\t\tif (!block || block.type !== 'code_block') return '';\n\t\t\treturn (block.attrs?.backgroundColor as string) ?? '';\n\t\t},\n\n\t\tisCodeBlock(bid: BlockId): boolean {\n\t\t\tconst ctx: PluginContext | null = getContext();\n\t\t\tif (!ctx) return false;\n\t\t\tconst block: BlockNode | undefined = ctx.getState().getBlock(bid);\n\t\t\treturn block?.type === 'code_block';\n\t\t},\n\n\t\tgetSupportedLanguages(): readonly string[] {\n\t\t\tconst highlighter: SyntaxHighlighter | null = getHighlighter();\n\t\t\tif (!highlighter) return [];\n\t\t\treturn highlighter.getSupportedLanguages();\n\t\t},\n\t});\n}\n\n// --- Helper ---\n\nfunction setAttr(context: PluginContext, bid: BlockId, key: string, value: string): void {\n\tconst state = context.getState();\n\tconst block: BlockNode | undefined = state.getBlock(bid);\n\tif (!block || block.type !== 'code_block') return;\n\n\tconst path: BlockId[] | undefined = state.getNodePath(bid);\n\tif (!path) return;\n\n\tconst newAttrs: BlockAttrs = { ...block.attrs, [key]: value };\n\tconst tr: Transaction = state.transaction('command').setNodeAttr(path, newAttrs).build();\n\n\tcontext.dispatch(tr);\n}\n","/**\n * Per-block syntax-token cache for the code-block plugin.\n *\n * Holds the tokens produced by the active {@link SyntaxHighlighter} keyed by\n * block id, re-tokenizing only when a block's text or language changes. Lookups\n * use binary search over the cached, range-ordered token list and never trigger\n * a fresh tokenize.\n */\n\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { SyntaxHighlighter, SyntaxToken } from './CodeBlockTypes.js';\n\ninterface CacheEntry {\n\treadonly text: string;\n\treadonly language: string;\n\treadonly tokens: readonly SyntaxToken[];\n}\n\nexport class TokenCache {\n\tprivate readonly entries = new Map<BlockId, CacheEntry>();\n\n\t/**\n\t * Returns the cached tokens for `blockId`, re-tokenizing via `highlighter`\n\t * when the block's text or language has changed since the last call.\n\t * Returns an empty list when no highlighter is available.\n\t */\n\tgetTokens(\n\t\tblockId: BlockId,\n\t\ttext: string,\n\t\tlanguage: string,\n\t\thighlighter: SyntaxHighlighter | null,\n\t): readonly SyntaxToken[] {\n\t\tconst cached: CacheEntry | undefined = this.entries.get(blockId);\n\t\tif (cached && cached.text === text && cached.language === language) {\n\t\t\treturn cached.tokens;\n\t\t}\n\t\tconst tokens: readonly SyntaxToken[] = highlighter?.tokenize(text, language) ?? [];\n\t\tthis.entries.set(blockId, { text, language, tokens });\n\t\treturn tokens;\n\t}\n\n\t/**\n\t * Binary-searches the cached token list for the token whose range covers\n\t * `offset`. Returns `undefined` on cache miss or if the offset lies in a gap\n\t * between tokens.\n\t */\n\tfindTokenAt(blockId: BlockId, offset: number): SyntaxToken | undefined {\n\t\tconst cached: CacheEntry | undefined = this.entries.get(blockId);\n\t\tif (!cached) return undefined;\n\t\tconst tokens: readonly SyntaxToken[] = cached.tokens;\n\t\tlet low = 0;\n\t\tlet high = tokens.length - 1;\n\t\twhile (low <= high) {\n\t\t\tconst mid: number = (low + high) >>> 1;\n\t\t\tconst token: SyntaxToken | undefined = tokens[mid];\n\t\t\tif (!token) return undefined;\n\t\t\tif (offset < token.from) {\n\t\t\t\thigh = mid - 1;\n\t\t\t} else if (offset >= token.to) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\treturn token;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Drops cache entries whose block id is not in `activeIds`. */\n\tretain(activeIds: ReadonlySet<BlockId>): void {\n\t\tfor (const cachedId of this.entries.keys()) {\n\t\t\tif (!activeIds.has(cachedId)) {\n\t\t\t\tthis.entries.delete(cachedId);\n\t\t\t}\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.entries.clear();\n\t}\n}\n","/**\n * CodeBlockPlugin: orchestrates code-block registration by composing focused\n * collaborators — {@link TokenCache} (syntax-token caching), {@link AutoPairController}\n * (bracket/quote pairing), the highlighting setup, the decoration builder, and\n * the static schema/keyboard/command/service registrars.\n *\n * The plugin itself only wires these together and forwards the lifecycle hooks\n * (`decorations`, `onStateChange`, `destroy`).\n */\n\nimport type { DecorationSet } from '../../decorations/Decoration.js';\nimport { CODE_BLOCK_CSS } from '../../editor/styles/code-block.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { resolveLocale } from '../shared/PluginHelpers.js';\nimport { PopupManager } from '../shared/PopupManager.js';\nimport { AutoPairController } from './AutoPairController.js';\nimport { registerCodeBlockCommands } from './CodeBlockCommands.js';\nimport { createCodeBlockDecorations } from './CodeBlockDecorations.js';\nimport { setupHighlighting } from './CodeBlockHighlighting.js';\nimport { registerCodeBlockKeymaps } from './CodeBlockKeyboardHandlers.js';\nimport {\n\tCODE_BLOCK_LOCALE_EN,\n\ttype CodeBlockLocale,\n\tloadCodeBlockLocale,\n} from './CodeBlockLocale.js';\nimport { type LanguagePickerDeps, createCodeBlockNodeViewFactory } from './CodeBlockNodeView.js';\nimport {\n\tpatchTableCellContent,\n\tregisterCodeBlockInputRule,\n\tregisterCodeBlockMarkGuard,\n\tregisterCodeBlockNodeSpec,\n\tregisterCodeBlockPasteInterceptor,\n\tregisterCodeBlockToolbarItem,\n} from './CodeBlockSchema.js';\nimport { registerCodeBlockService } from './CodeBlockService.js';\nimport type {\n\tCodeBlockConfig,\n\tCodeBlockKeymap,\n\tResolvedIndentConfig,\n\tResolvedPairingConfig,\n\tSyntaxHighlighter,\n} from './CodeBlockTypes.js';\nimport {\n\tDEFAULT_CONFIG,\n\tDEFAULT_INDENT,\n\tDEFAULT_KEYMAP,\n\tDEFAULT_PAIRING,\n\tMAX_SPACE_COUNT,\n\tMIN_SPACE_COUNT,\n} from './CodeBlockTypes.js';\nimport { TokenCache } from './TokenCache.js';\n\nexport class CodeBlockPlugin implements Plugin {\n\treadonly id = 'code-block';\n\treadonly name = 'Code Block';\n\treadonly priority = 36;\n\n\tprivate readonly config: CodeBlockConfig;\n\tprivate readonly resolvedIndent: ResolvedIndentConfig;\n\tprivate readonly resolvedPairing: ResolvedPairingConfig;\n\tprivate readonly resolvedKeymap: Readonly<Record<keyof CodeBlockKeymap, string | null>>;\n\tprivate context: PluginContext | null = null;\n\tprivate locale!: CodeBlockLocale;\n\tprivate highlighter: SyntaxHighlighter | null = null;\n\tprivate readonly tokenCache = new TokenCache();\n\tprivate readonly autoPair: AutoPairController;\n\n\tconstructor(config?: Partial<CodeBlockConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t\tthis.resolvedIndent = resolveIndentConfig(this.config);\n\t\tthis.resolvedPairing = resolvePairingConfig(this.config);\n\t\tthis.resolvedKeymap = {\n\t\t\t...DEFAULT_KEYMAP,\n\t\t\t...config?.keymap,\n\t\t};\n\t\tthis.autoPair = new AutoPairController({\n\t\t\tresolvedIndent: this.resolvedIndent,\n\t\t\tresolvedPairing: this.resolvedPairing,\n\t\t\tgetTokenAt: (blockId, offset) => this.tokenCache.findTokenAt(blockId, offset),\n\t\t\tgetCompositionState: () => this.context?.getCompositionState() ?? null,\n\t\t});\n\t}\n\n\tasync init(context: PluginContext): Promise<void> {\n\t\tthis.locale = await resolveLocale(\n\t\t\tcontext,\n\t\t\tthis.config.locale,\n\t\t\tCODE_BLOCK_LOCALE_EN,\n\t\t\tloadCodeBlockLocale,\n\t\t);\n\t\tcontext.registerStyleSheet(CODE_BLOCK_CSS);\n\t\tthis.context = context;\n\n\t\tthis.highlighter = setupHighlighting(context, this.config, this.tokenCache);\n\t\tregisterCodeBlockNodeSpec(context);\n\t\tthis.registerNodeView(context);\n\t\tregisterCodeBlockCommands(context, this.config);\n\t\tregisterCodeBlockKeymaps(context, this.config, this.resolvedKeymap, {\n\t\t\tindent: this.resolvedIndent,\n\t\t\tpairing: this.resolvedPairing,\n\t\t\tpairStack: this.autoPair.pairStack,\n\t\t\tlocale: () => this.locale,\n\t\t});\n\t\tregisterCodeBlockInputRule(context);\n\t\tregisterCodeBlockToolbarItem(context, this.locale, this.resolvedKeymap.toggle);\n\t\tregisterCodeBlockMarkGuard(context);\n\t\tregisterCodeBlockService(\n\t\t\tcontext,\n\t\t\t() => this.highlighter,\n\t\t\t() => this.context,\n\t\t);\n\t\tregisterCodeBlockPasteInterceptor(context);\n\t\tcontext.registerTextInputInterceptor(this.autoPair.handleTextInput, {\n\t\t\tname: 'code-block:auto-pair',\n\t\t\tpriority: 10,\n\t\t});\n\t\tpatchTableCellContent(context);\n\t}\n\n\tdestroy(): void {\n\t\tthis.context = null;\n\t\tthis.highlighter = null;\n\t\tthis.tokenCache.clear();\n\t\tthis.autoPair.clear();\n\t}\n\n\tonStateChange(oldState: EditorState, newState: EditorState, tr: Transaction): void {\n\t\tthis.autoPair.syncOnStateChange(newState, tr);\n\n\t\tif (!this.context) return;\n\n\t\tconst oldBlockId: BlockId | null = !isTextSelection(oldState.selection)\n\t\t\t? null\n\t\t\t: oldState.selection.anchor.blockId;\n\t\tconst newBlockId: BlockId | null = !isTextSelection(newState.selection)\n\t\t\t? null\n\t\t\t: newState.selection.anchor.blockId;\n\n\t\tconst oldBlock: BlockNode | undefined = oldBlockId ? oldState.getBlock(oldBlockId) : undefined;\n\t\tconst newBlock: BlockNode | undefined = newBlockId ? newState.getBlock(newBlockId) : undefined;\n\n\t\tconst wasInCode: boolean = oldBlock?.type === 'code_block';\n\t\tconst nowInCode: boolean = newBlock?.type === 'code_block';\n\n\t\tif (!wasInCode && nowInCode) {\n\t\t\tthis.context.announce(this.locale.enteredCodeBlock);\n\t\t} else if (wasInCode && !nowInCode) {\n\t\t\tthis.context.announce(this.locale.leftCodeBlock);\n\t\t}\n\t}\n\n\tdecorations(state: EditorState): DecorationSet {\n\t\treturn createCodeBlockDecorations(state, {\n\t\t\thighlighter: this.highlighter,\n\t\t\ttokenCache: this.tokenCache,\n\t\t});\n\t}\n\n\tprivate registerNodeView(context: PluginContext): void {\n\t\tconst popupManager: PopupManager = new PopupManager(context.getContainer());\n\t\tconst highlighter = this.highlighter;\n\t\tconst pickerDeps: LanguagePickerDeps = {\n\t\t\tpopupManager,\n\t\t\tgetSupportedLanguages: () => highlighter?.getSupportedLanguages() ?? [],\n\t\t};\n\n\t\tcontext.registerNodeView(\n\t\t\t'code_block',\n\t\t\tcreateCodeBlockNodeViewFactory(this.config, this.locale, pickerDeps),\n\t\t);\n\t}\n}\n\n/**\n * Merges `indent.*` overrides with deprecated top-level `useSpaces`/`spaceCount`\n * fallbacks, and clamps `spaceCount` once into [MIN_SPACE_COUNT, MAX_SPACE_COUNT].\n */\nfunction resolveIndentConfig(config: CodeBlockConfig): ResolvedIndentConfig {\n\tconst useSpaces: boolean =\n\t\tconfig.indent?.useSpaces ?? config.useSpaces ?? DEFAULT_INDENT.useSpaces;\n\tconst rawSpaceCount: number =\n\t\tconfig.indent?.spaceCount ?? config.spaceCount ?? DEFAULT_INDENT.spaceCount;\n\tconst spaceCount: number = Math.max(\n\t\tMIN_SPACE_COUNT,\n\t\tMath.min(MAX_SPACE_COUNT, Math.trunc(rawSpaceCount)),\n\t);\n\tconst mode: 'none' | 'keep' | 'brackets' = config.indent?.mode ?? DEFAULT_INDENT.mode;\n\treturn { mode, useSpaces, spaceCount };\n}\n\nfunction resolvePairingConfig(config: CodeBlockConfig): ResolvedPairingConfig {\n\tconst p = config.pairing;\n\treturn {\n\t\tbrackets: p?.brackets ?? DEFAULT_PAIRING.brackets,\n\t\tquot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,gBAAiB,EAAY,IAC9C,EAAW,IACJ,GAGR,UAAA,GACC,EAAI,UAAU,IAAI,+BACnB,EAEA,YAAA,GACC,EAAI,UAAU,OAAO,+BACtB,EAEA,OAAA,GAEA,GAGH,CIzHG,CAA+B,KAAK,OAAQ,KAAK,OAAQ,GAE3D"}
|
|
1
|
+
{"version":3,"file":"CodeBlockPlugin-DC0-BnNy.mjs","names":[],"sources":["../../src/editor/styles/code-block.ts","../../src/plugins/code-block/BracketPairing.ts","../../src/plugins/code-block/IndentHelpers.ts","../../src/plugins/code-block/PairStack.ts","../../src/plugins/code-block/AutoPairController.ts","../../src/plugins/code-block/CodeBlockKeyboardHandlers.ts","../../src/plugins/code-block/CodeBlockCommands.ts","../../src/plugins/code-block/CodeBlockDecorations.ts","../../src/plugins/language/LanguageRegistry.ts","../../src/plugins/code-block/CodeBlockTypes.ts","../../src/plugins/code-block/highlighter/RegexTokenizer.ts","../../src/plugins/code-block/CodeBlockHighlighting.ts","../../src/plugins/code-block/CodeBlockLocale.ts","../../src/plugins/code-block/LanguagePicker.ts","../../src/plugins/code-block/CodeBlockNodeView.ts","../../src/plugins/code-block/CodeBlockSchema.ts","../../src/plugins/code-block/CodeBlockService.ts","../../src/plugins/code-block/TokenCache.ts","../../src/plugins/code-block/CodeBlockPlugin.ts"],"sourcesContent":["import { SYNTAX_TOKEN_TYPES } from '../theme/SyntaxTokenTypes.js';\n\n/** Generates per-token CSS rules from the canonical token type list. */\nfunction generateTokenCSS(): string {\n\treturn SYNTAX_TOKEN_TYPES.map(\n\t\t(type) =>\n\t\t\t`.notectl-token--${type} {\\n\\tcolor: var(--notectl-code-token-${type});\\n\\tfont-style: var(--notectl-code-token-${type}-font-style, inherit);\\n\\tfont-weight: var(--notectl-code-token-${type}-font-weight, inherit);\\n}`,\n\t).join('\\n');\n}\n\n/** Code block styles — syntax highlighting container, header, copy button. */\nexport const CODE_BLOCK_CSS = `\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language-btn {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tgap: 4px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 2px 6px;\n\tfont-size: inherit;\n\tfont-family: inherit;\n\ttransition: background 0.15s;\n}\n\n.notectl-code-block__language-btn:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-code-block__language-btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__chevron {\n\tdisplay: inline-flex;\n\talign-items: center;\n\topacity: 0.6;\n}\n\n.notectl-code-block__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Language picker popup */\n.notectl-language-picker {\n\tmin-width: 120px;\n\tmax-height: 200px;\n\toverflow-y: auto;\n\tpadding: 4px;\n\tbackground: var(--notectl-surface-raised, #fff);\n\tborder: 1px solid var(--notectl-border, #e0e0e0);\n\tborder-radius: 6px;\n\tbox-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);\n}\n\n.notectl-language-picker__option {\n\tpadding: 6px 10px;\n\tborder-radius: 4px;\n\tcursor: pointer;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg, #333);\n\twhite-space: nowrap;\n}\n\n.notectl-language-picker__option:hover {\n\tbackground: rgba(128, 128, 128, 0.1);\n}\n\n.notectl-language-picker__option:focus {\n\toutline: none;\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-language-picker__option[aria-selected=\"true\"] {\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary, #2563eb);\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${generateTokenCSS()}\n`;\n","/**\n * BracketPairing: resolves the action that should be taken when the user\n * types a printable character that could trigger auto-pairing, overtype,\n * surround, or quote suppression inside a code block.\n *\n * The resolver is a pure function — it consumes the current state, the\n * incoming char, a token lookup and the auto-pair stack, and returns a\n * typed action that the keyboard / interceptor layer applies. No DOM, no\n * dispatch.\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport {\n\ttype Selection,\n\tisCollapsed,\n\tisTextSelection,\n\tselectionRange,\n} from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { ResolvedPairingConfig, SyntaxToken } from './CodeBlockTypes.js';\nimport type { PairStack } from './PairStack.js';\n\n// --- Pair definitions ---\n\nexport interface PairDefinition {\n\treadonly open: string;\n\treadonly close: string;\n\treadonly kind: 'bracket' | 'quote';\n}\n\nexport const PAIR_DEFINITIONS: readonly PairDefinition[] = [\n\t{ open: '(', close: ')', kind: 'bracket' },\n\t{ open: '[', close: ']', kind: 'bracket' },\n\t{ open: '{', close: '}', kind: 'bracket' },\n\t{ open: '\"', close: '\"', kind: 'quote' },\n\t{ open: \"'\", close: \"'\", kind: 'quote' },\n\t{ open: '`', close: '`', kind: 'quote' },\n];\n\nconst OPEN_TO_PAIR: ReadonlyMap<string, PairDefinition> = new Map(\n\tPAIR_DEFINITIONS.map((d) => [d.open, d]),\n);\nconst CLOSE_TO_PAIR: ReadonlyMap<string, PairDefinition> = new Map(\n\t// For brackets close !== open, for quotes close === open\n\tPAIR_DEFINITIONS.filter((d) => d.kind === 'bracket').map((d) => [d.close, d]),\n);\n\n// --- Action variants ---\n\nexport type PairAction =\n\t| { readonly kind: 'pair'; readonly close: string }\n\t| { readonly kind: 'overtype' }\n\t| { readonly kind: 'wrap'; readonly open: string; readonly close: string }\n\t| { readonly kind: 'passthrough' };\n\n// --- Lookups injected by the caller ---\n\nexport type TokenLookup = (blockId: BlockId, offset: number) => SyntaxToken | undefined;\n\n// --- Resolver ---\n\nexport interface ResolvePairContext {\n\treadonly state: EditorState;\n\treadonly block: BlockNode;\n\treadonly blockId: BlockId;\n\treadonly char: string;\n\treadonly config: ResolvedPairingConfig;\n\treadonly pairStack: PairStack;\n\treadonly getTokenAt: TokenLookup;\n}\n\n/**\n * Decides what to do when the user types `char` inside a code block.\n * Returns a `PairAction` describing the next step.\n */\nexport function resolvePairAction(ctx: ResolvePairContext): PairAction {\n\tconst { state, char, config } = ctx;\n\tif (!isTextSelection(state.selection)) return { kind: 'passthrough' };\n\n\tconst sel = state.selection;\n\tconst definition: PairDefinition | undefined = OPEN_TO_PAIR.get(char);\n\n\t// Wrap takes precedence over suppression when there is a range selection.\n\tif (definition && !isCollapsed(sel) && surroundEnabled(definition, config)) {\n\t\tconst wrap = tryWrapAction(definition, sel, ctx);\n\t\tif (wrap) return wrap;\n\t}\n\n\tif (!isCollapsed(sel)) return { kind: 'passthrough' };\n\n\t// Overtype: user typed a close char that matches the next char and was\n\t// auto-inserted by us.\n\tif (config.overtype && shouldOvertype(ctx, char)) {\n\t\treturn { kind: 'overtype' };\n\t}\n\n\tif (!definition) return { kind: 'passthrough' };\n\n\t// Suppression checks for collapsed-cursor auto-pair.\n\tif (!pairingAllowed(definition, ctx)) return { kind: 'passthrough' };\n\n\treturn { kind: 'pair', close: definition.close };\n}\n\nfunction tryWrapAction(\n\tdef: PairDefinition,\n\tsel: Selection,\n\tctx: ResolvePairContext,\n): PairAction | null {\n\tconst { state } = ctx;\n\tconst order = state.getBlockOrder();\n\tconst range = selectionRange(sel, order);\n\tif (range.from.blockId !== range.to.blockId) return null;\n\tif (range.from.blockId !== ctx.blockId) return null;\n\treturn { kind: 'wrap', open: def.open, close: def.close };\n}\n\nfunction shouldOvertype(ctx: ResolvePairContext, char: string): boolean {\n\tconst closeDef: PairDefinition | undefined = closeDefinitionFor(char);\n\tif (!closeDef) return false;\n\n\tconst sel = ctx.state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tconst text: string = getBlockText(ctx.block);\n\tconst offset: number = sel.anchor.offset;\n\tif (text[offset] !== char) return false;\n\n\t// Only overtype if this exact close char was recorded by an auto-pair.\n\tconst entry = ctx.pairStack.peek(ctx.blockId, offset);\n\treturn Boolean(entry && entry.char === char);\n}\n\n/**\n * Returns the pair definition where `char` is a close char. Quotes are\n * symmetric, so `OPEN_TO_PAIR` is checked first for them.\n */\nfunction closeDefinitionFor(char: string): PairDefinition | undefined {\n\tconst symmetric = OPEN_TO_PAIR.get(char);\n\tif (symmetric?.kind === 'quote') return symmetric;\n\treturn CLOSE_TO_PAIR.get(char);\n}\n\nfunction surroundEnabled(def: PairDefinition, config: ResolvedPairingConfig): boolean {\n\tswitch (config.surround) {\n\t\tcase 'never':\n\t\t\treturn false;\n\t\tcase 'brackets':\n\t\t\treturn def.kind === 'bracket';\n\t\tcase 'quotes':\n\t\t\treturn def.kind === 'quote';\n\t\tcase 'languageDefined':\n\t\t\treturn true;\n\t}\n}\n\nfunction pairingAllowed(def: PairDefinition, ctx: ResolvePairContext): boolean {\n\tconst mode: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never' =\n\t\tdef.kind === 'quote' ? ctx.config.quotes : ctx.config.brackets;\n\tif (mode === 'never') return false;\n\n\tconst sel = ctx.state.selection;\n\tif (!isTextSelection(sel)) return true;\n\tconst text: string = getBlockText(ctx.block);\n\tconst offset: number = sel.anchor.offset;\n\n\tif (def.kind === 'quote' && def.open === \"'\" && isApostropheContext(text, offset)) {\n\t\treturn false;\n\t}\n\n\tif (mode === 'always') return true;\n\tif (mode === 'beforeWhitespace') {\n\t\treturn isFollowingCharCompatibleForPair(text, offset);\n\t}\n\t// languageDefined\n\tif (def.kind === 'quote') {\n\t\tconst token = ctx.getTokenAt(ctx.blockId, offset);\n\t\tif (!token) {\n\t\t\t// Cache miss: fall back to always-allow (safe default).\n\t\t\treturn true;\n\t\t}\n\t\tif (token.type === 'string' || token.type === 'comment') return false;\n\t\treturn true;\n\t}\n\t// Brackets always pair under languageDefined\n\treturn true;\n}\n\n/**\n * VS-Code-style apostrophe suppression: `'` directly after a word char\n * `[A-Za-z0-9_]` is *not* paired (so `don't`, `it's` work).\n */\nfunction isApostropheContext(text: string, offset: number): boolean {\n\tif (offset <= 0) return false;\n\tconst prev = text[offset - 1];\n\tif (!prev) return false;\n\treturn /[A-Za-z0-9_]/.test(prev);\n}\n\nfunction isFollowingCharCompatibleForPair(text: string, offset: number): boolean {\n\tif (offset >= text.length) return true;\n\tconst next = text[offset];\n\tif (!next) return true;\n\tif (/\\s/.test(next)) return true;\n\tif (CLOSE_TO_PAIR.has(next)) return true;\n\treturn false;\n}\n\n/**\n * Wrap-selection helper: given the open/close chars and a selection, returns\n * the offsets where the chars should be inserted in document order.\n */\nexport interface WrapPlan {\n\treadonly fromOffset: number;\n\treadonly toOffset: number;\n}\n\nexport function wrapSelectionPlan(sel: Selection, blockOrder: readonly BlockId[]): WrapPlan {\n\tconst range = selectionRange(sel, blockOrder);\n\treturn { fromOffset: range.from.offset, toOffset: range.to.offset };\n}\n","/**\n * Pure helpers for indent and bracket analysis inside code blocks.\n *\n * All helpers operate on the raw block text plus an offset; no editor state,\n * no transactions. This keeps them trivially testable and reusable from\n * keyboard handlers and the text-input interceptor alike.\n */\n\nexport interface ResolvedIndent {\n\t/** Active indent unit ('\\t' or N spaces). */\n\treadonly unit: string;\n\t/** Whether spaces are used (mirrors config). */\n\treadonly useSpaces: boolean;\n\t/** Effective indent width in characters. */\n\treadonly width: number;\n}\n\nconst OPEN_BRACKETS = new Set(['{', '[', '(']);\nconst CLOSE_BRACKETS_TO_OPEN: Readonly<Record<string, string>> = {\n\t'}': '{',\n\t']': '[',\n\t')': '(',\n};\n\n/** Returns the inclusive line range `[start, end)` covering `offset`. */\nexport function getLineRange(text: string, offset: number): { start: number; end: number } {\n\tconst start: number = text.lastIndexOf('\\n', offset - 1) + 1;\n\tconst nlIndex: number = text.indexOf('\\n', offset);\n\tconst end: number = nlIndex === -1 ? text.length : nlIndex;\n\treturn { start, end };\n}\n\n/** Returns the leading whitespace (tabs/spaces only) of the line covering `offset`. */\nexport function getCurrentLineIndent(text: string, offset: number): string {\n\tconst { start, end } = getLineRange(text, offset);\n\tlet i: number = start;\n\twhile (i < end) {\n\t\tconst ch = text[i];\n\t\tif (ch !== ' ' && ch !== '\\t') break;\n\t\ti++;\n\t}\n\treturn text.slice(start, i);\n}\n\n/**\n * Returns the last non-whitespace character of `text` in the range\n * `[lineStart, cursorOffset)`, or `''` if the entire prefix is whitespace.\n * The cursor itself is excluded.\n */\nexport function lastNonWhitespaceCharBeforeCursor(text: string, cursorOffset: number): string {\n\tconst { start } = getLineRange(text, cursorOffset);\n\tfor (let i = cursorOffset - 1; i >= start; i--) {\n\t\tconst ch = text[i];\n\t\tif (ch && ch !== ' ' && ch !== '\\t') return ch;\n\t}\n\treturn '';\n}\n\n/** True if the prefix `[lineStart, cursorOffset)` contains only whitespace. */\nexport function isWhitespaceOnlyBeforeOffset(text: string, cursorOffset: number): boolean {\n\tconst { start } = getLineRange(text, cursorOffset);\n\tfor (let i = start; i < cursorOffset; i++) {\n\t\tconst ch = text[i];\n\t\tif (ch !== ' ' && ch !== '\\t') return false;\n\t}\n\treturn true;\n}\n\n/**\n * True if the prefix up to `cursorOffset` ends with an open bracket\n * (`{`, `[`, `(`) — ignoring trailing whitespace.\n */\nexport function endsWithOpenBracket(text: string, cursorOffset: number): boolean {\n\tconst last: string = lastNonWhitespaceCharBeforeCursor(text, cursorOffset);\n\treturn OPEN_BRACKETS.has(last);\n}\n\n/**\n * True if the user just typed Enter between a matching open/close pair\n * (e.g. `{|}`, `[|]`, `(|)`). Checks the next char at cursor against the\n * char before the cursor; only matches direct pairs without intervening\n * whitespace.\n */\nexport function isBetweenBracketPair(text: string, cursorOffset: number): boolean {\n\tif (cursorOffset <= 0 || cursorOffset >= text.length) return false;\n\tconst before = text[cursorOffset - 1];\n\tconst after = text[cursorOffset];\n\tif (!before || !after) return false;\n\tconst expectedOpen: string | undefined = CLOSE_BRACKETS_TO_OPEN[after];\n\treturn expectedOpen === before;\n}\n\n/**\n * Returns the unit string for the resolved indent config.\n * `'\\t'` for tabs, `' '.repeat(spaceCount)` for spaces.\n */\nexport function resolveIndentUnit(useSpaces: boolean, spaceCount: number): string {\n\treturn useSpaces ? ' '.repeat(spaceCount) : '\\t';\n}\n\n/**\n * Removes exactly one indent unit from the start of `line`. If `line`\n * does not start with a full unit, removes whatever leading whitespace\n * exists up to the unit length (so a partially-indented line still loses\n * its leading whitespace). Returns `{ removed, rest }`.\n */\nexport function dedentOnce(\n\tline: string,\n\tuseSpaces: boolean,\n\tspaceCount: number,\n): { removed: string; rest: string } {\n\tif (line.length === 0) return { removed: '', rest: line };\n\tif (!useSpaces) {\n\t\tif (line[0] === '\\t') return { removed: '\\t', rest: line.slice(1) };\n\t\t// fall through: try removing up to `spaceCount` leading spaces\n\t}\n\tlet i = 0;\n\twhile (i < spaceCount && line[i] === ' ') i++;\n\treturn { removed: line.slice(0, i), rest: line.slice(i) };\n}\n\n/**\n * Returns the indentation that should be inserted *after* the newline when\n * the user presses Enter on the line covering `cursorOffset`. Combines the\n * line's existing leading whitespace with an extra indent step if the\n * prefix ends with an open bracket and `mode === 'brackets'`.\n */\nexport function nextIndentLevel(\n\ttext: string,\n\tcursorOffset: number,\n\tmode: 'none' | 'keep' | 'brackets',\n\tunit: string,\n): string {\n\tif (mode === 'none') return '';\n\tconst base: string = getCurrentLineIndent(text, cursorOffset);\n\tif (mode === 'keep') return base;\n\tif (endsWithOpenBracket(text, cursorOffset)) return base + unit;\n\treturn base;\n}\n\n/**\n * True if the prefix triggers the 3-line block-pattern: `{|}` (or `[|]`,\n * `(|)`) where cursor is exactly between an open/close pair. Used by the\n * Enter handler to expand the cursor onto its own indented line.\n */\nexport function shouldOpenIndentBlock(text: string, cursorOffset: number): boolean {\n\treturn isBetweenBracketPair(text, cursorOffset);\n}\n","/**\n * Auto-pair tracking stack: records the position of each auto-inserted\n * close character so that overtype (Bracket-Skip) and pair-delete only\n * fire on chars *we* produced — never on chars the user typed themselves.\n *\n * Positions are migrated through `Transaction.mapping` after every state\n * change. The single non-trivial choice is the association bias for\n * `mapResult`: we use `+1` (\"sticky right\") so an insert *at* the close\n * char's position lands left of the close char, matching the user\n * intuition \"I'm typing before this auto-paired `)`\".\n */\n\nimport type { Position } from '../../model/Selection.js';\nimport { createPosition } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { Mapping } from '../../state/Mapping.js';\n\nexport interface PairEntry {\n\treadonly pos: Position;\n\treadonly char: string;\n}\n\n/** Per-block stack of auto-pair entries. */\nexport class PairStack {\n\tprivate readonly buckets = new Map<BlockId, PairEntry[]>();\n\n\t/** Records a new auto-inserted close char at `pos`. */\n\tpush(pos: Position, char: string): void {\n\t\tconst bucket: PairEntry[] = this.buckets.get(pos.blockId) ?? [];\n\t\tbucket.push({ pos, char });\n\t\tthis.buckets.set(pos.blockId, bucket);\n\t}\n\n\t/**\n\t * Finds (and removes) an entry whose position matches `blockId`/`offset`\n\t * exactly. Returns the entry or `undefined` if no match.\n\t */\n\ttake(blockId: BlockId, offset: number): PairEntry | undefined {\n\t\tconst bucket: PairEntry[] | undefined = this.buckets.get(blockId);\n\t\tif (!bucket) return undefined;\n\t\tfor (let i = bucket.length - 1; i >= 0; i--) {\n\t\t\tconst entry: PairEntry | undefined = bucket[i];\n\t\t\tif (entry && entry.pos.offset === offset) {\n\t\t\t\tbucket.splice(i, 1);\n\t\t\t\tif (bucket.length === 0) this.buckets.delete(blockId);\n\t\t\t\treturn entry;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Returns (without removing) an entry whose position matches. */\n\tpeek(blockId: BlockId, offset: number): PairEntry | undefined {\n\t\tconst bucket: PairEntry[] | undefined = this.buckets.get(blockId);\n\t\tif (!bucket) return undefined;\n\t\tfor (let i = bucket.length - 1; i >= 0; i--) {\n\t\t\tconst entry: PairEntry | undefined = bucket[i];\n\t\t\tif (entry && entry.pos.offset === offset) return entry;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Clears all entries for the given block (used on code_block → paragraph). */\n\tclearBlock(blockId: BlockId): void {\n\t\tthis.buckets.delete(blockId);\n\t}\n\n\t/** Drops every recorded entry — used on plugin destroy/HMR. */\n\tclear(): void {\n\t\tthis.buckets.clear();\n\t}\n\n\t/** Number of recorded entries for a block; primarily for diagnostics/tests. */\n\tsizeForBlock(blockId: BlockId): number {\n\t\treturn this.buckets.get(blockId)?.length ?? 0;\n\t}\n\n\t/** Aggregate size across all blocks. */\n\tget size(): number {\n\t\tlet total = 0;\n\t\tfor (const bucket of this.buckets.values()) total += bucket.length;\n\t\treturn total;\n\t}\n\n\t/**\n\t * Migrates every recorded position through `mapping`. Entries that fall\n\t * inside removed content (or whose host block has vanished) are dropped.\n\t * Entries that change block (e.g. via split) get re-bucketed.\n\t */\n\tmigrate(mapping: Mapping): void {\n\t\tif (mapping.isEmpty) return;\n\t\tconst next = new Map<BlockId, PairEntry[]>();\n\t\tfor (const bucket of this.buckets.values()) {\n\t\t\tfor (const entry of bucket) {\n\t\t\t\tconst result = mapping.mapResult(entry.pos, +1);\n\t\t\t\tif (result.deleted) continue;\n\t\t\t\tconst migrated: PairEntry = { pos: result.pos, char: entry.char };\n\t\t\t\tconst bid: BlockId = result.pos.blockId;\n\t\t\t\tconst target: PairEntry[] = next.get(bid) ?? [];\n\t\t\t\ttarget.push(migrated);\n\t\t\t\tnext.set(bid, target);\n\t\t\t}\n\t\t}\n\t\tthis.buckets.clear();\n\t\tfor (const [bid, entries] of next) this.buckets.set(bid, entries);\n\t}\n\n\t/** Builds a position with the same shape as auto-pair entries. */\n\tstatic makePos(blockId: BlockId, offset: number): Position {\n\t\treturn createPosition(blockId, offset);\n\t}\n}\n","/**\n * Owns the auto-pairing behavior of the code-block plugin: bracket/quote\n * pairing, overtype-on-close, selection wrapping, and dedent-on-close-bracket.\n *\n * Encapsulates the mutable pair state ({@link PairStack} plus the deferred\n * push/take queue) so the plugin stays a thin orchestrator. Positions in the\n * deferred queue are expressed in *post-transaction* space and are reconciled\n * in {@link AutoPairController.syncOnStateChange} after the transaction's\n * mapping migration has run.\n */\n\nimport type { CompositionState } from '../../model/CompositionState.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport {\n\tcreateCollapsedSelection,\n\tcreatePosition,\n\tisCollapsed,\n\tisTextSelection,\n\tselectionRange,\n} from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { TextInputInterceptor } from '../Plugin.js';\nimport {\n\ttype PairAction,\n\ttype TokenLookup,\n\tresolvePairAction,\n\twrapSelectionPlan,\n} from './BracketPairing.js';\nimport type { ResolvedIndentConfig, ResolvedPairingConfig } from './CodeBlockTypes.js';\nimport { dedentOnce, getLineRange, isWhitespaceOnlyBeforeOffset } from './IndentHelpers.js';\nimport { PairStack } from './PairStack.js';\n\ninterface AutoPairDeps {\n\treadonly resolvedIndent: ResolvedIndentConfig;\n\treadonly resolvedPairing: ResolvedPairingConfig;\n\treadonly getTokenAt: TokenLookup;\n\t/** Returns the live composition state, or `null` when the editor is not ready. */\n\treadonly getCompositionState: () => CompositionState | null;\n}\n\ntype PendingPairOp =\n\t| {\n\t\t\treadonly kind: 'push';\n\t\t\treadonly blockId: BlockId;\n\t\t\treadonly offset: number;\n\t\t\treadonly char: string;\n\t }\n\t| { readonly kind: 'take'; readonly blockId: BlockId; readonly offset: number };\n\nexport class AutoPairController {\n\tprivate readonly resolvedIndent: ResolvedIndentConfig;\n\tprivate readonly resolvedPairing: ResolvedPairingConfig;\n\tprivate readonly getTokenAt: TokenLookup;\n\tprivate readonly getCompositionState: () => CompositionState | null;\n\n\tprivate readonly pairs = new PairStack();\n\tprivate readonly pendingPairOps: PendingPairOp[] = [];\n\n\tconstructor(deps: AutoPairDeps) {\n\t\tthis.resolvedIndent = deps.resolvedIndent;\n\t\tthis.resolvedPairing = deps.resolvedPairing;\n\t\tthis.getTokenAt = deps.getTokenAt;\n\t\tthis.getCompositionState = deps.getCompositionState;\n\t}\n\n\t/**\n\t * The shared pair-tracking stack. Exposed read-only so the keyboard handlers\n\t * can consult it for Backspace pair-delete; all mutation flows through this\n\t * controller's interceptor and {@link AutoPairController.syncOnStateChange}.\n\t */\n\tget pairStack(): PairStack {\n\t\treturn this.pairs;\n\t}\n\n\tclear(): void {\n\t\tthis.pairs.clear();\n\t\tthis.pendingPairOps.length = 0;\n\t}\n\n\t/**\n\t * Reconciles the pair stack after a transaction has been applied: migrates\n\t * tracked positions through the transaction mapping, applies the deferred\n\t * push/take ops recorded by the interceptor, then drops entries whose host\n\t * block is no longer a code block.\n\t */\n\tsyncOnStateChange(state: EditorState, tr: Transaction): void {\n\t\tif (this.pairs.size > 0 && !tr.mapping.isEmpty) {\n\t\t\tthis.pairs.migrate(tr.mapping);\n\t\t}\n\n\t\t// Apply any pending push/take operations recorded by the interceptor.\n\t\t// Positions in `pendingPairOps` are already expressed in *post-transaction*\n\t\t// space, so they must be applied AFTER the migration above (otherwise the\n\t\t// migration would shift them again).\n\t\tfor (const op of this.pendingPairOps) {\n\t\t\tif (op.kind === 'push') {\n\t\t\t\tthis.pairs.push(createPosition(op.blockId, op.offset), op.char);\n\t\t\t} else {\n\t\t\t\tthis.pairs.take(op.blockId, op.offset);\n\t\t\t}\n\t\t}\n\t\tthis.pendingPairOps.length = 0;\n\n\t\t// Clear entries whose host block is no longer a code block.\n\t\tfor (const step of tr.steps) {\n\t\t\tif (step.type !== 'setBlockType') continue;\n\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\tif (!block || block.type !== 'code_block') {\n\t\t\t\tthis.pairs.clearBlock(step.blockId);\n\t\t\t}\n\t\t}\n\t}\n\n\treadonly handleTextInput: TextInputInterceptor = (\n\t\ttext: string,\n\t\tstate: EditorState,\n\t): Transaction | null => {\n\t\t// Drop any pending pair ops left over from a previously suppressed\n\t\t// transaction. `onStateChange` only fires when a tr reaches `state.apply`;\n\t\t// if middleware blocked the last tr, its queued ops would otherwise leak\n\t\t// into the next successful cycle with stale offsets.\n\t\tthis.pendingPairOps.length = 0;\n\n\t\tconst composition: CompositionState | null = this.getCompositionState();\n\t\tif (!composition) return null;\n\t\tif (composition.isComposing) return null;\n\t\tif (!isTextSelection(state.selection)) return null;\n\t\t// Only single-char inputs trigger pair logic.\n\t\tif (text.length !== 1) return null;\n\n\t\tconst sel = state.selection;\n\t\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\t\tif (!block || block.type !== 'code_block') return null;\n\n\t\t// Dedent-on-close-bracket: typing `}`, `]`, `)` on a whitespace-only line\n\t\t// reduces leading indent by one step before inserting the char.\n\t\tconst dedentTr: Transaction | null = this.tryDedentOnCloseBracket(state, block, text);\n\t\tif (dedentTr) return dedentTr;\n\n\t\tconst action: PairAction = resolvePairAction({\n\t\t\tstate,\n\t\t\tblock,\n\t\t\tblockId: sel.anchor.blockId,\n\t\t\tchar: text,\n\t\t\tconfig: this.resolvedPairing,\n\t\t\tpairStack: this.pairs,\n\t\t\tgetTokenAt: this.getTokenAt,\n\t\t});\n\n\t\tswitch (action.kind) {\n\t\t\tcase 'pair':\n\t\t\t\treturn this.buildAutoPairTransaction(state, sel.anchor.blockId, action.close, text);\n\t\t\tcase 'overtype':\n\t\t\t\treturn this.buildOvertypeTransaction(state, sel.anchor.blockId);\n\t\t\tcase 'wrap':\n\t\t\t\treturn this.buildWrapTransaction(state, sel.anchor.blockId, action.open, action.close);\n\t\t\tcase 'passthrough':\n\t\t\t\treturn null;\n\t\t}\n\t};\n\n\tprivate tryDedentOnCloseBracket(\n\t\tstate: EditorState,\n\t\tblock: BlockNode,\n\t\tchar: string,\n\t): Transaction | null {\n\t\tif (this.resolvedIndent.mode !== 'brackets') return null;\n\t\tif (char !== '}' && char !== ']' && char !== ')') return null;\n\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel) || !isCollapsed(sel)) return null;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst offset: number = sel.anchor.offset;\n\t\tif (!isWhitespaceOnlyBeforeOffset(text, offset)) return null;\n\n\t\tconst { start } = getLineRange(text, offset);\n\t\tif (start === offset) return null; // no leading indent on this line\n\n\t\tconst blockId: BlockId = sel.anchor.blockId;\n\n\t\t// Combined dedent + overtype: when the next non-whitespace char ahead of\n\t\t// the cursor (across any newlines) is a tracked auto-paired close of the\n\t\t// same kind, collapse the gap so the user's typed close consumes the\n\t\t// auto-paired one instead of producing a duplicate.\n\t\tconst trackedClosePos: number | null = this.findTrackedCloseAfter(text, offset, char, blockId);\n\t\tif (trackedClosePos !== null) {\n\t\t\treturn state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(blockId, start, trackedClosePos)\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, start + 1))\n\t\t\t\t.build();\n\t\t}\n\n\t\tconst lineSlice: string = text.slice(start, offset);\n\t\tconst result = dedentOnce(\n\t\t\tlineSlice,\n\t\t\tthis.resolvedIndent.useSpaces,\n\t\t\tthis.resolvedIndent.spaceCount,\n\t\t);\n\t\tif (result.removed.length === 0) return null;\n\n\t\tconst newOffset: number = offset - result.removed.length;\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.deleteTextAt(blockId, newOffset, offset)\n\t\t\t.insertText(blockId, newOffset, char, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, newOffset + 1))\n\t\t\t.build();\n\t}\n\n\t/**\n\t * Scans forward from `offset` through whitespace and newlines for a tracked\n\t * auto-paired close char matching `char`. Returns its position or `null` if\n\t * any other char (or end-of-text) is encountered first.\n\t */\n\tprivate findTrackedCloseAfter(\n\t\ttext: string,\n\t\toffset: number,\n\t\tchar: string,\n\t\tblockId: BlockId,\n\t): number | null {\n\t\tfor (let i = offset; i < text.length; i++) {\n\t\t\tconst ch: string | undefined = text[i];\n\t\t\tif (ch === ' ' || ch === '\\t' || ch === '\\n') continue;\n\t\t\tif (ch === char) {\n\t\t\t\tconst entry = this.pairs.peek(blockId, i);\n\t\t\t\tif (entry && entry.char === char) return i;\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate buildAutoPairTransaction(\n\t\tstate: EditorState,\n\t\tblockId: BlockId,\n\t\tcloseChar: string,\n\t\topenChar: string,\n\t): Transaction {\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel)) {\n\t\t\tthrow new Error('buildAutoPairTransaction requires a text selection');\n\t\t}\n\t\tconst offset: number = sel.anchor.offset;\n\t\tconst inserted = `${openChar}${closeChar}`;\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, offset, inserted, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + 1))\n\t\t\t.build();\n\t\t// Record the auto-inserted close char so overtype/pair-delete can target it.\n\t\t// The position is expressed in post-transaction space; the actual push\n\t\t// happens in `syncOnStateChange` after the mapping migration runs.\n\t\tthis.pendingPairOps.push({\n\t\t\tkind: 'push',\n\t\t\tblockId,\n\t\t\toffset: offset + 1,\n\t\t\tchar: closeChar,\n\t\t});\n\t\treturn tr;\n\t}\n\n\tprivate buildOvertypeTransaction(state: EditorState, blockId: BlockId): Transaction {\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel)) {\n\t\t\tthrow new Error('buildOvertypeTransaction requires a text selection');\n\t\t}\n\t\tconst offset: number = sel.anchor.offset;\n\t\t// Schedule the take so it survives the migration phase (the entry's\n\t\t// position is in pre-transaction space, so migration will preserve it).\n\t\tthis.pendingPairOps.push({ kind: 'take', blockId, offset });\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + 1))\n\t\t\t.build();\n\t}\n\n\tprivate buildWrapTransaction(\n\t\tstate: EditorState,\n\t\tblockId: BlockId,\n\t\topenChar: string,\n\t\tcloseChar: string,\n\t): Transaction {\n\t\tconst sel = state.selection;\n\t\tif (!isTextSelection(sel)) {\n\t\t\tthrow new Error('buildWrapTransaction requires a text selection');\n\t\t}\n\t\tconst plan = wrapSelectionPlan(sel, state.getBlockOrder());\n\t\tconst range = selectionRange(sel, state.getBlockOrder());\n\t\tconst wasForward: boolean = range.from === sel.anchor;\n\t\tconst newFrom: number = plan.fromOffset + 1;\n\t\tconst newTo: number = plan.toOffset + 1;\n\t\tconst anchorOff: number = wasForward ? newFrom : newTo;\n\t\tconst headOff: number = wasForward ? newTo : newFrom;\n\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, plan.toOffset, closeChar, [])\n\t\t\t.insertText(blockId, plan.fromOffset, openChar, [])\n\t\t\t.setSelection({\n\t\t\t\tanchor: { blockId, offset: anchorOff },\n\t\t\t\thead: { blockId, offset: headOff },\n\t\t\t})\n\t\t\t.build();\n\t}\n}\n","/**\n * Keyboard handlers for code-block navigation and editing.\n * Handles Enter (with auto-indent + block-pattern), Backspace (with pair-delete),\n * Tab, Shift-Tab (with multi-line range handling), Escape, Arrow keys, and\n * configurable shortcuts (Mod+Enter, toggle).\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { generateBlockId, getBlockLength, getBlockText } from '../../model/Document.js';\nimport {\n\ttype Selection,\n\tcreateCollapsedSelection,\n\tcreateSelection,\n\tisCollapsed,\n\tisForward,\n\tisTextSelection,\n\tselectionRange,\n} from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport type { CodeBlockLocale } from './CodeBlockLocale.js';\nimport type {\n\tCodeBlockConfig,\n\tCodeBlockKeymap,\n\tResolvedIndentConfig,\n\tResolvedPairingConfig,\n} from './CodeBlockTypes.js';\nimport {\n\tdedentOnce,\n\tgetCurrentLineIndent,\n\tgetLineRange,\n\tnextIndentLevel,\n\tresolveIndentUnit,\n\tshouldOpenIndentBlock,\n} from './IndentHelpers.js';\nimport type { PairStack } from './PairStack.js';\n\n// --- Context Guard ---\n\ninterface CodeBlockContext {\n\treadonly state: EditorState;\n\treadonly sel: Selection;\n\treadonly block: BlockNode;\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n}\n\nfunction withCodeBlockContext(\n\tcontext: PluginContext,\n\thandler: (ctx: CodeBlockContext) => boolean,\n): boolean {\n\tconst state: EditorState = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst sel: Selection = state.selection;\n\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\tif (!block || block.type !== 'code_block') return false;\n\n\treturn handler({\n\t\tstate,\n\t\tsel,\n\t\tblock,\n\t\tblockId: sel.anchor.blockId,\n\t\toffset: sel.anchor.offset,\n\t});\n}\n\n/** Dependencies for the keyboard handlers. */\nexport interface CodeBlockKeyboardDeps {\n\treadonly indent: ResolvedIndentConfig;\n\treadonly pairing: ResolvedPairingConfig;\n\treadonly pairStack: PairStack;\n\treadonly locale: () => CodeBlockLocale;\n}\n\n/** Registers all code-block keyboard handlers. */\nexport function registerCodeBlockKeymaps(\n\tcontext: PluginContext,\n\tconfig: CodeBlockConfig,\n\tresolvedKeymap: Readonly<Record<keyof CodeBlockKeymap, string | null>>,\n\tdeps: CodeBlockKeyboardDeps,\n): void {\n\tconst keymap: Record<string, () => boolean> = {\n\t\tEnter: () => handleEnter(context, deps),\n\t\tBackspace: () => handleBackspace(context, deps),\n\t\tTab: () => handleTab(context, deps),\n\t\t'Shift-Tab': () => handleShiftTab(context, deps),\n\t\tEscape: () => handleEscape(context),\n\t\tArrowDown: () => handleArrowDown(context),\n\t\tArrowUp: () => handleArrowUp(context),\n\t\tArrowRight: () => handleArrowRight(context),\n\t\tArrowLeft: () => handleArrowLeft(context),\n\t};\n\n\tconst { insertAfter, toggle } = resolvedKeymap;\n\n\tif (insertAfter) {\n\t\tkeymap[insertAfter] = () => handleModEnter(context);\n\t}\n\tif (toggle) {\n\t\tkeymap[toggle] = () => context.executeCommand('toggleCodeBlock');\n\t}\n\n\tcontext.registerKeymap(keymap, { priority: 'context' });\n\n\t// `config` is kept in the signature for future language-defined indent rules.\n\tvoid config;\n}\n\n// --- Handler Functions ---\n\nfunction handleBackspace(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\t// Pair-delete: backspace between an auto-paired empty pair removes both chars.\n\t\tif (deps.pairing.deletePair && offset > 0) {\n\t\t\tconst text: string = getBlockText(block);\n\t\t\tconst before = text[offset - 1];\n\t\t\tconst after = text[offset];\n\t\t\tif (before && after && isMatchingPair(before, after)) {\n\t\t\t\tconst entry = deps.pairStack.peek(blockId, offset);\n\t\t\t\tif (entry && entry.char === after) {\n\t\t\t\t\tconst tr: Transaction = state\n\t\t\t\t\t\t.transaction('input')\n\t\t\t\t\t\t.deleteTextAt(blockId, offset - 1, offset + 1)\n\t\t\t\t\t\t.setSelection(createCollapsedSelection(blockId, offset - 1))\n\t\t\t\t\t\t.build();\n\t\t\t\t\tcontext.dispatch(tr);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (offset !== 0) return false;\n\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.setBlockType(blockId, nodeType('paragraph'))\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t});\n}\n\nfunction handleEnter(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tif (text.endsWith('\\n') && offset === text.length) {\n\t\t\treturn exitOnDoubleEnter(context, blockId, text);\n\t\t}\n\n\t\tconst unit: string = resolveIndentUnit(deps.indent.useSpaces, deps.indent.spaceCount);\n\n\t\t// Block-pattern: cursor between matching open/close → 3-line layout.\n\t\tif (deps.indent.mode === 'brackets' && shouldOpenIndentBlock(text, offset)) {\n\t\t\tconst baseIndent: string = getCurrentLineIndent(text, offset);\n\t\t\tconst insert = `\\n${baseIndent}${unit}\\n${baseIndent}`;\n\t\t\tconst cursorOffset: number = offset + 1 + baseIndent.length + unit.length;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.insertText(blockId, offset, insert, [])\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, cursorOffset))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\tconst indent: string = nextIndentLevel(text, offset, deps.indent.mode, unit);\n\t\tconst insert = `\\n${indent}`;\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, offset, insert, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + insert.length))\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t});\n}\n\nfunction handleTab(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, sel, block, blockId, offset }) => {\n\t\tconst unit: string = resolveIndentUnit(deps.indent.useSpaces, deps.indent.spaceCount);\n\n\t\tif (isCollapsed(sel)) {\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.insertText(blockId, offset, unit, [])\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, offset + unit.length))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\t// Range selection — must be within this code block.\n\t\tif (sel.anchor.blockId !== blockId || sel.head.blockId !== blockId) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst range = selectionRange(sel, state.getBlockOrder());\n\t\tconst fromOffset: number = range.from.offset;\n\t\tconst toOffset: number = range.to.offset;\n\t\tconst spansLine: boolean = text.slice(fromOffset, toOffset).includes('\\n');\n\n\t\tif (!spansLine) {\n\t\t\t// VS Code-style: replace selection with one indent unit.\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(blockId, fromOffset, toOffset)\n\t\t\t\t.insertText(blockId, fromOffset, unit, [])\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, fromOffset + unit.length))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\t// Multi-line indent.\n\t\tconst result = indentLineRange(text, fromOffset, toOffset, unit);\n\t\tconst builder = state.transaction('input');\n\t\t// Apply in reverse so earlier offsets remain valid after each insert.\n\t\tfor (let i = result.inserts.length - 1; i >= 0; i--) {\n\t\t\tconst insert = result.inserts[i];\n\t\t\tif (!insert) continue;\n\t\t\tbuilder.insertText(blockId, insert.offset, insert.text, []);\n\t\t}\n\t\tconst wasForward: boolean = isForward(sel, state.getBlockOrder());\n\t\tconst newFrom: number = result.lineStart;\n\t\tconst newTo: number = toOffset + result.totalInserted;\n\t\tconst anchorOff: number = wasForward ? newFrom : newTo;\n\t\tconst headOff: number = wasForward ? newTo : newFrom;\n\t\tbuilder.setSelection(\n\t\t\tcreateSelection({ blockId, offset: anchorOff }, { blockId, offset: headOff }),\n\t\t);\n\t\tcontext.dispatch(builder.build());\n\n\t\tif (result.lineCount >= 2) {\n\t\t\tcontext.announce(deps.locale().indentedNLines(result.lineCount));\n\t\t}\n\t\treturn true;\n\t});\n}\n\nfunction handleShiftTab(context: PluginContext, deps: CodeBlockKeyboardDeps): boolean {\n\treturn withCodeBlockContext(context, ({ state, sel, block, blockId, offset }) => {\n\t\tconst text: string = getBlockText(block);\n\n\t\tif (isCollapsed(sel)) {\n\t\t\treturn dedentSingleLine(context, state, blockId, offset, text, deps);\n\t\t}\n\n\t\tif (sel.anchor.blockId !== blockId || sel.head.blockId !== blockId) return false;\n\n\t\tconst range = selectionRange(sel, state.getBlockOrder());\n\t\tconst fromOffset: number = range.from.offset;\n\t\tconst toOffset: number = range.to.offset;\n\t\tconst spansLine: boolean = text.slice(fromOffset, toOffset).includes('\\n');\n\n\t\tif (!spansLine) {\n\t\t\treturn dedentSingleLine(context, state, blockId, offset, text, deps);\n\t\t}\n\n\t\tconst result = dedentLineRange(\n\t\t\ttext,\n\t\t\tfromOffset,\n\t\t\ttoOffset,\n\t\t\tdeps.indent.useSpaces,\n\t\t\tdeps.indent.spaceCount,\n\t\t);\n\t\tif (result.totalRemoved === 0) {\n\t\t\t// Nothing to remove — consume the event so the browser does not move focus.\n\t\t\treturn true;\n\t\t}\n\n\t\tconst builder = state.transaction('input');\n\t\tfor (let i = result.deletes.length - 1; i >= 0; i--) {\n\t\t\tconst del = result.deletes[i];\n\t\t\tif (!del) continue;\n\t\t\tbuilder.deleteTextAt(blockId, del.from, del.to);\n\t\t}\n\t\tconst wasForward: boolean = isForward(sel, state.getBlockOrder());\n\t\tconst newFrom: number = result.lineStart;\n\t\tconst newTo: number = toOffset - result.totalRemoved;\n\t\tconst anchorOff: number = wasForward ? newFrom : Math.max(newFrom, newTo);\n\t\tconst headOff: number = wasForward ? Math.max(newFrom, newTo) : newFrom;\n\t\tbuilder.setSelection(\n\t\t\tcreateSelection({ blockId, offset: anchorOff }, { blockId, offset: headOff }),\n\t\t);\n\t\tcontext.dispatch(builder.build());\n\n\t\tif (result.lineCount >= 2) {\n\t\t\tcontext.announce(deps.locale().dedentedNLines(result.lineCount));\n\t\t}\n\t\treturn true;\n\t});\n}\n\nfunction dedentSingleLine(\n\tcontext: PluginContext,\n\tstate: EditorState,\n\tblockId: BlockId,\n\toffset: number,\n\ttext: string,\n\tdeps: CodeBlockKeyboardDeps,\n): boolean {\n\tconst { start } = getLineRange(text, offset);\n\tconst lineText: string = text.slice(start);\n\tconst removed = dedentOnce(lineText, deps.indent.useSpaces, deps.indent.spaceCount);\n\tif (removed.removed.length === 0) return true;\n\n\tconst tr: Transaction = state\n\t\t.transaction('input')\n\t\t.deleteTextAt(blockId, start, start + removed.removed.length)\n\t\t.setSelection(\n\t\t\tcreateCollapsedSelection(blockId, Math.max(start, offset - removed.removed.length)),\n\t\t)\n\t\t.build();\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/**\n * Exits the code block to the next block or creates a new paragraph.\n * Exported for use by the `exitCodeBlock` command.\n */\nexport function handleEscape(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, blockId }) => {\n\t\tmoveToNextBlockOrInsertParagraph(context, state, blockId);\n\t\treturn true;\n\t});\n}\n\nfunction handleArrowDown(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst nextNewline: number = text.indexOf('\\n', offset);\n\t\tif (nextNewline !== -1) return false;\n\n\t\tmoveToNextBlockOrInsertParagraph(context, state, blockId);\n\t\treturn true;\n\t});\n}\n\nfunction handleArrowUp(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tconst firstNewline: number = text.indexOf('\\n');\n\t\tif (firstNewline !== -1 && offset > firstNewline) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn moveToPreviousBlockEnd(context, state, blockId);\n\t});\n}\n\nfunction handleArrowRight(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\n\t\tconst text: string = getBlockText(block);\n\t\tif (offset !== text.length) return false;\n\n\t\tmoveToNextBlockOrInsertParagraph(context, state, blockId);\n\t\treturn true;\n\t});\n}\n\nfunction handleArrowLeft(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ state, blockId, offset }) => {\n\t\tif (!isCollapsed(state.selection)) return false;\n\t\tif (offset !== 0) return false;\n\n\t\treturn moveToPreviousBlockEnd(context, state, blockId);\n\t});\n}\n\nfunction handleModEnter(context: PluginContext): boolean {\n\treturn withCodeBlockContext(context, ({ blockId }) => {\n\t\tinsertParagraphAfter(context, blockId);\n\t\treturn true;\n\t});\n}\n\n// --- Multi-line indent helpers ---\n\ninterface IndentRangeResult {\n\treadonly inserts: readonly { offset: number; text: string }[];\n\treadonly totalInserted: number;\n\treadonly lineCount: number;\n\treadonly lineStart: number;\n}\n\nfunction indentLineRange(text: string, from: number, to: number, unit: string): IndentRangeResult {\n\tconst lineStart: number = text.lastIndexOf('\\n', from - 1) + 1;\n\tconst inserts: { offset: number; text: string }[] = [];\n\tlet lineCount = 0;\n\n\tlet pos: number = lineStart;\n\twhile (pos < to) {\n\t\tinserts.push({ offset: pos, text: unit });\n\t\tlineCount++;\n\t\tconst nl: number = text.indexOf('\\n', pos);\n\t\tif (nl === -1 || nl >= to) break;\n\t\tpos = nl + 1;\n\t}\n\n\treturn {\n\t\tinserts,\n\t\ttotalInserted: lineCount * unit.length,\n\t\tlineCount,\n\t\tlineStart,\n\t};\n}\n\ninterface DedentRangeResult {\n\treadonly deletes: readonly { from: number; to: number }[];\n\treadonly totalRemoved: number;\n\treadonly lineCount: number;\n\treadonly lineStart: number;\n}\n\nfunction dedentLineRange(\n\ttext: string,\n\tfrom: number,\n\tto: number,\n\tuseSpaces: boolean,\n\tspaceCount: number,\n): DedentRangeResult {\n\tconst lineStart: number = text.lastIndexOf('\\n', from - 1) + 1;\n\tconst deletes: { from: number; to: number }[] = [];\n\tlet totalRemoved = 0;\n\tlet lineCount = 0;\n\n\tlet pos: number = lineStart;\n\twhile (pos < to) {\n\t\tlineCount++;\n\t\tconst lineSlice: string = text.slice(pos);\n\t\tconst result = dedentOnce(lineSlice, useSpaces, spaceCount);\n\t\tif (result.removed.length > 0) {\n\t\t\tdeletes.push({ from: pos, to: pos + result.removed.length });\n\t\t\ttotalRemoved += result.removed.length;\n\t\t}\n\t\tconst nl: number = text.indexOf('\\n', pos);\n\t\tif (nl === -1 || nl >= to) break;\n\t\tpos = nl + 1;\n\t}\n\n\treturn {\n\t\tdeletes,\n\t\ttotalRemoved,\n\t\tlineCount,\n\t\tlineStart,\n\t};\n}\n\n// --- Other helpers ---\n\nfunction isMatchingPair(open: string, close: string): boolean {\n\tswitch (open) {\n\t\tcase '(':\n\t\t\treturn close === ')';\n\t\tcase '[':\n\t\t\treturn close === ']';\n\t\tcase '{':\n\t\t\treturn close === '}';\n\t\tcase '\"':\n\t\tcase \"'\":\n\t\tcase '`':\n\t\t\treturn close === open;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction insertParagraphAfter(context: PluginContext, bid: BlockId): void {\n\tconst state: EditorState = context.getState();\n\tconst block: BlockNode | undefined = state.getBlock(bid);\n\tif (!block) return;\n\n\tconst blockLength: number = getBlockLength(block);\n\tconst newId: BlockId = generateBlockId();\n\n\tconst tr: Transaction = state\n\t\t.transaction('command')\n\t\t.splitBlock(bid, blockLength, newId)\n\t\t.setBlockType(newId, nodeType('paragraph'))\n\t\t.setSelection(createCollapsedSelection(newId, 0))\n\t\t.build();\n\n\tcontext.dispatch(tr);\n}\n\n/**\n * Moves the cursor to the start of the following block, or appends a fresh\n * paragraph when the code block is the last block. Shared exit tail for\n * Escape / ArrowDown / ArrowRight at the end of the code block.\n */\nfunction moveToNextBlockOrInsertParagraph(\n\tcontext: PluginContext,\n\tstate: EditorState,\n\tbid: BlockId,\n): void {\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst idx: number = blockOrder.indexOf(bid);\n\n\tif (idx < blockOrder.length - 1) {\n\t\tconst nextId: BlockId = blockOrder[idx + 1] as BlockId;\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('command')\n\t\t\t.setSelection(createCollapsedSelection(nextId, 0))\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn;\n\t}\n\n\tinsertParagraphAfter(context, bid);\n}\n\n/**\n * Moves the cursor to the end of the preceding block. Shared tail for\n * ArrowUp / ArrowLeft at the start of the code block. Returns `false` when the\n * code block is already the first block (no movement performed).\n */\nfunction moveToPreviousBlockEnd(context: PluginContext, state: EditorState, bid: BlockId): boolean {\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst idx: number = blockOrder.indexOf(bid);\n\tif (idx <= 0) return false;\n\n\tconst prevId: BlockId = blockOrder[idx - 1] as BlockId;\n\tconst prevBlock: BlockNode | undefined = state.getBlock(prevId);\n\tconst prevLen: number = prevBlock ? getBlockLength(prevBlock) : 0;\n\tconst tr: Transaction = state\n\t\t.transaction('command')\n\t\t.setSelection(createCollapsedSelection(prevId, prevLen))\n\t\t.build();\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\nfunction exitOnDoubleEnter(context: PluginContext, bid: BlockId, text: string): boolean {\n\tconst state: EditorState = context.getState();\n\tconst trimmedLen: number = text.length - 1;\n\tconst newId: BlockId = generateBlockId();\n\n\tconst tr: Transaction = state\n\t\t.transaction('input')\n\t\t.deleteTextAt(bid, trimmedLen, text.length)\n\t\t.splitBlock(bid, trimmedLen, newId)\n\t\t.setBlockType(newId, nodeType('paragraph'))\n\t\t.setSelection(createCollapsedSelection(newId, 0))\n\t\t.build();\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n","/**\n * Command registration and implementations for code blocks.\n * Handles toggle, insert, exit, and mark stripping.\n */\n\nimport {\n\tcreateSelectionForBlockBoundary,\n\tcreateSelectionForDocumentBoundary,\n\textractParentPath,\n\tfindSiblingIndex,\n\tgetSiblings,\n} from '../../commands/CommandHelpers.js';\nimport type { BlockNode, ChildNode } from '../../model/Document.js';\nimport {\n\tcreateEmptyParagraph,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tgetInlineChildren,\n\tisBlockNode,\n\tisTextNode,\n} from '../../model/Document.js';\nimport { findNodePath } from '../../model/NodeResolver.js';\nimport type { EditorSelection } from '../../model/Selection.js';\nimport { createCollapsedSelection, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction, TransactionBuilder } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport { handleEscape } from './CodeBlockKeyboardHandlers.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\n\n/** Registers all code-block commands. */\nexport function registerCodeBlockCommands(context: PluginContext, config: CodeBlockConfig): void {\n\tcontext.registerCommand('toggleCodeBlock', () => toggleCodeBlock(context, config));\n\n\tcontext.registerCommand('insertCodeBlock', () => insertCodeBlock(context, config));\n\n\tcontext.registerCommand('setCodeBlockLanguage', () => false);\n\n\tcontext.registerCommand('setCodeBlockBackground', () => false);\n\n\tcontext.registerCommand('exitCodeBlock', () => handleEscape(context));\n\n\tcontext.registerCommand('deleteCodeBlock', () => deleteCodeBlock(context));\n}\n\n// --- Command Implementations ---\n\nfunction toggleCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block) return false;\n\n\tif (block.type === 'code_block') {\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('command')\n\t\t\t.setBlockType(state.selection.anchor.blockId, nodeType('paragraph'))\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\treturn insertCodeBlock(context, config);\n}\n\nfunction insertCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\tif (!block || block.type === 'code_block') return false;\n\n\tconst attrs: Record<string, string | number | boolean> = {\n\t\tlanguage: config.defaultLanguage ?? '',\n\t\tbackgroundColor: '',\n\t};\n\n\tconst builder: TransactionBuilder = state.transaction('command');\n\tstripAllMarks(builder, block);\n\tbuilder\n\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0));\n\n\tcontext.dispatch(builder.build());\n\treturn true;\n}\n\n/** Deletes the code block at the current cursor position. */\nfunction deleteCodeBlock(context: PluginContext): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block || block.type !== 'code_block') return false;\n\n\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, block.id);\n\tif (!tr) return false;\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/** Builds a transaction that removes a code block and repositions the cursor. */\nexport function createDeleteCodeBlockTransaction(\n\tstate: EditorState,\n\tblockId: BlockId,\n): Transaction | null {\n\tconst path: string[] | undefined = findNodePath(state.doc, blockId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\tconst index: number = findSiblingIndex(siblings, blockId);\n\tif (index < 0) return null;\n\n\tconst builder = state.transaction('command');\n\n\tif (siblings.length === 1) {\n\t\tconst newId: BlockId = generateBlockId();\n\t\tbuilder.insertNode(parentPath, 0, createEmptyParagraph(newId));\n\t\tbuilder.removeNode(parentPath, 1);\n\t\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\t\treturn builder.build();\n\t}\n\n\tbuilder.removeNode(parentPath, index);\n\n\tconst selection: EditorSelection = resolvePostDeleteSelection(state, builder, siblings, index);\n\tbuilder.setSelection(selection);\n\treturn builder.build();\n}\n\n/**\n * Determines the cursor position after a code block has been removed.\n *\n * Fallback chain — the first successful step wins, guaranteeing the caller\n * always receives a valid selection:\n * 1. End of the previous block sibling.\n * 2. Start of the next block sibling.\n * 3. Start of any other selectable block in the document.\n * 4. A freshly inserted empty paragraph at the document root.\n */\nfunction resolvePostDeleteSelection(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\tsiblings: readonly ChildNode[],\n\tremovedIndex: number,\n): EditorSelection {\n\tconst prevSibling = siblings[removedIndex - 1];\n\tif (prevSibling && isBlockNode(prevSibling)) {\n\t\tconst sel = createSelectionForBlockBoundary(state, prevSibling.id, 'end');\n\t\tif (sel) return sel;\n\t}\n\n\tconst nextSibling = siblings[removedIndex + 1];\n\tif (nextSibling && isBlockNode(nextSibling)) {\n\t\tconst sel = createSelectionForBlockBoundary(state, nextSibling.id, 'start');\n\t\tif (sel) return sel;\n\t}\n\n\tconst removed = siblings[removedIndex];\n\tconst excludeId: BlockId | undefined = removed && isBlockNode(removed) ? removed.id : undefined;\n\tconst docSel = createSelectionForDocumentBoundary(state, 'start', excludeId);\n\tif (docSel) return docSel;\n\n\tconst newId: BlockId = generateBlockId();\n\tbuilder.insertNode([], 0, createEmptyParagraph(newId));\n\treturn createCollapsedSelection(newId, 0);\n}\n\n/**\n * Strips all marks from a block's inline content.\n * Used when converting to code_block so no formatting carries over.\n */\nfunction stripAllMarks(builder: TransactionBuilder, block: BlockNode): void {\n\tconst blockLength: number = getBlockLength(block);\n\tif (blockLength === 0) return;\n\n\tconst inlineChildren = getInlineChildren(block);\n\tlet offset = 0;\n\n\tfor (const child of inlineChildren) {\n\t\tif (isTextNode(child)) {\n\t\t\tif (child.text.length > 0) {\n\t\t\t\tfor (const mark of child.marks) {\n\t\t\t\t\tbuilder.removeMark(block.id, offset, offset + child.text.length, mark);\n\t\t\t\t}\n\t\t\t}\n\t\t\toffset += child.text.length;\n\t\t} else {\n\t\t\toffset += 1;\n\t\t}\n\t}\n}\n","/**\n * Builds the decoration set for code blocks: a focus highlight on the block\n * containing the caret plus per-token syntax-highlight decorations sourced from\n * the {@link TokenCache}.\n */\n\nimport type { Decoration } from '../../decorations/Decoration.js';\nimport {\n\tDecorationSet,\n\tinline as inlineDecoration,\n\tnode as nodeDecoration,\n} from '../../decorations/Decoration.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport { isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { SyntaxHighlighter, SyntaxToken } from './CodeBlockTypes.js';\nimport type { TokenCache } from './TokenCache.js';\n\ninterface CodeBlockDecorationDeps {\n\treadonly highlighter: SyntaxHighlighter | null;\n\treadonly tokenCache: TokenCache;\n}\n\n/**\n * Produces the focus + syntax-highlight decorations for all code blocks in\n * `state`. As a side effect, prunes cache entries for blocks that no longer\n * carry highlightable content so the cache tracks the live document.\n */\nexport function createCodeBlockDecorations(\n\tstate: EditorState,\n\tdeps: CodeBlockDecorationDeps,\n): DecorationSet {\n\tconst decorations: Decoration[] = [];\n\n\tconst focusedBlockId: BlockId | null = getFocusedCodeBlockId(state);\n\tif (focusedBlockId) {\n\t\tdecorations.push(nodeDecoration(focusedBlockId, { class: 'notectl-code-block--focused' }));\n\t}\n\n\tif (deps.highlighter) {\n\t\tconst activeBlockIds = new Set<BlockId>();\n\t\tfor (const bid of state.getBlockOrder()) {\n\t\t\tconst block: BlockNode | undefined = state.getBlock(bid);\n\t\t\tif (!block || block.type !== 'code_block') continue;\n\n\t\t\tconst lang: string = (block.attrs?.language as string) ?? '';\n\t\t\tif (!lang) continue;\n\n\t\t\tconst text: string = getBlockText(block);\n\t\t\tif (!text) continue;\n\n\t\t\tactiveBlockIds.add(bid);\n\t\t\tconst tokens: readonly SyntaxToken[] = deps.tokenCache.getTokens(\n\t\t\t\tbid,\n\t\t\t\ttext,\n\t\t\t\tlang,\n\t\t\t\tdeps.highlighter,\n\t\t\t);\n\t\t\tfor (const token of tokens) {\n\t\t\t\tdecorations.push(\n\t\t\t\t\tinlineDecoration(bid, token.from, token.to, {\n\t\t\t\t\t\tclass: `notectl-token--${token.type}`,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tdeps.tokenCache.retain(activeBlockIds);\n\t}\n\n\tif (decorations.length === 0) return DecorationSet.empty;\n\treturn DecorationSet.create(decorations);\n}\n\nfunction getFocusedCodeBlockId(state: EditorState): BlockId | null {\n\tif (!isTextSelection(state.selection)) return null;\n\tconst blockId: BlockId = state.selection.anchor.blockId;\n\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\tif (block?.type === 'code_block') return blockId;\n\treturn null;\n}\n","/**\n * Internal registry that stores LanguageSupport bundles and notifies\n * subscribers with replay semantics for late subscribers.\n */\n\nimport type {\n\tLanguageRegistryListener,\n\tLanguageRegistryService,\n\tLanguageSupport,\n} from './LanguageTypes.js';\n\nexport class LanguageRegistry implements LanguageRegistryService {\n\tprivate readonly bundles = new Map<string, LanguageSupport>();\n\tprivate readonly listeners: LanguageRegistryListener[] = [];\n\n\tregister(support: LanguageSupport): void {\n\t\tthis.bundles.set(support.id, support);\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\t/**\n\t * Subscribes to language registrations.\n\t * The listener is immediately called for all already-registered bundles\n\t * (replay semantics), then called for each future registration.\n\t */\n\tonRegister(listener: LanguageRegistryListener): void {\n\t\tthis.listeners.push(listener);\n\t\tfor (const support of this.bundles.values()) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\tget(id: string): LanguageSupport | undefined {\n\t\treturn this.bundles.get(id);\n\t}\n\n\tgetAll(): readonly LanguageSupport[] {\n\t\treturn [...this.bundles.values()];\n\t}\n}\n","/**\n * Types, interfaces, and constants for the code-block plugin.\n */\n\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { ServiceKey } from '../Plugin.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\tcode_block: {\n\t\t\tlanguage: string;\n\t\t\tbackgroundColor: string;\n\t\t};\n\t}\n}\n\n// --- Syntax Highlighting Types ---\n\nimport type { SyntaxTokenType } from '../../editor/theme/SyntaxTokenTypes.js';\n\nexport interface SyntaxToken {\n\treadonly from: number;\n\treadonly to: number;\n\treadonly type: SyntaxTokenType | (string & {});\n}\n\nexport interface SyntaxHighlighter {\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\tgetSupportedLanguages(): readonly string[];\n\tregisterLanguage?(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n}\n\n// --- Configuration ---\n\n/**\n * Configurable keyboard bindings for CodeBlockPlugin actions.\n * Omit a slot to use the default; set to `null` to disable the binding.\n *\n * Key descriptor format: `'Mod-Enter'`, `'Mod-Shift-M'`, etc.\n * `Mod` resolves to Cmd on macOS, Ctrl on Windows/Linux.\n */\nexport interface CodeBlockKeymap {\n\t/**\n\t * Insert a new paragraph below the code block and move the cursor there.\n\t * @default 'Mod-Enter'\n\t */\n\treadonly insertAfter?: string | null;\n\n\t/**\n\t * Toggle the current block between code block and paragraph.\n\t * @default 'Mod-Shift-M'\n\t */\n\treadonly toggle?: string | null;\n}\n\nexport const DEFAULT_KEYMAP: Readonly<Record<keyof CodeBlockKeymap, string>> = {\n\tinsertAfter: 'Mod-Enter',\n\ttoggle: 'Mod-Shift-M',\n};\n\n/** Auto-indent configuration block. All fields optional. */\nexport interface CodeBlockIndentConfig {\n\t/** Indent mode: `none` disables Enter-driven indent, `keep` only inherits the\n\t * previous line's indent, `brackets` additionally adds an extra step after\n\t * `{`, `[`, `(` and dedents on close chars. Default `'brackets'`. */\n\treadonly mode?: 'none' | 'keep' | 'brackets';\n\t/** Use spaces instead of a literal tab character. Default `false`. */\n\treadonly useSpaces?: boolean;\n\t/** Spaces per indent unit (clamped to [1, 16]). Default `2`. */\n\treadonly spaceCount?: number;\n}\n\n/** Auto-pair configuration block. All fields optional. */\nexport interface CodeBlockPairingConfig {\n\t/** Auto-pair behavior for brackets. Default `'languageDefined'`. */\n\treadonly brackets?: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\t/** Auto-pair behavior for quotes. Default `'languageDefined'`. */\n\treadonly quotes?: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\t/** Skip-over for auto-inserted close chars. Default `true`. */\n\treadonly overtype?: boolean;\n\t/** Backspace removes leftover empty auto-pair. Default `true`. */\n\treadonly deletePair?: boolean;\n\t/** Wrap-selection scope. Default `'languageDefined'` (= brackets + quotes). */\n\treadonly surround?: 'languageDefined' | 'quotes' | 'brackets' | 'never';\n}\n\n/**\n * Fully-resolved indent config seen by the keyboard handlers.\n * Differs from `CodeBlockIndentConfig` only in that all fields are required\n * after the constructor merge + clamp.\n */\nexport interface ResolvedIndentConfig {\n\treadonly mode: 'none' | 'keep' | 'brackets';\n\treadonly useSpaces: boolean;\n\treadonly spaceCount: number;\n}\n\n/** Fully-resolved pairing config — all fields required. */\nexport interface ResolvedPairingConfig {\n\treadonly brackets: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\treadonly quotes: 'always' | 'languageDefined' | 'beforeWhitespace' | 'never';\n\treadonly overtype: boolean;\n\treadonly deletePair: boolean;\n\treadonly surround: 'languageDefined' | 'quotes' | 'brackets' | 'never';\n}\n\nexport interface CodeBlockConfig {\n\treadonly highlighter?: SyntaxHighlighter;\n\treadonly defaultLanguage?: string;\n\t/**\n\t * @deprecated Use `indent.useSpaces` instead. Read as a fallback when\n\t * `indent.useSpaces` is unset.\n\t */\n\treadonly useSpaces?: boolean;\n\t/**\n\t * @deprecated Use `indent.spaceCount` instead. Read as a fallback when\n\t * `indent.spaceCount` is unset.\n\t */\n\treadonly spaceCount?: number;\n\treadonly showCopyButton?: boolean;\n\t/** Default body background color (overrides --notectl-code-block-bg). */\n\treadonly background?: string;\n\t/** Default header background color (overrides --notectl-code-block-header-bg). */\n\treadonly headerBackground?: string;\n\t/** Default text color (overrides --notectl-code-block-color). */\n\treadonly textColor?: string;\n\t/** Default header/label text color (overrides --notectl-code-block-header-color). */\n\treadonly headerColor?: string;\n\t/** Customize keyboard bindings for code block actions. */\n\treadonly keymap?: CodeBlockKeymap;\n\t/** Locale override for user-facing strings. */\n\treadonly locale?: import('./CodeBlockLocale.js').CodeBlockLocale;\n\t/** Auto-indent settings. */\n\treadonly indent?: CodeBlockIndentConfig;\n\t/** Bracket-pairing settings. */\n\treadonly pairing?: CodeBlockPairingConfig;\n}\n\nexport const DEFAULT_CONFIG: CodeBlockConfig = {\n\tdefaultLanguage: '',\n\tuseSpaces: false,\n\tspaceCount: 2,\n\tshowCopyButton: true,\n};\n\n/** Default values applied during config merge (see CodeBlockPlugin.constructor). */\nexport const DEFAULT_INDENT: ResolvedIndentConfig = {\n\tmode: 'brackets',\n\tuseSpaces: false,\n\tspaceCount: 2,\n};\n\nexport const DEFAULT_PAIRING: ResolvedPairingConfig = {\n\tbrackets: 'languageDefined',\n\tquotes: 'languageDefined',\n\tovertype: true,\n\tdeletePair: true,\n\tsurround: 'languageDefined',\n};\n\nexport const MIN_SPACE_COUNT = 1;\nexport const MAX_SPACE_COUNT = 16;\n\n// --- Service Types ---\n\nexport interface CodeBlockService {\n\tsetLanguage(blockId: BlockId, language: string): void;\n\tgetLanguage(blockId: BlockId): string;\n\tsetBackground(blockId: BlockId, color: string): void;\n\tgetBackground(blockId: BlockId): string;\n\tisCodeBlock(blockId: BlockId): boolean;\n\tgetSupportedLanguages(): readonly string[];\n}\n\nexport const CODE_BLOCK_SERVICE_KEY = new ServiceKey<CodeBlockService>('codeBlock');\n\n// --- Syntax Highlighter Service ---\n\nexport interface SyntaxHighlighterService {\n\tregisterLanguage(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n\tgetSupportedLanguages(): readonly string[];\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\t/**\n\t * Returns the cached token whose range covers `offset` in `blockId`, or\n\t * `undefined` if no token is registered at that position (e.g. cache miss,\n\t * whitespace between tokens, or block not yet tokenized). Uses binary\n\t * search over the per-block token cache; never triggers a fresh tokenize.\n\t */\n\tgetTokenAt(blockId: BlockId, offset: number): SyntaxToken | undefined;\n}\n\nexport const SYNTAX_HIGHLIGHTER_SERVICE_KEY = new ServiceKey<SyntaxHighlighterService>(\n\t'syntaxHighlighter',\n);\n\n// --- SVG Icon ---\n\nexport const CODE_BLOCK_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z\"/><path d=\"M11 14.17L8.83 12 11 9.83 9.59 8.41 6 12l3.59 3.59L11 14.17zm3.41 1.42L18 12l-3.59-3.59L13 9.83 15.17 12 13 14.17l1.41 1.42z\"/></svg>';\n","/**\n * Regex-based syntax tokenizer.\n * Implements the SyntaxHighlighter interface using linear regex scanning\n * with sticky (`y`-flagged) regexes to avoid O(n) substring allocations per position.\n */\n\nimport type { SyntaxHighlighter, SyntaxToken } from '../CodeBlockTypes.js';\nimport { iterateTokens } from './TokenIteration.js';\nimport type { LanguageDefinition } from './TokenizerTypes.js';\n\nexport class RegexTokenizer implements SyntaxHighlighter {\n\tprivate readonly languageMap = new Map<string, LanguageDefinition>();\n\n\tconstructor(languages?: readonly LanguageDefinition[]) {\n\t\tif (languages) {\n\t\t\tfor (const lang of languages) {\n\t\t\t\tthis.registerLanguageInternal(lang);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Registers a language definition. Overwrites existing definitions for the same name/aliases. */\n\tregisterLanguage(def: LanguageDefinition): void {\n\t\tthis.registerLanguageInternal(def);\n\t}\n\n\t/** Tokenizes code using the specified language. Returns empty array for unknown languages. */\n\ttokenize(code: string, language: string): readonly SyntaxToken[] {\n\t\tconst lang: LanguageDefinition | undefined = this.languageMap.get(language.toLowerCase());\n\t\tif (!lang) return [];\n\n\t\tconst tokens: SyntaxToken[] = [];\n\t\tfor (const token of iterateTokens(code, lang)) {\n\t\t\ttokens.push({ from: token.from, to: token.to, type: token.type });\n\t\t}\n\t\treturn tokens;\n\t}\n\n\t/** Returns all registered language names and aliases. */\n\tgetSupportedLanguages(): readonly string[] {\n\t\tconst names = new Set<string>();\n\t\tfor (const lang of this.languageMap.values()) {\n\t\t\tnames.add(lang.name);\n\t\t\tfor (const alias of lang.aliases) {\n\t\t\t\tnames.add(alias);\n\t\t\t}\n\t\t}\n\t\treturn [...names];\n\t}\n\n\tprivate registerLanguageInternal(def: LanguageDefinition): void {\n\t\tthis.languageMap.set(def.name.toLowerCase(), def);\n\t\tfor (const alias of def.aliases) {\n\t\t\tthis.languageMap.set(alias.toLowerCase(), def);\n\t\t}\n\t}\n}\n","/**\n * Wires up syntax highlighting for the code-block plugin: selects the active\n * highlighter (the configured one or the built-in {@link RegexTokenizer}),\n * registers the language registry with its bundled languages, and exposes the\n * `SyntaxHighlighterService`. The shared {@link TokenCache} is invalidated\n * whenever a new language is registered.\n */\n\nimport type { PluginContext } from '../Plugin.js';\nimport { LanguageRegistry } from '../language/LanguageRegistry.js';\nimport { LANGUAGE_REGISTRY_SERVICE_KEY } from '../language/LanguageTypes.js';\nimport {\n\tJAVA_SUPPORT,\n\tJSON_SUPPORT,\n\tTYPESCRIPT_SUPPORT,\n\tXML_SUPPORT,\n} from '../language/bundles/index.js';\nimport type { CodeBlockConfig, SyntaxHighlighter } from './CodeBlockTypes.js';\nimport { SYNTAX_HIGHLIGHTER_SERVICE_KEY } from './CodeBlockTypes.js';\nimport type { TokenCache } from './TokenCache.js';\nimport { RegexTokenizer } from './highlighter/RegexTokenizer.js';\n\n/**\n * Sets up the highlighter, language registry, and syntax-highlighter service.\n * Returns the active highlighter so the plugin can hand it to the node view and\n * decoration builder.\n */\nexport function setupHighlighting(\n\tcontext: PluginContext,\n\tconfig: CodeBlockConfig,\n\ttokenCache: TokenCache,\n): SyntaxHighlighter {\n\tconst highlighter: SyntaxHighlighter = config.highlighter ?? new RegexTokenizer();\n\n\tconst languageRegistry = new LanguageRegistry();\n\tlanguageRegistry.onRegister((support) => {\n\t\tif (support.highlighting && highlighter.registerLanguage) {\n\t\t\thighlighter.registerLanguage(support.highlighting);\n\t\t\ttokenCache.clear();\n\t\t}\n\t});\n\tcontext.registerService(LANGUAGE_REGISTRY_SERVICE_KEY, languageRegistry);\n\n\tlanguageRegistry.register(JAVA_SUPPORT);\n\tlanguageRegistry.register(JSON_SUPPORT);\n\tlanguageRegistry.register(TYPESCRIPT_SUPPORT);\n\tlanguageRegistry.register(XML_SUPPORT);\n\n\tcontext.registerService(SYNTAX_HIGHLIGHTER_SERVICE_KEY, {\n\t\tregisterLanguage: (def) => {\n\t\t\thighlighter.registerLanguage?.(def);\n\t\t\ttokenCache.clear();\n\t\t},\n\t\tgetSupportedLanguages: () => highlighter.getSupportedLanguages(),\n\t\ttokenize: (code, language) => highlighter.tokenize(code, language),\n\t\tgetTokenAt: (blockId, offset) => tokenCache.findTokenAt(blockId, offset),\n\t});\n\n\treturn highlighter;\n}\n","/** Locale interface and default English locale for the CodeBlockPlugin. */\n\nimport { type LocaleModuleMap, loadLocaleModule } from '../shared/LocaleLoader.js';\n\n// --- Locale Interface ---\n\nexport interface CodeBlockLocale {\n\treadonly label: string;\n\treadonly tooltip: (shortcut?: string) => string;\n\treadonly enteredCodeBlock: string;\n\treadonly leftCodeBlock: string;\n\treadonly copyCodeAria: string;\n\treadonly escToExit: string;\n\treadonly codeBlockAriaLabel: (lang: string) => string;\n\treadonly copiedToClipboard: string;\n\treadonly copyFailed: string;\n\treadonly deleteCodeBlockAria: string;\n\treadonly deletedCodeBlock: string;\n\treadonly selectLanguageAria: string;\n\treadonly languageChanged: (lang: string) => string;\n\treadonly plainText: string;\n\t/** Screen-reader announcement after multi-line Tab indent. */\n\treadonly indentedNLines: (n: number) => string;\n\t/** Screen-reader announcement after multi-line Shift-Tab dedent. */\n\treadonly dedentedNLines: (n: number) => string;\n}\n\n// --- Default English Locale ---\n\nexport const CODE_BLOCK_LOCALE_EN: CodeBlockLocale = {\n\tlabel: 'Code Block',\n\ttooltip: (shortcut?: string) => (shortcut ? `Code Block (${shortcut})` : 'Code Block'),\n\tenteredCodeBlock: 'Entered code block. Press Escape to exit.',\n\tleftCodeBlock: 'Left code block.',\n\tcopyCodeAria: 'Copy code',\n\tescToExit: 'Esc to exit',\n\tcodeBlockAriaLabel: (lang: string) => `${lang} code block. Press Escape to exit.`,\n\tcopiedToClipboard: 'Copied to clipboard',\n\tcopyFailed: 'Failed to copy code',\n\tdeleteCodeBlockAria: 'Delete code block',\n\tdeletedCodeBlock: 'Code block deleted',\n\tselectLanguageAria: 'Select language',\n\tlanguageChanged: (lang: string) => `Language changed to ${lang}`,\n\tplainText: 'plain',\n\tindentedNLines: (n: number) => (n === 1 ? '1 line indented' : `${n} lines indented`),\n\tdedentedNLines: (n: number) => (n === 1 ? '1 line dedented' : `${n} lines dedented`),\n};\n\n// --- Lazy Locale Loader ---\n\nconst localeModules: LocaleModuleMap<CodeBlockLocale> = import.meta.glob<{\n\tdefault: CodeBlockLocale;\n}>('./locales/*.ts', { eager: false });\n\nexport async function loadCodeBlockLocale(lang: string): Promise<CodeBlockLocale> {\n\treturn loadLocaleModule(localeModules, lang, CODE_BLOCK_LOCALE_EN);\n}\n","/**\n * Language picker popup for code blocks.\n * Opens a listbox dropdown anchored to the language button,\n * allowing users to select a syntax highlighting language.\n */\n\nimport { attachListboxKeyboard } from '../shared/PopupKeyboardPatterns.js';\nimport type { PopupServiceAPI } from '../shared/PopupManager.js';\nimport type { CodeBlockLocale } from './CodeBlockLocale.js';\n\n/** Configuration for opening the language picker popup. */\nexport interface LanguagePickerConfig {\n\treadonly anchor: HTMLElement;\n\treadonly languages: readonly string[];\n\treadonly currentLanguage: string;\n\treadonly onSelect: (language: string) => void;\n\treadonly popupManager: PopupServiceAPI;\n\treadonly locale: CodeBlockLocale;\n}\n\nconst OPTION_SELECTOR = '[role=\"option\"]';\n\n/** Opens a language picker popup anchored to the given element. */\nexport function openLanguagePicker(config: LanguagePickerConfig): void {\n\tconst { anchor, languages, currentLanguage, onSelect, popupManager, locale } = config;\n\n\tpopupManager.open({\n\t\tanchor,\n\t\tariaRole: 'listbox',\n\t\tariaLabel: locale.selectLanguageAria,\n\t\tclassName: 'notectl-language-picker',\n\t\tposition: 'below-start',\n\t\trestoreFocusTo: anchor,\n\t\tcontent(container, close) {\n\t\t\tconst normalizedCurrent: string = currentLanguage.toLowerCase();\n\n\t\t\t// \"plain\" option is always first\n\t\t\tappendOption(container, locale.plainText, '', normalizedCurrent === '');\n\n\t\t\t// Language options sorted alphabetically\n\t\t\tconst sorted: readonly string[] = [...languages].sort((a, b) => a.localeCompare(b));\n\t\t\tfor (const lang of sorted) {\n\t\t\t\tappendOption(container, lang, lang, normalizedCurrent === lang.toLowerCase());\n\t\t\t}\n\n\t\t\tattachListboxKeyboard({\n\t\t\t\tcontainer,\n\t\t\t\titemSelector: OPTION_SELECTOR,\n\t\t\t\tonSelect(item) {\n\t\t\t\t\tconst value: string = item.getAttribute('data-language') ?? '';\n\t\t\t\t\tonSelect(value);\n\t\t\t\t\tclose();\n\t\t\t\t},\n\t\t\t\tonClose() {\n\t\t\t\t\tclose();\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tcontainer.addEventListener('click', (e: Event) => {\n\t\t\t\tconst target: HTMLElement | null = (e.target as HTMLElement).closest(OPTION_SELECTOR);\n\t\t\t\tif (!target) return;\n\t\t\t\tconst value: string = target.getAttribute('data-language') ?? '';\n\t\t\t\tonSelect(value);\n\t\t\t\tclose();\n\t\t\t});\n\t\t},\n\t\tonClose() {\n\t\t\tanchor.setAttribute('aria-expanded', 'false');\n\t\t},\n\t});\n\n\tanchor.setAttribute('aria-expanded', 'true');\n}\n\nfunction appendOption(\n\tcontainer: HTMLElement,\n\tlabel: string,\n\tvalue: string,\n\tselected: boolean,\n): void {\n\tconst option: HTMLDivElement = document.createElement('div');\n\toption.className = 'notectl-language-picker__option';\n\toption.setAttribute('role', 'option');\n\toption.setAttribute('data-language', value);\n\toption.setAttribute('aria-selected', String(selected));\n\toption.setAttribute('tabindex', selected ? '0' : '-1');\n\toption.textContent = label;\n\tcontainer.appendChild(option);\n}\n","/**\n * NodeView factory for code blocks.\n * Renders <pre> with a non-editable header (language label + action buttons)\n * and a <code> content area where the Reconciler renders text.\n */\n\nimport type { BlockAttrs, BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { NodeView, NodeViewFactory } from '../../view/NodeView.js';\nimport type { PopupServiceAPI } from '../shared/PopupManager.js';\nimport { createDeleteCodeBlockTransaction } from './CodeBlockCommands.js';\nimport { CODE_BLOCK_LOCALE_EN, type CodeBlockLocale } from './CodeBlockLocale.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\nimport { openLanguagePicker } from './LanguagePicker.js';\n\n/** How long a screen-reader announcement stays in the live region before clearing. */\nconst ANNOUNCE_CLEAR_MS = 1000;\n\n/** Dependencies for the language picker in the code block header. */\nexport interface LanguagePickerDeps {\n\treadonly popupManager: PopupServiceAPI;\n\treadonly getSupportedLanguages: () => readonly string[];\n}\n\nconst COPY_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z\"/></svg>';\n\nconst DELETE_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z\"/></svg>';\n\nconst CHEVRON_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"10\" height=\"10\"><path d=\"M4 6l4 4 4-4\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>';\n\n/**\n * Copies text to the clipboard, rejecting when the Clipboard API is unavailable\n * (e.g. insecure context, missing permissions) or when the write itself fails.\n * Callers must handle rejection to give the user accurate feedback.\n */\nexport function copyTextToClipboard(text: string): Promise<void> {\n\tconst clipboard: Clipboard | undefined = globalThis.navigator?.clipboard;\n\tif (!clipboard || typeof clipboard.writeText !== 'function') {\n\t\treturn Promise.reject(new Error('Clipboard API unavailable'));\n\t}\n\treturn clipboard.writeText(text);\n}\n\n/** Creates a NodeViewFactory for code_block nodes. */\nexport function createCodeBlockNodeViewFactory(\n\tconfig: CodeBlockConfig,\n\tlocale: CodeBlockLocale = CODE_BLOCK_LOCALE_EN,\n\tpickerDeps?: LanguagePickerDeps,\n): NodeViewFactory {\n\treturn (\n\t\tnode: BlockNode,\n\t\tgetState: () => EditorState,\n\t\tdispatch: (tr: Transaction) => void,\n\t): NodeView => {\n\t\t// --- DOM Construction ---\n\t\tconst pre: HTMLElement = document.createElement('pre');\n\t\tpre.className = 'notectl-code-block';\n\t\tpre.setAttribute('data-block-id', node.id);\n\t\tpre.setAttribute('dir', 'ltr');\n\t\tpre.setAttribute('role', 'group');\n\t\tpre.setAttribute('aria-roledescription', 'code block');\n\t\tpre.setAttribute('part', 'code-block');\n\n\t\t// Header (non-editable)\n\t\tconst header: HTMLDivElement = document.createElement('div');\n\t\theader.className = 'notectl-code-block__header';\n\t\theader.setAttribute('contenteditable', 'false');\n\t\theader.setAttribute('part', 'code-block-header');\n\n\t\tconst langBtn: HTMLButtonElement = document.createElement('button');\n\t\tlangBtn.className = 'notectl-code-block__language-btn';\n\t\tlangBtn.type = 'button';\n\t\tlangBtn.setAttribute('aria-haspopup', 'listbox');\n\t\tlangBtn.setAttribute('aria-expanded', 'false');\n\t\tlangBtn.setAttribute('aria-label', locale.selectLanguageAria);\n\n\t\tconst showCopy: boolean = config.showCopyButton !== false;\n\t\tlet copyBtn: HTMLButtonElement | null = null;\n\n\t\tif (showCopy) {\n\t\t\tcopyBtn = document.createElement('button');\n\t\t\tcopyBtn.className = 'notectl-code-block__copy';\n\t\t\tcopyBtn.setAttribute('aria-label', locale.copyCodeAria);\n\t\t\tcopyBtn.setAttribute('data-notectl-no-print', '');\n\t\t\tcopyBtn.type = 'button';\n\t\t\tcopyBtn.innerHTML = COPY_ICON;\n\t\t}\n\n\t\t// Delete button\n\t\tconst deleteBtn: HTMLButtonElement = document.createElement('button');\n\t\tdeleteBtn.className = 'notectl-code-block__delete';\n\t\tdeleteBtn.setAttribute('aria-label', locale.deleteCodeBlockAria);\n\t\tdeleteBtn.title = locale.deleteCodeBlockAria;\n\t\tdeleteBtn.setAttribute('data-notectl-no-print', '');\n\t\tdeleteBtn.type = 'button';\n\t\tdeleteBtn.innerHTML = DELETE_ICON;\n\n\t\t// Screen reader live region for action feedback\n\t\tconst announcer: HTMLSpanElement = document.createElement('span');\n\t\tannouncer.className = 'notectl-sr-only';\n\t\tannouncer.setAttribute('aria-live', 'assertive');\n\t\tannouncer.setAttribute('aria-atomic', 'true');\n\n\t\t// Actions wrapper groups buttons on the right side\n\t\tconst actions: HTMLDivElement = document.createElement('div');\n\t\tactions.className = 'notectl-code-block__actions';\n\t\tif (copyBtn) {\n\t\t\tactions.appendChild(copyBtn);\n\t\t}\n\t\tactions.appendChild(deleteBtn);\n\n\t\theader.appendChild(langBtn);\n\t\theader.appendChild(actions);\n\t\theader.appendChild(announcer);\n\n\t\t// Content area (Reconciler target)\n\t\tconst code: HTMLElement = document.createElement('code');\n\t\tcode.className = 'notectl-code-block__content';\n\t\tcode.setAttribute('part', 'code-block-content');\n\n\t\t// Escape hint (visible only when focused, CSS-driven)\n\t\tconst escHint: HTMLDivElement = document.createElement('div');\n\t\tescHint.className = 'notectl-code-block__esc-hint';\n\t\tescHint.setAttribute('contenteditable', 'false');\n\t\tescHint.setAttribute('aria-hidden', 'true');\n\t\tescHint.setAttribute('data-notectl-no-print', '');\n\t\tescHint.textContent = locale.escToExit;\n\n\t\tpre.appendChild(header);\n\t\tpre.appendChild(code);\n\t\tpre.appendChild(escHint);\n\n\t\t// Apply config-level color overrides as CSS custom properties\n\t\tif (config.background) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-bg', config.background);\n\t\t}\n\t\tif (config.headerBackground) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-bg', config.headerBackground);\n\t\t}\n\t\tif (config.textColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-color', config.textColor);\n\t\t}\n\t\tif (config.headerColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-color', config.headerColor);\n\t\t}\n\n\t\tlet currentNodeId: BlockId = node.id;\n\n\t\t// --- Attribute Application ---\n\n\t\tfunction applyAttrs(n: BlockNode): void {\n\t\t\tconst lang: string = (n.attrs?.language as string) ?? '';\n\t\t\tconst langName: string = lang || locale.plainText;\n\t\t\tlangBtn.innerHTML = '';\n\t\t\tconst labelSpan: HTMLSpanElement = document.createElement('span');\n\t\t\tlabelSpan.className = 'notectl-code-block__language';\n\t\t\tlabelSpan.textContent = langName;\n\t\t\tlangBtn.appendChild(labelSpan);\n\t\t\tif (pickerDeps) {\n\t\t\t\tconst chevron: HTMLSpanElement = document.createElement('span');\n\t\t\t\tchevron.className = 'notectl-code-block__chevron';\n\t\t\t\tchevron.innerHTML = CHEVRON_ICON;\n\t\t\t\tlangBtn.appendChild(chevron);\n\t\t\t}\n\t\t\tpre.setAttribute('aria-label', locale.codeBlockAriaLabel(langName));\n\n\t\t\tif (lang) {\n\t\t\t\tcode.setAttribute('data-language', lang);\n\t\t\t} else {\n\t\t\t\tcode.removeAttribute('data-language');\n\t\t\t}\n\n\t\t\tconst bg: string = (n.attrs?.backgroundColor as string) ?? '';\n\t\t\tsetStyleProperty(pre, 'backgroundColor', bg || '');\n\t\t}\n\n\t\tapplyAttrs(node);\n\n\t\t// --- Copy Button Handler ---\n\n\t\tfunction announce(message: string): void {\n\t\t\tannouncer.textContent = message;\n\t\t\tsetTimeout(() => {\n\t\t\t\tannouncer.textContent = '';\n\t\t\t}, ANNOUNCE_CLEAR_MS);\n\t\t}\n\n\t\tif (copyBtn) {\n\t\t\tcopyBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\t\te.preventDefault();\n\t\t\t\te.stopPropagation();\n\n\t\t\t\tconst state: EditorState = getState();\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(currentNodeId);\n\t\t\t\tif (!block) return;\n\n\t\t\t\tconst text: string = getBlockText(block);\n\t\t\t\tcopyTextToClipboard(text).then(\n\t\t\t\t\t() => announce(locale.copiedToClipboard),\n\t\t\t\t\t() => announce(locale.copyFailed),\n\t\t\t\t);\n\t\t\t});\n\t\t}\n\n\t\t// --- Delete Button Handler ---\n\n\t\tdeleteBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\n\t\t\tconst state: EditorState = getState();\n\t\t\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, currentNodeId);\n\t\t\tif (!tr) return;\n\n\t\t\tannouncer.textContent = locale.deletedCodeBlock;\n\t\t\tdispatch(tr);\n\t\t});\n\n\t\t// --- Language Picker Handler ---\n\n\t\tif (pickerDeps) {\n\t\t\tlangBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\t\te.preventDefault();\n\t\t\t\te.stopPropagation();\n\n\t\t\t\tconst state: EditorState = getState();\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(currentNodeId);\n\t\t\t\tif (!block) return;\n\n\t\t\t\tconst currentLang: string = (block.attrs?.language as string) ?? '';\n\t\t\t\topenLanguagePicker({\n\t\t\t\t\tanchor: langBtn,\n\t\t\t\t\tlanguages: pickerDeps.getSupportedLanguages(),\n\t\t\t\t\tcurrentLanguage: currentLang,\n\t\t\t\t\tlocale,\n\t\t\t\t\tpopupManager: pickerDeps.popupManager,\n\t\t\t\t\tonSelect(language: string) {\n\t\t\t\t\t\tif (language === currentLang) return;\n\n\t\t\t\t\t\tconst latest: EditorState = getState();\n\t\t\t\t\t\tconst latestBlock: BlockNode | undefined = latest.getBlock(currentNodeId);\n\t\t\t\t\t\tif (!latestBlock) return;\n\n\t\t\t\t\t\tconst path: BlockId[] | undefined = latest.getNodePath(currentNodeId);\n\t\t\t\t\t\tif (!path) return;\n\n\t\t\t\t\t\tconst newAttrs: BlockAttrs = { ...latestBlock.attrs, language };\n\t\t\t\t\t\tconst tr: Transaction = latest\n\t\t\t\t\t\t\t.transaction('command')\n\t\t\t\t\t\t\t.setNodeAttr(path, newAttrs)\n\t\t\t\t\t\t\t.build();\n\t\t\t\t\t\tdispatch(tr);\n\n\t\t\t\t\t\tconst langName: string = language || locale.plainText;\n\t\t\t\t\t\tannounce(locale.languageChanged(langName));\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t// --- NodeView Interface ---\n\n\t\treturn {\n\t\t\tdom: pre,\n\t\t\tcontentDOM: code,\n\n\t\t\tupdate(updatedNode: BlockNode): boolean {\n\t\t\t\tif (updatedNode.type !== 'code_block') return false;\n\t\t\t\tcurrentNodeId = updatedNode.id;\n\t\t\t\tpre.setAttribute('data-block-id', updatedNode.id);\n\t\t\t\tapplyAttrs(updatedNode);\n\t\t\t\treturn true;\n\t\t\t},\n\n\t\t\tselectNode(): void {\n\t\t\t\tpre.classList.add('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdeselectNode(): void {\n\t\t\t\tpre.classList.remove('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdestroy(): void {\n\t\t\t\t// No cleanup needed\n\t\t\t},\n\t\t};\n\t};\n}\n","/**\n * Static editor registrations for the code-block plugin: the `code_block`\n * NodeSpec, the ```` ```lang ```` input rule, the toolbar item, the mark-guard\n * middleware, the paste interceptor, and the table-cell content patch.\n *\n * These are pure registration helpers with no per-instance state, mirroring the\n * `registerCodeBlockCommands` / `registerCodeBlockKeymaps` pattern.\n */\n\nimport { addDeleteSelectionSteps } from '../../commands/Commands.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { HTMLExportContext } from '../../model/NodeSpec.js';\nimport { createCollapsedSelection, isCollapsed, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { createBlockElement } from '../../view/DomUtils.js';\nimport type { PasteInterceptor, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../shared/ShortcutFormatting.js';\nimport type { CodeBlockLocale } from './CodeBlockLocale.js';\nimport { CODE_BLOCK_ICON } from './CodeBlockTypes.js';\n\nexport function registerCodeBlockNodeSpec(context: PluginContext): void {\n\tcontext.registerNodeSpec({\n\t\ttype: 'code_block',\n\t\tgroup: 'block',\n\t\tcontent: { allow: ['text'] },\n\t\tselectable: true,\n\t\tattrs: {\n\t\t\tlanguage: { default: '' },\n\t\t\tbackgroundColor: { default: '' },\n\t\t},\n\t\ttoDOM(node) {\n\t\t\tconst pre: HTMLElement = createBlockElement('pre', node.id);\n\t\t\tpre.className = 'notectl-code-block';\n\t\t\tpre.setAttribute('dir', 'ltr');\n\t\t\tpre.setAttribute('part', 'code-block');\n\t\t\tconst code: HTMLElement = document.createElement('code');\n\t\t\tcode.className = 'notectl-code-block__content';\n\t\t\tcode.setAttribute('part', 'code-block-content');\n\t\t\tpre.appendChild(code);\n\t\t\treturn pre;\n\t\t},\n\t\ttoHTML(node, content, ctx?: HTMLExportContext) {\n\t\t\tconst lang: string = escapeHTML((node.attrs?.language as string) ?? '');\n\t\t\tconst bg: string = escapeHTML((node.attrs?.backgroundColor as string) ?? '');\n\t\t\tconst langClass: string = lang ? ` class=\"language-${lang}\"` : '';\n\t\t\tconst bgAttr: string = bg\n\t\t\t\t? (ctx?.styleAttr(`background-color: ${bg}`) ?? ` style=\"background-color: ${bg}\"`)\n\t\t\t\t: '';\n\t\t\treturn `<pre dir=\"ltr\"${bgAttr}><code${langClass}>${content || ''}</code></pre>`;\n\t\t},\n\t\tparseHTML: [\n\t\t\t{\n\t\t\t\ttag: 'pre',\n\t\t\t\tgetAttrs(el: HTMLElement) {\n\t\t\t\t\tconst code: HTMLElement | null = el.querySelector('code');\n\t\t\t\t\tconst langClass: string = code?.className.match(/language-(\\S+)/)?.[1] ?? '';\n\t\t\t\t\tconst dataLang: string = code?.getAttribute('data-language') ?? '';\n\t\t\t\t\treturn {\n\t\t\t\t\t\tlanguage: dataLang || langClass,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: {\n\t\t\ttags: ['pre', 'code'],\n\t\t\tattrs: ['data-language', 'class', 'style'],\n\t\t},\n\t});\n}\n\nexport function registerCodeBlockInputRule(context: PluginContext): void {\n\tcontext.registerInputRule({\n\t\tpattern: /^```(\\w*) $/,\n\t\thandler: (state, match, start, _end) => {\n\t\t\tconst sel = state.selection;\n\t\t\tif (!isTextSelection(sel)) return null;\n\t\t\tif (!isCollapsed(sel)) return null;\n\n\t\t\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\t\t\tif (!block || block.type !== 'paragraph') return null;\n\n\t\t\tconst language: string = match[1] ?? '';\n\t\t\tconst attrs: Record<string, string | number | boolean> = {\n\t\t\t\tlanguage,\n\t\t\t\tbackgroundColor: '',\n\t\t\t};\n\n\t\t\treturn state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(sel.anchor.blockId, start, start + match[0].length)\n\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0))\n\t\t\t\t.build();\n\t\t},\n\t});\n}\n\nexport function registerCodeBlockToolbarItem(\n\tcontext: PluginContext,\n\tlocale: CodeBlockLocale,\n\ttoggleKey: string | null,\n): void {\n\tcontext.registerToolbarItem({\n\t\tid: 'code_block',\n\t\tgroup: 'block',\n\t\ticon: CODE_BLOCK_ICON,\n\t\tlabel: locale.label,\n\t\ttooltip: locale.tooltip(toggleKey ? formatShortcut(toggleKey) : undefined),\n\t\tcommand: 'toggleCodeBlock',\n\t\tisActive: (state) => {\n\t\t\tif (!isTextSelection(state.selection)) return false;\n\t\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\t\treturn block?.type === 'code_block';\n\t\t},\n\t});\n}\n\n/** Strips `addMark` steps targeting a code block so inline marks never apply there. */\nexport function registerCodeBlockMarkGuard(context: PluginContext): void {\n\tcontext.registerMiddleware(\n\t\t(tr, state, next) => {\n\t\t\tconst hasMarkInCodeBlock: boolean = tr.steps.some((step) => {\n\t\t\t\tif (step.type !== 'addMark') return false;\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\t\treturn block?.type === 'code_block';\n\t\t\t});\n\n\t\t\tif (!hasMarkInCodeBlock) {\n\t\t\t\tnext(tr);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst filtered = tr.steps.filter((step) => {\n\t\t\t\tif (step.type !== 'addMark') return true;\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\t\treturn block?.type !== 'code_block';\n\t\t\t});\n\n\t\t\tnext({ ...tr, steps: filtered });\n\t\t},\n\t\t{ name: 'code-block:mark-guard', priority: 50 },\n\t);\n}\n\nexport function registerCodeBlockPasteInterceptor(context: PluginContext): void {\n\tconst handleCodeBlockPaste: PasteInterceptor = (\n\t\tplainText: string,\n\t\t_html: string,\n\t\tstate: EditorState,\n\t): Transaction | null => {\n\t\tif (!plainText) return null;\n\t\tif (!isTextSelection(state.selection)) return null;\n\n\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\tif (!block || block.type !== 'code_block') return null;\n\n\t\tconst builder = state.transaction('paste');\n\n\t\tlet insertBlockId: BlockId = state.selection.anchor.blockId;\n\t\tlet insertOffset: number = state.selection.anchor.offset;\n\n\t\tif (!isCollapsed(state.selection)) {\n\t\t\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\t\t\tif (landingId) {\n\t\t\t\tinsertBlockId = landingId;\n\t\t\t\tinsertOffset = 0;\n\t\t\t}\n\t\t}\n\n\t\tbuilder.insertText(insertBlockId, insertOffset, plainText, []);\n\t\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + plainText.length));\n\n\t\treturn builder.build();\n\t};\n\n\tcontext.registerPasteInterceptor(handleCodeBlockPaste, {\n\t\tname: 'code-block:paste',\n\t\tpriority: 10,\n\t});\n}\n\n/** Extends `table_cell` content to allow nested code blocks, if not already allowed. */\nexport function patchTableCellContent(context: PluginContext): void {\n\tconst registry = context.getSchemaRegistry();\n\tconst cellSpec = registry.getNodeSpec('table_cell');\n\tif (!cellSpec?.content) return;\n\n\tconst currentAllow: readonly string[] = cellSpec.content.allow ?? [];\n\tif (currentAllow.includes('code_block')) return;\n\n\tregistry.removeNodeSpec('table_cell');\n\tregistry.registerNodeSpec({\n\t\t...cellSpec,\n\t\tcontent: {\n\t\t\t...cellSpec.content,\n\t\t\tallow: [...currentAllow, 'code_block'],\n\t\t},\n\t});\n}\n","/**\n * Service API for code blocks.\n * Provides language/background getters and setters.\n */\n\nimport type { BlockAttrs, BlockNode } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport type { SyntaxHighlighter } from './CodeBlockTypes.js';\nimport { CODE_BLOCK_SERVICE_KEY } from './CodeBlockTypes.js';\n\n/** Registers the CodeBlockService on the given context. */\nexport function registerCodeBlockService(\n\tcontext: PluginContext,\n\tgetHighlighter: () => SyntaxHighlighter | null,\n\tgetContext: () => PluginContext | null,\n): void {\n\tcontext.registerService(CODE_BLOCK_SERVICE_KEY, {\n\t\tsetLanguage(bid: BlockId, language: string): void {\n\t\t\tsetAttr(context, bid, 'language', language);\n\t\t},\n\n\t\tgetLanguage(bid: BlockId): string {\n\t\t\tconst ctx: PluginContext | null = getContext();\n\t\t\tif (!ctx) return '';\n\t\t\tconst block: BlockNode | undefined = ctx.getState().getBlock(bid);\n\t\t\tif (!block || block.type !== 'code_block') return '';\n\t\t\treturn (block.attrs?.language as string) ?? '';\n\t\t},\n\n\t\tsetBackground(bid: BlockId, color: string): void {\n\t\t\tsetAttr(context, bid, 'backgroundColor', color);\n\t\t},\n\n\t\tgetBackground(bid: BlockId): string {\n\t\t\tconst ctx: PluginContext | null = getContext();\n\t\t\tif (!ctx) return '';\n\t\t\tconst block: BlockNode | undefined = ctx.getState().getBlock(bid);\n\t\t\tif (!block || block.type !== 'code_block') return '';\n\t\t\treturn (block.attrs?.backgroundColor as string) ?? '';\n\t\t},\n\n\t\tisCodeBlock(bid: BlockId): boolean {\n\t\t\tconst ctx: PluginContext | null = getContext();\n\t\t\tif (!ctx) return false;\n\t\t\tconst block: BlockNode | undefined = ctx.getState().getBlock(bid);\n\t\t\treturn block?.type === 'code_block';\n\t\t},\n\n\t\tgetSupportedLanguages(): readonly string[] {\n\t\t\tconst highlighter: SyntaxHighlighter | null = getHighlighter();\n\t\t\tif (!highlighter) return [];\n\t\t\treturn highlighter.getSupportedLanguages();\n\t\t},\n\t});\n}\n\n// --- Helper ---\n\nfunction setAttr(context: PluginContext, bid: BlockId, key: string, value: string): void {\n\tconst state = context.getState();\n\tconst block: BlockNode | undefined = state.getBlock(bid);\n\tif (!block || block.type !== 'code_block') return;\n\n\tconst path: BlockId[] | undefined = state.getNodePath(bid);\n\tif (!path) return;\n\n\tconst newAttrs: BlockAttrs = { ...block.attrs, [key]: value };\n\tconst tr: Transaction = state.transaction('command').setNodeAttr(path, newAttrs).build();\n\n\tcontext.dispatch(tr);\n}\n","/**\n * Per-block syntax-token cache for the code-block plugin.\n *\n * Holds the tokens produced by the active {@link SyntaxHighlighter} keyed by\n * block id, re-tokenizing only when a block's text or language changes. Lookups\n * use binary search over the cached, range-ordered token list and never trigger\n * a fresh tokenize.\n */\n\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { SyntaxHighlighter, SyntaxToken } from './CodeBlockTypes.js';\n\ninterface CacheEntry {\n\treadonly text: string;\n\treadonly language: string;\n\treadonly tokens: readonly SyntaxToken[];\n}\n\nexport class TokenCache {\n\tprivate readonly entries = new Map<BlockId, CacheEntry>();\n\n\t/**\n\t * Returns the cached tokens for `blockId`, re-tokenizing via `highlighter`\n\t * when the block's text or language has changed since the last call.\n\t * Returns an empty list when no highlighter is available.\n\t */\n\tgetTokens(\n\t\tblockId: BlockId,\n\t\ttext: string,\n\t\tlanguage: string,\n\t\thighlighter: SyntaxHighlighter | null,\n\t): readonly SyntaxToken[] {\n\t\tconst cached: CacheEntry | undefined = this.entries.get(blockId);\n\t\tif (cached && cached.text === text && cached.language === language) {\n\t\t\treturn cached.tokens;\n\t\t}\n\t\tconst tokens: readonly SyntaxToken[] = highlighter?.tokenize(text, language) ?? [];\n\t\tthis.entries.set(blockId, { text, language, tokens });\n\t\treturn tokens;\n\t}\n\n\t/**\n\t * Binary-searches the cached token list for the token whose range covers\n\t * `offset`. Returns `undefined` on cache miss or if the offset lies in a gap\n\t * between tokens.\n\t */\n\tfindTokenAt(blockId: BlockId, offset: number): SyntaxToken | undefined {\n\t\tconst cached: CacheEntry | undefined = this.entries.get(blockId);\n\t\tif (!cached) return undefined;\n\t\tconst tokens: readonly SyntaxToken[] = cached.tokens;\n\t\tlet low = 0;\n\t\tlet high = tokens.length - 1;\n\t\twhile (low <= high) {\n\t\t\tconst mid: number = (low + high) >>> 1;\n\t\t\tconst token: SyntaxToken | undefined = tokens[mid];\n\t\t\tif (!token) return undefined;\n\t\t\tif (offset < token.from) {\n\t\t\t\thigh = mid - 1;\n\t\t\t} else if (offset >= token.to) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\treturn token;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Drops cache entries whose block id is not in `activeIds`. */\n\tretain(activeIds: ReadonlySet<BlockId>): void {\n\t\tfor (const cachedId of this.entries.keys()) {\n\t\t\tif (!activeIds.has(cachedId)) {\n\t\t\t\tthis.entries.delete(cachedId);\n\t\t\t}\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.entries.clear();\n\t}\n}\n","/**\n * CodeBlockPlugin: orchestrates code-block registration by composing focused\n * collaborators — {@link TokenCache} (syntax-token caching), {@link AutoPairController}\n * (bracket/quote pairing), the highlighting setup, the decoration builder, and\n * the static schema/keyboard/command/service registrars.\n *\n * The plugin itself only wires these together and forwards the lifecycle hooks\n * (`decorations`, `onStateChange`, `destroy`).\n */\n\nimport type { DecorationSet } from '../../decorations/Decoration.js';\nimport { CODE_BLOCK_CSS } from '../../editor/styles/code-block.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { resolveLocale } from '../shared/PluginHelpers.js';\nimport { PopupManager } from '../shared/PopupManager.js';\nimport { AutoPairController } from './AutoPairController.js';\nimport { registerCodeBlockCommands } from './CodeBlockCommands.js';\nimport { createCodeBlockDecorations } from './CodeBlockDecorations.js';\nimport { setupHighlighting } from './CodeBlockHighlighting.js';\nimport { registerCodeBlockKeymaps } from './CodeBlockKeyboardHandlers.js';\nimport {\n\tCODE_BLOCK_LOCALE_EN,\n\ttype CodeBlockLocale,\n\tloadCodeBlockLocale,\n} from './CodeBlockLocale.js';\nimport { type LanguagePickerDeps, createCodeBlockNodeViewFactory } from './CodeBlockNodeView.js';\nimport {\n\tpatchTableCellContent,\n\tregisterCodeBlockInputRule,\n\tregisterCodeBlockMarkGuard,\n\tregisterCodeBlockNodeSpec,\n\tregisterCodeBlockPasteInterceptor,\n\tregisterCodeBlockToolbarItem,\n} from './CodeBlockSchema.js';\nimport { registerCodeBlockService } from './CodeBlockService.js';\nimport type {\n\tCodeBlockConfig,\n\tCodeBlockKeymap,\n\tResolvedIndentConfig,\n\tResolvedPairingConfig,\n\tSyntaxHighlighter,\n} from './CodeBlockTypes.js';\nimport {\n\tDEFAULT_CONFIG,\n\tDEFAULT_INDENT,\n\tDEFAULT_KEYMAP,\n\tDEFAULT_PAIRING,\n\tMAX_SPACE_COUNT,\n\tMIN_SPACE_COUNT,\n} from './CodeBlockTypes.js';\nimport { TokenCache } from './TokenCache.js';\n\nexport class CodeBlockPlugin implements Plugin {\n\treadonly id = 'code-block';\n\treadonly name = 'Code Block';\n\treadonly priority = 36;\n\n\tprivate readonly config: CodeBlockConfig;\n\tprivate readonly resolvedIndent: ResolvedIndentConfig;\n\tprivate readonly resolvedPairing: ResolvedPairingConfig;\n\tprivate readonly resolvedKeymap: Readonly<Record<keyof CodeBlockKeymap, string | null>>;\n\tprivate context: PluginContext | null = null;\n\tprivate locale!: CodeBlockLocale;\n\tprivate highlighter: SyntaxHighlighter | null = null;\n\tprivate readonly tokenCache = new TokenCache();\n\tprivate readonly autoPair: AutoPairController;\n\n\tconstructor(config?: Partial<CodeBlockConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t\tthis.resolvedIndent = resolveIndentConfig(this.config);\n\t\tthis.resolvedPairing = resolvePairingConfig(this.config);\n\t\tthis.resolvedKeymap = {\n\t\t\t...DEFAULT_KEYMAP,\n\t\t\t...config?.keymap,\n\t\t};\n\t\tthis.autoPair = new AutoPairController({\n\t\t\tresolvedIndent: this.resolvedIndent,\n\t\t\tresolvedPairing: this.resolvedPairing,\n\t\t\tgetTokenAt: (blockId, offset) => this.tokenCache.findTokenAt(blockId, offset),\n\t\t\tgetCompositionState: () => this.context?.getCompositionState() ?? null,\n\t\t});\n\t}\n\n\tasync init(context: PluginContext): Promise<void> {\n\t\tthis.locale = await resolveLocale(\n\t\t\tcontext,\n\t\t\tthis.config.locale,\n\t\t\tCODE_BLOCK_LOCALE_EN,\n\t\t\tloadCodeBlockLocale,\n\t\t);\n\t\tcontext.registerStyleSheet(CODE_BLOCK_CSS);\n\t\tthis.context = context;\n\n\t\tthis.highlighter = setupHighlighting(context, this.config, this.tokenCache);\n\t\tregisterCodeBlockNodeSpec(context);\n\t\tthis.registerNodeView(context);\n\t\tregisterCodeBlockCommands(context, this.config);\n\t\tregisterCodeBlockKeymaps(context, this.config, this.resolvedKeymap, {\n\t\t\tindent: this.resolvedIndent,\n\t\t\tpairing: this.resolvedPairing,\n\t\t\tpairStack: this.autoPair.pairStack,\n\t\t\tlocale: () => this.locale,\n\t\t});\n\t\tregisterCodeBlockInputRule(context);\n\t\tregisterCodeBlockToolbarItem(context, this.locale, this.resolvedKeymap.toggle);\n\t\tregisterCodeBlockMarkGuard(context);\n\t\tregisterCodeBlockService(\n\t\t\tcontext,\n\t\t\t() => this.highlighter,\n\t\t\t() => this.context,\n\t\t);\n\t\tregisterCodeBlockPasteInterceptor(context);\n\t\tcontext.registerTextInputInterceptor(this.autoPair.handleTextInput, {\n\t\t\tname: 'code-block:auto-pair',\n\t\t\tpriority: 10,\n\t\t});\n\t\tpatchTableCellContent(context);\n\t}\n\n\tdestroy(): void {\n\t\tthis.context = null;\n\t\tthis.highlighter = null;\n\t\tthis.tokenCache.clear();\n\t\tthis.autoPair.clear();\n\t}\n\n\tonStateChange(oldState: EditorState, newState: EditorState, tr: Transaction): void {\n\t\tthis.autoPair.syncOnStateChange(newState, tr);\n\n\t\tif (!this.context) return;\n\n\t\tconst oldBlockId: BlockId | null = !isTextSelection(oldState.selection)\n\t\t\t? null\n\t\t\t: oldState.selection.anchor.blockId;\n\t\tconst newBlockId: BlockId | null = !isTextSelection(newState.selection)\n\t\t\t? null\n\t\t\t: newState.selection.anchor.blockId;\n\n\t\tconst oldBlock: BlockNode | undefined = oldBlockId ? oldState.getBlock(oldBlockId) : undefined;\n\t\tconst newBlock: BlockNode | undefined = newBlockId ? newState.getBlock(newBlockId) : undefined;\n\n\t\tconst wasInCode: boolean = oldBlock?.type === 'code_block';\n\t\tconst nowInCode: boolean = newBlock?.type === 'code_block';\n\n\t\tif (!wasInCode && nowInCode) {\n\t\t\tthis.context.announce(this.locale.enteredCodeBlock);\n\t\t} else if (wasInCode && !nowInCode) {\n\t\t\tthis.context.announce(this.locale.leftCodeBlock);\n\t\t}\n\t}\n\n\tdecorations(state: EditorState): DecorationSet {\n\t\treturn createCodeBlockDecorations(state, {\n\t\t\thighlighter: this.highlighter,\n\t\t\ttokenCache: this.tokenCache,\n\t\t});\n\t}\n\n\tprivate registerNodeView(context: PluginContext): void {\n\t\tconst popupManager: PopupManager = new PopupManager(context.getContainer());\n\t\tconst highlighter = this.highlighter;\n\t\tconst pickerDeps: LanguagePickerDeps = {\n\t\t\tpopupManager,\n\t\t\tgetSupportedLanguages: () => highlighter?.getSupportedLanguages() ?? [],\n\t\t};\n\n\t\tcontext.registerNodeView(\n\t\t\t'code_block',\n\t\t\tcreateCodeBlockNodeViewFactory(this.config, this.locale, pickerDeps),\n\t\t);\n\t}\n}\n\n/**\n * Merges `indent.*` overrides with deprecated top-level `useSpaces`/`spaceCount`\n * fallbacks, and clamps `spaceCount` once into [MIN_SPACE_COUNT, MAX_SPACE_COUNT].\n */\nfunction resolveIndentConfig(config: CodeBlockConfig): ResolvedIndentConfig {\n\tconst useSpaces: boolean =\n\t\tconfig.indent?.useSpaces ?? config.useSpaces ?? DEFAULT_INDENT.useSpaces;\n\tconst rawSpaceCount: number =\n\t\tconfig.indent?.spaceCount ?? config.spaceCount ?? DEFAULT_INDENT.spaceCount;\n\tconst spaceCount: number = Math.max(\n\t\tMIN_SPACE_COUNT,\n\t\tMath.min(MAX_SPACE_COUNT, Math.trunc(rawSpaceCount)),\n\t);\n\tconst mode: 'none' | 'keep' | 'brackets' = config.indent?.mode ?? DEFAULT_INDENT.mode;\n\treturn { mode, useSpaces, spaceCount };\n}\n\nfunction resolvePairingConfig(config: CodeBlockConfig): ResolvedPairingConfig {\n\tconst p = config.pairing;\n\treturn {\n\t\tbrackets: p?.brackets ?? DEFAULT_PAIRING.brackets,\n\t\tquotes: p?.quotes ?? DEFAULT_PAIRING.quotes,\n\t\tovertype: p?.overtype ?? DEFAULT_PAIRING.overtype,\n\t\tdeletePair: p?.deletePair ?? DEFAULT_PAIRING.deletePair,\n\t\tsurround: p?.surround ?? DEFAULT_PAIRING.surround,\n\t};\n}\n"],"mappings":"s/BAWA,IAAa,EAAiB,4tHAPtB,EAAmB,IACxB,GACA,mBAAmB,0CAA6C,+CAAkD,oEAAuE,+BACzL,KAAK,UCyBK,EAA8C,CAC1D,CAAE,KAAM,IAAK,MAAO,IAAK,KAAM,WAC/B,CAAE,KAAM,IAAK,MAAO,IAAK,KAAM,WAC/B,CAAE,KAAM,IAAK,MAAO,IAAK,KAAM,WAC/B,CAAE,KAAM,IAAK,MAAO,IAAK,KAAM,SAC/B,CAAE,KAAM,IAAK,MAAO,IAAK,KAAM,SAC/B,CAAE,KAAM,IAAK,MAAO,IAAK,KAAM,UAG1B,EAAoD,IAAI,IAC7D,EAAiB,IAAK,GAAM,CAAC,EAAE,KAAM,KAEhC,EAAqD,IAAI,IAE9D,EAAiB,OAAQ,GAAiB,YAAX,EAAE,MAAoB,IAAK,GAAM,CAAC,EAAE,MAAO,KC7B3E,IAAM,EAAgB,IAAI,IAAI,CAAC,IAAK,IAAK,MACnC,EAA2D,CAChE,IAAK,IACL,IAAK,IACL,IAAK,KAIN,SAAgB,EAAa,EAAc,GAC1C,MAAM,EAAgB,EAAK,YAAY,KAAM,EAAS,GAAK,EACrD,EAAkB,EAAK,QAAQ,KAAM,GAE3C,MAAO,CAAE,QAAO,KADgB,IAAZ,EAAiB,EAAK,OAAS,EAEpD,CAGA,SAAgB,EAAqB,EAAc,GAClD,MAAM,MAAE,EAAA,IAAO,GAAQ,EAAa,EAAM,GAC1C,IAAI,EAAY,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