@notectl/core 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/chunks/{CodeBlockPlugin-Uv6EXaH1.mjs → CodeBlockPlugin-CcB0WaIz.mjs} +2 -2
  2. package/dist/chunks/{CodeBlockPlugin-Uv6EXaH1.mjs.map → CodeBlockPlugin-CcB0WaIz.mjs.map} +1 -1
  3. package/dist/chunks/{Commands-CyT1Li7_.mjs → Commands-BIIpx_Zd.mjs} +2 -2
  4. package/dist/chunks/Commands-BIIpx_Zd.mjs.map +1 -0
  5. package/dist/chunks/{FormulaPlugin-UA-9tRpY.mjs → FormulaPlugin-66Cc9sH2.mjs} +2 -2
  6. package/dist/chunks/{FormulaPlugin-UA-9tRpY.mjs.map → FormulaPlugin-66Cc9sH2.mjs.map} +1 -1
  7. package/dist/chunks/{HardBreakPlugin-BkgoJkjC.mjs → HardBreakPlugin-9DOyCyyM.mjs} +2 -2
  8. package/dist/chunks/{HardBreakPlugin-BkgoJkjC.mjs.map → HardBreakPlugin-9DOyCyyM.mjs.map} +1 -1
  9. package/dist/chunks/{InlineCodePlugin-D3QulApr.mjs → InlineCodePlugin-Cj1EZ3x2.mjs} +2 -2
  10. package/dist/chunks/{InlineCodePlugin-D3QulApr.mjs.map → InlineCodePlugin-Cj1EZ3x2.mjs.map} +1 -1
  11. package/dist/chunks/{SimpleMark-Db8ir_z2.mjs → SimpleMark-Bdqjcz0G.mjs} +2 -2
  12. package/dist/chunks/{SimpleMark-Db8ir_z2.mjs.map → SimpleMark-Bdqjcz0G.mjs.map} +1 -1
  13. package/dist/chunks/{SmartPastePlugin-Db1RcNJf.mjs → SmartPastePlugin-BhkoH03E.mjs} +2 -2
  14. package/dist/chunks/{SmartPastePlugin-Db1RcNJf.mjs.map → SmartPastePlugin-BhkoH03E.mjs.map} +1 -1
  15. package/dist/chunks/{StrikethroughPlugin-Bsg7Ma4I.mjs → StrikethroughPlugin-DRuwEZhu.mjs} +2 -2
  16. package/dist/chunks/{StrikethroughPlugin-Bsg7Ma4I.mjs.map → StrikethroughPlugin-DRuwEZhu.mjs.map} +1 -1
  17. package/dist/chunks/{SuperSubPlugin-ChEga-b_.mjs → SuperSubPlugin-IZ_x8GS-.mjs} +2 -2
  18. package/dist/chunks/{SuperSubPlugin-ChEga-b_.mjs.map → SuperSubPlugin-IZ_x8GS-.mjs.map} +1 -1
  19. package/dist/chunks/{TextFormattingPlugin-Db5SCNOF.mjs → TextFormattingPlugin-CpyZgtLi.mjs} +2 -2
  20. package/dist/chunks/{TextFormattingPlugin-Db5SCNOF.mjs.map → TextFormattingPlugin-CpyZgtLi.mjs.map} +1 -1
  21. package/dist/chunks/{full--GEBZ2xU.mjs → full-CHkwduuY.mjs} +2 -2
  22. package/dist/chunks/{full--GEBZ2xU.mjs.map → full-CHkwduuY.mjs.map} +1 -1
  23. package/dist/chunks/{src-C5Lblp2i.mjs → src-gVRDR_79.mjs} +2 -2
  24. package/dist/chunks/{src-C5Lblp2i.mjs.map → src-gVRDR_79.mjs.map} +1 -1
  25. package/dist/commands/Commands.d.ts.map +1 -1
  26. package/dist/full.mjs +1 -1
  27. package/dist/notectl-core.mjs +1 -1
  28. package/dist/notectl-core.umd.js +1 -1
  29. package/dist/notectl-core.umd.js.map +1 -1
  30. package/dist/plugins/code-block.mjs +1 -1
  31. package/dist/plugins/formula.mjs +1 -1
  32. package/dist/plugins/hard-break.mjs +1 -1
  33. package/dist/plugins/inline-code.mjs +1 -1
  34. package/dist/plugins/smart-paste.mjs +1 -1
  35. package/dist/plugins/strikethrough.mjs +1 -1
  36. package/dist/plugins/super-sub.mjs +1 -1
  37. package/dist/plugins/text-formatting.mjs +1 -1
  38. package/dist/presets/full.mjs +1 -1
  39. package/dist/presets.mjs +1 -1
  40. package/package.json +415 -423
  41. package/dist/chunks/Commands-CyT1Li7_.mjs.map +0 -1
@@ -1,2 +1,2 @@
1
- import{T as t,_ as n,b as e,g as o,h as r,m as c,n as s,o as i,p as l,s as u,u as f,v as a,w as d}from"./Document-r7vLOAGA.mjs";import{i as k,n as m,r as b,t as g}from"./WordBoundary-DxeMBRyP.mjs";import{a as p,c as I,d as h,l as S,o as B,r as x,t as T,u as O}from"./Selection-HYoVFpAx.mjs";import{i as N,r as y}from"./TypeBrands-Ch9856Gb.mjs";import{r as A}from"./NodeResolver-ChgLF_IP.mjs";import{T as M,b as j,w as v,x as w}from"./BlockInsertion-6rR9tIGP.mjs";import{i as _,n as C,o as P,r as R}from"./NavigationQueries-Bt4zZ17v.mjs";import{a as D,o as Q}from"./AttributedMarkCommands-D4W2Jgpj.mjs";import{n as W,r as q,t as z}from"./NodeSelectionCommands-Dj4VxLdD.mjs";import{n as E}from"./RangeIterator-o8v3msQe.mjs";function F(){return{nodeTypes:["paragraph"],markTypes:["bold","italic","underline"],getNodeSpec:()=>{}}}function G(t){return{nodeTypes:t.getNodeTypes(),markTypes:t.getMarkTypes(),getNodeSpec:n=>t.getNodeSpec(n),getInlineNodeSpec:n=>t.getInlineNodeSpec(n),getMarkSpec:n=>t.getMarkSpec(n)}}function H(t,n){return t.markTypes.includes(n)}function J(t,n){return t.nodeTypes.includes(n)}function K(t,n){if("after"===n.side)return U(t,n);const e=t.getBlockOrder(),o=e.indexOf(n.blockId);if(o<=0)return null;const r=e[o-1];if(!r)return null;if(_(t,r)){const n=A(t.doc,r)??[];return t.transaction("input").setSelection(x(r,n)).build()}const c=t.getBlock(r);if(!c)return null;const s=l(c);return t.transaction("input").setSelection(T(r,s)).build()}function L(t,n){if("before"===n.side)return U(t,n);const e=t.getBlockOrder(),o=e.indexOf(n.blockId);if(o>=e.length-1)return null;const r=e[o+1];if(!r)return null;if(_(t,r)){const n=A(t.doc,r)??[];return t.transaction("input").setSelection(x(r,n)).build()}return t.transaction("input").setSelection(T(r,0)).build()}function U(t,n){const e=A(t.doc,n.blockId)??[];return z(t,x(n.blockId,e))}function V(t,n){const e=A(t.doc,n);if(!e||0===e.length)return-1;const o=e[0];return t.doc.children.findIndex(t=>t.id===o)}var X={bold:!0,italic:!0,underline:!0};function Y(t,n,o=X){if(function(t,n){const e=t;return"bold"===e?!n.bold:"italic"===e?!n.italic:"underline"===e&&!n.underline}(n,o))return null;if(!H(t.schema,n))return null;if(!O(t.selection))return null;const r={type:n},c=t.selection;if(B(c)){if(!t.getBlock(c.anchor.blockId))return null;const o=Q(t),s=e(o,n)?o.filter(t=>t.type!==n):[...o,r];return t.transaction("command").setStoredMarks(s,t.storedMarks).setSelection(c).build()}const s=h(c,t.getBlockOrder()),i=t.transaction("command"),l=et(t,n);return E(t,s,(t,n,e)=>{l?i.removeMark(t,n,e,r):i.addMark(t,n,e,r)}),i.setSelection(c),i.build()}function Z(t,n){return Y(t,N("bold"),n)}function $(t,n){return Y(t,N("italic"),n)}function tt(t,n){return Y(t,N("underline"),n)}function nt(t,n){const o=t.selection;return!!O(o)&&(B(o)?e(Q(t),n):et(t,n))}function et(t,n){const e=t.selection;if(!O(e))return!1;const o=t.getBlockOrder(),r=h(e,o),c=o.indexOf(r.from.blockId),s=o.indexOf(r.to.blockId);let i=!1;for(let u=c;u<=s;u++){const e=o[u];if(!e)continue;const f=t.getBlock(e);if(!f)continue;const a=l(f),d=ot(f,u===c?r.from.offset:0,u===s?r.to.offset:a,n);if("missing"===d)return!1;"present"===d&&(i=!0)}return i}function ot(n,o,r,c){let s=0,i=!1;for(const l of a(n))if(t(l)){const t=s+l.text.length;if(t>o&&s<r&&(i=!0,!e(l.marks,c)))return"missing";s=t}else s+=1;return i?"present":"empty"}function rt(t,n){const e=t.selection;if(S(e))return z(t,e);if(I(e))return null;if(!B(e))return dt(t);const o=t.getBlock(e.anchor.blockId);if(!o)return null;const r=n.range(o,e.anchor.offset);if(!r)return n.merge(t);const[c,s]=r;return t.transaction("input").deleteTextAt(o.id,c,s).setSelection(T(o.id,c)).build()}function ct(t){return rt(t,{merge:bt,range:(t,n)=>n<=0?null:"inline"===o(t,n-1)?.kind?[n-1,n]:[n-(k(r(t),s(t,n))||1),n]})}function st(t){return rt(t,{merge:gt,range:(t,n)=>n>=l(t)?null:"inline"===o(t,n)?.kind?[n,n+1]:[n,n+(b(r(t),s(t,n))||1)]})}function it(t){return rt(t,{merge:bt,range:(t,n)=>n>0?[g(t,n),n]:null})}function lt(t){return rt(t,{merge:gt,range:(t,n)=>n<l(t)?[n,m(t,n)]:null})}function ut(t){return rt(t,{merge:bt,range:(t,n)=>n>0?[0,n]:null})}function ft(t){return rt(t,{merge:gt,range:(t,n)=>{const e=l(t);return n<e?[n,e]:null}})}function at(t,e,o="input"){const r=t.selection;if(S(r))return q(t,r,e,o);if(I(r))return function(t,n,e,o){const{parentPath:r,siblings:c,index:s}=M(t,n.blockId),l="before"===n.side?Math.max(s,0):s>=0?s+1:c.length,u=f(),a=t.transaction(o);return a.insertNode(r,l,i(u)),a.insertText(u,0,e,[]),a.setSelection(T(u,e.length)),a.build()}(t,r,e,o);const s=t.transaction(o),l=function(t){if(t.storedMarks)return t.storedMarks;const e=t.selection;if(!O(e))return[];const o=t.getBlock(e.anchor.blockId);return o?B(e)?n(o,e.anchor.offset,n=>D(t.schema,n)):c(o,e.anchor.offset):[]}(t);let u;B(r)||(u=ht(t,s));const a=v(r,t.getBlockOrder()),d=u??a.blockId,k=u?0:a.offset;return s.insertText(d,k,e,l),s.setSelection(T(d,k+e.length)),s.build()}function dt(t){if(S(t.selection))return z(t,t.selection);if(I(t.selection))return null;if(B(t.selection))return null;const n=t.transaction("input"),e=ht(t,n),o=h(t.selection,t.getBlockOrder()),r=e??o.from.blockId,c=e?0:o.from.offset;return n.setSelection(T(r,c)),n.build()}function kt(t){const n=t.selection;if(S(n))return W(t,n);if(I(n))return function(t,n){const{parentPath:e,index:o}=M(t,n.blockId);if(o<0)return null;const r="before"===n.side?o:o+1,c=f(),s=t.transaction("input");return s.insertNode(e,r,i(c)),s.setSelection(T(c,0)),s.build()}(t,n);const e=t.transaction("input");let o;B(n)||(o=ht(t,e));const r=v(n,t.getBlockOrder()),c=o??r.blockId,s=o?0:r.offset,l=f();return e.splitBlock(c,s,l),e.setSelection(T(l,0)),e.build()}function mt(t){const n=t.selection;if(!O(n))return null;const e=t.transaction("input");let o;if(B(n)||(o=ht(t,e)),o)e.insertInlineNode(o,0,u(y("hard_break"))),e.setSelection(T(o,1));else{const{blockId:o,offset:r}=v(n,t.getBlockOrder());e.insertInlineNode(o,r,u(y("hard_break"))),e.setSelection(T(o,r+1))}return e.build()}function bt(t){return pt(t,"backward")}function gt(t){return pt(t,"forward")}function pt(t,n){const e=t.selection;if(!O(e))return null;const o=t.getBlockOrder(),r=o.indexOf(e.anchor.blockId),c="backward"===n?r-1:r+1;if(c<0||c>=o.length)return null;const s=o[c];if(!s)return null;if(R(t,e.anchor.blockId)||R(t,s))return null;if(!P(t,e.anchor.blockId,s)&&C(t,e.anchor.blockId))return null;if(_(t,s)){const n=A(t.doc,s)??[];return t.transaction("input").setSelection(x(s,n)).build()}if("backward"===n){const n=t.getBlock(s);if(!n)return null;const o=l(n);return t.transaction("input").mergeBlocksAt(s,e.anchor.blockId).setSelection(T(s,o)).build()}return t.transaction("input").mergeBlocksAt(e.anchor.blockId,s).setSelection(T(e.anchor.blockId,e.anchor.offset)).build()}function It(t){const n=t.doc.children,e=n[0],o=n[n.length-1];if(!e||!o)return t.transaction("command").setSelection(t.selection).build();const r=j(e),c=w(o),s=t.getBlock(c),i=s?l(s):0;return t.transaction("command").setSelection(p({blockId:r,offset:0},{blockId:c,offset:i})).build()}function ht(t,n){if(!O(t.selection))return;const e=t.getBlockOrder(),o=h(t.selection,e),r=e.indexOf(o.from.blockId),c=e.indexOf(o.to.blockId);if(r===c)return void n.deleteTextAt(o.from.blockId,o.from.offset,o.to.offset);const s=V(t,o.from.blockId),u=V(t,o.to.blockId);if(!(s===u||s<0||u<0))return function(t,n,e,o,r){const c=t.doc.children[o],s=t.doc.children[r];if(!c||!s)return;const u=d(c),a=d(s);let k,m=0;if(u||(k=f(),n.insertNode([],o,i(k)),m=1),u){const o=t.getBlock(e.from.blockId);if(o){const t=l(o);e.from.offset<t&&n.deleteTextAt(e.from.blockId,e.from.offset,t)}}a&&e.to.offset>0&&n.deleteTextAt(e.to.blockId,0,e.to.offset);const b=u?o+1:o+m;for(let i=a?r-1+m:r+m;i>=b;i--)n.removeNode([],i);return u&&a&&n.mergeBlocksAt(e.from.blockId,e.to.blockId),k}(t,n,o,s,u);!function(t,n,e,o,r,c){const s=t.getBlock(o.from.blockId);if(!s)return;const i=l(s);o.from.offset<i&&n.deleteTextAt(o.from.blockId,o.from.offset,i),o.to.offset>0&&n.deleteTextAt(o.to.blockId,0,o.to.offset);for(let u=r+1;u<c;u++){const r=e[u];if(!r)continue;const c=t.getBlock(r);if(!c)continue;const s=l(c);s>0&&n.deleteTextAt(r,0,s),n.mergeBlocksAt(o.from.blockId,r)}n.mergeBlocksAt(o.from.blockId,o.to.blockId)}(t,n,e,o,r,c)}export{J as C,H as S,Y as _,bt as a,L as b,ct as c,ft as d,it as f,$ as g,Z as h,at as i,st as l,nt as m,dt as n,It as o,lt as p,mt as r,kt as s,ht as t,ut as u,tt as v,G as w,F as x,K as y};
2
- //# sourceMappingURL=Commands-CyT1Li7_.mjs.map
1
+ import{T as t,_ as n,b as e,g as o,h as r,m as c,n as s,o as i,p as l,s as u,u as f,v as a,w as d}from"./Document-r7vLOAGA.mjs";import{i as m,n as k,r as b,t as g}from"./WordBoundary-DxeMBRyP.mjs";import{a as p,c as I,d as h,l as S,o as B,r as x,t as T,u as O}from"./Selection-HYoVFpAx.mjs";import{i as N,r as y}from"./TypeBrands-Ch9856Gb.mjs";import{r as A}from"./NodeResolver-ChgLF_IP.mjs";import{T as M,b as j,w as v,x as w}from"./BlockInsertion-6rR9tIGP.mjs";import{i as _,n as C,o as P,r as R}from"./NavigationQueries-Bt4zZ17v.mjs";import{a as D,o as Q}from"./AttributedMarkCommands-D4W2Jgpj.mjs";import{n as W,r as q,t as z}from"./NodeSelectionCommands-Dj4VxLdD.mjs";import{n as E}from"./RangeIterator-o8v3msQe.mjs";function F(){return{nodeTypes:["paragraph"],markTypes:["bold","italic","underline"],getNodeSpec:()=>{}}}function G(t){return{nodeTypes:t.getNodeTypes(),markTypes:t.getMarkTypes(),getNodeSpec:n=>t.getNodeSpec(n),getInlineNodeSpec:n=>t.getInlineNodeSpec(n),getMarkSpec:n=>t.getMarkSpec(n)}}function H(t,n){return t.markTypes.includes(n)}function J(t,n){return t.nodeTypes.includes(n)}function K(t,n){if("after"===n.side)return U(t,n);const e=t.getBlockOrder(),o=e.indexOf(n.blockId);if(o<=0)return null;const r=e[o-1];if(!r)return null;if(_(t,r)){const n=A(t.doc,r)??[];return t.transaction("input").setSelection(x(r,n)).build()}const c=t.getBlock(r);if(!c)return null;const s=l(c);return t.transaction("input").setSelection(T(r,s)).build()}function L(t,n){if("before"===n.side)return U(t,n);const e=t.getBlockOrder(),o=e.indexOf(n.blockId);if(o>=e.length-1)return null;const r=e[o+1];if(!r)return null;if(_(t,r)){const n=A(t.doc,r)??[];return t.transaction("input").setSelection(x(r,n)).build()}return t.transaction("input").setSelection(T(r,0)).build()}function U(t,n){const e=A(t.doc,n.blockId)??[];return z(t,x(n.blockId,e))}function V(t,n){const e=A(t.doc,n);if(!e||0===e.length)return-1;const o=e[0];return t.doc.children.findIndex(t=>t.id===o)}var X={bold:!0,italic:!0,underline:!0};function Y(t,n,o=X){if(function(t,n){const e=t;return"bold"===e?!n.bold:"italic"===e?!n.italic:"underline"===e&&!n.underline}(n,o))return null;if(!H(t.schema,n))return null;if(!O(t.selection))return null;const r={type:n},c=t.selection;if(B(c)){if(!t.getBlock(c.anchor.blockId))return null;const o=Q(t),s=e(o,n)?o.filter(t=>t.type!==n):[...o,r];return t.transaction("command").setStoredMarks(s,t.storedMarks).setSelection(c).build()}const s=h(c,t.getBlockOrder()),i=t.transaction("command"),l=et(t,n);return E(t,s,(t,n,e)=>{l?i.removeMark(t,n,e,r):i.addMark(t,n,e,r)}),i.setSelection(c),i.build()}function Z(t,n){return Y(t,N("bold"),n)}function $(t,n){return Y(t,N("italic"),n)}function tt(t,n){return Y(t,N("underline"),n)}function nt(t,n){const o=t.selection;return!!O(o)&&(B(o)?e(Q(t),n):et(t,n))}function et(t,n){const e=t.selection;if(!O(e))return!1;const o=t.getBlockOrder(),r=h(e,o),c=o.indexOf(r.from.blockId),s=o.indexOf(r.to.blockId);let i=!1;for(let u=c;u<=s;u++){const e=o[u];if(!e)continue;const f=t.getBlock(e);if(!f)continue;const a=l(f),d=ot(f,u===c?r.from.offset:0,u===s?r.to.offset:a,n);if("missing"===d)return!1;"present"===d&&(i=!0)}return i}function ot(n,o,r,c){let s=0,i=!1;for(const l of a(n))if(t(l)){const t=s+l.text.length;if(t>o&&s<r&&(i=!0,!e(l.marks,c)))return"missing";s=t}else s+=1;return i?"present":"empty"}function rt(t,n){const e=t.selection;if(S(e))return z(t,e);if(I(e))return null;if(!B(e))return dt(t);const o=t.getBlock(e.anchor.blockId);if(!o)return null;const r=n.range(o,e.anchor.offset);if(!r)return n.merge(t);const[c,s]=r;return t.transaction("input").deleteTextAt(o.id,c,s).setSelection(T(o.id,c)).build()}function ct(t){return rt(t,{merge:bt,range:(t,n)=>n<=0?null:"inline"===o(t,n-1)?.kind?[n-1,n]:[n-(m(r(t),s(t,n))||1),n]})}function st(t){return rt(t,{merge:gt,range:(t,n)=>n>=l(t)?null:"inline"===o(t,n)?.kind?[n,n+1]:[n,n+(b(r(t),s(t,n))||1)]})}function it(t){return rt(t,{merge:bt,range:(t,n)=>n>0?[g(t,n),n]:null})}function lt(t){return rt(t,{merge:gt,range:(t,n)=>n<l(t)?[n,k(t,n)]:null})}function ut(t){return rt(t,{merge:bt,range:(t,n)=>n>0?[0,n]:null})}function ft(t){return rt(t,{merge:gt,range:(t,n)=>{const e=l(t);return n<e?[n,e]:null}})}function at(t,e,o="input"){const r=t.selection;if(S(r))return q(t,r,e,o);if(I(r))return function(t,n,e,o){const{parentPath:r,siblings:c,index:s}=M(t,n.blockId),l="before"===n.side?Math.max(s,0):s>=0?s+1:c.length,u=f(),a=t.transaction(o);return a.insertNode(r,l,i(u)),a.insertText(u,0,e,[]),a.setSelection(T(u,e.length)),a.build()}(t,r,e,o);const s=t.transaction(o),l=function(t){if(t.storedMarks)return t.storedMarks;const e=t.selection;if(!O(e))return[];const o=t.getBlock(e.anchor.blockId);return o?B(e)?n(o,e.anchor.offset,n=>D(t.schema,n)):c(o,e.anchor.offset):[]}(t);let u;B(r)||(u=St(t,s));const a=v(r,t.getBlockOrder()),d=u??a.blockId,m=u?0:a.offset;return s.insertText(d,m,e,l),s.setSelection(T(d,m+e.length)),s.build()}function dt(t){if(S(t.selection))return z(t,t.selection);if(I(t.selection))return null;if(B(t.selection))return null;if(function(t){if(!O(t.selection))return!1;const n=ht(t);if(!n)return!1;const e=h(t.selection,t.getBlockOrder());return e.from.blockId===n.from.blockId&&e.from.offset===n.from.offset&&e.to.blockId===n.to.blockId&&e.to.offset===n.to.offset}(t))return function(t){const n=f(),e=t.transaction("input"),o=t.doc.children.length;e.insertNode([],0,i(n));for(let r=o;r>=1;r--)e.removeNode([],r);return e.setSelection(T(n,0)),e.build()}(t);const n=t.transaction("input"),e=St(t,n),o=h(t.selection,t.getBlockOrder()),r=e??o.from.blockId,c=e?0:o.from.offset;return n.setSelection(T(r,c)),n.build()}function mt(t){const n=t.selection;if(S(n))return W(t,n);if(I(n))return function(t,n){const{parentPath:e,index:o}=M(t,n.blockId);if(o<0)return null;const r="before"===n.side?o:o+1,c=f(),s=t.transaction("input");return s.insertNode(e,r,i(c)),s.setSelection(T(c,0)),s.build()}(t,n);const e=t.transaction("input");let o;B(n)||(o=St(t,e));const r=v(n,t.getBlockOrder()),c=o??r.blockId,s=o?0:r.offset,l=f();return e.splitBlock(c,s,l),e.setSelection(T(l,0)),e.build()}function kt(t){const n=t.selection;if(!O(n))return null;const e=t.transaction("input");let o;if(B(n)||(o=St(t,e)),o)e.insertInlineNode(o,0,u(y("hard_break"))),e.setSelection(T(o,1));else{const{blockId:o,offset:r}=v(n,t.getBlockOrder());e.insertInlineNode(o,r,u(y("hard_break"))),e.setSelection(T(o,r+1))}return e.build()}function bt(t){return pt(t,"backward")}function gt(t){return pt(t,"forward")}function pt(t,n){const e=t.selection;if(!O(e))return null;const o=t.getBlockOrder(),r=o.indexOf(e.anchor.blockId),c="backward"===n?r-1:r+1;if(c<0||c>=o.length)return null;const s=o[c];if(!s)return null;if(R(t,e.anchor.blockId)||R(t,s))return null;if(!P(t,e.anchor.blockId,s)&&C(t,e.anchor.blockId))return null;if(_(t,s)){const n=A(t.doc,s)??[];return t.transaction("input").setSelection(x(s,n)).build()}if("backward"===n){const n=t.getBlock(s);if(!n)return null;const o=l(n);return t.transaction("input").mergeBlocksAt(s,e.anchor.blockId).setSelection(T(s,o)).build()}return t.transaction("input").mergeBlocksAt(e.anchor.blockId,s).setSelection(T(e.anchor.blockId,e.anchor.offset)).build()}function It(t){const n=ht(t);return n?t.transaction("command").setSelection(p(n.from,n.to)).build():t.transaction("command").setSelection(t.selection).build()}function ht(t){const n=t.doc.children,e=n[0],o=n[n.length-1];if(!e||!o)return null;const r=j(e),c=w(o),s=t.getBlock(c);return{from:{blockId:r,offset:0},to:{blockId:c,offset:s?l(s):0}}}function St(t,n){if(!O(t.selection))return;const e=t.getBlockOrder(),o=h(t.selection,e),r=e.indexOf(o.from.blockId),c=e.indexOf(o.to.blockId);if(r===c)return void n.deleteTextAt(o.from.blockId,o.from.offset,o.to.offset);const s=V(t,o.from.blockId),u=V(t,o.to.blockId);if(!(s===u||s<0||u<0))return function(t,n,e,o,r){const c=t.doc.children[o],s=t.doc.children[r];if(!c||!s)return;const u=d(c),a=d(s);let m,k=0;if(u||(m=f(),n.insertNode([],o,i(m)),k=1),u){const o=t.getBlock(e.from.blockId);if(o){const t=l(o);e.from.offset<t&&n.deleteTextAt(e.from.blockId,e.from.offset,t)}}a&&e.to.offset>0&&n.deleteTextAt(e.to.blockId,0,e.to.offset);const b=u?o+1:o+k;for(let i=a?r-1+k:r+k;i>=b;i--)n.removeNode([],i);return u&&a&&n.mergeBlocksAt(e.from.blockId,e.to.blockId),m}(t,n,o,s,u);!function(t,n,e,o,r,c){const s=t.getBlock(o.from.blockId);if(!s)return;const i=l(s);o.from.offset<i&&n.deleteTextAt(o.from.blockId,o.from.offset,i),o.to.offset>0&&n.deleteTextAt(o.to.blockId,0,o.to.offset);for(let u=r+1;u<c;u++){const r=e[u];if(!r)continue;const c=t.getBlock(r);if(!c)continue;const s=l(c);s>0&&n.deleteTextAt(r,0,s),n.mergeBlocksAt(o.from.blockId,r)}n.mergeBlocksAt(o.from.blockId,o.to.blockId)}(t,n,e,o,r,c)}export{J as C,H as S,Y as _,bt as a,L as b,ct as c,ft as d,it as f,$ as g,Z as h,at as i,st as l,nt as m,dt as n,It as o,lt as p,kt as r,mt as s,St as t,ut as u,tt as v,G as w,F as x,K as y};
2
+ //# sourceMappingURL=Commands-BIIpx_Zd.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Commands-BIIpx_Zd.mjs","names":[],"sources":["../../src/model/Schema.ts","../../src/commands/GapCursorCommands.ts","../../src/commands/SelectionDeletion.ts","../../src/commands/MarkCommands.ts","../../src/commands/DeleteCommands.ts","../../src/commands/Commands.ts"],"sourcesContent":["/**\n * Schema definition for the Notectl editor.\n * Defines which node types and marks are allowed.\n */\n\nimport type { InlineNodeSpec } from './InlineNodeSpec.js';\nimport type { MarkSpec } from './MarkSpec.js';\nimport type { NodeSpec } from './NodeSpec.js';\nimport type { SchemaRegistry } from './SchemaRegistry.js';\n\nexport interface Schema {\n\treadonly nodeTypes: readonly string[];\n\treadonly markTypes: readonly string[];\n\t/** Looks up the full NodeSpec for a given type. Available when created via schemaFromRegistry. */\n\treadonly getNodeSpec?: (type: string) => NodeSpec | undefined;\n\t/** Looks up the full InlineNodeSpec for a given type. Available via schemaFromRegistry. */\n\treadonly getInlineNodeSpec?: (type: string) => InlineNodeSpec | undefined;\n\t/** Looks up the full MarkSpec for a given type. Available via schemaFromRegistry. */\n\treadonly getMarkSpec?: (type: string) => MarkSpec | undefined;\n}\n\n/** Creates the default schema with paragraph nodes and bold/italic/underline marks. */\nexport function defaultSchema(): Schema {\n\treturn {\n\t\tnodeTypes: ['paragraph'],\n\t\tmarkTypes: ['bold', 'italic', 'underline'],\n\t\tgetNodeSpec: () => undefined,\n\t};\n}\n\n/** Derives a Schema from a SchemaRegistry's registered specs. */\nexport function schemaFromRegistry(registry: SchemaRegistry): Schema {\n\treturn {\n\t\tnodeTypes: registry.getNodeTypes(),\n\t\tmarkTypes: registry.getMarkTypes(),\n\t\tgetNodeSpec: (type: string) => registry.getNodeSpec(type),\n\t\tgetInlineNodeSpec: (type: string) => registry.getInlineNodeSpec(type),\n\t\tgetMarkSpec: (type: string) => registry.getMarkSpec(type),\n\t};\n}\n\n/** Checks whether the given mark type is allowed by the schema. */\nexport function isMarkAllowed(schema: Schema, markType: string): boolean {\n\treturn schema.markTypes.includes(markType);\n}\n\n/** Checks whether the given node type is allowed by the schema. */\nexport function isNodeTypeAllowed(schema: Schema, nodeType: string): boolean {\n\treturn schema.nodeTypes.includes(nodeType);\n}\n","/**\n * Commands for GapCursor: deleting void blocks adjacent to gap cursors\n * and inserting paragraphs at gap positions.\n */\n\nimport { createEmptyParagraph, generateBlockId, getBlockLength } from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport type { GapCursorSelection, NodeSelection } from '../model/Selection.js';\nimport { createCollapsedSelection, createNodeSelection } from '../model/Selection.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport { isVoidBlock } from '../state/NavigationQueries.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { resolveSiblingContext } from './CommandHelpers.js';\nimport { deleteNodeSelection } from './NodeSelectionCommands.js';\n\n/**\n * Deletes the void block adjacent to a GapCursor when pressing Backspace.\n *\n * - `side === 'after'` → void block is behind the cursor → delete it.\n * - `side === 'before'` → void block is ahead → navigate backward (to previous block).\n * - At document start with `side === 'before'` → `null` (no-op).\n */\nexport function deleteBackwardAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n): Transaction | null {\n\tif (sel.side === 'after') {\n\t\treturn deleteVoidAtGap(state, sel);\n\t}\n\n\t// side === 'before': navigate to previous block\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst blockIdx: number = blockOrder.indexOf(sel.blockId);\n\n\tif (blockIdx <= 0) return null;\n\n\tconst prevId: BlockId | undefined = blockOrder[blockIdx - 1];\n\tif (!prevId) return null;\n\n\tif (isVoidBlock(state, prevId)) {\n\t\tconst path = findNodePath(state.doc, prevId) ?? [];\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createNodeSelection(prevId, path as BlockId[]))\n\t\t\t.build();\n\t}\n\n\tconst prevBlock = state.getBlock(prevId);\n\tif (!prevBlock) return null;\n\tconst prevLen: number = getBlockLength(prevBlock);\n\treturn state.transaction('input').setSelection(createCollapsedSelection(prevId, prevLen)).build();\n}\n\n/**\n * Deletes the void block adjacent to a GapCursor when pressing Delete.\n *\n * - `side === 'before'` → void block is ahead of the cursor → delete it.\n * - `side === 'after'` → void block is behind → navigate forward (to next block).\n * - At document end with `side === 'after'` → `null` (no-op).\n */\nexport function deleteForwardAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n): Transaction | null {\n\tif (sel.side === 'before') {\n\t\treturn deleteVoidAtGap(state, sel);\n\t}\n\n\t// side === 'after': navigate to next block\n\tconst blockOrder: readonly BlockId[] = state.getBlockOrder();\n\tconst blockIdx: number = blockOrder.indexOf(sel.blockId);\n\n\tif (blockIdx >= blockOrder.length - 1) return null;\n\n\tconst nextId: BlockId | undefined = blockOrder[blockIdx + 1];\n\tif (!nextId) return null;\n\n\tif (isVoidBlock(state, nextId)) {\n\t\tconst path = findNodePath(state.doc, nextId) ?? [];\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createNodeSelection(nextId, path as BlockId[]))\n\t\t\t.build();\n\t}\n\n\treturn state.transaction('input').setSelection(createCollapsedSelection(nextId, 0)).build();\n}\n\n/** Deletes the void block that the GapCursor is adjacent to, delegating to deleteNodeSelection. */\nfunction deleteVoidAtGap(state: EditorState, sel: GapCursorSelection): Transaction | null {\n\tconst path = (findNodePath(state.doc, sel.blockId) ?? []) as BlockId[];\n\tconst nodeSel: NodeSelection = createNodeSelection(sel.blockId, path);\n\treturn deleteNodeSelection(state, nodeSel);\n}\n\n/** Inserts a new paragraph at a GapCursor position (before or after the void block). */\nexport function insertParagraphAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n): Transaction | null {\n\tconst { parentPath, index } = resolveSiblingContext(state, sel.blockId);\n\tif (index < 0) return null;\n\n\tconst insertIdx: number = sel.side === 'before' ? index : index + 1;\n\tconst newId = generateBlockId();\n\tconst builder = state.transaction('input');\n\tbuilder.insertNode(parentPath, insertIdx, createEmptyParagraph(newId));\n\tbuilder.setSelection(createCollapsedSelection(newId, 0));\n\treturn builder.build();\n}\n\n/** Inserts text in a new paragraph at a GapCursor position. */\nexport function insertTextAtGap(\n\tstate: EditorState,\n\tsel: GapCursorSelection,\n\ttext: string,\n\torigin: 'input' | 'paste',\n): Transaction {\n\tconst { parentPath, siblings, index } = resolveSiblingContext(state, sel.blockId);\n\tconst insertIdx: number =\n\t\tsel.side === 'before' ? Math.max(index, 0) : index >= 0 ? index + 1 : siblings.length;\n\n\tconst newId = generateBlockId();\n\tconst builder = state.transaction(origin);\n\tbuilder.insertNode(parentPath, insertIdx, createEmptyParagraph(newId));\n\tbuilder.insertText(newId, 0, text, []);\n\tbuilder.setSelection(createCollapsedSelection(newId, text.length));\n\treturn builder.build();\n}\n","/**\n * Range-deletion helpers for multi-block text selections, split out of\n * Commands.ts. Handles two cases: a selection whose blocks share one root\n * ancestor (leaf range) and a selection spanning different root ancestors\n * (cross-root range).\n */\n\nimport {\n\tcreateEmptyParagraph,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tisLeafBlock,\n} from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport type { BlockId } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport type { TransactionBuilder } from '../state/Transaction.js';\n\n/** A normalized text-selection range (document-order from/to positions). */\nexport interface DeletionRange {\n\treadonly from: { readonly blockId: BlockId; readonly offset: number };\n\treadonly to: { readonly blockId: BlockId; readonly offset: number };\n}\n\n/** Returns the root-level ancestor index in `doc.children` for a given block. */\nexport function getRootBlockIndex(state: EditorState, blockId: BlockId): number {\n\tconst path = findNodePath(state.doc, blockId);\n\tif (!path || path.length === 0) return -1;\n\tconst rootId: string = path[0] as string;\n\treturn state.doc.children.findIndex((c) => c.id === rootId);\n}\n\n/** Deletes a multi-block selection where all blocks share the same root ancestor. */\nexport function deleteLeafRange(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\tblockOrder: readonly BlockId[],\n\trange: DeletionRange,\n\tfromIdx: number,\n\ttoIdx: number,\n): void {\n\tconst firstBlock = state.getBlock(range.from.blockId);\n\tif (!firstBlock) return;\n\tconst firstLen = getBlockLength(firstBlock);\n\n\tif (range.from.offset < firstLen) {\n\t\tbuilder.deleteTextAt(range.from.blockId, range.from.offset, firstLen);\n\t}\n\n\tif (range.to.offset > 0) {\n\t\tbuilder.deleteTextAt(range.to.blockId, 0, range.to.offset);\n\t}\n\n\tfor (let i = fromIdx + 1; i < toIdx; i++) {\n\t\tconst midBlockId = blockOrder[i];\n\t\tif (!midBlockId) continue;\n\t\tconst midBlock = state.getBlock(midBlockId);\n\t\tif (!midBlock) continue;\n\t\tconst midLen = getBlockLength(midBlock);\n\t\tif (midLen > 0) {\n\t\t\tbuilder.deleteTextAt(midBlockId, 0, midLen);\n\t\t}\n\t\tbuilder.mergeBlocksAt(range.from.blockId, midBlockId);\n\t}\n\n\tbuilder.mergeBlocksAt(range.from.blockId, range.to.blockId);\n}\n\n/**\n * Deletes a selection spanning different root-level ancestors.\n * Removes intermediate and composite root blocks, merges leaf roots.\n * Returns a replacement cursor block ID if from was inside a removed composite.\n */\nexport function deleteCrossRootRange(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n\trange: DeletionRange,\n\tfromRootIdx: number,\n\ttoRootIdx: number,\n): BlockId | undefined {\n\tconst fromRoot = state.doc.children[fromRootIdx];\n\tconst toRoot = state.doc.children[toRootIdx];\n\tif (!fromRoot || !toRoot) return undefined;\n\n\tconst fromIsLeaf: boolean = isLeafBlock(fromRoot);\n\tconst toIsLeaf: boolean = isLeafBlock(toRoot);\n\n\t// When from is inside a composite root, insert a landing paragraph\n\t// so callers can reference a surviving block for cursor/insert.\n\tlet landingId: BlockId | undefined;\n\tlet indexShift = 0;\n\n\tif (!fromIsLeaf) {\n\t\tlandingId = generateBlockId();\n\t\tbuilder.insertNode([], fromRootIdx, createEmptyParagraph(landingId));\n\t\tindexShift = 1;\n\t}\n\n\t// Delete text in from-leaf (only for leaf roots; composite roots are removed entirely)\n\tif (fromIsLeaf) {\n\t\tconst fromBlock = state.getBlock(range.from.blockId);\n\t\tif (fromBlock) {\n\t\t\tconst fromLen: number = getBlockLength(fromBlock);\n\t\t\tif (range.from.offset < fromLen) {\n\t\t\t\tbuilder.deleteTextAt(range.from.blockId, range.from.offset, fromLen);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Delete text in to-leaf (only for leaf roots)\n\tif (toIsLeaf && range.to.offset > 0) {\n\t\tbuilder.deleteTextAt(range.to.blockId, 0, range.to.offset);\n\t}\n\n\t// Remove root-level blocks in descending index order.\n\t// Keep from-root if it's a leaf; remove if composite (shifted by indexShift).\n\t// Keep to-root if it's a leaf (will merge into from); remove if composite.\n\tconst removeEnd: number = toIsLeaf ? toRootIdx - 1 + indexShift : toRootIdx + indexShift;\n\tconst removeStart: number = fromIsLeaf ? fromRootIdx + 1 : fromRootIdx + indexShift;\n\n\tfor (let i = removeEnd; i >= removeStart; i--) {\n\t\tbuilder.removeNode([], i);\n\t}\n\n\t// Merge to-root into from if both are leaf roots\n\tif (fromIsLeaf && toIsLeaf) {\n\t\tbuilder.mergeBlocksAt(range.from.blockId, range.to.blockId);\n\t}\n\n\treturn landingId;\n}\n","/**\n * Mark-related commands: toggling bold/italic/underline and checking\n * whether a mark is active.\n */\n\nimport {\n\ttype BlockNode,\n\ttype Mark,\n\tgetBlockLength,\n\tgetInlineChildren,\n\thasMark,\n\tisTextNode,\n} from '../model/Document.js';\nimport { isMarkAllowed } from '../model/Schema.js';\nimport { isCollapsed, isTextSelection, selectionRange } from '../model/Selection.js';\nimport type { MarkTypeName } from '../model/TypeBrands.js';\nimport { markType as mkType } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { resolveCursorMarks } from './CursorMarks.js';\nimport { forEachBlockInRange } from './RangeIterator.js';\n\n// --- Feature Configuration ---\n\nexport interface FeatureConfig {\n\treadonly bold: boolean;\n\treadonly italic: boolean;\n\treadonly underline: boolean;\n}\n\nconst defaultFeatures: FeatureConfig = { bold: true, italic: true, underline: true };\n\n/**\n * Toggles a mark on the current selection.\n * If collapsed, toggles stored marks. If range, applies/removes from text.\n */\nexport function toggleMark(\n\tstate: EditorState,\n\tmarkType: MarkTypeName,\n\tfeatures: FeatureConfig = defaultFeatures,\n): Transaction | null {\n\tif (isFeatureGated(markType, features)) return null;\n\tif (!isMarkAllowed(state.schema, markType)) return null;\n\tif (!isTextSelection(state.selection)) return null;\n\n\tconst mark: Mark = { type: markType };\n\tconst sel = state.selection;\n\n\tif (isCollapsed(sel)) {\n\t\t// Toggle stored marks\n\t\tconst anchorBlock = state.getBlock(sel.anchor.blockId);\n\t\tif (!anchorBlock) return null;\n\t\tconst currentMarks = resolveCursorMarks(state);\n\t\tconst hasIt = hasMark(currentMarks, markType);\n\t\tconst newMarks = hasIt\n\t\t\t? currentMarks.filter((m) => m.type !== markType)\n\t\t\t: [...currentMarks, mark];\n\n\t\treturn state\n\t\t\t.transaction('command')\n\t\t\t.setStoredMarks(newMarks, state.storedMarks)\n\t\t\t.setSelection(sel)\n\t\t\t.build();\n\t}\n\n\t// Range selection — apply/remove mark to all blocks in range\n\tconst range = selectionRange(sel, state.getBlockOrder());\n\tconst builder = state.transaction('command');\n\n\t// Determine if we should add or remove\n\tconst shouldRemove = isMarkActiveInRange(state, markType);\n\n\tforEachBlockInRange(state, range, (blockId, from, to) => {\n\t\tif (shouldRemove) {\n\t\t\tbuilder.removeMark(blockId, from, to, mark);\n\t\t} else {\n\t\t\tbuilder.addMark(blockId, from, to, mark);\n\t\t}\n\t});\n\n\tbuilder.setSelection(sel);\n\treturn builder.build();\n}\n\nexport function toggleBold(state: EditorState, features?: FeatureConfig): Transaction | null {\n\treturn toggleMark(state, mkType('bold'), features);\n}\n\nexport function toggleItalic(state: EditorState, features?: FeatureConfig): Transaction | null {\n\treturn toggleMark(state, mkType('italic'), features);\n}\n\nexport function toggleUnderline(state: EditorState, features?: FeatureConfig): Transaction | null {\n\treturn toggleMark(state, mkType('underline'), features);\n}\n\n/** Checks if a mark is active at the current selection. */\nexport function isMarkActive(state: EditorState, markType: MarkTypeName): boolean {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return false;\n\n\tif (isCollapsed(sel)) {\n\t\treturn hasMark(resolveCursorMarks(state), markType);\n\t}\n\n\treturn isMarkActiveInRange(state, markType);\n}\n\n/** Per-slice result of scanning a block for a mark. */\ntype SliceMarkStatus = 'present' | 'missing' | 'empty';\n\n/** Checks if a mark is active across the entire selection range. */\nfunction isMarkActiveInRange(state: EditorState, markType: MarkTypeName): boolean {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return false;\n\tconst blockOrder = state.getBlockOrder();\n\tconst range = selectionRange(sel, blockOrder);\n\n\tconst fromIdx = blockOrder.indexOf(range.from.blockId);\n\tconst toIdx = blockOrder.indexOf(range.to.blockId);\n\n\tlet sawMarkedText = false;\n\tfor (let i = fromIdx; i <= toIdx; i++) {\n\t\tconst blockId = blockOrder[i];\n\t\tif (!blockId) continue;\n\t\tconst block = state.getBlock(blockId);\n\t\tif (!block) continue;\n\t\tconst blockLen = getBlockLength(block);\n\t\tconst from = i === fromIdx ? range.from.offset : 0;\n\t\tconst to = i === toIdx ? range.to.offset : blockLen;\n\n\t\tconst status = markStatusInBlock(block, from, to, markType);\n\t\tif (status === 'missing') return false;\n\t\tif (status === 'present') sawMarkedText = true;\n\t}\n\n\t// Active only when the range actually contains text that carries the mark.\n\t// A range with no markable text (only empty blocks, or a void block such as a\n\t// lone display formula on Ctrl+A) is NOT active — returning true there would\n\t// light up every toolbar format button.\n\treturn sawMarkedText;\n}\n\n/**\n * Scans a block's `[from, to)` slice for `markType`. Returns:\n * - `missing` when some text character in the slice lacks the mark,\n * - `present` when the slice has text and all of it carries the mark,\n * - `empty` when the slice has no markable text (empty slice or only InlineNodes).\n *\n * An `empty` slice is neutral: it neither activates nor inverts the range check,\n * so an empty paragraph in the middle of a multi-block selection does not flip\n * the result (regression #130).\n */\nfunction markStatusInBlock(\n\tblock: BlockNode,\n\tfrom: number,\n\tto: number,\n\tmarkType: MarkTypeName,\n): SliceMarkStatus {\n\tlet pos = 0;\n\tlet sawText = false;\n\tfor (const child of getInlineChildren(block)) {\n\t\tif (isTextNode(child)) {\n\t\t\tconst childEnd = pos + child.text.length;\n\t\t\tif (childEnd > from && pos < to) {\n\t\t\t\tsawText = true;\n\t\t\t\tif (!hasMark(child.marks, markType)) return 'missing';\n\t\t\t}\n\t\t\tpos = childEnd;\n\t\t} else {\n\t\t\t// InlineNode: atomic, width 1, carries no marks.\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn sawText ? 'present' : 'empty';\n}\n\nfunction isFeatureGated(type: MarkTypeName, features: FeatureConfig): boolean {\n\tconst key = type as string;\n\tif (key === 'bold') return !features.bold;\n\tif (key === 'italic') return !features.italic;\n\tif (key === 'underline') return !features.underline;\n\treturn false;\n}\n","/**\n * Delete commands: character, word, and soft-line deletion in both directions.\n */\n\nimport {\n\ttype BlockNode,\n\tblockOffsetToTextOffset,\n\tgetBlockLength,\n\tgetBlockText,\n\tgetContentAtOffset,\n} from '../model/Document.js';\nimport { nextGraphemeSize, prevGraphemeSize } from '../model/GraphemeUtils.js';\nimport {\n\tcreateCollapsedSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\n} from '../model/Selection.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport { deleteSelectionCommand, mergeBlockBackward, mergeBlockForward } from './Commands.js';\nimport { deleteNodeSelection } from './NodeSelectionCommands.js';\nimport { findWordBoundaryBackward, findWordBoundaryForward } from './WordBoundary.js';\n\ninterface DeleteConfig {\n\treadonly merge: (state: EditorState) => Transaction | null;\n\treadonly range: (block: BlockNode, offset: number) => readonly [number, number] | null;\n}\n\nfunction deleteInDirection(state: EditorState, config: DeleteConfig): Transaction | null {\n\tconst sel = state.selection;\n\n\tif (isNodeSelection(sel)) return deleteNodeSelection(state, sel);\n\tif (isGapCursor(sel)) return null;\n\tif (!isCollapsed(sel)) return deleteSelectionCommand(state);\n\n\tconst block = state.getBlock(sel.anchor.blockId);\n\tif (!block) return null;\n\n\tconst range = config.range(block, sel.anchor.offset);\n\tif (!range) return config.merge(state);\n\n\tconst [from, to] = range;\n\treturn state\n\t\t.transaction('input')\n\t\t.deleteTextAt(block.id, from, to)\n\t\t.setSelection(createCollapsedSelection(block.id, from))\n\t\t.build();\n}\n\n/** Handles backspace key. */\nexport function deleteBackward(state: EditorState): Transaction | null {\n\treturn deleteInDirection(state, {\n\t\tmerge: mergeBlockBackward,\n\t\trange: (block, offset) => {\n\t\t\tif (offset <= 0) return null;\n\t\t\tconst content = getContentAtOffset(block, offset - 1);\n\t\t\tif (content?.kind === 'inline') return [offset - 1, offset];\n\t\t\tconst text: string = getBlockText(block);\n\t\t\tconst textOffset: number = blockOffsetToTextOffset(block, offset);\n\t\t\tconst step: number = prevGraphemeSize(text, textOffset) || 1;\n\t\t\treturn [offset - step, offset];\n\t\t},\n\t});\n}\n\n/** Handles delete key. */\nexport function deleteForward(state: EditorState): Transaction | null {\n\treturn deleteInDirection(state, {\n\t\tmerge: mergeBlockForward,\n\t\trange: (block, offset) => {\n\t\t\tconst len: number = getBlockLength(block);\n\t\t\tif (offset >= len) return null;\n\t\t\tconst content = getContentAtOffset(block, offset);\n\t\t\tif (content?.kind === 'inline') return [offset, offset + 1];\n\t\t\tconst text: string = getBlockText(block);\n\t\t\tconst textOffset: number = blockOffsetToTextOffset(block, offset);\n\t\t\tconst step: number = nextGraphemeSize(text, textOffset) || 1;\n\t\t\treturn [offset, offset + step];\n\t\t},\n\t});\n}\n\n/** Handles Ctrl+Backspace: delete word backward. */\nexport function deleteWordBackward(state: EditorState): Transaction | null {\n\treturn deleteInDirection(state, {\n\t\tmerge: mergeBlockBackward,\n\t\trange: (block, offset) =>\n\t\t\toffset > 0 ? [findWordBoundaryBackward(block, offset), offset] : null,\n\t});\n}\n\n/** Handles Ctrl+Delete: delete word forward. */\nexport function deleteWordForward(state: EditorState): Transaction | null {\n\treturn deleteInDirection(state, {\n\t\tmerge: mergeBlockForward,\n\t\trange: (block, offset) => {\n\t\t\tconst len = getBlockLength(block);\n\t\t\treturn offset < len ? [offset, findWordBoundaryForward(block, offset)] : null;\n\t\t},\n\t});\n}\n\n/** Handles Cmd+Backspace: delete to start of line/block. */\nexport function deleteSoftLineBackward(state: EditorState): Transaction | null {\n\treturn deleteInDirection(state, {\n\t\tmerge: mergeBlockBackward,\n\t\trange: (_block, offset) => (offset > 0 ? [0, offset] : null),\n\t});\n}\n\n/** Handles Cmd+Delete: delete to end of line/block. */\nexport function deleteSoftLineForward(state: EditorState): Transaction | null {\n\treturn deleteInDirection(state, {\n\t\tmerge: mergeBlockForward,\n\t\trange: (block, offset) => {\n\t\t\tconst len = getBlockLength(block);\n\t\t\treturn offset < len ? [offset, len] : null;\n\t\t},\n\t});\n}\n","/**\n * Core editor commands and barrel re-exports from submodules.\n *\n * This module contains text insertion, block splitting, block merging,\n * selection deletion, and select-all. Mark, delete, gap-cursor, node-selection,\n * and word-boundary commands are re-exported from their respective modules.\n */\n\nimport {\n\ttype Mark,\n\tcreateEmptyParagraph,\n\tcreateInlineNode,\n\tgenerateBlockId,\n\tgetBlockLength,\n\tgetBlockMarksAtOffset,\n\tgetCursorMarks,\n} from '../model/Document.js';\nimport { findNodePath } from '../model/NodeResolver.js';\nimport {\n\tcreateCollapsedSelection,\n\tcreateNodeSelection,\n\tcreateSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\n\tisTextSelection,\n\tselectionRange,\n} from '../model/Selection.js';\nimport { type BlockId, inlineType } from '../model/TypeBrands.js';\nimport type { EditorState } from '../state/EditorState.js';\nimport {\n\tisInsideIsolating,\n\tisIsolatingBlock,\n\tisVoidBlock,\n\tsharesParent,\n} from '../state/NavigationQueries.js';\nimport type { Transaction } from '../state/Transaction.js';\nimport type { TransactionBuilder } from '../state/Transaction.js';\nimport { resolveInsertPoint } from './CommandHelpers.js';\nimport { isMarkInclusive } from './CursorMarks.js';\nimport { insertParagraphAtGap, insertTextAtGap } from './GapCursorCommands.js';\nimport {\n\tdeleteNodeSelection,\n\tfindFirstLeafBlockId,\n\tfindLastLeafBlockId,\n\tinsertParagraphAfterNodeSelection,\n\tinsertTextAfterNodeSelection,\n} from './NodeSelectionCommands.js';\nimport { deleteCrossRootRange, deleteLeafRange, getRootBlockIndex } from './SelectionDeletion.js';\n\n// --- Re-exports from submodules ---\n\nexport {\n\tcanCrossBlockBoundary,\n\tisInsideIsolating,\n\tisIsolatingBlock,\n\tisVoidBlock,\n\tsharesParent,\n} from '../state/NavigationQueries.js';\n\nexport type { FeatureConfig } from './MarkCommands.js';\nexport {\n\tisMarkActive,\n\ttoggleBold,\n\ttoggleItalic,\n\ttoggleMark,\n\ttoggleUnderline,\n} from './MarkCommands.js';\n\nexport {\n\tdeleteBackward,\n\tdeleteForward,\n\tdeleteSoftLineBackward,\n\tdeleteSoftLineForward,\n\tdeleteWordBackward,\n\tdeleteWordForward,\n} from './DeleteCommands.js';\n\nexport {\n\tdeleteNodeSelection,\n\tfindFirstLeafBlockId,\n\tfindLastLeafBlockId,\n\tinsertParagraphAfterNodeSelection,\n\tinsertTextAfterNodeSelection,\n\tnavigateArrowIntoVoid,\n} from './NodeSelectionCommands.js';\n\nexport {\n\tdeleteBackwardAtGap,\n\tdeleteForwardAtGap,\n\tinsertParagraphAtGap,\n\tinsertTextAtGap,\n} from './GapCursorCommands.js';\n\nexport {\n\tfindWordBoundaryBackward,\n\tfindWordBoundaryForward,\n} from './WordBoundary.js';\n\nexport {\n\tapplyAttributedMark,\n\tgetMarkAttrAtSelection,\n\tisAttributedMarkActive,\n\tremoveAttributedMark,\n} from './AttributedMarkCommands.js';\n\nexport { forEachBlockIdInRange, forEachBlockInRange } from './RangeIterator.js';\n\n// --- Text Commands ---\n\n/** Inserts text at the current selection, replacing any selected range. */\nexport function insertTextCommand(\n\tstate: EditorState,\n\ttext: string,\n\torigin: 'input' | 'paste' = 'input',\n): Transaction {\n\tconst sel = state.selection;\n\n\t// NodeSelection: insert paragraph after void block with the text\n\tif (isNodeSelection(sel)) {\n\t\treturn insertTextAfterNodeSelection(state, sel, text, origin);\n\t}\n\n\t// GapCursor: insert paragraph at the gap position with the text\n\tif (isGapCursor(sel)) {\n\t\treturn insertTextAtGap(state, sel, text, origin);\n\t}\n\n\tconst builder = state.transaction(origin);\n\tconst marks = resolveActiveMarks(state);\n\n\tlet landingId: BlockId | undefined;\n\tif (!isCollapsed(sel)) {\n\t\tlandingId = addDeleteSelectionSteps(state, builder);\n\t}\n\n\tconst resolved = resolveInsertPoint(sel, state.getBlockOrder());\n\tconst insertBlockId: BlockId = landingId ?? resolved.blockId;\n\tconst insertOffset: number = landingId ? 0 : resolved.offset;\n\n\tbuilder.insertText(insertBlockId, insertOffset, text, marks);\n\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + text.length));\n\n\treturn builder.build();\n}\n\n/** Deletes the current selection. */\nexport function deleteSelectionCommand(state: EditorState): Transaction | null {\n\tif (isNodeSelection(state.selection)) {\n\t\treturn deleteNodeSelection(state, state.selection);\n\t}\n\tif (isGapCursor(state.selection)) return null;\n\tif (isCollapsed(state.selection)) return null;\n\n\t// Deleting a selection that spans the whole document resets it to the\n\t// canonical empty state (a single empty paragraph). Without this, the range\n\t// merge keeps the first block's type and attributes, leaving e.g. an empty\n\t// centered title behind so the placeholder never returns.\n\tif (selectionCoversDocument(state)) {\n\t\treturn clearDocument(state);\n\t}\n\n\tconst builder = state.transaction('input');\n\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\n\tconst range = selectionRange(state.selection, state.getBlockOrder());\n\tconst cursorBlockId: BlockId = landingId ?? range.from.blockId;\n\tconst cursorOffset: number = landingId ? 0 : range.from.offset;\n\tbuilder.setSelection(createCollapsedSelection(cursorBlockId, cursorOffset));\n\n\treturn builder.build();\n}\n\n/** Splits the current block at the cursor position (Enter key). */\nexport function splitBlockCommand(state: EditorState): Transaction | null {\n\tconst sel = state.selection;\n\n\t// NodeSelection: insert empty paragraph after the void block\n\tif (isNodeSelection(sel)) {\n\t\treturn insertParagraphAfterNodeSelection(state, sel);\n\t}\n\n\t// GapCursor: insert empty paragraph at the gap position\n\tif (isGapCursor(sel)) {\n\t\treturn insertParagraphAtGap(state, sel);\n\t}\n\n\tconst builder = state.transaction('input');\n\n\tlet landingId: BlockId | undefined;\n\tif (!isCollapsed(sel)) {\n\t\tlandingId = addDeleteSelectionSteps(state, builder);\n\t}\n\n\tconst resolved = resolveInsertPoint(sel, state.getBlockOrder());\n\tconst blockId: BlockId = landingId ?? resolved.blockId;\n\tconst offset: number = landingId ? 0 : resolved.offset;\n\tconst newBlockId = generateBlockId();\n\n\t// splitBlock operates at the same level in the tree — the StepApplication\n\t// handles this correctly because it looks up the block by ID recursively.\n\tbuilder.splitBlock(blockId, offset, newBlockId);\n\tbuilder.setSelection(createCollapsedSelection(newBlockId, 0));\n\n\treturn builder.build();\n}\n\n/** Inserts a hard line break (InlineNode) at the current cursor position. */\nexport function insertHardBreakCommand(state: EditorState): Transaction | null {\n\tconst sel = state.selection;\n\n\tif (!isTextSelection(sel)) return null;\n\n\tconst builder = state.transaction('input');\n\n\tlet cursorBlockId: BlockId | undefined;\n\tif (!isCollapsed(sel)) {\n\t\tconst landingId: BlockId | undefined = addDeleteSelectionSteps(state, builder);\n\t\tcursorBlockId = landingId;\n\t}\n\n\tif (cursorBlockId) {\n\t\t// Cross-root deletion replaced from-block; insert hard break in landing block\n\t\tbuilder.insertInlineNode(cursorBlockId, 0, createInlineNode(inlineType('hard_break')));\n\t\tbuilder.setSelection(createCollapsedSelection(cursorBlockId, 1));\n\t} else {\n\t\tconst { blockId: insertBlockId, offset: insertOffset } = resolveInsertPoint(\n\t\t\tsel,\n\t\t\tstate.getBlockOrder(),\n\t\t);\n\t\tbuilder.insertInlineNode(\n\t\t\tinsertBlockId,\n\t\t\tinsertOffset,\n\t\t\tcreateInlineNode(inlineType('hard_break')),\n\t\t);\n\t\tbuilder.setSelection(createCollapsedSelection(insertBlockId, insertOffset + 1));\n\t}\n\n\treturn builder.build();\n}\n\n/**\n * Merges the current block with the previous block, respecting\n * isolating boundaries and void blocks.\n */\nexport function mergeBlockBackward(state: EditorState): Transaction | null {\n\treturn mergeAdjacentBlock(state, 'backward');\n}\n\n/**\n * Merges the next block into the current block, respecting\n * isolating boundaries and void blocks.\n */\nexport function mergeBlockForward(state: EditorState): Transaction | null {\n\treturn mergeAdjacentBlock(state, 'forward');\n}\n\n/**\n * Shared implementation for merging adjacent blocks in either direction.\n * Validates selection, isolating boundaries, and void blocks before merging.\n */\nfunction mergeAdjacentBlock(\n\tstate: EditorState,\n\tdirection: 'backward' | 'forward',\n): Transaction | null {\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return null;\n\n\tconst blockOrder = state.getBlockOrder();\n\tconst blockIdx: number = blockOrder.indexOf(sel.anchor.blockId);\n\n\tconst adjacentIdx: number = direction === 'backward' ? blockIdx - 1 : blockIdx + 1;\n\tif (adjacentIdx < 0 || adjacentIdx >= blockOrder.length) return null;\n\n\tconst adjacentId: BlockId | undefined = blockOrder[adjacentIdx];\n\tif (!adjacentId) return null;\n\n\tif (isIsolatingBlock(state, sel.anchor.blockId) || isIsolatingBlock(state, adjacentId)) {\n\t\treturn null;\n\t}\n\tif (!sharesParent(state, sel.anchor.blockId, adjacentId)) {\n\t\tif (isInsideIsolating(state, sel.anchor.blockId)) return null;\n\t}\n\n\tif (isVoidBlock(state, adjacentId)) {\n\t\tconst path = findNodePath(state.doc, adjacentId) ?? [];\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.setSelection(createNodeSelection(adjacentId, path as BlockId[]))\n\t\t\t.build();\n\t}\n\n\tif (direction === 'backward') {\n\t\tconst prevBlock = state.getBlock(adjacentId);\n\t\tif (!prevBlock) return null;\n\t\tconst prevLen: number = getBlockLength(prevBlock);\n\t\treturn state\n\t\t\t.transaction('input')\n\t\t\t.mergeBlocksAt(adjacentId, sel.anchor.blockId)\n\t\t\t.setSelection(createCollapsedSelection(adjacentId, prevLen))\n\t\t\t.build();\n\t}\n\n\treturn state\n\t\t.transaction('input')\n\t\t.mergeBlocksAt(sel.anchor.blockId, adjacentId)\n\t\t.setSelection(createCollapsedSelection(sel.anchor.blockId, sel.anchor.offset))\n\t\t.build();\n}\n\n/** Selects all content in the editor, using leaf block endpoints. */\nexport function selectAll(state: EditorState): Transaction {\n\tconst docRange = documentRange(state);\n\tif (!docRange) return state.transaction('command').setSelection(state.selection).build();\n\n\treturn state\n\t\t.transaction('command')\n\t\t.setSelection(createSelection(docRange.from, docRange.to))\n\t\t.build();\n}\n\n// --- Internal Helpers ---\n\ninterface DocumentPosition {\n\treadonly blockId: BlockId;\n\treadonly offset: number;\n}\n\n/**\n * Endpoints of a full-document selection: the start of the first leaf block to\n * the end of the last leaf block. Returns `null` for an empty document.\n */\nfunction documentRange(\n\tstate: EditorState,\n): { from: DocumentPosition; to: DocumentPosition } | null {\n\tconst blocks = state.doc.children;\n\tconst firstBlock = blocks[0];\n\tconst lastBlock = blocks[blocks.length - 1];\n\tif (!firstBlock || !lastBlock) return null;\n\n\tconst firstLeafId: BlockId = findFirstLeafBlockId(firstBlock);\n\tconst lastLeafId: BlockId = findLastLeafBlockId(lastBlock);\n\tconst lastLeaf = state.getBlock(lastLeafId);\n\tconst lastLeafLen: number = lastLeaf ? getBlockLength(lastLeaf) : 0;\n\n\treturn {\n\t\tfrom: { blockId: firstLeafId, offset: 0 },\n\t\tto: { blockId: lastLeafId, offset: lastLeafLen },\n\t};\n}\n\n/** True when the current text selection spans the entire document. */\nfunction selectionCoversDocument(state: EditorState): boolean {\n\tif (!isTextSelection(state.selection)) return false;\n\tconst docRange = documentRange(state);\n\tif (!docRange) return false;\n\n\tconst range = selectionRange(state.selection, state.getBlockOrder());\n\treturn (\n\t\trange.from.blockId === docRange.from.blockId &&\n\t\trange.from.offset === docRange.from.offset &&\n\t\trange.to.blockId === docRange.to.blockId &&\n\t\trange.to.offset === docRange.to.offset\n\t);\n}\n\n/**\n * Replaces the whole document with a single empty paragraph and places the\n * cursor inside it. The fresh paragraph is inserted before the originals are\n * removed so the document never passes through a zero-children state.\n */\nfunction clearDocument(state: EditorState): Transaction {\n\tconst newBlockId: BlockId = generateBlockId();\n\tconst builder = state.transaction('input');\n\tconst originalCount: number = state.doc.children.length;\n\n\tbuilder.insertNode([], 0, createEmptyParagraph(newBlockId));\n\t// The originals shifted to indices 1..originalCount; remove them descending\n\t// so each index stays valid as the document shrinks.\n\tfor (let i = originalCount; i >= 1; i--) {\n\t\tbuilder.removeNode([], i);\n\t}\n\tbuilder.setSelection(createCollapsedSelection(newBlockId, 0));\n\n\treturn builder.build();\n}\n\nfunction resolveActiveMarks(state: EditorState): readonly Mark[] {\n\tif (state.storedMarks) return state.storedMarks;\n\n\tconst sel = state.selection;\n\tif (!isTextSelection(sel)) return [];\n\n\tconst block = state.getBlock(sel.anchor.blockId);\n\tif (!block) return [];\n\n\t// A range replaced by typing inherits the marks at its anchor (raw content\n\t// marks); only a collapsed cursor honors right-boundary inclusivity.\n\tif (!isCollapsed(sel)) return getBlockMarksAtOffset(block, sel.anchor.offset);\n\n\treturn getCursorMarks(block, sel.anchor.offset, (type) => isMarkInclusive(state.schema, type));\n}\n\n/**\n * Adds steps to delete the current text selection.\n * Returns a replacement cursor block ID when the original from-block\n * was inside a composite root that got removed (undefined otherwise).\n */\nexport function addDeleteSelectionSteps(\n\tstate: EditorState,\n\tbuilder: TransactionBuilder,\n): BlockId | undefined {\n\tif (!isTextSelection(state.selection)) return undefined;\n\tconst blockOrder = state.getBlockOrder();\n\tconst range = selectionRange(state.selection, blockOrder);\n\tconst fromIdx = blockOrder.indexOf(range.from.blockId);\n\tconst toIdx = blockOrder.indexOf(range.to.blockId);\n\n\tif (fromIdx === toIdx) {\n\t\tbuilder.deleteTextAt(range.from.blockId, range.from.offset, range.to.offset);\n\t\treturn undefined;\n\t}\n\n\tconst fromRootIdx: number = getRootBlockIndex(state, range.from.blockId);\n\tconst toRootIdx: number = getRootBlockIndex(state, range.to.blockId);\n\n\tif (fromRootIdx === toRootIdx || fromRootIdx < 0 || toRootIdx < 0) {\n\t\tdeleteLeafRange(state, builder, blockOrder, range, fromIdx, toIdx);\n\t\treturn undefined;\n\t}\n\n\treturn deleteCrossRootRange(state, builder, range, fromRootIdx, toRootIdx);\n}\n"],"mappings":"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"}
@@ -1,2 +1,2 @@
1
- import{C as t,M as e,i as n,s as i,v as a}from"./Document-r7vLOAGA.mjs";import{l as r,o,r as l,t as s,u as c}from"./Selection-HYoVFpAx.mjs";import{t as p}from"./Commands-CyT1Li7_.mjs";import{a as u,r as d}from"./TypeBrands-Ch9856Gb.mjs";import{n as m}from"./DomUtils-Bf7JLFlx.mjs";import{c as h,w as f}from"./BlockInsertion-6rR9tIGP.mjs";import{t as b}from"./SelectionSync-BSHIw1EE.mjs";import{a as g,i as v,s as x}from"./PluginHelpers-D4quRJ5a.mjs";import{i as y}from"./PopupPositioning-DtUrY9bh.mjs";import{r as w}from"./ColorValidation-DAijTjG9.mjs";import L from"dompurify";var k={"&":"&amp;","<":"&lt;",">":"&gt;"},S={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function C(t){return t.replace(/[&<>]/g,t=>k[t]??t)}function A(t){return t.replace(/[&<>"]/g,t=>S[t]??t)}function $(t){if(!t)return"";let e="";for(const[n,i]of Object.entries(t))!1!==i&&null!=i&&(e+=!0!==i?` ${n}="${A(String(i))}"`:` ${n}="true"`);return e}function z(t,e,n){return`<${t}${$(n)}>${e}</${t}>`}function _(t,e){return z("mi",C(t),e)}function E(t,e){return z("mn",C(t),e)}function B(t,e){return z("mo",C(t),e)}function I(t,e){return z("mtext",C(t),e)}function D(t){return function(t,e){return`<${t}${$(e)}></${t}>`}("mspace",t)}function N(t,e){return z("mrow",t,e)}function P(t){return 0===t.length?"":1===t.length?t[0]??"":N(t.join(""))}function q(t,e,n){return z("mfrac",`${t}${e}`,n)}function R(t,e,n){return z("mover",`${t}${e}`,n)}function F(t,e,n){return z("munder",`${t}${e}`,n)}function O(t){return z("mtd",t)}function T(t){return z("mtr",t.map(O).join(""))}var j={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&apos;":"'","&#39;":"'"};function M(t){const e=t.display?"block":"inline",n=t.alt?` alttext="${A(t.alt)}"`:"",i=void 0!==t.latex&&""!==t.latex,a=`<annotation encoding="application/x-tex">${C(t.latex??"")}</annotation>`;return`<math display="${e}"${n}>${i?`<semantics>${t.presentation}${a}</semantics>`:t.presentation}</math>`}function H(t){const e=t.match(/<annotation\b[^>]*\bencoding=["']application\/x-tex["'][^>]*>([\s\S]*?)<\/annotation>/i);var n;if(e&&void 0!==e[1])return(n=e[1],n.replace(/&(?:amp|lt|gt|quot|apos|#39);/g,t=>j[t]??t)).trim()}function G(t){return t.replace(/^(<math\b[^>]*?)\s+mathsize=(?:"[^"]*"|'[^']*')/i,"$1")}var U=/<math[\s>]/i;function K(t){return U.test(t.mathml)?function(t,e){const n=t.replace(/^(<math\b[^>]*?)\s+alttext=["'][^"']*["']/i,"$1");return e?n.replace(/^<math\b/i,`<math alttext="${A(e)}"`):n}(t.mathml,t.alt):""}function W(t,e){const n=K(e);n?t.innerHTML=n:t.textContent=e.latex||e.alt||"⊡"}function V(t,e){const n="string"==typeof e?.fontSize?e.fontSize:"";t.style.fontSize=n}function Z(t){return{mathml:"string"==typeof t?.mathml?t.mathml:"",latex:"string"==typeof t?.latex?t.latex:"",alt:"string"==typeof t?.alt?t.alt:"",fontSize:"string"==typeof t?.fontSize?t.fontSize:""}}function X(t){const e=K(t);return e?function(t,e){const n=G(t);return e?n.replace(/^<math\b/i,`<math mathsize="${A(e)}"`):n}(e,w(t.fontSize)?t.fontSize:""):e}function Q(t){const e=t.getAttribute("mathsize")??"";return w(e)?e:""}function J(t,e){if("block"===t.getAttribute("display")!==e)return!1;const n=G(function(t){return t.replace(/^(<math\b[^>]*?)\s+data-block-id=(?:"[^"]*"|'[^']*')/i,"$1")}(t.outerHTML));return{mathml:n,latex:H(n)??"",alt:t.getAttribute("alttext")??"",fontSize:Q(t)}}var Y="math_inline",tt="math_display",et={insertInline:"Mod-Shift-E",insertDisplay:"Mod-Shift-M"},nt=[12,16,20,24,32,40,48,64,96],it={},at=["math","semantics","annotation","mrow","mi","mn","mo","mtext","ms","mspace","mfrac","msqrt","mroot","msup","msub","msubsup","mover","munder","munderover","mmultiscripts","mprescripts","none","mtable","mtr","mlabeledtr","mtd","mpadded","mphantom","mstyle","merror","menclose","mfenced","maction"],rt=["display","encoding","mathvariant","mathsize","mathcolor","mathbackground","displaystyle","scriptlevel","scriptminsize","scriptsizemultiplier","stretchy","symmetric","largeop","movablelimits","accent","accentunder","form","fence","separator","lspace","rspace","voffset","minsize","maxsize","linethickness","columnalign","rowalign","columnspacing","rowspacing","columnlines","rowlines","columnspan","rowspan","align","open","close","separators","notation","alttext","depth","width","height"];function ot(t){const e=t.selection;if(!r(e))return null;const n=t.getBlock(e.nodeId);return n&&"math_display"===n.type?e.nodeId:null}function lt(t){return{mathml:t.mathml,latex:t.latex,alt:t.alt,fontSize:t.fontSize}}function st(t,e){const n=t.selection;if(0===e.length||!c(n))return null;const a=t.transaction("command"),r=o(n)?void 0:p(t,a);let l,u;if(r)l=r,u=0;else{const e=f(n,t.getBlockOrder());l=e.blockId,u=e.offset}for(const o of e)a.insertInlineNode(l,u,i(d(Y),lt(o))),u+=1;return a.setSelection(s(l,u)),a.build()}function ct(t,e){const i=v(t);if(0===e.length||!i)return null;const a=e.map(t=>n(u(tt),[],void 0,lt(t))),r=t.transaction("command");if(!h(t,r,i,a))return null;const o=a[a.length-1];return o?(r.setSelection(l(o.id,[])),r.build()):null}function pt(t){return{mathml:t.mathml,latex:t.latex,alt:t.alt,fontSize:t.fontSize}}function ut(t,e,n){const i=pt(n);n.display?function(t,e){const n=function(t,e){return ct(t,[e])}(t.getState(),e);!!n&&t.dispatch(n)}(t,i):function(t,e){const n=function(t,e){return st(t,[e])}(t.getState(),e);!!n&&t.dispatch(n)}(t,i),t.announce(e.inserted)}function dt(t,e){return void 0===e?{node:t}:{node:t,kind:e}}function mt(t,e,n=!1){return{node:t,kind:e,bigOp:!0,intLike:n}}var ht=/* @__PURE__ */function(t){return t.Ordinary="ordinary",t.Binary="binary",t.Relation="relation",t.Arrow="arrow",t.Open="open",t.Close="close",t.Function="function",t.BigOp="bigop",t.Punct="punct",t}({});function ft(t,e){return{char:t,kind:e}}var bt="ordinary",gt="binary",vt="relation",xt="arrow",yt="function",wt="bigop",Lt="punct",kt={alpha:ft("α",bt),beta:ft("β",bt),gamma:ft("γ",bt),delta:ft("δ",bt),epsilon:ft("ϵ",bt),varepsilon:ft("ε",bt),zeta:ft("ζ",bt),eta:ft("η",bt),theta:ft("θ",bt),vartheta:ft("ϑ",bt),iota:ft("ι",bt),kappa:ft("κ",bt),lambda:ft("λ",bt),mu:ft("μ",bt),nu:ft("ν",bt),xi:ft("ξ",bt),omicron:ft("ο",bt),pi:ft("π",bt),varpi:ft("ϖ",bt),rho:ft("ρ",bt),varrho:ft("ϱ",bt),sigma:ft("σ",bt),varsigma:ft("ς",bt),tau:ft("τ",bt),upsilon:ft("υ",bt),phi:ft("ϕ",bt),varphi:ft("φ",bt),chi:ft("χ",bt),psi:ft("ψ",bt),omega:ft("ω",bt),Gamma:ft("Γ",bt),Delta:ft("Δ",bt),Theta:ft("Θ",bt),Lambda:ft("Λ",bt),Xi:ft("Ξ",bt),Pi:ft("Π",bt),Sigma:ft("Σ",bt),Upsilon:ft("Υ",bt),Phi:ft("Φ",bt),Psi:ft("Ψ",bt),Omega:ft("Ω",bt)},St={sin:ft("sin",yt),cos:ft("cos",yt),tan:ft("tan",yt),cot:ft("cot",yt),sec:ft("sec",yt),csc:ft("csc",yt),sinh:ft("sinh",yt),cosh:ft("cosh",yt),tanh:ft("tanh",yt),coth:ft("coth",yt),arcsin:ft("arcsin",yt),arccos:ft("arccos",yt),arctan:ft("arctan",yt),log:ft("log",yt),ln:ft("ln",yt),lg:ft("lg",yt),exp:ft("exp",yt),deg:ft("deg",yt),det:ft("det",yt),dim:ft("dim",yt),hom:ft("hom",yt),ker:ft("ker",yt),arg:ft("arg",yt),Pr:ft("Pr",yt)},Ct={sum:ft("∑",wt),prod:ft("∏",wt),coprod:ft("∐",wt),int:ft("∫",wt),iint:ft("∬",wt),iiint:ft("∭",wt),oint:ft("∮",wt),bigcup:ft("⋃",wt),bigcap:ft("⋂",wt),bigsqcup:ft("⨆",wt),bigvee:ft("⋁",wt),bigwedge:ft("⋀",wt),bigoplus:ft("⨁",wt),bigotimes:ft("⨂",wt),bigodot:ft("⨀",wt),biguplus:ft("⨄",wt),lim:ft("lim",wt),limsup:ft("lim sup",wt),liminf:ft("lim inf",wt),injlim:ft("inj lim",wt),projlim:ft("proj lim",wt),max:ft("max",wt),min:ft("min",wt),sup:ft("sup",wt),inf:ft("inf",wt),gcd:ft("gcd",wt)},At={times:ft("×",gt),div:ft("÷",gt),pm:ft("±",gt),mp:ft("∓",gt),cdot:ft("⋅",gt),ast:ft("∗",gt),star:ft("⋆",gt),circ:ft("∘",gt),bullet:ft("∙",gt),oplus:ft("⊕",gt),ominus:ft("⊖",gt),otimes:ft("⊗",gt),oslash:ft("⊘",gt),odot:ft("⊙",gt),cap:ft("∩",gt),cup:ft("∪",gt),uplus:ft("⊎",gt),sqcap:ft("⊓",gt),sqcup:ft("⊔",gt),wedge:ft("∧",gt),land:ft("∧",gt),vee:ft("∨",gt),lor:ft("∨",gt),setminus:ft("∖",gt),wr:ft("≀",gt),diamond:ft("⋄",gt),bigtriangleup:ft("△",gt),bigtriangledown:ft("▽",gt),triangleleft:ft("◁",gt),triangleright:ft("▷",gt),amalg:ft("⨿",gt),dagger:ft("†",gt),ddagger:ft("‡",gt)},$t={leq:ft("≤",vt),le:ft("≤",vt),geq:ft("≥",vt),ge:ft("≥",vt),neq:ft("≠",vt),ne:ft("≠",vt),equiv:ft("≡",vt),sim:ft("∼",vt),simeq:ft("≃",vt),cong:ft("≅",vt),approx:ft("≈",vt),propto:ft("∝",vt),prec:ft("≺",vt),succ:ft("≻",vt),preceq:ft("⪯",vt),succeq:ft("⪰",vt),ll:ft("≪",vt),gg:ft("≫",vt),lll:ft("⋘",vt),ggg:ft("⋙",vt),subset:ft("⊂",vt),supset:ft("⊃",vt),subseteq:ft("⊆",vt),supseteq:ft("⊇",vt),subsetneq:ft("⊊",vt),supsetneq:ft("⊋",vt),sqsubseteq:ft("⊑",vt),sqsupseteq:ft("⊒",vt),in:ft("∈",vt),ni:ft("∋",vt),notin:ft("∉",vt),mid:ft("∣",vt),parallel:ft("∥",vt),perp:ft("⊥",vt),models:ft("⊨",vt),vdash:ft("⊢",vt),dashv:ft("⊣",vt),doteq:ft("≐",vt),asymp:ft("≍",vt),bowtie:ft("⋈",vt),smile:ft("⌣",vt),frown:ft("⌢",vt)},zt={leftarrow:ft("←",xt),gets:ft("←",xt),rightarrow:ft("→",xt),to:ft("→",xt),leftrightarrow:ft("↔",xt),Leftarrow:ft("⇐",xt),Rightarrow:ft("⇒",xt),Leftrightarrow:ft("⇔",xt),mapsto:ft("↦",xt),longrightarrow:ft("⟶",xt),longleftarrow:ft("⟵",xt),longleftrightarrow:ft("⟷",xt),Longrightarrow:ft("⟹",xt),Longleftarrow:ft("⟸",xt),Longleftrightarrow:ft("⟺",xt),implies:ft("⟹",xt),iff:ft("⟺",xt),uparrow:ft("↑",xt),downarrow:ft("↓",xt),updownarrow:ft("↕",xt),nearrow:ft("↗",xt),searrow:ft("↘",xt),swarrow:ft("↙",xt),nwarrow:ft("↖",xt),hookleftarrow:ft("↩",xt),hookrightarrow:ft("↪",xt),rightharpoonup:ft("⇀",xt),rightharpoondown:ft("⇁",xt),leftharpoonup:ft("↼",xt),leftharpoondown:ft("↽",xt),nleftarrow:ft("↚",xt),nrightarrow:ft("↛",xt)},_t={langle:ft("⟨","open"),rangle:ft("⟩","close"),lceil:ft("⌈","open"),rceil:ft("⌉","close"),lfloor:ft("⌊","open"),rfloor:ft("⌋","close"),lbrace:ft("{","open"),rbrace:ft("}","close"),lbrack:ft("[","open"),rbrack:ft("]","close"),lvert:ft("|","open"),rvert:ft("|","close"),lVert:ft("‖","open"),rVert:ft("‖","close"),vert:ft("|","relation"),Vert:ft("‖","relation"),backslash:ft("\\",bt)},Et={infty:ft("∞",bt),partial:ft("∂",bt),nabla:ft("∇",bt),forall:ft("∀",bt),exists:ft("∃",bt),nexists:ft("∄",bt),emptyset:ft("∅",bt),varnothing:ft("∅",bt),aleph:ft("ℵ",bt),beth:ft("ℶ",bt),hbar:ft("ℏ",bt),ell:ft("ℓ",bt),Re:ft("ℜ",bt),Im:ft("ℑ",bt),wp:ft("℘",bt),prime:ft("′",bt),angle:ft("∠",bt),measuredangle:ft("∡",bt),triangle:ft("△",bt),neg:ft("¬",bt),lnot:ft("¬",bt),top:ft("⊤",bt),bot:ft("⊥",bt),flat:ft("♭",bt),natural:ft("♮",bt),sharp:ft("♯",bt),clubsuit:ft("♣",bt),diamondsuit:ft("♢",bt),heartsuit:ft("♡",bt),spadesuit:ft("♠",bt),surd:ft("√",bt),complement:ft("∁",bt),square:ft("□",bt),blacksquare:ft("■",bt),bigstar:ft("★",bt),checkmark:ft("✓",bt),degree:ft("°",bt),cdots:ft("⋯",bt),ldots:ft("…",bt),dots:ft("…",bt),dotsb:ft("⋯",bt),vdots:ft("⋮",bt),ddots:ft("⋱",bt)},Bt={colon:ft(":",Lt),cdotp:ft("·",Lt),ldotp:ft(".",Lt)},It={...kt,...St,...Ct,...At,...$t,...zt,..._t,...Et,...Bt},Dt={"(":ft("(","open"),")":ft(")","close"),"[":ft("[","open"),"]":ft("]","close"),"|":ft("|","relation"),"/":ft("/",bt)};function Nt(t){if("."===t)return ft("",bt);if(t.startsWith("\\")){const e=t.slice(1);return"{"===e?ft("{","open"):"}"===e?ft("}","close"):"|"===e?ft("‖","relation"):"\\"===e?ft("\\",bt):_t[e]}return Dt[t]}var Pt=/* @__PURE__ */function(t){return t.Command="command",t.GroupOpen="groupOpen",t.GroupClose="groupClose",t.Superscript="superscript",t.Subscript="subscript",t.Prime="prime",t.Ampersand="ampersand",t.RowBreak="rowBreak",t.NbSpace="nbSpace",t.Number="number",t.Char="char",t}({}),qt=new Set(["{","}","%","$","#","&","_",",",":",";","!"," ","|","\\",".","/","'","~","^"]);function Rt(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}function Ft(t){return t>="0"&&t<="9"}function Ot(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function Tt(t,e,n){return{type:t,value:e,position:n}}function jt(t,e){const n=t[e+1];if(void 0!==n&&!Rt(n))return"\\"===n?Tt("rowBreak","\\",e):Tt("command",n,e);let i=e+1;for(;i<t.length;){const e=t[i];if(void 0===e||!Rt(e))break;i+=1}return Tt("command",t.slice(e+1,i),e)}function Mt(t,e){let n=e;for(;n<t.length;){const e=t[n];if(void 0===e||!Ft(e))break;n+=1}if("."===t[n]&&void 0!==t[n+1]&&Ft(t[n+1]??""))for(n+=1;n<t.length;){const e=t[n];if(void 0===e||!Ft(e))break;n+=1}return Tt("number",t.slice(e,n),e)}function Ht(t,e){switch(t){case"{":return Tt("groupOpen",t,e);case"}":return Tt("groupClose",t,e);case"^":return Tt("superscript",t,e);case"_":return Tt("subscript",t,e);case"'":return Tt("prime",t,e);case"&":return Tt("ampersand",t,e);case"~":return Tt("nbSpace",t,e);default:return Tt("char",t,e)}}function Gt(t,e){return{glyph:t,under:!1,stretchy:e}}function Ut(t,e){return{glyph:t,under:!0,stretchy:e}}var Kt={hat:Gt("^",!1),widehat:Gt("^",!0),check:Gt("ˇ",!1),tilde:Gt("~",!1),widetilde:Gt("~",!0),bar:Gt("‾",!1),overline:Gt("‾",!0),vec:Gt("→",!1),overrightarrow:Gt("→",!0),overleftarrow:Gt("←",!0),overleftrightarrow:Gt("↔",!0),dot:Gt("˙",!1),ddot:Gt("¨",!1),dddot:Gt("⃛",!1),acute:Gt("´",!1),grave:Gt("`",!1),breve:Gt("˘",!1),mathring:Gt("˚",!1),overbrace:Gt("⏞",!0),underline:Ut("_",!0),underbrace:Ut("⏟",!0),underrightarrow:Ut("→",!0),underleftarrow:Ut("←",!0)},Wt={matrix:{open:"",close:""},pmatrix:{open:"(",close:")"},bmatrix:{open:"[",close:"]"},Bmatrix:{open:"{",close:"}"},vmatrix:{open:"|",close:"|"},Vmatrix:{open:"‖",close:"‖"},cases:{open:"{",close:"",columnalign:"left"},aligned:{open:"",close:"",columnalign:"right left"},align:{open:"",close:"",columnalign:"right left"},gathered:{open:"",close:"",columnalign:"center"},smallmatrix:{open:"",close:""}};function Vt(t){return t.type===Pt.Command&&"end"===t.value}function Zt(t){return t.type===Pt.Ampersand||t.type===Pt.RowBreak||t.type===Pt.Command&&"end"===t.value}var Xt={",":"0.167em",":":"0.222em",";":"0.278em","!":"-0.167em"," ":"0.25em",quad:"1em",qquad:"2em",thinspace:"0.167em",medspace:"0.222em",thickspace:"0.278em",negthinspace:"-0.167em",negmedspace:"-0.222em",negthickspace:"-0.278em",enspace:"0.5em"};function Qt(t){return t in Xt}function Jt(t){const e=Xt[t];if(void 0!==e)return D({width:e})}function Yt(){return D({width:"0.25em"})}function te(t){const e=t.parseRawArgument();return(n=e)in Wt||"array"===n?function(t,e){"array"===t&&(e.parseOptionalArgument(),e.parseRawArgument());const n=function(t,e){const n=[];let i=[],a=[];const r=()=>{i.push(N(a.join(""))),a=[]},o=()=>{r(),n.push(i),i=[]};for(;;){const n=e.peek();if(void 0===n){e.error({message:`Unterminated environment \\begin{${t}}`});break}if(Vt(n)){e.next(),e.parseRawArgument();break}if(n.type===Pt.Ampersand){e.next(),r();continue}if(n.type===Pt.RowBreak){e.next(),o();continue}if(n.type===Pt.GroupClose){e.next(),e.error({message:"Unmatched brace",position:n.position});continue}const i=e.parseAtomsUntil(Zt);a.push(...i.map(t=>t.node))}return(a.length>0||i.length>0)&&o(),0===n.length&&n.push([""]),n}(t,e).map(t=>t.map(t=>t)),i=Wt[t]??{open:"",close:""},a=(r=n,o=i.columnalign?{columnalign:i.columnalign}:void 0,z("mtable",r.map(T).join(""),o));var r,o;return i.open||i.close?dt(N(`${i.open?B(i.open,{stretchy:!0,fence:!0}):""}${a}${i.close?B(i.close,{stretchy:!0,fence:!0}):""}`)):dt(a)}(e,t):(t.error({message:"Unknown environment",command:e}),dt(z("merror",I(e))));var n}function ee(t){return t.type===Pt.Command&&"right"===t.value}function ne(t){const e=t.next();return void 0===e?".":e.type===Pt.Command?`\\${e.value}`:e.value}function ie(t){return t&&""!==t.char?B(t.char,{fence:!0,stretchy:!0}):""}var ae={},re={"double-struck":{upperBase:120120,lowerBase:120146,digitBase:120792,holes:{C:8450,H:8461,N:8469,P:8473,Q:8474,R:8477,Z:8484}},script:{upperBase:119964,lowerBase:119990,holes:{B:8492,E:8496,F:8497,H:8459,I:8464,L:8466,M:8499,R:8475,e:8495,g:8458,o:8500}},fraktur:{upperBase:120068,lowerBase:120094,holes:{C:8493,H:8460,I:8465,R:8476,Z:8488}},bold:{upperBase:119808,lowerBase:119834,digitBase:120782,holes:ae},italic:{upperBase:119860,lowerBase:119886,holes:{h:8462}},"sans-serif":{upperBase:120224,lowerBase:120250,digitBase:120802,holes:ae},monospace:{upperBase:120432,lowerBase:120458,digitBase:120822,holes:ae}};function oe(t,e){if(1!==t.length)return null;const n=re[e],i=n.holes[t];return void 0!==i?String.fromCodePoint(i):function(t){return t>="A"&&t<="Z"}(t)?String.fromCodePoint(n.upperBase+(t.charCodeAt(0)-65)):function(t){return t>="a"&&t<="z"}(t)?String.fromCodePoint(n.lowerBase+(t.charCodeAt(0)-97)):function(t){return t>="0"&&t<="9"}(t)&&void 0!==n.digitBase?String.fromCodePoint(n.digitBase+(t.charCodeAt(0)-48)):null}var le=/<(mi|mn)>([^<]*)<\/\1>/g,se=/<mi>([^<]*)<\/mi>/g;var ce={mathbb:"double-struck",mathcal:"script",mathscr:"script",mathfrak:"fraktur",mathbf:"bold",mathit:"italic",mathsf:"sans-serif",mathtt:"monospace"},pe={boldsymbol:"bold-italic",bm:"bold-italic"},ue={text:void 0,textnormal:"normal",textrm:"normal",textbf:"bold",textit:"italic",textsf:"sans-serif",texttt:"monospace",mbox:void 0};function de(t,e){if("operatorname"===t)return dt(_(e.parseRawArgument(),{mathvariant:"normal"}));if(t in ue){const n=ue[t],i=e.parseRawArgument();return dt(n?I(i,{mathvariant:n}):I(i))}const n=ce[t];if(void 0!==n)return dt((i=e.parseArgument(),a=n,i.replace(le,(t,e,n)=>{const i=function(t,e){let n="";for(const i of t)n+=oe(i,e)??i;return n}(n,a);return"mn"===e?E(i):_(i)})));var i,a;if("mathrm"===t)return dt(e.parseArgument().replace(se,(t,e)=>_(e,{mathvariant:"normal"})));const r=pe[t],o=e.parseArgument();return dt(void 0===r?o:z("mstyle",o,{mathvariant:r}))}var me=new Set(["frac","dfrac","tfrac","cfrac"]),he=new Set(["binom","dbinom","tbinom","choose"]),fe=new Set(["overset","underset","stackrel"]);var be=new Set(["∫","∬","∭","∮"]);var ge=class{source;tokens;pos=0;depth=0;depthExceeded=!1;errors=[];display;constructor(t,e,n){this.source=t,this.tokens=e,this.display=n}get collectedErrors(){return this.errors}peek(){return this.tokens[this.pos]}next(){const t=this.tokens[this.pos];return void 0!==t&&(this.pos+=1),t}error(t){this.errors.push(t)}parseTopLevel(){const t=[];for(;;){const e=this.peek();if(void 0===e)break;if(e.type===Pt.GroupClose){this.next(),this.error({message:"Unmatched brace",position:e.position});continue}const n=this.parseAtomWithScripts();void 0!==n&&t.push(n)}return t}parseExpression(t){const e=[];for(;;){const n=this.peek();if(void 0===n||t(n))break;if(n.type===Pt.GroupClose)break;const i=this.parseAtomWithScripts();void 0!==i&&e.push(i)}return e}parseAtomsUntil(t){return this.parseExpression(t)}parseAtomWithScripts(){const t=this.parseBaseAtom();if(void 0!==t)return this.attachScripts(t)}attachScripts(t){let e,n,i,a="";for(;;){const t=this.peek();if(void 0===t)break;if(t.type!==Pt.Prime)if(t.type!==Pt.Command||"limits"!==t.value)if(t.type!==Pt.Command||"nolimits"!==t.value)if(t.type!==Pt.Superscript){if(t.type!==Pt.Subscript)break;this.next(),e=this.combineSub(e,this.parseArgument())}else this.next(),n=this.combineSup(n,this.parseArgument());else this.next(),i="nolimits";else this.next(),i="limits";else this.next(),a+="′"}return a&&(n=void 0===n?B(a):N(`${B(a)}${n}`)),void 0===e&&void 0===n?t:dt(this.buildScripts(t,e,n,i))}combineSup(t,e){return void 0===t?e:(this.error({message:"Double superscript"}),N(`${t}${e}`))}combineSub(t,e){return void 0===t?e:(this.error({message:"Double subscript"}),N(`${t}${e}`))}buildScripts(t,e,n,i){const a=!0===t.bigOp&&!0!==t.intLike&&this.display;if("limits"===i||"nolimits"!==i&&a){if(void 0!==e&&void 0!==n)return function(t,e,n){return z("munderover",`${t}${e}${n}`)}(t.node,e,n);if(void 0!==e)return F(t.node,e);if(void 0!==n)return R(t.node,n)}return void 0!==e&&void 0!==n?function(t,e,n){return z("msubsup",`${t}${e}${n}`)}(t.node,e,n):void 0!==e?function(t,e){return z("msub",`${t}${e}`)}(t.node,e):void 0!==n?function(t,e){return z("msup",`${t}${e}`)}(t.node,n):t.node}parseBaseAtom(){if(this.depth>=256)return this.bailDeepNesting();this.depth+=1;try{return this.parseBaseAtomInner()}finally{this.depth-=1}}bailDeepNesting(){const t=this.next();if(void 0!==t&&!this.depthExceeded)return this.depthExceeded=!0,this.error({message:"Maximum nesting depth exceeded",position:t.position}),dt(z("merror",I("⋯")))}parseBaseAtomInner(){const t=this.next();if(void 0!==t)switch(t.type){case Pt.Number:return dt(E(t.value));case Pt.Char:return this.parseChar(t.value);case Pt.GroupOpen:return this.parseGroup();case Pt.NbSpace:return dt(Yt());case Pt.Command:return this.parseCommand(t);case Pt.Superscript:case Pt.Subscript:case Pt.Prime:return this.pos-=1,this.attachScripts(dt(N("")));case Pt.Ampersand:case Pt.RowBreak:case Pt.GroupClose:default:return}}parseGroup(){const t=this.parseExpression(()=>!1);return this.expect(Pt.GroupClose),dt(P(t.map(t=>t.node)))}parseChar(t){const e=Nt(t);return!e||e.kind!==ht.Open&&e.kind!==ht.Close?dt("+"===t||"-"===t||"*"===t||"="===t||"/"===t||"|"===t||","===t||";"===t||"."===t||":"===t||"!"===t||"?"===t||"<"===t||">"===t?B(t):_(t)):dt(B(t,{fence:!0}),e.kind)}parseCommand(t){const e=t.value,n=function(t){return It[t]}(e);if(n)return this.symbolAtom(n);if(1===(i=e).length&&qt.has(i))return this.controlSymbolAtom(e);var i;const a=this.dispatchStructural(e);if(void 0!==a)return a;const r=this.dispatchSpecial(e,t);return void 0!==r?r:(this.error({message:"Unknown command",command:`\\${e}`,position:t.position}),dt(z("merror",I(`\\${e}`))))}dispatchStructural(t){if(function(t){return me.has(t)}(t))return dt(q((e=this).parseArgument(),e.parseArgument()));var e;if(function(t){return he.has(t)}(t))return function(t){const e=q(t.parseArgument(),t.parseArgument(),{linethickness:0});return dt(N(`${B("(",{fence:!0})}${e}${B(")",{fence:!0})}`))}(this);if("sqrt"===t)return function(t){const e=t.parseOptionalArgument(),n=t.parseArgument();return dt(void 0===e||""===e?function(t){return z("msqrt",t)}(n):function(t,e){return z("mroot",`${t}${e}`)}(n,e))}(this);if(function(t){return fe.has(t)}(t))return function(t,e){const n=e.parseArgument(),i=e.parseArgument();return dt("underset"===t?F(i,n):R(i,n))}(t,this);if(function(t){return t in Kt}(t))return function(t,e){const n=Kt[t];if(!n)return dt("");const i=e.parseArgument(),a=B(n.glyph,{stretchy:n.stretchy}),r=n.under?{accentunder:!0}:{accent:!0};return dt(n.under?F(i,a,r):R(i,a,r))}(t,this);if(function(t){return t in ce||t in pe||t in ue||"mathrm"===t||"operatorname"===t}(t))return de(t,this);if(Qt(t)){const e=Jt(t);return void 0===e?void 0:dt(e)}}dispatchSpecial(t,e){return"left"===t?function(t){const e=Nt(ne(t)),n=t.parseAtomsUntil(ee),i=t.peek();let a=".";void 0!==i&&ee(i)?(t.next(),a=ne(t)):t.error({message:"Unmatched \\left"});const r=Nt(a),o=ie(e),l=ie(r);return dt(P([o,...n.map(t=>t.node),l]))}(this):"begin"===t?te(this):"pmod"===t?function(t){const e=t.parseArgument(),n=B("(",{fence:!0}),i=B(")",{fence:!0});return dt(N(`${n}${I("mod")}${Yt()}${e}${i}`))}(this):"bmod"===t||"mod"===t?dt(B("mod",{lspace:"0.222em",rspace:"0.222em"})):"substack"===t?function(t){!function(t){const e=t.peek();void 0!==e&&e.type===Pt.GroupOpen&&t.next()}(t);const e=[];let n=[];for(;;){const i=t.peek();if(void 0===i||i.type===Pt.GroupClose)break;if(i.type===Pt.RowBreak){t.next(),e.push(P(n)),n=[];continue}const a=t.parseAtomsUntil(t=>t.type===Pt.RowBreak);n.push(...a.map(t=>t.node))}return function(t){const e=t.peek();void 0!==e&&e.type===Pt.GroupClose&&t.next()}(t),e.push(P(n)),dt(z("mtable",e.map(t=>z("mtr",z("mtd",t))).join("")))}(this):"right"===t?(n=e.position,ne(this),this.error({message:"Unmatched \\right",position:n}),dt(P([]))):void 0;var n}symbolAtom(t){switch(t.kind){case ht.Ordinary:return dt(_(t.char),t.kind);case ht.Function:return dt(_(t.char,{mathvariant:"normal"}),t.kind);case ht.BigOp:return this.bigOperator(t);case ht.Open:case ht.Close:return dt(B(t.char,{fence:!0}),t.kind);default:return dt(B(t.char),t.kind)}}bigOperator(t){if(/[a-z]/i.test(t.char))return mt(B(t.char,{movablelimits:!0}),t.kind);const e=be.has(t.char);return mt(B(t.char,{movablelimits:!0,largeop:!0}),t.kind,e)}controlSymbolAtom(t){if(Qt(t)){const e=Jt(t);return void 0===e?void 0:dt(e)}return"{"===t?dt(B("{",{fence:!0}),ht.Open):"}"===t?dt(B("}",{fence:!0}),ht.Close):dt("|"===t?B("‖"):"\\"===t?B("\\"):"/"===t?B("/"):"'"===t?B("′"):"."===t?B("."):I(t))}parseArgument(){return""===(t=this.parseArgumentRaw())?N(""):t;var t}parseArgumentRaw(){const t=this.peek();if(void 0===t)return"";if(t.type===Pt.GroupOpen){this.next();const t=this.parseExpression(()=>!1);return this.expect(Pt.GroupClose),P(t.map(t=>t.node))}return this.parseBaseAtom()?.node??""}parseOptionalArgument(){const t=this.peek();if(void 0===t||t.type!==Pt.Char||"["!==t.value)return;this.next();const e=this.parseExpression(t=>t.type===Pt.Char&&"]"===t.value),n=this.peek();return void 0!==n&&n.type===Pt.Char&&"]"===n.value&&this.next(),P(e.map(t=>t.node))}parseRawArgument(){const t=this.peek();if(void 0===t)return"";if(t.type!==Pt.GroupOpen)return this.next(),t.value;const e=t.position;this.next();let n=1,i=this.source.length;for(;;){const t=this.next();if(void 0===t)break;if(t.type===Pt.GroupOpen)n+=1;else if(t.type===Pt.GroupClose&&(n-=1,0===n)){i=t.position;break}}return this.source.slice(e+1,i)}expect(t){const e=this.peek();void 0===e||e.type!==t?t===Pt.GroupClose&&this.error({message:"Unmatched brace"}):this.next()}},ve="<mrow></mrow>";function xe(t,e){const n=e?.display??!1;if(""===t.trim())return{presentation:ve,errors:[]};const{atoms:i,errors:a}=function(t,e){const n=new ge(t,function(t){const e=[];let n=0;for(;n<t.length;){const i=t[n]??"";if("\\"===i){const i=jt(t,n);if(e.push(i),n+="rowBreak"===i.type?2:Math.max(1,i.value.length)+1,"command"===i.type&&Rt(i.value[0]??""))for(;n<t.length&&Ot(t[n]??"");)n+=1;continue}if(Ft(i)){const i=Mt(t,n);e.push(i),n+=i.value.length;continue}if(Ot(i)){n+=1;continue}const a=Ht(i,n);a&&e.push(a),n+=1}return e}(t),e);return{atoms:n.parseTopLevel(),errors:n.collectedErrors}}(t,n);return{presentation:ye(i),errors:a}}function ye(t){if(0===t.length)return ve;if(1===t.length){const e=t[0];return e?e.node:ve}return N(t.map(t=>t.node).join(""))}var we=/(?<!\$)\$([^$\n]+)\$$/,Le=/\$\$([^$\n]+)\$\$$/;function ke(t,e){const n=t.getBlock(e);return void 0!==n&&"code_block"!==n.type}function Se(t,e){const n=t-e;return n<0?null:{from:n,to:t}}var Ce={insertInline:"Insert formula",insertInlineTooltip:"Insert inline formula",editFormula:"Edit formula",latexLabel:"LaTeX",latexPlaceholder:"e.g. \\frac{a}{b} + \\sqrt{x}",previewLabel:"Preview",insertButton:"Insert",updateButton:"Update",cancelButton:"Cancel",displayToggle:"Display (block) equation",sizeLabel:"Size",sizeDefault:"Default",altLabel:"Description",altPlaceholder:"Spoken description (optional)",paletteLabel:"Symbols and structures",emptyPreview:"Nothing to preview yet.",inserted:"Formula inserted.",updated:"Formula updated.",editing:"Editing formula.",selected:"Formula selected. Press Enter to edit.",unknownCommand:t=>`Unknown LaTeX command: ${t}`,groupFractions:"Fractions",groupScripts:"Scripts",groupRoots:"Roots",groupAccents:"Accents",groupOperators:"Operators",groupFunctions:"Functions",groupGreek:"Greek letters",groupRelations:"Relations",groupSets:"Sets",groupLogic:"Logic",groupArrows:"Arrows",groupDelimiters:"Brackets",groupDots:"Dots",groupMatrices:"Matrices"},Ae=/* #__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar-D1jFXqLJ.mjs"),"./locales/de.ts":()=>import("./de-DY3obIAF.mjs"),"./locales/es.ts":()=>import("./es-CtOtKQCP.mjs"),"./locales/fr.ts":()=>import("./fr-DjMZ-3K5.mjs"),"./locales/hi.ts":()=>import("./hi-4CiAKVjT.mjs"),"./locales/pt.ts":()=>import("./pt-BkpVtod-.mjs"),"./locales/ru.ts":()=>import("./ru-BotG0MFT.mjs"),"./locales/zh.ts":()=>import("./zh-CWGAPVei.mjs")});async function $e(t){return x(Ae,t,Ce)}var ze=class{root;buttons=[];activeIndex=0;constructor(t,e,n){this.root=document.createElement("div"),this.root.className="notectl-math-palette",this.root.setAttribute("role","toolbar"),this.root.setAttribute("aria-label",e);for(const i of t)this.root.appendChild(this.buildGroup(i,n));this.root.addEventListener("keydown",t=>this.onKeydown(t)),this.setActive(0)}focus(){this.buttons[this.activeIndex]?.focus()}activeButton(){return this.buttons[this.activeIndex]}buildGroup(t,e){const n=document.createElement("div");n.className="notectl-math-palette__group",n.setAttribute("role","group"),n.setAttribute("aria-label",t.label);for(const i of t.items){const t=document.createElement("button");t.type="button",t.className="notectl-math-palette__btn",t.textContent=i.label,t.setAttribute("aria-label",i.ariaLabel),t.tabIndex=-1,t.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),t.addEventListener("click",()=>e(i.snippet)),this.buttons.push(t),n.appendChild(t)}return n}onKeydown(t){if("Enter"===t.key||" "===t.key)return t.preventDefault(),t.stopPropagation(),void this.buttons[this.activeIndex]?.click();const e=this.buttons.length-1;let n=this.activeIndex;switch(t.key){case"ArrowRight":case"ArrowDown":n=this.activeIndex>=e?0:this.activeIndex+1;break;case"ArrowLeft":case"ArrowUp":n=this.activeIndex<=0?e:this.activeIndex-1;break;case"Home":n=0;break;case"End":n=e;break;default:return}t.preventDefault(),t.stopPropagation(),this.setActive(n),this.buttons[n]?.focus()}setActive(t){const e=this.buttons[this.activeIndex];e&&(e.tabIndex=-1);const n=this.buttons[t];n&&(n.tabIndex=0),this.activeIndex=t}},_e=0,Ee=class{root;options;textarea;preview;previewEmpty;errorsList;altInput;commitBtn;palette=null;displayCheckbox=null;cancelBtn=null;fontSizeSelect=null;display;lastErrorKey="";constructor(t){this.options=t,this.display=t.initialDisplay??!1;const e=++_e;this.root=document.createElement("div"),this.root.className="notectl-formula-editor",this.root.setAttribute("role","group"),this.root.setAttribute("aria-label",t.locale.latexLabel),t.palette&&t.palette.length>0&&(this.palette=new ze(t.palette,t.locale.paletteLabel,t=>this.insertSnippet(t)),this.root.appendChild(this.palette.root)),this.textarea=this.buildLatexField(e),this.preview=document.createElement("div"),this.previewEmpty=document.createElement("div"),this.errorsList=document.createElement("ul"),this.altInput=this.buildAltField(e),this.commitBtn=document.createElement("button"),this.root.appendChild(this.buildPreview()),this.root.appendChild(this.errorsList),this.root.appendChild(this.altInput.parentElement),t.fontSizes&&t.fontSizes.length>0&&this.root.appendChild(this.buildSizeField(e)),"insert"===t.mode&&this.root.appendChild(this.buildDisplayToggle(e)),this.root.appendChild(this.buildActions()),this.errorsList.className="notectl-formula-editor__errors",this.errorsList.id=`notectl-formula-errors-${e}`,this.errorsList.setAttribute("aria-live","polite"),this.textarea.setAttribute("aria-describedby",this.errorsList.id),this.root.addEventListener("keydown",t=>this.onRootKeydown(t)),this.update()}focus(){this.textarea.focus(),this.textarea.setSelectionRange(this.textarea.value.length,this.textarea.value.length)}onRootKeydown(t){if("Escape"===t.key)return t.preventDefault(),t.stopPropagation(),void this.options.onCancel();"Tab"===t.key&&(t.preventDefault(),t.stopPropagation(),this.moveFocus(!t.shiftKey))}focusStops(){const t=[],e=this.palette?.activeButton();return e&&t.push(e),t.push(this.textarea,this.altInput),this.fontSizeSelect&&t.push(this.fontSizeSelect),this.displayCheckbox&&t.push(this.displayCheckbox),this.cancelBtn&&t.push(this.cancelBtn),t.push(this.commitBtn),t}moveFocus(t){const e=this.focusStops();if(0===e.length)return;const n=this.activeElement();let i=e.findIndex(t=>t===n);-1===i&&n&&this.palette?.root.contains(n)&&(i=0),-1===i&&(i=t?e.length-1:0),e[(i+(t?1:-1)+e.length)%e.length]?.focus()}activeElement(){let t=this.root.getRootNode().activeElement;for(;t?.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t}getResult(){const t=this.textarea.value.trim(),e=this.altInput.value.trim(),{presentation:n}=xe(t,{display:this.display});return{latex:t,mathml:M({presentation:n,latex:t,display:this.display,alt:e||void 0}),alt:e,display:this.display,fontSize:this.fontSizeSelect?.value??""}}insertSnippet(t){const e=this.textarea.selectionStart??this.textarea.value.length,n=this.textarea.selectionEnd??e,i=t.indexOf("$0"),a=i>=0?t.replace("$0",""):t,r=i>=0?i:a.length,o=this.textarea.value;this.textarea.value=o.slice(0,e)+a+o.slice(n);const l=e+r;this.textarea.focus(),this.textarea.setSelectionRange(l,l),this.update()}buildLatexField(t){const e=document.createElement("div");e.className="notectl-formula-editor__field";const n=document.createElement("label");n.className="notectl-formula-editor__label",n.htmlFor=`notectl-formula-latex-${t}`,n.textContent=this.options.locale.latexLabel;const i=document.createElement("textarea");return i.id=`notectl-formula-latex-${t}`,i.className="notectl-formula-editor__input",i.placeholder=this.options.locale.latexPlaceholder,i.rows=2,i.spellcheck=!1,i.value=this.options.initialLatex??"",i.addEventListener("input",()=>this.update()),i.addEventListener("keydown",t=>this.onTextareaKeydown(t)),e.appendChild(n),e.appendChild(i),this.root.appendChild(e),i}buildPreview(){const t=document.createElement("div");t.className="notectl-formula-editor__field";const e=document.createElement("span");return e.className="notectl-formula-editor__label",e.textContent=this.options.locale.previewLabel,this.preview.className="notectl-formula-editor__preview",this.previewEmpty.className="notectl-formula-editor__preview-empty",this.previewEmpty.textContent=this.options.locale.emptyPreview,t.appendChild(e),t.appendChild(this.previewEmpty),t.appendChild(this.preview),t}buildAltField(t){const e=document.createElement("div");e.className="notectl-formula-editor__field";const n=document.createElement("label");n.className="notectl-formula-editor__label",n.htmlFor=`notectl-formula-alt-${t}`,n.textContent=this.options.locale.altLabel;const i=document.createElement("input");return i.id=`notectl-formula-alt-${t}`,i.type="text",i.className="notectl-formula-editor__alt",i.placeholder=this.options.locale.altPlaceholder,i.value=this.options.initialAlt??"",e.appendChild(n),e.appendChild(i),i}buildSizeField(t){const e=document.createElement("div");e.className="notectl-formula-editor__field";const n=document.createElement("label");n.className="notectl-formula-editor__label",n.htmlFor=`notectl-formula-size-${t}`,n.textContent=this.options.locale.sizeLabel;const i=document.createElement("select");i.id=`notectl-formula-size-${t}`,i.className="notectl-formula-editor__size";const a=this.options.initialFontSize??"";i.appendChild(this.buildSizeOption("",this.options.locale.sizeDefault));for(const r of this.options.fontSizes??[])i.appendChild(this.buildSizeOption(`${r}px`,String(r)));return a&&!Array.from(i.options).some(t=>t.value===a)&&i.appendChild(this.buildSizeOption(a,a.replace("px",""))),i.value=a,i.addEventListener("change",()=>this.applyPreviewFontSize()),this.fontSizeSelect=i,e.appendChild(n),e.appendChild(i),e}buildSizeOption(t,e){const n=document.createElement("option");return n.value=t,n.textContent=e,n}applyPreviewFontSize(){this.preview.style.fontSize=this.fontSizeSelect?.value||""}buildDisplayToggle(t){const e=document.createElement("label");e.className="notectl-formula-editor__toggle",e.htmlFor=`notectl-formula-display-${t}`;const n=document.createElement("input");n.id=`notectl-formula-display-${t}`,n.type="checkbox",n.checked=this.display,n.addEventListener("change",()=>{this.display=n.checked,this.update()}),this.displayCheckbox=n;const i=document.createElement("span");return i.textContent=this.options.locale.displayToggle,e.appendChild(n),e.appendChild(i),e}buildActions(){const t=document.createElement("div");t.className="notectl-formula-editor__actions";const e=document.createElement("button");return e.type="button",e.className="notectl-formula-editor__btn",e.textContent=this.options.locale.cancel,e.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),e.addEventListener("click",()=>this.options.onCancel()),this.cancelBtn=e,this.commitBtn.type="button",this.commitBtn.className="notectl-formula-editor__btn notectl-formula-editor__btn--primary",this.commitBtn.textContent="edit"===this.options.mode?this.options.locale.commitUpdate:this.options.locale.commitInsert,this.commitBtn.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),this.commitBtn.addEventListener("click",()=>this.commit()),t.appendChild(e),t.appendChild(this.commitBtn),t}onTextareaKeydown(t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.commit())}commit(){const t=this.getResult();t.latex?this.options.onCommit(t):this.options.onCancel()}update(){this.applyPreviewFontSize();const t=this.textarea.value.trim();if(!t)return this.preview.innerHTML="",this.previewEmpty.hidden=!1,void this.renderErrors([]);this.previewEmpty.hidden=!0;const{presentation:e,errors:n}=xe(t,{display:this.display});this.preview.innerHTML=M({presentation:e,display:this.display}),this.renderErrors(n.map(t=>t.command??t.message))}renderErrors(t){const e=t.join("");if(e!==this.lastErrorKey){this.lastErrorKey=e,this.errorsList.replaceChildren();for(const e of t){const t=document.createElement("li");t.textContent=e.startsWith("\\")?this.options.locale.unknownCommand(e):e,this.errorsList.appendChild(t)}}}};function Be(t){return[{id:"fractions",label:(e={fractions:t.groupFractions,scripts:t.groupScripts,roots:t.groupRoots,accents:t.groupAccents,operators:t.groupOperators,functions:t.groupFunctions,greek:t.groupGreek,relations:t.groupRelations,sets:t.groupSets,logic:t.groupLogic,arrows:t.groupArrows,delimiters:t.groupDelimiters,dots:t.groupDots,matrices:t.groupMatrices}).fractions,items:[{label:"a╱b",ariaLabel:"Fraction",snippet:"\\frac{$0}{}"},{label:"⒞",ariaLabel:"Binomial coefficient",snippet:"\\binom{$0}{}"}]},{id:"scripts",label:e.scripts,items:[{label:"xⁿ",ariaLabel:"Superscript",snippet:"^{$0}"},{label:"xₙ",ariaLabel:"Subscript",snippet:"_{$0}"},{label:"xⁿₘ",ariaLabel:"Subscript and superscript",snippet:"_{$0}^{}"}]},{id:"roots",label:e.roots,items:[{label:"√",ariaLabel:"Square root",snippet:"\\sqrt{$0}"},{label:"ⁿ√",ariaLabel:"N-th root",snippet:"\\sqrt[$0]{}"}]},{id:"accents",label:e.accents,items:[{label:"→",ariaLabel:"Vector",snippet:"\\vec{$0}"},{label:"â",ariaLabel:"Hat",snippet:"\\hat{$0}"},{label:"ā",ariaLabel:"Overline",snippet:"\\overline{$0}"},{label:"ȧ",ariaLabel:"Dot above",snippet:"\\dot{$0}"},{label:"ã",ariaLabel:"Tilde",snippet:"\\tilde{$0}"}]},{id:"operators",label:e.operators,items:[{label:"∑",ariaLabel:"Sum with limits",snippet:"\\sum_{$0}^{}"},{label:"∏",ariaLabel:"Product with limits",snippet:"\\prod_{$0}^{}"},{label:"∫",ariaLabel:"Integral with limits",snippet:"\\int_{$0}^{}"},{label:"∬",ariaLabel:"Double integral",snippet:"\\iint "},{label:"∮",ariaLabel:"Contour integral",snippet:"\\oint "},{label:"lim",ariaLabel:"Limit",snippet:"\\lim_{$0}"},{label:"∂",ariaLabel:"Partial derivative",snippet:"\\partial "},{label:"∇",ariaLabel:"Nabla (del)",snippet:"\\nabla "},{label:"×",ariaLabel:"Times",snippet:"\\times "},{label:"·",ariaLabel:"Dot product",snippet:"\\cdot "},{label:"±",ariaLabel:"Plus or minus",snippet:"\\pm "},{label:"÷",ariaLabel:"Division",snippet:"\\div "},{label:"∞",ariaLabel:"Infinity",snippet:"\\infty "}]},{id:"functions",label:e.functions,items:[{label:"sin",ariaLabel:"Sine",snippet:"\\sin "},{label:"cos",ariaLabel:"Cosine",snippet:"\\cos "},{label:"tan",ariaLabel:"Tangent",snippet:"\\tan "},{label:"log",ariaLabel:"Logarithm",snippet:"\\log "},{label:"ln",ariaLabel:"Natural logarithm",snippet:"\\ln "},{label:"exp",ariaLabel:"Exponential function",snippet:"\\exp "}]},{id:"greek",label:e.greek,items:[{label:"α",ariaLabel:"Alpha",snippet:"\\alpha "},{label:"β",ariaLabel:"Beta",snippet:"\\beta "},{label:"γ",ariaLabel:"Gamma",snippet:"\\gamma "},{label:"δ",ariaLabel:"Delta",snippet:"\\delta "},{label:"ε",ariaLabel:"Epsilon",snippet:"\\varepsilon "},{label:"ζ",ariaLabel:"Zeta",snippet:"\\zeta "},{label:"η",ariaLabel:"Eta",snippet:"\\eta "},{label:"θ",ariaLabel:"Theta",snippet:"\\theta "},{label:"κ",ariaLabel:"Kappa",snippet:"\\kappa "},{label:"λ",ariaLabel:"Lambda",snippet:"\\lambda "},{label:"μ",ariaLabel:"Mu",snippet:"\\mu "},{label:"ν",ariaLabel:"Nu",snippet:"\\nu "},{label:"ξ",ariaLabel:"Xi",snippet:"\\xi "},{label:"π",ariaLabel:"Pi",snippet:"\\pi "},{label:"ρ",ariaLabel:"Rho",snippet:"\\rho "},{label:"σ",ariaLabel:"Sigma",snippet:"\\sigma "},{label:"τ",ariaLabel:"Tau",snippet:"\\tau "},{label:"φ",ariaLabel:"Phi",snippet:"\\varphi "},{label:"χ",ariaLabel:"Chi",snippet:"\\chi "},{label:"ψ",ariaLabel:"Psi",snippet:"\\psi "},{label:"ω",ariaLabel:"Omega",snippet:"\\omega "},{label:"Γ",ariaLabel:"Capital gamma",snippet:"\\Gamma "},{label:"Δ",ariaLabel:"Capital delta",snippet:"\\Delta "},{label:"Θ",ariaLabel:"Capital theta",snippet:"\\Theta "},{label:"Λ",ariaLabel:"Capital lambda",snippet:"\\Lambda "},{label:"Π",ariaLabel:"Capital pi",snippet:"\\Pi "},{label:"Σ",ariaLabel:"Capital sigma",snippet:"\\Sigma "},{label:"Φ",ariaLabel:"Capital phi",snippet:"\\Phi "},{label:"Ψ",ariaLabel:"Capital psi",snippet:"\\Psi "},{label:"Ω",ariaLabel:"Capital omega",snippet:"\\Omega "}]},{id:"relations",label:e.relations,items:[{label:"≤",ariaLabel:"Less than or equal to",snippet:"\\leq "},{label:"≥",ariaLabel:"Greater than or equal to",snippet:"\\geq "},{label:"≠",ariaLabel:"Not equal to",snippet:"\\neq "},{label:"≈",ariaLabel:"Approximately equal to",snippet:"\\approx "},{label:"≡",ariaLabel:"Equivalent to",snippet:"\\equiv "},{label:"∼",ariaLabel:"Similar to",snippet:"\\sim "},{label:"≅",ariaLabel:"Congruent to",snippet:"\\cong "},{label:"∝",ariaLabel:"Proportional to",snippet:"\\propto "}]},{id:"sets",label:e.sets,items:[{label:"∈",ariaLabel:"Element of",snippet:"\\in "},{label:"∉",ariaLabel:"Not an element of",snippet:"\\notin "},{label:"⊂",ariaLabel:"Subset of",snippet:"\\subset "},{label:"⊆",ariaLabel:"Subset of or equal to",snippet:"\\subseteq "},{label:"∪",ariaLabel:"Union",snippet:"\\cup "},{label:"∩",ariaLabel:"Intersection",snippet:"\\cap "},{label:"∅",ariaLabel:"Empty set",snippet:"\\emptyset "},{label:"ℝ",ariaLabel:"Real numbers",snippet:"\\mathbb{R}"},{label:"ℕ",ariaLabel:"Natural numbers",snippet:"\\mathbb{N}"},{label:"ℤ",ariaLabel:"Integers",snippet:"\\mathbb{Z}"},{label:"ℚ",ariaLabel:"Rational numbers",snippet:"\\mathbb{Q}"},{label:"ℂ",ariaLabel:"Complex numbers",snippet:"\\mathbb{C}"}]},{id:"logic",label:e.logic,items:[{label:"∀",ariaLabel:"For all",snippet:"\\forall "},{label:"∃",ariaLabel:"There exists",snippet:"\\exists "},{label:"¬",ariaLabel:"Logical not",snippet:"\\neg "},{label:"∧",ariaLabel:"Logical and",snippet:"\\land "},{label:"∨",ariaLabel:"Logical or",snippet:"\\lor "},{label:"⟹",ariaLabel:"Implies",snippet:"\\implies "},{label:"⟺",ariaLabel:"If and only if",snippet:"\\iff "}]},{id:"arrows",label:e.arrows,items:[{label:"→",ariaLabel:"Right arrow",snippet:"\\to "},{label:"⇒",ariaLabel:"Rightwards double arrow",snippet:"\\Rightarrow "},{label:"↔",ariaLabel:"Left-right arrow",snippet:"\\leftrightarrow "},{label:"↦",ariaLabel:"Maps to",snippet:"\\mapsto "}]},{id:"delimiters",label:e.delimiters,items:[{label:"( )",ariaLabel:"Auto-sized parentheses",snippet:"\\left($0\\right)"},{label:"[ ]",ariaLabel:"Auto-sized brackets",snippet:"\\left[$0\\right]"},{label:"{ }",ariaLabel:"Auto-sized braces",snippet:"\\left\\{$0\\right\\}"},{label:"|x|",ariaLabel:"Absolute value",snippet:"\\left|$0\\right|"},{label:"‖x‖",ariaLabel:"Norm",snippet:"\\left\\|$0\\right\\|"},{label:"⌊x⌋",ariaLabel:"Floor",snippet:"\\left\\lfloor $0\\right\\rfloor"},{label:"⌈x⌉",ariaLabel:"Ceiling",snippet:"\\left\\lceil $0\\right\\rceil"}]},{id:"dots",label:e.dots,items:[{label:"⋯",ariaLabel:"Centred ellipsis",snippet:"\\cdots "},{label:"…",ariaLabel:"Baseline ellipsis",snippet:"\\ldots "},{label:"⋮",ariaLabel:"Vertical ellipsis",snippet:"\\vdots "},{label:"⋱",ariaLabel:"Diagonal ellipsis",snippet:"\\ddots "}]},{id:"matrices",label:e.matrices,items:[{label:"[ ]",ariaLabel:"Bracket matrix",snippet:"\\begin{bmatrix} $0 & \\\\ & \\end{bmatrix}"},{label:"( )",ariaLabel:"Parenthesis matrix",snippet:"\\begin{pmatrix} $0 & \\\\ & \\end{pmatrix}"},{label:"{",ariaLabel:"Cases",snippet:"\\begin{cases} $0 & \\\\ & \\end{cases}"}]}];var e}function Ie(t,e){const n=new Ee({locale:(i=e.locale,{latexLabel:i.latexLabel,latexPlaceholder:i.latexPlaceholder,previewLabel:i.previewLabel,emptyPreview:i.emptyPreview,altLabel:i.altLabel,altPlaceholder:i.altPlaceholder,displayToggle:i.displayToggle,sizeLabel:i.sizeLabel,sizeDefault:i.sizeDefault,commitInsert:i.insertButton,commitUpdate:i.updateButton,cancel:i.cancelButton,paletteLabel:i.paletteLabel,unknownCommand:i.unknownCommand}),mode:e.mode,initialLatex:e.initialLatex,initialAlt:e.initialAlt,initialDisplay:e.initialDisplay,initialFontSize:e.initialFontSize,fontSizes:e.fontSizes,palette:Be(e.locale),onCommit:e.onCommit,onCancel:e.onClose});var i;return t.appendChild(n.root),requestAnimationFrame(()=>n.focus()),n}var De=class{context;locale;fontSizes;panel=null;outsideHandler=null;constructor(t,e,n){this.context=t,this.locale=e,this.fontSizes=n}isOpen(){return null!==this.panel}openInsert(t){if(this.context.isReadOnly())return;const e=Ne();this.open({rect:e,mode:"insert",initialDisplay:t,onCommit:t=>{ut(this.context,this.locale,t),this.close(!0)}})}openEdit(t){this.context.isReadOnly()||(this.context.announce(this.locale.editing),this.open({rect:t.rect??Ne(),mode:"edit",initialLatex:t.latex,initialAlt:t.alt,initialDisplay:"display"===t.kind,initialFontSize:t.fontSize,onCommit:e=>{this.commitEdit(t,e),this.context.announce(this.locale.updated),this.close(!0)}}))}close(t){this.panel&&(this.outsideHandler&&(document.removeEventListener("mousedown",this.outsideHandler,!0),this.outsideHandler=null),this.panel.remove(),this.panel=null,t&&this.context.getContainer().focus())}commitEdit(t,e){const n=pt(e);"inline"===t.kind&&t.blockId&&void 0!==t.offset?function(t,e,n,i){const a=t.getState().transaction("command").setInlineNodeAttr(e,n,lt(i)).build();t.dispatch(a)}(this.context,t.blockId,t.offset,n):"display"===t.kind&&t.path&&function(t,e,n){const i=t.getState().transaction("command").setNodeAttr(e,lt(n)).build();t.dispatch(i)}(this.context,t.path,n)}open(t){this.close(!1);const e=document.createElement("div");e.className="notectl-formula-overlay",e.setAttribute("role","dialog"),e.setAttribute("aria-label","edit"===t.mode?this.locale.editFormula:this.locale.insertInline),this.panel=e,Ie(e,{context:this.context,locale:this.locale,mode:t.mode,initialLatex:t.initialLatex,initialAlt:t.initialAlt,initialDisplay:t.initialDisplay,initialFontSize:t.initialFontSize,fontSizes:this.fontSizes,onCommit:t.onCommit,onClose:()=>this.close(!0)}),this.context.getPluginContainer("top").appendChild(e),y(e),function(t,e){const n=e?e.bottom:window.innerHeight/3,i=e?e.left:window.innerWidth/3,a=t.offsetWidth||360,r=window.innerWidth-a-8,o=Math.max(8,Math.min(i,r)),l=window.innerHeight-t.offsetHeight-8,s=Math.min(n+8,Math.max(8,l));t.style.left=`${Math.round(o)}px`,t.style.top=`${Math.round(s)}px`}(e,t.rect),this.installOutsideHandler()}installOutsideHandler(){const t=t=>{this.panel&&!t.composedPath().includes(this.panel)&&this.close(!1)};this.outsideHandler=t,requestAnimationFrame(()=>{this.outsideHandler&&document.addEventListener("mousedown",t,!0)})}};function Ne(){const t=window.getSelection();if(!t||0===t.rangeCount)return null;const e=t.getRangeAt(0).getBoundingClientRect();return 0===e.width&&0===e.height&&0===e.top&&0===e.left?null:e}function Pe(t){const e=document.createElement("template");return e.innerHTML=t,e.content}function qe(t){const e=function(t){const e=L.sanitize(t,{ALLOWED_TAGS:[...at],ALLOWED_ATTR:[...rt]});return/<math[\s>]/i.test(e)?e:null}(t.outerHTML);if(!e)return null;const n=G(e);return{mathml:n,latex:H(n)??"",alt:"",fontSize:Q(t)}}var Re=class{id="formula";name="Formula";priority=46;config;resolvedKeymap;fontSizes;locale=Ce;overlay=null;context=null;clickHandler=null;constructor(t){this.config={...it,...t},this.resolvedKeymap={...et,...t?.keymap},this.fontSizes=this.config.fontSizes??nt}async init(t){var e;this.context=t,this.locale=await g(t,this.config.locale,Ce,$e),t.registerStyleSheet("\n.notectl-math math {\n\tfont-family: 'Notectl Math', math;\n}\n\n.notectl-math--inline {\n\tdisplay: inline-block;\n\tvertical-align: middle;\n\tpadding: 0 1px;\n\tborder-radius: 3px;\n\tcursor: pointer;\n}\n\n.notectl-math--inline:hover {\n\tbackground: var(--notectl-highlight, rgba(0, 0, 0, 0.06));\n}\n\n.notectl-math--inline:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-math--inline math {\n\tfont-size: 1.15em;\n}\n\n.notectl-math--display {\n\tdisplay: block;\n\tmargin: 12px 0;\n\ttext-align: center;\n\tcursor: pointer;\n\tuser-select: none;\n\t-webkit-user-select: none;\n}\n\n.notectl-math--display math {\n\tfont-size: 1.35em;\n\tdisplay: inline-block;\n}\n\n.notectl-math--display.notectl-math--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 4px;\n\tborder-radius: 6px;\n}\n\n.notectl-math__error,\n.notectl-math merror {\n\tcolor: var(--notectl-danger, #c0392b);\n\tbackground: var(--notectl-danger-bg, rgba(192, 57, 43, 0.1));\n\tborder-radius: 3px;\n\tpadding: 0 2px;\n}\n"),t.registerStyleSheet("\n.notectl-formula-editor {\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 8px;\n\tpadding: 10px;\n\tmin-width: 320px;\n\tmax-width: 460px;\n\tbox-sizing: border-box;\n}\n\n.notectl-formula-editor__field {\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 4px;\n}\n\n.notectl-formula-editor__label {\n\tfont-size: 12px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-fg-muted, #555);\n}\n\n.notectl-formula-editor__input {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tpadding: 6px 8px;\n\tfont-family: 'SF Mono', 'Fira Code', Menlo, Consolas, monospace;\n\tfont-size: 13px;\n\tline-height: 1.5;\n\tresize: vertical;\n\tmin-height: 56px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-formula-editor__alt {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tpadding: 5px 8px;\n\tfont-size: 13px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-formula-editor__size {\n\tbox-sizing: border-box;\n\tpadding: 5px 8px;\n\tfont-size: 13px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tcolor: var(--notectl-fg);\n\tcursor: pointer;\n}\n\n.notectl-formula-editor__size:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-formula-editor__preview {\n\tmin-height: 44px;\n\tpadding: 8px;\n\tborder: 1px dashed var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-raised, #fafafa);\n\ttext-align: center;\n\toverflow-x: auto;\n}\n\n.notectl-formula-editor__preview math {\n\tfont-family: 'Notectl Math', math;\n\tfont-size: 1.3em;\n}\n\n.notectl-formula-editor__preview-empty {\n\tcolor: var(--notectl-fg-muted, #888);\n\tfont-size: 13px;\n}\n\n.notectl-formula-editor__errors {\n\tcolor: var(--notectl-danger, #c0392b);\n\tfont-size: 12px;\n\tmargin: 0;\n\tpadding-inline-start: 16px;\n}\n\n.notectl-formula-editor__row {\n\tdisplay: flex;\n\tgap: 8px;\n\talign-items: center;\n}\n\n.notectl-formula-editor__toggle {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 6px;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-formula-editor__actions {\n\tdisplay: flex;\n\tgap: 8px;\n\tjustify-content: flex-end;\n\tmargin-top: 2px;\n}\n\n.notectl-formula-editor__btn {\n\tpadding: 6px 14px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-raised);\n\tcolor: var(--notectl-fg);\n\tcursor: pointer;\n\tfont-size: 13px;\n}\n\n.notectl-formula-editor__btn--primary {\n\tbackground: var(--notectl-primary);\n\tborder-color: var(--notectl-primary);\n\tcolor: var(--notectl-primary-fg, #fff);\n}\n\n.notectl-formula-editor__btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-formula-overlay {\n\tposition: fixed;\n\tz-index: 1000;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 8px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tbox-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);\n}\n\n.notectl-math-palette {\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\tgap: 8px;\n\tpadding: 2px 2px 8px;\n\tborder-bottom: 1px solid var(--notectl-border);\n\tmargin-bottom: 2px;\n\tmax-height: 216px;\n\toverflow-y: auto;\n}\n\n.notectl-math-palette__group {\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\tgap: 2px;\n}\n\n.notectl-math-palette__group + .notectl-math-palette__group {\n\tborder-inline-start: 1px solid var(--notectl-border);\n\tpadding-inline-start: 6px;\n}\n\n.notectl-math-palette__btn {\n\tmin-width: 30px;\n\theight: 30px;\n\tpadding: 0 6px;\n\tborder: 1px solid transparent;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-fg);\n\tcursor: pointer;\n\tfont-size: 15px;\n\tline-height: 1;\n}\n\n.notectl-math-palette__btn:hover {\n\tbackground: var(--notectl-surface-raised);\n}\n\n.notectl-math-palette__btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n"),this.config.mathFont&&t.registerStyleSheet(function(t){const e=(t.family.split(",")[0]??t.name).trim().replace(/['"]/g,"");return(t.fontFaces??[]).map(t=>{const n=[`font-family: '${e}'`,`src: ${t.src}`];return t.weight&&n.push(`font-weight: ${t.weight}`),t.style&&n.push(`font-style: ${t.style}`),n.push(`font-display: ${t.display??"swap"}`),`@font-face { ${n.join("; ")}; }`}).join("\n")}(this.config.mathFont)),t.registerInlineNodeSpec({type:Y,attrs:{mathml:{default:""},latex:{default:""},alt:{default:""},fontSize:{default:""}},toDOM(t){const e=document.createElement("span");return e.className="notectl-math notectl-math--inline",e.setAttribute("contenteditable","false"),e.setAttribute("data-inline-type",Y),W(e,Z(t.attrs)),V(e,t.attrs),e},toHTMLString:t=>X(Z(t.attrs)),parseHTML:[{tag:"math",getAttrs:t=>J(t,!1)}],sanitize:{tags:[...at],attrs:[...rt]}}),t.registerNodeSpec({type:tt,group:"block",isVoid:!0,selectable:!0,attrs:{mathml:{default:""},latex:{default:""},alt:{default:""},fontSize:{default:""}},toDOM(t){const e=m("div",t.id);return e.className="notectl-math notectl-math--display",e.setAttribute("data-void","true"),e.setAttribute("data-selectable","true"),W(e,Z(t.attrs)),V(e,t.attrs),e},toHTML:t=>X(Z(t.attrs)),parseHTML:[{tag:"math",getAttrs:t=>J(t,!0)}],sanitize:{tags:[...at],attrs:[...rt]}}),this.overlay=new De(t,this.locale,this.fontSizes),t.registerNodeView(tt,(e={onEdit:(t,e)=>this.editDisplay(t,e),onSelect:()=>t.announce(this.locale.selected)},t=>{let n=t.id,i=!1;const a=m("div",t.id);return a.className="notectl-math notectl-math--display",a.setAttribute("data-void","true"),a.setAttribute("data-selectable","true"),W(a,Z(t.attrs)),V(a,t.attrs),a.addEventListener("dblclick",t=>{t.preventDefault(),e.onEdit(n,a.getBoundingClientRect())}),{dom:a,contentDOM:null,update:t=>"math_display"===t.type&&(n=t.id,a.setAttribute("data-block-id",t.id),W(a,Z(t.attrs)),V(a,t.attrs),!0),selectNode(){a.classList.add("notectl-math--selected"),i||(i=!0,e.onSelect())},deselectNode(){a.classList.remove("notectl-math--selected"),i=!1}}}));for(const a of[{pattern:Le,handler(t,e){const i=t.selection;if(!c(i)||!o(i))return null;const a=(e[1]??"").trim();if(!a)return null;const r=i.anchor.blockId;if(!ke(t,r))return null;const s=Se(i.anchor.offset,e[0].length);if(!s)return null;const p=t.doc.children.findIndex(t=>t.id===r);if(-1===p)return null;const{presentation:d}=xe(a,{display:!0}),m=M({presentation:d,latex:a,display:!0}),h=t.transaction("input").deleteTextAt(r,s.from,s.to);return function(t,e,i){const a=n(u(tt),[],void 0,lt(i)),r=n(u("paragraph"));t.insertNode([],e,a).insertNode([],e+1,r).setSelection(l(a.id,[]))}(h,p+1,{mathml:m,latex:a,alt:"",fontSize:""}),h.build()}},{pattern:we,handler(t,e){const n=t.selection;if(!c(n)||!o(n))return null;const a=(e[1]??"").trim();if(!a)return null;const r=n.anchor.blockId;if(!ke(t,r))return null;const l=Se(n.anchor.offset,e[0].length);if(!l)return null;const{presentation:p}=xe(a,{display:!1}),u=M({presentation:p,latex:a,display:!1}),m=i(d(Y),{mathml:u,latex:a,alt:"",fontSize:""});return t.transaction("input").deleteTextAt(r,l.from,l.to).insertInlineNode(r,l.from,m).setSelection(s(r,l.from+1)).build()}}])t.registerInputRule(a);t.registerPasteInterceptor((t,e,n)=>{if(!function(t){if(!t)return!1;const e=Pe(t);if(!e.querySelector("math"))return!1;const n=e.cloneNode(!0);for(const i of Array.from(n.querySelectorAll('math, [aria-hidden="true"]')))i.remove();return""===(n.textContent??"").trim()}(e))return null;const i=function(t){if(!t)return[];const e=Pe(t);for(const n of Array.from(e.querySelectorAll('[aria-hidden="true"]')))n.remove();return Array.from(e.querySelectorAll("math"))}(e).map(qe).filter(t=>null!==t);return 0===i.length?null:i.every(t=>{return e=t.mathml,!/<math\b[^>]*\bdisplay=["']block["']/i.test(e);var e})?st(n,i):ct(n,i)},{name:"formula",priority:40}),this.registerCommands(t),this.registerKeymap(t),function(t,e,n){t.registerToolbarItem({id:"formula",group:"insert",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round"><path d="M18 5 H6 L12 12 L6 19 H18"/></svg>',label:e.insertInline,tooltip:e.insertInlineTooltip,command:"insertInlineFormula",popupType:"custom",renderPopup:(t,i,a)=>{Ie(t,{context:i,locale:e,mode:"insert",fontSizes:n,onClose:a,onCommit:t=>{ut(i,e,t),a(),i.getContainer().focus()}})}})}(t,this.locale,this.fontSizes),this.installClickToEdit(t)}destroy(){this.clickHandler&&this.context&&this.context.getContainer().removeEventListener("click",this.clickHandler),this.clickHandler=null,this.overlay?.close(!1),this.overlay=null,this.context=null}registerCommands(n){n.registerCommand("insertInlineFormula",()=>{const i=function(n){const i=n.selection;if(!c(i)||!o(i))return null;const r=i.anchor.blockId,l=n.getBlock(r);if(!l)return null;const s=i.anchor.offset;for(const{child:o,from:c,to:p}of e(a(l)))if(t(o)&&"math_inline"===o.inlineType&&(p===s||c===s)){const t=Z(o.attrs);return{kind:"inline",blockId:r,offset:c,latex:t.latex,alt:t.alt,fontSize:t.fontSize,rect:null}}return null}(n.getState());return i?(this.overlay?.openEdit(i),!0):(this.overlay?.openInsert(!1),!0)}),n.registerCommand("insertDisplayFormula",()=>{const t=ot(n.getState());return t?(this.editDisplay(t,null),!0):(this.overlay?.openInsert(!0),!0)})}registerKeymap(t){const e={},n=this.resolvedKeymap.insertInline,i=this.resolvedKeymap.insertDisplay;n&&(e[n]=()=>t.executeCommand("insertInlineFormula")),i&&(e[i]=()=>t.executeCommand("insertDisplayFormula")),e.Enter=()=>{const e=ot(t.getState());return!!e&&(this.editDisplay(e,null),!0)},t.registerKeymap(e,{priority:"context"})}installClickToEdit(n){const i=n.getContainer(),r=r=>{if(n.isReadOnly())return;const o=r.target?.closest(".notectl-math--inline");if(!o)return;const l=function(n,i,r){const o=b(n,i,0);if(!o)return null;const l=function(n,i,r){const o=n.getBlock(i);if(!o)return null;for(const{child:l,from:s}of e(a(o)))if(s===r&&t(l)&&"math_inline"===l.inlineType)return Z(l.attrs);return null}(r,o.blockId,o.offset);return l?{kind:"inline",blockId:o.blockId,offset:o.offset,latex:l.latex,alt:l.alt,fontSize:l.fontSize,rect:i.getBoundingClientRect()}:null}(i,o,n.getState());l&&(r.preventDefault(),this.overlay?.openEdit(l))};this.clickHandler=r,i.addEventListener("click",r)}editDisplay(t,e){if(!this.overlay||!this.context)return;const n=function(t,e,n){const i=t.getBlock(e);if(!i||"math_display"!==i.type)return null;const a=Z(i.attrs);return{kind:"display",path:t.getNodePath(e)??[e],latex:a.latex,alt:a.alt,fontSize:a.fontSize,rect:n}}(this.context.getState(),t,e);n&&this.overlay.openEdit(n)}};export{rt as a,M as c,xe as i,Ce as n,at as o,$e as r,et as s,Re as t};
2
- //# sourceMappingURL=FormulaPlugin-UA-9tRpY.mjs.map
1
+ import{C as t,M as e,i as n,s as i,v as a}from"./Document-r7vLOAGA.mjs";import{l as r,o,r as l,t as s,u as c}from"./Selection-HYoVFpAx.mjs";import{t as p}from"./Commands-BIIpx_Zd.mjs";import{a as u,r as d}from"./TypeBrands-Ch9856Gb.mjs";import{n as m}from"./DomUtils-Bf7JLFlx.mjs";import{c as h,w as f}from"./BlockInsertion-6rR9tIGP.mjs";import{t as b}from"./SelectionSync-BSHIw1EE.mjs";import{a as g,i as v,s as x}from"./PluginHelpers-D4quRJ5a.mjs";import{i as y}from"./PopupPositioning-DtUrY9bh.mjs";import{r as w}from"./ColorValidation-DAijTjG9.mjs";import L from"dompurify";var k={"&":"&amp;","<":"&lt;",">":"&gt;"},S={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function C(t){return t.replace(/[&<>]/g,t=>k[t]??t)}function A(t){return t.replace(/[&<>"]/g,t=>S[t]??t)}function $(t){if(!t)return"";let e="";for(const[n,i]of Object.entries(t))!1!==i&&null!=i&&(e+=!0!==i?` ${n}="${A(String(i))}"`:` ${n}="true"`);return e}function z(t,e,n){return`<${t}${$(n)}>${e}</${t}>`}function _(t,e){return z("mi",C(t),e)}function E(t,e){return z("mn",C(t),e)}function B(t,e){return z("mo",C(t),e)}function I(t,e){return z("mtext",C(t),e)}function D(t){return function(t,e){return`<${t}${$(e)}></${t}>`}("mspace",t)}function N(t,e){return z("mrow",t,e)}function P(t){return 0===t.length?"":1===t.length?t[0]??"":N(t.join(""))}function q(t,e,n){return z("mfrac",`${t}${e}`,n)}function R(t,e,n){return z("mover",`${t}${e}`,n)}function F(t,e,n){return z("munder",`${t}${e}`,n)}function O(t){return z("mtd",t)}function T(t){return z("mtr",t.map(O).join(""))}var j={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&apos;":"'","&#39;":"'"};function M(t){const e=t.display?"block":"inline",n=t.alt?` alttext="${A(t.alt)}"`:"",i=void 0!==t.latex&&""!==t.latex,a=`<annotation encoding="application/x-tex">${C(t.latex??"")}</annotation>`;return`<math display="${e}"${n}>${i?`<semantics>${t.presentation}${a}</semantics>`:t.presentation}</math>`}function H(t){const e=t.match(/<annotation\b[^>]*\bencoding=["']application\/x-tex["'][^>]*>([\s\S]*?)<\/annotation>/i);var n;if(e&&void 0!==e[1])return(n=e[1],n.replace(/&(?:amp|lt|gt|quot|apos|#39);/g,t=>j[t]??t)).trim()}function G(t){return t.replace(/^(<math\b[^>]*?)\s+mathsize=(?:"[^"]*"|'[^']*')/i,"$1")}var U=/<math[\s>]/i;function K(t){return U.test(t.mathml)?function(t,e){const n=t.replace(/^(<math\b[^>]*?)\s+alttext=["'][^"']*["']/i,"$1");return e?n.replace(/^<math\b/i,`<math alttext="${A(e)}"`):n}(t.mathml,t.alt):""}function W(t,e){const n=K(e);n?t.innerHTML=n:t.textContent=e.latex||e.alt||"⊡"}function V(t,e){const n="string"==typeof e?.fontSize?e.fontSize:"";t.style.fontSize=n}function Z(t){return{mathml:"string"==typeof t?.mathml?t.mathml:"",latex:"string"==typeof t?.latex?t.latex:"",alt:"string"==typeof t?.alt?t.alt:"",fontSize:"string"==typeof t?.fontSize?t.fontSize:""}}function X(t){const e=K(t);return e?function(t,e){const n=G(t);return e?n.replace(/^<math\b/i,`<math mathsize="${A(e)}"`):n}(e,w(t.fontSize)?t.fontSize:""):e}function Q(t){const e=t.getAttribute("mathsize")??"";return w(e)?e:""}function J(t,e){if("block"===t.getAttribute("display")!==e)return!1;const n=G(function(t){return t.replace(/^(<math\b[^>]*?)\s+data-block-id=(?:"[^"]*"|'[^']*')/i,"$1")}(t.outerHTML));return{mathml:n,latex:H(n)??"",alt:t.getAttribute("alttext")??"",fontSize:Q(t)}}var Y="math_inline",tt="math_display",et={insertInline:"Mod-Shift-E",insertDisplay:"Mod-Shift-M"},nt=[12,16,20,24,32,40,48,64,96],it={},at=["math","semantics","annotation","mrow","mi","mn","mo","mtext","ms","mspace","mfrac","msqrt","mroot","msup","msub","msubsup","mover","munder","munderover","mmultiscripts","mprescripts","none","mtable","mtr","mlabeledtr","mtd","mpadded","mphantom","mstyle","merror","menclose","mfenced","maction"],rt=["display","encoding","mathvariant","mathsize","mathcolor","mathbackground","displaystyle","scriptlevel","scriptminsize","scriptsizemultiplier","stretchy","symmetric","largeop","movablelimits","accent","accentunder","form","fence","separator","lspace","rspace","voffset","minsize","maxsize","linethickness","columnalign","rowalign","columnspacing","rowspacing","columnlines","rowlines","columnspan","rowspan","align","open","close","separators","notation","alttext","depth","width","height"];function ot(t){const e=t.selection;if(!r(e))return null;const n=t.getBlock(e.nodeId);return n&&"math_display"===n.type?e.nodeId:null}function lt(t){return{mathml:t.mathml,latex:t.latex,alt:t.alt,fontSize:t.fontSize}}function st(t,e){const n=t.selection;if(0===e.length||!c(n))return null;const a=t.transaction("command"),r=o(n)?void 0:p(t,a);let l,u;if(r)l=r,u=0;else{const e=f(n,t.getBlockOrder());l=e.blockId,u=e.offset}for(const o of e)a.insertInlineNode(l,u,i(d(Y),lt(o))),u+=1;return a.setSelection(s(l,u)),a.build()}function ct(t,e){const i=v(t);if(0===e.length||!i)return null;const a=e.map(t=>n(u(tt),[],void 0,lt(t))),r=t.transaction("command");if(!h(t,r,i,a))return null;const o=a[a.length-1];return o?(r.setSelection(l(o.id,[])),r.build()):null}function pt(t){return{mathml:t.mathml,latex:t.latex,alt:t.alt,fontSize:t.fontSize}}function ut(t,e,n){const i=pt(n);n.display?function(t,e){const n=function(t,e){return ct(t,[e])}(t.getState(),e);!!n&&t.dispatch(n)}(t,i):function(t,e){const n=function(t,e){return st(t,[e])}(t.getState(),e);!!n&&t.dispatch(n)}(t,i),t.announce(e.inserted)}function dt(t,e){return void 0===e?{node:t}:{node:t,kind:e}}function mt(t,e,n=!1){return{node:t,kind:e,bigOp:!0,intLike:n}}var ht=/* @__PURE__ */function(t){return t.Ordinary="ordinary",t.Binary="binary",t.Relation="relation",t.Arrow="arrow",t.Open="open",t.Close="close",t.Function="function",t.BigOp="bigop",t.Punct="punct",t}({});function ft(t,e){return{char:t,kind:e}}var bt="ordinary",gt="binary",vt="relation",xt="arrow",yt="function",wt="bigop",Lt="punct",kt={alpha:ft("α",bt),beta:ft("β",bt),gamma:ft("γ",bt),delta:ft("δ",bt),epsilon:ft("ϵ",bt),varepsilon:ft("ε",bt),zeta:ft("ζ",bt),eta:ft("η",bt),theta:ft("θ",bt),vartheta:ft("ϑ",bt),iota:ft("ι",bt),kappa:ft("κ",bt),lambda:ft("λ",bt),mu:ft("μ",bt),nu:ft("ν",bt),xi:ft("ξ",bt),omicron:ft("ο",bt),pi:ft("π",bt),varpi:ft("ϖ",bt),rho:ft("ρ",bt),varrho:ft("ϱ",bt),sigma:ft("σ",bt),varsigma:ft("ς",bt),tau:ft("τ",bt),upsilon:ft("υ",bt),phi:ft("ϕ",bt),varphi:ft("φ",bt),chi:ft("χ",bt),psi:ft("ψ",bt),omega:ft("ω",bt),Gamma:ft("Γ",bt),Delta:ft("Δ",bt),Theta:ft("Θ",bt),Lambda:ft("Λ",bt),Xi:ft("Ξ",bt),Pi:ft("Π",bt),Sigma:ft("Σ",bt),Upsilon:ft("Υ",bt),Phi:ft("Φ",bt),Psi:ft("Ψ",bt),Omega:ft("Ω",bt)},St={sin:ft("sin",yt),cos:ft("cos",yt),tan:ft("tan",yt),cot:ft("cot",yt),sec:ft("sec",yt),csc:ft("csc",yt),sinh:ft("sinh",yt),cosh:ft("cosh",yt),tanh:ft("tanh",yt),coth:ft("coth",yt),arcsin:ft("arcsin",yt),arccos:ft("arccos",yt),arctan:ft("arctan",yt),log:ft("log",yt),ln:ft("ln",yt),lg:ft("lg",yt),exp:ft("exp",yt),deg:ft("deg",yt),det:ft("det",yt),dim:ft("dim",yt),hom:ft("hom",yt),ker:ft("ker",yt),arg:ft("arg",yt),Pr:ft("Pr",yt)},Ct={sum:ft("∑",wt),prod:ft("∏",wt),coprod:ft("∐",wt),int:ft("∫",wt),iint:ft("∬",wt),iiint:ft("∭",wt),oint:ft("∮",wt),bigcup:ft("⋃",wt),bigcap:ft("⋂",wt),bigsqcup:ft("⨆",wt),bigvee:ft("⋁",wt),bigwedge:ft("⋀",wt),bigoplus:ft("⨁",wt),bigotimes:ft("⨂",wt),bigodot:ft("⨀",wt),biguplus:ft("⨄",wt),lim:ft("lim",wt),limsup:ft("lim sup",wt),liminf:ft("lim inf",wt),injlim:ft("inj lim",wt),projlim:ft("proj lim",wt),max:ft("max",wt),min:ft("min",wt),sup:ft("sup",wt),inf:ft("inf",wt),gcd:ft("gcd",wt)},At={times:ft("×",gt),div:ft("÷",gt),pm:ft("±",gt),mp:ft("∓",gt),cdot:ft("⋅",gt),ast:ft("∗",gt),star:ft("⋆",gt),circ:ft("∘",gt),bullet:ft("∙",gt),oplus:ft("⊕",gt),ominus:ft("⊖",gt),otimes:ft("⊗",gt),oslash:ft("⊘",gt),odot:ft("⊙",gt),cap:ft("∩",gt),cup:ft("∪",gt),uplus:ft("⊎",gt),sqcap:ft("⊓",gt),sqcup:ft("⊔",gt),wedge:ft("∧",gt),land:ft("∧",gt),vee:ft("∨",gt),lor:ft("∨",gt),setminus:ft("∖",gt),wr:ft("≀",gt),diamond:ft("⋄",gt),bigtriangleup:ft("△",gt),bigtriangledown:ft("▽",gt),triangleleft:ft("◁",gt),triangleright:ft("▷",gt),amalg:ft("⨿",gt),dagger:ft("†",gt),ddagger:ft("‡",gt)},$t={leq:ft("≤",vt),le:ft("≤",vt),geq:ft("≥",vt),ge:ft("≥",vt),neq:ft("≠",vt),ne:ft("≠",vt),equiv:ft("≡",vt),sim:ft("∼",vt),simeq:ft("≃",vt),cong:ft("≅",vt),approx:ft("≈",vt),propto:ft("∝",vt),prec:ft("≺",vt),succ:ft("≻",vt),preceq:ft("⪯",vt),succeq:ft("⪰",vt),ll:ft("≪",vt),gg:ft("≫",vt),lll:ft("⋘",vt),ggg:ft("⋙",vt),subset:ft("⊂",vt),supset:ft("⊃",vt),subseteq:ft("⊆",vt),supseteq:ft("⊇",vt),subsetneq:ft("⊊",vt),supsetneq:ft("⊋",vt),sqsubseteq:ft("⊑",vt),sqsupseteq:ft("⊒",vt),in:ft("∈",vt),ni:ft("∋",vt),notin:ft("∉",vt),mid:ft("∣",vt),parallel:ft("∥",vt),perp:ft("⊥",vt),models:ft("⊨",vt),vdash:ft("⊢",vt),dashv:ft("⊣",vt),doteq:ft("≐",vt),asymp:ft("≍",vt),bowtie:ft("⋈",vt),smile:ft("⌣",vt),frown:ft("⌢",vt)},zt={leftarrow:ft("←",xt),gets:ft("←",xt),rightarrow:ft("→",xt),to:ft("→",xt),leftrightarrow:ft("↔",xt),Leftarrow:ft("⇐",xt),Rightarrow:ft("⇒",xt),Leftrightarrow:ft("⇔",xt),mapsto:ft("↦",xt),longrightarrow:ft("⟶",xt),longleftarrow:ft("⟵",xt),longleftrightarrow:ft("⟷",xt),Longrightarrow:ft("⟹",xt),Longleftarrow:ft("⟸",xt),Longleftrightarrow:ft("⟺",xt),implies:ft("⟹",xt),iff:ft("⟺",xt),uparrow:ft("↑",xt),downarrow:ft("↓",xt),updownarrow:ft("↕",xt),nearrow:ft("↗",xt),searrow:ft("↘",xt),swarrow:ft("↙",xt),nwarrow:ft("↖",xt),hookleftarrow:ft("↩",xt),hookrightarrow:ft("↪",xt),rightharpoonup:ft("⇀",xt),rightharpoondown:ft("⇁",xt),leftharpoonup:ft("↼",xt),leftharpoondown:ft("↽",xt),nleftarrow:ft("↚",xt),nrightarrow:ft("↛",xt)},_t={langle:ft("⟨","open"),rangle:ft("⟩","close"),lceil:ft("⌈","open"),rceil:ft("⌉","close"),lfloor:ft("⌊","open"),rfloor:ft("⌋","close"),lbrace:ft("{","open"),rbrace:ft("}","close"),lbrack:ft("[","open"),rbrack:ft("]","close"),lvert:ft("|","open"),rvert:ft("|","close"),lVert:ft("‖","open"),rVert:ft("‖","close"),vert:ft("|","relation"),Vert:ft("‖","relation"),backslash:ft("\\",bt)},Et={infty:ft("∞",bt),partial:ft("∂",bt),nabla:ft("∇",bt),forall:ft("∀",bt),exists:ft("∃",bt),nexists:ft("∄",bt),emptyset:ft("∅",bt),varnothing:ft("∅",bt),aleph:ft("ℵ",bt),beth:ft("ℶ",bt),hbar:ft("ℏ",bt),ell:ft("ℓ",bt),Re:ft("ℜ",bt),Im:ft("ℑ",bt),wp:ft("℘",bt),prime:ft("′",bt),angle:ft("∠",bt),measuredangle:ft("∡",bt),triangle:ft("△",bt),neg:ft("¬",bt),lnot:ft("¬",bt),top:ft("⊤",bt),bot:ft("⊥",bt),flat:ft("♭",bt),natural:ft("♮",bt),sharp:ft("♯",bt),clubsuit:ft("♣",bt),diamondsuit:ft("♢",bt),heartsuit:ft("♡",bt),spadesuit:ft("♠",bt),surd:ft("√",bt),complement:ft("∁",bt),square:ft("□",bt),blacksquare:ft("■",bt),bigstar:ft("★",bt),checkmark:ft("✓",bt),degree:ft("°",bt),cdots:ft("⋯",bt),ldots:ft("…",bt),dots:ft("…",bt),dotsb:ft("⋯",bt),vdots:ft("⋮",bt),ddots:ft("⋱",bt)},Bt={colon:ft(":",Lt),cdotp:ft("·",Lt),ldotp:ft(".",Lt)},It={...kt,...St,...Ct,...At,...$t,...zt,..._t,...Et,...Bt},Dt={"(":ft("(","open"),")":ft(")","close"),"[":ft("[","open"),"]":ft("]","close"),"|":ft("|","relation"),"/":ft("/",bt)};function Nt(t){if("."===t)return ft("",bt);if(t.startsWith("\\")){const e=t.slice(1);return"{"===e?ft("{","open"):"}"===e?ft("}","close"):"|"===e?ft("‖","relation"):"\\"===e?ft("\\",bt):_t[e]}return Dt[t]}var Pt=/* @__PURE__ */function(t){return t.Command="command",t.GroupOpen="groupOpen",t.GroupClose="groupClose",t.Superscript="superscript",t.Subscript="subscript",t.Prime="prime",t.Ampersand="ampersand",t.RowBreak="rowBreak",t.NbSpace="nbSpace",t.Number="number",t.Char="char",t}({}),qt=new Set(["{","}","%","$","#","&","_",",",":",";","!"," ","|","\\",".","/","'","~","^"]);function Rt(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}function Ft(t){return t>="0"&&t<="9"}function Ot(t){return" "===t||"\t"===t||"\n"===t||"\r"===t}function Tt(t,e,n){return{type:t,value:e,position:n}}function jt(t,e){const n=t[e+1];if(void 0!==n&&!Rt(n))return"\\"===n?Tt("rowBreak","\\",e):Tt("command",n,e);let i=e+1;for(;i<t.length;){const e=t[i];if(void 0===e||!Rt(e))break;i+=1}return Tt("command",t.slice(e+1,i),e)}function Mt(t,e){let n=e;for(;n<t.length;){const e=t[n];if(void 0===e||!Ft(e))break;n+=1}if("."===t[n]&&void 0!==t[n+1]&&Ft(t[n+1]??""))for(n+=1;n<t.length;){const e=t[n];if(void 0===e||!Ft(e))break;n+=1}return Tt("number",t.slice(e,n),e)}function Ht(t,e){switch(t){case"{":return Tt("groupOpen",t,e);case"}":return Tt("groupClose",t,e);case"^":return Tt("superscript",t,e);case"_":return Tt("subscript",t,e);case"'":return Tt("prime",t,e);case"&":return Tt("ampersand",t,e);case"~":return Tt("nbSpace",t,e);default:return Tt("char",t,e)}}function Gt(t,e){return{glyph:t,under:!1,stretchy:e}}function Ut(t,e){return{glyph:t,under:!0,stretchy:e}}var Kt={hat:Gt("^",!1),widehat:Gt("^",!0),check:Gt("ˇ",!1),tilde:Gt("~",!1),widetilde:Gt("~",!0),bar:Gt("‾",!1),overline:Gt("‾",!0),vec:Gt("→",!1),overrightarrow:Gt("→",!0),overleftarrow:Gt("←",!0),overleftrightarrow:Gt("↔",!0),dot:Gt("˙",!1),ddot:Gt("¨",!1),dddot:Gt("⃛",!1),acute:Gt("´",!1),grave:Gt("`",!1),breve:Gt("˘",!1),mathring:Gt("˚",!1),overbrace:Gt("⏞",!0),underline:Ut("_",!0),underbrace:Ut("⏟",!0),underrightarrow:Ut("→",!0),underleftarrow:Ut("←",!0)},Wt={matrix:{open:"",close:""},pmatrix:{open:"(",close:")"},bmatrix:{open:"[",close:"]"},Bmatrix:{open:"{",close:"}"},vmatrix:{open:"|",close:"|"},Vmatrix:{open:"‖",close:"‖"},cases:{open:"{",close:"",columnalign:"left"},aligned:{open:"",close:"",columnalign:"right left"},align:{open:"",close:"",columnalign:"right left"},gathered:{open:"",close:"",columnalign:"center"},smallmatrix:{open:"",close:""}};function Vt(t){return t.type===Pt.Command&&"end"===t.value}function Zt(t){return t.type===Pt.Ampersand||t.type===Pt.RowBreak||t.type===Pt.Command&&"end"===t.value}var Xt={",":"0.167em",":":"0.222em",";":"0.278em","!":"-0.167em"," ":"0.25em",quad:"1em",qquad:"2em",thinspace:"0.167em",medspace:"0.222em",thickspace:"0.278em",negthinspace:"-0.167em",negmedspace:"-0.222em",negthickspace:"-0.278em",enspace:"0.5em"};function Qt(t){return t in Xt}function Jt(t){const e=Xt[t];if(void 0!==e)return D({width:e})}function Yt(){return D({width:"0.25em"})}function te(t){const e=t.parseRawArgument();return(n=e)in Wt||"array"===n?function(t,e){"array"===t&&(e.parseOptionalArgument(),e.parseRawArgument());const n=function(t,e){const n=[];let i=[],a=[];const r=()=>{i.push(N(a.join(""))),a=[]},o=()=>{r(),n.push(i),i=[]};for(;;){const n=e.peek();if(void 0===n){e.error({message:`Unterminated environment \\begin{${t}}`});break}if(Vt(n)){e.next(),e.parseRawArgument();break}if(n.type===Pt.Ampersand){e.next(),r();continue}if(n.type===Pt.RowBreak){e.next(),o();continue}if(n.type===Pt.GroupClose){e.next(),e.error({message:"Unmatched brace",position:n.position});continue}const i=e.parseAtomsUntil(Zt);a.push(...i.map(t=>t.node))}return(a.length>0||i.length>0)&&o(),0===n.length&&n.push([""]),n}(t,e).map(t=>t.map(t=>t)),i=Wt[t]??{open:"",close:""},a=(r=n,o=i.columnalign?{columnalign:i.columnalign}:void 0,z("mtable",r.map(T).join(""),o));var r,o;return i.open||i.close?dt(N(`${i.open?B(i.open,{stretchy:!0,fence:!0}):""}${a}${i.close?B(i.close,{stretchy:!0,fence:!0}):""}`)):dt(a)}(e,t):(t.error({message:"Unknown environment",command:e}),dt(z("merror",I(e))));var n}function ee(t){return t.type===Pt.Command&&"right"===t.value}function ne(t){const e=t.next();return void 0===e?".":e.type===Pt.Command?`\\${e.value}`:e.value}function ie(t){return t&&""!==t.char?B(t.char,{fence:!0,stretchy:!0}):""}var ae={},re={"double-struck":{upperBase:120120,lowerBase:120146,digitBase:120792,holes:{C:8450,H:8461,N:8469,P:8473,Q:8474,R:8477,Z:8484}},script:{upperBase:119964,lowerBase:119990,holes:{B:8492,E:8496,F:8497,H:8459,I:8464,L:8466,M:8499,R:8475,e:8495,g:8458,o:8500}},fraktur:{upperBase:120068,lowerBase:120094,holes:{C:8493,H:8460,I:8465,R:8476,Z:8488}},bold:{upperBase:119808,lowerBase:119834,digitBase:120782,holes:ae},italic:{upperBase:119860,lowerBase:119886,holes:{h:8462}},"sans-serif":{upperBase:120224,lowerBase:120250,digitBase:120802,holes:ae},monospace:{upperBase:120432,lowerBase:120458,digitBase:120822,holes:ae}};function oe(t,e){if(1!==t.length)return null;const n=re[e],i=n.holes[t];return void 0!==i?String.fromCodePoint(i):function(t){return t>="A"&&t<="Z"}(t)?String.fromCodePoint(n.upperBase+(t.charCodeAt(0)-65)):function(t){return t>="a"&&t<="z"}(t)?String.fromCodePoint(n.lowerBase+(t.charCodeAt(0)-97)):function(t){return t>="0"&&t<="9"}(t)&&void 0!==n.digitBase?String.fromCodePoint(n.digitBase+(t.charCodeAt(0)-48)):null}var le=/<(mi|mn)>([^<]*)<\/\1>/g,se=/<mi>([^<]*)<\/mi>/g;var ce={mathbb:"double-struck",mathcal:"script",mathscr:"script",mathfrak:"fraktur",mathbf:"bold",mathit:"italic",mathsf:"sans-serif",mathtt:"monospace"},pe={boldsymbol:"bold-italic",bm:"bold-italic"},ue={text:void 0,textnormal:"normal",textrm:"normal",textbf:"bold",textit:"italic",textsf:"sans-serif",texttt:"monospace",mbox:void 0};function de(t,e){if("operatorname"===t)return dt(_(e.parseRawArgument(),{mathvariant:"normal"}));if(t in ue){const n=ue[t],i=e.parseRawArgument();return dt(n?I(i,{mathvariant:n}):I(i))}const n=ce[t];if(void 0!==n)return dt((i=e.parseArgument(),a=n,i.replace(le,(t,e,n)=>{const i=function(t,e){let n="";for(const i of t)n+=oe(i,e)??i;return n}(n,a);return"mn"===e?E(i):_(i)})));var i,a;if("mathrm"===t)return dt(e.parseArgument().replace(se,(t,e)=>_(e,{mathvariant:"normal"})));const r=pe[t],o=e.parseArgument();return dt(void 0===r?o:z("mstyle",o,{mathvariant:r}))}var me=new Set(["frac","dfrac","tfrac","cfrac"]),he=new Set(["binom","dbinom","tbinom","choose"]),fe=new Set(["overset","underset","stackrel"]);var be=new Set(["∫","∬","∭","∮"]);var ge=class{source;tokens;pos=0;depth=0;depthExceeded=!1;errors=[];display;constructor(t,e,n){this.source=t,this.tokens=e,this.display=n}get collectedErrors(){return this.errors}peek(){return this.tokens[this.pos]}next(){const t=this.tokens[this.pos];return void 0!==t&&(this.pos+=1),t}error(t){this.errors.push(t)}parseTopLevel(){const t=[];for(;;){const e=this.peek();if(void 0===e)break;if(e.type===Pt.GroupClose){this.next(),this.error({message:"Unmatched brace",position:e.position});continue}const n=this.parseAtomWithScripts();void 0!==n&&t.push(n)}return t}parseExpression(t){const e=[];for(;;){const n=this.peek();if(void 0===n||t(n))break;if(n.type===Pt.GroupClose)break;const i=this.parseAtomWithScripts();void 0!==i&&e.push(i)}return e}parseAtomsUntil(t){return this.parseExpression(t)}parseAtomWithScripts(){const t=this.parseBaseAtom();if(void 0!==t)return this.attachScripts(t)}attachScripts(t){let e,n,i,a="";for(;;){const t=this.peek();if(void 0===t)break;if(t.type!==Pt.Prime)if(t.type!==Pt.Command||"limits"!==t.value)if(t.type!==Pt.Command||"nolimits"!==t.value)if(t.type!==Pt.Superscript){if(t.type!==Pt.Subscript)break;this.next(),e=this.combineSub(e,this.parseArgument())}else this.next(),n=this.combineSup(n,this.parseArgument());else this.next(),i="nolimits";else this.next(),i="limits";else this.next(),a+="′"}return a&&(n=void 0===n?B(a):N(`${B(a)}${n}`)),void 0===e&&void 0===n?t:dt(this.buildScripts(t,e,n,i))}combineSup(t,e){return void 0===t?e:(this.error({message:"Double superscript"}),N(`${t}${e}`))}combineSub(t,e){return void 0===t?e:(this.error({message:"Double subscript"}),N(`${t}${e}`))}buildScripts(t,e,n,i){const a=!0===t.bigOp&&!0!==t.intLike&&this.display;if("limits"===i||"nolimits"!==i&&a){if(void 0!==e&&void 0!==n)return function(t,e,n){return z("munderover",`${t}${e}${n}`)}(t.node,e,n);if(void 0!==e)return F(t.node,e);if(void 0!==n)return R(t.node,n)}return void 0!==e&&void 0!==n?function(t,e,n){return z("msubsup",`${t}${e}${n}`)}(t.node,e,n):void 0!==e?function(t,e){return z("msub",`${t}${e}`)}(t.node,e):void 0!==n?function(t,e){return z("msup",`${t}${e}`)}(t.node,n):t.node}parseBaseAtom(){if(this.depth>=256)return this.bailDeepNesting();this.depth+=1;try{return this.parseBaseAtomInner()}finally{this.depth-=1}}bailDeepNesting(){const t=this.next();if(void 0!==t&&!this.depthExceeded)return this.depthExceeded=!0,this.error({message:"Maximum nesting depth exceeded",position:t.position}),dt(z("merror",I("⋯")))}parseBaseAtomInner(){const t=this.next();if(void 0!==t)switch(t.type){case Pt.Number:return dt(E(t.value));case Pt.Char:return this.parseChar(t.value);case Pt.GroupOpen:return this.parseGroup();case Pt.NbSpace:return dt(Yt());case Pt.Command:return this.parseCommand(t);case Pt.Superscript:case Pt.Subscript:case Pt.Prime:return this.pos-=1,this.attachScripts(dt(N("")));case Pt.Ampersand:case Pt.RowBreak:case Pt.GroupClose:default:return}}parseGroup(){const t=this.parseExpression(()=>!1);return this.expect(Pt.GroupClose),dt(P(t.map(t=>t.node)))}parseChar(t){const e=Nt(t);return!e||e.kind!==ht.Open&&e.kind!==ht.Close?dt("+"===t||"-"===t||"*"===t||"="===t||"/"===t||"|"===t||","===t||";"===t||"."===t||":"===t||"!"===t||"?"===t||"<"===t||">"===t?B(t):_(t)):dt(B(t,{fence:!0}),e.kind)}parseCommand(t){const e=t.value,n=function(t){return It[t]}(e);if(n)return this.symbolAtom(n);if(1===(i=e).length&&qt.has(i))return this.controlSymbolAtom(e);var i;const a=this.dispatchStructural(e);if(void 0!==a)return a;const r=this.dispatchSpecial(e,t);return void 0!==r?r:(this.error({message:"Unknown command",command:`\\${e}`,position:t.position}),dt(z("merror",I(`\\${e}`))))}dispatchStructural(t){if(function(t){return me.has(t)}(t))return dt(q((e=this).parseArgument(),e.parseArgument()));var e;if(function(t){return he.has(t)}(t))return function(t){const e=q(t.parseArgument(),t.parseArgument(),{linethickness:0});return dt(N(`${B("(",{fence:!0})}${e}${B(")",{fence:!0})}`))}(this);if("sqrt"===t)return function(t){const e=t.parseOptionalArgument(),n=t.parseArgument();return dt(void 0===e||""===e?function(t){return z("msqrt",t)}(n):function(t,e){return z("mroot",`${t}${e}`)}(n,e))}(this);if(function(t){return fe.has(t)}(t))return function(t,e){const n=e.parseArgument(),i=e.parseArgument();return dt("underset"===t?F(i,n):R(i,n))}(t,this);if(function(t){return t in Kt}(t))return function(t,e){const n=Kt[t];if(!n)return dt("");const i=e.parseArgument(),a=B(n.glyph,{stretchy:n.stretchy}),r=n.under?{accentunder:!0}:{accent:!0};return dt(n.under?F(i,a,r):R(i,a,r))}(t,this);if(function(t){return t in ce||t in pe||t in ue||"mathrm"===t||"operatorname"===t}(t))return de(t,this);if(Qt(t)){const e=Jt(t);return void 0===e?void 0:dt(e)}}dispatchSpecial(t,e){return"left"===t?function(t){const e=Nt(ne(t)),n=t.parseAtomsUntil(ee),i=t.peek();let a=".";void 0!==i&&ee(i)?(t.next(),a=ne(t)):t.error({message:"Unmatched \\left"});const r=Nt(a),o=ie(e),l=ie(r);return dt(P([o,...n.map(t=>t.node),l]))}(this):"begin"===t?te(this):"pmod"===t?function(t){const e=t.parseArgument(),n=B("(",{fence:!0}),i=B(")",{fence:!0});return dt(N(`${n}${I("mod")}${Yt()}${e}${i}`))}(this):"bmod"===t||"mod"===t?dt(B("mod",{lspace:"0.222em",rspace:"0.222em"})):"substack"===t?function(t){!function(t){const e=t.peek();void 0!==e&&e.type===Pt.GroupOpen&&t.next()}(t);const e=[];let n=[];for(;;){const i=t.peek();if(void 0===i||i.type===Pt.GroupClose)break;if(i.type===Pt.RowBreak){t.next(),e.push(P(n)),n=[];continue}const a=t.parseAtomsUntil(t=>t.type===Pt.RowBreak);n.push(...a.map(t=>t.node))}return function(t){const e=t.peek();void 0!==e&&e.type===Pt.GroupClose&&t.next()}(t),e.push(P(n)),dt(z("mtable",e.map(t=>z("mtr",z("mtd",t))).join("")))}(this):"right"===t?(n=e.position,ne(this),this.error({message:"Unmatched \\right",position:n}),dt(P([]))):void 0;var n}symbolAtom(t){switch(t.kind){case ht.Ordinary:return dt(_(t.char),t.kind);case ht.Function:return dt(_(t.char,{mathvariant:"normal"}),t.kind);case ht.BigOp:return this.bigOperator(t);case ht.Open:case ht.Close:return dt(B(t.char,{fence:!0}),t.kind);default:return dt(B(t.char),t.kind)}}bigOperator(t){if(/[a-z]/i.test(t.char))return mt(B(t.char,{movablelimits:!0}),t.kind);const e=be.has(t.char);return mt(B(t.char,{movablelimits:!0,largeop:!0}),t.kind,e)}controlSymbolAtom(t){if(Qt(t)){const e=Jt(t);return void 0===e?void 0:dt(e)}return"{"===t?dt(B("{",{fence:!0}),ht.Open):"}"===t?dt(B("}",{fence:!0}),ht.Close):dt("|"===t?B("‖"):"\\"===t?B("\\"):"/"===t?B("/"):"'"===t?B("′"):"."===t?B("."):I(t))}parseArgument(){return""===(t=this.parseArgumentRaw())?N(""):t;var t}parseArgumentRaw(){const t=this.peek();if(void 0===t)return"";if(t.type===Pt.GroupOpen){this.next();const t=this.parseExpression(()=>!1);return this.expect(Pt.GroupClose),P(t.map(t=>t.node))}return this.parseBaseAtom()?.node??""}parseOptionalArgument(){const t=this.peek();if(void 0===t||t.type!==Pt.Char||"["!==t.value)return;this.next();const e=this.parseExpression(t=>t.type===Pt.Char&&"]"===t.value),n=this.peek();return void 0!==n&&n.type===Pt.Char&&"]"===n.value&&this.next(),P(e.map(t=>t.node))}parseRawArgument(){const t=this.peek();if(void 0===t)return"";if(t.type!==Pt.GroupOpen)return this.next(),t.value;const e=t.position;this.next();let n=1,i=this.source.length;for(;;){const t=this.next();if(void 0===t)break;if(t.type===Pt.GroupOpen)n+=1;else if(t.type===Pt.GroupClose&&(n-=1,0===n)){i=t.position;break}}return this.source.slice(e+1,i)}expect(t){const e=this.peek();void 0===e||e.type!==t?t===Pt.GroupClose&&this.error({message:"Unmatched brace"}):this.next()}},ve="<mrow></mrow>";function xe(t,e){const n=e?.display??!1;if(""===t.trim())return{presentation:ve,errors:[]};const{atoms:i,errors:a}=function(t,e){const n=new ge(t,function(t){const e=[];let n=0;for(;n<t.length;){const i=t[n]??"";if("\\"===i){const i=jt(t,n);if(e.push(i),n+="rowBreak"===i.type?2:Math.max(1,i.value.length)+1,"command"===i.type&&Rt(i.value[0]??""))for(;n<t.length&&Ot(t[n]??"");)n+=1;continue}if(Ft(i)){const i=Mt(t,n);e.push(i),n+=i.value.length;continue}if(Ot(i)){n+=1;continue}const a=Ht(i,n);a&&e.push(a),n+=1}return e}(t),e);return{atoms:n.parseTopLevel(),errors:n.collectedErrors}}(t,n);return{presentation:ye(i),errors:a}}function ye(t){if(0===t.length)return ve;if(1===t.length){const e=t[0];return e?e.node:ve}return N(t.map(t=>t.node).join(""))}var we=/(?<!\$)\$([^$\n]+)\$$/,Le=/\$\$([^$\n]+)\$\$$/;function ke(t,e){const n=t.getBlock(e);return void 0!==n&&"code_block"!==n.type}function Se(t,e){const n=t-e;return n<0?null:{from:n,to:t}}var Ce={insertInline:"Insert formula",insertInlineTooltip:"Insert inline formula",editFormula:"Edit formula",latexLabel:"LaTeX",latexPlaceholder:"e.g. \\frac{a}{b} + \\sqrt{x}",previewLabel:"Preview",insertButton:"Insert",updateButton:"Update",cancelButton:"Cancel",displayToggle:"Display (block) equation",sizeLabel:"Size",sizeDefault:"Default",altLabel:"Description",altPlaceholder:"Spoken description (optional)",paletteLabel:"Symbols and structures",emptyPreview:"Nothing to preview yet.",inserted:"Formula inserted.",updated:"Formula updated.",editing:"Editing formula.",selected:"Formula selected. Press Enter to edit.",unknownCommand:t=>`Unknown LaTeX command: ${t}`,groupFractions:"Fractions",groupScripts:"Scripts",groupRoots:"Roots",groupAccents:"Accents",groupOperators:"Operators",groupFunctions:"Functions",groupGreek:"Greek letters",groupRelations:"Relations",groupSets:"Sets",groupLogic:"Logic",groupArrows:"Arrows",groupDelimiters:"Brackets",groupDots:"Dots",groupMatrices:"Matrices"},Ae=/* #__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar-D1jFXqLJ.mjs"),"./locales/de.ts":()=>import("./de-DY3obIAF.mjs"),"./locales/es.ts":()=>import("./es-CtOtKQCP.mjs"),"./locales/fr.ts":()=>import("./fr-DjMZ-3K5.mjs"),"./locales/hi.ts":()=>import("./hi-4CiAKVjT.mjs"),"./locales/pt.ts":()=>import("./pt-BkpVtod-.mjs"),"./locales/ru.ts":()=>import("./ru-BotG0MFT.mjs"),"./locales/zh.ts":()=>import("./zh-CWGAPVei.mjs")});async function $e(t){return x(Ae,t,Ce)}var ze=class{root;buttons=[];activeIndex=0;constructor(t,e,n){this.root=document.createElement("div"),this.root.className="notectl-math-palette",this.root.setAttribute("role","toolbar"),this.root.setAttribute("aria-label",e);for(const i of t)this.root.appendChild(this.buildGroup(i,n));this.root.addEventListener("keydown",t=>this.onKeydown(t)),this.setActive(0)}focus(){this.buttons[this.activeIndex]?.focus()}activeButton(){return this.buttons[this.activeIndex]}buildGroup(t,e){const n=document.createElement("div");n.className="notectl-math-palette__group",n.setAttribute("role","group"),n.setAttribute("aria-label",t.label);for(const i of t.items){const t=document.createElement("button");t.type="button",t.className="notectl-math-palette__btn",t.textContent=i.label,t.setAttribute("aria-label",i.ariaLabel),t.tabIndex=-1,t.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),t.addEventListener("click",()=>e(i.snippet)),this.buttons.push(t),n.appendChild(t)}return n}onKeydown(t){if("Enter"===t.key||" "===t.key)return t.preventDefault(),t.stopPropagation(),void this.buttons[this.activeIndex]?.click();const e=this.buttons.length-1;let n=this.activeIndex;switch(t.key){case"ArrowRight":case"ArrowDown":n=this.activeIndex>=e?0:this.activeIndex+1;break;case"ArrowLeft":case"ArrowUp":n=this.activeIndex<=0?e:this.activeIndex-1;break;case"Home":n=0;break;case"End":n=e;break;default:return}t.preventDefault(),t.stopPropagation(),this.setActive(n),this.buttons[n]?.focus()}setActive(t){const e=this.buttons[this.activeIndex];e&&(e.tabIndex=-1);const n=this.buttons[t];n&&(n.tabIndex=0),this.activeIndex=t}},_e=0,Ee=class{root;options;textarea;preview;previewEmpty;errorsList;altInput;commitBtn;palette=null;displayCheckbox=null;cancelBtn=null;fontSizeSelect=null;display;lastErrorKey="";constructor(t){this.options=t,this.display=t.initialDisplay??!1;const e=++_e;this.root=document.createElement("div"),this.root.className="notectl-formula-editor",this.root.setAttribute("role","group"),this.root.setAttribute("aria-label",t.locale.latexLabel),t.palette&&t.palette.length>0&&(this.palette=new ze(t.palette,t.locale.paletteLabel,t=>this.insertSnippet(t)),this.root.appendChild(this.palette.root)),this.textarea=this.buildLatexField(e),this.preview=document.createElement("div"),this.previewEmpty=document.createElement("div"),this.errorsList=document.createElement("ul"),this.altInput=this.buildAltField(e),this.commitBtn=document.createElement("button"),this.root.appendChild(this.buildPreview()),this.root.appendChild(this.errorsList),this.root.appendChild(this.altInput.parentElement),t.fontSizes&&t.fontSizes.length>0&&this.root.appendChild(this.buildSizeField(e)),"insert"===t.mode&&this.root.appendChild(this.buildDisplayToggle(e)),this.root.appendChild(this.buildActions()),this.errorsList.className="notectl-formula-editor__errors",this.errorsList.id=`notectl-formula-errors-${e}`,this.errorsList.setAttribute("aria-live","polite"),this.textarea.setAttribute("aria-describedby",this.errorsList.id),this.root.addEventListener("keydown",t=>this.onRootKeydown(t)),this.update()}focus(){this.textarea.focus(),this.textarea.setSelectionRange(this.textarea.value.length,this.textarea.value.length)}onRootKeydown(t){if("Escape"===t.key)return t.preventDefault(),t.stopPropagation(),void this.options.onCancel();"Tab"===t.key&&(t.preventDefault(),t.stopPropagation(),this.moveFocus(!t.shiftKey))}focusStops(){const t=[],e=this.palette?.activeButton();return e&&t.push(e),t.push(this.textarea,this.altInput),this.fontSizeSelect&&t.push(this.fontSizeSelect),this.displayCheckbox&&t.push(this.displayCheckbox),this.cancelBtn&&t.push(this.cancelBtn),t.push(this.commitBtn),t}moveFocus(t){const e=this.focusStops();if(0===e.length)return;const n=this.activeElement();let i=e.findIndex(t=>t===n);-1===i&&n&&this.palette?.root.contains(n)&&(i=0),-1===i&&(i=t?e.length-1:0),e[(i+(t?1:-1)+e.length)%e.length]?.focus()}activeElement(){let t=this.root.getRootNode().activeElement;for(;t?.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t}getResult(){const t=this.textarea.value.trim(),e=this.altInput.value.trim(),{presentation:n}=xe(t,{display:this.display});return{latex:t,mathml:M({presentation:n,latex:t,display:this.display,alt:e||void 0}),alt:e,display:this.display,fontSize:this.fontSizeSelect?.value??""}}insertSnippet(t){const e=this.textarea.selectionStart??this.textarea.value.length,n=this.textarea.selectionEnd??e,i=t.indexOf("$0"),a=i>=0?t.replace("$0",""):t,r=i>=0?i:a.length,o=this.textarea.value;this.textarea.value=o.slice(0,e)+a+o.slice(n);const l=e+r;this.textarea.focus(),this.textarea.setSelectionRange(l,l),this.update()}buildLatexField(t){const e=document.createElement("div");e.className="notectl-formula-editor__field";const n=document.createElement("label");n.className="notectl-formula-editor__label",n.htmlFor=`notectl-formula-latex-${t}`,n.textContent=this.options.locale.latexLabel;const i=document.createElement("textarea");return i.id=`notectl-formula-latex-${t}`,i.className="notectl-formula-editor__input",i.placeholder=this.options.locale.latexPlaceholder,i.rows=2,i.spellcheck=!1,i.value=this.options.initialLatex??"",i.addEventListener("input",()=>this.update()),i.addEventListener("keydown",t=>this.onTextareaKeydown(t)),e.appendChild(n),e.appendChild(i),this.root.appendChild(e),i}buildPreview(){const t=document.createElement("div");t.className="notectl-formula-editor__field";const e=document.createElement("span");return e.className="notectl-formula-editor__label",e.textContent=this.options.locale.previewLabel,this.preview.className="notectl-formula-editor__preview",this.previewEmpty.className="notectl-formula-editor__preview-empty",this.previewEmpty.textContent=this.options.locale.emptyPreview,t.appendChild(e),t.appendChild(this.previewEmpty),t.appendChild(this.preview),t}buildAltField(t){const e=document.createElement("div");e.className="notectl-formula-editor__field";const n=document.createElement("label");n.className="notectl-formula-editor__label",n.htmlFor=`notectl-formula-alt-${t}`,n.textContent=this.options.locale.altLabel;const i=document.createElement("input");return i.id=`notectl-formula-alt-${t}`,i.type="text",i.className="notectl-formula-editor__alt",i.placeholder=this.options.locale.altPlaceholder,i.value=this.options.initialAlt??"",e.appendChild(n),e.appendChild(i),i}buildSizeField(t){const e=document.createElement("div");e.className="notectl-formula-editor__field";const n=document.createElement("label");n.className="notectl-formula-editor__label",n.htmlFor=`notectl-formula-size-${t}`,n.textContent=this.options.locale.sizeLabel;const i=document.createElement("select");i.id=`notectl-formula-size-${t}`,i.className="notectl-formula-editor__size";const a=this.options.initialFontSize??"";i.appendChild(this.buildSizeOption("",this.options.locale.sizeDefault));for(const r of this.options.fontSizes??[])i.appendChild(this.buildSizeOption(`${r}px`,String(r)));return a&&!Array.from(i.options).some(t=>t.value===a)&&i.appendChild(this.buildSizeOption(a,a.replace("px",""))),i.value=a,i.addEventListener("change",()=>this.applyPreviewFontSize()),this.fontSizeSelect=i,e.appendChild(n),e.appendChild(i),e}buildSizeOption(t,e){const n=document.createElement("option");return n.value=t,n.textContent=e,n}applyPreviewFontSize(){this.preview.style.fontSize=this.fontSizeSelect?.value||""}buildDisplayToggle(t){const e=document.createElement("label");e.className="notectl-formula-editor__toggle",e.htmlFor=`notectl-formula-display-${t}`;const n=document.createElement("input");n.id=`notectl-formula-display-${t}`,n.type="checkbox",n.checked=this.display,n.addEventListener("change",()=>{this.display=n.checked,this.update()}),this.displayCheckbox=n;const i=document.createElement("span");return i.textContent=this.options.locale.displayToggle,e.appendChild(n),e.appendChild(i),e}buildActions(){const t=document.createElement("div");t.className="notectl-formula-editor__actions";const e=document.createElement("button");return e.type="button",e.className="notectl-formula-editor__btn",e.textContent=this.options.locale.cancel,e.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),e.addEventListener("click",()=>this.options.onCancel()),this.cancelBtn=e,this.commitBtn.type="button",this.commitBtn.className="notectl-formula-editor__btn notectl-formula-editor__btn--primary",this.commitBtn.textContent="edit"===this.options.mode?this.options.locale.commitUpdate:this.options.locale.commitInsert,this.commitBtn.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),this.commitBtn.addEventListener("click",()=>this.commit()),t.appendChild(e),t.appendChild(this.commitBtn),t}onTextareaKeydown(t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this.commit())}commit(){const t=this.getResult();t.latex?this.options.onCommit(t):this.options.onCancel()}update(){this.applyPreviewFontSize();const t=this.textarea.value.trim();if(!t)return this.preview.innerHTML="",this.previewEmpty.hidden=!1,void this.renderErrors([]);this.previewEmpty.hidden=!0;const{presentation:e,errors:n}=xe(t,{display:this.display});this.preview.innerHTML=M({presentation:e,display:this.display}),this.renderErrors(n.map(t=>t.command??t.message))}renderErrors(t){const e=t.join("");if(e!==this.lastErrorKey){this.lastErrorKey=e,this.errorsList.replaceChildren();for(const e of t){const t=document.createElement("li");t.textContent=e.startsWith("\\")?this.options.locale.unknownCommand(e):e,this.errorsList.appendChild(t)}}}};function Be(t){return[{id:"fractions",label:(e={fractions:t.groupFractions,scripts:t.groupScripts,roots:t.groupRoots,accents:t.groupAccents,operators:t.groupOperators,functions:t.groupFunctions,greek:t.groupGreek,relations:t.groupRelations,sets:t.groupSets,logic:t.groupLogic,arrows:t.groupArrows,delimiters:t.groupDelimiters,dots:t.groupDots,matrices:t.groupMatrices}).fractions,items:[{label:"a╱b",ariaLabel:"Fraction",snippet:"\\frac{$0}{}"},{label:"⒞",ariaLabel:"Binomial coefficient",snippet:"\\binom{$0}{}"}]},{id:"scripts",label:e.scripts,items:[{label:"xⁿ",ariaLabel:"Superscript",snippet:"^{$0}"},{label:"xₙ",ariaLabel:"Subscript",snippet:"_{$0}"},{label:"xⁿₘ",ariaLabel:"Subscript and superscript",snippet:"_{$0}^{}"}]},{id:"roots",label:e.roots,items:[{label:"√",ariaLabel:"Square root",snippet:"\\sqrt{$0}"},{label:"ⁿ√",ariaLabel:"N-th root",snippet:"\\sqrt[$0]{}"}]},{id:"accents",label:e.accents,items:[{label:"→",ariaLabel:"Vector",snippet:"\\vec{$0}"},{label:"â",ariaLabel:"Hat",snippet:"\\hat{$0}"},{label:"ā",ariaLabel:"Overline",snippet:"\\overline{$0}"},{label:"ȧ",ariaLabel:"Dot above",snippet:"\\dot{$0}"},{label:"ã",ariaLabel:"Tilde",snippet:"\\tilde{$0}"}]},{id:"operators",label:e.operators,items:[{label:"∑",ariaLabel:"Sum with limits",snippet:"\\sum_{$0}^{}"},{label:"∏",ariaLabel:"Product with limits",snippet:"\\prod_{$0}^{}"},{label:"∫",ariaLabel:"Integral with limits",snippet:"\\int_{$0}^{}"},{label:"∬",ariaLabel:"Double integral",snippet:"\\iint "},{label:"∮",ariaLabel:"Contour integral",snippet:"\\oint "},{label:"lim",ariaLabel:"Limit",snippet:"\\lim_{$0}"},{label:"∂",ariaLabel:"Partial derivative",snippet:"\\partial "},{label:"∇",ariaLabel:"Nabla (del)",snippet:"\\nabla "},{label:"×",ariaLabel:"Times",snippet:"\\times "},{label:"·",ariaLabel:"Dot product",snippet:"\\cdot "},{label:"±",ariaLabel:"Plus or minus",snippet:"\\pm "},{label:"÷",ariaLabel:"Division",snippet:"\\div "},{label:"∞",ariaLabel:"Infinity",snippet:"\\infty "}]},{id:"functions",label:e.functions,items:[{label:"sin",ariaLabel:"Sine",snippet:"\\sin "},{label:"cos",ariaLabel:"Cosine",snippet:"\\cos "},{label:"tan",ariaLabel:"Tangent",snippet:"\\tan "},{label:"log",ariaLabel:"Logarithm",snippet:"\\log "},{label:"ln",ariaLabel:"Natural logarithm",snippet:"\\ln "},{label:"exp",ariaLabel:"Exponential function",snippet:"\\exp "}]},{id:"greek",label:e.greek,items:[{label:"α",ariaLabel:"Alpha",snippet:"\\alpha "},{label:"β",ariaLabel:"Beta",snippet:"\\beta "},{label:"γ",ariaLabel:"Gamma",snippet:"\\gamma "},{label:"δ",ariaLabel:"Delta",snippet:"\\delta "},{label:"ε",ariaLabel:"Epsilon",snippet:"\\varepsilon "},{label:"ζ",ariaLabel:"Zeta",snippet:"\\zeta "},{label:"η",ariaLabel:"Eta",snippet:"\\eta "},{label:"θ",ariaLabel:"Theta",snippet:"\\theta "},{label:"κ",ariaLabel:"Kappa",snippet:"\\kappa "},{label:"λ",ariaLabel:"Lambda",snippet:"\\lambda "},{label:"μ",ariaLabel:"Mu",snippet:"\\mu "},{label:"ν",ariaLabel:"Nu",snippet:"\\nu "},{label:"ξ",ariaLabel:"Xi",snippet:"\\xi "},{label:"π",ariaLabel:"Pi",snippet:"\\pi "},{label:"ρ",ariaLabel:"Rho",snippet:"\\rho "},{label:"σ",ariaLabel:"Sigma",snippet:"\\sigma "},{label:"τ",ariaLabel:"Tau",snippet:"\\tau "},{label:"φ",ariaLabel:"Phi",snippet:"\\varphi "},{label:"χ",ariaLabel:"Chi",snippet:"\\chi "},{label:"ψ",ariaLabel:"Psi",snippet:"\\psi "},{label:"ω",ariaLabel:"Omega",snippet:"\\omega "},{label:"Γ",ariaLabel:"Capital gamma",snippet:"\\Gamma "},{label:"Δ",ariaLabel:"Capital delta",snippet:"\\Delta "},{label:"Θ",ariaLabel:"Capital theta",snippet:"\\Theta "},{label:"Λ",ariaLabel:"Capital lambda",snippet:"\\Lambda "},{label:"Π",ariaLabel:"Capital pi",snippet:"\\Pi "},{label:"Σ",ariaLabel:"Capital sigma",snippet:"\\Sigma "},{label:"Φ",ariaLabel:"Capital phi",snippet:"\\Phi "},{label:"Ψ",ariaLabel:"Capital psi",snippet:"\\Psi "},{label:"Ω",ariaLabel:"Capital omega",snippet:"\\Omega "}]},{id:"relations",label:e.relations,items:[{label:"≤",ariaLabel:"Less than or equal to",snippet:"\\leq "},{label:"≥",ariaLabel:"Greater than or equal to",snippet:"\\geq "},{label:"≠",ariaLabel:"Not equal to",snippet:"\\neq "},{label:"≈",ariaLabel:"Approximately equal to",snippet:"\\approx "},{label:"≡",ariaLabel:"Equivalent to",snippet:"\\equiv "},{label:"∼",ariaLabel:"Similar to",snippet:"\\sim "},{label:"≅",ariaLabel:"Congruent to",snippet:"\\cong "},{label:"∝",ariaLabel:"Proportional to",snippet:"\\propto "}]},{id:"sets",label:e.sets,items:[{label:"∈",ariaLabel:"Element of",snippet:"\\in "},{label:"∉",ariaLabel:"Not an element of",snippet:"\\notin "},{label:"⊂",ariaLabel:"Subset of",snippet:"\\subset "},{label:"⊆",ariaLabel:"Subset of or equal to",snippet:"\\subseteq "},{label:"∪",ariaLabel:"Union",snippet:"\\cup "},{label:"∩",ariaLabel:"Intersection",snippet:"\\cap "},{label:"∅",ariaLabel:"Empty set",snippet:"\\emptyset "},{label:"ℝ",ariaLabel:"Real numbers",snippet:"\\mathbb{R}"},{label:"ℕ",ariaLabel:"Natural numbers",snippet:"\\mathbb{N}"},{label:"ℤ",ariaLabel:"Integers",snippet:"\\mathbb{Z}"},{label:"ℚ",ariaLabel:"Rational numbers",snippet:"\\mathbb{Q}"},{label:"ℂ",ariaLabel:"Complex numbers",snippet:"\\mathbb{C}"}]},{id:"logic",label:e.logic,items:[{label:"∀",ariaLabel:"For all",snippet:"\\forall "},{label:"∃",ariaLabel:"There exists",snippet:"\\exists "},{label:"¬",ariaLabel:"Logical not",snippet:"\\neg "},{label:"∧",ariaLabel:"Logical and",snippet:"\\land "},{label:"∨",ariaLabel:"Logical or",snippet:"\\lor "},{label:"⟹",ariaLabel:"Implies",snippet:"\\implies "},{label:"⟺",ariaLabel:"If and only if",snippet:"\\iff "}]},{id:"arrows",label:e.arrows,items:[{label:"→",ariaLabel:"Right arrow",snippet:"\\to "},{label:"⇒",ariaLabel:"Rightwards double arrow",snippet:"\\Rightarrow "},{label:"↔",ariaLabel:"Left-right arrow",snippet:"\\leftrightarrow "},{label:"↦",ariaLabel:"Maps to",snippet:"\\mapsto "}]},{id:"delimiters",label:e.delimiters,items:[{label:"( )",ariaLabel:"Auto-sized parentheses",snippet:"\\left($0\\right)"},{label:"[ ]",ariaLabel:"Auto-sized brackets",snippet:"\\left[$0\\right]"},{label:"{ }",ariaLabel:"Auto-sized braces",snippet:"\\left\\{$0\\right\\}"},{label:"|x|",ariaLabel:"Absolute value",snippet:"\\left|$0\\right|"},{label:"‖x‖",ariaLabel:"Norm",snippet:"\\left\\|$0\\right\\|"},{label:"⌊x⌋",ariaLabel:"Floor",snippet:"\\left\\lfloor $0\\right\\rfloor"},{label:"⌈x⌉",ariaLabel:"Ceiling",snippet:"\\left\\lceil $0\\right\\rceil"}]},{id:"dots",label:e.dots,items:[{label:"⋯",ariaLabel:"Centred ellipsis",snippet:"\\cdots "},{label:"…",ariaLabel:"Baseline ellipsis",snippet:"\\ldots "},{label:"⋮",ariaLabel:"Vertical ellipsis",snippet:"\\vdots "},{label:"⋱",ariaLabel:"Diagonal ellipsis",snippet:"\\ddots "}]},{id:"matrices",label:e.matrices,items:[{label:"[ ]",ariaLabel:"Bracket matrix",snippet:"\\begin{bmatrix} $0 & \\\\ & \\end{bmatrix}"},{label:"( )",ariaLabel:"Parenthesis matrix",snippet:"\\begin{pmatrix} $0 & \\\\ & \\end{pmatrix}"},{label:"{",ariaLabel:"Cases",snippet:"\\begin{cases} $0 & \\\\ & \\end{cases}"}]}];var e}function Ie(t,e){const n=new Ee({locale:(i=e.locale,{latexLabel:i.latexLabel,latexPlaceholder:i.latexPlaceholder,previewLabel:i.previewLabel,emptyPreview:i.emptyPreview,altLabel:i.altLabel,altPlaceholder:i.altPlaceholder,displayToggle:i.displayToggle,sizeLabel:i.sizeLabel,sizeDefault:i.sizeDefault,commitInsert:i.insertButton,commitUpdate:i.updateButton,cancel:i.cancelButton,paletteLabel:i.paletteLabel,unknownCommand:i.unknownCommand}),mode:e.mode,initialLatex:e.initialLatex,initialAlt:e.initialAlt,initialDisplay:e.initialDisplay,initialFontSize:e.initialFontSize,fontSizes:e.fontSizes,palette:Be(e.locale),onCommit:e.onCommit,onCancel:e.onClose});var i;return t.appendChild(n.root),requestAnimationFrame(()=>n.focus()),n}var De=class{context;locale;fontSizes;panel=null;outsideHandler=null;constructor(t,e,n){this.context=t,this.locale=e,this.fontSizes=n}isOpen(){return null!==this.panel}openInsert(t){if(this.context.isReadOnly())return;const e=Ne();this.open({rect:e,mode:"insert",initialDisplay:t,onCommit:t=>{ut(this.context,this.locale,t),this.close(!0)}})}openEdit(t){this.context.isReadOnly()||(this.context.announce(this.locale.editing),this.open({rect:t.rect??Ne(),mode:"edit",initialLatex:t.latex,initialAlt:t.alt,initialDisplay:"display"===t.kind,initialFontSize:t.fontSize,onCommit:e=>{this.commitEdit(t,e),this.context.announce(this.locale.updated),this.close(!0)}}))}close(t){this.panel&&(this.outsideHandler&&(document.removeEventListener("mousedown",this.outsideHandler,!0),this.outsideHandler=null),this.panel.remove(),this.panel=null,t&&this.context.getContainer().focus())}commitEdit(t,e){const n=pt(e);"inline"===t.kind&&t.blockId&&void 0!==t.offset?function(t,e,n,i){const a=t.getState().transaction("command").setInlineNodeAttr(e,n,lt(i)).build();t.dispatch(a)}(this.context,t.blockId,t.offset,n):"display"===t.kind&&t.path&&function(t,e,n){const i=t.getState().transaction("command").setNodeAttr(e,lt(n)).build();t.dispatch(i)}(this.context,t.path,n)}open(t){this.close(!1);const e=document.createElement("div");e.className="notectl-formula-overlay",e.setAttribute("role","dialog"),e.setAttribute("aria-label","edit"===t.mode?this.locale.editFormula:this.locale.insertInline),this.panel=e,Ie(e,{context:this.context,locale:this.locale,mode:t.mode,initialLatex:t.initialLatex,initialAlt:t.initialAlt,initialDisplay:t.initialDisplay,initialFontSize:t.initialFontSize,fontSizes:this.fontSizes,onCommit:t.onCommit,onClose:()=>this.close(!0)}),this.context.getPluginContainer("top").appendChild(e),y(e),function(t,e){const n=e?e.bottom:window.innerHeight/3,i=e?e.left:window.innerWidth/3,a=t.offsetWidth||360,r=window.innerWidth-a-8,o=Math.max(8,Math.min(i,r)),l=window.innerHeight-t.offsetHeight-8,s=Math.min(n+8,Math.max(8,l));t.style.left=`${Math.round(o)}px`,t.style.top=`${Math.round(s)}px`}(e,t.rect),this.installOutsideHandler()}installOutsideHandler(){const t=t=>{this.panel&&!t.composedPath().includes(this.panel)&&this.close(!1)};this.outsideHandler=t,requestAnimationFrame(()=>{this.outsideHandler&&document.addEventListener("mousedown",t,!0)})}};function Ne(){const t=window.getSelection();if(!t||0===t.rangeCount)return null;const e=t.getRangeAt(0).getBoundingClientRect();return 0===e.width&&0===e.height&&0===e.top&&0===e.left?null:e}function Pe(t){const e=document.createElement("template");return e.innerHTML=t,e.content}function qe(t){const e=function(t){const e=L.sanitize(t,{ALLOWED_TAGS:[...at],ALLOWED_ATTR:[...rt]});return/<math[\s>]/i.test(e)?e:null}(t.outerHTML);if(!e)return null;const n=G(e);return{mathml:n,latex:H(n)??"",alt:"",fontSize:Q(t)}}var Re=class{id="formula";name="Formula";priority=46;config;resolvedKeymap;fontSizes;locale=Ce;overlay=null;context=null;clickHandler=null;constructor(t){this.config={...it,...t},this.resolvedKeymap={...et,...t?.keymap},this.fontSizes=this.config.fontSizes??nt}async init(t){var e;this.context=t,this.locale=await g(t,this.config.locale,Ce,$e),t.registerStyleSheet("\n.notectl-math math {\n\tfont-family: 'Notectl Math', math;\n}\n\n.notectl-math--inline {\n\tdisplay: inline-block;\n\tvertical-align: middle;\n\tpadding: 0 1px;\n\tborder-radius: 3px;\n\tcursor: pointer;\n}\n\n.notectl-math--inline:hover {\n\tbackground: var(--notectl-highlight, rgba(0, 0, 0, 0.06));\n}\n\n.notectl-math--inline:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-math--inline math {\n\tfont-size: 1.15em;\n}\n\n.notectl-math--display {\n\tdisplay: block;\n\tmargin: 12px 0;\n\ttext-align: center;\n\tcursor: pointer;\n\tuser-select: none;\n\t-webkit-user-select: none;\n}\n\n.notectl-math--display math {\n\tfont-size: 1.35em;\n\tdisplay: inline-block;\n}\n\n.notectl-math--display.notectl-math--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 4px;\n\tborder-radius: 6px;\n}\n\n.notectl-math__error,\n.notectl-math merror {\n\tcolor: var(--notectl-danger, #c0392b);\n\tbackground: var(--notectl-danger-bg, rgba(192, 57, 43, 0.1));\n\tborder-radius: 3px;\n\tpadding: 0 2px;\n}\n"),t.registerStyleSheet("\n.notectl-formula-editor {\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 8px;\n\tpadding: 10px;\n\tmin-width: 320px;\n\tmax-width: 460px;\n\tbox-sizing: border-box;\n}\n\n.notectl-formula-editor__field {\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: 4px;\n}\n\n.notectl-formula-editor__label {\n\tfont-size: 12px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-fg-muted, #555);\n}\n\n.notectl-formula-editor__input {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tpadding: 6px 8px;\n\tfont-family: 'SF Mono', 'Fira Code', Menlo, Consolas, monospace;\n\tfont-size: 13px;\n\tline-height: 1.5;\n\tresize: vertical;\n\tmin-height: 56px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-formula-editor__alt {\n\twidth: 100%;\n\tbox-sizing: border-box;\n\tpadding: 5px 8px;\n\tfont-size: 13px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-formula-editor__size {\n\tbox-sizing: border-box;\n\tpadding: 5px 8px;\n\tfont-size: 13px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tcolor: var(--notectl-fg);\n\tcursor: pointer;\n}\n\n.notectl-formula-editor__size:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-formula-editor__preview {\n\tmin-height: 44px;\n\tpadding: 8px;\n\tborder: 1px dashed var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-raised, #fafafa);\n\ttext-align: center;\n\toverflow-x: auto;\n}\n\n.notectl-formula-editor__preview math {\n\tfont-family: 'Notectl Math', math;\n\tfont-size: 1.3em;\n}\n\n.notectl-formula-editor__preview-empty {\n\tcolor: var(--notectl-fg-muted, #888);\n\tfont-size: 13px;\n}\n\n.notectl-formula-editor__errors {\n\tcolor: var(--notectl-danger, #c0392b);\n\tfont-size: 12px;\n\tmargin: 0;\n\tpadding-inline-start: 16px;\n}\n\n.notectl-formula-editor__row {\n\tdisplay: flex;\n\tgap: 8px;\n\talign-items: center;\n}\n\n.notectl-formula-editor__toggle {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 6px;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg);\n}\n\n.notectl-formula-editor__actions {\n\tdisplay: flex;\n\tgap: 8px;\n\tjustify-content: flex-end;\n\tmargin-top: 2px;\n}\n\n.notectl-formula-editor__btn {\n\tpadding: 6px 14px;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 4px;\n\tbackground: var(--notectl-surface-raised);\n\tcolor: var(--notectl-fg);\n\tcursor: pointer;\n\tfont-size: 13px;\n}\n\n.notectl-formula-editor__btn--primary {\n\tbackground: var(--notectl-primary);\n\tborder-color: var(--notectl-primary);\n\tcolor: var(--notectl-primary-fg, #fff);\n}\n\n.notectl-formula-editor__btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-formula-overlay {\n\tposition: fixed;\n\tz-index: 1000;\n\tborder: 1px solid var(--notectl-border);\n\tborder-radius: 8px;\n\tbackground: var(--notectl-surface-overlay, #fff);\n\tbox-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);\n}\n\n.notectl-math-palette {\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\tgap: 8px;\n\tpadding: 2px 2px 8px;\n\tborder-bottom: 1px solid var(--notectl-border);\n\tmargin-bottom: 2px;\n\tmax-height: 216px;\n\toverflow-y: auto;\n}\n\n.notectl-math-palette__group {\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\tgap: 2px;\n}\n\n.notectl-math-palette__group + .notectl-math-palette__group {\n\tborder-inline-start: 1px solid var(--notectl-border);\n\tpadding-inline-start: 6px;\n}\n\n.notectl-math-palette__btn {\n\tmin-width: 30px;\n\theight: 30px;\n\tpadding: 0 6px;\n\tborder: 1px solid transparent;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-fg);\n\tcursor: pointer;\n\tfont-size: 15px;\n\tline-height: 1;\n}\n\n.notectl-math-palette__btn:hover {\n\tbackground: var(--notectl-surface-raised);\n}\n\n.notectl-math-palette__btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n"),this.config.mathFont&&t.registerStyleSheet(function(t){const e=(t.family.split(",")[0]??t.name).trim().replace(/['"]/g,"");return(t.fontFaces??[]).map(t=>{const n=[`font-family: '${e}'`,`src: ${t.src}`];return t.weight&&n.push(`font-weight: ${t.weight}`),t.style&&n.push(`font-style: ${t.style}`),n.push(`font-display: ${t.display??"swap"}`),`@font-face { ${n.join("; ")}; }`}).join("\n")}(this.config.mathFont)),t.registerInlineNodeSpec({type:Y,attrs:{mathml:{default:""},latex:{default:""},alt:{default:""},fontSize:{default:""}},toDOM(t){const e=document.createElement("span");return e.className="notectl-math notectl-math--inline",e.setAttribute("contenteditable","false"),e.setAttribute("data-inline-type",Y),W(e,Z(t.attrs)),V(e,t.attrs),e},toHTMLString:t=>X(Z(t.attrs)),parseHTML:[{tag:"math",getAttrs:t=>J(t,!1)}],sanitize:{tags:[...at],attrs:[...rt]}}),t.registerNodeSpec({type:tt,group:"block",isVoid:!0,selectable:!0,attrs:{mathml:{default:""},latex:{default:""},alt:{default:""},fontSize:{default:""}},toDOM(t){const e=m("div",t.id);return e.className="notectl-math notectl-math--display",e.setAttribute("data-void","true"),e.setAttribute("data-selectable","true"),W(e,Z(t.attrs)),V(e,t.attrs),e},toHTML:t=>X(Z(t.attrs)),parseHTML:[{tag:"math",getAttrs:t=>J(t,!0)}],sanitize:{tags:[...at],attrs:[...rt]}}),this.overlay=new De(t,this.locale,this.fontSizes),t.registerNodeView(tt,(e={onEdit:(t,e)=>this.editDisplay(t,e),onSelect:()=>t.announce(this.locale.selected)},t=>{let n=t.id,i=!1;const a=m("div",t.id);return a.className="notectl-math notectl-math--display",a.setAttribute("data-void","true"),a.setAttribute("data-selectable","true"),W(a,Z(t.attrs)),V(a,t.attrs),a.addEventListener("dblclick",t=>{t.preventDefault(),e.onEdit(n,a.getBoundingClientRect())}),{dom:a,contentDOM:null,update:t=>"math_display"===t.type&&(n=t.id,a.setAttribute("data-block-id",t.id),W(a,Z(t.attrs)),V(a,t.attrs),!0),selectNode(){a.classList.add("notectl-math--selected"),i||(i=!0,e.onSelect())},deselectNode(){a.classList.remove("notectl-math--selected"),i=!1}}}));for(const a of[{pattern:Le,handler(t,e){const i=t.selection;if(!c(i)||!o(i))return null;const a=(e[1]??"").trim();if(!a)return null;const r=i.anchor.blockId;if(!ke(t,r))return null;const s=Se(i.anchor.offset,e[0].length);if(!s)return null;const p=t.doc.children.findIndex(t=>t.id===r);if(-1===p)return null;const{presentation:d}=xe(a,{display:!0}),m=M({presentation:d,latex:a,display:!0}),h=t.transaction("input").deleteTextAt(r,s.from,s.to);return function(t,e,i){const a=n(u(tt),[],void 0,lt(i)),r=n(u("paragraph"));t.insertNode([],e,a).insertNode([],e+1,r).setSelection(l(a.id,[]))}(h,p+1,{mathml:m,latex:a,alt:"",fontSize:""}),h.build()}},{pattern:we,handler(t,e){const n=t.selection;if(!c(n)||!o(n))return null;const a=(e[1]??"").trim();if(!a)return null;const r=n.anchor.blockId;if(!ke(t,r))return null;const l=Se(n.anchor.offset,e[0].length);if(!l)return null;const{presentation:p}=xe(a,{display:!1}),u=M({presentation:p,latex:a,display:!1}),m=i(d(Y),{mathml:u,latex:a,alt:"",fontSize:""});return t.transaction("input").deleteTextAt(r,l.from,l.to).insertInlineNode(r,l.from,m).setSelection(s(r,l.from+1)).build()}}])t.registerInputRule(a);t.registerPasteInterceptor((t,e,n)=>{if(!function(t){if(!t)return!1;const e=Pe(t);if(!e.querySelector("math"))return!1;const n=e.cloneNode(!0);for(const i of Array.from(n.querySelectorAll('math, [aria-hidden="true"]')))i.remove();return""===(n.textContent??"").trim()}(e))return null;const i=function(t){if(!t)return[];const e=Pe(t);for(const n of Array.from(e.querySelectorAll('[aria-hidden="true"]')))n.remove();return Array.from(e.querySelectorAll("math"))}(e).map(qe).filter(t=>null!==t);return 0===i.length?null:i.every(t=>{return e=t.mathml,!/<math\b[^>]*\bdisplay=["']block["']/i.test(e);var e})?st(n,i):ct(n,i)},{name:"formula",priority:40}),this.registerCommands(t),this.registerKeymap(t),function(t,e,n){t.registerToolbarItem({id:"formula",group:"insert",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round"><path d="M18 5 H6 L12 12 L6 19 H18"/></svg>',label:e.insertInline,tooltip:e.insertInlineTooltip,command:"insertInlineFormula",popupType:"custom",renderPopup:(t,i,a)=>{Ie(t,{context:i,locale:e,mode:"insert",fontSizes:n,onClose:a,onCommit:t=>{ut(i,e,t),a(),i.getContainer().focus()}})}})}(t,this.locale,this.fontSizes),this.installClickToEdit(t)}destroy(){this.clickHandler&&this.context&&this.context.getContainer().removeEventListener("click",this.clickHandler),this.clickHandler=null,this.overlay?.close(!1),this.overlay=null,this.context=null}registerCommands(n){n.registerCommand("insertInlineFormula",()=>{const i=function(n){const i=n.selection;if(!c(i)||!o(i))return null;const r=i.anchor.blockId,l=n.getBlock(r);if(!l)return null;const s=i.anchor.offset;for(const{child:o,from:c,to:p}of e(a(l)))if(t(o)&&"math_inline"===o.inlineType&&(p===s||c===s)){const t=Z(o.attrs);return{kind:"inline",blockId:r,offset:c,latex:t.latex,alt:t.alt,fontSize:t.fontSize,rect:null}}return null}(n.getState());return i?(this.overlay?.openEdit(i),!0):(this.overlay?.openInsert(!1),!0)}),n.registerCommand("insertDisplayFormula",()=>{const t=ot(n.getState());return t?(this.editDisplay(t,null),!0):(this.overlay?.openInsert(!0),!0)})}registerKeymap(t){const e={},n=this.resolvedKeymap.insertInline,i=this.resolvedKeymap.insertDisplay;n&&(e[n]=()=>t.executeCommand("insertInlineFormula")),i&&(e[i]=()=>t.executeCommand("insertDisplayFormula")),e.Enter=()=>{const e=ot(t.getState());return!!e&&(this.editDisplay(e,null),!0)},t.registerKeymap(e,{priority:"context"})}installClickToEdit(n){const i=n.getContainer(),r=r=>{if(n.isReadOnly())return;const o=r.target?.closest(".notectl-math--inline");if(!o)return;const l=function(n,i,r){const o=b(n,i,0);if(!o)return null;const l=function(n,i,r){const o=n.getBlock(i);if(!o)return null;for(const{child:l,from:s}of e(a(o)))if(s===r&&t(l)&&"math_inline"===l.inlineType)return Z(l.attrs);return null}(r,o.blockId,o.offset);return l?{kind:"inline",blockId:o.blockId,offset:o.offset,latex:l.latex,alt:l.alt,fontSize:l.fontSize,rect:i.getBoundingClientRect()}:null}(i,o,n.getState());l&&(r.preventDefault(),this.overlay?.openEdit(l))};this.clickHandler=r,i.addEventListener("click",r)}editDisplay(t,e){if(!this.overlay||!this.context)return;const n=function(t,e,n){const i=t.getBlock(e);if(!i||"math_display"!==i.type)return null;const a=Z(i.attrs);return{kind:"display",path:t.getNodePath(e)??[e],latex:a.latex,alt:a.alt,fontSize:a.fontSize,rect:n}}(this.context.getState(),t,e);n&&this.overlay.openEdit(n)}};export{rt as a,M as c,xe as i,Ce as n,at as o,$e as r,et as s,Re as t};
2
+ //# sourceMappingURL=FormulaPlugin-66Cc9sH2.mjs.map