@notectl/core 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{CaretNavigationPlugin-mQ1nxJ6m.mjs → CaretNavigationPlugin-C-6zNBbl.mjs} +2 -2
- package/dist/chunks/{CaretNavigationPlugin-mQ1nxJ6m.mjs.map → CaretNavigationPlugin-C-6zNBbl.mjs.map} +1 -1
- package/dist/chunks/{CodeBlockPlugin-oPGiMno0.mjs → CodeBlockPlugin-C8H0nfF6.mjs} +2 -2
- package/dist/chunks/{CodeBlockPlugin-oPGiMno0.mjs.map → CodeBlockPlugin-C8H0nfF6.mjs.map} +1 -1
- package/dist/chunks/FontPlugin-BDjM9v3y.mjs +2 -0
- package/dist/chunks/FontPlugin-BDjM9v3y.mjs.map +1 -0
- package/dist/chunks/{ListPlugin-CZgkinoS.mjs → ListPlugin-C_YjbVjT.mjs} +2 -2
- package/dist/chunks/ListPlugin-C_YjbVjT.mjs.map +1 -0
- package/dist/chunks/{SmartPastePlugin-BvYBbHSA.mjs → SmartPastePlugin-pejM1Zyk.mjs} +2 -2
- package/dist/chunks/{SmartPastePlugin-BvYBbHSA.mjs.map → SmartPastePlugin-pejM1Zyk.mjs.map} +1 -1
- package/dist/chunks/XmlDetector-B1y1NzDL.mjs +2 -0
- package/dist/chunks/XmlDetector-B1y1NzDL.mjs.map +1 -0
- package/dist/chunks/{XmlSupport-Czr8xQB1.mjs → XmlSupport-DRkIIe34.mjs} +2 -2
- package/dist/chunks/{XmlSupport-Czr8xQB1.mjs.map → XmlSupport-DRkIIe34.mjs.map} +1 -1
- package/dist/chunks/{full-B-bw4M7L.mjs → full-NtKyNKJ6.mjs} +2 -2
- package/dist/chunks/{full-B-bw4M7L.mjs.map → full-NtKyNKJ6.mjs.map} +1 -1
- package/dist/chunks/minimal-gSvMMQTU.mjs +2 -0
- package/dist/chunks/{minimal-CMt909kl.mjs.map → minimal-gSvMMQTU.mjs.map} +1 -1
- package/dist/chunks/src-CHVVMZB_.mjs +2 -0
- package/dist/chunks/src-CHVVMZB_.mjs.map +1 -0
- package/dist/editor/styles/list.d.ts +1 -1
- package/dist/editor/styles/list.d.ts.map +1 -1
- package/dist/full.mjs +1 -1
- package/dist/model/KeymapRegistry.d.ts.map +1 -1
- package/dist/notectl-core.mjs +1 -1
- package/dist/notectl-core.umd.js +1 -1
- package/dist/notectl-core.umd.js.map +1 -1
- package/dist/plugins/caret-navigation.mjs +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/font/FontPlugin.d.ts.map +1 -1
- package/dist/plugins/font.mjs +1 -1
- package/dist/plugins/language.mjs +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/smart-paste/detectors/JavaDetector.d.ts.map +1 -1
- package/dist/plugins/smart-paste.mjs +1 -1
- package/dist/presets/full.mjs +1 -1
- package/dist/presets/minimal.mjs +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/view/BlockWrapperManagement.d.ts +6 -4
- package/dist/view/BlockWrapperManagement.d.ts.map +1 -1
- package/dist/view/CaretNavigation.d.ts +5 -4
- package/dist/view/CaretNavigation.d.ts.map +1 -1
- package/dist/view/EditorView.d.ts +9 -1
- package/dist/view/EditorView.d.ts.map +1 -1
- package/dist/view/EditorViewEvents.d.ts +1 -1
- package/dist/view/EditorViewEvents.d.ts.map +1 -1
- package/dist/view/Reconciler.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/chunks/FontPlugin-DYntd3gN.mjs +0 -2
- package/dist/chunks/FontPlugin-DYntd3gN.mjs.map +0 -1
- package/dist/chunks/ListPlugin-CZgkinoS.mjs.map +0 -1
- package/dist/chunks/XmlDetector-BiWxa0RJ.mjs +0 -2
- package/dist/chunks/XmlDetector-BiWxa0RJ.mjs.map +0 -1
- package/dist/chunks/minimal-CMt909kl.mjs +0 -2
- package/dist/chunks/src-dxsvbiql.mjs +0 -2
- package/dist/chunks/src-dxsvbiql.mjs.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{S as e,a as t,c as o,d as n,g as c,m as r,y as s}from"./Document-DnPKbcPE.mjs";import{o as l,t as i,u as a}from"./Selection-B14e7gd0.mjs";import{t as d}from"./Commands-ByBjgD3-.mjs";import{a as g}from"./TypeBrands-BQR8dEYU.mjs";import{n as u}from"./DomUtils-BkyCg-OO.mjs";import{r as h}from"./HTMLUtils-BLwp5G4f.mjs";import{n as p}from"./NodeResolver-BkOsZnuU.mjs";import{a as k,n as b,o as f,t as m}from"./CommandHelpers-G6M-qXJR.mjs";import{s as y}from"./StyleRuntime-Bwde5icB.mjs";import{n as C}from"./Plugin-C4cBw3bs.mjs";import{i as x,r as B,t as v}from"./Decoration-D-yB-H5v.mjs";import{t as S}from"./SyntaxTokenTypes-CY2-rJCA.mjs";import{i as _}from"./PluginHelpers-BZU5rE44.mjs";import{t as w}from"./ShortcutFormatting-c0IajwWG.mjs";import{i as I}from"./XmlDetector-BiWxa0RJ.mjs";import{a as A,r as L,t as T}from"./XmlSupport-Czr8xQB1.mjs";var M=`\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__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${S.map(e=>`.notectl-token--${e} {\n\tcolor: var(--notectl-code-token-${e});\n\tfont-style: var(--notectl-code-token-${e}-font-style, inherit);\n\tfont-weight: var(--notectl-code-token-${e}-font-weight, inherit);\n}`).join("\n")}\n`,N=class{bundles=/* @__PURE__ */new Map;listeners=[];register(e){this.bundles.set(e.id,e);for(const t of this.listeners)t(e)}onRegister(e){this.listeners.push(e);for(const t of this.bundles.values())e(t)}get(e){return this.bundles.get(e)}getAll(){return[...this.bundles.values()]}};function j(e,t){const o=e.getState();if(!a(o.selection))return!1;const n=o.selection,c=o.getBlock(n.anchor.blockId);return!(!c||"code_block"!==c.type)&&t({state:o,block:c,blockId:n.anchor.blockId,offset:n.anchor.offset})}function E(e){return j(e,({state:t,blockId:o})=>{const n=t.getBlockOrder(),c=n.indexOf(o);if(c<n.length-1){const o=n[c+1],r=t.transaction("command").setSelection(i(o,0)).build();e.dispatch(r)}else z(e,o);return!0})}function z(e,t){const c=e.getState(),r=c.getBlock(t);if(!r)return;const s=n(r),l=o(),a=c.transaction("command").splitBlock(t,s,l).setBlockType(l,g("paragraph")).setSelection(i(l,0)).build();e.dispatch(a)}function H(t,o){const r=t.getState(),s=r.selection;if(!a(s))return!1;const l=r.getBlock(s.anchor.blockId);if(!l||"code_block"===l.type)return!1;const d={language:o.defaultLanguage??"",backgroundColor:""},u=r.transaction("command");return function(t,o){if(0===n(o))return;const r=c(o);let s=0;for(const n of r)if(e(n)){if(n.text.length>0)for(const e of n.marks)t.removeMark(o.id,s,s+n.text.length,e);s+=n.text.length}else s+=1}(u,l),u.setBlockType(s.anchor.blockId,g("code_block"),d).setSelection(i(s.anchor.blockId,0)),t.dispatch(u.build()),!0}function O(e,n){const c=p(e.doc,n);if(!c)return null;const r=b(c),l=f(e,r),a=k(l,n);if(a<0)return null;const d=e.transaction("command");if(1===l.length){const e=o();return d.insertNode(r,0,t(e)),d.removeNode(r,1),d.setSelection(i(e,0)),d.build()}d.removeNode(r,a);const g=l[a-1];if(g&&s(g)){const t=m(e,g.id,"end");if(t)return d.setSelection(t),d.build()}const u=l[a+1];if(u&&s(u)){const t=m(e,u.id,"start");t&&d.setSelection(t)}return d.build()}var R={label:"Code Block",tooltip:e=>e?`Code Block (${e})`:"Code Block",enteredCodeBlock:"Entered code block. Press Escape to exit.",leftCodeBlock:"Left code block.",copyCodeAria:"Copy code",escToExit:"Esc to exit",codeBlockAriaLabel:e=>`${e} code block. Press Escape to exit.`,copiedToClipboard:"Copied to clipboard",deleteCodeBlockAria:"Delete code block",deletedCodeBlock:"Code block deleted"},$=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar-M3QzJIS8.mjs"),"./locales/de.ts":()=>import("./de-ClJaNWJr.mjs"),"./locales/es.ts":()=>import("./es-DIH9KVn1.mjs"),"./locales/fr.ts":()=>import("./fr-BZRak2_s.mjs"),"./locales/hi.ts":()=>import("./hi-DkEmvBok.mjs"),"./locales/pt.ts":()=>import("./pt-DCfJFt-v.mjs"),"./locales/ru.ts":()=>import("./ru-CsFv_mi4.mjs"),"./locales/zh.ts":()=>import("./zh-D9QN2C7q.mjs")});async function P(e){if("en"===e)return R;const t=$[`./locales/${e}.ts`];if(!t)return R;try{return(await t()).default}catch{return R}}var D={insertAfter:"Mod-Enter",toggle:"Mod-Shift-M"},V={defaultLanguage:"",useSpaces:!1,spaceCount:2,showCopyButton:!0},F=new C("codeBlock"),K=new C("syntaxHighlighter");function U(e,t,o,n){const c=e.getState(),r=c.getBlock(t);if(!r||"code_block"!==r.type)return;const s=c.getNodePath(t);if(!s)return;const l={...r.attrs,[o]:n},i=c.transaction("command").setNodeAttr(s,l).build();e.dispatch(i)}var G=class{languageMap=/* @__PURE__ */new Map;constructor(e){if(e)for(const t of e)this.registerLanguageInternal(t)}registerLanguage(e){this.registerLanguageInternal(e)}tokenize(e,t){const o=this.languageMap.get(t.toLowerCase());if(!o)return[];const n=[];let c=0;for(;c<e.length;){let t=!1;for(const r of o.patterns){const o=r.pattern.exec(e.slice(c));if(o&&o[0].length>0){n.push({from:c,to:c+o[0].length,type:r.type}),c+=o[0].length,t=!0;break}}t||c++}return n}getSupportedLanguages(){const e=/* @__PURE__ */new Set;for(const t of this.languageMap.values()){e.add(t.name);for(const o of t.aliases)e.add(o)}return[...e]}registerLanguageInternal(e){this.languageMap.set(e.name.toLowerCase(),e);for(const t of e.aliases)this.languageMap.set(t.toLowerCase(),e)}},X=class{id="code-block";name="Code Block";priority=36;config;resolvedKeymap;context=null;locale;highlighter=null;languageRegistry=new N;tokenCache=/* @__PURE__ */new Map;constructor(e){this.config={...V,...e},this.resolvedKeymap={...D,...e?.keymap}}async init(e){this.locale=await _(e,this.config.locale,R,P),e.registerStyleSheet(M),this.context=e,this.initHighlighter(),this.registerLanguageRegistry(e),this.registerNodeSpec(e),this.registerNodeView(e),function(e,t){e.registerCommand("toggleCodeBlock",()=>function(e,t){const o=e.getState();if(!a(o.selection))return!1;const n=o.getBlock(o.selection.anchor.blockId);if(!n)return!1;if("code_block"===n.type){const t=o.transaction("command").setBlockType(o.selection.anchor.blockId,g("paragraph")).setSelection(o.selection).build();return e.dispatch(t),!0}return H(e,t)}(e,t)),e.registerCommand("insertCodeBlock",()=>H(e,t)),e.registerCommand("setCodeBlockLanguage",()=>!1),e.registerCommand("setCodeBlockBackground",()=>!1),e.registerCommand("exitCodeBlock",()=>E(e)),e.registerCommand("deleteCodeBlock",()=>function(e){const t=e.getState();if(!a(t.selection))return!1;const o=t.getBlock(t.selection.anchor.blockId);if(!o||"code_block"!==o.type)return!1;const n=O(t,o.id);return!!n&&(e.dispatch(n),!0)}(e))}(e,this.config),function(e,t,c){const s={Enter:()=>function(e){return j(e,({state:t,block:n,blockId:c,offset:s})=>{if(!l(t.selection))return!1;const a=r(n);if(a.endsWith("\n")&&s===a.length)return function(e,t,n){const c=e.getState(),r=n.length-1,s=o(),l=c.transaction("input").deleteTextAt(t,r,n.length).splitBlock(t,r,s).setBlockType(s,g("paragraph")).setSelection(i(s,0)).build();return e.dispatch(l),!0}(e,c,a);const d=t.transaction("input").insertText(c,s,"\n",[]).setSelection(i(c,s+1)).build();return e.dispatch(d),!0})}(e),Backspace:()=>function(e){return j(e,({state:t,blockId:o,offset:n})=>{if(!l(t.selection))return!1;if(0!==n)return!1;const c=t.transaction("input").setBlockType(o,g("paragraph")).setSelection(t.selection).build();return e.dispatch(c),!0})}(e),Tab:()=>function(e,t){return j(e,({state:o,blockId:n,offset:c})=>{const r=t.useSpaces?" ".repeat(t.spaceCount??2):"\t",s=o.transaction("input").insertText(n,c,r,[]).setSelection(i(n,c+r.length)).build();return e.dispatch(s),!0})}(e,t),"Shift-Tab":()=>function(e,t){return j(e,({state:o,block:n,blockId:c,offset:s})=>{const l=r(n),a=l.lastIndexOf("\n",s-1)+1;if(t.useSpaces){const n=t.spaceCount??2;if(l.slice(a,a+n)===" ".repeat(n)){const t=o.transaction("input").deleteTextAt(c,a,a+n).setSelection(i(c,Math.max(a,s-n))).build();return e.dispatch(t),!0}}else if("\t"===l[a]){const t=o.transaction("input").deleteTextAt(c,a,a+1).setSelection(i(c,Math.max(a,s-1))).build();return e.dispatch(t),!0}return!0})}(e,t),Escape:()=>E(e),ArrowDown:()=>function(e){return j(e,({state:t,block:o,blockId:n,offset:c})=>{if(!l(t.selection))return!1;if(-1!==r(o).indexOf("\n",c))return!1;const s=t.getBlockOrder(),a=s.indexOf(n);if(a<s.length-1){const o=s[a+1],n=t.transaction("command").setSelection(i(o,0)).build();e.dispatch(n)}else z(e,n);return!0})}(e),ArrowUp:()=>function(e){return j(e,({state:t,block:o,blockId:c,offset:s})=>{if(!l(t.selection))return!1;const a=r(o).indexOf("\n");if(-1!==a&&s>a)return!1;const d=t.getBlockOrder(),g=d.indexOf(c);if(g>0){const o=d[g-1],c=t.getBlock(o),r=c?n(c):0,s=t.transaction("command").setSelection(i(o,r)).build();return e.dispatch(s),!0}return!1})}(e),ArrowRight:()=>function(e){return j(e,({state:t,block:o,blockId:n,offset:c})=>{if(!l(t.selection))return!1;if(c!==r(o).length)return!1;const s=t.getBlockOrder(),a=s.indexOf(n);if(a<s.length-1){const o=s[a+1],n=t.transaction("command").setSelection(i(o,0)).build();e.dispatch(n)}else z(e,n);return!0})}(e),ArrowLeft:()=>function(e){return j(e,({state:t,blockId:o,offset:c})=>{if(!l(t.selection))return!1;if(0!==c)return!1;const r=t.getBlockOrder(),s=r.indexOf(o);if(s>0){const o=r[s-1],c=t.getBlock(o),l=c?n(c):0,a=t.transaction("command").setSelection(i(o,l)).build();return e.dispatch(a),!0}return!1})}(e)},{insertAfter:a,toggle:d}=c;a&&(s[a]=()=>function(e){return j(e,({blockId:t})=>(z(e,t),!0))}(e)),d&&(s[d]=()=>e.executeCommand("toggleCodeBlock")),e.registerKeymap(s,{priority:"context"})}(e,this.config,this.resolvedKeymap),this.registerInputRule(e),this.registerToolbarItem(e),this.registerMiddleware(e),function(e,t,o){e.registerService(F,{setLanguage(t,o){U(e,t,"language",o)},getLanguage(e){const t=o();if(!t)return"";const n=t.getState().getBlock(e);return n&&"code_block"===n.type?n.attrs?.language??"":""},setBackground(t,o){U(e,t,"backgroundColor",o)},getBackground(e){const t=o();if(!t)return"";const n=t.getState().getBlock(e);return n&&"code_block"===n.type?n.attrs?.backgroundColor??"":""},isCodeBlock(e){const t=o();return!!t&&"code_block"===t.getState().getBlock(e)?.type},getSupportedLanguages:()=>t.highlighter?t.highlighter.getSupportedLanguages():[]})}(e,this.config,()=>this.context),this.registerSyntaxHighlighterService(e),this.registerPasteInterceptor(e),this.patchTableCellContent(e)}destroy(){this.context=null,this.highlighter=null,this.tokenCache.clear()}onStateChange(e,t,o){if(!this.context)return;const n=a(e.selection)?e.selection.anchor.blockId:null,c=a(t.selection)?t.selection.anchor.blockId:null,r=n?e.getBlock(n):void 0,s=c?t.getBlock(c):void 0,l="code_block"===r?.type,i="code_block"===s?.type;!l&&i?this.context.announce(this.locale.enteredCodeBlock):l&&!i&&this.context.announce(this.locale.leftCodeBlock)}decorations(e){const t=[],o=this.getFocusedCodeBlockId(e);if(o&&t.push(x(o,{class:"notectl-code-block--focused"})),this.highlighter){const o=/* @__PURE__ */new Set;for(const n of e.getBlockOrder()){const c=e.getBlock(n);if(!c||"code_block"!==c.type)continue;const s=c.attrs?.language??"";if(!s)continue;const l=r(c);if(!l)continue;o.add(n);const i=this.getCachedTokens(n,l,s);for(const e of i)t.push(B(n,e.from,e.to,{class:`notectl-token--${e.type}`}))}for(const e of this.tokenCache.keys())o.has(e)||this.tokenCache.delete(e)}return 0===t.length?v.empty:v.create(t)}registerNodeSpec(e){e.registerNodeSpec({type:"code_block",group:"block",content:{allow:["text"]},selectable:!0,attrs:{language:{default:""},backgroundColor:{default:""}},toDOM(e){const t=u("pre",e.id);t.className="notectl-code-block",t.setAttribute("dir","ltr");const o=document.createElement("code");return o.className="notectl-code-block__content",t.appendChild(o),t},toHTML(e,t,o){const n=h(e.attrs?.language??""),c=h(e.attrs?.backgroundColor??""),r=n?` class="language-${n}"`:"";return`<pre dir="ltr"${c?o?.styleAttr(`background-color: ${c}`)??` style="background-color: ${c}"`:""}><code${r}>${t||""}</code></pre>`},parseHTML:[{tag:"pre",getAttrs(e){const t=e.querySelector("code"),o=t?.className.match(/language-(\S+)/)?.[1]??"";return{language:(t?.getAttribute("data-language")??"")||o}}}],sanitize:{tags:["pre","code"],attrs:["data-language","class","style"]}})}registerNodeView(e){e.registerNodeView("code_block",function(e,t=R){return(o,n,c)=>{const s=document.createElement("pre");s.className="notectl-code-block",s.setAttribute("data-block-id",o.id),s.setAttribute("dir","ltr"),s.setAttribute("role","group"),s.setAttribute("aria-roledescription","code block");const l=document.createElement("div");l.className="notectl-code-block__header",l.setAttribute("contenteditable","false");const i=document.createElement("span");i.className="notectl-code-block__language";let a=null;!1!==e.showCopyButton&&(a=document.createElement("button"),a.className="notectl-code-block__copy",a.setAttribute("aria-label",t.copyCodeAria),a.setAttribute("data-notectl-no-print",""),a.type="button",a.innerHTML='<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>');const d=document.createElement("button");d.className="notectl-code-block__delete",d.setAttribute("aria-label",t.deleteCodeBlockAria),d.title=t.deleteCodeBlockAria,d.setAttribute("data-notectl-no-print",""),d.type="button",d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>';const g=document.createElement("span");g.className="notectl-sr-only",g.setAttribute("aria-live","assertive"),g.setAttribute("aria-atomic","true");const u=document.createElement("div");u.className="notectl-code-block__actions",a&&u.appendChild(a),u.appendChild(d),l.appendChild(i),l.appendChild(u),l.appendChild(g);const h=document.createElement("code");h.className="notectl-code-block__content";const p=document.createElement("div");p.className="notectl-code-block__esc-hint",p.setAttribute("contenteditable","false"),p.setAttribute("aria-hidden","true"),p.setAttribute("data-notectl-no-print",""),p.textContent=t.escToExit,s.appendChild(l),s.appendChild(h),s.appendChild(p),e.background&&y(s,"--notectl-code-block-bg",e.background),e.headerBackground&&y(s,"--notectl-code-block-header-bg",e.headerBackground),e.textColor&&y(s,"--notectl-code-block-color",e.textColor),e.headerColor&&y(s,"--notectl-code-block-header-color",e.headerColor);let k=o.id;function b(e){const o=e.attrs?.language??"",n=o||"plain";i.textContent=n,s.setAttribute("aria-label",t.codeBlockAriaLabel(n)),o?h.setAttribute("data-language",o):h.removeAttribute("data-language"),y(s,"backgroundColor",(e.attrs?.backgroundColor??"")||"")}return b(o),a&&a.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();const o=n().getBlock(k);if(!o)return;const c=r(o);navigator.clipboard.writeText(c),g.textContent=t.copiedToClipboard,setTimeout(()=>{g.textContent=""},1e3)}),d.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();const o=O(n(),k);o&&(g.textContent=t.deletedCodeBlock,c(o))}),{dom:s,contentDOM:h,update:e=>"code_block"===e.type&&(k=e.id,s.setAttribute("data-block-id",e.id),b(e),!0),selectNode(){s.classList.add("notectl-code-block--selected")},deselectNode(){s.classList.remove("notectl-code-block--selected")},destroy(){}}}}(this.config,this.locale))}registerInputRule(e){e.registerInputRule({pattern:/^```(\w*) $/,handler:(e,t,o,n)=>{const c=e.selection;if(!a(c))return null;if(!l(c))return null;const r=e.getBlock(c.anchor.blockId);if(!r||"paragraph"!==r.type)return null;const s={language:t[1]??"",backgroundColor:""};return e.transaction("input").deleteTextAt(c.anchor.blockId,o,o+t[0].length).setBlockType(c.anchor.blockId,g("code_block"),s).setSelection(i(c.anchor.blockId,0)).build()}})}registerToolbarItem(e){e.registerToolbarItem({id:"code_block",group:"block",icon:'<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>',label:this.locale.label,tooltip:this.locale.tooltip(this.resolvedKeymap.toggle?w(this.resolvedKeymap.toggle):void 0),command:"toggleCodeBlock",isActive:e=>!!a(e.selection)&&"code_block"===e.getBlock(e.selection.anchor.blockId)?.type})}registerMiddleware(e){e.registerMiddleware((e,t,o)=>{if(!e.steps.some(e=>"addMark"===e.type&&"code_block"===t.getBlock(e.blockId)?.type))return void o(e);const n=e.steps.filter(e=>"addMark"!==e.type||"code_block"!==t.getBlock(e.blockId)?.type);o({...e,steps:n})},{name:"code-block:mark-guard",priority:50})}registerPasteInterceptor(e){e.registerPasteInterceptor(this.handleCodeBlockPaste,{name:"code-block:paste",priority:10})}handleCodeBlockPaste=(e,t,o)=>{if(!e)return null;if(!a(o.selection))return null;const n=o.getBlock(o.selection.anchor.blockId);if(!n||"code_block"!==n.type)return null;const c=o.transaction("paste");let r=o.selection.anchor.blockId,s=o.selection.anchor.offset;if(!l(o.selection)){const e=d(o,c);e&&(r=e,s=0)}return c.insertText(r,s,e,[]),c.setSelection(i(r,s+e.length)),c.build()};patchTableCellContent(e){const t=e.getSchemaRegistry(),o=t.getNodeSpec("table_cell");if(!o?.content)return;const n=o.content.allow??[];n.includes("code_block")||(t.removeNodeSpec("table_cell"),t.registerNodeSpec({...o,content:{...o.content,allow:[...n,"code_block"]}}))}initHighlighter(){this.config.highlighter?this.highlighter=this.config.highlighter:this.highlighter=new G}registerLanguageRegistry(e){const t=this.highlighter,o=this.tokenCache;this.languageRegistry.onRegister(e=>{e.highlighting&&t?.registerLanguage&&(t.registerLanguage(e.highlighting),o.clear())}),e.registerService(I,this.languageRegistry),this.languageRegistry.register(A),this.languageRegistry.register(L),this.languageRegistry.register(T)}registerSyntaxHighlighterService(e){const t=this.highlighter;t&&e.registerService(K,{registerLanguage:e=>{t.registerLanguage?.(e),this.tokenCache.clear()},getSupportedLanguages:()=>t.getSupportedLanguages(),tokenize:(e,o)=>t.tokenize(e,o)})}getCachedTokens(e,t,o){const n=this.tokenCache.get(e);if(n&&n.text===t&&n.language===o)return n.tokens;const c=this.highlighter?.tokenize(t,o)??[];return this.tokenCache.set(e,{text:t,language:o,tokens:c}),c}getFocusedCodeBlockId(e){if(!a(e.selection))return null;const t=e.selection.anchor.blockId;return"code_block"===e.getBlock(t)?.type?t:null}};export{R as a,K as i,G as n,P as o,F as r,X as t};
|
|
2
|
-
//# sourceMappingURL=CodeBlockPlugin-
|
|
1
|
+
import{S as e,a as t,c as o,d as n,g as c,m as r,y as s}from"./Document-DnPKbcPE.mjs";import{o as l,t as i,u as a}from"./Selection-B14e7gd0.mjs";import{t as d}from"./Commands-ByBjgD3-.mjs";import{a as g}from"./TypeBrands-BQR8dEYU.mjs";import{n as u}from"./DomUtils-BkyCg-OO.mjs";import{r as h}from"./HTMLUtils-BLwp5G4f.mjs";import{n as p}from"./NodeResolver-BkOsZnuU.mjs";import{a as k,n as b,o as f,t as m}from"./CommandHelpers-G6M-qXJR.mjs";import{s as y}from"./StyleRuntime-Bwde5icB.mjs";import{n as C}from"./Plugin-C4cBw3bs.mjs";import{i as x,r as B,t as v}from"./Decoration-D-yB-H5v.mjs";import{t as S}from"./SyntaxTokenTypes-CY2-rJCA.mjs";import{i as _}from"./PluginHelpers-BZU5rE44.mjs";import{t as w}from"./ShortcutFormatting-c0IajwWG.mjs";import{i as I}from"./XmlDetector-B1y1NzDL.mjs";import{a as A,r as L,t as T}from"./XmlSupport-DRkIIe34.mjs";var M=`\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__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${S.map(e=>`.notectl-token--${e} {\n\tcolor: var(--notectl-code-token-${e});\n\tfont-style: var(--notectl-code-token-${e}-font-style, inherit);\n\tfont-weight: var(--notectl-code-token-${e}-font-weight, inherit);\n}`).join("\n")}\n`,N=class{bundles=/* @__PURE__ */new Map;listeners=[];register(e){this.bundles.set(e.id,e);for(const t of this.listeners)t(e)}onRegister(e){this.listeners.push(e);for(const t of this.bundles.values())e(t)}get(e){return this.bundles.get(e)}getAll(){return[...this.bundles.values()]}};function j(e,t){const o=e.getState();if(!a(o.selection))return!1;const n=o.selection,c=o.getBlock(n.anchor.blockId);return!(!c||"code_block"!==c.type)&&t({state:o,block:c,blockId:n.anchor.blockId,offset:n.anchor.offset})}function E(e){return j(e,({state:t,blockId:o})=>{const n=t.getBlockOrder(),c=n.indexOf(o);if(c<n.length-1){const o=n[c+1],r=t.transaction("command").setSelection(i(o,0)).build();e.dispatch(r)}else z(e,o);return!0})}function z(e,t){const c=e.getState(),r=c.getBlock(t);if(!r)return;const s=n(r),l=o(),a=c.transaction("command").splitBlock(t,s,l).setBlockType(l,g("paragraph")).setSelection(i(l,0)).build();e.dispatch(a)}function H(t,o){const r=t.getState(),s=r.selection;if(!a(s))return!1;const l=r.getBlock(s.anchor.blockId);if(!l||"code_block"===l.type)return!1;const d={language:o.defaultLanguage??"",backgroundColor:""},u=r.transaction("command");return function(t,o){if(0===n(o))return;const r=c(o);let s=0;for(const n of r)if(e(n)){if(n.text.length>0)for(const e of n.marks)t.removeMark(o.id,s,s+n.text.length,e);s+=n.text.length}else s+=1}(u,l),u.setBlockType(s.anchor.blockId,g("code_block"),d).setSelection(i(s.anchor.blockId,0)),t.dispatch(u.build()),!0}function O(e,n){const c=p(e.doc,n);if(!c)return null;const r=b(c),l=f(e,r),a=k(l,n);if(a<0)return null;const d=e.transaction("command");if(1===l.length){const e=o();return d.insertNode(r,0,t(e)),d.removeNode(r,1),d.setSelection(i(e,0)),d.build()}d.removeNode(r,a);const g=l[a-1];if(g&&s(g)){const t=m(e,g.id,"end");if(t)return d.setSelection(t),d.build()}const u=l[a+1];if(u&&s(u)){const t=m(e,u.id,"start");t&&d.setSelection(t)}return d.build()}var R={label:"Code Block",tooltip:e=>e?`Code Block (${e})`:"Code Block",enteredCodeBlock:"Entered code block. Press Escape to exit.",leftCodeBlock:"Left code block.",copyCodeAria:"Copy code",escToExit:"Esc to exit",codeBlockAriaLabel:e=>`${e} code block. Press Escape to exit.`,copiedToClipboard:"Copied to clipboard",deleteCodeBlockAria:"Delete code block",deletedCodeBlock:"Code block deleted"},$=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar-M3QzJIS8.mjs"),"./locales/de.ts":()=>import("./de-ClJaNWJr.mjs"),"./locales/es.ts":()=>import("./es-DIH9KVn1.mjs"),"./locales/fr.ts":()=>import("./fr-BZRak2_s.mjs"),"./locales/hi.ts":()=>import("./hi-DkEmvBok.mjs"),"./locales/pt.ts":()=>import("./pt-DCfJFt-v.mjs"),"./locales/ru.ts":()=>import("./ru-CsFv_mi4.mjs"),"./locales/zh.ts":()=>import("./zh-D9QN2C7q.mjs")});async function P(e){if("en"===e)return R;const t=$[`./locales/${e}.ts`];if(!t)return R;try{return(await t()).default}catch{return R}}var D={insertAfter:"Mod-Enter",toggle:"Mod-Shift-M"},V={defaultLanguage:"",useSpaces:!1,spaceCount:2,showCopyButton:!0},F=new C("codeBlock"),K=new C("syntaxHighlighter");function U(e,t,o,n){const c=e.getState(),r=c.getBlock(t);if(!r||"code_block"!==r.type)return;const s=c.getNodePath(t);if(!s)return;const l={...r.attrs,[o]:n},i=c.transaction("command").setNodeAttr(s,l).build();e.dispatch(i)}var G=class{languageMap=/* @__PURE__ */new Map;constructor(e){if(e)for(const t of e)this.registerLanguageInternal(t)}registerLanguage(e){this.registerLanguageInternal(e)}tokenize(e,t){const o=this.languageMap.get(t.toLowerCase());if(!o)return[];const n=[];let c=0;for(;c<e.length;){let t=!1;for(const r of o.patterns){const o=r.pattern.exec(e.slice(c));if(o&&o[0].length>0){n.push({from:c,to:c+o[0].length,type:r.type}),c+=o[0].length,t=!0;break}}t||c++}return n}getSupportedLanguages(){const e=/* @__PURE__ */new Set;for(const t of this.languageMap.values()){e.add(t.name);for(const o of t.aliases)e.add(o)}return[...e]}registerLanguageInternal(e){this.languageMap.set(e.name.toLowerCase(),e);for(const t of e.aliases)this.languageMap.set(t.toLowerCase(),e)}},X=class{id="code-block";name="Code Block";priority=36;config;resolvedKeymap;context=null;locale;highlighter=null;languageRegistry=new N;tokenCache=/* @__PURE__ */new Map;constructor(e){this.config={...V,...e},this.resolvedKeymap={...D,...e?.keymap}}async init(e){this.locale=await _(e,this.config.locale,R,P),e.registerStyleSheet(M),this.context=e,this.initHighlighter(),this.registerLanguageRegistry(e),this.registerNodeSpec(e),this.registerNodeView(e),function(e,t){e.registerCommand("toggleCodeBlock",()=>function(e,t){const o=e.getState();if(!a(o.selection))return!1;const n=o.getBlock(o.selection.anchor.blockId);if(!n)return!1;if("code_block"===n.type){const t=o.transaction("command").setBlockType(o.selection.anchor.blockId,g("paragraph")).setSelection(o.selection).build();return e.dispatch(t),!0}return H(e,t)}(e,t)),e.registerCommand("insertCodeBlock",()=>H(e,t)),e.registerCommand("setCodeBlockLanguage",()=>!1),e.registerCommand("setCodeBlockBackground",()=>!1),e.registerCommand("exitCodeBlock",()=>E(e)),e.registerCommand("deleteCodeBlock",()=>function(e){const t=e.getState();if(!a(t.selection))return!1;const o=t.getBlock(t.selection.anchor.blockId);if(!o||"code_block"!==o.type)return!1;const n=O(t,o.id);return!!n&&(e.dispatch(n),!0)}(e))}(e,this.config),function(e,t,c){const s={Enter:()=>function(e){return j(e,({state:t,block:n,blockId:c,offset:s})=>{if(!l(t.selection))return!1;const a=r(n);if(a.endsWith("\n")&&s===a.length)return function(e,t,n){const c=e.getState(),r=n.length-1,s=o(),l=c.transaction("input").deleteTextAt(t,r,n.length).splitBlock(t,r,s).setBlockType(s,g("paragraph")).setSelection(i(s,0)).build();return e.dispatch(l),!0}(e,c,a);const d=t.transaction("input").insertText(c,s,"\n",[]).setSelection(i(c,s+1)).build();return e.dispatch(d),!0})}(e),Backspace:()=>function(e){return j(e,({state:t,blockId:o,offset:n})=>{if(!l(t.selection))return!1;if(0!==n)return!1;const c=t.transaction("input").setBlockType(o,g("paragraph")).setSelection(t.selection).build();return e.dispatch(c),!0})}(e),Tab:()=>function(e,t){return j(e,({state:o,blockId:n,offset:c})=>{const r=t.useSpaces?" ".repeat(t.spaceCount??2):"\t",s=o.transaction("input").insertText(n,c,r,[]).setSelection(i(n,c+r.length)).build();return e.dispatch(s),!0})}(e,t),"Shift-Tab":()=>function(e,t){return j(e,({state:o,block:n,blockId:c,offset:s})=>{const l=r(n),a=l.lastIndexOf("\n",s-1)+1;if(t.useSpaces){const n=t.spaceCount??2;if(l.slice(a,a+n)===" ".repeat(n)){const t=o.transaction("input").deleteTextAt(c,a,a+n).setSelection(i(c,Math.max(a,s-n))).build();return e.dispatch(t),!0}}else if("\t"===l[a]){const t=o.transaction("input").deleteTextAt(c,a,a+1).setSelection(i(c,Math.max(a,s-1))).build();return e.dispatch(t),!0}return!0})}(e,t),Escape:()=>E(e),ArrowDown:()=>function(e){return j(e,({state:t,block:o,blockId:n,offset:c})=>{if(!l(t.selection))return!1;if(-1!==r(o).indexOf("\n",c))return!1;const s=t.getBlockOrder(),a=s.indexOf(n);if(a<s.length-1){const o=s[a+1],n=t.transaction("command").setSelection(i(o,0)).build();e.dispatch(n)}else z(e,n);return!0})}(e),ArrowUp:()=>function(e){return j(e,({state:t,block:o,blockId:c,offset:s})=>{if(!l(t.selection))return!1;const a=r(o).indexOf("\n");if(-1!==a&&s>a)return!1;const d=t.getBlockOrder(),g=d.indexOf(c);if(g>0){const o=d[g-1],c=t.getBlock(o),r=c?n(c):0,s=t.transaction("command").setSelection(i(o,r)).build();return e.dispatch(s),!0}return!1})}(e),ArrowRight:()=>function(e){return j(e,({state:t,block:o,blockId:n,offset:c})=>{if(!l(t.selection))return!1;if(c!==r(o).length)return!1;const s=t.getBlockOrder(),a=s.indexOf(n);if(a<s.length-1){const o=s[a+1],n=t.transaction("command").setSelection(i(o,0)).build();e.dispatch(n)}else z(e,n);return!0})}(e),ArrowLeft:()=>function(e){return j(e,({state:t,blockId:o,offset:c})=>{if(!l(t.selection))return!1;if(0!==c)return!1;const r=t.getBlockOrder(),s=r.indexOf(o);if(s>0){const o=r[s-1],c=t.getBlock(o),l=c?n(c):0,a=t.transaction("command").setSelection(i(o,l)).build();return e.dispatch(a),!0}return!1})}(e)},{insertAfter:a,toggle:d}=c;a&&(s[a]=()=>function(e){return j(e,({blockId:t})=>(z(e,t),!0))}(e)),d&&(s[d]=()=>e.executeCommand("toggleCodeBlock")),e.registerKeymap(s,{priority:"context"})}(e,this.config,this.resolvedKeymap),this.registerInputRule(e),this.registerToolbarItem(e),this.registerMiddleware(e),function(e,t,o){e.registerService(F,{setLanguage(t,o){U(e,t,"language",o)},getLanguage(e){const t=o();if(!t)return"";const n=t.getState().getBlock(e);return n&&"code_block"===n.type?n.attrs?.language??"":""},setBackground(t,o){U(e,t,"backgroundColor",o)},getBackground(e){const t=o();if(!t)return"";const n=t.getState().getBlock(e);return n&&"code_block"===n.type?n.attrs?.backgroundColor??"":""},isCodeBlock(e){const t=o();return!!t&&"code_block"===t.getState().getBlock(e)?.type},getSupportedLanguages:()=>t.highlighter?t.highlighter.getSupportedLanguages():[]})}(e,this.config,()=>this.context),this.registerSyntaxHighlighterService(e),this.registerPasteInterceptor(e),this.patchTableCellContent(e)}destroy(){this.context=null,this.highlighter=null,this.tokenCache.clear()}onStateChange(e,t,o){if(!this.context)return;const n=a(e.selection)?e.selection.anchor.blockId:null,c=a(t.selection)?t.selection.anchor.blockId:null,r=n?e.getBlock(n):void 0,s=c?t.getBlock(c):void 0,l="code_block"===r?.type,i="code_block"===s?.type;!l&&i?this.context.announce(this.locale.enteredCodeBlock):l&&!i&&this.context.announce(this.locale.leftCodeBlock)}decorations(e){const t=[],o=this.getFocusedCodeBlockId(e);if(o&&t.push(x(o,{class:"notectl-code-block--focused"})),this.highlighter){const o=/* @__PURE__ */new Set;for(const n of e.getBlockOrder()){const c=e.getBlock(n);if(!c||"code_block"!==c.type)continue;const s=c.attrs?.language??"";if(!s)continue;const l=r(c);if(!l)continue;o.add(n);const i=this.getCachedTokens(n,l,s);for(const e of i)t.push(B(n,e.from,e.to,{class:`notectl-token--${e.type}`}))}for(const e of this.tokenCache.keys())o.has(e)||this.tokenCache.delete(e)}return 0===t.length?v.empty:v.create(t)}registerNodeSpec(e){e.registerNodeSpec({type:"code_block",group:"block",content:{allow:["text"]},selectable:!0,attrs:{language:{default:""},backgroundColor:{default:""}},toDOM(e){const t=u("pre",e.id);t.className="notectl-code-block",t.setAttribute("dir","ltr");const o=document.createElement("code");return o.className="notectl-code-block__content",t.appendChild(o),t},toHTML(e,t,o){const n=h(e.attrs?.language??""),c=h(e.attrs?.backgroundColor??""),r=n?` class="language-${n}"`:"";return`<pre dir="ltr"${c?o?.styleAttr(`background-color: ${c}`)??` style="background-color: ${c}"`:""}><code${r}>${t||""}</code></pre>`},parseHTML:[{tag:"pre",getAttrs(e){const t=e.querySelector("code"),o=t?.className.match(/language-(\S+)/)?.[1]??"";return{language:(t?.getAttribute("data-language")??"")||o}}}],sanitize:{tags:["pre","code"],attrs:["data-language","class","style"]}})}registerNodeView(e){e.registerNodeView("code_block",function(e,t=R){return(o,n,c)=>{const s=document.createElement("pre");s.className="notectl-code-block",s.setAttribute("data-block-id",o.id),s.setAttribute("dir","ltr"),s.setAttribute("role","group"),s.setAttribute("aria-roledescription","code block");const l=document.createElement("div");l.className="notectl-code-block__header",l.setAttribute("contenteditable","false");const i=document.createElement("span");i.className="notectl-code-block__language";let a=null;!1!==e.showCopyButton&&(a=document.createElement("button"),a.className="notectl-code-block__copy",a.setAttribute("aria-label",t.copyCodeAria),a.setAttribute("data-notectl-no-print",""),a.type="button",a.innerHTML='<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>');const d=document.createElement("button");d.className="notectl-code-block__delete",d.setAttribute("aria-label",t.deleteCodeBlockAria),d.title=t.deleteCodeBlockAria,d.setAttribute("data-notectl-no-print",""),d.type="button",d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>';const g=document.createElement("span");g.className="notectl-sr-only",g.setAttribute("aria-live","assertive"),g.setAttribute("aria-atomic","true");const u=document.createElement("div");u.className="notectl-code-block__actions",a&&u.appendChild(a),u.appendChild(d),l.appendChild(i),l.appendChild(u),l.appendChild(g);const h=document.createElement("code");h.className="notectl-code-block__content";const p=document.createElement("div");p.className="notectl-code-block__esc-hint",p.setAttribute("contenteditable","false"),p.setAttribute("aria-hidden","true"),p.setAttribute("data-notectl-no-print",""),p.textContent=t.escToExit,s.appendChild(l),s.appendChild(h),s.appendChild(p),e.background&&y(s,"--notectl-code-block-bg",e.background),e.headerBackground&&y(s,"--notectl-code-block-header-bg",e.headerBackground),e.textColor&&y(s,"--notectl-code-block-color",e.textColor),e.headerColor&&y(s,"--notectl-code-block-header-color",e.headerColor);let k=o.id;function b(e){const o=e.attrs?.language??"",n=o||"plain";i.textContent=n,s.setAttribute("aria-label",t.codeBlockAriaLabel(n)),o?h.setAttribute("data-language",o):h.removeAttribute("data-language"),y(s,"backgroundColor",(e.attrs?.backgroundColor??"")||"")}return b(o),a&&a.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();const o=n().getBlock(k);if(!o)return;const c=r(o);navigator.clipboard.writeText(c),g.textContent=t.copiedToClipboard,setTimeout(()=>{g.textContent=""},1e3)}),d.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();const o=O(n(),k);o&&(g.textContent=t.deletedCodeBlock,c(o))}),{dom:s,contentDOM:h,update:e=>"code_block"===e.type&&(k=e.id,s.setAttribute("data-block-id",e.id),b(e),!0),selectNode(){s.classList.add("notectl-code-block--selected")},deselectNode(){s.classList.remove("notectl-code-block--selected")},destroy(){}}}}(this.config,this.locale))}registerInputRule(e){e.registerInputRule({pattern:/^```(\w*) $/,handler:(e,t,o,n)=>{const c=e.selection;if(!a(c))return null;if(!l(c))return null;const r=e.getBlock(c.anchor.blockId);if(!r||"paragraph"!==r.type)return null;const s={language:t[1]??"",backgroundColor:""};return e.transaction("input").deleteTextAt(c.anchor.blockId,o,o+t[0].length).setBlockType(c.anchor.blockId,g("code_block"),s).setSelection(i(c.anchor.blockId,0)).build()}})}registerToolbarItem(e){e.registerToolbarItem({id:"code_block",group:"block",icon:'<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>',label:this.locale.label,tooltip:this.locale.tooltip(this.resolvedKeymap.toggle?w(this.resolvedKeymap.toggle):void 0),command:"toggleCodeBlock",isActive:e=>!!a(e.selection)&&"code_block"===e.getBlock(e.selection.anchor.blockId)?.type})}registerMiddleware(e){e.registerMiddleware((e,t,o)=>{if(!e.steps.some(e=>"addMark"===e.type&&"code_block"===t.getBlock(e.blockId)?.type))return void o(e);const n=e.steps.filter(e=>"addMark"!==e.type||"code_block"!==t.getBlock(e.blockId)?.type);o({...e,steps:n})},{name:"code-block:mark-guard",priority:50})}registerPasteInterceptor(e){e.registerPasteInterceptor(this.handleCodeBlockPaste,{name:"code-block:paste",priority:10})}handleCodeBlockPaste=(e,t,o)=>{if(!e)return null;if(!a(o.selection))return null;const n=o.getBlock(o.selection.anchor.blockId);if(!n||"code_block"!==n.type)return null;const c=o.transaction("paste");let r=o.selection.anchor.blockId,s=o.selection.anchor.offset;if(!l(o.selection)){const e=d(o,c);e&&(r=e,s=0)}return c.insertText(r,s,e,[]),c.setSelection(i(r,s+e.length)),c.build()};patchTableCellContent(e){const t=e.getSchemaRegistry(),o=t.getNodeSpec("table_cell");if(!o?.content)return;const n=o.content.allow??[];n.includes("code_block")||(t.removeNodeSpec("table_cell"),t.registerNodeSpec({...o,content:{...o.content,allow:[...n,"code_block"]}}))}initHighlighter(){this.config.highlighter?this.highlighter=this.config.highlighter:this.highlighter=new G}registerLanguageRegistry(e){const t=this.highlighter,o=this.tokenCache;this.languageRegistry.onRegister(e=>{e.highlighting&&t?.registerLanguage&&(t.registerLanguage(e.highlighting),o.clear())}),e.registerService(I,this.languageRegistry),this.languageRegistry.register(A),this.languageRegistry.register(L),this.languageRegistry.register(T)}registerSyntaxHighlighterService(e){const t=this.highlighter;t&&e.registerService(K,{registerLanguage:e=>{t.registerLanguage?.(e),this.tokenCache.clear()},getSupportedLanguages:()=>t.getSupportedLanguages(),tokenize:(e,o)=>t.tokenize(e,o)})}getCachedTokens(e,t,o){const n=this.tokenCache.get(e);if(n&&n.text===t&&n.language===o)return n.tokens;const c=this.highlighter?.tokenize(t,o)??[];return this.tokenCache.set(e,{text:t,language:o,tokens:c}),c}getFocusedCodeBlockId(e){if(!a(e.selection))return null;const t=e.selection.anchor.blockId;return"code_block"===e.getBlock(t)?.type?t:null}};export{R as a,K as i,G as n,P as o,F as r,X as t};
|
|
2
|
+
//# sourceMappingURL=CodeBlockPlugin-C8H0nfF6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlockPlugin-oPGiMno0.mjs","names":[],"sources":["../../src/editor/styles/code-block.ts","../../src/plugins/language/LanguageRegistry.ts","../../src/plugins/code-block/CodeBlockKeyboardHandlers.ts","../../src/plugins/code-block/CodeBlockCommands.ts","../../src/plugins/code-block/CodeBlockLocale.ts","../../src/plugins/code-block/CodeBlockNodeView.ts","../../src/plugins/code-block/CodeBlockTypes.ts","../../src/plugins/code-block/CodeBlockService.ts","../../src/plugins/code-block/highlighter/RegexTokenizer.ts","../../src/plugins/code-block/CodeBlockPlugin.ts"],"sourcesContent":["import { SYNTAX_TOKEN_TYPES } from '../theme/SyntaxTokenTypes.js';\n\n/** Generates per-token CSS rules from the canonical token type list. */\nfunction generateTokenCSS(): string {\n\treturn SYNTAX_TOKEN_TYPES.map(\n\t\t(type) =>\n\t\t\t`.notectl-token--${type} {\\n\\tcolor: var(--notectl-code-token-${type});\\n\\tfont-style: var(--notectl-code-token-${type}-font-style, inherit);\\n\\tfont-weight: var(--notectl-code-token-${type}-font-weight, inherit);\\n}`,\n\t).join('\\n');\n}\n\n/** Code block styles — syntax highlighting container, header, copy button. */\nexport const CODE_BLOCK_CSS = `\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${generateTokenCSS()}\n`;\n","/**\n * Internal registry that stores LanguageSupport bundles and notifies\n * subscribers with replay semantics for late subscribers.\n */\n\nimport type {\n\tLanguageRegistryListener,\n\tLanguageRegistryService,\n\tLanguageSupport,\n} from './LanguageTypes.js';\n\nexport class LanguageRegistry implements LanguageRegistryService {\n\tprivate readonly bundles = new Map<string, LanguageSupport>();\n\tprivate readonly listeners: LanguageRegistryListener[] = [];\n\n\tregister(support: LanguageSupport): void {\n\t\tthis.bundles.set(support.id, support);\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\t/**\n\t * Subscribes to language registrations.\n\t * The listener is immediately called for all already-registered bundles\n\t * (replay semantics), then called for each future registration.\n\t */\n\tonRegister(listener: LanguageRegistryListener): void {\n\t\tthis.listeners.push(listener);\n\t\tfor (const support of this.bundles.values()) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\tget(id: string): LanguageSupport | undefined {\n\t\treturn this.bundles.get(id);\n\t}\n\n\tgetAll(): readonly LanguageSupport[] {\n\t\treturn [...this.bundles.values()];\n\t}\n}\n","/**\n * 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 { createCollapsedSelection, isCollapsed, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport 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 (!isTextSelection(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 {\n\tcreateSelectionForBlockBoundary,\n\textractParentPath,\n\tfindSiblingIndex,\n\tgetSiblings,\n} from '../../commands/CommandHelpers.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport {\n\tcreateEmptyParagraph,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tgetInlineChildren,\n\tisBlockNode,\n\tisTextNode,\n} from '../../model/Document.js';\nimport { findNodePath } from '../../model/NodeResolver.js';\nimport { createCollapsedSelection, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction, TransactionBuilder } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport { handleEscape } from './CodeBlockKeyboardHandlers.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\n\n/** Registers all code-block commands. */\nexport function registerCodeBlockCommands(context: PluginContext, config: CodeBlockConfig): void {\n\tcontext.registerCommand('toggleCodeBlock', () => toggleCodeBlock(context, config));\n\n\tcontext.registerCommand('insertCodeBlock', () => insertCodeBlock(context, config));\n\n\tcontext.registerCommand('setCodeBlockLanguage', () => false);\n\n\tcontext.registerCommand('setCodeBlockBackground', () => false);\n\n\tcontext.registerCommand('exitCodeBlock', () => handleEscape(context));\n\n\tcontext.registerCommand('deleteCodeBlock', () => deleteCodeBlock(context));\n}\n\n// --- Command Implementations ---\n\nfunction toggleCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block) return false;\n\n\tif (block.type === 'code_block') {\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('command')\n\t\t\t.setBlockType(state.selection.anchor.blockId, nodeType('paragraph'))\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\treturn insertCodeBlock(context, config);\n}\n\nfunction insertCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\tif (!block || block.type === 'code_block') return false;\n\n\tconst attrs: Record<string, string | number | boolean> = {\n\t\tlanguage: config.defaultLanguage ?? '',\n\t\tbackgroundColor: '',\n\t};\n\n\tconst builder: TransactionBuilder = state.transaction('command');\n\tstripAllMarks(builder, block);\n\tbuilder\n\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0));\n\n\tcontext.dispatch(builder.build());\n\treturn true;\n}\n\n/** Deletes the code block at the current cursor position. */\nfunction deleteCodeBlock(context: PluginContext): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block || block.type !== 'code_block') return false;\n\n\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, block.id);\n\tif (!tr) return false;\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/** Builds a transaction that removes a code block and repositions the cursor. */\nexport function createDeleteCodeBlockTransaction(\n\tstate: EditorState,\n\tblockId: BlockId,\n): Transaction | null {\n\tconst path: string[] | undefined = findNodePath(state.doc, blockId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\tconst index: number = findSiblingIndex(siblings, blockId);\n\tif (index < 0) return null;\n\n\tconst builder = state.transaction('command');\n\n\tif (siblings.length === 1) {\n\t\tconst newId: BlockId = generateBlockId();\n\t\tbuilder.insertNode(parentPath, 0, createEmptyParagraph(newId));\n\t\tbuilder.removeNode(parentPath, 1);\n\t\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\t\treturn builder.build();\n\t}\n\n\tbuilder.removeNode(parentPath, index);\n\n\tconst prevSibling = siblings[index - 1];\n\tif (prevSibling && isBlockNode(prevSibling)) {\n\t\tconst selection = createSelectionForBlockBoundary(state, prevSibling.id, 'end');\n\t\tif (selection) {\n\t\t\tbuilder.setSelection(selection);\n\t\t\treturn builder.build();\n\t\t}\n\t}\n\n\tconst nextSibling = siblings[index + 1];\n\tif (nextSibling && isBlockNode(nextSibling)) {\n\t\tconst selection = createSelectionForBlockBoundary(state, nextSibling.id, 'start');\n\t\tif (selection) {\n\t\t\tbuilder.setSelection(selection);\n\t\t}\n\t}\n\n\treturn builder.build();\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\treadonly copyCodeAria: string;\n\treadonly escToExit: string;\n\treadonly codeBlockAriaLabel: (lang: string) => string;\n\treadonly copiedToClipboard: string;\n\treadonly deleteCodeBlockAria: string;\n\treadonly deletedCodeBlock: string;\n}\n\n// --- Default English Locale ---\n\nexport const CODE_BLOCK_LOCALE_EN: CodeBlockLocale = {\n\tlabel: 'Code Block',\n\ttooltip: (shortcut?: string) => (shortcut ? `Code Block (${shortcut})` : 'Code Block'),\n\tenteredCodeBlock: 'Entered code block. Press Escape to exit.',\n\tleftCodeBlock: 'Left code block.',\n\tcopyCodeAria: 'Copy code',\n\tescToExit: 'Esc to exit',\n\tcodeBlockAriaLabel: (lang: string) => `${lang} code block. Press Escape to exit.`,\n\tcopiedToClipboard: 'Copied to clipboard',\n\tdeleteCodeBlockAria: 'Delete code block',\n\tdeletedCodeBlock: 'Code block deleted',\n};\n\n// --- Lazy Locale Loader ---\n\nconst localeModules: Record<string, () => Promise<{ default: CodeBlockLocale }>> =\n\timport.meta.glob<{ default: CodeBlockLocale }>('./locales/*.ts', { eager: false });\n\nexport async function loadCodeBlockLocale(lang: string): Promise<CodeBlockLocale> {\n\tif (lang === 'en') return CODE_BLOCK_LOCALE_EN;\n\tconst loader = localeModules[`./locales/${lang}.ts`];\n\tif (!loader) return CODE_BLOCK_LOCALE_EN;\n\ttry {\n\t\tconst mod = await loader();\n\t\treturn mod.default;\n\t} catch {\n\t\treturn CODE_BLOCK_LOCALE_EN;\n\t}\n}\n","/**\n * NodeView factory for code blocks.\n * Renders <pre> with a non-editable header (language label + action buttons)\n * and a <code> content area where the Reconciler renders text.\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { NodeView, NodeViewFactory } from '../../view/NodeView.js';\nimport { createDeleteCodeBlockTransaction } from './CodeBlockCommands.js';\nimport { CODE_BLOCK_LOCALE_EN, type CodeBlockLocale } from './CodeBlockLocale.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\nconst DELETE_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z\"/></svg>';\n\n/** Creates a NodeViewFactory for code_block nodes. */\nexport function createCodeBlockNodeViewFactory(\n\tconfig: CodeBlockConfig,\n\tlocale: CodeBlockLocale = CODE_BLOCK_LOCALE_EN,\n): NodeViewFactory {\n\treturn (\n\t\tnode: BlockNode,\n\t\tgetState: () => EditorState,\n\t\tdispatch: (tr: Transaction) => void,\n\t): NodeView => {\n\t\t// --- DOM Construction ---\n\t\tconst pre: HTMLElement = document.createElement('pre');\n\t\tpre.className = 'notectl-code-block';\n\t\tpre.setAttribute('data-block-id', node.id);\n\t\tpre.setAttribute('dir', 'ltr');\n\t\tpre.setAttribute('role', 'group');\n\t\tpre.setAttribute('aria-roledescription', 'code block');\n\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', locale.copyCodeAria);\n\t\t\tcopyBtn.setAttribute('data-notectl-no-print', '');\n\t\t\tcopyBtn.type = 'button';\n\t\t\tcopyBtn.innerHTML = COPY_ICON;\n\t\t}\n\n\t\t// Delete button\n\t\tconst deleteBtn: HTMLButtonElement = document.createElement('button');\n\t\tdeleteBtn.className = 'notectl-code-block__delete';\n\t\tdeleteBtn.setAttribute('aria-label', locale.deleteCodeBlockAria);\n\t\tdeleteBtn.title = locale.deleteCodeBlockAria;\n\t\tdeleteBtn.setAttribute('data-notectl-no-print', '');\n\t\tdeleteBtn.type = 'button';\n\t\tdeleteBtn.innerHTML = DELETE_ICON;\n\n\t\t// Screen reader live region for action feedback\n\t\tconst announcer: HTMLSpanElement = document.createElement('span');\n\t\tannouncer.className = 'notectl-sr-only';\n\t\tannouncer.setAttribute('aria-live', 'assertive');\n\t\tannouncer.setAttribute('aria-atomic', 'true');\n\n\t\t// Actions wrapper groups buttons on the right side\n\t\tconst actions: HTMLDivElement = document.createElement('div');\n\t\tactions.className = 'notectl-code-block__actions';\n\t\tif (copyBtn) {\n\t\t\tactions.appendChild(copyBtn);\n\t\t}\n\t\tactions.appendChild(deleteBtn);\n\n\t\theader.appendChild(langLabel);\n\t\theader.appendChild(actions);\n\t\theader.appendChild(announcer);\n\n\t\t// Content area (Reconciler target)\n\t\tconst code: HTMLElement = document.createElement('code');\n\t\tcode.className = 'notectl-code-block__content';\n\n\t\t// Escape hint (visible only when focused, CSS-driven)\n\t\tconst escHint: HTMLDivElement = document.createElement('div');\n\t\tescHint.className = 'notectl-code-block__esc-hint';\n\t\tescHint.setAttribute('contenteditable', 'false');\n\t\tescHint.setAttribute('aria-hidden', 'true');\n\t\tescHint.setAttribute('data-notectl-no-print', '');\n\t\tescHint.textContent = locale.escToExit;\n\n\t\tpre.appendChild(header);\n\t\tpre.appendChild(code);\n\t\tpre.appendChild(escHint);\n\n\t\t// Apply config-level color overrides as CSS custom properties\n\t\tif (config.background) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-bg', config.background);\n\t\t}\n\t\tif (config.headerBackground) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-bg', config.headerBackground);\n\t\t}\n\t\tif (config.textColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-color', config.textColor);\n\t\t}\n\t\tif (config.headerColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-color', config.headerColor);\n\t\t}\n\n\t\tlet currentNodeId: BlockId = node.id;\n\n\t\t// --- Attribute Application ---\n\n\t\tfunction applyAttrs(n: BlockNode): void {\n\t\t\tconst lang: string = (n.attrs?.language as string) ?? '';\n\t\t\tconst langName: string = lang || 'plain';\n\t\t\tlangLabel.textContent = langName;\n\t\t\tpre.setAttribute('aria-label', locale.codeBlockAriaLabel(langName));\n\n\t\t\tif (lang) {\n\t\t\t\tcode.setAttribute('data-language', lang);\n\t\t\t} else {\n\t\t\t\tcode.removeAttribute('data-language');\n\t\t\t}\n\n\t\t\tconst bg: string = (n.attrs?.backgroundColor as string) ?? '';\n\t\t\tsetStyleProperty(pre, 'backgroundColor', bg || '');\n\t\t}\n\n\t\tapplyAttrs(node);\n\n\t\t// --- Copy Button Handler ---\n\n\t\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\tannouncer.textContent = locale.copiedToClipboard;\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tannouncer.textContent = '';\n\t\t\t\t}, 1000);\n\t\t\t});\n\t\t}\n\n\t\t// --- Delete Button Handler ---\n\n\t\tdeleteBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\n\t\t\tconst state: EditorState = getState();\n\t\t\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, currentNodeId);\n\t\t\tif (!tr) return;\n\n\t\t\tannouncer.textContent = locale.deletedCodeBlock;\n\t\t\tdispatch(tr);\n\t\t});\n\n\t\t// --- NodeView Interface ---\n\n\t\treturn {\n\t\t\tdom: pre,\n\t\t\tcontentDOM: code,\n\n\t\t\tupdate(updatedNode: BlockNode): boolean {\n\t\t\t\tif (updatedNode.type !== 'code_block') return false;\n\t\t\t\tcurrentNodeId = updatedNode.id;\n\t\t\t\tpre.setAttribute('data-block-id', updatedNode.id);\n\t\t\t\tapplyAttrs(updatedNode);\n\t\t\t\treturn true;\n\t\t\t},\n\n\t\t\tselectNode(): void {\n\t\t\t\tpre.classList.add('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdeselectNode(): void {\n\t\t\t\tpre.classList.remove('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdestroy(): void {\n\t\t\t\t// No cleanup needed\n\t\t\t},\n\t\t};\n\t};\n}\n","/**\n * Types, interfaces, and constants for the code-block plugin.\n */\n\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { ServiceKey } from '../Plugin.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\tcode_block: {\n\t\t\tlanguage: string;\n\t\t\tbackgroundColor: string;\n\t\t};\n\t}\n}\n\n// --- Syntax Highlighting Types ---\n\nimport type { SyntaxTokenType } from '../../editor/theme/SyntaxTokenTypes.js';\n\nexport interface SyntaxToken {\n\treadonly from: number;\n\treadonly to: number;\n\treadonly type: SyntaxTokenType | (string & {});\n}\n\nexport interface SyntaxHighlighter {\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\tgetSupportedLanguages(): readonly string[];\n\tregisterLanguage?(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n}\n\n// --- Configuration ---\n\n/**\n * Configurable keyboard bindings for CodeBlockPlugin actions.\n * Omit a slot to use the default; set to `null` to disable the binding.\n *\n * Key descriptor format: `'Mod-Enter'`, `'Mod-Shift-M'`, etc.\n * `Mod` resolves to Cmd on macOS, Ctrl on Windows/Linux.\n */\nexport interface CodeBlockKeymap {\n\t/**\n\t * Insert a new paragraph below the code block and move the cursor there.\n\t * @default 'Mod-Enter'\n\t */\n\treadonly insertAfter?: string | null;\n\n\t/**\n\t * Toggle the current block between code block and paragraph.\n\t * @default 'Mod-Shift-M'\n\t */\n\treadonly toggle?: string | null;\n}\n\nexport const DEFAULT_KEYMAP: Readonly<Record<keyof CodeBlockKeymap, string>> = {\n\tinsertAfter: 'Mod-Enter',\n\ttoggle: 'Mod-Shift-M',\n};\n\nexport interface CodeBlockConfig {\n\treadonly highlighter?: SyntaxHighlighter;\n\treadonly defaultLanguage?: string;\n\treadonly useSpaces?: boolean;\n\treadonly spaceCount?: number;\n\treadonly showCopyButton?: boolean;\n\t/** Default body background color (overrides --notectl-code-block-bg). */\n\treadonly background?: string;\n\t/** Default header background color (overrides --notectl-code-block-header-bg). */\n\treadonly headerBackground?: string;\n\t/** Default text color (overrides --notectl-code-block-color). */\n\treadonly textColor?: string;\n\t/** Default header/label text color (overrides --notectl-code-block-header-color). */\n\treadonly headerColor?: string;\n\t/** Customize keyboard bindings for code block actions. */\n\treadonly keymap?: CodeBlockKeymap;\n\t/** Locale override for user-facing strings. */\n\treadonly locale?: import('./CodeBlockLocale.js').CodeBlockLocale;\n}\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// --- Syntax Highlighter Service ---\n\nexport interface SyntaxHighlighterService {\n\tregisterLanguage(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n\tgetSupportedLanguages(): readonly string[];\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n}\n\nexport const SYNTAX_HIGHLIGHTER_SERVICE_KEY = new ServiceKey<SyntaxHighlighterService>(\n\t'syntaxHighlighter',\n);\n\n// --- SVG Icon ---\n\nexport const CODE_BLOCK_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"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 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: BlockId[] | undefined = state.getNodePath(bid);\n\tif (!path) return;\n\n\tconst newAttrs: BlockAttrs = { ...block.attrs, [key]: value };\n\tconst tr: Transaction = state.transaction('command').setNodeAttr(path, newAttrs).build();\n\n\tcontext.dispatch(tr);\n}\n","/**\n * Regex-based syntax tokenizer.\n * Implements the SyntaxHighlighter interface using linear regex scanning.\n */\n\nimport type { SyntaxHighlighter, SyntaxToken } from '../CodeBlockTypes.js';\nimport type { LanguageDefinition } from './TokenizerTypes.js';\n\nexport class RegexTokenizer implements SyntaxHighlighter {\n\tprivate readonly languageMap = new Map<string, LanguageDefinition>();\n\n\tconstructor(languages?: readonly LanguageDefinition[]) {\n\t\tif (languages) {\n\t\t\tfor (const lang of languages) {\n\t\t\t\tthis.registerLanguageInternal(lang);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Registers a language definition. Overwrites existing definitions for the same name/aliases. */\n\tregisterLanguage(def: LanguageDefinition): void {\n\t\tthis.registerLanguageInternal(def);\n\t}\n\n\t/** Tokenizes code using the specified language. Returns empty array for unknown languages. */\n\ttokenize(code: string, language: string): readonly SyntaxToken[] {\n\t\tconst lang: LanguageDefinition | undefined = this.languageMap.get(language.toLowerCase());\n\t\tif (!lang) return [];\n\n\t\tconst tokens: SyntaxToken[] = [];\n\t\tlet pos = 0;\n\n\t\twhile (pos < code.length) {\n\t\t\tlet matched = false;\n\n\t\t\tfor (const pattern of lang.patterns) {\n\t\t\t\tconst match: RegExpExecArray | null = pattern.pattern.exec(code.slice(pos));\n\t\t\t\tif (match && match[0].length > 0) {\n\t\t\t\t\ttokens.push({\n\t\t\t\t\t\tfrom: pos,\n\t\t\t\t\t\tto: pos + match[0].length,\n\t\t\t\t\t\ttype: pattern.type,\n\t\t\t\t\t});\n\t\t\t\t\tpos += match[0].length;\n\t\t\t\t\tmatched = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!matched) {\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\n\t\treturn tokens;\n\t}\n\n\t/** Returns all registered language names and aliases. */\n\tgetSupportedLanguages(): readonly string[] {\n\t\tconst names = new Set<string>();\n\t\tfor (const lang of this.languageMap.values()) {\n\t\t\tnames.add(lang.name);\n\t\t\tfor (const alias of lang.aliases) {\n\t\t\t\tnames.add(alias);\n\t\t\t}\n\t\t}\n\t\treturn [...names];\n\t}\n\n\tprivate registerLanguageInternal(def: LanguageDefinition): void {\n\t\tthis.languageMap.set(def.name.toLowerCase(), def);\n\t\tfor (const alias of def.aliases) {\n\t\t\tthis.languageMap.set(alias.toLowerCase(), def);\n\t\t}\n\t}\n}\n","/**\n * 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 { addDeleteSelectionSteps } from '../../commands/Commands.js';\nimport type { Decoration, DecorationSet } from '../../decorations/Decoration.js';\nimport {\n\tinline as inlineDecoration,\n\tnode as nodeDecoration,\n} from '../../decorations/Decoration.js';\nimport { DecorationSet as DecorationSetClass } from '../../decorations/Decoration.js';\nimport { CODE_BLOCK_CSS } from '../../editor/styles/code-block.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { HTMLExportContext } from '../../model/NodeSpec.js';\nimport { createCollapsedSelection, isCollapsed, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { createBlockElement } from '../../view/DomUtils.js';\nimport type { PasteInterceptor, Plugin, PluginContext } from '../Plugin.js';\nimport { LanguageRegistry } from '../language/LanguageRegistry.js';\nimport { LANGUAGE_REGISTRY_SERVICE_KEY } from '../language/LanguageTypes.js';\nimport { JAVA_SUPPORT, JSON_SUPPORT, XML_SUPPORT } from '../language/bundles/index.js';\nimport { resolveLocale } from '../shared/PluginHelpers.js';\nimport { formatShortcut } from '../shared/ShortcutFormatting.js';\nimport { registerCodeBlockCommands } from './CodeBlockCommands.js';\nimport { registerCodeBlockKeymaps } from './CodeBlockKeyboardHandlers.js';\nimport {\n\tCODE_BLOCK_LOCALE_EN,\n\ttype CodeBlockLocale,\n\tloadCodeBlockLocale,\n} from './CodeBlockLocale.js';\nimport { createCodeBlockNodeViewFactory } from './CodeBlockNodeView.js';\nimport { registerCodeBlockService } from './CodeBlockService.js';\nimport type {\n\tCodeBlockConfig,\n\tCodeBlockKeymap,\n\tSyntaxHighlighter,\n\tSyntaxToken,\n} from './CodeBlockTypes.js';\nimport {\n\tCODE_BLOCK_ICON,\n\tDEFAULT_CONFIG,\n\tDEFAULT_KEYMAP,\n\tSYNTAX_HIGHLIGHTER_SERVICE_KEY,\n} from './CodeBlockTypes.js';\nimport { RegexTokenizer } from './highlighter/RegexTokenizer.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\tprivate highlighter: SyntaxHighlighter | null = null;\n\tprivate readonly languageRegistry = new LanguageRegistry();\n\tprivate readonly tokenCache = new Map<\n\t\tBlockId,\n\t\t{\n\t\t\treadonly text: string;\n\t\t\treadonly language: string;\n\t\t\treadonly tokens: readonly SyntaxToken[];\n\t\t}\n\t>();\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\tasync init(context: PluginContext): Promise<void> {\n\t\tthis.locale = await resolveLocale(\n\t\t\tcontext,\n\t\t\tthis.config.locale,\n\t\t\tCODE_BLOCK_LOCALE_EN,\n\t\t\tloadCodeBlockLocale,\n\t\t);\n\t\tcontext.registerStyleSheet(CODE_BLOCK_CSS);\n\t\tthis.context = context;\n\n\t\tthis.initHighlighter();\n\t\tthis.registerLanguageRegistry(context);\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.registerSyntaxHighlighterService(context);\n\t\tthis.registerPasteInterceptor(context);\n\t\tthis.patchTableCellContent(context);\n\t}\n\n\tdestroy(): void {\n\t\tthis.context = null;\n\t\tthis.highlighter = null;\n\t\tthis.tokenCache.clear();\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 = !isTextSelection(oldState.selection)\n\t\t\t? null\n\t\t\t: oldState.selection.anchor.blockId;\n\t\tconst newBlockId: BlockId | null = !isTextSelection(newState.selection)\n\t\t\t? null\n\t\t\t: newState.selection.anchor.blockId;\n\n\t\tconst oldBlock: BlockNode | undefined = oldBlockId ? oldState.getBlock(oldBlockId) : undefined;\n\t\tconst newBlock: BlockNode | undefined = newBlockId ? newState.getBlock(newBlockId) : undefined;\n\n\t\tconst wasInCode: boolean = oldBlock?.type === 'code_block';\n\t\tconst nowInCode: boolean = newBlock?.type === 'code_block';\n\n\t\tif (!wasInCode && nowInCode) {\n\t\t\tthis.context.announce(this.locale.enteredCodeBlock);\n\t\t} else if (wasInCode && !nowInCode) {\n\t\t\tthis.context.announce(this.locale.leftCodeBlock);\n\t\t}\n\t}\n\n\tdecorations(state: EditorState): DecorationSet {\n\t\tconst decorations: Decoration[] = [];\n\n\t\tconst focusedBlockId: BlockId | null = this.getFocusedCodeBlockId(state);\n\t\tif (focusedBlockId) {\n\t\t\tdecorations.push(nodeDecoration(focusedBlockId, { class: 'notectl-code-block--focused' }));\n\t\t}\n\n\t\tif (this.highlighter) {\n\t\t\tconst activeBlockIds = new Set<BlockId>();\n\t\t\tfor (const bid of state.getBlockOrder()) {\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(bid);\n\t\t\t\tif (!block || block.type !== 'code_block') continue;\n\n\t\t\t\tconst lang: string = (block.attrs?.language as string) ?? '';\n\t\t\t\tif (!lang) continue;\n\n\t\t\t\tconst text: string = getBlockText(block);\n\t\t\t\tif (!text) continue;\n\n\t\t\t\tactiveBlockIds.add(bid);\n\t\t\t\tconst tokens: readonly SyntaxToken[] = this.getCachedTokens(bid, text, lang);\n\t\t\t\tfor (const token of tokens) {\n\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\tinlineDecoration(bid, token.from, token.to, {\n\t\t\t\t\t\t\tclass: `notectl-token--${token.type}`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Purge stale cache entries\n\t\t\tfor (const cachedId of this.tokenCache.keys()) {\n\t\t\t\tif (!activeBlockIds.has(cachedId)) {\n\t\t\t\t\tthis.tokenCache.delete(cachedId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (decorations.length === 0) return DecorationSetClass.empty;\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\tpre.setAttribute('dir', 'ltr');\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, ctx?: HTMLExportContext) {\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 bgAttr: string = bg\n\t\t\t\t\t? (ctx?.styleAttr(`background-color: ${bg}`) ?? ` style=\"background-color: ${bg}\"`)\n\t\t\t\t\t: '';\n\t\t\t\treturn `<pre dir=\"ltr\"${bgAttr}><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(\n\t\t\t'code_block',\n\t\t\tcreateCodeBlockNodeViewFactory(this.config, this.locale),\n\t\t);\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 (!isTextSelection(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\tisActive: (state) => {\n\t\t\t\tif (!isTextSelection(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// --- Paste Interceptor ---\n\n\tprivate registerPasteInterceptor(context: PluginContext): void {\n\t\tcontext.registerPasteInterceptor(this.handleCodeBlockPaste, {\n\t\t\tname: 'code-block:paste',\n\t\t\tpriority: 10,\n\t\t});\n\t}\n\n\tprivate readonly handleCodeBlockPaste: PasteInterceptor = (\n\t\tplainText: string,\n\t\t_html: string,\n\t\tstate: EditorState,\n\t): Transaction | null => {\n\t\tif (!plainText) return null;\n\t\tif (!isTextSelection(state.selection)) return null;\n\n\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\tif (!block || block.type !== 'code_block') return null;\n\n\t\tconst builder = state.transaction('paste');\n\n\t\tlet insertBlockId: BlockId = state.selection.anchor.blockId;\n\t\tlet insertOffset: number = state.selection.anchor.offset;\n\n\t\tif (!isCollapsed(state.selection)) {\n\t\t\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\t\t\tif (landingId) {\n\t\t\t\tinsertBlockId = landingId;\n\t\t\t\tinsertOffset = 0;\n\t\t\t}\n\t\t}\n\n\t\tbuilder.insertText(insertBlockId, insertOffset, plainText, []);\n\t\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + plainText.length));\n\n\t\treturn builder.build();\n\t};\n\n\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// --- Highlighter Setup ---\n\n\tprivate initHighlighter(): void {\n\t\tif (this.config.highlighter) {\n\t\t\tthis.highlighter = this.config.highlighter;\n\t\t} else {\n\t\t\tthis.highlighter = new RegexTokenizer();\n\t\t}\n\t}\n\n\tprivate registerLanguageRegistry(context: PluginContext): void {\n\t\tconst highlighter: SyntaxHighlighter | null = this.highlighter;\n\t\tconst cache: Map<\n\t\t\tBlockId,\n\t\t\t{ readonly text: string; readonly language: string; readonly tokens: readonly SyntaxToken[] }\n\t\t> = this.tokenCache;\n\n\t\tthis.languageRegistry.onRegister((support) => {\n\t\t\tif (support.highlighting && highlighter?.registerLanguage) {\n\t\t\t\thighlighter.registerLanguage(support.highlighting);\n\t\t\t\tcache.clear();\n\t\t\t}\n\t\t});\n\n\t\tcontext.registerService(LANGUAGE_REGISTRY_SERVICE_KEY, this.languageRegistry);\n\n\t\tthis.languageRegistry.register(JAVA_SUPPORT);\n\t\tthis.languageRegistry.register(JSON_SUPPORT);\n\t\tthis.languageRegistry.register(XML_SUPPORT);\n\t}\n\n\tprivate registerSyntaxHighlighterService(context: PluginContext): void {\n\t\tconst tokenizer = this.highlighter;\n\t\tif (!tokenizer) return;\n\n\t\tcontext.registerService(SYNTAX_HIGHLIGHTER_SERVICE_KEY, {\n\t\t\tregisterLanguage: (def) => {\n\t\t\t\ttokenizer.registerLanguage?.(def);\n\t\t\t\tthis.tokenCache.clear();\n\t\t\t},\n\t\t\tgetSupportedLanguages: () => tokenizer.getSupportedLanguages(),\n\t\t\ttokenize: (code, language) => tokenizer.tokenize(code, language),\n\t\t});\n\t}\n\n\tprivate getCachedTokens(\n\t\tblockId: BlockId,\n\t\ttext: string,\n\t\tlanguage: string,\n\t): readonly SyntaxToken[] {\n\t\tconst cached = this.tokenCache.get(blockId);\n\t\tif (cached && cached.text === text && cached.language === language) {\n\t\t\treturn cached.tokens;\n\t\t}\n\t\tconst tokens: readonly SyntaxToken[] = this.highlighter?.tokenize(text, language) ?? [];\n\t\tthis.tokenCache.set(blockId, { text, language, tokens });\n\t\treturn tokens;\n\t}\n\n\t// --- Helpers ---\n\n\tprivate getFocusedCodeBlockId(state: EditorState): BlockId | null {\n\t\tif (!isTextSelection(state.selection)) return null;\n\t\tconst blockId: BlockId = state.selection.anchor.blockId;\n\t\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\t\tif (block?.type === 'code_block')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GhC,gCAAA,CAAyC,GACxC,MAAM,EAAY,KAAK,YAClB,GAEL,EAAQ,gBAAgB,EAAgC,CACvD,iBAAmB,IAClB,EAAU,mBAAmB,GAC7B,KAAK,WAAW,SAEjB,sBAAA,IAA6B,EAAU,wBACvC,SAAA,CAAW,EAAM,IAAa,EAAU,SAAS,EAAM,KAIzD,eAAA,CACC,EACA,EACA,GAEA,MAAM,EAAS,KAAK,WAAW,IAAI,GACnC,GAAI,GAAU,EAAO,OAAS,GAAQ,EAAO,WAAa,EACzD,OAAO,EAAO,OAEf,MAAM,EAAiC,KAAK,aAAa,SAAS,EAAM,IAAa,GAErF,OADA,KAAK,WAAW,IAAI,EAAS,CAAE,OAAM,WAAU,WACxC,EAKR,qBAAA,CAA8B,GAC7B,IAAK,EAAgB,EAAM,WAAY,OAAO,KAC9C,MAAM,EAAmB,EAAM,UAAU,OAAO,QAEhD,MAAoB,eADiB,EAAM,SAAS,IACzC,KAA8B,EAClC"}
|
|
1
|
+
{"version":3,"file":"CodeBlockPlugin-C8H0nfF6.mjs","names":[],"sources":["../../src/editor/styles/code-block.ts","../../src/plugins/language/LanguageRegistry.ts","../../src/plugins/code-block/CodeBlockKeyboardHandlers.ts","../../src/plugins/code-block/CodeBlockCommands.ts","../../src/plugins/code-block/CodeBlockLocale.ts","../../src/plugins/code-block/CodeBlockNodeView.ts","../../src/plugins/code-block/CodeBlockTypes.ts","../../src/plugins/code-block/CodeBlockService.ts","../../src/plugins/code-block/highlighter/RegexTokenizer.ts","../../src/plugins/code-block/CodeBlockPlugin.ts"],"sourcesContent":["import { SYNTAX_TOKEN_TYPES } from '../theme/SyntaxTokenTypes.js';\n\n/** Generates per-token CSS rules from the canonical token type list. */\nfunction generateTokenCSS(): string {\n\treturn SYNTAX_TOKEN_TYPES.map(\n\t\t(type) =>\n\t\t\t`.notectl-token--${type} {\\n\\tcolor: var(--notectl-code-token-${type});\\n\\tfont-style: var(--notectl-code-token-${type}-font-style, inherit);\\n\\tfont-weight: var(--notectl-code-token-${type}-font-weight, inherit);\\n}`,\n\t).join('\\n');\n}\n\n/** Code block styles — syntax highlighting container, header, copy button. */\nexport const CODE_BLOCK_CSS = `\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${generateTokenCSS()}\n`;\n","/**\n * Internal registry that stores LanguageSupport bundles and notifies\n * subscribers with replay semantics for late subscribers.\n */\n\nimport type {\n\tLanguageRegistryListener,\n\tLanguageRegistryService,\n\tLanguageSupport,\n} from './LanguageTypes.js';\n\nexport class LanguageRegistry implements LanguageRegistryService {\n\tprivate readonly bundles = new Map<string, LanguageSupport>();\n\tprivate readonly listeners: LanguageRegistryListener[] = [];\n\n\tregister(support: LanguageSupport): void {\n\t\tthis.bundles.set(support.id, support);\n\t\tfor (const listener of this.listeners) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\t/**\n\t * Subscribes to language registrations.\n\t * The listener is immediately called for all already-registered bundles\n\t * (replay semantics), then called for each future registration.\n\t */\n\tonRegister(listener: LanguageRegistryListener): void {\n\t\tthis.listeners.push(listener);\n\t\tfor (const support of this.bundles.values()) {\n\t\t\tlistener(support);\n\t\t}\n\t}\n\n\tget(id: string): LanguageSupport | undefined {\n\t\treturn this.bundles.get(id);\n\t}\n\n\tgetAll(): readonly LanguageSupport[] {\n\t\treturn [...this.bundles.values()];\n\t}\n}\n","/**\n * 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 { createCollapsedSelection, isCollapsed, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport 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 (!isTextSelection(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 {\n\tcreateSelectionForBlockBoundary,\n\textractParentPath,\n\tfindSiblingIndex,\n\tgetSiblings,\n} from '../../commands/CommandHelpers.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport {\n\tcreateEmptyParagraph,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tgetInlineChildren,\n\tisBlockNode,\n\tisTextNode,\n} from '../../model/Document.js';\nimport { findNodePath } from '../../model/NodeResolver.js';\nimport { createCollapsedSelection, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction, TransactionBuilder } from '../../state/Transaction.js';\nimport type { PluginContext } from '../Plugin.js';\nimport { handleEscape } from './CodeBlockKeyboardHandlers.js';\nimport type { CodeBlockConfig } from './CodeBlockTypes.js';\n\n/** Registers all code-block commands. */\nexport function registerCodeBlockCommands(context: PluginContext, config: CodeBlockConfig): void {\n\tcontext.registerCommand('toggleCodeBlock', () => toggleCodeBlock(context, config));\n\n\tcontext.registerCommand('insertCodeBlock', () => insertCodeBlock(context, config));\n\n\tcontext.registerCommand('setCodeBlockLanguage', () => false);\n\n\tcontext.registerCommand('setCodeBlockBackground', () => false);\n\n\tcontext.registerCommand('exitCodeBlock', () => handleEscape(context));\n\n\tcontext.registerCommand('deleteCodeBlock', () => deleteCodeBlock(context));\n}\n\n// --- Command Implementations ---\n\nfunction toggleCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block) return false;\n\n\tif (block.type === 'code_block') {\n\t\tconst tr: Transaction = state\n\t\t\t.transaction('command')\n\t\t\t.setBlockType(state.selection.anchor.blockId, nodeType('paragraph'))\n\t\t\t.setSelection(state.selection)\n\t\t\t.build();\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\treturn insertCodeBlock(context, config);\n}\n\nfunction insertCodeBlock(context: PluginContext, config: CodeBlockConfig): boolean {\n\tconst state = context.getState();\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(sel.anchor.blockId);\n\tif (!block || block.type === 'code_block') return false;\n\n\tconst attrs: Record<string, string | number | boolean> = {\n\t\tlanguage: config.defaultLanguage ?? '',\n\t\tbackgroundColor: '',\n\t};\n\n\tconst builder: TransactionBuilder = state.transaction('command');\n\tstripAllMarks(builder, block);\n\tbuilder\n\t\t.setBlockType(sel.anchor.blockId, nodeType('code_block'), attrs)\n\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, 0));\n\n\tcontext.dispatch(builder.build());\n\treturn true;\n}\n\n/** Deletes the code block at the current cursor position. */\nfunction deleteCodeBlock(context: PluginContext): boolean {\n\tconst state = context.getState();\n\tif (!isTextSelection(state.selection)) return false;\n\n\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\tif (!block || block.type !== 'code_block') return false;\n\n\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, block.id);\n\tif (!tr) return false;\n\n\tcontext.dispatch(tr);\n\treturn true;\n}\n\n/** Builds a transaction that removes a code block and repositions the cursor. */\nexport function createDeleteCodeBlockTransaction(\n\tstate: EditorState,\n\tblockId: BlockId,\n): Transaction | null {\n\tconst path: string[] | undefined = findNodePath(state.doc, blockId);\n\tif (!path) return null;\n\n\tconst parentPath: BlockId[] = extractParentPath(path);\n\tconst siblings = getSiblings(state, parentPath);\n\tconst index: number = findSiblingIndex(siblings, blockId);\n\tif (index < 0) return null;\n\n\tconst builder = state.transaction('command');\n\n\tif (siblings.length === 1) {\n\t\tconst newId: BlockId = generateBlockId();\n\t\tbuilder.insertNode(parentPath, 0, createEmptyParagraph(newId));\n\t\tbuilder.removeNode(parentPath, 1);\n\t\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\t\treturn builder.build();\n\t}\n\n\tbuilder.removeNode(parentPath, index);\n\n\tconst prevSibling = siblings[index - 1];\n\tif (prevSibling && isBlockNode(prevSibling)) {\n\t\tconst selection = createSelectionForBlockBoundary(state, prevSibling.id, 'end');\n\t\tif (selection) {\n\t\t\tbuilder.setSelection(selection);\n\t\t\treturn builder.build();\n\t\t}\n\t}\n\n\tconst nextSibling = siblings[index + 1];\n\tif (nextSibling && isBlockNode(nextSibling)) {\n\t\tconst selection = createSelectionForBlockBoundary(state, nextSibling.id, 'start');\n\t\tif (selection) {\n\t\t\tbuilder.setSelection(selection);\n\t\t}\n\t}\n\n\treturn builder.build();\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\treadonly copyCodeAria: string;\n\treadonly escToExit: string;\n\treadonly codeBlockAriaLabel: (lang: string) => string;\n\treadonly copiedToClipboard: string;\n\treadonly deleteCodeBlockAria: string;\n\treadonly deletedCodeBlock: string;\n}\n\n// --- Default English Locale ---\n\nexport const CODE_BLOCK_LOCALE_EN: CodeBlockLocale = {\n\tlabel: 'Code Block',\n\ttooltip: (shortcut?: string) => (shortcut ? `Code Block (${shortcut})` : 'Code Block'),\n\tenteredCodeBlock: 'Entered code block. Press Escape to exit.',\n\tleftCodeBlock: 'Left code block.',\n\tcopyCodeAria: 'Copy code',\n\tescToExit: 'Esc to exit',\n\tcodeBlockAriaLabel: (lang: string) => `${lang} code block. Press Escape to exit.`,\n\tcopiedToClipboard: 'Copied to clipboard',\n\tdeleteCodeBlockAria: 'Delete code block',\n\tdeletedCodeBlock: 'Code block deleted',\n};\n\n// --- Lazy Locale Loader ---\n\nconst localeModules: Record<string, () => Promise<{ default: CodeBlockLocale }>> =\n\timport.meta.glob<{ default: CodeBlockLocale }>('./locales/*.ts', { eager: false });\n\nexport async function loadCodeBlockLocale(lang: string): Promise<CodeBlockLocale> {\n\tif (lang === 'en') return CODE_BLOCK_LOCALE_EN;\n\tconst loader = localeModules[`./locales/${lang}.ts`];\n\tif (!loader) return CODE_BLOCK_LOCALE_EN;\n\ttry {\n\t\tconst mod = await loader();\n\t\treturn mod.default;\n\t} catch {\n\t\treturn CODE_BLOCK_LOCALE_EN;\n\t}\n}\n","/**\n * NodeView factory for code blocks.\n * Renders <pre> with a non-editable header (language label + action buttons)\n * and a <code> content area where the Reconciler renders text.\n */\n\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { NodeView, NodeViewFactory } from '../../view/NodeView.js';\nimport { createDeleteCodeBlockTransaction } from './CodeBlockCommands.js';\nimport { CODE_BLOCK_LOCALE_EN, type CodeBlockLocale } from './CodeBlockLocale.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\nconst DELETE_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z\"/></svg>';\n\n/** Creates a NodeViewFactory for code_block nodes. */\nexport function createCodeBlockNodeViewFactory(\n\tconfig: CodeBlockConfig,\n\tlocale: CodeBlockLocale = CODE_BLOCK_LOCALE_EN,\n): NodeViewFactory {\n\treturn (\n\t\tnode: BlockNode,\n\t\tgetState: () => EditorState,\n\t\tdispatch: (tr: Transaction) => void,\n\t): NodeView => {\n\t\t// --- DOM Construction ---\n\t\tconst pre: HTMLElement = document.createElement('pre');\n\t\tpre.className = 'notectl-code-block';\n\t\tpre.setAttribute('data-block-id', node.id);\n\t\tpre.setAttribute('dir', 'ltr');\n\t\tpre.setAttribute('role', 'group');\n\t\tpre.setAttribute('aria-roledescription', 'code block');\n\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', locale.copyCodeAria);\n\t\t\tcopyBtn.setAttribute('data-notectl-no-print', '');\n\t\t\tcopyBtn.type = 'button';\n\t\t\tcopyBtn.innerHTML = COPY_ICON;\n\t\t}\n\n\t\t// Delete button\n\t\tconst deleteBtn: HTMLButtonElement = document.createElement('button');\n\t\tdeleteBtn.className = 'notectl-code-block__delete';\n\t\tdeleteBtn.setAttribute('aria-label', locale.deleteCodeBlockAria);\n\t\tdeleteBtn.title = locale.deleteCodeBlockAria;\n\t\tdeleteBtn.setAttribute('data-notectl-no-print', '');\n\t\tdeleteBtn.type = 'button';\n\t\tdeleteBtn.innerHTML = DELETE_ICON;\n\n\t\t// Screen reader live region for action feedback\n\t\tconst announcer: HTMLSpanElement = document.createElement('span');\n\t\tannouncer.className = 'notectl-sr-only';\n\t\tannouncer.setAttribute('aria-live', 'assertive');\n\t\tannouncer.setAttribute('aria-atomic', 'true');\n\n\t\t// Actions wrapper groups buttons on the right side\n\t\tconst actions: HTMLDivElement = document.createElement('div');\n\t\tactions.className = 'notectl-code-block__actions';\n\t\tif (copyBtn) {\n\t\t\tactions.appendChild(copyBtn);\n\t\t}\n\t\tactions.appendChild(deleteBtn);\n\n\t\theader.appendChild(langLabel);\n\t\theader.appendChild(actions);\n\t\theader.appendChild(announcer);\n\n\t\t// Content area (Reconciler target)\n\t\tconst code: HTMLElement = document.createElement('code');\n\t\tcode.className = 'notectl-code-block__content';\n\n\t\t// Escape hint (visible only when focused, CSS-driven)\n\t\tconst escHint: HTMLDivElement = document.createElement('div');\n\t\tescHint.className = 'notectl-code-block__esc-hint';\n\t\tescHint.setAttribute('contenteditable', 'false');\n\t\tescHint.setAttribute('aria-hidden', 'true');\n\t\tescHint.setAttribute('data-notectl-no-print', '');\n\t\tescHint.textContent = locale.escToExit;\n\n\t\tpre.appendChild(header);\n\t\tpre.appendChild(code);\n\t\tpre.appendChild(escHint);\n\n\t\t// Apply config-level color overrides as CSS custom properties\n\t\tif (config.background) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-bg', config.background);\n\t\t}\n\t\tif (config.headerBackground) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-bg', config.headerBackground);\n\t\t}\n\t\tif (config.textColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-color', config.textColor);\n\t\t}\n\t\tif (config.headerColor) {\n\t\t\tsetStyleProperty(pre, '--notectl-code-block-header-color', config.headerColor);\n\t\t}\n\n\t\tlet currentNodeId: BlockId = node.id;\n\n\t\t// --- Attribute Application ---\n\n\t\tfunction applyAttrs(n: BlockNode): void {\n\t\t\tconst lang: string = (n.attrs?.language as string) ?? '';\n\t\t\tconst langName: string = lang || 'plain';\n\t\t\tlangLabel.textContent = langName;\n\t\t\tpre.setAttribute('aria-label', locale.codeBlockAriaLabel(langName));\n\n\t\t\tif (lang) {\n\t\t\t\tcode.setAttribute('data-language', lang);\n\t\t\t} else {\n\t\t\t\tcode.removeAttribute('data-language');\n\t\t\t}\n\n\t\t\tconst bg: string = (n.attrs?.backgroundColor as string) ?? '';\n\t\t\tsetStyleProperty(pre, 'backgroundColor', bg || '');\n\t\t}\n\n\t\tapplyAttrs(node);\n\n\t\t// --- Copy Button Handler ---\n\n\t\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\tannouncer.textContent = locale.copiedToClipboard;\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tannouncer.textContent = '';\n\t\t\t\t}, 1000);\n\t\t\t});\n\t\t}\n\n\t\t// --- Delete Button Handler ---\n\n\t\tdeleteBtn.addEventListener('click', (e: MouseEvent) => {\n\t\t\te.preventDefault();\n\t\t\te.stopPropagation();\n\n\t\t\tconst state: EditorState = getState();\n\t\t\tconst tr: Transaction | null = createDeleteCodeBlockTransaction(state, currentNodeId);\n\t\t\tif (!tr) return;\n\n\t\t\tannouncer.textContent = locale.deletedCodeBlock;\n\t\t\tdispatch(tr);\n\t\t});\n\n\t\t// --- NodeView Interface ---\n\n\t\treturn {\n\t\t\tdom: pre,\n\t\t\tcontentDOM: code,\n\n\t\t\tupdate(updatedNode: BlockNode): boolean {\n\t\t\t\tif (updatedNode.type !== 'code_block') return false;\n\t\t\t\tcurrentNodeId = updatedNode.id;\n\t\t\t\tpre.setAttribute('data-block-id', updatedNode.id);\n\t\t\t\tapplyAttrs(updatedNode);\n\t\t\t\treturn true;\n\t\t\t},\n\n\t\t\tselectNode(): void {\n\t\t\t\tpre.classList.add('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdeselectNode(): void {\n\t\t\t\tpre.classList.remove('notectl-code-block--selected');\n\t\t\t},\n\n\t\t\tdestroy(): void {\n\t\t\t\t// No cleanup needed\n\t\t\t},\n\t\t};\n\t};\n}\n","/**\n * Types, interfaces, and constants for the code-block plugin.\n */\n\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { ServiceKey } from '../Plugin.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\tcode_block: {\n\t\t\tlanguage: string;\n\t\t\tbackgroundColor: string;\n\t\t};\n\t}\n}\n\n// --- Syntax Highlighting Types ---\n\nimport type { SyntaxTokenType } from '../../editor/theme/SyntaxTokenTypes.js';\n\nexport interface SyntaxToken {\n\treadonly from: number;\n\treadonly to: number;\n\treadonly type: SyntaxTokenType | (string & {});\n}\n\nexport interface SyntaxHighlighter {\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n\tgetSupportedLanguages(): readonly string[];\n\tregisterLanguage?(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n}\n\n// --- Configuration ---\n\n/**\n * Configurable keyboard bindings for CodeBlockPlugin actions.\n * Omit a slot to use the default; set to `null` to disable the binding.\n *\n * Key descriptor format: `'Mod-Enter'`, `'Mod-Shift-M'`, etc.\n * `Mod` resolves to Cmd on macOS, Ctrl on Windows/Linux.\n */\nexport interface CodeBlockKeymap {\n\t/**\n\t * Insert a new paragraph below the code block and move the cursor there.\n\t * @default 'Mod-Enter'\n\t */\n\treadonly insertAfter?: string | null;\n\n\t/**\n\t * Toggle the current block between code block and paragraph.\n\t * @default 'Mod-Shift-M'\n\t */\n\treadonly toggle?: string | null;\n}\n\nexport const DEFAULT_KEYMAP: Readonly<Record<keyof CodeBlockKeymap, string>> = {\n\tinsertAfter: 'Mod-Enter',\n\ttoggle: 'Mod-Shift-M',\n};\n\nexport interface CodeBlockConfig {\n\treadonly highlighter?: SyntaxHighlighter;\n\treadonly defaultLanguage?: string;\n\treadonly useSpaces?: boolean;\n\treadonly spaceCount?: number;\n\treadonly showCopyButton?: boolean;\n\t/** Default body background color (overrides --notectl-code-block-bg). */\n\treadonly background?: string;\n\t/** Default header background color (overrides --notectl-code-block-header-bg). */\n\treadonly headerBackground?: string;\n\t/** Default text color (overrides --notectl-code-block-color). */\n\treadonly textColor?: string;\n\t/** Default header/label text color (overrides --notectl-code-block-header-color). */\n\treadonly headerColor?: string;\n\t/** Customize keyboard bindings for code block actions. */\n\treadonly keymap?: CodeBlockKeymap;\n\t/** Locale override for user-facing strings. */\n\treadonly locale?: import('./CodeBlockLocale.js').CodeBlockLocale;\n}\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// --- Syntax Highlighter Service ---\n\nexport interface SyntaxHighlighterService {\n\tregisterLanguage(def: import('./highlighter/TokenizerTypes.js').LanguageDefinition): void;\n\tgetSupportedLanguages(): readonly string[];\n\ttokenize(code: string, language: string): readonly SyntaxToken[];\n}\n\nexport const SYNTAX_HIGHLIGHTER_SERVICE_KEY = new ServiceKey<SyntaxHighlighterService>(\n\t'syntaxHighlighter',\n);\n\n// --- SVG Icon ---\n\nexport const CODE_BLOCK_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"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 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: BlockId[] | undefined = state.getNodePath(bid);\n\tif (!path) return;\n\n\tconst newAttrs: BlockAttrs = { ...block.attrs, [key]: value };\n\tconst tr: Transaction = state.transaction('command').setNodeAttr(path, newAttrs).build();\n\n\tcontext.dispatch(tr);\n}\n","/**\n * Regex-based syntax tokenizer.\n * Implements the SyntaxHighlighter interface using linear regex scanning.\n */\n\nimport type { SyntaxHighlighter, SyntaxToken } from '../CodeBlockTypes.js';\nimport type { LanguageDefinition } from './TokenizerTypes.js';\n\nexport class RegexTokenizer implements SyntaxHighlighter {\n\tprivate readonly languageMap = new Map<string, LanguageDefinition>();\n\n\tconstructor(languages?: readonly LanguageDefinition[]) {\n\t\tif (languages) {\n\t\t\tfor (const lang of languages) {\n\t\t\t\tthis.registerLanguageInternal(lang);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Registers a language definition. Overwrites existing definitions for the same name/aliases. */\n\tregisterLanguage(def: LanguageDefinition): void {\n\t\tthis.registerLanguageInternal(def);\n\t}\n\n\t/** Tokenizes code using the specified language. Returns empty array for unknown languages. */\n\ttokenize(code: string, language: string): readonly SyntaxToken[] {\n\t\tconst lang: LanguageDefinition | undefined = this.languageMap.get(language.toLowerCase());\n\t\tif (!lang) return [];\n\n\t\tconst tokens: SyntaxToken[] = [];\n\t\tlet pos = 0;\n\n\t\twhile (pos < code.length) {\n\t\t\tlet matched = false;\n\n\t\t\tfor (const pattern of lang.patterns) {\n\t\t\t\tconst match: RegExpExecArray | null = pattern.pattern.exec(code.slice(pos));\n\t\t\t\tif (match && match[0].length > 0) {\n\t\t\t\t\ttokens.push({\n\t\t\t\t\t\tfrom: pos,\n\t\t\t\t\t\tto: pos + match[0].length,\n\t\t\t\t\t\ttype: pattern.type,\n\t\t\t\t\t});\n\t\t\t\t\tpos += match[0].length;\n\t\t\t\t\tmatched = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!matched) {\n\t\t\t\tpos++;\n\t\t\t}\n\t\t}\n\n\t\treturn tokens;\n\t}\n\n\t/** Returns all registered language names and aliases. */\n\tgetSupportedLanguages(): readonly string[] {\n\t\tconst names = new Set<string>();\n\t\tfor (const lang of this.languageMap.values()) {\n\t\t\tnames.add(lang.name);\n\t\t\tfor (const alias of lang.aliases) {\n\t\t\t\tnames.add(alias);\n\t\t\t}\n\t\t}\n\t\treturn [...names];\n\t}\n\n\tprivate registerLanguageInternal(def: LanguageDefinition): void {\n\t\tthis.languageMap.set(def.name.toLowerCase(), def);\n\t\tfor (const alias of def.aliases) {\n\t\t\tthis.languageMap.set(alias.toLowerCase(), def);\n\t\t}\n\t}\n}\n","/**\n * 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 { addDeleteSelectionSteps } from '../../commands/Commands.js';\nimport type { Decoration, DecorationSet } from '../../decorations/Decoration.js';\nimport {\n\tinline as inlineDecoration,\n\tnode as nodeDecoration,\n} from '../../decorations/Decoration.js';\nimport { DecorationSet as DecorationSetClass } from '../../decorations/Decoration.js';\nimport { CODE_BLOCK_CSS } from '../../editor/styles/code-block.js';\nimport type { BlockNode } from '../../model/Document.js';\nimport { getBlockText } from '../../model/Document.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { HTMLExportContext } from '../../model/NodeSpec.js';\nimport { createCollapsedSelection, isCollapsed, isTextSelection } from '../../model/Selection.js';\nimport type { BlockId } from '../../model/TypeBrands.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Transaction } from '../../state/Transaction.js';\nimport { createBlockElement } from '../../view/DomUtils.js';\nimport type { PasteInterceptor, Plugin, PluginContext } from '../Plugin.js';\nimport { LanguageRegistry } from '../language/LanguageRegistry.js';\nimport { LANGUAGE_REGISTRY_SERVICE_KEY } from '../language/LanguageTypes.js';\nimport { JAVA_SUPPORT, JSON_SUPPORT, XML_SUPPORT } from '../language/bundles/index.js';\nimport { resolveLocale } from '../shared/PluginHelpers.js';\nimport { formatShortcut } from '../shared/ShortcutFormatting.js';\nimport { registerCodeBlockCommands } from './CodeBlockCommands.js';\nimport { registerCodeBlockKeymaps } from './CodeBlockKeyboardHandlers.js';\nimport {\n\tCODE_BLOCK_LOCALE_EN,\n\ttype CodeBlockLocale,\n\tloadCodeBlockLocale,\n} from './CodeBlockLocale.js';\nimport { createCodeBlockNodeViewFactory } from './CodeBlockNodeView.js';\nimport { registerCodeBlockService } from './CodeBlockService.js';\nimport type {\n\tCodeBlockConfig,\n\tCodeBlockKeymap,\n\tSyntaxHighlighter,\n\tSyntaxToken,\n} from './CodeBlockTypes.js';\nimport {\n\tCODE_BLOCK_ICON,\n\tDEFAULT_CONFIG,\n\tDEFAULT_KEYMAP,\n\tSYNTAX_HIGHLIGHTER_SERVICE_KEY,\n} from './CodeBlockTypes.js';\nimport { RegexTokenizer } from './highlighter/RegexTokenizer.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\tprivate highlighter: SyntaxHighlighter | null = null;\n\tprivate readonly languageRegistry = new LanguageRegistry();\n\tprivate readonly tokenCache = new Map<\n\t\tBlockId,\n\t\t{\n\t\t\treadonly text: string;\n\t\t\treadonly language: string;\n\t\t\treadonly tokens: readonly SyntaxToken[];\n\t\t}\n\t>();\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\tasync init(context: PluginContext): Promise<void> {\n\t\tthis.locale = await resolveLocale(\n\t\t\tcontext,\n\t\t\tthis.config.locale,\n\t\t\tCODE_BLOCK_LOCALE_EN,\n\t\t\tloadCodeBlockLocale,\n\t\t);\n\t\tcontext.registerStyleSheet(CODE_BLOCK_CSS);\n\t\tthis.context = context;\n\n\t\tthis.initHighlighter();\n\t\tthis.registerLanguageRegistry(context);\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.registerSyntaxHighlighterService(context);\n\t\tthis.registerPasteInterceptor(context);\n\t\tthis.patchTableCellContent(context);\n\t}\n\n\tdestroy(): void {\n\t\tthis.context = null;\n\t\tthis.highlighter = null;\n\t\tthis.tokenCache.clear();\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 = !isTextSelection(oldState.selection)\n\t\t\t? null\n\t\t\t: oldState.selection.anchor.blockId;\n\t\tconst newBlockId: BlockId | null = !isTextSelection(newState.selection)\n\t\t\t? null\n\t\t\t: newState.selection.anchor.blockId;\n\n\t\tconst oldBlock: BlockNode | undefined = oldBlockId ? oldState.getBlock(oldBlockId) : undefined;\n\t\tconst newBlock: BlockNode | undefined = newBlockId ? newState.getBlock(newBlockId) : undefined;\n\n\t\tconst wasInCode: boolean = oldBlock?.type === 'code_block';\n\t\tconst nowInCode: boolean = newBlock?.type === 'code_block';\n\n\t\tif (!wasInCode && nowInCode) {\n\t\t\tthis.context.announce(this.locale.enteredCodeBlock);\n\t\t} else if (wasInCode && !nowInCode) {\n\t\t\tthis.context.announce(this.locale.leftCodeBlock);\n\t\t}\n\t}\n\n\tdecorations(state: EditorState): DecorationSet {\n\t\tconst decorations: Decoration[] = [];\n\n\t\tconst focusedBlockId: BlockId | null = this.getFocusedCodeBlockId(state);\n\t\tif (focusedBlockId) {\n\t\t\tdecorations.push(nodeDecoration(focusedBlockId, { class: 'notectl-code-block--focused' }));\n\t\t}\n\n\t\tif (this.highlighter) {\n\t\t\tconst activeBlockIds = new Set<BlockId>();\n\t\t\tfor (const bid of state.getBlockOrder()) {\n\t\t\t\tconst block: BlockNode | undefined = state.getBlock(bid);\n\t\t\t\tif (!block || block.type !== 'code_block') continue;\n\n\t\t\t\tconst lang: string = (block.attrs?.language as string) ?? '';\n\t\t\t\tif (!lang) continue;\n\n\t\t\t\tconst text: string = getBlockText(block);\n\t\t\t\tif (!text) continue;\n\n\t\t\t\tactiveBlockIds.add(bid);\n\t\t\t\tconst tokens: readonly SyntaxToken[] = this.getCachedTokens(bid, text, lang);\n\t\t\t\tfor (const token of tokens) {\n\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\tinlineDecoration(bid, token.from, token.to, {\n\t\t\t\t\t\t\tclass: `notectl-token--${token.type}`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Purge stale cache entries\n\t\t\tfor (const cachedId of this.tokenCache.keys()) {\n\t\t\t\tif (!activeBlockIds.has(cachedId)) {\n\t\t\t\t\tthis.tokenCache.delete(cachedId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (decorations.length === 0) return DecorationSetClass.empty;\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\tpre.setAttribute('dir', 'ltr');\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, ctx?: HTMLExportContext) {\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 bgAttr: string = bg\n\t\t\t\t\t? (ctx?.styleAttr(`background-color: ${bg}`) ?? ` style=\"background-color: ${bg}\"`)\n\t\t\t\t\t: '';\n\t\t\t\treturn `<pre dir=\"ltr\"${bgAttr}><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(\n\t\t\t'code_block',\n\t\t\tcreateCodeBlockNodeViewFactory(this.config, this.locale),\n\t\t);\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 (!isTextSelection(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\tisActive: (state) => {\n\t\t\t\tif (!isTextSelection(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// --- Paste Interceptor ---\n\n\tprivate registerPasteInterceptor(context: PluginContext): void {\n\t\tcontext.registerPasteInterceptor(this.handleCodeBlockPaste, {\n\t\t\tname: 'code-block:paste',\n\t\t\tpriority: 10,\n\t\t});\n\t}\n\n\tprivate readonly handleCodeBlockPaste: PasteInterceptor = (\n\t\tplainText: string,\n\t\t_html: string,\n\t\tstate: EditorState,\n\t): Transaction | null => {\n\t\tif (!plainText) return null;\n\t\tif (!isTextSelection(state.selection)) return null;\n\n\t\tconst block: BlockNode | undefined = state.getBlock(state.selection.anchor.blockId);\n\t\tif (!block || block.type !== 'code_block') return null;\n\n\t\tconst builder = state.transaction('paste');\n\n\t\tlet insertBlockId: BlockId = state.selection.anchor.blockId;\n\t\tlet insertOffset: number = state.selection.anchor.offset;\n\n\t\tif (!isCollapsed(state.selection)) {\n\t\t\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\t\t\tif (landingId) {\n\t\t\t\tinsertBlockId = landingId;\n\t\t\t\tinsertOffset = 0;\n\t\t\t}\n\t\t}\n\n\t\tbuilder.insertText(insertBlockId, insertOffset, plainText, []);\n\t\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + plainText.length));\n\n\t\treturn builder.build();\n\t};\n\n\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// --- Highlighter Setup ---\n\n\tprivate initHighlighter(): void {\n\t\tif (this.config.highlighter) {\n\t\t\tthis.highlighter = this.config.highlighter;\n\t\t} else {\n\t\t\tthis.highlighter = new RegexTokenizer();\n\t\t}\n\t}\n\n\tprivate registerLanguageRegistry(context: PluginContext): void {\n\t\tconst highlighter: SyntaxHighlighter | null = this.highlighter;\n\t\tconst cache: Map<\n\t\t\tBlockId,\n\t\t\t{ readonly text: string; readonly language: string; readonly tokens: readonly SyntaxToken[] }\n\t\t> = this.tokenCache;\n\n\t\tthis.languageRegistry.onRegister((support) => {\n\t\t\tif (support.highlighting && highlighter?.registerLanguage) {\n\t\t\t\thighlighter.registerLanguage(support.highlighting);\n\t\t\t\tcache.clear();\n\t\t\t}\n\t\t});\n\n\t\tcontext.registerService(LANGUAGE_REGISTRY_SERVICE_KEY, this.languageRegistry);\n\n\t\tthis.languageRegistry.register(JAVA_SUPPORT);\n\t\tthis.languageRegistry.register(JSON_SUPPORT);\n\t\tthis.languageRegistry.register(XML_SUPPORT);\n\t}\n\n\tprivate registerSyntaxHighlighterService(context: PluginContext): void {\n\t\tconst tokenizer = this.highlighter;\n\t\tif (!tokenizer) return;\n\n\t\tcontext.registerService(SYNTAX_HIGHLIGHTER_SERVICE_KEY, {\n\t\t\tregisterLanguage: (def) => {\n\t\t\t\ttokenizer.registerLanguage?.(def);\n\t\t\t\tthis.tokenCache.clear();\n\t\t\t},\n\t\t\tgetSupportedLanguages: () => tokenizer.getSupportedLanguages(),\n\t\t\ttokenize: (code, language) => tokenizer.tokenize(code, language),\n\t\t});\n\t}\n\n\tprivate getCachedTokens(\n\t\tblockId: BlockId,\n\t\ttext: string,\n\t\tlanguage: string,\n\t): readonly SyntaxToken[] {\n\t\tconst cached = this.tokenCache.get(blockId);\n\t\tif (cached && cached.text === text && cached.language === language) {\n\t\t\treturn cached.tokens;\n\t\t}\n\t\tconst tokens: readonly SyntaxToken[] = this.highlighter?.tokenize(text, language) ?? [];\n\t\tthis.tokenCache.set(blockId, { text, language, tokens });\n\t\treturn tokens;\n\t}\n\n\t// --- Helpers ---\n\n\tprivate getFocusedCodeBlockId(state: EditorState): BlockId | null {\n\t\tif (!isTextSelection(state.selection)) return null;\n\t\tconst blockId: BlockId = state.selection.anchor.blockId;\n\t\tconst block: BlockNode | undefined = state.getBlock(blockId);\n\t\tif (block?.type === 'code_block') return blockId;\n\t\treturn null;\n\t}\n}\n"],"mappings":"u1BAWA,IAAa,EAAiB,4wEAPtB,EAAmB,IACxB,GACA,mBAAmB,0CAA6C,+CAAkD,oEAAuE,+BACzL,KAAK,UCIK,EAAb,MACC,uBAA2B,IAAI,IAC/B,UAAyD,GAEzD,QAAA,CAAS,GACR,KAAK,QAAQ,IAAI,EAAQ,GAAI,GAC7B,IAAK,MAAM,KAAY,KAAK,UAC3B,EAAS,GASX,UAAA,CAAW,GACV,KAAK,UAAU,KAAK,GACpB,IAAK,MAAM,KAAW,KAAK,QAAQ,SAClC,EAAS,GAIX,GAAA,CAAI,GACH,OAAO,KAAK,QAAQ,IAAI,GAGzB,MAAA,GACC,MAAO,IAAI,KAAK,QAAQ,YCV1B,SAAS,EACR,EACA,GAEA,MAAM,EAAqB,EAAQ,WACnC,IAAK,EAAgB,EAAM,WAAY,OAAO,EAE9C,MAAM,EAAM,EAAM,UACZ,EAA+B,EAAM,SAAS,EAAI,OAAO,SAC/D,SAAK,GAAwB,eAAf,EAAM,OAEb,EAAQ,CACd,QACA,QACA,QAAS,EAAI,OAAO,QACpB,OAAQ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f.mjs";import{i as n,n as o,r as i,t as r}from"./AttributedMarkCommands-BiJtiHpx.mjs";import{r as s,s as a}from"./StyleRuntime-Bwde5icB.mjs";import{i as l}from"./PluginHelpers-BZU5rE44.mjs";import{n as c}from"./ColorValidation-rOrJxBBt.mjs";var m={label:"Font",tooltip:"Font Family"},p=/* @__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar-CqD9pUY0.mjs"),"./locales/de.ts":()=>import("./de-hneXQd4z.mjs"),"./locales/es.ts":()=>import("./es-DFCDhXJb.mjs"),"./locales/fr.ts":()=>import("./fr-DGBuhK3D.mjs"),"./locales/hi.ts":()=>import("./hi-ClSwgZfK.mjs"),"./locales/pt.ts":()=>import("./pt-kFy3gqNp.mjs"),"./locales/ru.ts":()=>import("./ru-DZge62_-.mjs"),"./locales/zh.ts":()=>import("./zh-CyX2tIRP.mjs")});async function f(t){if("en"===t)return m;const e=p[`./locales/${t}.ts`];if(!e)return m;try{return(await e()).default}catch{return m}}var d=class{id="font";name="Font";priority=22;config;locale;injectedStyleElement=null;context=null;constructor(t){this.config=t}async init(t){this.locale=await l(t,this.config.locale,m,f),t.registerStyleSheet("\n/* Font Select — Width overrides for combobox button */\n.notectl-toolbar-btn--font {\n\tmin-width: 100px;\n\tmax-width: 160px;\n}\n\n/* Font Picker Popup */\n.notectl-font-picker {\n\tmin-width: 200px;\n\tmax-height: 320px;\n\toverflow-y: auto;\n}\n\n.notectl-font-picker__list {\n\tpadding: 4px 0;\n}\n\n.notectl-font-picker__item {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n\twidth: 100%;\n\tpadding: 7px 12px;\n\tborder: none;\n\tbackground: none;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tcolor: var(--notectl-fg);\n\tline-height: 1.4;\n\ttext-align: start;\n\twhite-space: nowrap;\n\tfont-family: inherit;\n\ttransition: background 0.1s;\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item:hover {\n\t\tbackground: var(--notectl-hover-bg);\n\t}\n}\n\n.notectl-font-picker__item--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item--active:hover {\n\t\tbackground: var(--notectl-active-bg);\n\t}\n}\n\n.notectl-font-picker__check {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 16px;\n\tflex-shrink: 0;\n\tfont-size: 13px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__label {\n\tflex: 1;\n}\n\n.notectl-font-picker__separator {\n\theight: 1px;\n\tbackground: var(--notectl-border);\n\tmargin: 4px 8px;\n}\n"),this.context=t,this.registerMarkSpec(t),this.registerCommands(t),this.config.fonts.length>0&&this.registerToolbarItem(t),this.injectFontFaces()}destroy(){this.injectedStyleElement?.remove(),this.injectedStyleElement=null,this.context=null}registerMarkSpec(t){t.registerMarkSpec({type:"font",rank:6,attrs:{family:{default:""}},toDOM(t){const e=document.createElement("span"),n=t.attrs?.family??"";return n&&a(e,"fontFamily",n),e},toHTMLString:(t,n,o)=>{const i=String(t.attrs?.family??"");if(!i||!c(i))return n;const r=`font-family: ${e(i)}`;return`<span${o?.styleAttr(r)??` style="${r}"`}>${n}</span>`},toHTMLStyle:t=>{const n=String(t.attrs?.family??"");return n&&c(n)?`font-family: ${e(n)}`:null},parseHTML:[{tag:"span",getAttrs:t=>{const e=t.style.fontFamily;return!!e&&{family:e.replace(/"/g,"'")}}}],sanitize:{tags:["span"]}})}registerCommands(t){t.registerCommand("removeFont",()=>{const e=t.getState();return this.removeFont(t,e)}),t.registerCommand("setFont",()=>!1)}get defaultFont(){if(this.config.defaultFont){const t=this.config.fonts.find(t=>t.name===this.config.defaultFont);if(t)return t}return this.config.fonts[0]}registerToolbarItem(t){t.registerToolbarItem({id:"font",group:"format",label:this.locale.label,tooltip:this.locale.tooltip,command:"removeFont",popupType:"combobox",getLabel:t=>this.resolveFontName(this.getActiveFont(t)),renderPopup:(t,e,n)=>{this.renderFontPopup(t,e,n)},isActive:t=>this.isFontActive(t)})}resolveFontName(t){return t?this.config.fonts.find(e=>e.family===t)?.name??(t.split(",")[0]??"").trim().replace(/['"]/g,""):this.defaultFont?.name??this.locale.label}isFontActive(t){return i(t,"font")}getActiveFont(t){return o(t,"font",t=>t.attrs.family??null)}applyFont(e,n,o){const i=r(n,{type:t("font"),attrs:{family:o}});return!!i&&(e.dispatch(i),!0)}removeFont(e,o){const i=n(o,t("font"));return!!i&&(e.dispatch(i),!0)}injectFontFaces(){const t=[];for(const o of this.config.fonts)if(o.fontFaces?.length)for(const e of o.fontFaces){const n=[`font-family: '${(o.family.split(",")[0]??"").trim().replace(/['"]/g,"")}'`,`src: ${e.src}`];e.weight&&n.push(`font-weight: ${e.weight}`),e.style&&n.push(`font-style: ${e.style}`),n.push(`font-display: ${e.display??"swap"}`),t.push(`@font-face {\n\t${n.join(";\n\t")};\n}`)}if(0===t.length)return;const e=document.createElement("style");e.setAttribute("data-notectl-fonts","");const n=this.context?s(this.context.getContainer()):void 0;n&&e.setAttribute("nonce",n),e.textContent=t.join("\n\n"),document.head.appendChild(e),this.injectedStyleElement=e}renderFontPopup(t,e,n){t.classList.add("notectl-font-picker");const o=e.getState(),i=this.getActiveFont(o),r=this.defaultFont?.family,s=e.getContainer(),a=document.createElement("div");a.className="notectl-font-picker__list",a.setAttribute("role","listbox"),a.setAttribute("aria-label",this.locale.label);for(const l of this.config.fonts){const t=void 0!==r&&l.family===r,o=t&&!i||i===l.family,c=this.createFontItem(l.name,l.family,o,o=>{o.preventDefault(),o.stopPropagation(),t?e.executeCommand("removeFont"):this.applyFont(e,e.getState(),l.family),n({restoreFocusTo:s})});l.category&&c.setAttribute("data-category",l.category),a.appendChild(c)}t.appendChild(a)}createFontItem(t,e,n,o){const i=document.createElement("button");i.type="button",i.className="notectl-font-picker__item",i.setAttribute("role","option"),i.setAttribute("aria-selected",String(n)),n&&i.classList.add("notectl-font-picker__item--active");const r=document.createElement("span");r.className="notectl-font-picker__check",r.textContent=n?"✓":"",i.appendChild(r);const s=document.createElement("span");return s.className="notectl-font-picker__label",s.textContent=t,e&&a(s,"fontFamily",e),i.appendChild(s),i.addEventListener("mousedown",o),i}};export{m as n,f as r,d as t};
|
|
2
|
+
//# sourceMappingURL=FontPlugin-BDjM9v3y.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FontPlugin-BDjM9v3y.mjs","names":[],"sources":["../../src/editor/styles/font-select.ts","../../src/plugins/font/FontLocale.ts","../../src/plugins/font/FontPlugin.ts"],"sourcesContent":["/** Font picker toolbar combobox + popup styles. */\nexport const FONT_SELECT_CSS = `\n/* Font Select — Width overrides for combobox button */\n.notectl-toolbar-btn--font {\n\tmin-width: 100px;\n\tmax-width: 160px;\n}\n\n/* Font Picker Popup */\n.notectl-font-picker {\n\tmin-width: 200px;\n\tmax-height: 320px;\n\toverflow-y: auto;\n}\n\n.notectl-font-picker__list {\n\tpadding: 4px 0;\n}\n\n.notectl-font-picker__item {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n\twidth: 100%;\n\tpadding: 7px 12px;\n\tborder: none;\n\tbackground: none;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tcolor: var(--notectl-fg);\n\tline-height: 1.4;\n\ttext-align: start;\n\twhite-space: nowrap;\n\tfont-family: inherit;\n\ttransition: background 0.1s;\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item:hover {\n\t\tbackground: var(--notectl-hover-bg);\n\t}\n}\n\n.notectl-font-picker__item--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item--active:hover {\n\t\tbackground: var(--notectl-active-bg);\n\t}\n}\n\n.notectl-font-picker__check {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 16px;\n\tflex-shrink: 0;\n\tfont-size: 13px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__label {\n\tflex: 1;\n}\n\n.notectl-font-picker__separator {\n\theight: 1px;\n\tbackground: var(--notectl-border);\n\tmargin: 4px 8px;\n}\n`;\n","/** Locale interface and default English locale for the FontPlugin. */\n\n// --- Locale Interface ---\n\nexport interface FontLocale {\n\treadonly label: string;\n\treadonly tooltip: string;\n}\n\n// --- Default English Locale ---\n\nexport const FONT_LOCALE_EN: FontLocale = {\n\tlabel: 'Font',\n\ttooltip: 'Font Family',\n};\n\n// --- Lazy Locale Loader ---\n\nconst localeModules: Record<string, () => Promise<{ default: FontLocale }>> = import.meta.glob<{\n\tdefault: FontLocale;\n}>('./locales/*.ts', { eager: false });\n\nexport async function loadFontLocale(lang: string): Promise<FontLocale> {\n\tif (lang === 'en') return FONT_LOCALE_EN;\n\tconst loader = localeModules[`./locales/${lang}.ts`];\n\tif (!loader) return FONT_LOCALE_EN;\n\ttry {\n\t\tconst mod = await loader();\n\t\treturn mod.default;\n\t} catch {\n\t\treturn FONT_LOCALE_EN;\n\t}\n}\n","/**\n * FontPlugin: registers a font-family mark, a combobox-style toolbar selector\n * for font selection, and a developer-friendly API for registering custom fonts\n * (WOFF2, TTF, OTF).\n */\n\nimport {\n\tapplyAttributedMark,\n\tgetMarkAttrAtSelection,\n\tisAttributedMarkActive,\n\tremoveAttributedMark,\n} from '../../commands/AttributedMarkCommands.js';\nimport { FONT_SELECT_CSS } from '../../editor/styles/font-select.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { HTMLExportContext } from '../../model/NodeSpec.js';\nimport { markType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport { getStyleNonceForNode, setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { isValidCSSFontFamily } from '../shared/ColorValidation.js';\nimport { resolveLocale } from '../shared/PluginHelpers.js';\nimport type { PopupCloseOptions } from '../shared/PopupManager.js';\nimport { FONT_LOCALE_EN, type FontLocale, loadFontLocale } from './FontLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\tfont: { family: string };\n\t}\n}\n\n// --- Public Types ---\n\n/** Describes a single @font-face source. */\nexport interface FontFaceDescriptor {\n\t/** CSS `src` value, e.g. `\"url('/fonts/My.woff2') format('woff2')\"`. */\n\treadonly src: string;\n\t/** Font weight, e.g. `'400'` or `'300 700'` for variable fonts. */\n\treadonly weight?: string;\n\t/** Font style, e.g. `'normal'` or `'italic'`. */\n\treadonly style?: string;\n\t/** Font display strategy. Defaults to `'swap'`. */\n\treadonly display?: string;\n}\n\n/** Defines a font available in the editor. */\nexport interface FontDefinition {\n\t/** Display name shown in the toolbar dropdown. */\n\treadonly name: string;\n\t/** CSS `font-family` value, e.g. `\"'Fira Code', monospace\"`. */\n\treadonly family: string;\n\t/** Font category for grouping in the UI. */\n\treadonly category?: 'serif' | 'sans-serif' | 'monospace' | 'display' | 'handwriting';\n\t/**\n\t * Optional `@font-face` descriptors. When provided, the plugin\n\t * auto-injects the corresponding CSS rules into the document.\n\t */\n\treadonly fontFaces?: readonly FontFaceDescriptor[];\n}\n\n// --- Configuration ---\n\nexport interface FontConfig {\n\t/**\n\t * Fonts available in the editor. System fonts require no `fontFaces`.\n\t * Custom fonts with `fontFaces` get their `@font-face` rules auto-injected.\n\t *\n\t * Use `STARTER_FONTS` for a pre-configured set of fonts:\n\t * ```ts\n\t * new FontPlugin({ fonts: [...STARTER_FONTS] })\n\t * ```\n\t */\n\treadonly fonts: readonly FontDefinition[];\n\t/**\n\t * Name of the font that acts as the editor's default.\n\t * Selecting this font removes the mark (since the editor already uses it).\n\t * Defaults to the first font in the list.\n\t */\n\treadonly defaultFont?: string;\n\treadonly locale?: FontLocale;\n}\n\n// --- Plugin ---\n\nexport class FontPlugin implements Plugin {\n\treadonly id = 'font';\n\treadonly name = 'Font';\n\treadonly priority = 22;\n\n\tprivate readonly config: FontConfig;\n\tprivate locale!: FontLocale;\n\tprivate injectedStyleElement: HTMLStyleElement | null = null;\n\tprivate context: PluginContext | null = null;\n\n\tconstructor(config: FontConfig) {\n\t\tthis.config = config;\n\t}\n\n\tasync init(context: PluginContext): Promise<void> {\n\t\tthis.locale = await resolveLocale(context, this.config.locale, FONT_LOCALE_EN, loadFontLocale);\n\n\t\tcontext.registerStyleSheet(FONT_SELECT_CSS);\n\t\tthis.context = context;\n\t\tthis.registerMarkSpec(context);\n\t\tthis.registerCommands(context);\n\t\tif (this.config.fonts.length > 0) {\n\t\t\tthis.registerToolbarItem(context);\n\t\t}\n\t\tthis.injectFontFaces();\n\t}\n\n\tdestroy(): void {\n\t\tthis.injectedStyleElement?.remove();\n\t\tthis.injectedStyleElement = null;\n\t\tthis.context = null;\n\t}\n\n\t// --- Schema ---\n\n\tprivate registerMarkSpec(context: PluginContext): void {\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: 'font',\n\t\t\trank: 6,\n\t\t\tattrs: {\n\t\t\t\tfamily: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(mark) {\n\t\t\t\tconst span: HTMLElement = document.createElement('span');\n\t\t\t\tconst family: string = mark.attrs?.family ?? '';\n\t\t\t\tif (family) {\n\t\t\t\t\tsetStyleProperty(span, 'fontFamily', family);\n\t\t\t\t}\n\t\t\t\treturn span;\n\t\t\t},\n\t\t\ttoHTMLString: (mark, content, ctx?: HTMLExportContext) => {\n\t\t\t\tconst family: string = String(mark.attrs?.family ?? '');\n\t\t\t\tif (!family || !isValidCSSFontFamily(family)) return content;\n\t\t\t\tconst decl: string = `font-family: ${escapeHTML(family)}`;\n\t\t\t\tconst attr: string = ctx?.styleAttr(decl) ?? ` style=\"${decl}\"`;\n\t\t\t\treturn `<span${attr}>${content}</span>`;\n\t\t\t},\n\t\t\ttoHTMLStyle: (mark) => {\n\t\t\t\tconst family: string = String(mark.attrs?.family ?? '');\n\t\t\t\tif (!family || !isValidCSSFontFamily(family)) return null;\n\t\t\t\treturn `font-family: ${escapeHTML(family)}`;\n\t\t\t},\n\t\t\tparseHTML: [\n\t\t\t\t{\n\t\t\t\t\ttag: 'span',\n\t\t\t\t\tgetAttrs: (el) => {\n\t\t\t\t\t\tconst family: string = el.style.fontFamily;\n\t\t\t\t\t\tif (!family) return false;\n\t\t\t\t\t\t// Browsers normalize CSS quotes to double-quotes;\n\t\t\t\t\t\t// our internal convention uses single-quotes.\n\t\t\t\t\t\tconst normalized: string = family.replace(/\"/g, \"'\");\n\t\t\t\t\t\treturn { family: normalized };\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tsanitize: { tags: ['span'] },\n\t\t});\n\t}\n\n\t// --- Commands ---\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('removeFont', () => {\n\t\t\tconst state: EditorState = context.getState();\n\t\t\treturn this.removeFont(context, state);\n\t\t});\n\n\t\tcontext.registerCommand('setFont', () => {\n\t\t\treturn false;\n\t\t});\n\t}\n\n\t// --- Toolbar ---\n\n\tprivate get defaultFont(): FontDefinition | undefined {\n\t\tif (this.config.defaultFont) {\n\t\t\tconst found: FontDefinition | undefined = this.config.fonts.find(\n\t\t\t\t(f) => f.name === this.config.defaultFont,\n\t\t\t);\n\t\t\tif (found) return found;\n\t\t}\n\t\treturn this.config.fonts[0];\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'font',\n\t\t\tgroup: 'format',\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip,\n\t\t\tcommand: 'removeFont',\n\t\t\tpopupType: 'combobox',\n\t\t\tgetLabel: (state: EditorState): string => this.resolveFontName(this.getActiveFont(state)),\n\t\t\trenderPopup: (container, ctx, onClose) => {\n\t\t\t\tthis.renderFontPopup(container, ctx, onClose);\n\t\t\t},\n\t\t\tisActive: (state) => this.isFontActive(state),\n\t\t});\n\t}\n\n\tprivate resolveFontName(family: string | null): string {\n\t\tif (!family) return this.defaultFont?.name ?? this.locale.label;\n\t\tconst match: FontDefinition | undefined = this.config.fonts.find((f) => f.family === family);\n\t\treturn match?.name ?? (family.split(',')[0] ?? '').trim().replace(/['\"]/g, '');\n\t}\n\n\t// --- State Queries ---\n\n\tprivate isFontActive(state: EditorState): boolean {\n\t\treturn isAttributedMarkActive(state, 'font');\n\t}\n\n\tgetActiveFont(state: EditorState): string | null {\n\t\treturn getMarkAttrAtSelection(state, 'font', (m) => m.attrs.family ?? null);\n\t}\n\n\t// --- Font Application ---\n\n\tapplyFont(context: PluginContext, state: EditorState, family: string): boolean {\n\t\tconst mark = { type: markType('font'), attrs: { family } };\n\t\tconst tr = applyAttributedMark(state, mark);\n\t\tif (!tr) return false;\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\tprivate removeFont(context: PluginContext, state: EditorState): boolean {\n\t\tconst tr = removeAttributedMark(state, markType('font'));\n\t\tif (!tr) return false;\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\t// --- @font-face Injection ---\n\n\tprivate injectFontFaces(): void {\n\t\tconst rules: string[] = [];\n\n\t\tfor (const font of this.config.fonts) {\n\t\t\tif (!font.fontFaces?.length) continue;\n\n\t\t\tfor (const face of font.fontFaces) {\n\t\t\t\tconst familyName: string = (font.family.split(',')[0] ?? '').trim().replace(/['\"]/g, '');\n\t\t\t\tconst declarations: string[] = [`font-family: '${familyName}'`, `src: ${face.src}`];\n\t\t\t\tif (face.weight) {\n\t\t\t\t\tdeclarations.push(`font-weight: ${face.weight}`);\n\t\t\t\t}\n\t\t\t\tif (face.style) {\n\t\t\t\t\tdeclarations.push(`font-style: ${face.style}`);\n\t\t\t\t}\n\t\t\t\tdeclarations.push(`font-display: ${face.display ?? 'swap'}`);\n\n\t\t\t\trules.push(`@font-face {\\n\\t${declarations.join(';\\n\\t')};\\n}`);\n\t\t\t}\n\t\t}\n\n\t\tif (rules.length === 0) return;\n\n\t\tconst style: HTMLStyleElement = document.createElement('style');\n\t\tstyle.setAttribute('data-notectl-fonts', '');\n\t\tconst nonce = this.context ? getStyleNonceForNode(this.context.getContainer()) : undefined;\n\t\tif (nonce) {\n\t\t\tstyle.setAttribute('nonce', nonce);\n\t\t}\n\t\tstyle.textContent = rules.join('\\n\\n');\n\t\tdocument.head.appendChild(style);\n\t\tthis.injectedStyleElement = style;\n\t}\n\n\t// --- Popup Rendering ---\n\n\tprivate renderFontPopup(\n\t\tcontainer: HTMLElement,\n\t\tcontext: PluginContext,\n\t\tonClose: (options?: PopupCloseOptions) => void,\n\t): void {\n\t\tcontainer.classList.add('notectl-font-picker');\n\n\t\tconst state: EditorState = context.getState();\n\t\tconst activeFont: string | null = this.getActiveFont(state);\n\t\tconst defaultFamily: string | undefined = this.defaultFont?.family;\n\t\tconst contentElement: HTMLElement = context.getContainer();\n\n\t\tconst list: HTMLDivElement = document.createElement('div');\n\t\tlist.className = 'notectl-font-picker__list';\n\t\tlist.setAttribute('role', 'listbox');\n\t\tlist.setAttribute('aria-label', this.locale.label);\n\n\t\tfor (const font of this.config.fonts) {\n\t\t\tconst isDefault: boolean = defaultFamily !== undefined && font.family === defaultFamily;\n\t\t\tconst isActive: boolean = isDefault\n\t\t\t\t? !activeFont || activeFont === font.family\n\t\t\t\t: activeFont === font.family;\n\n\t\t\tconst item: HTMLButtonElement = this.createFontItem(\n\t\t\t\tfont.name,\n\t\t\t\tfont.family,\n\t\t\t\tisActive,\n\t\t\t\t(e: MouseEvent) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\te.stopPropagation();\n\t\t\t\t\tif (isDefault) {\n\t\t\t\t\t\tcontext.executeCommand('removeFont');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.applyFont(context, context.getState(), font.family);\n\t\t\t\t\t}\n\t\t\t\t\tonClose({ restoreFocusTo: contentElement });\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (font.category) {\n\t\t\t\titem.setAttribute('data-category', font.category);\n\t\t\t}\n\n\t\t\tlist.appendChild(item);\n\t\t}\n\n\t\tcontainer.appendChild(list);\n\t}\n\n\tprivate createFontItem(\n\t\tname: string,\n\t\tfamily: string,\n\t\tisActive: boolean,\n\t\thandler: (e: MouseEvent) => void,\n\t): HTMLButtonElement {\n\t\tconst item: HTMLButtonElement = document.createElement('button');\n\t\titem.type = 'button';\n\t\titem.className = 'notectl-font-picker__item';\n\t\titem.setAttribute('role', 'option');\n\t\titem.setAttribute('aria-selected', String(isActive));\n\n\t\tif (isActive) {\n\t\t\titem.classList.add('notectl-font-picker__item--active');\n\t\t}\n\n\t\t// Checkmark indicator\n\t\tconst check: HTMLSpanElement = document.createElement('span');\n\t\tcheck.className = 'notectl-font-picker__check';\n\t\tcheck.textContent = isActive ? '\\u2713' : '';\n\t\titem.appendChild(check);\n\n\t\t// Font name label (rendered in the font itself for preview)\n\t\tconst label: HTMLSpanElement = document.createElement('span');\n\t\tlabel.className = 'notectl-font-picker__label';\n\t\tlabel.textContent = name;\n\t\tif (family) {\n\t\t\tsetStyleProperty(label, 'fontFamily', family);\n\t\t}\n\t\titem.appendChild(label);\n\n\t\titem.addEventListener('mousedown', handler);\n\t\treturn item;\n\t}\n}\n"],"mappings":"qUACA,ICUa,EAA6B,CACzC,MAAO,OACP,QAAS,eAKJ,iBAAwE,OAAA,OAAA,CAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,qBAAA,kBAAA,IAAA,OAAA,uBAI9E,eAAsB,EAAe,GACpC,GAAa,OAAT,EAAe,OAAO,EAC1B,MAAM,EAAS,EAAc,aAAa,QAC1C,IAAK,EAAQ,OAAO,EACpB,IAEC,aADkB,KACP,cAEX,OAAO,GCuDT,IAAa,EAAb,MACC,GAAc,OACd,KAAg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