@notectl/core 1.7.1 → 1.7.3

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.
Files changed (182) hide show
  1. package/dist/chunks/{AttrRegistry-Ci0qAvtS.mjs → AttrRegistry-D9Jx_RVb.mjs} +2 -2
  2. package/dist/chunks/{AttrRegistry-Ci0qAvtS.mjs.map → AttrRegistry-D9Jx_RVb.mjs.map} +1 -1
  3. package/dist/chunks/AttributedMarkCommands-BtLea72z.mjs +80 -0
  4. package/dist/chunks/AttributedMarkCommands-BtLea72z.mjs.map +1 -0
  5. package/dist/chunks/{CaretNavigation-qLfeL0So.mjs → CaretNavigation-7JYpIKbs.mjs} +3 -3
  6. package/dist/chunks/{CaretNavigation-qLfeL0So.mjs.map → CaretNavigation-7JYpIKbs.mjs.map} +1 -1
  7. package/dist/chunks/{ColorGrid-BBkN0AOb.mjs → ColorGrid--lBQ7jCK.mjs} +56 -55
  8. package/dist/chunks/ColorGrid--lBQ7jCK.mjs.map +1 -0
  9. package/dist/chunks/{ColorPickerPopup-D3ysvOH-.mjs → ColorPickerPopup-TpIRlXc8.mjs} +15 -15
  10. package/dist/chunks/ColorPickerPopup-TpIRlXc8.mjs.map +1 -0
  11. package/dist/chunks/{Document-DfZ1NOjs.mjs → Document-Brtw2jL1.mjs} +6 -6
  12. package/dist/chunks/Document-Brtw2jL1.mjs.map +1 -0
  13. package/dist/chunks/{MarkCommands-uybmkw9l.mjs → MarkCommands-6RUJ4L3r.mjs} +3 -3
  14. package/dist/chunks/MarkCommands-6RUJ4L3r.mjs.map +1 -0
  15. package/dist/chunks/{NodeResolver-CzLmmrph.mjs → NodeResolver-C2XYkeOi.mjs} +2 -2
  16. package/dist/chunks/{NodeResolver-CzLmmrph.mjs.map → NodeResolver-C2XYkeOi.mjs.map} +1 -1
  17. package/dist/chunks/NodeSpec-NZVvcCuH.mjs.map +1 -1
  18. package/dist/chunks/PopupPositioning-CgjgAKjp.mjs +34 -0
  19. package/dist/chunks/PopupPositioning-CgjgAKjp.mjs.map +1 -0
  20. package/dist/chunks/RangeIterator-Bh4Vl_6D.mjs +16 -0
  21. package/dist/chunks/{RangeIterator-Bye0UtbY.mjs.map → RangeIterator-Bh4Vl_6D.mjs.map} +1 -1
  22. package/dist/chunks/StyleRuntime-CP4NCwKT.mjs +235 -0
  23. package/dist/chunks/StyleRuntime-CP4NCwKT.mjs.map +1 -0
  24. package/dist/chunks/ToolbarItem-BpZggUGo.mjs.map +1 -1
  25. package/dist/chunks/{index-Bt_d4IqB.mjs → index--7pBhSF4.mjs} +74 -73
  26. package/dist/chunks/index--7pBhSF4.mjs.map +1 -0
  27. package/dist/chunks/{index-DayTn6Re.mjs → index-BXCkjDax.mjs} +78 -83
  28. package/dist/chunks/index-BXCkjDax.mjs.map +1 -0
  29. package/dist/chunks/{index-DGKQhSAl.mjs → index-BXtw5PNN.mjs} +2 -2
  30. package/dist/chunks/{index-DGKQhSAl.mjs.map → index-BXtw5PNN.mjs.map} +1 -1
  31. package/dist/chunks/{ToolbarPlugin-B7oJRzpl.mjs → index-BcDRT4K2.mjs} +110 -121
  32. package/dist/chunks/index-BcDRT4K2.mjs.map +1 -0
  33. package/dist/chunks/{index-DoCvDkfj.mjs → index-BjFBWBOC.mjs} +23 -25
  34. package/dist/chunks/index-BjFBWBOC.mjs.map +1 -0
  35. package/dist/chunks/{index-CrKz_IEn.mjs → index-C1opJocO.mjs} +2 -2
  36. package/dist/chunks/{index-CrKz_IEn.mjs.map → index-C1opJocO.mjs.map} +1 -1
  37. package/dist/chunks/{index-CfyS_pgH.mjs → index-CCyqQ0Dz.mjs} +32 -31
  38. package/dist/chunks/index-CCyqQ0Dz.mjs.map +1 -0
  39. package/dist/chunks/{index-E7OgN7hM.mjs → index-Cd3uJLP3.mjs} +2 -2
  40. package/dist/chunks/{index-E7OgN7hM.mjs.map → index-Cd3uJLP3.mjs.map} +1 -1
  41. package/dist/chunks/{index-yhz2qeeh.mjs → index-DSAuGP4n.mjs} +131 -127
  42. package/dist/chunks/index-DSAuGP4n.mjs.map +1 -0
  43. package/dist/chunks/{index-CH1r7DL-.mjs → index-DtRfqsq5.mjs} +211 -210
  44. package/dist/chunks/index-DtRfqsq5.mjs.map +1 -0
  45. package/dist/chunks/{index-CFPP456m.mjs → index-DxbQirny.mjs} +8 -8
  46. package/dist/chunks/{index-CFPP456m.mjs.map → index-DxbQirny.mjs.map} +1 -1
  47. package/dist/chunks/{index-DuRNETFv.mjs → index-ErZ5_a1o.mjs} +3 -3
  48. package/dist/chunks/{index-DuRNETFv.mjs.map → index-ErZ5_a1o.mjs.map} +1 -1
  49. package/dist/chunks/{index-Deag_lVi.mjs → index-WpbK_s_H.mjs} +29 -31
  50. package/dist/chunks/index-WpbK_s_H.mjs.map +1 -0
  51. package/dist/chunks/{index-DIvHQtE2.mjs → index-WrqH1wG8.mjs} +15 -14
  52. package/dist/chunks/index-WrqH1wG8.mjs.map +1 -0
  53. package/dist/chunks/{index-Dy6SllXW.mjs → index-fsVJLutn.mjs} +3 -3
  54. package/dist/chunks/{index-Dy6SllXW.mjs.map → index-fsVJLutn.mjs.map} +1 -1
  55. package/dist/chunks/{index-Ckzqtn5D.mjs → index-fx3KIap3.mjs} +15 -14
  56. package/dist/chunks/index-fx3KIap3.mjs.map +1 -0
  57. package/dist/chunks/{index-DmuuFS5D.mjs → index-oOJo-ywB.mjs} +4 -4
  58. package/dist/chunks/{index-DmuuFS5D.mjs.map → index-oOJo-ywB.mjs.map} +1 -1
  59. package/dist/chunks/{index-CFJFD4lF.mjs → index-toj88jtL.mjs} +19 -18
  60. package/dist/chunks/index-toj88jtL.mjs.map +1 -0
  61. package/dist/commands/AttributedMarkCommands.d.ts.map +1 -1
  62. package/dist/commands/MarkCommands.d.ts +3 -3
  63. package/dist/commands/MarkCommands.d.ts.map +1 -1
  64. package/dist/editor/CSSClassCollector.d.ts +36 -0
  65. package/dist/editor/CSSClassCollector.d.ts.map +1 -0
  66. package/dist/editor/ContentHTMLTypes.d.ts +29 -0
  67. package/dist/editor/ContentHTMLTypes.d.ts.map +1 -0
  68. package/dist/editor/ContentStyleInjector.d.ts +69 -0
  69. package/dist/editor/ContentStyleInjector.d.ts.map +1 -0
  70. package/dist/editor/DocumentParser.d.ts +9 -1
  71. package/dist/editor/DocumentParser.d.ts.map +1 -1
  72. package/dist/editor/DocumentSerializer.d.ts +6 -0
  73. package/dist/editor/DocumentSerializer.d.ts.map +1 -1
  74. package/dist/editor/EditorThemeController.d.ts +3 -0
  75. package/dist/editor/EditorThemeController.d.ts.map +1 -1
  76. package/dist/editor/MarkSerializer.d.ts +7 -0
  77. package/dist/editor/MarkSerializer.d.ts.map +1 -1
  78. package/dist/editor/NotectlEditor.d.ts +13 -3
  79. package/dist/editor/NotectlEditor.d.ts.map +1 -1
  80. package/dist/editor/PaperLayoutController.d.ts.map +1 -1
  81. package/dist/editor/styles/font-select.d.ts +1 -1
  82. package/dist/editor/styles/font-select.d.ts.map +1 -1
  83. package/dist/editor/styles/font-size-select.d.ts +1 -1
  84. package/dist/editor/styles/font-size-select.d.ts.map +1 -1
  85. package/dist/editor/styles/heading-select.d.ts +1 -1
  86. package/dist/editor/styles/heading-select.d.ts.map +1 -1
  87. package/dist/editor/styles/toolbar.d.ts +1 -1
  88. package/dist/editor/styles/toolbar.d.ts.map +1 -1
  89. package/dist/index.d.ts +10 -12
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/input/LegacyHTMLNormalizer.d.ts.map +1 -1
  92. package/dist/model/Document.d.ts +0 -4
  93. package/dist/model/Document.d.ts.map +1 -1
  94. package/dist/model/NodeSpec.d.ts +19 -2
  95. package/dist/model/NodeSpec.d.ts.map +1 -1
  96. package/dist/notectl-core.mjs +613 -477
  97. package/dist/notectl-core.mjs.map +1 -1
  98. package/dist/notectl-core.umd.js +1571 -1225
  99. package/dist/notectl-core.umd.js.map +1 -1
  100. package/dist/plugins/alignment/AlignmentPlugin.d.ts.map +1 -1
  101. package/dist/plugins/alignment.mjs +1 -1
  102. package/dist/plugins/caret-navigation.mjs +1 -1
  103. package/dist/plugins/code-block/CodeBlockNodeView.d.ts.map +1 -1
  104. package/dist/plugins/code-block/CodeBlockPlugin.d.ts +0 -1
  105. package/dist/plugins/code-block/CodeBlockPlugin.d.ts.map +1 -1
  106. package/dist/plugins/code-block/index.d.ts +2 -1
  107. package/dist/plugins/code-block/index.d.ts.map +1 -1
  108. package/dist/plugins/code-block.mjs +1 -1
  109. package/dist/plugins/font/FontPlugin.d.ts +0 -1
  110. package/dist/plugins/font/FontPlugin.d.ts.map +1 -1
  111. package/dist/plugins/font-size/FontSizePlugin.d.ts +0 -2
  112. package/dist/plugins/font-size/FontSizePlugin.d.ts.map +1 -1
  113. package/dist/plugins/font-size/FontSizePopup.d.ts +3 -1
  114. package/dist/plugins/font-size/FontSizePopup.d.ts.map +1 -1
  115. package/dist/plugins/font-size.mjs +1 -1
  116. package/dist/plugins/font.mjs +1 -1
  117. package/dist/plugins/gap-cursor.mjs +6 -6
  118. package/dist/plugins/hard-break.mjs +1 -1
  119. package/dist/plugins/heading/HeadingBlockTypePicker.d.ts.map +1 -1
  120. package/dist/plugins/heading.mjs +1 -1
  121. package/dist/plugins/highlight/HighlightPlugin.d.ts.map +1 -1
  122. package/dist/plugins/highlight.mjs +1 -1
  123. package/dist/plugins/horizontal-rule.mjs +1 -1
  124. package/dist/plugins/image/ImageNodeView.d.ts.map +1 -1
  125. package/dist/plugins/image/ImagePlugin.d.ts.map +1 -1
  126. package/dist/plugins/image.mjs +1 -1
  127. package/dist/plugins/link.mjs +1 -1
  128. package/dist/plugins/list/ListPlugin.d.ts.map +1 -1
  129. package/dist/plugins/list.mjs +1 -1
  130. package/dist/plugins/print/PrintContentPreparer.d.ts.map +1 -1
  131. package/dist/plugins/shared/ColorGrid.d.ts.map +1 -1
  132. package/dist/plugins/shared/ColorPickerPopup.d.ts +2 -1
  133. package/dist/plugins/shared/ColorPickerPopup.d.ts.map +1 -1
  134. package/dist/plugins/shared/PopupManager.d.ts +12 -2
  135. package/dist/plugins/shared/PopupManager.d.ts.map +1 -1
  136. package/dist/plugins/shared/PopupPositioning.d.ts.map +1 -1
  137. package/dist/plugins/strikethrough.mjs +1 -1
  138. package/dist/plugins/super-sub.mjs +1 -1
  139. package/dist/plugins/table/TableContextMenu.d.ts.map +1 -1
  140. package/dist/plugins/table/TableControls.d.ts.map +1 -1
  141. package/dist/plugins/table/TableControlsDOM.d.ts.map +1 -1
  142. package/dist/plugins/table/TableControlsLayout.d.ts.map +1 -1
  143. package/dist/plugins/table/TableNodeViews.d.ts.map +1 -1
  144. package/dist/plugins/table/TablePlugin.d.ts.map +1 -1
  145. package/dist/plugins/table.mjs +1 -1
  146. package/dist/plugins/text-color/TextColorPlugin.d.ts.map +1 -1
  147. package/dist/plugins/text-color.mjs +1 -1
  148. package/dist/plugins/text-formatting.mjs +1 -1
  149. package/dist/plugins/toolbar/ToolbarItem.d.ts +3 -2
  150. package/dist/plugins/toolbar/ToolbarItem.d.ts.map +1 -1
  151. package/dist/plugins/toolbar/ToolbarOverflowController.d.ts.map +1 -1
  152. package/dist/plugins/toolbar/ToolbarPopupController.d.ts +0 -3
  153. package/dist/plugins/toolbar/ToolbarPopupController.d.ts.map +1 -1
  154. package/dist/plugins/toolbar/ToolbarRenderers.d.ts.map +1 -1
  155. package/dist/plugins/toolbar/ToolbarTooltip.d.ts.map +1 -1
  156. package/dist/plugins/toolbar.mjs +2 -2
  157. package/dist/presets/PresetTypes.d.ts +1 -1
  158. package/dist/presets/PresetTypes.d.ts.map +1 -1
  159. package/dist/style/StyleRuntime.d.ts +34 -0
  160. package/dist/style/StyleRuntime.d.ts.map +1 -0
  161. package/dist/view/Reconciler.d.ts.map +1 -1
  162. package/package.json +1 -1
  163. package/dist/chunks/AttributedMarkCommands-BETuHXj8.mjs +0 -58
  164. package/dist/chunks/AttributedMarkCommands-BETuHXj8.mjs.map +0 -1
  165. package/dist/chunks/ColorGrid-BBkN0AOb.mjs.map +0 -1
  166. package/dist/chunks/ColorPickerPopup-D3ysvOH-.mjs.map +0 -1
  167. package/dist/chunks/Document-DfZ1NOjs.mjs.map +0 -1
  168. package/dist/chunks/MarkCommands-uybmkw9l.mjs.map +0 -1
  169. package/dist/chunks/PopupPositioning-Cn6L_mO2.mjs +0 -30
  170. package/dist/chunks/PopupPositioning-Cn6L_mO2.mjs.map +0 -1
  171. package/dist/chunks/RangeIterator-Bye0UtbY.mjs +0 -16
  172. package/dist/chunks/ToolbarPlugin-B7oJRzpl.mjs.map +0 -1
  173. package/dist/chunks/index-Bt_d4IqB.mjs.map +0 -1
  174. package/dist/chunks/index-CFJFD4lF.mjs.map +0 -1
  175. package/dist/chunks/index-CH1r7DL-.mjs.map +0 -1
  176. package/dist/chunks/index-CfyS_pgH.mjs.map +0 -1
  177. package/dist/chunks/index-Ckzqtn5D.mjs.map +0 -1
  178. package/dist/chunks/index-DIvHQtE2.mjs.map +0 -1
  179. package/dist/chunks/index-DayTn6Re.mjs.map +0 -1
  180. package/dist/chunks/index-Deag_lVi.mjs.map +0 -1
  181. package/dist/chunks/index-DoCvDkfj.mjs.map +0 -1
  182. package/dist/chunks/index-yhz2qeeh.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolbarPlugin-B7oJRzpl.mjs","sources":["../../src/plugins/shared/PopupManager.ts","../../src/editor/styles/toolbar.ts","../../src/plugins/toolbar/ToolbarLocale.ts","../../src/plugins/toolbar/ToolbarOverflowBehavior.ts","../../src/plugins/toolbar/ToolbarOverflowController.ts","../../src/plugins/toolbar/ToolbarRenderers.ts","../../src/plugins/toolbar/ToolbarPopupController.ts","../../src/plugins/toolbar/ToolbarTooltip.ts","../../src/plugins/toolbar/ToolbarPlugin.ts"],"sourcesContent":["/**\n * Central popup lifecycle manager. Handles creation, positioning,\n * click-outside closing, Escape key, focus restoration, and popup stacking\n * for submenus/nested popups.\n */\n\nimport { ServiceKey } from '../Plugin.js';\nimport { type PopupPosition, appendToRoot, positionPopup } from './PopupPositioning.js';\n\n// --- Types ---\n\nexport interface PopupConfig {\n\treadonly anchor: HTMLElement | DOMRect;\n\treadonly content: (container: HTMLElement, close: () => void) => void;\n\treadonly className?: string;\n\treadonly ariaRole?: 'menu' | 'listbox' | 'grid' | 'dialog';\n\treadonly ariaLabel?: string;\n\treadonly restoreFocusTo?: HTMLElement;\n\treadonly onClose?: () => void;\n\treadonly position?: PopupPosition;\n\treadonly parent?: PopupHandle;\n\treadonly referenceNode?: Node;\n}\n\nexport interface PopupHandle {\n\tclose(): void;\n\tgetElement(): HTMLElement;\n}\n\nexport interface PopupServiceAPI {\n\topen(config: PopupConfig): PopupHandle;\n\tclose(): void;\n\tcloseAll(): void;\n\tisOpen(): boolean;\n}\n\nexport const PopupServiceKey = new ServiceKey<PopupServiceAPI>('popup');\n\n// --- Internal Entry ---\n\ninterface PopupEntry {\n\treadonly element: HTMLElement;\n\treadonly config: PopupConfig;\n\treadonly clickOutsideHandler: (e: MouseEvent) => void;\n\treadonly parent: PopupEntry | null;\n}\n\n// --- Manager ---\n\nexport class PopupManager implements PopupServiceAPI {\n\tprivate readonly stack: PopupEntry[] = [];\n\tprivate readonly referenceNode: Node;\n\n\tconstructor(referenceNode: Node) {\n\t\tthis.referenceNode = referenceNode;\n\t}\n\n\t/** Opens a popup with the given configuration. Returns a handle for closing it. */\n\topen(config: PopupConfig): PopupHandle {\n\t\tconst popup: HTMLDivElement = document.createElement('div');\n\t\tpopup.className = config.className ? `notectl-popup ${config.className}` : 'notectl-popup';\n\n\t\tif (config.ariaRole) {\n\t\t\tpopup.setAttribute('role', config.ariaRole);\n\t\t}\n\t\tif (config.ariaLabel) {\n\t\t\tpopup.setAttribute('aria-label', config.ariaLabel);\n\t\t}\n\n\t\tconst handle: PopupHandle = {\n\t\t\tclose: () => this.closeEntry(entry),\n\t\t\tgetElement: () => popup,\n\t\t};\n\n\t\tconfig.content(popup, () => this.closeEntry(entry));\n\n\t\tconst refNode: Node = config.referenceNode ?? this.referenceNode;\n\t\tappendToRoot(popup, refNode);\n\n\t\tconst anchorRect: DOMRect =\n\t\t\tconfig.anchor instanceof HTMLElement ? config.anchor.getBoundingClientRect() : config.anchor;\n\t\tpositionPopup(popup, anchorRect, {\n\t\t\tposition: config.position ?? 'below-start',\n\t\t});\n\n\t\tconst parentEntry: PopupEntry | null = config.parent\n\t\t\t? this.findEntryByHandle(config.parent)\n\t\t\t: null;\n\n\t\tconst clickOutsideHandler = (e: MouseEvent): void => {\n\t\t\tconst path: EventTarget[] = e.composedPath();\n\t\t\tif (path.includes(popup)) return;\n\n\t\t\t// Don't close if click is inside any ancestor popup in the stack\n\t\t\tfor (const stackEntry of this.stack) {\n\t\t\t\tif (path.includes(stackEntry.element)) return;\n\t\t\t}\n\n\t\t\t// Don't close if click is on the anchor element\n\t\t\tif (config.anchor instanceof HTMLElement && path.includes(config.anchor)) return;\n\n\t\t\tthis.closeEntry(entry);\n\t\t};\n\n\t\tconst entry: PopupEntry = {\n\t\t\telement: popup,\n\t\t\tconfig,\n\t\t\tclickOutsideHandler,\n\t\t\tparent: parentEntry,\n\t\t};\n\n\t\tthis.stack.push(entry);\n\n\t\tsetTimeout(() => {\n\t\t\tdocument.addEventListener('mousedown', clickOutsideHandler);\n\t\t}, 0);\n\n\t\tthis.focusFirstItem(popup);\n\n\t\treturn handle;\n\t}\n\n\t/** Closes the topmost popup in the stack. */\n\tclose(): void {\n\t\tconst top: PopupEntry | undefined = this.stack[this.stack.length - 1];\n\t\tif (top) {\n\t\t\tthis.closeEntry(top);\n\t\t}\n\t}\n\n\t/** Closes all open popups. */\n\tcloseAll(): void {\n\t\twhile (this.stack.length > 0) {\n\t\t\tconst top: PopupEntry | undefined = this.stack[this.stack.length - 1];\n\t\t\tif (top) {\n\t\t\t\tthis.closeEntry(top);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Returns true if any popup is currently open. */\n\tisOpen(): boolean {\n\t\treturn this.stack.length > 0;\n\t}\n\n\t/** Cleans up all popups and event listeners. */\n\tdestroy(): void {\n\t\tthis.closeAll();\n\t}\n\n\t// --- Internal ---\n\n\tprivate closeEntry(entry: PopupEntry): void {\n\t\tconst index: number = this.stack.indexOf(entry);\n\t\tif (index === -1) return;\n\n\t\t// Close all child popups first (anything above this entry in the stack)\n\t\twhile (this.stack.length > index + 1) {\n\t\t\tconst child: PopupEntry | undefined = this.stack[this.stack.length - 1];\n\t\t\tif (child) {\n\t\t\t\tthis.removeEntry(child);\n\t\t\t}\n\t\t}\n\n\t\tthis.removeEntry(entry);\n\n\t\tif (entry.config.restoreFocusTo) {\n\t\t\tentry.config.restoreFocusTo.focus();\n\t\t}\n\t\tentry.config.onClose?.();\n\t}\n\n\tprivate removeEntry(entry: PopupEntry): void {\n\t\tconst index: number = this.stack.indexOf(entry);\n\t\tif (index === -1) return;\n\n\t\tthis.stack.splice(index, 1);\n\t\tentry.element.remove();\n\t\tdocument.removeEventListener('mousedown', entry.clickOutsideHandler);\n\t}\n\n\tprivate findEntryByHandle(handle: PopupHandle): PopupEntry | null {\n\t\tconst element: HTMLElement = handle.getElement();\n\t\treturn this.stack.find((e) => e.element === element) ?? null;\n\t}\n\n\tprivate focusFirstItem(popup: HTMLElement): void {\n\t\trequestAnimationFrame(() => {\n\t\t\tconst firstFocusable: HTMLElement | null =\n\t\t\t\tpopup.querySelector('[role=\"menuitem\"]') ??\n\t\t\t\tpopup.querySelector('[role=\"option\"]') ??\n\t\t\t\tpopup.querySelector('[role=\"gridcell\"]') ??\n\t\t\t\tpopup.querySelector('input') ??\n\t\t\t\tpopup.querySelector('button');\n\t\t\tfirstFocusable?.focus();\n\t\t});\n\t}\n}\n","/** Toolbar styles — buttons, separators, tooltips, popups, dropdowns. */\nexport const TOOLBAR_CSS = `\n/* Toolbar */\n.notectl-plugin-container--top {\n\tdisplay: flex;\n\talign-items: center;\n\tflex-wrap: nowrap;\n\tborder-bottom: 1px solid var(--notectl-border);\n\tbackground: var(--notectl-toolbar-bg, var(--notectl-surface-raised));\n\tmin-height: 40px;\n}\n\n.notectl-toolbar {\n\tdisplay: flex;\n\talign-items: center;\n\tflex-wrap: nowrap;\n\toverflow: hidden;\n\tflex: 1;\n\tmin-width: 0;\n\tgap: 2px;\n\tpadding: 4px 8px;\n}\n\n.notectl-toolbar[hidden] {\n\tdisplay: none;\n}\n\n.notectl-toolbar-btn {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 32px;\n\theight: 32px;\n\tborder: 1px solid transparent;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcursor: pointer;\n\tcolor: var(--notectl-fg);\n\tfont-size: 14px;\n\tline-height: 1;\n\tpadding: 0;\n\tflex-shrink: 0;\n\ttransition: background 0.1s, border-color 0.1s;\n}\n\n.notectl-toolbar-btn:hover {\n\tbackground: var(--notectl-hover-bg);\n\tborder-color: var(--notectl-border);\n}\n\n.notectl-toolbar-btn--active {\n\tbackground: var(--notectl-active-bg);\n\tborder-color: var(--notectl-primary-muted);\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-toolbar-btn:focus-visible {\n\tbox-shadow: 0 0 0 2px var(--notectl-focus-ring);\n\toutline: none;\n}\n\n.notectl-toolbar-btn:disabled {\n\topacity: 0.4;\n\tcursor: not-allowed;\n}\n\n.notectl-toolbar-btn:disabled:hover {\n\tbackground: transparent;\n\tborder-color: transparent;\n}\n\n.notectl-toolbar-btn__icon {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\tpointer-events: none;\n}\n\n.notectl-toolbar-btn__icon svg {\n\tdisplay: block;\n\twidth: 18px;\n\theight: 18px;\n\tfill: currentColor;\n}\n\n/* Tooltip (rendered as fixed-position element in shadow root) */\n.notectl-toolbar-tooltip {\n\tposition: fixed;\n\tpadding: 4px 8px;\n\tborder-radius: 4px;\n\tbackground: var(--notectl-tooltip-bg);\n\tcolor: var(--notectl-tooltip-fg);\n\tfont-size: 11px;\n\tfont-weight: 500;\n\twhite-space: nowrap;\n\tpointer-events: none;\n\tz-index: 10001;\n\tline-height: 1.4;\n\tletter-spacing: 0.01em;\n\tfont-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n}\n\n.notectl-toolbar-separator {\n\tdisplay: inline-block;\n\twidth: 1px;\n\theight: 20px;\n\tbackground: var(--notectl-border);\n\tmargin: 0 4px;\n\tvertical-align: middle;\n}\n\n/* Toolbar Popups */\n.notectl-toolbar-popup {\n\tbackground: var(--notectl-surface-overlay);\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 6px;\n\tbox-shadow: 0 4px 12px var(--notectl-shadow);\n\toverflow: hidden;\n}\n\n/* Grid Picker */\n.notectl-grid-picker__cell:focus-visible {\n\toutline: 2px solid var(--notectl-focus-ring);\n\toutline-offset: -1px;\n}\n\n.notectl-grid-picker__cell--highlighted {\n\tbackground: var(--notectl-primary-muted);\n\tborder-color: var(--notectl-primary);\n}\n\n/* Dropdown */\n.notectl-dropdown {\n\tmin-width: 160px;\n\tpadding: 4px 0;\n}\n\n.notectl-dropdown__item {\n\tdisplay: flex;\n\talign-items: center;\n\twidth: 100%;\n\tpadding: 8px 12px;\n\ttext-align: left;\n\tborder: none;\n\tbackground: none;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tcolor: var(--notectl-fg);\n\tline-height: 1.4;\n\tfont-family: inherit;\n\twhite-space: nowrap;\n}\n\n.notectl-dropdown__item:hover,\n.notectl-dropdown__item:focus-visible {\n\tbackground: var(--notectl-hover-bg);\n}\n\n.notectl-dropdown__item:focus-visible {\n\toutline: none;\n}\n\n.notectl-dropdown__item-icon {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 28px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-fg-muted);\n\tflex-shrink: 0;\n}\n\n.notectl-dropdown__item-label {\n\tflex: 1;\n}\n\n/* Overflow behavior: flow mode — toolbar wraps to additional rows */\n.notectl-toolbar[data-overflow=\"flow\"] {\n\tflex-wrap: wrap;\n\toverflow: visible;\n}\n\n/* Overflow behavior: none — toolbar clips without any responsive behavior */\n.notectl-toolbar[data-overflow=\"none\"] {\n\tflex-wrap: nowrap;\n\toverflow: hidden;\n}\n\n/* Overflow: hidden items (burger-menu mode) */\n.notectl-toolbar-btn--overflow-hidden,\n.notectl-toolbar-separator--overflow-hidden {\n\tdisplay: none;\n}\n\n/* Overflow \"more\" button */\n.notectl-toolbar-overflow-btn {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 32px;\n\theight: 32px;\n\tborder: 1px solid transparent;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcursor: pointer;\n\tcolor: var(--notectl-fg);\n\tfont-size: 16px;\n\tline-height: 1;\n\tpadding: 0;\n\tflex-shrink: 0;\n\tmargin-left: auto;\n\ttransition: background 0.1s, border-color 0.1s;\n}\n\n.notectl-toolbar-overflow-btn:hover {\n\tbackground: var(--notectl-hover-bg);\n\tborder-color: var(--notectl-border);\n}\n\n.notectl-toolbar-overflow-btn--hidden {\n\tdisplay: none;\n}\n\n.notectl-toolbar-overflow-btn:focus-visible {\n\tbox-shadow: 0 0 0 2px var(--notectl-focus-ring);\n\toutline: none;\n}\n\n/* Dropdown item states shared by all dropdown menus (including overflow) */\n.notectl-dropdown__item:disabled {\n\topacity: 0.4;\n\tcursor: not-allowed;\n}\n\n.notectl-dropdown__item:disabled:hover {\n\tbackground: none;\n}\n\n.notectl-dropdown__item--active {\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-dropdown__item-icon svg {\n\tdisplay: block;\n\twidth: 16px;\n\theight: 16px;\n\tfill: currentColor;\n}\n\n.notectl-dropdown__separator {\n\theight: 1px;\n\tbackground: var(--notectl-border);\n\tmargin: 4px 0;\n}\n\n/* Combobox-style toolbar buttons (shared base for font, fontSize, heading, etc.) */\n.notectl-toolbar-btn[role=\"combobox\"] {\n\twidth: auto;\n\tpadding: 0 8px;\n\tgap: 4px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-bg);\n}\n\n.notectl-toolbar-btn[role=\"combobox\"]:hover {\n\tbackground: var(--notectl-hover-bg);\n\tborder-color: var(--notectl-fg-muted);\n}\n\n.notectl-toolbar-btn[role=\"combobox\"].notectl-toolbar-btn--active {\n\tbackground: var(--notectl-bg);\n\tborder-color: var(--notectl-primary-muted);\n}\n\n.notectl-toolbar-combobox__label {\n\tflex: 1;\n\tfont-size: 13px;\n\tfont-weight: 500;\n\tcolor: var(--notectl-fg);\n\twhite-space: nowrap;\n\toverflow: hidden;\n\ttext-overflow: ellipsis;\n\ttext-align: left;\n\tline-height: 30px;\n}\n\n.notectl-toolbar-combobox__arrow {\n\tflex-shrink: 0;\n\tfont-size: 11px;\n\tcolor: var(--notectl-fg-muted);\n\tline-height: 30px;\n}\n\n/* Link Popup */\n.notectl-link-popup {\n\tpadding: 8px;\n\tmin-width: 200px;\n}\n\n.notectl-link-popup__input {\n\twidth: 100%;\n\tpadding: 4px;\n\tbox-sizing: border-box;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg);\n\tbackground: var(--notectl-bg);\n}\n\n.notectl-link-popup__input:focus-visible {\n\toutline: 2px solid var(--notectl-focus-ring);\n\toutline-offset: -1px;\n}\n\n.notectl-link-popup__button {\n\twidth: 100%;\n\tpadding: 6px 12px;\n\tcursor: pointer;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-bg);\n\tcolor: var(--notectl-fg);\n\tfont-size: 13px;\n}\n\n.notectl-link-popup__button--apply {\n\tmargin-top: 4px;\n}\n\n.notectl-link-popup__button:hover {\n\tbackground: var(--notectl-hover-bg);\n}\n\n.notectl-link-popup__button:focus-visible {\n\toutline: 2px solid var(--notectl-focus-ring);\n\toutline-offset: -1px;\n}\n`;\n","/** Locale interface and default English locale for the ToolbarPlugin. */\n\n// --- Locale Interface ---\n\nexport interface ToolbarLocale {\n\treadonly formattingOptionsAria: string;\n\treadonly moreToolsAria: string;\n}\n\n// --- Default English Locale ---\n\nexport const TOOLBAR_LOCALE_EN: ToolbarLocale = {\n\tformattingOptionsAria: 'Formatting options',\n\tmoreToolsAria: 'More tools',\n};\n\n// --- German Locale ---\n\nexport const TOOLBAR_LOCALE_DE: ToolbarLocale = {\n\tformattingOptionsAria: 'Formatierungsoptionen',\n\tmoreToolsAria: 'Weitere Werkzeuge',\n};\n\n// --- Spanish Locale ---\n\nexport const TOOLBAR_LOCALE_ES: ToolbarLocale = {\n\tformattingOptionsAria: 'Opciones de formato',\n\tmoreToolsAria: 'Más herramientas',\n};\n\n// --- French Locale ---\n\nexport const TOOLBAR_LOCALE_FR: ToolbarLocale = {\n\tformattingOptionsAria: 'Options de mise en forme',\n\tmoreToolsAria: \"Plus d'outils\",\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const TOOLBAR_LOCALE_ZH: ToolbarLocale = {\n\tformattingOptionsAria: '格式选项',\n\tmoreToolsAria: '更多工具',\n};\n\n// --- Russian Locale ---\n\nexport const TOOLBAR_LOCALE_RU: ToolbarLocale = {\n\tformattingOptionsAria: 'Параметры форматирования',\n\tmoreToolsAria: 'Другие инструменты',\n};\n\n// --- Arabic Locale ---\n\nexport const TOOLBAR_LOCALE_AR: ToolbarLocale = {\n\tformattingOptionsAria: 'خيارات التنسيق',\n\tmoreToolsAria: 'أدوات إضافية',\n};\n\n// --- Hindi Locale ---\n\nexport const TOOLBAR_LOCALE_HI: ToolbarLocale = {\n\tformattingOptionsAria: 'फ़ॉर्मेटिंग विकल्प',\n\tmoreToolsAria: 'और उपकरण',\n};\n\n// --- Locale Map ---\n\nexport const TOOLBAR_LOCALES: Record<string, ToolbarLocale> = {\n\ten: TOOLBAR_LOCALE_EN,\n\tde: TOOLBAR_LOCALE_DE,\n\tes: TOOLBAR_LOCALE_ES,\n\tfr: TOOLBAR_LOCALE_FR,\n\tzh: TOOLBAR_LOCALE_ZH,\n\tru: TOOLBAR_LOCALE_RU,\n\tar: TOOLBAR_LOCALE_AR,\n\thi: TOOLBAR_LOCALE_HI,\n};\n","/**\n * Controls how the toolbar responds when items exceed the available width.\n *\n * @example\n * ```typescript\n * const editor = await createEditor({\n * toolbar: {\n * groups: [[BoldPlugin, ItalicPlugin], [HeadingPlugin]],\n * overflow: ToolbarOverflowBehavior.Flow,\n * },\n * });\n * ```\n */\nexport const ToolbarOverflowBehavior = {\n\t/** Items that don't fit are hidden behind a \"...\" dropdown button. Default. */\n\tBurgerMenu: 'burger-menu',\n\t/** Toolbar wraps to additional rows when items overflow. Pure CSS, no JS measurement. */\n\tFlow: 'flow',\n\t/** No responsive behavior; the toolbar clips at the container boundary. */\n\tNone: 'none',\n} as const;\n\nexport type ToolbarOverflowBehavior =\n\t(typeof ToolbarOverflowBehavior)[keyof typeof ToolbarOverflowBehavior];\n","/**\n * ToolbarOverflowController: manages responsive toolbar overflow.\n * Uses ResizeObserver to detect when items exceed available width,\n * hides overflow items, and shows a \"more\" dropdown button.\n * Delegates popup lifecycle to PopupManager when available.\n */\n\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { PluginContext } from '../Plugin.js';\nimport type { PopupHandle, PopupManager } from '../shared/PopupManager.js';\nimport { appendToRoot } from '../shared/PopupPositioning.js';\nimport type { ToolbarItem } from './ToolbarItem.js';\nimport { findNextDropdownItem } from './ToolbarKeyboardNav.js';\n\n// --- Types ---\n\ninterface OverflowEntry {\n\treadonly element: HTMLButtonElement;\n\treadonly item: ToolbarItem;\n}\n\ntype OnOverflowChange = (\n\tvisibleButtons: readonly HTMLButtonElement[],\n\toverflowButton: HTMLButtonElement | null,\n) => void;\n\ntype OnItemActivated = (overflowButton: HTMLButtonElement, item: ToolbarItem) => void;\n\nexport interface OverflowControllerConfig {\n\treadonly toolbar: HTMLElement;\n\treadonly ariaLabel: string;\n\treadonly context: PluginContext;\n\treadonly onOverflowChange: OnOverflowChange;\n\treadonly onItemActivated: OnItemActivated;\n\treadonly getActiveElement: () => Element | null;\n\treadonly popupManager?: PopupManager;\n}\n\n// --- Constants ---\n\nconst OVERFLOW_BTN_WIDTH = 34;\nconst GAP = 2;\nconst HIDDEN_BTN_CLASS = 'notectl-toolbar-btn--overflow-hidden';\nconst HIDDEN_SEP_CLASS = 'notectl-toolbar-separator--overflow-hidden';\nconst HIDDEN_OVERFLOW_CLASS = 'notectl-toolbar-overflow-btn--hidden';\nconst ELLIPSIS_SVG =\n\t'<svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\"><circle cx=\"3\" cy=\"8\" r=\"1.5\" fill=\"currentColor\"/><circle cx=\"8\" cy=\"8\" r=\"1.5\" fill=\"currentColor\"/><circle cx=\"13\" cy=\"8\" r=\"1.5\" fill=\"currentColor\"/></svg>';\n\n// --- Controller ---\n\nexport class ToolbarOverflowController {\n\tprivate readonly toolbar: HTMLElement;\n\tprivate readonly context: PluginContext;\n\tprivate readonly onOverflowChange: OnOverflowChange;\n\tprivate readonly onItemActivated: OnItemActivated;\n\tprivate readonly getActiveElement: () => Element | null;\n\tprivate readonly ariaLabel: string;\n\tprivate readonly popupManager: PopupManager | null;\n\n\tprivate entries: OverflowEntry[] = [];\n\tprivate overflowButton: HTMLButtonElement | null = null;\n\tprivate overflowDropdown: HTMLElement | null = null;\n\tprivate overflowHandle: PopupHandle | null = null;\n\tprivate overflowEntries: OverflowEntry[] = [];\n\tprivate resizeObserver: ResizeObserver | null = null;\n\tprivate closeHandler: ((e: MouseEvent) => void) | null = null;\n\n\tconstructor(config: OverflowControllerConfig) {\n\t\tthis.toolbar = config.toolbar;\n\t\tthis.ariaLabel = config.ariaLabel;\n\t\tthis.context = config.context;\n\t\tthis.onOverflowChange = config.onOverflowChange;\n\t\tthis.onItemActivated = config.onItemActivated;\n\t\tthis.getActiveElement = config.getActiveElement;\n\t\tthis.popupManager = config.popupManager ?? null;\n\n\t\tthis.resizeObserver = new ResizeObserver(() => this.recalculate());\n\t\tthis.resizeObserver.observe(this.toolbar);\n\t}\n\n\t/** Called after renderItems() — stores button references and recalculates. */\n\tupdate(buttons: readonly { element: HTMLButtonElement; item: ToolbarItem }[]): void {\n\t\tthis.entries = buttons.map((b) => ({ element: b.element, item: b.item }));\n\t\tthis.recalculate();\n\t}\n\n\t/** Measures toolbar and redistributes items between visible and overflow. */\n\trecalculate(): void {\n\t\tif (this.entries.length === 0) return;\n\n\t\tthis.closeDropdown();\n\t\tthis.resetVisibility();\n\t\tthis.ensureOverflowButton();\n\t\tthis.setOverflowButtonVisible(false);\n\n\t\t// Phase 1 — Measure (reads only): batch all layout reads before any writes\n\t\tconst availableWidth: number = this.measureAvailableWidth();\n\t\tconst children: HTMLElement[] = Array.from(this.toolbar.children) as HTMLElement[];\n\t\tconst childWidths: Map<HTMLElement, number> = this.measureChildWidths(children);\n\n\t\t// Phase 2 — Apply (writes only): use cached widths, no layout reads\n\t\tconst maxWidth: number = availableWidth - OVERFLOW_BTN_WIDTH - GAP;\n\t\tlet usedWidth = 0;\n\t\tlet overflowing = false;\n\t\tconst overflowList: OverflowEntry[] = [];\n\n\t\tfor (const child of children) {\n\t\t\tif (child === this.overflowButton) continue;\n\n\t\t\tif (child.classList.contains('notectl-toolbar-separator')) {\n\t\t\t\tif (overflowing) {\n\t\t\t\t\tchild.classList.add(HIDDEN_SEP_CLASS);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst sepWidth: number = (childWidths.get(child) ?? 0) + GAP;\n\t\t\t\tif (usedWidth + sepWidth > maxWidth) {\n\t\t\t\t\toverflowing = true;\n\t\t\t\t\tchild.classList.add(HIDDEN_SEP_CLASS);\n\t\t\t\t} else {\n\t\t\t\t\tusedWidth += sepWidth;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst entry: OverflowEntry | undefined = this.entries.find((oe) => oe.element === child);\n\t\t\tif (!entry) continue;\n\n\t\t\tif (overflowing) {\n\t\t\t\tentry.element.classList.add(HIDDEN_BTN_CLASS);\n\t\t\t\toverflowList.push(entry);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst btnWidth: number = (childWidths.get(child) ?? 0) + GAP;\n\t\t\tif (usedWidth + btnWidth > maxWidth) {\n\t\t\t\toverflowing = true;\n\t\t\t\tentry.element.classList.add(HIDDEN_BTN_CLASS);\n\t\t\t\toverflowList.push(entry);\n\t\t\t} else {\n\t\t\t\tusedWidth += btnWidth;\n\t\t\t}\n\t\t}\n\n\t\tthis.overflowEntries = overflowList;\n\t\tthis.hideTrailingSeparators();\n\t\tthis.setOverflowButtonVisible(overflowList.length > 0);\n\t\tthis.notifyChange();\n\t}\n\n\t/** Updates active/disabled states for items in the open overflow dropdown. */\n\tupdateItemStates(state: EditorState): void {\n\t\tif (!this.overflowDropdown) return;\n\n\t\tconst menuItems: HTMLButtonElement[] = Array.from(\n\t\t\tthis.overflowDropdown.querySelectorAll('.notectl-dropdown__item'),\n\t\t) as HTMLButtonElement[];\n\n\t\tfor (const menuItem of menuItems) {\n\t\t\tconst itemId: string | null = menuItem.getAttribute('data-toolbar-item');\n\t\t\tconst entry: OverflowEntry | undefined = this.overflowEntries.find(\n\t\t\t\t(oe) => oe.item.id === itemId,\n\t\t\t);\n\t\t\tif (!entry) continue;\n\n\t\t\tconst active: boolean = entry.item.isActive?.(state) ?? false;\n\t\t\tconst enabled: boolean = entry.item.isEnabled?.(state) ?? true;\n\t\t\tmenuItem.classList.toggle('notectl-dropdown__item--active', active);\n\t\t\tmenuItem.disabled = !enabled;\n\n\t\t\tif (entry.item.popupType === 'combobox') {\n\t\t\t\tconst labelEl: HTMLSpanElement | null = menuItem.querySelector(\n\t\t\t\t\t'.notectl-dropdown__item-label',\n\t\t\t\t);\n\t\t\t\tif (labelEl) {\n\t\t\t\t\tlabelEl.textContent = entry.item.getLabel(state);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Cleans up ResizeObserver, DOM elements, and event listeners. */\n\tdestroy(): void {\n\t\tthis.resizeObserver?.disconnect();\n\t\tthis.resizeObserver = null;\n\t\tthis.closeDropdown();\n\t\tthis.overflowButton?.remove();\n\t\tthis.overflowButton = null;\n\t\tthis.entries = [];\n\t\tthis.overflowEntries = [];\n\t}\n\n\t// --- Measurement ---\n\n\tprivate measureChildWidths(children: readonly HTMLElement[]): Map<HTMLElement, number> {\n\t\tconst widths: Map<HTMLElement, number> = new Map();\n\t\tfor (const child of children) {\n\t\t\tif (child === this.overflowButton) continue;\n\t\t\twidths.set(child, child.offsetWidth);\n\t\t}\n\t\treturn widths;\n\t}\n\n\tprivate measureAvailableWidth(): number {\n\t\tconst toolbarStyle: CSSStyleDeclaration = getComputedStyle(this.toolbar);\n\t\tconst paddingLeft: number = Number.parseFloat(toolbarStyle.paddingLeft) || 0;\n\t\tconst paddingRight: number = Number.parseFloat(toolbarStyle.paddingRight) || 0;\n\t\treturn this.toolbar.clientWidth - paddingLeft - paddingRight;\n\t}\n\n\tprivate resetVisibility(): void {\n\t\tfor (const entry of this.entries) {\n\t\t\tentry.element.classList.remove(HIDDEN_BTN_CLASS);\n\t\t}\n\t\tconst separators: HTMLElement[] = Array.from(\n\t\t\tthis.toolbar.querySelectorAll('.notectl-toolbar-separator'),\n\t\t) as HTMLElement[];\n\t\tfor (const sep of separators) {\n\t\t\tsep.classList.remove(HIDDEN_SEP_CLASS);\n\t\t}\n\t}\n\n\t// --- Overflow Button ---\n\n\tprivate setOverflowButtonVisible(visible: boolean): void {\n\t\tif (!this.overflowButton) return;\n\t\tthis.overflowButton.classList.toggle(HIDDEN_OVERFLOW_CLASS, !visible);\n\t\tif (!visible) {\n\t\t\tthis.overflowButton.removeAttribute('tabindex');\n\t\t}\n\t}\n\n\tprivate ensureOverflowButton(): void {\n\t\tif (this.overflowButton) return;\n\n\t\tconst btn: HTMLButtonElement = document.createElement('button');\n\t\tbtn.type = 'button';\n\t\tbtn.className = 'notectl-toolbar-overflow-btn';\n\t\tbtn.setAttribute('aria-label', this.ariaLabel);\n\t\tbtn.setAttribute('aria-haspopup', 'true');\n\t\tbtn.setAttribute('aria-expanded', 'false');\n\t\tbtn.innerHTML = ELLIPSIS_SVG;\n\n\t\tbtn.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\tthis.toggleDropdown();\n\t\t});\n\n\t\tthis.toolbar.appendChild(btn);\n\t\tthis.overflowButton = btn;\n\t}\n\n\t// --- Dropdown ---\n\n\tprivate toggleDropdown(): void {\n\t\tif (this.overflowDropdown) {\n\t\t\tthis.closeDropdown();\n\t\t} else {\n\t\t\tthis.openDropdown();\n\t\t}\n\t}\n\n\tprivate openDropdown(): void {\n\t\tif (!this.overflowButton || this.overflowEntries.length === 0) return;\n\n\t\tconst dropdown: HTMLDivElement = document.createElement('div');\n\t\tdropdown.className = 'notectl-toolbar-popup notectl-dropdown';\n\t\tdropdown.setAttribute('role', 'menu');\n\n\t\tthis.renderDropdownItems(dropdown, this.context.getState());\n\n\t\tif (this.popupManager) {\n\t\t\tthis.overflowHandle = this.popupManager.open({\n\t\t\t\tanchor: this.overflowButton,\n\t\t\t\tclassName: 'notectl-toolbar-popup notectl-dropdown',\n\t\t\t\tariaRole: 'menu',\n\t\t\t\tposition: 'below-end',\n\t\t\t\treferenceNode: this.overflowButton,\n\t\t\t\trestoreFocusTo: this.overflowButton,\n\t\t\t\tonClose: () => {\n\t\t\t\t\tthis.overflowHandle = null;\n\t\t\t\t\tthis.overflowDropdown = null;\n\t\t\t\t\tif (this.overflowButton) {\n\t\t\t\t\t\tthis.overflowButton.setAttribute('aria-expanded', 'false');\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcontent: (popup: HTMLElement) => {\n\t\t\t\t\tthis.renderDropdownItems(popup, this.context.getState());\n\t\t\t\t\tthis.overflowDropdown = popup;\n\t\t\t\t\tpopup.addEventListener('keydown', (e: KeyboardEvent) => this.handleDropdownKeydown(e));\n\t\t\t\t},\n\t\t\t});\n\t\t\tthis.overflowButton.setAttribute('aria-expanded', 'true');\n\t\t} else {\n\t\t\tthis.positionDropdown(dropdown);\n\t\t\tappendToRoot(dropdown, this.overflowButton);\n\t\t\tthis.overflowDropdown = dropdown;\n\t\t\tthis.overflowButton.setAttribute('aria-expanded', 'true');\n\n\t\t\trequestAnimationFrame(() => {\n\t\t\t\tconst first: HTMLElement | null = dropdown.querySelector('[role=\"menuitem\"]');\n\t\t\t\tfirst?.focus();\n\t\t\t});\n\n\t\t\tdropdown.addEventListener('keydown', (e: KeyboardEvent) => this.handleDropdownKeydown(e));\n\t\t\tthis.registerCloseHandler();\n\t\t}\n\t}\n\n\tprivate renderDropdownItems(dropdown: HTMLElement, state: EditorState): void {\n\t\tlet lastGroup: string | null = null;\n\n\t\tfor (const entry of this.overflowEntries) {\n\t\t\tif (lastGroup !== null && entry.item.group !== lastGroup) {\n\t\t\t\tconst sep: HTMLDivElement = document.createElement('div');\n\t\t\t\tsep.className = 'notectl-dropdown__separator';\n\t\t\t\tsep.setAttribute('role', 'separator');\n\t\t\t\tdropdown.appendChild(sep);\n\t\t\t}\n\t\t\tlastGroup = entry.item.group;\n\n\t\t\tconst menuBtn: HTMLButtonElement = document.createElement('button');\n\t\t\tmenuBtn.type = 'button';\n\t\t\tmenuBtn.className = 'notectl-dropdown__item';\n\t\t\tmenuBtn.setAttribute('role', 'menuitem');\n\t\t\tmenuBtn.setAttribute('tabindex', '-1');\n\t\t\tmenuBtn.setAttribute('data-toolbar-item', entry.item.id);\n\n\t\t\tconst iconSpan: HTMLSpanElement = document.createElement('span');\n\t\t\ticonSpan.className = 'notectl-dropdown__item-icon';\n\t\t\tif (entry.item.popupType !== 'combobox') {\n\t\t\t\ticonSpan.innerHTML = entry.item.icon;\n\t\t\t}\n\t\t\tmenuBtn.appendChild(iconSpan);\n\n\t\t\tconst labelSpan: HTMLSpanElement = document.createElement('span');\n\t\t\tlabelSpan.className = 'notectl-dropdown__item-label';\n\t\t\tlabelSpan.textContent =\n\t\t\t\tentry.item.popupType === 'combobox'\n\t\t\t\t\t? entry.item.getLabel(state)\n\t\t\t\t\t: (entry.item.tooltip ?? entry.item.label);\n\t\t\tmenuBtn.appendChild(labelSpan);\n\n\t\t\tmenuBtn.addEventListener('mousedown', (ev: MouseEvent) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tev.stopPropagation();\n\t\t\t\tthis.activateOverflowItem(entry);\n\t\t\t});\n\n\t\t\tdropdown.appendChild(menuBtn);\n\t\t}\n\t}\n\n\tprivate positionDropdown(dropdown: HTMLElement): void {\n\t\tif (!this.overflowButton) return;\n\n\t\tconst rect: DOMRect = this.overflowButton.getBoundingClientRect();\n\t\tconst rightEdge: number = window.innerWidth - rect.right;\n\n\t\tdropdown.style.position = 'fixed';\n\t\tdropdown.style.top = `${rect.bottom + 2}px`;\n\t\tdropdown.style.right = `${rightEdge}px`;\n\t\tdropdown.style.left = 'auto';\n\t\tdropdown.style.zIndex = '10000';\n\t}\n\n\tprivate registerCloseHandler(): void {\n\t\tthis.closeHandler = (ev: MouseEvent) => {\n\t\t\tconst path: EventTarget[] = ev.composedPath();\n\t\t\tif (\n\t\t\t\tthis.overflowDropdown &&\n\t\t\t\t!path.includes(this.overflowDropdown) &&\n\t\t\t\tthis.overflowButton &&\n\t\t\t\t!path.includes(this.overflowButton)\n\t\t\t) {\n\t\t\t\tthis.closeDropdown();\n\t\t\t}\n\t\t};\n\t\tsetTimeout(() => {\n\t\t\tif (this.closeHandler) {\n\t\t\t\tdocument.addEventListener('mousedown', this.closeHandler);\n\t\t\t}\n\t\t}, 0);\n\t}\n\n\tprivate closeDropdown(): void {\n\t\tif (this.overflowHandle) {\n\t\t\tconst handle: PopupHandle = this.overflowHandle;\n\t\t\tthis.overflowHandle = null;\n\t\t\tthis.overflowDropdown = null;\n\t\t\thandle.close();\n\t\t\tif (this.overflowButton) {\n\t\t\t\tthis.overflowButton.setAttribute('aria-expanded', 'false');\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.overflowDropdown) {\n\t\t\tthis.overflowDropdown.remove();\n\t\t\tthis.overflowDropdown = null;\n\t\t}\n\t\tif (this.overflowButton) {\n\t\t\tthis.overflowButton.setAttribute('aria-expanded', 'false');\n\t\t}\n\t\tif (this.closeHandler) {\n\t\t\tdocument.removeEventListener('mousedown', this.closeHandler);\n\t\t\tthis.closeHandler = null;\n\t\t}\n\t}\n\n\tprivate activateOverflowItem(entry: OverflowEntry): void {\n\t\tthis.closeDropdown();\n\t\tif (entry.item.popupType && this.overflowButton) {\n\t\t\tthis.onItemActivated(this.overflowButton, entry.item);\n\t\t} else {\n\t\t\tthis.context.executeCommand(entry.item.command);\n\t\t}\n\t}\n\n\t// --- Keyboard Navigation ---\n\n\tprivate handleDropdownKeydown(e: KeyboardEvent): void {\n\t\tif (!this.overflowDropdown) return;\n\n\t\tif (e.key === 'Escape' || e.key === 'Tab') {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\tthis.closeDropdown();\n\t\t\tthis.overflowButton?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\tconst items: HTMLElement[] = Array.from(\n\t\t\tthis.overflowDropdown.querySelectorAll('[role=\"menuitem\"]'),\n\t\t) as HTMLElement[];\n\t\tconst current: number = items.indexOf(this.getActiveElement() as HTMLElement);\n\n\t\tswitch (e.key) {\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst next: number = findNextDropdownItem(items, current, 1);\n\t\t\t\titems[next]?.focus();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst prev: number = findNextDropdownItem(items, current, -1);\n\t\t\t\titems[prev]?.focus();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'Enter':\n\t\t\tcase ' ': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst focusedItem: HTMLElement | undefined = items[current];\n\t\t\t\tif (!focusedItem) break;\n\t\t\t\tconst itemId: string | null = focusedItem.getAttribute('data-toolbar-item');\n\t\t\t\tconst entry: OverflowEntry | undefined = this.overflowEntries.find(\n\t\t\t\t\t(oe) => oe.item.id === itemId,\n\t\t\t\t);\n\t\t\t\tif (entry) this.activateOverflowItem(entry);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Helpers ---\n\n\tprivate hideTrailingSeparators(): void {\n\t\tconst children: HTMLElement[] = Array.from(this.toolbar.children) as HTMLElement[];\n\t\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\t\tconst child: HTMLElement | undefined = children[i];\n\t\t\tif (!child || child === this.overflowButton) continue;\n\t\t\tif (child.classList.contains('notectl-toolbar-separator')) {\n\t\t\t\tif (!child.classList.contains(HIDDEN_SEP_CLASS)) {\n\t\t\t\t\tchild.classList.add(HIDDEN_SEP_CLASS);\n\t\t\t\t}\n\t\t\t} else if (!child.classList.contains(HIDDEN_BTN_CLASS)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate notifyChange(): void {\n\t\tconst visible: HTMLButtonElement[] = this.entries\n\t\t\t.filter((oe) => !oe.element.classList.contains(HIDDEN_BTN_CLASS))\n\t\t\t.map((oe) => oe.element);\n\t\tthis.onOverflowChange(visible, this.overflowEntries.length > 0 ? this.overflowButton : null);\n\t}\n}\n","/**\n * ToolbarRenderers: pure rendering functions for toolbar popup content.\n * Grid pickers, dropdown menus, and separator elements.\n */\n\nimport type { DropdownConfig, GridPickerConfig } from './ToolbarItem.js';\n\nconst HIGHLIGHTED_CLASS = 'notectl-grid-picker__cell--highlighted';\n\n/**\n * Renders a grid picker into the given container.\n * Calls `onClose` after a cell is selected so the popup can be dismissed.\n */\nexport function renderGridPicker(\n\tcontainer: HTMLElement,\n\tconfig: GridPickerConfig,\n\tonClose: () => void,\n): void {\n\tcontainer.className += ' notectl-grid-picker';\n\n\tconst grid: HTMLDivElement = document.createElement('div');\n\tgrid.className = 'notectl-grid-picker__grid';\n\tgrid.setAttribute('role', 'grid');\n\tgrid.style.display = 'grid';\n\tgrid.style.gridTemplateColumns = `repeat(${config.maxCols}, 1fr)`;\n\tgrid.style.gap = '2px';\n\tgrid.style.padding = '8px';\n\n\tconst label: HTMLDivElement = document.createElement('div');\n\tlabel.className = 'notectl-grid-picker__label';\n\tlabel.textContent = '1 x 1';\n\tlabel.style.textAlign = 'center';\n\tlabel.style.padding = '4px';\n\tlabel.style.fontSize = '12px';\n\tlabel.setAttribute('aria-live', 'polite');\n\n\tfor (let r = 1; r <= config.maxRows; r++) {\n\t\tfor (let c = 1; c <= config.maxCols; c++) {\n\t\t\tconst cell: HTMLDivElement = document.createElement('div');\n\t\t\tcell.className = 'notectl-grid-picker__cell';\n\t\t\tcell.setAttribute('role', 'gridcell');\n\t\t\tcell.setAttribute('tabindex', '-1');\n\t\t\tcell.setAttribute('aria-label', `${r} x ${c}`);\n\t\t\tcell.style.width = '20px';\n\t\t\tcell.style.height = '20px';\n\t\t\tcell.style.border = '1px solid #ccc';\n\t\t\tcell.style.cursor = 'pointer';\n\t\t\tcell.setAttribute('data-row', String(r));\n\t\t\tcell.setAttribute('data-col', String(c));\n\n\t\t\tcell.addEventListener('mouseenter', () => {\n\t\t\t\thighlightCells(grid, r, c);\n\t\t\t\tlabel.textContent = `${r} x ${c}`;\n\t\t\t});\n\n\t\t\tcell.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\t\te.preventDefault();\n\t\t\t\te.stopPropagation();\n\t\t\t\tconfig.onSelect(r, c);\n\t\t\t\tonClose();\n\t\t\t});\n\n\t\t\tcell.addEventListener('click', () => {\n\t\t\t\tconfig.onSelect(r, c);\n\t\t\t\tonClose();\n\t\t\t});\n\n\t\t\tgrid.appendChild(cell);\n\t\t}\n\t}\n\n\tcontainer.appendChild(grid);\n\tcontainer.appendChild(label);\n}\n\n/**\n * Highlights grid cells up to the given row/col and updates the label.\n * Used by both mouse hover and keyboard navigation.\n */\nexport function highlightCells(grid: HTMLElement, targetRow: number, targetCol: number): void {\n\tconst cells: NodeListOf<Element> = grid.querySelectorAll('.notectl-grid-picker__cell');\n\tfor (const cell of cells) {\n\t\tconst r: number = Number(cell.getAttribute('data-row'));\n\t\tconst c: number = Number(cell.getAttribute('data-col'));\n\t\tcell.classList.toggle(HIGHLIGHTED_CLASS, r <= targetRow && c <= targetCol);\n\t}\n}\n\n/**\n * Renders a dropdown menu into the given container.\n * Calls `onClose` after an item is activated so the popup can be dismissed.\n */\nexport function renderDropdown(\n\tcontainer: HTMLElement,\n\tconfig: DropdownConfig,\n\texecuteCommand: (command: string) => void,\n\tonClose: () => void,\n): void {\n\tcontainer.classList.add('notectl-dropdown');\n\tcontainer.setAttribute('role', 'menu');\n\n\tfor (const item of config.items) {\n\t\tconst btn: HTMLButtonElement = document.createElement('button');\n\t\tbtn.type = 'button';\n\t\tbtn.className = 'notectl-dropdown__item';\n\t\tbtn.setAttribute('role', 'menuitem');\n\t\tbtn.setAttribute('tabindex', '-1');\n\n\t\tif (item.icon) {\n\t\t\tconst iconSpan: HTMLSpanElement = document.createElement('span');\n\t\t\ticonSpan.className = 'notectl-dropdown__item-icon';\n\t\t\ticonSpan.innerHTML = item.icon;\n\t\t\tbtn.appendChild(iconSpan);\n\t\t}\n\n\t\tconst labelSpan: HTMLSpanElement = document.createElement('span');\n\t\tlabelSpan.className = 'notectl-dropdown__item-label';\n\t\tlabelSpan.textContent = item.label;\n\t\tbtn.appendChild(labelSpan);\n\n\t\tbtn.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\texecuteCommand(item.command);\n\t\t\tonClose();\n\t\t});\n\n\t\tbtn.addEventListener('click', () => {\n\t\t\texecuteCommand(item.command);\n\t\t\tonClose();\n\t\t});\n\n\t\tcontainer.appendChild(btn);\n\t}\n}\n\n/** Creates a toolbar group separator element. */\nexport function createSeparator(): HTMLSpanElement {\n\tconst sep: HTMLSpanElement = document.createElement('span');\n\tsep.className = 'notectl-toolbar-separator';\n\tsep.setAttribute('role', 'separator');\n\treturn sep;\n}\n","/**\n * ToolbarPopupController: manages popup lifecycle, positioning, keyboard\n * navigation, and auto-close for toolbar popups (grid pickers, dropdowns,\n * and custom popups). Delegates lifecycle to PopupManager.\n */\n\nimport type { PluginContext } from '../Plugin.js';\nimport type { PopupHandle, PopupManager } from '../shared/PopupManager.js';\nimport type { ToolbarItem } from './ToolbarItem.js';\nimport { findNextDropdownItem, navigateGrid } from './ToolbarKeyboardNav.js';\nimport { highlightCells, renderDropdown, renderGridPicker } from './ToolbarRenderers.js';\n\nexport class ToolbarPopupController {\n\tprivate activePopup: HTMLElement | null = null;\n\tprivate activePopupButton: HTMLButtonElement | null = null;\n\tprivate activeHandle: PopupHandle | null = null;\n\tprivate readonly getActiveElement: () => Element | null;\n\tprivate popupManager: PopupManager | null = null;\n\n\tconstructor(getActiveElement: () => Element | null) {\n\t\tthis.getActiveElement = getActiveElement;\n\t}\n\n\t/** Injects the PopupManager instance (called after service registration). */\n\tsetPopupManager(manager: PopupManager): void {\n\t\tthis.popupManager = manager;\n\t}\n\n\t/** Whether a popup is currently open. */\n\tisOpen(): boolean {\n\t\treturn this.activePopup !== null;\n\t}\n\n\t/** Toggles a popup for the given toolbar button. */\n\ttoggle(button: HTMLButtonElement, item: ToolbarItem, context: PluginContext): void {\n\t\tif (this.activePopup) {\n\t\t\tthis.close();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.popupManager) {\n\t\t\tthis.openViaManager(button, item, context);\n\t\t} else {\n\t\t\tthis.openLegacy(button, item, context);\n\t\t}\n\t}\n\n\t/** Closes the active popup and cleans up event listeners. */\n\tclose(): void {\n\t\tif (this.activeHandle) {\n\t\t\t// Prevent onClose callback from re-entering\n\t\t\tconst handle: PopupHandle = this.activeHandle;\n\t\t\tthis.activeHandle = null;\n\t\t\tthis.clearButtonState();\n\t\t\thandle.close();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.clearButtonState();\n\t\tif (this.activePopup) {\n\t\t\tthis.activePopup.remove();\n\t\t\tthis.activePopup = null;\n\t\t}\n\t}\n\n\t/** Closes popup and restores focus to the trigger button. */\n\tcloseAndRestoreFocus(): void {\n\t\tconst triggerBtn: HTMLButtonElement | null = this.activePopupButton;\n\t\tthis.close();\n\t\ttriggerBtn?.focus();\n\t}\n\n\tdestroy(): void {\n\t\tthis.close();\n\t}\n\n\t// --- PopupManager path ---\n\n\tprivate openViaManager(\n\t\tbutton: HTMLButtonElement,\n\t\titem: ToolbarItem,\n\t\tcontext: PluginContext,\n\t): void {\n\t\tif (!this.popupManager) return;\n\n\t\tthis.activePopupButton = button;\n\t\tbutton.classList.add('notectl-toolbar-btn--popup-open');\n\t\tbutton.setAttribute('aria-expanded', 'true');\n\n\t\tthis.activeHandle = this.popupManager.open({\n\t\t\tanchor: button,\n\t\t\tclassName: 'notectl-toolbar-popup',\n\t\t\treferenceNode: button,\n\t\t\trestoreFocusTo: button,\n\t\t\tposition: 'below-start',\n\t\t\tonClose: () => {\n\t\t\t\t// Called when PopupManager closes the popup (click-outside, etc.)\n\t\t\t\tthis.activeHandle = null;\n\t\t\t\tthis.clearButtonState();\n\t\t\t\tthis.activePopup = null;\n\t\t\t},\n\t\t\tcontent: (popup: HTMLElement, close: () => void) => {\n\t\t\t\tthis.activePopup = popup;\n\t\t\t\tthis.renderPopupContent(popup, item, context, close);\n\t\t\t\tpopup.addEventListener('keydown', (e: KeyboardEvent) => this.handlePopupKeydown(e));\n\t\t\t},\n\t\t});\n\t}\n\n\t// --- Legacy path (no PopupManager available) ---\n\n\tprivate openLegacy(button: HTMLButtonElement, item: ToolbarItem, context: PluginContext): void {\n\t\tconst popup: HTMLDivElement = document.createElement('div');\n\t\tpopup.className = 'notectl-toolbar-popup';\n\n\t\tthis.renderPopupContent(popup, item, context, () => this.close());\n\n\t\tthis.positionAndAppend(popup, button);\n\n\t\tthis.activePopup = popup;\n\t\tthis.activePopupButton = button;\n\t\tbutton.classList.add('notectl-toolbar-btn--popup-open');\n\t\tbutton.setAttribute('aria-expanded', 'true');\n\n\t\tthis.focusFirstItem(popup);\n\n\t\tpopup.addEventListener('keydown', (e: KeyboardEvent) => this.handlePopupKeydown(e));\n\n\t\tconst closePopupHandler = (e: MouseEvent): void => {\n\t\t\tconst path: EventTarget[] = e.composedPath();\n\t\t\tif (!path.includes(popup) && !path.includes(button)) {\n\t\t\t\tthis.close();\n\t\t\t}\n\t\t};\n\t\tsetTimeout(() => {\n\t\t\tdocument.addEventListener('mousedown', closePopupHandler);\n\t\t}, 0);\n\n\t\t// Store handler for cleanup in close\n\t\tpopup.dataset.legacyClose = 'true';\n\t\tconst origClose = this.close.bind(this);\n\t\tthis.close = () => {\n\t\t\tdocument.removeEventListener('mousedown', closePopupHandler);\n\t\t\tthis.close = origClose;\n\t\t\torigClose();\n\t\t};\n\t}\n\n\t// --- Shared rendering ---\n\n\tprivate renderPopupContent(\n\t\tpopup: HTMLElement,\n\t\titem: ToolbarItem,\n\t\tcontext: PluginContext,\n\t\tclose: () => void,\n\t): void {\n\t\tswitch (item.popupType) {\n\t\t\tcase 'gridPicker':\n\t\t\t\trenderGridPicker(popup, item.popupConfig, close);\n\t\t\t\tbreak;\n\t\t\tcase 'dropdown':\n\t\t\t\trenderDropdown(\n\t\t\t\t\tpopup,\n\t\t\t\t\titem.popupConfig,\n\t\t\t\t\t(cmd: string) => context.executeCommand(cmd),\n\t\t\t\t\tclose,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'custom':\n\t\t\t\titem.renderPopup(popup, context, close);\n\t\t\t\tbreak;\n\t\t\tcase 'combobox':\n\t\t\t\titem.renderPopup(popup, context, close);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t// --- Button state ---\n\n\tprivate clearButtonState(): void {\n\t\tif (this.activePopupButton) {\n\t\t\tthis.activePopupButton.classList.remove('notectl-toolbar-btn--popup-open');\n\t\t\tthis.activePopupButton.setAttribute('aria-expanded', 'false');\n\t\t\tthis.activePopupButton = null;\n\t\t}\n\t}\n\n\t// --- Legacy Positioning ---\n\n\tprivate positionAndAppend(popup: HTMLElement, button: HTMLButtonElement): void {\n\t\tconst rect: DOMRect = button.getBoundingClientRect();\n\t\tpopup.style.position = 'fixed';\n\t\tpopup.style.top = `${rect.bottom + 2}px`;\n\t\tpopup.style.left = `${rect.left}px`;\n\t\tpopup.style.zIndex = '10000';\n\n\t\tconst root: Node = button.getRootNode();\n\t\tif (root instanceof ShadowRoot) {\n\t\t\troot.appendChild(popup);\n\t\t} else {\n\t\t\tdocument.body.appendChild(popup);\n\t\t}\n\t}\n\n\t// --- Focus ---\n\n\tprivate focusFirstItem(popup: HTMLElement): void {\n\t\trequestAnimationFrame(() => {\n\t\t\tconst firstItem: HTMLElement | null =\n\t\t\t\tpopup.querySelector('[role=\"menuitem\"]') ??\n\t\t\t\tpopup.querySelector('.notectl-grid-picker__cell') ??\n\t\t\t\tpopup.querySelector('button');\n\t\t\tfirstItem?.focus();\n\t\t});\n\t}\n\n\t// --- Keyboard Navigation ---\n\n\tprivate handlePopupKeydown(e: KeyboardEvent): void {\n\t\tif (!this.activePopup) return;\n\n\t\tif (e.key === 'Escape') {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\t\t\tthis.closeAndRestoreFocus();\n\t\t\treturn;\n\t\t}\n\n\t\tif (e.key === 'Tab') {\n\t\t\te.preventDefault();\n\t\t\tthis.closeAndRestoreFocus();\n\t\t\treturn;\n\t\t}\n\n\t\tconst menuItems: NodeListOf<Element> = this.activePopup.querySelectorAll('[role=\"menuitem\"]');\n\t\tif (menuItems.length > 0) {\n\t\t\tthis.handleDropdownKeydown(e, menuItems);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hasGrid: boolean = this.activePopup.querySelector('.notectl-grid-picker__cell') !== null;\n\t\tif (hasGrid) {\n\t\t\tthis.handleGridKeydown(e);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.handleCustomPopupKeydown(e);\n\t}\n\n\tprivate handleDropdownKeydown(e: KeyboardEvent, items: NodeListOf<Element>): void {\n\t\tconst itemArr: HTMLElement[] = Array.from(items) as HTMLElement[];\n\t\tconst current: number = itemArr.indexOf(this.getActiveElement() as HTMLElement);\n\n\t\tswitch (e.key) {\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst next: number = findNextDropdownItem(itemArr, current, 1);\n\t\t\t\titemArr[next]?.focus();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst prev: number = findNextDropdownItem(itemArr, current, -1);\n\t\t\t\titemArr[prev]?.focus();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'Enter':\n\t\t\tcase ' ': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst focused: HTMLElement | undefined = itemArr[current];\n\t\t\t\tif (focused) focused.click();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleGridKeydown(e: KeyboardEvent): void {\n\t\tconst focused: HTMLElement = this.getActiveElement() as HTMLElement;\n\t\tconst row: number = Number(focused?.getAttribute('data-row') ?? 1);\n\t\tconst col: number = Number(focused?.getAttribute('data-col') ?? 1);\n\n\t\tconst grid: Element | null =\n\t\t\tthis.activePopup?.querySelector('.notectl-grid-picker__grid') ?? null;\n\t\tif (!grid) return;\n\n\t\tconst lastCell: Element | null = grid.querySelector('.notectl-grid-picker__cell:last-child');\n\t\tconst maxCols: number = Number(lastCell?.getAttribute('data-col') ?? 1);\n\t\tconst maxRows: number = Number(lastCell?.getAttribute('data-row') ?? 1);\n\n\t\tif (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {\n\t\t\te.preventDefault();\n\t\t\tconst [newRow, newCol]: [number, number] = navigateGrid(\n\t\t\t\trow,\n\t\t\t\tcol,\n\t\t\t\tmaxRows,\n\t\t\t\tmaxCols,\n\t\t\t\te.key as 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight',\n\t\t\t);\n\t\t\tconst target: HTMLElement | null = grid.querySelector(\n\t\t\t\t`.notectl-grid-picker__cell[data-row=\"${newRow}\"][data-col=\"${newCol}\"]`,\n\t\t\t);\n\t\t\ttarget?.focus();\n\n\t\t\thighlightCells(grid as HTMLElement, newRow, newCol);\n\t\t\tconst label: Element | null =\n\t\t\t\tthis.activePopup?.querySelector('.notectl-grid-picker__label') ?? null;\n\t\t\tif (label) label.textContent = `${newRow} x ${newCol}`;\n\t\t}\n\n\t\tif (e.key === 'Enter' || e.key === ' ') {\n\t\t\te.preventDefault();\n\t\t\tfocused?.click();\n\t\t}\n\t}\n\n\tprivate handleCustomPopupKeydown(e: KeyboardEvent): void {\n\t\tif (!this.activePopup) return;\n\t\tconst buttons: HTMLButtonElement[] = Array.from(this.activePopup.querySelectorAll('button'));\n\t\tif (buttons.length === 0) return;\n\t\tconst active: HTMLElement = this.getActiveElement() as HTMLElement;\n\t\tconst currentIdx: number = buttons.indexOf(active as HTMLButtonElement);\n\n\t\tswitch (e.key) {\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst next: number = findNextDropdownItem(buttons, currentIdx, 1);\n\t\t\t\tbuttons[next]?.focus();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst prev: number = findNextDropdownItem(buttons, currentIdx, -1);\n\t\t\t\tbuttons[prev]?.focus();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'Enter':\n\t\t\tcase ' ': {\n\t\t\t\te.preventDefault();\n\t\t\t\tif (active) {\n\t\t\t\t\tactive.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true }));\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * ToolbarTooltip: manages the tooltip lifecycle for toolbar buttons.\n * Shows a tooltip after a short delay when hovering or focusing a button,\n * hides it when the cursor leaves or focus moves away.\n */\n\nconst TOOLTIP_DELAY_MS = 500;\n\nexport class ToolbarTooltip {\n\tprivate readonly element: HTMLElement;\n\tprivate timer: ReturnType<typeof setTimeout> | null = null;\n\tprivate target: HTMLButtonElement | null = null;\n\tprivate readonly isPopupActive: () => boolean;\n\n\tstatic readonly TOOLTIP_ID = 'notectl-toolbar-tooltip';\n\n\tconstructor(isPopupActive: () => boolean) {\n\t\tthis.isPopupActive = isPopupActive;\n\t\tthis.element = document.createElement('div');\n\t\tthis.element.className = 'notectl-toolbar-tooltip';\n\t\tthis.element.id = ToolbarTooltip.TOOLTIP_ID;\n\t\tthis.element.setAttribute('role', 'tooltip');\n\t\tthis.element.style.display = 'none';\n\t}\n\n\tshow(button: HTMLButtonElement): void {\n\t\tthis.hide();\n\n\t\tif (this.isPopupActive() || button.disabled) return;\n\n\t\tconst text: string | null = button.getAttribute('data-tooltip');\n\t\tif (!text) return;\n\n\t\tthis.target = button;\n\n\t\tthis.timer = setTimeout(() => {\n\t\t\tif (this.isPopupActive()) return;\n\n\t\t\tthis.element.textContent = text;\n\t\t\tthis.element.style.display = '';\n\n\t\t\tconst root: Node = button.getRootNode();\n\t\t\tif (root instanceof ShadowRoot && !this.element.parentNode) {\n\t\t\t\troot.appendChild(this.element);\n\t\t\t} else if (!(root instanceof ShadowRoot) && !this.element.parentNode) {\n\t\t\t\tdocument.body.appendChild(this.element);\n\t\t\t}\n\n\t\t\tbutton.setAttribute('aria-describedby', ToolbarTooltip.TOOLTIP_ID);\n\n\t\t\tconst rect: DOMRect = button.getBoundingClientRect();\n\t\t\tthis.element.style.position = 'fixed';\n\t\t\tthis.element.style.top = `${rect.bottom + 6}px`;\n\t\t\tthis.element.style.left = `${rect.left + rect.width / 2}px`;\n\t\t\tthis.element.style.transform = 'translateX(-50%)';\n\t\t}, TOOLTIP_DELAY_MS);\n\t}\n\n\thide(): void {\n\t\tif (this.timer) {\n\t\t\tclearTimeout(this.timer);\n\t\t\tthis.timer = null;\n\t\t}\n\t\tif (this.target) {\n\t\t\tthis.target.removeAttribute('aria-describedby');\n\t\t\tthis.target = null;\n\t\t}\n\t\tthis.element.style.display = 'none';\n\t}\n\n\tdestroy(): void {\n\t\tthis.hide();\n\t\tthis.element.remove();\n\t}\n}\n","/**\n * Toolbar plugin: renders toolbar items registered by other plugins.\n * Acts as a pure rendering engine — has no knowledge of specific features.\n * Supports buttons, dropdowns, grid pickers, and custom popups.\n * Implements WAI-ARIA Toolbar pattern with roving tabindex.\n */\n\nimport { TOOLBAR_CSS } from '../../editor/styles/toolbar.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { ServiceKey } from '../Plugin.js';\nimport type { Plugin, PluginConfig, PluginContext } from '../Plugin.js';\nimport { PopupManager, PopupServiceKey } from '../shared/PopupManager.js';\nimport type { ToolbarItem } from './ToolbarItem.js';\nimport {\n\tapplyRovingTabindex,\n\tfindFirstEnabled,\n\tfindLastEnabled,\n\tfindNextEnabled,\n} from './ToolbarKeyboardNav.js';\nimport { TOOLBAR_LOCALES, type ToolbarLocale } from './ToolbarLocale.js';\nimport {\n\tToolbarOverflowBehavior,\n\ttype ToolbarOverflowBehavior as ToolbarOverflowBehaviorType,\n} from './ToolbarOverflowBehavior.js';\nimport { ToolbarOverflowController } from './ToolbarOverflowController.js';\nimport { ToolbarPopupController } from './ToolbarPopupController.js';\nimport { createSeparator } from './ToolbarRenderers.js';\nimport { ToolbarTooltip } from './ToolbarTooltip.js';\n\n// --- Layout Config ---\n\nexport interface ToolbarLayoutConfig {\n\treadonly groups: ReadonlyArray<ReadonlyArray<string>>;\n\t/**\n\t * Controls responsive overflow behavior when toolbar items exceed available width.\n\t * Defaults to `ToolbarOverflowBehavior.BurgerMenu`.\n\t */\n\treadonly overflow?: ToolbarOverflowBehaviorType;\n}\n\n// --- Typed Service API ---\n\nexport interface ToolbarServiceAPI {\n\t/** Re-reads isActive/isEnabled from state and updates all buttons. */\n\trefresh(): void;\n\t/** Closes the currently open popup, if any. */\n\tclosePopup(): void;\n}\n\nexport const ToolbarServiceKey = new ServiceKey<ToolbarServiceAPI>('toolbar');\n\n// --- Plugin ---\n\ninterface ToolbarButton {\n\telement: HTMLButtonElement;\n\titem: ToolbarItem;\n\tcomboLabelEl: HTMLSpanElement | null;\n}\n\nexport class ToolbarPlugin implements Plugin {\n\treadonly id = 'toolbar';\n\treadonly name = 'Toolbar';\n\treadonly priority = 10;\n\n\tprivate context: PluginContext | null = null;\n\tprivate toolbarElement: HTMLElement | null = null;\n\tprivate buttons: ToolbarButton[] = [];\n\tprivate readonly hiddenItems = new Set<string>();\n\tprivate readonly layoutConfig: ToolbarLayoutConfig | null;\n\tprivate overflowBehavior: ToolbarOverflowBehaviorType;\n\tprivate focusedIndex = 0;\n\tprivate tooltip: ToolbarTooltip | null = null;\n\tprivate popupController: ToolbarPopupController | null = null;\n\tprivate popupManager: PopupManager | null = null;\n\tprivate overflowController: ToolbarOverflowController | null = null;\n\tprivate visibleElements: HTMLButtonElement[] = [];\n\tprivate locale!: ToolbarLocale;\n\n\tconstructor(layoutConfig?: ToolbarLayoutConfig) {\n\t\tthis.layoutConfig = layoutConfig ?? null;\n\t\tthis.overflowBehavior = layoutConfig?.overflow ?? ToolbarOverflowBehavior.BurgerMenu;\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(TOOLBAR_LOCALES, context);\n\t\tcontext.registerStyleSheet(TOOLBAR_CSS);\n\t\tthis.context = context;\n\n\t\tthis.popupManager = new PopupManager(context.getContainer());\n\t\tcontext.registerService(PopupServiceKey, this.popupManager);\n\n\t\tthis.popupController = new ToolbarPopupController(() => this.getActiveElement());\n\t\tthis.popupController.setPopupManager(this.popupManager);\n\t\tthis.tooltip = new ToolbarTooltip(() => this.popupController?.isOpen() ?? false);\n\n\t\tcontext.registerService(ToolbarServiceKey, {\n\t\t\trefresh: () => this.updateButtonStates(context.getState()),\n\t\t\tclosePopup: () => this.popupController?.close(),\n\t\t});\n\n\t\tthis.createToolbarElement();\n\t}\n\n\t/** Returns the current overflow behavior. */\n\tgetOverflowBehavior(): ToolbarOverflowBehaviorType {\n\t\treturn this.overflowBehavior;\n\t}\n\n\t/** Switches the overflow behavior at runtime. */\n\tsetOverflowBehavior(behavior: ToolbarOverflowBehaviorType): void {\n\t\tif (behavior === this.overflowBehavior) return;\n\n\t\tthis.overflowBehavior = behavior;\n\t\tthis.applyOverflowBehavior();\n\t\tthis.renderItems();\n\t}\n\n\tonReady(): void {\n\t\tthis.renderItems();\n\t}\n\n\tdestroy(): void {\n\t\tthis.overflowController?.destroy();\n\t\tthis.overflowController = null;\n\t\tthis.popupController?.destroy();\n\t\tthis.popupController = null;\n\t\tthis.popupManager?.destroy();\n\t\tthis.popupManager = null;\n\t\tthis.tooltip?.destroy();\n\t\tthis.tooltip = null;\n\t\tif (this.toolbarElement) {\n\t\t\tthis.toolbarElement.remove();\n\t\t\tthis.toolbarElement = null;\n\t\t}\n\t\tthis.buttons = [];\n\t\tthis.visibleElements = [];\n\t\tthis.context = null;\n\t}\n\n\tonStateChange(_oldState: EditorState, newState: EditorState, _tr: Transaction): void {\n\t\tthis.updateButtonStates(newState);\n\t}\n\n\tonReadOnlyChange(readonly: boolean): void {\n\t\tif (this.toolbarElement) {\n\t\t\tthis.toolbarElement.hidden = readonly;\n\t\t}\n\t}\n\n\tonConfigure(config: PluginConfig): void {\n\t\tfor (const [key, value] of Object.entries(config)) {\n\t\t\tif (value === false) {\n\t\t\t\tthis.hiddenItems.add(key);\n\t\t\t} else {\n\t\t\t\tthis.hiddenItems.delete(key);\n\t\t\t}\n\t\t}\n\t\tthis.renderItems();\n\t}\n\n\t// --- Toolbar ---\n\n\tprivate createToolbarElement(): void {\n\t\tif (!this.context) return;\n\n\t\tif (this.toolbarElement) {\n\t\t\tthis.toolbarElement.remove();\n\t\t}\n\t\tthis.buttons = [];\n\n\t\tconst container: HTMLElement = this.context.getPluginContainer('top');\n\t\tthis.toolbarElement = document.createElement('div');\n\t\tthis.toolbarElement.setAttribute('role', 'toolbar');\n\t\tthis.toolbarElement.setAttribute('aria-label', this.locale.formattingOptionsAria);\n\t\tthis.toolbarElement.setAttribute('data-notectl-no-print', '');\n\t\tthis.toolbarElement.className = 'notectl-toolbar';\n\n\t\tthis.toolbarElement.addEventListener('keydown', (e) => this.handleToolbarKeydown(e));\n\n\t\tthis.applyOverflowBehavior();\n\t\tcontainer.appendChild(this.toolbarElement);\n\t}\n\n\t/** Applies the current overflow behavior: creates/destroys the overflow controller and sets the data attribute. */\n\tprivate applyOverflowBehavior(): void {\n\t\tif (!this.toolbarElement || !this.context) return;\n\n\t\t// Tear down existing overflow controller\n\t\tthis.overflowController?.destroy();\n\t\tthis.overflowController = null;\n\n\t\tthis.toolbarElement.setAttribute('data-overflow', this.overflowBehavior);\n\n\t\tif (this.overflowBehavior === ToolbarOverflowBehavior.BurgerMenu) {\n\t\t\tthis.overflowController = new ToolbarOverflowController({\n\t\t\t\ttoolbar: this.toolbarElement,\n\t\t\t\tariaLabel: this.locale.moreToolsAria,\n\t\t\t\tcontext: this.context,\n\t\t\t\tpopupManager: this.popupManager ?? undefined,\n\t\t\t\tonOverflowChange: (visibleButtons, overflowBtn) => {\n\t\t\t\t\tthis.visibleElements = overflowBtn\n\t\t\t\t\t\t? [...visibleButtons, overflowBtn]\n\t\t\t\t\t\t: [...visibleButtons];\n\t\t\t\t\tthis.initRovingTabindex();\n\t\t\t\t},\n\t\t\t\tonItemActivated: (btn: HTMLButtonElement, item: ToolbarItem) => {\n\t\t\t\t\tthis.activateButton(btn, item);\n\t\t\t\t},\n\t\t\t\tgetActiveElement: () => this.getActiveElement(),\n\t\t\t});\n\t\t} else {\n\t\t\t// Flow and None modes: all buttons are visible for roving tabindex\n\t\t\tthis.visibleElements = [];\n\t\t}\n\t}\n\n\tprivate renderItems(): void {\n\t\tif (!this.context || !this.toolbarElement) return;\n\n\t\tfor (const btn of this.buttons) {\n\t\t\tbtn.element.remove();\n\t\t}\n\t\tthis.buttons = [];\n\n\t\tfor (const sep of this.toolbarElement.querySelectorAll('.notectl-toolbar-separator')) {\n\t\t\tsep.remove();\n\t\t}\n\n\t\tif (this.layoutConfig) {\n\t\t\tthis.renderItemsByLayout();\n\t\t} else {\n\t\t\tthis.renderItemsByPriority();\n\t\t}\n\n\t\tif (this.buttons.length > 0 && !this.toolbarElement.parentElement) {\n\t\t\tconst container: HTMLElement = this.context.getPluginContainer('top');\n\t\t\tcontainer.appendChild(this.toolbarElement);\n\t\t}\n\n\t\tthis.overflowController?.update(this.buttons);\n\t\tthis.initRovingTabindex();\n\t\tthis.updateButtonStates(this.context.getState());\n\t}\n\n\t// --- Roving Tabindex ---\n\n\tprivate getTabElements(): HTMLButtonElement[] {\n\t\treturn this.visibleElements.length > 0\n\t\t\t? this.visibleElements\n\t\t\t: this.buttons.map((b) => b.element);\n\t}\n\n\tprivate initRovingTabindex(): void {\n\t\tconst elements: HTMLButtonElement[] = this.getTabElements();\n\t\tconst first: number = findFirstEnabled(elements);\n\t\tthis.focusedIndex = first >= 0 ? first : 0;\n\t\tapplyRovingTabindex(elements, this.focusedIndex);\n\t}\n\n\tprivate setRovingFocus(index: number): void {\n\t\tconst elements: HTMLButtonElement[] = this.getTabElements();\n\t\tif (index < 0 || index >= elements.length) return;\n\t\tthis.focusedIndex = index;\n\t\tapplyRovingTabindex(elements, index);\n\t\telements[index]?.focus();\n\t}\n\n\t/** Returns the active element, respecting shadow DOM boundaries. */\n\tprivate getActiveElement(): Element | null {\n\t\tconst root: Node | undefined = this.toolbarElement?.getRootNode();\n\t\tif (root instanceof ShadowRoot) {\n\t\t\treturn root.activeElement;\n\t\t}\n\t\treturn document.activeElement;\n\t}\n\n\tprivate syncFocusedIndex(): void {\n\t\tconst active: Element | null = this.getActiveElement();\n\t\tconst elements: HTMLButtonElement[] = this.getTabElements();\n\t\tconst idx: number = elements.findIndex((el) => el === active);\n\t\tif (idx >= 0) {\n\t\t\tthis.focusedIndex = idx;\n\t\t}\n\t}\n\n\t// --- Toolbar Keyboard ---\n\n\tprivate handleToolbarKeydown(e: KeyboardEvent): void {\n\t\tconst elements: HTMLButtonElement[] = this.getTabElements();\n\t\tif (elements.length === 0) return;\n\n\t\tthis.syncFocusedIndex();\n\n\t\tswitch (e.key) {\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst next: number = findNextEnabled(elements, this.focusedIndex, 1);\n\t\t\t\tthis.setRovingFocus(next);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst prev: number = findNextEnabled(elements, this.focusedIndex, -1);\n\t\t\t\tthis.setRovingFocus(prev);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'Home': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst first: number = findFirstEnabled(elements);\n\t\t\t\tif (first >= 0) this.setRovingFocus(first);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'End': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst last: number = findLastEnabled(elements);\n\t\t\t\tif (last >= 0) this.setRovingFocus(last);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'Enter':\n\t\t\tcase ' ': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst focused: HTMLButtonElement | undefined = elements[this.focusedIndex];\n\t\t\t\tconst btn: ToolbarButton | undefined = this.buttons.find((b) => b.element === focused);\n\t\t\t\tif (btn) this.activateButton(btn.element, btn.item);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Activates a toolbar button (shared between mouse click and keyboard). */\n\tprivate activateButton(btn: HTMLButtonElement, item: ToolbarItem): void {\n\t\tthis.tooltip?.hide();\n\t\tif (item.popupType && this.context) {\n\t\t\tthis.popupController?.toggle(btn, item, this.context);\n\t\t} else {\n\t\t\tthis.context?.executeCommand(item.command);\n\t\t}\n\t}\n\n\t// --- Layout Rendering ---\n\n\tprivate renderItemsByLayout(): void {\n\t\tif (!this.context || !this.toolbarElement || !this.layoutConfig) return;\n\n\t\tconst toolbarReg = this.context.getToolbarRegistry();\n\t\tlet firstGroup = true;\n\n\t\tfor (const groupPluginIds of this.layoutConfig.groups) {\n\t\t\tconst groupItems: ToolbarItem[] = [];\n\t\t\tfor (const pId of groupPluginIds) {\n\t\t\t\tconst items: ToolbarItem[] = toolbarReg\n\t\t\t\t\t.getToolbarItemsByPlugin(pId)\n\t\t\t\t\t.filter((item) => !this.hiddenItems.has(item.id));\n\t\t\t\titems.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));\n\t\t\t\tgroupItems.push(...items);\n\t\t\t}\n\n\t\t\tif (groupItems.length === 0) continue;\n\n\t\t\tif (!firstGroup) {\n\t\t\t\tthis.toolbarElement.appendChild(createSeparator());\n\t\t\t}\n\t\t\tfirstGroup = false;\n\n\t\t\tfor (const item of groupItems) {\n\t\t\t\tconst btn: ToolbarButton = this.createButton(item);\n\t\t\t\tthis.toolbarElement.appendChild(btn.element);\n\t\t\t\tthis.buttons.push(btn);\n\t\t\t}\n\t\t}\n\n\t\tif (this.buttons.length === 0) {\n\t\t\tthis.toolbarElement.remove();\n\t\t}\n\t}\n\n\tprivate renderItemsByPriority(): void {\n\t\tif (!this.context || !this.toolbarElement) return;\n\n\t\tconst toolbarRegistry = this.context.getToolbarRegistry();\n\t\tconst items: ToolbarItem[] = toolbarRegistry\n\t\t\t.getToolbarItems()\n\t\t\t.filter((item) => !this.hiddenItems.has(item.id));\n\t\tif (items.length === 0) {\n\t\t\tthis.toolbarElement.remove();\n\t\t\treturn;\n\t\t}\n\n\t\tconst sorted: ToolbarItem[] = [...items].sort(\n\t\t\t(a, b) => (a.priority ?? 100) - (b.priority ?? 100),\n\t\t);\n\n\t\tconst hasSeparatorAfter: boolean = sorted.some((item) => item.separatorAfter);\n\n\t\tif (hasSeparatorAfter) {\n\t\t\tfor (let i = 0; i < sorted.length; i++) {\n\t\t\t\tconst item: ToolbarItem | undefined = sorted[i];\n\t\t\t\tif (!item) continue;\n\t\t\t\tconst btn: ToolbarButton = this.createButton(item);\n\t\t\t\tthis.toolbarElement.appendChild(btn.element);\n\t\t\t\tthis.buttons.push(btn);\n\n\t\t\t\tif (item.separatorAfter && i < sorted.length - 1) {\n\t\t\t\t\tthis.toolbarElement.appendChild(createSeparator());\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst groups = new Map<string, ToolbarItem[]>();\n\t\t\tfor (const item of sorted) {\n\t\t\t\tconst list: ToolbarItem[] = groups.get(item.group) ?? [];\n\t\t\t\tlist.push(item);\n\t\t\t\tgroups.set(item.group, list);\n\t\t\t}\n\n\t\t\tlet firstGroup = true;\n\t\t\tfor (const [, groupItems] of groups) {\n\t\t\t\tif (!firstGroup) {\n\t\t\t\t\tthis.toolbarElement.appendChild(createSeparator());\n\t\t\t\t}\n\t\t\t\tfirstGroup = false;\n\n\t\t\t\tfor (const item of groupItems) {\n\t\t\t\t\tconst btn: ToolbarButton = this.createButton(item);\n\t\t\t\t\tthis.toolbarElement.appendChild(btn.element);\n\t\t\t\t\tthis.buttons.push(btn);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// --- Button Creation ---\n\n\tprivate createButton(item: ToolbarItem): ToolbarButton {\n\t\tconst btn: HTMLButtonElement = document.createElement('button');\n\t\tbtn.type = 'button';\n\t\tbtn.className = `notectl-toolbar-btn notectl-toolbar-btn--${item.id}`;\n\t\tbtn.setAttribute('aria-pressed', 'false');\n\t\tbtn.setAttribute('aria-label', item.label);\n\t\tbtn.setAttribute('data-toolbar-item', item.id);\n\t\tbtn.setAttribute('data-tooltip', item.tooltip ?? item.label);\n\n\t\tlet comboLabelEl: HTMLSpanElement | null = null;\n\n\t\tif (item.popupType === 'combobox') {\n\t\t\tbtn.setAttribute('role', 'combobox');\n\t\t\tbtn.setAttribute('aria-haspopup', 'listbox');\n\t\t\tbtn.setAttribute('aria-expanded', 'false');\n\n\t\t\tconst labelSpan: HTMLSpanElement = document.createElement('span');\n\t\t\tlabelSpan.className = 'notectl-toolbar-combobox__label';\n\t\t\tconst state: EditorState | undefined = this.context?.getState();\n\t\t\tif (state) {\n\t\t\t\tlabelSpan.textContent = item.getLabel(state);\n\t\t\t}\n\t\t\tbtn.appendChild(labelSpan);\n\t\t\tcomboLabelEl = labelSpan;\n\n\t\t\tconst arrowSpan: HTMLSpanElement = document.createElement('span');\n\t\t\tarrowSpan.className = 'notectl-toolbar-combobox__arrow';\n\t\t\tarrowSpan.setAttribute('aria-hidden', 'true');\n\t\t\tarrowSpan.textContent = '\\u25BE';\n\t\t\tbtn.appendChild(arrowSpan);\n\t\t} else {\n\t\t\tif (item.popupType) {\n\t\t\t\tbtn.setAttribute('aria-haspopup', 'true');\n\t\t\t\tbtn.setAttribute('aria-expanded', 'false');\n\t\t\t}\n\n\t\t\tconst span: HTMLSpanElement = document.createElement('span');\n\t\t\tspan.className = 'notectl-toolbar-btn__icon';\n\t\t\tspan.innerHTML = item.icon;\n\t\t\tbtn.appendChild(span);\n\t\t}\n\n\t\tbtn.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\tthis.activateButton(btn, item);\n\t\t});\n\n\t\tbtn.addEventListener('mouseenter', () => this.tooltip?.show(btn));\n\t\tbtn.addEventListener('mouseleave', () => this.tooltip?.hide());\n\t\tbtn.addEventListener('focus', () => this.tooltip?.show(btn));\n\t\tbtn.addEventListener('blur', () => this.tooltip?.hide());\n\n\t\treturn { element: btn, item, comboLabelEl };\n\t}\n\n\t// --- Button State Updates ---\n\n\tprivate updateButtonStates(state: EditorState): void {\n\t\tfor (const btn of this.buttons) {\n\t\t\tconst active: boolean = btn.item.isActive?.(state) ?? false;\n\t\t\tconst enabled: boolean = btn.item.isEnabled?.(state) ?? true;\n\t\t\tbtn.element.setAttribute('aria-pressed', String(active));\n\t\t\tbtn.element.classList.toggle('notectl-toolbar-btn--active', active);\n\t\t\tbtn.element.disabled = !enabled;\n\t\t\tif (!enabled) {\n\t\t\t\tbtn.element.setAttribute('aria-disabled', 'true');\n\t\t\t} else {\n\t\t\t\tbtn.element.removeAttribute('aria-disabled');\n\t\t\t}\n\t\t\tif (btn.comboLabelEl && btn.item.popupType === 'combobox') {\n\t\t\t\tbtn.comboLabelEl.textContent = btn.item.getLabel(state);\n\t\t\t}\n\t\t}\n\t\tthis.overflowController?.updateItemStates(state);\n\t}\n}\n"],"names":["PopupServiceKey","ServiceKey","PopupManager","stack","referenceNode","this","config","popup","document","createElement","className","ariaRole","setAttribute","ariaLabel","handle","close","closeEntry","entry","getElement","content","refNode","appendToRoot","anchorRect","anchor","HTMLElement","getBoundingClientRect","positionPopup","position","parentEntry","parent","findEntryByHandle","clickOutsideHandler","e","path","composedPath","includes","stackEntry","element","push","setTimeout","addEventListener","focusFirstItem","top","length","closeAll","isOpen","destroy","index","indexOf","child","removeEntry","restoreFocusTo","focus","onClose","splice","remove","removeEventListener","find","requestAnimationFrame","firstFocusable","querySelector","TOOLBAR_LOCALE_EN","formattingOptionsAria","moreToolsAria","TOOLBAR_LOCALES","en","de","es","fr","zh","ru","ar","hi","ToolbarOverflowBehavior","BurgerMenu","Flow","None","HIDDEN_BTN_CLASS","HIDDEN_SEP_CLASS","ToolbarOverflowController","toolbar","context","onOverflowChange","onItemActivated","getActiveElement","popupManager","entries","overflowButton","overflowDropdown","overflowHandle","overflowEntries","resizeObserver","closeHandler","ResizeObserver","recalculate","observe","buttons","map","b","item","closeDropdown","resetVisibility","ensureOverflowButton","setOverflowButtonVisible","availableWidth","measureAvailableWidth","children","Array","from","childWidths","measureChildWidths","maxWidth","usedWidth","overflowing","overflowList","classList","contains","add","sepWidth","get","oe","btnWidth","hideTrailingSeparators","notifyChange","state","menuItems","querySelectorAll","menuItem","itemId","getAttribute","id","active","isActive","enabled","isEnabled","toggle","disabled","popupType","labelEl","textContent","getLabel","disconnect","widths","Map","set","offsetWidth","toolbarStyle","getComputedStyle","paddingLeft","Number","parseFloat","paddingRight","clientWidth","separators","sep","visible","removeAttribute","btn","type","innerHTML","preventDefault","toggleDropdown","appendChild","openDropdown","dropdown","renderDropdownItems","getState","open","handleDropdownKeydown","positionDropdown","first","registerCloseHandler","lastGroup","group","menuBtn","iconSpan","icon","labelSpan","tooltip","label","ev","stopPropagation","activateOverflowItem","rect","rightEdge","window","innerWidth","right","style","bottom","left","zIndex","executeCommand","command","key","items","current","next","findNextDropdownItem","prev","focusedItem","i","filter","highlightCells","grid","targetRow","targetCol","cells","cell","r","c","createSeparator","ToolbarPopupController","activePopup","activePopupButton","activeHandle","manager","button","openViaManager","openLegacy","clearButtonState","closeAndRestoreFocus","triggerBtn","renderPopupContent","handlePopupKeydown","positionAndAppend","closePopupHandler","dataset","legacyClose","origClose","bind","container","display","gridTemplateColumns","maxCols","gap","padding","textAlign","fontSize","maxRows","width","height","border","cursor","String","onSelect","popupConfig","cmd","renderPopup","root","getRootNode","ShadowRoot","body","firstItem","handleGridKeydown","handleCustomPopupKeydown","itemArr","focused","click","row","col","lastCell","newRow","newCol","navigateGrid","target","currentIdx","dispatchEvent","MouseEvent","bubbles","cancelable","ToolbarTooltip","timer","isPopupActive","static","TOOLTIP_ID","hide","text","parentNode","transform","clearTimeout","ToolbarServiceKey","ToolbarPlugin","name","priority","toolbarElement","hiddenItems","Set","layoutConfig","overflowBehavior","focusedIndex","popupController","overflowController","visibleElements","locale","overflow","resolvePluginLocale","registerStyleSheet","getContainer","registerService","setPopupManager","refresh","updateButtonStates","closePopup","createToolbarElement","getOverflowBehavior","behavior","applyOverflowBehavior","renderItems","onReady","_oldState","newState","_tr","readonly","hidden","value","Object","delete","getPluginContainer","handleToolbarKeydown","visibleButtons","overflowBtn","initRovingTabindex","activateButton","renderItemsByLayout","renderItemsByPriority","parentElement","update","getTabElements","elements","findFirstEnabled","applyRovingTabindex","activeElement","syncFocusedIndex","idx","findIndex","el","findNextEnabled","setRovingFocus","last","findLastEnabled","toolbarReg","getToolbarRegistry","firstGroup","groupPluginIds","groups","groupItems","pId","getToolbarItemsByPlugin","has","sort","a","createButton","getToolbarItems","sorted","some","separatorAfter","list","comboLabelEl","arrowSpan","span","show","updateItemStates"],"mappings":";;;AAoCO,MAAMA,IAAkB,IAAIC,EAA4B,OAAA;AAaxD,MAAMC,EAAAA;AAAAA,EACKC,QAAsB,CAAA;AAAA,EACtBC;AAAAA,EAEjB,YAAYA,IAAAA;AACXC,SAAKD,gBAAgBA;AAAAA,EACtB;AAAA,EAGA,KAAKE,IAAAA;AACJ,UAAMC,KAAwBC,SAASC,cAAc,KAAA;AACrDF,IAAAA,GAAMG,YAAYJ,GAAOI,YAAY,iBAAiBJ,GAAOI,SAAAA,KAAc,iBAEvEJ,GAAOK,YACVJ,GAAMK,aAAa,QAAQN,GAAOK,QAAAA,GAE/BL,GAAOO,aACVN,GAAMK,aAAa,cAAcN,GAAOO,SAAAA;AAGzC,UAAMC,KAAsB,EAC3BC,OAAO,MAAMV,KAAKW,WAAWC,EAAAA,GAC7BC,YAAY,MAAMX,GAAAA;AAGnBD,IAAAA,GAAOa,QAAQZ,IAAO,MAAMF,KAAKW,WAAWC,EAAAA,CAAAA;AAE5C,UAAMG,KAAgBd,GAAOF,iBAAiBC,KAAKD;AACnDiB,MAAad,IAAOa,EAAAA;AAEpB,UAAME,KACLhB,GAAOiB,kBAAkBC,cAAclB,GAAOiB,OAAOE,sBAAAA,IAA0BnB,GAAOiB;AACvFG,MAAcnB,IAAOe,IAAY,EAChCK,UAAUrB,GAAOqB,YAAY,cAAA,CAAA;AAG9B,UAAMC,KAAiCtB,GAAOuB,SAC3CxB,KAAKyB,kBAAkBxB,GAAOuB,MAAAA,IAC9B,MAEGE,KAAuBC,CAAAA,OAAAA;AAC5B,YAAMC,KAAsBD,GAAEE,aAAAA;AAC9B,UAAA,CAAID,GAAKE,SAAS5B,EAAAA,GAAlB;AAGA,mBAAW6B,MAAc/B,KAAKF,MAC7B,KAAI8B,GAAKE,SAASC,GAAWC,OAAAA,EAAU;AAIpC/B,QAAAA,GAAOiB,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C9B;AAAA,EAIQ,mBAAmB1O,IAAAA;AAC1B,eAAWiC,MAAOxJ,KAAK2F,SAAS;AAC/B,YAAMmC,KAAkB0B,GAAI1D,KAAKiC,WAAWR,cACtCS,KAAmBwB,GAAI1D,KAAKmC,YAAYV,EAAAA,KAAAA;AAC9CiC,MAAAA,GAAIxH,QAAQzB,aAAa,gBAAgBwO,OAAOjH,EAAAA,CAAAA,GAChD0B,GAAIxH,QAAQ8E,UAAUoB,OAAO,+BAA+BJ,EAAAA,GAC5D0B,GAAIxH,QAAQmG,WAAAA,CAAYH,IACnBA,KAGJwB,GAAIxH,QAAQuH,gBAAgB,eAAA,IAF5BC,GAAIxH,QAAQzB,aAAa,iBAAiB,MAAA,GAIvCiJ,GAAIyM,gBAAuC,eAAvBzM,GAAI1D,KAAKsC,cAChCoB,GAAIyM,aAAa3N,cAAckB,GAAI1D,KAAKyC,SAAShB,EAAAA;AAAAA,IAEnD;AACAvH,SAAK+R,oBAAoBsE,iBAAiB9O,EAAAA;AAAAA,EAC3C;AAAA;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-Bt_d4IqB.mjs","sources":["../../src/decorations/PositionMapping.ts","../../src/decorations/Decoration.ts","../../src/plugins/code-block/CodeBlockKeyboardHandlers.ts","../../src/plugins/code-block/CodeBlockCommands.ts","../../src/plugins/code-block/CodeBlockLocale.ts","../../src/plugins/code-block/CodeBlockTypes.ts","../../src/plugins/code-block/CodeBlockService.ts","../../src/plugins/code-block/CodeBlockPlugin.ts","../../src/editor/styles/code-block.ts","../../src/plugins/code-block/CodeBlockNodeView.ts"],"sourcesContent":["/**\n * Pure functions for mapping decorations through transaction steps.\n * Handles position adjustments when the document changes — insertions,\n * deletions, splits, merges, and structural node removal.\n */\n\nimport type {\n\tDeleteTextStep,\n\tInsertTextStep,\n\tMergeBlocksStep,\n\tRemoveNodeStep,\n\tSplitBlockStep,\n\tStep,\n} from '../state/Transaction.js';\nimport type {\n\tDecoration,\n\tInlineDecoration,\n\tNodeDecoration,\n\tWidgetDecoration,\n} from './Decoration.js';\n\n/**\n * Maps a single decoration through a step.\n * Returns the mapped decoration, an array (when a split produces two),\n * or null if the decoration was deleted by the step.\n */\nexport function mapDecorationThroughStep(\n\tdeco: Decoration,\n\tstep: Step,\n): Decoration | readonly Decoration[] | null {\n\tswitch (deco.type) {\n\t\tcase 'inline':\n\t\t\treturn mapInline(deco, step);\n\t\tcase 'widget':\n\t\t\treturn mapWidget(deco, step);\n\t\tcase 'node':\n\t\t\treturn mapNode(deco, step);\n\t}\n}\n\nfunction mapInline(\n\tdeco: InlineDecoration,\n\tstep: Step,\n): InlineDecoration | readonly InlineDecoration[] | null {\n\tswitch (step.type) {\n\t\tcase 'insertText':\n\t\t\treturn mapInlineInsert(deco, step);\n\t\tcase 'deleteText':\n\t\t\treturn mapInlineDelete(deco, step);\n\t\tcase 'splitBlock':\n\t\t\treturn mapInlineSplit(deco, step);\n\t\tcase 'mergeBlocks':\n\t\t\treturn mapInlineMerge(deco, step);\n\t\tcase 'removeNode':\n\t\t\treturn removeIfBlockDeleted(deco, step);\n\t\tdefault:\n\t\t\treturn deco;\n\t}\n}\n\nfunction mapWidget(deco: WidgetDecoration, step: Step): WidgetDecoration | null {\n\tswitch (step.type) {\n\t\tcase 'insertText':\n\t\t\treturn mapWidgetInsert(deco, step);\n\t\tcase 'deleteText':\n\t\t\treturn mapWidgetDelete(deco, step);\n\t\tcase 'splitBlock':\n\t\t\treturn mapWidgetSplit(deco, step);\n\t\tcase 'mergeBlocks':\n\t\t\treturn mapWidgetMerge(deco, step);\n\t\tcase 'removeNode':\n\t\t\treturn removeIfBlockDeleted(deco, step);\n\t\tdefault:\n\t\t\treturn deco;\n\t}\n}\n\nfunction mapNode(deco: NodeDecoration, step: Step): NodeDecoration | null {\n\tswitch (step.type) {\n\t\tcase 'mergeBlocks':\n\t\t\treturn mapNodeMerge(deco, step);\n\t\tcase 'removeNode':\n\t\t\treturn removeIfBlockDeleted(deco, step);\n\t\tdefault:\n\t\t\treturn deco;\n\t}\n}\n\n// --- InsertText ---\n\nfunction mapInlineInsert(deco: InlineDecoration, step: InsertTextStep): InlineDecoration {\n\tif (deco.blockId !== step.blockId) return deco;\n\n\tconst len: number = step.text.length;\n\t// from: assoc=-1 (stays at boundary — only shifts if insertion is strictly before)\n\tconst newFrom: number = deco.from > step.offset ? deco.from + len : deco.from;\n\t// to: assoc=1 (moves past insertion — shifts if insertion is at or before)\n\tconst newTo: number = deco.to >= step.offset ? deco.to + len : deco.to;\n\n\tif (newFrom === deco.from && newTo === deco.to) return deco;\n\treturn { ...deco, from: newFrom, to: newTo };\n}\n\nfunction mapWidgetInsert(deco: WidgetDecoration, step: InsertTextStep): WidgetDecoration {\n\tif (deco.blockId !== step.blockId) return deco;\n\n\tconst len: number = step.text.length;\n\t// At boundary: side=-1 means \"before insertion\" (assoc=-1, stays), side=1 means \"after\" (moves)\n\tif (deco.offset > step.offset) {\n\t\treturn { ...deco, offset: deco.offset + len };\n\t}\n\tif (deco.offset === step.offset && deco.side >= 1) {\n\t\treturn { ...deco, offset: deco.offset + len };\n\t}\n\treturn deco;\n}\n\n// --- DeleteText ---\n\nfunction mapInlineDelete(deco: InlineDecoration, step: DeleteTextStep): InlineDecoration | null {\n\tif (deco.blockId !== step.blockId) return deco;\n\n\tconst delLen: number = step.to - step.from;\n\tconst newFrom: number = clampAndShift(deco.from, step.from, step.to, delLen);\n\tconst newTo: number = clampAndShift(deco.to, step.from, step.to, delLen);\n\n\tif (newFrom >= newTo) return null;\n\tif (newFrom === deco.from && newTo === deco.to) return deco;\n\treturn { ...deco, from: newFrom, to: newTo };\n}\n\nfunction mapWidgetDelete(deco: WidgetDecoration, step: DeleteTextStep): WidgetDecoration | null {\n\tif (deco.blockId !== step.blockId) return deco;\n\n\t// Widget strictly inside deleted range → deleted\n\tif (deco.offset > step.from && deco.offset < step.to) return null;\n\n\tconst delLen: number = step.to - step.from;\n\tif (deco.offset >= step.to) {\n\t\treturn { ...deco, offset: deco.offset - delLen };\n\t}\n\treturn deco;\n}\n\n// --- SplitBlock ---\n\nfunction mapInlineSplit(\n\tdeco: InlineDecoration,\n\tstep: SplitBlockStep,\n): InlineDecoration | readonly InlineDecoration[] {\n\tif (deco.blockId !== step.blockId) return deco;\n\n\t// Entirely before split point → unchanged\n\tif (deco.to <= step.offset) return deco;\n\n\t// Entirely after split point → move to new block, adjust offsets\n\tif (deco.from >= step.offset) {\n\t\treturn {\n\t\t\t...deco,\n\t\t\tblockId: step.newBlockId,\n\t\t\tfrom: deco.from - step.offset,\n\t\t\tto: deco.to - step.offset,\n\t\t};\n\t}\n\n\t// Spanning the split point → split into two decorations\n\tconst left: InlineDecoration = { ...deco, to: step.offset };\n\tconst right: InlineDecoration = {\n\t\t...deco,\n\t\tblockId: step.newBlockId,\n\t\tfrom: 0,\n\t\tto: deco.to - step.offset,\n\t};\n\treturn [left, right];\n}\n\nfunction mapWidgetSplit(deco: WidgetDecoration, step: SplitBlockStep): WidgetDecoration {\n\tif (deco.blockId !== step.blockId) return deco;\n\n\t// Before split → stays\n\tif (deco.offset < step.offset) return deco;\n\n\t// After split → new block\n\tif (deco.offset > step.offset) {\n\t\treturn {\n\t\t\t...deco,\n\t\t\tblockId: step.newBlockId,\n\t\t\toffset: deco.offset - step.offset,\n\t\t};\n\t}\n\n\t// At boundary: side determines which block\n\tif (deco.side >= 1) {\n\t\treturn {\n\t\t\t...deco,\n\t\t\tblockId: step.newBlockId,\n\t\t\toffset: 0,\n\t\t};\n\t}\n\treturn deco;\n}\n\n// --- MergeBlocks ---\n\nfunction mapInlineMerge(deco: InlineDecoration, step: MergeBlocksStep): InlineDecoration {\n\tif (deco.blockId !== step.sourceBlockId) return deco;\n\n\treturn {\n\t\t...deco,\n\t\tblockId: step.targetBlockId,\n\t\tfrom: deco.from + step.targetLengthBefore,\n\t\tto: deco.to + step.targetLengthBefore,\n\t};\n}\n\nfunction mapWidgetMerge(deco: WidgetDecoration, step: MergeBlocksStep): WidgetDecoration {\n\tif (deco.blockId !== step.sourceBlockId) return deco;\n\n\treturn {\n\t\t...deco,\n\t\tblockId: step.targetBlockId,\n\t\toffset: deco.offset + step.targetLengthBefore,\n\t};\n}\n\nfunction mapNodeMerge(deco: NodeDecoration, step: MergeBlocksStep): NodeDecoration | null {\n\t// Source block disappears → delete its node decoration\n\tif (deco.blockId === step.sourceBlockId) return null;\n\treturn deco;\n}\n\n// --- RemoveNode ---\n\nfunction removeIfBlockDeleted<T extends Decoration>(deco: T, step: RemoveNodeStep): T | null {\n\tif (deco.blockId === step.removedNode.id) return null;\n\treturn deco;\n}\n\n// --- Helpers ---\n\nfunction clampAndShift(pos: number, delFrom: number, delTo: number, delLen: number): number {\n\tif (pos <= delFrom) return pos;\n\tif (pos >= delTo) return pos - delLen;\n\treturn delFrom;\n}\n","/**\n * Decoration types and DecorationSet for transient, view-only annotations.\n * Decorations are NOT part of the document model and do NOT affect undo/redo.\n */\n\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { mapDecorationThroughStep } from './PositionMapping.js';\n\n// --- Decoration Attrs ---\n\nexport interface DecorationAttrs {\n\treadonly class?: string;\n\treadonly style?: string;\n\treadonly nodeName?: string;\n\treadonly [key: string]: string | undefined;\n}\n\n// --- Decoration Types ---\n\nexport interface InlineDecoration {\n\treadonly type: 'inline';\n\treadonly blockId: BlockId;\n\treadonly from: number;\n\treadonly to: number;\n\treadonly attrs: DecorationAttrs;\n}\n\nexport interface NodeDecoration {\n\treadonly type: 'node';\n\treadonly blockId: BlockId;\n\treadonly attrs: DecorationAttrs;\n}\n\nexport interface WidgetDecoration {\n\treadonly type: 'widget';\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n\treadonly toDOM: () => HTMLElement;\n\treadonly side: -1 | 1;\n\treadonly key?: string;\n}\n\nexport type Decoration = InlineDecoration | NodeDecoration | WidgetDecoration;\n\n// --- Factory Functions ---\n\n/** Creates an inline decoration for a text range within a block. */\nexport function inline(\n\tblockId: BlockId,\n\tfrom: number,\n\tto: number,\n\tattrs: DecorationAttrs,\n): InlineDecoration {\n\treturn { type: 'inline', blockId, from, to, attrs };\n}\n\n/** Creates a node decoration that applies to a whole block element. */\nexport function node(blockId: BlockId, attrs: DecorationAttrs): NodeDecoration {\n\treturn { type: 'node', blockId, attrs };\n}\n\n/** Creates a widget decoration that inserts a DOM element at a position. */\nexport function widget(\n\tblockId: BlockId,\n\toffset: number,\n\ttoDOM: () => HTMLElement,\n\toptions?: { readonly side?: -1 | 1; readonly key?: string },\n): WidgetDecoration {\n\treturn {\n\t\ttype: 'widget',\n\t\tblockId,\n\t\toffset,\n\t\ttoDOM,\n\t\tside: options?.side ?? -1,\n\t\tkey: options?.key,\n\t};\n}\n\n// --- DecorationSet ---\n\n/**\n * Immutable set of decorations indexed by block ID.\n * Provides efficient lookup and merging of decoration collections.\n */\nexport class DecorationSet {\n\tstatic readonly empty: DecorationSet = new DecorationSet(new Map());\n\n\tprivate constructor(private readonly byBlock: ReadonlyMap<BlockId, readonly Decoration[]>) {}\n\n\t/** Creates a DecorationSet from a flat array of decorations. */\n\tstatic create(decorations: readonly Decoration[]): DecorationSet {\n\t\tif (decorations.length === 0) return DecorationSet.empty;\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const deco of decorations) {\n\t\t\tconst existing = map.get(deco.blockId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(deco);\n\t\t\t} else {\n\t\t\t\tmap.set(deco.blockId, [deco]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns all decorations for a given block. */\n\tfind(blockId: BlockId): readonly Decoration[] {\n\t\treturn this.byBlock.get(blockId) ?? [];\n\t}\n\n\t/** Returns only inline decorations for a given block. */\n\tfindInline(blockId: BlockId): readonly InlineDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is InlineDecoration => d.type === 'inline');\n\t}\n\n\t/** Returns only node decorations for a given block. */\n\tfindNode(blockId: BlockId): readonly NodeDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is NodeDecoration => d.type === 'node');\n\t}\n\n\t/** Returns only widget decorations for a given block. */\n\tfindWidget(blockId: BlockId): readonly WidgetDecoration[] {\n\t\tconst decos = this.byBlock.get(blockId);\n\t\tif (!decos) return [];\n\t\treturn decos.filter((d): d is WidgetDecoration => d.type === 'widget');\n\t}\n\n\t/** Returns a new DecorationSet with the given decorations added. */\n\tadd(decorations: readonly Decoration[]): DecorationSet {\n\t\tif (decorations.length === 0) return this;\n\t\tif (this.isEmpty) return DecorationSet.create(decorations);\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tmap.set(bid, [...decos]);\n\t\t}\n\t\tfor (const deco of decorations) {\n\t\t\tconst existing = map.get(deco.blockId);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(deco);\n\t\t\t} else {\n\t\t\t\tmap.set(deco.blockId, [deco]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns a new DecorationSet with decorations matching the predicate removed. */\n\tremove(predicate: (d: Decoration) => boolean): DecorationSet {\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tlet changed = false;\n\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tconst filtered = decos.filter((d) => !predicate(d));\n\t\t\tif (filtered.length !== decos.length) changed = true;\n\t\t\tif (filtered.length > 0) {\n\t\t\t\tmap.set(bid, filtered);\n\t\t\t}\n\t\t}\n\n\t\tif (!changed) return this;\n\t\tif (map.size === 0) return DecorationSet.empty;\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Returns a new DecorationSet merging this set with another. */\n\tmerge(other: DecorationSet): DecorationSet {\n\t\tif (other.isEmpty) return this;\n\t\tif (this.isEmpty) return other;\n\n\t\tconst map = new Map<BlockId, Decoration[]>();\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tmap.set(bid, [...decos]);\n\t\t}\n\t\tfor (const [bid, decos] of other.byBlock) {\n\t\t\tconst existing = map.get(bid);\n\t\t\tif (existing) {\n\t\t\t\texisting.push(...decos);\n\t\t\t} else {\n\t\t\t\tmap.set(bid, [...decos]);\n\t\t\t}\n\t\t}\n\t\treturn new DecorationSet(map);\n\t}\n\n\t/** Checks equality — reference first, then structural comparison. */\n\tequals(other: DecorationSet): boolean {\n\t\tif (this === other) return true;\n\t\tif (this.byBlock.size !== other.byBlock.size) return false;\n\n\t\tfor (const [bid, decos] of this.byBlock) {\n\t\t\tconst otherDecos = other.byBlock.get(bid);\n\t\t\tif (!otherDecos) return false;\n\t\t\tif (!decorationArraysEqual(decos, otherDecos)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** True if the set contains no decorations. */\n\tget isEmpty(): boolean {\n\t\treturn this.byBlock.size === 0;\n\t}\n\n\t/**\n\t * Maps decorations through document changes described by a transaction.\n\t * Decorations that become invalid (e.g. fully deleted range) are removed.\n\t * Decorations that span a split point are split into two.\n\t */\n\tmap(tr: Transaction): DecorationSet {\n\t\tif (this.isEmpty || tr.steps.length === 0) return this;\n\n\t\tlet mapped: Decoration[] = [];\n\t\tfor (const decos of this.byBlock.values()) {\n\t\t\tfor (const d of decos) {\n\t\t\t\tmapped.push(d);\n\t\t\t}\n\t\t}\n\n\t\tfor (const step of tr.steps) {\n\t\t\tconst next: Decoration[] = [];\n\t\t\tfor (const deco of mapped) {\n\t\t\t\tconst result = mapDecorationThroughStep(deco, step);\n\t\t\t\tif (result === null) continue;\n\t\t\t\tif (Array.isArray(result)) {\n\t\t\t\t\tfor (const r of result) {\n\t\t\t\t\t\tnext.push(r);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnext.push(result as Decoration);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmapped = next;\n\t\t}\n\n\t\tif (mapped.length === 0) return DecorationSet.empty;\n\t\treturn DecorationSet.create(mapped);\n\t}\n}\n\n// --- Helpers ---\n\n/** Compares two decoration arrays for structural equality. */\nexport function decorationArraysEqual(a: readonly Decoration[], b: readonly Decoration[]): boolean {\n\tif (a === b) return true;\n\tif (a.length !== b.length) return false;\n\n\tfor (let i = 0; i < a.length; i++) {\n\t\tconst ai = a[i];\n\t\tconst bi = b[i];\n\t\tif (!ai || !bi || !decorationsEqual(ai, bi)) return false;\n\t}\n\treturn true;\n}\n\n/** Compares two individual decorations for structural equality. */\nfunction decorationsEqual(a: Decoration, b: Decoration): boolean {\n\tif (a.type !== b.type) return false;\n\tif (a.blockId !== b.blockId) return false;\n\n\tswitch (a.type) {\n\t\tcase 'inline': {\n\t\t\tconst bi = b as InlineDecoration;\n\t\t\treturn a.from === bi.from && a.to === bi.to && attrsEqual(a.attrs, bi.attrs);\n\t\t}\n\t\tcase 'node': {\n\t\t\tconst bn = b as NodeDecoration;\n\t\t\treturn attrsEqual(a.attrs, bn.attrs);\n\t\t}\n\t\tcase 'widget': {\n\t\t\tconst bw = b as WidgetDecoration;\n\t\t\treturn (\n\t\t\t\ta.offset === bw.offset && a.side === bw.side && a.key === bw.key && a.toDOM === bw.toDOM\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** Compares two DecorationAttrs objects. */\nfunction attrsEqual(a: DecorationAttrs, b: DecorationAttrs): boolean {\n\tif (a === b) return true;\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\tif (aKeys.length !== bKeys.length) return false;\n\tfor (const key of aKeys) {\n\t\tif (a[key] !== b[key]) return false;\n\t}\n\treturn true;\n}\n","/**\n * Keyboard handlers for code-block navigation and editing.\n * Handles Enter, Backspace, Tab, Shift-Tab, Escape, Arrow keys,\n * and configurable shortcuts (Mod+Enter, toggle).\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { generateBlockId, getBlockLength, getBlockText } from '../../model/Document.js';\nimport {\n\tcreateCollapsedSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\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 { CodeBlockConfig, CodeBlockKeymap } from './CodeBlockTypes.js';\n\n// --- Context Guard ---\n\ninterface CodeBlockContext {\n\treadonly state: EditorState;\n\treadonly block: BlockNode;\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n}\n\n/**\n * Guards against NodeSelection and non-code-block blocks.\n * Returns false (not handled) if the cursor is not inside a code block.\n */\nfunction withCodeBlockContext(\n\tcontext: PluginContext,\n\thandler: (ctx: CodeBlockContext) => boolean,\n): boolean {\n\tconst state: EditorState = context.getState();\n\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\n\tconst sel = 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\tblock,\n\t\tblockId: sel.anchor.blockId,\n\t\toffset: sel.anchor.offset,\n\t});\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): void {\n\tconst keymap: Record<string, () => boolean> = {\n\t\tEnter: () => handleEnter(context),\n\t\tBackspace: () => handleBackspace(context),\n\t\tTab: () => handleTab(context, config),\n\t\t'Shift-Tab': () => handleShiftTab(context, config),\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\n// --- Handler Functions ---\n\nfunction handleBackspace(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\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): 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\n\t\tif (text.endsWith('\\n') && offset === text.length) {\n\t\t\treturn exitOnDoubleEnter(context, blockId, text);\n\t\t}\n\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, offset, '\\n', [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + 1))\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t});\n}\n\nfunction handleTab(context: PluginContext, config: CodeBlockConfig): boolean {\n\treturn withCodeBlockContext(context, ({ state, blockId, offset }) => {\n\t\tconst indent: string = config.useSpaces ? ' '.repeat(config.spaceCount ?? 2) : '\\t';\n\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('input')\n\t\t\t.insertText(blockId, offset, indent, [])\n\t\t\t.setSelection(createCollapsedSelection(blockId, offset + indent.length))\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t});\n}\n\nfunction handleShiftTab(context: PluginContext, config: CodeBlockConfig): boolean {\n\treturn withCodeBlockContext(context, ({ state, block, blockId, offset }) => {\n\t\tconst text: string = getBlockText(block);\n\t\tconst lineStart: number = text.lastIndexOf('\\n', offset - 1) + 1;\n\n\t\tif (config.useSpaces) {\n\t\t\tconst spaceCount: number = config.spaceCount ?? 2;\n\t\t\tconst linePrefix: string = text.slice(lineStart, lineStart + spaceCount);\n\t\t\tif (linePrefix === ' '.repeat(spaceCount)) {\n\t\t\t\tconst tr: Transaction = state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.deleteTextAt(blockId, lineStart, lineStart + spaceCount)\n\t\t\t\t\t.setSelection(createCollapsedSelection(blockId, Math.max(lineStart, offset - spaceCount)))\n\t\t\t\t\t.build();\n\t\t\t\tcontext.dispatch(tr);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (text[lineStart] === '\\t') {\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('input')\n\t\t\t\t.deleteTextAt(blockId, lineStart, lineStart + 1)\n\t\t\t\t.setSelection(createCollapsedSelection(blockId, Math.max(lineStart, offset - 1)))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn true; // Consume event even if no dedent possible\n\t});\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\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\t\tconst idx: number = blockOrder.indexOf(blockId);\n\n\t\tif (idx < blockOrder.length - 1) {\n\t\t\tconst nextId: BlockId = blockOrder[idx + 1] as BlockId;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('command')\n\t\t\t\t.setSelection(createCollapsedSelection(nextId, 0))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t} else {\n\t\t\tinsertParagraphAfter(context, blockId);\n\t\t}\n\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\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\t\tconst idx: number = blockOrder.indexOf(blockId);\n\n\t\tif (idx < blockOrder.length - 1) {\n\t\t\tconst nextId: BlockId = blockOrder[idx + 1] as BlockId;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('command')\n\t\t\t\t.setSelection(createCollapsedSelection(nextId, 0))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t} else {\n\t\t\tinsertParagraphAfter(context, blockId);\n\t\t}\n\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\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\t\tconst idx: number = blockOrder.indexOf(blockId);\n\n\t\tif (idx > 0) {\n\t\t\tconst prevId: BlockId = blockOrder[idx - 1] as BlockId;\n\t\t\tconst prevBlock: BlockNode | undefined = state.getBlock(prevId);\n\t\t\tconst prevLen: number = prevBlock ? getBlockLength(prevBlock) : 0;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('command')\n\t\t\t\t.setSelection(createCollapsedSelection(prevId, prevLen))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\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\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\t\tconst idx: number = blockOrder.indexOf(blockId);\n\n\t\tif (idx < blockOrder.length - 1) {\n\t\t\tconst nextId: BlockId = blockOrder[idx + 1] as BlockId;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('command')\n\t\t\t\t.setSelection(createCollapsedSelection(nextId, 0))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t} else {\n\t\t\tinsertParagraphAfter(context, blockId);\n\t\t}\n\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\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\t\tconst idx: number = blockOrder.indexOf(blockId);\n\n\t\tif (idx > 0) {\n\t\t\tconst prevId: BlockId = blockOrder[idx - 1] as BlockId;\n\t\t\tconst prevBlock: BlockNode | undefined = state.getBlock(prevId);\n\t\t\tconst prevLen: number = prevBlock ? getBlockLength(prevBlock) : 0;\n\t\t\tconst tr: Transaction = state\n\t\t\t\t.transaction('command')\n\t\t\t\t.setSelection(createCollapsedSelection(prevId, prevLen))\n\t\t\t\t.build();\n\t\t\tcontext.dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\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// --- Shared Helpers ---\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\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 type { BlockNode } from '../../model/Document.js';\nimport { getBlockLength, getInlineChildren, isTextNode } from '../../model/Document.js';\nimport { createCollapsedSelection, isGapCursor, isNodeSelection } from '../../model/Selection.js';\nimport { nodeType } from '../../model/TypeBrands.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\n// --- Command Implementations ---\n\nfunction toggleCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tif (isNodeSelection(state.selection) || isGapCursor(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 (isNodeSelection(sel) || isGapCursor(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/**\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","/** Locale interface and default English locale for the CodeBlockPlugin. */\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}\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};\n\n// --- German Locale ---\n\nexport const CODE_BLOCK_LOCALE_DE: CodeBlockLocale = {\n\tlabel: 'Codeblock',\n\ttooltip: (shortcut?: string) => (shortcut ? `Codeblock (${shortcut})` : 'Codeblock'),\n\tenteredCodeBlock: 'Codeblock betreten. Escape zum Verlassen drücken.',\n\tleftCodeBlock: 'Codeblock verlassen.',\n};\n\n// --- Spanish Locale ---\n\nexport const CODE_BLOCK_LOCALE_ES: CodeBlockLocale = {\n\tlabel: 'Bloque de código',\n\ttooltip: (shortcut?: string) =>\n\t\tshortcut ? `Bloque de código (${shortcut})` : 'Bloque de código',\n\tenteredCodeBlock: 'Bloque de código activado. Pulse Escape para salir.',\n\tleftCodeBlock: 'Bloque de código desactivado.',\n};\n\n// --- French Locale ---\n\nexport const CODE_BLOCK_LOCALE_FR: CodeBlockLocale = {\n\tlabel: 'Bloc de code',\n\ttooltip: (shortcut?: string) => (shortcut ? `Bloc de code (${shortcut})` : 'Bloc de code'),\n\tenteredCodeBlock: 'Bloc de code activé. Appuyez sur Échap pour quitter.',\n\tleftCodeBlock: 'Bloc de code quitté.',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const CODE_BLOCK_LOCALE_ZH: CodeBlockLocale = {\n\tlabel: '代码块',\n\ttooltip: (shortcut?: string) => (shortcut ? `代码块 (${shortcut})` : '代码块'),\n\tenteredCodeBlock: '已进入代码块。按 Escape 退出。',\n\tleftCodeBlock: '已离开代码块。',\n};\n\n// --- Russian Locale ---\n\nexport const CODE_BLOCK_LOCALE_RU: CodeBlockLocale = {\n\tlabel: 'Блок кода',\n\ttooltip: (shortcut?: string) => (shortcut ? `Блок кода (${shortcut})` : 'Блок кода'),\n\tenteredCodeBlock: 'Вход в блок кода. Нажмите Escape для выхода.',\n\tleftCodeBlock: 'Выход из блока кода.',\n};\n\n// --- Arabic Locale ---\n\nexport const CODE_BLOCK_LOCALE_AR: CodeBlockLocale = {\n\tlabel: 'كتلة كود',\n\ttooltip: (shortcut?: string) => (shortcut ? `كتلة كود (${shortcut})` : 'كتلة كود'),\n\tenteredCodeBlock: 'تم الدخول إلى كتلة الكود. اضغط Escape للخروج.',\n\tleftCodeBlock: 'تم الخروج من كتلة الكود.',\n};\n\n// --- Hindi Locale ---\n\nexport const CODE_BLOCK_LOCALE_HI: CodeBlockLocale = {\n\tlabel: 'कोड ब्लॉक',\n\ttooltip: (shortcut?: string) => (shortcut ? `कोड ब्लॉक (${shortcut})` : 'कोड ब्लॉक'),\n\tenteredCodeBlock: 'कोड ब्लॉक में प्रवेश किया। बाहर निकलने के लिए Escape दबाएँ।',\n\tleftCodeBlock: 'कोड ब्लॉक से बाहर।',\n};\n\n// --- Locale Map ---\n\nexport const CODE_BLOCK_LOCALES: Record<string, CodeBlockLocale> = {\n\ten: CODE_BLOCK_LOCALE_EN,\n\tde: CODE_BLOCK_LOCALE_DE,\n\tes: CODE_BLOCK_LOCALE_ES,\n\tfr: CODE_BLOCK_LOCALE_FR,\n\tzh: CODE_BLOCK_LOCALE_ZH,\n\tru: CODE_BLOCK_LOCALE_RU,\n\tar: CODE_BLOCK_LOCALE_AR,\n\thi: CODE_BLOCK_LOCALE_HI,\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\nexport interface SyntaxToken {\n\treadonly from: number;\n\treadonly to: number;\n\treadonly type: string;\n}\n\nexport interface SyntaxHighlighter {\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\tgetSupportedLanguages(): readonly string[];\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\nexport interface CodeBlockConfig {\n\treadonly highlighter?: SyntaxHighlighter;\n\treadonly defaultLanguage?: string;\n\treadonly useSpaces?: boolean;\n\treadonly spaceCount?: number;\n\treadonly showCopyButton?: boolean;\n\treadonly separatorAfter?: 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}\n\nexport const DEFAULT_CONFIG: CodeBlockConfig = {\n\tdefaultLanguage: '',\n\tuseSpaces: false,\n\tspaceCount: 2,\n\tshowCopyButton: true,\n};\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// --- 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=\"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z\"/></svg>';\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 { findNodePath } from '../../model/NodeResolver.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport type { CodeBlockConfig } 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\tconfig: CodeBlockConfig,\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\tif (config.highlighter) {\n\t\t\t\treturn config.highlighter.getSupportedLanguages();\n\t\t\t}\n\t\t\treturn [];\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: string[] | undefined = findNodePath(state.doc, bid);\n\tif (!path) return;\n\n\tconst newAttrs: BlockAttrs = { ...block.attrs, [key]: value };\n\tconst tr: Transaction = state\n\t\t.transaction('command')\n\t\t.setNodeAttr(path as BlockId[], newAttrs)\n\t\t.build();\n\n\tcontext.dispatch(tr);\n}\n","/**\n * CodeBlockPlugin: orchestrates code block registration by delegating to\n * focused modules for keyboard handling, commands, and service API.\n *\n * Inline responsibilities: NodeSpec, NodeView, InputRule, Toolbar,\n * Middleware, Decorations, and lifecycle hooks (focus tracking).\n */\n\nimport type { DecorationSet } from '../../decorations/Decoration.js';\nimport { inline as inlineDecoration } from '../../decorations/Decoration.js';\nimport { DecorationSet as DecorationSetClass } from '../../decorations/Decoration.js';\nimport { CODE_BLOCK_CSS } from '../../editor/styles/code-block.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport { createBlockElement } from '../../model/NodeSpec.js';\nimport {\n\tcreateCollapsedSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\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 { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { registerCodeBlockCommands } from './CodeBlockCommands.js';\nimport { registerCodeBlockKeymaps } from './CodeBlockKeyboardHandlers.js';\nimport { CODE_BLOCK_LOCALES, type CodeBlockLocale } from './CodeBlockLocale.js';\nimport { createCodeBlockNodeViewFactory } from './CodeBlockNodeView.js';\nimport { registerCodeBlockService } from './CodeBlockService.js';\nimport type { CodeBlockConfig, CodeBlockKeymap, SyntaxToken } from './CodeBlockTypes.js';\nimport { CODE_BLOCK_ICON, DEFAULT_CONFIG, DEFAULT_KEYMAP } from './CodeBlockTypes.js';\n\n// Re-exports for backward compatibility\nexport {\n\tCODE_BLOCK_SERVICE_KEY,\n\ttype CodeBlockConfig,\n\ttype CodeBlockKeymap,\n\ttype CodeBlockService,\n\ttype SyntaxHighlighter,\n\ttype SyntaxToken,\n} from './CodeBlockTypes.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 resolvedKeymap: Readonly<Record<keyof CodeBlockKeymap, string | null>>;\n\tprivate context: PluginContext | null = null;\n\tprivate locale!: CodeBlockLocale;\n\n\tconstructor(config?: Partial<CodeBlockConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t\tthis.resolvedKeymap = {\n\t\t\t...DEFAULT_KEYMAP,\n\t\t\t...config?.keymap,\n\t\t};\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(CODE_BLOCK_LOCALES, context, this.config.locale);\n\t\tcontext.registerStyleSheet(CODE_BLOCK_CSS);\n\t\tthis.context = context;\n\n\t\tthis.registerNodeSpec(context);\n\t\tthis.registerNodeView(context);\n\t\tregisterCodeBlockCommands(context, this.config);\n\t\tregisterCodeBlockKeymaps(context, this.config, this.resolvedKeymap);\n\t\tthis.registerInputRule(context);\n\t\tthis.registerToolbarItem(context);\n\t\tthis.registerMiddleware(context);\n\t\tregisterCodeBlockService(context, this.config, () => this.context);\n\t\tthis.patchTableCellContent(context);\n\t}\n\n\tdestroy(): void {\n\t\tthis.context = null;\n\t}\n\n\tonStateChange(oldState: EditorState, newState: EditorState, _tr: Transaction): void {\n\t\tif (!this.context) return;\n\n\t\tconst oldBlockId: BlockId | null =\n\t\t\tisNodeSelection(oldState.selection) || isGapCursor(oldState.selection)\n\t\t\t\t? null\n\t\t\t\t: oldState.selection.anchor.blockId;\n\t\tconst newBlockId: BlockId | null =\n\t\t\tisNodeSelection(newState.selection) || isGapCursor(newState.selection)\n\t\t\t\t? null\n\t\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 && oldBlockId) {\n\t\t\tthis.setBlockFocused(oldBlockId, false);\n\t\t}\n\t\tif (nowInCode && newBlockId) {\n\t\t\tthis.setBlockFocused(newBlockId, true);\n\t\t}\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\tif (!this.config.highlighter) return DecorationSetClass.empty;\n\n\t\tconst decorations: ReturnType<typeof inlineDecoration>[] = [];\n\t\tconst highlighter = this.config.highlighter;\n\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\tconst tokens: readonly SyntaxToken[] = highlighter.tokenize(text, lang);\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\treturn DecorationSetClass.create(decorations);\n\t}\n\n\t// --- NodeSpec ---\n\n\tprivate registerNodeSpec(context: PluginContext): void {\n\t\tcontext.registerNodeSpec({\n\t\t\ttype: 'code_block',\n\t\t\tgroup: 'block',\n\t\t\tcontent: { allow: ['text'] },\n\t\t\tselectable: true,\n\t\t\tattrs: {\n\t\t\t\tlanguage: { default: '' },\n\t\t\t\tbackgroundColor: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(node) {\n\t\t\t\tconst pre: HTMLElement = createBlockElement('pre', node.id);\n\t\t\t\tpre.className = 'notectl-code-block';\n\t\t\t\tconst code: HTMLElement = document.createElement('code');\n\t\t\t\tcode.className = 'notectl-code-block__content';\n\t\t\t\tpre.appendChild(code);\n\t\t\t\treturn pre;\n\t\t\t},\n\t\t\ttoHTML(node, content) {\n\t\t\t\tconst lang: string = escapeHTML((node.attrs?.language as string) ?? '');\n\t\t\t\tconst bg: string = escapeHTML((node.attrs?.backgroundColor as string) ?? '');\n\t\t\t\tconst langClass: string = lang ? ` class=\"language-${lang}\"` : '';\n\t\t\t\tconst bgStyle: string = bg ? ` style=\"background-color: ${bg}\"` : '';\n\t\t\t\treturn `<pre${bgStyle}><code${langClass}>${content || ''}</code></pre>`;\n\t\t\t},\n\t\t\tparseHTML: [\n\t\t\t\t{\n\t\t\t\t\ttag: 'pre',\n\t\t\t\t\tgetAttrs(el: HTMLElement) {\n\t\t\t\t\t\tconst code: HTMLElement | null = el.querySelector('code');\n\t\t\t\t\t\tconst langClass: string = code?.className.match(/language-(\\S+)/)?.[1] ?? '';\n\t\t\t\t\t\tconst dataLang: string = code?.getAttribute('data-language') ?? '';\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tlanguage: dataLang || langClass,\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tsanitize: {\n\t\t\t\ttags: ['pre', 'code'],\n\t\t\t\tattrs: ['data-language', 'class', 'style'],\n\t\t\t},\n\t\t});\n\t}\n\n\t// --- NodeView ---\n\n\tprivate registerNodeView(context: PluginContext): void {\n\t\tcontext.registerNodeView('code_block', createCodeBlockNodeViewFactory(this.config));\n\t}\n\n\t// --- Input Rule ---\n\n\tprivate registerInputRule(context: PluginContext): void {\n\t\tcontext.registerInputRule({\n\t\t\tpattern: /^```(\\w*) $/,\n\t\t\thandler: (state, match, start, _end) => {\n\t\t\t\tconst sel = state.selection;\n\t\t\t\tif (isNodeSelection(sel) || isGapCursor(sel)) return null;\n\t\t\t\tif (!isCollapsed(sel)) return null;\n\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\t\t\t\tif (!block || block.type !== 'paragraph') return null;\n\n\t\t\t\tconst language: string = match[1] ?? '';\n\t\t\t\tconst attrs: Record<string, string | number | boolean> = {\n\t\t\t\t\tlanguage,\n\t\t\t\t\tbackgroundColor: '',\n\t\t\t\t};\n\n\t\t\t\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.deleteTextAt(sel.anchor.blockId, start, start + match[0].length)\n\t\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t\t\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0))\n\t\t\t\t\t.build();\n\t\t\t},\n\t\t});\n\t}\n\n\t// --- Toolbar ---\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'code_block',\n\t\t\tgroup: 'block',\n\t\t\ticon: CODE_BLOCK_ICON,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip(\n\t\t\t\tthis.resolvedKeymap.toggle ? formatShortcut(this.resolvedKeymap.toggle) : undefined,\n\t\t\t),\n\t\t\tcommand: 'toggleCodeBlock',\n\t\t\tpriority: 56,\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tisActive: (state) => {\n\t\t\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\t\t\treturn block?.type === 'code_block';\n\t\t\t},\n\t\t});\n\t}\n\n\t// --- Middleware (Mark Prevention) ---\n\n\tprivate registerMiddleware(context: PluginContext): void {\n\t\tcontext.registerMiddleware(\n\t\t\t(tr, state, next) => {\n\t\t\t\tconst hasMarkInCodeBlock: boolean = tr.steps.some((step) => {\n\t\t\t\t\tif (step.type !== 'addMark') return false;\n\t\t\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\t\t\treturn block?.type === 'code_block';\n\t\t\t\t});\n\n\t\t\t\tif (!hasMarkInCodeBlock) {\n\t\t\t\t\tnext(tr);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst filtered = tr.steps.filter((step) => {\n\t\t\t\t\tif (step.type !== 'addMark') return true;\n\t\t\t\t\tconst block: BlockNode | undefined = state.getBlock(step.blockId);\n\t\t\t\t\treturn block?.type !== 'code_block';\n\t\t\t\t});\n\n\t\t\t\tnext({ ...tr, steps: filtered });\n\t\t\t},\n\t\t\t{ name: 'code-block:mark-guard', priority: 50 },\n\t\t);\n\t}\n\n\t// --- Table Cell Patching ---\n\n\tprivate patchTableCellContent(context: PluginContext): void {\n\t\tconst registry = context.getSchemaRegistry();\n\t\tconst cellSpec = registry.getNodeSpec('table_cell');\n\t\tif (!cellSpec?.content) return;\n\n\t\tconst currentAllow: readonly string[] = cellSpec.content.allow ?? [];\n\t\tif (currentAllow.includes('code_block')) return;\n\n\t\tregistry.removeNodeSpec('table_cell');\n\t\tregistry.registerNodeSpec({\n\t\t\t...cellSpec,\n\t\t\tcontent: {\n\t\t\t\t...cellSpec.content,\n\t\t\t\tallow: [...currentAllow, 'code_block'],\n\t\t\t},\n\t\t});\n\t}\n\n\t// --- Helpers ---\n\n\tprivate setBlockFocused(bid: BlockId, focused: boolean): void {\n\t\tif (!this.context) return;\n\t\tconst container: HTMLElement = this.context.getContainer();\n\t\tconst el: Element | null = container.querySelector(`[data-block-id=\"${bid}\"]`);\n\t\tif (el) {\n\t\t\tel.classList.toggle('notectl-code-block--focused', focused);\n\t\t}\n\t}\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 {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__copy {\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\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy 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\tright: 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","/**\n * NodeView factory for code blocks.\n * Renders <pre> with a non-editable header (language label + copy button)\n * and a <code> content area where the Reconciler renders text.\n */\n\nimport type { 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 type { NodeView, NodeViewFactory } from '../../view/NodeView.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\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\n/** Creates a NodeViewFactory for code_block nodes. */\nexport function createCodeBlockNodeViewFactory(config: CodeBlockConfig): NodeViewFactory {\n\treturn (\n\t\tnode: BlockNode,\n\t\tgetState: () => EditorState,\n\t\t_dispatch: (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('role', 'group');\n\t\tpre.setAttribute('aria-roledescription', '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\n\t\tconst langLabel: HTMLSpanElement = document.createElement('span');\n\t\tlangLabel.className = 'notectl-code-block__language';\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', 'Copy code');\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// Screen reader live region for copy feedback\n\t\tconst copyAnnouncer: HTMLSpanElement = document.createElement('span');\n\t\tcopyAnnouncer.className = 'notectl-sr-only';\n\t\tcopyAnnouncer.setAttribute('aria-live', 'assertive');\n\t\tcopyAnnouncer.setAttribute('aria-atomic', 'true');\n\n\t\theader.appendChild(langLabel);\n\t\tif (copyBtn) {\n\t\t\theader.appendChild(copyBtn);\n\t\t}\n\t\theader.appendChild(copyAnnouncer);\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\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 = 'Esc to exit';\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\tpre.style.setProperty('--notectl-code-block-bg', config.background);\n\t\t}\n\t\tif (config.headerBackground) {\n\t\t\tpre.style.setProperty('--notectl-code-block-header-bg', config.headerBackground);\n\t\t}\n\t\tif (config.textColor) {\n\t\t\tpre.style.setProperty('--notectl-code-block-color', config.textColor);\n\t\t}\n\t\tif (config.headerColor) {\n\t\t\tpre.style.setProperty('--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 || 'plain';\n\t\t\tlangLabel.textContent = langName;\n\t\t\tpre.setAttribute('aria-label', `${langName} code block. Press Escape to exit.`);\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\tpre.style.backgroundColor = bg || '';\n\t\t}\n\n\t\tapplyAttrs(node);\n\n\t\t// --- Copy Button Handler ---\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\tnavigator.clipboard.writeText(text);\n\n\t\t\t\t// Announce to screen readers\n\t\t\t\tcopyAnnouncer.textContent = 'Copied to clipboard';\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcopyAnnouncer.textContent = '';\n\t\t\t\t}, 1000);\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"],"names":["mapDecorationThroughStep","deco","step","type","blockId","len","text","length","newFrom","from","offset","newTo","to","delLen","clampAndShift","newBlockId","sourceBlockId","targetBlockId","targetLengthBefore","removeIfBlockDeleted","side","removedNode","id","pos","delFrom","delTo","inline","attrs","node","widget","toDOM","options","key","DecorationSet","byBlock","this","static","Map","decorations","empty","map","existing","get","push","set","decos","filter","d","isEmpty","create","bid","predicate","changed","filtered","size","other","otherDecos","decorationArraysEqual","tr","steps","mapped","values","next","result","Array","isArray","r","a","b","i","ai","bi","decorationsEqual","attrsEqual","bn","bw","aKeys","Object","keys","bKeys","withCodeBlockContext","context","handler","state","getState","isNodeSelection","selection","isGapCursor","sel","block","getBlock","anchor","handleEscape","blockOrder","getBlockOrder","idx","indexOf","nextId","transaction","setSelection","createCollapsedSelection","build","dispatch","insertParagraphAfter","blockLength","getBlockLength","newId","generateBlockId","splitBlock","setBlockType","nodeType","insertCodeBlock","config","language","defaultLanguage","backgroundColor","builder","inlineChildren","getInlineChildren","child","isTextNode","mark","marks","removeMark","CODE_BLOCK_LOCALE_EN","label","tooltip","shortcut","enteredCodeBlock","leftCodeBlock","CODE_BLOCK_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_KEYMAP","insertAfter","toggle","DEFAULT_CONFIG","useSpaces","spaceCount","showCopyButton","CODE_BLOCK_SERVICE_KEY","ServiceKey","setAttr","value","path","findNodePath","doc","newAttrs","setNodeAttr","CodeBlockPlugin","name","priority","resolvedKeymap","locale","keymap","resolvePluginLocale","registerStyleSheet","registerNodeSpec","registerNodeView","registerCommand","Enter","isCollapsed","getBlockText","endsWith","trimmedLen","deleteTextAt","insertText","Backspace","Tab","indent","repeat","lineStart","lastIndexOf","slice","Math","max","Escape","ArrowDown","ArrowUp","firstNewline","prevId","prevBlock","prevLen","ArrowRight","ArrowLeft","executeCommand","registerKeymap","registerInputRule","registerToolbarItem","registerMiddleware","getContext","registerService","ctx","color","getSupportedLanguages","highlighter","patchTableCellContent","destroy","oldState","newState","_tr","oldBlockId","oldBlock","newBlock","wasInCode","nowInCode","setBlockFocused","announce","DecorationSetClass","lang","tokens","tokenize","token","inlineDecoration","class","group","content","allow","selectable","default","pre","createBlockElement","className","code","document","createElement","appendChild","escapeHTML","bg","parseHTML","tag","el","querySelector","langClass","match","getAttribute","sanitize","tags","_dispatch","setAttribute","header","langLabel","copyBtn","innerHTML","copyAnnouncer","escHint","textContent","background","style","setProperty","headerBackground","textColor","headerColor","currentNodeId","applyAttrs","n","langName","removeAttribute","addEventListener","e","preventDefault","stopPropagation","navigator","clipboard","writeText","setTimeout","dom","contentDOM","update","updatedNode","classList","add","remove","pattern","start","_end","icon","formatShortcut","command","separatorAfter","isActive","some","registry","getSchemaRegistry","cellSpec","getNodeSpec","currentAllow","includes","removeNodeSpec","focused","getContainer"],"mappings":";;;;;;;;AA0BO,SAASA,EACfC,IACAC,IAAAA;AAEA,UAAQD,GAAKE,MAAAA;AAAAA,IACZ,KAAK;AACJ,cAQH,SACCF,IACAC,IAAAA;AAEA,gBAAQA,GAAKC,MAAAA;AAAAA,UACZ,KAAK;AACJ,oBA4CH,SAAyBF,IAAwBC,IAAAA;AAChD,kBAAID,GAAKG,YAAYF,GAAKE,QAAS,QAAOH;AAE1C,oBAAMI,KAAcH,GAAKI,KAAKC,QAExBC,KAAkBP,GAAKQ,OAAOP,GAAKQ,SAAST,GAAKQ,OAAOJ,KAAMJ,GAAKQ,MAEnEE,KAAgBV,GAAKW,MAAMV,GAAKQ,SAAST,GAAKW,KAAKP,KAAMJ,GAAKW;AAEpE,qBAAIJ,OAAYP,GAAKQ,QAAQE,OAAUV,GAAKW,KAAWX,KAChD,EAAA,GAAKA,IAAMQ,MAAMD,IAASI,IAAID,GAAAA;AAAAA,YACtC,GAvD0BV,IAAMC,EAAAA;AAAAA,UAC9B,KAAK;AACJ,oBAuEH,SAAyBD,IAAwBC,IAAAA;AAChD,kBAAID,GAAKG,YAAYF,GAAKE,QAAS,QAAOH;AAE1C,oBAAMY,KAAiBX,GAAKU,KAAKV,GAAKO,MAChCD,KAAkBM,EAAcb,GAAKQ,MAAMP,GAAKO,MAAMP,GAAKU,IAAIC,EAAAA,GAC/DF,KAAgBG,EAAcb,GAAKW,IAAIV,GAAKO,MAAMP,GAAKU,IAAIC;AAEjE,qBAAIL,MAAWG,KAAc,OACzBH,OAAYP,GAAKQ,QAAQE,OAAUV,GAAKW,KAAWX,KAChD,EA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,IAAAA,MACHA,GAAGuC,UAAUvI,OAAO,+BAA+B0J,EAAAA;AAAAA,EAErD;AAAA;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-CFJFD4lF.mjs","sources":["../../src/plugins/alignment/AlignmentLocale.ts","../../src/plugins/alignment/AlignmentPlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the AlignmentPlugin. */\n\nexport interface AlignmentLocale {\n\treadonly alignLeft: string;\n\treadonly alignCenter: string;\n\treadonly alignRight: string;\n\treadonly justify: string;\n\treadonly toolbarLabel: string;\n\treadonly toolbarTooltip: string;\n}\n\n// --- Default English Locale ---\n\nexport const ALIGNMENT_LOCALE_EN: AlignmentLocale = {\n\talignLeft: 'Align Left',\n\talignCenter: 'Align Center',\n\talignRight: 'Align Right',\n\tjustify: 'Justify',\n\ttoolbarLabel: 'Alignment',\n\ttoolbarTooltip: 'Alignment',\n};\n\n// --- German Locale ---\n\nexport const ALIGNMENT_LOCALE_DE: AlignmentLocale = {\n\talignLeft: 'Linksbündig',\n\talignCenter: 'Zentriert',\n\talignRight: 'Rechtsbündig',\n\tjustify: 'Blocksatz',\n\ttoolbarLabel: 'Ausrichtung',\n\ttoolbarTooltip: 'Ausrichtung',\n};\n\n// --- Spanish Locale ---\n\nexport const ALIGNMENT_LOCALE_ES: AlignmentLocale = {\n\talignLeft: 'Alinear a la izquierda',\n\talignCenter: 'Centrar',\n\talignRight: 'Alinear a la derecha',\n\tjustify: 'Justificar',\n\ttoolbarLabel: 'Alineación',\n\ttoolbarTooltip: 'Alineación',\n};\n\n// --- French Locale ---\n\nexport const ALIGNMENT_LOCALE_FR: AlignmentLocale = {\n\talignLeft: 'Aligner à gauche',\n\talignCenter: 'Centrer',\n\talignRight: 'Aligner à droite',\n\tjustify: 'Justifier',\n\ttoolbarLabel: 'Alignement',\n\ttoolbarTooltip: 'Alignement',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const ALIGNMENT_LOCALE_ZH: AlignmentLocale = {\n\talignLeft: '左对齐',\n\talignCenter: '居中',\n\talignRight: '右对齐',\n\tjustify: '两端对齐',\n\ttoolbarLabel: '对齐',\n\ttoolbarTooltip: '对齐',\n};\n\n// --- Russian Locale ---\n\nexport const ALIGNMENT_LOCALE_RU: AlignmentLocale = {\n\talignLeft: 'По левому краю',\n\talignCenter: 'По центру',\n\talignRight: 'По правому краю',\n\tjustify: 'По ширине',\n\ttoolbarLabel: 'Выравнивание',\n\ttoolbarTooltip: 'Выравнивание',\n};\n\n// --- Arabic Locale ---\n\nexport const ALIGNMENT_LOCALE_AR: AlignmentLocale = {\n\talignLeft: 'محاذاة لليسار',\n\talignCenter: 'توسيط',\n\talignRight: 'محاذاة لليمين',\n\tjustify: 'ضبط',\n\ttoolbarLabel: 'المحاذاة',\n\ttoolbarTooltip: 'المحاذاة',\n};\n\n// --- Hindi Locale ---\n\nexport const ALIGNMENT_LOCALE_HI: AlignmentLocale = {\n\talignLeft: 'बाएँ संरेखित करें',\n\talignCenter: 'केंद्र में',\n\talignRight: 'दाएँ संरेखित करें',\n\tjustify: 'समायोजित करें',\n\ttoolbarLabel: 'संरेखण',\n\ttoolbarTooltip: 'संरेखण',\n};\n\n// --- Locale Map ---\n\nexport const ALIGNMENT_LOCALES: Record<string, AlignmentLocale> = {\n\ten: ALIGNMENT_LOCALE_EN,\n\tde: ALIGNMENT_LOCALE_DE,\n\tes: ALIGNMENT_LOCALE_ES,\n\tfr: ALIGNMENT_LOCALE_FR,\n\tzh: ALIGNMENT_LOCALE_ZH,\n\tru: ALIGNMENT_LOCALE_RU,\n\tar: ALIGNMENT_LOCALE_AR,\n\thi: ALIGNMENT_LOCALE_HI,\n};\n","/**\n * AlignmentPlugin: adds left/center/right/justify alignment as a block\n * attribute on paragraphs, headings, images, and other alignable types.\n * Patches their NodeSpecs to render the `align` attribute via inline\n * `text-align` style and provides toggle commands, keyboard shortcuts,\n * and a toolbar dropdown. Handles both TextSelection and NodeSelection.\n */\n\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { findNodePath } from '../../model/NodeResolver.js';\nimport { isNodeSelection, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { ALIGNMENT_LOCALES, type AlignmentLocale } from './AlignmentLocale.js';\n\n// --- Public Types ---\n\nexport type BlockAlignment = 'left' | 'center' | 'right' | 'justify';\n\nexport interface AlignmentConfig {\n\t/** Which alignments to expose. Defaults to all four. */\n\treadonly alignments: readonly BlockAlignment[];\n\t/** Block types that support alignment. Defaults to paragraph + heading + title + subtitle + table_cell + image. */\n\treadonly alignableTypes: readonly string[];\n\t/** Per-type default alignment (e.g. `{ image: 'center' }`). Falls back to `'left'`. */\n\treadonly defaults: Readonly<Record<string, BlockAlignment>>;\n\t/** When true, a separator is rendered after the toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: AlignmentLocale;\n}\n\n// --- Constants ---\n\nconst DEFAULT_CONFIG: AlignmentConfig = {\n\talignments: ['left', 'center', 'right', 'justify'],\n\talignableTypes: ['paragraph', 'heading', 'title', 'subtitle', 'table_cell', 'image'],\n\tdefaults: { image: 'center' },\n};\n\nexport const ALIGNMENT_ICONS: Readonly<Record<BlockAlignment, string>> = {\n\tleft: '<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z\"/></svg>',\n\tcenter:\n\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z\"/></svg>',\n\tright:\n\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z\"/></svg>',\n\tjustify:\n\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zM3 3v2h18V3H3z\"/></svg>',\n};\n\n// --- Plugin ---\n\nexport class AlignmentPlugin implements Plugin {\n\treadonly id = 'alignment';\n\treadonly name = 'Alignment';\n\treadonly priority = 90;\n\n\tprivate readonly config: AlignmentConfig;\n\tprivate locale!: AlignmentLocale;\n\tprivate alignableTypes!: ReadonlySet<string>;\n\n\tconstructor(config?: Partial<AlignmentConfig>) {\n\t\tthis.config = {\n\t\t\t...DEFAULT_CONFIG,\n\t\t\t...config,\n\t\t\tdefaults: { ...DEFAULT_CONFIG.defaults, ...config?.defaults },\n\t\t};\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(ALIGNMENT_LOCALES, context, this.config.locale);\n\n\t\tthis.alignableTypes = new Set(this.config.alignableTypes);\n\t\tthis.patchNodeSpecs(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerKeymaps(context);\n\t\tthis.registerToolbarItem(context);\n\t\tthis.registerMiddleware(context);\n\t}\n\n\t// --- NodeSpec Patching ---\n\n\t/**\n\t * Patches existing NodeSpecs for alignable block types to support the\n\t * `align` attribute and render it as an inline style. Skips types\n\t * that already define an `align` attribute in their spec.\n\t */\n\tprivate patchNodeSpecs(context: PluginContext): void {\n\t\tconst registry = context.getSchemaRegistry();\n\n\t\tfor (const type of this.config.alignableTypes) {\n\t\t\tconst spec = registry.getNodeSpec(type);\n\t\t\tif (!spec) continue;\n\n\t\t\t// Skip types that already declare an `align` attr (e.g. image)\n\t\t\tif (spec.attrs?.align) continue;\n\n\t\t\tconst originalToDOM = spec.toDOM;\n\t\t\tconst defaultAlign: BlockAlignment = this.config.defaults[type] ?? 'left';\n\n\t\t\tregistry.removeNodeSpec(type);\n\t\t\tregistry.registerNodeSpec({\n\t\t\t\t...spec,\n\t\t\t\tattrs: {\n\t\t\t\t\t...spec.attrs,\n\t\t\t\t\talign: { default: defaultAlign },\n\t\t\t\t},\n\t\t\t\ttoDOM(node) {\n\t\t\t\t\tconst el = originalToDOM.call(spec, node);\n\t\t\t\t\tapplyAlignment(el, node);\n\t\t\t\t\treturn el;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t// --- Commands ---\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tfor (const alignment of this.config.alignments) {\n\t\t\tcontext.registerCommand(`align${capitalize(alignment)}`, () => {\n\t\t\t\treturn this.setAlignment(context, alignment);\n\t\t\t});\n\t\t}\n\t}\n\n\t// --- Keymaps ---\n\n\tprivate registerKeymaps(context: PluginContext): void {\n\t\tconst bindings: Record<string, () => boolean> = {};\n\n\t\tif (this.config.alignments.includes('left')) {\n\t\t\tbindings['Mod-Shift-L'] = () => context.executeCommand('alignLeft');\n\t\t}\n\t\tif (this.config.alignments.includes('center')) {\n\t\t\tbindings['Mod-Shift-E'] = () => context.executeCommand('alignCenter');\n\t\t}\n\t\tif (this.config.alignments.includes('right')) {\n\t\t\tbindings['Mod-Shift-R'] = () => context.executeCommand('alignRight');\n\t\t}\n\t\tif (this.config.alignments.includes('justify')) {\n\t\t\tbindings['Mod-Shift-J'] = () => context.executeCommand('alignJustify');\n\t\t}\n\n\t\tif (Object.keys(bindings).length > 0) {\n\t\t\tcontext.registerKeymap(bindings);\n\t\t}\n\t}\n\n\t// --- Toolbar ---\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst dropdownItems = this.config.alignments.map((alignment) => ({\n\t\t\tlabel: this.getAlignmentLabel(alignment),\n\t\t\tcommand: `align${capitalize(alignment)}`,\n\t\t\ticon: ALIGNMENT_ICONS[alignment],\n\t\t}));\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'alignment',\n\t\t\tgroup: 'block',\n\t\t\ticon: ALIGNMENT_ICONS.left,\n\t\t\tlabel: this.locale.toolbarLabel,\n\t\t\ttooltip: this.locale.toolbarTooltip,\n\t\t\tcommand: 'alignLeft',\n\t\t\tpriority: 60,\n\t\t\tpopupType: 'dropdown',\n\t\t\tpopupConfig: { items: dropdownItems },\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tisActive: (state) => this.isNonDefaultAlignment(state),\n\t\t\tisEnabled: (state) => this.isAlignable(state),\n\t\t});\n\t}\n\n\tprivate getAlignmentLabel(alignment: BlockAlignment): string {\n\t\tconst labels: Record<BlockAlignment, string> = {\n\t\t\tleft: this.locale.alignLeft,\n\t\t\tcenter: this.locale.alignCenter,\n\t\t\tright: this.locale.alignRight,\n\t\t\tjustify: this.locale.justify,\n\t\t};\n\t\treturn labels[alignment];\n\t}\n\n\t// --- Middleware ---\n\n\t/**\n\t * Preserves the `align` attribute when other plugins change the block\n\t * type (e.g. paragraph → heading) via `setBlockType`, which replaces attrs.\n\t */\n\tprivate registerMiddleware(context: PluginContext): void {\n\t\tcontext.registerMiddleware(\n\t\t\t(tr, _state, next) => {\n\t\t\t\tlet patched = false;\n\n\t\t\t\tconst patchedSteps = tr.steps.map((step) => {\n\t\t\t\t\tif (step.type !== 'setBlockType') return step;\n\t\t\t\t\tif (!this.alignableTypes.has(step.nodeType)) return step;\n\n\t\t\t\t\tconst prevAlign = step.previousAttrs?.align;\n\t\t\t\t\tif (!prevAlign || prevAlign === 'left') return step;\n\n\t\t\t\t\t// Carry forward align into new attrs\n\t\t\t\t\tpatched = true;\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...step,\n\t\t\t\t\t\tattrs: { ...step.attrs, align: prevAlign },\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tnext(patched ? { ...tr, steps: patchedSteps } : tr);\n\t\t\t},\n\t\t\t{ name: 'alignment:preserve-align' },\n\t\t);\n\t}\n\n\t// --- Alignment Logic ---\n\n\t/**\n\t * Gets the selected block, handling both TextSelection and NodeSelection.\n\t */\n\tprivate getSelectedBlock(state: EditorState): BlockNode | undefined {\n\t\tconst sel = state.selection;\n\t\tif (isNodeSelection(sel)) {\n\t\t\treturn state.getBlock(sel.nodeId);\n\t\t}\n\t\tif (isTextSelection(sel)) {\n\t\t\treturn state.getBlock(sel.anchor.blockId);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Gets the block ID of the selected block, handling both selection types.\n\t */\n\tprivate getSelectedBlockId(state: EditorState): BlockId | undefined {\n\t\tconst sel = state.selection;\n\t\tif (isNodeSelection(sel)) return sel.nodeId;\n\t\tif (isTextSelection(sel)) return sel.anchor.blockId;\n\t\treturn undefined;\n\t}\n\n\tprivate setAlignment(context: PluginContext, alignment: BlockAlignment): boolean {\n\t\tconst state = context.getState();\n\t\tconst block = this.getSelectedBlock(state);\n\t\tif (!block || !this.alignableTypes.has(block.type)) return false;\n\n\t\tconst blockId = this.getSelectedBlockId(state);\n\t\tif (!blockId) return false;\n\n\t\tconst path = findNodePath(state.doc, blockId);\n\t\tif (!path) return false;\n\n\t\tconst newAttrs = { ...block.attrs, align: alignment };\n\n\t\tconst tr = state\n\t\t\t.transaction('command')\n\t\t\t.setNodeAttr(path as BlockId[], newAttrs)\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\tprivate isNonDefaultAlignment(state: EditorState): boolean {\n\t\tconst block = this.getSelectedBlock(state);\n\t\tif (!block || !this.alignableTypes.has(block.type)) return false;\n\t\tconst align = block.attrs?.align;\n\t\tconst defaultAlign: BlockAlignment = this.config.defaults[block.type] ?? 'left';\n\t\treturn align != null && align !== defaultAlign;\n\t}\n\n\tprivate isAlignable(state: EditorState): boolean {\n\t\tconst block = this.getSelectedBlock(state);\n\t\treturn block != null && this.alignableTypes.has(block.type);\n\t}\n}\n\n// --- Helpers ---\n\nfunction applyAlignment(el: HTMLElement, node: BlockNode): void {\n\tconst align = node.attrs?.align;\n\tif (typeof align === 'string' && align !== 'left') {\n\t\tel.style.textAlign = align;\n\t}\n}\n\nfunction capitalize(s: string): string {\n\treturn s.charAt(0).toUpperCase() + s.slice(1);\n}\n"],"names":["ALIGNMENT_LOCALE_EN","alignLeft","alignCenter","alignRight","justify","toolbarLabel","toolbarTooltip","ALIGNMENT_LOCALE_DE","ALIGNMENT_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","alignments","alignableTypes","defaults","image","ALIGNMENT_ICONS","left","center","right","AlignmentPlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","Set","patchNodeSpecs","registerCommands","registerKeymaps","registerToolbarItem","registerMiddleware","registry","getSchemaRegistry","type","spec","getNodeSpec","attrs","align","originalToDOM","toDOM","defaultAlign","removeNodeSpec","registerNodeSpec","default","node","el","call","applyAlignment","alignment","registerCommand","capitalize","setAlignment","bindings","includes","executeCommand","Object","keys","length","registerKeymap","dropdownItems","map","label","getAlignmentLabel","command","icon","group","tooltip","popupType","popupConfig","items","separatorAfter","isActive","state","isNonDefaultAlignment","isEnabled","isAlignable","tr","_state","next","patched","patchedSteps","steps","step","has","nodeType","prevAlign","previousAttrs","sel","selection","isNodeSelection","getBlock","nodeId","isTextSelection","anchor","blockId","getState","block","getSelectedBlock","getSelectedBlockId","path","findNodePath","doc","newAttrs","transaction","setNodeAttr","setSelection","build","dispatch","style","textAlign","s","charAt","toUpperCase","slice"],"mappings":";;;AAaO,MAAMA,IAAuC,EACnDC,WAAW,cACXC,aAAa,gBACbC,YAAY,eACZC,SAAS,WACTC,cAAc,aACdC,gBAAgB,YAAA,GAKJC,IAAuC,EACnDN,WAAW,eACXC,aAAa,aACbC,YAAY,gBACZC,SAAS,aACTC,cAAc,eACdC,gBAAgB,cAAA,GAuEJE,IAAqD,EACjEC,IAAIT,GACJU,IAAIH,GACJI,IArEmD,EACnDV,WAAW,0BACXC,aAAa,WACbC,YAAY,w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