@strifeapp/strife 0.1.0-preview.11 → 0.1.0-preview.14
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.esm.js +1 -1
- package/package.json +6 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={CONNECT:1,HSHK:2,EU:4,SYNC:8};class t extends MessageChannel{constructor(){super(),this.broadcastChannel=new BroadcastChannel('app.broadcast');switch(this.port1.addEventListener('message',(t=>{t.data.cmd===e.CONNECT&&this.onConnected(t)}),{once:!0}),this.port1.start(),this._ready=new Promise(((e,t)=>{this.readyResolve=e,this.readyReject=t})),this._ready.then((()=>{console.log(`SENDING MESSAGE FROM SDK IN WINDOW ${window.name}`),window.top.postMessage({cmd:e.HSHK,context:{name:window.name,height:document.body.scrollHeight}},'*',[this.port2])})),window.addEventListener('beforeunload',(()=>{console.log('unload'),this.send({foo:'bar'})})),window.addEventListener('click',(()=>{this.send({cmd:e.EU,updates:[{action:'click',lastUserInteraction:(new Date).valueOf(),context:window.name}]})}),!1),document.readyState){case'loading':case'interactive':document.onreadystatechange=()=>{'complete'===document.readyState&&this.readyResolve()};break;case'complete':this.readyResolve()}}subscribe(e){if(null==e)throw new Error('Parameter can not be null!');this.broadcastChannel.addEventListener('message',e),this.port1.addEventListener('message',e),this.port1.addEventListener('message',(e=>this.broadcastChannel.postMessage(e.data)))}send(e){this.port1.postMessage(e),this.broadcastChannel.postMessage(e)}onConnected(e){return e}}var s=new t;const i={NONE:8,EDIT:16,RESET:32,INIT:64,SYNC:128},r=()=>s,n=[];s.subscribe((({data:t})=>{try{t.cmd===e.SYNC?(t.sync.forEach((e=>{switch(e.action){case i.INIT:n.forEach((({self:t,handler:s})=>{const i=e.data.find((e=>e.propertyName===t.dataset.propertyName));e.currentPath===window.location.pathname&&i&&(t.dataset.placeholder=i.placeholder)}));break;case i.EDIT:case i.RESET:n.forEach((({self:t,handler:s})=>{if(e.currentPath===window.location.pathname&&(e.action===i.RESET||e.data.some((e=>e.name===t.dataset.propertyName)))){const i=e.data.find((e=>e.name===t.dataset.propertyName))?.value;s(i)}}))}})),s.send({cmd:e.EU,updates:[{action:i.SYNC,context:{name:window.name,height:document.body.scrollHeight}}]})):t.cmd===e.EU&&t.action===i.FOCUS&&t.updates.forEach((e=>{n.forEach((({self:t})=>{e.propertyName===t.dataset.propertyName&&e.currentPath===window.location.pathname&&t.scrollIntoView({behavior:'smooth',block:'center'})}))}))}catch(e){console.error(e)}}));const o=(e,t)=>(n.push({self:e,handler:t}),s),a=new CSSStyleSheet;a.replaceSync(':root {\n --str-placeholder-text-opacity: 0.3;\n --str-placeholder-background-color: #0099ff;\n --str-placeholder-background-opacity: 0.8;\n}\n\n[is]:not([is=\'str-template-cpnt\'] [is]):hover {\n outline: solid 1px #0099ff;\n cursor: pointer;\n}\nimg.previewing {\n --img-previewing-url: \'\';\n --img-previewing-size: 100%;\n --img-previewing-position: 0px 0px;\n background-image: var(--img-previewing-url);\n background-repeat: no-repeat;\n background-position: var(--img-previewing-position);\n background-size: var(--img-previewing-size);\n}\nimg.previewing.previewing--empty {\n background-image: repeating-linear-gradient(45deg, var(--str-placeholder-background-color) 0, transparent 1px, transparent 0, transparent 50%);\n background-repeat: repeat;\n background-position: 0 0;\n background-size: 15px 15px;\n outline: solid 1px var(--str-placeholder-background-color);\n opacity: var(--str-placeholder-background-opacity);\n}\n\n\n\n:where([is^="str-h"]:empty, [is^="str-textarea"]:empty, [is^="str-address"]:empty)::before {\n color: inherit;\n\n opacity: var(--str-placeholder-text-opacity);\n\n content: attr(data-placeholder);\n}');class c extends HTMLHeadingElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-h1-cpnt',c,{extends:'h1'}),customElements.define('str-h2-cpnt',class extends c{},{extends:'h2'}),customElements.define('str-h3-cpnt',class extends c{},{extends:'h3'}),customElements.define('str-h4-cpnt',class extends c{},{extends:'h4'}),customElements.define('str-h5-cpnt',class extends c{},{extends:'h5'}),customElements.define('str-h6-cpnt',class extends c{},{extends:'h6'});class d extends HTMLElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-address-cpnt',d,{extends:'address'});class h extends HTMLAnchorElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>this.href=e))}}customElements.define('str-anchor-cpnt',h,{extends:'a'});const l='https://images.nimbleinitiatives.com/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png';customElements.define('str-picture-cpnt',class extends HTMLPictureElement{_propertyMedia;_currentSrc;constructor(){super(),this.image=this.querySelector('img'),this.sources=[...this.querySelectorAll('source')],this.tabIndex=0,this.image.complete?this.init():(this.image.addEventListener('load',(e=>{this.init()}),{once:!0}),this.image.addEventListener('error',(e=>{this.init()}),{once:!0})),this._initied=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),o(this,(e=>{this.render(this,e)}))}initPreview(){console.groupCollapsed('[STR-PICTURE-CPNT ('+window.name+') INIT DEBUG]'),this.image.currentSrc||console.warn('img[currentSrc] is empty.'),this._currentSrc=this.sources.find((e=>{if(this.image.currentSrc)return e.srcset===this.image.currentSrc;{const t=window.matchMedia(e.media);return console.log('Trying to match media...',e.media,'matches=',t.matches),t.matches}})),this._currentSrc?(this._propertyMedia=this._currentSrc.dataset?.propertyMedia,console.log('currentSrc set to ',this._currentSrc,' and property media set to ',this._propertyMedia),this.offsetWidth<this._currentSrc.width&&console.log('container width ('+this.offsetWidth+'px) is smaller than given source width ('+this._currentSrc.width+'px). Image is scaled to',(this.offsetWidth/this._currentSrc.width*100).toFixed(0),'%'),!this.image.currentSrc&&this._currentSrc.width&&this._currentSrc.height&&(this.image.classList.add('previewing--empty'),console.log('Image was empty on load.')),this.image.classList.add('previewing'),this.image.style.maxWidth='100%',this.image.style.width=this._currentSrc.width+'px',this.image.style.aspectRatio=this._currentSrc.width/this._currentSrc.height,console.log('image width (max 100%) and aspect ratio set to',this.image.style.width,this.image.style.aspectRatio),this.image.style.setProperty('--img-previewing-url',`url(${this.image.currentSrc||this._currentSrc.srcset})`),console.log('CSS variable --img-previewing-url set to',this.image.currentSrc||this._currentSrc.srcset||'null','[IS TRANSPARENT PIXEL:]',(this.image.currentSrc||this._currentSrc.srcset)===l),this.image.style.setProperty('--img-previewing-size','100%'),this.image.style.setProperty('--img-previewing-position','0px,0px'),this.image.src=l,this.sources.forEach((e=>{e.srcset=l})),this.image.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})):console.warn('currentSrc could not be set (null)'),console.groupEnd()}render(e,t,s){this._initied.then((()=>{if(console.groupCollapsed('[STR-PICTURE-CPNT ('+window.name+') RENDER DEBUG]'),this._propertyMedia&&t&&t[this._propertyMedia]&&t[this._propertyMedia].source&&t[this._propertyMedia].source.crop){const e=this.image.offsetWidth/t[this._propertyMedia].width,s=this.image.offsetWidth/2-t[this._propertyMedia].source.originalWidth*(t[this._propertyMedia].source.crop.zoom*e)*t[this._propertyMedia].source.crop.focusX,i=this.image.offsetHeight/2-t[this._propertyMedia].source.originalHeight*(t[this._propertyMedia].source.crop.zoom*e)*t[this._propertyMedia].source.crop.focusY,r=t[this._propertyMedia].source.originalWidth/this.image.offsetWidth*(t[this._propertyMedia].source.crop.zoom*e);this.image.style.setProperty('--img-previewing-url',`url(${t[this._propertyMedia].source.originalPreview})`),console.log('CSS variable --img-previewing-url set to',t[this._propertyMedia].source.originalPreview||'null','[IS TRANSPARENT PIXEL:]',t[this._propertyMedia].source.originalPreview===l),this.image.style.setProperty('--img-previewing-size',100*r+'%'),this.image.style.setProperty('--img-previewing-position',`${s}px ${i}px`),t[this._propertyMedia].source.originalPreview?this.image.classList.remove('previewing--empty'):this.image.classList.add('previewing--empty'),console.log('Received render request with result',t[this._propertyMedia]),console.log('Calculating: Rendered size',(100*e).toFixed(0),'%'),console.log('Calculating: Translate X',s),console.log('Calculating: Translate Y',i),console.log('Calculating: Zoom',r)}else console.warn('Received invalid result and render aborted');console.groupEnd()}))}disconnectedCallback(){}},{extends:'picture'}),customElements.define('str-img-cpnt',class extends HTMLImageElement{constructor(){super(),this.tabIndex=0,this.complete?this.init():(this.addEventListener('load',(e=>{this.init()}),{once:!0}),this.addEventListener('error',(e=>{this.init()}),{once:!0})),this._loaded=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),o(this,(e=>{this.render(this,e)}))}initPreview(){this.classList.add('previewing'),this.src||this.classList.add('previewing--empty'),this.style.width=this.width+'px',this.style.height=this.height+'px',this.style.setProperty('--img-previewing-url',`url(${this.src})`),this.style.setProperty('--img-previewing-size','100%'),this.style.setProperty('--img-previewing-position','0px,0px'),this.src='https://images.nimbleinitiatives.com/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png',this.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})}render(e,t,s){this._loaded.then((()=>{if(t&&t.source){const e=this.offsetWidth/t.width,s=this.offsetWidth/2-t.source.originalWidth*(t.source.crop.zoom*e)*t.source.crop.focusX,i=this.offsetHeight/2-t.source.originalHeight*(t.source.crop.zoom*e)*t.source.crop.focusY,r=t.source.originalWidth/this.offsetWidth*(t.source.crop.zoom*e);this.style.setProperty('--img-previewing-url',`url(${t.source.originalPreview})`),this.style.setProperty('--img-previewing-size',100*r+'%'),this.style.setProperty('--img-previewing-position',`${s}px ${i}px`),t.source.originalPreview?this.classList.remove('previewing--empty'):this.classList.add('previewing--empty')}}))}disconnectedCallback(){}},{extends:'img'}),customElements.define('strife-blocks-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}},{extends:'div'});class p extends HTMLElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-strong-cpnt',p,{extends:'strong'});class m extends HTMLElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this)}}customElements.define('str-template-cpnt',m),customElements.define('str-textarea-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}async connectedCallback(){o(this,(e=>{this.innerHTML=e}))}},{extends:'div'});class g extends HTMLSpanElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-span-cpnt',g,{extends:'span'});class u extends HTMLParagraphElement{constructor(){super(),this.tabIndex=0}connectedCallback(){o(this,(e=>this.textContent=e))}}customElements.define('str-p-cpnt',u,{extends:'p'}),document.adoptedStyleSheets=[a];export{i as ACTION,e as CMD,r as default,o as useState};
|
|
1
|
+
const e={CONNECT:1,HSHK:2,EU:4,SYNC:8};class t extends MessageChannel{constructor(){super(),this.broadcastChannel=new BroadcastChannel('app.broadcast');switch(this.port1.addEventListener('message',(t=>{t.data.cmd===e.CONNECT&&this.onConnected(t)}),{once:!0}),this.port1.start(),this._ready=new Promise(((e,t)=>{this.readyResolve=e,this.readyReject=t})),this._ready.then((()=>{console.log(`SENDING MESSAGE FROM SDK IN WINDOW ${window.name}`),window.top.postMessage({cmd:e.HSHK,context:{name:window.name,height:document.body.scrollHeight}},'*',[this.port2])})),window.addEventListener('beforeunload',(()=>{console.log('unload'),this.send({foo:'bar'})})),window.addEventListener('click',(()=>{this.send({cmd:e.EU,updates:[{action:'click',lastUserInteraction:(new Date).valueOf(),context:window.name}]})}),!1),document.readyState){case'loading':case'interactive':document.onreadystatechange=()=>{'complete'===document.readyState&&this.readyResolve()};break;case'complete':this.readyResolve()}}subscribe(e){if(null==e)throw new Error('Parameter can not be null!');this.broadcastChannel.addEventListener('message',e),this.port1.addEventListener('message',e),this.port1.addEventListener('message',(e=>this.broadcastChannel.postMessage(e.data)))}send(e){this.port1.postMessage(e),this.broadcastChannel.postMessage(e)}onConnected(e){return e}}var n=new t;const r={NONE:8,EDIT:16,RESET:32,INIT:64,SYNC:128},i=()=>n,o=[];n.subscribe((({data:t})=>{try{t.cmd===e.SYNC?(t.sync.forEach((e=>{switch(e.action){case r.INIT:o.forEach((({self:t,handler:n})=>{const r=e.data.find((e=>e.propertyName===t.dataset.propertyName));e.currentPath===window.location.pathname&&r&&(t.dataset.placeholder=r.placeholder)}));break;case r.EDIT:case r.RESET:o.forEach((({self:t,handler:n})=>{if(e.currentPath===window.location.pathname&&(e.action===r.RESET||e.data.some((e=>e.name===t.dataset.propertyName)))){const r=e.data.find((e=>e.name===t.dataset.propertyName))?.value;n(r)}}))}})),n.send({cmd:e.EU,updates:[{action:r.SYNC,context:{name:window.name,height:document.body.scrollHeight}}]})):t.cmd===e.EU&&t.action===r.FOCUS&&t.updates.forEach((e=>{o.forEach((({self:t})=>{e.propertyName===t.dataset.propertyName&&e.currentPath===window.location.pathname&&t.scrollIntoView({behavior:'smooth',block:'center'})}))}))}catch(e){console.error(e)}}));const s=(e,t)=>(o.push({self:e,handler:t}),n),a=new CSSStyleSheet;a.replaceSync(':root {\n --str-placeholder-text-opacity: 0.3;\n --str-placeholder-background-color: #0099ff;\n --str-placeholder-background-opacity: 0.8;\n}\nimg.previewing {\n --img-previewing-url: \'\';\n --img-previewing-size: 100%;\n --img-previewing-position: 0px 0px;\n background-image: var(--img-previewing-url);\n background-repeat: no-repeat;\n background-position: var(--img-previewing-position);\n background-size: var(--img-previewing-size);\n}\nimg.previewing.previewing--empty {\n background-image: repeating-linear-gradient(45deg, var(--str-placeholder-background-color) 0, transparent 1px, transparent 0, transparent 50%);\n background-repeat: repeat;\n background-position: 0 0;\n background-size: 15px 15px;\n outline: solid 1px var(--str-placeholder-background-color);\n opacity: var(--str-placeholder-background-opacity);\n}\n\n\n\n:where([is^="str-h"]:empty, [is^="str-textarea"]:empty, [is^="str-address"]:empty, [is^="str-anchor"]:empty, [is^="str-p"]:empty)::before {\n color: inherit;\n\n opacity: var(--str-placeholder-text-opacity);\n\n content: attr(data-placeholder);\n}');class l extends HTMLHeadingElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.render(e)))}render(e){this.textContent=e}}customElements.define('str-h1-cpnt',l,{extends:'h1'}),customElements.define('str-h2-cpnt',class extends l{},{extends:'h2'}),customElements.define('str-h3-cpnt',class extends l{},{extends:'h3'}),customElements.define('str-h4-cpnt',class extends l{},{extends:'h4'}),customElements.define('str-h5-cpnt',class extends l{},{extends:'h5'}),customElements.define('str-h6-cpnt',class extends l{},{extends:'h6'});class c extends HTMLElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.render(e)))}render(e){this.textContent=e}}customElements.define('str-address-cpnt',c,{extends:'address'});class d extends HTMLAnchorElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.render(e)))}render(e){if(e){this.href=e.href;const t=this.childNodes;if(0===t.length)this.textContent=e.text;else for(const n of t)n.nodeType===Node.TEXT_NODE&&(n.nodeValue=e.text);'_blank'===e.target&&(this.target=e.target)}}}customElements.define('str-anchor-cpnt',d,{extends:'a'});const h='https://images.nimbleinitiatives.com/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png';customElements.define('str-picture-cpnt',class extends HTMLPictureElement{_propertyMedia;_currentSrc;constructor(){super(),this.image=this.querySelector('img'),this.sources=[...this.querySelectorAll('source')],this.tabIndex=0,this.image.complete?this.init():(this.image.addEventListener('load',(e=>{this.init()}),{once:!0}),this.image.addEventListener('error',(e=>{this.init()}),{once:!0})),this._initied=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),s(this,(e=>{this.render(e)}))}initPreview(){console.groupCollapsed('[STR-PICTURE-CPNT ('+window.name+') INIT DEBUG]'),this.image.currentSrc||console.warn('img[currentSrc] is empty.'),this._currentSrc=this.sources.find((e=>{if(this.image.currentSrc)return e.srcset===this.image.currentSrc;{const t=window.matchMedia(e.media);return console.log('Trying to match media...',e.media,'matches=',t.matches),t.matches}})),this._currentSrc?(this._propertyMedia=this._currentSrc.dataset?.propertyMedia,console.log('currentSrc set to ',this._currentSrc,' and property media set to ',this._propertyMedia),this.offsetWidth<this._currentSrc.width&&console.log('container width ('+this.offsetWidth+'px) is smaller than given source width ('+this._currentSrc.width+'px). Image is scaled to',(this.offsetWidth/this._currentSrc.width*100).toFixed(0),'%'),!this.image.currentSrc&&this._currentSrc.width&&this._currentSrc.height&&(this.image.classList.add('previewing--empty'),console.log('Image was empty on load.')),this.image.classList.add('previewing'),this.image.style.maxWidth='100%',this.image.style.width=this._currentSrc.width+'px',this.image.style.aspectRatio=this._currentSrc.width/this._currentSrc.height,console.log('image width (max 100%) and aspect ratio set to',this.image.style.width,this.image.style.aspectRatio),this.image.style.setProperty('--img-previewing-url',`url(${this.image.currentSrc||this._currentSrc.srcset})`),console.log('CSS variable --img-previewing-url set to',this.image.currentSrc||this._currentSrc.srcset||'null','[IS TRANSPARENT PIXEL:]',(this.image.currentSrc||this._currentSrc.srcset)===h),this.image.style.setProperty('--img-previewing-size','100%'),this.image.style.setProperty('--img-previewing-position','0px,0px'),this.image.src=h,this.sources.forEach((e=>{e.srcset=h})),this.image.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})):console.warn('currentSrc could not be set (null)'),console.groupEnd()}render(e){this._initied.then((()=>{if(console.groupCollapsed('[STR-PICTURE-CPNT ('+window.name+') RENDER DEBUG]'),this._propertyMedia&&e&&e[this._propertyMedia]&&e[this._propertyMedia].source&&e[this._propertyMedia].source.crop){const t=this.image.offsetWidth/e[this._propertyMedia].width,n=this.image.offsetWidth/2-e[this._propertyMedia].source.originalWidth*(e[this._propertyMedia].source.crop.zoom*t)*e[this._propertyMedia].source.crop.focusX,r=this.image.offsetHeight/2-e[this._propertyMedia].source.originalHeight*(e[this._propertyMedia].source.crop.zoom*t)*e[this._propertyMedia].source.crop.focusY,i=e[this._propertyMedia].source.originalWidth/this.image.offsetWidth*(e[this._propertyMedia].source.crop.zoom*t);this.image.style.setProperty('--img-previewing-url',`url(${e[this._propertyMedia].source.originalPreview})`),console.log('CSS variable --img-previewing-url set to',e[this._propertyMedia].source.originalPreview||'null','[IS TRANSPARENT PIXEL:]',e[this._propertyMedia].source.originalPreview===h),this.image.style.setProperty('--img-previewing-size',100*i+'%'),this.image.style.setProperty('--img-previewing-position',`${n}px ${r}px`),e[this._propertyMedia].source.originalPreview?this.image.classList.remove('previewing--empty'):this.image.classList.add('previewing--empty'),console.log('Received render request with result',e[this._propertyMedia]),console.log('Calculating: Rendered size',(100*t).toFixed(0),'%'),console.log('Calculating: Translate X',n),console.log('Calculating: Translate Y',r),console.log('Calculating: Zoom',i)}else console.warn('Received invalid result and render aborted');console.groupEnd()}))}disconnectedCallback(){}},{extends:'picture'}),customElements.define('str-img-cpnt',class extends HTMLImageElement{constructor(){super(),this.tabIndex=0,this.complete?this.init():(this.addEventListener('load',(e=>{this.init()}),{once:!0}),this.addEventListener('error',(e=>{this.init()}),{once:!0})),this._loaded=new Promise(((e,t)=>{this.loadedResolve=e,this.loadedReject=t}))}connectedCallback(){}init(){this.initPreview(),s(this,(e=>{this.render(e)}))}initPreview(){this.classList.add('previewing'),this.src||this.classList.add('previewing--empty'),this.style.width=this.width+'px',this.style.height=this.height+'px',this.style.setProperty('--img-previewing-url',`url(${this.src})`),this.style.setProperty('--img-previewing-size','100%'),this.style.setProperty('--img-previewing-position','0px,0px'),this.src='https://images.nimbleinitiatives.com/AS3SX_-B59mU1hdDS7B_YfI5Lu9Ut-kLpdaAhraKgy4/w:1/h:1/aHR0cHM6Ly9zdHJpZmUuYi1jZG4ubmV0L3RyYW5zcGFyZW50MXgxLnBuZw.png',this.addEventListener('load',(e=>{this.loadedResolve()}),{once:!0})}render(e){this._loaded.then((()=>{if(e&&e.source){const t=this.offsetWidth/e.width,n=this.offsetWidth/2-e.source.originalWidth*(e.source.crop.zoom*t)*e.source.crop.focusX,r=this.offsetHeight/2-e.source.originalHeight*(e.source.crop.zoom*t)*e.source.crop.focusY,i=e.source.originalWidth/this.offsetWidth*(e.source.crop.zoom*t);this.style.setProperty('--img-previewing-url',`url(${e.source.originalPreview})`),this.style.setProperty('--img-previewing-size',100*i+'%'),this.style.setProperty('--img-previewing-position',`${n}px ${r}px`),e.source.originalPreview?this.classList.remove('previewing--empty'):this.classList.add('previewing--empty')}}))}disconnectedCallback(){}},{extends:'img'}),customElements.define('strife-blocks-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.textContent=e))}},{extends:'div'});class p extends HTMLElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.render(e)))}render(e){this.textContent=e}}customElements.define('str-strong-cpnt',p,{extends:'strong'});class u extends HTMLElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this)}}function f(e){this.content=e}function m(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),o=t.child(r);if(i!=o){if(!i.sameMarkup(o))return n;if(i.isText&&i.text!=o.text){for(let e=0;i.text[e]==o.text[e];e++)n++;return n}if(i.content.size||o.content.size){let e=m(i.content,o.content,n+1);if(null!=e)return e}n+=i.nodeSize}else n+=i.nodeSize}}function g(e,t,n,r){for(let i=e.childCount,o=t.childCount;;){if(0==i||0==o)return i==o?null:{a:n,b:r};let s=e.child(--i),a=t.child(--o),l=s.nodeSize;if(s!=a){if(!s.sameMarkup(a))return{a:n,b:r};if(s.isText&&s.text!=a.text){let e=0,t=Math.min(s.text.length,a.text.length);for(;e<t&&s.text[s.text.length-e-1]==a.text[a.text.length-e-1];)e++,n--,r--;return{a:n,b:r}}if(s.content.size||a.content.size){let e=g(s.content,a.content,n-1,r-1);if(e)return e}n-=l,r-=l}else n-=l,r-=l}}customElements.define('str-template-cpnt',u),f.prototype={constructor:f,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return-1==t?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),o=r.content.slice();return-1==i?o.push(n||e,t):(o[i+1]=t,n&&(o[i]=n)),new f(o)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new f(n)},addToStart:function(e,t){return new f([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new f(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),o=r.find(e);return i.splice(-1==o?i.length:o,0,t,n),new f(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=f.from(e)).size?new f(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=f.from(e)).size?new f(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=f.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(((t,n)=>{e[t]=n})),e},get size(){return this.content.length>>1}},f.from=e=>{if(e instanceof f)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new f(t)};class y{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let o=0,s=0;s<t;o++){let a=this.content[o],l=s+a.nodeSize;if(l>e&&!1!==n(a,r+s,i||null,o)&&a.content.size){let i=s+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i='',o=!0;return this.nodesBetween(e,t,((s,a)=>{s.isText?(i+=s.text.slice(Math.max(e,a)-a,t-a),o=!n):s.isLeaf?(r?i+='function'==typeof r?r(s):r:s.type.spec.leafText&&(i+=s.type.spec.leafText(s)),o=!n):!o&&s.isBlock&&(i+=n,o=!0)}),0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new y(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,o=0;o<t;i++){let s=this.content[i],a=o+s.nodeSize;a>e&&((o<e||a>t)&&(s=s.isText?s.cut(Math.max(0,e-o),Math.min(s.text.length,t-o)):s.cut(Math.max(0,e-o-1),Math.min(s.content.size,t-o-1))),n.push(s),r+=s.nodeSize),o=a}return new y(n,r)}cutByIndex(e,t){return e==t?y.empty:0==e&&t==this.content.length?this:new y(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new y(r,i)}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,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return m(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return g(this,e,t,n)}findIndex(e,t=-1){if(0==e)return v(0,e);if(e==this.size)return v(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=r+this.child(n).nodeSize;if(i>=e)return i==e||t>0?v(n+1,i):v(n,r);r=i}}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,n=0;for(let r=0;r<e.length;r++){let i=e[r];n+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(t||(t=e.slice(0,r)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new y(t||e,n)}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 w={index:0,offset:0};function v(e,t){return w.index=e,w.offset=t,w}function b(e,t){if(e===t)return!0;if(!e||'object'!=typeof e||!t||'object'!=typeof t)return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!b(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!b(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class k{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}return t||(t=e.slice()),n||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&&b(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 n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);return n.create(t.attrs)}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&0==e.length)return k.none;if(e instanceof k)return[e];let t=e.slice();return t.sort(((e,t)=>e.type.rank-t.type.rank)),t}}k.none=[];class x extends Error{}class S{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=C(this.content,e+this.openStart,t);return n&&new S(n,this.openStart,this.openEnd)}removeBetween(e,t){return new S(M(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 S.empty;let n=t.openStart||0,r=t.openEnd||0;if('number'!=typeof n||'number'!=typeof r)throw new RangeError('Invalid input for Slice.fromJSON');return new S(y.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new S(e,n,r)}}function M(e,t,n){let{index:r,offset:i}=e.findIndex(t),o=e.maybeChild(r),{index:s,offset:a}=e.findIndex(n);if(i==t||o.isText){if(a!=n&&!e.child(s).isText)throw new RangeError('Removing non-flat range');return e.cut(0,t).append(e.cut(n))}if(r!=s)throw new RangeError('Removing non-flat range');return e.replaceChild(r,o.copy(M(o.content,t-i-1,n-i-1)))}function C(e,t,n,r){let{index:i,offset:o}=e.findIndex(t),s=e.maybeChild(i);if(o==t||s.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let a=C(s.content,t-o-1,n);return a&&e.replaceChild(i,s.copy(a))}function T(e,t,n){if(n.openStart>e.depth)throw new x('Inserted content deeper than insertion position');if(e.depth-n.openStart!=t.depth-n.openEnd)throw new x('Inconsistent open depths');return O(e,t,n,0)}function O(e,t,n,r){let i=e.index(r),o=e.node(r);if(i==t.index(r)&&r<e.depth-n.openStart){let s=O(e,t,n,r+1);return o.copy(o.content.replaceChild(i,s))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=r||t.depth!=r){let{start:i,end:s}=function(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(y.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(n,e);return I(o,R(e,i,s,t,r))}{let r=e.parent,i=r.content;return I(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}}return I(o,P(e,t,r))}function N(e,t){if(!t.type.compatibleContent(e.type))throw new x('Cannot join '+t.type.name+' onto '+e.type.name)}function E(e,t,n){let r=e.node(n);return N(r,t.node(n)),r}function A(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function D(e,t,n,r){let i=(t||e).node(n),o=0,s=t?t.index(n):i.childCount;e&&(o=e.index(n),e.depth>n?o++:e.textOffset&&(A(e.nodeAfter,r),o++));for(let e=o;e<s;e++)A(i.child(e),r);t&&t.depth==n&&t.textOffset&&A(t.nodeBefore,r)}function I(e,t){return e.type.checkContent(t),e.copy(t)}function R(e,t,n,r,i){let o=e.depth>i&&E(e,t,i+1),s=r.depth>i&&E(n,r,i+1),a=[];return D(null,e,i,a),o&&s&&t.index(i)==n.index(i)?(N(o,s),A(I(o,R(e,t,n,r,i+1)),a)):(o&&A(I(o,P(e,t,i+1)),a),D(t,n,i,a),s&&A(I(s,P(n,r,i+1)),a)),D(r,null,i,a),new y(a)}function P(e,t,n){let r=[];if(D(null,e,n,r),e.depth>n){A(I(E(e,t,n+1),P(e,t,n+1)),r)}return D(t,null,n,r),new y(r)}S.empty=new S(y.empty,0,0);class L{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?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[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw new RangeError('There is no position before the top-level node');return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw new RangeError('There is no position after the top-level node');return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].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 n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}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):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return k.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var o=0;o<i.length;o++)!1!==i[o].type.spec.inclusive||r&&i[o].isInSet(r.marks)||(i=i[o--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)!1!==n[i].type.spec.inclusive||r&&n[i].isInSet(r.marks)||(n=n[i--].removeFromSet(n));return n}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 n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new V(this,e,n);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 n=[],r=0,i=t;for(let t=e;;){let{index:e,offset:o}=t.content.findIndex(i),s=i-o;if(n.push(t,e,r+o),!s)break;if(t=t.child(e),t.isText)break;i=s-1,r+=o+1}return new L(t,n,i)}static resolveCached(e,t){for(let n=0;n<$.length;n++){let r=$[n];if(r.pos==t&&r.doc==e)return r}let n=$[z]=L.resolve(e,t);return z=(z+1)%B,n}}let $=[],z=0,B=12;class V{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}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 F=Object.create(null);class H{constructor(e,t,n,r=k.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||y.empty}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,n,r=0){this.content.nodesBetween(e,t,n,r,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,n,r){return this.content.textBetween(e,t,n,r)}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,n){return this.type==e&&b(this.attrs,t||e.defaultAttrs||F)&&k.sameSet(this.marks,n||k.none)}copy(e=null){return e==this.content?this:new H(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new H(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return S.empty;let r=this.resolve(e),i=this.resolve(t),o=n?0:r.sharedDepth(t),s=r.start(o),a=r.node(o).content.cut(r.pos-s,i.pos-s);return new S(a,r.depth-o,i.depth-o)}replace(e,t,n){return T(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return L.resolveCached(this,e)}resolveNoCache(e){return L.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,(e=>(n.isInSet(e.marks)&&(r=!0),!r))),r}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()+')'),_(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,n=y.empty,r=0,i=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,i),s=o&&o.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),o=i&&i.matchFragment(this.content,t);return!!o&&o.validEnd}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);let e=k.none;for(let t=0;t<this.marks.length;t++)e=this.marks[t].addToSet(e);if(!k.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((e=>e.type.name))}`);this.content.forEach((e=>e.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((e=>e.toJSON()))),e}static fromJSON(e,t){if(!t)throw new RangeError('Invalid input for Node.fromJSON');let n=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError('Invalid mark data for Node.fromJSON');n=t.marks.map(e.markFromJSON)}if('text'==t.type){if('string'!=typeof t.text)throw new RangeError('Invalid text node in JSON');return e.text(t.text,n)}let r=y.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,r,n)}}H.prototype.text=void 0;class j extends H{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw new RangeError('Empty text nodes are not allowed');this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):_(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 j(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new j(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&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 _(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+'('+t+')';return t}class W{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new J(e,t);if(null==n.next)return W.empty;let r=q(n);n.next&&n.err('Unexpected trailing text');let i=function(e){let t=Object.create(null);return n(Z(e,0));function n(r){let i=[];r.forEach((t=>{e[t].forEach((({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<i.length;e++)i[e][0]==t&&(r=i[e][1]);Z(e,n).forEach((e=>{r||i.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)}))}))}));let o=t[r.join(',')]=new W(r.indexOf(e.length-1)>-1);for(let e=0;e<i.length;e++){let r=i[e][1].sort(X);o.next.push({type:i[e][0],next:t[r.join(',')]||n(r)})}return o}}(function(e){let t=[[]];return i(o(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach((e=>e.to=t))}function o(e,t){if('choice'==e.type)return e.exprs.reduce(((e,n)=>e.concat(o(n,t))),[]);if('seq'!=e.type){if('star'==e.type){let s=n();return r(t,s),i(o(e.expr,s),s),[r(s)]}if('plus'==e.type){let s=n();return i(o(e.expr,t),s),i(o(e.expr,s),s),[r(s)]}if('opt'==e.type)return[r(t)].concat(o(e.expr,t));if('range'==e.type){let s=t;for(let t=0;t<e.min;t++){let t=n();i(o(e.expr,s),t),s=t}if(-1==e.max)i(o(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();r(s,t),i(o(e.expr,s),t),s=t}return[r(s)]}if('name'==e.type)return[r(t,void 0,e.value)];throw new Error('Unknown expr type')}for(let r=0;;r++){let s=o(e.exprs[r],t);if(r==e.exprs.length-1)return s;i(s,t=n())}}}(r));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,o=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];o.push(n.name),!i||n.isText||n.hasRequiredAttrs()||(i=!1),-1==r.indexOf(s)&&r.push(s)}i&&t.err('Only non-generatable nodes ('+o.join(', ')+') in a required position (see https://prosemirror.net/docs/guide/#generatable)')}}(i,n),i}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,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return 0!=this.next.length&&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 n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];return function i(o,s){let a=o.matchFragment(e,n);if(a&&(!t||a.validEnd))return y.from(s.map((e=>e.createAndFill())));for(let e=0;e<o.next.length;e++){let{type:t,next:n}=o.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==r.indexOf(n)){r.push(n);let e=i(n,s.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:o,next:s}=i.next[e];o.isLeaf||o.hasRequiredAttrs()||o.name in t||r.type&&!s.validEnd||(n.push({match:o.contentMatch,type:o,via:r}),t[o.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=[];return function t(n){e.push(n);for(let r=0;r<n.next.length;r++)-1==e.indexOf(n.next[r].next)&&t(n.next[r].next)}(this),e.map(((t,n)=>{let r=n+(t.validEnd?'*':' ')+' ';for(let n=0;n<t.next.length;n++)r+=(n?', ':'')+t.next[n].type.name+'->'+e.indexOf(t.next[n].next);return r})).join('\n')}}W.empty=new W(!0);class J{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 q(e){let t=[];do{t.push(K(e))}while(e.eat('|'));return 1==t.length?t[0]:{type:'choice',exprs:t}}function K(e){let t=[];do{t.push(U(e))}while(e.next&&')'!=e.next&&'|'!=e.next);return 1==t.length?t[0]:{type:'seq',exprs:t}}function U(e){let t=function(e){if(e.eat('(')){let t=q(e);return e.eat(')')||e.err('Missing closing paren'),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.groups.indexOf(t)>-1&&i.push(r)}0==i.length&&e.err('No node type or group \''+t+'\' found');return i}(e,e.next).map((t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err('Mixing inline and block content'),{type:'name',value:t})));return e.pos++,1==t.length?t[0]:{type:'choice',exprs:t}}e.err('Unexpected token \''+e.next+'\'')}(e);for(;;)if(e.eat('+'))t={type:'plus',expr:t};else if(e.eat('*'))t={type:'star',expr:t};else if(e.eat('?'))t={type:'opt',expr:t};else{if(!e.eat('{'))break;t=Y(e,t)}return t}function G(e){/\D/.test(e.next)&&e.err('Expected number, got \''+e.next+'\'');let t=Number(e.next);return e.pos++,t}function Y(e,t){let n=G(e),r=n;return e.eat(',')&&(r='}'!=e.next?G(e):-1),e.eat('}')||e.err('Unclosed braced range'),{type:'range',min:n,max:r,expr:t}}function X(e,t){return t-e}function Z(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e<i.length;e++){let{term:r,to:o}=i[e];r||-1!=n.indexOf(o)||t(o)}}(t),n.sort(X)}function Q(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function ee(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(void 0===i){let t=e[r];if(!t.hasDefault)throw new RangeError('No value supplied for attribute '+r);i=t.default}n[r]=i}return n}function te(e){let t=Object.create(null);if(e)for(let n in e)t[n]=new re(e[n]);return t}class ne{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(' '):[],this.attrs=te(n.attrs),this.defaultAttrs=Q(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||'text'==e),this.isText='text'==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==W.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}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:ee(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error('NodeType.create can\'t construct text nodes');return new H(this,this.computeAttrs(e),y.from(t),k.setFrom(n))}createChecked(e=null,t,n){return t=y.from(t),this.checkContent(t),new H(this,this.computeAttrs(e),t,k.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=y.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(y.empty,!0);return i?new H(this,e,t.append(i),k.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).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)}`)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(null==this.markSet)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:k.none:e}static compile(e,t){let n=Object.create(null);e.forEach(((e,r)=>n[e]=new ne(e,t,r)));let r=t.spec.topNode||'doc';if(!n[r])throw new RangeError('Schema is missing its top node type (\''+r+'\')');if(!n.text)throw new RangeError('Every schema needs a \'text\' type');for(let e in n.text.attrs)throw new RangeError('The text node type should not have attributes');return n}}class re{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,'default'),this.default=e.default}get isRequired(){return!this.hasDefault}}class ie{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=te(r.attrs),this.excluded=null;let i=Q(this.attrs);this.instance=i?new k(this,i):null}create(e=null){return!e&&this.instance?this.instance:new k(this,ee(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach(((e,i)=>n[e]=new ie(e,r++,t,i))),n}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]}excludes(e){return this.excluded.indexOf(e)>-1}}class oe{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=f.from(e.nodes),t.marks=f.from(e.marks||{}),this.nodes=ne.compile(this.spec.nodes,this),this.marks=ie.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw new RangeError(e+' can not be both a node and a mark');let t=this.nodes[e],r=t.spec.content||'',i=t.spec.marks;t.contentMatch=n[r]||(n[r]=W.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.markSet='_'==i?null:i?se(this,i.split(' ')):''!=i&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:''==n?[]:se(this,n.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,n,r){if('string'==typeof e)e=this.nodeType(e);else{if(!(e instanceof ne))throw new RangeError('Invalid node type: '+e);if(e.schema!=this)throw new RangeError('Node type from different schema used ('+e.name+')')}return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new j(n,n.defaultAttrs,e,k.setFrom(t))}mark(e,t){return'string'==typeof e&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return H.fromJSON(this,e)}markFromJSON(e){return k.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError('Unknown node type: '+e);return t}}function se(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],o=e.marks[i],s=o;if(o)n.push(o);else for(let t in e.marks){let r=e.marks[t];('_'==i||r.spec.group&&r.spec.group.split(' ').indexOf(i)>-1)&&n.push(s=r)}if(!s)throw new SyntaxError('Unknown mark type: \''+t[r]+'\'')}return n}class ae{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach((e=>{e.tag?this.tags.push(e):e.style&&this.styles.push(e)})),this.normalizeLists=!this.tags.some((t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)}))}parse(e,t={}){let n=new ue(this,t,!1);return n.addAll(e,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ue(this,t,!0);return n.addAll(e,t.from,t.to),S.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(fe(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],o=r.style;if(!(0!=o.indexOf(e)||r.context&&!n.matchesContext(r.context)||o.length>e.length&&(61!=o.charCodeAt(e.length)||o.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((null==e.priority?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach((e=>{n(e=me(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)}))}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach((e=>{n(e=me(e)),e.node||e.ignore||e.mark||(e.node=t)}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new ae(e,ae.schemaRules(e)))}}const le={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},ce={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},de={ol:!0,ul:!0};function he(e,t,n){return null!=t?(t?1:0)|('full'===t?2:0):e&&'pre'==e.whitespace?3:-5&n}class pe{constructor(e,t,n,r,i,o,s){this.type=e,this.attrs=t,this.marks=n,this.pendingMarks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=k.none,this.stashMarks=[],this.match=o||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[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}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,n=this.pendingMarks;t<n.length;t++){let r=n[t];(this.type?this.type.allowsMarkType(r.type):ge(r.type,e))&&!r.isInSet(this.activeMarks)&&(this.activeMarks=r.addToSet(this.activeMarks),this.pendingMarks=r.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!le.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class ue{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0;let r,i=t.topNode,o=he(null,t.preserveWhitespace,0)|(n?4:0);r=i?new pe(i.type,i.attrs,k.none,k.none,!0,t.topMatch||i.type.contentMatch,o):new pe(n?null:e.schema.topNodeType,null,k.none,k.none,!0,null,o),this.nodes=[r],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){if(3==e.nodeType)this.addTextNode(e);else if(1==e.nodeType){let t=e.getAttribute('style');if(t){let n=this.readStyles(function(e){let t,n=/\s*([\w-]+)\s*:\s*([^;]+)/g,r=[];for(;t=n.exec(e);)r.push(t[1],t[2].trim());return r}(t));if(!n)return;let[r,i]=n,o=this.top;for(let e=0;e<i.length;e++)this.removePendingMark(i[e],o);for(let e=0;e<r.length;e++)this.addPendingMark(r[e]);this.addElement(e);for(let e=0;e<r.length;e++)this.removePendingMark(r[e],o);for(let e=0;e<i.length;e++)this.addPendingMark(i[e])}else this.addElement(e)}}addTextNode(e){let t=e.nodeValue,n=this.top;if(2&n.options||n.inlineContext(e)||/[^ \t\r\n\u000c]/.test(t)){if(1&n.options)t=2&n.options?t.replace(/\r\n?/g,'\n'):t.replace(/\r?\n|\r/g,' ');else if(t=t.replace(/[ \t\r\n\u000c]+/g,' '),/^[ \t\r\n\u000c]/.test(t)&&this.open==this.nodes.length-1){let r=n.content[n.content.length-1],i=e.previousSibling;(!r||i&&'BR'==i.nodeName||r.isText&&/[ \t\r\n\u000c]$/.test(r.text))&&(t=t.slice(1))}t&&this.insertNode(this.parser.schema.text(t)),this.findInText(e)}else this.findInside(e)}addElement(e,t){let n,r=e.nodeName.toLowerCase();de.hasOwnProperty(r)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&de.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):'li'==e?n=t:e&&(n=null)}}(e);let i=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(n=this.parser.matchTag(e,this,t));if(i?i.ignore:ce.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e);else if(!i||i.skip||i.closeParent){i&&i.closeParent?this.open=Math.max(0,this.open-1):i&&i.skip.nodeType&&(e=i.skip);let t,n=this.top,o=this.needsBlock;if(le.hasOwnProperty(r))n.content.length&&n.content[0].isInline&&this.open&&(this.open--,n=this.top),t=!0,n.type||(this.needsBlock=!0);else if(!e.firstChild)return void this.leafFallback(e);this.addAll(e),t&&this.sync(n),this.needsBlock=o}else this.addElementByRule(e,i,!1===i.consuming?n:void 0)}leafFallback(e){'BR'==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode('\n'))}ignoreFallback(e){'BR'!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text('-'))}readStyles(e){let t=k.none,n=k.none;e:for(let r=0;r<e.length;r+=2)for(let i;;){let o=this.parser.matchStyle(e[r],e[r+1],this,i);if(!o)continue e;if(o.ignore)return null;if(o.clearMark?this.top.pendingMarks.forEach((e=>{o.clearMark(e)&&(n=e.addToSet(n))})):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),!1!==o.consuming)break;i=o}return[t,n]}addElementByRule(e,t,n){let r,i,o;if(t.node)i=this.parser.schema.nodes[t.node],i.isLeaf?this.insertNode(i.create(t.attrs))||this.leafFallback(e):r=this.enter(i,t.attrs||null,t.preserveWhitespace);else{o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o)}let s=this.top;if(i&&i.isLeaf)this.findInside(e);else if(n)this.addElement(e,n);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach((e=>this.insertNode(e)));else{let n=e;'string'==typeof t.contentElement?n=e.querySelector(t.contentElement):'function'==typeof t.contentElement?n=t.contentElement(e):t.contentElement&&(n=t.contentElement),this.findAround(e,n,!0),this.addAll(n)}r&&this.sync(s)&&this.open--,o&&this.removePendingMark(o,s)}addAll(e,t,n){let r=t||0;for(let i=t?e.childNodes[t]:e.firstChild,o=null==n?null:e.childNodes[n];i!=o;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i);this.findAtPoint(e,r)}findPlace(e){let t,n;for(let r=this.open;r>=0;r--){let i=this.nodes[r],o=i.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,n=i,!o.length))break;if(i.solid)break}if(!t)return!1;this.sync(n);for(let e=0;e<t.length;e++)this.enterInner(t[e],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&this.enterInner(e)}if(this.findPlace(e)){this.closeExtra();let t=this.top;t.applyPending(e.type),t.match&&(t.match=t.match.matchType(e.type));let n=t.activeMarks;for(let r=0;r<e.marks.length;r++)t.type&&!t.type.allowsMarkType(e.marks[r].type)||(n=e.marks[r].addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n){let r=this.findPlace(e.create(t));return r&&this.enterInner(e,t,!0,n),r}enterInner(e,t=null,n=!1,r){this.closeExtra();let i=this.top;i.applyPending(e),i.match=i.match&&i.match.matchType(e);let o=he(e,r,i.options);4&i.options&&0==i.content.length&&(o|=4),this.nodes.push(new pe(e,t,i.activeMarks,i.pendingMarks,n,null,o)),this.open++}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 n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)if(null==this.find[r].pos&&1==e.nodeType&&e.contains(this.find[r].node)){t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].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('/'),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),i=-(n?n.depth+1:0)+(r?0:1),o=(e,s)=>{for(;e>=0;e--){let a=t[e];if(''==a){if(e==t.length-1||0==e)continue;for(;s>=i;s--)if(o(e-1,s))return!0;return!1}{let e=s>0||0==s&&r?this.nodes[s].type:n&&s>=i?n.node(s-i).type:null;if(!e||e.name!=a&&-1==e.groups.indexOf(a))return!1;s--}}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 n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}addPendingMark(e){let t=function(e,t){for(let n=0;n<t.length;n++)if(e.eq(t[n]))return t[n]}(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let n=this.open;n>=0;n--){let r=this.nodes[n];if(r.pendingMarks.lastIndexOf(e)>-1)r.pendingMarks=e.removeFromSet(r.pendingMarks);else{r.activeMarks=e.removeFromSet(r.activeMarks);let t=r.popFromStashMark(e);t&&r.type&&r.type.allowsMarkType(t.type)&&(r.activeMarks=t.addToSet(r.activeMarks))}if(r==t)break}}}function fe(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function me(e){let t={};for(let n in e)t[n]=e[n];return t}function ge(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let o=[],s=e=>{o.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t)return!0;if(o.indexOf(i)<0&&s(i))return!0}};if(s(i.contentMatch))return!0}}class ye{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=ve(t).createDocumentFragment());let r=n,i=[];return e.forEach((e=>{if(i.length||e.marks.length){let n=0,o=0;for(;n<i.length&&o<e.marks.length;){let t=e.marks[o];if(this.marks[t.type.name]){if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,o++}else o++}for(;n<i.length;)r=i.pop()[1];for(;o<e.marks.length;){let n=e.marks[o++],s=this.serializeMark(n,e.isInline,t);s&&(i.push([n,r]),r.appendChild(s.dom),r=s.contentDOM||s.dom)}}r.appendChild(this.serializeNodeInner(e,t))})),n}serializeNodeInner(e,t){let{dom:n,contentDOM:r}=ye.renderSpec(ve(t),this.nodes[e.type.name](e));if(r){if(e.isLeaf)throw new RangeError('Content hole not allowed in a leaf node spec');this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&ye.renderSpec(ve(n),r(e,t))}static renderSpec(e,t,n=null){if('string'==typeof t)return{dom:e.createTextNode(t)};if(null!=t.nodeType)return{dom:t};if(t.dom&&null!=t.dom.nodeType)return t;let r,i=t[0],o=i.indexOf(' ');o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s=n?e.createElementNS(n,i):e.createElement(i),a=t[1],l=1;if(a&&'object'==typeof a&&null==a.nodeType&&!Array.isArray(a)){l=2;for(let e in a)if(null!=a[e]){let t=e.indexOf(' ');t>0?s.setAttributeNS(e.slice(0,t),e.slice(t+1),a[e]):s.setAttribute(e,a[e])}}for(let i=l;i<t.length;i++){let o=t[i];if(0===o){if(i<t.length-1||i>l)throw new RangeError('Content hole must be the only child of its parent node');return{dom:s,contentDOM:s}}{let{dom:t,contentDOM:i}=ye.renderSpec(e,o,n);if(s.appendChild(t),i){if(r)throw new RangeError('Multiple content holes');r=i}}}return{dom:s,contentDOM:r}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new ye(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=we(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return we(e.marks)}}function we(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function ve(e){return e.document||window.document}const be=Math.pow(2,16);function ke(e){return 65535&e}class xe{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class Se{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Se.empty)return Se.empty}recover(e){let t=0,n=ke(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/be}(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,i=this.inverted?2:1,o=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let a=this.ranges[s]-(this.inverted?r:0);if(a>e)break;let l=this.ranges[s+i],c=this.ranges[s+o],d=a+l;if(e<=d){let i=a+r+((l?e==a?-1:e==d?1:t:t)<0?0:c);if(n)return i;let o=e==(t<0?a:d)?null:s/3+(e-a)*be,h=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(h|=8),new xe(i,h,o)}r+=c-l}return n?e+r:new xe(e+r,0,null)}touches(e,t){let n=0,r=ke(t),i=this.inverted?2:1,o=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let s=this.ranges[t]-(this.inverted?n:0);if(s>e)break;let a=this.ranges[t+i];if(e<=s+a&&t==3*r)return!0;n+=this.ranges[t+o]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let o=this.ranges[r],s=o-(this.inverted?i:0),a=o+(this.inverted?0:i),l=this.ranges[r+t],c=this.ranges[r+n];e(s,s+l,a,a+c),i+=c-l}}invert(){return new Se(this.ranges,!this.inverted)}toString(){return(this.inverted?'-':'')+JSON.stringify(this.ranges)}static offset(e){return 0==e?Se.empty:new Se(e<0?[0,-e,0]:[0,0,e])}}Se.empty=new Se([]);class Me{constructor(e=[],t,n=0,r=e.length){this.maps=e,this.mirror=t,this.from=n,this.to=r}slice(e=0,t=this.maps.length){return new Me(this.maps,this.mirror,e,t)}copy(){return new Me(this.maps.slice(),this.mirror&&this.mirror.slice(),this.from,this.to)}appendMap(e,t){this.to=this.maps.push(e),null!=t&&this.setMirror(this.maps.length-1,t)}appendMapping(e){for(let t=0,n=this.maps.length;t<e.maps.length;t++){let r=e.getMirror(t);this.appendMap(e.maps[t],null!=r&&r<t?n+r: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,n=this.maps.length+e.maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e.maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new Me;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this.maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this.maps[n].mapResult(e,t);if(null!=i.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this.maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new xe(e,r,null)}}const Ce=Object.create(null);class Te{getMap(){return Se.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError('Invalid input for Step.fromJSON');let n=Ce[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Ce)throw new RangeError('Duplicate use of step JSON ID '+e);return Ce[e]=t,t.prototype.jsonID=e,t}}class Oe{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new Oe(e,null)}static fail(e){return new Oe(null,e)}static fromReplace(e,t,n,r){try{return Oe.ok(e.replace(t,n,r))}catch(e){if(e instanceof x)return Oe.fail(e.message);throw e}}}function Ne(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy(Ne(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return y.fromArray(r)}class Ee extends Te{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=new S(Ne(t.content,((e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e),r),t.openStart,t.openEnd);return Oe.fromReplace(e,this.from,this.to,i)}invert(){return new Ae(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Ee(t.pos,n.pos,this.mark)}merge(e){return e instanceof Ee&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ee(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('number'!=typeof t.from||'number'!=typeof t.to)throw new RangeError('Invalid input for AddMarkStep.fromJSON');return new Ee(t.from,t.to,e.markFromJSON(t.mark))}}Te.jsonID('addMark',Ee);class Ae extends Te{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new S(Ne(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return Oe.fromReplace(e,this.from,this.to,n)}invert(){return new Ee(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new Ae(t.pos,n.pos,this.mark)}merge(e){return e instanceof Ae&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ae(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('number'!=typeof t.from||'number'!=typeof t.to)throw new RangeError('Invalid input for RemoveMarkStep.fromJSON');return new Ae(t.from,t.to,e.markFromJSON(t.mark))}}Te.jsonID('removeMark',Ae);class De extends Te{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Oe.fail('No node at mark step\'s position');let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Oe.fromReplace(e,this.pos,this.pos+1,new S(y.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new De(this.pos,t.marks[n]);return new De(this.pos,this.mark)}}return new Ie(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new De(t.pos,this.mark)}toJSON(){return{stepType:'addNodeMark',pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if('number'!=typeof t.pos)throw new RangeError('Invalid input for AddNodeMarkStep.fromJSON');return new De(t.pos,e.markFromJSON(t.mark))}}Te.jsonID('addNodeMark',De);class Ie extends Te{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Oe.fail('No node at mark step\'s position');let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Oe.fromReplace(e,this.pos,this.pos+1,new S(y.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new De(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ie(t.pos,this.mark)}toJSON(){return{stepType:'removeNodeMark',pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if('number'!=typeof t.pos)throw new RangeError('Invalid input for RemoveNodeMarkStep.fromJSON');return new Ie(t.pos,e.markFromJSON(t.mark))}}Te.jsonID('removeNodeMark',Ie);class Re extends Te{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Le(e,this.from,this.to)?Oe.fail('Structure replace would overwrite content'):Oe.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Se([this.from,this.to-this.from,this.slice.size])}invert(e){return new Re(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deletedAcross&&n.deletedAcross?null:new Re(t.pos,Math.max(t.pos,n.pos),this.slice)}merge(e){if(!(e instanceof Re)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let t=this.slice.size+e.slice.size==0?S.empty:new S(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Re(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?S.empty:new S(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Re(this.from,this.to+(e.to-e.from),t,this.structure)}}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('number'!=typeof t.from||'number'!=typeof t.to)throw new RangeError('Invalid input for ReplaceStep.fromJSON');return new Re(t.from,t.to,S.fromJSON(e,t.slice),!!t.structure)}}Te.jsonID('replace',Re);class Pe extends Te{constructor(e,t,n,r,i,o,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=o,this.structure=s}apply(e){if(this.structure&&(Le(e,this.from,this.gapFrom)||Le(e,this.gapTo,this.to)))return Oe.fail('Structure gap-replace would overwrite content');let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Oe.fail('Gap is not a flat range');let n=this.slice.insertAt(this.insert,t.content);return n?Oe.fromReplace(e,this.from,this.to,n):Oe.fail('Content does not fit in gap')}getMap(){return new Se([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 Pe(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),n=e.mapResult(this.to,-1),r=e.map(this.gapFrom,-1),i=e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||i>n.pos?null:new Pe(t.pos,n.pos,r,i,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('number'!=typeof t.from||'number'!=typeof t.to||'number'!=typeof t.gapFrom||'number'!=typeof t.gapTo||'number'!=typeof t.insert)throw new RangeError('Invalid input for ReplaceAroundStep.fromJSON');return new Pe(t.from,t.to,t.gapFrom,t.gapTo,S.fromJSON(e,t.slice),t.insert,!!t.structure)}}function Le(e,t,n){let r=e.resolve(t),i=n-t,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let e=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function $e(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function ze(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let r=e.$from.node(n),i=e.$from.index(n),o=e.$to.indexAfter(n);if(n<e.depth&&r.canReplace(i,o,t))return n;if(0==n||r.type.spec.isolating||!$e(r,i,o))break}return null}function Be(e,t,n=null,r=e){let i=function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,o=n.contentMatchAt(r).findWrapping(t);if(!o)return null;let s=o.length?o[0]:t;return n.canReplaceWith(r,i,s)?o:null}(e,t),o=i&&function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,o=n.child(r),s=t.contentMatch.findWrapping(o.type);if(!s)return null;let a=(s.length?s[s.length-1]:t).contentMatch;for(let e=r;a&&e<i;e++)a=a.matchType(n.child(e).type);return a&&a.validEnd?s:null}(r,t);return o?i.map(Ve).concat({type:t,attrs:n}).concat(o.map(Ve)):null}function Ve(e){return{type:e,attrs:null}}function Fe(e,t,n=1,r){let i=e.resolve(t),o=i.depth-n,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>o;e--,t--){let n=i.node(e),o=i.index(e);if(n.type.spec.isolating)return!1;let s=n.content.cutByIndex(o,n.childCount),a=r&&r[t]||n;if(a!=n&&(s=s.replaceChild(0,a.type.create(a.attrs))),!n.canReplace(o+1,n.childCount)||!a.type.validContent(s))return!1}let a=i.indexAfter(o),l=r&&r[0];return i.node(o).canReplaceWith(a,a,l?l.type:i.node(o+1).type)}function He(e,t){let n=e.resolve(t),r=n.index();return je(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function je(e,t){return!(!e||!t||e.isLeaf||!e.canAppend(t))}function _e(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,o,s=r.index(e);if(e==r.depth?(i=r.nodeBefore,o=r.nodeAfter):n>0?(i=r.node(e+1),s++,o=r.node(e).maybeChild(s)):(i=r.node(e).maybeChild(s-1),o=r.node(e+1)),i&&!i.isTextblock&&je(i,o)&&r.node(e).canReplace(s,s+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function We(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,o=r.index(t)+(n>0?1:0),s=r.node(t),a=!1;if(1==e)a=s.canReplace(o,o,i);else{let e=s.contentMatchAt(o).findWrapping(i.firstChild.type);a=e&&s.canReplaceWith(o,o,e[0])}if(a)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function Je(e,t,n=t,r=S.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),o=e.resolve(n);return qe(i,o,r)?new Re(t,n,r):new Ke(i,o,r).fit()}function qe(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}Te.jsonID('replaceAround',Pe);class Ke{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=y.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=y.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,o=n.depth,s=r.depth;for(;o&&s&&1==i.childCount;)i=i.firstChild.content,o--,s--;let a=new S(i,o,s);return e>-1?new Pe(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new Re(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=Ye(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let o,{type:s,match:a}=this.frontier[e],l=null;if(1==t&&(i?a.matchType(i.type)||(l=a.fillBefore(y.from(i),!1)):r&&s.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:l};if(2==t&&i&&(o=a.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:o};if(r&&a.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Ye(e,t);return!(!r.childCount||r.firstChild.isLeaf)&&(this.unplaced=new S(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Ye(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new S(Ue(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new S(Ue(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let o=this.unplaced,s=n?n.content:o.content,a=o.openStart-e,l=0,c=[],{match:d,type:h}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)c.push(r.child(e));d=d.matchFragment(r)}let p=s.size+e-(o.content.size-o.openEnd);for(;l<s.childCount;){let e=s.child(l),t=d.matchType(e.type);if(!t)break;l++,(l>1||0==a||e.content.size)&&(d=t,c.push(Xe(e.mark(h.allowedMarks(e.marks)),1==l?a:0,l==s.childCount?p:-1)))}let u=l==s.childCount;u||(p=-1),this.placed=Ge(this.placed,t,y.from(c)),this.frontier[t].match=d,u&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=s;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=u?0==e?S.empty:new S(Ue(o.content,e-1,1),e-1,p<0?o.openEnd:e-1):new S(Ue(o.content,e,l),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e,t=this.frontier[this.depth];if(!t.type.isTextblock||!Ze(this.$to,this.$to.depth,t.type,t.match,!1)||this.$to.depth==this.depth&&(e=this.findCloseLevel(this.$to))&&e.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=Ze(e,t,r,n,i);if(o){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=Ze(e,n,r,t,!0);if(!i||i.childCount)continue e}return{depth:t,fit:o,move:i?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=Ge(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Ge(this.placed,this.depth,y.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(y.empty,!0);e.childCount&&(this.placed=Ge(this.placed,this.frontier.length,e))}}function Ue(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(Ue(e.firstChild.content,t-1,n)))}function Ge(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Ge(e.lastChild.content,t-1,n)))}function Ye(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function Xe(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,Xe(r.firstChild,t-1,1==r.childCount?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),e.copy(r)}function Ze(e,t,n,r,i){let o=e.node(t),s=i?e.indexAfter(t):e.index(t);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let a=r.fillBefore(o.content,!0,s);return a&&!function(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}(n,o.content,s)?a:null}function Qe(e){return e.spec.defining||e.spec.definingForContent}function et(e,t,n,r,i){if(t<n){let i=e.firstChild;e=e.replaceChild(0,i.copy(et(i.content,t+1,n,r,i)))}if(t>r){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(y.empty,!0))}return e}function tt(e,t){let n=[];for(let r=Math.min(e.depth,t.depth);r>=0;r--){let i=e.start(r);if(i<e.pos-(e.depth-r)||t.end(r)>t.pos+(t.depth-r)||e.node(r).type.spec.isolating||t.node(r).type.spec.isolating)break;(i==t.start(r)||r==e.depth&&r==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&r&&t.start(r-1)==i-1)&&n.push(r)}return n}class nt extends Te{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return Oe.fail('No node at attribute step\'s position');let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return Oe.fromReplace(e,this.pos,this.pos+1,new S(y.from(r),0,t.isLeaf?0:1))}getMap(){return Se.empty}invert(e){return new nt(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 nt(t.pos,this.attr,this.value)}toJSON(){return{stepType:'attr',pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if('number'!=typeof t.pos||'string'!=typeof t.attr)throw new RangeError('Invalid input for AttrStep.fromJSON');return new nt(t.pos,t.attr,t.value)}}Te.jsonID('attr',nt);let rt=class extends Error{};rt=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(rt.prototype=Object.create(Error.prototype)).constructor=rt,rt.prototype.name='TransformError';const it=Object.create(null);class ot{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new st(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=S.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,o=this.ranges;for(let s=0;s<o.length;s++){let{$from:a,$to:l}=o[s],c=e.mapping.slice(i);e.replaceRange(c.map(a.pos),c.map(l.pos),s?S.empty:t),0==s&>(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:o,$to:s}=r[i],a=e.mapping.slice(n),l=a.map(o.pos),c=a.map(s.pos);i?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),gt(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new ct(e):mt(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?mt(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):mt(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new ut(e.node(0))}static atStart(e){return mt(e,e,0,0,1)||new ut(e)}static atEnd(e){return mt(e,e,e.content.size,e.childCount,-1)||new ut(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError('Invalid input for Selection.fromJSON');let n=it[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in it)throw new RangeError('Duplicate use of selection JSON ID '+e);return it[e]=t,t.prototype.jsonID=e,t}getBookmark(){return ct.between(this.$anchor,this.$head).getBookmark()}}ot.prototype.visible=!0;class st{constructor(e,t){this.$from=e,this.$to=t}}let at=!1;function lt(e){at||e.parent.inlineContent||(at=!0,console.warn('TextSelection endpoint not pointing into a node with inline content ('+e.parent.type.name+')'))}class ct extends ot{constructor(e,t=e){lt(e),lt(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return ot.near(n);let r=e.resolve(t.map(this.anchor));return new ct(r.parent.inlineContent?r:n,n)}replace(e,t=S.empty){if(super.replace(e,t),t==S.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof ct&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new dt(this.anchor,this.head)}toJSON(){return{type:'text',anchor:this.anchor,head:this.head}}static fromJSON(e,t){if('number'!=typeof t.anchor||'number'!=typeof t.head)throw new RangeError('Invalid input for TextSelection.fromJSON');return new ct(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if(n&&!r||(n=r>=0?1:-1),!t.parent.inlineContent){let e=ot.findFrom(t,n,!0)||ot.findFrom(t,-n,!0);if(!e)return ot.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r||(e=(ot.findFrom(e,-n,!0)||ot.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0)&&(e=t),new ct(e,t)}}ot.jsonID('text',ct);class dt{constructor(e,t){this.anchor=e,this.head=t}map(e){return new dt(e.map(this.anchor),e.map(this.head))}resolve(e){return ct.between(e.resolve(this.anchor),e.resolve(this.head))}}class ht extends ot{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),i=e.resolve(r);return n?ot.near(i):new ht(i)}content(){return new S(y.from(this.node),0,0)}eq(e){return e instanceof ht&&e.anchor==this.anchor}toJSON(){return{type:'node',anchor:this.anchor}}getBookmark(){return new pt(this.anchor)}static fromJSON(e,t){if('number'!=typeof t.anchor)throw new RangeError('Invalid input for NodeSelection.fromJSON');return new ht(e.resolve(t.anchor))}static create(e,t){return new ht(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}ht.prototype.visible=!1,ot.jsonID('node',ht);class pt{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new dt(n,n):new pt(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&ht.isSelectable(n)?new ht(t):ot.near(t)}}class ut extends ot{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=S.empty){if(t==S.empty){e.delete(0,e.doc.content.size);let t=ot.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:'all'}}static fromJSON(e){return new ut(e)}map(e){return new ut(e)}eq(e){return e instanceof ut}getBookmark(){return ft}}ot.jsonID('all',ut);const ft={map(){return this},resolve:e=>new ut(e)};function mt(e,t,n,r,i,o=!1){if(t.inlineContent)return ct.create(e,n);for(let s=r-(i>0?0:1);i>0?s<t.childCount:s>=0;s+=i){let r=t.child(s);if(r.isAtom){if(!o&&ht.isSelectable(r))return ht.create(e,n-(i<0?r.nodeSize:0))}else{let t=mt(e,r,n+i,i<0?r.childCount:0,i,o);if(t)return t}n+=r.nodeSize*i}return null}function gt(e,t,n){let r=e.steps.length-1;if(r<t)return;let i,o=e.steps[r];(o instanceof Re||o instanceof Pe)&&(e.mapping.maps[r].forEach(((e,t,n,r)=>{null==i&&(i=r)})),e.setSelection(ot.near(e.doc.resolve(i),n)))}class yt extends class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Me}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new rt(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,n=S.empty){let r=Je(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new S(y.from(n),0,0))}delete(e,t){return this.replace(e,t,S.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),o=e.doc.resolve(n);if(qe(i,o,r))return e.step(new Re(t,n,r));let s=tt(i,e.doc.resolve(n));0==s[s.length-1]&&s.pop();let a=-(i.depth+1);s.unshift(a);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;s.indexOf(e)>-1?a=e:i.before(e)==t&&s.splice(1,0,-e)}let l=s.indexOf(a),c=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){let t=c[e].type,n=Qe(t);if(n&&i.node(l).type!=t)d=e;else if(n||!t.isTextblock)break}for(let t=r.openStart;t>=0;t--){let a=(t+d+1)%(r.openStart+1),h=c[a];if(h)for(let t=0;t<s.length;t++){let c=s[(t+l)%s.length],d=!0;c<0&&(d=!1,c=-c);let p=i.node(c-1),u=i.index(c-1);if(p.canReplaceWith(u,u,h.type,h.marks))return e.replace(i.before(c),d?o.after(c):n,new S(et(r.content,0,r.openStart,a),a,r.openEnd))}}let h=e.steps.length;for(let a=s.length-1;a>=0&&(e.replace(t,n,r),!(e.steps.length>h));a--){let e=s[a];e<0||(t=i.before(e),n=o.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=((e,t,n)=>{let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)return null}return null})(e.doc,t,r.type);null!=i&&(t=n=i)}e.replaceRange(t,n,new S(y.from(r),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),o=tt(r,i);for(let t=0;t<o.length;t++){let n=o[t],s=t==o.length-1;if(s&&0==n||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(s||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(t-r.start(o)==r.depth-o&&n>r.end(o)&&i.end(o)-n!=i.depth-o)return e.delete(r.before(o),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:r,$to:i,depth:o}=t,s=r.before(o+1),a=i.after(o+1),l=s,c=a,d=y.empty,h=0;for(let e=o,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=y.from(r.node(e).copy(d)),h++):l--;let p=y.empty,u=0;for(let e=o,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=y.from(i.node(e).copy(p)),u++):c++;e.step(new Pe(l,c,s,a,new S(d.append(p),h,u),d.size-h,!0))}(this,e,t),this}join(e,t=1){return function(e,t,n){let r=new Re(t-n,t+n,S.empty,!0);e.step(r)}(this,e,t),this}wrap(e,t){return function(e,t,n){let r=y.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw new RangeError('Wrapper type given to Transform.wrap does not form valid content of its parent wrapper')}r=y.from(n[e].type.create(n[e].attrs,r))}let i=t.start,o=t.end;e.step(new Pe(i,o,i,o,new S(r,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,r=null){return function(e,t,n,r,i){if(!r.isTextblock)throw new RangeError('Type given to setBlockType should be a textblock');let o=e.steps.length;e.doc.nodesBetween(t,n,((t,n)=>{if(t.isTextblock&&!t.hasMarkup(r,i)&&((e,t,n)=>{let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)})(e.doc,e.mapping.slice(o).map(n),r)){e.clearIncompatible(e.mapping.slice(o).map(n,1),r);let s=e.mapping.slice(o),a=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new Pe(a,l,a+1,l-1,new S(y.from(r.create(i,null,t.marks)),0,0),1,!0)),!1}}))}(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return function(e,t,n,r,i){let o=e.doc.nodeAt(t);if(!o)throw new RangeError('No node at given position');n||(n=o.type);let s=n.create(r,null,i||o.marks);if(o.isLeaf)return e.replaceWith(t,t+o.nodeSize,s);if(!n.validContent(o.content))throw new RangeError('Invalid content for node type '+n.name);e.step(new Pe(t,t+o.nodeSize,t+1,t+o.nodeSize-1,new S(y.from(s),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new nt(e,t,n)),this}addNodeMark(e,t){return this.step(new De(e,t)),this}removeNodeMark(e,t){if(!(t instanceof k)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError('No node at position '+e);if(!(t=t.isInSet(n.marks)))return this}return this.step(new Ie(e,t)),this}split(e,t=1,n){return function(e,t,n=1,r){let i=e.doc.resolve(t),o=y.empty,s=y.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){o=y.from(i.node(e).copy(o));let t=r&&r[a];s=y.from(t?t.type.create(t.attrs,s):i.node(e).copy(s))}e.step(new Re(t,t,new S(o.append(s),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,r){let i,o,s=[],a=[];e.doc.nodesBetween(t,n,((e,l,c)=>{if(!e.isInline)return;let d=e.marks;if(!r.isInSet(d)&&c.type.allowsMarkType(r.type)){let c=Math.max(l,t),h=Math.min(l+e.nodeSize,n),p=r.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(i&&i.to==c&&i.mark.eq(d[e])?i.to=h:s.push(i=new Ae(c,h,d[e])));o&&o.to==c?o.to=h:a.push(o=new Ee(c,h,r))}})),s.forEach((t=>e.step(t))),a.forEach((t=>e.step(t)))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,r){let i=[],o=0;e.doc.nodesBetween(t,n,((e,s)=>{if(!e.isInline)return;o++;let a=null;if(r instanceof ie){let t,n=e.marks;for(;t=r.isInSet(n);)(a||(a=[])).push(t),n=t.removeFromSet(n)}else r?r.isInSet(e.marks)&&(a=[r]):a=e.marks;if(a&&a.length){let r=Math.min(s+e.nodeSize,n);for(let e=0;e<a.length;e++){let n,l=a[e];for(let e=0;e<i.length;e++){let t=i[e];t.step==o-1&&l.eq(i[e].style)&&(n=t)}n?(n.to=r,n.step=o):i.push({style:l,from:Math.max(s,t),to:r,step:o})}}})),i.forEach((t=>e.step(new Ae(t.from,t.to,t.style))))}(this,e,t,n),this}clearIncompatible(e,t,n){return function(e,t,n,r=n.contentMatch){let i=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t<i.childCount;t++){let a=i.child(t),l=s+a.nodeSize,c=r.matchType(a.type);if(c){r=c;for(let t=0;t<a.marks.length;t++)n.allowsMarkType(a.marks[t].type)||e.step(new Ae(s,l,a.marks[t]))}else o.push(new Re(s,l,S.empty));s=l}if(!r.validEnd){let t=r.fillBefore(y.empty,!0);e.replace(s,s,new S(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}(this,e,t,n),this}}{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=-3&(1|this.updated),this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return k.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(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||k.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),n=n??t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.setSelection(ot.near(this.selection.$to)),this}}setMeta(e,t){return this.meta['string'==typeof e?e:e.key]=t,this}getMeta(e){return this.meta['string'==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function wt(e,t){return t&&e?e.bind(t):e}class vt{constructor(e,t,n){this.name=e,this.init=wt(t.init,n),this.apply=wt(t.apply,n)}}const bt=[new vt('doc',{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new vt('selection',{init:(e,t)=>e.selection||ot.atStart(t.doc),apply:e=>e.selection}),new vt('storedMarks',{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new vt('scrollToSelection',{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class kt{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=bt.slice(),t&&t.forEach((e=>{if(this.pluginsByKey[e.key])throw new RangeError('Adding different instances of a keyed plugin ('+e.key+')');this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new vt(e.key,e.spec.state,e))}))}}class xt{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 n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let o=0;o<this.config.plugins.length;o++){let s=this.config.plugins[o];if(s.spec.appendTransaction){let a=r?r[o].n:0,l=r?r[o].state:this,c=a<t.length&&s.spec.appendTransaction.call(s,a?t.slice(a):t,l,n);if(c&&n.filterTransaction(c,o)){if(c.setMeta('appendedTransaction',e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<o?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),i=!0}r&&(r[o]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError('Applying a mismatched transaction');let t=new xt(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new yt(this)}static create(e){let t=new kt(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new xt(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new kt(this.schema,e.plugins),n=t.fields,r=new xt(t);for(let t=0;t<n.length;t++){let i=n[t].name;r[i]=this.hasOwnProperty(i)?this[i]:n[t].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map((e=>e.toJSON()))),e&&'object'==typeof e)for(let n in e){if('doc'==n||'selection'==n)throw new RangeError('The JSON fields `doc` and `selection` are reserved');let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw new RangeError('Invalid input for EditorState.fromJSON');if(!e.schema)throw new RangeError('Required config field \'schema\' missing');let r=new kt(e.schema,e.plugins),i=new xt(r);return r.fields.forEach((r=>{if('doc'==r.name)i.doc=H.fromJSON(e.schema,t.doc);else if('selection'==r.name)i.selection=ot.fromJSON(i.doc,t.selection);else if('storedMarks'==r.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let o in n){let s=n[o],a=s.spec.state;if(s.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,o))return void(i[r.name]=a.fromJSON.call(s,e,t[o],i))}i[r.name]=r.init(e,i)}})),i}}function St(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):'handleDOMEvents'==r&&(i=St(i,t,{})),n[r]=i}return n}class Mt{constructor(e){this.spec=e,this.props={},e.props&&St(e.props,this,this.props),this.key=e.key?e.key.key:Tt('plugin')}getState(e){return e[this.key]}}const Ct=Object.create(null);function Tt(e){return e in Ct?e+'$'+ ++Ct[e]:(Ct[e]=0,e+'$')}class Ot{constructor(e='key'){this.key=Tt(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Nt=e=>{for(var t=0;;t++)if(!(e=e.previousSibling))return t},Et=e=>{let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let At=null;const Dt=(e,t,n)=>{let r=At||(At=document.createRange());return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},It=(e,t,n,r)=>n&&(Pt(e,t,n,r,-1)||Pt(e,t,n,r,1)),Rt=/^(img|br|input|textarea|hr)$/i;function Pt(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Lt(e))){let n=e.parentNode;if(!n||1!=n.nodeType||$t(e)||Rt.test(e.nodeName)||'false'==e.contentEditable)return!1;t=Nt(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;if('false'==(e=e.childNodes[t+(i<0?-1:0)]).contentEditable)return!1;t=i<0?Lt(e):0}}}function Lt(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function $t(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const zt=e=>e.focusNode&&It(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset);function Bt(e,t){let n=document.createEvent('Event');return n.initEvent('keydown',!0,!0),n.keyCode=e,n.key=n.code=t,n}const Vt='undefined'!=typeof navigator?navigator:null,Ft='undefined'!=typeof document?document:null,Ht=Vt&&Vt.userAgent||'',jt=/Edge\/(\d+)/.exec(Ht),_t=/MSIE \d/.exec(Ht),Wt=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ht),Jt=!!(_t||Wt||jt),qt=_t?document.documentMode:Wt?+Wt[1]:jt?+jt[1]:0,Kt=!Jt&&/gecko\/(\d+)/i.test(Ht);Kt&&(/Firefox\/(\d+)/.exec(Ht)||[0,0])[1];const Ut=!Jt&&/Chrome\/(\d+)/.exec(Ht),Gt=!!Ut,Yt=Ut?+Ut[1]:0,Xt=!Jt&&!!Vt&&/Apple Computer/.test(Vt.vendor),Zt=Xt&&(/Mobile\/\w+/.test(Ht)||!!Vt&&Vt.maxTouchPoints>2),Qt=Zt||!!Vt&&/Mac/.test(Vt.platform),en=/Android \d/.test(Ht),tn=!!Ft&&'webkitFontSmoothing'in Ft.documentElement.style,nn=tn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function rn(e){return{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function on(e,t){return'number'==typeof e?e:e[t]}function sn(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function an(e,t,n){let r=e.someProp('scrollThreshold')||0,i=e.someProp('scrollMargin')||5,o=e.dom.ownerDocument;for(let s=n||e.dom;s;s=Et(s)){if(1!=s.nodeType)continue;let e=s,n=e==o.body,a=n?rn(o):sn(e),l=0,c=0;if(t.top<a.top+on(r,'top')?c=-(a.top-t.top+on(i,'top')):t.bottom>a.bottom-on(r,'bottom')&&(c=t.bottom-a.bottom+on(i,'bottom')),t.left<a.left+on(r,'left')?l=-(a.left-t.left+on(i,'left')):t.right>a.right-on(r,'right')&&(l=t.right-a.right+on(i,'right')),l||c)if(n)o.defaultView.scrollBy(l,c);else{let n=e.scrollLeft,r=e.scrollTop;c&&(e.scrollTop+=c),l&&(e.scrollLeft+=l);let i=e.scrollLeft-n,o=e.scrollTop-r;t={left:t.left-i,top:t.top-o,right:t.right-i,bottom:t.bottom-o}}if(n)break}}function ln(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Et(r));return t}function cn(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:o}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=o&&(r.scrollLeft=o)}}let dn=null;function hn(e,t){let n,r,i=2e8,o=0,s=t.top,a=t.top;for(let l=e.firstChild,c=0;l;l=l.nextSibling,c++){let e;if(1==l.nodeType)e=l.getClientRects();else{if(3!=l.nodeType)continue;e=Dt(l).getClientRects()}for(let d=0;d<e.length;d++){let h=e[d];if(h.top<=s&&h.bottom>=a){s=Math.max(h.bottom,s),a=Math.min(h.top,a);let e=h.left>t.left?h.left-t.left:h.right<t.left?t.left-h.right:0;if(e<i){n=l,i=e,r=e&&3==n.nodeType?{left:h.right<t.left?h.right:h.left,top:t.top}:t,1==l.nodeType&&e&&(o=c+(t.left>=(h.left+h.right)/2?1:0));continue}}!n&&(t.left>=h.right&&t.top>=h.top||t.left>=h.left&&t.top>=h.bottom)&&(o=c+1)}}return n&&3==n.nodeType?function(e,t){let n=e.nodeValue.length,r=document.createRange();for(let i=0;i<n;i++){r.setEnd(e,i+1),r.setStart(e,i);let n=mn(r,1);if(n.top!=n.bottom&&pn(t,n))return{node:e,offset:i+(t.left>=(n.left+n.right)/2?1:0)}}return{node:e,offset:0}}(n,r):!n||i&&1==n.nodeType?{node:e,offset:o}:hn(n,r)}function pn(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function un(e,t,n){let r=e.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(t.top-n.top)/(n.bottom-n.top))-2)),o=i;;){let n=e.childNodes[o];if(1==n.nodeType){let e=n.getClientRects();for(let r=0;r<e.length;r++){let i=e[r];if(pn(t,i))return un(n,t,i)}}if((o=(o+1)%r)==i)break}return e}function fn(e,t){let n,r=e.dom.ownerDocument,i=0;if(r.caretPositionFromPoint)try{let e=r.caretPositionFromPoint(t.left,t.top);e&&({offsetNode:n,offset:i}=e)}catch(e){}if(!n&&r.caretRangeFromPoint){let e=r.caretRangeFromPoint(t.left,t.top);e&&({startContainer:n,startOffset:i}=e)}let o,s=(e.root.elementFromPoint?e.root:r).elementFromPoint(t.left,t.top);if(!s||!e.dom.contains(1!=s.nodeType?s.parentNode:s)){let n=e.dom.getBoundingClientRect();if(!pn(t,n))return null;if(s=un(e.dom,t,n),!s)return null}if(Xt)for(let e=s;n&&e;e=Et(e))e.draggable&&(n=void 0);if(s=function(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}(s,t),n){if(Kt&&1==n.nodeType&&(i=Math.min(i,n.childNodes.length),i<n.childNodes.length)){let e,r=n.childNodes[i];'IMG'==r.nodeName&&(e=r.getBoundingClientRect()).right<=t.left&&e.bottom>t.top&&i++}n==e.dom&&i==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?o=e.state.doc.content.size:0!=i&&1==n.nodeType&&'BR'==n.childNodes[i-1].nodeName||(o=function(e,t,n,r){let i=-1;for(let n=t,o=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0);if(!t)return null;if(1==t.dom.nodeType&&(t.node.isBlock&&t.parent&&!o||!t.contentDOM)){let e=t.dom.getBoundingClientRect();if(t.node.isBlock&&t.parent&&!o&&(o=!0,e.left>r.left||e.top>r.top?i=t.posBefore:(e.right<r.left||e.bottom<r.top)&&(i=t.posAfter)),!t.contentDOM&&i<0)return(t.node.isBlock?r.top<(e.top+e.bottom)/2:r.left<(e.left+e.right)/2)?t.posBefore:t.posAfter}n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}(e,n,i,t))}null==o&&(o=function(e,t,n){let{node:r,offset:i}=hn(t,n),o=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();o=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,o)}(e,s,t));let a=e.docView.nearestDesc(s,!0);return{pos:o,inside:a?a.posAtStart-a.border:-1}}function mn(e,t){let n=e.getClientRects();return n.length?n[t<0?0:n.length-1]:e.getBoundingClientRect()}const gn=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function yn(e,t,n){let{node:r,offset:i,atom:o}=e.docView.domFromPos(t,n<0?-1:1),s=tn||Kt;if(3==r.nodeType){if(!s||!gn.test(r.nodeValue)&&(n<0?i:i!=r.nodeValue.length)){let e=i,t=i,o=n<0?1:-1;return n<0&&!i?(t++,o=-1):n>=0&&i==r.nodeValue.length?(e--,o=1):n<0?e--:t++,wn(mn(Dt(r,e,t),1),o<0)}{let e=mn(Dt(r,i,i),n);if(Kt&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=mn(Dt(r,i-1,i-1),-1);if(t.top==e.top){let n=mn(Dt(r,i,i+1),-1);if(n.top!=e.top)return wn(n,n.left<t.left)}}return e}}if(!e.state.doc.resolve(t-(o||0)).parent.inlineContent){if(null==o&&i&&(n<0||i==Lt(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return vn(e.getBoundingClientRect(),!1)}if(null==o&&i<Lt(r)){let e=r.childNodes[i];if(1==e.nodeType)return vn(e.getBoundingClientRect(),!0)}return vn(r.getBoundingClientRect(),n>=0)}if(null==o&&i&&(n<0||i==Lt(r))){let e=r.childNodes[i-1],t=3==e.nodeType?Dt(e,Lt(e)-(s?0:1)):1!=e.nodeType||'BR'==e.nodeName&&e.nextSibling?null:e;if(t)return wn(mn(t,1),!1)}if(null==o&&i<Lt(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?Dt(e,0,s?0:1):1==e.nodeType?e:null:null;if(t)return wn(mn(t,-1),!0)}return wn(mn(3==r.nodeType?Dt(r):r,-n),n>=0)}function wn(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function vn(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function bn(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}const kn=/[\u0590-\u08ac]/;let xn=null,Sn=null,Mn=!1;function Cn(e,t,n){return xn==t&&Sn==n?Mn:(xn=t,Sn=n,Mn='up'==n||'down'==n?function(e,t,n){let r=t.selection,i='up'==n?r.$from:r.$to;return bn(e,t,(()=>{let{node:t}=e.docView.domFromPos(i.pos,'up'==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=yn(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=Dt(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&('up'==n?r.top-i.top>2*(i.bottom-r.top):i.bottom-r.bottom>2*(r.bottom-i.top)))return!1}}return!0}))}(e,t,n):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,a=e.domSelection();return kn.test(r.parent.textContent)&&a.modify?bn(e,t,(()=>{let{focusNode:t,focusOffset:i,anchorNode:o,anchorOffset:s}=e.domSelectionRange(),l=a.caretBidiLevel;a.modify('move',n,'character');let c=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:d,focusOffset:h}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&i==h;try{a.collapse(o,s),t&&(t!=o||i!=s)&&a.extend&&a.extend(t,i)}catch(e){}return null!=l&&(a.caretBidiLevel=l),p})):'left'==n||'backward'==n?o:s}(e,t,n))}class Tn{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){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,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.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,n){if(this.contentDOM&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode)){if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&(!(r=n.pmViewDesc)||r.parent!=this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&(!(r=n.pmViewDesc)||r.parent!=this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}}let r;if(e==this.dom&&this.contentDOM)r=t>Nt(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i,o=this.getDesc(r);if(o&&(!t||o.node)){if(!n||!(i=o.nodeDOM)||(1==i.nodeType?i.contains(1==e.nodeType?e:e.parentNode):i==e))return o;n=!1}}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)r=r.children[0];return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n,r=0,i=0;for(let t=0;r<this.children.length;r++){let n=this.children[r],o=t+n.size;if(o>e||n instanceof Rn){i=e-t;break}t=o}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(;r&&!(n=this.children[r-1]).size&&n instanceof On&&n.side>=0;r--);if(t<=0){let e,n=!0;for(;e=r?this.children[r-1]:null,e&&e.dom.parentNode!=this.contentDOM;r--,n=!1);return e&&t&&n&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Nt(e.dom)+1:0}}{let e,n=!0;for(;e=r<this.children.length?this.children[r]:null,e&&e.dom.parentNode!=this.contentDOM;r++,n=!1);return e&&n&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Nt(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let o=n,s=0;;s++){let n=this.children[s],a=o+n.size;if(-1==r&&e<=a){let i=o+n.border;if(e>=i&&t<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=o;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=Nt(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(a>t||s==this.children.length-1)){t=a;for(let e=s+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=Nt(n.dom);break}t+=n.size}-1==i&&(i=this.contentDOM.childNodes.length);break}o=a}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw new RangeError('No node after pos '+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),o=Math.max(e,t);for(let s=0,a=0;s<this.children.length;s++){let l=this.children[s],c=a+l.size;if(i>a&&o<c)return l.setSelection(e-a-l.border,t-a-l.border,n,r);a=c}let s=this.domFromPos(e,e?-1:1),a=t==e?s:this.domFromPos(t,t?-1:1),l=n.getSelection(),c=!1;if((Kt||Xt)&&e==t){let{node:e,offset:t}=s;if(3==e.nodeType){if(c=!(!t||'\n'!=e.nodeValue[t-1]),c&&t==e.nodeValue.length)for(let t,n=e;n;n=n.parentNode){if(t=n.nextSibling){'BR'==t.nodeName&&(s=a={node:t.parentNode,offset:Nt(t)+1});break}let e=n.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];c=n&&('BR'==n.nodeName||'false'==n.contentEditable)}}if(Kt&&l.focusNode&&l.focusNode!=a.node&&1==l.focusNode.nodeType){let e=l.focusNode.childNodes[l.focusOffset];e&&'false'==e.contentEditable&&(r=!0)}if(!(r||c&&Xt)&&It(s.node,s.offset,l.anchorNode,l.anchorOffset)&&It(a.node,a.offset,l.focusNode,l.focusOffset))return;let d=!1;if((l.extend||e==t)&&!c){l.collapse(s.node,s.offset);try{e!=t&&l.extend(a.node,a.offset),d=!0}catch(e){}}if(!d){if(e>t){let e=s;s=a,a=e}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(s.node,s.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&'selection'!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],o=n+i.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let r=n+i.border,s=o-i.border;if(e>=r&&t<=s)return this.dirty=e==n||t==o?2:1,void(e!=r||t!=s||!i.contentLost&&i.dom.parentNode==this.contentDOM?i.markDirty(e-r,t-r):i.dirty=3);i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=o}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}}class On extends Tn{constructor(e,t,n,r){let i,o=t.type.toDOM;if('function'==typeof o&&(o=o(n,(()=>i?i.parent?i.parent.posBeforeChild(i):void 0:r))),!t.type.spec.raw){if(1!=o.nodeType){let e=document.createElement('span');e.appendChild(o),o=e}o.contentEditable='false',o.classList.add('ProseMirror-widget')}super(e,[],o,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return'selection'!=e.type||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 Nn extends Tn{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}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'characterData'===e.type&&e.target.nodeValue==e.oldValue}}class En extends Tn{constructor(e,t,n,r){super(e,[],n,r),this.mark=t}static create(e,t,n,r){let i=r.nodeViews[t.type.name],o=i&&i(t,r,n);return o&&o.dom||(o=ye.renderSpec(document,t.type.spec.toDOM(t,n))),new En(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM||void 0}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let r=En.create(this.parent,this.mark,!0,n),i=this.children,o=this.size;t<o&&(i=qn(i,t,o,n)),e>0&&(i=qn(i,0,e,n));for(let e=0;e<i.length;e++)i[e].parent=r;return r.children=i,r}}class An extends Tn{constructor(e,t,n,r,i,o,s,a,l){super(e,[],i,o),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=s,o&&this.updateChildren(a,l)}static create(e,t,n,r,i,o){let s,a=i.nodeViews[t.type.name],l=a&&a(t,i,(()=>s?s.parent?s.parent.posBeforeChild(s):void 0:o),n,r),c=l&&l.dom,d=l&&l.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw new RangeError('Text must be rendered as a DOM text node')}else c=document.createTextNode(t.text);else c||({dom:c,contentDOM:d}=ye.renderSpec(document,t.type.spec.toDOM(t)));d||t.isText||'BR'==c.nodeName||(c.hasAttribute('contenteditable')||(c.contentEditable='false'),t.type.spec.draggable&&(c.draggable=!0));let h=c;return c=Hn(c,n,t),l?s=new Pn(e,t,n,r,c,d||null,h,l,i,o+1):t.isText?new In(e,t,n,r,c,h,i):new An(e,t,n,r,c,d||null,h,i,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if('pre'==this.node.type.whitespace&&(e.preserveWhitespace='full'),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&jn(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,o=i&&i.pos>-1?i:null,s=i&&i.pos<0,a=new Wn(this,o&&o.node,e);!function(e,t,n,r){let i=t.locals(e),o=0;if(0==i.length){for(let n=0;n<e.childCount;n++){let s=e.child(n);r(s,i,t.forChild(o,s),n),o+=s.nodeSize}return}let s=0,a=[],l=null;for(let c=0;;){if(s<i.length&&i[s].to==o){let e,t=i[s++];for(;s<i.length&&i[s].to==o;)(e||(e=[t])).push(i[s++]);if(e){e.sort(Jn);for(let t=0;t<e.length;t++)n(e[t],c,!!l)}else n(t,c,!!l)}let d,h;if(l)h=-1,d=l,l=null;else{if(!(c<e.childCount))break;h=c,d=e.child(c++)}for(let e=0;e<a.length;e++)a[e].to<=o&&a.splice(e--,1);for(;s<i.length&&i[s].from<=o&&i[s].to>o;)a.push(i[s++]);let p=o+d.nodeSize;if(d.isText){let e=p;s<i.length&&i[s].from<e&&(e=i[s].from);for(let t=0;t<a.length;t++)a[t].to<e&&(e=a[t].to);e<p&&(l=d.cut(e-o),d=d.cut(0,e-o),p=e,h=-1)}r(d,d.isInline&&!d.isLeaf?a.filter((e=>!e.inline)):a.slice(),t.forChild(o,d),h),o=p}}(this.node,this.innerDeco,((t,i,o)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!o&&a.syncToMarks(i==this.node.childCount?k.none:this.node.child(i).marks,n,e),a.placeWidget(t,e,r)}),((t,o,l,c)=>{let d;a.syncToMarks(t.marks,n,e),a.findNodeMatch(t,o,l,c)||s&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(d=a.findIndexWithChild(i.node))>-1&&a.updateNodeAt(t,o,l,d,e)||a.updateNextNode(t,o,l,e,c)||a.addNode(t,o,l,e,r),r+=t.nodeSize})),a.syncToMarks([],n,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(o&&this.protectLocalComposition(e,o),Ln(this.contentDOM,this.children,e),Zt&&function(e){if('UL'==e.nodeName||'OL'==e.nodeName){let t=e.style.cssText;e.style.cssText=t+'; list-style: square !important',window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof ct)||n<t||r>t+this.node.content.size)return null;let i=e.domSelectionRange(),o=function(e,t){for(;;){if(3==e.nodeType)return e;if(1==e.nodeType&&t>0){if(e.childNodes.length>t&&3==e.childNodes[t].nodeType)return e.childNodes[t];t=Lt(e=e.childNodes[t-1])}else{if(!(1==e.nodeType&&t<e.childNodes.length))return null;e=e.childNodes[t],t=0}}}(i.focusNode,i.focusOffset);if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let e=o.nodeValue,i=function(e,t,n,r){for(let i=0,o=0;i<e.childCount&&o<=r;){let s=e.child(i++),a=o;if(o+=s.nodeSize,!s.isText)continue;let l=s.text;for(;i<e.childCount;){let t=e.child(i++);if(o+=t.nodeSize,!t.isText)break;l+=t.text}if(o>=n){let e=a<r?l.lastIndexOf(t,r-a-1):-1;if(e>=0&&e+t.length+a>=n)return a+e;if(n==r&&l.length>=r+t.length-a&&l.slice(r-a,r-a+t.length)==t)return r}}return-1}(this.node.content,e,n-t,r-t);return i<0?null:{node:o,pos:i,text:e}}return{node:o,pos:-1,text:''}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let o=new Nn(this,i,t,r);e.input.compositionNodes.push(o),this.children=qn(this.children,n,n+r.length,e,o)}update(e,t,n,r){return!(3==this.dirty||!e.sameMarkup(this.node))&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(jn(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=Vn(this.dom,this.nodeDOM,Bn(this.outerDeco,this.node,t),Bn(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.add('ProseMirror-selectednode'),!this.contentDOM&&this.node.type.spec.draggable||(this.dom.draggable=!0)}deselectNode(){1==this.nodeDOM.nodeType&&this.nodeDOM.classList.remove('ProseMirror-selectednode'),!this.contentDOM&&this.node.type.spec.draggable||this.dom.removeAttribute('draggable')}get domAtom(){return this.node.isAtom}}function Dn(e,t,n,r,i){return Hn(r,t,e),new An(void 0,e,t,n,r,r,r,i,0)}class In extends An{constructor(e,t,n,r,i,o,s){super(e,t,n,r,i,null,o,s,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return!(3==this.dirty||0!=this.dirty&&!this.inParent()||!e.sameMarkup(this.node))&&(this.updateOuterDeco(t),0==this.dirty&&e.text==this.node.text||e.text==this.nodeDOM.nodeValue||(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!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,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return'characterData'!=e.type&&'selection'!=e.type}slice(e,t,n){let r=this.node.cut(e,t),i=document.createTextNode(r.text);return new In(this.parent,r,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom==this.nodeDOM||0!=e&&t!=this.nodeDOM.nodeValue.length||(this.dirty=3)}get domAtom(){return!1}}class Rn extends Tn{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return'IMG'==this.dom.nodeName}}class Pn extends An{constructor(e,t,n,r,i,o,s,a,l,c){super(e,t,n,r,i,o,s,l,c),this.spec=a}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Ln(e,t,n){let r=e.firstChild,i=!1;for(let o=0;o<t.length;o++){let s=t[o],a=s.dom;if(a.parentNode==e){for(;a!=r;)r=_n(r),i=!0;r=r.nextSibling}else i=!0,e.insertBefore(a,r);if(s instanceof En){let t=r?r.previousSibling:e.lastChild;Ln(s.contentDOM,s.children,n),r=t?t.nextSibling:e.firstChild}}for(;r;)r=_n(r),i=!0;i&&n.trackWrites==e&&(n.trackWrites=null)}const $n=function(e){e&&(this.nodeName=e)};$n.prototype=Object.create(null);const zn=[new $n];function Bn(e,t,n){if(0==e.length)return zn;let r=n?zn[0]:new $n,i=[r];for(let o=0;o<e.length;o++){let s=e[o].type.attrs;if(s){s.nodeName&&i.push(r=new $n(s.nodeName));for(let e in s){let o=s[e];null!=o&&(n&&1==i.length&&i.push(r=new $n(t.isInline?'span':'div')),'class'==e?r.class=(r.class?r.class+' ':'')+o:'style'==e?r.style=(r.style?r.style+';':'')+o:'nodeName'!=e&&(r[e]=o))}}}return i}function Vn(e,t,n,r){if(n==zn&&r==zn)return t;let i=t;for(let t=0;t<r.length;t++){let o=r[t],s=n[t];if(t){let t;s&&s.nodeName==o.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==o.nodeName||(t=document.createElement(o.nodeName),t.pmIsDeco=!0,t.appendChild(i),s=zn[0]),i=t}Fn(i,s||zn[0],o)}return i}function Fn(e,t,n){for(let r in t)'class'==r||'style'==r||'nodeName'==r||r in n||e.removeAttribute(r);for(let r in n)'class'!=r&&'style'!=r&&'nodeName'!=r&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(' ').filter(Boolean):[],i=n.class?n.class.split(' ').filter(Boolean):[];for(let t=0;t<r.length;t++)-1==i.indexOf(r[t])&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)-1==r.indexOf(i[t])&&e.classList.add(i[t]);0==e.classList.length&&e.removeAttribute('class')}if(t.style!=n.style){if(t.style){let n,r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;n=r.exec(t.style);)e.style.removeProperty(n[1])}n.style&&(e.style.cssText+=n.style)}}function Hn(e,t,n){return Vn(e,e,zn,Bn(t,n,1!=e.nodeType))}function jn(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function _n(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class Wn{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,r=n.children.length,i=e.childCount,o=new Map,s=[];e:for(;i>0;){let a;for(;;)if(r){let e=n.children[r-1];if(!(e instanceof En)){a=e,r--;break}n=e,r=e.children.length}else{if(n==t)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=e.child(i-1))break;--i,o.set(a,i),s.push(a)}}return{index:i,matched:o,matches:s.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n){let r=0,i=this.stack.length>>1,o=Math.min(i,e.length);for(;r<o&&(r==i-1?this.top:this.stack[r+1<<1]).matchesMark(e[r])&&!1!==e[r].type.spec.spanning;)r++;for(;r<i;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let r=-1;for(let t=this.index;t<Math.min(this.index+3,this.top.children.length);t++){let n=this.top.children[t];if(n.matchesMark(e[i])&&!this.isLocked(n.dom)){r=t;break}}if(r>-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let r=En.create(this.top,e[i],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,i++}}findNodeMatch(e,t,n,r){let i,o=-1;if(r>=this.preMatch.index&&(i=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,n))o=this.top.children.indexOf(i,this.index);else for(let r=this.index,i=Math.min(this.top.children.length,r+5);r<i;r++){let i=this.top.children[r];if(i.matchesNode(e,t,n)&&!this.preMatch.matched.has(i)){o=r;break}}return!(o<0)&&(this.destroyBetween(this.index,o),this.index++,!0)}updateNodeAt(e,t,n,r,i){let o=this.top.children[r];return 3==o.dirty&&o.dom==o.contentDOM&&(o.dirty=2),!!o.update(e,t,n,i)&&(this.destroyBetween(this.index,r),this.index++,!0)}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t)for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e;return-1}e=t}}updateNextNode(e,t,n,r,i){for(let o=this.index;o<this.top.children.length;o++){let s=this.top.children[o];if(s instanceof An){let a=this.preMatch.matched.get(s);if(null!=a&&a!=i)return!1;let l=s.dom;if(!(this.isLocked(l)&&!(e.isText&&s.node&&s.node.isText&&s.nodeDOM.nodeValue==e.text&&3!=s.dirty&&jn(t,s.outerDeco)))&&s.update(e,t,n,r))return this.destroyBetween(this.index,o),s.dom!=l&&(this.changed=!0),this.index++,!0;break}}return!1}addNode(e,t,n,r,i){this.top.children.splice(this.index++,0,An.create(this.top,e,t,n,r,i)),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(!r||!r.matchesWidget(e)||e!=r.widget&&r.widget.type.toDOM.parentNode){let r=new On(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}else this.index++}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof En;)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))&&((Xt||Gt)&&e&&'false'==e.dom.contentEditable&&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 n=document.createElement(e);'IMG'==e&&(n.className='ProseMirror-separator',n.alt=''),'BR'==e&&(n.className='ProseMirror-trailingBreak');let r=new Rn(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function Jn(e,t){return e.type.side-t.type.side}function qn(e,t,n,r,i){let o=[];for(let s=0,a=0;s<e.length;s++){let l=e[s],c=a,d=a+=l.size;c>=n||d<=t?o.push(l):(c<t&&o.push(l.slice(0,t-c,r)),i&&(o.push(i),i=void 0),d>n&&o.push(l.slice(n-c,l.size,r)))}return o}function Kn(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),o=i&&0==i.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let a,l,c=r.resolve(s);if(zt(n)){for(a=c;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&ht.isSelectable(e)&&i.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,i=t==Lt(e);r||i;){if(e==n)return!0;let t=Nt(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==Lt(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new ht(s==e?c:r.resolve(e))}}else{let t=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(t<0)return null;a=r.resolve(t)}if(!l){l=nr(e,a,c,'pointer'==t||e.state.selection.head<c.pos&&!o?1:-1)}return l}function Un(e){return e.editable?e.hasFocus():ir(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function Gn(e,t=!1){let n=e.state.selection;if(er(e,n),Un(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&Gt){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&It(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset))return e.input.mouseDown.delayedSelectionSync=!0,void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection(),n=document.createRange(),r=e.cursorWrapper.dom,i='IMG'==r.nodeName;i?n.setEnd(r.parentNode,Nt(r)+1):n.setEnd(r,0);n.collapse(!1),t.removeAllRanges(),t.addRange(n),!i&&!e.state.selection.visible&&Jt&&qt<=11&&(r.disabled=!0,r.disabled=!1)}(e);else{let r,i,{anchor:o,head:s}=n;!Yn||n instanceof ct||(n.$from.parent.inlineContent||(r=Xn(e,n.from)),n.empty||n.$from.parent.inlineContent||(i=Xn(e,n.to))),e.docView.setSelection(o,s,e.root,t),Yn&&(r&&Qn(r),i&&Qn(i)),n.visible?e.dom.classList.remove('ProseMirror-hideselection'):(e.dom.classList.add('ProseMirror-hideselection'),'onselectionchange'in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener('selectionchange',e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,i=n.anchorOffset;t.addEventListener('selectionchange',e.input.hideSelectionGuard=()=>{n.anchorNode==r&&n.anchorOffset==i||(t.removeEventListener('selectionchange',e.input.hideSelectionGuard),setTimeout((()=>{Un(e)&&!e.state.selection.visible||e.dom.classList.remove('ProseMirror-hideselection')}),20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const Yn=Xt||Gt&&Yt<63;function Xn(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,o=r?n.childNodes[r-1]:null;if(Xt&&i&&'false'==i.contentEditable)return Zn(i);if(!(i&&'false'!=i.contentEditable||o&&'false'!=o.contentEditable)){if(i)return Zn(i);if(o)return Zn(o)}}function Zn(e){return e.contentEditable='true',Xt&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function Qn(e){e.contentEditable='false',e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function er(e,t){if(t instanceof ht){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(tr(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else tr(e)}function tr(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function nr(e,t,n,r){return e.someProp('createSelectionBetween',(r=>r(e,t,n)))||ct.between(t,n,r)}function rr(e){return!(e.editable&&!e.hasFocus())&&ir(e)}function ir(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(e){return!1}}function or(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),o=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return o&&ot.findFrom(o,t)}function sr(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function ar(e,t,n){let r=e.state.selection;if(!(r instanceof ct)){if(r instanceof ht&&r.node.isInline)return sr(e,new ct(t>0?r.$to:r.$from));{let n=or(e.state,t);return!!n&&sr(e,n)}}if(!r.empty||n.indexOf('s')>-1)return!1;if(e.endOfTextblock(t>0?'right':'left')){let n=or(e.state,t);return!!(n&&n instanceof ht)&&sr(e,n)}if(!(Qt&&n.indexOf('m')>-1)){let n,i=r.$head,o=i.textOffset?null:t<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText)return!1;let s=t<0?i.pos-o.nodeSize:i.pos;return!!(o.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(ht.isSelectable(o)?sr(e,new ht(t<0?e.state.doc.resolve(i.pos-o.nodeSize):i)):!!tn&&sr(e,new ct(e.state.doc.resolve(t<0?s:s+o.nodeSize))))}}function lr(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function cr(e){let t=e.pmViewDesc;return t&&0==t.size&&(e.nextSibling||'BR'!=e.nodeName)}function dr(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,o,s=!1;for(Kt&&1==n.nodeType&&r<lr(n)&&cr(n.childNodes[r])&&(s=!0);;)if(r>0){if(1!=n.nodeType)break;{let e=n.childNodes[r-1];if(cr(e))i=n,o=--r;else{if(3!=e.nodeType)break;n=e,r=n.nodeValue.length}}}else{if(pr(n))break;{let t=n.previousSibling;for(;t&&cr(t);)i=n.parentNode,o=Nt(t),t=t.previousSibling;if(t)n=t,r=lr(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}s?ur(e,n,r):i&&ur(e,i,o)}function hr(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,o,s=lr(n);for(;;)if(r<s){if(1!=n.nodeType)break;if(!cr(n.childNodes[r]))break;i=n,o=++r}else{if(pr(n))break;{let t=n.nextSibling;for(;t&&cr(t);)i=t.parentNode,o=Nt(t)+1,t=t.nextSibling;if(t)n=t,r=0,s=lr(n);else{if(n=n.parentNode,n==e.dom)break;r=s=0}}}i&&ur(e,i,o)}function pr(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function ur(e,t,n){let r=e.domSelection();if(zt(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout((()=>{e.state==i&&Gn(e)}),50)}function fr(e,t,n){let r=e.state.selection;if(r instanceof ct&&!r.empty||n.indexOf('s')>-1)return!1;if(Qt&&n.indexOf('m')>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?'up':'down')){let n=or(e.state,t);if(n&&n instanceof ht)return sr(e,n)}if(!i.parent.inlineContent){let n=t<0?i:o,s=r instanceof ut?ot.near(n,t):ot.findFrom(n,t);return!!s&&sr(e,s)}return!1}function mr(e,t){if(!(e.state.selection instanceof ct))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?'forward':'backward'))return!0;let o=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let r=e.state.tr;return t<0?r.delete(n.pos-o.nodeSize,n.pos):r.delete(n.pos,n.pos+o.nodeSize),e.dispatch(r),!0}return!1}function gr(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function yr(e,t){let n=t.keyCode,r=function(e){let t='';return e.ctrlKey&&(t+='c'),e.metaKey&&(t+='m'),e.altKey&&(t+='a'),e.shiftKey&&(t+='s'),t}(t);return 8==n||Qt&&72==n&&'c'==r?mr(e,-1)||dr(e):46==n||Qt&&68==n&&'c'==r?mr(e,1)||hr(e):13==n||27==n||(37==n||Qt&&66==n&&'c'==r?ar(e,-1,r)||dr(e):39==n||Qt&&70==n&&'c'==r?ar(e,1,r)||hr(e):38==n||Qt&&80==n&&'c'==r?fr(e,-1,r)||dr(e):40==n||Qt&&78==n&&'c'==r?function(e){if(!Xt||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&'false'==t.firstChild.contentEditable){let n=t.firstChild;gr(e,n,'true'),setTimeout((()=>gr(e,n,'false')),20)}return!1}(e)||fr(e,1,r)||hr(e):r==(Qt?'m':'c')&&(66==n||73==n||89==n||90==n))}function wr(e,t){e.someProp('transformCopied',(n=>{t=n(t,e)}));let n=[],{content:r,openStart:i,openEnd:o}=t;for(;i>1&&o>1&&1==r.childCount&&1==r.firstChild.childCount;){i--,o--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let s=e.someProp('clipboardSerializer')||ye.fromSchema(e.state.schema),a=Nr(),l=a.createElement('div');l.appendChild(s.serializeFragment(r,{document:a}));let c,d=l.firstChild,h=0;for(;d&&1==d.nodeType&&(c=Tr[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=a.createElement(c[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),h++}d=l.firstChild}return d&&1==d.nodeType&&d.setAttribute('data-pm-slice',`${i} ${o}${h?` -${h}`:''} ${JSON.stringify(n)}`),{dom:l,text:e.someProp('clipboardTextSerializer',(n=>n(t,e)))||t.content.textBetween(0,t.content.size,'\n\n')}}function vr(e,t,n,r,i){let o,s,a=i.parent.type.spec.code;if(!n&&!t)return null;let l=t&&(r||a||!n);if(l){if(e.someProp('transformPastedText',(n=>{t=n(t,a||r,e)})),a)return t?new S(y.from(e.state.schema.text(t.replace(/\r\n?/g,'\n'))),0,0):S.empty;let n=e.someProp('clipboardTextParser',(n=>n(t,i,r,e)));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,s=ye.fromSchema(r);o=document.createElement('div'),t.split(/(?:\r\n?|\n)+/).forEach((e=>{let t=o.appendChild(document.createElement('p'));e&&t.appendChild(s.serializeNode(r.text(e,n)))}))}}else e.someProp('transformPastedHTML',(t=>{n=t(n,e)})),o=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,r=Nr().createElement('div'),i=/<([a-z][^>\s]+)/i.exec(e);(n=i&&Tr[i[1].toLowerCase()])&&(e=n.map((e=>'<'+e+'>')).join('')+e+n.map((e=>'</'+e+'>')).reverse().join(''));if(r.innerHTML=e,n)for(let e=0;e<n.length;e++)r=r.querySelector(n[e])||r;return r}(n),tn&&function(e){let t=e.querySelectorAll(Gt?'span:not([class]):not([style])':'span.Apple-converted-space');for(let n=0;n<t.length;n++){let r=t[n];1==r.childNodes.length&&' '==r.textContent&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(' '),r)}}(o);let c=o&&o.querySelector('[data-pm-slice]'),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute('data-pm-slice')||'');if(d&&d[3])for(let e=+d[3];e>0;e--){let e=o.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;o=e}if(!s){let t=e.someProp('clipboardParser')||e.someProp('domParser')||ae.fromSchema(e.state.schema);s=t.parseSlice(o,{preserveWhitespace:!(!l&&!d),context:i,ruleFromNode:e=>'BR'!=e.nodeName||e.nextSibling||!e.parentNode||br.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(d)s=function(e,t){if(!e.size)return e;let n,r=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(t){return e}let{content:i,openStart:o,openEnd:s}=e;for(let e=n.length-2;e>=0;e-=2){let t=r.nodes[n[e]];if(!t||t.hasRequiredAttrs())break;i=y.from(t.create(n[e+1],i)),o++,s++}return new S(i,o,s)}(Cr(s,+d[1],+d[2]),d[4]);else if(s=S.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r,i=t.node(n).contentMatchAt(t.index(n)),o=[];if(e.forEach((e=>{if(!o)return;let t,n=i.findWrapping(e.type);if(!n)return o=null;if(t=o.length&&r.length&&xr(n,r,e,o[o.length-1],0))o[o.length-1]=t;else{o.length&&(o[o.length-1]=Sr(o[o.length-1],r.length));let t=kr(e,n);o.push(t),i=i.matchType(t.type),r=n}})),o)return y.from(o)}return e}(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e<s.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=s.content.lastChild;t<s.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);s=Cr(s,e,t)}return e.someProp('transformPasted',(t=>{s=t(s,e)})),s}const br=/^(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 kr(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,y.from(e));return e}function xr(e,t,n,r,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let o=xr(e,t,n,r.lastChild,i+1);if(o)return r.copy(r.content.replaceChild(r.childCount-1,o));if(r.contentMatchAt(r.childCount).matchType(i==e.length-1?n.type:e[i+1]))return r.copy(r.content.append(y.from(kr(n,e,i+1))))}}function Sr(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,Sr(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(y.empty,!0);return e.copy(n.append(r))}function Mr(e,t,n,r,i,o){let s=t<0?e.firstChild:e.lastChild,a=s.content;return i<r-1&&(a=Mr(a,t,n,r,i+1,o)),i>=n&&(a=t<0?s.contentMatchAt(0).fillBefore(a,e.childCount>1||o<=i).append(a):a.append(s.contentMatchAt(s.childCount).fillBefore(y.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,s.copy(a))}function Cr(e,t,n){return t<e.openStart&&(e=new S(Mr(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new S(Mr(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}const Tr={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 Or=null;function Nr(){return Or||(Or=document.implementation.createHTMLDocument('title'))}const Er={},Ar={},Dr={touchstart:!0,touchmove:!0};class Ir{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.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Rr(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function Pr(e){e.someProp('handleDOMEvents',(t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Lr(e,t))}))}function Lr(e,t){return e.someProp('handleDOMEvents',(n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)}))}function $r(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function zr(e){return{left:e.clientX,top:e.clientY}}function Br(e,t,n,r,i){if(-1==r)return!1;let o=e.state.doc.resolve(r);for(let r=o.depth+1;r>0;r--)if(e.someProp(t,(t=>r>o.depth?t(e,n,o.nodeAfter,o.before(r),i,!0):t(e,n,o.node(r),o.before(r),i,!1))))return!0;return!1}function Vr(e,t,n){e.focused||e.focus();let r=e.state.tr.setSelection(t);'pointer'==n&&r.setMeta('pointer',!0),e.dispatch(r)}function Fr(e,t,n,r,i){return Br(e,'handleClickOn',t,n,r)||e.someProp('handleClick',(n=>n(e,t,r)))||(i?function(e,t){if(-1==t)return!1;let n,r,i=e.state.selection;i instanceof ht&&(n=i.node);let o=e.state.doc.resolve(t);for(let e=o.depth+1;e>0;e--){let t=e>o.depth?o.nodeAfter:o.node(e);if(ht.isSelectable(t)){r=n&&i.$from.depth>0&&e>=i.$from.depth&&o.before(i.$from.depth+1)==i.$from.pos?o.before(i.$from.depth):o.before(e);break}}return null!=r&&(Vr(e,ht.create(e.state.doc,r),'pointer'),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&ht.isSelectable(r))&&(Vr(e,new ht(n),'pointer'),!0)}(e,n))}function Hr(e,t,n,r){return Br(e,'handleDoubleClickOn',t,n,r)||e.someProp('handleDoubleClick',(n=>n(e,t,r)))}function jr(e,t,n,r){return Br(e,'handleTripleClickOn',t,n,r)||e.someProp('handleTripleClick',(n=>n(e,t,r)))||function(e,t,n){if(0!=n.button)return!1;let r=e.state.doc;if(-1==t)return!!r.inlineContent&&(Vr(e,ct.create(r,0,r.content.size),'pointer'),!0);let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),o=i.before(t);if(n.inlineContent)Vr(e,ct.create(r,o+1,o+1+n.content.size),'pointer');else{if(!ht.isSelectable(n))continue;Vr(e,ht.create(r,o),'pointer')}return!0}}(e,n,r)}function _r(e){return Yr(e)}Ar.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!qr(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!en||!Gt||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!Zt||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp('handleKeyDown',(t=>t(e,n)))||yr(e,n)?n.preventDefault():Rr(e,'key');else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout((()=>{e.input.lastIOSEnter==t&&(e.someProp('handleKeyDown',(t=>t(e,Bt(13,'Enter')))),e.input.lastIOSEnter=0)}),200)}},Ar.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},Ar.keypress=(e,t)=>{let n=t;if(qr(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||Qt&&n.metaKey)return;if(e.someProp('handleKeyPress',(t=>t(e,n))))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof ct&&r.$from.sameParent(r.$to))){let t=String.fromCharCode(n.charCode);/[\r\n]/.test(t)||e.someProp('handleTextInput',(n=>n(e,r.$from.pos,r.$to.pos,t)))||e.dispatch(e.state.tr.insertText(t).scrollIntoView()),n.preventDefault()}};const Wr=Qt?'metaKey':'ctrlKey';Er.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=_r(e),i=Date.now(),o='singleClick';i-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}(n,e.input.lastClick)&&!n[Wr]&&('singleClick'==e.input.lastClick.type?o='doubleClick':'doubleClick'==e.input.lastClick.type&&(o='tripleClick')),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:o};let s=e.posAtCoords(zr(n));s&&('singleClick'==o?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new Jr(e,s,n,!!r)):('doubleClick'==o?Hr:jr)(e,s.pos,s.inside,n)?n.preventDefault():Rr(e,'pointer'))};class Jr{constructor(e,t,n,r){let i,o;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Wr],this.allowDefault=n.shiftKey,t.inside>-1)i=e.state.doc.nodeAt(t.inside),o=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,o=n.depth?n.before():0}const s=r?null:n.target,a=s?e.docView.nearestDesc(s,!0):null;this.target=a?a.dom:null;let{selection:l}=e.state;(0==n.button&&i.type.spec.draggable&&!1!==i.type.spec.selectable||l instanceof ht&&l.from<=o&&l.to>o)&&(this.mightDrag={node:i,pos:o,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!Kt||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)),Rr(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((()=>Gn(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(zr(e))),this.updateAllowDefault(e),this.allowDefault||!t?Rr(this.view,'pointer'):Fr(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||Xt&&this.mightDrag&&!this.mightDrag.node.isAtom||Gt&&!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)?(Vr(this.view,ot.near(this.view.state.doc.resolve(t.pos)),'pointer'),e.preventDefault()):Rr(this.view,'pointer')}move(e){this.updateAllowDefault(e),Rr(this.view,'pointer'),0==e.buttons&&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)}}function qr(e,t){return!!e.composing||!!(Xt&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}Er.touchstart=e=>{e.input.lastTouch=Date.now(),_r(e),Rr(e,'pointer')},Er.touchmove=e=>{e.input.lastTouch=Date.now(),Rr(e,'pointer')},Er.contextmenu=e=>_r(e);const Kr=en?5e3:-1;function Ur(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout((()=>Yr(e)),t))}function Gr(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=function(){let e=document.createEvent('Event');return e.initEvent('event',!0,!0),e.timeStamp}());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function Yr(e,t=!1){if(!(en&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),Gr(e),t||e.docView&&e.docView.dirty){let t=Kn(e);return t&&!t.eq(e.state.selection)?e.dispatch(e.state.tr.setSelection(t)):e.updateState(e.state),!0}return!1}}Ar.compositionstart=Ar.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$from;if(t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some((e=>!1===e.type.spec.inclusive))))e.markCursor=e.state.storedMarks||n.marks(),Yr(e,!0),e.markCursor=null;else if(Yr(e),Kt&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&1==n.nodeType&&0!=r;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(3==t.nodeType){e.domSelection().collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Ur(e,Kr)},Ar.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,Ur(e,20))};const Xr=Jt&&qt<15||Zt&&nn<604;function Zr(e,t,n,r,i){let o=vr(e,t,n,r,e.state.selection.$from);if(e.someProp('handlePaste',(t=>t(e,i,o||S.empty))))return!0;if(!o)return!1;let s=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(o),a=s?e.state.tr.replaceSelectionWith(s,e.input.shiftKey):e.state.tr.replaceSelection(o);return e.dispatch(a.scrollIntoView().setMeta('paste',!0).setMeta('uiEvent','paste')),!0}Er.copy=Ar.cut=(e,t)=>{let n=t,r=e.state.selection,i='cut'==n.type;if(r.empty)return;let o=Xr?null:n.clipboardData,s=r.content(),{dom:a,text:l}=wr(e,s);o?(n.preventDefault(),o.clearData(),o.setData('text/html',a.innerHTML),o.setData('text/plain',l)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement('div'));n.appendChild(t),n.style.cssText='position: fixed; left: -10000px; top: 10px';let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout((()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()}),50)}(e,a),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta('uiEvent','cut'))},Ar.paste=(e,t)=>{let n=t;if(e.composing&&!en)return;let r=Xr?null:n.clipboardData;r&&Zr(e,r.getData('text/plain'),r.getData('text/html'),e.input.shiftKey,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?'textarea':'div'));n||(r.contentEditable='true'),r.style.cssText='position: fixed; left: -10000px; top: 10px',r.focus(),setTimeout((()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Zr(e,r.value,null,e.input.shiftKey,t):Zr(e,r.textContent,r.innerHTML,e.input.shiftKey,t)}),50)}(e,n)};class Qr{constructor(e,t){this.slice=e,this.move=t}}const ei=Qt?'altKey':'ctrlKey';Er.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,o=i.empty?null:e.posAtCoords(zr(n));if(o&&o.pos>=i.from&&o.pos<=(i instanceof ht?i.to-1:i.to));else if(r&&r.mightDrag)e.dispatch(e.state.tr.setSelection(ht.create(e.state.doc,r.mightDrag.pos)));else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&e.dispatch(e.state.tr.setSelection(ht.create(e.state.doc,t.posBefore)))}let s=e.state.selection.content(),{dom:a,text:l}=wr(e,s);n.dataTransfer.clearData(),n.dataTransfer.setData(Xr?'Text':'text/html',a.innerHTML),n.dataTransfer.effectAllowed='copyMove',Xr||n.dataTransfer.setData('text/plain',l),e.dragging=new Qr(s,!n[ei])},Er.dragend=e=>{let t=e.dragging;window.setTimeout((()=>{e.dragging==t&&(e.dragging=null)}),50)},Ar.dragover=Ar.dragenter=(e,t)=>t.preventDefault(),Ar.drop=(e,t)=>{let n=t,r=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let i=e.posAtCoords(zr(n));if(!i)return;let o=e.state.doc.resolve(i.pos),s=r&&r.slice;s?e.someProp('transformPasted',(t=>{s=t(s,e)})):s=vr(e,n.dataTransfer.getData(Xr?'Text':'text/plain'),Xr?null:n.dataTransfer.getData('text/html'),!1,o);let a=!(!r||n[ei]);if(e.someProp('handleDrop',(t=>t(e,n,s||S.empty,a))))return void n.preventDefault();if(!s)return;n.preventDefault();let l=s?We(e.state.doc,o.pos,s):o.pos;null==l&&(l=o.pos);let c=e.state.tr;a&&c.deleteSelection();let d=c.mapping.map(l),h=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,p=c.doc;if(h?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(p))return;let u=c.doc.resolve(d);if(h&&ht.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new ht(u));else{let t=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach(((e,n,r,i)=>t=i)),c.setSelection(nr(e,u,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta('uiEvent','drop'))},Er.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add('ProseMirror-focused'),e.domObserver.start(),e.focused=!0,setTimeout((()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Gn(e)}),20))},Er.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove('ProseMirror-focused'),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},Er.beforeinput=(e,t)=>{if(Gt&&en&&'deleteContentBackward'==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout((()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp('handleKeyDown',(t=>t(e,Bt(8,'Backspace')))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())}),50)}};for(let e in Ar)Er[e]=Ar[e];function ti(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}class ni{constructor(e,t){this.toDOM=e,this.spec=t||ai,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:o}=e.mapResult(t.from+r,this.side<0?-1:1);return o?null:new oi(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof ni&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ti(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class ri{constructor(e,t){this.attrs=e,this.spec=t||ai}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,o=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=o?null:new oi(i,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof ri&&ti(this.attrs,e.attrs)&&ti(this.spec,e.spec)}static is(e){return e.type instanceof ri}destroy(){}}class ii{constructor(e,t){this.attrs=e,this.spec=t||ai}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let o=e.mapResult(t.to+r,-1);return o.deleted||o.pos<=i.pos?null:new oi(i.pos-n,o.pos-n,this)}valid(e,t){let n,{index:r,offset:i}=e.content.findIndex(t.from);return i==t.from&&!(n=e.child(r)).isText&&i+n.nodeSize==t.to}eq(e){return this==e||e instanceof ii&&ti(this.attrs,e.attrs)&&ti(this.spec,e.spec)}destroy(){}}class oi{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new oi(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,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new oi(e,e,new ni(t,n))}static inline(e,t,n,r){return new oi(e,t,new ri(n,r))}static node(e,t,n,r){return new oi(e,t,new ii(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof ri}}const si=[],ai={};class li{constructor(e,t){this.local=e.length?e:si,this.children=t.length?t:si}static create(e,t){return t.length?fi(t,e,0,ai):ci}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,i){for(let o=0;o<this.local.length;o++){let s=this.local[o];s.from<=t&&s.to>=e&&(!i||i(s.spec))&&n.push(s.copy(s.from+r,s.to+r))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let s=this.children[o]+1;this.children[o+2].findInner(e-s,t-s,n,r+s,i)}}map(e,t,n){return this==ci||0==e.maps.length?this:this.mapInner(e,t,0,0,n||ai)}mapInner(e,t,n,r,i){let o;for(let s=0;s<this.local.length;s++){let a=this.local[s].map(e,n,r);a&&a.type.valid(t,a)?(o||(o=[])).push(a):i.onRemove&&i.onRemove(this.local[s].spec)}return this.children.length?function(e,t,n,r,i,o,s){let a=e.slice();for(let e=0,t=o;e<n.maps.length;e++){let r=0;n.maps[e].forEach(((e,n,o,s)=>{let l=s-o-(n-e);for(let s=0;s<a.length;s+=3){let c=a[s+1];if(c<0||e>c+t-r)continue;let d=a[s]+t-r;n>=d?a[s+1]=e<=d?-2:-1:o>=i&&l&&(a[s]+=l,a[s+1]+=l)}r+=l})),t=n.maps[e].map(t,-1)}let l=!1;for(let t=0;t<a.length;t+=3)if(a[t+1]<0){if(-2==a[t+1]){l=!0,a[t+1]=-1;continue}let c=n.map(e[t]+o),d=c-i;if(d<0||d>=r.content.size){l=!0;continue}let h=n.map(e[t+1]+o,-1)-i,{index:p,offset:u}=r.content.findIndex(d),f=r.maybeChild(p);if(f&&u==d&&u+f.nodeSize==h){let r=a[t+2].mapInner(n,f,c+1,e[t]+o+1,s);r!=ci?(a[t]=d,a[t+1]=h,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=function(e,t,n,r,i,o,s){function a(e,t){for(let o=0;o<e.local.length;o++){let a=e.local[o].map(r,i,t);a?n.push(a):s.onRemove&&s.onRemove(e.local[o].spec)}for(let n=0;n<e.children.length;n+=3)a(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)-1==e[n+1]&&a(e[n+2],t[n]+o+1);return n}(a,e,t,n,i,o,s),c=fi(l,r,0,s);t=c.local;for(let e=0;e<a.length;e+=3)a[e+1]<0&&(a.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<a.length&&a[t]<n;)t+=3;a.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new li(t.sort(mi),a)}(this.children,o||[],e,t,n,r,i):o?new li(o.sort(mi),si):ci}add(e,t){return t.length?this==ci?li.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,i=0;e.forEach(((e,o)=>{let s,a=o+n;if(s=pi(t,e,a)){for(r||(r=this.children.slice());i<r.length&&r[i]<o;)i+=3;r[i]==o?r[i+2]=r[i+2].addInner(e,s,a+1):r.splice(i,0,o,o+e.nodeSize,fi(s,e,a+1,ai)),i+=3}}));let o=hi(i?ui(t):t,-n);for(let t=0;t<o.length;t++)o[t].type.valid(e,o[t])||o.splice(t--,1);return new li(o.length?this.local.concat(o).sort(mi):this.local,r||this.children)}remove(e){return 0==e.length||this==ci?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let r=0;r<n.length;r+=3){let i,o=n[r]+t,s=n[r+1]+t;for(let t,n=0;n<e.length;n++)(t=e[n])&&t.from>o&&t.to<s&&(e[n]=null,(i||(i=[])).push(t));if(!i)continue;n==this.children&&(n=this.children.slice());let a=n[r+2].removeInner(i,o+1);a!=ci?n[r+2]=a:(n.splice(r,3),r-=3)}if(r.length)for(let n,i=0;i<e.length;i++)if(n=e[i])for(let e=0;e<r.length;e++)r[e].eq(n,t)&&(r==this.local&&(r=this.local.slice()),r.splice(e--,1));return n==this.children&&r==this.local?this:r.length||n.length?new li(r,n):ci}forChild(e,t){if(this==ci)return this;if(t.isLeaf)return li.empty;let n,r;for(let t=0;t<this.children.length;t+=3)if(this.children[t]>=e){this.children[t]==e&&(n=this.children[t+2]);break}let i=e+1,o=i+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>i&&t.type instanceof ri){let e=Math.max(i,t.from)-i,n=Math.min(o,t.to)-i;e<n&&(r||(r=[])).push(t.copy(e,n))}}if(r){let e=new li(r.sort(mi),si);return n?new di([e,n]):e}return n||ci}eq(e){if(this==e)return!0;if(!(e instanceof li)||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 gi(this.localsInner(e))}localsInner(e){if(this==ci)return si;if(e.inlineContent||!this.local.some(ri.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof ri||t.push(this.local[e]);return t}}li.empty=new li([],[]),li.removeOverlap=gi;const ci=li.empty;class di{constructor(e){this.members=e}map(e,t){const n=this.members.map((n=>n.map(e,t,ai)));return di.from(n)}forChild(e,t){if(t.isLeaf)return li.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=ci&&(i instanceof di?n=n.concat(i.members):n.push(i))}return di.from(n)}eq(e){if(!(e instanceof di)||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,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<i.length;e++)t.push(i[e])}else t=i}return t?gi(n?t:t.sort(mi)):si}static from(e){switch(e.length){case 0:return ci;case 1:return e[0];default:return new di(e.every((e=>e instanceof li))?e:e.reduce(((e,t)=>e.concat(t instanceof li?t:t.members)),[]))}}}function hi(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new oi(i.from+t,i.to+t,i.type))}return n}function pi(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t,o=0;o<e.length;o++)(t=e[o])&&t.from>n&&t.to<r&&((i||(i=[])).push(t),e[o]=null);return i}function ui(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function fi(e,t,n,r){let i=[],o=!1;t.forEach(((t,s)=>{let a=pi(e,t,s+n);if(a){o=!0;let e=fi(a,t,n+s+1,r);e!=ci&&i.push(s,s+t.nodeSize,e)}}));let s=hi(o?ui(e):e,-n).sort(mi);for(let e=0;e<s.length;e++)s[e].type.valid(t,s[e])||(r.onRemove&&r.onRemove(s[e].spec),s.splice(e--,1));return s.length||i.length?new li(s,i):ci}function mi(e,t){return e.from-t.from||e.to-t.to}function gi(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let o=t[i];if(o.from!=r.from){o.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,o.from),yi(t,i,r.copy(o.from,r.to)));break}o.to!=r.to&&(t==e&&(t=e.slice()),t[i]=o.copy(o.from,r.to),yi(t,i+1,o.copy(r.to,o.to)))}}return t}function yi(e,t,n){for(;t<e.length&&mi(n,e[t])>0;)t++;e.splice(t,0,n)}function wi(e){let t=[];return e.someProp('decorations',(n=>{let r=n(e.state);r&&r!=ci&&t.push(r)})),e.cursorWrapper&&t.push(li.create(e.state.doc,[e.cursorWrapper.deco])),di.from(t)}const vi={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},bi=Jt&&qt<=11;class ki{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 xi{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new ki,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver((e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);Jt&&qt<=11&&e.some((e=>'childList'==e.type&&e.removedNodes.length||'characterData'==e.type&&e.oldValue.length>e.target.nodeValue.length))?this.flushSoon():this.flush()})),bi&&(this.onCharData=e=>{this.queue.push({target:e.target,type:'characterData',oldValue:e.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,vi)),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(rr(this.view)){if(this.suppressingSelectionUpdates)return Gn(this.view);if(Jt&&qt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&It(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,n=new Set;for(let t=e.focusNode;t;t=Et(t))n.add(t);for(let r=e.anchorNode;r;r=Et(r))if(n.has(r)){t=r;break}let r=t&&this.view.docView.nearestDesc(t);return r&&r.ignoreMutation({type:'selection',target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.observer?this.observer.takeRecords():[];this.queue.length&&(t=this.queue.concat(t),this.queue.length=0);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&rr(e)&&!this.ignoreSelectionChange(n),i=-1,o=-1,s=!1,a=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],a);n&&(i=i<0?n.from:Math.min(n.from,i),o=o<0?n.to:Math.max(n.to,o),n.typeOver&&(s=!0))}if(Kt&&a.length>1){let e=a.filter((e=>'BR'==e.nodeName));if(2==e.length){let t=e[0],n=e[1];t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}}let l=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&zt(n)&&(l=Kn(e))&&l.eq(ot.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Gn(e),this.currentSelection.set(n),e.scrollToSelection()):(i>-1||r)&&(i>-1&&(e.docView.markDirty(i,o),function(e){if(Si.has(e))return;if(Si.set(e,null),-1!==['normal','nowrap','pre-line'].indexOf(getComputedStyle(e.dom).whiteSpace)){if(e.requiresGeckoHackNode=Kt,Mi)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.'),Mi=!0}}(e)),this.handleDOMChange(i,o,s,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||Gn(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if('attributes'==e.type&&(n==this.view.docView||'contenteditable'==e.attributeName||'style'==e.attributeName&&!e.oldValue&&!e.target.getAttribute('style')))return null;if(!n||n.ignoreMutation(e))return null;if('childList'==e.type){for(let n=0;n<e.addedNodes.length;n++)t.push(e.addedNodes[n]);if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(Jt&&qt<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:o}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(r=n),(!o||Array.prototype.indexOf.call(e.addedNodes,o)<0)&&(i=o)}let o=r&&r.parentNode==e.target?Nt(r)+1:0,s=n.localPosFromDOM(e.target,o,-1),a=i&&i.parentNode==e.target?Nt(i):e.target.childNodes.length;return{from:s,to:n.localPosFromDOM(e.target,a,1)}}return'attributes'==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}}}let Si=new WeakMap,Mi=!1;function Ci(e){let t=e.pmViewDesc;if(t)return t.parseRule();if('BR'==e.nodeName&&e.parentNode){if(Xt&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement('div');return e.appendChild(document.createElement('li')),{skip:e}}if(e.parentNode.lastChild==e||Xt&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if('IMG'==e.nodeName&&e.getAttribute('mark-placeholder'))return{ignore:!0};return null}const Ti=/^(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 Oi(e,t,n,r,i){if(t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=Kn(e,t);if(n&&!e.state.selection.eq(n)){if(Gt&&en&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp('handleKeyDown',(t=>t(e,Bt(13,'Enter')))))return;let r=e.state.tr.setSelection(n);'pointer'==t?r.setMeta('pointer',!0):'key'==t&&r.scrollIntoView(),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let a,l,c=e.state.selection,d=function(e,t,n){let r,{node:i,fromOffset:o,toOffset:s,from:a,to:l}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(r=[{node:d,offset:c.anchorOffset}],zt(c)||r.push({node:c.focusNode,offset:c.focusOffset})),Gt&&8===e.input.lastKeyCode)for(let e=s;e>o;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if('BR'==t.nodeName&&!n){s=e;break}if(!n||n.size)break}let h=e.state.doc,p=e.someProp('domParser')||ae.fromSchema(e.state.schema),u=h.resolve(a),f=null,m=p.parse(i,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:o,to:s,preserveWhitespace:'pre'!=u.parent.type.whitespace||'full',findPositions:r,ruleFromNode:Ci,context:u});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),f={anchor:e+a,head:t+a}}return{doc:m,sel:f,from:a,to:l}}(e,t,n),h=e.state.doc,p=h.slice(d.from,d.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(a=e.state.selection.to,l='end'):(a=e.state.selection.from,l='start'),e.input.lastKeyCode=null;let u=function(e,t,n,r,i){let o=e.findDiffStart(t,n);if(null==o)return null;let{a:s,b:a}=e.findDiffEnd(t,n+e.size,n+t.size);if('end'==i){r-=s+Math.max(0,o-Math.min(s,a))-o}if(s<o&&e.size<t.size){o-=r<=o&&r>=s?o-r:0,a=o+(a-s),s=o}else if(a<o){o-=r<=o&&r>=a?o-r:0,s=o+(s-a),a=o}return{start:o,endA:s,endB:a}}(p.content,d.doc.content,d.from,a,l);if((Zt&&e.input.lastIOSEnter>Date.now()-225||en)&&i.some((e=>1==e.nodeType&&!Ti.test(e.nodeName)))&&(!u||u.endA>=u.endB)&&e.someProp('handleKeyDown',(t=>t(e,Bt(13,'Enter')))))return void(e.input.lastIOSEnter=0);if(!u){if(!(r&&c instanceof ct&&!c.empty&&c.$head.sameParent(c.$anchor))||e.composing||d.sel&&d.sel.anchor!=d.sel.head){if(d.sel){let t=Ni(e,e.state.doc,d.sel);t&&!t.eq(e.state.selection)&&e.dispatch(e.state.tr.setSelection(t))}return}u={start:c.from,endA:c.to,endB:c.to}}if(Gt&&e.cursorWrapper&&d.sel&&d.sel.anchor==e.cursorWrapper.deco.from&&d.sel.head==d.sel.anchor){let e=u.endB-u.start;d.sel={anchor:d.sel.anchor+e,head:d.sel.anchor+e}}e.input.domChangeCount++,e.state.selection.from<e.state.selection.to&&u.start==u.endB&&e.state.selection instanceof ct&&(u.start>e.state.selection.from&&u.start<=e.state.selection.from+2&&e.state.selection.from>=d.from?u.start=e.state.selection.from:u.endA<e.state.selection.to&&u.endA>=e.state.selection.to-2&&e.state.selection.to<=d.to&&(u.endB+=e.state.selection.to-u.endA,u.endA=e.state.selection.to)),Jt&&qt<=11&&u.endB==u.start+1&&u.endA==u.start&&u.start>d.from&&' '==d.doc.textBetween(u.start-d.from-1,u.start-d.from+1)&&(u.start--,u.endA--,u.endB--);let f,m=d.doc.resolveNoCache(u.start-d.from),g=d.doc.resolveNoCache(u.endB-d.from),w=h.resolve(u.start),v=m.sameParent(g)&&m.parent.inlineContent&&w.end()>=u.endA;if((Zt&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some((e=>'DIV'==e.nodeName||'P'==e.nodeName)))||!v&&m.pos<d.doc.content.size&&(f=ot.findFrom(d.doc.resolve(m.pos+1),1,!0))&&f.head==g.pos)&&e.someProp('handleKeyDown',(t=>t(e,Bt(13,'Enter')))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>u.start&&function(e,t,n,r,i){if(!r.parent.isTextblock||n-t<=i.pos-r.pos||Ei(r,!0,!1)<i.pos)return!1;let o=e.resolve(t);if(o.parentOffset<o.parent.content.size||!o.parent.isTextblock)return!1;let s=e.resolve(Ei(o,!0,!0));return!(!s.parent.isTextblock||s.pos>n||Ei(s,!0,!1)<n)&&r.parent.content.cut(r.parentOffset).eq(s.parent.content)}(h,u.start,u.endA,m,g)&&e.someProp('handleKeyDown',(t=>t(e,Bt(8,'Backspace')))))return void(en&&Gt&&e.domObserver.suppressSelectionUpdates());Gt&&en&&u.endB==u.start&&(e.input.lastAndroidDelete=Date.now()),en&&!v&&m.start()!=g.start()&&0==g.parentOffset&&m.depth==g.depth&&d.sel&&d.sel.anchor==d.sel.head&&d.sel.head==u.endA&&(u.endB-=2,g=d.doc.resolveNoCache(u.endB-d.from),setTimeout((()=>{e.someProp('handleKeyDown',(t=>t(e,Bt(13,'Enter'))))}),20));let b,k,x,S=u.start,M=u.endA;if(v)if(m.pos==g.pos)Jt&&qt<=11&&0==m.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout((()=>Gn(e)),20)),b=e.state.tr.delete(S,M),k=h.resolve(u.start).marksAcross(h.resolve(u.endA));else if(u.endA==u.endB&&(x=function(e,t){let n,r,i,o=e.firstChild.marks,s=t.firstChild.marks,a=o,l=s;for(let e=0;e<s.length;e++)a=s[e].removeFromSet(a);for(let e=0;e<o.length;e++)l=o[e].removeFromSet(l);if(1==a.length&&0==l.length)r=a[0],n='add',i=e=>e.mark(r.addToSet(e.marks));else{if(0!=a.length||1!=l.length)return null;r=l[0],n='remove',i=e=>e.mark(r.removeFromSet(e.marks))}let c=[];for(let e=0;e<t.childCount;e++)c.push(i(t.child(e)));if(y.from(c).eq(e))return{mark:r,type:n}}(m.parent.content.cut(m.parentOffset,g.parentOffset),w.parent.content.cut(w.parentOffset,u.endA-w.start()))))b=e.state.tr,'add'==x.type?b.addMark(S,M,x.mark):b.removeMark(S,M,x.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let t=m.parent.textBetween(m.parentOffset,g.parentOffset);if(e.someProp('handleTextInput',(n=>n(e,S,M,t))))return;b=e.state.tr.insertText(t,S,M)}if(b||(b=e.state.tr.replace(S,M,d.doc.slice(u.start-d.from,u.endB-d.from))),d.sel){let t=Ni(e,b.doc,d.sel);t&&!(Gt&&en&&e.composing&&t.empty&&(u.start!=u.endB||e.input.lastAndroidDelete<Date.now()-100)&&(t.head==S||t.head==b.mapping.map(M)-1)||Jt&&t.empty&&t.head==S)&&b.setSelection(t)}k&&b.ensureMarks(k),e.dispatch(b.scrollIntoView())}function Ni(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:nr(e,t.resolve(n.anchor),t.resolve(n.head))}function Ei(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}class Ai{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 Ir,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Li),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement('div'),e&&(e.appendChild?e.appendChild(this.dom):'function'==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Ri(this),Ii(this),this.nodeViews=Pi(this),this.docView=Dn(this.state.doc,Di(this),wi(this),this.dom,this),this.domObserver=new xi(this,((e,t,n,r)=>Oi(this,e,t,n,r))),this.domObserver.start(),function(e){for(let t in Er){let n=Er[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!$r(e,t)||Lr(e,t)||!e.editable&&t.type in Ar||n(e,t)},Dr[t]?{passive:!0}:void 0)}Xt&&e.dom.addEventListener('input',(()=>null)),Pr(e)}(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(Li),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(Gr(this),i=!0),this.state=e;let o=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(o||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=Pi(this);(function(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(o||t.handleDOMEvents!=this._props.handleDOMEvents)&&Pr(this),this.editable=Ri(this),Ii(this);let s=wi(this),a=Di(this),l=n.plugins==e.plugins||n.doc.eq(e.doc)?e.scrollToSelection>n.scrollToSelection?'to selection':'preserve':'reset',c=r||!this.docView.matchesNode(e.doc,a,s);!c&&e.selection.eq(n.selection)||(i=!0);let d='preserve'==l&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),i=Math.max(0,r.top);for(let o=(r.left+r.right)/2,s=i+1;s<Math.min(innerHeight,r.bottom);s+=5){let r=e.root.elementFromPoint(o,s);if(!r||r==e.dom||!e.dom.contains(r))continue;let a=r.getBoundingClientRect();if(a.top>=i-20){t=r,n=a.top;break}}return{refDOM:t,refTop:n,stack:ln(e.dom)}}(this);if(i){this.domObserver.stop();let t=c&&(Jt||Gt)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&function(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}(n.selection,e.selection);if(c){let n=Gt?this.trackWrites=this.domSelectionRange().focusNode:null;!r&&this.docView.update(e.doc,a,s,this)||(this.docView.updateOuterDeco([]),this.docView.destroy(),this.docView=Dn(e.doc,a,s,this.dom,this)),n&&!this.trackWrites&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&function(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return It(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?Gn(this,t):(er(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),'reset'==l?this.dom.scrollTop=0:'to selection'==l?this.scrollToSelection():d&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;cn(n,0==r?0:r-t)}(d)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(this.someProp('handleScrollToSelection',(e=>e(this))));else if(this.state.selection instanceof ht){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&an(this,t.getBoundingClientRect(),e)}else an(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)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}}someProp(e,t){let n,r=this._props&&this._props[e];if(null!=r&&(n=t?t(r):r))return n;for(let r=0;r<this.directPlugins.length;r++){let i=this.directPlugins[r].props[e];if(null!=i&&(n=t?t(i):i))return n}let i=this.state.plugins;if(i)for(let r=0;r<i.length;r++){let o=i[r].props[e];if(null!=o&&(n=t?t(o):o))return n}}hasFocus(){if(Jt){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('false'==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(dn)return e.focus(dn);let t=ln(e);e.focus(null==dn?{get preventScroll(){return dn={preventScroll:!0},!0}}:void 0),dn||(dn=!1,cn(t,0))}(this.dom),Gn(this),this.domObserver.start()}get root(){let e=this._root;if(null==e)for(let e=this.dom.parentNode;e;e=e.parentNode)if(9==e.nodeType||11==e.nodeType&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e;return e||document}posAtCoords(e){return fn(this,e)}coordsAtPos(e,t=1){return yn(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,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw new RangeError('DOM position not inside the editor');return r}endOfTextblock(e,t){return Cn(this,t||this.state,e)}pasteHTML(e,t){return Zr(this,'',e,!1,t||new ClipboardEvent('paste'))}pasteText(e,t){return Zr(this,e,null,!0,t||new ClipboardEvent('paste'))}destroy(){this.docView&&(!function(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],wi(this),this),this.dom.textContent=''):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){Lr(e,t)||!Er[t.type]||!e.editable&&t.type in Ar||Er[t.type](e,t)}(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){return Xt&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom?function(e){let t;function n(e){e.preventDefault(),e.stopImmediatePropagation(),t=e.getTargetRanges()[0]}e.dom.addEventListener('beforeinput',n,!0),document.execCommand('indent'),e.dom.removeEventListener('beforeinput',n,!0);let r=t.startContainer,i=t.startOffset,o=t.endContainer,s=t.endOffset,a=e.domAtPos(e.state.selection.anchor);return It(a.node,a.offset,o,s)&&([r,i,o,s]=[o,s,r,i]),{anchorNode:r,anchorOffset:i,focusNode:o,focusOffset:s}}(this):this.domSelection()}domSelection(){return this.root.getSelection()}}function Di(e){let t=Object.create(null);return t.class='ProseMirror',t.contenteditable=String(e.editable),t.translate='no',e.someProp('attributes',(n=>{if('function'==typeof n&&(n=n(e.state)),n)for(let e in n)'class'==e&&(t.class+=' '+n[e]),'style'==e?t.style=(t.style?t.style+';':'')+n[e]:t[e]||'contenteditable'==e||'nodeName'==e||(t[e]=String(n[e]))})),[oi.node(0,e.state.doc.content.size,t)]}function Ii(e){if(e.markCursor){let t=document.createElement('img');t.className='ProseMirror-separator',t.setAttribute('mark-placeholder','true'),t.setAttribute('alt',''),e.cursorWrapper={dom:t,deco:oi.widget(e.state.selection.head,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Ri(e){return!e.someProp('editable',(t=>!1===t(e.state)))}function Pi(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp('nodeViews',n),e.someProp('markViews',n),t}function Li(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw new RangeError('Plugins passed directly to the view must not have a state component')}var $i={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:'\''},zi={48:')',49:'!',50:'@',51:'#',52:'$',53:'%',54:'^',55:'&',56:'*',57:'(',59:':',61:'+',173:'_',186:':',187:'+',188:'<',189:'_',190:'>',191:'?',192:'~',219:'{',220:'|',221:'}',222:'"'},Bi='undefined'!=typeof navigator&&/Chrome\/(\d+)/.exec(navigator.userAgent);'undefined'!=typeof navigator&&/Gecko\/\d+/.test(navigator.userAgent);for(var Vi='undefined'!=typeof navigator&&/Mac/.test(navigator.platform),Fi='undefined'!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Hi=Vi||Bi&&+Bi[1]<57,ji=0;ji<10;ji++)$i[48+ji]=$i[96+ji]=String(ji);for(ji=1;ji<=24;ji++)$i[ji+111]='F'+ji;for(ji=65;ji<=90;ji++)$i[ji]=String.fromCharCode(ji+32),zi[ji]=String.fromCharCode(ji);for(var _i in $i)zi.hasOwnProperty(_i)||(zi[_i]=$i[_i]);const Wi='undefined'!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform);function Ji(e){let t,n,r,i,o=e.split(/-(?!$)/),s=o[o.length-1];'Space'==s&&(s=' ');for(let e=0;e<o.length-1;e++){let s=o[e];if(/^(cmd|meta|m)$/i.test(s))i=!0;else if(/^a(lt)?$/i.test(s))t=!0;else if(/^(c|ctrl|control)$/i.test(s))n=!0;else if(/^s(hift)?$/i.test(s))r=!0;else{if(!/^mod$/i.test(s))throw new Error('Unrecognized modifier name: '+s);Wi?i=!0:n=!0}}return t&&(s='Alt-'+s),n&&(s='Ctrl-'+s),i&&(s='Meta-'+s),r&&(s='Shift-'+s),s}function qi(e,t,n=!0){return t.altKey&&(e='Alt-'+e),t.ctrlKey&&(e='Ctrl-'+e),t.metaKey&&(e='Meta-'+e),n&&t.shiftKey&&(e='Shift-'+e),e}function Ki(e){let t=function(e){let t=Object.create(null);for(let n in e)t[Ji(n)]=e[n];return t}(e);return(e,n)=>{let r,i=function(e){var t=!(Hi&&(e.ctrlKey||e.altKey||e.metaKey)||Fi&&e.shiftKey&&e.key&&1==e.key.length||'Unidentified'==e.key)&&e.key||(e.shiftKey?zi:$i)[e.keyCode]||e.key||'Unidentified';return'Esc'==t&&(t='Escape'),'Del'==t&&(t='Delete'),'Left'==t&&(t='ArrowLeft'),'Up'==t&&(t='ArrowUp'),'Right'==t&&(t='ArrowRight'),'Down'==t&&(t='ArrowDown'),t}(n),o=t[qi(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&' '!=i){if(n.shiftKey){let r=t[qi(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.shiftKey||n.altKey||n.metaKey||i.charCodeAt(0)>127)&&(r=$i[n.keyCode])&&r!=i){let i=t[qi(r,n)];if(i&&i(e.state,e.dispatch,e))return!0}}return!1}}function Ui(e,t,n=!1){for(let r=e;r;r='start'==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)return!1}return!1}function Gi(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Yi(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}function Xi(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Zi(e,t,n){let r,i,o=t.nodeBefore,s=t.nodeAfter;if(o.type.spec.isolating||s.type.spec.isolating)return!1;if(function(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,o=t.index();return!(!(r&&i&&r.type.compatibleContent(i.type))||(!r.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(o,o+1)||!i.isTextblock&&!He(e.doc,t.pos)||(n&&n(e.tr.clearIncompatible(t.pos,r.type,r.contentMatchAt(r.childCount)).join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let a=t.parent.canReplace(t.index(),t.index()+1);if(a&&(r=(i=o.contentMatchAt(o.childCount)).findWrapping(s.type))&&i.matchType(r[0]||s.type).validEnd){if(n){let i=t.pos+s.nodeSize,a=y.empty;for(let e=r.length-1;e>=0;e--)a=y.from(r[e].create(null,a));a=y.from(o.copy(a));let l=e.tr.step(new Pe(t.pos-1,i,t.pos,i,new S(a,1,0),r.length,!0)),c=i+2*r.length;He(l.doc,c)&&l.join(c),n(l.scrollIntoView())}return!0}let l=ot.findFrom(t,1),c=l&&l.$from.blockRange(l.$to),d=c&&ze(c);if(null!=d&&d>=t.depth)return n&&n(e.tr.lift(c,d).scrollIntoView()),!0;if(a&&Ui(s,'start',!0)&&Ui(o,'end')){let r=o,i=[];for(;i.push(r),!r.isTextblock;)r=r.lastChild;let a=s,l=1;for(;!a.isTextblock;a=a.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,a.content)){if(n){let r=y.empty;for(let e=i.length-1;e>=0;e--)r=y.from(i[e].copy(r));n(e.tr.step(new Pe(t.pos-i.length,t.pos+s.nodeSize,t.pos+l,t.pos+s.nodeSize-l,new S(r,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function Qi(e){return(t,n)=>{let r=t.selection,i=e<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return!!i.node(o).isTextblock&&(n&&n(t.tr.setSelection(ct.create(t.doc,e<0?i.start(o):i.end(o)))),!0)}}const eo=Qi(-1),to=Qi(1);function no(e,t=null){return(n,r)=>{let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];n.doc.nodesBetween(o,s,((r,o)=>{if(i)return!1;if(r.isTextblock&&!r.hasMarkup(e,t))if(r.type==e)i=!0;else{let t=n.doc.resolve(o),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}}))}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:o},$to:{pos:s}}=n.selection.ranges[r];i.setBlockType(o,s,e,t)}r(i.scrollIntoView())}return!0}}function ro(e,t=null){return(n,r)=>{let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=!1,l=s;if(!s)return!1;if(s.depth>=2&&i.node(s.depth-1).type.compatibleContent(e)&&0==s.startIndex){if(0==i.index(s.depth-1))return!1;let e=n.doc.resolve(s.start-2);l=new V(e,e,s.depth),s.endIndex<s.parent.childCount&&(s=new V(i,n.doc.resolve(o.end(s.depth)),s.depth)),a=!0}let c=Be(l,e,t,s);return!!c&&(r&&r(function(e,t,n,r,i){let o=y.empty;for(let e=n.length-1;e>=0;e--)o=y.from(n[e].type.create(n[e].attrs,o));e.step(new Pe(t.start-(r?2:0),t.end,t.start,t.end,new S(o,0,0),n.length,!0));let s=0;for(let e=0;e<n.length;e++)n[e].type==i&&(s=e+1);let a=n.length-s,l=t.start+n.length-(r?2:0),c=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&Fe(e.doc,l,a)&&(e.split(l,a),l+=2*a),l+=c.child(n).nodeSize;return e}(n.tr,s,c,a,e).scrollIntoView()),!0)}}function io(e){return(t,n)=>{let{$from:r,$to:i}=t.selection,o=r.blockRange(i,(t=>t.childCount>0&&t.firstChild.type==e));return!!o&&(!n||(r.node(o.depth-1).type==e?function(e,t,n,r){let i=e.tr,o=r.end,s=r.$to.end(r.depth);o<s&&(i.step(new Pe(o-1,s,o,s,new S(y.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new V(i.doc.resolve(r.$from.pos),i.doc.resolve(s),r.depth));const a=ze(r);if(null==a)return!1;i.lift(r,a);let l=i.mapping.map(o,-1)-1;He(i.doc,l)&&i.join(l);return t(i.scrollIntoView()),!0}(t,n,e,o):function(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,o=n.startIndex;t>o;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let o=r.doc.resolve(n.start),s=o.nodeAfter;if(r.mapping.map(n.end)!=n.start+o.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==i.childCount,c=o.node(-1),d=o.index(-1);if(!c.canReplace(d+(a?0:1),d+1,s.content.append(l?y.empty:y.from(i))))return!1;let h=o.pos,p=h+s.nodeSize;return r.step(new Pe(h-(a?1:0),p+(l?1:0),h+1,p-1,new S((a?y.empty:y.from(i.copy(y.empty))).append(l?y.empty:y.from(i.copy(y.empty))),a?0:1,l?0:1),a?0:1)),t(r.scrollIntoView()),!0}(t,n,o)))}}function oo(e){const{state:t,transaction:n}=e;let{selection:r}=n,{doc:i}=n,{storedMarks:o}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),filterTransaction:t.filterTransaction,plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return o},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,o=n.storedMarks,n}}}'undefined'!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):'undefined'!=typeof os&&os.platform&&os.platform();class so{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,o=this.buildProps(i);return Object.fromEntries(Object.entries(e).map((([e,t])=>[e,(...e)=>{const n=t(...e)(o);return i.getMeta('preventDispatch')||this.hasCustomState||r.dispatch(i),n}])))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){const{rawCommands:n,editor:r,state:i}=this,{view:o}=r,s=[],a=!!e,l=e||i.tr,c={...Object.fromEntries(Object.entries(n).map((([e,n])=>[e,(...e)=>{const r=this.buildProps(l,t),i=n(...e)(r);return s.push(i),c}]))),run:()=>(a||!t||l.getMeta('preventDispatch')||this.hasCustomState||o.dispatch(l),s.every((e=>!0===e)))};return c}createCan(e){const{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,false),o=Object.fromEntries(Object.entries(t).map((([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])));return{...o,chain:()=>this.createChain(r,false)}}buildProps(e,t=!0){const{rawCommands:n,editor:r,state:i}=this,{view:o}=r;i.storedMarks&&e.setStoredMarks(i.storedMarks);const s={tr:e,editor:r,view:o,state:oo({state:i,transaction:e}),dispatch:t?()=>{}:void 0,chain:()=>this.createChain(e),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map((([e,t])=>[e,(...e)=>t(...e)(s)])))}};return s}}function ao(e,t,n){if(void 0===e.config[t]&&e.parent)return ao(e.parent,t,n);if('function'==typeof e.config[t]){return e.config[t].bind({...n,parent:e.parent?ao(e.parent,t,n):null})}return e.config[t]}function lo(e){return{baseExtensions:e.filter((e=>'extension'===e.type)),nodeExtensions:e.filter((e=>'node'===e.type)),markExtensions:e.filter((e=>'mark'===e.type))}}function co(e){const t=[],{nodeExtensions:n,markExtensions:r}=lo(e),i=[...n,...r],o={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return e.forEach((e=>{const n=ao(e,'addGlobalAttributes',{name:e.name,options:e.options,storage:e.storage});if(!n)return;n().forEach((e=>{e.types.forEach((n=>{Object.entries(e.attributes).forEach((([e,r])=>{t.push({type:n,name:e,attribute:{...o,...r}})}))}))}))})),i.forEach((e=>{const n={name:e.name,options:e.options,storage:e.storage},r=ao(e,'addAttributes',n);if(!r)return;const i=r();Object.entries(i).forEach((([n,r])=>{const i={...o,...r};'function'==typeof(null==i?void 0:i.default)&&(i.default=i.default()),(null==i?void 0:i.isRequired)&&void 0===(null==i?void 0:i.default)&&delete i.default,t.push({type:e.name,name:n,attribute:i})}))})),t}function ho(e,t){if('string'==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function po(...e){return e.filter((e=>!!e)).reduce(((e,t)=>{const n={...e};return Object.entries(t).forEach((([e,t])=>{n[e]?n[e]='class'===e?[n[e],t].join(' '):'style'===e?[n[e],t].join('; '):t:n[e]=t})),n}),{})}function uo(e,t){return t.filter((e=>e.attribute.rendered)).map((t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]})).reduce(((e,t)=>po(e,t)),{})}function fo(e){return'function'==typeof e}function mo(e,t,...n){return fo(e)?t?e.bind(t)(...n):e(...n):e}function go(e,t){return e.style?e:{...e,getAttrs:n=>{const r=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===r)return!1;const i=t.reduce(((e,t)=>{const r=t.attribute.parseHTML?t.attribute.parseHTML(n):function(e){return'string'!=typeof e?e:e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):'true'===e||'false'!==e&&e}(n.getAttribute(t.name));return null==r?e:{...e,[t.name]:r}}),{});return{...r,...i}}}}function yo(e){return Object.fromEntries(Object.entries(e).filter((([e,t])=>('attrs'!==e||!function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t)))}function wo(e,t){return t.nodes[e]||t.marks[e]||null}function vo(e,t){return Array.isArray(t)?t.some((t=>('string'==typeof t?t:t.name)===e.name)):t}function bo(e){return'[object RegExp]'===Object.prototype.toString.call(e)}class ko{constructor(e){this.find=e.find,this.handler=e.handler}}function xo(e){var t;const{editor:n,from:r,to:i,text:o,rules:s,plugin:a}=e,{view:l}=n;if(l.composing)return!1;const c=l.state.doc.resolve(r);if(c.parent.type.spec.code||(null===(t=c.nodeBefore||c.nodeAfter)||void 0===t?void 0:t.marks.find((e=>e.type.spec.code))))return!1;let d=!1;const h=((e,t=500)=>{let n='';const r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,((e,t,i,o)=>{var s,a;const l=(null===(a=(s=e.type.spec).toText)||void 0===a?void 0:a.call(s,{node:e,pos:t,parent:i,index:o}))||e.textContent||'%leaf%';n+=l.slice(0,Math.max(0,r-t))})),n})(c)+o;return s.forEach((e=>{if(d)return;const t=((e,t)=>{if(bo(t))return t.exec(e);const n=t(e);if(!n)return null;const r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r})(h,e.find);if(!t)return;const s=l.state.tr,c=oo({state:l.state,transaction:s}),p={from:r-(t[0].length-o.length),to:i},{commands:u,chain:f,can:m}=new so({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:u,chain:f,can:m})&&s.steps.length&&(s.setMeta(a,{transform:s,from:r,to:i,text:o}),l.dispatch(s),d=!0)})),d}function So(e){const{editor:t,rules:n}=e,r=new Mt({state:{init:()=>null,apply(e,t){const n=e.getMeta(r);return n||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput:(e,i,o,s)=>xo({editor:t,from:i,to:o,text:s,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout((()=>{const{$cursor:i}=e.state.selection;i&&xo({editor:t,from:i.pos,to:i.pos,text:'',rules:n,plugin:r})})),!1)},handleKeyDown(e,i){if('Enter'!==i.key)return!1;const{$cursor:o}=e.state.selection;return!!o&&xo({editor:t,from:o.pos,to:o.pos,text:'\n',rules:n,plugin:r})}},isInputRules:!0});return r}class Mo{constructor(e){this.find=e.find,this.handler=e.handler}}function Co(e){const{editor:t,state:n,from:r,to:i,rule:o}=e,{commands:s,chain:a,can:l}=new so({editor:t,state:n}),c=[];n.doc.nodesBetween(r,i,((e,t)=>{if(!e.isTextblock||e.type.spec.code)return;const d=Math.max(r,t),h=Math.min(i,t+e.content.size);((e,t)=>{if(bo(t))return[...e.matchAll(t)];const n=t(e);return n?n.map((t=>{const n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),n.push(t.replaceWith)),n})):[]})(e.textBetween(d-t,h-t,void 0,''),o.find).forEach((e=>{if(void 0===e.index)return;const t=d+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},h=o.handler({state:n,range:i,match:e,commands:s,chain:a,can:l});c.push(h)}))}));return c.every((e=>null!==e))}function To(e){const{editor:t,rules:n}=e;let r=null,i=!1,o=!1;return n.map((e=>new Mt({view(e){const t=t=>{var n;r=(null===(n=e.dom.parentElement)||void 0===n?void 0:n.contains(t.target))?e.dom.parentElement:null};return window.addEventListener('dragstart',t),{destroy(){window.removeEventListener('dragstart',t)}}},props:{handleDOMEvents:{drop:e=>(o=r===e.dom.parentElement,!1),paste:(e,t)=>{var n;const r=null===(n=t.clipboardData)||void 0===n?void 0:n.getData('text/html');return i=!!(null==r?void 0:r.includes('data-pm-slice')),!1}}},appendTransaction:(n,r,s)=>{const a=n[0],l='paste'===a.getMeta('uiEvent')&&!i,c='drop'===a.getMeta('uiEvent')&&!o;if(!l&&!c)return;const d=r.doc.content.findDiffStart(s.doc.content),h=r.doc.content.findDiffEnd(s.doc.content);if('number'!=typeof d||!h||d===h.b)return;const p=s.tr,u=oo({state:s,transaction:p});return Co({editor:t,state:u,from:Math.max(d-1,0),to:h.b-1,rule:e})&&p.steps.length?p:void 0}})))}class Oo{constructor(e,t){this.splittableMarks=[],this.editor=t,this.extensions=Oo.resolve(e),this.schema=function(e,t){var n;const r=co(e),{nodeExtensions:i,markExtensions:o}=lo(e),s=null===(n=i.find((e=>ao(e,'topNode'))))||void 0===n?void 0:n.name,a=Object.fromEntries(i.map((n=>{const i=r.filter((e=>e.type===n.name)),o={name:n.name,options:n.options,storage:n.storage,editor:t},s=yo({...e.reduce(((e,t)=>{const r=ao(t,'extendNodeSchema',o);return{...e,...r?r(n):{}}}),{}),content:mo(ao(n,'content',o)),marks:mo(ao(n,'marks',o)),group:mo(ao(n,'group',o)),inline:mo(ao(n,'inline',o)),atom:mo(ao(n,'atom',o)),selectable:mo(ao(n,'selectable',o)),draggable:mo(ao(n,'draggable',o)),code:mo(ao(n,'code',o)),defining:mo(ao(n,'defining',o)),isolating:mo(ao(n,'isolating',o)),attrs:Object.fromEntries(i.map((e=>{var t;return[e.name,{default:null===(t=null==e?void 0:e.attribute)||void 0===t?void 0:t.default}]})))}),a=mo(ao(n,'parseHTML',o));a&&(s.parseDOM=a.map((e=>go(e,i))));const l=ao(n,'renderHTML',o);l&&(s.toDOM=e=>l({node:e,HTMLAttributes:uo(e,i)}));const c=ao(n,'renderText',o);return c&&(s.toText=c),[n.name,s]}))),l=Object.fromEntries(o.map((n=>{const i=r.filter((e=>e.type===n.name)),o={name:n.name,options:n.options,storage:n.storage,editor:t},s=yo({...e.reduce(((e,t)=>{const r=ao(t,'extendMarkSchema',o);return{...e,...r?r(n):{}}}),{}),inclusive:mo(ao(n,'inclusive',o)),excludes:mo(ao(n,'excludes',o)),group:mo(ao(n,'group',o)),spanning:mo(ao(n,'spanning',o)),code:mo(ao(n,'code',o)),attrs:Object.fromEntries(i.map((e=>{var t;return[e.name,{default:null===(t=null==e?void 0:e.attribute)||void 0===t?void 0:t.default}]})))}),a=mo(ao(n,'parseHTML',o));a&&(s.parseDOM=a.map((e=>go(e,i))));const l=ao(n,'renderHTML',o);return l&&(s.toDOM=e=>l({mark:e,HTMLAttributes:uo(e,i)})),[n.name,s]})));return new oe({topNode:s,nodes:a,marks:l})}(this.extensions,t),this.extensions.forEach((e=>{var t;this.editor.extensionStorage[e.name]=e.storage;const n={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:wo(e.name,this.schema)};if('mark'===e.type){(null===(t=mo(ao(e,'keepOnSplit',n)))||void 0===t||t)&&this.splittableMarks.push(e.name)}const r=ao(e,'onBeforeCreate',n);r&&this.editor.on('beforeCreate',r);const i=ao(e,'onCreate',n);i&&this.editor.on('create',i);const o=ao(e,'onUpdate',n);o&&this.editor.on('update',o);const s=ao(e,'onSelectionUpdate',n);s&&this.editor.on('selectionUpdate',s);const a=ao(e,'onTransaction',n);a&&this.editor.on('transaction',a);const l=ao(e,'onFocus',n);l&&this.editor.on('focus',l);const c=ao(e,'onBlur',n);c&&this.editor.on('blur',c);const d=ao(e,'onDestroy',n);d&&this.editor.on('destroy',d)}))}static resolve(e){const t=Oo.sort(Oo.flatten(e)),n=function(e){const t=e.filter(((t,n)=>e.indexOf(t)!==n));return[...new Set(t)]}(t.map((e=>e.name)));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map((e=>`'${e}'`)).join(', ')}]. This can lead to issues.`),t}static flatten(e){return e.map((e=>{const t=ao(e,'addExtensions',{name:e.name,options:e.options,storage:e.storage});return t?[e,...this.flatten(t())]:e})).flat(10)}static sort(e){return e.sort(((e,t)=>{const n=ao(e,'priority')||100,r=ao(t,'priority')||100;return n>r?-1:n<r?1:0}))}get commands(){return this.extensions.reduce(((e,t)=>{const n=ao(t,'addCommands',{name:t.name,options:t.options,storage:t.storage,editor:this.editor,type:wo(t.name,this.schema)});return n?{...e,...n()}:e}),{})}get plugins(){const{editor:e}=this,t=Oo.sort([...this.extensions].reverse()),n=[],r=[],i=t.map((t=>{const i={name:t.name,options:t.options,storage:t.storage,editor:e,type:wo(t.name,this.schema)},o=[],s=ao(t,'addKeyboardShortcuts',i);let a={};if('mark'===t.type&&t.config.exitable&&(a.ArrowRight=()=>vs.handleExit({editor:e,mark:t})),s){const t=Object.fromEntries(Object.entries(s()).map((([t,n])=>[t,()=>n({editor:e})])));a={...a,...t}}const l=new Mt({props:{handleKeyDown:Ki(a)}});o.push(l);const c=ao(t,'addInputRules',i);vo(t,e.options.enableInputRules)&&c&&n.push(...c());const d=ao(t,'addPasteRules',i);vo(t,e.options.enablePasteRules)&&d&&r.push(...d());const h=ao(t,'addProseMirrorPlugins',i);if(h){const e=h();o.push(...e)}return o})).flat();return[So({editor:e,rules:n}),...To({editor:e,rules:r}),...i]}get attributes(){return co(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:t}=lo(this.extensions);return Object.fromEntries(t.filter((e=>!!ao(e,'addNodeView'))).map((t=>{const n=this.attributes.filter((e=>e.type===t.name)),r={name:t.name,options:t.options,storage:t.storage,editor:e,type:ho(t.name,this.schema)},i=ao(t,'addNodeView',r);if(!i)return[];return[t.name,(r,o,s,a)=>{const l=uo(r,n);return i()({editor:e,node:r,getPos:s,decorations:a,HTMLAttributes:l,extension:t})}]})))}}function No(e){return'Object'===function(e){return Object.prototype.toString.call(e).slice(8,-1)}(e)&&(e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype)}function Eo(e,t){const n={...e};return No(e)&&No(t)&&Object.keys(t).forEach((r=>{No(t[r])?r in e?n[r]=Eo(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})})),n}class Ao{constructor(e={}){this.type='extension',this.name='extension',this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=mo(ao(this,'addOptions',{name:this.name}))),this.storage=mo(ao(this,'addStorage',{name:this.name,options:this.options}))||{}}static create(e={}){return new Ao(e)}configure(e={}){const t=this.extend();return t.options=Eo(this.options,e),t.storage=mo(ao(t,'addStorage',{name:t.name,options:t.options})),t}extend(e={}){const t=new Ao(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=mo(ao(t,'addOptions',{name:t.name})),t.storage=mo(ao(t,'addStorage',{name:t.name,options:t.options})),t}}function Do(e,t,n){const{from:r,to:i}=t,{blockSeparator:o='\n\n',textSerializers:s={}}=n||{};let a='',l=!0;return e.nodesBetween(r,i,((e,n,c,d)=>{var h;const p=null==s?void 0:s[e.type.name];p?(e.isBlock&&!l&&(a+=o,l=!0),c&&(a+=p({node:e,pos:n,parent:c,index:d,range:t}))):e.isText?(a+=null===(h=null==e?void 0:e.text)||void 0===h?void 0:h.slice(Math.max(r,n)-n,i-n),l=!1):e.isBlock&&!l&&(a+=o,l=!0)})),a}function Io(e){return Object.fromEntries(Object.entries(e.nodes).filter((([,e])=>e.spec.toText)).map((([e,t])=>[e,t.spec.toText])))}const Ro=Ao.create({name:'clipboardTextSerializer',addProseMirrorPlugins(){return[new Mt({key:new Ot('clipboardTextSerializer'),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:o}=i,s=Math.min(...o.map((e=>e.$from.pos))),a=Math.max(...o.map((e=>e.$to.pos)));return Do(r,{from:s,to:a},{textSerializers:Io(n)})}}})]}});function Po(e,t,n={strict:!0}){const r=Object.keys(t);return!r.length||r.every((r=>n.strict?t[r]===e[r]:bo(t[r])?t[r].test(e[r]):t[r]===e[r]))}function Lo(e,t,n={}){return e.find((e=>e.type===t&&Po(e.attrs,n)))}function $o(e,t,n={}){return!!Lo(e,t,n)}function zo(e,t,n={}){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(e.parentOffset===r.offset&&0!==r.offset&&(r=e.parent.childBefore(e.parentOffset)),!r.node)return;const i=Lo([...r.node.marks],t,n);if(!i)return;let o=r.index,s=e.start()+r.offset,a=o+1,l=s+r.node.nodeSize;for(Lo([...r.node.marks],t,n);o>0&&i.isInSet(e.parent.child(o-1).marks);)o-=1,s-=e.parent.child(o).nodeSize;for(;a<e.parent.childCount&&$o([...e.parent.child(a).marks],t,n);)l+=e.parent.child(a).nodeSize,a+=1;return{from:s,to:l}}function Bo(e,t){if('string'==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}function Vo(e){return e instanceof ct}function Fo(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function Ho(e,t=null){if(!t)return null;const n=ot.atStart(e),r=ot.atEnd(e);if('start'===t||!0===t)return n;if('end'===t)return r;const i=n.from,o=r.to;return'all'===t?ct.create(e,Fo(0,i,o),Fo(e.content.size,i,o)):ct.create(e,Fo(t,i,o),Fo(t,i,o))}function jo(){return['iPad Simulator','iPhone Simulator','iPod Simulator','iPad','iPhone','iPod'].includes(navigator.platform)||navigator.userAgent.includes('Mac')&&'ontouchend'in document}function _o(e){const t=`<body>${e}</body>`;return(new window.DOMParser).parseFromString(t,'text/html').body}function Wo(e,t,n){if(n={slice:!0,parseOptions:{},...n},'object'==typeof e&&null!==e)try{return Array.isArray(e)&&e.length>0?y.fromArray(e.map((e=>t.nodeFromJSON(e)))):t.nodeFromJSON(e)}catch(r){return console.warn('[tiptap warn]: Invalid content.','Passed value:',e,'Error:',r),Wo('',t,n)}if('string'==typeof e){const r=ae.fromSchema(t);return n.slice?r.parseSlice(_o(e),n.parseOptions).content:r.parse(_o(e),n.parseOptions)}return Wo('',t,n)}function Jo(){return'undefined'!=typeof navigator&&/Mac/.test(navigator.platform)}function qo(e,t,n={}){const{from:r,to:i,empty:o}=e.selection,s=t?ho(t,e.schema):null,a=[];e.doc.nodesBetween(r,i,((e,t)=>{if(e.isText)return;const n=Math.max(r,t),o=Math.min(i,t+e.nodeSize);a.push({node:e,from:n,to:o})}));const l=i-r,c=a.filter((e=>!s||s.name===e.node.type.name)).filter((e=>Po(e.node.attrs,n,{strict:!1})));if(o)return!!c.length;return c.reduce(((e,t)=>e+t.to-t.from),0)>=l}function Ko(e,t){return t.nodes[e]?'node':t.marks[e]?'mark':null}function Uo(e,t){const n='string'==typeof t?[t]:t;return Object.keys(e).reduce(((t,r)=>(n.includes(r)||(t[r]=e[r]),t)),{})}function Go(e,t,n={}){return Wo(e,t,{slice:!1,parseOptions:n})}function Yo(e){return t=>function(e,t){for(let n=e.depth;n>0;n-=1){const r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}(t.$from,e)}function Xo(e,t){const n=Bo(t,e.schema),{from:r,to:i,empty:o}=e.selection,s=[];o?(e.storedMarks&&s.push(...e.storedMarks),s.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,(e=>{s.push(...e.marks)}));const a=s.find((e=>e.type.name===n.name));return a?{...a.attrs}:{}}function Zo(e,t){const n=Ko('string'==typeof t?t:t.name,e.schema);return'node'===n?function(e,t){const n=ho(t,e.schema),{from:r,to:i}=e.selection,o=[];e.doc.nodesBetween(r,i,(e=>{o.push(e)}));const s=o.reverse().find((e=>e.type.name===n.name));return s?{...s.attrs}:{}}(e,t):'mark'===n?Xo(e,t):{}}function Qo(e,t,n){const r=[];return e===t?n.resolve(e).marks().forEach((t=>{const i=zo(n.resolve(e-1),t.type);i&&r.push({mark:t,...i})})):n.nodesBetween(e,t,((e,t)=>{r.push(...e.marks.map((n=>({from:t,to:t+e.nodeSize,mark:n}))))})),r}function es(e,t,n){return Object.fromEntries(Object.entries(n).filter((([n])=>{const r=e.find((e=>e.type===t&&e.name===n));return!!r&&r.attribute.keepOnSplit})))}function ts(e,t,n={}){const{empty:r,ranges:i}=e.selection,o=t?Bo(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter((e=>!o||o.name===e.type.name)).find((e=>Po(e.attrs,n,{strict:!1})));let s=0;const a=[];if(i.forEach((({$from:t,$to:n})=>{const r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,((e,t)=>{if(!e.isText&&!e.marks.length)return;const n=Math.max(r,t),o=Math.min(i,t+e.nodeSize);s+=o-n,a.push(...e.marks.map((e=>({mark:e,from:n,to:o}))))}))})),0===s)return!1;const l=a.filter((e=>!o||o.name===e.mark.type.name)).filter((e=>Po(e.mark.attrs,n,{strict:!1}))).reduce(((e,t)=>e+t.to-t.from),0),c=a.filter((e=>!o||e.mark.type!==o&&e.mark.type.excludes(o))).reduce(((e,t)=>e+t.to-t.from),0);return(l>0?l+c:l)>=s}function ns(e,t){const{nodeExtensions:n}=lo(t),r=n.find((t=>t.name===e));if(!r)return!1;const i=mo(ao(r,'group',{name:r.name,options:r.options,storage:r.storage}));return'string'==typeof i&&i.split(' ').includes('list')}function rs(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const r=n.filter((e=>null==t?void 0:t.includes(e.type.name)));e.tr.ensureMarks(r)}}const is=(e,t)=>{const n=Yo((e=>e.type===t))(e.selection);if(!n)return!0;const r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===r)return!0;const i=e.doc.nodeAt(r);return n.node.type!==(null==i?void 0:i.type)||!He(e.doc,n.pos)||(e.join(n.pos),!0)},ss=(e,t)=>{const n=Yo((e=>e.type===t))(e.selection);if(!n)return!0;const r=e.doc.resolve(n.start).after(n.depth);if(void 0===r)return!0;const i=e.doc.nodeAt(r);return n.node.type!==(null==i?void 0:i.type)||!He(e.doc,r)||(e.join(r),!0)};var as=Object.freeze({__proto__:null,blur:()=>({editor:e,view:t})=>(requestAnimationFrame((()=>{var n;e.isDestroyed||(t.dom.blur(),null===(n=null===window||void 0===window?void 0:window.getSelection())||void 0===n||n.removeAllRanges())})),!0),clearContent:(e=!1)=>({commands:t})=>t.setContent('',e),clearNodes:()=>({state:e,tr:t,dispatch:n})=>{const{selection:r}=t,{ranges:i}=r;return!n||(i.forEach((({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,((e,n)=>{if(e.type.isText)return;const{doc:r,mapping:i}=t,o=r.resolve(i.map(n)),s=r.resolve(i.map(n+e.nodeSize)),a=o.blockRange(s);if(!a)return;const l=ze(a);if(e.type.isTextblock){const{defaultType:e}=o.parent.contentMatchAt(o.index());t.setNodeMarkup(a.start,e)}(l||0===l)&&t.lift(a,l)}))})),!0)},command:e=>t=>e(t),createParagraphNear:()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof ut||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=Xi(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,s=e.tr.insert(n,o.createAndFill());s.setSelection(ct.create(s.doc,n+1)),t(s.scrollIntoView())}return!0})(e,t),deleteCurrentNode:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;const i=e.selection.$anchor;for(let n=i.depth;n>0;n-=1){if(i.node(n).type===r.type){if(t){const t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}}return!1},deleteNode:e=>({tr:t,state:n,dispatch:r})=>{const i=ho(e,n.schema),o=t.selection.$anchor;for(let e=o.depth;e>0;e-=1){if(o.node(e).type===i){if(r){const n=o.before(e),r=o.after(e);t.delete(n,r).scrollIntoView()}return!0}}return!1},deleteRange:e=>({tr:t,dispatch:n})=>{const{from:r,to:i}=e;return n&&t.delete(r,i),!0},deleteSelection:()=>({state:e,dispatch:t})=>((e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0))(e,t),enter:()=>({commands:e})=>e.keyboardShortcut('Enter'),exitCode:()=>({state:e,dispatch:t})=>((e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),o=n.indexAfter(-1),s=Xi(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,s.createAndFill());i.setSelection(ot.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0})(e,t),extendMarkRange:(e,t={})=>({tr:n,state:r,dispatch:i})=>{const o=Bo(e,r.schema),{doc:s,selection:a}=n,{$from:l,from:c,to:d}=a;if(i){const e=zo(l,o,t);if(e&&e.from<=c&&e.to>=d){const t=ct.create(s,e.from,e.to);n.setSelection(t)}}return!0},first:e=>t=>{const n='function'==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1},focus:(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:o})=>{t={scrollIntoView:!0,...t};const s=()=>{jo()&&r.dom.focus(),requestAnimationFrame((()=>{n.isDestroyed||(r.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())}))};if(r.hasFocus()&&null===e||!1===e)return!0;if(o&&null===e&&!Vo(n.state.selection))return s(),!0;const a=Ho(i.doc,e)||n.state.selection,l=n.state.selection.eq(a);return o&&(l||i.setSelection(a),l&&i.storedMarks&&i.setStoredMarks(i.storedMarks),s()),!0},forEach:(e,t)=>n=>e.every(((e,r)=>t(e,{...n,index:r}))),insertContent:(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),insertContentAt:(e,t,n)=>({tr:r,dispatch:i,editor:o})=>{if(i){n={parseOptions:{},updateSelection:!0,...n};const i=Wo(t,o.schema,{parseOptions:{preserveWhitespace:'full',...n.parseOptions}});if('<>'===i.toString())return!0;let{from:s,to:a}='number'==typeof e?{from:e,to:e}:e,l=!0,c=!0;if((i.toString().startsWith('<')?i:[i]).forEach((e=>{e.check(),l=!!l&&(e.isText&&0===e.marks.length),c=!!c&&e.isBlock})),s===a&&c){const{parent:e}=r.doc.resolve(s);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(s-=1,a+=1)}l?Array.isArray(t)?r.insertText(t.map((e=>e.text||'')).join(''),s,a):'object'==typeof t&&t&&t.text?r.insertText(t.text,s,a):r.insertText(t,s,a):r.replaceWith(s,a,i),n.updateSelection&&function(e,t,n){const r=e.steps.length-1;if(r<t)return;const i=e.steps[r];if(!(i instanceof Re||i instanceof Pe))return;const o=e.mapping.maps[r];let s=0;o.forEach(((e,t,n,r)=>{0===s&&(s=r)})),e.setSelection(ot.near(e.doc.resolve(s),n))}(r,r.steps.length-1,-1)}return!0},joinUp:()=>({state:e,dispatch:t})=>((e,t)=>{let n,r=e.selection,i=r instanceof ht;if(i){if(r.node.isTextblock||!He(e.doc,r.from))return!1;n=r.from}else if(n=_e(e.doc,r.from,-1),null==n)return!1;if(t){let r=e.tr.join(n);i&&r.setSelection(ht.create(r.doc,n-e.doc.resolve(n).nodeBefore.nodeSize)),t(r.scrollIntoView())}return!0})(e,t),joinDown:()=>({state:e,dispatch:t})=>((e,t)=>{let n,r=e.selection;if(r instanceof ht){if(r.node.isTextblock||!He(e.doc,r.to))return!1;n=r.to}else if(n=_e(e.doc,r.to,1),null==n)return!1;return t&&t(e.tr.join(n).scrollIntoView()),!0})(e,t),joinBackward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=((e,t)=>{let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock('backward',e):n.parentOffset>0)?null:n})(e,n);if(!r)return!1;let i=Gi(r);if(!i){let n=r.blockRange(),i=n&&ze(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let o=i.nodeBefore;if(!o.type.spec.isolating&&Zi(e,i,t))return!0;if(0==r.parent.content.size&&(Ui(o,'end')||ht.isSelectable(o))){let n=Je(e.doc,r.before(),r.after(),S.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(Ui(o,'end')?ot.findFrom(r.doc.resolve(r.mapping.map(i.pos,-1)),-1):ht.create(r.doc,i.pos-o.nodeSize)),t(r.scrollIntoView())}return!0}}return!(!o.isAtom||i.depth!=r.depth-1||(t&&t(e.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),0))})(e,t),joinForward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=((e,t)=>{let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock('forward',e):n.parentOffset<n.parent.content.size)?null:n})(e,n);if(!r)return!1;let i=Yi(r);if(!i)return!1;let o=i.nodeAfter;if(Zi(e,i,t))return!0;if(0==r.parent.content.size&&(Ui(o,'start')||ht.isSelectable(o))){let n=Je(e.doc,r.before(),r.after(),S.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(Ui(o,'start')?ot.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):ht.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return!(!o.isAtom||i.depth!=r.depth-1||(t&&t(e.tr.delete(i.pos,i.pos+o.nodeSize).scrollIntoView()),0))})(e,t),keyboardShortcut:e=>({editor:t,view:n,tr:r,dispatch:i})=>{const o=function(e){const t=e.split(/-(?!$)/);let n,r,i,o,s=t[t.length-1];'Space'===s&&(s=' ');for(let e=0;e<t.length-1;e+=1){const s=t[e];if(/^(cmd|meta|m)$/i.test(s))o=!0;else if(/^a(lt)?$/i.test(s))n=!0;else if(/^(c|ctrl|control)$/i.test(s))r=!0;else if(/^s(hift)?$/i.test(s))i=!0;else{if(!/^mod$/i.test(s))throw new Error(`Unrecognized modifier name: ${s}`);jo()||Jo()?o=!0:r=!0}}return n&&(s=`Alt-${s}`),r&&(s=`Ctrl-${s}`),o&&(s=`Meta-${s}`),i&&(s=`Shift-${s}`),s}(e).split(/-(?!$)/),s=o.find((e=>!['Alt','Ctrl','Meta','Shift'].includes(e))),a=new KeyboardEvent('keydown',{key:'Space'===s?' ':s,altKey:o.includes('Alt'),ctrlKey:o.includes('Ctrl'),metaKey:o.includes('Meta'),shiftKey:o.includes('Shift'),bubbles:!0,cancelable:!0}),l=t.captureTransaction((()=>{n.someProp('handleKeyDown',(e=>e(n,a)))}));return null==l||l.steps.forEach((e=>{const t=e.map(r.mapping);t&&i&&r.maybeStep(t)})),!0},lift:(e,t={})=>({state:n,dispatch:r})=>!!qo(n,ho(e,n.schema),t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),o=i&&ze(i);return null!=o&&(t&&t(e.tr.lift(i,o).scrollIntoView()),!0)})(n,r),liftEmptyBlock:()=>({state:e,dispatch:t})=>((e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Fe(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&ze(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)})(e,t),liftListItem:e=>({state:t,dispatch:n})=>io(ho(e,t.schema))(t,n),newlineInCode:()=>({state:e,dispatch:t})=>((e,t)=>{let{$head:n,$anchor:r}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(r)||(t&&t(e.tr.insertText('\n').scrollIntoView()),0))})(e,t),resetAttributes:(e,t)=>({tr:n,state:r,dispatch:i})=>{let o=null,s=null;const a=Ko('string'==typeof e?e:e.name,r.schema);return!!a&&('node'===a&&(o=ho(e,r.schema)),'mark'===a&&(s=Bo(e,r.schema)),i&&n.selection.ranges.forEach((e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,((e,r)=>{o&&o===e.type&&n.setNodeMarkup(r,void 0,Uo(e.attrs,t)),s&&e.marks.length&&e.marks.forEach((i=>{s===i.type&&n.addMark(r,r+e.nodeSize,s.create(Uo(i.attrs,t)))}))}))})),!0)},scrollIntoView:()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),selectAll:()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),selectNodeBackward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let{$head:r,empty:i}=e.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock('backward',e):r.parentOffset>0)return!1;o=Gi(r)}let s=o&&o.nodeBefore;return!(!s||!ht.isSelectable(s)||(t&&t(e.tr.setSelection(ht.create(e.doc,o.pos-s.nodeSize)).scrollIntoView()),0))})(e,t),selectNodeForward:()=>({state:e,dispatch:t})=>((e,t,n)=>{let{$head:r,empty:i}=e.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock('forward',e):r.parentOffset<r.parent.content.size)return!1;o=Yi(r)}let s=o&&o.nodeAfter;return!(!s||!ht.isSelectable(s)||(t&&t(e.tr.setSelection(ht.create(e.doc,o.pos)).scrollIntoView()),0))})(e,t),selectParentNode:()=>({state:e,dispatch:t})=>((e,t)=>{let n,{$from:r,to:i}=e.selection,o=r.sharedDepth(i);return 0!=o&&(n=r.before(o),t&&t(e.tr.setSelection(ht.create(e.doc,n))),!0)})(e,t),selectTextblockEnd:()=>({state:e,dispatch:t})=>to(e,t),selectTextblockStart:()=>({state:e,dispatch:t})=>eo(e,t),setContent:(e,t=!1,n={})=>({tr:r,editor:i,dispatch:o})=>{const{doc:s}=r,a=Go(e,i.schema,n);return o&&r.replaceWith(0,s.content.size,a).setMeta('preventUpdate',!t),!0},setMark:(e,t={})=>({tr:n,state:r,dispatch:i})=>{const{selection:o}=n,{empty:s,ranges:a}=o,l=Bo(e,r.schema);if(i)if(s){const e=Xo(r,l);n.addStoredMark(l.create({...e,...t}))}else a.forEach((e=>{const i=e.$from.pos,o=e.$to.pos;r.doc.nodesBetween(i,o,((e,r)=>{const s=Math.max(r,i),a=Math.min(r+e.nodeSize,o);e.marks.find((e=>e.type===l))?e.marks.forEach((e=>{l===e.type&&n.addMark(s,a,l.create({...e.attrs,...t}))})):n.addMark(s,a,l.create(t))}))}));return function(e,t,n){var r;const{selection:i}=t;let o=null;if(Vo(i)&&(o=i.$cursor),o){const t=null!==(r=e.storedMarks)&&void 0!==r?r:o.marks();return!!n.isInSet(t)||!t.some((e=>e.type.excludes(n)))}const{ranges:s}=i;return s.some((({$from:t,$to:r})=>{let i=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,((e,t,r)=>{if(i)return!1;if(e.isInline){const t=!r||r.type.allowsMarkType(n),o=!!n.isInSet(e.marks)||!e.marks.some((e=>e.type.excludes(n)));i=t&&o}return!i})),i}))}(r,n,l)},setMeta:(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),setNode:(e,t={})=>({state:n,dispatch:r,chain:i})=>{const o=ho(e,n.schema);return o.isTextblock?i().command((({commands:e})=>!!no(o,t)(n)||e.clearNodes())).command((({state:e})=>no(o,t)(e,r))).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},setNodeSelection:e=>({tr:t,dispatch:n})=>{if(n){const{doc:n}=t,r=Fo(e,0,n.content.size),i=ht.create(n,r);t.setSelection(i)}return!0},setTextSelection:e=>({tr:t,dispatch:n})=>{if(n){const{doc:n}=t,{from:r,to:i}='number'==typeof e?{from:e,to:e}:e,o=ct.atStart(n).from,s=ct.atEnd(n).to,a=Fo(r,o,s),l=Fo(i,o,s),c=ct.create(n,a,l);t.setSelection(c)}return!0},sinkListItem:e=>({state:t,dispatch:n})=>{const r=ho(e,t.schema);return(i=r,(e,t)=>{let{$from:n,$to:r}=e.selection,o=n.blockRange(r,(e=>e.childCount>0&&e.firstChild.type==i));if(!o)return!1;let s=o.startIndex;if(0==s)return!1;let a=o.parent,l=a.child(s-1);if(l.type!=i)return!1;if(t){let n=l.lastChild&&l.lastChild.type==a.type,r=y.from(n?i.create():null),s=new S(y.from(i.create(null,y.from(a.type.create(null,r)))),n?3:1,0),c=o.start,d=o.end;t(e.tr.step(new Pe(c-(n?3:1),d,c,d,s,1,!0)).scrollIntoView())}return!0})(t,n);var i},splitBlock:({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{const{selection:o,doc:s}=t,{$from:a,$to:l}=o,c=es(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(o instanceof ht&&o.node.isBlock)return!(!a.parentOffset||!Fe(s,a.pos))&&(r&&(e&&rs(n,i.extensionManager.splittableMarks),t.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;if(r){const r=l.parentOffset===l.parent.content.size;o instanceof ct&&t.deleteSelection();const s=0===a.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(a.node(-1).contentMatchAt(a.indexAfter(-1)));let d=r&&s?[{type:s,attrs:c}]:void 0,h=Fe(t.doc,t.mapping.map(a.pos),1,d);if(d||h||!Fe(t.doc,t.mapping.map(a.pos),1,s?[{type:s}]:void 0)||(h=!0,d=s?[{type:s,attrs:c}]:void 0),h&&(t.split(t.mapping.map(a.pos),1,d),s&&!r&&!a.parentOffset&&a.parent.type!==s)){const e=t.mapping.map(a.before()),n=t.doc.resolve(e);a.node(-1).canReplaceWith(n.index(),n.index()+1,s)&&t.setNodeMarkup(t.mapping.map(a.before()),s)}e&&rs(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return!0},splitListItem:e=>({tr:t,state:n,dispatch:r,editor:i})=>{var o;const s=ho(e,n.schema),{$from:a,$to:l}=n.selection,c=n.selection.node;if(c&&c.isBlock||a.depth<2||!a.sameParent(l))return!1;const d=a.node(-1);if(d.type!==s)return!1;const h=i.extensionManager.attributes;if(0===a.parent.content.size&&a.node(-1).childCount===a.indexAfter(-1)){if(2===a.depth||a.node(-3).type!==s||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let e=y.empty;const n=a.index(-1)?1:a.index(-2)?2:3;for(let t=a.depth-n;t>=a.depth-3;t-=1)e=y.from(a.node(t).copy(e));const r=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,i=es(h,a.node().type.name,a.node().attrs),l=(null===(o=s.contentMatch.defaultType)||void 0===o?void 0:o.createAndFill(i))||void 0;e=e.append(y.from(s.createAndFill(null,l)||void 0));const c=a.before(a.depth-(n-1));t.replace(c,a.after(-r),new S(e,4-n,0));let d=-1;t.doc.nodesBetween(c,t.doc.content.size,((e,t)=>{if(d>-1)return!1;e.isTextblock&&0===e.content.size&&(d=t+1)})),d>-1&&t.setSelection(ct.near(t.doc.resolve(d))),t.scrollIntoView()}return!0}const p=l.pos===a.end()?d.contentMatchAt(0).defaultType:null,u=es(h,d.type.name,d.attrs),f=es(h,a.node().type.name,a.node().attrs);t.delete(a.pos,l.pos);const m=p?[{type:s,attrs:u},{type:p,attrs:f}]:[{type:s,attrs:u}];if(!Fe(t.doc,a.pos,2))return!1;if(r){const{selection:e,storedMarks:o}=n,{splittableMarks:s}=i.extensionManager,l=o||e.$to.parentOffset&&e.$from.marks();if(t.split(a.pos,2,m).scrollIntoView(),!l||!r)return!0;const c=l.filter((e=>s.includes(e.type.name)));t.ensureMarks(c)}return!0},toggleList:(e,t,n,r={})=>({editor:i,tr:o,state:s,dispatch:a,chain:l,commands:c,can:d})=>{const{extensions:h,splittableMarks:p}=i.extensionManager,u=ho(e,s.schema),f=ho(t,s.schema),{selection:m,storedMarks:g}=s,{$from:y,$to:w}=m,v=y.blockRange(w),b=g||m.$to.parentOffset&&m.$from.marks();if(!v)return!1;const k=Yo((e=>ns(e.type.name,h)))(m);if(v.depth>=1&&k&&v.depth-k.depth<=1){if(k.node.type===u)return c.liftListItem(f);if(ns(k.node.type.name,h)&&u.validContent(k.node.content)&&a)return l().command((()=>(o.setNodeMarkup(k.pos,u),!0))).command((()=>is(o,u))).command((()=>ss(o,u))).run()}return n&&b&&a?l().command((()=>{const e=d().wrapInList(u,r),t=b.filter((e=>p.includes(e.type.name)));return o.ensureMarks(t),!!e||c.clearNodes()})).wrapInList(u,r).command((()=>is(o,u))).command((()=>ss(o,u))).run():l().command((()=>!!d().wrapInList(u,r)||c.clearNodes())).wrapInList(u,r).command((()=>is(o,u))).command((()=>ss(o,u))).run()},toggleMark:(e,t={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:o=!1}=n,s=Bo(e,r.schema);return ts(r,s,t)?i.unsetMark(s,{extendEmptyMarkRange:o}):i.setMark(s,t)},toggleNode:(e,t,n={})=>({state:r,commands:i})=>{const o=ho(e,r.schema),s=ho(t,r.schema);return qo(r,o,n)?i.setNode(s):i.setNode(o,n)},toggleWrap:(e,t={})=>({state:n,commands:r})=>{const i=ho(e,n.schema);return qo(n,i,t)?r.lift(i):r.wrapIn(i,t)},undoInputRule:()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let r=0;r<n.length;r+=1){const i=n[r];let o;if(i.spec.isInputRules&&(o=i.getState(e))){if(t){const t=e.tr,n=o.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(o.text){const n=t.doc.resolve(o.from).marks();t.replaceWith(o.from,o.to,e.schema.text(o.text,n))}else t.delete(o.from,o.to)}return!0}}return!1},unsetAllMarks:()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:r,ranges:i}=n;return r||t&&i.forEach((t=>{e.removeMark(t.$from.pos,t.$to.pos)})),!0},unsetMark:(e,t={})=>({tr:n,state:r,dispatch:i})=>{var o;const{extendEmptyMarkRange:s=!1}=t,{selection:a}=n,l=Bo(e,r.schema),{$from:c,empty:d,ranges:h}=a;if(!i)return!0;if(d&&s){let{from:e,to:t}=a;const r=null===(o=c.marks().find((e=>e.type===l)))||void 0===o?void 0:o.attrs,i=zo(c,l,r);i&&(e=i.from,t=i.to),n.removeMark(e,t,l)}else h.forEach((e=>{n.removeMark(e.$from.pos,e.$to.pos,l)}));return n.removeStoredMark(l),!0},updateAttributes:(e,t={})=>({tr:n,state:r,dispatch:i})=>{let o=null,s=null;const a=Ko('string'==typeof e?e:e.name,r.schema);return!!a&&('node'===a&&(o=ho(e,r.schema)),'mark'===a&&(s=Bo(e,r.schema)),i&&n.selection.ranges.forEach((e=>{const i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,((e,r)=>{o&&o===e.type&&n.setNodeMarkup(r,void 0,{...e.attrs,...t}),s&&e.marks.length&&e.marks.forEach((o=>{if(s===o.type){const l=Math.max(r,i),c=Math.min(r+e.nodeSize,a);n.addMark(l,c,s.create({...o.attrs,...t}))}}))}))})),!0)},wrapIn:(e,t={})=>({state:n,dispatch:r})=>function(e,t=null){return(n,r)=>{let{$from:i,$to:o}=n.selection,s=i.blockRange(o),a=s&&Be(s,e,t);return!!a&&(r&&r(n.tr.wrap(s,a).scrollIntoView()),!0)}}(ho(e,n.schema),t)(n,r),wrapInList:(e,t={})=>({state:n,dispatch:r})=>ro(ho(e,n.schema),t)(n,r)});const ls=Ao.create({name:'commands',addCommands:()=>({...as})}),cs=Ao.create({name:'editable',addProseMirrorPlugins(){return[new Mt({key:new Ot('editable'),props:{editable:()=>this.editor.options.editable}})]}}),ds=Ao.create({name:'focusEvents',addProseMirrorPlugins(){const{editor:e}=this;return[new Mt({key:new Ot('focusEvents'),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const r=e.state.tr.setMeta('focus',{event:n}).setMeta('addToHistory',!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;const r=e.state.tr.setMeta('blur',{event:n}).setMeta('addToHistory',!1);return t.dispatch(r),!1}}}})]}}),hs=Ao.create({name:'keymap',addKeyboardShortcuts(){const e=()=>this.editor.commands.first((({commands:e})=>[()=>e.undoInputRule(),()=>e.command((({tr:t})=>{const{selection:n,doc:r}=t,{empty:i,$anchor:o}=n,{pos:s,parent:a}=o,l=ot.atStart(r).from===s;return!(!(i&&l&&a.type.isTextblock)||a.textContent.length)&&e.clearNodes()})),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()])),t=()=>this.editor.commands.first((({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()])),n={Enter:()=>this.editor.commands.first((({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()])),'Mod-Enter':()=>this.editor.commands.exitCode(),Backspace:e,'Mod-Backspace':e,'Shift-Backspace':e,Delete:t,'Mod-Delete':t,'Mod-a':()=>this.editor.commands.selectAll()},r={...n},i={...n,'Ctrl-h':e,'Alt-Backspace':e,'Ctrl-d':t,'Ctrl-Alt-Backspace':t,'Alt-Delete':t,'Alt-d':t,'Ctrl-a':()=>this.editor.commands.selectTextblockStart(),'Ctrl-e':()=>this.editor.commands.selectTextblockEnd()};return jo()||Jo()?i:r},addProseMirrorPlugins(){return[new Mt({key:new Ot('clearDocument'),appendTransaction:(e,t,n)=>{if(!(e.some((e=>e.docChanged))&&!t.doc.eq(n.doc)))return;const{empty:r,from:i,to:o}=t.selection,s=ot.atStart(t.doc).from,a=ot.atEnd(t.doc).to;if(r||!(i===s&&o===a))return;if(!(0===n.doc.textBetween(0,n.doc.content.size,' ',' ').length))return;const l=n.tr,c=oo({state:n,transaction:l}),{commands:d}=new so({editor:this.editor,state:c});return d.clearNodes(),l.steps.length?l:void 0}})]}}),ps=Ao.create({name:'tabindex',addProseMirrorPlugins(){return[new Mt({key:new Ot('tabindex'),props:{attributes:this.editor.isEditable?{tabindex:'0'}:{}}})]}});var us=Object.freeze({__proto__:null,ClipboardTextSerializer:Ro,Commands:ls,Editable:cs,FocusEvents:ds,Keymap:hs,Tabindex:ps});class fs extends class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){const n=this.callbacks[e];return n&&n.forEach((e=>e.apply(this,t))),this}off(e,t){const n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter((e=>e!==t)):delete this.callbacks[e]),this}removeAllListeners(){this.callbacks={}}}{constructor(e={}){super(),this.isFocused=!1,this.extensionStorage={},this.options={element:document.createElement('div'),content:'',injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on('beforeCreate',this.options.onBeforeCreate),this.emit('beforeCreate',{editor:this}),this.createView(),this.injectCSS(),this.on('create',this.options.onCreate),this.on('update',this.options.onUpdate),this.on('selectionUpdate',this.options.onSelectionUpdate),this.on('transaction',this.options.onTransaction),this.on('focus',this.options.onFocus),this.on('blur',this.options.onBlur),this.on('destroy',this.options.onDestroy),window.setTimeout((()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit('create',{editor:this}))}),0)}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&document&&(this.css=function(e,t){const n=document.querySelector('style[data-tiptap-style]');if(null!==n)return n;const r=document.createElement('style');return t&&r.setAttribute('nonce',t),r.setAttribute('data-tiptap-style',''),r.innerHTML=e,document.getElementsByTagName('head')[0].appendChild(r),r}('.ProseMirror {\n position: relative;\n}\n\n.ProseMirror {\n word-wrap: break-word;\n white-space: pre-wrap;\n white-space: break-spaces;\n -webkit-font-variant-ligatures: none;\n font-variant-ligatures: none;\n font-feature-settings: "liga" 0; /* the above doesn\'t seem to work in Edge */\n}\n\n.ProseMirror [contenteditable="false"] {\n white-space: normal;\n}\n\n.ProseMirror [contenteditable="false"] [contenteditable="true"] {\n white-space: pre-wrap;\n}\n\n.ProseMirror pre {\n white-space: pre-wrap;\n}\n\nimg.ProseMirror-separator {\n display: inline !important;\n border: none !important;\n margin: 0 !important;\n width: 1px !important;\n height: 1px !important;\n}\n\n.ProseMirror-gapcursor {\n display: none;\n pointer-events: none;\n position: absolute;\n margin: 0;\n}\n\n.ProseMirror-gapcursor:after {\n content: "";\n display: block;\n position: absolute;\n top: -2px;\n width: 20px;\n border-top: 1px solid black;\n animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;\n}\n\n@keyframes ProseMirror-cursor-blink {\n to {\n visibility: hidden;\n }\n}\n\n.ProseMirror-hideselection *::selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection *::-moz-selection {\n background: transparent;\n}\n\n.ProseMirror-hideselection * {\n caret-color: transparent;\n}\n\n.ProseMirror-focused .ProseMirror-gapcursor {\n display: block;\n}\n\n.tippy-box[data-animation=fade][data-state=hidden] {\n opacity: 0\n}',this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.view&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit('update',{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,t){const n=fo(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});this.view.updateState(r)}unregisterPlugin(e){if(this.isDestroyed)return;const t='string'==typeof e?`${e}$`:e.key,n=this.state.reconfigure({plugins:this.state.plugins.filter((e=>!e.key.startsWith(t)))});this.view.updateState(n)}createExtensionManager(){const e=[...this.options.enableCoreExtensions?Object.values(us):[],...this.options.extensions].filter((e=>['extension','node','mark'].includes(null==e?void 0:e.type)));this.extensionManager=new Oo(e,this)}createCommandManager(){this.commandManager=new so({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){const e=Go(this.options.content,this.schema,this.options.parseOptions),t=Ho(e,this.options.autofocus);this.view=new Ai(this.options.element,{...this.options.editorProps,dispatchTransaction:this.dispatchTransaction.bind(this),state:xt.create({doc:e,selection:t||void 0})});const n=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(n),this.createNodeViews();this.view.dom.editor=this}createNodeViews(){this.view.setProps({nodeViews:this.extensionManager.nodeViews})}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction)return this.capturedTransaction?void e.steps.forEach((e=>{var t;return null===(t=this.capturedTransaction)||void 0===t?void 0:t.step(e)})):void(this.capturedTransaction=e);const t=this.state.apply(e),n=!this.state.selection.eq(t.selection);this.view.updateState(t),this.emit('transaction',{editor:this,transaction:e}),n&&this.emit('selectionUpdate',{editor:this,transaction:e});const r=e.getMeta('focus'),i=e.getMeta('blur');r&&this.emit('focus',{editor:this,event:r.event,transaction:e}),i&&this.emit('blur',{editor:this,event:i.event,transaction:e}),e.docChanged&&!e.getMeta('preventUpdate')&&this.emit('update',{editor:this,transaction:e})}getAttributes(e){return Zo(this.state,e)}isActive(e,t){const n='string'==typeof e?e:null,r='string'==typeof e?t:e;return function(e,t,n={}){if(!t)return qo(e,null,n)||ts(e,null,n);const r=Ko(t,e.schema);return'node'===r?qo(e,t,n):'mark'===r&&ts(e,t,n)}(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return function(e,t){const n=ye.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement('div');return r.appendChild(n),r.innerHTML}(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t='\n\n',textSerializers:n={}}=e||{};return function(e,t){return Do(e,{from:0,to:e.content.size},t)}(this.state.doc,{blockSeparator:t,textSerializers:{...Io(this.schema),...n}})}get isEmpty(){return function(e){var t;const n=null===(t=e.type.createAndFill())||void 0===t?void 0:t.toJSON(),r=e.toJSON();return JSON.stringify(n)===JSON.stringify(r)}(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){this.emit('destroy'),this.view&&this.view.destroy(),this.removeAllListeners()}get isDestroyed(){var e;return!(null===(e=this.view)||void 0===e?void 0:e.docView)}}function ms(e){return new ko({find:e.find,handler:({state:t,range:n,match:r})=>{const i=mo(e.getAttributes,void 0,r);if(!1===i||null===i)return null;const{tr:o}=t,s=r[r.length-1],a=r[0];let l=n.to;if(s){const r=a.search(/\S/),c=n.from+a.indexOf(s),d=c+s.length;if(Qo(n.from,n.to,t.doc).filter((t=>t.mark.type.excluded.find((n=>n===e.type&&n!==t.mark.type)))).filter((e=>e.to>c)).length)return null;d<n.to&&o.delete(d,n.to),c>n.from&&o.delete(n.from+r,c),l=n.from+r+s.length,o.addMark(n.from+r,l,e.type.create(i||{})),o.removeStoredMark(e.type)}}})}function gs(e){return new ko({find:e.find,handler:({state:t,range:n,match:r})=>{const i=mo(e.getAttributes,void 0,r)||{},{tr:o}=t,s=n.from;let a=n.to;if(r[1]){let t=s+r[0].lastIndexOf(r[1]);t>a?t=a:a=t+r[1].length;const n=r[0][r[0].length-1];o.insertText(n,s+r[0].length-1),o.replaceWith(t,a,e.type.create(i))}else r[0]&&o.replaceWith(s,a,e.type.create(i))}})}function ys(e){return new ko({find:e.find,handler:({state:t,range:n,match:r})=>{const i=t.doc.resolve(n.from),o=mo(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,o)}})}function ws(e){return new ko({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{const o=mo(e.getAttributes,void 0,r)||{},s=t.tr.delete(n.from,n.to),a=s.doc.resolve(n.from).blockRange(),l=a&&Be(a,e.type,o);if(!l)return null;if(s.wrap(a,l),e.keepMarks&&e.editor){const{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,o=r||n.$to.parentOffset&&n.$from.marks();if(o){const e=o.filter((e=>i.includes(e.type.name)));s.ensureMarks(e)}}if(e.keepAttributes){const t='bulletList'===e.type.name||'orderedList'===e.type.name?'listItem':'taskList';i().updateAttributes(t,o).run()}const c=s.doc.resolve(n.from-1).nodeBefore;c&&c.type===e.type&&He(s.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,c))&&s.join(n.from-1)}})}class vs{constructor(e={}){this.type='mark',this.name='mark',this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=mo(ao(this,'addOptions',{name:this.name}))),this.storage=mo(ao(this,'addStorage',{name:this.name,options:this.options}))||{}}static create(e={}){return new vs(e)}configure(e={}){const t=this.extend();return t.options=Eo(this.options,e),t.storage=mo(ao(t,'addStorage',{name:t.name,options:t.options})),t}extend(e={}){const t=new vs(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=mo(ao(t,'addOptions',{name:t.name})),t.storage=mo(ao(t,'addStorage',{name:t.name,options:t.options})),t}static handleExit({editor:e,mark:t}){const{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){const i=r.marks();if(!!!i.find((e=>(null==e?void 0:e.type.name)===t.name)))return!1;const o=i.find((e=>(null==e?void 0:e.type.name)===t.name));return o&&n.removeStoredMark(o),n.insertText(' ',r.pos),e.view.dispatch(n),!0}return!1}}class bs{constructor(e={}){this.type='node',this.name='node',this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=mo(ao(this,'addOptions',{name:this.name}))),this.storage=mo(ao(this,'addStorage',{name:this.name,options:this.options}))||{}}static create(e={}){return new bs(e)}configure(e={}){const t=this.extend();return t.options=Eo(this.options,e),t.storage=mo(ao(t,'addStorage',{name:t.name,options:t.options})),t}extend(e={}){const t=new bs(e);return t.parent=this,this.child=t,t.name=e.name?e.name:t.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${t.name}".`),t.options=mo(ao(t,'addOptions',{name:t.name})),t.storage=mo(ao(t,'addStorage',{name:t.name,options:t.options})),t}}function ks(e){return new Mo({find:e.find,handler:({state:t,range:n,match:r})=>{const i=mo(e.getAttributes,void 0,r);if(!1===i||null===i)return null;const{tr:o}=t,s=r[r.length-1],a=r[0];let l=n.to;if(s){const r=a.search(/\S/),c=n.from+a.indexOf(s),d=c+s.length;if(Qo(n.from,n.to,t.doc).filter((t=>t.mark.type.excluded.find((n=>n===e.type&&n!==t.mark.type)))).filter((e=>e.to>c)).length)return null;d<n.to&&o.delete(d,n.to),c>n.from&&o.delete(n.from+r,c),l=n.from+r+s.length,o.addMark(n.from+r,l,e.type.create(i||{})),o.removeStoredMark(e.type)}}})}const xs=/^\s*>\s$/,Ss=bs.create({name:'blockquote',addOptions:()=>({HTMLAttributes:{}}),content:'block+',group:'block',defining:!0,parseHTML:()=>[{tag:'blockquote'}],renderHTML({HTMLAttributes:e}){return['blockquote',po(this.options.HTMLAttributes,e),0]},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{'Mod-Shift-b':()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[ws({find:xs,type:this.type})]}}),Ms=/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/,Cs=/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/g,Ts=/(?:^|\s)((?:__)((?:[^__]+))(?:__))$/,Os=/(?:^|\s)((?:__)((?:[^__]+))(?:__))/g,Ns=vs.create({name:'bold',addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:'strong'},{tag:'b',getAttrs:e=>'normal'!==e.style.fontWeight&&null},{style:'font-weight',getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],renderHTML({HTMLAttributes:e}){return['strong',po(this.options.HTMLAttributes,e),0]},addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{'Mod-b':()=>this.editor.commands.toggleBold(),'Mod-B':()=>this.editor.commands.toggleBold()}},addInputRules(){return[ms({find:Ms,type:this.type}),ms({find:Ts,type:this.type})]},addPasteRules(){return[ks({find:Cs,type:this.type}),ks({find:Os,type:this.type})]}}),Es=bs.create({name:'listItem',addOptions:()=>({HTMLAttributes:{}}),content:'paragraph block*',defining:!0,parseHTML:()=>[{tag:'li'}],renderHTML({HTMLAttributes:e}){return['li',po(this.options.HTMLAttributes,e),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),'Shift-Tab':()=>this.editor.commands.liftListItem(this.name)}}}),As=vs.create({name:'textStyle',addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:'span',getAttrs:e=>!!e.hasAttribute('style')&&{}}],renderHTML({HTMLAttributes:e}){return['span',po(this.options.HTMLAttributes,e),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:e,commands:t})=>{const n=Xo(e,this.type);return!!Object.entries(n).some((([,e])=>!!e))||t.unsetMark(this.name)}}}}),Ds=/^\s*([-+*])\s$/,Is=bs.create({name:'bulletList',addOptions:()=>({itemTypeName:'listItem',HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}),group:'block list',content(){return`${this.options.itemTypeName}+`},parseHTML:()=>[{tag:'ul'}],renderHTML({HTMLAttributes:e}){return['ul',po(this.options.HTMLAttributes,e),0]},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Es.name,this.editor.getAttributes(As.name)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{'Mod-Shift-8':()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=ws({find:Ds,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=ws({find:Ds,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(As.name),editor:this.editor})),[e]}}),Rs=/(?:^|\s)((?:`)((?:[^`]+))(?:`))$/,Ps=/(?:^|\s)((?:`)((?:[^`]+))(?:`))/g,Ls=vs.create({name:'code',addOptions:()=>({HTMLAttributes:{}}),excludes:'_',code:!0,exitable:!0,parseHTML:()=>[{tag:'code'}],renderHTML({HTMLAttributes:e}){return['code',po(this.options.HTMLAttributes,e),0]},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{'Mod-e':()=>this.editor.commands.toggleCode()}},addInputRules(){return[ms({find:Rs,type:this.type})]},addPasteRules(){return[ks({find:Ps,type:this.type})]}}),$s=/^```([a-z]+)?[\s\n]$/,zs=/^~~~([a-z]+)?[\s\n]$/,Bs=bs.create({name:'codeBlock',addOptions:()=>({languageClassPrefix:'language-',exitOnTripleEnter:!0,exitOnArrowDown:!0,HTMLAttributes:{}}),content:'text*',marks:'',group:'block',code:!0,defining:!0,addAttributes(){return{language:{default:null,parseHTML:e=>{var t;const{languageClassPrefix:n}=this.options,r=[...(null===(t=e.firstElementChild)||void 0===t?void 0:t.classList)||[]].filter((e=>e.startsWith(n))).map((e=>e.replace(n,'')))[0];return r||null},rendered:!1}}},parseHTML:()=>[{tag:'pre',preserveWhitespace:'full'}],renderHTML({node:e,HTMLAttributes:t}){return['pre',po(this.options.HTMLAttributes,t),['code',{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,'paragraph',e)}},addKeyboardShortcuts(){return{'Mod-Alt-c':()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:e,$anchor:t}=this.editor.state.selection,n=1===t.pos;return!(!e||t.parent.type.name!==this.name)&&(!(!n&&t.parent.textContent.length)&&this.editor.commands.clearNodes())},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;const o=r.parentOffset===r.parent.nodeSize-2,s=r.parent.textContent.endsWith('\n\n');return!(!o||!s)&&e.chain().command((({tr:e})=>(e.delete(r.pos-2,r.pos),!0))).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;const{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:o}=n;if(!o||i.parent.type!==this.type)return!1;if(!(i.parentOffset===i.parent.nodeSize-2))return!1;const s=i.after();if(void 0===s)return!1;return!r.nodeAt(s)&&e.commands.exitCode()}}},addInputRules(){return[ys({find:$s,type:this.type,getAttributes:e=>({language:e[1]})}),ys({find:zs,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new Mt({key:new Ot('codeBlockVSCodeHandler'),props:{handlePaste:(e,t)=>{if(!t.clipboardData)return!1;if(this.editor.isActive(this.type.name))return!1;const n=t.clipboardData.getData('text/plain'),r=t.clipboardData.getData('vscode-editor-data'),i=r?JSON.parse(r):void 0,o=null==i?void 0:i.mode;if(!n||!o)return!1;const{tr:s}=e.state;return s.replaceSelectionWith(this.type.create({language:o})),s.setSelection(ct.near(s.doc.resolve(Math.max(0,s.selection.from-2)))),s.insertText(n.replace(/\r\n?/g,'\n')),s.setMeta('paste',!0),e.dispatch(s),!0}}})]}}),Vs=bs.create({name:'doc',topNode:!0,content:'block+'});function Fs(e={}){return new Mt({view:t=>new Hs(t,e)})}class Hs{constructor(e,t){var n;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=null!==(n=t.width)&&void 0!==n?n:1,this.color=!1===t.color?void 0:t.color||'black',this.class=t.class,this.handlers=['dragover','dragend','drop','dragleave'].map((t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}}))}destroy(){this.handlers.forEach((({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t)))}update(e,t){null!=this.cursorPos&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,null==e?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e,t=this.editorView.state.doc.resolve(this.cursorPos),n=!t.parent.inlineContent;if(n){let n=t.nodeBefore,r=t.nodeAfter;if(n||r){let t=this.editorView.nodeDOM(this.cursorPos-(n?n.nodeSize:0));if(t){let i=t.getBoundingClientRect(),o=n?i.bottom:i.top;n&&r&&(o=(o+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2),e={left:i.left,right:i.right,top:o-this.width/2,bottom:o+this.width/2}}}}if(!e){let t=this.editorView.coordsAtPos(this.cursorPos);e={left:t.left-this.width/2,right:t.left+this.width/2,top:t.top,bottom:t.bottom}}let r,i,o=this.editorView.dom.offsetParent;if(this.element||(this.element=o.appendChild(document.createElement('div')),this.class&&(this.element.className=this.class),this.element.style.cssText='position: absolute; z-index: 50; pointer-events: none;',this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle('prosemirror-dropcursor-block',n),this.element.classList.toggle('prosemirror-dropcursor-inline',!n),!o||o==document.body&&'static'==getComputedStyle(o).position)r=-pageXOffset,i=-pageYOffset;else{let e=o.getBoundingClientRect();r=e.left-o.scrollLeft,i=e.top-o.scrollTop}this.element.style.left=e.left-r+'px',this.element.style.top=e.top-i+'px',this.element.style.width=e.right-e.left+'px',this.element.style.height=e.bottom-e.top+'px'}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout((()=>this.setCursor(null)),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i='function'==typeof r?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=We(this.editorView.state.doc,e,this.editorView.dragging.slice);null!=t&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){e.target!=this.editorView.dom&&this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}const js=Ao.create({name:'dropCursor',addOptions:()=>({color:'currentColor',width:1,class:void 0}),addProseMirrorPlugins(){return[Fs(this.options)]}});class _s extends ot{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return _s.valid(n)?new _s(n):ot.near(n)}content(){return S.empty}eq(e){return e instanceof _s&&e.head==this.head}toJSON(){return{type:'gapcursor',pos:this.head}}static fromJSON(e,t){if('number'!=typeof t.pos)throw new RangeError('Invalid input for GapCursor.fromJSON');return new _s(e.resolve(t.pos))}getBookmark(){return new Ws(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!function(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(0!=n)for(let e=r.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}else if(r.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n!=r.childCount)for(let e=r.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||e.isAtom||e.type.spec.isolating)return!0;if(e.inlineContent)return!1}else if(r.type.spec.isolating)return!0}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&_s.valid(e))return e;let r=e.pos,i=null;for(let n=e.depth;;n--){let o=e.node(n);if(t>0?e.indexAfter(n)<o.childCount:e.index(n)>0){i=o.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;r+=t;let s=e.doc.resolve(r);if(_s.valid(s))return s}for(;;){let o=t>0?i.firstChild:i.lastChild;if(!o){if(i.isAtom&&!i.isText&&!ht.isSelectable(i)){e=e.doc.resolve(r+i.nodeSize*t),n=!1;continue e}break}i=o,r+=t;let s=e.doc.resolve(r);if(_s.valid(s))return s}return null}}}_s.prototype.visible=!1,_s.findFrom=_s.findGapCursorFrom,ot.jsonID('gapcursor',_s);class Ws{constructor(e){this.pos=e}map(e){return new Ws(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return _s.valid(t)?new _s(t):ot.near(t)}}const Js=Ki({ArrowLeft:qs('horiz',-1),ArrowRight:qs('horiz',1),ArrowUp:qs('vert',-1),ArrowDown:qs('vert',1)});function qs(e,t){const n='vert'==e?t>0?'down':'up':t>0?'right':'left';return(e,r,i)=>{let o=e.selection,s=t>0?o.$to:o.$from,a=o.empty;if(o instanceof ct){if(!i.endOfTextblock(n)||0==s.depth)return!1;a=!1,s=e.doc.resolve(t>0?s.after():s.before())}let l=_s.findGapCursorFrom(s,t,a);return!!l&&(r&&r(e.tr.setSelection(new _s(l))),!0)}}function Ks(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!_s.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return!(i&&i.inside>-1&&ht.isSelectable(e.state.doc.nodeAt(i.inside)))&&(e.dispatch(e.state.tr.setSelection(new _s(r))),!0)}function Us(e,t){if('insertCompositionText'!=t.inputType||!(e.state.selection instanceof _s))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=y.empty;for(let e=r.length-1;e>=0;e--)i=y.from(r[e].createAndFill(null,i));let o=e.state.tr.replace(n.pos,n.pos,new S(i,0,0));return o.setSelection(ct.near(o.doc.resolve(n.pos+1))),e.dispatch(o),!1}function Gs(e){if(!(e.selection instanceof _s))return null;let t=document.createElement('div');return t.className='ProseMirror-gapcursor',li.create(e.doc,[oi.widget(e.selection.head,t,{key:'gapcursor'})])}const Ys=Ao.create({name:'gapCursor',addProseMirrorPlugins:()=>[new Mt({props:{decorations:Gs,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&_s.valid(n)?new _s(n):null,handleClick:Ks,handleKeyDown:Js,handleDOMEvents:{beforeinput:Us}}})],extendNodeSchema(e){var t;return{allowGapCursor:null!==(t=mo(ao(e,'allowGapCursor',{name:e.name,options:e.options,storage:e.storage})))&&void 0!==t?t:null}}}),Xs=bs.create({name:'hardBreak',addOptions:()=>({keepMarks:!0,HTMLAttributes:{}}),inline:!0,group:'inline',selectable:!1,parseHTML:()=>[{tag:'br'}],renderHTML({HTMLAttributes:e}){return['br',po(this.options.HTMLAttributes,e)]},renderText:()=>'\n',addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command((()=>{const{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:s}=r.extensionManager,a=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command((({tr:e,dispatch:t})=>{if(t&&a&&o){const t=a.filter((e=>s.includes(e.type.name)));e.ensureMarks(t)}return!0})).run()}))])}},addKeyboardShortcuts(){return{'Mod-Enter':()=>this.editor.commands.setHardBreak(),'Shift-Enter':()=>this.editor.commands.setHardBreak()}}}),Zs=bs.create({name:'heading',addOptions:()=>({levels:[1,2,3,4,5,6],HTMLAttributes:{}}),content:'inline*',group:'block',defining:!0,addAttributes:()=>({level:{default:1,rendered:!1}}),parseHTML(){return this.options.levels.map((e=>({tag:`h${e}`,attrs:{level:e}})))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,po(this.options.HTMLAttributes,t),0]},addCommands(){return{setHeading:e=>({commands:t})=>!!this.options.levels.includes(e.level)&&t.setNode(this.name,e),toggleHeading:e=>({commands:t})=>!!this.options.levels.includes(e.level)&&t.toggleNode(this.name,'paragraph',e)}},addKeyboardShortcuts(){return this.options.levels.reduce(((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})})),{})},addInputRules(){return this.options.levels.map((e=>ys({find:new RegExp(`^(#{1,${e}})\\s$`),type:this.type,getAttributes:{level:e}})))}});var Qs=function(){};Qs.prototype.append=function(e){return e.length?(e=Qs.from(e),!this.length&&e||e.length<200&&this.leafAppend(e)||this.length<200&&e.leafPrepend(this)||this.appendInner(e)):this},Qs.prototype.prepend=function(e){return e.length?Qs.from(e).append(this):this},Qs.prototype.appendInner=function(e){return new ta(this,e)},Qs.prototype.slice=function(e,t){return void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t?Qs.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},Qs.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},Qs.prototype.forEach=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},Qs.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var r=[];return this.forEach(((t,n)=>r.push(e(t,n))),t,n),r},Qs.from=function(e){return e instanceof Qs?e:e&&e.length?new ea(e):Qs.empty};var ea=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return 0==e&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(!1===e(this.values[i],r+i))return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(!1===e(this.values[i],r+i))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=200)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=200)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=()=>0,Object.defineProperties(t.prototype,n),t}(Qs);Qs.empty=new ea([]);var ta=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;return!(t<i&&!1===this.left.forEachInner(e,t,Math.min(n,i),r))&&(!(n>i&&!1===this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i))&&void 0)},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;return!(t>i&&!1===this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i))&&(!(n<i&&!1===this.left.forEachInvertedInner(e,Math.min(t,i),n,r))&&void 0)},t.prototype.sliceInner=function(e,t){if(0==e&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(Qs),na=Qs;class ra{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,r,i=this.items.length;for(;;i--){if(this.items.get(i-1).selection){--i;break}}t&&(n=this.remapping(i,this.items.length),r=n.maps.length);let o,s,a=e.tr,l=[],c=[];return this.items.forEach(((e,t)=>{if(!e.step)return n||(n=this.remapping(i,t+1),r=n.maps.length),r--,void c.push(e);if(n){c.push(new ia(e.map));let t,i=e.step.map(n.slice(r));i&&a.maybeStep(i).doc&&(t=a.mapping.maps[a.mapping.maps.length-1],l.push(new ia(t,void 0,void 0,l.length+c.length))),r--,t&&n.appendMap(t,r)}else a.maybeStep(e.step);return e.selection?(o=n?e.selection.map(n.slice(r)):e.selection,s=new ra(this.items.slice(0,i).append(c.reverse().concat(l)),this.eventCount-1),!1):void 0}),this.items.length,0),{remaining:s,transform:a,selection:o}}addTransform(e,t,n,r){let i=[],o=this.eventCount,s=this.items,a=!r&&s.length?s.get(s.length-1):null;for(let n=0;n<e.steps.length;n++){let l,c=e.steps[n].invert(e.docs[n]),d=new ia(e.mapping.maps[n],c,t);(l=a&&a.merge(d))&&(d=l,n?i.pop():s=s.slice(0,s.length-1)),i.push(d),t&&(o++,t=void 0),r||(a=d)}let l=o-n.depth;return l>sa&&(s=function(e,t){let n;return e.forEach(((e,r)=>{if(e.selection&&0==t--)return n=r,!1})),e.slice(n)}(s,l),o-=l),new ra(s.append(i),o)}remapping(e,t){let n=new Me;return this.items.forEach(((t,r)=>{let i=null!=t.mirrorOffset&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)}),e,t),n}addMaps(e){return 0==this.eventCount?this:new ra(this.items.append(e.map((e=>new ia(e)))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],r=Math.max(0,this.items.length-t),i=e.mapping,o=e.steps.length,s=this.eventCount;this.items.forEach((e=>{e.selection&&s--}),r);let a=t;this.items.forEach((t=>{let r=i.getMirror(--a);if(null==r)return;o=Math.min(o,r);let l=i.maps[r];if(t.step){let o=e.steps[r].invert(e.docs[r]),c=t.selection&&t.selection.map(i.slice(a+1,r));c&&s++,n.push(new ia(l,o,c))}else n.push(new ia(l))}),r);let l=[];for(let e=t;e<o;e++)l.push(new ia(i.maps[e]));let c=this.items.slice(0,r).append(l).append(n),d=new ra(c,s);return d.emptyItemCount()>500&&(d=d.compress(this.items.length-n.length)),d}emptyItemCount(){let e=0;return this.items.forEach((t=>{t.step||e++})),e}compress(e=this.items.length){let t=this.remapping(0,e),n=t.maps.length,r=[],i=0;return this.items.forEach(((o,s)=>{if(s>=e)r.push(o),o.selection&&i++;else if(o.step){let e=o.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let a=o.selection&&o.selection.map(t.slice(n));a&&i++;let l,c=new ia(s.invert(),e,a),d=r.length-1;(l=r.length&&r[d].merge(c))?r[d]=l:r.push(c)}}else o.map&&n--}),this.items.length,0),new ra(na.from(r.reverse()),i)}}ra.empty=new ra(na.empty,0);class ia{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new ia(t.getMap().invert(),t,this.selection)}}}class oa{constructor(e,t,n,r){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r}}const sa=20;function aa(e){let t=[];return e.forEach(((e,n,r,i)=>t.push(r,i))),t}function la(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),o=t.map(e[r+1],-1);i<=o&&n.push(i,o)}return n}function ca(e,t,n,r){let i=pa(t),o=ua.get(t).spec.config,s=(r?e.undone:e.done).popEvent(t,i);if(!s)return;let a=s.selection.resolve(s.transform.doc),l=(r?e.done:e.undone).addTransform(s.transform,t.selection.getBookmark(),o,i),c=new oa(r?l:s.remaining,r?s.remaining:l,null,0);n(s.transform.setSelection(a).setMeta(ua,{redo:r,historyState:c}).scrollIntoView())}let da=!1,ha=null;function pa(e){let t=e.plugins;if(ha!=t){da=!1,ha=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){da=!0;break}}return da}const ua=new Ot('history'),fa=new Ot('closeHistory');function ma(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Mt({key:ua,state:{init:()=>new oa(ra.empty,ra.empty,null,0),apply:(t,n,r)=>function(e,t,n,r){let i,o=n.getMeta(ua);if(o)return o.historyState;n.getMeta(fa)&&(e=new oa(e.done,e.undone,null,0));let s=n.getMeta('appendedTransaction');if(0==n.steps.length)return e;if(s&&s.getMeta(ua))return s.getMeta(ua).redo?new oa(e.done.addTransform(n,void 0,r,pa(t)),e.undone,aa(n.mapping.maps[n.steps.length-1]),e.prevTime):new oa(e.done,e.undone.addTransform(n,void 0,r,pa(t)),null,e.prevTime);if(!1===n.getMeta('addToHistory')||s&&!1===s.getMeta('addToHistory'))return(i=n.getMeta('rebased'))?new oa(e.done.rebased(n,i),e.undone.rebased(n,i),la(e.prevRanges,n.mapping),e.prevTime):new oa(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),la(e.prevRanges,n.mapping),e.prevTime);{let i=0==e.prevTime||!s&&(e.prevTime<(n.time||0)-r.newGroupDelay||!((e,t)=>{if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach(((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)})),n})(n,e.prevRanges)),o=s?la(e.prevRanges,n.mapping):aa(n.mapping.maps[n.steps.length-1]);return new oa(e.done.addTransform(n,i?t.selection.getBookmark():void 0,r,pa(t)),ra.empty,o,n.time)}}(n,r,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r='historyUndo'==n?ga:'historyRedo'==n?ya:null;return!!r&&(t.preventDefault(),r(e.state,e.dispatch))}}}})}const ga=(e,t)=>{let n=ua.getState(e);return!(!n||0==n.done.eventCount)&&(t&&ca(n,e,t,!1),!0)},ya=(e,t)=>{let n=ua.getState(e);return!(!n||0==n.undone.eventCount)&&(t&&ca(n,e,t,!0),!0)},wa=Ao.create({name:'history',addOptions:()=>({depth:100,newGroupDelay:500}),addCommands:()=>({undo:()=>({state:e,dispatch:t})=>ga(e,t),redo:()=>({state:e,dispatch:t})=>ya(e,t)}),addProseMirrorPlugins(){return[ma(this.options)]},addKeyboardShortcuts(){return{'Mod-z':()=>this.editor.commands.undo(),'Mod-y':()=>this.editor.commands.redo(),'Shift-Mod-z':()=>this.editor.commands.redo(),'Mod-я':()=>this.editor.commands.undo(),'Shift-Mod-я':()=>this.editor.commands.redo()}}}),va=bs.create({name:'horizontalRule',addOptions:()=>({HTMLAttributes:{}}),group:'block',parseHTML:()=>[{tag:'hr'}],renderHTML({HTMLAttributes:e}){return['hr',po(this.options.HTMLAttributes,e)]},addCommands(){return{setHorizontalRule:()=>({chain:e})=>e().insertContent({type:this.name}).command((({tr:e,dispatch:t})=>{var n;if(t){const{$to:t}=e.selection,r=t.end();if(t.nodeAfter)e.setSelection(ct.create(e.doc,t.pos));else{const i=null===(n=t.parent.type.contentMatch.defaultType)||void 0===n?void 0:n.create();i&&(e.insert(r,i),e.setSelection(ct.create(e.doc,r)))}e.scrollIntoView()}return!0})).run()}},addInputRules(){return[gs({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),ba=/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/,ka=/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/g,xa=/(?:^|\s)((?:_)((?:[^_]+))(?:_))$/,Sa=/(?:^|\s)((?:_)((?:[^_]+))(?:_))/g,Ma=vs.create({name:'italic',addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:'em'},{tag:'i',getAttrs:e=>'normal'!==e.style.fontStyle&&null},{style:'font-style=italic'}],renderHTML({HTMLAttributes:e}){return['em',po(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{'Mod-i':()=>this.editor.commands.toggleItalic(),'Mod-I':()=>this.editor.commands.toggleItalic()}},addInputRules(){return[ms({find:ba,type:this.type}),ms({find:xa,type:this.type})]},addPasteRules(){return[ks({find:ka,type:this.type}),ks({find:Sa,type:this.type})]}}),Ca=bs.create({name:'listItem',addOptions:()=>({HTMLAttributes:{}}),content:'paragraph block*',defining:!0,parseHTML:()=>[{tag:'li'}],renderHTML({HTMLAttributes:e}){return['li',po(this.options.HTMLAttributes,e),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),'Shift-Tab':()=>this.editor.commands.liftListItem(this.name)}}}),Ta=bs.create({name:'listItem',addOptions:()=>({HTMLAttributes:{}}),content:'paragraph block*',defining:!0,parseHTML:()=>[{tag:'li'}],renderHTML({HTMLAttributes:e}){return['li',po(this.options.HTMLAttributes,e),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),'Shift-Tab':()=>this.editor.commands.liftListItem(this.name)}}}),Oa=vs.create({name:'textStyle',addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:'span',getAttrs:e=>!!e.hasAttribute('style')&&{}}],renderHTML({HTMLAttributes:e}){return['span',po(this.options.HTMLAttributes,e),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:e,commands:t})=>{const n=Xo(e,this.type);return!!Object.entries(n).some((([,e])=>!!e))||t.unsetMark(this.name)}}}}),Na=/^(\d+)\.\s$/,Ea=bs.create({name:'orderedList',addOptions:()=>({itemTypeName:'listItem',HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}),group:'block list',content(){return`${this.options.itemTypeName}+`},addAttributes:()=>({start:{default:1,parseHTML:e=>e.hasAttribute('start')?parseInt(e.getAttribute('start')||'',10):1}}),parseHTML:()=>[{tag:'ol'}],renderHTML({HTMLAttributes:e}){const{start:t,...n}=e;return 1===t?['ol',po(this.options.HTMLAttributes,n),0]:['ol',po(this.options.HTMLAttributes,e),0]},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Ta.name,this.editor.getAttributes(Oa.name)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{'Mod-Shift-7':()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=ws({find:Na,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=ws({find:Na,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(Oa.name)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[e]}}),Aa=bs.create({name:'paragraph',priority:1e3,addOptions:()=>({HTMLAttributes:{}}),group:'block',content:'inline*',parseHTML:()=>[{tag:'p'}],renderHTML({HTMLAttributes:e}){return['p',po(this.options.HTMLAttributes,e),0]},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{'Mod-Alt-0':()=>this.editor.commands.setParagraph()}}}),Da=/(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/,Ia=/(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/g,Ra=vs.create({name:'strike',addOptions:()=>({HTMLAttributes:{}}),parseHTML:()=>[{tag:'s'},{tag:'del'},{tag:'strike'},{style:'text-decoration',consuming:!1,getAttrs:e=>!!e.includes('line-through')&&{}}],renderHTML({HTMLAttributes:e}){return['s',po(this.options.HTMLAttributes,e),0]},addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{'Mod-Shift-x':()=>this.editor.commands.toggleStrike()}},addInputRules(){return[ms({find:Da,type:this.type})]},addPasteRules(){return[ks({find:Ia,type:this.type})]}}),Pa=bs.create({name:'text',group:'inline'}),La=Ao.create({name:'starterKit',addExtensions(){var e,t,n,r,i,o,s,a,l,c,d,h,p,u,f,m,g,y;const w=[];return!1!==this.options.blockquote&&w.push(Ss.configure(null===(e=this.options)||void 0===e?void 0:e.blockquote)),!1!==this.options.bold&&w.push(Ns.configure(null===(t=this.options)||void 0===t?void 0:t.bold)),!1!==this.options.bulletList&&w.push(Is.configure(null===(n=this.options)||void 0===n?void 0:n.bulletList)),!1!==this.options.code&&w.push(Ls.configure(null===(r=this.options)||void 0===r?void 0:r.code)),!1!==this.options.codeBlock&&w.push(Bs.configure(null===(i=this.options)||void 0===i?void 0:i.codeBlock)),!1!==this.options.document&&w.push(Vs.configure(null===(o=this.options)||void 0===o?void 0:o.document)),!1!==this.options.dropcursor&&w.push(js.configure(null===(s=this.options)||void 0===s?void 0:s.dropcursor)),!1!==this.options.gapcursor&&w.push(Ys.configure(null===(a=this.options)||void 0===a?void 0:a.gapcursor)),!1!==this.options.hardBreak&&w.push(Xs.configure(null===(l=this.options)||void 0===l?void 0:l.hardBreak)),!1!==this.options.heading&&w.push(Zs.configure(null===(c=this.options)||void 0===c?void 0:c.heading)),!1!==this.options.history&&w.push(wa.configure(null===(d=this.options)||void 0===d?void 0:d.history)),!1!==this.options.horizontalRule&&w.push(va.configure(null===(h=this.options)||void 0===h?void 0:h.horizontalRule)),!1!==this.options.italic&&w.push(Ma.configure(null===(p=this.options)||void 0===p?void 0:p.italic)),!1!==this.options.listItem&&w.push(Ca.configure(null===(u=this.options)||void 0===u?void 0:u.listItem)),!1!==this.options.orderedList&&w.push(Ea.configure(null===(f=this.options)||void 0===f?void 0:f.orderedList)),!1!==this.options.paragraph&&w.push(Aa.configure(null===(m=this.options)||void 0===m?void 0:m.paragraph)),!1!==this.options.strike&&w.push(Ra.configure(null===(g=this.options)||void 0===g?void 0:g.strike)),!1!==this.options.text&&w.push(Pa.configure(null===(y=this.options)||void 0===y?void 0:y.text)),w}}),$a=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,za=bs.create({name:'image',addOptions:()=>({inline:!1,allowBase64:!1,HTMLAttributes:{}}),inline(){return this.options.inline},group(){return this.options.inline?'inline':'block'},draggable:!0,addAttributes:()=>({src:{default:null},alt:{default:null},title:{default:null}}),parseHTML(){return[{tag:this.options.allowBase64?'img[src]':'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:e}){return['img',po(this.options.HTMLAttributes,e)]},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[gs({find:$a,type:this.type,getAttributes:e=>{const[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});var Ba=bs.create({name:'video',group:'block',selectable:!0,draggable:!0,atom:!0,addOptions:()=>({allowFullscreen:!0,allow:'accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;',HTMLAttributes:{class:'video-container'}}),addAttributes(){return{src:{default:null},width:{default:640},height:{default:360},class:{default:null},frameborder:{default:0},allowfullscreen:{default:this.options.allowFullscreen,parseHTML:()=>this.options.allowFullscreen},allow:{default:this.options.allow}}},parseHTML:()=>[{tag:'iframe'}],renderHTML({HTMLAttributes:e}){return['div',this.options.HTMLAttributes,['iframe',e]]},addCommands(){return{setVideo:e=>({tr:t,dispatch:n})=>{const{selection:r}=t;this.editor.isEditable&&(e={...e,class:'pointer-events-none'});const i=this.type.create(e);return n&&t.replaceRangeWith(r.from,r.to,i),!0}}}});customElements.define('str-textarea-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}connectedCallback(){const e=this.innerHTML;this.innerHTML='';const t=new fs({element:this,editable:!1,extensions:[La,za.configure({HTMLAttributes:{class:'editor-image'}}),,Ba],content:e});s(this,(e=>t.commands.setContent(e)))}},{extends:'div'});class Va extends HTMLSpanElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.render(e)))}render(e){this.textContent=e}}customElements.define('str-span-cpnt',Va,{extends:'span'});class Fa extends HTMLParagraphElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(e=>this.render(e)))}render(e){this.textContent=e}}customElements.define('str-p-cpnt',Fa,{extends:'p'}),customElements.define('str-chapters-cpnt',class extends HTMLDivElement{constructor(){super(),this.tabIndex=0}connectedCallback(){s(this,(t=>{this.innerHTML='',t.forEach(((e,t)=>{let n=document.getElementById(e['@strife'].type).content;this.appendChild(n.cloneNode(!0));this.querySelectorAll(`[is^="str-"]:not([data-property-name^="${this.dataset.propertyName}."])`).forEach((n=>{const r=n.dataset.propertyName;n.dataset.propertyName=`${this.dataset.propertyName}.${t}.${r}`,n.render(e[r])}))})),n.send({cmd:e.EU,updates:[{action:r.INIT,context:{name:'chapters',propertyName:this.dataset.propertyName}}]})}))}},{extends:'div'}),document.adoptedStyleSheets=[a];export{r as ACTION,e as CMD,i as default,s as useState};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strifeapp/strife",
|
|
3
|
-
"version": "0.1.0-preview.
|
|
3
|
+
"version": "0.1.0-preview.14",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -10,12 +10,14 @@
|
|
|
10
10
|
"unpkg": "dist/index.esm.js",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"prepublishOnly": "npm --no-git-tag-version version --preid=preview",
|
|
13
|
-
"postversion": "npx rollup -c -i index.js -o dist/index.esm.js"
|
|
13
|
+
"postversion": "npx rollup -c -i index.js -o dist/index.esm.js",
|
|
14
|
+
"start": "npx rollup -c -i index.js -o dist/index.esm.js -w"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
17
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
18
|
+
"acorn-import-assertions": "^1.8.0",
|
|
16
19
|
"rollup": "^2.64.0",
|
|
17
20
|
"rollup-plugin-import-assert": "^2.1.0",
|
|
18
|
-
"rollup-plugin-terser": "^7.0.2"
|
|
19
|
-
"acorn-import-assertions": "^1.8.0"
|
|
21
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
20
22
|
}
|
|
21
23
|
}
|