@grapesjs/studio-sdk-plugins 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,13 +1,13 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react");const wr="app.grapesjs.com",bs="app-stage.grapesjs.com",Kr=[wr,bs,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],Nl="license:check:start",Al="license:check:end",Cs=()=>typeof window<"u",Tl=({isDev:n,isStage:e})=>`${n?"":`https://${e?bs:wr}`}/api`,Dl=()=>{const n=Cs()&&window.location.hostname;return!!n&&(Kr.includes(n)||Kr.some(e=>n.endsWith(e)))},El=()=>(Cs()&&window.location.hostname)===wr;function xs(n){return typeof n=="function"}var Rl={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.6",STUDIO_NPM_PACKAGE_VERSION:"1.0.25"};const Il=Rl.NODE_ENV!=="production";async function zl({path:n,method:e="GET",headers:t={},body:r}){const s=`${Tl({isDev:Il,isStage:!El()})}${n}`,o={method:e,headers:{"Content-Type":"application/json",...t}};r&&(o.body=JSON.stringify(r));const l=await fetch(s,o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}function Vl(n){const e=n;return e.init=t=>r=>n(r,t),e}const kr=n=>Vl(n);async function Sr({editor:n,pluginName:e,licenseKey:t,cleanup:r}){let i=!1;const s=Dl();n.on(Nl,()=>{i=!0}),n.on(Al,({sdkLicense:o})=>{o||r()}),setTimeout(async()=>{if(!i){if(s)return;t&&await Pl({licenseKey:t,pluginName:e})||r()}},2e3)}async function Pl({licenseKey:n,pluginName:e}){try{const t=await zl({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:e})}),{license:r}=t.result||{};return!!r}catch(t){return console.error("Error during SDK license check:",t),!1}}const jr=(...n)=>n.map(e=>`[data-gjs-type="${e}"]`).join(","),Bl="dialogComponent",Hl=function(n,e={}){const{Blocks:t,Components:r}=n,{licenseKey:i}=e,s="gjs-plg-dialog",o="gjs-plg-dialog-overlay",l="gjs-plg-dialog-content",a="gjs-plg-dialog-close",c="gjs-plg-dialog-title",h="gjs-plg-dialog-body",f="gjs-plg-dialog-description",d="gjs-plg-dialog-placeholder";t.add(s,{label:"Dialog",media:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react");const Ar="app.grapesjs.com",vs="app-stage.grapesjs.com",Zr=[Ar,vs,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],Pl="license:check:start",Vl="license:check:end",Os=()=>typeof window<"u",Bl=({isDev:n,isStage:e})=>`${n?"":`https://${e?vs:Ar}`}/api`,Hl=()=>{const n=Os()&&window.location.hostname;return!!n&&(Zr.includes(n)||Zr.some(e=>n.endsWith(e)))},Ll=()=>(Os()&&window.location.hostname)===Ar;function Ns(n){return typeof n=="function"}var Fl={NODE_ENV:"production",NPM_PACKAGE_VERSION:"1.0.7",STUDIO_NPM_PACKAGE_VERSION:"1.0.25"};const Wl=Fl.NODE_ENV!=="production";async function $l({path:n,method:e="GET",headers:t={},body:r}){const s=`${Bl({isDev:Wl,isStage:!Ll()})}${n}`,o={method:e,headers:{"Content-Type":"application/json",...t}};r&&(o.body=JSON.stringify(r));const l=await fetch(s,o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return l.json()}function Jl(n){const e=n;return e.init=t=>r=>n(r,t),e}const Mn=n=>Jl(n);async function vn({editor:n,pluginName:e,licenseKey:t,cleanup:r}){let i=!1;const s=Hl();n.on(Pl,()=>{i=!0}),n.on(Vl,({sdkLicense:o})=>{o||r()}),setTimeout(async()=>{if(!i){if(s)return;t&&await ql({licenseKey:t,pluginName:e})||r()}},2e3)}async function ql({licenseKey:n,pluginName:e}){try{const t=await $l({path:`/sdk/${n}`,method:"POST",body:JSON.stringify({d:window.location.hostname,pn:e})}),{license:r}=t.result||{};return!!r}catch(t){return console.error("Error during SDK license check:",t),!1}}const Xr="gjs-plg-",Yr=(...n)=>n.map(e=>`[data-gjs-type="${e}"]`).join(","),Kl="dialogComponent",jl=function(n,e={}){const{Blocks:t,Components:r}=n,{licenseKey:i}=e,s="gjs-plg-dialog",o="gjs-plg-dialog-overlay",l="gjs-plg-dialog-content",a="gjs-plg-dialog-close",c="gjs-plg-dialog-title",h="gjs-plg-dialog-body",f="gjs-plg-dialog-description",d="gjs-plg-dialog-placeholder";t.add(s,{label:"Dialog",media:`
2
2
  <svg viewBox="0 0 24 24">
3
3
  <path d="M4 4h16v10H8l-4 4V4z"></path>
4
4
  </svg>
5
- `,category:"Extra",content:{type:s},activate:!0,...e.block}),r.addType(s,{model:{defaults:{tagName:"div",attributes:{class:s,"data-type-role":s},components:[{type:o},{type:d}],draggable:jr("wrapper"),droppable:jr(s),styles:`
5
+ `,category:"Extra",content:{type:s},activate:!0,...e.block}),r.addType(s,{model:{defaults:{tagName:"div",attributes:{class:s,"data-type-role":s},components:[{type:o},{type:d}],draggable:Yr("wrapper"),droppable:Yr(s),styles:`
6
6
  .${s} {
7
7
  position: relative;
8
8
  z-index: 1;
9
9
  }
10
- `,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(u){var m;(m=u.getSelected())==null||m.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(u){const m=this;function g(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),D=m.querySelector('[data-type-role="gjs-plg-dialog-close"]');function j(){E.style.display="none"}v?(m._onCloseWhenPressingX=j,D.addEventListener("click",m._onCloseWhenPressingX)):(D.removeEventListener("click",m._onCloseWhenPressingX),m._onCloseWhenPressingX=null)}function b(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function D(j){j.key==="Escape"&&(E.style.display="none")}v?(m._onCloseWhenPressingEsc=D,m.addEventListener("keydown",m._onCloseWhenPressingEsc)):(m.removeEventListener("keydown",m._onCloseWhenPressingEsc),m._onCloseWhenPressingEsc=null)}function S(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function D(){E.style.display="flex"}v?(m._onOpenWhenLeavingWindow=D,document.addEventListener("mouseleave",m._onOpenWhenLeavingWindow)):(document.removeEventListener("mouseleave",m._onOpenWhenLeavingWindow),m._onOpenWhenLeavingWindow=null)}function N(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function D(){const j=document.documentElement.scrollTop;v&&j>=Number(v)&&(E.style.display="flex")}v?(m._onOpenWhenScrollingToLevel=D,document.addEventListener("scroll",m._onOpenWhenScrollingToLevel)):(document.removeEventListener("scroll",m._onOpenWhenScrollingToLevel),m._onOpenWhenScrollingToLevel=null)}g(u.closeWhenPressingX),b(u.closeWhenPressingEsc),S(u.openWhenLeavingWindow),N(u.openWhenScrollingToLevel)}},init(){this.on("active",this.handleOpenWhenClickPlaceholder)},handleOpenWhenClickPlaceholder(){this.view.el.querySelector('[data-type-role="gjs-plg-dialog-placeholder"]').addEventListener("click",()=>{const m=this.view.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');m.style.display="flex"})}},view:{onActive(){const u=this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');u.style.display="flex"}}}),r.addType(o,{model:{defaults:{tagName:"div",attributes:{class:o,"data-type-role":o},components:{type:l},droppable:!1,draggable:!1,styles:`
10
+ `,traits:[{type:"button",label:"Open dialog",name:"onActive",changeProp:!0,command(u){var m;(m=u.getSelected())==null||m.trigger("active")}},{type:"checkbox",label:"Close when pressing X",name:"closeWhenPressingX",default:!0,changeProp:!0},{type:"checkbox",label:"Close when pressing ESC",name:"closeWhenPressingEsc",default:!0,changeProp:!0},{type:"checkbox",label:"Open when leaving the window",name:"openWhenLeavingWindow",default:!1,changeProp:!0},{type:"number",label:"Open when scrolling to level",name:"openWhenScrollingToLevel",default:0,changeProp:!0}],"script-props":["closeWhenPressingX","closeWhenPressingEsc","openWhenLeavingWindow","openWhenScrollingToLevel"],script:function(u){const m=this;function g(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]'),T=m.querySelector('[data-type-role="gjs-plg-dialog-close"]');function j(){E.style.display="none"}v?(m._onCloseWhenPressingX=j,T.addEventListener("click",m._onCloseWhenPressingX)):(T.removeEventListener("click",m._onCloseWhenPressingX),m._onCloseWhenPressingX=null)}function b(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function T(j){j.key==="Escape"&&(E.style.display="none")}v?(m._onCloseWhenPressingEsc=T,m.addEventListener("keydown",m._onCloseWhenPressingEsc)):(m.removeEventListener("keydown",m._onCloseWhenPressingEsc),m._onCloseWhenPressingEsc=null)}function k(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function T(){E.style.display="flex"}v?(m._onOpenWhenLeavingWindow=T,document.addEventListener("mouseleave",m._onOpenWhenLeavingWindow)):(document.removeEventListener("mouseleave",m._onOpenWhenLeavingWindow),m._onOpenWhenLeavingWindow=null)}function O(v){const E=m.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');function T(){const j=document.documentElement.scrollTop;v&&j>=Number(v)&&(E.style.display="flex")}v?(m._onOpenWhenScrollingToLevel=T,document.addEventListener("scroll",m._onOpenWhenScrollingToLevel)):(document.removeEventListener("scroll",m._onOpenWhenScrollingToLevel),m._onOpenWhenScrollingToLevel=null)}g(u.closeWhenPressingX),b(u.closeWhenPressingEsc),k(u.openWhenLeavingWindow),O(u.openWhenScrollingToLevel)}},init(){this.on("active",this.handleOpenWhenClickPlaceholder)},handleOpenWhenClickPlaceholder(){this.view.el.querySelector('[data-type-role="gjs-plg-dialog-placeholder"]').addEventListener("click",()=>{const m=this.view.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');m.style.display="flex"})}},view:{onActive(){const u=this.el.querySelector('[data-type-role="gjs-plg-dialog-overlay"]');u.style.display="flex"}}}),r.addType(o,{model:{defaults:{tagName:"div",attributes:{class:o,"data-type-role":o},components:{type:l},droppable:!1,draggable:!1,styles:`
11
11
  .${o} {
12
12
  position: fixed;
13
13
  top: 0;
@@ -56,13 +56,23 @@
56
56
  .${f} {
57
57
  margin: 0;
58
58
  }
59
- `}}}),r.addType(d,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:d,"data-type-role":d},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){this.listenTo(this.em,"run:core:preview",()=>{this.el.style.display="none"}),this.listenTo(this.em,"stop:core:preview",()=>{this.el.style.display=""})}}}),Sr({editor:n,licenseKey:i,pluginName:Bl,cleanup:()=>{t.remove(s),r.removeType(s)}})},Ll=kr(Hl);function Fl(n,e,t){let r,i,s,o,l;const a=e;function c(){const f=Date.now()-o;f<a&&f>=0?r=setTimeout(c,a-f):(r=null,l=n.apply(s,i),s=i=null)}const h=function(){return s=this,i=arguments,o=Date.now(),r||(r=setTimeout(c,a)),l};return h.clear=function(){r&&(clearTimeout(r),r=null)},h.flush=function(){r&&(l=n.apply(s,i),s=i=null,clearTimeout(r),r=null)},h}var Rt=(n=>(n.toastAdd="studio:toastAdd",n.dialogOpen="studio:dialogOpen",n.dialogClose="studio:dialogClose",n.sidebarLeftSet="studio:sidebarLeft:set",n.sidebarLeftGet="studio:sidebarLeft:get",n.sidebarLeftToggle="studio:sidebarLeft:toggle",n.sidebarRightSet="studio:sidebarRight:set",n.sidebarRightGet="studio:sidebarRight:get",n.sidebarRightToggle="studio:sidebarRight:toggle",n.sidebarTopSet="studio:sidebarTop:set",n.sidebarTopGet="studio:sidebarTop:get",n.sidebarTopToggle="studio:sidebarTop:toggle",n.sidebarBottomSet="studio:sidebarBottom:set",n.sidebarBottomGet="studio:sidebarBottom:get",n.sidebarBottomToggle="studio:sidebarBottom:toggle",n.symbolAdd="studio:symbolAdd",n.symbolDetach="studio:symbolDetach",n.symbolOverride="studio:symbolOverride",n.symbolPropagateStyles="studio:propagateStyles",n.getPagesConfig="studio:getPagesConfig",n.setPagesConfig="studio:setPagesConfig",n.getPageSettings="studio:getPageSettings",n.setPageSettings="studio:setPageSettings",n.projectFiles="studio:projectFiles",n.canvasReload="studio:canvasReload",n.getBlocksPanel="studio:getBlocksPanel",n.setBlocksPanel="studio:setBlocksPanel",n.contextMenuComponent="studio:contextMenuComponent",n.layoutAdd="studio:layoutAdd",n.layoutRemove="studio:layoutRemove",n.layoutToggle="studio:layoutToggle",n))(Rt||{}),x=(n=>(n.table="table",n.tableSettings="tableSettings",n.tableDelete="tableDelete",n.tableHead="tableHead",n.tableFoot="tableFoot",n.tableCellItems="tableCellItems",n.tableCellProperties="tableCellProperties",n.tableCellMerge="tableCellMerge",n.tableCellSplit="tableCellSplit",n.tableRowItems="tableRowItems",n.tableRowInsertBefore="tableRowInsertBefore",n.tableRowInsertAfter="tableRowInsertAfter",n.tableRowDelete="tableRowDelete",n.tableRowProperties="tableRowProperties",n.tableRowCut="tableRowCut",n.tableRowCopy="tableRowCopy",n.tableRowPasteBefore="tableRowPasteBefore",n.tableRowPasteAfter="tableRowPasteAfter",n.tableColumn="tableColumn",n.tableColumnItems="tableColumnItems",n.tableColumnInsertBefore="tableColumnInsertBefore",n.tableColumnInsertAfter="tableColumnInsertAfter",n.tableColumnDelete="tableColumnDelete",n.tableColumnCut="tableColumnCut",n.tableColumnCopy="tableColumnCopy",n.tableColumnPasteBefore="tableColumnPasteBefore",n.tableColumnPasteAfter="tableColumnPasteAfter",n))(x||{});const A={table:'<svg viewBox="0 0 24 24"><path d="M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2m0 4v4h6V8H5m8 0v4h6V8h-6m-8 6v4h6v-4H5m8 0v4h6v-4h-6Z"/></svg>',tableSettings:'<svg viewBox="0 0 24 24"><path d="M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2m0 4v4h6V8H5m8 0v4h6V8h-6m-8 6v4h6v-4H5m8 0v4h6v-4h-6Z"/></svg>',tableDelete:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zM5 6v12h14V6H5z"/><path d="m14.4 8.6 1 1-2.3 2.4 2.3 2.4-1 1-2.4-2.3-2.4 2.3-1-1 2.3-2.4-2.3-2.4 1-1 2.4 2.3z"/></svg>',tableHead:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14Zm-8 11H5v3h6v-3Zm8 0h-6v3h6v-3Zm0-5h-6v3h6v-3ZM5 13h6v-3H5v3Z"/></svg>',tableFoot:'<svg viewBox="0 0 24 24" data-test="1" style="transform: rotate(180deg);"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14Zm-8 11H5v3h6v-3Zm8 0h-6v3h6v-3Zm0-5h-6v3h6v-3ZM5 13h6v-3H5v3Z"/></svg>',tableColumn:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14Zm0 9h-4v5h4v-5Zm-6 0H9v5h4v-5Zm0-7H9v5h4V6Zm6 0h-4v5h4V6Z"/></svg>',tableCellItems:"",tableCellProperties:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6l2-2h14zm-8 9H5v5h6v-5zm8 0h-6v5h6v-5zm-8-7H5v5h6V6z"/></svg>',tableCellMerge:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6l2-2h14zM5 16v2h3v-2H5zm14-5h-9v7h9v-7zm0-5h-4v3h4V6zM8 6H5v3h3V6zm5 0h-3v3h3V6zm-8 8h3v-3H5v3z"/></svg>',tableCellSplit:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zM8 15.5H5V18h3v-2.5zm11-5h-9V18h9v-7.5zm-2.5 1 1 1-2 2 2 2-1 1-2-2-2 2-1-1 2-2-2-2 1-1 2 2 2-2zm-8.5-1H5v3h3v-3zM19 6h-4v2.5h4V6zM8 6H5v2.5h3V6zm5 0h-3v2.5h3V6z"/></svg>',tableRowItems:"",tableRowInsertBefore:'<svg viewBox="0 0 24 24"><path d="M6 4a1 1 0 1 1 0 2H5v6h14V6h-1a1 1 0 0 1 0-2h2c.6 0 1 .4 1 1v13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5c0-.6.4-1 1-1h2zm5 10H5v4h6v-4zm8 0h-6v4h6v-4zM12 3c.5 0 1 .4 1 .9V6h2a1 1 0 0 1 0 2h-2v2a1 1 0 0 1-2 .1V8H9a1 1 0 0 1 0-2h2V4c0-.6.4-1 1-1z"/></svg>',tableRowInsertAfter:'<svg viewBox="0 0 24 24"><path d="M12 13c.5 0 1 .4 1 .9V16h2a1 1 0 0 1 .1 2H13v2a1 1 0 0 1-2 .1V18H9a1 1 0 0 1-.1-2H11v-2c0-.6.4-1 1-1zm6 7a1 1 0 0 1 0-2h1v-6H5v6h1a1 1 0 0 1 0 2H4a1 1 0 0 1-1-1V6c0-1.1.9-2 2-2h14a2 2 0 0 1 2 2v13c0 .5-.4 1-.9 1H18zM11 6H5v4h6V6zm8 0h-6v4h6V6z"/></svg>',tableRowDelete:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm0 2H5v3h2.5v2H5v2h2.5v2H5v3h14v-3h-2.5v-2H19v-2h-2.5V9H19V6zm-4.7 1.8 1.2 1L13 12l2.6 3.3-1.2 1-2.3-3-2.3 3-1.2-1L11 12 8.5 8.7l1.2-1 2.3 3 2.3-3z"/></svg>',tableRowProperties:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zM5 15v3h6v-3H5zm14 0h-6v3h6v-3zm0-9h-6v3h6V6zM5 9h6V6H5v3z"/></svg>',tableRowCut:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M22 3v5H9l3 3 2-2h4l-4 4 1 1h.5c.4 0 .8 0 1.2.3.5.2.9.4 1.2.8.7.6 1 1.3 1 2.2.2.8 0 1.5-.6 2l-.8.5-1 .2c-.4 0-.8 0-1.2-.3a3.9 3.9 0 0 1-2.1-2.2c-.2-.5-.3-1-.2-1.5l-1-1-1 1c0 .5 0 1-.2 1.5-.1.5-.4 1-.9 1.4-.3.4-.7.6-1.2.8l-1.2.3c-.4 0-.7 0-1-.2-.3 0-.6-.3-.8-.5-.5-.5-.8-1.2-.7-2a3 3 0 0 1 1-2.2A3.7 3.7 0 0 1 8.6 14H9l1-1-4-4-.5-1a3.3 3.3 0 0 1 0-2c0-.4.3-.7.5-1l2 2V3h14zM8.5 15.3h-.3a2.6 2.6 0 0 0-.8.4 2.5 2.5 0 0 0-.9 1.1l-.1.4v.7l.2.5.5.2h.7a2.5 2.5 0 0 0 .8-.3L9 18l.4-.4.2-.4.1-.4v-.7a1 1 0 0 0-.2-.5 1 1 0 0 0-.4-.2h-.5zm7 0H15a1 1 0 0 0-.4.3 1 1 0 0 0-.2.5 1.5 1.5 0 0 0 0 .7v.4a2.8 2.8 0 0 0 .5.7h.1a2.8 2.8 0 0 0 .8.6l.4.1h.7l.5-.2.2-.5v-.7a2.6 2.6 0 0 0-.3-.8 2.4 2.4 0 0 0-.7-.7 2.5 2.5 0 0 0-.8-.3h-.3zM12 11.6c-.4 0-.7.1-1 .4-.3.3-.4.6-.4 1s.1.7.4 1c.3.3.6.4 1 .4s.7-.1 1-.4c.3-.3.4-.6.4-1s-.1-.7-.4-1c-.3-.3-.6-.4-1-.4zm8.5-7.1h-11v2h11v-2z"/></svg>',tableRowCopy:'<svg viewBox="0 0 24 24"><path d="M22 11v7H6v-7h16zm-2 2H8v3h12v-3zm-1-6v2H4v5H2V7h17z"/></svg>',tableRowPasteBefore:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V7h-2V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h12v-4h2v4c0 1-.8 2-1.9 2H6c-1 0-2-.8-2-1.9V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm10 7v5H8V8h14zm-1.5 1.5h-11v2h11v-2zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',tableRowPasteAfter:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V11h-2V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h14c0 1-.8 2-1.9 2H6c-1 0-2-.8-2-1.9V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm10 11v5H8v-5h14zm-1.5 1.5h-11v2h11v-2zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',tableColumnItems:"",tableColumnInsertBefore:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a1 1 0 0 1-1-1v-2a1 1 0 0 1 2 0v1h8V6H5v1a1 1 0 1 1-2 0V5c0-.6.4-1 1-1h15zm0 9h-4v5h4v-5zM8 8c.5 0 1 .4 1 .9V11h2a1 1 0 0 1 .1 2H9v2a1 1 0 0 1-2 .1V13H5a1 1 0 0 1-.1-2H7V9c0-.6.4-1 1-1zm11-2h-4v5h4V6z"/></svg>',tableColumnInsertAfter:'<svg viewBox="0 0 24 24"><path d="M20 4c.6 0 1 .4 1 1v2a1 1 0 0 1-2 0V6h-8v12h8v-1a1 1 0 0 1 2 0v2c0 .5-.4 1-.9 1H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h15zM9 13H5v5h4v-5zm7-5c.5 0 1 .4 1 .9V11h2a1 1 0 0 1 .1 2H17v2a1 1 0 0 1-2 .1V13h-2a1 1 0 0 1-.1-2H15V9c0-.6.4-1 1-1zM9 6H5v5h4V6z"/></svg>',tableColumnDelete:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm-4 4h-2V6h-2v2H9V6H5v12h4v-2h2v2h2v-2h2v2h4V6h-4v2zm.3.5 1 1.2-3 2.3 3 2.3-1 1.2L12 13l-3.3 2.6-1-1.2 3-2.3-3-2.3 1-1.2L12 11l3.3-2.5z"/></svg>',tableColumnCut:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M7.2 4.5a3 3 0 0 1 2.2 1A3.7 3.7 0 0 1 10.5 8v.5l1 1 4-4 1-.5a3.3 3.3 0 0 1 2 0c.4 0 .7.3 1 .5L17 8h4v13h-6V10l-1.5 1.5.5.5v4l-2.5-2.5-1 1v.5c0 .4 0 .8-.3 1.2-.2.5-.4.9-.8 1.2-.6.7-1.3 1-2.2 1-.8.2-1.5 0-2-.6l-.5-.8-.2-1c0-.4 0-.8.3-1.2A3.9 3.9 0 0 1 7 12.7c.5-.2 1-.3 1.5-.2l1-1-1-1c-.5 0-1 0-1.5-.2-.5-.1-1-.4-1.4-.9-.4-.3-.6-.7-.8-1.2L4.5 7c0-.4 0-.7.2-1 0-.3.3-.6.5-.8.5-.5 1.2-.8 2-.7zm12.3 5h-3v10h3v-10zM8 13.8h-.3l-.4.2a2.8 2.8 0 0 0-.7.4v.1a2.8 2.8 0 0 0-.6.8l-.1.4v.7l.2.5.5.2h.7a2.6 2.6 0 0 0 .8-.3 2.4 2.4 0 0 0 .7-.7 2.5 2.5 0 0 0 .3-.8 1.5 1.5 0 0 0 0-.8 1 1 0 0 0-.2-.4 1 1 0 0 0-.5-.2H8zm3.5-3.7c-.4 0-.7.1-1 .4-.3.3-.4.6-.4 1s.1.7.4 1c.3.3.6.4 1 .4s.7-.1 1-.4c.3-.3.4-.6.4-1s-.1-.7-.4-1c-.3-.3-.6-.4-1-.4zM7 5.8h-.4a1 1 0 0 0-.5.3 1 1 0 0 0-.2.5v.7a2.5 2.5 0 0 0 .3.8l.2.3h.1l.4.4.4.2.4.1h.7L9 9l.2-.4a1.6 1.6 0 0 0 0-.8 2.6 2.6 0 0 0-.3-.8 2.5 2.5 0 0 0-1.2-1l-.4-.1H7z"/></svg>',tableColumnCopy:'<svg viewBox="0 0 24 24"><path d="M17 6v16h-7V6h7zm-2 2h-3v12h3V8zm-2-6v2H8v15H6V2h7z"/></svg>',tableColumnPasteBefore:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V18c0 1-.8 2-1.9 2H11v-2h7V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v2H4V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm-2 7v12H4V8h6zM8.5 9.5h-3v9h3v-9zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',tableColumnPasteAfter:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V7h-2V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h7v2H6c-1 0-2-.8-2-1.9V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm8 7v12h-6V8h6zm-1.5 1.5h-3v9h3v-9zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>'},de="table",ws="thead",ks="tfoot",Xn="tbody",Y="row",I="cell",Mr="clipboardTable",Wl=[de,ws,ks,Xn,Y,I],xn=n=>n.em.get(Mr)||[],$l=n=>n.every(e=>e.is(I)),vr=(n,e)=>{const{editor:t,event:r,opts:i}=n,s=r.currentTarget||r.target,{x:o,y:l,width:a,height:c}=s.getBoundingClientRect(),h={style:{width:240,height:300},placer:{type:"popover",closeOnClickAway:!0,x:o,y:l,w:a,h:c},layout:{type:"tabs",value:"props",tabs:[{id:"styles",label:"Styles",children:{type:"panelStyles"}},{id:"props",label:"Properties",children:{type:"panelProperties",style:{padding:"14px 7px"}}}]},...e};xs(i.openSettings)?i.openSettings({...n,layoutProps:h}):t.runCommand(Rt.layoutToggle,h)},Jl=(n,{rows:e=1,cells:t=5,text:r}={})=>({type:n,components:Array.from(Array(e).keys()).map(i=>({type:Y,components:Array.from(Array(t).keys()).map(s=>({type:I,components:r?{type:"text",content:xs(r)?r({y:i,x:s}):r}:void 0}))}))}),Ss="Table settings",Ms=n=>{const{component:e}=n;return e.is(de)?e:e.closestType(de)},ql=n=>{var e;(e=Ms(n))==null||e.remove(n.opts)},Kl=n=>{const e=Ms(n);e&&(n.editor.select(e),vr(n,{id:"tableSettings",header:{label:Ss}}))},vs=n=>[{id:x.table,icon:A[x.table],label:"Table",items:[{id:x.tableSettings,label:Ss,icon:A[x.tableSettings],onClick:({event:t})=>Kl({...n,event:t})},{id:x.tableDelete,label:"Delete table",icon:A[x.tableDelete],onClick:()=>ql(n)}]}],Os=({editor:n})=>{const e=xn(n);return e.length&&$l(e)},_r=({component:n,editor:e,after:t})=>{if(!n.is(I))return;const r=n.closestType(de),i=n.closestType(Y),s=n.index()+(t?1:0);r==null||r.findType(Y).forEach(l=>l.append({type:I},{at:s}));const o=i==null?void 0:i.components().at(s);o&&e.select(o)},Ns=({component:n,opts:e})=>{if(!n.is(I))return;const t=n.closestType(de),r=n.index();t==null||t.findType(Y).forEach(i=>{var s;return(s=i.components().at(r))==null?void 0:s.remove(e)})},As=({component:n,editor:e})=>{if(!n.is(I))return;const t=n.closestType(de),r=n.index(),i=(t==null?void 0:t.findType(Y).map(s=>s.components().at(r)))||[];i.length&&e.em.set(Mr,i)},Ur=n=>{const{component:e,editor:t,after:r}=n;if(!e.is(I)||!Os(n))return;const i=xn(t),s=e.closestType(de),o=e.index()+(r?1:0);s==null||s.findType(Y).forEach((l,a)=>{const c=i[a],h=(c==null?void 0:c.clone())||{type:I};l.append(h,{at:o})})},jl=n=>{const{component:e}=n;e.is(I)&&(As(n),Ns({...n,opts:{temporary:!0}}))},_l=n=>{const e=Os(n);return[{id:x.tableColumnItems,icon:A[x.tableColumn],label:"Column",items:[{id:x.tableColumnInsertBefore,label:"Insert column before",icon:A[x.tableColumnInsertBefore],onClick:()=>_r(n)},{id:x.tableColumnInsertAfter,label:"Insert column after",icon:A[x.tableColumnInsertAfter],onClick:()=>_r({...n,after:!0})},{id:x.tableColumnDelete,label:"Delete column",icon:A[x.tableColumnDelete],onClick:()=>Ns(n)},{id:x.tableColumnCut,label:"Cut column",icon:A[x.tableColumnCut],onClick:()=>jl(n)},{id:x.tableColumnCopy,label:"Copy column",icon:A[x.tableColumnCopy],onClick:()=>As(n)},{id:x.tableColumnPasteBefore,label:"Paste column before",icon:A[x.tableColumnPasteBefore],disabled:!e,onClick:()=>Ur(n)},{id:x.tableColumnPasteAfter,label:"Paste column after",icon:A[x.tableColumnPasteAfter],disabled:!e,onClick:()=>Ur({...n,after:!0})}]}]},Ts="Row settings",Ul=n=>n.every(e=>e.is(Y)),Ct=n=>{const{component:e}=n,t=e.is(I),r=e.is(Y);if(!(!t&&!r))return r?e:e.closestType(Y)},Gr=n=>{const{component:e,editor:t,after:r}=n,i=Ct(n);if(!i)return;const s=i.index()+(r?1:0),o=i.components().length,l=Array.from(Array(o).keys()).map(()=>({type:I})),a=i.parent();if(a){const c=a.append({type:Y,components:l},{at:s})[0];if(e.is(I)&&c){const h=e.index(),f=c.components().at(h);f&&t.select(f)}}},Ds=n=>{var e;(e=Ct(n))==null||e.remove(n.opts)},Es=n=>{const e=Ct(n);e&&n.editor.em.set(Mr,[e])},Zr=n=>{var l;const{editor:e,after:t}=n,r=Ct(n);if(!r||!Rs(n))return;const s=xn(e)[0],o=r.index()+(t?1:0);s&&((l=r.parent())==null||l.append(s.clone(),{at:o}))},Gl=n=>{Ct(n)&&(Es(n),Ds({...n,opts:{temporary:!0}}))},Rs=({editor:n})=>{const e=xn(n);return e.length&&Ul(e)},Zl=n=>{const e=Ct(n);e&&(n.editor.select(e),vr(n,{id:"tableRowSettings",header:{label:Ts}}))},Is=n=>{const e=Rs(n);return[{id:x.tableRowItems,icon:A[x.tableRowProperties],label:"Row",items:[{id:x.tableRowInsertBefore,label:"Insert row before",icon:A[x.tableRowInsertBefore],onClick:()=>Gr(n)},{id:x.tableRowInsertAfter,label:"Insert row after",icon:A[x.tableRowInsertAfter],onClick:()=>Gr({...n,after:!0})},{id:x.tableRowDelete,label:"Delete row",icon:A[x.tableRowDelete],onClick:()=>Ds(n)},{id:x.tableRowProperties,label:Ts,icon:A[x.tableRowProperties],onClick:({event:r})=>Zl({...n,event:r})},{id:x.tableRowCut,label:"Cut row",icon:A[x.tableRowCut],onClick:()=>Gl(n)},{id:x.tableRowCopy,label:"Copy row",icon:A[x.tableRowCopy],onClick:()=>Es(n)},{id:x.tableRowPasteBefore,label:"Paste row before",icon:A[x.tableRowPasteBefore],disabled:!e,onClick:()=>Zr(n)},{id:x.tableRowPasteAfter,label:"Paste row after",icon:A[x.tableRowPasteAfter],disabled:!e,onClick:()=>Zr({...n,after:!0})}]},...vs(n)]},Or=n=>{const e=n.attributes.attributes||{},t=parseInt(`${e.rowspan||1}`,10),r=parseInt(`${e.colspan||1}`,10);return{rowspan:t,colspan:r}};function zs(n){const e=[];return n.components().forEach((t,r)=>{t.components().each((i,s)=>{const{rowspan:o,colspan:l}=Or(i);if(e[r])for(;e[r][s];)s++;for(let a=r;a<r+o;a++){e[a]||(e[a]=[]);for(let c=s;c<s+l;c++)e[a][c]={real:a===r&&c===s,cell:i,rowspan:o,colspan:l}}})}),e}function ot(n,e,t){var r;return(r=n[t])==null?void 0:r[e]}const Yn=n=>n.closestType(Y);function Xl(n,{x:e,y:t,rows:r,cols:i}){var l;let s=Yn(n[t][e].cell),o;for(let a=1;a<=r;a++)if(s=(l=s==null?void 0:s.parent())==null?void 0:l.components().at(s.index()+1),s){for(o=e;o>=0;o--){const{cell:c}=n[t+a][o],h=Yn(c);if(h===s){for(let f=1;f<=i;f++){const d=c.index();h.append({type:I},{at:d+1})}break}}if(o===-1){const h=s.components().at(0).index();for(let f=1;f<=i;f++)s.append({type:I},{at:h})}}}function Vs(n){for(let e=0;e<n.length;e++)for(let t=0;t<n[e].length;t++){const i=n[e][t].cell;if(i.em.selected.hasComponent(i)){const{rowspan:s,colspan:o}=Or(i);if(o>1||s>1){i.addAttributes({colspan:1,rowspan:1});for(let l=0;l<o-1;l++){const a=i.index();Yn(i).append({type:I},{at:a+1})}Xl(n,{x:t,y:e,rows:s-1,cols:o})}}}}function Yl(n){const e=[];n.components().forEach(t=>{t.components().length||e.push(t)}),e.forEach(t=>t.remove())}const wn=(n,e={})=>{var o;const t=zs(n),{em:r}=n;let i,s;for(let l=0;l<t.length;l++)for(let a=0;a<t[l].length;a++){const c=t[l][a];if((o=e.selected)!=null&&o.includes(c.cell)||r.selected.hasComponent(c.cell)){const h={x:a,y:l};i||(i=h),s=h}}return{grid:t,startPos:i,endPos:s}};function Ql(n,e={}){const t=wn(n),{startPos:r,endPos:i}=t;let{grid:s}=t;const{em:o}=n;if(!r||!i)return;const l=r.x,a=r.y,c=i.x,h=i.y,f=ot(s,l,a),d=ot(s,c,h);if(f&&d){Vs(s),s=zs(n);const p=[],u=ot(s,l,a).cell;u.addAttributes({colspan:c-l+1,rowspan:h-a+1});for(let m=a;m<=h;m++)for(let g=l;g<=c;g++){const b=ot(s,g,m);if(!b)continue;const{cell:S}=b;S!==u&&p.push(S)}p.forEach(m=>{e.mergeContent&&u.append(m.components().models),m.remove()}),o.setSelected(u),Yl(n)}}const Ps="Cell settings",ea="Merge cells",ta="Split cell",na=n=>n.closestType(Y),dt=n=>{var e;return(e=na(n))==null?void 0:e.parent()},ra=n=>{const e=n.editor.getSelectedAll(),t=dt(e[0]),r=e[0];if(!t||!(r!=null&&r.is(I))||e.length>1)return!1;const{rowspan:i,colspan:s}=Or(r);return!(s<2&&i<2)},ia=n=>{const t=n.editor.getSelectedAll()[0],r=dt(t),{grid:i}=wn(r);Vs(i)},Bs=n=>{const e=n.editor.getSelectedAll(),t=dt(e[0]);if(!t||e.length<2||e.some(l=>!l.is(I)||dt(l)!==t))return!1;const{grid:r,startPos:i,endPos:s}=wn(t),{em:o}=t;if(!i||!s)return!1;for(let l=i.y;l<=s.y;l++)for(let a=i.x;a<=s.x;a++){const c=ot(r,a,l);if(!c||!o.selected.hasComponent(c.cell))return!1}return!0},sa=n=>{const{editor:e}=n;if(!Bs(n))return;const t=e.getSelectedAll(),r=dt(t[0]);Ql(r,{mergeContent:!0})},oa=n=>{vr(n,{id:"tableCellSettings",header:{label:Ps}})},la=n=>[{id:x.tableCellItems,icon:A[x.tableCellProperties],label:"Cell",items:[{id:x.tableCellProperties,label:Ps,icon:A[x.tableCellProperties],onClick:({event:t})=>oa({...n,event:t})},{id:x.tableCellMerge,label:ea,icon:A[x.tableCellMerge],onClick:()=>sa(n),disabled:!Bs(n)},{id:x.tableCellSplit,label:ta,icon:A[x.tableCellSplit],onClick:()=>ia(n),disabled:!ra(n)}]},..._l(n),...Is(n)],aa=n=>{const e=n[0]&&dt(n[0]);if(!e)return;const{grid:t,startPos:r,endPos:i}=wn(e,{selected:n});if(!r||!i)return;const s=[];for(let o=r.y;o<=i.y;o++)for(let l=r.x;l<=i.x;l++){const a=ot(t,l,o);a&&s.push(a.cell)}s.length&&e.em.setSelected(s,{fromCell:!0})},ca="tableComponent",ha=function(n,e={}){const t={block:{},...e},{Components:r}=n,i={copyable:!1,emptyState:!0,highlightable:!1,stylable:["color","font-family","font-size","font-weight","line-height","text-align","vertical-align","background-color","border-width","border-style","border-color"]};r.addType(de,{block:t.block&&{label:"Table",media:A.table,category:"Extra",content:{type:de,style:{width:"100%"}},select:!0,...t.block},model:{defaults:{emptyState:!0,highlightable:!1,icon:A.table,stylable:["width","height","margin","font-family","font-size","font-weight","line-height","text-align","background","background-color","border-width","border-style","border-color"],traits:[{type:"number",min:0,name:"cellspacing",label:"Cell spacing"},{type:"number",min:0,name:"cellpadding",label:"Cell padding"},{id:"tableCaption",type:"checkbox",label:"Caption",setValue({component:o,value:l,emitUpdate:a}){const c=o.find("caption")[0];l?!c&&o.append({type:"text",tagName:"caption",components:{type:"textnode",content:"Caption"}}):c==null||c.remove(),a(),n.refresh({tools:!0})},getValue(o){return!!o.component.find("caption")[0]}}],components:Jl(Xn,{rows:5}),contextMenu:({items:o,editor:l,component:a})=>[...vs({editor:l,component:a,opts:t}),...o]}}}),r.addType(ws,{model:{defaults:{icon:A.tableHead,...i}}}),r.addType(ks,{model:{defaults:{icon:A.tableFoot,...i}}}),r.addType(Xn,{model:{defaults:{icon:A.tableRowProperties,...i}}}),r.addType(Y,{model:{defaults:{icon:A.tableRowProperties,emptyState:!0,highlightable:!1,stylable:["height","text-align","border-width","border-style","border-color"],traits:[],contextMenu:({items:o,editor:l,component:a})=>[...Is({editor:l,component:a,opts:t}),...o]}}}),r.addType(I,{model:{defaults:{icon:A.tableCellProperties,emptyState:{styleOut:"height: 1px"},stylable:["width","height","padding","background-color","text-align","vertical-align","border-width","border-style","border-color"],traits:[{id:"tableCellType",type:"select",options:[{value:"td",name:"Cell"},{value:"th",name:"Header Cell"}],label:"Cell type",name:"tagName",changeProp:!0},{id:"tableCellScope",type:"select",options:[{value:!1,name:"None"},{value:"row",name:"Row"},{value:"col",name:"Column"},{value:"rowgroup",name:"Row group"},{value:"colgroup",name:"Column group"}],label:"Scope",name:"scope"}],contextMenu:({items:o,editor:l,component:a})=>[...la({editor:l,component:a,opts:t}),...o]}}});const s=Fl((o,l)=>{var f;const a=n.getSelectedAll(),c=!!((f=l==null?void 0:l.event)!=null&&f.shiftKey);if(a.length<2||!c||l.fromCell)return;const h=a.map(d=>d.is(I)?d:d.closestType(I)).filter(Boolean);h.length===a.length&&aa(h)},0);n.on("component:select",s),Sr({editor:n,licenseKey:t.licenseKey,pluginName:ca,cleanup:()=>{n.off("component:select",s),n.Blocks.remove(de),Wl.forEach(o=>r.removeType(o))}})},fa=kr(ha);function H(n){this.content=n}H.prototype={constructor:H,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var r=t&&t!=n?this.remove(t):this,i=r.find(n),s=r.content.slice();return i==-1?s.push(t||n,e):(s[i+1]=e,t&&(s[i]=t)),new H(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new H(t)},addToStart:function(n,e){return new H([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new H(t)},addBefore:function(n,e,t){var r=this.remove(e),i=r.content.slice(),s=r.find(n);return i.splice(s==-1?i.length:s,0,e,t),new H(i)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=H.from(n),n.size?new H(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=H.from(n),n.size?new H(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=H.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};H.from=function(n){if(n instanceof H)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new H(e)};function Hs(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Hs(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Ls(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=0,h=Math.min(o.text.length,l.text.length);for(;c<h&&o.text[o.text.length-c-1]==l.text[l.text.length-c-1];)c++,t--,r--;return{a:t,b:r}}if(o.content.size||l.content.size){let c=Ls(o.content,l.content,t-1,r-1);if(c)return c}t-=a,r-=a}}class y{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,i=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&r(a,i+l,s||null,o)!==!1&&a.content.size){let h=l+1;a.nodesBetween(Math.max(0,e-h),Math.min(a.content.size,t-h),r,i+h)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new y(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new y(r,i)}cutByIndex(e,t){return e==t?y.empty:e==0&&t==this.content.length?this:new y(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new y(i,s)}addToStart(e){return new y([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new y(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let i=this.content[t];e(i,r,t),r+=i.nodeSize}}findDiffStart(e,t=0){return Hs(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return Ls(this,e,t,r)}findIndex(e,t=-1){if(e==0)return _t(0,e);if(e==this.size)return _t(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?_t(r+1,o):_t(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return y.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new y(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return y.empty;let t,r=0;for(let i=0;i<e.length;i++){let s=e[i];r+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new y(t||e,r)}static from(e){if(!e)return y.empty;if(e instanceof y)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new y([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}y.empty=new y([],0);const En={index:0,offset:0};function _t(n,e){return En.index=n,En.offset=e,En}function sn(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!sn(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!sn(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}class T{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!r&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&sn(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[t.type];if(!r)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=r.create(t.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(t[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return T.none;if(e instanceof T)return[e];let t=e.slice();return t.sort((r,i)=>r.type.rank-i.type.rank),t}}T.none=[];class on extends Error{}class C{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Ws(this.content,e+this.openStart,t);return r&&new C(r,this.openStart,this.openEnd)}removeBetween(e,t){return new C(Fs(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return C.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new C(y.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new C(e,r,i)}}C.empty=new C(y.empty,0,0);function Fs(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Fs(s.content,e-i-1,t-i-1)))}function Ws(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return n.cut(0,e).append(t).append(n.cut(e));let l=Ws(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function da(n,e,t){if(t.openStart>n.depth)throw new on("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new on("Inconsistent open depths");return $s(n,e,t,0)}function $s(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r<n.depth-t.openStart){let o=$s(n,e,t,r+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let o=n.parent,l=o.content;return _e(o,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=ua(t,n);return _e(s,qs(n,o,l,e,r))}else return _e(s,ln(n,e,r))}function Js(n,e){if(!e.type.compatibleContent(n.type))throw new on("Cannot join "+e.type.name+" onto "+n.type.name)}function Qn(n,e,t){let r=n.node(t);return Js(r,e.node(t)),r}function je(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Nt(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(je(n.nodeAfter,r),s++));for(let l=s;l<o;l++)je(i.child(l),r);e&&e.depth==t&&e.textOffset&&je(e.nodeBefore,r)}function _e(n,e){return n.type.checkContent(e),n.copy(e)}function qs(n,e,t,r,i){let s=n.depth>i&&Qn(n,e,i+1),o=r.depth>i&&Qn(t,r,i+1),l=[];return Nt(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(Js(s,o),je(_e(s,qs(n,e,t,r,i+1)),l)):(s&&je(_e(s,ln(n,e,i+1)),l),Nt(e,t,i,l),o&&je(_e(o,ln(t,r,i+1)),l)),Nt(r,null,i,l),new y(l)}function ln(n,e,t){let r=[];if(Nt(null,n,t,r),n.depth>t){let i=Qn(n,e,t+1);je(_e(i,ln(n,e,t+1)),r)}return Nt(e,null,t,r),new y(r)}function ua(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class It{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=r.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return T.none;if(this.textOffset)return e.child(t).marks;let r=e.maybeChild(t-1),i=e.maybeChild(t);if(!r){let l=r;r=i,i=l}let s=r.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let r=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new an(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new It(t,r,s)}static resolveCached(e,t){let r=Xr.get(e);if(r)for(let s=0;s<r.elts.length;s++){let o=r.elts[s];if(o.pos==t)return o}else Xr.set(e,r=new pa);let i=r.elts[r.i]=It.resolve(e,t);return r.i=(r.i+1)%ma,i}}class pa{constructor(){this.elts=[],this.i=0}}const ma=12,Xr=new WeakMap;class an{constructor(e,t,r){this.$from=e,this.$to=t,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const ga=Object.create(null);let Ue=class er{constructor(e,t,r,i=T.none){this.type=e,this.attrs=t,this.marks=i,this.content=r||y.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,r,i=0){this.content.nodesBetween(e,t,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,r,i){return this.content.textBetween(e,t,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,r){return this.type==e&&sn(this.attrs,t||e.defaultAttrs||ga)&&T.sameSet(this.marks,r||T.none)}copy(e=null){return e==this.content?this:new er(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new er(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,r=!1){if(e==t)return C.empty;let i=this.resolve(e),s=this.resolve(t),o=r?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new C(c,i.depth-o,s.depth-o)}replace(e,t,r){return da(this.resolve(e),this.resolve(t),r)}nodeAt(e){for(let t=this;;){let{index:r,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(r),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(t),index:t,offset:r};let i=this.content.child(t-1);return{node:i,index:t-1,offset:r-i.nodeSize}}resolve(e){return It.resolveCached(this,e)}resolveNoCache(e){return It.resolve(this,e)}rangeHasMark(e,t,r){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Ks(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=y.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;a<s;a++)if(!this.type.allowsMarks(r.child(a).marks))return!1;return!0}canReplaceWith(e,t,r,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(r),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=T.none;for(let t=0;t<this.marks.length;t++){let r=this.marks[t];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!T.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=y.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ue.prototype.text=void 0;class cn extends Ue{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ks(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new cn(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new cn(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Ks(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Ye{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new ya(e,t);if(r.next==null)return Ye.empty;let i=js(r);r.next&&r.err("Unexpected trailing text");let s=Ma(Sa(i));return va(s,r),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,r=e.childCount){let i=this;for(let s=t;i&&s<r;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let r=0;r<e.next.length;r++)if(this.next[t].type==e.next[r].type)return!0;return!1}fillBefore(e,t=!1,r=0){let i=[this];function s(o,l){let a=o.matchFragment(e,r);if(a&&(!t||a.validEnd))return y.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:h,next:f}=o.next[c];if(!(h.isText||h.hasRequiredAttrs())&&i.indexOf(f)==-1){i.push(f);let d=s(f,l.concat(h));if(d)return d}}return null}return s(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let l=i;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!i.type||a.validEnd)&&(r.push({match:l.contentMatch,type:l,via:i}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&t(r.next[i].next)}return t(this),e.map((r,i)=>{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o<r.next.length;o++)s+=(o?", ":"")+r.next[o].type.name+"->"+e.indexOf(r.next[o].next);return s}).join(`
60
- `)}}Ye.empty=new Ye(!0);class ya{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function js(n){let e=[];do e.push(ba(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ba(n){let e=[];do e.push(Ca(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Ca(n){let e=ka(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=xa(n,e);else break;return e}function Yr(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function xa(n,e){let t=Yr(n),r=t;return n.eat(",")&&(n.next!="}"?r=Yr(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function wa(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function ka(n){if(n.eat("(")){let e=js(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=wa(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Sa(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let h=t();i(s(o.expr,a),h),a=h}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let h=t();r(a,h),i(s(o.expr,a),h),a=h}return[r(a)]}else{if(o.type=="name")return[r(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function _s(n,e){return e-n}function Qr(n,e){let t=[];return r(e),t.sort(_s);function r(i){let s=n[i];if(s.length==1&&!s[0].term)return r(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&r(a)}}}function Ma(n){let e=Object.create(null);return t(Qr(n,0));function t(r){let i=[];r.forEach(o=>{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let h=0;h<i.length;h++)i[h][0]==l&&(c=i[h][1]);Qr(n,a).forEach(h=>{c||i.push([l,c=[]]),c.indexOf(h)==-1&&c.push(h)})})});let s=e[r.join(",")]=new Ye(r.indexOf(n.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(_s);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function va(n,e){for(let t=0,r=[n];t<r.length;t++){let i=r[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),r.indexOf(c)==-1&&r.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Us(n){let e=Object.create(null);for(let t in n){let r=n[t];if(!r.hasDefault)return null;e[t]=r.default}return e}function Gs(n,e){let t=Object.create(null);for(let r in n){let i=e&&e[r];if(i===void 0){let s=n[r];if(s.hasDefault)i=s.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=i}return t}function Zs(n,e,t,r){for(let i in e)if(!(i in n))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${i}`);for(let i in n){let s=n[i];s.validate&&s.validate(e[i])}}function Xs(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new Na(n,r,e[r]);return t}let ei=class Ys{constructor(e,t,r){this.name=e,this.schema=t,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=Xs(e,r.attrs),this.defaultAttrs=Us(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Ye.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Gs(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ue(this,this.computeAttrs(e),y.from(t),T.setFrom(r))}createChecked(e=null,t,r){return t=y.from(t),this.checkContent(t),new Ue(this,this.computeAttrs(e),t,T.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=y.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(y.empty,!0);return s?new Ue(this,e,t.append(s),T.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Zs(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?t&&t.push(e[r]):t||(t=e.slice(0,r));return t?t.length?t:T.none:e}static compile(e,t){let r=Object.create(null);e.forEach((s,o)=>r[s]=new Ys(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Oa(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}class Na{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Oa(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class kn{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Xs(e,i.attrs),this.excluded=null;let s=Us(this.attrs);this.instance=s?new T(this,s):null}create(e=null){return!e&&this.instance?this.instance:new T(this,Gs(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new kn(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){Zs(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Aa{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=H.from(e.nodes),t.marks=H.from(e.marks||{}),this.nodes=ei.compile(this.spec.nodes,this),this.marks=kn.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=Ye.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?ti(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:ti(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ei){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new cn(r,r.defaultAttrs,e,T.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ue.fromJSON(this,e)}markFromJSON(e){return T.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function ti(n,e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],s=n.marks[i],o=s;if(s)t.push(s);else for(let l in n.marks){let a=n.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ta(n){return n.tag!=null}function Da(n){return n.style!=null}class ut{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ta(i))this.tags.push(i);else if(Da(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new ri(this,t,!1);return r.addAll(e,T.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new ri(this,t,!0);return r.addAll(e,T.none,t.from,t.to),C.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(Ia(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,r,i){for(let s=i?this.styles.indexOf(i)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!r.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,i)}for(let i in e.marks){let s=e.marks[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ii(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=ii(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new ut(e,ut.schemaRules(e)))}}const Qs={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Ea={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},eo={ol:!0,ul:!0},hn=1,fn=2,At=4;function ni(n,e,t){return e!=null?(e?hn:0)|(e==="full"?fn:0):n&&n.whitespace=="pre"?hn|fn:t&~At}class Ut{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=T.none,this.match=s||(o&At?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&hn)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Qs.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class ri{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ni(null,t.preserveWhitespace,0)|(r?At:0);i?s=new Ut(i.type,i.attrs,T.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Ut(null,null,T.none,!0,null,o):s=new Ut(e.schema.topNodeType,null,T.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&fn||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&hn)i.options&fn?r=r.replace(/\r\n?/g,`
61
- `):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;eo.hasOwnProperty(i)&&this.parser.normalizeLists&&Ra(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Ea.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,a=this.top,c=this.needsBlock;if(Qs.hasOwnProperty(i))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),l=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(a),this.needsBlock=c}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
62
- `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=r.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(o,t.attrs||null,r,t.preserveWhitespace);a&&(s=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s<r.length;s++)t=this.enterInner(r[s],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let i=this.textblockFromContext();i&&(t=this.enterInner(i,null,t))}let r=this.findPlace(e,t);if(r){this.closeExtra();let i=this.top;i.match&&(i.match=i.match.matchType(e.type));let s=T.none;for(let o of r.concat(e.marks))(i.type?i.type.allowsMarkType(o.type):si(o.type,e.type))&&(s=o.addToSet(s));return i.content.push(e.mark(s)),!0}return!1}enter(e,t,r,i){let s=this.findPlace(e.create(t),r);return s&&(s=this.enterInner(e,t,r,!0,i)),s}enterInner(e,t,r,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=ni(e,s,o.options);o.options&At&&o.content.length==0&&(l|=At);let a=T.none;return r=r.filter(c=>(o.type?o.type.allowsMarkType(c.type):si(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ut(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==t&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,r){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let h=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!h||h.name!=c&&!h.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function Ra(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&eo.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Ia(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ii(n){let e={};for(let t in n)e[t]=n[t];return e}function si(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:h}=l.edge(a);if(c==e||s.indexOf(h)<0&&o(h))return!0}};if(o(i.contentMatch))return!0}}class tt{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},r){r||(r=Rn(t).createDocumentFragment());let i=r,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)i=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],h=this.serializeMark(c,o.isInline,t);h&&(s.push([c,i]),i.appendChild(h.dom),i=h.contentDOM||h.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),r}serializeNodeInner(e,t){let{dom:r,contentDOM:i}=Qt(Rn(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return r}serializeNode(e,t={}){let r=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&Qt(Rn(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return Qt(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new tt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=oi(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return oi(e.marks)}}function oi(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function Rn(n){return n.document||window.document}const li=new WeakMap;function za(n){let e=li.get(n);return e===void 0&&li.set(n,e=Va(n)),e}function Va(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i<r.length;i++)t(r[i]);else for(let i in r)t(r[i])}return t(n),e}function Qt(n,e,t,r){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=za(r))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),c=e[1],h=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){h=2;for(let f in c)if(c[f]!=null){let d=f.indexOf(" ");d>0?a.setAttributeNS(f.slice(0,d),f.slice(d+1),c[f]):a.setAttribute(f,c[f])}}for(let f=h;f<e.length;f++){let d=e[f];if(d===0){if(f<e.length-1||f>h)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:u}=Qt(n,d,t,r);if(a.appendChild(p),u){if(l)throw new RangeError("Multiple content holes");l=u}}}return{dom:a,contentDOM:l}}const to=65535,no=Math.pow(2,16);function Pa(n,e){return n+e*no}function ai(n){return n&to}function Ba(n){return(n-(n&to))/no}const ro=1,io=2,en=4,so=8;class tr{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&so)>0}get deletedBefore(){return(this.delInfo&(ro|en))>0}get deletedAfter(){return(this.delInfo&(io|en))>0}get deletedAcross(){return(this.delInfo&en)>0}}class Q{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Q.empty)return Q.empty}recover(e){let t=0,r=ai(e);if(!this.inverted)for(let i=0;i<r;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+t+Ba(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],h=this.ranges[l+o],f=a+c;if(e<=f){let d=c?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:h);if(r)return p;let u=e==(t<0?a:f)?null:Pa(l/3,e-a),m=e==a?io:e==f?ro:en;return(t<0?e!=a:e!=f)&&(m|=so),new tr(p,m,u)}i+=h-c}return r?e+i:new tr(e+i,0,null)}touches(e,t){let r=0,i=ai(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let c=this.ranges[l+s],h=a+c;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],h=this.ranges[i+r];e(l,l+c,a,a+h),s+=h-c}}invert(){return new Q(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Q.empty:new Q(e<0?[0,-e,0]:[0,0,e])}}Q.empty=new Q([]);class at{constructor(e=[],t,r=0,i=e.length){this.maps=e,this.mirror=t,this.from=r,this.to=i}slice(e=0,t=this.maps.length){return new at(this.maps,this.mirror,e,t)}copy(){return new at(this.maps.slice(),this.mirror&&this.mirror.slice(),this.from,this.to)}appendMap(e,t){this.to=this.maps.push(e),t!=null&&this.setMirror(this.maps.length-1,t)}appendMapping(e){for(let t=0,r=this.maps.length;t<e.maps.length;t++){let i=e.getMirror(t);this.appendMap(e.maps[t],i!=null&&i<t?r+i:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,r=this.maps.length+e.maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new at;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;r<this.to;r++)e=this.maps[r].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,r){let i=0;for(let s=this.from;s<this.to;s++){let o=this.maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this.maps[a].recover(l.recover);continue}}i|=l.delInfo,e=l.pos}return r?e:new tr(e,i,null)}}const In=Object.create(null);class K{getMap(){return Q.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=In[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in In)throw new RangeError("Duplicate use of step JSON ID "+e);return In[e]=t,t.prototype.jsonID=e,t}}class V{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new V(e,null)}static fail(e){return new V(null,e)}static fromReplace(e,t,r,i){try{return V.ok(e.replace(t,r,i))}catch(s){if(s instanceof on)return V.fail(s.message);throw s}}}function Nr(n,e,t){let r=[];for(let i=0;i<n.childCount;i++){let s=n.child(i);s.content.size&&(s=s.copy(Nr(s.content,e,s))),s.isInline&&(s=e(s,t,i)),r.push(s)}return y.fromArray(r)}class Re extends K{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),s=new C(Nr(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return V.fromReplace(e,this.from,this.to,s)}invert(){return new fe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Re(t.pos,r.pos,this.mark)}merge(e){return e instanceof Re&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Re(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Re(t.from,t.to,e.markFromJSON(t.mark))}}K.jsonID("addMark",Re);class fe extends K{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new C(Nr(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return V.fromReplace(e,this.from,this.to,r)}invert(){return new Re(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new fe(t.pos,r.pos,this.mark)}merge(e){return e instanceof fe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new fe(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new fe(t.from,t.to,e.markFromJSON(t.mark))}}K.jsonID("removeMark",fe);class Ie extends K{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return V.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return V.fromReplace(e,this.pos,this.pos+1,new C(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(r))return new Ie(this.pos,t.marks[i]);return new Ie(this.pos,this.mark)}}return new pt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ie(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Ie(t.pos,e.markFromJSON(t.mark))}}K.jsonID("addNodeMark",Ie);class pt extends K{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return V.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return V.fromReplace(e,this.pos,this.pos+1,new C(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Ie(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new pt(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new pt(t.pos,e.markFromJSON(t.mark))}}K.jsonID("removeNodeMark",pt);class J extends K{constructor(e,t,r,i=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=i}apply(e){return this.structure&&nr(e,this.from,this.to)?V.fail("Structure replace would overwrite content"):V.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Q([this.from,this.to-this.from,this.slice.size])}invert(e){return new J(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deletedAcross&&r.deletedAcross?null:new J(t.pos,Math.max(t.pos,r.pos),this.slice)}merge(e){if(!(e instanceof J)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?C.empty:new C(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new J(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?C.empty:new C(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new J(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new J(t.from,t.to,C.fromJSON(e,t.slice),!!t.structure)}}K.jsonID("replace",J);class W extends K{constructor(e,t,r,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(nr(e,this.from,this.gapFrom)||nr(e,this.gapTo,this.to)))return V.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return V.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?V.fromReplace(e,this.from,this.to,r):V.fail("Content does not fit in gap")}getMap(){return new Q([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new W(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||i<t.pos||s>r.pos?null:new W(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new W(t.from,t.to,t.gapFrom,t.gapTo,C.fromJSON(e,t.slice),t.insert,!!t.structure)}}K.jsonID("replaceAround",W);function nr(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Ha(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,h)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&h.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+a.nodeSize,t),u=r.addToSet(f);for(let m=0;m<f.length;m++)f[m].isInSet(u)||(o&&o.to==d&&o.mark.eq(f[m])?o.to=p:i.push(o=new fe(d,p,f[m])));l&&l.to==d?l.to=p:s.push(l=new Re(d,p,r))}}),i.forEach(a=>n.step(a)),s.forEach(a=>n.step(a))}function La(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof kn){let c=o.marks,h;for(;h=r.isInSet(c);)(a||(a=[])).push(h),c=h.removeFromSet(c)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let h=0;h<a.length;h++){let f=a[h],d;for(let p=0;p<i.length;p++){let u=i[p];u.step==s-1&&f.eq(i[p].style)&&(d=u)}d?(d.to=c,d.step=s):i.push({style:f,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>n.step(new fe(o.from,o.to,o.style)))}function Ar(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),h=l+c.nodeSize,f=r.matchType(c.type);if(!f)o.push(new J(l,h,C.empty));else{r=f;for(let d=0;d<c.marks.length;d++)t.allowsMarkType(c.marks[d].type)||n.step(new fe(l,h,c.marks[d]));if(i&&c.isText&&t.whitespace!="pre"){let d,p=/\r?\n|\r/g,u;for(;d=p.exec(c.text);)u||(u=new C(y.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new J(l+d.index,l+d.index+d[0].length,u))}}l=h}if(!r.validEnd){let a=r.fillBefore(y.empty,!0);n.replace(l,l,new C(a,0,0))}for(let a=o.length-1;a>=0;a--)n.step(o[a])}function Fa(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Sn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(r<n.depth&&i.canReplace(s,o,t))return r;if(r==0||i.type.spec.isolating||!Fa(i,s,o))break}return null}function Wa(n,e,t){let{$from:r,$to:i,depth:s}=e,o=r.before(s+1),l=i.after(s+1),a=o,c=l,h=y.empty,f=0;for(let u=s,m=!1;u>t;u--)m||r.index(u)>0?(m=!0,h=y.from(r.node(u).copy(h)),f++):a--;let d=y.empty,p=0;for(let u=s,m=!1;u>t;u--)m||i.after(u+1)<i.end(u)?(m=!0,d=y.from(i.node(u).copy(d)),p++):c++;n.step(new W(a,c,o,l,new C(h.append(d),f,p),h.size-f,!0))}function oo(n,e,t=null,r=n){let i=$a(n,e),s=i&&Ja(r,e);return s?i.map(ci).concat({type:e,attrs:t}).concat(s.map(ci)):null}function ci(n){return{type:n,attrs:null}}function $a(n,e){let{parent:t,startIndex:r,endIndex:i}=n,s=t.contentMatchAt(r).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(r,i,o)?s:null}function Ja(n,e){let{parent:t,startIndex:r,endIndex:i}=n,s=t.child(r),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let c=r;a&&c<i;c++)a=a.matchType(t.child(c).type);return!a||!a.validEnd?null:o}function qa(n,e,t){let r=y.empty;for(let o=t.length-1;o>=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=y.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new W(i,s,i,s,new C(r,0,0),t.length,!0))}function Ka(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,a)&&ja(n.doc,n.mapping.slice(s).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",u=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!u?c=!1:!p&&u&&(c=!0)}c===!1&&ao(n,o,l,s),Ar(n,n.mapping.slice(s).map(l,1),r,void 0,c===null);let h=n.mapping.slice(s),f=h.map(l,1),d=h.map(l+o.nodeSize,1);return n.step(new W(f,d,f+1,d-1,new C(y.from(r.create(a,null,o.marks)),0,0),1,!0)),c===!0&&lo(n,o,l,s),!1}})}function lo(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function ao(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
63
- `))}})}function ja(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function _a(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new W(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new C(y.from(o),0,0),1,!0))}function ct(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,h=t-2;c>s;c--,h--){let f=i.node(c),d=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),u=r&&r[h+1];u&&(p=p.replaceChild(0,u.type.create(u.attrs)));let m=r&&r[h]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function Ua(n,e,t=1,r){let i=n.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=y.from(i.node(l).copy(s));let h=r&&r[c];o=y.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new J(e,e,new C(s.append(o),t,t),!0))}function Mn(n,e){let t=n.resolve(e),r=t.index();return Za(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Ga(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==r?n.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!n.type.allowsMarks(s.marks))return!1}return t.validEnd}function Za(n,e){return!!(n&&e&&!n.isLeaf&&Ga(n,e))}function Xa(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",f=!!o.contentMatch.matchType(i);h&&!f?r=!1:!h&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);ao(n,h.node(),h.before(),l)}o.inlineContent&&Ar(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new J(c,a.map(e+t,-1),C.empty,!0)),r===!0){let h=n.doc.resolve(c);lo(n,h.node(),h.before(),n.steps.length)}return n}function Ya(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s<r.node(i).childCount)return null}return null}function Qa(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let i=t.content;for(let s=0;s<t.openStart;s++)i=i.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=r.depth;o>=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),c=r.node(o),h=!1;if(s==1)h=c.canReplace(a,a,i);else{let f=c.contentMatchAt(a).findWrapping(i.firstChild.type);h=f&&c.canReplaceWith(a,a,f[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Tr(n,e,t=e,r=C.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return co(i,s,r)?new J(e,t,r):new ec(i,s,r).fit()}function co(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class ec{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new C(s,o,l);return e>-1?new W(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new J(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r<e;r++){let s=t.firstChild;if(t.childCount>1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=zn(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],h,f=null;if(t==1&&(o?c.matchType(o.type)||(f=c.fillBefore(y.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(h=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=zn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new C(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=zn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new C(Mt(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new C(Mt(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=r?r.content:o.content,a=o.openStart-e,c=0,h=[],{match:f,type:d}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)h.push(i.child(m));f=f.matchFragment(i)}let p=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=f.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(f=g,h.push(ho(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let u=c==l.childCount;u||(p=-1),this.placed=vt(this.placed,t,y.from(h)),this.frontier[t].match=f,u&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<p;m++){let b=g.lastChild;this.frontier.push({type:b.type,match:b.contentMatchAt(b.childCount)}),g=b.content}this.unplaced=u?e==0?C.empty:new C(Mt(o.content,e-1,1),e-1,p<0?o.openEnd:e-1):new C(Mt(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!Vn(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:r}=this.$to,i=this.$to.after(r);for(;r>1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=Vn(e,t,i,r,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],h=Vn(e,l,c,a,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=vt(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=vt(this.placed,this.depth,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=vt(this.placed,this.frontier.length,t))}}function Mt(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Mt(n.firstChild.content,e-1,t)))}function vt(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(vt(n.lastChild.content,e-1,t)))}function zn(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function ho(n,e,t){if(e<=0)return n;let r=n.content;return e>1&&(r=r.replaceChild(0,ho(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),n.copy(r)}function Vn(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!tc(t,s.content,o)?l:null}function tc(n,e,t){for(let r=t;r<e.childCount;r++)if(!n.allowsMarks(e.child(r).marks))return!0;return!1}function nc(n){return n.spec.defining||n.spec.definingForContent}function rc(n,e,t,r){if(!r.size)return n.deleteRange(e,t);let i=n.doc.resolve(e),s=n.doc.resolve(t);if(co(i,s,r))return n.step(new J(e,t,r));let o=uo(i,n.doc.resolve(t));o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let d=i.depth,p=i.pos-1;d>0;d--,p--){let u=i.node(d).type.spec;if(u.defining||u.definingAsContext||u.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==p&&o.splice(1,0,-d)}let a=o.indexOf(l),c=[],h=r.openStart;for(let d=r.content,p=0;;p++){let u=d.firstChild;if(c.push(u),p==r.openStart)break;d=u.content}for(let d=h-1;d>=0;d--){let p=c[d],u=nc(p.type);if(u&&!p.sameMarkup(i.node(Math.abs(l)-1)))h=d;else if(u||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+h+1)%(r.openStart+1),u=c[p];if(u)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],b=!0;g<0&&(b=!1,g=-g);let S=i.node(g-1),N=i.index(g-1);if(S.canReplaceWith(N,N,u.type,u.marks))return n.replace(i.before(g),b?s.after(g):t,new C(fo(r.content,0,r.openStart,p),p,r.openEnd))}}let f=n.steps.length;for(let d=o.length-1;d>=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=o[d];p<0||(e=i.before(p),t=s.after(p))}}function fo(n,e,t,r,i){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(fo(s.content,e+1,t,r,s)))}if(e>r){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(y.empty,!0))}return n}function ic(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Ya(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new C(y.from(r),0,0))}function sc(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=uo(r,i);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||r.node(l).type.contentMatch.validEnd)return n.delete(r.start(l),i.end(l));if(l>0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function uo(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(s<n.pos-(n.depth-i)||e.end(i)>e.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class ht extends K{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return V.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return V.fromReplace(e,this.pos,this.pos+1,new C(y.from(i),0,t.isLeaf?0:1))}getMap(){return Q.empty}invert(e){return new ht(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new ht(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new ht(t.pos,t.attr,t.value)}}K.jsonID("attr",ht);class zt extends K{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return V.ok(r)}getMap(){return Q.empty}invert(e){return new zt(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new zt(t.attr,t.value)}}K.jsonID("docAttr",zt);let mt=class extends Error{};mt=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};mt.prototype=Object.create(Error.prototype);mt.prototype.constructor=mt;mt.prototype.name="TransformError";class po{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new at}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new mt(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=C.empty){let i=Tr(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new C(y.from(r),0,0))}delete(e,t){return this.replace(e,t,C.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return rc(this,e,t,r),this}replaceRangeWith(e,t,r){return ic(this,e,t,r),this}deleteRange(e,t){return sc(this,e,t),this}lift(e,t){return Wa(this,e,t),this}join(e,t=1){return Xa(this,e,t),this}wrap(e,t){return qa(this,e,t),this}setBlockType(e,t=e,r,i=null){return Ka(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return _a(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ht(e,t,r)),this}setDocAttribute(e,t){return this.step(new zt(e,t)),this}addNodeMark(e,t){return this.step(new Ie(e,t)),this}removeNodeMark(e,t){if(!(t instanceof T)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new pt(e,t)),this}split(e,t=1,r){return Ua(this,e,t,r),this}addMark(e,t,r){return Ha(this,e,t,r),this}removeMark(e,t,r){return La(this,e,t,r),this}clearIncompatible(e,t,r){return Ar(this,e,t,r),this}}const Pn=Object.create(null);class k{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new mo(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=C.empty){let r=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=r,r=r.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],h=e.mapping.slice(s);e.replaceRange(h.map(a.pos),h.map(c.pos),l?C.empty:t),l==0&&di(e,s,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(r),c=a.map(o.pos),h=a.map(l.pos);s?e.deleteRange(c,h):(e.replaceRangeWith(c,h,t),di(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let i=e.parent.inlineContent?new M(e):it(e.node(0),e.parent,e.pos,e.index(),t,r);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?it(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):it(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new te(e.node(0))}static atStart(e){return it(e,e,0,0,1)||new te(e)}static atEnd(e){return it(e,e,e.content.size,e.childCount,-1)||new te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Pn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Pn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Pn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return M.between(this.$anchor,this.$head).getBookmark()}}k.prototype.visible=!0;class mo{constructor(e,t){this.$from=e,this.$to=t}}let hi=!1;function fi(n){!hi&&!n.parent.inlineContent&&(hi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class M extends k{constructor(e,t=e){fi(e),fi(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return k.near(r);let i=e.resolve(t.map(this.anchor));return new M(i.parent.inlineContent?i:r,r)}replace(e,t=C.empty){if(super.replace(e,t),t==C.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof M&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new vn(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new M(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=k.findFrom(t,r,!0)||k.findFrom(t,-r,!0);if(s)t=s.$head;else return k.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(k.findFrom(e,-r,!0)||k.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new M(e,t)}}k.jsonID("text",M);class vn{constructor(e,t){this.anchor=e,this.head=t}map(e){return new vn(e.map(this.anchor),e.map(this.head))}resolve(e){return M.between(e.resolve(this.anchor),e.resolve(this.head))}}class w extends k{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return r?k.near(s):new w(s)}content(){return new C(y.from(this.node),0,0)}eq(e){return e instanceof w&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Dr(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new w(e.resolve(t.anchor))}static create(e,t){return new w(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}w.prototype.visible=!1;k.jsonID("node",w);class Dr{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new vn(r,r):new Dr(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&w.isSelectable(r)?new w(t):k.near(t)}}class te extends k{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=C.empty){if(t==C.empty){e.delete(0,e.doc.content.size);let r=k.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new te(e)}map(e){return new te(e)}eq(e){return e instanceof te}getBookmark(){return oc}}k.jsonID("all",te);const oc={map(){return this},resolve(n){return new te(n)}};function it(n,e,t,r,i,s=!1){if(e.inlineContent)return M.create(n,t);for(let o=r-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&w.isSelectable(l))return w.create(n,t-(i<0?l.nodeSize:0))}else{let a=it(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function di(n,e,t){let r=n.steps.length-1;if(r<e)return;let i=n.steps[r];if(!(i instanceof J||i instanceof W))return;let s=n.mapping.maps[r],o;s.forEach((l,a,c,h)=>{o==null&&(o=h)}),n.setSelection(k.near(n.doc.resolve(o),t))}const ui=1,Gt=2,pi=4;class lc extends po{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|ui)&~Gt,this.storedMarks=null,this}get selectionSet(){return(this.updated&ui)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Gt,this}ensureMarks(e){return T.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Gt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Gt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||T.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(k.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=pi,this}get scrolledIntoView(){return(this.updated&pi)>0}}function mi(n,e){return!e||!n?n:n.bind(e)}class Ot{constructor(e,t,r){this.name=e,this.init=mi(t.init,r),this.apply=mi(t.apply,r)}}const ac=[new Ot("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Ot("selection",{init(n,e){return n.selection||k.atStart(e.doc)},apply(n){return n.selection}}),new Ot("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Ot("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Bn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ac.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Ot(r.key,r.spec.state,r))})}}class lt{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=t){let i=this.config.plugins[r];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],r=this.applyInner(e),i=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=i?i[o].n:0,c=i?i[o].state:this,h=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,r);if(h&&r.filterTransaction(h,o)){if(h.setMeta("appendedTransaction",e),!i){i=[];for(let f=0;f<this.config.plugins.length;f++)i.push(f<o?{state:r,n:t.length}:{state:this,n:0})}t.push(h),r=r.applyInner(h),s=!0}i&&(i[o]={state:r,n:t.length})}}if(!s)return{state:r,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new lt(this.config),r=this.config.fields;for(let i=0;i<r.length;i++){let s=r[i];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new lc(this)}static create(e){let t=new Bn(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new lt(t);for(let i=0;i<t.fields.length;i++)r[t.fields[i].name]=t.fields[i].init(e,r);return r}reconfigure(e){let t=new Bn(this.schema,e.plugins),r=t.fields,i=new lt(t);for(let s=0;s<r.length;s++){let o=r[s].name;i[o]=this.hasOwnProperty(o)?this[o]:r[s].init(e,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(r=>r.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Bn(e.schema,e.plugins),s=new lt(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ue.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=k.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}}function go(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=go(i,e,{})),t[r]=i}return t}class Ft{constructor(e){this.spec=e,this.props={},e.props&&go(e.props,this,this.props),this.key=e.key?e.key.key:yo("plugin")}getState(e){return e[this.key]}}const Hn=Object.create(null);function yo(n){return n in Hn?n+"$"+ ++Hn[n]:(Hn[n]=0,n+"$")}class Wt{constructor(e="key"){this.key=yo(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const bo=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function cc(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const hc=(n,e,t)=>{let r=cc(n,t);if(!r)return!1;let i=Co(r);if(!i){let o=r.blockRange(),l=o&&Sn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(vo(n,i,e,-1))return!0;if(r.parent.content.size==0&&(gt(s,"end")||w.isSelectable(s)))for(let o=r.depth;;o--){let l=Tr(n.doc,r.before(o),r.after(o),C.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=n.tr.step(l);a.setSelection(gt(s,"end")?k.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):w.create(a.doc,i.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||r.node(o-1).childCount>1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function gt(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}const fc=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=Co(r)}let o=s&&s.nodeBefore;return!o||!w.isSelectable(o)?!1:(e&&e(n.tr.setSelection(w.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Co(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function dc(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const uc=(n,e,t)=>{let r=dc(n,t);if(!r)return!1;let i=xo(r);if(!i)return!1;let s=i.nodeAfter;if(vo(n,i,e,1))return!0;if(r.parent.content.size==0&&(gt(s,"start")||w.isSelectable(s))){let o=Tr(n.doc,r.before(),r.after(),C.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=n.tr.step(o);l.setSelection(gt(s,"start")?k.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):w.create(l.doc,l.mapping.map(i.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0):!1},pc=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset<r.parent.content.size)return!1;s=xo(r)}let o=s&&s.nodeAfter;return!o||!w.isSelectable(o)?!1:(e&&e(n.tr.setSelection(w.create(n.doc,s.pos)).scrollIntoView()),!0)};function xo(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const mc=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
64
- `).scrollIntoView()),!0)};function Er(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const wo=(n,e)=>{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Er(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,o.createAndFill());a.setSelection(k.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},gc=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=Er(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,l=n.tr.insert(o,s.createAndFill());l.setSelection(M.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},ko=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ct(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Sn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function So(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof w&&e.selection.node.isBlock)return!r.parentOffset||!ct(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){a=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),l=Er(r.node(p-1).contentMatchAt(r.indexAfter(p-1)));let m=n&&n(i.parent,a,r);s.unshift(m||(a&&l?{type:l}:null)),o=p;break}else{if(p==1)return!1;s.unshift(null)}let h=e.tr;(e.selection instanceof M||e.selection instanceof te)&&h.deleteSelection();let f=h.mapping.map(r.pos),d=ct(h.doc,f,s.length,s);if(d||(s[0]=l?{type:l}:null,d=ct(h.doc,f,s.length,s)),h.split(f,s.length,s),!a&&c&&r.node(o).type!=l){let p=h.mapping.map(r.before(o)),u=h.doc.resolve(p);l&&r.node(o-1).canReplaceWith(u.index(),u.index()+1,l)&&h.setNodeMarkup(h.mapping.map(r.before(o)),l)}return t&&t(h.scrollIntoView()),!0}}const yc=So(),Mo=(n,e)=>(e&&e(n.tr.setSelection(new te(n.doc))),!0);function bc(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Mn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function vo(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&bc(n,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let p=e.pos+s.nodeSize,u=y.empty;for(let b=o.length-1;b>=0;b--)u=y.from(o[b].create(null,u));u=y.from(i.copy(u));let m=n.tr.step(new W(e.pos-1,p,e.pos,p,new C(u,1,0),o.length,!0)),g=m.doc.resolve(p+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Mn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&a?null:k.findFrom(e,1),f=h&&h.$from.blockRange(h.$to),d=f&&Sn(f);if(d!=null&&d>=e.depth)return t&&t(n.tr.lift(f,d).scrollIntoView()),!0;if(c&&gt(s,"start",!0)&&gt(i,"end")){let p=i,u=[];for(;u.push(p),!p.isTextblock;)p=p.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(t){let b=y.empty;for(let N=u.length-1;N>=0;N--)b=y.from(u[N].copy(b));let S=n.tr.step(new W(e.pos-u.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new C(b,u.length,0),0,!0));t(S.scrollIntoView())}return!0}}return!1}function Oo(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(M.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}const Cc=Oo(-1),xc=Oo(1);function wc(n,e=null){return function(t,r){let i=!1;for(let s=0;s<t.selection.ranges.length&&!i;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,c)=>{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let h=t.doc.resolve(c),f=h.index();i=h.parent.canReplaceWith(f,f+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[o];s.setBlockType(l,a,n,e)}r(s.scrollIntoView())}return!0}}function kc(n,e,t,r){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?n.inlineContent&&n.type.allowsMarkType(t):!1;if(n.nodesBetween(s.pos,o.pos,(a,c)=>{if(l||!r)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function We(n,e=null,t){let r=t!==!1;return function(i,s){let{empty:o,$cursor:l,ranges:a}=i.selection;if(o&&!l||!kc(i.doc,a,n,r))return!1;if(s)if(l)n.isInSet(i.storedMarks||l.marks())?s(i.tr.removeStoredMark(n)):s(i.tr.addStoredMark(n.create(e)));else{let c,h=i.tr;c=!a.some(f=>i.doc.rangeHasMark(f.$from.pos,f.$to.pos,n));for(let f=0;f<a.length;f++){let{$from:d,$to:p}=a[f];if(!c)h.removeMark(d.pos,p.pos,n);else{let u=d.pos,m=p.pos,g=d.nodeAfter,b=p.nodeBefore,S=g&&g.isText?/^\s*/.exec(g.text)[0].length:0,N=b&&b.isText?/\s*$/.exec(b.text)[0].length:0;u+S<m&&(u+=S,m-=N),h.addMark(u,m,n.create(e))}}s(h.scrollIntoView())}return!0}}function Vt(...n){return function(e,t,r){for(let i=0;i<n.length;i++)if(n[i](e,t,r))return!0;return!1}}let Ln=Vt(bo,hc,fc),gi=Vt(bo,uc,pc);const we={Enter:Vt(mc,gc,ko,yc),"Mod-Enter":wo,Backspace:Ln,"Mod-Backspace":Ln,"Shift-Backspace":Ln,Delete:gi,"Mod-Delete":gi,"Mod-a":Mo},No={"Ctrl-h":we.Backspace,"Alt-Backspace":we["Mod-Backspace"],"Ctrl-d":we.Delete,"Ctrl-Alt-Backspace":we["Mod-Delete"],"Alt-Delete":we["Mod-Delete"],"Alt-d":we["Mod-Delete"],"Ctrl-a":Cc,"Ctrl-e":xc};for(let n in we)No[n]=we[n];const Sc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Mc=Sc?No:we;var dn=200,P=function(){};P.prototype.append=function(e){return e.length?(e=P.from(e),!this.length&&e||e.length<dn&&this.leafAppend(e)||this.length<dn&&e.leafPrepend(this)||this.appendInner(e)):this};P.prototype.prepend=function(e){return e.length?P.from(e).append(this):this};P.prototype.appendInner=function(e){return new vc(this,e)};P.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?P.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};P.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};P.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};P.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};P.from=function(e){return e instanceof P?e:e&&e.length?new Ao(e):P.empty};var Ao=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a<o;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,s,o,l){for(var a=s-1;a>=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=dn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=dn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(P);P.empty=new Ao([]);var vc=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,i,s,o){var l=this.left.length;if(i<l&&this.left.forEachInner(r,i,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(r,Math.min(i,l),s,o)===!1)return!1},e.prototype.sliceInner=function(r,i){if(r==0&&i==this.length)return this;var s=this.left.length;return i<=s?this.left.slice(r,i):r>=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(P);const Oc=500;class ae{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],h=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),s=i.maps.length),s--,h.push(f);return}if(i){h.push(new he(f.map));let p=f.step.map(i.slice(s)),u;p&&o.maybeStep(p).doc&&(u=o.mapping.maps[o.mapping.maps.length-1],c.push(new he(u,void 0,void 0,c.length+h.length))),s--,u&&i.appendMap(u,s)}else o.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(s)):f.selection,a=new ae(this.items.slice(0,r).append(h.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let h=0;h<e.steps.length;h++){let f=e.steps[h].invert(e.docs[h]),d=new he(e.mapping.maps[h],f,t),p;(p=a&&a.merge(d))&&(d=p,h?s.pop():l=l.slice(0,l.length-1)),s.push(d),t&&(o++,t=void 0),i||(a=d)}let c=o-r.depth;return c>Ac&&(l=Nc(l,c),o-=c),new ae(l.append(s),o)}remapping(e,t){let r=new at;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new ae(this.items.append(e.map(t=>new he(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let u=s.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(s.slice(a+1,p));g&&l++,r.push(new he(u,m,g))}else r.push(new he(u))},i);let c=[];for(let d=t;d<o;d++)c.push(new he(s.maps[d]));let h=this.items.slice(0,i).append(c).append(r),f=new ae(h,l);return f.emptyItemCount()>Oc&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let f=new he(c.invert(),a,h),d,p=i.length-1;(d=i.length&&i[p].merge(f))?i[p]=d:i.push(f)}}else o.map&&r--},this.items.length,0),new ae(P.from(i.reverse()),s)}}ae.empty=new ae(P.empty,0);function Nc(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}class he{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new he(t.getMap().invert(),t,this.selection)}}}class Ne{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}}const Ac=20;function Tc(n,e,t,r){let i=t.getMeta(Ge),s;if(i)return i.historyState;t.getMeta(Rc)&&(n=new Ne(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(Ge))return o.getMeta(Ge).redo?new Ne(n.done.addTransform(t,void 0,r,tn(e)),n.undone,yi(t.mapping.maps),n.prevTime,n.prevComposition):new Ne(n.done,n.undone.addTransform(t,void 0,r,tn(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!Dc(t,n.prevRanges)),c=o?Fn(n.prevRanges,t.mapping):yi(t.mapping.maps);return new Ne(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,tn(e)),ae.empty,c,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Ne(n.done.rebased(t,s),n.undone.rebased(t,s),Fn(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Ne(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Fn(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Dc(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let s=0;s<e.length;s+=2)r<=e[s+1]&&i>=e[s]&&(t=!0)}),t}function yi(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,s,o)=>e.push(s,o));return e}function Fn(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let i=e.map(n[r],1),s=e.map(n[r+1],-1);i<=s&&t.push(i,s)}return t}function Ec(n,e,t){let r=tn(e),i=Ge.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),a=new Ne(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Ge,{redo:t,historyState:a})}let Wn=!1,bi=null;function tn(n){let e=n.plugins;if(bi!=e){Wn=!1,bi=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Wn=!0;break}}return Wn}const Ge=new Wt("history"),Rc=new Wt("closeHistory");function Ic(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new Ft({key:Ge,state:{init(){return new Ne(ae.empty,ae.empty,null,0,-1)},apply(e,t,r){return Tc(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,i=r=="historyUndo"?Do:r=="historyRedo"?rr:null;return i?(t.preventDefault(),i(e.state,e.dispatch)):!1}}}})}function To(n,e){return(t,r)=>{let i=Ge.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=Ec(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}const Do=To(!1,!0),rr=To(!0,!0);var He={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},un={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},zc=typeof navigator<"u"&&/Mac/.test(navigator.platform),Vc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var L=0;L<10;L++)He[48+L]=He[96+L]=String(L);for(var L=1;L<=24;L++)He[L+111]="F"+L;for(var L=65;L<=90;L++)He[L]=String.fromCharCode(L+32),un[L]=String.fromCharCode(L);for(var $n in He)un.hasOwnProperty($n)||(un[$n]=He[$n]);function Pc(n){var e=zc&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Vc&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?un:He)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Bc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Hc(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))r=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Bc?o=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return r&&(t="Alt-"+t),i&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Lc(n){let e=Object.create(null);for(let t in n)e[Hc(t)]=n[t];return e}function Jn(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function qn(n){return new Ft({props:{handleKeyDown:Eo(n)}})}function Eo(n){let e=Lc(n);return function(t,r){let i=Pc(r),s,o=e[Jn(i,r)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let l=e[Jn(i,r,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((r.shiftKey||r.altKey||r.metaKey||i.charCodeAt(0)>127)&&(s=He[r.keyCode])&&s!=i){let l=e[Jn(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}function Ci(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=!1,a=o;if(!o)return!1;if(o.depth>=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);a=new an(h,h,o.depth),o.endIndex<o.parent.childCount&&(o=new an(i,t.doc.resolve(s.end(o.depth)),o.depth)),l=!0}let c=oo(a,n,e,o);return c?(r&&r(Fc(t.tr,o,c,l,n).scrollIntoView()),!0):!1}}function Fc(n,e,t,r,i){let s=y.empty;for(let h=t.length-1;h>=0;h--)s=y.from(t[h].type.create(t[h].attrs,s));n.step(new W(e.start-(r?2:0),e.end,e.start,e.end,new C(s,0,0),t.length,!0));let o=0;for(let h=0;h<t.length;h++)t[h].type==i&&(o=h+1);let l=t.length-o,a=e.start+t.length-(r?2:0),c=e.parent;for(let h=e.startIndex,f=e.endIndex,d=!0;h<f;h++,d=!1)!d&&ct(n.doc,a,l)&&(n.split(a,l),a+=2*l),a+=c.child(h).nodeSize;return n}function Wc(n,e){return function(t,r){let{$from:i,$to:s,node:o}=t.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(s))return!1;let l=i.node(-1);if(l.type!=n)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=n||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=y.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let b=i.depth-d;b>=i.depth-3;b--)f=y.from(i.node(b).copy(f));let p=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(y.from(n.createAndFill()));let u=i.before(i.depth-(d-1)),m=t.tr.replace(u,i.after(-p),new C(f,4-d,0)),g=-1;m.doc.nodesBetween(u,m.doc.content.size,(b,S)=>{if(g>-1)return!1;b.isTextblock&&b.content.size==0&&(g=S+1)}),g>-1&&m.setSelection(k.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,s.pos),h=a?[null,{type:a}]:void 0;return ct(c.doc,i.pos,2,h)?(r&&r(c.split(i.pos,2,h).scrollIntoView()),!0):!1}}function ir(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?$c(e,t,n,s):Jc(e,t,s):!0:!1}}function $c(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new W(s-1,o,s,o,new C(y.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new an(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));const l=Sn(r);if(l==null)return!1;i.lift(r,l);let a=i.mapping.map(s,-1)-1;return Mn(i.doc,a)&&i.join(a),e(i.scrollIntoView()),!0}function Jc(n,e,t){let r=n.tr,i=t.parent;for(let p=t.end,u=t.endIndex-1,m=t.startIndex;u>m;u--)p-=i.child(u).nodeSize,r.delete(p-1,p+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),h=s.index(-1);if(!c.canReplace(h+(l?0:1),h+1,o.content.append(a?y.empty:y.from(i))))return!1;let f=s.pos,d=f+o.nodeSize;return r.step(new W(f-(l?1:0),d+(a?1:0),f+1,d-1,new C((l?y.empty:y.from(i.copy(y.empty))).append(a?y.empty:y.from(i.copy(y.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function qc(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,h=y.from(c?n.create():null),f=new C(y.from(n.create(null,y.from(l.type.create(null,h)))),c?3:1,0),d=s.start,p=s.end;t(e.tr.step(new W(d-(c?3:1),p,d,p,f,1,!0)).scrollIntoView())}return!0}}const F=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Pt=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let sr=null;const xe=function(n,e,t){let r=sr||(sr=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Kc=function(){sr=null},Qe=function(n,e,t,r){return t&&(xi(n,e,t,r,-1)||xi(n,e,t,r,1))},jc=/^(img|br|input|textarea|hr)$/i;function xi(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:ie(n))){let s=n.parentNode;if(!s||s.nodeType!=1||$t(n)||jc.test(n.nodeName)||n.contentEditable=="false")return!1;e=F(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?ie(n):0}else return!1}}function ie(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function _c(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=ie(n)}else if(n.parentNode&&!$t(n))e=F(n),n=n.parentNode;else return null}}function Uc(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!$t(n))e=F(n)+1,n=n.parentNode;else return null}}function Gc(n,e,t){for(let r=e==0,i=e==ie(n);r||i;){if(n==t)return!0;let s=F(n);if(n=n.parentNode,!n)return!1;r=r&&s==0,i=i&&s==ie(n)}}function $t(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const On=function(n){return n.focusNode&&Qe(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function $e(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Zc(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Xc(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(ie(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(ie(r.startContainer),r.startOffset)}}}const ue=typeof navigator<"u"?navigator:null,wi=typeof document<"u"?document:null,Le=ue&&ue.userAgent||"",or=/Edge\/(\d+)/.exec(Le),Ro=/MSIE \d/.exec(Le),lr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Le),X=!!(Ro||lr||or),Ve=Ro?document.documentMode:lr?+lr[1]:or?+or[1]:0,ce=!X&&/gecko\/(\d+)/i.test(Le);ce&&+(/Firefox\/(\d+)/.exec(Le)||[0,0])[1];const ar=!X&&/Chrome\/(\d+)/.exec(Le),q=!!ar,Io=ar?+ar[1]:0,_=!X&&!!ue&&/Apple Computer/.test(ue.vendor),yt=_&&(/Mobile\/\w+/.test(Le)||!!ue&&ue.maxTouchPoints>2),re=yt||(ue?/Mac/.test(ue.platform):!1),Yc=ue?/Win/.test(ue.platform):!1,le=/Android \d/.test(Le),Jt=!!wi&&"webkitFontSmoothing"in wi.documentElement.style,Qc=Jt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function eh(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ge(n,e){return typeof n=="number"?n:n[e]}function th(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function ki(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Pt(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,c=a?eh(s):th(l),h=0,f=0;if(e.top<c.top+ge(r,"top")?f=-(c.top-e.top+ge(i,"top")):e.bottom>c.bottom-ge(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+ge(i,"top")-c.top:e.bottom-c.bottom+ge(i,"bottom")),e.left<c.left+ge(r,"left")?h=-(c.left-e.left+ge(i,"left")):e.right>c.right-ge(r,"right")&&(h=e.right-c.right+ge(i,"right")),h||f)if(a)s.defaultView.scrollBy(h,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),h&&(l.scrollLeft+=h);let u=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-u,top:e.top-m,right:e.right-u,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function nh(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=n.root.elementFromPoint(s,o);if(!l||l==n.dom||!n.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:zo(n.dom)}}function zo(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Pt(r));return e}function rh({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Vo(t,r==0?0:r-e)}function Vo(n,e){for(let t=0;t<n.length;t++){let{dom:r,top:i,left:s}=n[t];r.scrollTop!=i+e&&(r.scrollTop=i+e),r.scrollLeft!=s&&(r.scrollLeft=s)}}let nt=null;function ih(n){if(n.setActive)return n.setActive();if(nt)return n.focus(nt);let e=zo(n);n.focus(nt==null?{get preventScroll(){return nt={preventScroll:!0},!0}}:void 0),nt||(nt=!1,Vo(e,0))}function Po(n,e){let t,r=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let h=n.firstChild,f=0;h;h=h.nextSibling,f++){let d;if(h.nodeType==1)d=h.getClientRects();else if(h.nodeType==3)d=xe(h).getClientRects();else continue;for(let p=0;p<d.length;p++){let u=d[p];if(u.top<=o&&u.bottom>=l){o=Math.max(u.bottom,o),l=Math.min(u.top,l);let m=u.left>e.left?u.left-e.left:u.right<e.left?e.left-u.right:0;if(m<r){t=h,r=m,i=m&&t.nodeType==3?{left:u.right<e.left?u.right:u.left,top:e.top}:e,h.nodeType==1&&m&&(s=f+(e.left>=(u.left+u.right)/2?1:0));continue}}else u.top>e.top&&!a&&u.left<=e.left&&u.right>=e.left&&(a=h,c={left:Math.max(u.left,Math.min(u.right,e.left)),top:u.top});!t&&(e.left>=u.right&&e.top>=u.top||e.left>=u.left&&e.top>=u.bottom)&&(s=f+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?sh(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:Po(t,i)}function sh(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i<t;i++){r.setEnd(n,i+1),r.setStart(n,i);let s=Oe(r,1);if(s.top!=s.bottom&&Rr(e,s))return{node:n,offset:i+(e.left>=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function Rr(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function oh(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function lh(n,e,t){let{node:r,offset:i}=Po(e,t),s=-1;if(r.nodeType==1&&!r.firstChild){let o=r.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function ah(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&a.left>r.left||a.top>r.top?i=l.posBefore:(!o&&a.right<r.left||a.bottom<r.top)&&(i=l.posAfter),o=!0),!l.contentDOM&&i<0&&!l.node.isText)return(l.node.isBlock?r.top<(a.top+a.bottom)/2:r.left<(a.left+a.right)/2)?l.posBefore:l.posAfter}s=l.dom.parentNode}return i>-1?i:n.docView.posFromDOM(e,t,-1)}function Bo(n,e,t){let r=n.childNodes.length;if(r&&t.top<t.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-t.top)/(t.bottom-t.top))-2)),s=i;;){let o=n.childNodes[s];if(o.nodeType==1){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Rr(e,c))return Bo(o,e,c)}}if((s=(s+1)%r)==i)break}return n}function ch(n,e){let t=n.dom.ownerDocument,r,i=0,s=Xc(t,e.left,e.top);s&&({node:r,offset:i}=s);let o=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!o||!n.dom.contains(o.nodeType!=1?o.parentNode:o)){let c=n.dom.getBoundingClientRect();if(!Rr(e,c)||(o=Bo(n.dom,e,c),!o))return null}if(_)for(let c=o;r&&c;c=Pt(c))c.draggable&&(r=void 0);if(o=oh(o,e),r){if(ce&&r.nodeType==1&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let h=r.childNodes[i],f;h.nodeName=="IMG"&&(f=h.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&i++}let c;Jt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=ah(n,r,i,e))}l==null&&(l=lh(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Si(n){return n.top<n.bottom||n.left<n.right}function Oe(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(Si(r))return r}return Array.prototype.find.call(t,Si)||n.getBoundingClientRect()}const hh=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Ho(n,e,t){let{node:r,offset:i,atom:s}=n.docView.domFromPos(e,t<0?-1:1),o=Jt||ce;if(r.nodeType==3)if(o&&(hh.test(r.nodeValue)||(t<0?!i:i==r.nodeValue.length))){let a=Oe(xe(r,i,i),t);if(ce&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let c=Oe(xe(r,i-1,i-1),-1);if(c.top==a.top){let h=Oe(xe(r,i,i+1),-1);if(h.top!=a.top)return xt(h,h.left<c.left)}}return a}else{let a=i,c=i,h=t<0?1:-1;return t<0&&!i?(c++,h=-1):t>=0&&i==r.nodeValue.length?(a--,h=1):t<0?a--:c++,xt(Oe(xe(r,a,c),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==ie(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Kn(a.getBoundingClientRect(),!1)}if(s==null&&i<ie(r)){let a=r.childNodes[i];if(a.nodeType==1)return Kn(a.getBoundingClientRect(),!0)}return Kn(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==ie(r))){let a=r.childNodes[i-1],c=a.nodeType==3?xe(a,ie(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return xt(Oe(c,1),!1)}if(s==null&&i<ie(r)){let a=r.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?xe(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return xt(Oe(c,-1),!0)}return xt(Oe(r.nodeType==3?xe(r):r,-t),t>=0)}function xt(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Kn(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Lo(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function fh(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Lo(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=Ho(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=xe(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let h=a[c];if(h.bottom>h.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}const dh=/[\u0590-\u08ac]/;function uh(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!dh.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:Lo(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:h,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:u,focusOffset:m}=n.domSelectionRange(),g=u&&!p.contains(u.nodeType==1?u:u.parentNode)||a==u&&c==m;try{l.collapse(h,f),a&&(a!=h||c!=f)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}let Mi=null,vi=null,Oi=!1;function ph(n,e,t){return Mi==e&&vi==t?Oi:(Mi=e,vi=t,Oi=t=="up"||t=="down"?fh(n,e,t):uh(n,e,t))}const se=0,Ni=1,Je=2,pe=3;class qt{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=se,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,r=this.posAtStart;;t++){let i=this.children[t];if(i==e)return r;r+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,r){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(r<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=t>F(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;t<this.children.length;t++){let i=this.children[t],s=r+i.size;if(r==e&&s!=r){for(;!i.border&&i.children.length;)i=i.children[0];return i}if(e<s)return i.descAt(e-r-i.border);r=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,i=0;for(let s=0;r<this.children.length;r++){let o=this.children[r],l=s+o.size;if(l>e||o instanceof Wo){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Fo&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?F(s.dom)+1:0}}else{let s,o=!0;for(;s=r<this.children.length?this.children[r]:null,!(!s||s.dom.parentNode==this.contentDOM);r++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?F(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let o=r,l=0;;l++){let a=this.children[l],c=o+a.size;if(i==-1&&e<=c){let h=o+a.border;if(e>=h&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,h);e=o;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=F(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let h=l+1;h<this.children.length;h++){let f=this.children[h];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=F(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:r}=this.domFromPos(e,0);if(t.nodeType!=1||r==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[r]}setSelection(e,t,r,i=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let p=0,u=0;p<this.children.length;p++){let m=this.children[p],g=u+m.size;if(s>u&&o<g)return m.setSelection(e-u-m.border,t-u-m.border,r,i);u=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=r.root.getSelection(),h=r.domSelectionRange(),f=!1;if((ce||_)&&e==t){let{node:p,offset:u}=l;if(p.nodeType==3){if(f=!!(u&&p.nodeValue[u-1]==`
65
- `),f&&u==p.nodeValue.length)for(let m=p,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:F(g)+1});break}let b=m.pmViewDesc;if(b&&b.node&&b.node.isBlock)break}}else{let m=p.childNodes[u-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(ce&&h.focusNode&&h.focusNode!=a.node&&h.focusNode.nodeType==1){let p=h.focusNode.childNodes[h.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||f&&_)&&Qe(l.node,l.offset,h.anchorNode,h.anchorOffset)&&Qe(a.node,a.offset,h.focusNode,h.focusOffset))return;let d=!1;if((c.extend||e==t)&&!f){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let u=l;l=a,a=u}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i<this.children.length;i++){let s=this.children[i],o=r+s.size;if(r==o?e<=o&&t>=r:e<o&&t>r){let l=r+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==r||t==o?Je:Ni,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=pe:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Je:pe}r=o}this.dirty=Je}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Je:Ni;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class Fo extends qt{constructor(e,t,r,i){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(r,()=>{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==se&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class mh extends qt{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class et extends qt{constructor(e,t,r,i,s){super(e,[],r,i),this.mark=t,this.spec=s}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=tt.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new et(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&pe||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=pe&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=se){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=se}}slice(e,t,r){let i=et.create(this.parent,this.mark,!0,r),s=this.children,o=this.size;t<o&&(s=hr(s,t,o,r)),e>0&&(s=hr(s,0,e,r));for(let l=0;l<s.length;l++)s[l].parent=i;return i.children=s,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Pe extends qt{constructor(e,t,r,i,s,o,l,a,c){super(e,[],s,o),this.node=t,this.outerDeco=r,this.innerDeco=i,this.nodeDOM=l}static create(e,t,r,i,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),h=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:f}=tt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=qo(h,r,t),c?a=new gh(e,t,r,i,h,f||null,d,c,s,o+1):t.isText?new Nn(e,t,r,i,h,d,s):new Pe(e,t,r,i,h,f||null,d,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==se&&e.eq(this.node)&&pn(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new bh(this,o&&o.node,e);wh(this.node,this.innerDeco,(c,h,f)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!f&&a.syncToMarks(h==this.node.childCount?T.none:this.node.child(h).marks,r,e),a.placeWidget(c,e,i)},(c,h,f,d)=>{a.syncToMarks(c.marks,r,e);let p;a.findNodeMatch(c,h,f,d)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(p=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(c,h,f,p,e)||a.updateNextNode(c,h,f,e,d,i)||a.addNode(c,h,f,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Je)&&(o&&this.protectLocalComposition(e,o),$o(this.contentDOM,this.children,e),yt&&kh(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof M)||r<t||i>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Sh(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new mh(this,s,t,i);e.input.compositionNodes.push(o),this.children=hr(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==pe||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=se}updateOuterDeco(e){if(pn(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Jo(this.dom,this.nodeDOM,cr(this.outerDeco,this.node,t),cr(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Ai(n,e,t,r,i){qo(r,e,n);let s=new Pe(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Nn extends Pe{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==pe||this.dirty!=se&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=se||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=se,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new Nn(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=pe)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Wo extends qt{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==se&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class gh extends Pe{constructor(e,t,r,i,s,o,l,a,c,h){super(e,t,r,i,s,o,l,c,h),this.spec=a}update(e,t,r,i){if(this.dirty==pe)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function $o(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==n){for(;l!=r;)r=Ti(r),i=!0;r=r.nextSibling}else i=!0,n.insertBefore(l,r);if(o instanceof et){let a=r?r.previousSibling:n.lastChild;$o(o.contentDOM,o.children,t),r=a?a.nextSibling:n.firstChild}}for(;r;)r=Ti(r),i=!0;i&&t.trackWrites==n&&(t.trackWrites=null)}const Tt=function(n){n&&(this.nodeName=n)};Tt.prototype=Object.create(null);const qe=[new Tt];function cr(n,e,t){if(n.length==0)return qe;let r=t?qe[0]:new Tt,i=[r];for(let s=0;s<n.length;s++){let o=n[s].type.attrs;if(o){o.nodeName&&i.push(r=new Tt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(r=new Tt(e.isInline?"span":"div")),l=="class"?r.class=(r.class?r.class+" ":"")+a:l=="style"?r.style=(r.style?r.style+";":"")+a:l!="nodeName"&&(r[l]=a))}}}return i}function Jo(n,e,t,r){if(t==qe&&r==qe)return e;let i=e;for(let s=0;s<r.length;s++){let o=r[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&i!=n&&(a=i.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=qe[0]),i=a}yh(i,l||qe[0],o)}return i}function yh(n,e,t){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in t)&&n.removeAttribute(r);for(let r in t)r!="class"&&r!="style"&&r!="nodeName"&&t[r]!=e[r]&&n.setAttribute(r,t[r]);if(e.class!=t.class){let r=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<r.length;s++)i.indexOf(r[s])==-1&&n.classList.remove(r[s]);for(let s=0;s<i.length;s++)r.indexOf(i[s])==-1&&n.classList.add(i[s]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=r.exec(e.style);)n.style.removeProperty(i[1])}t.style&&(n.style.cssText+=t.style)}}function qo(n,e,t){return Jo(n,n,qe,cr(e,t,n.nodeType!=1))}function pn(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function Ti(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class bh{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Ch(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let r=e;r<t;r++)this.top.children[r].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,r){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=se,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let l=-1;for(let a=this.index;a<Math.min(this.index+3,this.top.children.length);a++){let c=this.top.children[a];if(c.matchesMark(e[s])&&!this.isLocked(c.dom)){l=a;break}}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=et.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,r)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,r,i,s){let o=this.top.children[i];return o.dirty==pe&&o.dom==o.contentDOM&&(o.dirty=Je),o.update(e,t,r,s)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let r=e.pmViewDesc;if(r){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==r)return i}return-1}e=t}}updateNextNode(e,t,r,i,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Pe){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let h=a.dom,f,d=this.isLocked(h)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=pe&&pn(t,a.outerDeco));if(!d&&a.update(e,t,r,i))return this.destroyBetween(this.index,l),a.dom!=h&&(this.changed=!0),this.index++,!0;if(!d&&(f=this.recreateWrapper(a,e,t,r,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Je,f.updateChildren(i,o+1),f.dirty=se),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,r,i,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!pn(r,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Pe.create(this.top,t,r,i,s,o);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,r,i,s){let o=Pe.create(this.top,e,t,r,i,s);o.contentDOM&&o.updateChildren(i,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,r){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let s=new Fo(this.top,e,t,r);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof et;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Nn)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((_||q)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let r=document.createElement(e);e=="IMG"&&(r.className="ProseMirror-separator",r.alt=""),e=="BR"&&(r.className="ProseMirror-trailingBreak");let i=new Wo(this.top,[],r,null);t!=this.top?t.children.push(i):t.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function Ch(n,e){let t=e,r=t.children.length,i=n.childCount,s=new Map,o=[];e:for(;i>0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof et)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function xh(n,e){return n.type.side-e.type.side}function wh(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let c=0;c<n.childCount;c++){let h=n.child(c);r(h,i,e.forChild(s,h),c),s+=h.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let h,f;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(h?(f||(f=[h])).push(g):h=g)}if(h)if(f){f.sort(xh);for(let g=0;g<f.length;g++)t(f[g],c,!!a)}else t(h,c,!!a);let d,p;if(a)p=-1,d=a,a=null;else if(c<n.childCount)p=c,d=n.child(c++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)l.push(i[o++]);let u=s+d.nodeSize;if(d.isText){let g=u;o<i.length&&i[o].from<g&&(g=i[o].from);for(let b=0;b<l.length;b++)l[b].to<g&&(g=l[b].to);g<u&&(a=d.cut(g-s),d=d.cut(0,g-s),u=g,p=-1)}else for(;o<i.length&&i[o].to<u;)o++;let m=d.isInline&&!d.isLeaf?l.filter(g=>!g.inline):l.slice();r(d,m,e.forChild(s,d),p),s=u}}function kh(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Sh(n,e,t,r){for(let i=0,s=0;i<n.childCount&&s<=r;){let o=n.child(i++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;i<n.childCount;){let c=n.child(i++);if(s+=c.nodeSize,!c.isText)break;a+=c.text}if(s>=t){if(s>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l<r?a.lastIndexOf(e,r-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function hr(n,e,t,r,i){let s=[];for(let o=0,l=0;o<n.length;o++){let a=n[o],c=l,h=l+=a.size;c>=t||h<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,r)),i&&(s.push(i),i=void 0),h>t&&s.push(a.slice(t-c,a.size,r)))}return s}function Ir(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,c;if(On(t)){for(a=o;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&w.isSelectable(f)&&i.parent&&!(f.isInline&&Gc(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new w(o==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,d=o;for(let p=0;p<t.rangeCount;p++){let u=t.getRangeAt(p);f=Math.min(f,n.docView.posFromDOM(u.startContainer,u.startOffset,1)),d=Math.max(d,n.docView.posFromDOM(u.endContainer,u.endOffset,-1))}if(f<0)return null;[a,o]=d==n.state.selection.anchor?[d,f]:[f,d],l=r.resolve(o)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let h=r.resolve(a);if(!c){let f=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;c=zr(n,h,l,f)}return c}function Ko(n){return n.editable?n.hasFocus():_o(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function ke(n,e=!1){let t=n.state.selection;if(jo(n,t),!!Ko(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&q){let r=n.domSelectionRange(),i=n.domObserver.currentSelection;if(r.anchorNode&&i.anchorNode&&Qe(r.anchorNode,r.anchorOffset,i.anchorNode,i.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)vh(n);else{let{anchor:r,head:i}=t,s,o;Di&&!(t instanceof M)&&(t.$from.parent.inlineContent||(s=Ei(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=Ei(n,t.to))),n.docView.setSelection(r,i,n,e),Di&&(s&&Ri(s),o&&Ri(o)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Mh(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const Di=_||q&&Io<63;function Ei(n,e){let{node:t,offset:r}=n.docView.domFromPos(e,0),i=r<t.childNodes.length?t.childNodes[r]:null,s=r?t.childNodes[r-1]:null;if(_&&i&&i.contentEditable=="false")return jn(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return jn(i);if(s)return jn(s)}}function jn(n){return n.contentEditable="true",_&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function Ri(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Mh(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),r=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Ko(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function vh(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,F(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&X&&Ve<=11&&(r.disabled=!0,r.disabled=!1)}function jo(n,e){if(e instanceof w){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Ii(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Ii(n)}function Ii(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function zr(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||M.between(e,t,r)}function zi(n){return n.editable&&!n.hasFocus()?!1:_o(n)}function _o(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Oh(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Qe(e.node,e.offset,t.anchorNode,t.anchorOffset)}function fr(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&k.findFrom(s,e)}function Ae(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Vi(n,e,t){let r=n.state.selection;if(r instanceof M)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ae(n,new M(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=fr(n.state,e);return i&&i instanceof w?Ae(n,i):!1}else if(!(re&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?w.isSelectable(s)?Ae(n,new w(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):Jt?Ae(n,new M(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof w&&r.node.isInline)return Ae(n,new M(e>0?r.$to:r.$from));{let i=fr(n.state,e);return i?Ae(n,i):!1}}}function mn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Dt(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function rt(n,e){return e<0?Nh(n):Ah(n)}function Nh(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(ce&&t.nodeType==1&&r<mn(t)&&Dt(t.childNodes[r],-1)&&(o=!0);;)if(r>0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Dt(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Uo(t))break;{let l=t.previousSibling;for(;l&&Dt(l,-1);)i=t.parentNode,s=F(l),l=l.previousSibling;if(l)t=l,r=mn(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?dr(n,t,r):i&&dr(n,i,s)}function Ah(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=mn(t),s,o;for(;;)if(r<i){if(t.nodeType!=1)break;let l=t.childNodes[r];if(Dt(l,1))s=t,o=++r;else break}else{if(Uo(t))break;{let l=t.nextSibling;for(;l&&Dt(l,1);)s=l.parentNode,o=F(l)+1,l=l.nextSibling;if(l)t=l,r=0,i=mn(t);else{if(t=t.parentNode,t==n.dom)break;r=i=0}}}s&&dr(n,s,o)}function Uo(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function Th(n,e){for(;n&&e==n.childNodes.length&&!$t(n);)e=F(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function Dh(n,e){for(;n&&!e&&!$t(n);)e=F(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function dr(n,e,t){if(e.nodeType!=3){let s,o;(o=Th(e,t))?(e=o,t=0):(s=Dh(e,t))&&(e=s,t=s.nodeValue.length)}let r=n.domSelection();if(!r)return;if(On(r)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),r.removeAllRanges(),r.addRange(s)}else r.extend&&r.extend(e,t);n.domObserver.setCurSelection();let{state:i}=n;setTimeout(()=>{n.state==i&&ke(n)},50)}function Pi(n,e){let t=n.state.doc.resolve(e);if(!(q||Yc)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left<i.left?"ltr":"rtl"}if(e<t.end()){let s=n.coordsAtPos(e+1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Bi(n,e,t){let r=n.state.selection;if(r instanceof M&&!r.empty||t.indexOf("s")>-1||re&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=fr(n.state,e);if(o&&o instanceof w)return Ae(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof te?k.near(o,e):k.findFrom(o,e);return l?Ae(n,l):!1}return!1}function Hi(n,e){if(!(n.state.selection instanceof M))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function Li(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Eh(n){if(!_||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;Li(n,r,"true"),setTimeout(()=>Li(n,r,"false"),20)}return!1}function Rh(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Ih(n,e){let t=e.keyCode,r=Rh(e);if(t==8||re&&t==72&&r=="c")return Hi(n,-1)||rt(n,-1);if(t==46&&!e.shiftKey||re&&t==68&&r=="c")return Hi(n,1)||rt(n,1);if(t==13||t==27)return!0;if(t==37||re&&t==66&&r=="c"){let i=t==37?Pi(n,n.state.selection.from)=="ltr"?-1:1:-1;return Vi(n,i,r)||rt(n,i)}else if(t==39||re&&t==70&&r=="c"){let i=t==39?Pi(n,n.state.selection.from)=="ltr"?1:-1:1;return Vi(n,i,r)||rt(n,i)}else{if(t==38||re&&t==80&&r=="c")return Bi(n,-1,r)||rt(n,-1);if(t==40||re&&t==78&&r=="c")return Eh(n)||Bi(n,1,r)||rt(n,1);if(r==(re?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Go(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let o=n.someProp("clipboardSerializer")||tt.fromSchema(n.state.schema),l=tl(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c=a.firstChild,h,f=0;for(;c&&c.nodeType==1&&(h=el[c.nodeName.toLowerCase()]);){for(let p=h.length-1;p>=0;p--){let u=l.createElement(h[p]);for(;a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u),f++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,`
59
+ `}}}),r.addType(d,{model:{toHTML(){return""},defaults:{tagName:"button",attributes:{class:d,"data-type-role":d},components:"Dialog (click me to open)",droppable:!1,draggable:!1}},view:{init(){this.listenTo(this.em,"run:core:preview",()=>{this.el.style.display="none"}),this.listenTo(this.em,"stop:core:preview",()=>{this.el.style.display=""})}}}),vn({editor:n,licenseKey:i,pluginName:Kl,cleanup:()=>{t.remove(s),r.removeType(s)}})},_l=Mn(jl);function As(n,e,t){let r,i,s,o,l;const a=e;function c(){const f=Date.now()-o;f<a&&f>=0?r=setTimeout(c,a-f):(r=null,l=n.apply(s,i),s=i=null)}const h=function(){return s=this,i=arguments,o=Date.now(),r||(r=setTimeout(c,a)),l};return h.clear=function(){r&&(clearTimeout(r),r=null)},h.flush=function(){r&&(l=n.apply(s,i),s=i=null,clearTimeout(r),r=null)},h}var Pt=(n=>(n.toastAdd="studio:toastAdd",n.dialogOpen="studio:dialogOpen",n.dialogClose="studio:dialogClose",n.sidebarLeftSet="studio:sidebarLeft:set",n.sidebarLeftGet="studio:sidebarLeft:get",n.sidebarLeftToggle="studio:sidebarLeft:toggle",n.sidebarRightSet="studio:sidebarRight:set",n.sidebarRightGet="studio:sidebarRight:get",n.sidebarRightToggle="studio:sidebarRight:toggle",n.sidebarTopSet="studio:sidebarTop:set",n.sidebarTopGet="studio:sidebarTop:get",n.sidebarTopToggle="studio:sidebarTop:toggle",n.sidebarBottomSet="studio:sidebarBottom:set",n.sidebarBottomGet="studio:sidebarBottom:get",n.sidebarBottomToggle="studio:sidebarBottom:toggle",n.symbolAdd="studio:symbolAdd",n.symbolDetach="studio:symbolDetach",n.symbolOverride="studio:symbolOverride",n.symbolPropagateStyles="studio:propagateStyles",n.getPagesConfig="studio:getPagesConfig",n.setPagesConfig="studio:setPagesConfig",n.getPageSettings="studio:getPageSettings",n.setPageSettings="studio:setPageSettings",n.projectFiles="studio:projectFiles",n.canvasReload="studio:canvasReload",n.getBlocksPanel="studio:getBlocksPanel",n.setBlocksPanel="studio:setBlocksPanel",n.contextMenuComponent="studio:contextMenuComponent",n.layoutAdd="studio:layoutAdd",n.layoutRemove="studio:layoutRemove",n.layoutToggle="studio:layoutToggle",n))(Pt||{}),x=(n=>(n.table="table",n.tableSettings="tableSettings",n.tableDelete="tableDelete",n.tableHead="tableHead",n.tableFoot="tableFoot",n.tableCellItems="tableCellItems",n.tableCellProperties="tableCellProperties",n.tableCellMerge="tableCellMerge",n.tableCellSplit="tableCellSplit",n.tableRowItems="tableRowItems",n.tableRowInsertBefore="tableRowInsertBefore",n.tableRowInsertAfter="tableRowInsertAfter",n.tableRowDelete="tableRowDelete",n.tableRowProperties="tableRowProperties",n.tableRowCut="tableRowCut",n.tableRowCopy="tableRowCopy",n.tableRowPasteBefore="tableRowPasteBefore",n.tableRowPasteAfter="tableRowPasteAfter",n.tableColumn="tableColumn",n.tableColumnItems="tableColumnItems",n.tableColumnInsertBefore="tableColumnInsertBefore",n.tableColumnInsertAfter="tableColumnInsertAfter",n.tableColumnDelete="tableColumnDelete",n.tableColumnCut="tableColumnCut",n.tableColumnCopy="tableColumnCopy",n.tableColumnPasteBefore="tableColumnPasteBefore",n.tableColumnPasteAfter="tableColumnPasteAfter",n))(x||{});const A={table:'<svg viewBox="0 0 24 24"><path d="M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2m0 4v4h6V8H5m8 0v4h6V8h-6m-8 6v4h6v-4H5m8 0v4h6v-4h-6Z"/></svg>',tableSettings:'<svg viewBox="0 0 24 24"><path d="M5 4h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2m0 4v4h6V8H5m8 0v4h6V8h-6m-8 6v4h6v-4H5m8 0v4h6v-4h-6Z"/></svg>',tableDelete:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zM5 6v12h14V6H5z"/><path d="m14.4 8.6 1 1-2.3 2.4 2.3 2.4-1 1-2.4-2.3-2.4 2.3-1-1 2.3-2.4-2.3-2.4 1-1 2.4 2.3z"/></svg>',tableHead:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14Zm-8 11H5v3h6v-3Zm8 0h-6v3h6v-3Zm0-5h-6v3h6v-3ZM5 13h6v-3H5v3Z"/></svg>',tableFoot:'<svg viewBox="0 0 24 24" data-test="1" style="transform: rotate(180deg);"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14Zm-8 11H5v3h6v-3Zm8 0h-6v3h6v-3Zm0-5h-6v3h6v-3ZM5 13h6v-3H5v3Z"/></svg>',tableColumn:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14Zm0 9h-4v5h4v-5Zm-6 0H9v5h4v-5Zm0-7H9v5h4V6Zm6 0h-4v5h4V6Z"/></svg>',tableCellItems:"",tableCellProperties:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6l2-2h14zm-8 9H5v5h6v-5zm8 0h-6v5h6v-5zm-8-7H5v5h6V6z"/></svg>',tableCellMerge:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6l2-2h14zM5 16v2h3v-2H5zm14-5h-9v7h9v-7zm0-5h-4v3h4V6zM8 6H5v3h3V6zm5 0h-3v3h3V6zm-8 8h3v-3H5v3z"/></svg>',tableCellSplit:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zM8 15.5H5V18h3v-2.5zm11-5h-9V18h9v-7.5zm-2.5 1 1 1-2 2 2 2-1 1-2-2-2 2-1-1 2-2-2-2 1-1 2 2 2-2zm-8.5-1H5v3h3v-3zM19 6h-4v2.5h4V6zM8 6H5v2.5h3V6zm5 0h-3v2.5h3V6z"/></svg>',tableRowItems:"",tableRowInsertBefore:'<svg viewBox="0 0 24 24"><path d="M6 4a1 1 0 1 1 0 2H5v6h14V6h-1a1 1 0 0 1 0-2h2c.6 0 1 .4 1 1v13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5c0-.6.4-1 1-1h2zm5 10H5v4h6v-4zm8 0h-6v4h6v-4zM12 3c.5 0 1 .4 1 .9V6h2a1 1 0 0 1 0 2h-2v2a1 1 0 0 1-2 .1V8H9a1 1 0 0 1 0-2h2V4c0-.6.4-1 1-1z"/></svg>',tableRowInsertAfter:'<svg viewBox="0 0 24 24"><path d="M12 13c.5 0 1 .4 1 .9V16h2a1 1 0 0 1 .1 2H13v2a1 1 0 0 1-2 .1V18H9a1 1 0 0 1-.1-2H11v-2c0-.6.4-1 1-1zm6 7a1 1 0 0 1 0-2h1v-6H5v6h1a1 1 0 0 1 0 2H4a1 1 0 0 1-1-1V6c0-1.1.9-2 2-2h14a2 2 0 0 1 2 2v13c0 .5-.4 1-.9 1H18zM11 6H5v4h6V6zm8 0h-6v4h6V6z"/></svg>',tableRowDelete:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm0 2H5v3h2.5v2H5v2h2.5v2H5v3h14v-3h-2.5v-2H19v-2h-2.5V9H19V6zm-4.7 1.8 1.2 1L13 12l2.6 3.3-1.2 1-2.3-3-2.3 3-1.2-1L11 12 8.5 8.7l1.2-1 2.3 3 2.3-3z"/></svg>',tableRowProperties:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zM5 15v3h6v-3H5zm14 0h-6v3h6v-3zm0-9h-6v3h6V6zM5 9h6V6H5v3z"/></svg>',tableRowCut:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M22 3v5H9l3 3 2-2h4l-4 4 1 1h.5c.4 0 .8 0 1.2.3.5.2.9.4 1.2.8.7.6 1 1.3 1 2.2.2.8 0 1.5-.6 2l-.8.5-1 .2c-.4 0-.8 0-1.2-.3a3.9 3.9 0 0 1-2.1-2.2c-.2-.5-.3-1-.2-1.5l-1-1-1 1c0 .5 0 1-.2 1.5-.1.5-.4 1-.9 1.4-.3.4-.7.6-1.2.8l-1.2.3c-.4 0-.7 0-1-.2-.3 0-.6-.3-.8-.5-.5-.5-.8-1.2-.7-2a3 3 0 0 1 1-2.2A3.7 3.7 0 0 1 8.6 14H9l1-1-4-4-.5-1a3.3 3.3 0 0 1 0-2c0-.4.3-.7.5-1l2 2V3h14zM8.5 15.3h-.3a2.6 2.6 0 0 0-.8.4 2.5 2.5 0 0 0-.9 1.1l-.1.4v.7l.2.5.5.2h.7a2.5 2.5 0 0 0 .8-.3L9 18l.4-.4.2-.4.1-.4v-.7a1 1 0 0 0-.2-.5 1 1 0 0 0-.4-.2h-.5zm7 0H15a1 1 0 0 0-.4.3 1 1 0 0 0-.2.5 1.5 1.5 0 0 0 0 .7v.4a2.8 2.8 0 0 0 .5.7h.1a2.8 2.8 0 0 0 .8.6l.4.1h.7l.5-.2.2-.5v-.7a2.6 2.6 0 0 0-.3-.8 2.4 2.4 0 0 0-.7-.7 2.5 2.5 0 0 0-.8-.3h-.3zM12 11.6c-.4 0-.7.1-1 .4-.3.3-.4.6-.4 1s.1.7.4 1c.3.3.6.4 1 .4s.7-.1 1-.4c.3-.3.4-.6.4-1s-.1-.7-.4-1c-.3-.3-.6-.4-1-.4zm8.5-7.1h-11v2h11v-2z"/></svg>',tableRowCopy:'<svg viewBox="0 0 24 24"><path d="M22 11v7H6v-7h16zm-2 2H8v3h12v-3zm-1-6v2H4v5H2V7h17z"/></svg>',tableRowPasteBefore:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V7h-2V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h12v-4h2v4c0 1-.8 2-1.9 2H6c-1 0-2-.8-2-1.9V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm10 7v5H8V8h14zm-1.5 1.5h-11v2h11v-2zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',tableRowPasteAfter:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V11h-2V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h14c0 1-.8 2-1.9 2H6c-1 0-2-.8-2-1.9V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm10 11v5H8v-5h14zm-1.5 1.5h-11v2h11v-2zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',tableColumnItems:"",tableColumnInsertBefore:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a1 1 0 0 1-1-1v-2a1 1 0 0 1 2 0v1h8V6H5v1a1 1 0 1 1-2 0V5c0-.6.4-1 1-1h15zm0 9h-4v5h4v-5zM8 8c.5 0 1 .4 1 .9V11h2a1 1 0 0 1 .1 2H9v2a1 1 0 0 1-2 .1V13H5a1 1 0 0 1-.1-2H7V9c0-.6.4-1 1-1zm11-2h-4v5h4V6z"/></svg>',tableColumnInsertAfter:'<svg viewBox="0 0 24 24"><path d="M20 4c.6 0 1 .4 1 1v2a1 1 0 0 1-2 0V6h-8v12h8v-1a1 1 0 0 1 2 0v2c0 .5-.4 1-.9 1H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h15zM9 13H5v5h4v-5zm7-5c.5 0 1 .4 1 .9V11h2a1 1 0 0 1 .1 2H17v2a1 1 0 0 1-2 .1V13h-2a1 1 0 0 1-.1-2H15V9c0-.6.4-1 1-1zM9 6H5v5h4V6z"/></svg>',tableColumnDelete:'<svg viewBox="0 0 24 24"><path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm-4 4h-2V6h-2v2H9V6H5v12h4v-2h2v2h2v-2h2v2h4V6h-4v2zm.3.5 1 1.2-3 2.3 3 2.3-1 1.2L12 13l-3.3 2.6-1-1.2 3-2.3-3-2.3 1-1.2L12 11l3.3-2.5z"/></svg>',tableColumnCut:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M7.2 4.5a3 3 0 0 1 2.2 1A3.7 3.7 0 0 1 10.5 8v.5l1 1 4-4 1-.5a3.3 3.3 0 0 1 2 0c.4 0 .7.3 1 .5L17 8h4v13h-6V10l-1.5 1.5.5.5v4l-2.5-2.5-1 1v.5c0 .4 0 .8-.3 1.2-.2.5-.4.9-.8 1.2-.6.7-1.3 1-2.2 1-.8.2-1.5 0-2-.6l-.5-.8-.2-1c0-.4 0-.8.3-1.2A3.9 3.9 0 0 1 7 12.7c.5-.2 1-.3 1.5-.2l1-1-1-1c-.5 0-1 0-1.5-.2-.5-.1-1-.4-1.4-.9-.4-.3-.6-.7-.8-1.2L4.5 7c0-.4 0-.7.2-1 0-.3.3-.6.5-.8.5-.5 1.2-.8 2-.7zm12.3 5h-3v10h3v-10zM8 13.8h-.3l-.4.2a2.8 2.8 0 0 0-.7.4v.1a2.8 2.8 0 0 0-.6.8l-.1.4v.7l.2.5.5.2h.7a2.6 2.6 0 0 0 .8-.3 2.4 2.4 0 0 0 .7-.7 2.5 2.5 0 0 0 .3-.8 1.5 1.5 0 0 0 0-.8 1 1 0 0 0-.2-.4 1 1 0 0 0-.5-.2H8zm3.5-3.7c-.4 0-.7.1-1 .4-.3.3-.4.6-.4 1s.1.7.4 1c.3.3.6.4 1 .4s.7-.1 1-.4c.3-.3.4-.6.4-1s-.1-.7-.4-1c-.3-.3-.6-.4-1-.4zM7 5.8h-.4a1 1 0 0 0-.5.3 1 1 0 0 0-.2.5v.7a2.5 2.5 0 0 0 .3.8l.2.3h.1l.4.4.4.2.4.1h.7L9 9l.2-.4a1.6 1.6 0 0 0 0-.8 2.6 2.6 0 0 0-.3-.8 2.5 2.5 0 0 0-1.2-1l-.4-.1H7z"/></svg>',tableColumnCopy:'<svg viewBox="0 0 24 24"><path d="M17 6v16h-7V6h7zm-2 2h-3v12h3V8zm-2-6v2H8v15H6V2h7z"/></svg>',tableColumnPasteBefore:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V18c0 1-.8 2-1.9 2H11v-2h7V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v2H4V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm-2 7v12H4V8h6zM8.5 9.5h-3v9h3v-9zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',tableColumnPasteAfter:'<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a3 3 0 0 1 2.8 2H18c1 0 2 .8 2 1.9V7h-2V5h-2v1c0 .6-.4 1-1 1H9a1 1 0 0 1-1-1V5H6v13h7v2H6c-1 0-2-.8-2-1.9V5c0-1 .8-2 1.9-2h3.3A3 3 0 0 1 12 1zm8 7v12h-6V8h6zm-1.5 1.5h-3v9h3v-9zM12 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>'},de="table",Ts="thead",Ds="tfoot",ir="tbody",Y="row",I="cell",Tr="clipboardTable",Ul=[de,Ts,Ds,ir,Y,I],On=n=>n.em.get(Tr)||[],Gl=n=>n.every(e=>e.is(I)),Dr=(n,e)=>{const{editor:t,event:r,opts:i}=n,s=r.currentTarget||r.target,{x:o,y:l,width:a,height:c}=s.getBoundingClientRect(),h={style:{width:240,height:300},placer:{type:"popover",closeOnClickAway:!0,x:o,y:l,w:a,h:c},layout:{type:"tabs",value:"props",tabs:[{id:"styles",label:"Styles",children:{type:"panelStyles"}},{id:"props",label:"Properties",children:{type:"panelProperties",style:{padding:"14px 7px"}}}]},...e};Ns(i.openSettings)?i.openSettings({...n,layoutProps:h}):t.runCommand(Pt.layoutToggle,h)},Zl=(n,{rows:e=1,cells:t=5,text:r}={})=>({type:n,components:Array.from(Array(e).keys()).map(i=>({type:Y,components:Array.from(Array(t).keys()).map(s=>({type:I,components:r?{type:"text",content:Ns(r)?r({y:i,x:s}):r}:void 0}))}))}),Es="Table settings",Rs=n=>{const{component:e}=n;return e.is(de)?e:e.closestType(de)},Xl=n=>{var e;(e=Rs(n))==null||e.remove(n.opts)},Yl=n=>{const e=Rs(n);e&&(n.editor.select(e),Dr(n,{id:"tableSettings",header:{label:Es}}))},Is=n=>[{id:x.table,icon:A[x.table],label:"Table",items:[{id:x.tableSettings,label:Es,icon:A[x.tableSettings],onClick:({event:t})=>Yl({...n,event:t})},{id:x.tableDelete,label:"Delete table",icon:A[x.tableDelete],onClick:()=>Xl(n)}]}],zs=({editor:n})=>{const e=On(n);return e.length&&Gl(e)},Qr=({component:n,editor:e,after:t})=>{if(!n.is(I))return;const r=n.closestType(de),i=n.closestType(Y),s=n.index()+(t?1:0);r==null||r.findType(Y).forEach(l=>l.append({type:I},{at:s}));const o=i==null?void 0:i.components().at(s);o&&e.select(o)},Ps=({component:n,opts:e})=>{if(!n.is(I))return;const t=n.closestType(de),r=n.index();t==null||t.findType(Y).forEach(i=>{var s;return(s=i.components().at(r))==null?void 0:s.remove(e)})},Vs=({component:n,editor:e})=>{if(!n.is(I))return;const t=n.closestType(de),r=n.index(),i=(t==null?void 0:t.findType(Y).map(s=>s.components().at(r)))||[];i.length&&e.em.set(Tr,i)},ei=n=>{const{component:e,editor:t,after:r}=n;if(!e.is(I)||!zs(n))return;const i=On(t),s=e.closestType(de),o=e.index()+(r?1:0);s==null||s.findType(Y).forEach((l,a)=>{const c=i[a],h=(c==null?void 0:c.clone())||{type:I};l.append(h,{at:o})})},Ql=n=>{const{component:e}=n;e.is(I)&&(Vs(n),Ps({...n,opts:{temporary:!0}}))},ea=n=>{const e=zs(n);return[{id:x.tableColumnItems,icon:A[x.tableColumn],label:"Column",items:[{id:x.tableColumnInsertBefore,label:"Insert column before",icon:A[x.tableColumnInsertBefore],onClick:()=>Qr(n)},{id:x.tableColumnInsertAfter,label:"Insert column after",icon:A[x.tableColumnInsertAfter],onClick:()=>Qr({...n,after:!0})},{id:x.tableColumnDelete,label:"Delete column",icon:A[x.tableColumnDelete],onClick:()=>Ps(n)},{id:x.tableColumnCut,label:"Cut column",icon:A[x.tableColumnCut],onClick:()=>Ql(n)},{id:x.tableColumnCopy,label:"Copy column",icon:A[x.tableColumnCopy],onClick:()=>Vs(n)},{id:x.tableColumnPasteBefore,label:"Paste column before",icon:A[x.tableColumnPasteBefore],disabled:!e,onClick:()=>ei(n)},{id:x.tableColumnPasteAfter,label:"Paste column after",icon:A[x.tableColumnPasteAfter],disabled:!e,onClick:()=>ei({...n,after:!0})}]}]},Bs="Row settings",ta=n=>n.every(e=>e.is(Y)),kt=n=>{const{component:e}=n,t=e.is(I),r=e.is(Y);if(!(!t&&!r))return r?e:e.closestType(Y)},ti=n=>{const{component:e,editor:t,after:r}=n,i=kt(n);if(!i)return;const s=i.index()+(r?1:0),o=i.components().length,l=Array.from(Array(o).keys()).map(()=>({type:I})),a=i.parent();if(a){const c=a.append({type:Y,components:l},{at:s})[0];if(e.is(I)&&c){const h=e.index(),f=c.components().at(h);f&&t.select(f)}}},Hs=n=>{var e;(e=kt(n))==null||e.remove(n.opts)},Ls=n=>{const e=kt(n);e&&n.editor.em.set(Tr,[e])},ni=n=>{var l;const{editor:e,after:t}=n,r=kt(n);if(!r||!Fs(n))return;const s=On(e)[0],o=r.index()+(t?1:0);s&&((l=r.parent())==null||l.append(s.clone(),{at:o}))},na=n=>{kt(n)&&(Ls(n),Hs({...n,opts:{temporary:!0}}))},Fs=({editor:n})=>{const e=On(n);return e.length&&ta(e)},ra=n=>{const e=kt(n);e&&(n.editor.select(e),Dr(n,{id:"tableRowSettings",header:{label:Bs}}))},Ws=n=>{const e=Fs(n);return[{id:x.tableRowItems,icon:A[x.tableRowProperties],label:"Row",items:[{id:x.tableRowInsertBefore,label:"Insert row before",icon:A[x.tableRowInsertBefore],onClick:()=>ti(n)},{id:x.tableRowInsertAfter,label:"Insert row after",icon:A[x.tableRowInsertAfter],onClick:()=>ti({...n,after:!0})},{id:x.tableRowDelete,label:"Delete row",icon:A[x.tableRowDelete],onClick:()=>Hs(n)},{id:x.tableRowProperties,label:Bs,icon:A[x.tableRowProperties],onClick:({event:r})=>ra({...n,event:r})},{id:x.tableRowCut,label:"Cut row",icon:A[x.tableRowCut],onClick:()=>na(n)},{id:x.tableRowCopy,label:"Copy row",icon:A[x.tableRowCopy],onClick:()=>Ls(n)},{id:x.tableRowPasteBefore,label:"Paste row before",icon:A[x.tableRowPasteBefore],disabled:!e,onClick:()=>ni(n)},{id:x.tableRowPasteAfter,label:"Paste row after",icon:A[x.tableRowPasteAfter],disabled:!e,onClick:()=>ni({...n,after:!0})}]},...Is(n)]},Er=n=>{const e=n.attributes.attributes||{},t=parseInt(`${e.rowspan||1}`,10),r=parseInt(`${e.colspan||1}`,10);return{rowspan:t,colspan:r}};function $s(n){const e=[];return n.components().forEach((t,r)=>{t.components().each((i,s)=>{const{rowspan:o,colspan:l}=Er(i);if(e[r])for(;e[r][s];)s++;for(let a=r;a<r+o;a++){e[a]||(e[a]=[]);for(let c=s;c<s+l;c++)e[a][c]={real:a===r&&c===s,cell:i,rowspan:o,colspan:l}}})}),e}function ct(n,e,t){var r;return(r=n[t])==null?void 0:r[e]}const sr=n=>n.closestType(Y);function ia(n,{x:e,y:t,rows:r,cols:i}){var l;let s=sr(n[t][e].cell),o;for(let a=1;a<=r;a++)if(s=(l=s==null?void 0:s.parent())==null?void 0:l.components().at(s.index()+1),s){for(o=e;o>=0;o--){const{cell:c}=n[t+a][o],h=sr(c);if(h===s){for(let f=1;f<=i;f++){const d=c.index();h.append({type:I},{at:d+1})}break}}if(o===-1){const h=s.components().at(0).index();for(let f=1;f<=i;f++)s.append({type:I},{at:h})}}}function Js(n){for(let e=0;e<n.length;e++)for(let t=0;t<n[e].length;t++){const i=n[e][t].cell;if(i.em.selected.hasComponent(i)){const{rowspan:s,colspan:o}=Er(i);if(o>1||s>1){i.addAttributes({colspan:1,rowspan:1});for(let l=0;l<o-1;l++){const a=i.index();sr(i).append({type:I},{at:a+1})}ia(n,{x:t,y:e,rows:s-1,cols:o})}}}}function sa(n){const e=[];n.components().forEach(t=>{t.components().length||e.push(t)}),e.forEach(t=>t.remove())}const Nn=(n,e={})=>{var o;const t=$s(n),{em:r}=n;let i,s;for(let l=0;l<t.length;l++)for(let a=0;a<t[l].length;a++){const c=t[l][a];if((o=e.selected)!=null&&o.includes(c.cell)||r.selected.hasComponent(c.cell)){const h={x:a,y:l};i||(i=h),s=h}}return{grid:t,startPos:i,endPos:s}};function oa(n,e={}){const t=Nn(n),{startPos:r,endPos:i}=t;let{grid:s}=t;const{em:o}=n;if(!r||!i)return;const l=r.x,a=r.y,c=i.x,h=i.y,f=ct(s,l,a),d=ct(s,c,h);if(f&&d){Js(s),s=$s(n);const p=[],u=ct(s,l,a).cell;u.addAttributes({colspan:c-l+1,rowspan:h-a+1});for(let m=a;m<=h;m++)for(let g=l;g<=c;g++){const b=ct(s,g,m);if(!b)continue;const{cell:k}=b;k!==u&&p.push(k)}p.forEach(m=>{e.mergeContent&&u.append(m.components().models),m.remove()}),o.setSelected(u),sa(n)}}const qs="Cell settings",la="Merge cells",aa="Split cell",ca=n=>n.closestType(Y),mt=n=>{var e;return(e=ca(n))==null?void 0:e.parent()},ha=n=>{const e=n.editor.getSelectedAll(),t=mt(e[0]),r=e[0];if(!t||!(r!=null&&r.is(I))||e.length>1)return!1;const{rowspan:i,colspan:s}=Er(r);return!(s<2&&i<2)},fa=n=>{const t=n.editor.getSelectedAll()[0],r=mt(t),{grid:i}=Nn(r);Js(i)},Ks=n=>{const e=n.editor.getSelectedAll(),t=mt(e[0]);if(!t||e.length<2||e.some(l=>!l.is(I)||mt(l)!==t))return!1;const{grid:r,startPos:i,endPos:s}=Nn(t),{em:o}=t;if(!i||!s)return!1;for(let l=i.y;l<=s.y;l++)for(let a=i.x;a<=s.x;a++){const c=ct(r,a,l);if(!c||!o.selected.hasComponent(c.cell))return!1}return!0},da=n=>{const{editor:e}=n;if(!Ks(n))return;const t=e.getSelectedAll(),r=mt(t[0]);oa(r,{mergeContent:!0})},ua=n=>{Dr(n,{id:"tableCellSettings",header:{label:qs}})},pa=n=>[{id:x.tableCellItems,icon:A[x.tableCellProperties],label:"Cell",items:[{id:x.tableCellProperties,label:qs,icon:A[x.tableCellProperties],onClick:({event:t})=>ua({...n,event:t})},{id:x.tableCellMerge,label:la,icon:A[x.tableCellMerge],onClick:()=>da(n),disabled:!Ks(n)},{id:x.tableCellSplit,label:aa,icon:A[x.tableCellSplit],onClick:()=>fa(n),disabled:!ha(n)}]},...ea(n),...Ws(n)],ma=n=>{const e=n[0]&&mt(n[0]);if(!e)return;const{grid:t,startPos:r,endPos:i}=Nn(e,{selected:n});if(!r||!i)return;const s=[];for(let o=r.y;o<=i.y;o++)for(let l=r.x;l<=i.x;l++){const a=ct(t,l,o);a&&s.push(a.cell)}s.length&&e.em.setSelected(s,{fromCell:!0})},ga="tableComponent",ya=function(n,e={}){const t={block:{},...e},{Components:r}=n,i={copyable:!1,emptyState:!0,highlightable:!1,stylable:["color","font-family","font-size","font-weight","line-height","text-align","vertical-align","background-color","border-width","border-style","border-color"]};r.addType(de,{block:t.block&&{label:"Table",media:A.table,category:"Extra",content:{type:de,style:{width:"100%"}},select:!0,...t.block},model:{defaults:{emptyState:!0,highlightable:!1,icon:A.table,stylable:["width","height","margin","font-family","font-size","font-weight","line-height","text-align","background","background-color","border-width","border-style","border-color"],traits:[{type:"number",min:0,name:"cellspacing",label:"Cell spacing"},{type:"number",min:0,name:"cellpadding",label:"Cell padding"},{id:"tableCaption",type:"checkbox",label:"Caption",setValue({component:o,value:l,emitUpdate:a}){const c=o.find("caption")[0];l?!c&&o.append({type:"text",tagName:"caption",components:{type:"textnode",content:"Caption"}}):c==null||c.remove(),a(),n.refresh({tools:!0})},getValue(o){return!!o.component.find("caption")[0]}}],components:Zl(ir,{rows:5}),contextMenu:({items:o,editor:l,component:a})=>[...Is({editor:l,component:a,opts:t}),...o]}}}),r.addType(Ts,{model:{defaults:{icon:A.tableHead,...i}}}),r.addType(Ds,{model:{defaults:{icon:A.tableFoot,...i}}}),r.addType(ir,{model:{defaults:{icon:A.tableRowProperties,...i}}}),r.addType(Y,{model:{defaults:{icon:A.tableRowProperties,emptyState:!0,highlightable:!1,stylable:["height","text-align","border-width","border-style","border-color"],traits:[],contextMenu:({items:o,editor:l,component:a})=>[...Ws({editor:l,component:a,opts:t}),...o]}}}),r.addType(I,{model:{defaults:{icon:A.tableCellProperties,emptyState:{styleOut:"height: 1px"},stylable:["width","height","padding","background-color","text-align","vertical-align","border-width","border-style","border-color"],traits:[{id:"tableCellType",type:"select",options:[{value:"td",name:"Cell"},{value:"th",name:"Header Cell"}],label:"Cell type",name:"tagName",changeProp:!0},{id:"tableCellScope",type:"select",options:[{value:!1,name:"None"},{value:"row",name:"Row"},{value:"col",name:"Column"},{value:"rowgroup",name:"Row group"},{value:"colgroup",name:"Column group"}],label:"Scope",name:"scope"}],contextMenu:({items:o,editor:l,component:a})=>[...pa({editor:l,component:a,opts:t}),...o]}}});const s=As((o,l)=>{var f;const a=n.getSelectedAll(),c=!!((f=l==null?void 0:l.event)!=null&&f.shiftKey);if(a.length<2||!c||l.fromCell)return;const h=a.map(d=>d.is(I)?d:d.closestType(I)).filter(Boolean);h.length===a.length&&ma(h)},0);n.on("component:select",s),vn({editor:n,licenseKey:t.licenseKey,pluginName:ga,cleanup:()=>{n.off("component:select",s),n.Blocks.remove(de),Ul.forEach(o=>r.removeType(o))}})},ba=Mn(ya),ri="page://",We="list-pages",it="list-pages-item",$e="list-pages-link",Ca=n=>n.components().reduce((e,t)=>{var o;const r=t.findFirstType($e),i=(o=r==null?void 0:r.attributes.attributes)==null?void 0:o.href,s=i!=null&&i.startsWith(ri)?i.replace(ri,""):"";if(s&&r){const l=e[s];l?l.push(r):e[s]=[r]}return e},{}),xa="listPagesComponent",nn="data-type-role",wa="page_root",ka=n=>e=>e.is(n),Sa=n=>(e,t)=>t.is(n),Bn=n=>e=>{var t;return((t=e.getAttribute)==null?void 0:t.call(e,nn))===n},Ma=function(n,e={}){const{Blocks:t,Components:r,Pages:i}=n,{licenseKey:s,block:o={}}=e,l="List Pages",a="List Pages Item",c="Link",h=`${Xr}${We}`,f=`${Xr}${$e}`,d='<svg viewBox="0 0 24 24"><path d="M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z"/></svg>',p='<svg viewBox="0 0 24 24"><path d="M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z" /></svg>';r.addType(We,{block:o&&{label:l,media:d,category:"Extra",select:!0,...e.block},isComponent:Bn(We),model:{defaults:{tagName:"ul",name:l,[wa]:"",classes:h,attributes:{[nn]:We},droppable:ka(it),styles:`
60
+ .${h} {
61
+ list-style: none;
62
+ margin: 0;
63
+ padding: 0;
64
+ }
65
+ `},init(){this.syncPageItems=As(this.syncPageItems.bind(this),0),this.listenTo(this.em,i.events.all,this.syncPageItems),this.syncPageItems()},syncPageItems(){if(n.Components.getSymbolInfo(this).isInstance)return;const u=this.em.Pages.getAll(),m=this.components(),g=Ca(this);u.forEach((b,k)=>{const O=b.id,v=b.getName(),E=g[O];E?E==null||E.forEach(T=>{T.getInnerHTML()!==v&&T.components(v)}):m.add({type:it,components:[{type:$e,attributes:{href:`page://${O}`},components:{type:"textnode",content:v}}]},{at:k})})}}}),r.addType(it,{isComponent:Bn(it),model:{defaults:{name:a,tagName:"li",icon:p,attributes:{[nn]:it},components:{type:$e},draggable:Sa(We)}}}),r.addType($e,{extend:"link",isComponent:Bn($e),model:{defaults:{removable:!1,copyable:!1,delegate:{move:u=>u.closestType(it)},name:c,classes:f,attributes:{[nn]:$e},components:{type:"textnode",content:"Item"},styles:`
66
+ .${f} {
67
+ text-decoration: none;
68
+ }
69
+ `}}}),vn({editor:n,licenseKey:s,pluginName:xa,cleanup:()=>{t.remove(We),r.removeType(We)}})},va=Mn(Ma);function H(n){this.content=n}H.prototype={constructor:H,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var r=t&&t!=n?this.remove(t):this,i=r.find(n),s=r.content.slice();return i==-1?s.push(t||n,e):(s[i+1]=e,t&&(s[i]=t)),new H(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new H(t)},addToStart:function(n,e){return new H([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new H(t)},addBefore:function(n,e,t){var r=this.remove(e),i=r.content.slice(),s=r.find(n);return i.splice(s==-1?i.length:s,0,e,t),new H(i)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=H.from(n),n.size?new H(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=H.from(n),n.size?new H(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=H.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};H.from=function(n){if(n instanceof H)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new H(e)};function js(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=js(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function _s(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=0,h=Math.min(o.text.length,l.text.length);for(;c<h&&o.text[o.text.length-c-1]==l.text[l.text.length-c-1];)c++,t--,r--;return{a:t,b:r}}if(o.content.size||l.content.size){let c=_s(o.content,l.content,t-1,r-1);if(c)return c}t-=a,r-=a}}class y{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,i=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&r(a,i+l,s||null,o)!==!1&&a.content.size){let h=l+1;a.nodesBetween(Math.max(0,e-h),Math.min(a.content.size,t-h),r,i+h)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new y(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new y(r,i)}cutByIndex(e,t){return e==t?y.empty:e==0&&t==this.content.length?this:new y(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new y(i,s)}addToStart(e){return new y([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new y(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let i=this.content[t];e(i,r,t),r+=i.nodeSize}}findDiffStart(e,t=0){return js(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return _s(this,e,t,r)}findIndex(e,t=-1){if(e==0)return Zt(0,e);if(e==this.size)return Zt(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Zt(r+1,o):Zt(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return y.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new y(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return y.empty;let t,r=0;for(let i=0;i<e.length;i++){let s=e[i];r+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new y(t||e,r)}static from(e){if(!e)return y.empty;if(e instanceof y)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new y([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}y.empty=new y([],0);const Hn={index:0,offset:0};function Zt(n,e){return Hn.index=n,Hn.offset=e,Hn}function cn(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!cn(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!cn(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}class D{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!r&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&cn(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[t.type];if(!r)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=r.create(t.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(t[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return D.none;if(e instanceof D)return[e];let t=e.slice();return t.sort((r,i)=>r.type.rank-i.type.rank),t}}D.none=[];class hn extends Error{}class C{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Gs(this.content,e+this.openStart,t);return r&&new C(r,this.openStart,this.openEnd)}removeBetween(e,t){return new C(Us(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return C.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new C(y.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new C(e,r,i)}}C.empty=new C(y.empty,0,0);function Us(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Us(s.content,e-i-1,t-i-1)))}function Gs(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return n.cut(0,e).append(t).append(n.cut(e));let l=Gs(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function Oa(n,e,t){if(t.openStart>n.depth)throw new hn("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new hn("Inconsistent open depths");return Zs(n,e,t,0)}function Zs(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r<n.depth-t.openStart){let o=Zs(n,e,t,r+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let o=n.parent,l=o.content;return Ge(o,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Na(t,n);return Ge(s,Ys(n,o,l,e,r))}else return Ge(s,fn(n,e,r))}function Xs(n,e){if(!e.type.compatibleContent(n.type))throw new hn("Cannot join "+e.type.name+" onto "+n.type.name)}function or(n,e,t){let r=n.node(t);return Xs(r,e.node(t)),r}function Ue(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Dt(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Ue(n.nodeAfter,r),s++));for(let l=s;l<o;l++)Ue(i.child(l),r);e&&e.depth==t&&e.textOffset&&Ue(e.nodeBefore,r)}function Ge(n,e){return n.type.checkContent(e),n.copy(e)}function Ys(n,e,t,r,i){let s=n.depth>i&&or(n,e,i+1),o=r.depth>i&&or(t,r,i+1),l=[];return Dt(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(Xs(s,o),Ue(Ge(s,Ys(n,e,t,r,i+1)),l)):(s&&Ue(Ge(s,fn(n,e,i+1)),l),Dt(e,t,i,l),o&&Ue(Ge(o,fn(t,r,i+1)),l)),Dt(r,null,i,l),new y(l)}function fn(n,e,t){let r=[];if(Dt(null,n,t,r),n.depth>t){let i=or(n,e,t+1);Ue(Ge(i,fn(n,e,t+1)),r)}return Dt(e,null,t,r),new y(r)}function Na(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class Vt{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=r.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return D.none;if(this.textOffset)return e.child(t).marks;let r=e.maybeChild(t-1),i=e.maybeChild(t);if(!r){let l=r;r=i,i=l}let s=r.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let r=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new dn(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new Vt(t,r,s)}static resolveCached(e,t){let r=ii.get(e);if(r)for(let s=0;s<r.elts.length;s++){let o=r.elts[s];if(o.pos==t)return o}else ii.set(e,r=new Aa);let i=r.elts[r.i]=Vt.resolve(e,t);return r.i=(r.i+1)%Ta,i}}class Aa{constructor(){this.elts=[],this.i=0}}const Ta=12,ii=new WeakMap;class dn{constructor(e,t,r){this.$from=e,this.$to=t,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const Da=Object.create(null);let Ze=class lr{constructor(e,t,r,i=D.none){this.type=e,this.attrs=t,this.marks=i,this.content=r||y.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,r,i=0){this.content.nodesBetween(e,t,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,r,i){return this.content.textBetween(e,t,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,r){return this.type==e&&cn(this.attrs,t||e.defaultAttrs||Da)&&D.sameSet(this.marks,r||D.none)}copy(e=null){return e==this.content?this:new lr(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new lr(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,r=!1){if(e==t)return C.empty;let i=this.resolve(e),s=this.resolve(t),o=r?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new C(c,i.depth-o,s.depth-o)}replace(e,t,r){return Oa(this.resolve(e),this.resolve(t),r)}nodeAt(e){for(let t=this;;){let{index:r,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(r),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(t),index:t,offset:r};let i=this.content.child(t-1);return{node:i,index:t-1,offset:r-i.nodeSize}}resolve(e){return Vt.resolveCached(this,e)}resolveNoCache(e){return Vt.resolve(this,e)}rangeHasMark(e,t,r){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Qs(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=y.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;a<s;a++)if(!this.type.allowsMarks(r.child(a).marks))return!1;return!0}canReplaceWith(e,t,r,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(r),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=D.none;for(let t=0;t<this.marks.length;t++){let r=this.marks[t];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!D.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=y.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Ze.prototype.text=void 0;class un extends Ze{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Qs(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new un(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new un(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function Qs(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class et{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Ea(e,t);if(r.next==null)return et.empty;let i=eo(r);r.next&&r.err("Unexpected trailing text");let s=Ha(Ba(i));return La(s,r),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,r=e.childCount){let i=this;for(let s=t;i&&s<r;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let r=0;r<e.next.length;r++)if(this.next[t].type==e.next[r].type)return!0;return!1}fillBefore(e,t=!1,r=0){let i=[this];function s(o,l){let a=o.matchFragment(e,r);if(a&&(!t||a.validEnd))return y.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:h,next:f}=o.next[c];if(!(h.isText||h.hasRequiredAttrs())&&i.indexOf(f)==-1){i.push(f);let d=s(f,l.concat(h));if(d)return d}}return null}return s(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let l=i;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!i.type||a.validEnd)&&(r.push({match:l.contentMatch,type:l,via:i}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&t(r.next[i].next)}return t(this),e.map((r,i)=>{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o<r.next.length;o++)s+=(o?", ":"")+r.next[o].type.name+"->"+e.indexOf(r.next[o].next);return s}).join(`
70
+ `)}}et.empty=new et(!0);class Ea{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function eo(n){let e=[];do e.push(Ra(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function Ra(n){let e=[];do e.push(Ia(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Ia(n){let e=Va(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=za(n,e);else break;return e}function si(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function za(n,e){let t=si(n),r=t;return n.eat(",")&&(n.next!="}"?r=si(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Pa(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function Va(n){if(n.eat("(")){let e=eo(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Pa(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Ba(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let h=t();i(s(o.expr,a),h),a=h}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let h=t();r(a,h),i(s(o.expr,a),h),a=h}return[r(a)]}else{if(o.type=="name")return[r(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function to(n,e){return e-n}function oi(n,e){let t=[];return r(e),t.sort(to);function r(i){let s=n[i];if(s.length==1&&!s[0].term)return r(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&r(a)}}}function Ha(n){let e=Object.create(null);return t(oi(n,0));function t(r){let i=[];r.forEach(o=>{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let h=0;h<i.length;h++)i[h][0]==l&&(c=i[h][1]);oi(n,a).forEach(h=>{c||i.push([l,c=[]]),c.indexOf(h)==-1&&c.push(h)})})});let s=e[r.join(",")]=new et(r.indexOf(n.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(to);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function La(n,e){for(let t=0,r=[n];t<r.length;t++){let i=r[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),r.indexOf(c)==-1&&r.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function no(n){let e=Object.create(null);for(let t in n){let r=n[t];if(!r.hasDefault)return null;e[t]=r.default}return e}function ro(n,e){let t=Object.create(null);for(let r in n){let i=e&&e[r];if(i===void 0){let s=n[r];if(s.hasDefault)i=s.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=i}return t}function io(n,e,t,r){for(let i in e)if(!(i in n))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${i}`);for(let i in n){let s=n[i];s.validate&&s.validate(e[i])}}function so(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new Wa(n,r,e[r]);return t}let li=class oo{constructor(e,t,r){this.name=e,this.schema=t,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=so(e,r.attrs),this.defaultAttrs=no(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==et.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ro(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ze(this,this.computeAttrs(e),y.from(t),D.setFrom(r))}createChecked(e=null,t,r){return t=y.from(t),this.checkContent(t),new Ze(this,this.computeAttrs(e),t,D.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=y.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(y.empty,!0);return s?new Ze(this,e,t.append(s),D.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){io(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?t&&t.push(e[r]):t||(t=e.slice(0,r));return t?t.length?t:D.none:e}static compile(e,t){let r=Object.create(null);e.forEach((s,o)=>r[s]=new oo(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Fa(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}class Wa{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Fa(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class An{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=so(e,i.attrs),this.excluded=null;let s=no(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,ro(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new An(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){io(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class $a{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=H.from(e.nodes),t.marks=H.from(e.marks||{}),this.nodes=li.compile(this.spec.nodes,this),this.marks=An.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=et.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?ai(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:ai(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof li){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new un(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Ze.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function ai(n,e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],s=n.marks[i],o=s;if(s)t.push(s);else for(let l in n.marks){let a=n.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function Ja(n){return n.tag!=null}function qa(n){return n.style!=null}class gt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(Ja(i))this.tags.push(i);else if(qa(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let r=new hi(this,t,!1);return r.addAll(e,D.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new hi(this,t,!0);return r.addAll(e,D.none,t.from,t.to),C.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let s=this.tags[i];if(_a(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,r,i){for(let s=i?this.styles.indexOf(i)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!r.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,i)}for(let i in e.marks){let s=e.marks[i].spec.parseDOM;s&&s.forEach(o=>{r(o=fi(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=fi(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new gt(e,gt.schemaRules(e)))}}const lo={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Ka={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ao={ol:!0,ul:!0},pn=1,mn=2,Et=4;function ci(n,e,t){return e!=null?(e?pn:0)|(e==="full"?mn:0):n&&n.whitespace=="pre"?pn|mn:t&~Et}class Xt{constructor(e,t,r,i,s,o){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=D.none,this.match=s||(o&Et?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&pn)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!lo.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class hi{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0;let i=t.topNode,s,o=ci(null,t.preserveWhitespace,0)|(r?Et:0);i?s=new Xt(i.type,i.attrs,D.none,!0,t.topMatch||i.type.contentMatch,o):r?s=new Xt(null,null,D.none,!0,null,o):s=new Xt(e.schema.topNodeType,null,D.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top;if(i.options&mn||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(i.options&pn)i.options&mn?r=r.replace(/\r\n?/g,`
71
+ `):r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],o=e.previousSibling;(!s||o&&o.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=e.nodeName.toLowerCase(),s;ao.hasOwnProperty(i)&&this.parser.normalizeLists&&ja(e);let o=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,r));if(o?o.ignore:Ka.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(e=o.skip);let l,a=this.top,c=this.needsBlock;if(lo.hasOwnProperty(i))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),l=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);return}let h=o&&o.skip?t:this.readStyles(e,t);h&&this.addAll(e,h),l&&this.sync(a),this.needsBlock=c}else{let l=this.readStyles(e,t);l&&this.addElementByRule(e,o,l,o.consuming===!1?s:void 0)}}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
72
+ `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let s=this.parser.matchedStyles[i],o=r.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),r)||this.leafFallback(e,r);else{let a=this.enter(o,t.attrs||null,r,t.preserveWhitespace);a&&(s=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t){let r,i;for(let s=this.open;s>=0;s--){let o=this.nodes[s],l=o.findWrapping(e);if(l&&(!r||r.length>l.length)&&(r=l,i=o,!l.length)||o.solid)break}if(!r)return null;this.sync(i);for(let s=0;s<r.length;s++)t=this.enterInner(r[s],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let i=this.textblockFromContext();i&&(t=this.enterInner(i,null,t))}let r=this.findPlace(e,t);if(r){this.closeExtra();let i=this.top;i.match&&(i.match=i.match.matchType(e.type));let s=D.none;for(let o of r.concat(e.marks))(i.type?i.type.allowsMarkType(o.type):di(o.type,e.type))&&(s=o.addToSet(s));return i.content.push(e.mark(s)),!0}return!1}enter(e,t,r,i){let s=this.findPlace(e.create(t),r);return s&&(s=this.enterInner(e,t,r,!0,i)),s}enterInner(e,t,r,i=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=ci(e,s,o.options);o.options&Et&&o.content.length==0&&(l|=Et);let a=D.none;return r=r.filter(c=>(o.type?o.type.allowsMarkType(c.type):di(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Xt(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(this.isOpen||this.options.topOpen)}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==t&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,r){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&t.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let h=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!h||h.name!=c&&!h.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function ja(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ao.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function _a(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function fi(n){let e={};for(let t in n)e[t]=n[t];return e}function di(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:h}=l.edge(a);if(c==e||s.indexOf(h)<0&&o(h))return!0}};if(o(i.contentMatch))return!0}}class rt{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},r){r||(r=Ln(t).createDocumentFragment());let i=r,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)i=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],h=this.serializeMark(c,o.isInline,t);h&&(s.push([c,i]),i.appendChild(h.dom),i=h.contentDOM||h.dom)}}i.appendChild(this.serializeNodeInner(o,t))}),r}serializeNodeInner(e,t){let{dom:r,contentDOM:i}=rn(Ln(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return r}serializeNode(e,t={}){let r=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&rn(Ln(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return rn(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new rt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ui(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ui(e.marks)}}function ui(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function Ln(n){return n.document||window.document}const pi=new WeakMap;function Ua(n){let e=pi.get(n);return e===void 0&&pi.set(n,e=Ga(n)),e}function Ga(n){let e=null;function t(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i<r.length;i++)t(r[i]);else for(let i in r)t(r[i])}return t(n),e}function rn(n,e,t,r){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let i=e[0],s;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=Ua(r))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=i.indexOf(" ");o>0&&(t=i.slice(0,o),i=i.slice(o+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),c=e[1],h=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){h=2;for(let f in c)if(c[f]!=null){let d=f.indexOf(" ");d>0?a.setAttributeNS(f.slice(0,d),f.slice(d+1),c[f]):a.setAttribute(f,c[f])}}for(let f=h;f<e.length;f++){let d=e[f];if(d===0){if(f<e.length-1||f>h)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:u}=rn(n,d,t,r);if(a.appendChild(p),u){if(l)throw new RangeError("Multiple content holes");l=u}}}return{dom:a,contentDOM:l}}const co=65535,ho=Math.pow(2,16);function Za(n,e){return n+e*ho}function mi(n){return n&co}function Xa(n){return(n-(n&co))/ho}const fo=1,uo=2,sn=4,po=8;class ar{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&po)>0}get deletedBefore(){return(this.delInfo&(fo|sn))>0}get deletedAfter(){return(this.delInfo&(uo|sn))>0}get deletedAcross(){return(this.delInfo&sn)>0}}class Q{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Q.empty)return Q.empty}recover(e){let t=0,r=mi(e);if(!this.inverted)for(let i=0;i<r;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+t+Xa(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],h=this.ranges[l+o],f=a+c;if(e<=f){let d=c?e==a?-1:e==f?1:t:t,p=a+i+(d<0?0:h);if(r)return p;let u=e==(t<0?a:f)?null:Za(l/3,e-a),m=e==a?uo:e==f?fo:sn;return(t<0?e!=a:e!=f)&&(m|=po),new ar(p,m,u)}i+=h-c}return r?e+i:new ar(e+i,0,null)}touches(e,t){let r=0,i=mi(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let c=this.ranges[l+s],h=a+c;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],h=this.ranges[i+r];e(l,l+c,a,a+h),s+=h-c}}invert(){return new Q(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Q.empty:new Q(e<0?[0,-e,0]:[0,0,e])}}Q.empty=new Q([]);class ft{constructor(e=[],t,r=0,i=e.length){this.maps=e,this.mirror=t,this.from=r,this.to=i}slice(e=0,t=this.maps.length){return new ft(this.maps,this.mirror,e,t)}copy(){return new ft(this.maps.slice(),this.mirror&&this.mirror.slice(),this.from,this.to)}appendMap(e,t){this.to=this.maps.push(e),t!=null&&this.setMirror(this.maps.length-1,t)}appendMapping(e){for(let t=0,r=this.maps.length;t<e.maps.length;t++){let i=e.getMirror(t);this.appendMap(e.maps[t],i!=null&&i<t?r+i:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,r=this.maps.length+e.maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new ft;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;r<this.to;r++)e=this.maps[r].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,r){let i=0;for(let s=this.from;s<this.to;s++){let o=this.maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this.maps[a].recover(l.recover);continue}}i|=l.delInfo,e=l.pos}return r?e:new ar(e,i,null)}}const Fn=Object.create(null);class K{getMap(){return Q.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=Fn[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Fn)throw new RangeError("Duplicate use of step JSON ID "+e);return Fn[e]=t,t.prototype.jsonID=e,t}}class P{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new P(e,null)}static fail(e){return new P(null,e)}static fromReplace(e,t,r,i){try{return P.ok(e.replace(t,r,i))}catch(s){if(s instanceof hn)return P.fail(s.message);throw s}}}function Rr(n,e,t){let r=[];for(let i=0;i<n.childCount;i++){let s=n.child(i);s.content.size&&(s=s.copy(Rr(s.content,e,s))),s.isInline&&(s=e(s,t,i)),r.push(s)}return y.fromArray(r)}class Re extends K{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),s=new C(Rr(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return P.fromReplace(e,this.from,this.to,s)}invert(){return new fe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new Re(t.pos,r.pos,this.mark)}merge(e){return e instanceof Re&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Re(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Re(t.from,t.to,e.markFromJSON(t.mark))}}K.jsonID("addMark",Re);class fe extends K{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new C(Rr(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return P.fromReplace(e,this.from,this.to,r)}invert(){return new Re(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new fe(t.pos,r.pos,this.mark)}merge(e){return e instanceof fe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new fe(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new fe(t.from,t.to,e.markFromJSON(t.mark))}}K.jsonID("removeMark",fe);class Ie extends K{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return P.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return P.fromReplace(e,this.pos,this.pos+1,new C(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(r))return new Ie(this.pos,t.marks[i]);return new Ie(this.pos,this.mark)}}return new yt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ie(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Ie(t.pos,e.markFromJSON(t.mark))}}K.jsonID("addNodeMark",Ie);class yt extends K{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return P.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return P.fromReplace(e,this.pos,this.pos+1,new C(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Ie(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new yt(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new yt(t.pos,e.markFromJSON(t.mark))}}K.jsonID("removeNodeMark",yt);class J extends K{constructor(e,t,r,i=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=i}apply(e){return this.structure&&cr(e,this.from,this.to)?P.fail("Structure replace would overwrite content"):P.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Q([this.from,this.to-this.from,this.slice.size])}invert(e){return new J(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deletedAcross&&r.deletedAcross?null:new J(t.pos,Math.max(t.pos,r.pos),this.slice)}merge(e){if(!(e instanceof J)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?C.empty:new C(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new J(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?C.empty:new C(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new J(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new J(t.from,t.to,C.fromJSON(e,t.slice),!!t.structure)}}K.jsonID("replace",J);class W extends K{constructor(e,t,r,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(cr(e,this.from,this.gapFrom)||cr(e,this.gapTo,this.to)))return P.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return P.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?P.fromReplace(e,this.from,this.to,r):P.fail("Content does not fit in gap")}getMap(){return new Q([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new W(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||i<t.pos||s>r.pos?null:new W(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new W(t.from,t.to,t.gapFrom,t.gapTo,C.fromJSON(e,t.slice),t.insert,!!t.structure)}}K.jsonID("replaceAround",W);function cr(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Ya(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,h)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&h.type.allowsMarkType(r.type)){let d=Math.max(c,e),p=Math.min(c+a.nodeSize,t),u=r.addToSet(f);for(let m=0;m<f.length;m++)f[m].isInSet(u)||(o&&o.to==d&&o.mark.eq(f[m])?o.to=p:i.push(o=new fe(d,p,f[m])));l&&l.to==d?l.to=p:s.push(l=new Re(d,p,r))}}),i.forEach(a=>n.step(a)),s.forEach(a=>n.step(a))}function Qa(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof An){let c=o.marks,h;for(;h=r.isInSet(c);)(a||(a=[])).push(h),c=h.removeFromSet(c)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let h=0;h<a.length;h++){let f=a[h],d;for(let p=0;p<i.length;p++){let u=i[p];u.step==s-1&&f.eq(i[p].style)&&(d=u)}d?(d.to=c,d.step=s):i.push({style:f,from:Math.max(l,e),to:c,step:s})}}}),i.forEach(o=>n.step(new fe(o.from,o.to,o.style)))}function Ir(n,e,t,r=t.contentMatch,i=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),h=l+c.nodeSize,f=r.matchType(c.type);if(!f)o.push(new J(l,h,C.empty));else{r=f;for(let d=0;d<c.marks.length;d++)t.allowsMarkType(c.marks[d].type)||n.step(new fe(l,h,c.marks[d]));if(i&&c.isText&&t.whitespace!="pre"){let d,p=/\r?\n|\r/g,u;for(;d=p.exec(c.text);)u||(u=new C(y.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new J(l+d.index,l+d.index+d[0].length,u))}}l=h}if(!r.validEnd){let a=r.fillBefore(y.empty,!0);n.replace(l,l,new C(a,0,0))}for(let a=o.length-1;a>=0;a--)n.step(o[a])}function ec(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Tn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(r<n.depth&&i.canReplace(s,o,t))return r;if(r==0||i.type.spec.isolating||!ec(i,s,o))break}return null}function tc(n,e,t){let{$from:r,$to:i,depth:s}=e,o=r.before(s+1),l=i.after(s+1),a=o,c=l,h=y.empty,f=0;for(let u=s,m=!1;u>t;u--)m||r.index(u)>0?(m=!0,h=y.from(r.node(u).copy(h)),f++):a--;let d=y.empty,p=0;for(let u=s,m=!1;u>t;u--)m||i.after(u+1)<i.end(u)?(m=!0,d=y.from(i.node(u).copy(d)),p++):c++;n.step(new W(a,c,o,l,new C(h.append(d),f,p),h.size-f,!0))}function mo(n,e,t=null,r=n){let i=nc(n,e),s=i&&rc(r,e);return s?i.map(gi).concat({type:e,attrs:t}).concat(s.map(gi)):null}function gi(n){return{type:n,attrs:null}}function nc(n,e){let{parent:t,startIndex:r,endIndex:i}=n,s=t.contentMatchAt(r).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(r,i,o)?s:null}function rc(n,e){let{parent:t,startIndex:r,endIndex:i}=n,s=t.child(r),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let c=r;a&&c<i;c++)a=a.matchType(t.child(c).type);return!a||!a.validEnd?null:o}function ic(n,e,t){let r=y.empty;for(let o=t.length-1;o>=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=y.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new W(i,s,i,s,new C(r,0,0),t.length,!0))}function sc(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,a)&&oc(n.doc,n.mapping.slice(s).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",u=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!u?c=!1:!p&&u&&(c=!0)}c===!1&&yo(n,o,l,s),Ir(n,n.mapping.slice(s).map(l,1),r,void 0,c===null);let h=n.mapping.slice(s),f=h.map(l,1),d=h.map(l+o.nodeSize,1);return n.step(new W(f,d,f+1,d-1,new C(y.from(r.create(a,null,o.marks)),0,0),1,!0)),c===!0&&go(n,o,l,s),!1}})}function go(n,e,t,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function yo(n,e,t,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=n.mapping.slice(r).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
73
+ `))}})}function oc(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function lc(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new W(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new C(y.from(o),0,0),1,!0))}function dt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,h=t-2;c>s;c--,h--){let f=i.node(c),d=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(d,f.childCount),u=r&&r[h+1];u&&(p=p.replaceChild(0,u.type.create(u.attrs)));let m=r&&r[h]||f;if(!f.canReplace(d+1,f.childCount)||!m.type.validContent(p))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function ac(n,e,t=1,r){let i=n.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){s=y.from(i.node(l).copy(s));let h=r&&r[c];o=y.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new J(e,e,new C(s.append(o),t,t),!0))}function Dn(n,e){let t=n.resolve(e),r=t.index();return hc(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function cc(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i<e.childCount;i++){let s=e.child(i),o=s.type==r?n.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!n.type.allowsMarks(s.marks))return!1}return t.validEnd}function hc(n,e){return!!(n&&e&&!n.isLeaf&&cc(n,e))}function fc(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(i&&o.inlineContent){let h=o.whitespace=="pre",f=!!o.contentMatch.matchType(i);h&&!f?r=!1:!h&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let h=n.doc.resolve(e+t);yo(n,h.node(),h.before(),l)}o.inlineContent&&Ir(n,e+t-1,o,s.node().contentMatchAt(s.index()),r==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new J(c,a.map(e+t,-1),C.empty,!0)),r===!0){let h=n.doc.resolve(c);go(n,h.node(),h.before(),n.steps.length)}return n}function dc(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s<r.node(i).childCount)return null}return null}function uc(n,e,t){let r=n.resolve(e);if(!t.content.size)return e;let i=t.content;for(let s=0;s<t.openStart;s++)i=i.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=r.depth;o>=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),c=r.node(o),h=!1;if(s==1)h=c.canReplace(a,a,i);else{let f=c.contentMatchAt(a).findWrapping(i.firstChild.type);h=f&&c.canReplaceWith(a,a,f[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function zr(n,e,t=e,r=C.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return bo(i,s,r)?new J(e,t,r):new pc(i,s,r).fit()}function bo(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class pc{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new C(s,o,l);return e>-1?new W(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new J(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r<e;r++){let s=t.firstChild;if(t.childCount>1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Wn(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],h,f=null;if(t==1&&(o?c.matchType(o.type)||(f=c.fillBefore(y.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:f};if(t==2&&o&&(h=c.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Wn(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new C(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Wn(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new C(Nt(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new C(Nt(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=r?r.content:o.content,a=o.openStart-e,c=0,h=[],{match:f,type:d}=this.frontier[t];if(i){for(let m=0;m<i.childCount;m++)h.push(i.child(m));f=f.matchFragment(i)}let p=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=f.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(f=g,h.push(Co(m.mark(d.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?p:-1)))}let u=c==l.childCount;u||(p=-1),this.placed=At(this.placed,t,y.from(h)),this.frontier[t].match=f,u&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<p;m++){let b=g.lastChild;this.frontier.push({type:b.type,match:b.contentMatchAt(b.childCount)}),g=b.content}this.unplaced=u?e==0?C.empty:new C(Nt(o.content,e-1,1),e-1,p<0?o.openEnd:e-1):new C(Nt(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!$n(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:r}=this.$to,i=this.$to.after(r);for(;r>1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=$n(e,t,i,r,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],h=$n(e,l,c,a,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=At(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=At(this.placed,this.depth,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=At(this.placed,this.frontier.length,t))}}function Nt(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Nt(n.firstChild.content,e-1,t)))}function At(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(At(n.lastChild.content,e-1,t)))}function Wn(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function Co(n,e,t){if(e<=0)return n;let r=n.content;return e>1&&(r=r.replaceChild(0,Co(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),n.copy(r)}function $n(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!mc(t,s.content,o)?l:null}function mc(n,e,t){for(let r=t;r<e.childCount;r++)if(!n.allowsMarks(e.child(r).marks))return!0;return!1}function gc(n){return n.spec.defining||n.spec.definingForContent}function yc(n,e,t,r){if(!r.size)return n.deleteRange(e,t);let i=n.doc.resolve(e),s=n.doc.resolve(t);if(bo(i,s,r))return n.step(new J(e,t,r));let o=wo(i,n.doc.resolve(t));o[o.length-1]==0&&o.pop();let l=-(i.depth+1);o.unshift(l);for(let d=i.depth,p=i.pos-1;d>0;d--,p--){let u=i.node(d).type.spec;if(u.defining||u.definingAsContext||u.isolating)break;o.indexOf(d)>-1?l=d:i.before(d)==p&&o.splice(1,0,-d)}let a=o.indexOf(l),c=[],h=r.openStart;for(let d=r.content,p=0;;p++){let u=d.firstChild;if(c.push(u),p==r.openStart)break;d=u.content}for(let d=h-1;d>=0;d--){let p=c[d],u=gc(p.type);if(u&&!p.sameMarkup(i.node(Math.abs(l)-1)))h=d;else if(u||!p.type.isTextblock)break}for(let d=r.openStart;d>=0;d--){let p=(d+h+1)%(r.openStart+1),u=c[p];if(u)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],b=!0;g<0&&(b=!1,g=-g);let k=i.node(g-1),O=i.index(g-1);if(k.canReplaceWith(O,O,u.type,u.marks))return n.replace(i.before(g),b?s.after(g):t,new C(xo(r.content,0,r.openStart,p),p,r.openEnd))}}let f=n.steps.length;for(let d=o.length-1;d>=0&&(n.replace(e,t,r),!(n.steps.length>f));d--){let p=o[d];p<0||(e=i.before(p),t=s.after(p))}}function xo(n,e,t,r,i){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(xo(s.content,e+1,t,r,s)))}if(e>r){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(y.empty,!0))}return n}function bc(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=dc(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new C(y.from(r),0,0))}function Cc(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=wo(r,i);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||r.node(l).type.contentMatch.validEnd)return n.delete(r.start(l),i.end(l));if(l>0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return n.delete(r.before(o),t);n.delete(e,t)}function wo(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(s<n.pos-(n.depth-i)||e.end(i)>e.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}class ut extends K{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return P.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return P.fromReplace(e,this.pos,this.pos+1,new C(y.from(i),0,t.isLeaf?0:1))}getMap(){return Q.empty}invert(e){return new ut(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new ut(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new ut(t.pos,t.attr,t.value)}}K.jsonID("attr",ut);class Bt extends K{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return P.ok(r)}getMap(){return Q.empty}invert(e){return new Bt(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Bt(t.attr,t.value)}}K.jsonID("docAttr",Bt);let bt=class extends Error{};bt=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};bt.prototype=Object.create(Error.prototype);bt.prototype.constructor=bt;bt.prototype.name="TransformError";class ko{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ft}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new bt(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=C.empty){let i=zr(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new C(y.from(r),0,0))}delete(e,t){return this.replace(e,t,C.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return yc(this,e,t,r),this}replaceRangeWith(e,t,r){return bc(this,e,t,r),this}deleteRange(e,t){return Cc(this,e,t),this}lift(e,t){return tc(this,e,t),this}join(e,t=1){return fc(this,e,t),this}wrap(e,t){return ic(this,e,t),this}setBlockType(e,t=e,r,i=null){return sc(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return lc(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new ut(e,t,r)),this}setDocAttribute(e,t){return this.step(new Bt(e,t)),this}addNodeMark(e,t){return this.step(new Ie(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new yt(e,t)),this}split(e,t=1,r){return ac(this,e,t,r),this}addMark(e,t,r){return Ya(this,e,t,r),this}removeMark(e,t,r){return Qa(this,e,t,r),this}clearIncompatible(e,t,r){return Ir(this,e,t,r),this}}const Jn=Object.create(null);class S{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new So(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=C.empty){let r=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=r,r=r.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],h=e.mapping.slice(s);e.replaceRange(h.map(a.pos),h.map(c.pos),l?C.empty:t),l==0&&Ci(e,s,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(r),c=a.map(o.pos),h=a.map(l.pos);s?e.deleteRange(c,h):(e.replaceRangeWith(c,h,t),Ci(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let i=e.parent.inlineContent?new M(e):lt(e.node(0),e.parent,e.pos,e.index(),t,r);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?lt(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):lt(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new te(e.node(0))}static atStart(e){return lt(e,e,0,0,1)||new te(e)}static atEnd(e){return lt(e,e,e.content.size,e.childCount,-1)||new te(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Jn[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Jn)throw new RangeError("Duplicate use of selection JSON ID "+e);return Jn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return M.between(this.$anchor,this.$head).getBookmark()}}S.prototype.visible=!0;class So{constructor(e,t){this.$from=e,this.$to=t}}let yi=!1;function bi(n){!yi&&!n.parent.inlineContent&&(yi=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class M extends S{constructor(e,t=e){bi(e),bi(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new M(i.parent.inlineContent?i:r,r)}replace(e,t=C.empty){if(super.replace(e,t),t==C.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof M&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new En(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new M(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new M(e,t)}}S.jsonID("text",M);class En{constructor(e,t){this.anchor=e,this.head=t}map(e){return new En(e.map(this.anchor),e.map(this.head))}resolve(e){return M.between(e.resolve(this.anchor),e.resolve(this.head))}}class w extends S{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return r?S.near(s):new w(s)}content(){return new C(y.from(this.node),0,0)}eq(e){return e instanceof w&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Pr(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new w(e.resolve(t.anchor))}static create(e,t){return new w(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}w.prototype.visible=!1;S.jsonID("node",w);class Pr{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new En(r,r):new Pr(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&w.isSelectable(r)?new w(t):S.near(t)}}class te extends S{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=C.empty){if(t==C.empty){e.delete(0,e.doc.content.size);let r=S.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new te(e)}map(e){return new te(e)}eq(e){return e instanceof te}getBookmark(){return xc}}S.jsonID("all",te);const xc={map(){return this},resolve(n){return new te(n)}};function lt(n,e,t,r,i,s=!1){if(e.inlineContent)return M.create(n,t);for(let o=r-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&w.isSelectable(l))return w.create(n,t-(i<0?l.nodeSize:0))}else{let a=lt(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function Ci(n,e,t){let r=n.steps.length-1;if(r<e)return;let i=n.steps[r];if(!(i instanceof J||i instanceof W))return;let s=n.mapping.maps[r],o;s.forEach((l,a,c,h)=>{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}const xi=1,Yt=2,wi=4;class wc extends ko{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|xi)&~Yt,this.storedMarks=null,this}get selectionSet(){return(this.updated&xi)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Yt,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Yt)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Yt,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=wi,this}get scrolledIntoView(){return(this.updated&wi)>0}}function ki(n,e){return!e||!n?n:n.bind(e)}class Tt{constructor(e,t,r){this.name=e,this.init=ki(t.init,r),this.apply=ki(t.apply,r)}}const kc=[new Tt("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Tt("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new Tt("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Tt("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class qn{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=kc.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Tt(r.key,r.spec.state,r))})}}class ht{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=t){let i=this.config.plugins[r];if(i.spec.filterTransaction&&!i.spec.filterTransaction.call(i,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],r=this.applyInner(e),i=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=i?i[o].n:0,c=i?i[o].state:this,h=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,r);if(h&&r.filterTransaction(h,o)){if(h.setMeta("appendedTransaction",e),!i){i=[];for(let f=0;f<this.config.plugins.length;f++)i.push(f<o?{state:r,n:t.length}:{state:this,n:0})}t.push(h),r=r.applyInner(h),s=!0}i&&(i[o]={state:r,n:t.length})}}if(!s)return{state:r,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new ht(this.config),r=this.config.fields;for(let i=0;i<r.length;i++){let s=r[i];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new wc(this)}static create(e){let t=new qn(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new ht(t);for(let i=0;i<t.fields.length;i++)r[t.fields[i].name]=t.fields[i].init(e,r);return r}reconfigure(e){let t=new qn(this.schema,e.plugins),r=t.fields,i=new ht(t);for(let s=0;s<r.length;s++){let o=r[s].name;i[o]=this.hasOwnProperty(o)?this[o]:r[s].init(e,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(r=>r.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new qn(e.schema,e.plugins),s=new ht(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Ze.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}}function Mo(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Mo(i,e,{})),t[r]=i}return t}class Jt{constructor(e){this.spec=e,this.props={},e.props&&Mo(e.props,this,this.props),this.key=e.key?e.key.key:vo("plugin")}getState(e){return e[this.key]}}const Kn=Object.create(null);function vo(n){return n in Kn?n+"$"+ ++Kn[n]:(Kn[n]=0,n+"$")}class qt{constructor(e="key"){this.key=vo(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Oo=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Sc(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Mc=(n,e,t)=>{let r=Sc(n,t);if(!r)return!1;let i=No(r);if(!i){let o=r.blockRange(),l=o&&Tn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Io(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Ct(s,"end")||w.isSelectable(s)))for(let o=r.depth;;o--){let l=zr(n.doc,r.before(o),r.after(o),C.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=n.tr.step(l);a.setSelection(Ct(s,"end")?S.findFrom(a.doc.resolve(a.mapping.map(i.pos,-1)),-1):w.create(a.doc,i.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||r.node(o-1).childCount>1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Ct(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}const vc=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=No(r)}let o=s&&s.nodeBefore;return!o||!w.isSelectable(o)?!1:(e&&e(n.tr.setSelection(w.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function No(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function Oc(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const Nc=(n,e,t)=>{let r=Oc(n,t);if(!r)return!1;let i=Ao(r);if(!i)return!1;let s=i.nodeAfter;if(Io(n,i,e,1))return!0;if(r.parent.content.size==0&&(Ct(s,"start")||w.isSelectable(s))){let o=zr(n.doc,r.before(),r.after(),C.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=n.tr.step(o);l.setSelection(Ct(s,"start")?S.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):w.create(l.doc,l.mapping.map(i.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0):!1},Ac=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset<r.parent.content.size)return!1;s=Ao(r)}let o=s&&s.nodeAfter;return!o||!w.isSelectable(o)?!1:(e&&e(n.tr.setSelection(w.create(n.doc,s.pos)).scrollIntoView()),!0)};function Ao(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const Tc=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
74
+ `).scrollIntoView()),!0)};function Vr(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const To=(n,e)=>{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=Vr(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,o.createAndFill());a.setSelection(S.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Dc=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof te||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=Vr(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,l=n.tr.insert(o,s.createAndFill());l.setSelection(M.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},Do=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(dt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Tn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Eo(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof w&&e.selection.node.isBlock)return!r.parentOffset||!dt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){a=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),l=Vr(r.node(p-1).contentMatchAt(r.indexAfter(p-1)));let m=n&&n(i.parent,a,r);s.unshift(m||(a&&l?{type:l}:null)),o=p;break}else{if(p==1)return!1;s.unshift(null)}let h=e.tr;(e.selection instanceof M||e.selection instanceof te)&&h.deleteSelection();let f=h.mapping.map(r.pos),d=dt(h.doc,f,s.length,s);if(d||(s[0]=l?{type:l}:null,d=dt(h.doc,f,s.length,s)),h.split(f,s.length,s),!a&&c&&r.node(o).type!=l){let p=h.mapping.map(r.before(o)),u=h.doc.resolve(p);l&&r.node(o-1).canReplaceWith(u.index(),u.index()+1,l)&&h.setNodeMarkup(h.mapping.map(r.before(o)),l)}return t&&t(h.scrollIntoView()),!0}}const Ec=Eo(),Ro=(n,e)=>(e&&e(n.tr.setSelection(new te(n.doc))),!0);function Rc(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Dn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Io(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&Rc(n,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let p=e.pos+s.nodeSize,u=y.empty;for(let b=o.length-1;b>=0;b--)u=y.from(o[b].create(null,u));u=y.from(i.copy(u));let m=n.tr.step(new W(e.pos-1,p,e.pos,p,new C(u,1,0),o.length,!0)),g=m.doc.resolve(p+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Dn(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&a?null:S.findFrom(e,1),f=h&&h.$from.blockRange(h.$to),d=f&&Tn(f);if(d!=null&&d>=e.depth)return t&&t(n.tr.lift(f,d).scrollIntoView()),!0;if(c&&Ct(s,"start",!0)&&Ct(i,"end")){let p=i,u=[];for(;u.push(p),!p.isTextblock;)p=p.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(p.canReplace(p.childCount,p.childCount,m.content)){if(t){let b=y.empty;for(let O=u.length-1;O>=0;O--)b=y.from(u[O].copy(b));let k=n.tr.step(new W(e.pos-u.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new C(b,u.length,0),0,!0));t(k.scrollIntoView())}return!0}}return!1}function zo(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(M.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}const Ic=zo(-1),zc=zo(1);function Pc(n,e=null){return function(t,r){let i=!1;for(let s=0;s<t.selection.ranges.length&&!i;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,c)=>{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let h=t.doc.resolve(c),f=h.index();i=h.parent.canReplaceWith(f,f+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[o];s.setBlockType(l,a,n,e)}r(s.scrollIntoView())}return!0}}function Vc(n,e,t,r){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?n.inlineContent&&n.type.allowsMarkType(t):!1;if(n.nodesBetween(s.pos,o.pos,(a,c)=>{if(l||!r)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function Je(n,e=null,t){let r=t!==!1;return function(i,s){let{empty:o,$cursor:l,ranges:a}=i.selection;if(o&&!l||!Vc(i.doc,a,n,r))return!1;if(s)if(l)n.isInSet(i.storedMarks||l.marks())?s(i.tr.removeStoredMark(n)):s(i.tr.addStoredMark(n.create(e)));else{let c,h=i.tr;c=!a.some(f=>i.doc.rangeHasMark(f.$from.pos,f.$to.pos,n));for(let f=0;f<a.length;f++){let{$from:d,$to:p}=a[f];if(!c)h.removeMark(d.pos,p.pos,n);else{let u=d.pos,m=p.pos,g=d.nodeAfter,b=p.nodeBefore,k=g&&g.isText?/^\s*/.exec(g.text)[0].length:0,O=b&&b.isText?/\s*$/.exec(b.text)[0].length:0;u+k<m&&(u+=k,m-=O),h.addMark(u,m,n.create(e))}}s(h.scrollIntoView())}return!0}}function Ht(...n){return function(e,t,r){for(let i=0;i<n.length;i++)if(n[i](e,t,r))return!0;return!1}}let jn=Ht(Oo,Mc,vc),Si=Ht(Oo,Nc,Ac);const we={Enter:Ht(Tc,Dc,Do,Ec),"Mod-Enter":To,Backspace:jn,"Mod-Backspace":jn,"Shift-Backspace":jn,Delete:Si,"Mod-Delete":Si,"Mod-a":Ro},Po={"Ctrl-h":we.Backspace,"Alt-Backspace":we["Mod-Backspace"],"Ctrl-d":we.Delete,"Ctrl-Alt-Backspace":we["Mod-Delete"],"Alt-Delete":we["Mod-Delete"],"Alt-d":we["Mod-Delete"],"Ctrl-a":Ic,"Ctrl-e":zc};for(let n in we)Po[n]=we[n];const Bc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Hc=Bc?Po:we;var gn=200,V=function(){};V.prototype.append=function(e){return e.length?(e=V.from(e),!this.length&&e||e.length<gn&&this.leafAppend(e)||this.length<gn&&e.leafPrepend(this)||this.appendInner(e)):this};V.prototype.prepend=function(e){return e.length?V.from(e).append(this):this};V.prototype.appendInner=function(e){return new Lc(this,e)};V.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?V.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};V.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};V.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};V.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};V.from=function(e){return e instanceof V?e:e&&e.length?new Vo(e):V.empty};var Vo=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a<o;a++)if(i(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(i,s,o,l){for(var a=s-1;a>=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=gn)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=gn)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(V);V.empty=new Vo([]);var Lc=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,i,s,o){var l=this.left.length;if(i<l&&this.left.forEachInner(r,i,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(r,Math.min(i,l),s,o)===!1)return!1},e.prototype.sliceInner=function(r,i){if(r==0&&i==this.length)return this;var s=this.left.length;return i<=s?this.left.slice(r,i):r>=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(V);const Fc=500;class ae{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,s;t&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,a,c=[],h=[];return this.items.forEach((f,d)=>{if(!f.step){i||(i=this.remapping(r,d+1),s=i.maps.length),s--,h.push(f);return}if(i){h.push(new he(f.map));let p=f.step.map(i.slice(s)),u;p&&o.maybeStep(p).doc&&(u=o.mapping.maps[o.mapping.maps.length-1],c.push(new he(u,void 0,void 0,c.length+h.length))),s--,u&&i.appendMap(u,s)}else o.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(s)):f.selection,a=new ae(this.items.slice(0,r).append(h.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,r,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let h=0;h<e.steps.length;h++){let f=e.steps[h].invert(e.docs[h]),d=new he(e.mapping.maps[h],f,t),p;(p=a&&a.merge(d))&&(d=p,h?s.pop():l=l.slice(0,l.length-1)),s.push(d),t&&(o++,t=void 0),i||(a=d)}let c=o-r.depth;return c>$c&&(l=Wc(l,c),o-=c),new ae(l.append(s),o)}remapping(e,t){let r=new ft;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,t),r}addMaps(e){return this.eventCount==0?this:new ae(this.items.append(e.map(t=>new he(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(d=>{d.selection&&l--},i);let a=t;this.items.forEach(d=>{let p=s.getMirror(--a);if(p==null)return;o=Math.min(o,p);let u=s.maps[p];if(d.step){let m=e.steps[p].invert(e.docs[p]),g=d.selection&&d.selection.map(s.slice(a+1,p));g&&l++,r.push(new he(u,m,g))}else r.push(new he(u))},i);let c=[];for(let d=t;d<o;d++)c.push(new he(s.maps[d]));let h=this.items.slice(0,i).append(c).append(r),f=new ae(h,l);return f.emptyItemCount()>Fc&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let h=o.selection&&o.selection.map(t.slice(r));h&&s++;let f=new he(c.invert(),a,h),d,p=i.length-1;(d=i.length&&i[p].merge(f))?i[p]=d:i.push(f)}}else o.map&&r--},this.items.length,0),new ae(V.from(i.reverse()),s)}}ae.empty=new ae(V.empty,0);function Wc(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}class he{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new he(t.getMap().invert(),t,this.selection)}}}class Ne{constructor(e,t,r,i,s){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}}const $c=20;function Jc(n,e,t,r){let i=t.getMeta(Xe),s;if(i)return i.historyState;t.getMeta(jc)&&(n=new Ne(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(Xe))return o.getMeta(Xe).redo?new Ne(n.done.addTransform(t,void 0,r,on(e)),n.undone,Mi(t.mapping.maps),n.prevTime,n.prevComposition):new Ne(n.done,n.undone.addTransform(t,void 0,r,on(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!qc(t,n.prevRanges)),c=o?_n(n.prevRanges,t.mapping):Mi(t.mapping.maps);return new Ne(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,on(e)),ae.empty,c,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Ne(n.done.rebased(t,s),n.undone.rebased(t,s),_n(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Ne(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),_n(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function qc(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let s=0;s<e.length;s+=2)r<=e[s+1]&&i>=e[s]&&(t=!0)}),t}function Mi(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,s,o)=>e.push(s,o));return e}function _n(n,e){if(!n)return null;let t=[];for(let r=0;r<n.length;r+=2){let i=e.map(n[r],1),s=e.map(n[r+1],-1);i<=s&&t.push(i,s)}return t}function Kc(n,e,t){let r=on(e),i=Xe.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,r);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),i,r),a=new Ne(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Xe,{redo:t,historyState:a})}let Un=!1,vi=null;function on(n){let e=n.plugins;if(vi!=e){Un=!1,vi=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Un=!0;break}}return Un}const Xe=new qt("history"),jc=new qt("closeHistory");function _c(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new Jt({key:Xe,state:{init(){return new Ne(ae.empty,ae.empty,null,0,-1)},apply(e,t,r){return Jc(t,r,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let r=t.inputType,i=r=="historyUndo"?Ho:r=="historyRedo"?hr:null;return i?(t.preventDefault(),i(e.state,e.dispatch)):!1}}}})}function Bo(n,e){return(t,r)=>{let i=Xe.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let s=Kc(i,t,n);s&&r(e?s.scrollIntoView():s)}return!0}}const Ho=Bo(!1,!0),hr=Bo(!0,!0);var He={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},yn={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Uc=typeof navigator<"u"&&/Mac/.test(navigator.platform),Gc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var L=0;L<10;L++)He[48+L]=He[96+L]=String(L);for(var L=1;L<=24;L++)He[L+111]="F"+L;for(var L=65;L<=90;L++)He[L]=String.fromCharCode(L+32),yn[L]=String.fromCharCode(L);for(var Gn in He)yn.hasOwnProperty(Gn)||(yn[Gn]=He[Gn]);function Zc(n){var e=Uc&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Gc&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?yn:He)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Xc=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function Yc(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))r=!0;else if(/^(c|ctrl|control)$/i.test(a))i=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Xc?o=!0:i=!0;else throw new Error("Unrecognized modifier name: "+a)}return r&&(t="Alt-"+t),i&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Qc(n){let e=Object.create(null);for(let t in n)e[Yc(t)]=n[t];return e}function Zn(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function Xn(n){return new Jt({props:{handleKeyDown:Lo(n)}})}function Lo(n){let e=Qc(n);return function(t,r){let i=Zc(r),s,o=e[Zn(i,r)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let l=e[Zn(i,r,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((r.shiftKey||r.altKey||r.metaKey||i.charCodeAt(0)>127)&&(s=He[r.keyCode])&&s!=i){let l=e[Zn(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}function Oi(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=!1,a=o;if(!o)return!1;if(o.depth>=2&&i.node(o.depth-1).type.compatibleContent(n)&&o.startIndex==0){if(i.index(o.depth-1)==0)return!1;let h=t.doc.resolve(o.start-2);a=new dn(h,h,o.depth),o.endIndex<o.parent.childCount&&(o=new dn(i,t.doc.resolve(s.end(o.depth)),o.depth)),l=!0}let c=mo(a,n,e,o);return c?(r&&r(eh(t.tr,o,c,l,n).scrollIntoView()),!0):!1}}function eh(n,e,t,r,i){let s=y.empty;for(let h=t.length-1;h>=0;h--)s=y.from(t[h].type.create(t[h].attrs,s));n.step(new W(e.start-(r?2:0),e.end,e.start,e.end,new C(s,0,0),t.length,!0));let o=0;for(let h=0;h<t.length;h++)t[h].type==i&&(o=h+1);let l=t.length-o,a=e.start+t.length-(r?2:0),c=e.parent;for(let h=e.startIndex,f=e.endIndex,d=!0;h<f;h++,d=!1)!d&&dt(n.doc,a,l)&&(n.split(a,l),a+=2*l),a+=c.child(h).nodeSize;return n}function th(n,e){return function(t,r){let{$from:i,$to:s,node:o}=t.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(s))return!1;let l=i.node(-1);if(l.type!=n)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=n||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let f=y.empty,d=i.index(-1)?1:i.index(-2)?2:3;for(let b=i.depth-d;b>=i.depth-3;b--)f=y.from(i.node(b).copy(f));let p=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;f=f.append(y.from(n.createAndFill()));let u=i.before(i.depth-(d-1)),m=t.tr.replace(u,i.after(-p),new C(f,4-d,0)),g=-1;m.doc.nodesBetween(u,m.doc.content.size,(b,k)=>{if(g>-1)return!1;b.isTextblock&&b.content.size==0&&(g=k+1)}),g>-1&&m.setSelection(S.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let a=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,s.pos),h=a?[null,{type:a}]:void 0;return dt(c.doc,i.pos,2,h)?(r&&r(c.split(i.pos,2,h).scrollIntoView()),!0):!1}}function fr(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?nh(e,t,n,s):rh(e,t,s):!0:!1}}function nh(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new W(s-1,o,s,o,new C(y.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new dn(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));const l=Tn(r);if(l==null)return!1;i.lift(r,l);let a=i.mapping.map(s,-1)-1;return Dn(i.doc,a)&&i.join(a),e(i.scrollIntoView()),!0}function rh(n,e,t){let r=n.tr,i=t.parent;for(let p=t.end,u=t.endIndex-1,m=t.startIndex;u>m;u--)p-=i.child(u).nodeSize,r.delete(p-1,p+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=s.node(-1),h=s.index(-1);if(!c.canReplace(h+(l?0:1),h+1,o.content.append(a?y.empty:y.from(i))))return!1;let f=s.pos,d=f+o.nodeSize;return r.step(new W(f-(l?1:0),d+(a?1:0),f+1,d-1,new C((l?y.empty:y.from(i.copy(y.empty))).append(a?y.empty:y.from(i.copy(y.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function ih(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,h=y.from(c?n.create():null),f=new C(y.from(n.create(null,y.from(l.type.create(null,h)))),c?3:1,0),d=s.start,p=s.end;t(e.tr.step(new W(d-(c?3:1),p,d,p,f,1,!0)).scrollIntoView())}return!0}}const F=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Lt=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let dr=null;const xe=function(n,e,t){let r=dr||(dr=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},sh=function(){dr=null},tt=function(n,e,t,r){return t&&(Ni(n,e,t,r,-1)||Ni(n,e,t,r,1))},oh=/^(img|br|input|textarea|hr)$/i;function Ni(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:ie(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Kt(n)||oh.test(n.nodeName)||n.contentEditable=="false")return!1;e=F(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?ie(n):0}else return!1}}function ie(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function lh(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=ie(n)}else if(n.parentNode&&!Kt(n))e=F(n),n=n.parentNode;else return null}}function ah(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!Kt(n))e=F(n)+1,n=n.parentNode;else return null}}function ch(n,e,t){for(let r=e==0,i=e==ie(n);r||i;){if(n==t)return!0;let s=F(n);if(n=n.parentNode,!n)return!1;r=r&&s==0,i=i&&s==ie(n)}}function Kt(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const Rn=function(n){return n.focusNode&&tt(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function qe(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function hh(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function fh(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:Math.min(ie(r.offsetNode),r.offset)}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:Math.min(ie(r.startContainer),r.startOffset)}}}const ue=typeof navigator<"u"?navigator:null,Ai=typeof document<"u"?document:null,Le=ue&&ue.userAgent||"",ur=/Edge\/(\d+)/.exec(Le),Fo=/MSIE \d/.exec(Le),pr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Le),X=!!(Fo||pr||ur),Pe=Fo?document.documentMode:pr?+pr[1]:ur?+ur[1]:0,ce=!X&&/gecko\/(\d+)/i.test(Le);ce&&+(/Firefox\/(\d+)/.exec(Le)||[0,0])[1];const mr=!X&&/Chrome\/(\d+)/.exec(Le),q=!!mr,Wo=mr?+mr[1]:0,_=!X&&!!ue&&/Apple Computer/.test(ue.vendor),xt=_&&(/Mobile\/\w+/.test(Le)||!!ue&&ue.maxTouchPoints>2),re=xt||(ue?/Mac/.test(ue.platform):!1),dh=ue?/Win/.test(ue.platform):!1,le=/Android \d/.test(Le),jt=!!Ai&&"webkitFontSmoothing"in Ai.documentElement.style,uh=jt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ph(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ge(n,e){return typeof n=="number"?n:n[e]}function mh(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ti(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Lt(o)){if(o.nodeType!=1)continue;let l=o,a=l==s.body,c=a?ph(s):mh(l),h=0,f=0;if(e.top<c.top+ge(r,"top")?f=-(c.top-e.top+ge(i,"top")):e.bottom>c.bottom-ge(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+ge(i,"top")-c.top:e.bottom-c.bottom+ge(i,"bottom")),e.left<c.left+ge(r,"left")?h=-(c.left-e.left+ge(i,"left")):e.right>c.right-ge(r,"right")&&(h=e.right-c.right+ge(i,"right")),h||f)if(a)s.defaultView.scrollBy(h,f);else{let d=l.scrollLeft,p=l.scrollTop;f&&(l.scrollTop+=f),h&&(l.scrollLeft+=h);let u=l.scrollLeft-d,m=l.scrollTop-p;e={left:e.left-u,top:e.top-m,right:e.right-u,bottom:e.bottom-m}}if(a||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function gh(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=n.root.elementFromPoint(s,o);if(!l||l==n.dom||!n.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:$o(n.dom)}}function $o(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Lt(r));return e}function yh({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Jo(t,r==0?0:r-e)}function Jo(n,e){for(let t=0;t<n.length;t++){let{dom:r,top:i,left:s}=n[t];r.scrollTop!=i+e&&(r.scrollTop=i+e),r.scrollLeft!=s&&(r.scrollLeft=s)}}let st=null;function bh(n){if(n.setActive)return n.setActive();if(st)return n.focus(st);let e=$o(n);n.focus(st==null?{get preventScroll(){return st={preventScroll:!0},!0}}:void 0),st||(st=!1,Jo(e,0))}function qo(n,e){let t,r=2e8,i,s=0,o=e.top,l=e.top,a,c;for(let h=n.firstChild,f=0;h;h=h.nextSibling,f++){let d;if(h.nodeType==1)d=h.getClientRects();else if(h.nodeType==3)d=xe(h).getClientRects();else continue;for(let p=0;p<d.length;p++){let u=d[p];if(u.top<=o&&u.bottom>=l){o=Math.max(u.bottom,o),l=Math.min(u.top,l);let m=u.left>e.left?u.left-e.left:u.right<e.left?e.left-u.right:0;if(m<r){t=h,r=m,i=m&&t.nodeType==3?{left:u.right<e.left?u.right:u.left,top:e.top}:e,h.nodeType==1&&m&&(s=f+(e.left>=(u.left+u.right)/2?1:0));continue}}else u.top>e.top&&!a&&u.left<=e.left&&u.right>=e.left&&(a=h,c={left:Math.max(u.left,Math.min(u.right,e.left)),top:u.top});!t&&(e.left>=u.right&&e.top>=u.top||e.left>=u.left&&e.top>=u.bottom)&&(s=f+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?Ch(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:qo(t,i)}function Ch(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i<t;i++){r.setEnd(n,i+1),r.setStart(n,i);let s=Oe(r,1);if(s.top!=s.bottom&&Br(e,s))return{node:n,offset:i+(e.left>=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function Br(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function xh(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function wh(n,e,t){let{node:r,offset:i}=qo(e,t),s=-1;if(r.nodeType==1&&!r.firstChild){let o=r.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function kh(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)){let a=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&(!o&&a.left>r.left||a.top>r.top?i=l.posBefore:(!o&&a.right<r.left||a.bottom<r.top)&&(i=l.posAfter),o=!0),!l.contentDOM&&i<0&&!l.node.isText)return(l.node.isBlock?r.top<(a.top+a.bottom)/2:r.left<(a.left+a.right)/2)?l.posBefore:l.posAfter}s=l.dom.parentNode}return i>-1?i:n.docView.posFromDOM(e,t,-1)}function Ko(n,e,t){let r=n.childNodes.length;if(r&&t.top<t.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-t.top)/(t.bottom-t.top))-2)),s=i;;){let o=n.childNodes[s];if(o.nodeType==1){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(Br(e,c))return Ko(o,e,c)}}if((s=(s+1)%r)==i)break}return n}function Sh(n,e){let t=n.dom.ownerDocument,r,i=0,s=fh(t,e.left,e.top);s&&({node:r,offset:i}=s);let o=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!o||!n.dom.contains(o.nodeType!=1?o.parentNode:o)){let c=n.dom.getBoundingClientRect();if(!Br(e,c)||(o=Ko(n.dom,e,c),!o))return null}if(_)for(let c=o;r&&c;c=Lt(c))c.draggable&&(r=void 0);if(o=xh(o,e),r){if(ce&&r.nodeType==1&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let h=r.childNodes[i],f;h.nodeName=="IMG"&&(f=h.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&i++}let c;jt&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=kh(n,r,i,e))}l==null&&(l=wh(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Di(n){return n.top<n.bottom||n.left<n.right}function Oe(n,e){let t=n.getClientRects();if(t.length){let r=t[e<0?0:t.length-1];if(Di(r))return r}return Array.prototype.find.call(t,Di)||n.getBoundingClientRect()}const Mh=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function jo(n,e,t){let{node:r,offset:i,atom:s}=n.docView.domFromPos(e,t<0?-1:1),o=jt||ce;if(r.nodeType==3)if(o&&(Mh.test(r.nodeValue)||(t<0?!i:i==r.nodeValue.length))){let a=Oe(xe(r,i,i),t);if(ce&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let c=Oe(xe(r,i-1,i-1),-1);if(c.top==a.top){let h=Oe(xe(r,i,i+1),-1);if(h.top!=a.top)return St(h,h.left<c.left)}}return a}else{let a=i,c=i,h=t<0?1:-1;return t<0&&!i?(c++,h=-1):t>=0&&i==r.nodeValue.length?(a--,h=1):t<0?a--:c++,St(Oe(xe(r,a,c),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==ie(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Yn(a.getBoundingClientRect(),!1)}if(s==null&&i<ie(r)){let a=r.childNodes[i];if(a.nodeType==1)return Yn(a.getBoundingClientRect(),!0)}return Yn(r.getBoundingClientRect(),t>=0)}if(s==null&&i&&(t<0||i==ie(r))){let a=r.childNodes[i-1],c=a.nodeType==3?xe(a,ie(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return St(Oe(c,1),!1)}if(s==null&&i<ie(r)){let a=r.childNodes[i];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?xe(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return St(Oe(c,-1),!0)}return St(Oe(r.nodeType==3?xe(r):r,-t),t>=0)}function St(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Yn(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function _o(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function vh(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return _o(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=jo(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=xe(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let h=a[c];if(h.bottom>h.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}const Oh=/[\u0590-\u08ac]/;function Nh(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return l?!Oh.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:_o(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:h,anchorOffset:f}=n.domSelectionRange(),d=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:u,focusOffset:m}=n.domSelectionRange(),g=u&&!p.contains(u.nodeType==1?u:u.parentNode)||a==u&&c==m;try{l.collapse(h,f),a&&(a!=h||c!=f)&&l.extend&&l.extend(a,c)}catch{}return d!=null&&(l.caretBidiLevel=d),g}):r.pos==r.start()||r.pos==r.end()}let Ei=null,Ri=null,Ii=!1;function Ah(n,e,t){return Ei==e&&Ri==t?Ii:(Ei=e,Ri=t,Ii=t=="up"||t=="down"?vh(n,e,t):Nh(n,e,t))}const se=0,zi=1,Ke=2,pe=3;class _t{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=se,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,r=this.posAtStart;;t++){let i=this.children[t];if(i==e)return r;r+=i.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,r){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(r<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let i;if(e==this.dom&&this.contentDOM)i=t>F(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;t<this.children.length;t++){let i=this.children[t],s=r+i.size;if(r==e&&s!=r){for(;!i.border&&i.children.length;)i=i.children[0];return i}if(e<s)return i.descAt(e-r-i.border);r=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,i=0;for(let s=0;r<this.children.length;r++){let o=this.children[r],l=s+o.size;if(l>e||o instanceof Go){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Uo&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?F(s.dom)+1:0}}else{let s,o=!0;for(;s=r<this.children.length?this.children[r]:null,!(!s||s.dom.parentNode==this.contentDOM);r++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?F(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let i=-1,s=-1;for(let o=r,l=0;;l++){let a=this.children[l],c=o+a.size;if(i==-1&&e<=c){let h=o+a.border;if(e>=h&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,h);e=o;for(let f=l;f>0;f--){let d=this.children[f-1];if(d.size&&d.dom.parentNode==this.contentDOM&&!d.emptyChildAt(1)){i=F(d.dom)+1;break}e-=d.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let h=l+1;h<this.children.length;h++){let f=this.children[h];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=F(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:i,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:r}=this.domFromPos(e,0);if(t.nodeType!=1||r==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[r]}setSelection(e,t,r,i=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let p=0,u=0;p<this.children.length;p++){let m=this.children[p],g=u+m.size;if(s>u&&o<g)return m.setSelection(e-u-m.border,t-u-m.border,r,i);u=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=r.root.getSelection(),h=r.domSelectionRange(),f=!1;if((ce||_)&&e==t){let{node:p,offset:u}=l;if(p.nodeType==3){if(f=!!(u&&p.nodeValue[u-1]==`
75
+ `),f&&u==p.nodeValue.length)for(let m=p,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:F(g)+1});break}let b=m.pmViewDesc;if(b&&b.node&&b.node.isBlock)break}}else{let m=p.childNodes[u-1];f=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(ce&&h.focusNode&&h.focusNode!=a.node&&h.focusNode.nodeType==1){let p=h.focusNode.childNodes[h.focusOffset];p&&p.contentEditable=="false"&&(i=!0)}if(!(i||f&&_)&&tt(l.node,l.offset,h.anchorNode,h.anchorOffset)&&tt(a.node,a.offset,h.focusNode,h.focusOffset))return;let d=!1;if((c.extend||e==t)&&!f){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),d=!0}catch{}}if(!d){if(e>t){let u=l;l=a,a=u}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i<this.children.length;i++){let s=this.children[i],o=r+s.size;if(r==o?e<=o&&t>=r:e<o&&t>r){let l=r+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==r||t==o?Ke:zi,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=pe:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Ke:pe}r=o}this.dirty=Ke}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?Ke:zi;t.dirty<r&&(t.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}isText(e){return!1}}class Uo extends _t{constructor(e,t,r,i){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(r,()=>{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==se&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}}class Th extends _t{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class nt extends _t{constructor(e,t,r,i,s){super(e,[],r,i),this.mark=t,this.spec=s}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=rt.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new nt(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&pe||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=pe&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=se){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=se}}slice(e,t,r){let i=nt.create(this.parent,this.mark,!0,r),s=this.children,o=this.size;t<o&&(s=yr(s,t,o,r)),e>0&&(s=yr(s,0,e,r));for(let l=0;l<s.length;l++)s[l].parent=i;return i.children=s,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Ve extends _t{constructor(e,t,r,i,s,o,l,a,c){super(e,[],s,o),this.node=t,this.outerDeco=r,this.innerDeco=i,this.nodeDOM=l}static create(e,t,r,i,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),h=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:f}=rt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let d=h;return h=Yo(h,r,t),c?a=new Dh(e,t,r,i,h,f||null,d,c,s,o+1):t.isText?new In(e,t,r,i,h,d,s):new Ve(e,t,r,i,h,f||null,d,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==se&&e.eq(this.node)&&bn(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new Rh(this,o&&o.node,e);Ph(this.node,this.innerDeco,(c,h,f)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!f&&a.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),a.placeWidget(c,e,i)},(c,h,f,d)=>{a.syncToMarks(c.marks,r,e);let p;a.findNodeMatch(c,h,f,d)||l&&e.state.selection.from>i&&e.state.selection.to<i+c.nodeSize&&(p=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(c,h,f,p,e)||a.updateNextNode(c,h,f,e,d,i)||a.addNode(c,h,f,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Ke)&&(o&&this.protectLocalComposition(e,o),Zo(this.contentDOM,this.children,e),xt&&Vh(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof M)||r<t||i>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Bh(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Th(this,s,t,i);e.input.compositionNodes.push(o),this.children=yr(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==pe||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=se}updateOuterDeco(e){if(bn(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Xo(this.dom,this.nodeDOM,gr(this.outerDeco,this.node,t),gr(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Pi(n,e,t,r,i){Yo(r,e,n);let s=new Ve(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class In extends Ve{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==pe||this.dirty!=se&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=se||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=se,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new In(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=pe)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Go extends _t{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==se&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Dh extends Ve{constructor(e,t,r,i,s,o,l,a,c,h){super(e,t,r,i,s,o,l,c,h),this.spec=a}update(e,t,r,i){if(this.dirty==pe)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Zo(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==n){for(;l!=r;)r=Vi(r),i=!0;r=r.nextSibling}else i=!0,n.insertBefore(l,r);if(o instanceof nt){let a=r?r.previousSibling:n.lastChild;Zo(o.contentDOM,o.children,t),r=a?a.nextSibling:n.firstChild}}for(;r;)r=Vi(r),i=!0;i&&t.trackWrites==n&&(t.trackWrites=null)}const Rt=function(n){n&&(this.nodeName=n)};Rt.prototype=Object.create(null);const je=[new Rt];function gr(n,e,t){if(n.length==0)return je;let r=t?je[0]:new Rt,i=[r];for(let s=0;s<n.length;s++){let o=n[s].type.attrs;if(o){o.nodeName&&i.push(r=new Rt(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&i.length==1&&i.push(r=new Rt(e.isInline?"span":"div")),l=="class"?r.class=(r.class?r.class+" ":"")+a:l=="style"?r.style=(r.style?r.style+";":"")+a:l!="nodeName"&&(r[l]=a))}}}return i}function Xo(n,e,t,r){if(t==je&&r==je)return e;let i=e;for(let s=0;s<r.length;s++){let o=r[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&i!=n&&(a=i.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(i),l=je[0]),i=a}Eh(i,l||je[0],o)}return i}function Eh(n,e,t){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in t)&&n.removeAttribute(r);for(let r in t)r!="class"&&r!="style"&&r!="nodeName"&&t[r]!=e[r]&&n.setAttribute(r,t[r]);if(e.class!=t.class){let r=e.class?e.class.split(" ").filter(Boolean):[],i=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<r.length;s++)i.indexOf(r[s])==-1&&n.classList.remove(r[s]);for(let s=0;s<i.length;s++)r.indexOf(i[s])==-1&&n.classList.add(i[s]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,i;for(;i=r.exec(e.style);)n.style.removeProperty(i[1])}t.style&&(n.style.cssText+=t.style)}}function Yo(n,e,t){return Xo(n,n,je,gr(e,t,n.nodeType!=1))}function bn(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function Vi(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Rh{constructor(e,t,r){this.lock=t,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Ih(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let r=e;r<t;r++)this.top.children[r].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,r){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=se,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let l=-1;for(let a=this.index;a<Math.min(this.index+3,this.top.children.length);a++){let c=this.top.children[a];if(c.matchesMark(e[s])&&!this.isLocked(c.dom)){l=a;break}}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=nt.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,r)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,r,i,s){let o=this.top.children[i];return o.dirty==pe&&o.dom==o.contentDOM&&(o.dirty=Ke),o.update(e,t,r,s)?(this.destroyBetween(this.index,i),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let r=e.pmViewDesc;if(r){for(let i=this.index;i<this.top.children.length;i++)if(this.top.children[i]==r)return i}return-1}e=t}}updateNextNode(e,t,r,i,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Ve){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let h=a.dom,f,d=this.isLocked(h)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=pe&&bn(t,a.outerDeco));if(!d&&a.update(e,t,r,i))return this.destroyBetween(this.index,l),a.dom!=h&&(this.changed=!0),this.index++,!0;if(!d&&(f=this.recreateWrapper(a,e,t,r,i,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Ke,f.updateChildren(i,o+1),f.dirty=se),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,r,i,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!bn(r,e.outerDeco)||!i.eq(e.innerDeco))return null;let l=Ve.create(this.top,t,r,i,s,o);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,r,i,s){let o=Ve.create(this.top,e,t,r,i,s);o.contentDOM&&o.updateChildren(i,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,r){let i=this.index<this.top.children.length?this.top.children[this.index]:null;if(i&&i.matchesWidget(e)&&(e==i.widget||!i.widget.type.toDOM.parentNode))this.index++;else{let s=new Uo(this.top,e,t,r);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof nt;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof In)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((_||q)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let r=document.createElement(e);e=="IMG"&&(r.className="ProseMirror-separator",r.alt=""),e=="BR"&&(r.className="ProseMirror-trailingBreak");let i=new Go(this.top,[],r,null);t!=this.top?t.children.push(i):t.children.splice(this.index++,0,i),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function Ih(n,e){let t=e,r=t.children.length,i=n.childCount,s=new Map,o=[];e:for(;i>0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof nt)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function zh(n,e){return n.type.side-e.type.side}function Ph(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let c=0;c<n.childCount;c++){let h=n.child(c);r(h,i,e.forChild(s,h),c),s+=h.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let h,f;for(;o<i.length&&i[o].to==s;){let g=i[o++];g.widget&&(h?(f||(f=[h])).push(g):h=g)}if(h)if(f){f.sort(zh);for(let g=0;g<f.length;g++)t(f[g],c,!!a)}else t(h,c,!!a);let d,p;if(a)p=-1,d=a,a=null;else if(c<n.childCount)p=c,d=n.child(c++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)l.push(i[o++]);let u=s+d.nodeSize;if(d.isText){let g=u;o<i.length&&i[o].from<g&&(g=i[o].from);for(let b=0;b<l.length;b++)l[b].to<g&&(g=l[b].to);g<u&&(a=d.cut(g-s),d=d.cut(0,g-s),u=g,p=-1)}else for(;o<i.length&&i[o].to<u;)o++;let m=d.isInline&&!d.isLeaf?l.filter(g=>!g.inline):l.slice();r(d,m,e.forChild(s,d),p),s=u}}function Vh(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Bh(n,e,t,r){for(let i=0,s=0;i<n.childCount&&s<=r;){let o=n.child(i++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;i<n.childCount;){let c=n.child(i++);if(s+=c.nodeSize,!c.isText)break;a+=c.text}if(s>=t){if(s>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l<r?a.lastIndexOf(e,r-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function yr(n,e,t,r,i){let s=[];for(let o=0,l=0;o<n.length;o++){let a=n[o],c=l,h=l+=a.size;c>=t||h<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,r)),i&&(s.push(i),i=void 0),h>t&&s.push(a.slice(t-c,a.size,r)))}return s}function Hr(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,c;if(Rn(t)){for(a=o;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&w.isSelectable(f)&&i.parent&&!(f.isInline&&ch(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;c=new w(o==d?l:r.resolve(d))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=o,d=o;for(let p=0;p<t.rangeCount;p++){let u=t.getRangeAt(p);f=Math.min(f,n.docView.posFromDOM(u.startContainer,u.startOffset,1)),d=Math.max(d,n.docView.posFromDOM(u.endContainer,u.endOffset,-1))}if(f<0)return null;[a,o]=d==n.state.selection.anchor?[d,f]:[f,d],l=r.resolve(o)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let h=r.resolve(a);if(!c){let f=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;c=Lr(n,h,l,f)}return c}function Qo(n){return n.editable?n.hasFocus():tl(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function ke(n,e=!1){let t=n.state.selection;if(el(n,t),!!Qo(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&q){let r=n.domSelectionRange(),i=n.domObserver.currentSelection;if(r.anchorNode&&i.anchorNode&&tt(r.anchorNode,r.anchorOffset,i.anchorNode,i.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)Lh(n);else{let{anchor:r,head:i}=t,s,o;Bi&&!(t instanceof M)&&(t.$from.parent.inlineContent||(s=Hi(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=Hi(n,t.to))),n.docView.setSelection(r,i,n,e),Bi&&(s&&Li(s),o&&Li(o)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Hh(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const Bi=_||q&&Wo<63;function Hi(n,e){let{node:t,offset:r}=n.docView.domFromPos(e,0),i=r<t.childNodes.length?t.childNodes[r]:null,s=r?t.childNodes[r-1]:null;if(_&&i&&i.contentEditable=="false")return Qn(i);if((!i||i.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(i)return Qn(i);if(s)return Qn(s)}}function Qn(n){return n.contentEditable="true",_&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function Li(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Hh(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),r=t.anchorNode,i=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Qo(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Lh(n){let e=n.domSelection(),t=document.createRange();if(!e)return;let r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setStart(r.parentNode,F(r)+1):t.setStart(r,0),t.collapse(!0),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&X&&Pe<=11&&(r.disabled=!0,r.disabled=!1)}function el(n,e){if(e instanceof w){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Fi(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Fi(n)}function Fi(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Lr(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||M.between(e,t,r)}function Wi(n){return n.editable&&!n.hasFocus()?!1:tl(n)}function tl(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Fh(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return tt(e.node,e.offset,t.anchorNode,t.anchorOffset)}function br(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Ae(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function $i(n,e,t){let r=n.state.selection;if(r instanceof M)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Ae(n,new M(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=br(n.state,e);return i&&i instanceof w?Ae(n,i):!1}else if(!(re&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?w.isSelectable(s)?Ae(n,new w(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):jt?Ae(n,new M(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof w&&r.node.isInline)return Ae(n,new M(e>0?r.$to:r.$from));{let i=br(n.state,e);return i?Ae(n,i):!1}}}function Cn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function It(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function ot(n,e){return e<0?Wh(n):$h(n)}function Wh(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(ce&&t.nodeType==1&&r<Cn(t)&&It(t.childNodes[r],-1)&&(o=!0);;)if(r>0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(It(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(nl(t))break;{let l=t.previousSibling;for(;l&&It(l,-1);)i=t.parentNode,s=F(l),l=l.previousSibling;if(l)t=l,r=Cn(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Cr(n,t,r):i&&Cr(n,i,s)}function $h(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Cn(t),s,o;for(;;)if(r<i){if(t.nodeType!=1)break;let l=t.childNodes[r];if(It(l,1))s=t,o=++r;else break}else{if(nl(t))break;{let l=t.nextSibling;for(;l&&It(l,1);)s=l.parentNode,o=F(l)+1,l=l.nextSibling;if(l)t=l,r=0,i=Cn(t);else{if(t=t.parentNode,t==n.dom)break;r=i=0}}}s&&Cr(n,s,o)}function nl(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function Jh(n,e){for(;n&&e==n.childNodes.length&&!Kt(n);)e=F(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function qh(n,e){for(;n&&!e&&!Kt(n);)e=F(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function Cr(n,e,t){if(e.nodeType!=3){let s,o;(o=Jh(e,t))?(e=o,t=0):(s=qh(e,t))&&(e=s,t=s.nodeValue.length)}let r=n.domSelection();if(!r)return;if(Rn(r)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),r.removeAllRanges(),r.addRange(s)}else r.extend&&r.extend(e,t);n.domObserver.setCurSelection();let{state:i}=n;setTimeout(()=>{n.state==i&&ke(n)},50)}function Ji(n,e){let t=n.state.doc.resolve(e);if(!(q||dh)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left<i.left?"ltr":"rtl"}if(e<t.end()){let s=n.coordsAtPos(e+1),o=(s.top+s.bottom)/2;if(o>i.top&&o<i.bottom&&Math.abs(s.left-i.left)>1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function qi(n,e,t){let r=n.state.selection;if(r instanceof M&&!r.empty||t.indexOf("s")>-1||re&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=br(n.state,e);if(o&&o instanceof w)return Ae(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof te?S.near(o,e):S.findFrom(o,e);return l?Ae(n,l):!1}return!1}function Ki(n,e){if(!(n.state.selection instanceof M))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function ji(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Kh(n){if(!_||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;ji(n,r,"true"),setTimeout(()=>ji(n,r,"false"),20)}return!1}function jh(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function _h(n,e){let t=e.keyCode,r=jh(e);if(t==8||re&&t==72&&r=="c")return Ki(n,-1)||ot(n,-1);if(t==46&&!e.shiftKey||re&&t==68&&r=="c")return Ki(n,1)||ot(n,1);if(t==13||t==27)return!0;if(t==37||re&&t==66&&r=="c"){let i=t==37?Ji(n,n.state.selection.from)=="ltr"?-1:1:-1;return $i(n,i,r)||ot(n,i)}else if(t==39||re&&t==70&&r=="c"){let i=t==39?Ji(n,n.state.selection.from)=="ltr"?1:-1:1;return $i(n,i,r)||ot(n,i)}else{if(t==38||re&&t==80&&r=="c")return qi(n,-1,r)||ot(n,-1);if(t==40||re&&t==78&&r=="c")return Kh(n)||qi(n,1,r)||ot(n,1);if(r==(re?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function rl(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let o=n.someProp("clipboardSerializer")||rt.fromSchema(n.state.schema),l=cl(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c=a.firstChild,h,f=0;for(;c&&c.nodeType==1&&(h=al[c.nodeName.toLowerCase()]);){for(let p=h.length-1;p>=0;p--){let u=l.createElement(h[p]);for(;a.firstChild;)u.appendChild(a.firstChild);a.appendChild(u),f++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let d=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,`
66
76
 
67
- `);return{dom:a,text:d,slice:e}}function Zo(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=e&&(r||s||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,s||r,n)}),s)return e?new C(y.from(n.state.schema.text(e.replace(/\r\n?/g,`
68
- `))),0,0):C.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,u=tt.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(u.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=Bh(t),Jt&&Hh(o);let c=o&&o.querySelector("[data-pm-slice]"),h=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let f=+h[3];f>0;f--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||ut.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||h),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!zh.test(d.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Lh(Fi(l,+h[1],+h[2]),h[4]);else if(l=C.maxOpen(Vh(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f<l.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=l.content.lastChild;d<l.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);l=Fi(l,f,d)}return n.someProp("transformPasted",f=>{l=f(l,n)}),l}const zh=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Vh(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&Yo(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=Qo(o[o.length-1],s.length));let h=Xo(l,a);o.push(h),i=i.matchType(h.type),s=a}}),o)return y.from(o)}return n}function Xo(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,y.from(n));return n}function Yo(n,e,t,r,i){if(i<n.length&&i<e.length&&n[i]==e[i]){let s=Yo(n,e,t,r.lastChild,i+1);if(s)return r.copy(r.content.replaceChild(r.childCount-1,s));if(r.contentMatchAt(r.childCount).matchType(i==n.length-1?t.type:n[i+1]))return r.copy(r.content.append(y.from(Xo(t,n,i+1))))}}function Qo(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Qo(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(y.empty,!0);return n.copy(t.append(r))}function ur(n,e,t,r,i,s){let o=e<0?n.firstChild:n.lastChild,l=o.content;return n.childCount>1&&(s=0),i<r-1&&(l=ur(l,e,t,r,i+1,s)),i>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(y.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function Fi(n,e,t){return e<n.openStart&&(n=new C(ur(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new C(ur(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const el={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Wi=null;function tl(){return Wi||(Wi=document.implementation.createHTMLDocument("title"))}let _n=null;function Ph(n){let e=window.trustedTypes;return e?(_n||(_n=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),_n.createHTML(n)):n}function Bh(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=tl().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&el[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=Ph(n),i)for(let s=0;s<i.length;s++)t=t.querySelector(i[s])||t;return t}function Hh(n){let e=n.querySelectorAll(q?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let r=e[t];r.childNodes.length==1&&r.textContent==" "&&r.parentNode&&r.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),r)}}function Lh(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return n}let{content:i,openStart:s,openEnd:o}=n;for(let l=r.length-2;l>=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=y.from(a.create(r[l+1],i)),s++,o++}return new C(i,s,o)}const U={},G={},Fh={touchstart:!0,touchmove:!0};class Wh{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function $h(n){for(let e in U){let t=U[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{qh(n,r)&&!Vr(n,r)&&(n.editable||!(r.type in G))&&t(n,r)},Fh[e]?{passive:!0}:void 0)}_&&n.dom.addEventListener("input",()=>null),pr(n)}function ze(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Jh(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function pr(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Vr(n,r))})}function Vr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function qh(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Kh(n,e){!Vr(n,e)&&U[e.type]&&(n.editable||!(e.type in G))&&U[e.type](n,e)}G.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!rl(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(le&&q&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),yt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,$e(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Ih(n,t)?t.preventDefault():ze(n,"key")};G.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};G.keypress=(n,e)=>{let t=e;if(rl(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||re&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof M)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function An(n){return{left:n.clientX,top:n.clientY}}function jh(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Pr(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function ft(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function _h(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&w.isSelectable(r)?(ft(n,new w(t)),!0):!1}function Uh(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof w&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(w.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(ft(n,w.create(n.state.doc,i)),!0):!1}function Gh(n,e,t,r,i){return Pr(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?Uh(n,t):_h(n,t))}function Zh(n,e,t,r){return Pr(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Xh(n,e,t,r){return Pr(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Yh(n,t,r)}function Yh(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(ft(n,M.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)ft(n,M.create(r,l+1,l+1+o.content.size));else if(w.isSelectable(o))ft(n,w.create(r,l));else continue;return!0}}function Br(n){return gn(n)}const nl=re?"metaKey":"ctrlKey";U.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Br(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&jh(t,n.input.lastClick)&&!t[nl]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(An(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Qh(n,o,t,!!r)):(s=="doubleClick"?Zh:Xh)(n,o.pos,o.inside,t)?t.preventDefault():ze(n,"pointer"))};class Qh{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[nl],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:c}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof w&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ce&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),ze(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>ke(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(An(e))),this.updateAllowDefault(e),this.allowDefault||!t?ze(this.view,"pointer"):Gh(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||_&&this.mightDrag&&!this.mightDrag.node.isAtom||q&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(ft(this.view,k.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ze(this.view,"pointer")}move(e){this.updateAllowDefault(e),ze(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}U.touchstart=n=>{n.input.lastTouch=Date.now(),Br(n),ze(n,"pointer")};U.touchmove=n=>{n.input.lastTouch=Date.now(),ze(n,"pointer")};U.contextmenu=n=>Br(n);function rl(n,e){return n.composing?!0:_&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const ef=le?5e3:-1;G.compositionstart=G.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof M&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),gn(n,!0),n.markCursor=null;else if(gn(n,!e.selection.empty),ce&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}il(n,ef)};G.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,il(n,20))};function il(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>gn(n),e))}function sl(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=nf());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function tf(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=_c(e.focusNode,e.focusOffset),r=Uc(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function nf(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function gn(n,e=!1){if(!(le&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),sl(n),e||n.docView&&n.docView.dirty){let t=Ir(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function rf(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const Bt=X&&Ve<15||yt&&Qc<604;U.copy=G.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Bt?null:t.clipboardData,o=r.content(),{dom:l,text:a}=Go(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):rf(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function sf(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function of(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Ht(n,r.value,null,i,e):Ht(n,r.textContent,r.innerHTML,i,e)},50)}function Ht(n,e,t,r,i){let s=Zo(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,s||C.empty)))return!0;if(!s)return!1;let o=sf(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ol(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}G.paste=(n,e)=>{let t=e;if(n.composing&&!le)return;let r=Bt?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Ht(n,ol(r),r.getData("text/html"),i,t)?t.preventDefault():of(n,t)};class ll{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const al=re?"altKey":"ctrlKey";U.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(An(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof w?i.to-1:i.to))){if(r&&r.mightDrag)o=w.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=w.create(n.state.doc,f.posBefore))}}let l=(o||n.state.selection).content(),{dom:a,text:c,slice:h}=Go(n,l);(!t.dataTransfer.files.length||!q||Io>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Bt?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Bt||t.dataTransfer.setData("text/plain",c),n.dragging=new ll(h,!t[al],o)};U.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};G.dragover=G.dragenter=(n,e)=>e.preventDefault();G.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(An(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",u=>{o=u(o,n)}):o=Zo(n,ol(t.dataTransfer),Bt?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[al]);if(n.someProp("handleDrop",u=>u(n,t,o||C.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?Qa(n.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=n.state.tr;if(l){let{node:u}=r;u?u.replace(c):c.deleteSelection()}let h=c.mapping.map(a),f=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,d=c.doc;if(f?c.replaceRangeWith(h,h,o.content.firstChild):c.replaceRange(h,h,o),c.doc.eq(d))return;let p=c.doc.resolve(h);if(f&&w.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new w(p));else{let u=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,b,S)=>u=S),c.setSelection(zr(n,p,c.doc.resolve(u)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};U.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&ke(n)},20))};U.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};U.beforeinput=(n,e)=>{if(q&&le&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,$e(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in G)U[n]=G[n];function Lt(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class yn{constructor(e,t){this.toDOM=e,this.spec=t||Ze,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new Z(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof yn&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Lt(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Be{constructor(e,t){this.attrs=e,this.spec=t||Ze}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new Z(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Be&&Lt(this.attrs,e.attrs)&&Lt(this.spec,e.spec)}static is(e){return e.type instanceof Be}destroy(){}}class Hr{constructor(e,t){this.attrs=e,this.spec=t||Ze}map(e,t,r,i){let s=e.mapResult(t.from+i,1);if(s.deleted)return null;let o=e.mapResult(t.to+i,-1);return o.deleted||o.pos<=s.pos?null:new Z(s.pos-r,o.pos-r,this)}valid(e,t){let{index:r,offset:i}=e.content.findIndex(t.from),s;return i==t.from&&!(s=e.child(r)).isText&&i+s.nodeSize==t.to}eq(e){return this==e||e instanceof Hr&&Lt(this.attrs,e.attrs)&&Lt(this.spec,e.spec)}destroy(){}}class Z{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new Z(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,r){return this.type.map(e,this,t,r)}static widget(e,t,r){return new Z(e,e,new yn(t,r))}static inline(e,t,r,i){return new Z(e,t,new Be(r,i))}static node(e,t,r,i){return new Z(e,t,new Hr(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Be}get widget(){return this.type instanceof yn}}const st=[],Ze={};class R{constructor(e,t){this.local=e.length?e:st,this.children=t.length?t:st}static create(e,t){return t.length?bn(t,e,0,Ze):$}find(e,t,r){let i=[];return this.findInner(e??0,t??1e9,i,0,r),i}findInner(e,t,r,i,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==$||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Ze)}mapInner(e,t,r,i,s){let o;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,r,i);a&&a.type.valid(t,a)?(o||(o=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?lf(this.children,o||[],e,t,r,i,s):o?new R(o.sort(Xe),st):$}add(e,t){return t.length?this==$?R.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let i,s=0;e.forEach((l,a)=>{let c=a+r,h;if(h=hl(t,l,c)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,h,c+1):i.splice(s,0,a,a+l.nodeSize,bn(h,l,c+1,Ze)),s+=3}});let o=cl(s?fl(t):t,-r);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new R(o.length?this.local.concat(o).sort(Xe):this.local,i||this.children)}remove(e){return e.length==0||this==$?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,i=this.local;for(let s=0;s<r.length;s+=3){let o,l=r[s]+t,a=r[s+1]+t;for(let h=0,f;h<e.length;h++)(f=e[h])&&f.from>l&&f.to<a&&(e[h]=null,(o||(o=[])).push(f));if(!o)continue;r==this.children&&(r=this.children.slice());let c=r[s+2].removeInner(o,l+1);c!=$?r[s+2]=c:(r.splice(s,3),s-=3)}if(i.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<i.length;l++)i[l].eq(o,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new R(i,r):$}forChild(e,t){if(this==$)return this;if(t.isLeaf)return R.empty;let r,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof Be){let c=Math.max(s,a.from)-s,h=Math.min(o,a.to)-s;c<h&&(i||(i=[])).push(a.copy(c,h))}}if(i){let l=new R(i.sort(Xe),st);return r?new De([l,r]):l}return r||$}eq(e){if(this==e)return!0;if(!(e instanceof R)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return Lr(this.localsInner(e))}localsInner(e){if(this==$)return st;if(e.inlineContent||!this.local.some(Be.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Be||t.push(this.local[r]);return t}forEachSet(e){e(this)}}R.empty=new R([],[]);R.removeOverlap=Lr;const $=R.empty;class De{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,Ze));return De.from(r)}forChild(e,t){if(t.isLeaf)return R.empty;let r=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=$&&(s instanceof De?r=r.concat(s.members):r.push(s))}return De.from(r)}eq(e){if(!(e instanceof De)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,r=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!t)t=s;else{r&&(t=t.slice(),r=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?Lr(r?t:t.sort(Xe)):st}static from(e){switch(e.length){case 0:return $;case 1:return e[0];default:return new De(e.every(t=>t instanceof R)?e:e.reduce((t,r)=>t.concat(r instanceof R?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lf(n,e,t,r,i,s,o){let l=n.slice();for(let c=0,h=s;c<t.maps.length;c++){let f=0;t.maps[c].forEach((d,p,u,m)=>{let g=m-u-(p-d);for(let b=0;b<l.length;b+=3){let S=l[b+1];if(S<0||d>S+h-f)continue;let N=l[b]+h-f;p>=N?l[b+1]=d<=N?-2:-1:d>=h&&g&&(l[b]+=g,l[b+1]+=g)}f+=g}),h=t.maps[c].map(h,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let h=t.map(n[c]+s),f=h-i;if(f<0||f>=r.content.size){a=!0;continue}let d=t.map(n[c+1]+s,-1),p=d-i,{index:u,offset:m}=r.content.findIndex(f),g=r.maybeChild(u);if(g&&m==f&&m+g.nodeSize==p){let b=l[c+2].mapInner(t,g,h+1,n[c]+s+1,o);b!=$?(l[c]=f,l[c+1]=p,l[c+2]=b):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=af(l,n,e,t,i,s,o),h=bn(c,r,0,o);e=h.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,d=0;f<h.children.length;f+=3){let p=h.children[f];for(;d<l.length&&l[d]<p;)d+=3;l.splice(d,0,h.children[f],h.children[f+1],h.children[f+2])}}return new R(e.sort(Xe),l)}function cl(n,e){if(!e||!n.length)return n;let t=[];for(let r=0;r<n.length;r++){let i=n[r];t.push(new Z(i.from+e,i.to+e,i.type))}return t}function af(n,e,t,r,i,s,o){function l(a,c){for(let h=0;h<a.local.length;h++){let f=a.local[h].map(r,i,c);f?t.push(f):o.onRemove&&o.onRemove(a.local[h].spec)}for(let h=0;h<a.children.length;h+=3)l(a.children[h+2],a.children[h]+c+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+s+1);return t}function hl(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,i=null;for(let s=0,o;s<n.length;s++)(o=n[s])&&o.from>t&&o.to<r&&((i||(i=[])).push(o),n[s]=null);return i}function fl(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function bn(n,e,t,r){let i=[],s=!1;e.forEach((l,a)=>{let c=hl(n,l,a+t);if(c){s=!0;let h=bn(c,l,t+a+1,r);h!=$&&i.push(a,a+l.nodeSize,h)}});let o=cl(s?fl(n):n,-t).sort(Xe);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(r.onRemove&&r.onRemove(o[l].spec),o.splice(l--,1));return o.length||i.length?new R(o,i):$}function Xe(n,e){return n.from-e.from||n.to-e.to}function Lr(n){let e=n;for(let t=0;t<e.length-1;t++){let r=e[t];if(r.from!=r.to)for(let i=t+1;i<e.length;i++){let s=e[i];if(s.from==r.from){s.to!=r.to&&(e==n&&(e=n.slice()),e[i]=s.copy(s.from,r.to),$i(e,i+1,s.copy(r.to,s.to)));continue}else{s.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,s.from),$i(e,i,r.copy(s.from,r.to)));break}}}return e}function $i(n,e,t){for(;e<n.length&&Xe(t,n[e])>0;)e++;n.splice(e,0,t)}function Un(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=$&&e.push(r)}),n.cursorWrapper&&e.push(R.create(n.state.doc,[n.cursorWrapper.deco])),De.from(e)}const cf={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},hf=X&&Ve<=11;class ff{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class df{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new ff,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;i<r.length;i++)this.queue.push(r[i]);X&&Ve<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),hf&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,cf)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(zi(this.view)){if(this.suppressingSelectionUpdates)return ke(this.view);if(X&&Ve<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Qe(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=Pt(s))t.add(s);for(let s=e.anchorNode;s;s=Pt(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&zi(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let h=0;h<t.length;h++){let f=this.registerMutation(t[h],a);f&&(s=s<0?f.from:Math.min(f.from,s),o=o<0?f.to:Math.max(f.to,o),f.typeOver&&(l=!0))}if(ce&&a.length){let h=a.filter(f=>f.nodeName=="BR");if(h.length==2){let[f,d]=h;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of h){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||mf(e,f)!=p)&&d.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&On(r)&&(c=Ir(e))&&c.eq(k.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ke(e),this.currentSelection.set(r),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),uf(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||ke(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;h<e.addedNodes.length;h++){let f=e.addedNodes[h];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let i=e.previousSibling,s=e.nextSibling;if(X&&Ve<=11&&e.addedNodes.length)for(let h=0;h<e.addedNodes.length;h++){let{previousSibling:f,nextSibling:d}=e.addedNodes[h];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(s=d)}let o=i&&i.parentNode==e.target?F(i)+1:0,l=r.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?F(s):e.target.childNodes.length,c=r.localPosFromDOM(e.target,a,1);return{from:l,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let Ji=new WeakMap,qi=!1;function uf(n){if(!Ji.has(n)&&(Ji.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=ce,qi)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),qi=!0}}function Ki(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,s=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return Qe(o.node,o.offset,i,s)&&([t,r,i,s]=[i,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}}function pf(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Ki(n,i)}let t;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",r,!0),t?Ki(n,t):null}function mf(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let r=n.docView.nearestDesc(t,!0);if(r&&r.node.isBlock)return t}return null}function gf(n,e,t){let{node:r,fromOffset:i,toOffset:s,from:o,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),c,h=a.anchorNode;if(h&&n.dom.contains(h.nodeType==1?h:h.parentNode)&&(c=[{node:h,offset:a.anchorOffset}],On(a)||c.push({node:a.focusNode,offset:a.focusOffset})),q&&n.input.lastKeyCode===8)for(let g=s;g>i;g--){let b=r.childNodes[g-1],S=b.pmViewDesc;if(b.nodeName=="BR"&&!S){s=g;break}if(!S||S.size)break}let f=n.state.doc,d=n.someProp("domParser")||ut.fromSchema(n.state.schema),p=f.resolve(o),u=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:yf,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=g),u={anchor:g+o,head:b+o}}return{doc:m,sel:u,from:o,to:l}}function yf(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(_&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||_&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const bf=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Cf(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let O=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,ve=Ir(n,O);if(ve&&!n.state.selection.eq(ve)){if(q&&le&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",Ol=>Ol(n,$e(13,"Enter"))))return;let jt=n.state.tr.setSelection(ve);O=="pointer"?jt.setMeta("pointer",!0):O=="key"&&jt.scrollIntoView(),s&&jt.setMeta("composition",s),n.dispatch(jt)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=gf(n,e,t),h=n.state.doc,f=h.slice(c.from,c.to),d,p;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(d=n.state.selection.to,p="end"):(d=n.state.selection.from,p="start"),n.input.lastKeyCode=null;let u=kf(f.content,c.doc.content,c.from,d,p);if(u&&n.input.domChangeCount++,(yt&&n.input.lastIOSEnter>Date.now()-225||le)&&i.some(O=>O.nodeType==1&&!bf.test(O.nodeName))&&(!u||u.endA>=u.endB)&&n.someProp("handleKeyDown",O=>O(n,$e(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!u)if(r&&a instanceof M&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))u={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let O=ji(n,n.state.doc,c.sel);if(O&&!O.eq(n.state.selection)){let ve=n.state.tr.setSelection(O);s&&ve.setMeta("composition",s),n.dispatch(ve)}}return}n.state.selection.from<n.state.selection.to&&u.start==u.endB&&n.state.selection instanceof M&&(u.start>n.state.selection.from&&u.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?u.start=n.state.selection.from:u.endA<n.state.selection.to&&u.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(u.endB+=n.state.selection.to-u.endA,u.endA=n.state.selection.to)),X&&Ve<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>c.from&&c.doc.textBetween(u.start-c.from-1,u.start-c.from+1)=="  "&&(u.start--,u.endA--,u.endB--);let m=c.doc.resolveNoCache(u.start-c.from),g=c.doc.resolveNoCache(u.endB-c.from),b=h.resolve(u.start),S=m.sameParent(g)&&m.parent.inlineContent&&b.end()>=u.endA,N;if((yt&&n.input.lastIOSEnter>Date.now()-225&&(!S||i.some(O=>O.nodeName=="DIV"||O.nodeName=="P"))||!S&&m.pos<c.doc.content.size&&!m.sameParent(g)&&(N=k.findFrom(c.doc.resolve(m.pos+1),1,!0))&&N.head==g.pos)&&n.someProp("handleKeyDown",O=>O(n,$e(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>u.start&&wf(h,u.start,u.endA,m,g)&&n.someProp("handleKeyDown",O=>O(n,$e(8,"Backspace")))){le&&q&&n.domObserver.suppressSelectionUpdates();return}q&&le&&u.endB==u.start&&(n.input.lastAndroidDelete=Date.now()),le&&!S&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==u.endA&&(u.endB-=2,g=c.doc.resolveNoCache(u.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(O){return O(n,$e(13,"Enter"))})},20));let v=u.start,E=u.endA,D,j,Me;if(S){if(m.pos==g.pos)X&&Ve<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>ke(n),20)),D=n.state.tr.delete(v,E),j=h.resolve(u.start).marksAcross(h.resolve(u.endA));else if(u.endA==u.endB&&(Me=xf(m.parent.content.cut(m.parentOffset,g.parentOffset),b.parent.content.cut(b.parentOffset,u.endA-b.start()))))D=n.state.tr,Me.type=="add"?D.addMark(v,E,Me.mark):D.removeMark(v,E,Me.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let O=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",ve=>ve(n,v,E,O)))return;D=n.state.tr.insertText(O,v,E)}}if(D||(D=n.state.tr.replace(v,E,c.doc.slice(u.start-c.from,u.endB-c.from))),c.sel){let O=ji(n,D.doc,c.sel);O&&!(q&&le&&n.composing&&O.empty&&(u.start!=u.endB||n.input.lastAndroidDelete<Date.now()-100)&&(O.head==v||O.head==D.mapping.map(E)-1)||X&&O.empty&&O.head==v)&&D.setSelection(O)}j&&D.ensureMarks(j),s&&D.setMeta("composition",s),n.dispatch(D.scrollIntoView())}function ji(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:zr(n,e.resolve(t.anchor),e.resolve(t.head))}function xf(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,a;for(let h=0;h<r.length;h++)i=r[h].removeFromSet(i);for(let h=0;h<t.length;h++)s=t[h].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=h=>h.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=h=>h.mark(l.removeFromSet(h.marks));else return null;let c=[];for(let h=0;h<e.childCount;h++)c.push(a(e.child(h)));if(y.from(c).eq(n))return{mark:l,type:o}}function wf(n,e,t,r,i){if(t-e<=i.pos-r.pos||Gn(r,!0,!1)<i.pos)return!1;let s=n.resolve(e);if(!r.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=n.resolve(Gn(s,!0,!0));return!o.parent.isTextblock||o.pos>t||Gn(o,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function Gn(n,e,t){let r=n.depth,i=e?n.end():n.pos;for(;r>0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function kf(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));r-=o+a-s}if(o<s&&n.size<e.size){let a=r<=s&&r>=o?s-r:0;s-=a,s&&s<e.size&&_i(e.textBetween(s-1,s+1))&&(s+=a?1:-1),l=s+(l-o),o=s}else if(l<s){let a=r<=s&&r>=l?s-r:0;s-=a,s&&s<n.size&&_i(n.textBetween(s-1,s+1))&&(s+=a?1:-1),o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}function _i(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class Sf{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Wh,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Yi),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Zi(this),Gi(this),this.nodeViews=Xi(this),this.docView=Ai(this.state.doc,Ui(this),Un(this),this.dom,this),this.domObserver=new df(this,(r,i,s,o)=>Cf(this,r,i,s,o)),this.domObserver.start(),$h(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&pr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Yi),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(sl(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Xi(this);vf(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&pr(this),this.editable=Zi(this),Gi(this);let a=Un(this),c=Ui(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,c,a);(f||!e.selection.eq(i.selection))&&(o=!0);let d=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&nh(this);if(o){this.domObserver.stop();let p=f&&(X||q)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Mf(i.selection,e.selection);if(f){let u=q?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=tf(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Ai(e.doc,c,a,this.dom,this)),u&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Oh(this))?ke(this,p):(jo(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():d&&rh(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof w){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&ki(this,t.getBoundingClientRect(),e)}else ki(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let r=this.directPlugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let r=this.state.plugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let r=this.pluginViews[t];r.update&&r.update(this,e)}}updateDraggedNode(e,t){let r=e.node,i=-1;if(this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let s=r.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ll(e.slice,e.move,i<0?void 0:w.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(i=t?t(l):l))return i}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(X){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&ih(this.dom),ke(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return ch(this,e)}coordsAtPos(e,t=1){return Ho(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return ph(this,t||this.state,e)}pasteHTML(e,t){return Ht(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Ht(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Jh(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Un(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Kc())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Kh(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?_&&this.root.nodeType===11&&Zc(this.dom.ownerDocument)==this.dom&&pf(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function Ui(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[Z.node(0,n.state.doc.content.size,e)]}function Gi(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Z.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Zi(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Mf(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Xi(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function vf(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Yi(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var mr,gr;if(typeof WeakMap<"u"){let n=new WeakMap;mr=e=>n.get(e),gr=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;mr=r=>{for(let i=0;i<n.length;i+=2)if(n[i]==r)return n[i+1]},gr=(r,i)=>(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e<this.map.length;e++){const t=this.map[e];if(t!=n)continue;const r=e%this.width,i=e/this.width|0;let s=r+1,o=i+1;for(let l=1;s<this.width&&this.map[e+l]==t;l++)s++;for(let l=1;o<this.height&&this.map[e+this.width*l]==t;l++)o++;return{left:r,top:i,right:s,bottom:o}}throw new RangeError(`No cell with offset ${n} found`)}colCount(n){for(let e=0;e<this.map.length;e++)if(this.map[e]==n)return e%this.width;throw new RangeError(`No cell with offset ${n} found`)}nextCell(n,e,t){const{left:r,right:i,top:s,bottom:o}=this.findCell(n);return e=="horiz"?(t<0?r==0:i==this.width)?null:this.map[s*this.width+(t<0?r-1:i)]:(t<0?s==0:o==this.height)?null:this.map[r+this.width*(t<0?s-1:o)]}rectBetween(n,e){const{left:t,right:r,top:i,bottom:s}=this.findCell(n),{left:o,right:l,top:a,bottom:c}=this.findCell(e);return{left:Math.min(t,o),top:Math.min(i,a),right:Math.max(r,l),bottom:Math.max(s,c)}}cellsInRect(n){const e=[],t={};for(let r=n.top;r<n.bottom;r++)for(let i=n.left;i<n.right;i++){const s=r*this.width+i,o=this.map[s];t[o]||(t[o]=!0,!(i==n.left&&i&&this.map[s-1]==o||r==n.top&&r&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(n,e,t){for(let r=0,i=0;;r++){const s=i+t.child(r).nodeSize;if(r==n){let o=e+n*this.width;const l=(n+1)*this.width;for(;o<l&&this.map[o]<i;)o++;return o==l?s-1:this.map[o]}i=s}}static get(n){return mr(n)||gr(n,Of(n))}};function Of(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);const e=Nf(n),t=n.childCount,r=[];let i=0,s=null;const o=[];for(let c=0,h=e*t;c<h;c++)r[c]=0;for(let c=0,h=0;c<t;c++){const f=n.child(c);h++;for(let u=0;;u++){for(;i<r.length&&r[i]!=0;)i++;if(u==f.childCount)break;const m=f.child(u),{colspan:g,rowspan:b,colwidth:S}=m.attrs;for(let N=0;N<b;N++){if(N+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:b-N});break}const v=i+N*e;for(let E=0;E<g;E++){r[v+E]==0?r[v+E]=h:(s||(s=[])).push({type:"collision",row:c,pos:h,n:g-E});const D=S&&S[E];if(D){const j=(v+E)%e*2,Me=o[j];Me==null||Me!=D&&o[j+1]==1?(o[j]=D,o[j+1]=1):Me==D&&o[j+1]++}}}i+=g,h+=m.nodeSize}const d=(c+1)*e;let p=0;for(;i<d;)r[i++]==0&&p++;p&&(s||(s=[])).push({type:"missing",row:c,n:p}),h++}const l=new z(e,t,r,s);let a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&Af(l,o,n),l}function Nf(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){const i=n.child(r);let s=0;if(t)for(let o=0;o<r;o++){const l=n.child(o);for(let a=0;a<l.childCount;a++){const c=l.child(a);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){const l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function Af(n,e,t){n.problems||(n.problems=[]);const r={};for(let i=0;i<n.map.length;i++){const s=n.map[i];if(r[s])continue;r[s]=!0;const o=t.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let l=null;const a=o.attrs;for(let c=0;c<a.colspan;c++){const h=(i+c)%n.width,f=e[h*2];f!=null&&(!a.colwidth||a.colwidth[c]!=f)&&((l||(l=Tf(a)))[c]=f)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function Tf(n){if(n.colwidth)return n.colwidth.slice();const e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function Qi(n,e){if(typeof n=="string")return{};const t=n.getAttribute("data-colwidth"),r=t&&/^\d+(,\d+)*$/.test(t)?t.split(",").map(o=>Number(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const o in e){const l=e[o].getFromDOM,a=l&&l(n);a!=null&&(s[o]=a)}return s}function es(n,e){const t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function Df(n){const e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>Qi(r,e)}],toDOM(r){return["td",es(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>Qi(r,e)}],toDOM(r){return["th",es(r,e),0]}}}}function me(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Ee=new Wt("selectingCells");function Kt(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Tn(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Fr(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=Kt(e.$head)||Ef(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Ef(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function yr(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function Rf(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function Wr(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function dl(n,e,t){const r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function bt(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var B=class Ce extends k{constructor(e,t=e){const r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(h=>h!=t.pos-s);a.unshift(t.pos-s);const c=a.map(h=>{const f=r.nodeAt(h);if(!f)throw RangeError(`No cell with offset ${h} found`);const d=s+h+1;return new mo(l.resolve(d),l.resolve(d+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(yr(r)&&yr(i)&&Wr(r,i)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Ce.rowSelection(r,i):s&&this.isColSelection()?Ce.colSelection(r,i):new Ce(r,i)}return M.between(r,i)}content(){const e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let a=i.top;a<i.bottom;a++){const c=[];for(let h=a*t.width+i.left,f=i.left;f<i.right;f++,h++){const d=t.map[h];if(s[d])continue;s[d]=!0;const p=t.findCell(d);let u=e.nodeAt(d);if(!u)throw RangeError(`No cell with offset ${d} found`);const m=i.left-p.left,g=p.right-i.right;if(m>0||g>0){let b=u.attrs;if(m>0&&(b=bt(b,0,m)),g>0&&(b=bt(b,b.colspan-g,g)),p.left<i.left){if(u=u.type.createAndFill(b),!u)throw RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`)}else u=u.type.create(b,u.content)}if(p.top<i.top||p.bottom>i.bottom){const b={...u.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top<i.top?u=u.type.createAndFill(b):u=u.type.create(b,u.content)}c.push(u)}o.push(e.child(a).copy(y.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new C(y.from(l),1,1)}replace(e,t=C.empty){const r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){const{$from:l,$to:a}=i[o],c=e.mapping.slice(r);e.replace(c.map(l.pos),c.map(a.pos),o?C.empty:t)}const s=k.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new C(y.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),r=z.get(t),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(s+i.map[o.left])),l.bottom<i.height&&(t=a.resolve(s+i.map[i.width*(i.height-1)+l.right-1]))):(l.top>0&&(t=a.resolve(s+i.map[l.left])),o.bottom<i.height&&(e=a.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new Ce(e,t)}isRowSelection(){const e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.colCount(this.$anchorCell.pos-r),s=t.colCount(this.$headCell.pos-r);if(Math.min(i,s)>0)return!1;const o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof Ce&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(s+i.map[o.top*i.width])),l.right<i.width&&(t=a.resolve(s+i.map[i.width*(l.top+1)-1]))):(l.left>0&&(t=a.resolve(s+i.map[l.top*i.width])),o.right<i.width&&(e=a.resolve(s+i.map[i.width*(o.top+1)-1]))),new Ce(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Ce(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Ce(e.resolve(t),e.resolve(r))}getBookmark(){return new If(this.$anchorCell.pos,this.$headCell.pos)}};B.prototype.visible=!1;k.jsonID("cell",B);var If=class ul{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ul(e.map(this.anchor),e.map(this.head))}resolve(e){const t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&Wr(t,r)?new B(t,r):k.near(r,1)}};function zf(n){if(!(n.selection instanceof B))return null;const e=[];return n.selection.forEachCell((t,r)=>{e.push(Z.node(r,r+t.nodeSize,{class:"selectedCell"}))}),R.create(n.doc,e)}function Vf({$from:n,$to:e}){if(n.pos==e.pos||n.pos<e.pos-6)return!1;let t=n.pos,r=e.pos,i=n.depth;for(;i>=0&&!(n.after(i+1)<n.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Pf({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){const s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Bf(n,e,t){const r=(e||n).selection,i=(e||n).doc;let s,o;if(r instanceof w&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=B.create(i,r.from);else if(o=="row"){const l=i.resolve(r.from+1);s=B.rowSelection(l,l)}else if(!t){const l=z.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];s=B.create(i,a+1,c)}}else r instanceof M&&Vf(r)?s=M.create(i,r.from):r instanceof M&&Pf(r)&&(s=M.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Hf=new Wt("fix-tables");function pl(n,e,t,r){const i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){const a=e.child(o);for(let c=l,h=Math.min(i,o+3);c<h;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}r(a,t),l<i&&n.child(l).sameMarkup(a)?pl(n.child(l),a,t+1,r):a.nodesBetween(0,a.content.size,r,t+1),t+=a.nodeSize}}function Lf(n,e){let t;const r=(i,s)=>{i.type.spec.tableRole=="table"&&(t=Ff(n,i,s,t))};return e?e.doc!=n.doc&&pl(e.doc,n.doc,0,r):n.doc.descendants(r),t}function Ff(n,e,t,r){const i=z.get(e);if(!i.problems)return r;r||(r=n.tr);const s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){const c=i.problems[a];if(c.type=="collision"){const h=e.nodeAt(c.pos);if(!h)continue;const f=h.attrs;for(let d=0;d<f.rowspan;d++)s[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,bt(f,f.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const h=e.nodeAt(c.pos);if(!h)continue;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,{...h.attrs,rowspan:h.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const h=e.nodeAt(c.pos);if(!h)continue;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,{...h.attrs,colwidth:c.colwidth})}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){const h=e.child(a),f=c+h.nodeSize,d=s[a];if(d>0){let p="cell";h.firstChild&&(p=h.firstChild.type.spec.tableRole);const u=[];for(let g=0;g<d;g++){const b=me(n.schema)[p].createAndFill();b&&u.push(b)}const m=(a==0||o==a-1)&&l==a?c+1:f-1;r.insert(r.mapping.map(m),u)}c=f}return r.setMeta(Hf,{fixTables:!0})}function ml(n){const e=n.selection,t=Fr(n),r=t.node(-1),i=t.start(-1),s=z.get(r);return{...e instanceof B?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(t.pos-i),tableStart:i,map:s,table:r}}function Wf(n){return function(e,t){if(!Tn(e))return!1;if(t){const r=me(e.schema),i=ml(e),s=e.tr,o=i.map.cellsInRect(n=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:n=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[a],r.cell,l[a].attrs);if(s.steps.length==0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],r.header_cell,l[a].attrs);t(s)}return!0}}function ts(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function $r(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?Wf(n):function(t,r){if(!Tn(t))return!1;if(r){const i=me(t.schema),s=ml(t),o=t.tr,l=ts("row",s,i),a=ts("column",s,i),h=(n==="column"?l:n==="row"?a:!1)?1:0,f=n=="column"?{left:0,top:h,right:1,bottom:s.map.height}:n=="row"?{left:h,top:0,right:s.map.width,bottom:1}:s,d=n=="column"?a?i.cell:i.header_cell:n=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(f).forEach(p=>{const u=p+s.tableStart,m=o.doc.nodeAt(u);m&&o.setNodeMarkup(u,d,m.attrs)}),r(o)}return!0}}$r("row",{useDeprecatedLogic:!0});$r("column",{useDeprecatedLogic:!0});$r("cell",{useDeprecatedLogic:!0});function $f(n,e){if(e<0){const t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){const s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;const t=n.node(-1);for(let r=n.indexAfter(-1),i=n.after();r<t.childCount;r++){const s=t.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}return null}function ns(n){return function(e,t){if(!Tn(e))return!1;const r=$f(Fr(e),n);if(r==null)return!1;if(t){const i=e.doc.resolve(r);t(e.tr.setSelection(M.between(i,Rf(i))).scrollIntoView())}return!0}}function Zt(n,e){const t=n.selection;if(!(t instanceof B))return!1;if(e){const r=n.tr,i=me(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new C(i,0,0))}),r.docChanged&&e(r)}return!0}function Jf(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content;const h=a?0:Math.max(0,t-1),f=a<e.childCount-1?0:Math.max(0,r-1);(h||f)&&(c=br(me(o).row,new C(c,h,f)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||r?br(me(o).row,new C(e,t,r)).content:e);else return null;return qf(o,l)}function qf(n,e){const t=[];for(let i=0;i<e.length;i++){const s=e[i];for(let o=s.childCount-1;o>=0;o--){const{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let r=0;for(let i=0;i<t.length;i++)r=Math.max(r,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(y.empty),t[i]<r){const s=me(n).cell.createAndFill(),o=[];for(let l=t[i];l<r;l++)o.push(s);e[i]=e[i].append(y.from(o))}return{height:e.length,width:r,rows:e}}function br(n,e){const t=n.createAndFill();return new po(t).replace(0,t.content.size,e).doc}function Kf({width:n,height:e,rows:t},r,i){if(n!=r){const s=[],o=[];for(let l=0;l<t.length;l++){const a=t[l],c=[];for(let h=s[l]||0,f=0;h<r;f++){let d=a.child(f%a.childCount);h+d.attrs.colspan>r&&(d=d.type.createChecked(bt(d.attrs,d.attrs.colspan,h+d.attrs.colspan-r),d.content)),c.push(d),h+=d.attrs.colspan;for(let p=1;p<d.attrs.rowspan;p++)s[l+p]=(s[l+p]||0)+d.attrs.colspan}o.push(y.from(c))}t=o,n=r}if(e!=i){const s=[];for(let o=0,l=0;o<i;o++,l++){const a=[],c=t[l%e];for(let h=0;h<c.childCount;h++){let f=c.child(h);o+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}s.push(y.from(a))}t=s,e=i}return{width:n,height:e,rows:t}}function jf(n,e,t,r,i,s,o){const l=n.doc.type.schema,a=me(l);let c,h;if(i>e.width)for(let f=0,d=0;f<e.height;f++){const p=t.child(f);d+=p.nodeSize;const u=[];let m;p.lastChild==null||p.lastChild.type==a.cell?m=c||(c=a.cell.createAndFill()):m=h||(h=a.header_cell.createAndFill());for(let g=e.width;g<i;g++)u.push(m);n.insert(n.mapping.slice(o).map(d-1+r),u)}if(s>e.height){const f=[];for(let u=0,m=(e.height-1)*e.width;u<Math.max(e.width,i);u++){const g=u>=e.width?!1:t.nodeAt(e.map[m+u]).type==a.header_cell;f.push(g?h||(h=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const d=a.row.create(null,y.from(f)),p=[];for(let u=e.height;u<s;u++)p.push(d);n.insert(n.mapping.slice(o).map(r+t.nodeSize-2),p)}return!!(c||h)}function rs(n,e,t,r,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){const h=o*e.width+c,f=e.map[h];if(e.map[h-e.width]==f){a=!0;const d=t.nodeAt(f),{top:p,left:u}=e.findCell(f);n.setNodeMarkup(n.mapping.slice(l).map(f+r),null,{...d.attrs,rowspan:o-p}),n.insert(n.mapping.slice(l).map(e.positionAt(o,u,t)),d.type.createAndFill({...d.attrs,rowspan:p+d.attrs.rowspan-o})),c+=d.attrs.colspan-1}}return a}function is(n,e,t,r,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){const h=c*e.width+o,f=e.map[h];if(e.map[h-1]==f){a=!0;const d=t.nodeAt(f),p=e.colCount(f),u=n.mapping.slice(l).map(f+r);n.setNodeMarkup(u,null,bt(d.attrs,o-p,d.attrs.colspan-(o-p))),n.insert(u+d.nodeSize,d.type.createAndFill(bt(d.attrs,0,o-p))),c+=d.attrs.rowspan-1}}return a}function ss(n,e,t,r,i){let s=t?n.doc.nodeAt(t-1):n.doc;if(!s)throw new Error("No table found");let o=z.get(s);const{top:l,left:a}=r,c=a+i.width,h=l+i.height,f=n.tr;let d=0;function p(){if(s=t?f.doc.nodeAt(t-1):f.doc,!s)throw new Error("No table found");o=z.get(s),d=f.mapping.maps.length}jf(f,o,s,t,c,h,d)&&p(),rs(f,o,s,t,a,c,l,d)&&p(),rs(f,o,s,t,a,c,h,d)&&p(),is(f,o,s,t,l,h,a,d)&&p(),is(f,o,s,t,l,h,c,d)&&p();for(let u=l;u<h;u++){const m=o.positionAt(u,a,s),g=o.positionAt(u,c,s);f.replace(f.mapping.slice(d).map(m+t),f.mapping.slice(d).map(g+t),new C(i.rows[u-l],0,0))}p(),f.setSelection(new B(f.doc.resolve(t+o.positionAt(l,a,s)),f.doc.resolve(t+o.positionAt(h-1,c-1,s)))),e(f)}var _f=Eo({ArrowLeft:Xt("horiz",-1),ArrowRight:Xt("horiz",1),ArrowUp:Xt("vert",-1),ArrowDown:Xt("vert",1),"Shift-ArrowLeft":Yt("horiz",-1),"Shift-ArrowRight":Yt("horiz",1),"Shift-ArrowUp":Yt("vert",-1),"Shift-ArrowDown":Yt("vert",1),Backspace:Zt,"Mod-Backspace":Zt,Delete:Zt,"Mod-Delete":Zt});function nn(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function Xt(n,e){return(t,r,i)=>{if(!i)return!1;const s=t.selection;if(s instanceof B)return nn(t,r,k.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;const o=gl(i,n,e);if(o==null)return!1;if(n=="horiz")return nn(t,r,k.near(t.doc.resolve(s.head+e),e));{const l=t.doc.resolve(o),a=dl(l,n,e);let c;return a?c=k.near(a,1):e<0?c=k.near(t.doc.resolve(l.before(-1)),-1):c=k.near(t.doc.resolve(l.after(-1)),1),nn(t,r,c)}}}function Yt(n,e){return(t,r,i)=>{if(!i)return!1;const s=t.selection;let o;if(s instanceof B)o=s;else{const a=gl(i,n,e);if(a==null)return!1;o=new B(t.doc.resolve(a))}const l=dl(o.$headCell,n,e);return l?nn(t,r,new B(o.$anchorCell,l)):!1}}function Uf(n,e){const t=n.state.doc,r=Kt(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new B(r))),!0):!1}function Gf(n,e,t){if(!Tn(n.state))return!1;let r=Jf(t);const i=n.state.selection;if(i instanceof B){r||(r={width:1,height:1,rows:[y.from(br(me(n.state.schema).cell,t))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=Kf(r,l.right-l.left,l.bottom-l.top),ss(n.state,n.dispatch,o,l,r),!0}else if(r){const s=Fr(n.state),o=s.start(-1);return ss(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function Zf(n,e){var t;if(e.ctrlKey||e.metaKey)return;const r=ls(n,e.target);let i;if(e.shiftKey&&n.state.selection instanceof B)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Kt(n.state.selection.$anchor))!=null&&((t=Zn(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(a,c){let h=Zn(n,c);const f=Ee.getState(n.state)==null;if(!h||!Wr(a,h))if(f)h=a;else return;const d=new B(a,h);if(f||!n.state.selection.eq(d)){const p=n.state.tr.setSelection(d);f&&p.setMeta(Ee,a.pos),n.dispatch(p)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Ee.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Ee,-1))}function l(a){const c=a,h=Ee.getState(n.state);let f;if(h!=null)f=n.state.doc.resolve(h);else if(ls(n,c.target)!=r&&(f=Zn(n,e),!f))return o();f&&s(f,c)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function gl(n,e,t){if(!(n.state.selection instanceof M))return null;const{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){const s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function ls(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function Zn(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Kt(n.state.doc.resolve(t.pos)):null}var Xf=class{constructor(n,e){this.node=n,this.defaultCellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Cr(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Cr(n,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Cr(n,e,t,r,i,s){var o;let l=0,a=!0,c=e.firstChild;const h=n.firstChild;if(h){for(let f=0,d=0;f<h.childCount;f++){const{colspan:p,colwidth:u}=h.child(f).attrs;for(let m=0;m<p;m++,d++){const g=i==d?s:u&&u[m],b=g?g+"px":"";if(l+=g||r,g||(a=!1),c)c.style.width!=b&&(c.style.width=b),c=c.nextSibling;else{const S=document.createElement("col");S.style.width=b,e.appendChild(S)}}}for(;c;){const f=c.nextSibling;(o=c.parentNode)==null||o.removeChild(c),c=f}a?(t.style.width=l+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=l+"px")}}var ee=new Wt("tableColumnResizing");function Yf({handleWidth:n=5,cellMinWidth:e=25,defaultCellMinWidth:t=100,View:r=Xf,lastColumnResizable:i=!0}={}){const s=new Ft({key:ee,state:{init(o,l){var a,c;const h=(c=(a=s.spec)==null?void 0:a.props)==null?void 0:c.nodeViews,f=me(l.schema).table.name;return r&&h&&(h[f]=(d,p)=>new r(d,t,p)),new Qf(-1,!1)},apply(o,l){return l.apply(o)}},props:{attributes:o=>{const l=ee.getState(o);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,l)=>{ed(o,l,n,i)},mouseleave:o=>{td(o)},mousedown:(o,l)=>{nd(o,l,e,t)}},decorations:o=>{const l=ee.getState(o);if(l&&l.activeHandle>-1)return ld(o,l.activeHandle)},nodeViews:{}}});return s}var Qf=class rn{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,r=e.getMeta(ee);if(r&&r.setHandle!=null)return new rn(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new rn(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return yr(e.doc.resolve(i))||(i=-1),new rn(i,t.dragging)}return t}};function ed(n,e,t,r){const i=ee.getState(n.state);if(i&&!i.dragging){const s=id(e.target);let o=-1;if(s){const{left:l,right:a}=s.getBoundingClientRect();e.clientX-l<=t?o=as(n,e,"left",t):a-e.clientX<=t&&(o=as(n,e,"right",t))}if(o!=i.activeHandle){if(!r&&o!==-1){const l=n.state.doc.resolve(o),a=l.node(-1),c=z.get(a),h=l.start(-1);if(c.colCount(l.pos-h)+l.nodeAfter.attrs.colspan-1==c.width-1)return}yl(n,o)}}}function td(n){const e=ee.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&yl(n,-1)}function nd(n,e,t,r){var i;const s=(i=n.dom.ownerDocument.defaultView)!=null?i:window,o=ee.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const l=n.state.doc.nodeAt(o.activeHandle),a=rd(n,o.activeHandle,l.attrs);n.dispatch(n.state.tr.setMeta(ee,{setDragging:{startX:e.clientX,startWidth:a}}));function c(f){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",h);const d=ee.getState(n.state);d!=null&&d.dragging&&(sd(n,d.activeHandle,cs(d.dragging,f,t)),n.dispatch(n.state.tr.setMeta(ee,{setDragging:null})))}function h(f){if(!f.which)return c(f);const d=ee.getState(n.state);if(d&&d.dragging){const p=cs(d.dragging,f,t);hs(n,d.activeHandle,p,r)}}return hs(n,o.activeHandle,a,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",h),e.preventDefault(),!0}function rd(n,e,{colspan:t,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const s=n.domAtPos(e);let l=s.node.childNodes[s.offset].offsetWidth,a=t;if(r)for(let c=0;c<t;c++)r[c]&&(l-=r[c],a--);return l/a}function id(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function as(n,e,t,r){const i=t=="right"?-r:r,s=n.posAtCoords({left:e.clientX+i,top:e.clientY});if(!s)return-1;const{pos:o}=s,l=Kt(n.state.doc.resolve(o));if(!l)return-1;if(t=="right")return l.pos;const a=z.get(l.node(-1)),c=l.start(-1),h=a.map.indexOf(l.pos-c);return h%a.width==0?-1:c+a.map[h-1]}function cs(n,e,t){const r=e.clientX-n.startX;return Math.max(t,n.startWidth+r)}function yl(n,e){n.dispatch(n.state.tr.setMeta(ee,{setHandle:e}))}function sd(n,e,t){const r=n.state.doc.resolve(e),i=r.node(-1),s=z.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){const h=c*s.width+l;if(c&&s.map[h]==s.map[h-s.width])continue;const f=s.map[h],d=i.nodeAt(f).attrs,p=d.colspan==1?0:l-s.colCount(f);if(d.colwidth&&d.colwidth[p]==t)continue;const u=d.colwidth?d.colwidth.slice():od(d.colspan);u[p]=t,a.setNodeMarkup(o+f,null,{...d,colwidth:u})}a.docChanged&&n.dispatch(a)}function hs(n,e,t,r){const i=n.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=z.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1;let a=n.domAtPos(i.start(-1)).node;for(;a&&a.nodeName!="TABLE";)a=a.parentNode;a&&Cr(s,a.firstChild,a,r,l,t)}function od(n){return Array(n).fill(0)}function ld(n,e){var t;const r=[],i=n.doc.resolve(e),s=i.node(-1);if(!s)return R.empty;const o=z.get(s),l=i.start(-1),a=o.colCount(i.pos-l)+i.nodeAfter.attrs.colspan-1;for(let c=0;c<o.height;c++){const h=a+c*o.width;if((a==o.width-1||o.map[h]!=o.map[h+1])&&(c==0||o.map[h]!=o.map[h-o.width])){const f=o.map[h],d=l+f+s.nodeAt(f).nodeSize-1,p=document.createElement("div");p.className="column-resize-handle",(t=ee.getState(n))!=null&&t.dragging&&r.push(Z.node(l+f,l+f+s.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),r.push(Z.widget(d,p))}}return R.create(n.doc,r)}function ad({allowTableNodeSelection:n=!1}={}){return new Ft({key:Ee,state:{init(){return null},apply(e,t){const r=e.getMeta(Ee);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;const{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:zf,handleDOMEvents:{mousedown:Zf},createSelectionBetween(e){return Ee.getState(e.state)!=null?e.state.selection:null},handleTripleClick:Uf,handleKeyDown:_f,handlePaste:Gf},appendTransaction(e,t,r){return Bf(r,Lf(r,t),n)}})}const Et=n=>{const e=Object.fromEntries(Array.from(n.attributes).map(t=>[t.name,t.value]));return delete e.draggable,e},fs="data-gs-mrk-fs",ds="data-gs-ib",Cn="data-gs-ifrg",Se="attrs",bl={[Se]:{default:"{}"}},ye={[Se]:{default:{}}},Cl=n=>({[Se]:JSON.stringify(Et(n))}),be=n=>({attrs:Et(n)}),wt=n=>e=>[n,e.attrs.attrs,0],Te=n=>n.attrs[Se]?JSON.parse(n.attrs[Se]):{},cd={doc:{content:"block+"},text:{group:"inline",inline:!0},inlineFragment:{group:"block",content:"inline*",isTextBlock:!0,parseDOM:[{tag:`span[${Cn}]`,getAttrs:be}],toDOM:()=>["span",{[Cn]:""},0]},div:{group:"block",content:"inline*",attrs:ye,parseDOM:[{tag:"div",getAttrs:be}],toDOM:wt("div")},paragraph:{group:"block",content:"inline*",attrs:ye,parseDOM:[{tag:"p",getAttrs:be}],toDOM:wt("p")},orderedList:{group:"block",content:"listItem+",attrs:ye,parseDOM:[{tag:"ol",getAttrs:be}],toDOM:wt("ol")},bulletList:{group:"block",content:"listItem+",attrs:ye,parseDOM:[{tag:"ul",getAttrs:be}],toDOM:wt("ul")},listItem:{content:"block*",group:"block",attrs:ye,parseDOM:[{tag:"li",getAttrs:be}],toDOM:wt("li"),defining:!0},codeBlock:{group:"block",content:"text*",marks:"",attrs:ye,parseDOM:[{tag:"pre",getAttrs:be}],toDOM:n=>["pre",n.attrs.attrs,["code",0]]},image:{inline:!0,group:"inline",selectable:!0,attrs:ye,parseDOM:[{tag:"img[src]",getAttrs:be}],toDOM:n=>["img",n.attrs.attrs]},inlineBreak:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:`br[${ds}]`}],toDOM(){return["br",{[ds]:""}]}},hardBreak:{inline:!1,group:"block",selectable:!1,attrs:ye,parseDOM:[{tag:"br",getAttrs:be}],toDOM:n=>["br",{...n.attrs.attrs}]},heading:{group:"block",content:"inline*",attrs:{level:{default:1},attrs:{default:{}}},defining:!0,parseDOM:Array.from({length:6},(n,e)=>({tag:`h${e+1}`,getAttrs:t=>({level:e+1,attrs:Et(t)})})),toDOM({attrs:n}){const{level:e}=n;return[e?`h${e}`:"div",n.attrs,0]}},...Df({tableGroup:"block",cellContent:"block+",cellAttributes:{[Se]:{default:ye[Se].default,getFromDOM:Et,setDOMAttr:(n,e)=>{n&&Object.assign(e,n)}},background:{default:null,getFromDOM(n){return n.style.backgroundColor||null},setDOMAttr(n,e){n&&(e.style=(e.style||"")+`background-color: ${n};`)}}}}),nonTextNode:{group:"block",content:"block*",attrs:{tagName:{default:"span"},attrs:{default:{}}},parseDOM:[{tag:"*:not(tbody)",getAttrs:n=>({tagName:n.tagName.toLowerCase(),attrs:Et(n)}),priority:0}],toDOM(n){const{tagName:e,attrs:t}=n.attrs;return[e,t,0]}}},kt=(n,e)=>({attrs:bl,parseDOM:n.map(t=>({tag:t,getAttrs:Cl})),toDOM:e}),hd={strong:kt(["strong","b"],n=>["b",Te(n)]),link:kt(["a"],n=>["a",Te(n),0]),em:kt(["em","i"],n=>["em",Te(n)]),underline:kt(["u"],n=>["u",Te(n),0]),strikethrough:kt(["s"],n=>["s",Te(n),0]),font_size:{attrs:{...bl,size:{default:null}},parseDOM:[{tag:`span[${fs}]`,getAttrs:n=>({...Cl(n),size:n.style.fontSize})}],toDOM(n){const{size:e}=n.attrs,t={...Te(n),[fs]:!0};return e&&(t.style=`font-size: ${e}`),["span",t,0]}}},us=new Aa({nodes:cd,marks:hd}),Dn=new WeakMap,Jr=new WeakMap,fd=(n,e)=>{Dn.set(n,e),Jr.set(e,n)},dd=(n,e)=>{Dn.delete(n),Jr.delete(e)},ps=n=>Dn.get(n),ud=n=>Jr.get(n),ms=n=>{var t;const e=ud(n);return(t=e==null?void 0:e.__gjsv)==null?void 0:t.model},pd=n=>n.dispatchEvent(new CustomEvent("input"));function md(n){const e=t=>{if(t.tagName==="SPAN"&&t.hasAttribute(Cn)){if(t.getAttribute("style")){t.removeAttribute(Cn);return}const r=t.parentElement;if(r){for(;t.firstChild;)r.insertBefore(t.firstChild,t);r.removeChild(t)}}else Array.from(t.children).forEach(r=>e(r))};e(n)}const gd=(n,e)=>{const t=yd(n);return t&&Od(t)?bd(n,e):t?So(()=>({type:n.schema.nodes.div}))(n,e):!1};function yd(n){const e=n.selection.$from;if(e.node(e.depth).type===n.schema.nodes.inlineFragment){const t=e.depth-1;return e.node(t)}return e.node(e.depth)}function bd(n,e){const{selection:t,schema:r,tr:i}=n;i.split(t.from,1);const s=t.from+1,o=i.doc.nodeAt(s),l={...o.attrs.attrs,id:void 0},a=o.textContent.length>0,c=o.textContent.length||0,h=o.textContent||" ",f=r.text(h),d=r.nodes.div.create(l,a?f:[],[]);return i.replaceRangeWith(s,s+c+2,d),i.setSelection(M.create(i.doc,s+1)),e==null||e(i.scrollIntoView()),!0}function Cd(n,e,t){const{state:r,dispatch:i}=n,{selection:s,tr:o}=r,l=(a,c,h)=>{const f={};return a.split(";").forEach(d=>{const[p,u]=d.split(":").map(m=>m.trim());p&&(f[p]=u)}),f[c]=h,Object.entries(f).map(([d,p])=>`${d}: ${p}`).join("; ")};if(!s.empty||t)o.doc.nodesBetween(s.from,s.to,(a,c)=>{var h,f;if(a.type===r.schema.nodes.image){const d=l(((h=a.attrs.attrs)==null?void 0:h.style)||"","float",e);o.setNodeMarkup(c,void 0,{...a.attrs,attrs:{...a.attrs.attrs,style:d}})}else if(a.type.isBlock){const d=l(((f=a.attrs.attrs)==null?void 0:f.style)||"","text-align",e);xl(a)?o.setBlockType(s.from,void 0,r.schema.nodes.div,{attrs:{style:d}}):o.setNodeMarkup(c,void 0,{...a.attrs,attrs:{...a.attrs.attrs,style:d}})}});else{const a=r.doc.resolve(s.from),c=a.start(a.depth),h=r.doc.nodeAt(c);if(h!=null&&h.type.isBlock){const f=l(h.attrs.style||"","text-align",e);o.setNodeMarkup(c,void 0,{...h.attrs,style:f})}}o.docChanged&&i(o.scrollIntoView())}const St=(n,e)=>{const{from:t,to:r}=n.selection;let i=!1;return n.doc.nodesBetween(t,r,s=>{if(i)return!1;s.marks.some(o=>o.type===e)&&(i=!0)}),i};function xd(n,e,t="_blank"){const{state:r,dispatch:i}=n,{schema:s,selection:o,tr:l}=r,a=s.marks.link;try{const c=a.create({[Se]:JSON.stringify({href:e,target:t})});l.addMark(o.from,o.to,c),i(l.scrollIntoView())}catch(c){console.error("Error applying link mark:",c)}}function wd(n,e){const{state:t,dispatch:r}=n,{selection:i,tr:s}=t;if(i.empty)return;const o=t.schema.marks.font_size;if(!o){console.error("Font size mark is not defined in the schema.");return}s.addMark(i.from,i.to,o.create({size:e})),r(s.scrollIntoView())}const Ke=(n,e)=>{const{doc:t,selection:r}=n.state,i=t.resolve(r.from);for(let s=i.depth;s>0;s--){const o=i.node(s);if(e(o))return{pos:s>0?i.before(s):0,start:i.start(s),depth:s,node:o}}},kd=n=>(n||"").split(";").map(e=>e.split(":")).reduce((e,[t,r])=>(t=t.replace(/-./g,i=>i.toUpperCase()[1]).trim(),e[t]=`${r}`.trim(),e),{});function Sd(...n){return(e,t)=>{const r=o=>{e=e.apply(o),t==null||t(o)},i=n.pop();return n.reduce((o,l)=>o||l(e,r),!1)&&i!==void 0&&i(e,t)}}const Md=(n,e)=>{const{state:t,dispatch:r}=n;if(e!=null&&e.event){const{event:i}=e,s=n.posAtCoords({left:i.clientX,top:i.clientY});s!=null&&s.pos&&r(t.tr.setSelection(M.create(t.doc,s.pos)))}else Mo(t,r);setTimeout(()=>setTimeout(()=>n.focus()))},xr=n=>n.isBlock,xl=n=>n.type.name==="inlineFragment",vd=n=>xr(n)&&!xl(n),wl=n=>n.type.name==="bulletList",kl=n=>n.type.name==="orderedList",Od=n=>n.type.name==="heading",Nd=n=>wl(n)||kl(n),gs=(n,e)=>{var s,o;const t=(s=Ke(n,l=>l.type===e))==null?void 0:s.node,r=n.state.schema.nodes.listItem;let i;return t?i=ir(r):(o=Ke(n,Nd))!=null&&o.node?i=Sd(ir(r),Ci(e)):i=Ci(e),i(n.state,n.dispatch)},Sl=(n,e)=>{const{selection:t}=n.state;return[...t.$from.marks(),...t.$to.marks()].find(r=>r.type.name===e)},Ad=n=>{var o;const{view:e,prop:t,editor:r,propCSS:i}=n,s=(o=Ke(e,vd))==null?void 0:o.node;if(s){const l=s.attrs.attrs||{},a=kd(l.style);if(t in a)return a[t]||"";if(l.id){const c=r.Components.getById(l.id);return((c==null?void 0:c.getStyle())||{})[i]||""}}return""},Td=n=>{const{view:e,prop:t,markName:r,editor:i,propCSS:s}=n,o=Sl(e,r);if(o){const l=o.attrs;if(l[t])return l[t];if(l[Se]){const a=Te(o).id;if(a){const c=i.Components.getById(a);return((c==null?void 0:c.getStyle())||{})[s]||""}}}return""},Ml=(n,e)=>{const{dispatch:t}=n,{nodes:r,marks:i}=n.state.schema;return{text:{selected:()=>{const{selection:s,doc:o}=n.state;return o.textBetween(s.from,s.to," ")},replace:(s,o={})=>{const{state:l}=n,{from:a}=l.selection;let c=l.tr.replaceSelectionWith(l.schema.text(s));o.select&&(c=c.setSelection(M.create(c.doc,a,a+s.length))),t==null||t(c)}},bold:{toggle:()=>We(i.strong)(n.state,t),isActive:()=>St(n.state,i.strong)},italic:{toggle:()=>We(i.em)(n.state,t),isActive:()=>St(n.state,i.em)},underline:{toggle:()=>We(i.underline)(n.state,t),isActive:()=>St(n.state,i.underline)},strikethrough:{toggle:()=>We(i.strikethrough)(n.state,t),isActive:()=>St(n.state,i.strikethrough)},link:{get:()=>{const s=ms(n);if(s!=null&&s.is("link"))return s.getAttributes();{const o=Sl(n,"link");return o?Te(o):{}}},toggle:()=>We(i.link)(n.state,t),isActive:()=>St(n.state,i.link),create:s=>{const o=ms(n);o!=null&&o.is("link")?(o.addAttributes({href:s.url,target:s.target}),n.focus()):xd(n,s.url,s.target)}},alignText:{get:()=>Ad({view:n,editor:e,prop:"textAlign",propCSS:"text-align"}),set:s=>Cd(n,s.value,!0)},fontSize:{get:()=>Td({view:n,editor:e,markName:"font_size",prop:"size",propCSS:"font-size"}),set:s=>wd(n,s.value)},image:{open(){const s="assetLayout",{state:o,dispatch:l}=n,{selection:a,doc:c}=o,h=c.textBetween(a.from,a.to," "),f={id:s,disablePropagation:!0,placer:{type:"dialog",title:"Select image",size:"l"},header:!1,layout:{type:"panelAssets",onSelect:d=>{const p={alt:h,src:d.asset.getSrc()};l(o.tr.replaceSelectionWith(r.image.createAndFill({attrs:p})))}}};e.runCommand(Rt.layoutToggle,f)}},heading:{get:()=>{var o;const s=(o=Ke(n,xr))==null?void 0:o.node;return`${(s==null?void 0:s.attrs.level)||""}`},set:({value:s})=>{var a;const{state:o}=n,l=(a=Ke(n,xr))==null?void 0:a.node;wc(o.schema.nodes.heading,{attrs:l==null?void 0:l.attrs.attrs,level:s?parseInt(s,10):0})(o,t)}},listBullet:{isActive:()=>{var s;return!!((s=Ke(n,wl))!=null&&s.node)},toggle:()=>gs(n,r.bulletList)},listOrdered:{isActive:()=>{var s;return!!((s=Ke(n,kl))!=null&&s.node)},toggle:()=>gs(n,r.orderedList)}}},oe="rte:selectionchange",ne={bold:'<svg viewBox="0 0 24 24"><path d="M13.5,15.5H10V12.5H13.5A1.5,1.5 0 0,1 15,14A1.5,1.5 0 0,1 13.5,15.5M10,6.5H13A1.5,1.5 0 0,1 14.5,8A1.5,1.5 0 0,1 13,9.5H10M15.6,10.79C16.57,10.11 17.25,9 17.25,8C17.25,5.74 15.5,4 13.25,4H7V18H14.04C16.14,18 17.75,16.3 17.75,14.21C17.75,12.69 16.89,11.39 15.6,10.79Z" /></svg>',italic:'<svg viewBox="0 0 24 24"><path d="M10,4V7H12.21L8.79,15H6V18H14V15H11.79L15.21,7H18V4H10Z" /></svg>',underline:'<svg viewBox="0 0 24 24"><path d="M5,21H19V19H5V21M12,17A6,6 0 0,0 18,11V3H15.5V11A3.5,3.5 0 0,1 12,14.5A3.5,3.5 0 0,1 8.5,11V3H6V11A6,6 0 0,0 12,17Z" /></svg>',strikethrough:'<svg viewBox="0 0 24 24"><path d="M7.2 9.8c-1.2-2.3.5-5 2.9-5.5 3.1-1 7.6.4 7.5 4.2h-3l-.1-.8c-.2-.6-.6-.9-1.2-1.1-.8-.3-2.1-.2-2.8.3C9 8.2 10.4 9.5 12 10H7.4l-.2-.2M21 13v-2H3v2h9.6l.6.2c.6.3 1.1.5 1.3 1.1.1.4.2.9 0 1.3-.2.5-.6.7-1.1.9-1.8.5-4-.2-3.9-2.4h-3c-.1 2.6 2.1 4.4 4.5 4.7 3.8.8 8.3-1.6 6.3-5.9l3.7.1Z"/></svg>',link:'<svg viewBox="0 0 24 24"><path d="M3.9,12C3.9,10.29 5.29,8.9 7,8.9H11V7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H11V15.1H7C5.29,15.1 3.9,13.71 3.9,12M8,13H16V11H8V13M17,7H13V8.9H17C18.71,8.9 20.1,10.29 20.1,12C20.1,13.71 18.71,15.1 17,15.1H13V17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7Z" /></svg>',image:'<svg viewBox="0 0 24 24"><path d="M19,19H5V5H19M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3M13.96,12.29L11.21,15.83L9.25,13.47L6.5,17H17.5L13.96,12.29Z"></path></svg>',listBullet:'<svg viewBox="0 0 24 24"><path d="M7 5h14v2H7V5m0 8v-2h14v2H7M4 4.5A1.5 1.5 0 0 1 5.5 6 1.5 1.5 0 0 1 4 7.5 1.5 1.5 0 0 1 2.5 6 1.5 1.5 0 0 1 4 4.5m0 6A1.5 1.5 0 0 1 5.5 12 1.5 1.5 0 0 1 4 13.5 1.5 1.5 0 0 1 2.5 12 1.5 1.5 0 0 1 4 10.5M7 19v-2h14v2H7m-3-2.5A1.5 1.5 0 0 1 5.5 18 1.5 1.5 0 0 1 4 19.5 1.5 1.5 0 0 1 2.5 18 1.5 1.5 0 0 1 4 16.5Z"/></svg>',listOrdered:'<svg viewBox="0 0 24 24"><path d="M7 13v-2h14v2H7m0 6v-2h14v2H7M7 7V5h14v2H7M3 8V5H2V4h2v4H3m-1 9v-1h3v4H2v-1h2v-.5H3v-1h1V17H2m2.3-7a.8.8 0 0 1 .7.8c0 .1 0 .3-.2.5L3 13h2v1H2v-1l2-2H2v-1h2.3Z"/></svg>',alignTextLeft:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M3,7H15V9H3V7M3,11H21V13H3V11M3,15H15V17H3V15M3,19H21V21H3V19Z" /></svg>',alignTextCenter:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M7,7H17V9H7V7M3,11H21V13H3V11M7,15H17V17H7V15M3,19H21V21H3V19Z" /></svg>',alignTextRight:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M9,7H21V9H9V7M3,11H21V13H3V11M9,15H21V17H9V15M3,19H21V21H3V19Z" /></svg>',alignTextJustify:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M3,7H21V9H3V7M3,11H21V13H3V11M3,15H21V17H3V15M3,19H21V21H3V19Z" /></svg>'},Dd=(n,e)=>{var a;const{editor:t,el:r}=n,i=Dn.get(r),s=Ml(i,t),o={separator:{type:"column",style:{borderRightWidth:"1px",borderRightStyle:"solid",alignSelf:"stretch",margin:3}},bold:{id:"bold",icon:ne.bold,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.bold.isActive()})}},onClick:({setState:c})=>{s.bold.toggle(),c({active:s.bold.isActive()})}},italic:{id:"italic",icon:ne.italic,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.italic.isActive()})}},onClick:({setState:c})=>{s.italic.toggle(),c({active:s.italic.isActive()})}},underline:{id:"underline",icon:ne.underline,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.underline.isActive()})}},onClick:({setState:c})=>{s.underline.toggle(),c({active:s.underline.isActive()})}},strikethrough:{id:"strikethrough",icon:ne.strikethrough,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.strikethrough.isActive()})}},onClick:({setState:c})=>{s.strikethrough.toggle(),c({active:s.strikethrough.isActive()})}},image:{id:"image",icon:ne.image,size:"s",type:"button",onClick:()=>s.image.open()},link:{id:"link",icon:ne.link,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.link.isActive(),disabled:i.state.selection.empty})}},onClick:({event:c})=>{const h=c.currentTarget||c.target,{x:f,y:d,width:p,height:u}=h.getBoundingClientRect(),m="linkLayout",g=()=>t.runCommand(Rt.layoutRemove,{id:m}),b=s.link.get(),S={id:m,style:{width:240},disablePropagation:!0,placer:{type:"popover",closeOnClickAway:!0,x:f,y:d,w:p,h:u},header:{label:"Link"},layout:{type:"column",as:"form",style:{padding:"0 10px 15px",gap:10},onSubmit:N=>{N.preventDefault();const v=new FormData(N.currentTarget);s.link.create({url:v.get("url"),target:v.get("target")}),g()},children:[{type:"inputField",name:"url",label:"URL",placeholder:"eg. https://google.com",required:!0,value:(b==null?void 0:b.href)||"",onChange:({value:N,setState:v})=>v({value:N})},{type:"selectField",name:"target",label:"Open link in",emptyState:"Current window",value:(b==null?void 0:b.target)||"",options:[{id:"",label:"Current window"},{id:"_blank",label:"New window"}],onChange:({value:N,setState:v})=>v({value:N})},{type:"row",style:{gap:10,justifyContent:"end"},children:[s.link.isActive()&&{type:"button",label:"Clear",buttonType:"button",onClick:()=>{s.link.toggle(),g()}},{type:"button",variant:"primary",label:"Submit",buttonType:"submit"}]}]}};t.runCommand(Rt.layoutToggle,S)}},alignText:{id:"alignText",type:"buttonGroupField",size:"s",value:"",options:[{id:"left",icon:ne.alignTextLeft},{id:"center",icon:ne.alignTextCenter},{id:"right",icon:ne.alignTextRight},{id:"justify",icon:ne.alignTextJustify}],editorEvents:{[oe]:({setState:c})=>{c({value:s.alignText.get()})}},onChange:({value:c,setState:h})=>{h({value:c}),s.alignText.set({value:c})}},listBullet:{id:"listBullet",icon:ne.listBullet,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.listBullet.isActive()})}},onClick:({setState:c})=>{s.listBullet.toggle(),c({active:s.listBullet.isActive()})}},listOrdered:{id:"listOrdered",icon:ne.listOrdered,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.listOrdered.isActive()})}},onClick:({setState:c})=>{s.listOrdered.toggle(),c({active:s.listOrdered.isActive()})}},heading:{id:"heading",type:"selectField",size:"s",value:"",emptyState:"Heading",options:[{id:"",label:"Normal"},{id:"1",label:"Heading 1"},{id:"2",label:"Heading 2"},{id:"3",label:"Heading 3"},{id:"4",label:"Heading 4"},{id:"5",label:"Heading 5"},{id:"6",label:"Heading 6"}],editorEvents:{[oe]:({setState:c})=>{c({value:s.heading.get()})}},onChange:({value:c,setState:h})=>{h({value:c}),s.heading.set({value:c}),i.focus()}},fontSize:{id:"fontSize",type:"selectField",size:"s",value:"",emptyState:"Font size",options:[{id:"8pt",label:"8pt"},{id:"10pt",label:"10pt"},{id:"12pt",label:"12pt"},{id:"14pt",label:"14pt"},{id:"18pt",label:"18pt"},{id:"24pt",label:"24pt"},{id:"36pt",label:"36pt"}],editorEvents:{[oe]:({setState:c})=>{c({value:s.fontSize.get()})}},onChange:({value:c,setState:h})=>{h({value:c}),s.fontSize.set({value:c}),i.focus()}}},l=[o.bold,o.italic,o.underline,o.strikethrough,o.image,o.link,o.listBullet,o.listOrdered,o.alignText,o.heading,o.fontSize];return((a=e.toolbar)==null?void 0:a.call(e,{...n,commands:s,layouts:o,proseMirror:{view:i},items:l}))||l};class Ed{constructor(e,t,r){this.editor=r,this.node=e,this.dom=document.createElement("img"),this.view=t,Object.keys(e.attrs.attrs).forEach(i=>{this.dom.setAttribute(i,e.attrs.attrs[i])}),this.dom.addEventListener("dblclick",i=>this.handleDoubleClick(i))}handleDoubleClick(e){const{editor:t,view:r}=this;Ml(r,t).image.open(),e.preventDefault()}update(e){return e.type!==this.node.type?!1:(this.node=e,Object.keys(e.attrs.attrs).forEach(t=>{this.dom.setAttribute(t,e.attrs.attrs[t])}),!0)}selectNode(){this.dom.style.outline="2px solid #ffca6f"}deselectNode(){this.dom.style.outline=""}}class Fe{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Rd(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}}function Rd(n){return function(e,t,r,i){let s=n;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),r+=o;let l=r-i;l>0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}const Id=500;function zd({rules:n}){let e=new Ft({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return ys(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&ys(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function ys(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-Id),l.parentOffset,null,"")+r;for(let c=0;c<i.length;c++){let h=i[c];if(l.parent.type.spec.code){if(!h.inCode)continue}else if(h.inCode==="only")continue;let f=h.match.exec(a),d=f&&h.handler(o,f,e-(f[0].length-r.length),t);if(d)return h.undoable&&d.setMeta(s,{transform:d,from:e,to:t,text:r}),n.dispatch(d),!0}return!1}const Vd=new Fe(/--$/,"—"),Pd=new Fe(/\.\.\.$/,"…"),Bd=new Fe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“"),Hd=new Fe(/"$/,"”"),Ld=new Fe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘"),Fd=new Fe(/'$/,"’"),Wd=[Bd,Hd,Ld,Fd];function qr(n,e,t=null,r){return new Fe(n,(i,s,o,l)=>{let a=t instanceof Function?t(s):t,c=i.tr.delete(o,l),h=c.doc.resolve(o),f=h.blockRange(),d=f&&oo(f,e,a);if(!d)return null;c.wrap(f,d);let p=c.doc.resolve(o-1).nodeBefore;return p&&p.type==e&&Mn(c.doc,o-1)&&(!r||r(s,p))&&c.join(o-1),c})}function vl(n,e,t=null){return new Fe(n,(r,i,s,o)=>{let l=r.doc.resolve(s),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(s,o).setBlockType(s,s,e,a):null})}function $d(n){return qr(/^\s*>\s$/,n)}function Jd(n){return qr(/^(\d+)\.\s$/,n,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order==+e[1])}function qd(n){return qr(/^\s*([-+*])\s$/,n)}function Kd(n){return vl(/^```$/,n)}function jd(n,e){return vl(new RegExp("^(#{1,"+e+"})\\s$"),n,t=>({level:t[1].length}))}function _d(n){const e=Wd.concat(Pd,Vd);let t;return(t=n.nodes.blockquote)&&e.push($d(t)),(t=n.nodes.orderedList)&&e.push(Jd(t)),(t=n.nodes.bulletList)&&e.push(qd(t)),(t=n.nodes.codeBlock)&&e.push(Kd(t)),(t=n.nodes.heading)&&e.push(jd(t,6)),zd({rules:e})}const Ud="rteProseMirror",Gd=function(n,e={}){const t={plugins:s=>s.plugins,...e},r=(s,o)=>{var p,u;const l=((p=t.schema)==null?void 0:p.call(t,{editor:n,schema:us}))||us,{nodes:a,marks:c}=l,h=ut.fromSchema(l).parse(s),f=lt.create({doc:h,schema:l,plugins:(u=t.plugins)==null?void 0:u.call(t,{editor:n,plugins:[Yf(),ad(),_d(l),Ic(),qn({Tab:ns(1),"Shift-Tab":ns(-1)}),qn({Enter:Vt(ko,Wc(a.listItem),gd),"Shift-Enter":Vt(wo,(m,g)=>(g&&g(m.tr.replaceSelectionWith(a.inlineBreak.create()).scrollIntoView()),!0)),"Mod-z":Do,"Mod-y":rr,"Mod-Shift-z":rr,"Mod-b":We(c.strong),"Mod-i":We(c.em),"Shift-Tab":ir(a.listItem),Tab:qc(a.listItem)}),qn(Mc)]})}),d=new Sf({mount:s},{state:f,dispatchTransaction(m){var v;const{state:g}=d,b=g.apply(m),S=!g.doc.eq(b.doc);d.updateState(b);const N=!g.selection.eq(b.selection);S&&(pd(((v=o==null?void 0:o.view)==null?void 0:v.el)||s),d.focus()),(N||S)&&n.trigger(oe)}});return s.__rteView=d,d.setProps({nodeViews:{image(m){return new Ed(m,d,n)}}}),d},i=s=>Dd(s,t);n.setCustomRte({toolbar:i,parseContent:!0,async enable(s,o,l){const a=r(s,l);return fd(s,a),Md(a,l),a},disable(s){const o=ps(s);if(o)return dd(s,o),o.destroy(),{forceSync:!0}},getContent(s){const o=ps(s);if(o){const{schema:l,doc:a}=o.state,c=document.createElement("div"),h=tt.fromSchema(l).serializeFragment(a.content);return h.childNodes.forEach(f=>{f.nodeType===Node.ELEMENT_NODE&&f.innerHTML===""&&(f.innerHTML="<br/>")}),c.appendChild(h),md(c),s.classList.remove("ProseMirror-focused"),c.innerHTML}return s.innerHTML}}),Sr({editor:n,licenseKey:t.licenseKey,pluginName:Ud,cleanup:()=>{n.RichTextEditor.customRte=void 0}})},Zd=kr(Gd);exports.dialogComponent=Ll;exports.rteProseMirror=Zd;exports.tableComponent=fa;
77
+ `);return{dom:a,text:d,slice:e}}function il(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=e&&(r||s||!t);if(a){if(n.someProp("transformPastedText",d=>{e=d(e,s||r,n)}),s)return e?new C(y.from(n.state.schema.text(e.replace(/\r\n?/g,`
78
+ `))),0,0):C.empty;let f=n.someProp("clipboardTextParser",d=>d(e,i,r,n));if(f)l=f;else{let d=i.marks(),{schema:p}=n.state,u=rt.fromSchema(p);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(u.serializeNode(p.text(m,d)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=Xh(t),jt&&Yh(o);let c=o&&o.querySelector("[data-pm-slice]"),h=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let f=+h[3];f>0;f--){let d=o.firstChild;for(;d&&d.nodeType!=1;)d=d.nextSibling;if(!d)break;o=d}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||gt.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||h),context:i,ruleFromNode(d){return d.nodeName=="BR"&&!d.nextSibling&&d.parentNode&&!Uh.test(d.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Qh(_i(l,+h[1],+h[2]),h[4]);else if(l=C.maxOpen(Gh(l.content,i),!0),l.openStart||l.openEnd){let f=0,d=0;for(let p=l.content.firstChild;f<l.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=l.content.lastChild;d<l.openEnd&&!p.type.spec.isolating;d++,p=p.lastChild);l=_i(l,f,d)}return n.someProp("transformPasted",f=>{l=f(l,n)}),l}const Uh=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Gh(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&ol(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=ll(o[o.length-1],s.length));let h=sl(l,a);o.push(h),i=i.matchType(h.type),s=a}}),o)return y.from(o)}return n}function sl(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,y.from(n));return n}function ol(n,e,t,r,i){if(i<n.length&&i<e.length&&n[i]==e[i]){let s=ol(n,e,t,r.lastChild,i+1);if(s)return r.copy(r.content.replaceChild(r.childCount-1,s));if(r.contentMatchAt(r.childCount).matchType(i==n.length-1?t.type:n[i+1]))return r.copy(r.content.append(y.from(sl(t,n,i+1))))}}function ll(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,ll(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(y.empty,!0);return n.copy(t.append(r))}function xr(n,e,t,r,i,s){let o=e<0?n.firstChild:n.lastChild,l=o.content;return n.childCount>1&&(s=0),i<r-1&&(l=xr(l,e,t,r,i+1,s)),i>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(y.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function _i(n,e,t){return e<n.openStart&&(n=new C(xr(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new C(xr(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const al={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Ui=null;function cl(){return Ui||(Ui=document.implementation.createHTMLDocument("title"))}let er=null;function Zh(n){let e=window.trustedTypes;return e?(er||(er=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),er.createHTML(n)):n}function Xh(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=cl().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&al[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=Zh(n),i)for(let s=0;s<i.length;s++)t=t.querySelector(i[s])||t;return t}function Yh(n){let e=n.querySelectorAll(q?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let r=e[t];r.childNodes.length==1&&r.textContent==" "&&r.parentNode&&r.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),r)}}function Qh(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return n}let{content:i,openStart:s,openEnd:o}=n;for(let l=r.length-2;l>=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=y.from(a.create(r[l+1],i)),s++,o++}return new C(i,s,o)}const U={},G={},ef={touchstart:!0,touchmove:!0};class tf{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function nf(n){for(let e in U){let t=U[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{sf(n,r)&&!Fr(n,r)&&(n.editable||!(r.type in G))&&t(n,r)},ef[e]?{passive:!0}:void 0)}_&&n.dom.addEventListener("input",()=>null),wr(n)}function ze(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function rf(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function wr(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Fr(n,r))})}function Fr(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function sf(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function of(n,e){!Fr(n,e)&&U[e.type]&&(n.editable||!(e.type in G))&&U[e.type](n,e)}G.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!fl(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(le&&q&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),xt&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,qe(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||_h(n,t)?t.preventDefault():ze(n,"key")};G.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};G.keypress=(n,e)=>{let t=e;if(fl(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||re&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof M)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function zn(n){return{left:n.clientX,top:n.clientY}}function lf(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Wr(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function pt(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function af(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&w.isSelectable(r)?(pt(n,new w(t)),!0):!1}function cf(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof w&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(w.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(pt(n,w.create(n.state.doc,i)),!0):!1}function hf(n,e,t,r,i){return Wr(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?cf(n,t):af(n,t))}function ff(n,e,t,r){return Wr(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function df(n,e,t,r){return Wr(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||uf(n,t,r)}function uf(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(pt(n,M.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)pt(n,M.create(r,l+1,l+1+o.content.size));else if(w.isSelectable(o))pt(n,w.create(r,l));else continue;return!0}}function $r(n){return xn(n)}const hl=re?"metaKey":"ctrlKey";U.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=$r(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&lf(t,n.input.lastClick)&&!t[hl]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(zn(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new pf(n,o,t,!!r)):(s=="doubleClick"?ff:df)(n,o.pos,o.inside,t)?t.preventDefault():ze(n,"pointer"))};class pf{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[hl],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.dom.nodeType==1?a.dom:null;let{selection:c}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof w&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ce&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),ze(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>ke(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(zn(e))),this.updateAllowDefault(e),this.allowDefault||!t?ze(this.view,"pointer"):hf(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||_&&this.mightDrag&&!this.mightDrag.node.isAtom||q&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(pt(this.view,S.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):ze(this.view,"pointer")}move(e){this.updateAllowDefault(e),ze(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}U.touchstart=n=>{n.input.lastTouch=Date.now(),$r(n),ze(n,"pointer")};U.touchmove=n=>{n.input.lastTouch=Date.now(),ze(n,"pointer")};U.contextmenu=n=>$r(n);function fl(n,e){return n.composing?!0:_&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const mf=le?5e3:-1;G.compositionstart=G.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof M&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),xn(n,!0),n.markCursor=null;else if(xn(n,!e.selection.empty),ce&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}dl(n,mf)};G.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,dl(n,20))};function dl(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>xn(n),e))}function ul(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=yf());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function gf(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=lh(e.focusNode,e.focusOffset),r=ah(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function yf(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function xn(n,e=!1){if(!(le&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),ul(n),e||n.docView&&n.docView.dirty){let t=Hr(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!n.state.selection.empty?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function bf(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const Ft=X&&Pe<15||xt&&uh<604;U.copy=G.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Ft?null:t.clipboardData,o=r.content(),{dom:l,text:a}=rl(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):bf(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Cf(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function xf(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Wt(n,r.value,null,i,e):Wt(n,r.textContent,r.innerHTML,i,e)},50)}function Wt(n,e,t,r,i){let s=il(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,s||C.empty)))return!0;if(!s)return!1;let o=Cf(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function pl(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}G.paste=(n,e)=>{let t=e;if(n.composing&&!le)return;let r=Ft?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Wt(n,pl(r),r.getData("text/html"),i,t)?t.preventDefault():xf(n,t)};class ml{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const gl=re?"altKey":"ctrlKey";U.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(zn(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof w?i.to-1:i.to))){if(r&&r.mightDrag)o=w.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=w.create(n.state.doc,f.posBefore))}}let l=(o||n.state.selection).content(),{dom:a,text:c,slice:h}=rl(n,l);(!t.dataTransfer.files.length||!q||Wo>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Ft?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Ft||t.dataTransfer.setData("text/plain",c),n.dragging=new ml(h,!t[gl],o)};U.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};G.dragover=G.dragenter=(n,e)=>e.preventDefault();G.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(zn(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",u=>{o=u(o,n)}):o=il(n,pl(t.dataTransfer),Ft?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[gl]);if(n.someProp("handleDrop",u=>u(n,t,o||C.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let a=o?uc(n.state.doc,s.pos,o):s.pos;a==null&&(a=s.pos);let c=n.state.tr;if(l){let{node:u}=r;u?u.replace(c):c.deleteSelection()}let h=c.mapping.map(a),f=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,d=c.doc;if(f?c.replaceRangeWith(h,h,o.content.firstChild):c.replaceRange(h,h,o),c.doc.eq(d))return;let p=c.doc.resolve(h);if(f&&w.isSelectable(o.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(o.content.firstChild))c.setSelection(new w(p));else{let u=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,b,k)=>u=k),c.setSelection(Lr(n,p,c.doc.resolve(u)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};U.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&ke(n)},20))};U.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};U.beforeinput=(n,e)=>{if(q&&le&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,qe(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in G)U[n]=G[n];function $t(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class wn{constructor(e,t){this.toDOM=e,this.spec=t||Ye,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new Z(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof wn&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&$t(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Be{constructor(e,t){this.attrs=e,this.spec=t||Ye}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new Z(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Be&&$t(this.attrs,e.attrs)&&$t(this.spec,e.spec)}static is(e){return e.type instanceof Be}destroy(){}}class Jr{constructor(e,t){this.attrs=e,this.spec=t||Ye}map(e,t,r,i){let s=e.mapResult(t.from+i,1);if(s.deleted)return null;let o=e.mapResult(t.to+i,-1);return o.deleted||o.pos<=s.pos?null:new Z(s.pos-r,o.pos-r,this)}valid(e,t){let{index:r,offset:i}=e.content.findIndex(t.from),s;return i==t.from&&!(s=e.child(r)).isText&&i+s.nodeSize==t.to}eq(e){return this==e||e instanceof Jr&&$t(this.attrs,e.attrs)&&$t(this.spec,e.spec)}destroy(){}}class Z{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new Z(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,r){return this.type.map(e,this,t,r)}static widget(e,t,r){return new Z(e,e,new wn(t,r))}static inline(e,t,r,i){return new Z(e,t,new Be(r,i))}static node(e,t,r,i){return new Z(e,t,new Jr(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Be}get widget(){return this.type instanceof wn}}const at=[],Ye={};class R{constructor(e,t){this.local=e.length?e:at,this.children=t.length?t:at}static create(e,t){return t.length?kn(t,e,0,Ye):$}find(e,t,r){let i=[];return this.findInner(e??0,t??1e9,i,0,r),i}findInner(e,t,r,i,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==$||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Ye)}mapInner(e,t,r,i,s){let o;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,r,i);a&&a.type.valid(t,a)?(o||(o=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?wf(this.children,o||[],e,t,r,i,s):o?new R(o.sort(Qe),at):$}add(e,t){return t.length?this==$?R.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let i,s=0;e.forEach((l,a)=>{let c=a+r,h;if(h=bl(t,l,c)){for(i||(i=this.children.slice());s<i.length&&i[s]<a;)s+=3;i[s]==a?i[s+2]=i[s+2].addInner(l,h,c+1):i.splice(s,0,a,a+l.nodeSize,kn(h,l,c+1,Ye)),s+=3}});let o=yl(s?Cl(t):t,-r);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new R(o.length?this.local.concat(o).sort(Qe):this.local,i||this.children)}remove(e){return e.length==0||this==$?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,i=this.local;for(let s=0;s<r.length;s+=3){let o,l=r[s]+t,a=r[s+1]+t;for(let h=0,f;h<e.length;h++)(f=e[h])&&f.from>l&&f.to<a&&(e[h]=null,(o||(o=[])).push(f));if(!o)continue;r==this.children&&(r=this.children.slice());let c=r[s+2].removeInner(o,l+1);c!=$?r[s+2]=c:(r.splice(s,3),s-=3)}if(i.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<i.length;l++)i[l].eq(o,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new R(i,r):$}forChild(e,t){if(this==$)return this;if(t.isLeaf)return R.empty;let r,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof Be){let c=Math.max(s,a.from)-s,h=Math.min(o,a.to)-s;c<h&&(i||(i=[])).push(a.copy(c,h))}}if(i){let l=new R(i.sort(Qe),at);return r?new De([l,r]):l}return r||$}eq(e){if(this==e)return!0;if(!(e instanceof R)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return qr(this.localsInner(e))}localsInner(e){if(this==$)return at;if(e.inlineContent||!this.local.some(Be.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Be||t.push(this.local[r]);return t}forEachSet(e){e(this)}}R.empty=new R([],[]);R.removeOverlap=qr;const $=R.empty;class De{constructor(e){this.members=e}map(e,t){const r=this.members.map(i=>i.map(e,t,Ye));return De.from(r)}forChild(e,t){if(t.isLeaf)return R.empty;let r=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=$&&(s instanceof De?r=r.concat(s.members):r.push(s))}return De.from(r)}eq(e){if(!(e instanceof De)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,r=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!t)t=s;else{r&&(t=t.slice(),r=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?qr(r?t:t.sort(Qe)):at}static from(e){switch(e.length){case 0:return $;case 1:return e[0];default:return new De(e.every(t=>t instanceof R)?e:e.reduce((t,r)=>t.concat(r instanceof R?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function wf(n,e,t,r,i,s,o){let l=n.slice();for(let c=0,h=s;c<t.maps.length;c++){let f=0;t.maps[c].forEach((d,p,u,m)=>{let g=m-u-(p-d);for(let b=0;b<l.length;b+=3){let k=l[b+1];if(k<0||d>k+h-f)continue;let O=l[b]+h-f;p>=O?l[b+1]=d<=O?-2:-1:d>=h&&g&&(l[b]+=g,l[b+1]+=g)}f+=g}),h=t.maps[c].map(h,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let h=t.map(n[c]+s),f=h-i;if(f<0||f>=r.content.size){a=!0;continue}let d=t.map(n[c+1]+s,-1),p=d-i,{index:u,offset:m}=r.content.findIndex(f),g=r.maybeChild(u);if(g&&m==f&&m+g.nodeSize==p){let b=l[c+2].mapInner(t,g,h+1,n[c]+s+1,o);b!=$?(l[c]=f,l[c+1]=p,l[c+2]=b):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=kf(l,n,e,t,i,s,o),h=kn(c,r,0,o);e=h.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,d=0;f<h.children.length;f+=3){let p=h.children[f];for(;d<l.length&&l[d]<p;)d+=3;l.splice(d,0,h.children[f],h.children[f+1],h.children[f+2])}}return new R(e.sort(Qe),l)}function yl(n,e){if(!e||!n.length)return n;let t=[];for(let r=0;r<n.length;r++){let i=n[r];t.push(new Z(i.from+e,i.to+e,i.type))}return t}function kf(n,e,t,r,i,s,o){function l(a,c){for(let h=0;h<a.local.length;h++){let f=a.local[h].map(r,i,c);f?t.push(f):o.onRemove&&o.onRemove(a.local[h].spec)}for(let h=0;h<a.children.length;h+=3)l(a.children[h+2],a.children[h]+c+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+s+1);return t}function bl(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,i=null;for(let s=0,o;s<n.length;s++)(o=n[s])&&o.from>t&&o.to<r&&((i||(i=[])).push(o),n[s]=null);return i}function Cl(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function kn(n,e,t,r){let i=[],s=!1;e.forEach((l,a)=>{let c=bl(n,l,a+t);if(c){s=!0;let h=kn(c,l,t+a+1,r);h!=$&&i.push(a,a+l.nodeSize,h)}});let o=yl(s?Cl(n):n,-t).sort(Qe);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(r.onRemove&&r.onRemove(o[l].spec),o.splice(l--,1));return o.length||i.length?new R(o,i):$}function Qe(n,e){return n.from-e.from||n.to-e.to}function qr(n){let e=n;for(let t=0;t<e.length-1;t++){let r=e[t];if(r.from!=r.to)for(let i=t+1;i<e.length;i++){let s=e[i];if(s.from==r.from){s.to!=r.to&&(e==n&&(e=n.slice()),e[i]=s.copy(s.from,r.to),Gi(e,i+1,s.copy(r.to,s.to)));continue}else{s.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,s.from),Gi(e,i,r.copy(s.from,r.to)));break}}}return e}function Gi(n,e,t){for(;e<n.length&&Qe(t,n[e])>0;)e++;n.splice(e,0,t)}function tr(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=$&&e.push(r)}),n.cursorWrapper&&e.push(R.create(n.state.doc,[n.cursorWrapper.deco])),De.from(e)}const Sf={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Mf=X&&Pe<=11;class vf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class Of{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new vf,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;i<r.length;i++)this.queue.push(r[i]);X&&Pe<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Mf&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Sf)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Wi(this.view)){if(this.suppressingSelectionUpdates)return ke(this.view);if(X&&Pe<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&tt(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=Lt(s))t.add(s);for(let s=e.anchorNode;s;s=Lt(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Wi(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let h=0;h<t.length;h++){let f=this.registerMutation(t[h],a);f&&(s=s<0?f.from:Math.min(f.from,s),o=o<0?f.to:Math.max(f.to,o),f.typeOver&&(l=!0))}if(ce&&a.length){let h=a.filter(f=>f.nodeName=="BR");if(h.length==2){let[f,d]=h;f.parentNode&&f.parentNode.parentNode==d.parentNode?d.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let d of h){let p=d.parentNode;p&&p.nodeName=="LI"&&(!f||Tf(e,f)!=p)&&d.remove()}}}let c=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Rn(r)&&(c=Hr(e))&&c.eq(S.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ke(e),this.currentSelection.set(r),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),Nf(e)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||ke(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;h<e.addedNodes.length;h++){let f=e.addedNodes[h];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let i=e.previousSibling,s=e.nextSibling;if(X&&Pe<=11&&e.addedNodes.length)for(let h=0;h<e.addedNodes.length;h++){let{previousSibling:f,nextSibling:d}=e.addedNodes[h];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!d||Array.prototype.indexOf.call(e.addedNodes,d)<0)&&(s=d)}let o=i&&i.parentNode==e.target?F(i)+1:0,l=r.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?F(s):e.target.childNodes.length,c=r.localPosFromDOM(e.target,a,1);return{from:l,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let Zi=new WeakMap,Xi=!1;function Nf(n){if(!Zi.has(n)&&(Zi.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=ce,Xi)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),Xi=!0}}function Yi(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,s=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return tt(o.node,o.offset,i,s)&&([t,r,i,s]=[i,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}}function Af(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Yi(n,i)}let t;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",r,!0),t?Yi(n,t):null}function Tf(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let r=n.docView.nearestDesc(t,!0);if(r&&r.node.isBlock)return t}return null}function Df(n,e,t){let{node:r,fromOffset:i,toOffset:s,from:o,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),c,h=a.anchorNode;if(h&&n.dom.contains(h.nodeType==1?h:h.parentNode)&&(c=[{node:h,offset:a.anchorOffset}],Rn(a)||c.push({node:a.focusNode,offset:a.focusOffset})),q&&n.input.lastKeyCode===8)for(let g=s;g>i;g--){let b=r.childNodes[g-1],k=b.pmViewDesc;if(b.nodeName=="BR"&&!k){s=g;break}if(!k||k.size)break}let f=n.state.doc,d=n.someProp("domParser")||gt.fromSchema(n.state.schema),p=f.resolve(o),u=null,m=d.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Ef,context:p});if(c&&c[0].pos!=null){let g=c[0].pos,b=c[1]&&c[1].pos;b==null&&(b=g),u={anchor:g+o,head:b+o}}return{doc:m,sel:u,from:o,to:l}}function Ef(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(_&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||_&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Rf=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function If(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let N=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,ve=Hr(n,N);if(ve&&!n.state.selection.eq(ve)){if(q&&le&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",zl=>zl(n,qe(13,"Enter"))))return;let Gt=n.state.tr.setSelection(ve);N=="pointer"?Gt.setMeta("pointer",!0):N=="key"&&Gt.scrollIntoView(),s&&Gt.setMeta("composition",s),n.dispatch(Gt)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=Df(n,e,t),h=n.state.doc,f=h.slice(c.from,c.to),d,p;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(d=n.state.selection.to,p="end"):(d=n.state.selection.from,p="start"),n.input.lastKeyCode=null;let u=Vf(f.content,c.doc.content,c.from,d,p);if(u&&n.input.domChangeCount++,(xt&&n.input.lastIOSEnter>Date.now()-225||le)&&i.some(N=>N.nodeType==1&&!Rf.test(N.nodeName))&&(!u||u.endA>=u.endB)&&n.someProp("handleKeyDown",N=>N(n,qe(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!u)if(r&&a instanceof M&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))u={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let N=Qi(n,n.state.doc,c.sel);if(N&&!N.eq(n.state.selection)){let ve=n.state.tr.setSelection(N);s&&ve.setMeta("composition",s),n.dispatch(ve)}}return}n.state.selection.from<n.state.selection.to&&u.start==u.endB&&n.state.selection instanceof M&&(u.start>n.state.selection.from&&u.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?u.start=n.state.selection.from:u.endA<n.state.selection.to&&u.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(u.endB+=n.state.selection.to-u.endA,u.endA=n.state.selection.to)),X&&Pe<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>c.from&&c.doc.textBetween(u.start-c.from-1,u.start-c.from+1)=="  "&&(u.start--,u.endA--,u.endB--);let m=c.doc.resolveNoCache(u.start-c.from),g=c.doc.resolveNoCache(u.endB-c.from),b=h.resolve(u.start),k=m.sameParent(g)&&m.parent.inlineContent&&b.end()>=u.endA,O;if((xt&&n.input.lastIOSEnter>Date.now()-225&&(!k||i.some(N=>N.nodeName=="DIV"||N.nodeName=="P"))||!k&&m.pos<c.doc.content.size&&!m.sameParent(g)&&(O=S.findFrom(c.doc.resolve(m.pos+1),1,!0))&&O.head==g.pos)&&n.someProp("handleKeyDown",N=>N(n,qe(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>u.start&&Pf(h,u.start,u.endA,m,g)&&n.someProp("handleKeyDown",N=>N(n,qe(8,"Backspace")))){le&&q&&n.domObserver.suppressSelectionUpdates();return}q&&le&&u.endB==u.start&&(n.input.lastAndroidDelete=Date.now()),le&&!k&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==u.endA&&(u.endB-=2,g=c.doc.resolveNoCache(u.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(N){return N(n,qe(13,"Enter"))})},20));let v=u.start,E=u.endA,T,j,Me;if(k){if(m.pos==g.pos)X&&Pe<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>ke(n),20)),T=n.state.tr.delete(v,E),j=h.resolve(u.start).marksAcross(h.resolve(u.endA));else if(u.endA==u.endB&&(Me=zf(m.parent.content.cut(m.parentOffset,g.parentOffset),b.parent.content.cut(b.parentOffset,u.endA-b.start()))))T=n.state.tr,Me.type=="add"?T.addMark(v,E,Me.mark):T.removeMark(v,E,Me.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let N=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",ve=>ve(n,v,E,N)))return;T=n.state.tr.insertText(N,v,E)}}if(T||(T=n.state.tr.replace(v,E,c.doc.slice(u.start-c.from,u.endB-c.from))),c.sel){let N=Qi(n,T.doc,c.sel);N&&!(q&&le&&n.composing&&N.empty&&(u.start!=u.endB||n.input.lastAndroidDelete<Date.now()-100)&&(N.head==v||N.head==T.mapping.map(E)-1)||X&&N.empty&&N.head==v)&&T.setSelection(N)}j&&T.ensureMarks(j),s&&T.setMeta("composition",s),n.dispatch(T.scrollIntoView())}function Qi(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Lr(n,e.resolve(t.anchor),e.resolve(t.head))}function zf(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,a;for(let h=0;h<r.length;h++)i=r[h].removeFromSet(i);for(let h=0;h<t.length;h++)s=t[h].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",a=h=>h.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=h=>h.mark(l.removeFromSet(h.marks));else return null;let c=[];for(let h=0;h<e.childCount;h++)c.push(a(e.child(h)));if(y.from(c).eq(n))return{mark:l,type:o}}function Pf(n,e,t,r,i){if(t-e<=i.pos-r.pos||nr(r,!0,!1)<i.pos)return!1;let s=n.resolve(e);if(!r.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=n.resolve(nr(s,!0,!0));return!o.parent.isTextblock||o.pos>t||nr(o,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function nr(n,e,t){let r=n.depth,i=e?n.end():n.pos;for(;r>0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function Vf(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));r-=o+a-s}if(o<s&&n.size<e.size){let a=r<=s&&r>=o?s-r:0;s-=a,s&&s<e.size&&es(e.textBetween(s-1,s+1))&&(s+=a?1:-1),l=s+(l-o),o=s}else if(l<s){let a=r<=s&&r>=l?s-r:0;s-=a,s&&s<n.size&&es(n.textBetween(s-1,s+1))&&(s+=a?1:-1),o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}function es(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class Bf{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new tf,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ss),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=rs(this),ns(this),this.nodeViews=is(this),this.docView=Pi(this.state.doc,ts(this),tr(this),this.dom,this),this.domObserver=new Of(this,(r,i,s,o)=>If(this,r,i,s,o)),this.domObserver.start(),nf(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&wr(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ss),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(ul(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=is(this);Lf(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&wr(this),this.editable=rs(this),ns(this);let a=tr(this),c=ts(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,c,a);(f||!e.selection.eq(i.selection))&&(o=!0);let d=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&gh(this);if(o){this.domObserver.stop();let p=f&&(X||q)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Hf(i.selection,e.selection);if(f){let u=q?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=gf(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Pi(e.doc,c,a,this.dom,this)),u&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Fh(this))?ke(this,p):(el(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():d&&yh(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof w){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ti(this,t.getBoundingClientRect(),e)}else Ti(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let r=this.directPlugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let r=this.state.plugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let r=this.pluginViews[t];r.update&&r.update(this,e)}}updateDraggedNode(e,t){let r=e.node,i=-1;if(this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let s=r.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ml(e.slice,e.move,i<0?void 0:w.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(i=t?t(l):l))return i}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(X){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&bh(this.dom),ke(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Sh(this,e)}coordsAtPos(e,t=1){return jo(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Ah(this,t||this.state,e)}pasteHTML(e,t){return Wt(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Wt(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(rf(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],tr(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,sh())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return of(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return e?_&&this.root.nodeType===11&&hh(this.dom.ownerDocument)==this.dom&&Af(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function ts(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[Z.node(0,n.state.doc.content.size,e)]}function ns(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Z.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function rs(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Hf(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function is(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Lf(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function ss(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var kr,Sr;if(typeof WeakMap<"u"){let n=new WeakMap;kr=e=>n.get(e),Sr=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;kr=r=>{for(let i=0;i<n.length;i+=2)if(n[i]==r)return n[i+1]},Sr=(r,i)=>(t==10&&(t=0),n[t++]=r,n[t++]=i)}var z=class{constructor(n,e,t,r){this.width=n,this.height=e,this.map=t,this.problems=r}findCell(n){for(let e=0;e<this.map.length;e++){const t=this.map[e];if(t!=n)continue;const r=e%this.width,i=e/this.width|0;let s=r+1,o=i+1;for(let l=1;s<this.width&&this.map[e+l]==t;l++)s++;for(let l=1;o<this.height&&this.map[e+this.width*l]==t;l++)o++;return{left:r,top:i,right:s,bottom:o}}throw new RangeError(`No cell with offset ${n} found`)}colCount(n){for(let e=0;e<this.map.length;e++)if(this.map[e]==n)return e%this.width;throw new RangeError(`No cell with offset ${n} found`)}nextCell(n,e,t){const{left:r,right:i,top:s,bottom:o}=this.findCell(n);return e=="horiz"?(t<0?r==0:i==this.width)?null:this.map[s*this.width+(t<0?r-1:i)]:(t<0?s==0:o==this.height)?null:this.map[r+this.width*(t<0?s-1:o)]}rectBetween(n,e){const{left:t,right:r,top:i,bottom:s}=this.findCell(n),{left:o,right:l,top:a,bottom:c}=this.findCell(e);return{left:Math.min(t,o),top:Math.min(i,a),right:Math.max(r,l),bottom:Math.max(s,c)}}cellsInRect(n){const e=[],t={};for(let r=n.top;r<n.bottom;r++)for(let i=n.left;i<n.right;i++){const s=r*this.width+i,o=this.map[s];t[o]||(t[o]=!0,!(i==n.left&&i&&this.map[s-1]==o||r==n.top&&r&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(n,e,t){for(let r=0,i=0;;r++){const s=i+t.child(r).nodeSize;if(r==n){let o=e+n*this.width;const l=(n+1)*this.width;for(;o<l&&this.map[o]<i;)o++;return o==l?s-1:this.map[o]}i=s}}static get(n){return kr(n)||Sr(n,Ff(n))}};function Ff(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);const e=Wf(n),t=n.childCount,r=[];let i=0,s=null;const o=[];for(let c=0,h=e*t;c<h;c++)r[c]=0;for(let c=0,h=0;c<t;c++){const f=n.child(c);h++;for(let u=0;;u++){for(;i<r.length&&r[i]!=0;)i++;if(u==f.childCount)break;const m=f.child(u),{colspan:g,rowspan:b,colwidth:k}=m.attrs;for(let O=0;O<b;O++){if(O+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:b-O});break}const v=i+O*e;for(let E=0;E<g;E++){r[v+E]==0?r[v+E]=h:(s||(s=[])).push({type:"collision",row:c,pos:h,n:g-E});const T=k&&k[E];if(T){const j=(v+E)%e*2,Me=o[j];Me==null||Me!=T&&o[j+1]==1?(o[j]=T,o[j+1]=1):Me==T&&o[j+1]++}}}i+=g,h+=m.nodeSize}const d=(c+1)*e;let p=0;for(;i<d;)r[i++]==0&&p++;p&&(s||(s=[])).push({type:"missing",row:c,n:p}),h++}const l=new z(e,t,r,s);let a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&$f(l,o,n),l}function Wf(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){const i=n.child(r);let s=0;if(t)for(let o=0;o<r;o++){const l=n.child(o);for(let a=0;a<l.childCount;a++){const c=l.child(a);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){const l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function $f(n,e,t){n.problems||(n.problems=[]);const r={};for(let i=0;i<n.map.length;i++){const s=n.map[i];if(r[s])continue;r[s]=!0;const o=t.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let l=null;const a=o.attrs;for(let c=0;c<a.colspan;c++){const h=(i+c)%n.width,f=e[h*2];f!=null&&(!a.colwidth||a.colwidth[c]!=f)&&((l||(l=Jf(a)))[c]=f)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function Jf(n){if(n.colwidth)return n.colwidth.slice();const e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function ls(n,e){if(typeof n=="string")return{};const t=n.getAttribute("data-colwidth"),r=t&&/^\d+(,\d+)*$/.test(t)?t.split(",").map(o=>Number(o)):null,i=Number(n.getAttribute("colspan")||1),s={colspan:i,rowspan:Number(n.getAttribute("rowspan")||1),colwidth:r&&r.length==i?r:null};for(const o in e){const l=e[o].getFromDOM,a=l&&l(n);a!=null&&(s[o]=a)}return s}function as(n,e){const t={};n.attrs.colspan!=1&&(t.colspan=n.attrs.colspan),n.attrs.rowspan!=1&&(t.rowspan=n.attrs.rowspan),n.attrs.colwidth&&(t["data-colwidth"]=n.attrs.colwidth.join(","));for(const r in e){const i=e[r].setDOMAttr;i&&i(n.attrs[r],t)}return t}function qf(n){const e=n.cellAttributes||{},t={colspan:{default:1},rowspan:{default:1},colwidth:{default:null}};for(const r in e)t[r]={default:e[r].default};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:n.tableGroup,parseDOM:[{tag:"table"}],toDOM(){return["table",["tbody",0]]}},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM(){return["tr",0]}},table_cell:{content:n.cellContent,attrs:t,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:r=>ls(r,e)}],toDOM(r){return["td",as(r,e),0]}},table_header:{content:n.cellContent,attrs:t,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:r=>ls(r,e)}],toDOM(r){return["th",as(r,e),0]}}}}function me(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}var Ee=new qt("selectingCells");function Ut(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function Pn(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Kr(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=Ut(e.$head)||Kf(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function Kf(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function Mr(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function jf(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function jr(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function xl(n,e,t){const r=n.node(-1),i=z.get(r),s=n.start(-1),o=i.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function wt(n,e,t=1){const r={...n,colspan:n.colspan-t};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}var B=class Ce extends S{constructor(e,t=e){const r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(h=>h!=t.pos-s);a.unshift(t.pos-s);const c=a.map(h=>{const f=r.nodeAt(h);if(!f)throw RangeError(`No cell with offset ${h} found`);const d=s+h+1;return new So(l.resolve(d),l.resolve(d+f.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){const r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(Mr(r)&&Mr(i)&&jr(r,i)){const s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Ce.rowSelection(r,i):s&&this.isColSelection()?Ce.colSelection(r,i):new Ce(r,i)}return M.between(r,i)}content(){const e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let a=i.top;a<i.bottom;a++){const c=[];for(let h=a*t.width+i.left,f=i.left;f<i.right;f++,h++){const d=t.map[h];if(s[d])continue;s[d]=!0;const p=t.findCell(d);let u=e.nodeAt(d);if(!u)throw RangeError(`No cell with offset ${d} found`);const m=i.left-p.left,g=p.right-i.right;if(m>0||g>0){let b=u.attrs;if(m>0&&(b=wt(b,0,m)),g>0&&(b=wt(b,b.colspan-g,g)),p.left<i.left){if(u=u.type.createAndFill(b),!u)throw RangeError(`Could not create cell with attrs ${JSON.stringify(b)}`)}else u=u.type.create(b,u.content)}if(p.top<i.top||p.bottom>i.bottom){const b={...u.attrs,rowspan:Math.min(p.bottom,i.bottom)-Math.max(p.top,i.top)};p.top<i.top?u=u.type.createAndFill(b):u=u.type.create(b,u.content)}c.push(u)}o.push(e.child(a).copy(y.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new C(y.from(l),1,1)}replace(e,t=C.empty){const r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){const{$from:l,$to:a}=i[o],c=e.mapping.slice(r);e.replace(c.map(l.pos),c.map(a.pos),o?C.empty:t)}const s=S.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new C(y.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),r=z.get(t),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(s+i.map[o.left])),l.bottom<i.height&&(t=a.resolve(s+i.map[i.width*(i.height-1)+l.right-1]))):(l.top>0&&(t=a.resolve(s+i.map[l.left])),o.bottom<i.height&&(e=a.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new Ce(e,t)}isRowSelection(){const e=this.$anchorCell.node(-1),t=z.get(e),r=this.$anchorCell.start(-1),i=t.colCount(this.$anchorCell.pos-r),s=t.colCount(this.$headCell.pos-r);if(Math.min(i,s)>0)return!1;const o=i+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof Ce&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const r=e.node(-1),i=z.get(r),s=e.start(-1),o=i.findCell(e.pos-s),l=i.findCell(t.pos-s),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(s+i.map[o.top*i.width])),l.right<i.width&&(t=a.resolve(s+i.map[i.width*(l.top+1)-1]))):(l.left>0&&(t=a.resolve(s+i.map[l.top*i.width])),o.right<i.width&&(e=a.resolve(s+i.map[i.width*(o.top+1)-1]))),new Ce(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Ce(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Ce(e.resolve(t),e.resolve(r))}getBookmark(){return new _f(this.$anchorCell.pos,this.$headCell.pos)}};B.prototype.visible=!1;S.jsonID("cell",B);var _f=class wl{constructor(e,t){this.anchor=e,this.head=t}map(e){return new wl(e.map(this.anchor),e.map(this.head))}resolve(e){const t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&jr(t,r)?new B(t,r):S.near(r,1)}};function Uf(n){if(!(n.selection instanceof B))return null;const e=[];return n.selection.forEachCell((t,r)=>{e.push(Z.node(r,r+t.nodeSize,{class:"selectedCell"}))}),R.create(n.doc,e)}function Gf({$from:n,$to:e}){if(n.pos==e.pos||n.pos<e.pos-6)return!1;let t=n.pos,r=e.pos,i=n.depth;for(;i>=0&&!(n.after(i+1)<n.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function Zf({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){const s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){const s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function Xf(n,e,t){const r=(e||n).selection,i=(e||n).doc;let s,o;if(r instanceof w&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=B.create(i,r.from);else if(o=="row"){const l=i.resolve(r.from+1);s=B.rowSelection(l,l)}else if(!t){const l=z.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];s=B.create(i,a+1,c)}}else r instanceof M&&Gf(r)?s=M.create(i,r.from):r instanceof M&&Zf(r)&&(s=M.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}var Yf=new qt("fix-tables");function kl(n,e,t,r){const i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){const a=e.child(o);for(let c=l,h=Math.min(i,o+3);c<h;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}r(a,t),l<i&&n.child(l).sameMarkup(a)?kl(n.child(l),a,t+1,r):a.nodesBetween(0,a.content.size,r,t+1),t+=a.nodeSize}}function Qf(n,e){let t;const r=(i,s)=>{i.type.spec.tableRole=="table"&&(t=ed(n,i,s,t))};return e?e.doc!=n.doc&&kl(e.doc,n.doc,0,r):n.doc.descendants(r),t}function ed(n,e,t,r){const i=z.get(e);if(!i.problems)return r;r||(r=n.tr);const s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){const c=i.problems[a];if(c.type=="collision"){const h=e.nodeAt(c.pos);if(!h)continue;const f=h.attrs;for(let d=0;d<f.rowspan;d++)s[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(f,f.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const h=e.nodeAt(c.pos);if(!h)continue;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,{...h.attrs,rowspan:h.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const h=e.nodeAt(c.pos);if(!h)continue;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,{...h.attrs,colwidth:c.colwidth})}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){const h=e.child(a),f=c+h.nodeSize,d=s[a];if(d>0){let p="cell";h.firstChild&&(p=h.firstChild.type.spec.tableRole);const u=[];for(let g=0;g<d;g++){const b=me(n.schema)[p].createAndFill();b&&u.push(b)}const m=(a==0||o==a-1)&&l==a?c+1:f-1;r.insert(r.mapping.map(m),u)}c=f}return r.setMeta(Yf,{fixTables:!0})}function Sl(n){const e=n.selection,t=Kr(n),r=t.node(-1),i=t.start(-1),s=z.get(r);return{...e instanceof B?s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):s.findCell(t.pos-i),tableStart:i,map:s,table:r}}function td(n){return function(e,t){if(!Pn(e))return!1;if(t){const r=me(e.schema),i=Sl(e),s=e.tr,o=i.map.cellsInRect(n=="column"?{left:i.left,top:0,right:i.right,bottom:i.map.height}:n=="row"?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[a],r.cell,l[a].attrs);if(s.steps.length==0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],r.header_cell,l[a].attrs);t(s)}return!0}}function cs(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function _r(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?td(n):function(t,r){if(!Pn(t))return!1;if(r){const i=me(t.schema),s=Sl(t),o=t.tr,l=cs("row",s,i),a=cs("column",s,i),h=(n==="column"?l:n==="row"?a:!1)?1:0,f=n=="column"?{left:0,top:h,right:1,bottom:s.map.height}:n=="row"?{left:h,top:0,right:s.map.width,bottom:1}:s,d=n=="column"?a?i.cell:i.header_cell:n=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(f).forEach(p=>{const u=p+s.tableStart,m=o.doc.nodeAt(u);m&&o.setNodeMarkup(u,d,m.attrs)}),r(o)}return!0}}_r("row",{useDeprecatedLogic:!0});_r("column",{useDeprecatedLogic:!0});_r("cell",{useDeprecatedLogic:!0});function nd(n,e){if(e<0){const t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){const s=n.node(-1).child(r),o=s.lastChild;if(o)return i-1-o.nodeSize;i-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;const t=n.node(-1);for(let r=n.indexAfter(-1),i=n.after();r<t.childCount;r++){const s=t.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}return null}function hs(n){return function(e,t){if(!Pn(e))return!1;const r=nd(Kr(e),n);if(r==null)return!1;if(t){const i=e.doc.resolve(r);t(e.tr.setSelection(M.between(i,jf(i))).scrollIntoView())}return!0}}function Qt(n,e){const t=n.selection;if(!(t instanceof B))return!1;if(e){const r=n.tr,i=me(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new C(i,0,0))}),r.docChanged&&e(r)}return!0}function rd(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.child(0).type.spec.tableRole=="table");)t--,r--,e=e.child(0).content;const i=e.child(0),s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content;const h=a?0:Math.max(0,t-1),f=a<e.childCount-1?0:Math.max(0,r-1);(h||f)&&(c=vr(me(o).row,new C(c,h,f)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||r?vr(me(o).row,new C(e,t,r)).content:e);else return null;return id(o,l)}function id(n,e){const t=[];for(let i=0;i<e.length;i++){const s=e[i];for(let o=s.childCount-1;o>=0;o--){const{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let r=0;for(let i=0;i<t.length;i++)r=Math.max(r,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(y.empty),t[i]<r){const s=me(n).cell.createAndFill(),o=[];for(let l=t[i];l<r;l++)o.push(s);e[i]=e[i].append(y.from(o))}return{height:e.length,width:r,rows:e}}function vr(n,e){const t=n.createAndFill();return new ko(t).replace(0,t.content.size,e).doc}function sd({width:n,height:e,rows:t},r,i){if(n!=r){const s=[],o=[];for(let l=0;l<t.length;l++){const a=t[l],c=[];for(let h=s[l]||0,f=0;h<r;f++){let d=a.child(f%a.childCount);h+d.attrs.colspan>r&&(d=d.type.createChecked(wt(d.attrs,d.attrs.colspan,h+d.attrs.colspan-r),d.content)),c.push(d),h+=d.attrs.colspan;for(let p=1;p<d.attrs.rowspan;p++)s[l+p]=(s[l+p]||0)+d.attrs.colspan}o.push(y.from(c))}t=o,n=r}if(e!=i){const s=[];for(let o=0,l=0;o<i;o++,l++){const a=[],c=t[l%e];for(let h=0;h<c.childCount;h++){let f=c.child(h);o+f.attrs.rowspan>i&&(f=f.type.create({...f.attrs,rowspan:Math.max(1,i-f.attrs.rowspan)},f.content)),a.push(f)}s.push(y.from(a))}t=s,e=i}return{width:n,height:e,rows:t}}function od(n,e,t,r,i,s,o){const l=n.doc.type.schema,a=me(l);let c,h;if(i>e.width)for(let f=0,d=0;f<e.height;f++){const p=t.child(f);d+=p.nodeSize;const u=[];let m;p.lastChild==null||p.lastChild.type==a.cell?m=c||(c=a.cell.createAndFill()):m=h||(h=a.header_cell.createAndFill());for(let g=e.width;g<i;g++)u.push(m);n.insert(n.mapping.slice(o).map(d-1+r),u)}if(s>e.height){const f=[];for(let u=0,m=(e.height-1)*e.width;u<Math.max(e.width,i);u++){const g=u>=e.width?!1:t.nodeAt(e.map[m+u]).type==a.header_cell;f.push(g?h||(h=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const d=a.row.create(null,y.from(f)),p=[];for(let u=e.height;u<s;u++)p.push(d);n.insert(n.mapping.slice(o).map(r+t.nodeSize-2),p)}return!!(c||h)}function fs(n,e,t,r,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){const h=o*e.width+c,f=e.map[h];if(e.map[h-e.width]==f){a=!0;const d=t.nodeAt(f),{top:p,left:u}=e.findCell(f);n.setNodeMarkup(n.mapping.slice(l).map(f+r),null,{...d.attrs,rowspan:o-p}),n.insert(n.mapping.slice(l).map(e.positionAt(o,u,t)),d.type.createAndFill({...d.attrs,rowspan:p+d.attrs.rowspan-o})),c+=d.attrs.colspan-1}}return a}function ds(n,e,t,r,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){const h=c*e.width+o,f=e.map[h];if(e.map[h-1]==f){a=!0;const d=t.nodeAt(f),p=e.colCount(f),u=n.mapping.slice(l).map(f+r);n.setNodeMarkup(u,null,wt(d.attrs,o-p,d.attrs.colspan-(o-p))),n.insert(u+d.nodeSize,d.type.createAndFill(wt(d.attrs,0,o-p))),c+=d.attrs.rowspan-1}}return a}function us(n,e,t,r,i){let s=t?n.doc.nodeAt(t-1):n.doc;if(!s)throw new Error("No table found");let o=z.get(s);const{top:l,left:a}=r,c=a+i.width,h=l+i.height,f=n.tr;let d=0;function p(){if(s=t?f.doc.nodeAt(t-1):f.doc,!s)throw new Error("No table found");o=z.get(s),d=f.mapping.maps.length}od(f,o,s,t,c,h,d)&&p(),fs(f,o,s,t,a,c,l,d)&&p(),fs(f,o,s,t,a,c,h,d)&&p(),ds(f,o,s,t,l,h,a,d)&&p(),ds(f,o,s,t,l,h,c,d)&&p();for(let u=l;u<h;u++){const m=o.positionAt(u,a,s),g=o.positionAt(u,c,s);f.replace(f.mapping.slice(d).map(m+t),f.mapping.slice(d).map(g+t),new C(i.rows[u-l],0,0))}p(),f.setSelection(new B(f.doc.resolve(t+o.positionAt(l,a,s)),f.doc.resolve(t+o.positionAt(h-1,c-1,s)))),e(f)}var ld=Lo({ArrowLeft:en("horiz",-1),ArrowRight:en("horiz",1),ArrowUp:en("vert",-1),ArrowDown:en("vert",1),"Shift-ArrowLeft":tn("horiz",-1),"Shift-ArrowRight":tn("horiz",1),"Shift-ArrowUp":tn("vert",-1),"Shift-ArrowDown":tn("vert",1),Backspace:Qt,"Mod-Backspace":Qt,Delete:Qt,"Mod-Delete":Qt});function ln(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function en(n,e){return(t,r,i)=>{if(!i)return!1;const s=t.selection;if(s instanceof B)return ln(t,r,S.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;const o=Ml(i,n,e);if(o==null)return!1;if(n=="horiz")return ln(t,r,S.near(t.doc.resolve(s.head+e),e));{const l=t.doc.resolve(o),a=xl(l,n,e);let c;return a?c=S.near(a,1):e<0?c=S.near(t.doc.resolve(l.before(-1)),-1):c=S.near(t.doc.resolve(l.after(-1)),1),ln(t,r,c)}}}function tn(n,e){return(t,r,i)=>{if(!i)return!1;const s=t.selection;let o;if(s instanceof B)o=s;else{const a=Ml(i,n,e);if(a==null)return!1;o=new B(t.doc.resolve(a))}const l=xl(o.$headCell,n,e);return l?ln(t,r,new B(o.$anchorCell,l)):!1}}function ad(n,e){const t=n.state.doc,r=Ut(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new B(r))),!0):!1}function cd(n,e,t){if(!Pn(n.state))return!1;let r=rd(t);const i=n.state.selection;if(i instanceof B){r||(r={width:1,height:1,rows:[y.from(vr(me(n.state.schema).cell,t))]});const s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=z.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=sd(r,l.right-l.left,l.bottom-l.top),us(n.state,n.dispatch,o,l,r),!0}else if(r){const s=Kr(n.state),o=s.start(-1);return us(n.state,n.dispatch,o,z.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function hd(n,e){var t;if(e.ctrlKey||e.metaKey)return;const r=ps(n,e.target);let i;if(e.shiftKey&&n.state.selection instanceof B)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&r&&(i=Ut(n.state.selection.$anchor))!=null&&((t=rr(n,e))==null?void 0:t.pos)!=i.pos)s(i,e),e.preventDefault();else if(!r)return;function s(a,c){let h=rr(n,c);const f=Ee.getState(n.state)==null;if(!h||!jr(a,h))if(f)h=a;else return;const d=new B(a,h);if(f||!n.state.selection.eq(d)){const p=n.state.tr.setSelection(d);f&&p.setMeta(Ee,a.pos),n.dispatch(p)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Ee.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Ee,-1))}function l(a){const c=a,h=Ee.getState(n.state);let f;if(h!=null)f=n.state.doc.resolve(h);else if(ps(n,c.target)!=r&&(f=rr(n,e),!f))return o();f&&s(f,c)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function Ml(n,e,t){if(!(n.state.selection instanceof M))return null;const{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){const s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function ps(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function rr(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Ut(n.state.doc.resolve(t.pos)):null}var fd=class{constructor(n,e){this.node=n,this.defaultCellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${e}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Or(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!=this.node.type?!1:(this.node=n,Or(n,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(n){return n.type=="attributes"&&(n.target==this.table||this.colgroup.contains(n.target))}};function Or(n,e,t,r,i,s){var o;let l=0,a=!0,c=e.firstChild;const h=n.firstChild;if(h){for(let f=0,d=0;f<h.childCount;f++){const{colspan:p,colwidth:u}=h.child(f).attrs;for(let m=0;m<p;m++,d++){const g=i==d?s:u&&u[m],b=g?g+"px":"";if(l+=g||r,g||(a=!1),c)c.style.width!=b&&(c.style.width=b),c=c.nextSibling;else{const k=document.createElement("col");k.style.width=b,e.appendChild(k)}}}for(;c;){const f=c.nextSibling;(o=c.parentNode)==null||o.removeChild(c),c=f}a?(t.style.width=l+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=l+"px")}}var ee=new qt("tableColumnResizing");function dd({handleWidth:n=5,cellMinWidth:e=25,defaultCellMinWidth:t=100,View:r=fd,lastColumnResizable:i=!0}={}){const s=new Jt({key:ee,state:{init(o,l){var a,c;const h=(c=(a=s.spec)==null?void 0:a.props)==null?void 0:c.nodeViews,f=me(l.schema).table.name;return r&&h&&(h[f]=(d,p)=>new r(d,t,p)),new ud(-1,!1)},apply(o,l){return l.apply(o)}},props:{attributes:o=>{const l=ee.getState(o);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,l)=>{pd(o,l,n,i)},mouseleave:o=>{md(o)},mousedown:(o,l)=>{gd(o,l,e,t)}},decorations:o=>{const l=ee.getState(o);if(l&&l.activeHandle>-1)return wd(o,l.activeHandle)},nodeViews:{}}});return s}var ud=class an{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,r=e.getMeta(ee);if(r&&r.setHandle!=null)return new an(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new an(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);return Mr(e.doc.resolve(i))||(i=-1),new an(i,t.dragging)}return t}};function pd(n,e,t,r){const i=ee.getState(n.state);if(i&&!i.dragging){const s=bd(e.target);let o=-1;if(s){const{left:l,right:a}=s.getBoundingClientRect();e.clientX-l<=t?o=ms(n,e,"left",t):a-e.clientX<=t&&(o=ms(n,e,"right",t))}if(o!=i.activeHandle){if(!r&&o!==-1){const l=n.state.doc.resolve(o),a=l.node(-1),c=z.get(a),h=l.start(-1);if(c.colCount(l.pos-h)+l.nodeAfter.attrs.colspan-1==c.width-1)return}vl(n,o)}}}function md(n){const e=ee.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&vl(n,-1)}function gd(n,e,t,r){var i;const s=(i=n.dom.ownerDocument.defaultView)!=null?i:window,o=ee.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const l=n.state.doc.nodeAt(o.activeHandle),a=yd(n,o.activeHandle,l.attrs);n.dispatch(n.state.tr.setMeta(ee,{setDragging:{startX:e.clientX,startWidth:a}}));function c(f){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",h);const d=ee.getState(n.state);d!=null&&d.dragging&&(Cd(n,d.activeHandle,gs(d.dragging,f,t)),n.dispatch(n.state.tr.setMeta(ee,{setDragging:null})))}function h(f){if(!f.which)return c(f);const d=ee.getState(n.state);if(d&&d.dragging){const p=gs(d.dragging,f,t);ys(n,d.activeHandle,p,r)}}return ys(n,o.activeHandle,a,r),s.addEventListener("mouseup",c),s.addEventListener("mousemove",h),e.preventDefault(),!0}function yd(n,e,{colspan:t,colwidth:r}){const i=r&&r[r.length-1];if(i)return i;const s=n.domAtPos(e);let l=s.node.childNodes[s.offset].offsetWidth,a=t;if(r)for(let c=0;c<t;c++)r[c]&&(l-=r[c],a--);return l/a}function bd(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function ms(n,e,t,r){const i=t=="right"?-r:r,s=n.posAtCoords({left:e.clientX+i,top:e.clientY});if(!s)return-1;const{pos:o}=s,l=Ut(n.state.doc.resolve(o));if(!l)return-1;if(t=="right")return l.pos;const a=z.get(l.node(-1)),c=l.start(-1),h=a.map.indexOf(l.pos-c);return h%a.width==0?-1:c+a.map[h-1]}function gs(n,e,t){const r=e.clientX-n.startX;return Math.max(t,n.startWidth+r)}function vl(n,e){n.dispatch(n.state.tr.setMeta(ee,{setHandle:e}))}function Cd(n,e,t){const r=n.state.doc.resolve(e),i=r.node(-1),s=z.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){const h=c*s.width+l;if(c&&s.map[h]==s.map[h-s.width])continue;const f=s.map[h],d=i.nodeAt(f).attrs,p=d.colspan==1?0:l-s.colCount(f);if(d.colwidth&&d.colwidth[p]==t)continue;const u=d.colwidth?d.colwidth.slice():xd(d.colspan);u[p]=t,a.setNodeMarkup(o+f,null,{...d,colwidth:u})}a.docChanged&&n.dispatch(a)}function ys(n,e,t,r){const i=n.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=z.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1;let a=n.domAtPos(i.start(-1)).node;for(;a&&a.nodeName!="TABLE";)a=a.parentNode;a&&Or(s,a.firstChild,a,r,l,t)}function xd(n){return Array(n).fill(0)}function wd(n,e){var t;const r=[],i=n.doc.resolve(e),s=i.node(-1);if(!s)return R.empty;const o=z.get(s),l=i.start(-1),a=o.colCount(i.pos-l)+i.nodeAfter.attrs.colspan-1;for(let c=0;c<o.height;c++){const h=a+c*o.width;if((a==o.width-1||o.map[h]!=o.map[h+1])&&(c==0||o.map[h]!=o.map[h-o.width])){const f=o.map[h],d=l+f+s.nodeAt(f).nodeSize-1,p=document.createElement("div");p.className="column-resize-handle",(t=ee.getState(n))!=null&&t.dragging&&r.push(Z.node(l+f,l+f+s.nodeAt(f).nodeSize,{class:"column-resize-dragging"})),r.push(Z.widget(d,p))}}return R.create(n.doc,r)}function kd({allowTableNodeSelection:n=!1}={}){return new Jt({key:Ee,state:{init(){return null},apply(e,t){const r=e.getMeta(Ee);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;const{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:Uf,handleDOMEvents:{mousedown:hd},createSelectionBetween(e){return Ee.getState(e.state)!=null?e.state.selection:null},handleTripleClick:ad,handleKeyDown:ld,handlePaste:cd},appendTransaction(e,t,r){return Xf(r,Qf(r,t),n)}})}const zt=n=>{const e=Object.fromEntries(Array.from(n.attributes).map(t=>[t.name,t.value]));return delete e.draggable,e},bs="data-gs-mrk-fs",Cs="data-gs-ib",Sn="data-gs-ifrg",Se="attrs",Ol={[Se]:{default:"{}"}},ye={[Se]:{default:{}}},Nl=n=>({[Se]:JSON.stringify(zt(n))}),be=n=>({attrs:zt(n)}),Mt=n=>e=>[n,e.attrs.attrs,0],Te=n=>n.attrs[Se]?JSON.parse(n.attrs[Se]):{},Sd={doc:{content:"block+"},text:{group:"inline",inline:!0},inlineFragment:{group:"block",content:"inline*",isTextBlock:!0,parseDOM:[{tag:`span[${Sn}]`,getAttrs:be}],toDOM:()=>["span",{[Sn]:""},0]},div:{group:"block",content:"inline*",attrs:ye,parseDOM:[{tag:"div",getAttrs:be}],toDOM:Mt("div")},paragraph:{group:"block",content:"inline*",attrs:ye,parseDOM:[{tag:"p",getAttrs:be}],toDOM:Mt("p")},orderedList:{group:"block",content:"listItem+",attrs:ye,parseDOM:[{tag:"ol",getAttrs:be}],toDOM:Mt("ol")},bulletList:{group:"block",content:"listItem+",attrs:ye,parseDOM:[{tag:"ul",getAttrs:be}],toDOM:Mt("ul")},listItem:{content:"block*",group:"block",attrs:ye,parseDOM:[{tag:"li",getAttrs:be}],toDOM:Mt("li"),defining:!0},codeBlock:{group:"block",content:"text*",marks:"",attrs:ye,parseDOM:[{tag:"pre",getAttrs:be}],toDOM:n=>["pre",n.attrs.attrs,["code",0]]},image:{inline:!0,group:"inline",selectable:!0,attrs:ye,parseDOM:[{tag:"img[src]",getAttrs:be}],toDOM:n=>["img",n.attrs.attrs]},inlineBreak:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:`br[${Cs}]`}],toDOM(){return["br",{[Cs]:""}]}},hardBreak:{inline:!1,group:"block",selectable:!1,attrs:ye,parseDOM:[{tag:"br",getAttrs:be}],toDOM:n=>["br",{...n.attrs.attrs}]},heading:{group:"block",content:"inline*",attrs:{level:{default:1},attrs:{default:{}}},defining:!0,parseDOM:Array.from({length:6},(n,e)=>({tag:`h${e+1}`,getAttrs:t=>({level:e+1,attrs:zt(t)})})),toDOM({attrs:n}){const{level:e}=n;return[e?`h${e}`:"div",n.attrs,0]}},...qf({tableGroup:"block",cellContent:"block+",cellAttributes:{[Se]:{default:ye[Se].default,getFromDOM:zt,setDOMAttr:(n,e)=>{n&&Object.assign(e,n)}},background:{default:null,getFromDOM(n){return n.style.backgroundColor||null},setDOMAttr(n,e){n&&(e.style=(e.style||"")+`background-color: ${n};`)}}}}),nonTextNode:{group:"block",content:"block*",attrs:{tagName:{default:"span"},attrs:{default:{}}},parseDOM:[{tag:"*:not(tbody)",getAttrs:n=>({tagName:n.tagName.toLowerCase(),attrs:zt(n)}),priority:0}],toDOM(n){const{tagName:e,attrs:t}=n.attrs;return[e,t,0]}}},vt=(n,e)=>({attrs:Ol,parseDOM:n.map(t=>({tag:t,getAttrs:Nl})),toDOM:e}),Md={strong:vt(["strong","b"],n=>["b",Te(n)]),link:vt(["a"],n=>["a",Te(n),0]),em:vt(["em","i"],n=>["em",Te(n)]),underline:vt(["u"],n=>["u",Te(n),0]),strikethrough:vt(["s"],n=>["s",Te(n),0]),font_size:{attrs:{...Ol,size:{default:null}},parseDOM:[{tag:`span[${bs}]`,getAttrs:n=>({...Nl(n),size:n.style.fontSize})}],toDOM(n){const{size:e}=n.attrs,t={...Te(n),[bs]:!0};return e&&(t.style=`font-size: ${e}`),["span",t,0]}}},xs=new $a({nodes:Sd,marks:Md}),Vn=new WeakMap,Ur=new WeakMap,vd=(n,e)=>{Vn.set(n,e),Ur.set(e,n)},Od=(n,e)=>{Vn.delete(n),Ur.delete(e)},ws=n=>Vn.get(n),Nd=n=>Ur.get(n),ks=n=>{var t;const e=Nd(n);return(t=e==null?void 0:e.__gjsv)==null?void 0:t.model},Ad=n=>n.dispatchEvent(new CustomEvent("input"));function Td(n){const e=t=>{if(t.tagName==="SPAN"&&t.hasAttribute(Sn)){if(t.getAttribute("style")){t.removeAttribute(Sn);return}const r=t.parentElement;if(r){for(;t.firstChild;)r.insertBefore(t.firstChild,t);r.removeChild(t)}}else Array.from(t.children).forEach(r=>e(r))};e(n)}const Dd=(n,e)=>{const t=Ed(n);return t&&Fd(t)?Rd(n,e):t?Eo(()=>({type:n.schema.nodes.div}))(n,e):!1};function Ed(n){const e=n.selection.$from;if(e.node(e.depth).type===n.schema.nodes.inlineFragment){const t=e.depth-1;return e.node(t)}return e.node(e.depth)}function Rd(n,e){const{selection:t,schema:r,tr:i}=n;i.split(t.from,1);const s=t.from+1,o=i.doc.nodeAt(s),l={...o.attrs.attrs,id:void 0},a=o.textContent.length>0,c=o.textContent.length||0,h=o.textContent||" ",f=r.text(h),d=r.nodes.div.create(l,a?f:[],[]);return i.replaceRangeWith(s,s+c+2,d),i.setSelection(M.create(i.doc,s+1)),e==null||e(i.scrollIntoView()),!0}function Id(n,e,t){const{state:r,dispatch:i}=n,{selection:s,tr:o}=r,l=(a,c,h)=>{const f={};return a.split(";").forEach(d=>{const[p,u]=d.split(":").map(m=>m.trim());p&&(f[p]=u)}),f[c]=h,Object.entries(f).map(([d,p])=>`${d}: ${p}`).join("; ")};if(!s.empty||t)o.doc.nodesBetween(s.from,s.to,(a,c)=>{var h,f;if(a.type===r.schema.nodes.image){const d=l(((h=a.attrs.attrs)==null?void 0:h.style)||"","float",e);o.setNodeMarkup(c,void 0,{...a.attrs,attrs:{...a.attrs.attrs,style:d}})}else if(a.type.isBlock){const d=l(((f=a.attrs.attrs)==null?void 0:f.style)||"","text-align",e);Al(a)?o.setBlockType(s.from,void 0,r.schema.nodes.div,{attrs:{style:d}}):o.setNodeMarkup(c,void 0,{...a.attrs,attrs:{...a.attrs.attrs,style:d}})}});else{const a=r.doc.resolve(s.from),c=a.start(a.depth),h=r.doc.nodeAt(c);if(h!=null&&h.type.isBlock){const f=l(h.attrs.style||"","text-align",e);o.setNodeMarkup(c,void 0,{...h.attrs,style:f})}}o.docChanged&&i(o.scrollIntoView())}const Ot=(n,e)=>{const{from:t,to:r}=n.selection;let i=!1;return n.doc.nodesBetween(t,r,s=>{if(i)return!1;s.marks.some(o=>o.type===e)&&(i=!0)}),i};function zd(n,e,t="_blank"){const{state:r,dispatch:i}=n,{schema:s,selection:o,tr:l}=r,a=s.marks.link;try{const c=a.create({[Se]:JSON.stringify({href:e,target:t})});l.addMark(o.from,o.to,c),i(l.scrollIntoView())}catch(c){console.error("Error applying link mark:",c)}}function Pd(n,e){const{state:t,dispatch:r}=n,{selection:i,tr:s}=t;if(i.empty)return;const o=t.schema.marks.font_size;if(!o){console.error("Font size mark is not defined in the schema.");return}s.addMark(i.from,i.to,o.create({size:e})),r(s.scrollIntoView())}const _e=(n,e)=>{const{doc:t,selection:r}=n.state,i=t.resolve(r.from);for(let s=i.depth;s>0;s--){const o=i.node(s);if(e(o))return{pos:s>0?i.before(s):0,start:i.start(s),depth:s,node:o}}},Vd=n=>(n||"").split(";").map(e=>e.split(":")).reduce((e,[t,r])=>(t=t.replace(/-./g,i=>i.toUpperCase()[1]).trim(),e[t]=`${r}`.trim(),e),{});function Bd(...n){return(e,t)=>{const r=o=>{e=e.apply(o),t==null||t(o)},i=n.pop();return n.reduce((o,l)=>o||l(e,r),!1)&&i!==void 0&&i(e,t)}}const Hd=(n,e)=>{const{state:t,dispatch:r}=n;if(e!=null&&e.event){const{event:i}=e,s=n.posAtCoords({left:i.clientX,top:i.clientY});s!=null&&s.pos&&r(t.tr.setSelection(M.create(t.doc,s.pos)))}else Ro(t,r);setTimeout(()=>setTimeout(()=>n.focus()))},Nr=n=>n.isBlock,Al=n=>n.type.name==="inlineFragment",Ld=n=>Nr(n)&&!Al(n),Tl=n=>n.type.name==="bulletList",Dl=n=>n.type.name==="orderedList",Fd=n=>n.type.name==="heading",Wd=n=>Tl(n)||Dl(n),Ss=(n,e)=>{var s,o;const t=(s=_e(n,l=>l.type===e))==null?void 0:s.node,r=n.state.schema.nodes.listItem;let i;return t?i=fr(r):(o=_e(n,Wd))!=null&&o.node?i=Bd(fr(r),Oi(e)):i=Oi(e),i(n.state,n.dispatch)},El=(n,e)=>{const{selection:t}=n.state;return[...t.$from.marks(),...t.$to.marks()].find(r=>r.type.name===e)},$d=n=>{var o;const{view:e,prop:t,editor:r,propCSS:i}=n,s=(o=_e(e,Ld))==null?void 0:o.node;if(s){const l=s.attrs.attrs||{},a=Vd(l.style);if(t in a)return a[t]||"";if(l.id){const c=r.Components.getById(l.id);return((c==null?void 0:c.getStyle())||{})[i]||""}}return""},Jd=n=>{const{view:e,prop:t,markName:r,editor:i,propCSS:s}=n,o=El(e,r);if(o){const l=o.attrs;if(l[t])return l[t];if(l[Se]){const a=Te(o).id;if(a){const c=i.Components.getById(a);return((c==null?void 0:c.getStyle())||{})[s]||""}}}return""},Rl=(n,e)=>{const{dispatch:t}=n,{nodes:r,marks:i}=n.state.schema;return{text:{selected:()=>{const{selection:s,doc:o}=n.state;return o.textBetween(s.from,s.to," ")},replace:(s,o={})=>{const{state:l}=n,{from:a}=l.selection;let c=l.tr.replaceSelectionWith(l.schema.text(s));o.select&&(c=c.setSelection(M.create(c.doc,a,a+s.length))),t==null||t(c)}},bold:{toggle:()=>Je(i.strong)(n.state,t),isActive:()=>Ot(n.state,i.strong)},italic:{toggle:()=>Je(i.em)(n.state,t),isActive:()=>Ot(n.state,i.em)},underline:{toggle:()=>Je(i.underline)(n.state,t),isActive:()=>Ot(n.state,i.underline)},strikethrough:{toggle:()=>Je(i.strikethrough)(n.state,t),isActive:()=>Ot(n.state,i.strikethrough)},link:{get:()=>{const s=ks(n);if(s!=null&&s.is("link"))return s.getAttributes();{const o=El(n,"link");return o?Te(o):{}}},toggle:()=>Je(i.link)(n.state,t),isActive:()=>Ot(n.state,i.link),create:s=>{const o=ks(n);o!=null&&o.is("link")?(o.addAttributes({href:s.url,target:s.target}),n.focus()):zd(n,s.url,s.target)}},alignText:{get:()=>$d({view:n,editor:e,prop:"textAlign",propCSS:"text-align"}),set:s=>Id(n,s.value,!0)},fontSize:{get:()=>Jd({view:n,editor:e,markName:"font_size",prop:"size",propCSS:"font-size"}),set:s=>Pd(n,s.value)},image:{open(){const s="assetLayout",{state:o,dispatch:l}=n,{selection:a,doc:c}=o,h=c.textBetween(a.from,a.to," "),f={id:s,disablePropagation:!0,placer:{type:"dialog",title:"Select image",size:"l"},header:!1,layout:{type:"panelAssets",onSelect:d=>{const p={alt:h,src:d.asset.getSrc()};l(o.tr.replaceSelectionWith(r.image.createAndFill({attrs:p})))}}};e.runCommand(Pt.layoutToggle,f)}},heading:{get:()=>{var o;const s=(o=_e(n,Nr))==null?void 0:o.node;return`${(s==null?void 0:s.attrs.level)||""}`},set:({value:s})=>{var a;const{state:o}=n,l=(a=_e(n,Nr))==null?void 0:a.node;Pc(o.schema.nodes.heading,{attrs:l==null?void 0:l.attrs.attrs,level:s?parseInt(s,10):0})(o,t)}},listBullet:{isActive:()=>{var s;return!!((s=_e(n,Tl))!=null&&s.node)},toggle:()=>Ss(n,r.bulletList)},listOrdered:{isActive:()=>{var s;return!!((s=_e(n,Dl))!=null&&s.node)},toggle:()=>Ss(n,r.orderedList)}}},oe="rte:selectionchange",ne={bold:'<svg viewBox="0 0 24 24"><path d="M13.5,15.5H10V12.5H13.5A1.5,1.5 0 0,1 15,14A1.5,1.5 0 0,1 13.5,15.5M10,6.5H13A1.5,1.5 0 0,1 14.5,8A1.5,1.5 0 0,1 13,9.5H10M15.6,10.79C16.57,10.11 17.25,9 17.25,8C17.25,5.74 15.5,4 13.25,4H7V18H14.04C16.14,18 17.75,16.3 17.75,14.21C17.75,12.69 16.89,11.39 15.6,10.79Z" /></svg>',italic:'<svg viewBox="0 0 24 24"><path d="M10,4V7H12.21L8.79,15H6V18H14V15H11.79L15.21,7H18V4H10Z" /></svg>',underline:'<svg viewBox="0 0 24 24"><path d="M5,21H19V19H5V21M12,17A6,6 0 0,0 18,11V3H15.5V11A3.5,3.5 0 0,1 12,14.5A3.5,3.5 0 0,1 8.5,11V3H6V11A6,6 0 0,0 12,17Z" /></svg>',strikethrough:'<svg viewBox="0 0 24 24"><path d="M7.2 9.8c-1.2-2.3.5-5 2.9-5.5 3.1-1 7.6.4 7.5 4.2h-3l-.1-.8c-.2-.6-.6-.9-1.2-1.1-.8-.3-2.1-.2-2.8.3C9 8.2 10.4 9.5 12 10H7.4l-.2-.2M21 13v-2H3v2h9.6l.6.2c.6.3 1.1.5 1.3 1.1.1.4.2.9 0 1.3-.2.5-.6.7-1.1.9-1.8.5-4-.2-3.9-2.4h-3c-.1 2.6 2.1 4.4 4.5 4.7 3.8.8 8.3-1.6 6.3-5.9l3.7.1Z"/></svg>',link:'<svg viewBox="0 0 24 24"><path d="M3.9,12C3.9,10.29 5.29,8.9 7,8.9H11V7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H11V15.1H7C5.29,15.1 3.9,13.71 3.9,12M8,13H16V11H8V13M17,7H13V8.9H17C18.71,8.9 20.1,10.29 20.1,12C20.1,13.71 18.71,15.1 17,15.1H13V17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7Z" /></svg>',image:'<svg viewBox="0 0 24 24"><path d="M19,19H5V5H19M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3M13.96,12.29L11.21,15.83L9.25,13.47L6.5,17H17.5L13.96,12.29Z"></path></svg>',listBullet:'<svg viewBox="0 0 24 24"><path d="M7 5h14v2H7V5m0 8v-2h14v2H7M4 4.5A1.5 1.5 0 0 1 5.5 6 1.5 1.5 0 0 1 4 7.5 1.5 1.5 0 0 1 2.5 6 1.5 1.5 0 0 1 4 4.5m0 6A1.5 1.5 0 0 1 5.5 12 1.5 1.5 0 0 1 4 13.5 1.5 1.5 0 0 1 2.5 12 1.5 1.5 0 0 1 4 10.5M7 19v-2h14v2H7m-3-2.5A1.5 1.5 0 0 1 5.5 18 1.5 1.5 0 0 1 4 19.5 1.5 1.5 0 0 1 2.5 18 1.5 1.5 0 0 1 4 16.5Z"/></svg>',listOrdered:'<svg viewBox="0 0 24 24"><path d="M7 13v-2h14v2H7m0 6v-2h14v2H7M7 7V5h14v2H7M3 8V5H2V4h2v4H3m-1 9v-1h3v4H2v-1h2v-.5H3v-1h1V17H2m2.3-7a.8.8 0 0 1 .7.8c0 .1 0 .3-.2.5L3 13h2v1H2v-1l2-2H2v-1h2.3Z"/></svg>',alignTextLeft:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M3,7H15V9H3V7M3,11H21V13H3V11M3,15H15V17H3V15M3,19H21V21H3V19Z" /></svg>',alignTextCenter:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M7,7H17V9H7V7M3,11H21V13H3V11M7,15H17V17H7V15M3,19H21V21H3V19Z" /></svg>',alignTextRight:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M9,7H21V9H9V7M3,11H21V13H3V11M9,15H21V17H9V15M3,19H21V21H3V19Z" /></svg>',alignTextJustify:'<svg viewBox="0 0 24 24"><path d="M3,3H21V5H3V3M3,7H21V9H3V7M3,11H21V13H3V11M3,15H21V17H3V15M3,19H21V21H3V19Z" /></svg>'},qd=(n,e)=>{var a;const{editor:t,el:r}=n,i=Vn.get(r),s=Rl(i,t),o={separator:{type:"column",style:{borderRightWidth:"1px",borderRightStyle:"solid",alignSelf:"stretch",margin:3}},bold:{id:"bold",icon:ne.bold,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.bold.isActive()})}},onClick:({setState:c})=>{s.bold.toggle(),c({active:s.bold.isActive()})}},italic:{id:"italic",icon:ne.italic,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.italic.isActive()})}},onClick:({setState:c})=>{s.italic.toggle(),c({active:s.italic.isActive()})}},underline:{id:"underline",icon:ne.underline,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.underline.isActive()})}},onClick:({setState:c})=>{s.underline.toggle(),c({active:s.underline.isActive()})}},strikethrough:{id:"strikethrough",icon:ne.strikethrough,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.strikethrough.isActive()})}},onClick:({setState:c})=>{s.strikethrough.toggle(),c({active:s.strikethrough.isActive()})}},image:{id:"image",icon:ne.image,size:"s",type:"button",onClick:()=>s.image.open()},link:{id:"link",icon:ne.link,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.link.isActive(),disabled:i.state.selection.empty})}},onClick:({event:c})=>{const h=c.currentTarget||c.target,{x:f,y:d,width:p,height:u}=h.getBoundingClientRect(),m="linkLayout",g=()=>t.runCommand(Pt.layoutRemove,{id:m}),b=s.link.get(),k={id:m,style:{width:240},disablePropagation:!0,placer:{type:"popover",closeOnClickAway:!0,x:f,y:d,w:p,h:u},header:{label:"Link"},layout:{type:"column",as:"form",style:{padding:"0 10px 15px",gap:10},onSubmit:O=>{O.preventDefault();const v=new FormData(O.currentTarget);s.link.create({url:v.get("url"),target:v.get("target")}),g()},children:[{type:"inputField",name:"url",label:"URL",placeholder:"eg. https://google.com",required:!0,value:(b==null?void 0:b.href)||"",onChange:({value:O,setState:v})=>v({value:O})},{type:"selectField",name:"target",label:"Open link in",emptyState:"Current window",value:(b==null?void 0:b.target)||"",options:[{id:"",label:"Current window"},{id:"_blank",label:"New window"}],onChange:({value:O,setState:v})=>v({value:O})},{type:"row",style:{gap:10,justifyContent:"end"},children:[s.link.isActive()&&{type:"button",label:"Clear",buttonType:"button",onClick:()=>{s.link.toggle(),g()}},{type:"button",variant:"primary",label:"Submit",buttonType:"submit"}]}]}};t.runCommand(Pt.layoutToggle,k)}},alignText:{id:"alignText",type:"buttonGroupField",size:"s",value:"",options:[{id:"left",icon:ne.alignTextLeft},{id:"center",icon:ne.alignTextCenter},{id:"right",icon:ne.alignTextRight},{id:"justify",icon:ne.alignTextJustify}],editorEvents:{[oe]:({setState:c})=>{c({value:s.alignText.get()})}},onChange:({value:c,setState:h})=>{h({value:c}),s.alignText.set({value:c})}},listBullet:{id:"listBullet",icon:ne.listBullet,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.listBullet.isActive()})}},onClick:({setState:c})=>{s.listBullet.toggle(),c({active:s.listBullet.isActive()})}},listOrdered:{id:"listOrdered",icon:ne.listOrdered,size:"s",type:"button",editorEvents:{[oe]:({setState:c})=>{c({active:s.listOrdered.isActive()})}},onClick:({setState:c})=>{s.listOrdered.toggle(),c({active:s.listOrdered.isActive()})}},heading:{id:"heading",type:"selectField",size:"s",value:"",emptyState:"Heading",options:[{id:"",label:"Normal"},{id:"1",label:"Heading 1"},{id:"2",label:"Heading 2"},{id:"3",label:"Heading 3"},{id:"4",label:"Heading 4"},{id:"5",label:"Heading 5"},{id:"6",label:"Heading 6"}],editorEvents:{[oe]:({setState:c})=>{c({value:s.heading.get()})}},onChange:({value:c,setState:h})=>{h({value:c}),s.heading.set({value:c}),i.focus()}},fontSize:{id:"fontSize",type:"selectField",size:"s",value:"",emptyState:"Font size",options:[{id:"8pt",label:"8pt"},{id:"10pt",label:"10pt"},{id:"12pt",label:"12pt"},{id:"14pt",label:"14pt"},{id:"18pt",label:"18pt"},{id:"24pt",label:"24pt"},{id:"36pt",label:"36pt"}],editorEvents:{[oe]:({setState:c})=>{c({value:s.fontSize.get()})}},onChange:({value:c,setState:h})=>{h({value:c}),s.fontSize.set({value:c}),i.focus()}}},l=[o.bold,o.italic,o.underline,o.strikethrough,o.image,o.link,o.listBullet,o.listOrdered,o.alignText,o.heading,o.fontSize];return((a=e.toolbar)==null?void 0:a.call(e,{...n,commands:s,layouts:o,proseMirror:{view:i},items:l}))||l};class Kd{constructor(e,t,r){this.editor=r,this.node=e,this.dom=document.createElement("img"),this.view=t,Object.keys(e.attrs.attrs).forEach(i=>{this.dom.setAttribute(i,e.attrs.attrs[i])}),this.dom.addEventListener("dblclick",i=>this.handleDoubleClick(i))}handleDoubleClick(e){const{editor:t,view:r}=this;Rl(r,t).image.open(),e.preventDefault()}update(e){return e.type!==this.node.type?!1:(this.node=e,Object.keys(e.attrs.attrs).forEach(t=>{this.dom.setAttribute(t,e.attrs.attrs[t])}),!0)}selectNode(){this.dom.style.outline="2px solid #ffca6f"}deselectNode(){this.dom.style.outline=""}}class Fe{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?jd(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1}}function jd(n){return function(e,t,r,i){let s=n;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),r+=o;let l=r-i;l>0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}const _d=500;function Ud({rules:n}){let e=new Jt({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return Ms(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&Ms(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function Ms(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-_d),l.parentOffset,null,"")+r;for(let c=0;c<i.length;c++){let h=i[c];if(l.parent.type.spec.code){if(!h.inCode)continue}else if(h.inCode==="only")continue;let f=h.match.exec(a),d=f&&h.handler(o,f,e-(f[0].length-r.length),t);if(d)return h.undoable&&d.setMeta(s,{transform:d,from:e,to:t,text:r}),n.dispatch(d),!0}return!1}const Gd=new Fe(/--$/,"—"),Zd=new Fe(/\.\.\.$/,"…"),Xd=new Fe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“"),Yd=new Fe(/"$/,"”"),Qd=new Fe(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘"),eu=new Fe(/'$/,"’"),tu=[Xd,Yd,Qd,eu];function Gr(n,e,t=null,r){return new Fe(n,(i,s,o,l)=>{let a=t instanceof Function?t(s):t,c=i.tr.delete(o,l),h=c.doc.resolve(o),f=h.blockRange(),d=f&&mo(f,e,a);if(!d)return null;c.wrap(f,d);let p=c.doc.resolve(o-1).nodeBefore;return p&&p.type==e&&Dn(c.doc,o-1)&&(!r||r(s,p))&&c.join(o-1),c})}function Il(n,e,t=null){return new Fe(n,(r,i,s,o)=>{let l=r.doc.resolve(s),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(s,o).setBlockType(s,s,e,a):null})}function nu(n){return Gr(/^\s*>\s$/,n)}function ru(n){return Gr(/^(\d+)\.\s$/,n,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order==+e[1])}function iu(n){return Gr(/^\s*([-+*])\s$/,n)}function su(n){return Il(/^```$/,n)}function ou(n,e){return Il(new RegExp("^(#{1,"+e+"})\\s$"),n,t=>({level:t[1].length}))}function lu(n){const e=tu.concat(Zd,Gd);let t;return(t=n.nodes.blockquote)&&e.push(nu(t)),(t=n.nodes.orderedList)&&e.push(ru(t)),(t=n.nodes.bulletList)&&e.push(iu(t)),(t=n.nodes.codeBlock)&&e.push(su(t)),(t=n.nodes.heading)&&e.push(ou(t,6)),Ud({rules:e})}const au="rteProseMirror",cu=function(n,e={}){const t={plugins:s=>s.plugins,...e},r=(s,o)=>{var p,u;const l=((p=t.schema)==null?void 0:p.call(t,{editor:n,schema:xs}))||xs,{nodes:a,marks:c}=l,h=gt.fromSchema(l).parse(s),f=ht.create({doc:h,schema:l,plugins:(u=t.plugins)==null?void 0:u.call(t,{editor:n,plugins:[dd(),kd(),lu(l),_c(),Xn({Tab:hs(1),"Shift-Tab":hs(-1)}),Xn({Enter:Ht(Do,th(a.listItem),Dd),"Shift-Enter":Ht(To,(m,g)=>(g&&g(m.tr.replaceSelectionWith(a.inlineBreak.create()).scrollIntoView()),!0)),"Mod-z":Ho,"Mod-y":hr,"Mod-Shift-z":hr,"Mod-b":Je(c.strong),"Mod-i":Je(c.em),"Shift-Tab":fr(a.listItem),Tab:ih(a.listItem)}),Xn(Hc)]})}),d=new Bf({mount:s},{state:f,dispatchTransaction(m){var v;const{state:g}=d,b=g.apply(m),k=!g.doc.eq(b.doc);d.updateState(b);const O=!g.selection.eq(b.selection);k&&(Ad(((v=o==null?void 0:o.view)==null?void 0:v.el)||s),d.focus()),(O||k)&&n.trigger(oe)}});return s.__rteView=d,d.setProps({nodeViews:{image(m){return new Kd(m,d,n)}}}),d},i=s=>qd(s,t);n.setCustomRte({toolbar:i,parseContent:!0,async enable(s,o,l){const a=r(s,l);return vd(s,a),Hd(a,l),a},disable(s){const o=ws(s);if(o)return Od(s,o),o.destroy(),{forceSync:!0}},getContent(s){const o=ws(s);if(o){const{schema:l,doc:a}=o.state,c=document.createElement("div"),h=rt.fromSchema(l).serializeFragment(a.content);return h.childNodes.forEach(f=>{f.nodeType===Node.ELEMENT_NODE&&f.innerHTML===""&&(f.innerHTML="<br/>")}),c.appendChild(h),Td(c),s.classList.remove("ProseMirror-focused"),c.innerHTML}return s.innerHTML}}),vn({editor:n,licenseKey:t.licenseKey,pluginName:au,cleanup:()=>{n.RichTextEditor.customRte=void 0}})},hu=Mn(cu);exports.dialogComponent=_l;exports.listPagesComponent=va;exports.rteProseMirror=hu;exports.tableComponent=ba;