@progress/kendo-editor-common 1.12.5-develop.4 → 1.12.5-develop.5

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.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.KendoEditorCommon=t():e.KendoEditorCommon=t()}(self,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){this.content=e}e.r(t),e.d(t,{AddMarkStep:()=>xe,AddNodeMarkStep:()=>Ce,AllSelection:()=>pt,AttrStep:()=>Ze,CellSelection:()=>Ha,ContentMatch:()=>$,DOMParser:()=>Y,DOMSerializer:()=>le,Decoration:()=>Nl,DecorationSet:()=>Tl,DocAttrStep:()=>et,EditorState:()=>kt,EditorView:()=>ta,Fragment:()=>s,GapCursor:()=>Pp,InputRule:()=>zd,MapResult:()=>me,Mapping:()=>ye,Mark:()=>d,MarkType:()=>X,Node:()=>D,NodeRange:()=>A,NodeSelection:()=>dt,NodeType:()=>J,Plugin:()=>St,PluginKey:()=>Nt,RemoveMarkStep:()=>Se,RemoveNodeMarkStep:()=>Me,ReplaceAroundStep:()=>Oe,ReplaceError:()=>h,ReplaceStep:()=>Ne,ResolvedPos:()=>C,Schema:()=>U,Selection:()=>rt,SelectionRange:()=>it,Slice:()=>p,Step:()=>ve,StepMap:()=>ge,StepResult:()=>be,TableMap:()=>ka,TextSelection:()=>at,Transaction:()=>gt,Transform:()=>nt,TransformError:()=>tt,__endComposition:()=>ea,__parseFromClipboard:()=>Zl,activeNode:()=>fo,addColSpan:()=>Fa,addColumn:()=>Xa,addColumnAfter:()=>nu,addColumnBefore:()=>tu,addListNodes:()=>Mo,addRow:()=>ec,addRowAfter:()=>Qp,addRowBefore:()=>Yp,alignBlocks:()=>mo,alignCenterRules:()=>qr,alignJustifyRules:()=>jr,alignLeftRules:()=>_r,alignRemoveRules:()=>Jr,alignRightRules:()=>Wr,applyInlineStyle:()=>eo,applyLink:()=>no,autoJoin:()=>yr,baseKeymap:()=>Sr,blockNodes:()=>so,blockquote:()=>Cr,bold:()=>Ud,buildKeymap:()=>oh,buildListKeymap:()=>rh,bulletList:()=>xo,canBeIndented:()=>Dr,canIndentAsListItem:()=>Ar,canInsert:()=>Ut,canJoin:()=>Pe,canOutdentAsListItem:()=>Tr,canSplit:()=>Be,caretColor:()=>np,caretColorKey:()=>tp,cellAround:()=>Ta,chainCommands:()=>wr,changeTextBlock:()=>io,cleanFormatting:()=>yo,cleanMarks:()=>Wn,cleanTextBlockFormatting:()=>ao,closeDoubleQuote:()=>Wd,closeHistory:()=>Sd,closeSingleQuote:()=>jd,colCount:()=>Ba,columnIsHeader:()=>La,columnResizing:()=>zc,columnResizingPluginKey:()=>Ic,convertMsLists:()=>uh,createParagraphNear:()=>nr,createTable:()=>Jp,cspFix:()=>qh,deleteColumn:()=>ou,deleteRow:()=>rc,deleteSelection:()=>Po,deleteTable:()=>gc,domToPmDoc:()=>An,dropCursor:()=>zp,dropPoint:()=>He,ellipsis:()=>Hd,emDash:()=>Ld,exitCode:()=>tr,expandSelection:()=>ln,expandToWordWrap:()=>an,find:()=>Dh,findAll:()=>Eh,findAt:()=>Th,findCell:()=>za,findWrapping:()=>Re,fixTables:()=>Ja,fixTablesKey:()=>qa,flattenNestedSpans:()=>Vn,formatBlockElements:()=>lo,fragmentToHtml:()=>Nn,gapCursor:()=>Lp,getActiveMarks:()=>Xn,getBlockFormats:()=>co,getHtml:()=>Dn,getInlineStyles:()=>Yn,getMark:()=>Kn,getNodeFromSelection:()=>nn,getSelectionText:()=>tn,goToNextCell:()=>mc,hasMark:()=>qn,hasNode:()=>po,hasSameMarkup:()=>Rn,history:()=>Nd,htmlToFragment:()=>Mn,imageResizeKey:()=>Uh,imageResizing:()=>ep,inSameTable:()=>Ia,indent:()=>Er,indentBlocks:()=>Nr,indentHtml:()=>rn,indentRules:()=>zo,inputRules:()=>Pd,insertImage:()=>ro,insertNode:()=>en,insertPoint:()=>Le,insertText:()=>oo,isAligned:()=>go,isHistoryTransaction:()=>Id,isInTable:()=>Da,isIndented:()=>Or,italic:()=>Gd,joinBackward:()=>Fo,joinDown:()=>Yo,joinForward:()=>Ko,joinPoint:()=>Fe,joinTextblockBackward:()=>Lo,joinTextblockForward:()=>Ho,joinUp:()=>Go,keydownHandler:()=>wa,keymap:()=>ya,lift:()=>Qo,liftBlockquote:()=>Mr,liftEmptyBlock:()=>or,liftListItem:()=>Do,liftTarget:()=>Ee,link:()=>th,listItem:()=>So,listMarkersStyles:()=>Ip,listStyle:()=>Pr,macBaseKeymap:()=>xr,marks:()=>td,mergeCells:()=>sc,moveCellForward:()=>$a,newlineInCode:()=>Zo,nextCell:()=>Pa,nodes:()=>ad,openDoubleQuote:()=>_d,openSingleQuote:()=>qd,orderedList:()=>ko,outdent:()=>Rr,outdentRules:()=>Bo,parentBlockFormat:()=>uo,parentNode:()=>Qt,parseContent:()=>Tn,pasteCleanup:()=>vh,pcBaseKeymap:()=>kr,placeholder:()=>Ph,pmAddColumnAfter:()=>Ga,pmAddColumnBefore:()=>Ua,pmAddRowAfter:()=>nc,pmAddRowBefore:()=>tc,pmDeleteColumn:()=>Qa,pmDocToFragment:()=>On,redo:()=>Td,redoDepth:()=>$d,redoNoScroll:()=>Ed,removeAllMarks:()=>_n,removeAttribute:()=>gh,removeColSpan:()=>Va,removeComments:()=>$n,removeLink:()=>to,removeTag:()=>mh,replace:()=>Rh,replaceAll:()=>$h,replaceImageSourcesFromRtf:()=>Ah,replaceStep:()=>_e,rowIsHeader:()=>Za,sanitize:()=>fh,sanitizeClassAttr:()=>yh,sanitizeStyleAttr:()=>wh,selectAll:()=>ar,selectNodeBackward:()=>qo,selectNodeForward:()=>Xo,selectParentNode:()=>lr,selectTextblockEnd:()=>pr,selectTextblockStart:()=>hr,selectedLineTextOnly:()=>on,selectedRect:()=>Ka,selectionCell:()=>Ea,selectionMarks:()=>Jn,setBlockType:()=>fr,setCellAttr:()=>cc,setHtml:()=>En,sinkListItem:()=>Eo,smartQuotes:()=>Jd,spacesFix:()=>Lh,splitBlock:()=>ir,splitBlockAs:()=>rr,splitBlockKeepMarks:()=>sr,splitCell:()=>lc,splitCellWithType:()=>ac,splitListItem:()=>Ao,splitListItemKeepMarks:()=>To,strikethrough:()=>Qd,subscript:()=>Zd,superscript:()=>eh,tableColumnResizeKey:()=>sp,tableEditing:()=>_c,tableEditingKey:()=>Aa,tableNodeTypes:()=>Oa,tableNodes:()=>Na,tableResizeKey:()=>ip,tableResizing:()=>Tp,tableRowResizeKey:()=>lp,textHighlight:()=>Jh,textHighlightKey:()=>jh,textblockTypeInputRule:()=>Xd,toggleHeader:()=>hc,toggleHeaderCell:()=>fc,toggleHeaderColumn:()=>uc,toggleHeaderRow:()=>pc,toggleInlineFormat:()=>Zn,toggleList:()=>Vr,toggleMark:()=>mr,toggleOrderedList:()=>Lr,toggleUnorderedList:()=>Fr,trimWhitespace:()=>vn,underline:()=>Yd,undo:()=>Ad,undoDepth:()=>Rd,undoInputRule:()=>Fd,undoNoScroll:()=>Dd,updateColumnsOnResize:()=>$c,wrapIn:()=>ur,wrapInList:()=>No,wrapRangeInList:()=>Oo,wrappingInputRule:()=>Kd}),n.prototype={constructor:n,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,o){var r=o&&o!=e?this.remove(o):this,i=r.find(e),s=r.content.slice();return-1==i?s.push(o||e,t):(s[i+1]=t,o&&(s[i]=o)),new n(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var o=this.content.slice();return o.splice(t,2),new n(o)},addToStart:function(e,t){return new n([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var o=this.remove(e).content.slice();return o.push(e,t),new n(o)},addBefore:function(e,t,o){var r=this.remove(t),i=r.content.slice(),s=r.find(e);return i.splice(-1==s?i.length:s,0,t,o),new n(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=n.from(e)).size?new n(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=n.from(e)).size?new n(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=n.from(e);for(var o=0;o<e.content.length;o+=2)t=t.remove(e.content[o]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},n.from=function(e){if(e instanceof n)return e;var t=[];if(e)for(var o in e)t.push(o,e[o]);return new n(t)};const o=n;function r(e,t,n){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(o),s=t.child(o);if(i!=s){if(!i.sameMarkup(s))return n;if(i.isText&&i.text!=s.text){for(let e=0;i.text[e]==s.text[e];e++)n++;return n}if(i.content.size||s.content.size){let e=r(i.content,s.content,n+1);if(null!=e)return e}n+=i.nodeSize}else n+=i.nodeSize}}function i(e,t,n,o){for(let r=e.childCount,s=t.childCount;;){if(0==r||0==s)return r==s?null:{a:n,b:o};let l=e.child(--r),a=t.child(--s),c=l.nodeSize;if(l!=a){if(!l.sameMarkup(a))return{a:n,b:o};if(l.isText&&l.text!=a.text){let e=0,t=Math.min(l.text.length,a.text.length);for(;e<t&&l.text[l.text.length-e-1]==a.text[a.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(l.content.size||a.content.size){let e=i(l.content,a.content,n-1,o-1);if(e)return e}n-=c,o-=c}else n-=c,o-=c}}class s{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,o=0,r){for(let i=0,s=0;s<t;i++){let l=this.content[i],a=s+l.nodeSize;if(a>e&&!1!==n(l,o+s,r||null,i)&&l.content.size){let r=s+1;l.nodesBetween(Math.max(0,e-r),Math.min(l.content.size,t-r),n,o+r)}s=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,o){let r="",i=!0;return this.nodesBetween(e,t,(s,l)=>{let a=s.isText?s.text.slice(Math.max(e,l)-l,t-l):s.isLeaf?o?"function"==typeof o?o(s):o:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&a||s.isTextblock)&&n&&(i?i=!1:r+=n),r+=a},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new s(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let r=0,i=0;i<t;r++){let s=this.content[r],l=i+s.nodeSize;l>e&&((i<e||l>t)&&(s=s.isText?s.cut(Math.max(0,e-i),Math.min(s.text.length,t-i)):s.cut(Math.max(0,e-i-1),Math.min(s.content.size,t-i-1))),n.push(s),o+=s.nodeSize),i=l}return new s(n,o)}cutByIndex(e,t){return e==t?s.empty:0==e&&t==this.content.length?this:new s(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new s(o,r)}addToStart(e){return new s([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new s(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 o=this.content[t];e(o,n,t),n+=o.nodeSize}}findDiffStart(e,t=0){return r(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return i(this,e,t,n)}findIndex(e){if(0==e)return a(0,e);if(e==this.size)return a(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let o=n+this.child(t).nodeSize;if(o>=e)return o==e?a(t+1,o):a(t,n);n=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return s.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new s(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return s.empty;let t,n=0;for(let o=0;o<e.length;o++){let r=e[o];n+=r.nodeSize,o&&r.isText&&e[o-1].sameMarkup(r)?(t||(t=e.slice(0,o)),t[t.length-1]=r.withText(t[t.length-1].text+r.text)):t&&t.push(r)}return new s(t||e,n)}static from(e){if(!e)return s.empty;if(e instanceof s)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new s([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}s.empty=new s([],0);const l={index:0,offset:0};function a(e,t){return l.index=e,l.offset=t,l}function c(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(!c(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!c(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class d{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let o=0;o<e.length;o++){let r=e[o];if(this.eq(r))return e;if(this.type.excludes(r.type))t||(t=e.slice(0,o));else{if(r.type.excludes(this.type))return e;!n&&r.type.rank>this.type.rank&&(t||(t=e.slice(0,o)),t.push(this),n=!0),t&&t.push(r)}}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&&c(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`);let o=n.create(t.attrs);return n.checkAttrs(o.attrs),o}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 d.none;if(e instanceof d)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}d.none=[];class h extends Error{}class p{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=f(this.content,e+this.openStart,t);return n&&new p(n,this.openStart,this.openEnd)}removeBetween(e,t){return new p(u(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 p.empty;let n=t.openStart||0,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new p(s.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,o=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)o++;return new p(e,n,o)}}function u(e,t,n){let{index:o,offset:r}=e.findIndex(t),i=e.maybeChild(o),{index:s,offset:l}=e.findIndex(n);if(r==t||i.isText){if(l!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(o!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(o,i.copy(u(i.content,t-r-1,n-r-1)))}function f(e,t,n,o){let{index:r,offset:i}=e.findIndex(t),s=e.maybeChild(r);if(i==t||s.isText)return o&&!o.canReplace(r,r,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=f(s.content,t-i-1,n,s);return l&&e.replaceChild(r,s.copy(l))}function m(e,t,n){if(n.openStart>e.depth)throw new h("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new h("Inconsistent open depths");return g(e,t,n,0)}function g(e,t,n,o){let r=e.index(o),i=e.node(o);if(r==t.index(o)&&o<e.depth-n.openStart){let s=g(e,t,n,o+1);return i.copy(i.content.replaceChild(r,s))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=o||t.depth!=o){let{start:r,end:l}=function(e,t){let n=t.depth-e.openStart,o=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)o=t.node(e).copy(s.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return k(i,x(e,r,l,t,o))}{let o=e.parent,r=o.content;return k(o,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}}return k(i,S(e,t,o))}function y(e,t){if(!t.type.compatibleContent(e.type))throw new h("Cannot join "+t.type.name+" onto "+e.type.name)}function w(e,t,n){let o=e.node(n);return y(o,t.node(n)),o}function v(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 b(e,t,n,o){let r=(t||e).node(n),i=0,s=t?t.index(n):r.childCount;e&&(i=e.index(n),e.depth>n?i++:e.textOffset&&(v(e.nodeAfter,o),i++));for(let e=i;e<s;e++)v(r.child(e),o);t&&t.depth==n&&t.textOffset&&v(t.nodeBefore,o)}function k(e,t){return e.type.checkContent(t),e.copy(t)}function x(e,t,n,o,r){let i=e.depth>r&&w(e,t,r+1),l=o.depth>r&&w(n,o,r+1),a=[];return b(null,e,r,a),i&&l&&t.index(r)==n.index(r)?(y(i,l),v(k(i,x(e,t,n,o,r+1)),a)):(i&&v(k(i,S(e,t,r+1)),a),b(t,n,r,a),l&&v(k(l,S(n,o,r+1)),a)),b(o,null,r,a),new s(a)}function S(e,t,n){let o=[];return b(null,e,n,o),e.depth>n&&v(k(w(e,t,n+1),S(e,t,n+1)),o),b(t,null,n,o),new s(o)}p.empty=new p(s.empty,0,0);class C{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],o=e.child(t);return n?e.child(t).cut(n):o}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],o=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)o+=n.child(t).nodeSize;return o}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return d.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),o=e.maybeChild(t);if(!n){let e=n;n=o,o=e}let r=n.marks;for(var i=0;i<r.length;i++)!1!==r[i].type.spec.inclusive||o&&r[i].isInSet(o.marks)||(r=r[i--].removeFromSet(r));return r}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,o=e.parent.maybeChild(e.index());for(var r=0;r<n.length;r++)!1!==n[r].type.spec.inclusive||o&&n[r].isInSet(o.marks)||(n=n[r--].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 A(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=[],o=0,r=t;for(let t=e;;){let{index:e,offset:i}=t.content.findIndex(r),s=r-i;if(n.push(t,e,o+i),!s)break;if(t=t.child(e),t.isText)break;r=s-1,o+=i+1}return new C(t,n,r)}static resolveCached(e,t){let n=O.get(e);if(n)for(let e=0;e<n.elts.length;e++){let o=n.elts[e];if(o.pos==t)return o}else O.set(e,n=new M);let o=n.elts[n.i]=C.resolve(e,t);return n.i=(n.i+1)%N,o}}class M{constructor(){this.elts=[],this.i=0}}const N=12,O=new WeakMap;class A{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 T=Object.create(null);class D{constructor(e,t,n,o=d.none){this.type=e,this.attrs=t,this.marks=o,this.content=n||s.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,o=0){this.content.nodesBetween(e,t,n,o,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,o){return this.content.textBetween(e,t,n,o)}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&&c(this.attrs,t||e.defaultAttrs||T)&&d.sameSet(this.marks,n||d.none)}copy(e=null){return e==this.content?this:new D(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new D(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 p.empty;let o=this.resolve(e),r=this.resolve(t),i=n?0:o.sharedDepth(t),s=o.start(i),l=o.node(i).content.cut(o.pos-s,r.pos-s);return new p(l,o.depth-i,r.depth-i)}replace(e,t,n){return m(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:o}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(o==e||t.isText)return t;e-=o+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 o=this.content.child(t-1);return{node:o,index:t-1,offset:n-o.nodeSize}}resolve(e){return C.resolveCached(this,e)}resolveNoCache(e){return C.resolve(this,e)}rangeHasMark(e,t,n){let o=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(o=!0),!o)),o}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()+")"),R(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=s.empty,o=0,r=n.childCount){let i=this.contentMatchAt(e).matchFragment(n,o,r),l=i&&i.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let e=o;e<r;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,o){if(o&&!this.type.allowsMarks(o))return!1;let r=this.contentMatchAt(e).matchType(n),i=r&&r.matchFragment(this.content,t);return!!i&&i.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),this.type.checkAttrs(this.attrs);let e=d.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!d.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;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 o=s.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,o,n);return r.type.checkAttrs(r.attrs),r}}D.prototype.text=void 0;class E extends D{constructor(e,t,n,o){if(super(e,t,null,o),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):R(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 E(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new E(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 R(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class ${constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new I(e,t);if(null==n.next)return $.empty;let o=z(n);n.next&&n.err("Unexpected trailing text");let r=function(e){let t=Object.create(null);return function n(o){let r=[];o.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let o;for(let e=0;e<r.length;e++)r[e][0]==t&&(o=r[e][1]);H(e,n).forEach(e=>{o||r.push([t,o=[]]),-1==o.indexOf(e)&&o.push(e)})})});let i=t[o.join(",")]=new $(o.indexOf(e.length-1)>-1);for(let e=0;e<r.length;e++){let o=r[e][1].sort(L);i.next.push({type:r[e][0],next:t[o.join(",")]||n(o)})}return i}(H(e,0))}(function(e){let t=[[]];return r(function e(t,i){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,i)),[]);if("seq"!=t.type){if("star"==t.type){let s=n();return o(i,s),r(e(t.expr,s),s),[o(s)]}if("plus"==t.type){let s=n();return r(e(t.expr,i),s),r(e(t.expr,s),s),[o(s)]}if("opt"==t.type)return[o(i)].concat(e(t.expr,i));if("range"==t.type){let s=i;for(let o=0;o<t.min;o++){let o=n();r(e(t.expr,s),o),s=o}if(-1==t.max)r(e(t.expr,s),s);else for(let i=t.min;i<t.max;i++){let i=n();o(s,i),r(e(t.expr,s),i),s=i}return[o(s)]}if("name"==t.type)return[o(i,void 0,t.value)];throw new Error("Unknown expr type")}for(let o=0;;o++){let s=e(t.exprs[o],i);if(o==t.exprs.length-1)return s;r(s,i=n())}}(e,0),n()),t;function n(){return t.push([])-1}function o(e,n,o){let r={term:o,to:n};return t[e].push(r),r}function r(e,t){e.forEach(e=>e.to=t)}}(o));return function(e,t){for(let n=0,o=[e];n<o.length;n++){let e=o[n],r=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];i.push(n.name),!r||n.isText||n.hasRequiredAttrs()||(r=!1),-1==o.indexOf(s)&&o.push(s)}r&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,n),r}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 o=this;for(let r=t;o&&r<n;r++)o=o.matchType(e.child(r).type);return o}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 o=[this];return function r(i,l){let a=i.matchFragment(e,n);if(a&&(!t||a.validEnd))return s.from(l.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==o.indexOf(n)){o.push(n);let e=r(n,l.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 o=n.shift(),r=o.match;if(r.matchType(e)){let e=[];for(let t=o;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<r.next.length;e++){let{type:i,next:s}=r.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||o.type&&!s.validEnd||(n.push({match:i.contentMatch,type:i,via:o}),t[i.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 o=0;o<n.next.length;o++)-1==e.indexOf(n.next[o].next)&&t(n.next[o].next)}(this),e.map((t,n)=>{let o=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)o+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return o}).join("\n")}}$.empty=new $(!0);class I{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 z(e){let t=[];do{t.push(B(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function B(e){let t=[];do{t.push(P(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function P(e){let t=function(e){if(e.eat("(")){let t=z(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,o=n[t];if(o)return[o];let r=[];for(let e in n){let o=n[e];o.isInGroup(t)&&r.push(o)}return 0==r.length&&e.err("No node type or group '"+t+"' found"),r}(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=F(e,t)}return t}function V(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function F(e,t){let n=V(e),o=n;return e.eat(",")&&(o="}"!=e.next?V(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:o,expr:t}}function L(e,t){return t-e}function H(e,t){let n=[];return function t(o){let r=e[o];if(1==r.length&&!r[0].term)return t(r[0].to);n.push(o);for(let e=0;e<r.length;e++){let{term:o,to:i}=r[e];o||-1!=n.indexOf(i)||t(i)}}(t),n.sort(L)}function _(e){let t=Object.create(null);for(let n in e){let o=e[n];if(!o.hasDefault)return null;t[n]=o.default}return t}function W(e,t){let n=Object.create(null);for(let o in e){let r=t&&t[o];if(void 0===r){let t=e[o];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+o);r=t.default}n[o]=r}return n}function q(e,t,n,o){for(let o in t)if(!(o in e))throw new RangeError(`Unsupported attribute ${o} for ${n} of type ${o}`);for(let n in e){let o=e[n];o.validate&&o.validate(t[n])}}function j(e,t){let n=Object.create(null);if(t)for(let o in t)n[o]=new K(e,o,t[o]);return n}class J{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=j(e,n.attrs),this.defaultAttrs=_(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==$.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:W(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new D(this,this.computeAttrs(e),s.from(t),d.setFrom(n))}createChecked(e=null,t,n){return t=s.from(t),this.checkContent(t),new D(this,this.computeAttrs(e),t,d.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=s.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let o=this.contentMatch.matchFragment(t),r=o&&o.fillBefore(s.empty,!0);return r?new D(this,e,t.append(r),d.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)}`)}checkAttrs(e){q(this.attrs,e,"node",this.name)}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:d.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,o)=>n[e]=new J(e,t,o));let o=t.spec.topNode||"doc";if(!n[o])throw new RangeError("Schema is missing its top node type ('"+o+"')");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 K{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let o=n.split("|");return n=>{let r=null===n?"null":typeof n;if(o.indexOf(r)<0)throw new RangeError(`Expected value of type ${o} for attribute ${t} on type ${e}, got ${r}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class X{constructor(e,t,n,o){this.name=e,this.rank=t,this.schema=n,this.spec=o,this.attrs=j(e,o.attrs),this.excluded=null;let r=_(this.attrs);this.instance=r?new d(this,r):null}create(e=null){return!e&&this.instance?this.instance:new d(this,W(this.attrs,e))}static compile(e,t){let n=Object.create(null),o=0;return e.forEach((e,r)=>n[e]=new X(e,o++,t,r)),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]}checkAttrs(e){q(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class U{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=o.from(e.nodes),t.marks=o.from(e.marks||{}),this.nodes=J.compile(this.spec.nodes,this),this.marks=X.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],o=t.spec.content||"",r=t.spec.marks;if(t.contentMatch=n[o]||(n[o]=$.parse(o,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==r?null:r?G(this,r.split(" ")):""!=r&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:G(this,n.split(" "))}this.nodeFromJSON=e=>D.fromJSON(this,e),this.markFromJSON=e=>d.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,o){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof J))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,o)}text(e,t){let n=this.nodes.text;return new E(n,n.defaultAttrs,e,d.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function G(e,t){let n=[];for(let o=0;o<t.length;o++){let r=t[o],i=e.marks[r],s=i;if(i)n.push(i);else for(let t in e.marks){let o=e.marks[t];("_"==r||o.spec.group&&o.spec.group.split(" ").indexOf(r)>-1)&&n.push(s=o)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[o]+"'")}return n}class Y{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),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 oe(this,t,!1);return n.addAll(e,d.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new oe(this,t,!0);return n.addAll(e,d.none,t.from,t.to),p.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){let n=this.tags[o];if(re(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,o){for(let r=o?this.styles.indexOf(o)+1:0;r<this.styles.length;r++){let o=this.styles[r],i=o.style;if(!(0!=i.indexOf(e)||o.context&&!n.matchesContext(o.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(o.getAttrs){let e=o.getAttrs(t);if(!1===e)continue;o.attrs=e||void 0}return o}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,o=0;for(;o<t.length;o++){let e=t[o];if((null==e.priority?50:e.priority)<n)break}t.splice(o,0,e)}for(let t in e.marks){let o=e.marks[t].spec.parseDOM;o&&o.forEach(e=>{n(e=ie(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let o=e.nodes[t].spec.parseDOM;o&&o.forEach(e=>{n(e=ie(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Y(e,Y.schemaRules(e)))}}const Q={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},Z={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ee={ol:!0,ul:!0};function te(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class ne{constructor(e,t,n,o,r,i){this.type=e,this.attrs=t,this.marks=n,this.solid=o,this.options=i,this.content=[],this.activeMarks=d.none,this.match=r||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(s.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=s.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(s.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Q.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class oe{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let o,r=t.topNode,i=te(null,t.preserveWhitespace,0)|(n?4:0);o=r?new ne(r.type,r.attrs,d.none,!0,t.topMatch||r.type.contentMatch,i):new ne(n?null:e.schema.topNodeType,null,d.none,!0,null,i),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,o=this.top,r=2&o.options?"full":this.localPreserveWS||(1&o.options)>0,{schema:i}=this.parser;if("full"===r||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r)if("full"===r)n=n.replace(/\r\n?/g,"\n");else if(i.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(i.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(i.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(i.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=o.content[o.content.length-1],r=e.previousSibling;(!t||r&&"BR"==r.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(i.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let o=this.localPreserveWS,r=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,s=e.nodeName.toLowerCase();ee.hasOwnProperty(s)&&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&&ee.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(l?l.ignore:Z.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let n,o=this.needsBlock;if(Q.hasOwnProperty(s))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=l&&l.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(r),this.needsBlock=o}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,l,n,!1===l.consuming?i:void 0)}this.localPreserveWS=o}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let o=this.parser.matchedStyles[e],r=n.getPropertyValue(o);if(r)for(let e;;){let n=this.parser.matchStyle(o,r,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1!==n.consuming)break;e=n}}return t}addElementByRule(e,t,n,o){let r,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(r=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,n,o);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let o=e;"string"==typeof t.contentElement?o=e.querySelector(t.contentElement):"function"==typeof t.contentElement?o=t.contentElement(e):t.contentElement&&(o=t.contentElement),this.findAround(e,o,!0),this.addAll(o,n),this.findAround(e,o,!1)}r&&this.sync(s)&&this.open--}addAll(e,t,n,o){let r=n||0;for(let i=n?e.childNodes[n]:e.firstChild,s=null==o?null:e.childNodes[o];i!=s;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i,t);this.findAtPoint(e,r)}findPlace(e,t,n){let o,r;for(let t=this.open,i=0;t>=0;t--){let s=this.nodes[t],l=s.findWrapping(e);if(l&&(!o||o.length>l.length+i)&&(o=l,r=s,!l.length))break;if(s.solid){if(n)break;i+=2}}if(!o)return null;this.sync(r);for(let e=0;e<o.length;e++)t=this.enterInner(o[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let o=this.findPlace(e,t,n);if(o){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=d.none;for(let r of o.concat(e.marks))(t.type?t.type.allowsMarkType(r.type):se(r.type,e.type))&&(n=r.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,o){let r=this.findPlace(e.create(t),n,!1);return r&&(r=this.enterInner(e,t,n,!0,o)),r}enterInner(e,t,n,o=!1,r){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let s=te(e,r,i.options);4&i.options&&0==i.content.length&&(s|=4);let l=d.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):se(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new ne(e,t,l,o,null,s)),this.open++,n}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;this.localPreserveWS&&(this.nodes[t].options|=1)}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 o=0;o<this.find.length;o++)null==this.find[o].pos&&1==e.nodeType&&e.contains(this.find[o].node)&&t.compareDocumentPosition(this.find[o].node)&(n?2:4)&&(this.find[o].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,o=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),r=-(n?n.depth+1:0)+(o?0:1),i=(e,s)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;s>=r;s--)if(i(e-1,s))return!0;return!1}{let e=s>0||0==s&&o?this.nodes[s].type:n&&s>=r?n.node(s-r).type:null;if(!e||e.name!=l&&!e.isInGroup(l))return!1;s--}}return!0};return i(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}}}function re(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ie(e){let t={};for(let n in e)t[n]=e[n];return t}function se(e,t){let n=t.schema.nodes;for(let o in n){let r=n[o];if(!r.allowsMarkType(e))continue;let i=[],s=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:o,next:r}=e.edge(n);if(o==t)return!0;if(i.indexOf(r)<0&&s(r))return!0}};if(s(r.contentMatch))return!0}}class le{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=ce(t).createDocumentFragment());let o=n,r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:o}=he(ce(t),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){let r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){let o=this.marks[e.type.name];return o&&he(ce(n),o(e,t),null,e.attrs)}static renderSpec(e,t,n=null,o){return he(e,t,n,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new le(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ae(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return ae(e.marks)}}function ae(e){let t={};for(let n in e){let o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function ce(e){return e.document||window.document}const de=new WeakMap;function he(e,t,n,o){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];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(o&&(r=function(e){let t=de.get(e);return void 0===t&&de.set(e,t=function(e){let t=null;return function e(n){if(n&&"object"==typeof n)if(Array.isArray(n))if("string"==typeof n[0])t||(t=[]),t.push(n);else for(let t=0;t<n.length;t++)e(n[t]);else for(let t in n)e(n[t])}(e),t}(e)),t}(o))&&r.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?a.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&a.style?a.style.cssText=c[e]:a.setAttribute(e,c[e])}}for(let r=d;r<t.length;r++){let i=t[r];if(0===i){if(r<t.length-1||r>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}{let{dom:t,contentDOM:r}=he(e,i,n,o);if(a.appendChild(t),r){if(s)throw new RangeError("Multiple content holes");s=r}}}return{dom:a,contentDOM:s}}const pe=Math.pow(2,16);function ue(e,t){return e+t*pe}function fe(e){return 65535&e}class me{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 ge{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&ge.empty)return ge.empty}recover(e){let t=0,n=fe(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))/pe}(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 o=0,r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?o:0);if(l>e)break;let a=this.ranges[s+r],c=this.ranges[s+i],d=l+a;if(e<=d){let r=l+o+((a?e==l?-1:e==d?1:t:t)<0?0:c);if(n)return r;let i=e==(t<0?l:d)?null:ue(s/3,e-l),h=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(h|=8),new me(r,h,i)}o+=c-a}return n?e+o:new me(e+o,0,null)}touches(e,t){let n=0,o=fe(t),r=this.inverted?2:1,i=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 l=this.ranges[t+r];if(e<=s+l&&t==3*o)return!0;n+=this.ranges[t+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,r=0;o<this.ranges.length;o+=3){let i=this.ranges[o],s=i-(this.inverted?r:0),l=i+(this.inverted?0:r),a=this.ranges[o+t],c=this.ranges[o+n];e(s,s+a,l,l+c),r+=c-a}}invert(){return new ge(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?ge.empty:new ge(e<0?[0,-e,0]:[0,0,e])}}ge.empty=new ge([]);class ye{constructor(e,t,n=0,o=(e?e.length:0)){this.mirror=t,this.from=n,this.to=o,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new ye(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),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 o=e.getMirror(t);this.appendMap(e._maps[t],null!=o&&o<t?n+o: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 o=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=o&&o>t?n-o-1:void 0)}}invert(){let e=new ye;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 o=0;for(let n=this.from;n<this.to;n++){let r=this._maps[n].mapResult(e,t);if(null!=r.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(r.recover);continue}}o|=r.delInfo,e=r.pos}return n?e:new me(e,o,null)}}const we=Object.create(null);class ve{getMap(){return ge.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=we[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 we)throw new RangeError("Duplicate use of step JSON ID "+e);return we[e]=t,t.prototype.jsonID=e,t}}class be{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new be(e,null)}static fail(e){return new be(null,e)}static fromReplace(e,t,n,o){try{return be.ok(e.replace(t,n,o))}catch(e){if(e instanceof h)return be.fail(e.message);throw e}}}function ke(e,t,n){let o=[];for(let r=0;r<e.childCount;r++){let i=e.child(r);i.content.size&&(i=i.copy(ke(i.content,t,i))),i.isInline&&(i=t(i,n,r)),o.push(i)}return s.fromArray(o)}class xe extends ve{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),o=n.node(n.sharedDepth(this.to)),r=new p(ke(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,o),t.openStart,t.openEnd);return be.fromReplace(e,this.from,this.to,r)}invert(){return new Se(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 xe(t.pos,n.pos,this.mark)}merge(e){return e instanceof xe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new xe(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 xe(t.from,t.to,e.markFromJSON(t.mark))}}ve.jsonID("addMark",xe);class Se extends ve{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 p(ke(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return be.fromReplace(e,this.from,this.to,n)}invert(){return new xe(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 Se(t.pos,n.pos,this.mark)}merge(e){return e instanceof Se&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Se(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 Se(t.from,t.to,e.markFromJSON(t.mark))}}ve.jsonID("removeMark",Se);class Ce extends ve{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return be.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return be.fromReplace(e,this.pos,this.pos+1,new p(s.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 Ce(this.pos,t.marks[n]);return new Ce(this.pos,this.mark)}}return new Me(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ce(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 Ce(t.pos,e.markFromJSON(t.mark))}}ve.jsonID("addNodeMark",Ce);class Me extends ve{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return be.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return be.fromReplace(e,this.pos,this.pos+1,new p(s.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Ce(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Me(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 Me(t.pos,e.markFromJSON(t.mark))}}ve.jsonID("removeNodeMark",Me);class Ne extends ve{constructor(e,t,n,o=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=o}apply(e){return this.structure&&Ae(e,this.from,this.to)?be.fail("Structure replace would overwrite content"):be.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ge([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ne(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 Ne(t.pos,Math.max(t.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Ne)||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?p.empty:new p(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ne(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?p.empty:new p(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ne(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 Ne(t.from,t.to,p.fromJSON(e,t.slice),!!t.structure)}}ve.jsonID("replace",Ne);class Oe extends ve{constructor(e,t,n,o,r,i,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=o,this.slice=r,this.insert=i,this.structure=s}apply(e){if(this.structure&&(Ae(e,this.from,this.gapFrom)||Ae(e,this.gapTo,this.to)))return be.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return be.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?be.fromReplace(e,this.from,this.to,n):be.fail("Content does not fit in gap")}getMap(){return new ge([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 Oe(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),o=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),r=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||o<t.pos||r>n.pos?null:new Oe(t.pos,n.pos,o,r,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 Oe(t.from,t.to,t.gapFrom,t.gapTo,p.fromJSON(e,t.slice),t.insert,!!t.structure)}}function Ae(e,t,n){let o=e.resolve(t),r=n-t,i=o.depth;for(;r>0&&i>0&&o.indexAfter(i)==o.node(i).childCount;)i--,r--;if(r>0){let e=o.node(i).maybeChild(o.indexAfter(i));for(;r>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,r--}}return!1}function Te(e,t,n,o=n.contentMatch,r=!0){let i=e.doc.nodeAt(t),l=[],a=t+1;for(let t=0;t<i.childCount;t++){let c=i.child(t),d=a+c.nodeSize,h=o.matchType(c.type);if(h){o=h;for(let t=0;t<c.marks.length;t++)n.allowsMarkType(c.marks[t].type)||e.step(new Se(a,d,c.marks[t]));if(r&&c.isText&&"pre"!=n.whitespace){let e,t,o=/\r?\n|\r/g;for(;e=o.exec(c.text);)t||(t=new p(s.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),l.push(new Ne(a+e.index,a+e.index+e[0].length,t))}}else l.push(new Ne(a,d,p.empty));a=d}if(!o.validEnd){let t=o.fillBefore(s.empty,!0);e.replace(a,a,new p(t,0,0))}for(let t=l.length-1;t>=0;t--)e.step(l[t])}function De(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Ee(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,o=0,r=0;;--n){let i=e.$from.node(n),s=e.$from.index(n)+o,l=e.$to.indexAfter(n)-r;if(n<e.depth&&i.canReplace(s,l,t))return n;if(0==n||i.type.spec.isolating||!De(i,s,l))break;s&&(o=1),l<i.childCount&&(r=1)}return null}function Re(e,t,n=null,o=e){let r=function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.contentMatchAt(o).findWrapping(t);if(!i)return null;let s=i.length?i[0]:t;return n.canReplaceWith(o,r,s)?i:null}(e,t),i=r&&function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.child(o),s=t.contentMatch.findWrapping(i.type);if(!s)return null;let l=(s.length?s[s.length-1]:t).contentMatch;for(let e=o;l&&e<r;e++)l=l.matchType(n.child(e).type);return l&&l.validEnd?s:null}(o,t);return i?r.map($e).concat({type:t,attrs:n}).concat(i.map($e)):null}function $e(e){return{type:e,attrs:null}}function Ie(e,t,n,o){t.forEach((r,i)=>{if(r.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(r.text);){let r=e.mapping.slice(o).map(n+1+i+s.index);e.replaceWith(r,r+1,t.type.schema.linebreakReplacement.create())}}})}function ze(e,t,n,o){t.forEach((r,i)=>{if(r.type==r.type.schema.linebreakReplacement){let r=e.mapping.slice(o).map(n+1+i);e.replaceWith(r,r+1,t.type.schema.text("\n"))}})}function Be(e,t,n=1,o){let r=e.resolve(t),i=r.depth-n,s=o&&o[o.length-1]||r.parent;if(i<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!s.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let e=r.depth-1,t=n-2;e>i;e--,t--){let n=r.node(e),i=r.index(e);if(n.type.spec.isolating)return!1;let s=n.content.cutByIndex(i,n.childCount),l=o&&o[t+1];l&&(s=s.replaceChild(0,l.type.create(l.attrs)));let a=o&&o[t]||n;if(!n.canReplace(i+1,n.childCount)||!a.type.validContent(s))return!1}let l=r.indexAfter(i),a=o&&o[0];return r.node(i).canReplaceWith(l,l,a?a.type:r.node(i+1).type)}function Pe(e,t){let n=e.resolve(t),o=n.index();return Ve(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(o,o+1)}function Ve(e,t){return!(!e||!t||e.isLeaf||!function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:o}=e.type.schema;for(let r=0;r<t.childCount;r++){let i=t.child(r),s=i.type==o?e.type.schema.nodes.text:i.type;if(n=n.matchType(s),!n)return!1;if(!e.type.allowsMarks(i.marks))return!1}return n.validEnd}(e,t))}function Fe(e,t,n=-1){let o=e.resolve(t);for(let e=o.depth;;e--){let r,i,s=o.index(e);if(e==o.depth?(r=o.nodeBefore,i=o.nodeAfter):n>0?(r=o.node(e+1),s++,i=o.node(e).maybeChild(s)):(r=o.node(e).maybeChild(s-1),i=o.node(e+1)),r&&!r.isTextblock&&Ve(r,i)&&o.node(e).canReplace(s,s+1))return t;if(0==e)break;t=n<0?o.before(e):o.after(e)}}function Le(e,t,n){let o=e.resolve(t);if(o.parent.canReplaceWith(o.index(),o.index(),n))return t;if(0==o.parentOffset)for(let e=o.depth-1;e>=0;e--){let t=o.index(e);if(o.node(e).canReplaceWith(t,t,n))return o.before(e+1);if(t>0)return null}if(o.parentOffset==o.parent.content.size)for(let e=o.depth-1;e>=0;e--){let t=o.indexAfter(e);if(o.node(e).canReplaceWith(t,t,n))return o.after(e+1);if(t<o.node(e).childCount)return null}return null}function He(e,t,n){let o=e.resolve(t);if(!n.content.size)return t;let r=n.content;for(let e=0;e<n.openStart;e++)r=r.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=o.depth;t>=0;t--){let n=t==o.depth?0:o.pos<=(o.start(t+1)+o.end(t+1))/2?-1:1,i=o.index(t)+(n>0?1:0),s=o.node(t),l=!1;if(1==e)l=s.canReplace(i,i,r);else{let e=s.contentMatchAt(i).findWrapping(r.firstChild.type);l=e&&s.canReplaceWith(i,i,e[0])}if(l)return 0==n?o.pos:n<0?o.before(t+1):o.after(t+1)}return null}function _e(e,t,n=t,o=p.empty){if(t==n&&!o.size)return null;let r=e.resolve(t),i=e.resolve(n);return We(r,i,o)?new Ne(t,n,o):new qe(r,i,o).fit()}function We(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}ve.jsonID("replaceAround",Oe);class qe{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=s.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=s.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,o=this.close(e<0?this.$to:n.doc.resolve(e));if(!o)return null;let r=this.placed,i=n.depth,s=o.depth;for(;i&&s&&1==r.childCount;)r=r.firstChild.content,i--,s--;let l=new p(r,i,s);return e>-1?new Oe(n.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||n.pos!=this.$to.pos?new Ne(n.pos,o.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,o=this.unplaced.openEnd;n<e;n++){let r=t.firstChild;if(t.childCount>1&&(o=0),r.type.spec.isolating&&o<=n){e=n;break}t=r.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,o=null;n?(o=Ke(this.unplaced.content,n-1).firstChild,e=o.content):e=this.unplaced.content;let r=e.firstChild;for(let e=this.depth;e>=0;e--){let i,{type:l,match:a}=this.frontier[e],c=null;if(1==t&&(r?a.matchType(r.type)||(c=a.fillBefore(s.from(r),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:n,frontierDepth:e,parent:o,inject:c};if(2==t&&r&&(i=a.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:e,parent:o,wrap:i};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=Ke(e,t);return!(!o.childCount||o.firstChild.isLeaf||(this.unplaced=new p(e,t+1,Math.max(n,o.size+t>=e.size-n?t+1:0)),0))}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=Ke(e,t);if(o.childCount<=1&&t>0){let r=e.size-t<=t+o.size;this.unplaced=new p(je(e,t-1,1),t-1,r?t-1:n)}else this.unplaced=new p(je(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:o,wrap:r}){for(;this.depth>t;)this.closeFrontierNode();if(r)for(let e=0;e<r.length;e++)this.openFrontierNode(r[e]);let i=this.unplaced,l=n?n.content:i.content,a=i.openStart-e,c=0,d=[],{match:h,type:u}=this.frontier[t];if(o){for(let e=0;e<o.childCount;e++)d.push(o.child(e));h=h.matchFragment(o)}let f=l.size+e-(i.content.size-i.openEnd);for(;c<l.childCount;){let e=l.child(c),t=h.matchType(e.type);if(!t)break;c++,(c>1||0==a||e.content.size)&&(h=t,d.push(Xe(e.mark(u.allowedMarks(e.marks)),1==c?a:0,c==l.childCount?f:-1)))}let m=c==l.childCount;m||(f=-1),this.placed=Je(this.placed,t,s.from(d)),this.frontier[t].match=h,m&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=l;e<f;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=m?0==e?p.empty:new p(je(i.content,e-1,1),e-1,f<0?i.openEnd:e-1):new p(je(i.content,e,c),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e,t=this.frontier[this.depth];if(!t.type.isTextblock||!Ue(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,o=this.$to.after(n);for(;n>1&&o==this.$to.end(--n);)++o;return o}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:o}=this.frontier[t],r=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=Ue(e,t,o,n,r);if(i){for(let n=t-1;n>=0;n--){let{match:t,type:o}=this.frontier[n],r=Ue(e,n,o,t,!0);if(!r||r.childCount)continue e}return{depth:t,fit:i,move:r?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=Je(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),o=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,o)}return e}openFrontierNode(e,t=null,n){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=Je(this.placed,this.depth,s.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(s.empty,!0);e.childCount&&(this.placed=Je(this.placed,this.frontier.length,e))}}function je(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(je(e.firstChild.content,t-1,n)))}function Je(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Je(e.lastChild.content,t-1,n)))}function Ke(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 o=e.content;return t>1&&(o=o.replaceChild(0,Xe(o.firstChild,t-1,1==o.childCount?n-1:0))),t>0&&(o=e.type.contentMatch.fillBefore(o).append(o),n<=0&&(o=o.append(e.type.contentMatch.matchFragment(o).fillBefore(s.empty,!0)))),e.copy(o)}function Ue(e,t,n,o,r){let i=e.node(t),s=r?e.indexAfter(t):e.index(t);if(s==i.childCount&&!n.compatibleContent(i.type))return null;let l=o.fillBefore(i.content,!0,s);return l&&!function(e,t,n){for(let o=n;o<t.childCount;o++)if(!e.allowsMarks(t.child(o).marks))return!0;return!1}(n,i.content,s)?l:null}function Ge(e){return e.spec.defining||e.spec.definingForContent}function Ye(e,t,n,o,r){if(t<n){let r=e.firstChild;e=e.replaceChild(0,r.copy(Ye(r.content,t+1,n,o,r)))}if(t>o){let t=r.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(s.empty,!0))}return e}function Qe(e,t){let n=[];for(let o=Math.min(e.depth,t.depth);o>=0;o--){let r=e.start(o);if(r<e.pos-(e.depth-o)||t.end(o)>t.pos+(t.depth-o)||e.node(o).type.spec.isolating||t.node(o).type.spec.isolating)break;(r==t.start(o)||o==e.depth&&o==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&o&&t.start(o-1)==r-1)&&n.push(o)}return n}class Ze extends ve{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 be.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 o=t.type.create(n,null,t.marks);return be.fromReplace(e,this.pos,this.pos+1,new p(s.from(o),0,t.isLeaf?0:1))}getMap(){return ge.empty}invert(e){return new Ze(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 Ze(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 Ze(t.pos,t.attr,t.value)}}ve.jsonID("attr",Ze);class et extends ve{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return be.ok(n)}getMap(){return ge.empty}invert(e){return new et(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new et(t.attr,t.value)}}ve.jsonID("docAttr",et);let tt=class extends Error{};tt=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},tt.prototype=Object.create(Error.prototype),tt.prototype.constructor=tt,tt.prototype.name="TransformError";class nt{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ye}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new tt(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=p.empty){let o=_e(this.doc,e,t,n);return o&&this.step(o),this}replaceWith(e,t,n){return this.replace(e,t,new p(s.from(n),0,0))}delete(e,t){return this.replace(e,t,p.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,o){if(!o.size)return e.deleteRange(t,n);let r=e.doc.resolve(t),i=e.doc.resolve(n);if(We(r,i,o))return e.step(new Ne(t,n,o));let s=Qe(r,i);0==s[s.length-1]&&s.pop();let l=-(r.depth+1);s.unshift(l);for(let e=r.depth,t=r.pos-1;e>0;e--,t--){let n=r.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;s.indexOf(e)>-1?l=e:r.before(e)==t&&s.splice(1,0,-e)}let a=s.indexOf(l),c=[],d=o.openStart;for(let e=o.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==o.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){let t=c[e],n=Ge(t.type);if(n&&!t.sameMarkup(r.node(Math.abs(l)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=o.openStart;t>=0;t--){let l=(t+d+1)%(o.openStart+1),h=c[l];if(h)for(let t=0;t<s.length;t++){let c=s[(t+a)%s.length],d=!0;c<0&&(d=!1,c=-c);let u=r.node(c-1),f=r.index(c-1);if(u.canReplaceWith(f,f,h.type,h.marks))return e.replace(r.before(c),d?i.after(c):n,new p(Ye(o.content,0,o.openStart,l),l,o.openEnd))}}let h=e.steps.length;for(let l=s.length-1;l>=0&&(e.replace(t,n,o),!(e.steps.length>h));l--){let e=s[l];e<0||(t=r.before(e),n=i.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,o){if(!o.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let r=Le(e.doc,t,o.type);null!=r&&(t=n=r)}e.replaceRange(t,n,new p(s.from(o),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let o=e.doc.resolve(t),r=e.doc.resolve(n),i=Qe(o,r);for(let t=0;t<i.length;t++){let n=i[t],s=t==i.length-1;if(s&&0==n||o.node(n).type.contentMatch.validEnd)return e.delete(o.start(n),r.end(n));if(n>0&&(s||o.node(n-1).canReplace(o.index(n-1),r.indexAfter(n-1))))return e.delete(o.before(n),r.after(n))}for(let i=1;i<=o.depth&&i<=r.depth;i++)if(t-o.start(i)==o.depth-i&&n>o.end(i)&&r.end(i)-n!=r.depth-i&&o.start(i-1)==r.start(i-1)&&o.node(i-1).canReplace(o.index(i-1),r.index(i-1)))return e.delete(o.before(i),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:o,$to:r,depth:i}=t,l=o.before(i+1),a=r.after(i+1),c=l,d=a,h=s.empty,u=0;for(let e=i,t=!1;e>n;e--)t||o.index(e)>0?(t=!0,h=s.from(o.node(e).copy(h)),u++):c--;let f=s.empty,m=0;for(let e=i,t=!1;e>n;e--)t||r.after(e+1)<r.end(e)?(t=!0,f=s.from(r.node(e).copy(f)),m++):d++;e.step(new Oe(c,d,l,a,new p(h.append(f),u,m),h.size-u,!0))}(this,e,t),this}join(e,t=1){return function(e,t,n){let o=null,{linebreakReplacement:r}=e.doc.type.schema,i=e.doc.resolve(t-n),s=i.node().type;if(r&&s.inlineContent){let e="pre"==s.whitespace,t=!!s.contentMatch.matchType(r);e&&!t?o=!1:!e&&t&&(o=!0)}let l=e.steps.length;if(!1===o){let o=e.doc.resolve(t+n);ze(e,o.node(),o.before(),l)}s.inlineContent&&Te(e,t+n-1,s,i.node().contentMatchAt(i.index()),null==o);let a=e.mapping.slice(l),c=a.map(t-n);if(e.step(new Ne(c,a.map(t+n,-1),p.empty,!0)),!0===o){let t=e.doc.resolve(c);Ie(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return function(e,t,n){let o=s.empty;for(let e=n.length-1;e>=0;e--){if(o.size){let t=n[e].type.contentMatch.matchFragment(o);if(!t||!t.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=s.from(n[e].type.create(n[e].attrs,o))}let r=t.start,i=t.end;e.step(new Oe(r,i,r,i,new p(o,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,o=null){return function(e,t,n,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let l="function"==typeof r?r(t):r;if(t.isTextblock&&!t.hasMarkup(o,l)&&function(e,t,n){let o=e.resolve(t),r=o.index();return o.parent.canReplaceWith(r,r+1,n)}(e.doc,e.mapping.slice(i).map(n),o)){let r=null;if(o.schema.linebreakReplacement){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(o.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&ze(e,t,n,i),Te(e,e.mapping.slice(i).map(n,1),o,void 0,null===r);let a=e.mapping.slice(i),c=a.map(n,1),d=a.map(n+t.nodeSize,1);return e.step(new Oe(c,d,c+1,d-1,new p(s.from(o.create(l,null,t.marks)),0,0),1,!0)),!0===r&&Ie(e,t,n,i),!1}})}(this,e,t,n,o),this}setNodeMarkup(e,t,n=null,o){return function(e,t,n,o,r){let i=e.doc.nodeAt(t);if(!i)throw new RangeError("No node at given position");n||(n=i.type);let l=n.create(o,null,r||i.marks);if(i.isLeaf)return e.replaceWith(t,t+i.nodeSize,l);if(!n.validContent(i.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Oe(t,t+i.nodeSize,t+1,t+i.nodeSize-1,new p(s.from(l),0,0),1,!0))}(this,e,t,n,o),this}setNodeAttribute(e,t,n){return this.step(new Ze(e,t,n)),this}setDocAttribute(e,t){return this.step(new et(e,t)),this}addNodeMark(e,t){return this.step(new Ce(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof d)t.isInSet(n.marks)&&this.step(new Me(e,t));else{let o,r=n.marks,i=[];for(;o=t.isInSet(r);)i.push(new Me(e,o)),r=o.removeFromSet(r);for(let e=i.length-1;e>=0;e--)this.step(i[e])}return this}split(e,t=1,n){return function(e,t,n=1,o){let r=e.doc.resolve(t),i=s.empty,l=s.empty;for(let e=r.depth,t=r.depth-n,a=n-1;e>t;e--,a--){i=s.from(r.node(e).copy(i));let t=o&&o[a];l=s.from(t?t.type.create(t.attrs,l):r.node(e).copy(l))}e.step(new Ne(t,t,new p(i.append(l),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,o){let r,i,s=[],l=[];e.doc.nodesBetween(t,n,(e,a,c)=>{if(!e.isInline)return;let d=e.marks;if(!o.isInSet(d)&&c.type.allowsMarkType(o.type)){let c=Math.max(a,t),h=Math.min(a+e.nodeSize,n),p=o.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(r&&r.to==c&&r.mark.eq(d[e])?r.to=h:s.push(r=new Se(c,h,d[e])));i&&i.to==c?i.to=h:l.push(i=new xe(c,h,o))}}),s.forEach(t=>e.step(t)),l.forEach(t=>e.step(t))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,o){let r=[],i=0;e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;i++;let l=null;if(o instanceof X){let t,n=e.marks;for(;t=o.isInSet(n);)(l||(l=[])).push(t),n=t.removeFromSet(n)}else o?o.isInSet(e.marks)&&(l=[o]):l=e.marks;if(l&&l.length){let o=Math.min(s+e.nodeSize,n);for(let e=0;e<l.length;e++){let n,a=l[e];for(let e=0;e<r.length;e++){let t=r[e];t.step==i-1&&a.eq(r[e].style)&&(n=t)}n?(n.to=o,n.step=i):r.push({style:a,from:Math.max(s,t),to:o,step:i})}}}),r.forEach(t=>e.step(new Se(t.from,t.to,t.style)))}(this,e,t,n),this}clearIncompatible(e,t,n){return Te(this,e,t,n),this}}const ot=Object.create(null);class rt{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new it(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=p.empty){let n=t.content.lastChild,o=null;for(let e=0;e<t.openEnd;e++)o=n,n=n.lastChild;let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:l,$to:a}=i[s],c=e.mapping.slice(r);e.replaceRange(c.map(l.pos),c.map(a.pos),s?p.empty:t),0==s&&mt(e,r,(n?n.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){let{$from:i,$to:s}=o[r],l=e.mapping.slice(n),a=l.map(i.pos),c=l.map(s.pos);r?e.deleteRange(a,c):(e.replaceRangeWith(a,c,t),mt(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let o=e.parent.inlineContent?new at(e):ft(e.node(0),e.parent,e.pos,e.index(),t,n);if(o)return o;for(let o=e.depth-1;o>=0;o--){let r=t<0?ft(e.node(0),e.node(o),e.before(o+1),e.index(o),t,n):ft(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,n);if(r)return r}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new pt(e.node(0))}static atStart(e){return ft(e,e,0,0,1)||new pt(e)}static atEnd(e){return ft(e,e,e.content.size,e.childCount,-1)||new pt(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=ot[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 ot)throw new RangeError("Duplicate use of selection JSON ID "+e);return ot[e]=t,t.prototype.jsonID=e,t}getBookmark(){return at.between(this.$anchor,this.$head).getBookmark()}}rt.prototype.visible=!0;class it{constructor(e,t){this.$from=e,this.$to=t}}let st=!1;function lt(e){st||e.parent.inlineContent||(st=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class at extends rt{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 rt.near(n);let o=e.resolve(t.map(this.anchor));return new at(o.parent.inlineContent?o:n,n)}replace(e,t=p.empty){if(super.replace(e,t),t==p.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof at&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ct(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 at(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let o=e.resolve(t);return new this(o,n==t?o:e.resolve(n))}static between(e,t,n){let o=e.pos-t.pos;if(n&&!o||(n=o>=0?1:-1),!t.parent.inlineContent){let e=rt.findFrom(t,n,!0)||rt.findFrom(t,-n,!0);if(!e)return rt.near(t,n);t=e.$head}return e.parent.inlineContent||(0==o||(e=(rt.findFrom(e,-n,!0)||rt.findFrom(e,n,!0)).$anchor).pos<t.pos!=o<0)&&(e=t),new at(e,t)}}rt.jsonID("text",at);class ct{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ct(e.map(this.anchor),e.map(this.head))}resolve(e){return at.between(e.resolve(this.anchor),e.resolve(this.head))}}class dt extends rt{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:o}=t.mapResult(this.anchor),r=e.resolve(o);return n?rt.near(r):new dt(r)}content(){return new p(s.from(this.node),0,0)}eq(e){return e instanceof dt&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ht(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new dt(e.resolve(t.anchor))}static create(e,t){return new dt(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}dt.prototype.visible=!1,rt.jsonID("node",dt);class ht{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new ct(n,n):new ht(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&dt.isSelectable(n)?new dt(t):rt.near(t)}}class pt extends rt{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=p.empty){if(t==p.empty){e.delete(0,e.doc.content.size);let t=rt.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new pt(e)}map(e){return new pt(e)}eq(e){return e instanceof pt}getBookmark(){return ut}}rt.jsonID("all",pt);const ut={map(){return this},resolve:e=>new pt(e)};function ft(e,t,n,o,r,i=!1){if(t.inlineContent)return at.create(e,n);for(let s=o-(r>0?0:1);r>0?s<t.childCount:s>=0;s+=r){let o=t.child(s);if(o.isAtom){if(!i&&dt.isSelectable(o))return dt.create(e,n-(r<0?o.nodeSize:0))}else{let t=ft(e,o,n+r,r<0?o.childCount:0,r,i);if(t)return t}n+=o.nodeSize*r}return null}function mt(e,t,n){let o=e.steps.length-1;if(o<t)return;let r,i=e.steps[o];(i instanceof Ne||i instanceof Oe)&&(e.mapping.maps[o].forEach((e,t,n,o)=>{null==r&&(r=o)}),e.setSelection(rt.near(e.doc.resolve(r),n)))}class gt extends nt{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&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return d.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(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)||d.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let o=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(o.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let r=this.storedMarks;if(!r){let e=this.doc.resolve(t);r=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,o.text(e,r)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(rt.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 yt(e,t){return t&&e?e.bind(t):e}class wt{constructor(e,t,n){this.name=e,this.init=yt(t.init,n),this.apply=yt(t.apply,n)}}const vt=[new wt("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new wt("selection",{init:(e,t)=>e.selection||rt.atStart(t.doc),apply:e=>e.selection}),new wt("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,o)=>o.selection.$cursor?e.storedMarks:null}),new wt("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class bt{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=vt.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 wt(e.key,e.spec.state,e))})}}class kt{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),o=null;for(;;){let r=!1;for(let i=0;i<this.config.plugins.length;i++){let s=this.config.plugins[i];if(s.spec.appendTransaction){let l=o?o[i].n:0,a=o?o[i].state:this,c=l<t.length&&s.spec.appendTransaction.call(s,l?t.slice(l):t,a,n);if(c&&n.filterTransaction(c,i)){if(c.setMeta("appendedTransaction",e),!o){o=[];for(let e=0;e<this.config.plugins.length;e++)o.push(e<i?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),r=!0}o&&(o[i]={state:n,n:t.length})}}if(!r)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new kt(this.config),n=this.config.fields;for(let o=0;o<n.length;o++){let r=n[o];t[r.name]=r.apply(e,this[r.name],this,t)}return t}get tr(){return new gt(this)}static create(e){let t=new bt(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new kt(t);for(let o=0;o<t.fields.length;o++)n[t.fields[o].name]=t.fields[o].init(e,n);return n}reconfigure(e){let t=new bt(this.schema,e.plugins),n=t.fields,o=new kt(t);for(let t=0;t<n.length;t++){let r=n[t].name;o[r]=this.hasOwnProperty(r)?this[r]:n[t].init(e,o)}return o}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 o=e[n],r=o.spec.state;r&&r.toJSON&&(t[n]=r.toJSON.call(o,this[o.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 o=new bt(e.schema,e.plugins),r=new kt(o);return o.fields.forEach(o=>{if("doc"==o.name)r.doc=D.fromJSON(e.schema,t.doc);else if("selection"==o.name)r.selection=rt.fromJSON(r.doc,t.selection);else if("storedMarks"==o.name)t.storedMarks&&(r.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let i in n){let s=n[i],l=s.spec.state;if(s.key==o.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(t,i))return void(r[o.name]=l.fromJSON.call(s,e,t[i],r))}r[o.name]=o.init(e,r)}}),r}}function xt(e,t,n){for(let o in e){let r=e[o];r instanceof Function?r=r.bind(t):"handleDOMEvents"==o&&(r=xt(r,t,{})),n[o]=r}return n}class St{constructor(e){this.spec=e,this.props={},e.props&&xt(e.props,this,this.props),this.key=e.key?e.key.key:Mt("plugin")}getState(e){return e[this.key]}}const Ct=Object.create(null);function Mt(e){return e in Ct?e+"$"+ ++Ct[e]:(Ct[e]=0,e+"$")}class Nt{constructor(e="key"){this.key=Mt(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Ot="k-parent-node",At="k-colgroup-data",Tt="k-resizable-node",Dt="k-editor-resize-handle",Et="data-dir-table-resize",Rt="data-dir-image-resize";var $t=function(){return"undefined"!=typeof window},It={wp:/(Windows Phone(?: OS)?)\s(\d+)\.(\d+(\.\d+)?)/,fire:/(Silk)\/(\d+)\.(\d+(\.\d+)?)/,android:/(Android|Android.*(?:Opera|Firefox).*?\/)\s*(\d+)(\.(\d+(\.\d+)?))?/,iphone:/(iPhone|iPod).*OS\s+(\d+)[\._]([\d\._]+)/,ipad:/(iPad).*OS\s+(\d+)[\._]([\d_]+)/,meego:/(MeeGo).+NokiaBrowser\/(\d+)\.([\d\._]+)/,webos:/(webOS)\/(\d+)\.(\d+(\.\d+)?)/,blackberry:/(BlackBerry|BB10).*?Version\/(\d+)\.(\d+(\.\d+)?)/,playbook:/(PlayBook).*?Tablet\s*OS\s*(\d+)\.(\d+(\.\d+)?)/,windows:/(MSIE)\s+(\d+)\.(\d+(\.\d+)?)/,tizen:/(tizen).*?Version\/(\d+)\.(\d+(\.\d+)?)/i,sailfish:/(sailfish).*rv:(\d+)\.(\d+(\.\d+)?).*firefox/i,ffos:/(Mobile).*rv:(\d+)\.(\d+(\.\d+)?).*Firefox/},zt={ios:/^i(phone|pad|pod)$/i,android:/^android|fire$/i,blackberry:/^blackberry|playbook/i,windows:/windows/,wp:/wp/,flat:/sailfish|ffos|tizen/i,meego:/meego/},Bt={edge:/(edge)[ \/]([\w.]+)/i,webkit:/(chrome)[ \/]([\w.]+)/i,safari:/(webkit)[ \/]([\w.]+)/i,opera:/(opera)(?:.*version|)[ \/]([\w.]+)/i,msie:/(msie\s|trident.*? rv:)([\w.]+)/i,mozilla:/(mozilla)(?:.*? rv:([\w.]+)|)/i},Pt={omini:/Opera\sMini/i,omobile:/Opera\sMobi/i,firefox:/Firefox|Fennec/i,mobilesafari:/version\/.*safari/i,ie:/MSIE|Windows\sPhone/i,chrome:/chrome|crios/i,webkit:/webkit/i},Vt=function(e,t,n){for(var o in t)if(t.hasOwnProperty(o)&&t[o].test(e))return o;return void 0!==n?n:e},Ft=$t()&&window.navigator?window.navigator.userAgent:null,Lt=Ft?function(e){var t=null,n=[];for(var o in Bt)if(Bt.hasOwnProperty(o)&&(n=e.match(Bt[o]))){(t={})[o]=!0,t[n[1].toLowerCase().split(" ")[0].split("/")[0]]=!0,t.version=parseInt(document.documentMode||n[2],10);break}return t}(Ft):null,Ht=(Ft&&function(e){var t,n=[];for(var o in It)if(It.hasOwnProperty(o)){if(!(n=e.match(It[o])))continue;if("windows"===o&&"plugins"in window.navigator)return null;var r={};return r.device=o,r.browser=Vt(e,Pt,"default"),r.name=Vt(o,zt),r[r.name]=!0,r.majorVersion=n[2],r.minorVersion=n[3]?n[3].replace("_","."):".0",t=r.minorVersion.replace(".","").substr(0,2),r.flatVersion=r.majorVersion+t+new Array(3-(t.length<3?t.length:2)).join("0"),r.cordova=void 0!==typeof window.PhoneGap||void 0!==typeof window.cordova,r.appMode=window.navigator.standalone||/file|local|wmapp/.test(window.location.protocol)||r.cordova,r}}(Ft),$t()&&window,Lt&&!Lt.chrome&&window.MSPointerEvent,Lt&&!Lt.chrome&&window.PointerEvent,{});Ht[void 0]=function(e){return e};var _t=/\/\*[\s\S]*?\*\//g,Wt=/([^\s:;]+?)\s*:\s*((?:(?:url\(\s*(?:(?:[^"')\\]|\\.)*|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')\s*\)|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^;"'])*?)\s*)(?=;|$)/gi,qt=/&quot;|&#34;|&#x22;/gi,jt=/&apos;|&#39;|&#x27;/gi;const Jt=(e,t)=>{const n=t.style,o=t.value,r=t.newValue;if(!e)return{changed:!1,style:null};const i=cn(e),s=Object.keys(i),l=[];for(let e=0;e<s.length;e++){const t=s[e];t.toLowerCase()===n&&o.test(i[t])||l.push(`${t}: ${i[t]}`)}return r&&l.push(`${n}: ${r}`),{style:l.join("; ")+(l.length?";":""),changed:Boolean(r)||l.length!==s.length}},Kt=/^.+$/;function Xt(e,t,n){let o;if(new RegExp("[^-]?"+t+":").test(e.style||"")){const{style:r}=Jt(e.style||"",{style:t,value:Kt,newValue:n});o={...e,style:r}}else o=e.style?{...e,style:e.style.replace(/;$/,"")+"; "+t+": "+n+";"}:{...e,style:t+": "+n+";"};return o}const Ut=(e,t)=>{const n=e.selection.$from;for(let e=n.depth;e>=0;e--){const o=n.index(e);if(n.node(e).canReplaceWith(o,o,t))return!0}return!1},Gt=e=>e instanceof D?e.type.name:e.name,Yt=(e,t=1)=>n=>((e,t=1)=>n=>{const{$from:o}=n;for(let n=o.depth;n>0;n--){const r=o.node(n);if(e(r)&&0==(t-=1))return{depth:n,node:r}}})(t=>Gt(t)===Gt(e),t)(n);function Qt(e,t){for(let n=e.depth;n>0;n--){const o=e.node(n);if(t(o))return{node:o,depth:n}}return null}const Zt=e=>{const t={};for(const n in e)n&&(e[n]||0===e[n])&&(t[n]=e[n]);return t},en=(e,t)=>(n,o)=>{const{selection:r,tr:i}=n;r instanceof dt&&r.node.type.name===e.type.name&&e.isLeaf&&!e.isText&&1===e.nodeSize?(i.setNodeMarkup(r.from,null,{...Zt(r.node.attrs),...Zt(e.attrs)}),i.setSelection(dt.create(i.doc,r.from))):i.replaceSelectionWith(e),t&&i.scrollIntoView(),o(i)},tn=e=>{const t=e.selection;if(t instanceof at||t instanceof pt){const e=t.content().content;return e.textBetween(0,e.size)}return""},nn=e=>{if(e.selection instanceof dt)return e.selection.node},on=e=>{let t="",n=!1;const{selection:o,doc:r}=e,{$from:i,$to:s,from:l,to:a}=o;return i.sameParent(s)&&(r.nodesBetween(l,a,e=>{n=n||e.isLeaf&&!e.isText}),n||(t=tn(e))),t},rn=e=>e.replace(/<\/(p|li|ul|ol|h[1-6]|table|tr|td|th)>/gi,"</$1>\n").replace(/<(ul|ol)([^>]*)><li/gi,"<$1$2>\n<li").replace(/<br \/>/gi,"<br />\n").replace(/\n$/,""),sn={before:/[^ !,?.[\]{}()]+$/i,after:/^[^ !,?.[\]{}()]+/i},ln=(e,t,n)=>{if(!n.applyToWord||!e.selection.empty)return{state:e,dispatch:t};const o=!0===n.applyToWord?sn:n.applyToWord;let r=null;const i=e.tr,s=e.selection,l=s.$head.nodeBefore,a=s.$head.nodeAfter;if(l&&"text"===l.type.name&&l.text&&a&&"text"===a.type.name&&a.text){const n=[];s.$head.parent.descendants((e,t)=>(n.push({node:e,pos:t}),!1));let l=s.$head.parentOffset;const a=n.findIndex(({node:e,pos:t})=>t<=l&&t+e.nodeSize>=l);let c=n[a].node.text,d=!1;for(let e=a-1;e>=0;e--){const t=n[e];!d&&t&&"text"===t.node.type.name?c=t.node.text+c:(d=!0,l-=t.node.nodeSize)}for(let e=a+1;e<n.length;e++){const t=n[e];if(!t||"text"!==t.node.type.name)break;c+=t.node.text}const h=c.substring(0,l),p=c.substring(l),u=o.before.exec(h),f=o.after.exec(p);if(u&&f){const n=u[0].length,o=f[0].length,l=r=s.from;return i.setSelection(at.create(e.doc,l-n,l+o)),{state:{tr:i,selection:i.selection,doc:i.doc,storedMarks:null,schema:i.doc.type.schema},dispatch:e=>{e.setSelection(at.create(e.doc,r)),t(e)}}}}return{state:e,dispatch:t}},an=(e,t)=>(n,o)=>{const{state:r,dispatch:i}=ln(n,o,t);return e(t)(r,i)},cn=e=>function(e){for(var t,n,o={},r=(e||"").replace(_t,"").replace(qt,'"').replace(jt,"'"),i=Wt.exec(r);null!==i;)t=i[1].trim(),n=i[2].trim(),o[t]=n,i=Wt.exec(r);return o}(e),dn=(e,t,n)=>{const o=cn(e);o[t]=n;const r=Object.keys(o).map(e=>o[e]?`${e}: ${o[e]}`:null).filter(Boolean).join("; ");return r?r+";":null},hn=(e,t)=>{const n=cn(t);for(const t in n)t&&void 0!==e.style[t]&&(e.style[t]=n[t])},pn=(e,t,n)=>{const o=e.getAttribute(t);void 0!==n&&n!==o?"style"===t?(e.removeAttribute(t),hn(e,n)):e.setAttribute(t,n):void 0===n&&e.removeAttribute(t)};class un{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 o,r=t[0],i=r.indexOf(" ");i>0&&(n=r.slice(0,i),r=r.slice(i+1));const s=n?e.createElementNS(n,r):e.createElement(r),l=t[1];let a=1;if(l&&"object"==typeof l&&null==l.nodeType&&!Array.isArray(l)){a=2;for(const e in l)null!=l[e]&&(i=e.indexOf(" "),i>0?s.setAttributeNS(e.slice(0,i),e.slice(i+1),l[e]):pn(s,e,l[e]))}for(let r=a;r<t.length;r++){const i=t[r];if(0===i){if(r<t.length-1||r>a)throw new RangeError("Content hole must be the only child of its parent node");return{dom:s,contentDOM:s}}{const{dom:t,contentDOM:r}=un.renderSpec(e,i,n);if(s.appendChild(t),r){if(o)throw new RangeError("Multiple content holes");o=r}}}return{dom:s,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new un(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){const t=fn(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return fn(e.marks)}constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=mn(t).createDocumentFragment());let o=n;const r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){const t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){const n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){const r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){const o=this.marks[e.type.name];return o&&un.renderSpec(mn(n),o(e,t))}serializeNodeInner(e,t){const{dom:n,contentDOM:o}=un.renderSpec(mn(t),this.nodes[e.type.name](e));if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}}function fn(e){const t={};for(const n in e)if(e[n]){const o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function mn(e){return e.document||window.document}const gn=["div","ol","ul","li","table","tbody","thead","tfoot","caption","td","th","p","tr","col","colgroup","article","main","nav","header","footer","aside","section"],yn=(e,t)=>{const n=(e.ownerDocument||document).createElement(t);Array.from(e.rows).filter(e=>e.getAttribute(Ot)===t).forEach(e=>{e.removeAttribute(Ot),n.appendChild(e)}),n.children.length&&e.appendChild(n)},wn=(e,t)=>{const n=t.toUpperCase();e.filter(e=>e.nodeName===n).forEach(e=>{Array.from(e.children).forEach(n=>{n.setAttribute(Ot,t),e.parentNode&&e.parentNode.insertBefore(n,e)}),e.remove()})},vn=(e,t=gn)=>{const n=t.join("|");return e.replace(new RegExp("\\s*(<(?:"+n+")(?:\\s[^>]*?)?>)","g"),"$1").replace(new RegExp("(<\\/(?:"+n+")(?:\\s[^>]*?)?>)\\s*","g"),"$1")},bn="data-style",kn=" "+bn+"=",xn=/<[^>]+>/gm,Sn=/\sstyle=/gm,Cn=e=>e.replace(Sn,kn),Mn=e=>{const t=document.createElement("template");var n;return t.innerHTML=(e=>e.replace(xn,Cn))(e),n=t.content,Array.from(n.querySelectorAll("["+bn+"]")).forEach(e=>{const t=e.getAttribute(bn);e.removeAttribute(bn),hn(e,t)}),t.content.cloneNode(!0)},Nn=e=>Array.from(e.childNodes).reduce((e,t)=>e+(t.outerHTML||t.textContent||""),""),On=e=>{const t=un.fromSchema(e.type.schema).serializeFragment(e.content);return(e=>{Array.from(e.querySelectorAll("table")).forEach(e=>{yn(e,"thead"),yn(e,"tbody"),yn(e,"tfoot");const t=Array.from(e.children).find(e=>0===e.children.length);t&&t.remove();const n=e.parentNode instanceof HTMLDivElement?e.parentNode:null;if(n&&n.matches("div[table]")){e.style.marginLeft=n.style.marginLeft,e.style.marginRight=n.style.marginRight;const t=Array.from(n.children).find(e=>e.matches("div[caption]"));if(t&&"<img>"!==t.innerHTML){const n=e.createCaption();for(t.id&&(n.id=t.id),t.className&&(n.className=t.className),Array.from(t.style).forEach(e=>{n.style[e]=t.style[e]});t.firstChild;)n.appendChild(t.firstChild)}n.style.width&&!e.style.width&&(e.style.width=n.style.width),n.parentNode.insertBefore(e,n),n.parentNode.removeChild(n)}})})(t),t},An=(e,t,n)=>Y.fromSchema(t).parse(e,n),Tn=(e,t,n)=>{const o=Mn(e);var r;return r=o,Array.from(r.querySelectorAll("table")).forEach(e=>{const t=Array.from(e.children);t.some(e=>"THEAD"===e.nodeName||"TFOOT"===e.nodeName)&&(wn(t,"thead"),wn(t,"tbody"),wn(t,"tfoot"));const n=t.find(e=>"COLGROUP"===e.nodeName);if(n&&(e.setAttribute(At,n.outerHTML),n.remove()),e.caption||e.style.marginLeft||e.style.marginRight){const t=document.createElement("div");if(t.setAttribute("table",""),t.style.display="table",t.style.marginLeft=e.style.marginLeft,t.style.marginRight=e.style.marginRight,e.caption){const n=document.createElement("div");for(n.setAttribute("caption",""),e.caption.id&&(n.id=e.caption.id),e.caption.className&&(n.className=e.caption.className),Array.from(e.caption.style).forEach(t=>{n.style[t]=e.caption.style[t]});e.caption.firstChild;)n.appendChild(e.caption.firstChild);e.removeChild(e.caption),t.appendChild(n)}e.parentNode.insertBefore(t,e),t.appendChild(e),/%/.test(e.style.width)&&(t.style.width=e.style.width,e.style.width="")}}),An(o,t,n)},Dn=e=>{const t=On(e.doc);return Nn(t)},En=(e,t="setHTML",n={preserveWhitespace:"full"})=>(o,r)=>r(o.tr.setSelection(new pt(o.doc)).replaceSelectionWith(Tn(e,o.schema,n)).setMeta("commandName",t)),Rn=(e,t,n,o)=>{const r=s.from(Tn(e,n,o)),i=s.from(Tn(t,n,o));return r.eq(i)},$n=e=>{const t=Mn(e);return In(t),Nn(t)},In=e=>{var t;const n=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_COMMENT);let o=n.nextNode();for(;o;)null===(t=o.parentNode)||void 0===t||t.removeChild(o),o=n.nextNode()};class zn{constructor(e){this.extractBefore=e=>this._traverseSide({edge:e,next:function(e){return e.previousSibling},insert:function(e,t){e.insertBefore(t,e.firstChild)}}),this.extractAfter=e=>this._traverseSide({edge:e,next:function(e){return e.nextSibling},insert:function(e,t){e.appendChild(t)}}),this._traverseSide=e=>{const t=this.top,n=t.ownerDocument.createDocumentFragment();let o=e.edge;do{const r=o.parentNode;for(o=e.next(o);o;){const t=e.next(o);e.insert(n,o),o=t}if(t===r||t.contains(r)){const t=r.cloneNode(!1);t.innerHTML="",t.appendChild(n),e.insert(n,t)}o=r}while(o&&o!==t);return n},this.top=e}}const Bn=e=>e.querySelector("span span"),Pn=e=>1===e.childNodes.length&&"SPAN"===e.firstChild.nodeName&&0===e.firstChild.childNodes.length,Vn=e=>{const t=Mn(e);let n=Bn(t);for(;n;){const e=n.parentNode.closest("span");if(e){const t=new zn(e),o=t.extractAfter(n),r=t.extractBefore(n);for(let t=0;t<n.style.length;t++){const o=n.style.item(t);e.style[o]=n.style.getPropertyValue(o)}n.removeAttribute("style"),n.classList.length&&Array.from(n.classList).forEach(t=>{e.classList.contains(t)||e.classList.add(t)}),n.removeAttribute("class");for(let t=0;t<n.attributes.length;t++){const o=n.attributes.item(t);o&&null!==o.nodeValue&&e.setAttribute(o.nodeName,o.nodeValue)}for(;n.firstChild&&n.parentNode;)n.parentNode.insertBefore(n.firstChild,n);n.parentNode&&n.parentNode.removeChild(n),e.parentNode&&(Pn(r)||e.parentNode.insertBefore(r,e),Pn(o)||e.parentNode.insertBefore(o,e.nextSibling))}n=Bn(t)}return Nn(t)},Fn=(e,t,n)=>{const o=o=>{const r=t[o],i=r.$from,s=r.$to;let l=0===i.depth&&e.type.allowsMarkType(n);if(e.nodesBetween(i.pos,s.pos,e=>{if(l)return!1;l=e.inlineContent&&e.type.allowsMarkType(n)}),l)return{v:!0}};for(let e=0;e<t.length;e++){const t=o(e);if(t)return t.v}return!1},Ln=(e,t,n)=>(o,r)=>{const{empty:i,$cursor:s,ranges:l}=o.selection;if(i&&!s||!Fn(o.doc,l,e))return!1;if(r)if(s)e.isInSet(o.storedMarks||s.marks())?r(n.removeStoredMark(e)):r(n.addStoredMark(e.create(t)));else{let i=!1;for(let t=0;!i&&t<l.length;t++){const{$from:n,$to:r}=l[t];i=o.doc.rangeHasMark(n.pos,r.pos,e)}for(let o=0;o<l.length;o++){const{$from:r,$to:s}=l[o];i?n.removeMark(r.pos,s.pos,e):n.addMark(r.pos,s.pos,e.create(t))}r(n.scrollIntoView())}return!0},Hn=(e,t,n,o)=>{void 0===o&&(o=null);const r=[];let i=0;return e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;i++;let l=null;if(o instanceof X){const t=o.isInSet(e.marks);t&&(l=[t])}else o?o.isInSet(e.marks)&&(l=[o]):l=e.marks;if(l&&l.length){const o=Math.min(s+e.nodeSize,n);for(let e=0;e<l.length;e++){const n=l[e];let a;for(let e=0;e<r.length;e++){const t=r[e];t.step===i-1&&n.eq(t.style)&&(a=t)}a?(a.to=o,a.step=i):r.push({style:n,from:Math.max(s,t),to:o,step:i})}}}),r.forEach(t=>e.step(new Se(t.from,t.to,t.style))),e},_n=({except:e=[]}={})=>(t,n)=>{const o=t.tr;var r;Wn(o,{except:(r=e,r instanceof Array?r:[r])}),o.docChanged&&n(o)},Wn=(e,{except:t})=>{const{doc:n,selection:o}=e,r=n.type.schema,{empty:i,ranges:s}=o,l=(t||[]).map(e=>e.name);if(!i){const t=Object.keys(r.marks).map(e=>r.marks[e]).filter(e=>-1===l.indexOf(e.name));s.forEach(({$from:n,$to:o})=>{t.forEach(t=>e.removeMark(n.pos,o.pos,t))})}},qn=(e,t)=>{const n=e.schema.marks,o=(t.altMarks||[]).filter(e=>n[e]),r=t.altStyle,{from:i,$from:s,to:l,empty:a}=e.selection,c=n[t.mark],d=e.doc;let h,p=!1;return a?(h=e.storedMarks||s.marks(),p=c&&c.isInSet(h)||o.some(e=>n[e].isInSet(h))):p=c&&d.rangeHasMark(i,l,c)||o.some(e=>d.rangeHasMark(i,l,n[e])),!p&&r&&n.style?Jn(e,n.style).some(e=>null!==jn(e,r)):Boolean(p)},jn=(e,t)=>{const n=e&&e.attrs.style||"",o=cn(n),r=Object.keys(o);for(let e=0;e<r.length;e++){const n=r[e];if(n.toLowerCase()===t.name&&t.value.test(o[n]))return o[n]}return null},Jn=(e,t)=>{const{from:n,$from:o,to:r,empty:i}=e.selection,s=[];return i?s.push(t.isInSet(e.storedMarks||o.marks())):e.doc.nodesBetween(n,r,e=>{e.isInline&&s.push(t.isInSet(e.marks))}),s},Kn=(e,t)=>{const n=Jn(e,t),o=n.filter(e=>Boolean(e));return n.length===o.length?n[0]:void 0},Xn=(e,t)=>{const n=Jn(e,t),o=n.filter(e=>Boolean(e));return{hasNodesWithoutMarks:n.length!==o.length,marks:o}},Un=(e,t)=>{const n=e.find(e=>"style"===e.type.name),o=n&&n.attrs.style;return Jt(o,t)},Gn=(e,t,n,o,r)=>{const i=r.create({style:o.style}),s=[],l=[];let a=null,c=null;return e.doc.nodesBetween(t,n,(e,d,h)=>{if(!e.isInline)return;const p=e.marks;if(!i.isInSet(p)&&h.type.allowsMarkType(i.type)){const i=Math.max(d,t),h=Math.min(d+e.nodeSize,n),u=Un(p,o);if(u.changed||o.newValue){const e=u.changed?{style:u.style||null}:{style:`${o.style}: ${o.newValue};`},t=r.isInSet(p)?p.find(e=>"style"===e.type.name):null,n=t?{...t.attrs,...e}:e,d=r.create(n),f=d.addToSet(p);for(let e=0;e<p.length;e++)p[e].isInSet(f)||(a&&a.to===i&&a.mark.eq(p[e])?a.to=h:(a=new Se(i,h,p[e]),s.push(a)));const m=c&&c.to===i,g=m&&d.attrs.style===c.mark.attrs.style;m&&g?c.to=h:Object.keys(n).some(e=>null!==n[e])&&(c=new xe(i,h,d),l.push(c))}}}),s.forEach(t=>e.step(t)),l.forEach(t=>e.step(t)),s.length+l.length>0},Yn=(e,t)=>{const n=e.schema.marks.style;return(n?Jn(e,n):[]).map(e=>jn(e,t)).filter(e=>null!==e)},Qn=(e,t)=>function(n,o,r){const{empty:i,ranges:s}=n.selection,l=n.selection instanceof at&&n.selection.$cursor;if(i&&!l||!Fn(n.doc,s,e))return!1;let a=!1;if(o){const i=r||n.tr;if(l){const r=n.storedMarks||l.marks();if(e.isInSet(r)){const n=Un(r,t),s=r.find(e=>"style"===e.type.name),l={...s?s.attrs:{},style:n.style||null};if(((e,t)=>{const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every(n=>e[n]===t[n])})(s.attrs,l))return!1;o(i.removeStoredMark(e)),Object.keys(l).some(e=>null!==l[e])&&o(i.addStoredMark(e.create(l))),a=!0}}else{for(let n=0;n<s.length;n++){const{$from:o,$to:r}=s[n];a=Gn(i,o.pos,r.pos,t,e)||a}a&&(i.scrollIntoView(),o(i))}}return a},Zn=(e,t,n)=>(o,r)=>{const i=o.schema.marks,{altStyle:s,altMarks:l=[],mark:a}=e,c=t||o.tr;let d=!1,h=!1;const p=()=>h=!0;s&&i.style&&(d=Qn(i.style,{style:s.name,value:s.value})(o,p,c));const u=[a,...l].filter(e=>i[e]).map(e=>qn(o,{mark:e})&&i[e]).filter(e=>e);return u.length?((e,t,n,o)=>{const{$cursor:r,ranges:i}=t.selection;if(o=o||t.tr,r)e.forEach(e=>{e.isInSet(t.storedMarks||r.marks())&&n(o.removeStoredMark(e))});else{for(let t=0;t<i.length;t++){const{$from:n,$to:r}=i[t];e.forEach(e=>{Hn(o,n.pos,r.pos,e)})}n(o.scrollIntoView())}})(u,o,p,c):d||Ln(i[a],n,c)(o,p),h&&r(c),h},eo=(e,t)=>(n,o)=>{const r=n.schema.marks.style,i={style:e.style,value:/^.+$/,newValue:e.value},s=n.tr;t&&s.setMeta("commandName",t),s.setMeta("args",e);const{empty:l,$cursor:a,ranges:c}=n.selection;if(l&&!a||!r||!Fn(n.doc,c,r))return!1;if(a){const e=n.storedMarks||a.marks(),t=r.isInSet(e)?e.find(e=>"style"===e.type.name):null,l={style:null};if(t&&t.attrs.style){const e=Jt(t.attrs.style,i);e.changed&&e.style&&(l.style=e.style)}else i.newValue&&(l.style=`${i.style}: ${i.newValue};`);const c=t?{...t.attrs,...l}:l;return Object.keys(c).some(e=>null!==c[e])?o(s.addStoredMark(r.create(c))):o(s.removeStoredMark(r)),!0}return Qn(r,i)(n,o,s)},to=(e,t)=>(n,o)=>{const{$cursor:r}=n.selection;if(r){const i=r.parent,s=r.index(),l=n.schema.marks[e.mark],a=i.child(s).marks.find(e=>e.type===l),c=i.childCount;let d,h,p=r.pos-r.textOffset,u=i.child(s).nodeSize;for(d=s-1;d>=0&&a.isInSet(i.child(d).marks);)h=i.child(d).nodeSize,u+=h,p-=h,d-=1;for(d=s+1;d<c&&a.isInSet(i.child(d).marks);)u+=i.child(d).nodeSize,d+=1;o(Hn(t||n.tr,p,p+u,a))}else Zn(e,t)(n,o)},no=({mark:e,attrs:t},n="link")=>(o,r)=>{const i=o.schema.marks,s=o.tr;n&&(s.setMeta("commandName",n),s.setMeta("args",t));let l=!1;const a=()=>l=!0;if(((e,t)=>{const n=Jn(e,t);return 1===n.length&&n[0]?n[0]:null})(o,i[e]))((e,t)=>(n,o)=>{const{$cursor:r,from:i,to:s}=n.selection,l=n.schema.marks[e.mark];if(r){const n=r.parent,i=r.index(),s=n.child(i).marks.find(e=>e.type===l),a=n.childCount;let c,d,h=r.pos-r.textOffset,p=n.child(i).nodeSize;for(c=i-1;c>=0&&s.isInSet(n.child(c).marks);)d=n.child(c).nodeSize,p+=d,h-=d,c-=1;for(c=i+1;c<a&&s.isInSet(n.child(c).marks);)p+=n.child(c).nodeSize,c+=1;t.removeMark(h,h+p,l),t.addMark(h,h+p,l.create(e.attrs)),o(t)}else t.doc.nodesBetween(i,s,(n,r)=>{n.isInline&&l.isInSet(n.marks)&&(t.removeMark(r,r+n.nodeSize,l),t.addMark(r,r+n.nodeSize,l.create(e.attrs)),o(t))})})({mark:e,attrs:t},s)(o,a);else{let n=o;qn(o,{mark:e})&&(to({mark:e,attrs:t},s)(o,a),n=kt.create({doc:s.doc,selection:s.selection})),l?Ln(i[e],t,s)(n,a):Zn({mark:e},s,t)(n,a)}return l&&r(s),l},oo=e=>(t,n)=>{n(t.tr.insertText(e.text,e.from,e.to))},ro=e=>(t,n)=>{const{image:o}=t.schema.nodes,r=o.createAndFill(e);en(r)(t,t=>n(t.setMeta("commandName","insertImage").setMeta("args",e)))},io=(e,t,n,o)=>{if(!n.isTextblock)return!1;const{ranges:r}=e.selection;r.forEach(r=>{const i=e.steps.length,l=r.$from.pos,a=r.$to.pos;e.doc.nodesBetween(l,a,(r,l)=>{if(r.eq(t)&&r.isTextblock&&!r.hasMarkup(n,o)&&((e,t,n)=>{const o=e.resolve(t),r=o.index();return o.parent.canReplaceWith(r,r+1,n)})(e.doc,e.mapping.slice(i).map(l),n)){e.clearIncompatible(e.mapping.slice(i).map(l,1),n);const t=e.mapping.slice(i),a=t.map(l,1),c=t.map(l+r.nodeSize,1),d=new p(s.from(n.create(o,null,r.marks)),0,0);return e.step(new Oe(a,c,a+1,c-1,d,1,!0)),!1}})})},so=(e,t={blocksInSelection:!1})=>{const{doc:n,selection:o}=e,{$from:r,ranges:i}=o,{blocksInSelection:s}=t,l=[],a=o instanceof dt?o.node:void 0;return a?a.isBlock?(l.push(a),a.nodesBetween(0,a.content.size,e=>{e.isBlock&&l.push(e)})):!s&&r.parent&&r.parent.isBlock&&l.push(r.parent):i.forEach(e=>{const t=e.$from.pos,o=e.$to.pos;n.nodesBetween(t,o,(e,n)=>{e.isBlock&&(!s||n>=t&&n+e.content.size+2<=o)&&l.push(e)})}),l},lo=(e,t)=>(n,o)=>{const r=so(n),i=n.schema.nodes,s=n.tr;s.setMeta("commandName",t),s.setMeta("args",{value:e}),r.forEach(t=>{if(t.type.isTextblock)if("p"===e)io(s,t,i.paragraph,t.attrs);else if(/^h[1-6]$/i.test(e)){const n=parseInt(e.substr(1),10);io(s,t,i.heading,{...t.attrs,level:n})}else"blockquote"===e&&io(s,t,i.blockquote,t.attrs)});const l=s.docChanged;return l&&o(s.scrollIntoView()),l},ao=(e,t={blocksInSelection:!0})=>{const{doc:n,selection:o}=e,{blocksInSelection:r,blockNodeType:i}=t;so({doc:n,selection:o},{blocksInSelection:r}).filter(e=>e.isTextblock).forEach(t=>{const{style:n="",class:o="",...r}=t.attrs||{},s=i||t.type;(n||o||s!==t.type)&&io(e,t,s,r)})},co=e=>{const t=so(e),n=e.schema.nodes,o=[];return t.forEach(e=>{e.type===n.paragraph?o.push("p"):e.type===n.heading?o.push(`h${e.attrs.level}`):e.type===n.blockquote&&n.blockquote.isTextblock&&o.push("blockquote")}),o},ho=(e,t)=>{let n,o,r=e.attrs.style;return r&&t.forEach(e=>{o={style:e.name,value:/^.+$/,newValue:e.value},n=Jt(r,o),r=n.changed?n.style:r}),r=r||t.reduce((e,t)=>(e&&t.value?e+" ":"")+t.value?`${t.name}: ${t.value};`:"",""),Object.assign({},e.attrs,{style:r||null})},po=(e,t)=>{const{from:n,to:o}=e.selection;let r=!1;return e.doc.nodesBetween(n,o,e=>(r=r||e.type===t,!r)),r},uo=e=>{const t=co(e);return 1===new Set(t).size?t[0]:null},fo=e=>({tag:uo(e)||""}),mo=(e,t)=>(n,o)=>{const r=so(n),i=n.tr;i.setMeta("commandName",t),r.forEach(t=>{if(t.type.isTextblock){const n=e.find(e=>e.node===t.type.name);if(n){const e=ho(t,n.style);io(i,t,t.type,e)}}});const s=i.docChanged;return s&&o(i.scrollIntoView()),s},go=(e,t)=>{const n=so(e);let o=!1;return n.forEach(e=>{if(!o&&e.type.isTextblock&&e.attrs.style){const n=t.find(t=>t.node===e.type.name);n&&(o=n.style.every(t=>!!t.value&&new RegExp(`${t.name}:\\s?${t.value}`,"i").test(e.attrs.style)))}}),o},yo=(e={blocksInSelection:!0})=>(t,n)=>{const o=t.tr,{blocksInSelection:r,blockNodeType:i,exceptMarks:s}=e,l=(s||[t.schema.marks.link]).filter(Boolean);Wn(o,{except:l}),ao(o,{blocksInSelection:r,blockNodeType:i});const a=o.docChanged;return a&&n&&n(o),a},wo=["ol",0],vo=["ul",0],bo=["li",0],ko={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs:e=>({order:e.hasAttribute("start")?+e.getAttribute("start"):1})}],toDOM:e=>1==e.attrs.order?wo:["ol",{start:e.attrs.order},0]},xo={parseDOM:[{tag:"ul"}],toDOM:()=>vo},So={parseDOM:[{tag:"li"}],toDOM:()=>bo,defining:!0};function Co(e,t){let n={};for(let t in e)n[t]=e[t];for(let e in t)n[e]=t[e];return n}function Mo(e,t,n){return e.append({ordered_list:Co(ko,{content:"list_item+",group:n}),bullet_list:Co(xo,{content:"list_item+",group:n}),list_item:Co(So,{content:t})})}function No(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i);if(!s)return!1;let l=o?n.tr:null;return!!Oo(l,s,e,t)&&(o&&o(l.scrollIntoView()),!0)}}function Oo(e,t,n,o=null){let r=!1,i=t,l=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=l.resolve(t.start-2);i=new A(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new A(t.$from,l.resolve(t.$to.end(t.depth)),t.depth)),r=!0}let a=Re(i,n,o,t);return!!a&&(e&&function(e,t,n,o,r){let i=s.empty;for(let e=n.length-1;e>=0;e--)i=s.from(n[e].type.create(n[e].attrs,i));e.step(new Oe(t.start-(o?2:0),t.end,t.start,t.end,new p(i,0,0),n.length,!0));let l=0;for(let e=0;e<n.length;e++)n[e].type==r&&(l=e+1);let a=n.length-l,c=t.start+n.length-(o?2:0),d=t.parent;for(let n=t.startIndex,o=t.endIndex,r=!0;n<o;n++,r=!1)!r&&Be(e.doc,c,a)&&(e.split(c,a),c+=2*a),c+=d.child(n).nodeSize}(e,t,a,r,n),!0)}function Ao(e,t){return function(n,o){let{$from:r,$to:i,node:l}=n.selection;if(l&&l.isBlock||r.depth<2||!r.sameParent(i))return!1;let a=r.node(-1);if(a.type!=e)return!1;if(0==r.parent.content.size&&r.node(-1).childCount==r.indexAfter(-1)){if(3==r.depth||r.node(-3).type!=e||r.index(-2)!=r.node(-2).childCount-1)return!1;if(o){let t=s.empty,i=r.index(-1)?1:r.index(-2)?2:3;for(let e=r.depth-i;e>=r.depth-3;e--)t=s.from(r.node(e).copy(t));let l=r.indexAfter(-1)<r.node(-2).childCount?1:r.indexAfter(-2)<r.node(-3).childCount?2:3;t=t.append(s.from(e.createAndFill()));let a=r.before(r.depth-(i-1)),c=n.tr.replace(a,r.after(-l),new p(t,4-i,0)),d=-1;c.doc.nodesBetween(a,c.doc.content.size,(e,t)=>{if(d>-1)return!1;e.isTextblock&&0==e.content.size&&(d=t+1)}),d>-1&&c.setSelection(rt.near(c.doc.resolve(d))),o(c.scrollIntoView())}return!0}let c=i.pos==r.end()?a.contentMatchAt(0).defaultType:null,d=n.tr.delete(r.pos,i.pos),h=c?[t?{type:e,attrs:t}:null,{type:c}]:void 0;return!!Be(d.doc,r.pos,2,h)&&(o&&o(d.split(r.pos,2,h).scrollIntoView()),!0)}}function To(e,t){let n=Ao(e,t);return(e,t)=>n(e,t&&(n=>{let o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();o&&n.ensureMarks(o),t(n)}))}function Do(e){return function(t,n){let{$from:o,$to:r}=t.selection,i=o.blockRange(r,t=>t.childCount>0&&t.firstChild.type==e);return!!i&&(!n||(o.node(i.depth-1).type==e?function(e,t,n,o){let r=e.tr,i=o.end,l=o.$to.end(o.depth);i<l&&(r.step(new Oe(i-1,l,i,l,new p(s.from(n.create(null,o.parent.copy())),1,0),1,!0)),o=new A(r.doc.resolve(o.$from.pos),r.doc.resolve(l),o.depth));const a=Ee(o);if(null==a)return!1;r.lift(o,a);let c=r.doc.resolve(r.mapping.map(i,-1)-1);return Pe(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),t(r.scrollIntoView()),!0}(t,n,e,i):function(e,t,n){let o=e.tr,r=n.parent;for(let e=n.end,t=n.endIndex-1,i=n.startIndex;t>i;t--)e-=r.child(t).nodeSize,o.delete(e-1,e+1);let i=o.doc.resolve(n.start),l=i.nodeAfter;if(o.mapping.map(n.end)!=n.start+i.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,c=n.endIndex==r.childCount,d=i.node(-1),h=i.index(-1);if(!d.canReplace(h+(a?0:1),h+1,l.content.append(c?s.empty:s.from(r))))return!1;let u=i.pos,f=u+l.nodeSize;return o.step(new Oe(u-(a?1:0),f+(c?1:0),u+1,f-1,new p((a?s.empty:s.from(r.copy(s.empty))).append(c?s.empty:s.from(r.copy(s.empty))),a?0:1,c?0:1),a?0:1)),t(o.scrollIntoView()),!0}(t,n,i)))}}function Eo(e){return function(t,n){let{$from:o,$to:r}=t.selection,i=o.blockRange(r,t=>t.childCount>0&&t.firstChild.type==e);if(!i)return!1;let l=i.startIndex;if(0==l)return!1;let a=i.parent,c=a.child(l-1);if(c.type!=e)return!1;if(n){let o=c.lastChild&&c.lastChild.type==a.type,r=s.from(o?e.create():null),l=new p(s.from(e.create(null,s.from(a.type.create(null,r)))),o?3:1,0),d=i.start,h=i.end;n(t.tr.step(new Oe(d-(o?3:1),h,d,h,l,1,!0)).scrollIntoView())}return!0}}const Ro={orderedList:"ordered_list",bulletList:"bullet_list",listItem:"list_item"},$o={listType:Ro.orderedList,types:{...Ro}},Io={listType:Ro.bulletList,types:{...Ro}},zo={nodes:[{node:"paragraph",style:"margin-left",rtlStyle:"margin-right",step:30,unit:"px"},{node:"heading",style:"margin-left",rtlStyle:"margin-right",step:30,unit:"px"}],listsTypes:{...Ro}},Bo={nodes:[{node:"paragraph",style:"margin-left",rtlStyle:"margin-right",step:-30,unit:"px"},{node:"heading",style:"margin-left",rtlStyle:"margin-right",step:-30,unit:"px"}],listsTypes:{...Ro}},Po=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Vo(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("backward",e):n.parentOffset>0)?null:n}const Fo=(e,t,n)=>{let o=Vo(e,n);if(!o)return!1;let r=jo(o);if(!r){let n=o.blockRange(),r=n&&Ee(n);return null!=r&&(t&&t(e.tr.lift(n,r).scrollIntoView()),!0)}let i=r.nodeBefore;if(cr(e,r,t,-1))return!0;if(0==o.parent.content.size&&(Wo(i,"end")||dt.isSelectable(i)))for(let n=o.depth;;n--){let s=_e(e.doc,o.before(n),o.after(n),p.empty);if(s&&s.slice.size<s.to-s.from){if(t){let n=e.tr.step(s);n.setSelection(Wo(i,"end")?rt.findFrom(n.doc.resolve(n.mapping.map(r.pos,-1)),-1):dt.create(n.doc,r.pos-i.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||o.node(n-1).childCount>1)break}return!(!i.isAtom||r.depth!=o.depth-1||(t&&t(e.tr.delete(r.pos-i.nodeSize,r.pos).scrollIntoView()),0))},Lo=(e,t,n)=>{let o=Vo(e,n);if(!o)return!1;let r=jo(o);return!!r&&_o(e,r,t)},Ho=(e,t,n)=>{let o=Jo(e,n);if(!o)return!1;let r=Uo(o);return!!r&&_o(e,r,t)};function _o(e,t,n){let o=t.nodeBefore,r=t.pos-1;for(;!o.isTextblock;r--){if(o.type.spec.isolating)return!1;let e=o.lastChild;if(!e)return!1;o=e}let i=t.nodeAfter,s=t.pos+1;for(;!i.isTextblock;s++){if(i.type.spec.isolating)return!1;let e=i.firstChild;if(!e)return!1;i=e}let l=_e(e.doc,r,s,p.empty);if(!l||l.from!=r||l instanceof Ne&&l.slice.size>=s-r)return!1;if(n){let t=e.tr.step(l);t.setSelection(at.create(t.doc,r)),n(t.scrollIntoView())}return!0}function Wo(e,t,n=!1){for(let o=e;o;o="start"==t?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(n&&1!=o.childCount)return!1}return!1}const qo=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):o.parentOffset>0)return!1;i=jo(o)}let s=i&&i.nodeBefore;return!(!s||!dt.isSelectable(s)||(t&&t(e.tr.setSelection(dt.create(e.doc,i.pos-s.nodeSize)).scrollIntoView()),0))};function jo(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 Jo(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("forward",e):n.parentOffset<n.parent.content.size)?null:n}const Ko=(e,t,n)=>{let o=Jo(e,n);if(!o)return!1;let r=Uo(o);if(!r)return!1;let i=r.nodeAfter;if(cr(e,r,t,1))return!0;if(0==o.parent.content.size&&(Wo(i,"start")||dt.isSelectable(i))){let n=_e(e.doc,o.before(),o.after(),p.empty);if(n&&n.slice.size<n.to-n.from){if(t){let o=e.tr.step(n);o.setSelection(Wo(i,"start")?rt.findFrom(o.doc.resolve(o.mapping.map(r.pos)),1):dt.create(o.doc,o.mapping.map(r.pos))),t(o.scrollIntoView())}return!0}}return!(!i.isAtom||r.depth!=o.depth-1||(t&&t(e.tr.delete(r.pos,r.pos+i.nodeSize).scrollIntoView()),0))},Xo=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):o.parentOffset<o.parent.content.size)return!1;i=Uo(o)}let s=i&&i.nodeAfter;return!(!s||!dt.isSelectable(s)||(t&&t(e.tr.setSelection(dt.create(e.doc,i.pos)).scrollIntoView()),0))};function Uo(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}const Go=(e,t)=>{let n,o=e.selection,r=o instanceof dt;if(r){if(o.node.isTextblock||!Pe(e.doc,o.from))return!1;n=o.from}else if(n=Fe(e.doc,o.from,-1),null==n)return!1;if(t){let o=e.tr.join(n);r&&o.setSelection(dt.create(o.doc,n-e.doc.resolve(n).nodeBefore.nodeSize)),t(o.scrollIntoView())}return!0},Yo=(e,t)=>{let n,o=e.selection;if(o instanceof dt){if(o.node.isTextblock||!Pe(e.doc,o.to))return!1;n=o.to}else if(n=Fe(e.doc,o.to,1),null==n)return!1;return t&&t(e.tr.join(n).scrollIntoView()),!0},Qo=(e,t)=>{let{$from:n,$to:o}=e.selection,r=n.blockRange(o),i=r&&Ee(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)},Zo=(e,t)=>{let{$head:n,$anchor:o}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(o)||(t&&t(e.tr.insertText("\n").scrollIntoView()),0))};function er(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}const tr=(e,t)=>{let{$head:n,$anchor:o}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(o))return!1;let r=n.node(-1),i=n.indexAfter(-1),s=er(r.contentMatchAt(i));if(!s||!r.canReplaceWith(i,i,s))return!1;if(t){let o=n.after(),r=e.tr.replaceWith(o,o,s.createAndFill());r.setSelection(rt.near(r.doc.resolve(o),1)),t(r.scrollIntoView())}return!0},nr=(e,t)=>{let n=e.selection,{$from:o,$to:r}=n;if(n instanceof pt||o.parent.inlineContent||r.parent.inlineContent)return!1;let i=er(r.parent.contentMatchAt(r.indexAfter()));if(!i||!i.isTextblock)return!1;if(t){let n=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,s=e.tr.insert(n,i.createAndFill());s.setSelection(at.create(s.doc,n+1)),t(s.scrollIntoView())}return!0},or=(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 o=n.before();if(Be(e.doc,o))return t&&t(e.tr.split(o).scrollIntoView()),!0}let o=n.blockRange(),r=o&&Ee(o);return null!=r&&(t&&t(e.tr.lift(o,r).scrollIntoView()),!0)};function rr(e){return(t,n)=>{let{$from:o,$to:r}=t.selection;if(t.selection instanceof dt&&t.selection.node.isBlock)return!(!o.parentOffset||!Be(t.doc,o.pos)||(n&&n(t.tr.split(o.pos).scrollIntoView()),0));if(!o.depth)return!1;let i,s,l=[],a=!1,c=!1;for(let t=o.depth;;t--){if(o.node(t).isBlock){a=o.end(t)==o.pos+(o.depth-t),c=o.start(t)==o.pos-(o.depth-t),s=er(o.node(t-1).contentMatchAt(o.indexAfter(t-1)));let n=e&&e(r.parent,a,o);l.unshift(n||(a&&s?{type:s}:null)),i=t;break}if(1==t)return!1;l.unshift(null)}let d=t.tr;(t.selection instanceof at||t.selection instanceof pt)&&d.deleteSelection();let h=d.mapping.map(o.pos),p=Be(d.doc,h,l.length,l);if(p||(l[0]=s?{type:s}:null,p=Be(d.doc,h,l.length,l)),!p)return!1;if(d.split(h,l.length,l),!a&&c&&o.node(i).type!=s){let e=d.mapping.map(o.before(i)),t=d.doc.resolve(e);s&&o.node(i-1).canReplaceWith(t.index(),t.index()+1,s)&&d.setNodeMarkup(d.mapping.map(o.before(i)),s)}return n&&n(d.scrollIntoView()),!0}}const ir=rr(),sr=(e,t)=>ir(e,t&&(n=>{let o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();o&&n.ensureMarks(o),t(n)})),lr=(e,t)=>{let n,{$from:o,to:r}=e.selection,i=o.sharedDepth(r);return 0!=i&&(n=o.before(i),t&&t(e.tr.setSelection(dt.create(e.doc,n))),!0)},ar=(e,t)=>(t&&t(e.tr.setSelection(new pt(e.doc))),!0);function cr(e,t,n,o){let r,i,l=t.nodeBefore,a=t.nodeAfter,c=l.type.spec.isolating||a.type.spec.isolating;if(!c&&function(e,t,n){let o=t.nodeBefore,r=t.nodeAfter,i=t.index();return!(!(o&&r&&o.type.compatibleContent(r.type))||(!o.content.size&&t.parent.canReplace(i-1,i)?(n&&n(e.tr.delete(t.pos-o.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(i,i+1)||!r.isTextblock&&!Pe(e.doc,t.pos)||(n&&n(e.tr.join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let d=!c&&t.parent.canReplace(t.index(),t.index()+1);if(d&&(r=(i=l.contentMatchAt(l.childCount)).findWrapping(a.type))&&i.matchType(r[0]||a.type).validEnd){if(n){let o=t.pos+a.nodeSize,i=s.empty;for(let e=r.length-1;e>=0;e--)i=s.from(r[e].create(null,i));i=s.from(l.copy(i));let c=e.tr.step(new Oe(t.pos-1,o,t.pos,o,new p(i,1,0),r.length,!0)),d=c.doc.resolve(o+2*r.length);d.nodeAfter&&d.nodeAfter.type==l.type&&Pe(c.doc,d.pos)&&c.join(d.pos),n(c.scrollIntoView())}return!0}let h=a.type.spec.isolating||o>0&&c?null:rt.findFrom(t,1),u=h&&h.$from.blockRange(h.$to),f=u&&Ee(u);if(null!=f&&f>=t.depth)return n&&n(e.tr.lift(u,f).scrollIntoView()),!0;if(d&&Wo(a,"start",!0)&&Wo(l,"end")){let o=l,r=[];for(;r.push(o),!o.isTextblock;)o=o.lastChild;let i=a,c=1;for(;!i.isTextblock;i=i.firstChild)c++;if(o.canReplace(o.childCount,o.childCount,i.content)){if(n){let o=s.empty;for(let e=r.length-1;e>=0;e--)o=s.from(r[e].copy(o));n(e.tr.step(new Oe(t.pos-r.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new p(o,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function dr(e){return function(t,n){let o=t.selection,r=e<0?o.$from:o.$to,i=r.depth;for(;r.node(i).isInline;){if(!i)return!1;i--}return!!r.node(i).isTextblock&&(n&&n(t.tr.setSelection(at.create(t.doc,e<0?r.start(i):r.end(i)))),!0)}}const hr=dr(-1),pr=dr(1);function ur(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i),l=s&&Re(s,e,t);return!!l&&(o&&o(n.tr.wrap(s,l).scrollIntoView()),!0)}}function fr(e,t=null){return function(n,o){let r=!1;for(let o=0;o<n.selection.ranges.length&&!r;o++){let{$from:{pos:i},$to:{pos:s}}=n.selection.ranges[o];n.doc.nodesBetween(i,s,(o,i)=>{if(r)return!1;if(o.isTextblock&&!o.hasMarkup(e,t))if(o.type==e)r=!0;else{let t=n.doc.resolve(i),o=t.index();r=t.parent.canReplaceWith(o,o+1,e)}})}if(!r)return!1;if(o){let r=n.tr;for(let o=0;o<n.selection.ranges.length;o++){let{$from:{pos:i},$to:{pos:s}}=n.selection.ranges[o];r.setBlockType(i,s,e,t)}o(r.scrollIntoView())}return!0}}function mr(e,t=null,n){let o=!1!==(n&&n.removeWhenPresent),r=!1!==(n&&n.enterInlineAtoms),i=!(n&&n.includeWhitespace);return function(n,s){let{empty:l,$cursor:a,ranges:c}=n.selection;if(l&&!a||!function(e,t,n,o){for(let r=0;r<t.length;r++){let{$from:i,$to:s}=t[r],l=0==i.depth&&e.inlineContent&&e.type.allowsMarkType(n);if(e.nodesBetween(i.pos,s.pos,(e,t)=>{if(l||!o&&e.isAtom&&e.isInline&&t>=i.pos&&t+e.nodeSize<=s.pos)return!1;l=e.inlineContent&&e.type.allowsMarkType(n)}),l)return!0}return!1}(n.doc,c,e,r))return!1;if(s)if(a)e.isInSet(n.storedMarks||a.marks())?s(n.tr.removeStoredMark(e)):s(n.tr.addStoredMark(e.create(t)));else{let l,a=n.tr;r||(c=function(e){let t=[];for(let n=0;n<e.length;n++){let{$from:o,$to:r}=e[n];o.doc.nodesBetween(o.pos,r.pos,(e,n)=>{if(e.isAtom&&e.content.size&&e.isInline&&n>=o.pos&&n+e.nodeSize<=r.pos)return n+1>o.pos&&t.push(new it(o,o.doc.resolve(n+1))),o=o.doc.resolve(n+1+e.content.size),!1}),o.pos<r.pos&&t.push(new it(o,r))}return t}(c)),l=o?!c.some(t=>n.doc.rangeHasMark(t.$from.pos,t.$to.pos,e)):!c.every(t=>{let n=!1;return a.doc.nodesBetween(t.$from.pos,t.$to.pos,(o,r,i)=>{if(n)return!1;n=!e.isInSet(o.marks)&&!!i&&i.type.allowsMarkType(e)&&!(o.isText&&/^\s*$/.test(o.textBetween(Math.max(0,t.$from.pos-r),Math.min(o.nodeSize,t.$to.pos-r))))}),!n});for(let n=0;n<c.length;n++){let{$from:o,$to:r}=c[n];if(l){let n=o.pos,s=r.pos,l=o.nodeAfter,c=r.nodeBefore,d=i&&l&&l.isText?/^\s*/.exec(l.text)[0].length:0,h=i&&c&&c.isText?/\s*$/.exec(c.text)[0].length:0;n+d<s&&(n+=d,s-=h),a.addMark(n,s,e.create(t))}else a.removeMark(o.pos,r.pos,e)}s(a.scrollIntoView())}return!0}}function gr(e,t){return n=>{if(!n.isGeneric)return e(n);let o=[];for(let e=0;e<n.mapping.maps.length;e++){let t=n.mapping.maps[e];for(let e=0;e<o.length;e++)o[e]=t.map(o[e]);t.forEach((e,t,n,r)=>o.push(n,r))}let r=[];for(let e=0;e<o.length;e+=2){let i=o[e],s=o[e+1],l=n.doc.resolve(i),a=l.sharedDepth(s),c=l.node(a);for(let e=l.indexAfter(a),n=l.after(a+1);n<=s;++e){let o=c.maybeChild(e);if(!o)break;if(e&&-1==r.indexOf(n)){let i=c.child(e-1);i.type==o.type&&t(i,o)&&r.push(n)}n+=o.nodeSize}}r.sort((e,t)=>e-t);for(let e=r.length-1;e>=0;e--)Pe(n.doc,r[e])&&n.join(r[e]);e(n)}}function yr(e,t){let n=Array.isArray(t)?e=>t.indexOf(e.type.name)>-1:t;return(t,o,r)=>e(t,o&&gr(o,n),r)}function wr(...e){return function(t,n,o){for(let r=0;r<e.length;r++)if(e[r](t,n,o))return!0;return!1}}let vr=wr(Po,Fo,qo),br=wr(Po,Ko,Xo);const kr={Enter:wr(Zo,nr,or,ir),"Mod-Enter":tr,Backspace:vr,"Mod-Backspace":vr,"Shift-Backspace":vr,Delete:br,"Mod-Delete":br,"Mod-a":ar},xr={"Ctrl-h":kr.Backspace,"Alt-Backspace":kr["Mod-Backspace"],"Ctrl-d":kr.Delete,"Ctrl-Alt-Backspace":kr["Mod-Delete"],"Alt-Delete":kr["Mod-Delete"],"Alt-d":kr["Mod-Delete"],"Ctrl-a":hr,"Ctrl-e":pr};for(let e in kr)xr[e]=kr[e];const Sr=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&"darwin"==os.platform())?xr:kr,Cr=(e,t)=>ur(e.schema.nodes.blockquote)(e,t),Mr=(e,t)=>{const{$from:n,$to:o}=e.selection,r=e.schema.nodes.blockquote,i=e.doc;let s=-1;const l=n.blockRange(o);l&&i.nodesBetween(l.start,l.end,(e,t)=>{e.type===r&&(s=t)});const a=-1!==s;return t&&a&&t(e.tr.lift(l,i.resolve(s).depth)),a},Nr=(e,t,n)=>(o,r)=>{const i=so(o),s=o.tr;s.setMeta("commandName",t),i.forEach(t=>{if(t.type.isTextblock){let o;const r=e.find(e=>e.node===t.type.name);if(r){const e="rtl"===n?r.rtlStyle:r.style,i={name:e,value:r.step>0?`${r.step}${r.unit}`:""};if(t.attrs.style){const n=new RegExp(`${e}:\\s?(\\d+)${r.unit}`,"i"),o=t.attrs.style.match(n);if(o){let e=parseFloat(o[1])+r.step;e=e<=0?"":e,i.value=`${e}${e?r.unit:""}`}}o=ho(t,[i])}o&&io(s,t,t.type,o)}});const l=s.docChanged;return l&&r(s.scrollIntoView()),l},Or=(e,t,n)=>{const o=so(e);let r=!1;return o.forEach(e=>{if(!r&&e.type.isTextblock&&e.attrs.style){const o=t.find(t=>t.node===e.type.name);if(o){const t="rtl"===n?o.rtlStyle:o.style,i=new RegExp(`${t}:\\s?\\d+${o.unit}`,"i");r=i.test(e.attrs.style)}}}),r},Ar=(e,t)=>Eo(t)(e),Tr=(e,t)=>{const n=e.schema.nodes[t.listsTypes.listItem],o=e.schema.nodes[t.listsTypes.orderedList],r=e.schema.nodes[t.listsTypes.bulletList],i=!!Yt(o,2)(e.selection),s=!!Yt(r,2)(e.selection);return(i||s)&&Do(n)(e)},Dr=(e,t)=>{const n=e.schema.nodes,o=n[zo.listsTypes.listItem];return(Or(e,t.nodes)||zo.nodes.some(t=>n[t.node]&&po(e,n[t.node])))&&!po(e,o)},Er=(e,t)=>{const n=e.schema.nodes[zo.listsTypes.listItem],o=Dr(e,zo);Ar(e,n)?Eo(n)(e,t):o&&Nr(zo.nodes)(e,t)},Rr=(e,t)=>{const n=e.schema.nodes,o=n[Bo.listsTypes.listItem],r=Dr(e,Bo);po(e,n.blockquote)?Mr(e,t):Tr(e,Bo)?Do(o)(e,t):r&&Nr(Bo.nodes)(e,t)},$r=(e,t,n)=>{let o=t.depth;const r=e.nodes[n.bulletList],i=e.nodes[n.orderedList],s=e.nodes[n.listItem];for(let e=t.depth;e>0;e--){const n=t.node(e);if(n.type!==r&&n.type!==i||(o=e),n.type!==r&&n.type!==i&&n.type!==s)break}return o-1};function Ir(e,t,n,o){const r=o||e.schema.nodes.listItem,{$from:i,$to:l}=t;let a=i.blockRange(l,e=>e.childCount&&e.firstChild.type===r);if(!a||a.depth<2||i.node(a.depth-1).type!==r)return n;const c=a.end,d=l.end(a.depth);return c<d&&(n.step(new Oe(c-1,d,c,d,new p(s.from(r.create(void 0,a.parent.copy())),1,0),1,!0)),a=new A(n.doc.resolve(i.pos),n.doc.resolve(d),a.depth)),n.lift(a,Ee(a)).scrollIntoView()}function zr(e){return function(t,n){const{tr:o}=t,{$from:r,$to:i}=t.selection;return o.doc.nodesBetween(r.pos,i.pos,(n,r)=>{if(n.isTextblock||"blockquote"===n.type.name||"div"===n.type.name){const n=new dt(o.doc.resolve(o.mapping.map(r))),i=n.$from.blockRange(n.$to);if(!i||n.$from.parent.type!==t.schema.nodes[e.listItem])return;const s=i&&Ee(i);if(null==s)return!1;o.lift(i,s)}}),n&&n(o),!0}}const Br=/list-style-type:\s?([\w-]+)/,Pr=e=>{const t=e.style||"",n=Br.exec(t);return n&&n[1]||""},Vr=(e,t,n,o,r)=>{const{listType:i,listAttrs:s={style:null}}=o,{selection:l}=e,a=l.$from.node(l.$from.depth-2),c=l.$to.node(l.$to.depth-2);if(a&&a.type.name===i&&Pr(a.attrs)===Pr(s)&&c&&c.type.name===i&&Pr(c.attrs)===Pr(s)){const i=n.state.schema.nodes,s={bulletList:i[o.bulletList],orderedList:i[o.orderedList],listItem:i[o.listItem]},a=((e,t)=>{const{bulletList:n,orderedList:o,listItem:r}=t;let i;for(let t=e.depth-1;t>0;t--){const s=e.node(t);if(s.type!==n&&s.type!==o||(i=t),s.type!==n&&s.type!==o&&s.type!==r)break}return i})(l.$to,s);let c=function(e,t,n,o,r,i){i||(i=e.schema.nodes.listItem);let s=!1;return r.doc.nodesBetween(t,n,(n,l)=>{if(!s&&n.type===i&&l>t){s=!0;let t=o+3;for(;t>o+2;){const o=r.doc.resolve(r.mapping.map(l));t=o.depth;const s=r.doc.resolve(r.mapping.map(l+n.textContent.length)),a=new at(o,s);r=Ir(e,a,r,i)}}}),r}(e,l.$to.pos,l.$to.end(a),a,n.state.tr,s.listItem);return c=function(e,t,n){const{from:o,to:r}=e.selection,{paragraph:i,heading:s}=e.schema.nodes,l=[];t.doc.nodesBetween(o,r,(e,t)=>{e.type!==i&&e.type!==s||l.push({node:e,pos:t})});for(let o=l.length-1;o>=0;o--){const r=l[o],i=t.doc.resolve(t.mapping.map(r.pos));if(i.depth>0){let o;o=r.node.textContent&&r.node.textContent.length>0?t.doc.resolve(t.mapping.map(r.pos+r.node.textContent.length)):t.doc.resolve(t.mapping.map(r.pos+1));const s=i.blockRange(o);s&&t.lift(s,$r(e.schema,i,n))}}return t}(e,c,o),c.setMeta("commandName",r),t(c),!0}return function(e){return function(t,n,o){if(!o)return!1;const r=(t=o.state).schema.nodes[e.listType],{$from:i,$to:s}=t.selection,l=i.node(-2),a=i.node(-3),c=function(e,t,n,o){return 0===function(e,t,n){const o=[],r=function(e,t){const n=["blockquote","bulletList","orderedList"];if(1===t.depth)return t;let o=t.node(t.depth),r=t;for(;t.depth>=1;)o=(t=e.resolve(t.before(t.depth))).node(t.depth),o&&-1!==n.indexOf(o.type.name)&&(r=t);return r}(e,t).depth;let i=e.resolve(t.start(r));for(;i.pos<=n.start(n.depth);){const t=Math.min(i.depth,r),n=i.node(t);if(n&&o.push(n),0===t)break;let s=e.resolve(i.after(t));if(s.start(t)>=e.nodeSize-2)break;s.depth!==i.depth&&(s=e.resolve(s.pos+2)),i=s.depth?e.resolve(s.start(s.depth)):e.resolve(s.end(s.depth))}return o}(e,t,n).filter(e=>e.type!==o).length}(t.doc,i,s,r);return(l&&l.type===r||a&&a.type===r)&&c?zr(e)(t,n):(c||(zr(e)(t,n),t=o.state),function(e,t={}){return yr(No(e,t),(t,n)=>t.type===n.type&&t.type===e)}(r,e.listAttrs)(t,n))}}(o)(e,t,n)};function Fr(e,t,n){return Vr(e,t,n,{listType:Io.listType,...Io.types})}function Lr(e,t,n){return Vr(e,t,n,{listType:$o.listType,...$o.types})}const Hr=(e,t)=>({name:e,value:t}),_r=[{node:"paragraph",style:[Hr("text-align","left")]},{node:"heading",style:[Hr("text-align","left")]},{node:"table_caption_external",style:[Hr("text-align","left")]}],Wr=[{node:"paragraph",style:[Hr("text-align","right")]},{node:"heading",style:[Hr("text-align","right")]},{node:"table_caption_external",style:[Hr("text-align","right")]}],qr=[{node:"paragraph",style:[Hr("text-align","center")]},{node:"heading",style:[Hr("text-align","center")]},{node:"table_caption_external",style:[Hr("text-align","center")]}],jr=[{node:"paragraph",style:[Hr("text-align","justify")]},{node:"heading",style:[Hr("text-align","justify")]},{node:"table_caption_external",style:[Hr("text-align","justify")]}],Jr=[{node:"paragraph",style:[Hr("text-align","")]},{node:"heading",style:[Hr("text-align","")]},{node:"table_caption_external",style:[Hr("text-align","")]}],Kr=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},Xr=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let Ur=null;const Gr=function(e,t,n){let o=Ur||(Ur=document.createRange());return o.setEnd(e,null==n?e.nodeValue.length:n),o.setStart(e,t||0),o},Yr=function(e,t,n,o){return n&&(Zr(e,t,n,o,-1)||Zr(e,t,n,o,1))},Qr=/^(img|br|input|textarea|hr)$/i;function Zr(e,t,n,o,r){for(var i;;){if(e==n&&t==o)return!0;if(t==(r<0?0:ei(e))){let n=e.parentNode;if(!n||1!=n.nodeType||ti(e)||Qr.test(e.nodeName)||"false"==e.contentEditable)return!1;t=Kr(e)+(r<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(r<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(i=n.pmViewDesc)||void 0===i?void 0:i.ignoreForSelection))return!1;t+=r}else e=n,t=r<0?ei(e):0}}}}function ei(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function ti(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 ni=function(e){return e.focusNode&&Yr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oi(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const ri="undefined"!=typeof navigator?navigator:null,ii="undefined"!=typeof document?document:null,si=ri&&ri.userAgent||"",li=/Edge\/(\d+)/.exec(si),ai=/MSIE \d/.exec(si),ci=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(si),di=!!(ai||ci||li),hi=ai?document.documentMode:ci?+ci[1]:li?+li[1]:0,pi=!di&&/gecko\/(\d+)/i.test(si);pi&&(/Firefox\/(\d+)/.exec(si)||[0,0])[1];const ui=!di&&/Chrome\/(\d+)/.exec(si),fi=!!ui,mi=ui?+ui[1]:0,gi=!di&&!!ri&&/Apple Computer/.test(ri.vendor),yi=gi&&(/Mobile\/\w+/.test(si)||!!ri&&ri.maxTouchPoints>2),wi=yi||!!ri&&/Mac/.test(ri.platform),vi=!!ri&&/Win/.test(ri.platform),bi=/Android \d/.test(si),ki=!!ii&&"webkitFontSmoothing"in ii.documentElement.style,xi=ki?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Si(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function Ci(e,t){return"number"==typeof e?e:e[t]}function Mi(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,o=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*o}}function Ni(e,t,n){let o=e.someProp("scrollThreshold")||0,r=e.someProp("scrollMargin")||5,i=e.dom.ownerDocument;for(let s=n||e.dom;s;){if(1!=s.nodeType){s=Xr(s);continue}let e=s,n=e==i.body,l=n?Si(i):Mi(e),a=0,c=0;if(t.top<l.top+Ci(o,"top")?c=-(l.top-t.top+Ci(r,"top")):t.bottom>l.bottom-Ci(o,"bottom")&&(c=t.bottom-t.top>l.bottom-l.top?t.top+Ci(r,"top")-l.top:t.bottom-l.bottom+Ci(r,"bottom")),t.left<l.left+Ci(o,"left")?a=-(l.left-t.left+Ci(r,"left")):t.right>l.right-Ci(o,"right")&&(a=t.right-l.right+Ci(r,"right")),a||c)if(n)i.defaultView.scrollBy(a,c);else{let n=e.scrollLeft,o=e.scrollTop;c&&(e.scrollTop+=c),a&&(e.scrollLeft+=a);let r=e.scrollLeft-n,i=e.scrollTop-o;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}let d=n?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s="absolute"==d?s.offsetParent:Xr(s)}}function Oi(e){let t=[],n=e.ownerDocument;for(let o=e;o&&(t.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),e!=n);o=Xr(o));return t}function Ai(e,t){for(let n=0;n<e.length;n++){let{dom:o,top:r,left:i}=e[n];o.scrollTop!=r+t&&(o.scrollTop=r+t),o.scrollLeft!=i&&(o.scrollLeft=i)}}let Ti=null;function Di(e,t){let n,o,r,i,s=2e8,l=0,a=t.top,c=t.top;for(let d=e.firstChild,h=0;d;d=d.nextSibling,h++){let e;if(1==d.nodeType)e=d.getClientRects();else{if(3!=d.nodeType)continue;e=Gr(d).getClientRects()}for(let p=0;p<e.length;p++){let u=e[p];if(u.top<=a&&u.bottom>=c){a=Math.max(u.bottom,a),c=Math.min(u.top,c);let e=u.left>t.left?u.left-t.left:u.right<t.left?t.left-u.right:0;if(e<s){n=d,s=e,o=e&&3==n.nodeType?{left:u.right<t.left?u.right:u.left,top:t.top}:t,1==d.nodeType&&e&&(l=h+(t.left>=(u.left+u.right)/2?1:0));continue}}else u.top>t.top&&!r&&u.left<=t.left&&u.right>=t.left&&(r=d,i={left:Math.max(u.left,Math.min(u.right,t.left)),top:u.top});!n&&(t.left>=u.right&&t.top>=u.top||t.left>=u.left&&t.top>=u.bottom)&&(l=h+1)}}return!n&&r&&(n=r,o=i,s=0),n&&3==n.nodeType?function(e,t){let n=e.nodeValue.length,o=document.createRange();for(let r=0;r<n;r++){o.setEnd(e,r+1),o.setStart(e,r);let n=zi(o,1);if(n.top!=n.bottom&&Ei(t,n))return{node:e,offset:r+(t.left>=(n.left+n.right)/2?1:0)}}return{node:e,offset:0}}(n,o):!n||s&&1==n.nodeType?{node:e,offset:l}:Di(n,o)}function Ei(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Ri(e,t,n){let o=e.childNodes.length;if(o&&n.top<n.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(t.top-n.top)/(n.bottom-n.top))-2)),i=r;;){let n=e.childNodes[i];if(1==n.nodeType){let e=n.getClientRects();for(let o=0;o<e.length;o++){let r=e[o];if(Ei(t,r))return Ri(n,t,r)}}if((i=(i+1)%o)==r)break}return e}function $i(e,t){let n,o=e.dom.ownerDocument,r=0,i=function(e,t,n){if(e.caretPositionFromPoint)try{let o=e.caretPositionFromPoint(t,n);if(o)return{node:o.offsetNode,offset:Math.min(ei(o.offsetNode),o.offset)}}catch(e){}if(e.caretRangeFromPoint){let o=e.caretRangeFromPoint(t,n);if(o)return{node:o.startContainer,offset:Math.min(ei(o.startContainer),o.startOffset)}}}(o,t.left,t.top);i&&({node:n,offset:r}=i);let s,l=(e.root.elementFromPoint?e.root:o).elementFromPoint(t.left,t.top);if(!l||!e.dom.contains(1!=l.nodeType?l.parentNode:l)){let n=e.dom.getBoundingClientRect();if(!Ei(t,n))return null;if(l=Ri(e.dom,t,n),!l)return null}if(gi)for(let e=l;n&&e;e=Xr(e))e.draggable&&(n=void 0);if(l=function(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}(l,t),n){if(pi&&1==n.nodeType&&(r=Math.min(r,n.childNodes.length),r<n.childNodes.length)){let e,o=n.childNodes[r];"IMG"==o.nodeName&&(e=o.getBoundingClientRect()).right<=t.left&&e.bottom>t.top&&r++}let o;ki&&r&&1==n.nodeType&&1==(o=n.childNodes[r-1]).nodeType&&"false"==o.contentEditable&&o.getBoundingClientRect().top>=t.top&&r--,n==e.dom&&r==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:0!=r&&1==n.nodeType&&"BR"==n.childNodes[r-1].nodeName||(s=function(e,t,n,o){let r=-1;for(let n=t,i=!1;n!=e.dom;){let t,s=e.docView.nearestDesc(n,!0);if(!s)return null;if(1==s.dom.nodeType&&(s.node.isBlock&&s.parent||!s.contentDOM)&&((t=s.dom.getBoundingClientRect()).width||t.height)&&(s.node.isBlock&&s.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(s.dom.nodeName)&&(!i&&t.left>o.left||t.top>o.top?r=s.posBefore:(!i&&t.right<o.left||t.bottom<o.top)&&(r=s.posAfter),i=!0),!s.contentDOM&&r<0&&!s.node.isText))return(s.node.isBlock?o.top<(t.top+t.bottom)/2:o.left<(t.left+t.right)/2)?s.posBefore:s.posAfter;n=s.dom.parentNode}return r>-1?r:e.docView.posFromDOM(t,n,-1)}(e,n,r,t))}null==s&&(s=function(e,t,n){let{node:o,offset:r}=Di(t,n),i=-1;if(1==o.nodeType&&!o.firstChild){let e=o.getBoundingClientRect();i=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(o,r,i)}(e,l,t));let a=e.docView.nearestDesc(l,!0);return{pos:s,inside:a?a.posAtStart-a.border:-1}}function Ii(e){return e.top<e.bottom||e.left<e.right}function zi(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Ii(e))return e}return Array.prototype.find.call(n,Ii)||e.getBoundingClientRect()}const Bi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Pi(e,t,n){let{node:o,offset:r,atom:i}=e.docView.domFromPos(t,n<0?-1:1),s=ki||pi;if(3==o.nodeType){if(!s||!Bi.test(o.nodeValue)&&(n<0?r:r!=o.nodeValue.length)){let e=r,t=r,i=n<0?1:-1;return n<0&&!r?(t++,i=-1):n>=0&&r==o.nodeValue.length?(e--,i=1):n<0?e--:t++,Vi(zi(Gr(o,e,t),i),i<0)}{let e=zi(Gr(o,r,r),n);if(pi&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let t=zi(Gr(o,r-1,r-1),-1);if(t.top==e.top){let n=zi(Gr(o,r,r+1),-1);if(n.top!=e.top)return Vi(n,n.left<t.left)}}return e}}if(!e.state.doc.resolve(t-(i||0)).parent.inlineContent){if(null==i&&r&&(n<0||r==ei(o))){let e=o.childNodes[r-1];if(1==e.nodeType)return Fi(e.getBoundingClientRect(),!1)}if(null==i&&r<ei(o)){let e=o.childNodes[r];if(1==e.nodeType)return Fi(e.getBoundingClientRect(),!0)}return Fi(o.getBoundingClientRect(),n>=0)}if(null==i&&r&&(n<0||r==ei(o))){let e=o.childNodes[r-1],t=3==e.nodeType?Gr(e,ei(e)-(s?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return Vi(zi(t,1),!1)}if(null==i&&r<ei(o)){let e=o.childNodes[r];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?Gr(e,0,s?0:1):1==e.nodeType?e:null:null;if(t)return Vi(zi(t,-1),!0)}return Vi(zi(3==o.nodeType?Gr(o):o,-n),n>=0)}function Vi(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 Fi(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 Li(e,t,n){let o=e.state,r=e.root.activeElement;o!=t&&e.updateState(t),r!=e.dom&&e.focus();try{return n()}finally{o!=t&&e.updateState(o),r!=e.dom&&r&&r.focus()}}const Hi=/[\u0590-\u08ac]/;let _i=null,Wi=null,qi=!1;class ji{constructor(e,t,n,o){this.parent=e,this.children=t,this.dom=n,this.contentDOM=o,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 o=this.children[t];if(o==e)return n;n+=o.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,o;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.previousSibling;return n?this.posBeforeChild(o)+o.size:this.posAtStart}{let n,o;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.nextSibling;return n?this.posBeforeChild(o):this.posAtEnd}}let o;if(e==this.dom&&this.contentDOM)o=t>Kr(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))o=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!1;break}if(t.previousSibling)break}if(null==o&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!0;break}if(t.nextSibling)break}}return(null==o?n>0:o)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,o=e;o;o=o.parentNode){let r,i=this.getDesc(o);if(i&&(!t||i.node)){if(!n||!(r=i.nodeDOM)||(1==r.nodeType?r.contains(1==e.nodeType?e:e.parentNode):r==e))return i;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 o=e;o;o=o.parentNode){let r=this.getDesc(o);if(r)return r.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let o=this.children[t],r=n+o.size;if(n==e&&r!=n){for(;!o.border&&o.children.length;)for(let e=0;e<o.children.length;e++){let t=o.children[e];if(t.size){o=t;break}}return o}if(e<r)return o.descAt(e-n-o.border);n=r}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,o=0;for(let t=0;n<this.children.length;n++){let r=this.children[n],i=t+r.size;if(i>e||r instanceof Qi){o=e-t;break}t=i}if(o)return this.children[n].domFromPos(o-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof Ji&&e.side>=0;n--);if(t<=0){let e,o=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,o=!1);return e&&t&&o&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Kr(e.dom)+1:0}}{let e,o=!0;for(;e=n<this.children.length?this.children[n]:null,e&&e.dom.parentNode!=this.contentDOM;n++,o=!1);return e&&o&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Kr(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 o=-1,r=-1;for(let i=n,s=0;;s++){let n=this.children[s],l=i+n.size;if(-1==o&&e<=l){let r=i+n.border;if(e>=r&&t<=l-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,r);e=i;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){o=Kr(n.dom)+1;break}e-=n.size}-1==o&&(o=0)}if(o>-1&&(l>t||s==this.children.length-1)){t=l;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)){r=Kr(n.dom);break}t+=n.size}-1==r&&(r=this.contentDOM.childNodes.length);break}i=l}return{node:this.contentDOM,from:e,to:t,fromOffset:o,toOffset:r}}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,o=!1){let r=Math.min(e,t),i=Math.max(e,t);for(let s=0,l=0;s<this.children.length;s++){let a=this.children[s],c=l+a.size;if(r>l&&i<c)return a.setSelection(e-l-a.border,t-l-a.border,n,o);l=c}let s=this.domFromPos(e,e?-1:1),l=t==e?s:this.domFromPos(t,t?-1:1),a=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((pi||gi)&&e==t){let{node:e,offset:t}=s;if(3==e.nodeType){if(d=!(!t||"\n"!=e.nodeValue[t-1]),d&&t==e.nodeValue.length)for(let t,n=e;n;n=n.parentNode){if(t=n.nextSibling){"BR"==t.nodeName&&(s=l={node:t.parentNode,offset:Kr(t)+1});break}let e=n.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(pi&&c.focusNode&&c.focusNode!=l.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(o=!0)}if(!(o||d&&gi)&&Yr(s.node,s.offset,c.anchorNode,c.anchorOffset)&&Yr(l.node,l.offset,c.focusNode,c.focusOffset))return;let h=!1;if((a.extend||e==t)&&(!d||!pi)){a.collapse(s.node,s.offset);try{e!=t&&a.extend(l.node,l.offset),h=!0}catch(e){}}if(!h){if(e>t){let e=s;s=l,l=e}let n=document.createRange();n.setEnd(l.node,l.offset),n.setStart(s.node,s.offset),a.removeAllRanges(),a.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,o=0;o<this.children.length;o++){let r=this.children[o],i=n+r.size;if(n==i?e<=i&&t>=n:e<i&&t>n){let o=n+r.border,s=i-r.border;if(e>=o&&t<=s)return this.dirty=e==n||t==i?2:1,void(e!=o||t!=s||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(e-o,t-o):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}n=i}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}get ignoreForSelection(){return!1}isText(e){return!1}}class Ji extends ji{constructor(e,t,n,o){let r,i=t.type.toDOM;if("function"==typeof i&&(i=i(n,()=>r?r.parent?r.parent.posBeforeChild(r):void 0:o)),!t.type.spec.raw){if(1!=i.nodeType){let e=document.createElement("span");e.appendChild(i),i=e}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,r=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 ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class Ki extends ji{constructor(e,t,n,o){super(e,[],t,null),this.textDOM=n,this.text=o}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 Xi extends ji{constructor(e,t,n,o,r){super(e,[],n,o),this.mark=t,this.spec=r}static create(e,t,n,o){let r=o.nodeViews[t.type.name],i=r&&r(t,o,n);return i&&i.dom||(i=le.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new Xi(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}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 o=Xi.create(this.parent,this.mark,!0,n),r=this.children,i=this.size;t<i&&(r=ps(r,t,i,n)),e>0&&(r=ps(r,0,e,n));for(let e=0;e<r.length;e++)r[e].parent=o;return o.children=r,o}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Ui extends ji{constructor(e,t,n,o,r,i,s,l,a){super(e,[],r,i),this.node=t,this.outerDeco=n,this.innerDeco=o,this.nodeDOM=s}static create(e,t,n,o,r,i){let s,l=r.nodeViews[t.type.name],a=l&&l(t,r,()=>s?s.parent?s.parent.posBeforeChild(s):void 0:i,n,o),c=a&&a.dom,d=a&&a.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 if(!c){let e=le.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let h=c;return c=ls(c,n,t),a?s=new Zi(e,t,n,o,c,d||null,h,a,r,i+1):t.isText?new Yi(e,t,n,o,c,h,r):new Ui(e,t,n,o,c,d||null,h,r,i+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=()=>s.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)&&as(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,o=t,r=e.composing?this.localCompositionInfo(e,t):null,i=r&&r.pos>-1?r:null,s=r&&r.pos<0,l=new ds(this,i&&i.node,e);!function(e,t,n,o){let r=t.locals(e),i=0;if(0==r.length){for(let n=0;n<e.childCount;n++){let s=e.child(n);o(s,r,t.forChild(i,s),n),i+=s.nodeSize}return}let s=0,l=[],a=null;for(let c=0;;){let d,h,p,u;for(;s<r.length&&r[s].to==i;){let e=r[s++];e.widget&&(d?(h||(h=[d])).push(e):d=e)}if(d)if(h){h.sort(hs);for(let e=0;e<h.length;e++)n(h[e],c,!!a)}else n(d,c,!!a);if(a)u=-1,p=a,a=null;else{if(!(c<e.childCount))break;u=c,p=e.child(c++)}for(let e=0;e<l.length;e++)l[e].to<=i&&l.splice(e--,1);for(;s<r.length&&r[s].from<=i&&r[s].to>i;)l.push(r[s++]);let f=i+p.nodeSize;if(p.isText){let e=f;s<r.length&&r[s].from<e&&(e=r[s].from);for(let t=0;t<l.length;t++)l[t].to<e&&(e=l[t].to);e<f&&(a=p.cut(e-i),p=p.cut(0,e-i),f=e,u=-1)}else for(;s<r.length&&r[s].to<f;)s++;o(p,p.isInline&&!p.isLeaf?l.filter(e=>!e.inline):l.slice(),t.forChild(i,p),u),i=f}}(this.node,this.innerDeco,(t,r,i)=>{t.spec.marks?l.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!i&&l.syncToMarks(r==this.node.childCount?d.none:this.node.child(r).marks,n,e),l.placeWidget(t,e,o)},(t,i,a,c)=>{let d;l.syncToMarks(t.marks,n,e),l.findNodeMatch(t,i,a,c)||s&&e.state.selection.from>o&&e.state.selection.to<o+t.nodeSize&&(d=l.findIndexWithChild(r.node))>-1&&l.updateNodeAt(t,i,a,d,e)||l.updateNextNode(t,i,a,e,c,o)||l.addNode(t,i,a,e,o),o+=t.nodeSize}),l.syncToMarks([],n,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||2==this.dirty)&&(i&&this.protectLocalComposition(e,i),es(this.contentDOM,this.children,e),yi&&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:o}=e.state.selection;if(!(e.state.selection instanceof at)||n<t||o>t+this.node.content.size)return null;let r=e.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let e=r.nodeValue,i=function(e,t,n,o){for(let r=0,i=0;r<e.childCount&&i<=o;){let s=e.child(r++),l=i;if(i+=s.nodeSize,!s.isText)continue;let a=s.text;for(;r<e.childCount;){let t=e.child(r++);if(i+=t.nodeSize,!t.isText)break;a+=t.text}if(i>=n){if(i>=o&&a.slice(o-t.length-l,o-l)==t)return o-t.length;let e=l<o?a.lastIndexOf(t,o-l-1):-1;if(e>=0&&e+t.length+l>=n)return l+e;if(n==o&&a.length>=o+t.length-l&&a.slice(o-l,o-l+t.length)==t)return o}}return-1}(this.node.content,e,n-t,o-t);return i<0?null:{node:r,pos:i,text:e}}return{node:r,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:o}){if(this.getDesc(t))return;let r=t;for(;r.parentNode!=this.contentDOM;r=r.parentNode){for(;r.previousSibling;)r.parentNode.removeChild(r.previousSibling);for(;r.nextSibling;)r.parentNode.removeChild(r.nextSibling);r.pmViewDesc&&(r.pmViewDesc=void 0)}let i=new Ki(this,r,t,o);e.input.compositionNodes.push(i),this.children=ps(this.children,n,n+o.length,e,i)}update(e,t,n,o){return!(3==this.dirty||!e.sameMarkup(this.node)||(this.updateInner(e,t,n,o),0))}updateInner(e,t,n,o){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(o,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(as(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=is(this.dom,this.nodeDOM,rs(this.outerDeco,this.node,t),rs(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.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Gi(e,t,n,o,r){ls(o,t,e);let i=new Ui(void 0,e,t,n,o,o,o,r,0);return i.contentDOM&&i.updateChildren(r,0),i}class Yi extends Ui{constructor(e,t,n,o,r,i,s){super(e,t,n,o,r,null,i,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,o){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,o.trackWrites==this.nodeDOM&&(o.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 o=this.node.cut(e,t),r=document.createTextNode(o.text);return new Yi(this.parent,o,this.outerDeco,this.innerDeco,r,r,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}isText(e){return this.node.text==e}}class Qi extends ji{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 Zi extends Ui{constructor(e,t,n,o,r,i,s,l,a,c){super(e,t,n,o,r,i,s,a,c),this.spec=l}update(e,t,n,o){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let r=this.spec.update(e,t,n);return r&&this.updateInner(e,t,n,o),r}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,o)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,o){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,o)}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 es(e,t,n){let o=e.firstChild,r=!1;for(let i=0;i<t.length;i++){let s=t[i],l=s.dom;if(l.parentNode==e){for(;l!=o;)o=cs(o),r=!0;o=o.nextSibling}else r=!0,e.insertBefore(l,o);if(s instanceof Xi){let t=o?o.previousSibling:e.lastChild;es(s.contentDOM,s.children,n),o=t?t.nextSibling:e.firstChild}}for(;o;)o=cs(o),r=!0;r&&n.trackWrites==e&&(n.trackWrites=null)}const ts=function(e){e&&(this.nodeName=e)};ts.prototype=Object.create(null);const ns=[new ts];function rs(e,t,n){if(0==e.length)return ns;let o=n?ns[0]:new ts,r=[o];for(let i=0;i<e.length;i++){let s=e[i].type.attrs;if(s){s.nodeName&&r.push(o=new ts(s.nodeName));for(let e in s){let i=s[e];null!=i&&(n&&1==r.length&&r.push(o=new ts(t.isInline?"span":"div")),"class"==e?o.class=(o.class?o.class+" ":"")+i:"style"==e?o.style=(o.style?o.style+";":"")+i:"nodeName"!=e&&(o[e]=i))}}}return r}function is(e,t,n,o){if(n==ns&&o==ns)return t;let r=t;for(let t=0;t<o.length;t++){let i=o[t],s=n[t];if(t){let t;s&&s.nodeName==i.nodeName&&r!=e&&(t=r.parentNode)&&t.nodeName.toLowerCase()==i.nodeName||(t=document.createElement(i.nodeName),t.pmIsDeco=!0,t.appendChild(r),s=ns[0]),r=t}ss(r,s||ns[0],i)}return r}function ss(e,t,n){for(let o in t)"class"==o||"style"==o||"nodeName"==o||o in n||e.removeAttribute(o);for(let o in n)"class"!=o&&"style"!=o&&"nodeName"!=o&&n[o]!=t[o]&&e.setAttribute(o,n[o]);if(t.class!=n.class){let o=t.class?t.class.split(" ").filter(Boolean):[],r=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<o.length;t++)-1==r.indexOf(o[t])&&e.classList.remove(o[t]);for(let t=0;t<r.length;t++)-1==o.indexOf(r[t])&&e.classList.add(r[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n,o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;n=o.exec(t.style);)e.style.removeProperty(n[1])}n.style&&(e.style.cssText+=n.style)}}function ls(e,t,n){return is(e,e,ns,rs(t,n,1!=e.nodeType))}function as(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 cs(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class ds{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,o=n.children.length,r=e.childCount,i=new Map,s=[];e:for(;r>0;){let l;for(;;)if(o){let e=n.children[o-1];if(!(e instanceof Xi)){l=e,o--;break}n=e,o=e.children.length}else{if(n==t)break e;o=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=e.child(r-1))break;--r,i.set(l,r),s.push(l)}}return{index:r,matched:i,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 o=0,r=this.stack.length>>1,i=Math.min(r,e.length);for(;o<i&&(o==r-1?this.top:this.stack[o+1<<1]).matchesMark(e[o])&&!1!==e[o].type.spec.spanning;)o++;for(;o<r;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),r--;for(;r<e.length;){this.stack.push(this.top,this.index+1);let o=-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[r])&&!this.isLocked(n.dom)){o=t;break}}if(o>-1)o>this.index&&(this.changed=!0,this.destroyBetween(this.index,o)),this.top=this.top.children[this.index];else{let o=Xi.create(this.top,e[r],t,n);this.top.children.splice(this.index,0,o),this.top=o,this.changed=!0}this.index=0,r++}}findNodeMatch(e,t,n,o){let r,i=-1;if(o>=this.preMatch.index&&(r=this.preMatch.matches[o-this.preMatch.index]).parent==this.top&&r.matchesNode(e,t,n))i=this.top.children.indexOf(r,this.index);else for(let o=this.index,r=Math.min(this.top.children.length,o+5);o<r;o++){let r=this.top.children[o];if(r.matchesNode(e,t,n)&&!this.preMatch.matched.has(r)){i=o;break}}return!(i<0||(this.destroyBetween(this.index,i),this.index++,0))}updateNodeAt(e,t,n,o,r){let i=this.top.children[o];return 3==i.dirty&&i.dom==i.contentDOM&&(i.dirty=2),!!i.update(e,t,n,r)&&(this.destroyBetween(this.index,o),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,o,r,i){for(let s=this.index;s<this.top.children.length;s++){let l=this.top.children[s];if(l instanceof Ui){let a=this.preMatch.matched.get(l);if(null!=a&&a!=r)return!1;let c,d=l.dom,h=this.isLocked(d)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&3!=l.dirty&&as(t,l.outerDeco));if(!h&&l.update(e,t,n,o))return this.destroyBetween(this.index,s),l.dom!=d&&(this.changed=!0),this.index++,!0;if(!h&&(c=this.recreateWrapper(l,e,t,n,o,i)))return this.destroyBetween(this.index,s),this.top.children[this.index]=c,c.contentDOM&&(c.dirty=2,c.updateChildren(o,i+1),c.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,o,r,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!as(n,e.outerDeco)||!o.eq(e.innerDeco))return null;let s=Ui.create(this.top,t,n,o,r,i);if(s.contentDOM){s.children=e.children,e.children=[];for(let e of s.children)e.parent=s}return e.destroy(),s}addNode(e,t,n,o,r){let i=Ui.create(this.top,e,t,n,o,r);i.contentDOM&&i.updateChildren(o,r+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,n){let o=this.index<this.top.children.length?this.top.children[this.index]:null;if(!o||!o.matchesWidget(e)||e!=o.widget&&o.widget.type.toDOM.parentNode){let o=new Ji(this.top,e,t,n);this.top.children.splice(this.index++,0,o),this.changed=!0}else this.index++}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Xi;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Yi)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((gi||fi)&&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 o=new Qi(this.top,[],n,null);t!=this.top?t.children.push(o):t.children.splice(this.index++,0,o),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function hs(e,t){return e.type.side-t.type.side}function ps(e,t,n,o,r){let i=[];for(let s=0,l=0;s<e.length;s++){let a=e[s],c=l,d=l+=a.size;c>=n||d<=t?i.push(a):(c<t&&i.push(a.slice(0,t-c,o)),r&&(i.push(r),r=void 0),d>n&&i.push(a.slice(n-c,a.size,o)))}return i}function us(e,t=null){let n=e.domSelectionRange(),o=e.state.doc;if(!n.focusNode)return null;let r=e.docView.nearestDesc(n.focusNode),i=r&&0==r.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l,a,c=o.resolve(s);if(ni(n)){for(l=s;r&&!r.node;)r=r.parent;let e=r.node;if(r&&e.isAtom&&dt.isSelectable(e)&&r.parent&&(!e.isInline||!function(e,t,n){for(let o=0==t,r=t==ei(e);o||r;){if(e==n)return!0;let t=Kr(e);if(!(e=e.parentNode))return!1;o=o&&0==t,r=r&&t==ei(e)}}(n.focusNode,n.focusOffset,r.dom))){let e=r.posBefore;a=new dt(s==e?c:o.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=s,r=s;for(let o=0;o<n.rangeCount;o++){let i=n.getRangeAt(o);t=Math.min(t,e.docView.posFromDOM(i.startContainer,i.startOffset,1)),r=Math.max(r,e.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(t<0)return null;[l,s]=r==e.state.selection.anchor?[r,t]:[t,r],c=o.resolve(s)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=o.resolve(l);return a||(a=xs(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!i?1:-1)),a}function fs(e){return e.editable?e.hasFocus():Cs(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function ms(e,t=!1){let n=e.state.selection;if(bs(e,n),fs(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&fi){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&Yr(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();if(!t)return;let n=e.cursorWrapper.dom,o="IMG"==n.nodeName;o?t.collapse(n.parentNode,Kr(n)+1):t.collapse(n,0),!o&&!e.state.selection.visible&&di&&hi<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let o,r,{anchor:i,head:s}=n;!gs||n instanceof at||(n.$from.parent.inlineContent||(o=ys(e,n.from)),n.empty||n.$from.parent.inlineContent||(r=ys(e,n.to))),e.docView.setSelection(i,s,e,t),gs&&(o&&vs(o),r&&vs(r)),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(),o=n.anchorNode,r=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==o&&n.anchorOffset==r||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{fs(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const gs=gi||fi&&mi<63;function ys(e,t){let{node:n,offset:o}=e.docView.domFromPos(t,0),r=o<n.childNodes.length?n.childNodes[o]:null,i=o?n.childNodes[o-1]:null;if(gi&&r&&"false"==r.contentEditable)return ws(r);if(!(r&&"false"!=r.contentEditable||i&&"false"!=i.contentEditable)){if(r)return ws(r);if(i)return ws(i)}}function ws(e){return e.contentEditable="true",gi&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function vs(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function bs(e,t){if(t instanceof dt){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(ks(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else ks(e)}function ks(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function xs(e,t,n,o){return e.someProp("createSelectionBetween",o=>o(e,t,n))||at.between(t,n,o)}function Ss(e){return!(e.editable&&!e.hasFocus())&&Cs(e)}function Cs(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 Ms(e,t){let{$anchor:n,$head:o}=e.selection,r=t>0?n.max(o):n.min(o),i=r.parent.inlineContent?r.depth?e.doc.resolve(t>0?r.after():r.before()):null:r;return i&&rt.findFrom(i,t)}function Ns(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Os(e,t,n){let o=e.state.selection;if(!(o instanceof at)){if(o instanceof dt&&o.node.isInline)return Ns(e,new at(t>0?o.$to:o.$from));{let n=Ms(e.state,t);return!!n&&Ns(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=o,r=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+r.nodeSize*(t<0?-1:1));return Ns(e,new at(o.$anchor,i))}if(!o.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ms(e.state,t);return!!(n&&n instanceof dt)&&Ns(e,n)}if(!(wi&&n.indexOf("m")>-1)){let n,r=o.$head,i=r.textOffset?null:t<0?r.nodeBefore:r.nodeAfter;if(!i||i.isText)return!1;let s=t<0?r.pos-i.nodeSize:r.pos;return!!(i.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(dt.isSelectable(i)?Ns(e,new dt(t<0?e.state.doc.resolve(r.pos-i.nodeSize):r)):!!ki&&Ns(e,new at(e.state.doc.resolve(t<0?s:s+i.nodeSize))))}}function As(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Ts(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function Ds(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=!1;for(pi&&1==n.nodeType&&o<As(n)&&Ts(n.childNodes[o],-1)&&(s=!0);;)if(o>0){if(1!=n.nodeType)break;{let e=n.childNodes[o-1];if(Ts(e,-1))r=n,i=--o;else{if(3!=e.nodeType)break;n=e,o=n.nodeValue.length}}}else{if(Es(n))break;{let t=n.previousSibling;for(;t&&Ts(t,-1);)r=n.parentNode,i=Kr(t),t=t.previousSibling;if(t)n=t,o=As(n);else{if(n=n.parentNode,n==e.dom)break;o=0}}}s?Rs(e,n,o):r&&Rs(e,r,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=As(n);for(;;)if(o<s){if(1!=n.nodeType)break;if(!Ts(n.childNodes[o],1))break;r=n,i=++o}else{if(Es(n))break;{let t=n.nextSibling;for(;t&&Ts(t,1);)r=t.parentNode,i=Kr(t)+1,t=t.nextSibling;if(t)n=t,o=0,s=As(n);else{if(n=n.parentNode,n==e.dom)break;o=s=0}}}r&&Rs(e,r,i)}(e)}function Es(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Rs(e,t,n){if(3!=t.nodeType){let e,o;(o=function(e,t){for(;e&&t==e.childNodes.length&&!ti(e);)t=Kr(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=o,n=0):(e=function(e,t){for(;e&&!t&&!ti(e);)t=Kr(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let o=e.domSelection();if(!o)return;if(ni(o)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),o.removeAllRanges(),o.addRange(e)}else o.extend&&o.extend(t,n);e.domObserver.setCurSelection();let{state:r}=e;setTimeout(()=>{e.state==r&&ms(e)},50)}function $s(e,t){let n=e.state.doc.resolve(t);if(!fi&&!vi&&n.parent.inlineContent){let o=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left<o.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left>o.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Is(e,t,n){let o=e.state.selection;if(o instanceof at&&!o.empty||n.indexOf("s")>-1)return!1;if(wi&&n.indexOf("m")>-1)return!1;let{$from:r,$to:i}=o;if(!r.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ms(e.state,t);if(n&&n instanceof dt)return Ns(e,n)}if(!r.parent.inlineContent){let n=t<0?r:i,s=o instanceof pt?rt.near(n,t):rt.findFrom(n,t);return!!s&&Ns(e,s)}return!1}function zs(e,t){if(!(e.state.selection instanceof at))return!0;let{$head:n,$anchor:o,empty:r}=e.state.selection;if(!n.sameParent(o))return!0;if(!r)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let o=e.state.tr;return t<0?o.delete(n.pos-i.nodeSize,n.pos):o.delete(n.pos,n.pos+i.nodeSize),e.dispatch(o),!0}return!1}function Bs(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Ps(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:o,openStart:r,openEnd:i}=t;for(;r>1&&i>1&&1==o.childCount&&1==o.firstChild.childCount;){r--,i--;let e=o.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),o=e.content}let s=e.someProp("clipboardSerializer")||le.fromSchema(e.state.schema),l=Ks(),a=l.createElement("div");a.appendChild(s.serializeFragment(o,{document:l}));let c,d=a.firstChild,h=0;for(;d&&1==d.nodeType&&(c=js[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=l.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),h++}d=a.firstChild}return d&&1==d.nodeType&&d.setAttribute("data-pm-slice",`${r} ${i}${h?` -${h}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function Vs(e,t,n,o,r){let i,l,a=r.parent.type.spec.code;if(!n&&!t)return null;let c=!!t&&(o||a||!n);if(c){if(e.someProp("transformPastedText",n=>{t=n(t,a||o,e)}),a)return l=new p(s.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{l=t(l,e,!0)}),l;let n=e.someProp("clipboardTextParser",n=>n(t,r,o,e));if(n)l=n;else{let n=r.marks(),{schema:o}=e.state,s=le.fromSchema(o);i=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=i.appendChild(document.createElement("p"));e&&t.appendChild(s.serializeNode(o.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),i=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,o=Ks().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(e);if((n=r&&js[r[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join("")),o.innerHTML=function(e){let t=window.trustedTypes;return t?(Xs||(Xs=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),Xs.createHTML(e)):e}(e),n)for(let e=0;e<n.length;e++)o=o.querySelector(n[e])||o;return o}(n),ki&&function(e){let t=e.querySelectorAll(fi?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let o=t[n];1==o.childNodes.length&&" "==o.textContent&&o.parentNode&&o.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),o)}}(i);let d=i&&i.querySelector("[data-pm-slice]"),h=d&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(d.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let e=+h[3];e>0;e--){let e=i.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;i=e}if(!l){let t=e.someProp("clipboardParser")||e.someProp("domParser")||Y.fromSchema(e.state.schema);l=t.parseSlice(i,{preserveWhitespace:!(!c&&!h),context:r,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||Fs.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(h)l=function(e,t){if(!e.size)return e;let n,o=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(t){return e}let{content:r,openStart:i,openEnd:l}=e;for(let e=n.length-2;e>=0;e-=2){let t=o.nodes[n[e]];if(!t||t.hasRequiredAttrs())break;r=s.from(t.create(n[e+1],r)),i++,l++}return new p(r,i,l)}(qs(l,+h[1],+h[2]),h[4]);else if(l=p.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let o,r=t.node(n).contentMatchAt(t.index(n)),i=[];if(e.forEach(e=>{if(!i)return;let t,n=r.findWrapping(e.type);if(!n)return i=null;if(t=i.length&&o.length&&Hs(n,o,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=_s(i[i.length-1],o.length));let t=Ls(e,n);i.push(t),r=r.matchType(t.type),o=n}}),i)return s.from(i)}return e}(l.content,r),!0),l.openStart||l.openEnd){let e=0,t=0;for(let t=l.content.firstChild;e<l.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=l.content.lastChild;t<l.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);l=qs(l,e,t)}return e.someProp("transformPasted",t=>{l=t(l,e,c)}),l}const Fs=/^(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 Ls(e,t,n=0){for(let o=t.length-1;o>=n;o--)e=t[o].create(null,s.from(e));return e}function Hs(e,t,n,o,r){if(r<e.length&&r<t.length&&e[r]==t[r]){let i=Hs(e,t,n,o.lastChild,r+1);if(i)return o.copy(o.content.replaceChild(o.childCount-1,i));if(o.contentMatchAt(o.childCount).matchType(r==e.length-1?n.type:e[r+1]))return o.copy(o.content.append(s.from(Ls(n,e,r+1))))}}function _s(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,_s(e.lastChild,t-1)),o=e.contentMatchAt(e.childCount).fillBefore(s.empty,!0);return e.copy(n.append(o))}function Ws(e,t,n,o,r,i){let l=t<0?e.firstChild:e.lastChild,a=l.content;return e.childCount>1&&(i=0),r<o-1&&(a=Ws(a,t,n,o,r+1,i)),r>=n&&(a=t<0?l.contentMatchAt(0).fillBefore(a,i<=r).append(a):a.append(l.contentMatchAt(l.childCount).fillBefore(s.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,l.copy(a))}function qs(e,t,n){return t<e.openStart&&(e=new p(Ws(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new p(Ws(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}const js={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 Js=null;function Ks(){return Js||(Js=document.implementation.createHTMLDocument("title"))}let Xs=null;const Us={},Gs={},Ys={touchstart:!0,touchmove:!0};class Qs{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Zs(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function el(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>tl(e,t))})}function tl(e,t){return e.someProp("handleDOMEvents",n=>{let o=n[t.type];return!!o&&(o(e,t)||t.defaultPrevented)})}function nl(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 ol(e){return{left:e.clientX,top:e.clientY}}function rl(e,t,n,o,r){if(-1==o)return!1;let i=e.state.doc.resolve(o);for(let o=i.depth+1;o>0;o--)if(e.someProp(t,t=>o>i.depth?t(e,n,i.nodeAfter,i.before(o),r,!0):t(e,n,i.node(o),i.before(o),r,!1)))return!0;return!1}function il(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let o=e.state.tr.setSelection(t);"pointer"==n&&o.setMeta("pointer",!0),e.dispatch(o)}function sl(e,t,n,o){return rl(e,"handleDoubleClickOn",t,n,o)||e.someProp("handleDoubleClick",n=>n(e,t,o))}function ll(e,t,n,o){return rl(e,"handleTripleClickOn",t,n,o)||e.someProp("handleTripleClick",n=>n(e,t,o))||function(e,t,n){if(0!=n.button)return!1;let o=e.state.doc;if(-1==t)return!!o.inlineContent&&(il(e,at.create(o,0,o.content.size),"pointer"),!0);let r=o.resolve(t);for(let t=r.depth+1;t>0;t--){let n=t>r.depth?r.nodeAfter:r.node(t),i=r.before(t);if(n.inlineContent)il(e,at.create(o,i+1,i+1+n.content.size),"pointer");else{if(!dt.isSelectable(n))continue;il(e,dt.create(o,i),"pointer")}return!0}}(e,n,o)}function al(e){return ml(e)}Gs.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!hl(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!bi||!fi||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!yi||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||function(e,t){let n=t.keyCode,o=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||wi&&72==n&&"c"==o)return zs(e,-1)||Ds(e,-1);if(46==n&&!t.shiftKey||wi&&68==n&&"c"==o)return zs(e,1)||Ds(e,1);if(13==n||27==n)return!0;if(37==n||wi&&66==n&&"c"==o){let t=37==n?"ltr"==$s(e,e.state.selection.from)?-1:1:-1;return Os(e,t,o)||Ds(e,t)}if(39==n||wi&&70==n&&"c"==o){let t=39==n?"ltr"==$s(e,e.state.selection.from)?1:-1:1;return Os(e,t,o)||Ds(e,t)}return 38==n||wi&&80==n&&"c"==o?Is(e,-1,o)||Ds(e,-1):40==n||wi&&78==n&&"c"==o?function(e){if(!gi||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;Bs(e,n,"true"),setTimeout(()=>Bs(e,n,"false"),20)}return!1}(e)||Is(e,1,o)||Ds(e,1):o==(wi?"m":"c")&&(66==n||73==n||89==n||90==n)}(e,n)?n.preventDefault():Zs(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,oi(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},Gs.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},Gs.keypress=(e,t)=>{let n=t;if(hl(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||wi&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let o=e.state.selection;if(!(o instanceof at&&o.$from.sameParent(o.$to))){let t=String.fromCharCode(n.charCode),r=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",n=>n(e,o.$from.pos,o.$to.pos,t,r))||e.dispatch(r()),n.preventDefault()}};const cl=wi?"metaKey":"ctrlKey";Us.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let o=al(e),r=Date.now(),i="singleClick";r-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,o=t.y-e.clientY;return n*n+o*o<100}(n,e.input.lastClick)&&!n[cl]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:r,x:n.clientX,y:n.clientY,type:i,button:n.button};let s=e.posAtCoords(ol(n));s&&("singleClick"==i?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new dl(e,s,n,!!o)):("doubleClick"==i?sl:ll)(e,s.pos,s.inside,n)?n.preventDefault():Zs(e,"pointer"))};class dl{constructor(e,t,n,o){let r,i;if(this.view=e,this.pos=t,this.event=n,this.flushed=o,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[cl],this.allowDefault=n.shiftKey,t.inside>-1)r=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);r=n.parent,i=n.depth?n.before():0}const s=o?null:n.target,l=s?e.docView.nearestDesc(s,!0):null;this.target=l&&1==l.nodeDOM.nodeType?l.nodeDOM:null;let{selection:a}=e.state;(0==n.button&&r.type.spec.draggable&&!1!==r.type.spec.selectable||a instanceof dt&&a.from<=i&&a.to>i)&&(this.mightDrag={node:r,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!pi||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)),Zs(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(()=>ms(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(ol(e))),this.updateAllowDefault(e),this.allowDefault||!t?Zs(this.view,"pointer"):function(e,t,n,o,r){return rl(e,"handleClickOn",t,n,o)||e.someProp("handleClick",n=>n(e,t,o))||(r?function(e,t){if(-1==t)return!1;let n,o,r=e.state.selection;r instanceof dt&&(n=r.node);let i=e.state.doc.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e);if(dt.isSelectable(t)){o=n&&r.$from.depth>0&&e>=r.$from.depth&&i.before(r.$from.depth+1)==r.$from.pos?i.before(r.$from.depth):i.before(e);break}}return null!=o&&(il(e,dt.create(e.state.doc,o),"pointer"),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),o=n.nodeAfter;return!!(o&&o.isAtom&&dt.isSelectable(o))&&(il(e,new dt(n),"pointer"),!0)}(e,n))}(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||gi&&this.mightDrag&&!this.mightDrag.node.isAtom||fi&&!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)?(il(this.view,rt.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Zs(this.view,"pointer")}move(e){this.updateAllowDefault(e),Zs(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 hl(e,t){return!!e.composing||!!(gi&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}Us.touchstart=e=>{e.input.lastTouch=Date.now(),al(e),Zs(e,"pointer")},Us.touchmove=e=>{e.input.lastTouch=Date.now(),Zs(e,"pointer")},Us.contextmenu=e=>al(e);const pl=bi?5e3:-1;function ul(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>ml(e),t))}function fl(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 ml(e,t=!1){if(!(bi&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),fl(e),t||e.docView&&e.docView.dirty){let n=us(e),o=e.state.selection;return n&&!n.eq(o)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}Gs.compositionstart=Gs.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof at&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)))e.markCursor=e.state.storedMarks||n.marks(),ml(e,!0),e.markCursor=null;else if(ml(e,!t.selection.empty),pi&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,o=t.focusOffset;n&&1==n.nodeType&&0!=o;){let t=o<0?n.lastChild:n.childNodes[o-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,o=-1}}e.input.composing=!0}ul(e,pl)},Gs.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,ul(e,20))};const gl=di&&hi<15||yi&&xi<604;function yl(e,t,n,o,r){let i=Vs(e,t,n,o,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,r,i||p.empty)))return!0;if(!i)return!1;let s=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=s?e.state.tr.replaceSelectionWith(s,o):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function wl(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Us.copy=Gs.cut=(e,t)=>{let n=t,o=e.state.selection,r="cut"==n.type;if(o.empty)return;let i=gl?null:n.clipboardData,s=o.content(),{dom:l,text:a}=Ps(e,s);i?(n.preventDefault(),i.clearData(),i.setData("text/html",l.innerHTML),i.setData("text/plain",a)):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 o=getSelection(),r=document.createRange();r.selectNodeContents(t),e.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,l),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Gs.paste=(e,t)=>{let n=t;if(e.composing&&!bi)return;let o=gl?null:n.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;o&&yl(e,wl(o),o.getData("text/html"),r,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,o=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),o.parentNode&&o.parentNode.removeChild(o),n?yl(e,o.value,null,r,t):yl(e,o.textContent,o.innerHTML,r,t)},50)}(e,n)};class vl{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const bl=wi?"altKey":"ctrlKey";function kl(e,t){let n=e.someProp("dragCopies",e=>!e(t));return null!=n?n:!t[bl]}Us.dragstart=(e,t)=>{let n=t,o=e.input.mouseDown;if(o&&o.done(),!n.dataTransfer)return;let r,i=e.state.selection,s=i.empty?null:e.posAtCoords(ol(n));if(s&&s.pos>=i.from&&s.pos<=(i instanceof dt?i.to-1:i.to));else if(o&&o.mightDrag)r=dt.create(e.state.doc,o.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&&(r=dt.create(e.state.doc,t.posBefore))}let l=(r||e.state.selection).content(),{dom:a,text:c,slice:d}=Ps(e,l);(!n.dataTransfer.files.length||!fi||mi>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(gl?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",gl||n.dataTransfer.setData("text/plain",c),e.dragging=new vl(d,kl(e,n),r)},Us.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},Gs.dragover=Gs.dragenter=(e,t)=>t.preventDefault(),Gs.drop=(e,t)=>{let n=t,o=e.dragging;if(e.dragging=null,!n.dataTransfer)return;let r=e.posAtCoords(ol(n));if(!r)return;let i=e.state.doc.resolve(r.pos),s=o&&o.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=Vs(e,wl(n.dataTransfer),gl?null:n.dataTransfer.getData("text/html"),!1,i);let l=!(!o||!kl(e,n));if(e.someProp("handleDrop",t=>t(e,n,s||p.empty,l)))return void n.preventDefault();if(!s)return;n.preventDefault();let a=s?He(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let c=e.state.tr;if(l){let{node:e}=o;e?e.replace(c):c.deleteSelection()}let d=c.mapping.map(a),h=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,u=c.doc;if(h?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(u))return;let f=c.doc.resolve(d);if(h&&dt.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new dt(f));else{let t=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,o,r)=>t=r),c.setSelection(xs(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta("uiEvent","drop"))},Us.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())&&ms(e)},20))},Us.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)},Us.beforeinput=(e,t)=>{if(fi&&bi&&"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,oi(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 Gs)Us[e]=Gs[e];function xl(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 Sl{constructor(e,t){this.toDOM=e,this.spec=t||Al,this.side=this.spec.side||0}map(e,t,n,o){let{pos:r,deleted:i}=e.mapResult(t.from+o,this.side<0?-1:1);return i?null:new Nl(r-n,r-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Sl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&xl(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Cl{constructor(e,t){this.attrs=e,this.spec=t||Al}map(e,t,n,o){let r=e.map(t.from+o,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+o,this.spec.inclusiveEnd?1:-1)-n;return r>=i?null:new Nl(r,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Cl&&xl(this.attrs,e.attrs)&&xl(this.spec,e.spec)}static is(e){return e.type instanceof Cl}destroy(){}}class Ml{constructor(e,t){this.attrs=e,this.spec=t||Al}map(e,t,n,o){let r=e.mapResult(t.from+o,1);if(r.deleted)return null;let i=e.mapResult(t.to+o,-1);return i.deleted||i.pos<=r.pos?null:new Nl(r.pos-n,i.pos-n,this)}valid(e,t){let n,{index:o,offset:r}=e.content.findIndex(t.from);return r==t.from&&!(n=e.child(o)).isText&&r+n.nodeSize==t.to}eq(e){return this==e||e instanceof Ml&&xl(this.attrs,e.attrs)&&xl(this.spec,e.spec)}destroy(){}}class Nl{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Nl(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 Nl(e,e,new Sl(t,n))}static inline(e,t,n,o){return new Nl(e,t,new Cl(n,o))}static node(e,t,n,o){return new Nl(e,t,new Ml(n,o))}get spec(){return this.type.spec}get inline(){return this.type instanceof Cl}get widget(){return this.type instanceof Sl}}const Ol=[],Al={};class Tl{constructor(e,t){this.local=e.length?e:Ol,this.children=t.length?t:Ol}static create(e,t){return t.length?zl(t,e,0,Al):Dl}find(e,t,n){let o=[];return this.findInner(null==e?0:e,null==t?1e9:t,o,0,n),o}findInner(e,t,n,o,r){for(let i=0;i<this.local.length;i++){let s=this.local[i];s.from<=t&&s.to>=e&&(!r||r(s.spec))&&n.push(s.copy(s.from+o,s.to+o))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let s=this.children[i]+1;this.children[i+2].findInner(e-s,t-s,n,o+s,r)}}map(e,t,n){return this==Dl||0==e.maps.length?this:this.mapInner(e,t,0,0,n||Al)}mapInner(e,t,n,o,r){let i;for(let s=0;s<this.local.length;s++){let l=this.local[s].map(e,n,o);l&&l.type.valid(t,l)?(i||(i=[])).push(l):r.onRemove&&r.onRemove(this.local[s].spec)}return this.children.length?function(e,t,n,o,r,i,s){let l=e.slice();for(let e=0,t=i;e<n.maps.length;e++){let o=0;n.maps[e].forEach((e,n,r,i)=>{let s=i-r-(n-e);for(let r=0;r<l.length;r+=3){let i=l[r+1];if(i<0||e>i+t-o)continue;let a=l[r]+t-o;n>=a?l[r+1]=e<=a?-2:-1:e>=t&&s&&(l[r]+=s,l[r+1]+=s)}o+=s}),t=n.maps[e].map(t,-1)}let a=!1;for(let t=0;t<l.length;t+=3)if(l[t+1]<0){if(-2==l[t+1]){a=!0,l[t+1]=-1;continue}let c=n.map(e[t]+i),d=c-r;if(d<0||d>=o.content.size){a=!0;continue}let h=n.map(e[t+1]+i,-1)-r,{index:p,offset:u}=o.content.findIndex(d),f=o.maybeChild(p);if(f&&u==d&&u+f.nodeSize==h){let o=l[t+2].mapInner(n,f,c+1,e[t]+i+1,s);o!=Dl?(l[t]=d,l[t+1]=h,l[t+2]=o):(l[t+1]=-2,a=!0)}else a=!0}if(a){let a=function(e,t,n,o,r,i,s){function l(e,t){for(let i=0;i<e.local.length;i++){let l=e.local[i].map(o,r,t);l?n.push(l):s.onRemove&&s.onRemove(e.local[i].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)-1==e[n+1]&&l(e[n+2],t[n]+i+1);return n}(l,e,t,n,r,i,s),c=zl(a,o,0,s);t=c.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new Tl(t.sort(Bl),l)}(this.children,i||[],e,t,n,o,r):i?new Tl(i.sort(Bl),Ol):Dl}add(e,t){return t.length?this==Dl?Tl.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let o,r=0;e.forEach((e,i)=>{let s,l=i+n;if(s=$l(t,e,l)){for(o||(o=this.children.slice());r<o.length&&o[r]<i;)r+=3;o[r]==i?o[r+2]=o[r+2].addInner(e,s,l+1):o.splice(r,0,i,i+e.nodeSize,zl(s,e,l+1,Al)),r+=3}});let i=Rl(r?Il(t):t,-n);for(let t=0;t<i.length;t++)i[t].type.valid(e,i[t])||i.splice(t--,1);return new Tl(i.length?this.local.concat(i).sort(Bl):this.local,o||this.children)}remove(e){return 0==e.length||this==Dl?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,o=this.local;for(let o=0;o<n.length;o+=3){let r,i=n[o]+t,s=n[o+1]+t;for(let t,n=0;n<e.length;n++)(t=e[n])&&t.from>i&&t.to<s&&(e[n]=null,(r||(r=[])).push(t));if(!r)continue;n==this.children&&(n=this.children.slice());let l=n[o+2].removeInner(r,i+1);l!=Dl?n[o+2]=l:(n.splice(o,3),o-=3)}if(o.length)for(let n,r=0;r<e.length;r++)if(n=e[r])for(let e=0;e<o.length;e++)o[e].eq(n,t)&&(o==this.local&&(o=this.local.slice()),o.splice(e--,1));return n==this.children&&o==this.local?this:o.length||n.length?new Tl(o,n):Dl}forChild(e,t){if(this==Dl)return this;if(t.isLeaf)return Tl.empty;let n,o;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 r=e+1,i=r+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<i&&t.to>r&&t.type instanceof Cl){let e=Math.max(r,t.from)-r,n=Math.min(i,t.to)-r;e<n&&(o||(o=[])).push(t.copy(e,n))}}if(o){let e=new Tl(o.sort(Bl),Ol);return n?new El([e,n]):e}return n||Dl}eq(e){if(this==e)return!0;if(!(e instanceof Tl)||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 Pl(this.localsInner(e))}localsInner(e){if(this==Dl)return Ol;if(e.inlineContent||!this.local.some(Cl.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof Cl||t.push(this.local[e]);return t}forEachSet(e){e(this)}}Tl.empty=new Tl([],[]),Tl.removeOverlap=Pl;const Dl=Tl.empty;class El{constructor(e){this.members=e}map(e,t){const n=this.members.map(n=>n.map(e,t,Al));return El.from(n)}forChild(e,t){if(t.isLeaf)return Tl.empty;let n=[];for(let o=0;o<this.members.length;o++){let r=this.members[o].forChild(e,t);r!=Dl&&(r instanceof El?n=n.concat(r.members):n.push(r))}return El.from(n)}eq(e){if(!(e instanceof El)||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 o=0;o<this.members.length;o++){let r=this.members[o].localsInner(e);if(r.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<r.length;e++)t.push(r[e])}else t=r}return t?Pl(n?t:t.sort(Bl)):Ol}static from(e){switch(e.length){case 0:return Dl;case 1:return e[0];default:return new El(e.every(e=>e instanceof Tl)?e:e.reduce((e,t)=>e.concat(t instanceof Tl?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Rl(e,t){if(!t||!e.length)return e;let n=[];for(let o=0;o<e.length;o++){let r=e[o];n.push(new Nl(r.from+t,r.to+t,r.type))}return n}function $l(e,t,n){if(t.isLeaf)return null;let o=n+t.nodeSize,r=null;for(let t,i=0;i<e.length;i++)(t=e[i])&&t.from>n&&t.to<o&&((r||(r=[])).push(t),e[i]=null);return r}function Il(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function zl(e,t,n,o){let r=[],i=!1;t.forEach((t,s)=>{let l=$l(e,t,s+n);if(l){i=!0;let e=zl(l,t,n+s+1,o);e!=Dl&&r.push(s,s+t.nodeSize,e)}});let s=Rl(i?Il(e):e,-n).sort(Bl);for(let e=0;e<s.length;e++)s[e].type.valid(t,s[e])||(o.onRemove&&o.onRemove(s[e].spec),s.splice(e--,1));return s.length||r.length?new Tl(s,r):Dl}function Bl(e,t){return e.from-t.from||e.to-t.to}function Pl(e){let t=e;for(let n=0;n<t.length-1;n++){let o=t[n];if(o.from!=o.to)for(let r=n+1;r<t.length;r++){let i=t[r];if(i.from!=o.from){i.from<o.to&&(t==e&&(t=e.slice()),t[n]=o.copy(o.from,i.from),Vl(t,r,o.copy(i.from,o.to)));break}i.to!=o.to&&(t==e&&(t=e.slice()),t[r]=i.copy(i.from,o.to),Vl(t,r+1,i.copy(o.to,i.to)))}}return t}function Vl(e,t,n){for(;t<e.length&&Bl(n,e[t])>0;)t++;e.splice(t,0,n)}function Fl(e){let t=[];return e.someProp("decorations",n=>{let o=n(e.state);o&&o!=Dl&&t.push(o)}),e.cursorWrapper&&t.push(Tl.create(e.state.doc,[e.cursorWrapper.deco])),El.from(t)}const Ll={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Hl=di&&hi<=11;class _l{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 Wl{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new _l,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);di&&hi<=11&&e.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),Hl&&(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,Ll)),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(Ss(this.view)){if(this.suppressingSelectionUpdates)return ms(this.view);if(di&&hi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Yr(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=Xr(t))n.add(t);for(let o=e.anchorNode;o;o=Xr(o))if(n.has(o)){t=o;break}let o=t&&this.view.docView.nearestDesc(t);return o&&o.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),o=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Ss(e)&&!this.ignoreSelectionChange(n),r=-1,i=-1,s=!1,l=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],l);n&&(r=r<0?n.from:Math.min(n.from,r),i=i<0?n.to:Math.max(n.to,i),n.typeOver&&(s=!0))}if(pi&&l.length){let t=l.filter(e=>"BR"==e.nodeName);if(2==t.length){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let o of t){let t=o.parentNode;!t||"LI"!=t.nodeName||n&&Kl(e,n)==t||o.remove()}}}let a=null;r<0&&o&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&ni(n)&&(a=us(e))&&a.eq(rt.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ms(e),this.currentSelection.set(n),e.scrollToSelection()):(r>-1||o)&&(r>-1&&(e.docView.markDirty(r,i),function(e){if(!ql.has(e)&&(ql.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))){if(e.requiresGeckoHackNode=pi,jl)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."),jl=!0}}(e)),this.handleDOMChange(r,i,s,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ms(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++){let o=e.addedNodes[n];t.push(o),3==o.nodeType&&(this.lastChangedTextNode=o)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let o=e.previousSibling,r=e.nextSibling;if(di&&hi<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:i}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(o=n),(!i||Array.prototype.indexOf.call(e.addedNodes,i)<0)&&(r=i)}let i=o&&o.parentNode==e.target?Kr(o)+1:0,s=n.localPosFromDOM(e.target,i,-1),l=r&&r.parentNode==e.target?Kr(r):e.target.childNodes.length;return{from:s,to:n.localPosFromDOM(e.target,l,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let ql=new WeakMap,jl=!1;function Jl(e,t){let n=t.startContainer,o=t.startOffset,r=t.endContainer,i=t.endOffset,s=e.domAtPos(e.state.selection.anchor);return Yr(s.node,s.offset,r,i)&&([n,o,r,i]=[r,i,n,o]),{anchorNode:n,anchorOffset:o,focusNode:r,focusOffset:i}}function Kl(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function Xl(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(gi&&/^(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||gi&&/^(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 Ul=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Gl(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:xs(e,t.resolve(n.anchor),t.resolve(n.head))}function Yl(e,t,n){let o=e.depth,r=t?e.end():e.pos;for(;o>0&&(t||e.indexAfter(o)==e.node(o).childCount);)o--,r++,t=!1;if(n){let t=e.node(o).maybeChild(e.indexAfter(o));for(;t&&!t.isLeaf;)t=t.firstChild,r++}return r}function Ql(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}const Zl=Vs,ea=ml;class ta{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 Qs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(sa),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=ra(this),oa(this),this.nodeViews=ia(this),this.docView=Gi(this.state.doc,na(this),Fl(this),this.dom,this),this.domObserver=new Wl(this,(e,t,n,o)=>function(e,t,n,o,r){let i=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=us(e,t);if(n&&!e.state.selection.eq(n)){if(fi&&bi&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oi(13,"Enter"))))return;let o=e.state.tr.setSelection(n);"pointer"==t?o.setMeta("pointer",!0):"key"==t&&o.scrollIntoView(),i&&o.setMeta("composition",i),e.dispatch(o)}return}let l=e.state.doc.resolve(t),a=l.sharedDepth(n);t=l.before(a+1),n=e.state.doc.resolve(n).after(a+1);let c,d,h=e.state.selection,p=function(e,t,n){let o,{node:r,fromOffset:i,toOffset:s,from:l,to:a}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(o=[{node:d,offset:c.anchorOffset}],ni(c)||o.push({node:c.focusNode,offset:c.focusOffset})),fi&&8===e.input.lastKeyCode)for(let e=s;e>i;e--){let t=r.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")||Y.fromSchema(e.state.schema),u=h.resolve(l),f=null,m=p.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:"pre"!=u.parent.type.whitespace||"full",findPositions:o,ruleFromNode:Xl,context:u});if(o&&null!=o[0].pos){let e=o[0].pos,t=o[1]&&o[1].pos;null==t&&(t=e),f={anchor:e+l,head:t+l}}return{doc:m,sel:f,from:l,to:a}}(e,t,n),u=e.state.doc,f=u.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(c=e.state.selection.to,d="end"):(c=e.state.selection.from,d="start"),e.input.lastKeyCode=null;let m=function(e,t,n,o,r){let i=e.findDiffStart(t,n);if(null==i)return null;let{a:s,b:l}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==r&&(o-=s+Math.max(0,i-Math.min(s,l))-i),s<i&&e.size<t.size){let e=o<=i&&o>=s?i-o:0;i-=e,i&&i<t.size&&Ql(t.textBetween(i-1,i+1))&&(i+=e?1:-1),l=i+(l-s),s=i}else if(l<i){let t=o<=i&&o>=l?i-o:0;i-=t,i&&i<e.size&&Ql(e.textBetween(i-1,i+1))&&(i+=t?1:-1),s=i+(s-l),l=i}return{start:i,endA:s,endB:l}}(f.content,p.doc.content,p.from,c,d);if(m&&e.input.domChangeCount++,(yi&&e.input.lastIOSEnter>Date.now()-225||bi)&&r.some(e=>1==e.nodeType&&!Ul.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",t=>t(e,oi(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(!m){if(!(o&&h instanceof at&&!h.empty&&h.$head.sameParent(h.$anchor))||e.composing||p.sel&&p.sel.anchor!=p.sel.head){if(p.sel){let t=Gl(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);i&&n.setMeta("composition",i),e.dispatch(n)}}return}m={start:h.from,endA:h.to,endB:h.to}}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof at&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),di&&hi<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g=p.doc.resolveNoCache(m.start-p.from),y=p.doc.resolveNoCache(m.endB-p.from),w=u.resolve(m.start),v=g.sameParent(y)&&g.parent.inlineContent&&w.end()>=m.endA;if((yi&&e.input.lastIOSEnter>Date.now()-225&&(!v||r.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!v&&g.pos<p.doc.content.size&&(!g.sameParent(y)||!g.parent.inlineContent)&&g.pos<y.pos&&!/\S/.test(p.doc.textBetween(g.pos,y.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oi(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>m.start&&function(e,t,n,o,r){if(n-t<=r.pos-o.pos||Yl(o,!0,!1)<r.pos)return!1;let i=e.resolve(t);if(!o.parent.isTextblock){let e=i.nodeAfter;return null!=e&&n==t+e.nodeSize}if(i.parentOffset<i.parent.content.size||!i.parent.isTextblock)return!1;let s=e.resolve(Yl(i,!0,!0));return!(!s.parent.isTextblock||s.pos>n||Yl(s,!0,!1)<n)&&o.parent.content.cut(o.parentOffset).eq(s.parent.content)}(u,m.start,m.endA,g,y)&&e.someProp("handleKeyDown",t=>t(e,oi(8,"Backspace"))))return void(bi&&fi&&e.domObserver.suppressSelectionUpdates());fi&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),bi&&!v&&g.start()!=y.start()&&0==y.parentOffset&&g.depth==y.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,y=p.doc.resolveNoCache(m.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oi(13,"Enter"))})},20));let b,k=m.start,x=m.endA,S=t=>{let n=t||e.state.tr.replace(k,x,p.doc.slice(m.start-p.from,m.endB-p.from));if(p.sel){let t=Gl(e,n.doc,p.sel);t&&!(fi&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==k||t.head==n.mapping.map(x)-1)||di&&t.empty&&t.head==k)&&n.setSelection(t)}return i&&n.setMeta("composition",i),n.scrollIntoView()};if(v)if(g.pos==y.pos){di&&hi<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>ms(e),20));let t=S(e.state.tr.delete(k,x)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(b=function(e,t){let n,o,r,i=e.firstChild.marks,l=t.firstChild.marks,a=i,c=l;for(let e=0;e<l.length;e++)a=l[e].removeFromSet(a);for(let e=0;e<i.length;e++)c=i[e].removeFromSet(c);if(1==a.length&&0==c.length)o=a[0],n="add",r=e=>e.mark(o.addToSet(e.marks));else{if(0!=a.length||1!=c.length)return null;o=c[0],n="remove",r=e=>e.mark(o.removeFromSet(e.marks))}let d=[];for(let e=0;e<t.childCount;e++)d.push(r(t.child(e)));if(s.from(d).eq(e))return{mark:o,type:n}}(g.parent.content.cut(g.parentOffset,y.parentOffset),w.parent.content.cut(w.parentOffset,m.endA-w.start())))){let t=S(e.state.tr);"add"==b.type?t.addMark(k,x,b.mark):t.removeMark(k,x,b.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let t=g.parent.textBetween(g.parentOffset,y.parentOffset),n=()=>S(e.state.tr.insertText(t,k,x));e.someProp("handleTextInput",o=>o(e,k,x,t,n))||e.dispatch(n())}else e.dispatch(S());else e.dispatch(S())}(this,e,t,n,o)),this.domObserver.start(),function(e){for(let t in Us){let n=Us[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!nl(e,t)||tl(e,t)||!e.editable&&t.type in Gs||n(e,t)},Ys[t]?{passive:!0}:void 0)}gi&&e.dom.addEventListener("input",()=>null),el(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&&el(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(sa),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){var n;let o=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(fl(this),i=!0),this.state=e;let s=o.plugins!=e.plugins||this._props.plugins!=t.plugins;if(s||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=ia(this);(function(e,t){let n=0,o=0;for(let o in e){if(e[o]!=t[o])return!0;n++}for(let e in t)o++;return n!=o})(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(s||t.handleDOMEvents!=this._props.handleDOMEvents)&&el(this),this.editable=ra(this),oa(this);let l=Fl(this),a=na(this),c=o.plugins==e.plugins||o.doc.eq(e.doc)?e.scrollToSelection>o.scrollToSelection?"to selection":"preserve":"reset",d=r||!this.docView.matchesNode(e.doc,a,l);!d&&e.selection.eq(o.selection)||(i=!0);let h="preserve"==c&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,o=e.dom.getBoundingClientRect(),r=Math.max(0,o.top);for(let i=(o.left+o.right)/2,s=r+1;s<Math.min(innerHeight,o.bottom);s+=5){let o=e.root.elementFromPoint(i,s);if(!o||o==e.dom||!e.dom.contains(o))continue;let l=o.getBoundingClientRect();if(l.top>=r-20){t=o,n=l.top;break}}return{refDOM:t,refTop:n,stack:Oi(e.dom)}}(this);if(i){this.domObserver.stop();let t=d&&(di||fi)&&!this.composing&&!o.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)}(o.selection,e.selection);if(d){let n=fi?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=ei(e=e.childNodes[t-1])}else{if(!e.parentNode||ti(e))return null;t=Kr(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),o=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||ti(e))return null;t=Kr(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&o&&n!=o){let t=o.pmViewDesc,r=e.domObserver.lastChangedTextNode;if(n==r||o==r)return r;if(!t||!t.isText(o.nodeValue))return o;if(e.input.compositionNode==o){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return o}}return n||o}(this)),!r&&this.docView.update(e.doc,a,l,this)||(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Gi(e.doc,a,l,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 Yr(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?ms(this,t):(bs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(o),(null===(n=this.dragging)||void 0===n?void 0:n.node)&&!o.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,o),"reset"==c?this.dom.scrollTop=0:"to selection"==c?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let o=e?e.getBoundingClientRect().top:0;Ai(n,0==o?0:o-t)}(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof dt){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&Ni(this,t.getBoundingClientRect(),e)}else Ni(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))}}}updateDraggedNode(e,t){let n=e.node,o=-1;if(this.state.doc.nodeAt(n.from)==n.node)o=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&this.state.doc.nodeAt(e))==n.node&&(o=e)}this.dragging=new vl(e.slice,e.move,o<0?void 0:dt.create(this.state.doc,o))}someProp(e,t){let n,o=this._props&&this._props[e];if(null!=o&&(n=t?t(o):o))return n;for(let o=0;o<this.directPlugins.length;o++){let r=this.directPlugins[o].props[e];if(null!=r&&(n=t?t(r):r))return n}let r=this.state.plugins;if(r)for(let o=0;o<r.length;o++){let i=r[o].props[e];if(null!=i&&(n=t?t(i):i))return n}}hasFocus(){if(di){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(Ti)return e.focus(Ti);let t=Oi(e);e.focus(null==Ti?{get preventScroll(){return Ti={preventScroll:!0},!0}}:void 0),Ti||(Ti=!1,Ai(t,0))}(this.dom),ms(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}updateRoot(){this._root=null}posAtCoords(e){return $i(this,e)}coordsAtPos(e,t=1){return Pi(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 o=this.docView.posFromDOM(e,t,n);if(null==o)throw new RangeError("DOM position not inside the editor");return o}endOfTextblock(e,t){return function(e,t,n){return _i==t&&Wi==n?qi:(_i=t,Wi=n,qi="up"==n||"down"==n?function(e,t,n){let o=t.selection,r="up"==n?o.$from:o.$to;return Li(e,t,()=>{let{node:t}=e.docView.domFromPos(r.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 o=Pi(e,r.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=Gr(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let r=t[e];if(r.bottom>r.top+1&&("up"==n?o.top-r.top>2*(r.bottom-o.top):r.bottom-o.bottom>2*(o.bottom-r.top)))return!1}}return!0})}(e,t,n):function(e,t,n){let{$head:o}=t.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,i=!r,s=r==o.parent.content.size,l=e.domSelection();return l?Hi.test(o.parent.textContent)&&l.modify?Li(e,t,()=>{let{focusNode:t,focusOffset:r,anchorNode:i,anchorOffset:s}=e.domSelectionRange(),a=l.caretBidiLevel;l.modify("move",n,"character");let c=o.depth?e.docView.domAfterPos(o.before()):e.dom,{focusNode:d,focusOffset:h}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&r==h;try{l.collapse(i,s),t&&(t!=i||r!=s)&&l.extend&&l.extend(t,r)}catch(e){}return null!=a&&(l.caretBidiLevel=a),p}):"left"==n||"backward"==n?i:s:o.pos==o.start()||o.pos==o.end()}(e,t,n))}(this,t||this.state,e)}pasteHTML(e,t){return yl(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return yl(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Ps(this,e)}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,[],Fl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ur=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){tl(e,t)||!Us[t.type]||!e.editable&&t.type in Gs||Us[t.type](e,t)}(this,e)}domSelectionRange(){let e=this.domSelection();return e?gi&&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,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Jl(e,n)}let n;function o(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",o,!0),n?Jl(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function na(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),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]))}),t.translate||(t.translate="no"),[Nl.node(0,e.state.doc.content.size,t)]}function oa(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:Nl.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function ra(e){return!e.someProp("editable",t=>!1===t(e.state))}function ia(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 sa(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")}ta.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var la={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:"'"},aa={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ca="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),da="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ha=0;ha<10;ha++)la[48+ha]=la[96+ha]=String(ha);for(ha=1;ha<=24;ha++)la[ha+111]="F"+ha;for(ha=65;ha<=90;ha++)la[ha]=String.fromCharCode(ha+32),aa[ha]=String.fromCharCode(ha);for(var pa in la)aa.hasOwnProperty(pa)||(aa[pa]=la[pa]);const ua="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),fa="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function ma(e){let t,n,o,r,i=e.split(/-(?!$)/),s=i[i.length-1];"Space"==s&&(s=" ");for(let e=0;e<i.length-1;e++){let s=i[e];if(/^(cmd|meta|m)$/i.test(s))r=!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))o=!0;else{if(!/^mod$/i.test(s))throw new Error("Unrecognized modifier name: "+s);ua?r=!0:n=!0}}return t&&(s="Alt-"+s),n&&(s="Ctrl-"+s),r&&(s="Meta-"+s),o&&(s="Shift-"+s),s}function ga(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 ya(e){return new St({props:{handleKeyDown:wa(e)}})}function wa(e){let t=function(e){let t=Object.create(null);for(let n in e)t[ma(n)]=e[n];return t}(e);return function(e,n){let o,r=function(e){var t=!(ca&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||da&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?aa:la)[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),i=t[ga(r,n)];if(i&&i(e.state,e.dispatch,e))return!0;if(1==r.length&&" "!=r){if(n.shiftKey){let o=t[ga(r,n,!1)];if(o&&o(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(fa&&n.ctrlKey&&n.altKey)&&(o=la[n.keyCode])&&o!=r){let r=t[ga(o,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}let va,ba;if("undefined"!=typeof WeakMap){let e=new WeakMap;va=t=>e.get(t),ba=(t,n)=>(e.set(t,n),n)}else{const e=[],t=10;let n=0;va=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},ba=(o,r)=>(n==t&&(n=0),e[n++]=o,e[n++]=r)}var ka=class{constructor(e,t,n,o){this.width=e,this.height=t,this.map=n,this.problems=o}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const o=t%this.width,r=t/this.width|0;let i=o+1,s=r+1;for(let e=1;i<this.width&&this.map[t+e]==n;e++)i++;for(let e=1;s<this.height&&this.map[t+this.width*e]==n;e++)s++;return{left:o,top:r,right:i,bottom:s}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:o,right:r,top:i,bottom:s}=this.findCell(e);return"horiz"==t?(n<0?0==o:r==this.width)?null:this.map[i*this.width+(n<0?o-1:r)]:(n<0?0==i:s==this.height)?null:this.map[o+this.width*(n<0?i-1:s)]}rectBetween(e,t){const{left:n,right:o,top:r,bottom:i}=this.findCell(e),{left:s,right:l,top:a,bottom:c}=this.findCell(t);return{left:Math.min(n,s),top:Math.min(r,a),right:Math.max(o,l),bottom:Math.max(i,c)}}cellsInRect(e){const t=[],n={};for(let o=e.top;o<e.bottom;o++)for(let r=e.left;r<e.right;r++){const i=o*this.width+r,s=this.map[i];n[s]||(n[s]=!0,r==e.left&&r&&this.map[i-1]==s||o==e.top&&o&&this.map[i-this.width]==s||t.push(s))}return t}positionAt(e,t,n){for(let o=0,r=0;;o++){const i=r+n.child(o).nodeSize;if(o==e){let n=t+e*this.width;const o=(e+1)*this.width;for(;n<o&&this.map[n]<r;)n++;return n==o?i-1:this.map[n]}r=i}}static get(e){return va(e)||ba(e,function(e){if("table"!=e.type.spec.tableRole)throw new RangeError("Not a table node: "+e.type.name);const t=function(e){let t=-1,n=!1;for(let o=0;o<e.childCount;o++){const r=e.child(o);let i=0;if(n)for(let t=0;t<o;t++){const n=e.child(t);for(let e=0;e<n.childCount;e++){const r=n.child(e);t+r.attrs.rowspan>o&&(i+=r.attrs.colspan)}}for(let e=0;e<r.childCount;e++){const t=r.child(e);i+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=i:t!=i&&(t=Math.max(t,i))}return t}(e),n=e.childCount,o=[];let r=0,i=null;const s=[];for(let e=0,r=t*n;e<r;e++)o[e]=0;for(let l=0,a=0;l<n;l++){const c=e.child(l);a++;for(let e=0;;e++){for(;r<o.length&&0!=o[r];)r++;if(e==c.childCount)break;const d=c.child(e),{colspan:h,rowspan:p,colwidth:u}=d.attrs;for(let e=0;e<p;e++){if(e+l>=n){(i||(i=[])).push({type:"overlong_rowspan",pos:a,n:p-e});break}const c=r+e*t;for(let e=0;e<h;e++){0==o[c+e]?o[c+e]=a:(i||(i=[])).push({type:"collision",row:l,pos:a,n:h-e});const n=u&&u[e];if(n){const o=(c+e)%t*2,r=s[o];null==r||r!=n&&1==s[o+1]?(s[o]=n,s[o+1]=1):r==n&&s[o+1]++}}}r+=h,a+=d.nodeSize}const d=(l+1)*t;let h=0;for(;r<d;)0==o[r++]&&h++;h&&(i||(i=[])).push({type:"missing",row:l,n:h}),a++}0!==t&&0!==n||(i||(i=[])).push({type:"zero_sized"});const l=new ka(t,n,o,i);let a=!1;for(let e=0;!a&&e<s.length;e+=2)null!=s[e]&&s[e+1]<n&&(a=!0);return a&&function(e,t,n){e.problems||(e.problems=[]);const o={};for(let r=0;r<e.map.length;r++){const i=e.map[r];if(o[i])continue;o[i]=!0;const s=n.nodeAt(i);if(!s)throw new RangeError(`No cell with offset ${i} found`);let l=null;const a=s.attrs;for(let n=0;n<a.colspan;n++){const o=t[(r+n)%e.width*2];null==o||a.colwidth&&a.colwidth[n]==o||((l||(l=xa(a)))[n]=o)}l&&e.problems.unshift({type:"colwidth mismatch",pos:i,colwidth:l})}}(l,s,e),l}(e))}};function xa(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function Sa(e,t){if("string"==typeof e)return{};const n=e.getAttribute("data-colwidth"),o=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(e=>Number(e)):null,r=Number(e.getAttribute("colspan")||1),i={colspan:r,rowspan:Number(e.getAttribute("rowspan")||1),colwidth:o&&o.length==r?o:null};for(const n in t){const o=t[n].getFromDOM,r=o&&o(e);null!=r&&(i[n]=r)}return i}function Ca(e,t){const n={};1!=e.attrs.colspan&&(n.colspan=e.attrs.colspan),1!=e.attrs.rowspan&&(n.rowspan=e.attrs.rowspan),e.attrs.colwidth&&(n["data-colwidth"]=e.attrs.colwidth.join(","));for(const o in t){const r=t[o].setDOMAttr;r&&r(e.attrs[o],n)}return n}function Ma(e){if(null!==e){if(!Array.isArray(e))throw new TypeError("colwidth must be null or an array");for(const t of e)if("number"!=typeof t)throw new TypeError("colwidth must be null or an array of numbers")}}function Na(e){const t=e.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Ma}};for(const e in t)n[e]={default:t[e].default,validate:t[e].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:e.tableGroup,parseDOM:[{tag:"table"}],toDOM:()=>["table",["tbody",0]]},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM:()=>["tr",0]},table_cell:{content:e.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:e=>Sa(e,t)}],toDOM:e=>["td",Ca(e,t),0]},table_header:{content:e.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:e=>Sa(e,t)}],toDOM:e=>["th",Ca(e,t),0]}}}function Oa(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const o=e.nodes[n],r=o.spec.tableRole;r&&(t[r]=o)}}return t}const Aa=new Nt("selectingCells");function Ta(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function Da(e){const t=e.selection.$head;for(let e=t.depth;e>0;e--)if("row"==t.node(e).type.spec.tableRole)return!0;return!1}function Ea(e){const t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&"cell"==t.node.type.spec.tableRole)return t.$anchor;const n=Ta(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function Ra(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function $a(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Ia(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function za(e){return ka.get(e.node(-1)).findCell(e.pos-e.start(-1))}function Ba(e){return ka.get(e.node(-1)).colCount(e.pos-e.start(-1))}function Pa(e,t,n){const o=e.node(-1),r=ka.get(o),i=e.start(-1),s=r.nextCell(e.pos-i,t,n);return null==s?null:e.node(0).resolve(i+s)}function Va(e,t,n=1){const o={...e,colspan:e.colspan-n};return o.colwidth&&(o.colwidth=o.colwidth.slice(),o.colwidth.splice(t,n),o.colwidth.some(e=>e>0)||(o.colwidth=null)),o}function Fa(e,t,n=1){const o={...e,colspan:e.colspan+n};if(o.colwidth){o.colwidth=o.colwidth.slice();for(let e=0;e<n;e++)o.colwidth.splice(t,0,0)}return o}function La(e,t,n){const o=Oa(t.type.schema).header_cell;for(let r=0;r<e.height;r++)if(t.nodeAt(e.map[n+r*e.width]).type!=o)return!1;return!0}var Ha=class e extends rt{constructor(e,t=e){const n=e.node(-1),o=ka.get(n),r=e.start(-1),i=o.rectBetween(e.pos-r,t.pos-r),s=e.node(0),l=o.cellsInRect(i).filter(e=>e!=t.pos-r);l.unshift(t.pos-r);const a=l.map(e=>{const t=n.nodeAt(e);if(!t)throw new RangeError(`No cell with offset ${e} found`);const o=r+e+1;return new it(s.resolve(o),s.resolve(o+t.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(t,n){const o=t.resolve(n.map(this.$anchorCell.pos)),r=t.resolve(n.map(this.$headCell.pos));if(Ra(o)&&Ra(r)&&Ia(o,r)){const t=this.$anchorCell.node(-1)!=o.node(-1);return t&&this.isRowSelection()?e.rowSelection(o,r):t&&this.isColSelection()?e.colSelection(o,r):new e(o,r)}return at.between(o,r)}content(){const e=this.$anchorCell.node(-1),t=ka.get(e),n=this.$anchorCell.start(-1),o=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),r={},i=[];for(let n=o.top;n<o.bottom;n++){const l=[];for(let i=n*t.width+o.left,s=o.left;s<o.right;s++,i++){const n=t.map[i];if(r[n])continue;r[n]=!0;const s=t.findCell(n);let a=e.nodeAt(n);if(!a)throw new RangeError(`No cell with offset ${n} found`);const c=o.left-s.left,d=s.right-o.right;if(c>0||d>0){let e=a.attrs;if(c>0&&(e=Va(e,0,c)),d>0&&(e=Va(e,e.colspan-d,d)),s.left<o.left){if(a=a.type.createAndFill(e),!a)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else a=a.type.create(e,a.content)}if(s.top<o.top||s.bottom>o.bottom){const e={...a.attrs,rowspan:Math.min(s.bottom,o.bottom)-Math.max(s.top,o.top)};a=s.top<o.top?a.type.createAndFill(e):a.type.create(e,a.content)}l.push(a)}i.push(e.child(n).copy(s.from(l)))}const l=this.isColSelection()&&this.isRowSelection()?e:i;return new p(s.from(l),1,1)}replace(e,t=p.empty){const n=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){const{$from:i,$to:s}=o[r],l=e.mapping.slice(n);e.replace(l.map(i.pos),l.map(s.pos),r?p.empty:t)}const r=rt.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);r&&e.setSelection(r)}replaceWith(e,t){this.replace(e,new p(s.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),n=ka.get(t),o=this.$anchorCell.start(-1),r=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let n=0;n<r.length;n++)e(t.nodeAt(r[n]),o+r[n])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,o=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,o)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const o=t.node(-1),r=ka.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.top<=l.top?(s.top>0&&(t=a.resolve(i+r.map[s.left])),l.bottom<r.height&&(n=a.resolve(i+r.map[r.width*(r.height-1)+l.right-1]))):(l.top>0&&(n=a.resolve(i+r.map[l.left])),s.bottom<r.height&&(t=a.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new e(t,n)}isRowSelection(){const e=this.$anchorCell.node(-1),t=ka.get(e),n=this.$anchorCell.start(-1),o=t.colCount(this.$anchorCell.pos-n),r=t.colCount(this.$headCell.pos-n);if(Math.min(o,r)>0)return!1;const i=o+this.$anchorCell.nodeAfter.attrs.colspan,s=r+this.$headCell.nodeAfter.attrs.colspan;return Math.max(i,s)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const o=t.node(-1),r=ka.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.left<=l.left?(s.left>0&&(t=a.resolve(i+r.map[s.top*r.width])),l.right<r.width&&(n=a.resolve(i+r.map[r.width*(l.top+1)-1]))):(l.left>0&&(n=a.resolve(i+r.map[l.top*r.width])),s.right<r.width&&(t=a.resolve(i+r.map[r.width*(s.top+1)-1]))),new e(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,o=n){return new e(t.resolve(n),t.resolve(o))}getBookmark(){return new _a(this.$anchorCell.pos,this.$headCell.pos)}};Ha.prototype.visible=!1,rt.jsonID("cell",Ha);var _a=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){const t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&Ia(t,n)?new Ha(t,n):rt.near(n,1)}};function Wa(e){if(!(e.selection instanceof Ha))return null;const t=[];return e.selection.forEachCell((e,n)=>{t.push(Nl.node(n,n+e.nodeSize,{class:"selectedCell"}))}),Tl.create(e.doc,t)}const qa=new Nt("fix-tables");function ja(e,t,n,o){const r=e.childCount,i=t.childCount;e:for(let s=0,l=0;s<i;s++){const i=t.child(s);for(let t=l,o=Math.min(r,s+3);t<o;t++)if(e.child(t)==i){l=t+1,n+=i.nodeSize;continue e}o(i,n),l<r&&e.child(l).sameMarkup(i)?ja(e.child(l),i,n+1,o):i.nodesBetween(0,i.content.size,o,n+1),n+=i.nodeSize}}function Ja(e,t){let n;const o=(t,o)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,o){const r=ka.get(t);if(!r.problems)return o;o||(o=e.tr);const i=[];for(let e=0;e<r.height;e++)i.push(0);for(let e=0;e<r.problems.length;e++){const s=r.problems[e];if("collision"==s.type){const e=t.nodeAt(s.pos);if(!e)continue;const r=e.attrs;for(let e=0;e<r.rowspan;e++)i[s.row+e]+=s.n;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,Va(r,r.colspan-s.n,s.n))}else if("missing"==s.type)i[s.row]+=s.n;else if("overlong_rowspan"==s.type){const e=t.nodeAt(s.pos);if(!e)continue;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-s.n})}else if("colwidth mismatch"==s.type){const e=t.nodeAt(s.pos);if(!e)continue;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,{...e.attrs,colwidth:s.colwidth})}else if("zero_sized"==s.type){const e=o.mapping.map(n);o.delete(e,e+t.nodeSize)}}let s,l;for(let e=0;e<i.length;e++)i[e]&&(null==s&&(s=e),l=e);for(let a=0,c=n+1;a<r.height;a++){const n=t.child(a),r=c+n.nodeSize,d=i[a];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);const i=[];for(let n=0;n<d;n++){const n=Oa(e.schema)[t].createAndFill();n&&i.push(n)}const h=0!=a&&s!=a-1||l!=a?r-1:c+1;o.insert(o.mapping.map(h),i)}c=r}return o.setMeta(qa,{fixTables:!0})}(e,t,o,n))};return t?t.doc!=e.doc&&ja(t.doc,e.doc,0,o):e.doc.descendants(o),n}function Ka(e){const t=e.selection,n=Ea(e),o=n.node(-1),r=n.start(-1),i=ka.get(o);return{...t instanceof Ha?i.rectBetween(t.$anchorCell.pos-r,t.$headCell.pos-r):i.findCell(n.pos-r),tableStart:r,map:i,table:o}}function Xa(e,{map:t,tableStart:n,table:o},r){let i=r>0?-1:0;La(t,o,r+i)&&(i=0==r||r==t.width?null:0);for(let s=0;s<t.height;s++){const l=s*t.width+r;if(r>0&&r<t.width&&t.map[l-1]==t.map[l]){const i=t.map[l],a=o.nodeAt(i);e.setNodeMarkup(e.mapping.map(n+i),null,Fa(a.attrs,r-t.colCount(i))),s+=a.attrs.rowspan-1}else{const a=null==i?Oa(o.type.schema).cell:o.nodeAt(t.map[l+i]).type,c=t.positionAt(s,r,o);e.insert(e.mapping.map(n+c),a.createAndFill())}}return e}function Ua(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(Xa(e.tr,n,n.left))}return!0}function Ga(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(Xa(e.tr,n,n.right))}return!0}function Ya(e,{map:t,table:n,tableStart:o},r){const i=e.mapping.maps.length;for(let s=0;s<t.height;){const l=s*t.width+r,a=t.map[l],c=n.nodeAt(a),d=c.attrs;if(r>0&&t.map[l-1]==a||r<t.width-1&&t.map[l+1]==a)e.setNodeMarkup(e.mapping.slice(i).map(o+a),null,Va(d,r-t.colCount(a)));else{const t=e.mapping.slice(i).map(o+a);e.delete(t,t+c.nodeSize)}s+=d.rowspan}}function Qa(e,t){if(!Da(e))return!1;if(t){const n=Ka(e),o=e.tr;if(0==n.left&&n.right==n.map.width)return!1;for(let e=n.right-1;Ya(o,n,e),e!=n.left;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw new RangeError("No table found");n.table=e,n.map=ka.get(e)}t(o)}return!0}function Za(e,t,n){var o;const r=Oa(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if((null===(o=t.nodeAt(e.map[i+n*e.width]))||void 0===o?void 0:o.type)!=r)return!1;return!0}function ec(e,{map:t,tableStart:n,table:o},r){let i=n;for(let e=0;e<r;e++)i+=o.child(e).nodeSize;const s=[];let l=r>0?-1:0;Za(t,o,r+l)&&(l=0==r||r==t.height?null:0);for(let i=0,c=t.width*r;i<t.width;i++,c++)if(r>0&&r<t.height&&t.map[c]==t.map[c-t.width]){const r=t.map[c],s=o.nodeAt(r).attrs;e.setNodeMarkup(n+r,null,{...s,rowspan:s.rowspan+1}),i+=s.colspan-1}else{var a;const e=null==l?Oa(o.type.schema).cell:null===(a=o.nodeAt(t.map[c+l*t.width]))||void 0===a?void 0:a.type,n=null==e?void 0:e.createAndFill();n&&s.push(n)}return e.insert(i,Oa(o.type.schema).row.create(null,s)),e}function tc(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(ec(e.tr,n,n.top))}return!0}function nc(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(ec(e.tr,n,n.bottom))}return!0}function oc(e,{map:t,table:n,tableStart:o},r){let i=0;for(let e=0;e<r;e++)i+=n.child(e).nodeSize;const s=i+n.child(r).nodeSize,l=e.mapping.maps.length;e.delete(i+o,s+o);const a=new Set;for(let i=0,s=r*t.width;i<t.width;i++,s++){const c=t.map[s];if(!a.has(c))if(a.add(c),r>0&&c==t.map[s-t.width]){const t=n.nodeAt(c).attrs;e.setNodeMarkup(e.mapping.slice(l).map(c+o),null,{...t,rowspan:t.rowspan-1}),i+=t.colspan-1}else if(r<t.height&&c==t.map[s+t.width]){const s=n.nodeAt(c),a=s.attrs,d=s.type.create({...a,rowspan:s.attrs.rowspan-1},s.content),h=t.positionAt(r+1,i,n);e.insert(e.mapping.slice(l).map(o+h),d),i+=a.colspan-1}}}function rc(e,t){if(!Da(e))return!1;if(t){const n=Ka(e),o=e.tr;if(0==n.top&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;oc(o,n,e),e!=n.top;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw new RangeError("No table found");n.table=e,n.map=ka.get(n.table)}t(o)}return!0}function ic(e){const t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function sc(e,t){const n=e.selection;if(!(n instanceof Ha)||n.$anchorCell.pos==n.$headCell.pos)return!1;const o=Ka(e),{map:r}=o;if(function({width:e,height:t,map:n},o){let r=o.top*e+o.left,i=r,s=(o.bottom-1)*e+o.left,l=r+(o.right-o.left-1);for(let t=o.top;t<o.bottom;t++){if(o.left>0&&n[i]==n[i-1]||o.right<e&&n[l]==n[l+1])return!0;i+=e,l+=e}for(let i=o.left;i<o.right;i++){if(o.top>0&&n[r]==n[r-e]||o.bottom<t&&n[s]==n[s+e])return!0;r++,s++}return!1}(r,o))return!1;if(t){const n=e.tr,i={};let l,a,c=s.empty;for(let e=o.top;e<o.bottom;e++)for(let t=o.left;t<o.right;t++){const s=r.map[e*r.width+t],d=o.table.nodeAt(s);if(!i[s]&&d)if(i[s]=!0,null==l)l=s,a=d;else{ic(d)||(c=c.append(d.content));const e=n.mapping.map(s+o.tableStart);n.delete(e,e+d.nodeSize)}}if(null==l||null==a)return!0;if(n.setNodeMarkup(l+o.tableStart,null,{...Fa(a.attrs,a.attrs.colspan,o.right-o.left-a.attrs.colspan),rowspan:o.bottom-o.top}),c.size>0){const e=l+1+a.content.size,t=ic(a)?l+1:e;n.replaceWith(t+o.tableStart,e+o.tableStart,c)}n.setSelection(new Ha(n.doc.resolve(l+o.tableStart))),t(n)}return!0}function lc(e,t){const n=Oa(e.schema);return ac(({node:e})=>n[e.type.spec.tableRole])(e,t)}function ac(e){return(t,n)=>{const o=t.selection;let r,i;if(o instanceof Ha){if(o.$anchorCell.pos!=o.$headCell.pos)return!1;r=o.$anchorCell.nodeAfter,i=o.$anchorCell.pos}else{var s;if(r=function(e){for(let t=e.depth;t>0;t--){const n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(o.$from),!r)return!1;i=null===(s=Ta(o.$from))||void 0===s?void 0:s.pos}if(null==r||null==i)return!1;if(1==r.attrs.colspan&&1==r.attrs.rowspan)return!1;if(n){let s=r.attrs;const l=[],a=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1}),s.colspan>1&&(s={...s,colspan:1});const c=Ka(t),d=t.tr;for(let e=0;e<c.right-c.left;e++)l.push(a?{...s,colwidth:a&&a[e]?[a[e]]:null}:s);let h;for(let t=c.top;t<c.bottom;t++){let n=c.map.positionAt(t,c.left,c.table);t==c.top&&(n+=r.nodeSize);for(let o=c.left,i=0;o<c.right;o++,i++)o==c.left&&t==c.top||d.insert(h=d.mapping.map(n+c.tableStart,1),e({node:r,row:t,col:o}).createAndFill(l[i]))}d.setNodeMarkup(i,e({node:r,row:c.top,col:c.left}),l[0]),o instanceof Ha&&d.setSelection(new Ha(d.doc.resolve(o.$anchorCell.pos),h?d.doc.resolve(h):void 0)),n(d)}return!0}}function cc(e,t){return function(n,o){if(!Da(n))return!1;const r=Ea(n);if(r.nodeAfter.attrs[e]===t)return!1;if(o){const i=n.tr;n.selection instanceof Ha?n.selection.forEachCell((n,o)=>{n.attrs[e]!==t&&i.setNodeMarkup(o,null,{...n.attrs,[e]:t})}):i.setNodeMarkup(r.pos,null,{...r.nodeAfter.attrs,[e]:t}),o(i)}return!0}}function dc(e,t,n){const o=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let e=0;e<o.length;e++){const r=t.table.nodeAt(o[e]);if(r&&r.type!==n.header_cell)return!1}return!0}function hc(e,t){return(t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic?function(e){return function(t,n){if(!Da(t))return!1;if(n){const o=Oa(t.schema),r=Ka(t),i=t.tr,s=r.map.cellsInRect("column"==e?{left:r.left,top:0,right:r.right,bottom:r.map.height}:"row"==e?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),l=s.map(e=>r.table.nodeAt(e));for(let e=0;e<s.length;e++)l[e].type==o.header_cell&&i.setNodeMarkup(r.tableStart+s[e],o.cell,l[e].attrs);if(0===i.steps.length)for(let e=0;e<s.length;e++)i.setNodeMarkup(r.tableStart+s[e],o.header_cell,l[e].attrs);n(i)}return!0}}(e):function(t,n){if(!Da(t))return!1;if(n){const o=Oa(t.schema),r=Ka(t),i=t.tr,s=dc("row",r,o),l=dc("column",r,o),a=("column"===e?s:"row"===e&&l)?1:0,c="column"==e?{left:0,top:a,right:1,bottom:r.map.height}:"row"==e?{left:a,top:0,right:r.map.width,bottom:1}:r,d="column"==e?l?o.cell:o.header_cell:"row"==e?s?o.cell:o.header_cell:o.cell;r.map.cellsInRect(c).forEach(e=>{const t=e+r.tableStart,n=i.doc.nodeAt(t);n&&i.setNodeMarkup(t,d,n.attrs)}),n(i)}return!0}}const pc=hc("row",{useDeprecatedLogic:!0}),uc=hc("column",{useDeprecatedLogic:!0}),fc=hc("cell",{useDeprecatedLogic:!0});function mc(e){return function(t,n){if(!Da(t))return!1;const o=function(e,t){if(t<0){const t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){const o=e.node(-1).child(t),r=o.lastChild;if(r)return n-1-r.nodeSize;n-=o.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const t=e.node(-1);for(let n=e.indexAfter(-1),o=e.after();n<t.childCount;n++){const e=t.child(n);if(e.childCount)return o+1;o+=e.nodeSize}}return null}(Ea(t),e);if(null==o)return!1;if(n){const e=t.doc.resolve(o);n(t.tr.setSelection(at.between(e,$a(e))).scrollIntoView())}return!0}}function gc(e,t){const n=e.selection.$anchor;for(let o=n.depth;o>0;o--)if("table"==n.node(o).type.spec.tableRole)return t&&t(e.tr.delete(n.before(o),n.after(o)).scrollIntoView()),!0;return!1}function yc(e,t){const n=e.selection;if(!(n instanceof Ha))return!1;if(t){const o=e.tr,r=Oa(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(r)||o.replace(o.mapping.map(t+1),o.mapping.map(t+e.nodeSize-1),new p(r,0,0))}),o.docChanged&&t(o)}return!0}function wc(e,t){const n=e.createAndFill();return new nt(n).replace(0,n.content.size,t).doc}function vc(e,t,n,o,r,i,s,l){if(0==s||s==t.height)return!1;let a=!1;for(let c=r;c<i;c++){const r=s*t.width+c,i=t.map[r];if(t.map[r-t.width]==i){a=!0;const r=n.nodeAt(i),{top:d,left:h}=t.findCell(i);e.setNodeMarkup(e.mapping.slice(l).map(i+o),null,{...r.attrs,rowspan:s-d}),e.insert(e.mapping.slice(l).map(t.positionAt(s,h,n)),r.type.createAndFill({...r.attrs,rowspan:d+r.attrs.rowspan-s})),c+=r.attrs.colspan-1}}return a}function bc(e,t,n,o,r,i,s,l){if(0==s||s==t.width)return!1;let a=!1;for(let c=r;c<i;c++){const r=c*t.width+s,i=t.map[r];if(t.map[r-1]==i){a=!0;const r=n.nodeAt(i),d=t.colCount(i),h=e.mapping.slice(l).map(i+o);e.setNodeMarkup(h,null,Va(r.attrs,s-d,r.attrs.colspan-(s-d))),e.insert(h+r.nodeSize,r.type.createAndFill(Va(r.attrs,0,s-d))),c+=r.attrs.rowspan-1}}return a}function kc(e,t,n,o,r){let i=n?e.doc.nodeAt(n-1):e.doc;if(!i)throw new Error("No table found");let l=ka.get(i);const{top:a,left:c}=o,d=c+r.width,h=a+r.height,u=e.tr;let f=0;function m(){if(i=n?u.doc.nodeAt(n-1):u.doc,!i)throw new Error("No table found");l=ka.get(i),f=u.mapping.maps.length}(function(e,t,n,o,r,i,l){const a=Oa(e.doc.type.schema);let c,d;if(r>t.width)for(let i=0,s=0;i<t.height;i++){const h=n.child(i);s+=h.nodeSize;const p=[];let u;u=null==h.lastChild||h.lastChild.type==a.cell?c||(c=a.cell.createAndFill()):d||(d=a.header_cell.createAndFill());for(let e=t.width;e<r;e++)p.push(u);e.insert(e.mapping.slice(l).map(s-1+o),p)}if(i>t.height){const h=[];for(let e=0,o=(t.height-1)*t.width;e<Math.max(t.width,r);e++){const r=!(e>=t.width)&&n.nodeAt(t.map[o+e]).type==a.header_cell;h.push(r?d||(d=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const p=a.row.create(null,s.from(h)),u=[];for(let e=t.height;e<i;e++)u.push(p);e.insert(e.mapping.slice(l).map(o+n.nodeSize-2),u)}return!(!c&&!d)})(u,l,i,n,d,h,f)&&m(),vc(u,l,i,n,c,d,a,f)&&m(),vc(u,l,i,n,c,d,h,f)&&m(),bc(u,l,i,n,a,h,c,f)&&m(),bc(u,l,i,n,a,h,d,f)&&m();for(let e=a;e<h;e++){const t=l.positionAt(e,c,i),o=l.positionAt(e,d,i);u.replace(u.mapping.slice(f).map(t+n),u.mapping.slice(f).map(o+n),new p(r.rows[e-a],0,0))}m(),u.setSelection(new Ha(u.doc.resolve(n+l.positionAt(a,c,i)),u.doc.resolve(n+l.positionAt(h-1,d-1,i)))),t(u)}const xc=wa({ArrowLeft:Cc("horiz",-1),ArrowRight:Cc("horiz",1),ArrowUp:Cc("vert",-1),ArrowDown:Cc("vert",1),"Shift-ArrowLeft":Mc("horiz",-1),"Shift-ArrowRight":Mc("horiz",1),"Shift-ArrowUp":Mc("vert",-1),"Shift-ArrowDown":Mc("vert",1),Backspace:yc,"Mod-Backspace":yc,Delete:yc,"Mod-Delete":yc});function Sc(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function Cc(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;if(i instanceof Ha)return Sc(n,o,rt.near(i.$headCell,t));if("horiz"!=e&&!i.empty)return!1;const s=Tc(r,e,t);if(null==s)return!1;if("horiz"==e)return Sc(n,o,rt.near(n.doc.resolve(i.head+t),t));{const r=n.doc.resolve(s),i=Pa(r,e,t);let l;return l=i?rt.near(i,1):t<0?rt.near(n.doc.resolve(r.before(-1)),-1):rt.near(n.doc.resolve(r.after(-1)),1),Sc(n,o,l)}}}function Mc(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;let s;if(i instanceof Ha)s=i;else{const o=Tc(r,e,t);if(null==o)return!1;s=new Ha(n.doc.resolve(o))}const l=Pa(s.$headCell,e,t);return!!l&&Sc(n,o,new Ha(s.$anchorCell,l))}}function Nc(e,t){const n=Ta(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new Ha(n))),!0)}function Oc(e,t,n){if(!Da(e.state))return!1;let o=function(e){if(0===e.size)return null;let{content:t,openStart:n,openEnd:o}=e;for(;1==t.childCount&&(n>0&&o>0||"table"==t.child(0).type.spec.tableRole);)n--,o--,t=t.child(0).content;const r=t.child(0),i=r.type.spec.tableRole,l=r.type.schema,a=[];if("row"==i)for(let e=0;e<t.childCount;e++){let r=t.child(e).content;const i=e?0:Math.max(0,n-1),s=e<t.childCount-1?0:Math.max(0,o-1);(i||s)&&(r=wc(Oa(l).row,new p(r,i,s)).content),a.push(r)}else{if("cell"!=i&&"header_cell"!=i)return null;a.push(n||o?wc(Oa(l).row,new p(t,n,o)).content:t)}return function(e,t){const n=[];for(let e=0;e<t.length;e++){const o=t[e];for(let t=o.childCount-1;t>=0;t--){const{rowspan:r,colspan:i}=o.child(t).attrs;for(let t=e;t<e+r;t++)n[t]=(n[t]||0)+i}}let o=0;for(let e=0;e<n.length;e++)o=Math.max(o,n[e]);for(let r=0;r<n.length;r++)if(r>=t.length&&t.push(s.empty),n[r]<o){const i=Oa(e).cell.createAndFill(),l=[];for(let e=n[r];e<o;e++)l.push(i);t[r]=t[r].append(s.from(l))}return{height:t.length,width:o,rows:t}}(l,a)}(n);const r=e.state.selection;if(r instanceof Ha){o||(o={width:1,height:1,rows:[s.from(wc(Oa(e.state.schema).cell,n))]});const t=r.$anchorCell.node(-1),i=r.$anchorCell.start(-1),l=ka.get(t).rectBetween(r.$anchorCell.pos-i,r.$headCell.pos-i);return o=function({width:e,height:t,rows:n},o,r){if(e!=o){const t=[],r=[];for(let e=0;e<n.length;e++){const i=n[e],l=[];for(let n=t[e]||0,r=0;n<o;r++){let s=i.child(r%i.childCount);n+s.attrs.colspan>o&&(s=s.type.createChecked(Va(s.attrs,s.attrs.colspan,n+s.attrs.colspan-o),s.content)),l.push(s),n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+s.attrs.colspan}r.push(s.from(l))}n=r,e=o}if(t!=r){const e=[];for(let o=0,i=0;o<r;o++,i++){const l=[],a=n[i%t];for(let e=0;e<a.childCount;e++){let t=a.child(e);o+t.attrs.rowspan>r&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,r-t.attrs.rowspan)},t.content)),l.push(t)}e.push(s.from(l))}n=e,t=r}return{width:e,height:t,rows:n}}(o,l.right-l.left,l.bottom-l.top),kc(e.state,e.dispatch,i,l,o),!0}if(o){const t=Ea(e.state),n=t.start(-1);return kc(e.state,e.dispatch,n,ka.get(t.node(-1)).findCell(t.pos-n),o),!0}return!1}function Ac(e,t){var n;if(0!=t.button)return;if(t.ctrlKey||t.metaKey)return;const o=Dc(e,t.target);let r;if(t.shiftKey&&e.state.selection instanceof Ha)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&o&&null!=(r=Ta(e.state.selection.$anchor))&&(null===(n=Ec(e,t))||void 0===n?void 0:n.pos)!=r.pos)i(r,t),t.preventDefault();else if(!o)return;function i(t,n){let o=Ec(e,n);const r=null==Aa.getState(e.state);if(!o||!Ia(t,o)){if(!r)return;o=t}const i=new Ha(t,o);if(r||!e.state.selection.eq(i)){const n=e.state.tr.setSelection(i);r&&n.setMeta(Aa,t.pos),e.dispatch(n)}}function s(){e.root.removeEventListener("mouseup",s),e.root.removeEventListener("dragstart",s),e.root.removeEventListener("mousemove",l),null!=Aa.getState(e.state)&&e.dispatch(e.state.tr.setMeta(Aa,-1))}function l(n){const r=n,l=Aa.getState(e.state);let a;if(null!=l)a=e.state.doc.resolve(l);else if(Dc(e,r.target)!=o&&(a=Ec(e,t),!a))return s();a&&i(a,r)}e.root.addEventListener("mouseup",s),e.root.addEventListener("dragstart",s),e.root.addEventListener("mousemove",l)}function Tc(e,t,n){if(!(e.state.selection instanceof at))return null;const{$head:o}=e.state.selection;for(let r=o.depth-1;r>=0;r--){const i=o.node(r);if((n<0?o.index(r):o.indexAfter(r))!=(n<0?0:i.childCount))return null;if("cell"==i.type.spec.tableRole||"header_cell"==i.type.spec.tableRole){const i=o.before(r),s="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(s)?i:null}}return null}function Dc(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function Ec(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:o,pos:r}=n;return o>=0&&Ta(e.state.doc.resolve(o))||Ta(e.state.doc.resolve(r))}var Rc=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),$c(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,$c(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function $c(e,t,n,o,r,i){let s=0,l=!0,a=t.firstChild;const c=e.firstChild;if(c){for(let e=0,n=0;e<c.childCount;e++){const{colspan:d,colwidth:h}=c.child(e).attrs;for(let e=0;e<d;e++,n++){const c=r==n?i:h&&h[e],d=c?c+"px":"";if(s+=c||o,c||(l=!1),a)a.style.width!=d&&(a.style.width=d),a=a.nextSibling;else{const e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;a;){var d;const e=a.nextSibling;null===(d=a.parentNode)||void 0===d||d.removeChild(a),a=e}l?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}const Ic=new Nt("tableColumnResizing");function zc({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:o=Rc,lastColumnResizable:r=!0}={}){const i=new St({key:Ic,state:{init(e,t){var r;const s=null===(r=i.spec)||void 0===r||null===(r=r.props)||void 0===r?void 0:r.nodeViews,l=Oa(t.schema).table.name;return o&&s&&(s[l]=(e,t)=>new o(e,n,t)),new Bc(-1,!1)},apply:(e,t)=>t.apply(e)},props:{attributes:e=>{const t=Ic.getState(e);return t&&t.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(t,n)=>{!function(e,t,n,o){if(!e.editable)return;const r=Ic.getState(e.state);if(r&&!r.dragging){const i=function(e){for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}(t.target);let s=-1;if(i){const{left:o,right:r}=i.getBoundingClientRect();t.clientX-o<=n?s=Pc(e,t,"left",n):r-t.clientX<=n&&(s=Pc(e,t,"right",n))}if(s!=r.activeHandle){if(!o&&-1!==s){const t=e.state.doc.resolve(s),n=t.node(-1),o=ka.get(n),r=t.start(-1);if(o.colCount(t.pos-r)+t.nodeAfter.attrs.colspan-1==o.width-1)return}Fc(e,s)}}}(t,n,e,r)},mouseleave:e=>{!function(e){if(!e.editable)return;const t=Ic.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Fc(e,-1)}(e)},mousedown:(e,o)=>{!function(e,t,n,o){var r;if(!e.editable)return!1;const i=null!==(r=e.dom.ownerDocument.defaultView)&&void 0!==r?r:window,s=Ic.getState(e.state);if(!s||-1==s.activeHandle||s.dragging)return!1;const l=e.state.doc.nodeAt(s.activeHandle),a=function(e,t,{colspan:n,colwidth:o}){const r=o&&o[o.length-1];if(r)return r;const i=e.domAtPos(t);let s=i.node.childNodes[i.offset].offsetWidth,l=n;if(o)for(let e=0;e<n;e++)o[e]&&(s-=o[e],l--);return s/l}(e,s.activeHandle,l.attrs);function c(t){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",d);const o=Ic.getState(e.state);(null==o?void 0:o.dragging)&&(function(e,t,n){const o=e.state.doc.resolve(t),r=o.node(-1),i=ka.get(r),s=o.start(-1),l=i.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1,a=e.state.tr;for(let e=0;e<i.height;e++){const t=e*i.width+l;if(e&&i.map[t]==i.map[t-i.width])continue;const o=i.map[t],c=r.nodeAt(o).attrs,d=1==c.colspan?0:l-i.colCount(o);if(c.colwidth&&c.colwidth[d]==n)continue;const h=c.colwidth?c.colwidth.slice():Hc(c.colspan);h[d]=n,a.setNodeMarkup(s+o,null,{...c,colwidth:h})}a.docChanged&&e.dispatch(a)}(e,o.activeHandle,Vc(o.dragging,t,n)),e.dispatch(e.state.tr.setMeta(Ic,{setDragging:null})))}function d(t){if(!t.which)return c(t);const r=Ic.getState(e.state);if(r&&r.dragging){const i=Vc(r.dragging,t,n);Lc(e,r.activeHandle,i,o)}}e.dispatch(e.state.tr.setMeta(Ic,{setDragging:{startX:t.clientX,startWidth:a}})),Lc(e,s.activeHandle,a,o),i.addEventListener("mouseup",c),i.addEventListener("mousemove",d),t.preventDefault()}(e,o,t,n)}},decorations:e=>{const t=Ic.getState(e);if(t&&t.activeHandle>-1)return function(e,t){const n=[],o=e.doc.resolve(t),r=o.node(-1);if(!r)return Tl.empty;const i=ka.get(r),s=o.start(-1),l=i.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1;for(let t=0;t<i.height;t++){const o=l+t*i.width;if(!(l!=i.width-1&&i.map[o]==i.map[o+1]||0!=t&&i.map[o]==i.map[o-i.width])){var a;const t=i.map[o],l=s+t+r.nodeAt(t).nodeSize-1,c=document.createElement("div");c.className="column-resize-handle",(null===(a=Ic.getState(e))||void 0===a?void 0:a.dragging)&&n.push(Nl.node(s+t,s+t+r.nodeAt(t).nodeSize,{class:"column-resize-dragging"})),n.push(Nl.widget(l,c))}}return Tl.create(e.doc,n)}(e,t.activeHandle)},nodeViews:{}}});return i}var Bc=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){const n=this,o=t.getMeta(Ic);if(o&&null!=o.setHandle)return new e(o.setHandle,!1);if(o&&void 0!==o.setDragging)return new e(n.activeHandle,o.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return Ra(t.doc.resolve(o))||(o=-1),new e(o,n.dragging)}return n}};function Pc(e,t,n,o){const r="right"==n?-o:o,i=e.posAtCoords({left:t.clientX+r,top:t.clientY});if(!i)return-1;const{pos:s}=i,l=Ta(e.state.doc.resolve(s));if(!l)return-1;if("right"==n)return l.pos;const a=ka.get(l.node(-1)),c=l.start(-1),d=a.map.indexOf(l.pos-c);return d%a.width==0?-1:c+a.map[d-1]}function Vc(e,t,n){const o=t.clientX-e.startX;return Math.max(n,e.startWidth+o)}function Fc(e,t){e.dispatch(e.state.tr.setMeta(Ic,{setHandle:t}))}function Lc(e,t,n,o){const r=e.state.doc.resolve(t),i=r.node(-1),s=r.start(-1),l=ka.get(i).colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;let a=e.domAtPos(r.start(-1)).node;for(;a&&"TABLE"!=a.nodeName;)a=a.parentNode;a&&$c(i,a.firstChild,a,o,l,n)}function Hc(e){return Array(e).fill(0)}function _c({allowTableNodeSelection:e=!1}={}){return new St({key:Aa,state:{init:()=>null,apply(e,t){const n=e.getMeta(Aa);if(null!=n)return-1==n?null:n;if(null==t||!e.docChanged)return t;const{deleted:o,pos:r}=e.mapping.mapResult(t);return o?null:r}},props:{decorations:Wa,handleDOMEvents:{mousedown:Ac},createSelectionBetween:e=>null!=Aa.getState(e.state)?e.state.selection:null,handleTripleClick:Nc,handleKeyDown:xc,handlePaste:Oc},appendTransaction:(t,n,o)=>function(e,t,n){const o=(t||e).selection,r=(t||e).doc;let i,s;if(o instanceof dt&&(s=o.node.type.spec.tableRole)){if("cell"==s||"header_cell"==s)i=Ha.create(r,o.from);else if("row"==s){const e=r.resolve(o.from+1);i=Ha.rowSelection(e,e)}else if(!n){const e=ka.get(o.node),t=o.from+1,n=t+e.map[e.width*e.height-1];i=Ha.create(r,t+1,n)}}else o instanceof at&&function({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,o=t.pos,r=e.depth;for(;r>=0&&!(e.after(r+1)<e.end(r));r--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,o--);return n==o&&/row|table/.test(e.node(r).type.spec.tableRole)}(o)?i=at.create(r,o.from):o instanceof at&&function({$from:e,$to:t}){let n,o;for(let t=e.depth;t>0;t--){const o=e.node(t);if("cell"===o.type.spec.tableRole||"header_cell"===o.type.spec.tableRole){n=o;break}}for(let e=t.depth;e>0;e--){const n=t.node(e);if("cell"===n.type.spec.tableRole||"header_cell"===n.type.spec.tableRole){o=n;break}}return n!==o&&0===t.parentOffset}(o)&&(i=at.create(r,o.$from.start(),o.$from.end()));return i&&(t||(t=e.tr)).setSelection(i),t}(o,Ja(o,n),e)})}const Wc=["blockquote",0],qc=["hr"],jc=["pre",["code",0]],Jc=["ol",0],Kc=["ul",0],Xc=["li",0],Uc=e=>{const t={},n=e.attributes;let o;for(let e=0;e<n.length;e++)o=n[e],t[o.name]=o.value;return t},Gc=e=>{const t={};return e.forEach(e=>{t[e]={default:null}}),t},Yc=()=>Gc(["style","class","id"]),Qc=(e,t)=>{for(const n in e)if(n&&null!==e[n]&&n!==t)return!0;return!1},Zc=(e,t=[])=>{const n={};for(const o in e)o&&null!==e[o]&&!t.find(e=>e===o)&&(n[o]=e[o]);return n},ed=e=>({[e]:{name:e,inclusive:!0,parseDOM:[{tag:e}],toDOM:()=>[e,0]}}),td={link:{attrs:{...Yc(),href:{default:null},target:{default:null},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a",getAttrs:Uc}],toDOM:e=>["a",Zc(e.attrs),0]},...ed("strong"),...ed("b"),...ed("em"),...ed("i"),...ed("del"),...ed("sub"),...ed("sup"),...ed("code"),style:{attrs:{...Yc()},parseDOM:[{tag:"span",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["span",Zc(e.attrs),0]:["span",0]},...ed("u")},nd=e=>({[e]:{default:null,getFromDOM:t=>t.getAttribute(e),setDOMAttr:(t,n)=>{n[e]=t}}}),od={...nd("style"),...nd("class"),...nd("id"),...nd("headers"),...nd("scope")},rd={doc:{content:"colgroup*"},col:{attrs:Gc(["id","class","style","span"]),parseDOM:[{getAttrs:Uc,tag:"col"}],toDOM:e=>["col",e.attrs]},colgroup:{attrs:Gc(["id","class","style","span"]),content:"col*",parseDOM:[{getAttrs:Uc,tag:"colgroup"}],toDOM:e=>["colgroup",e.attrs,0]},text:{inline:!0,group:"inline"}},id=new U({nodes:rd,marks:{}}),sd=e=>{const t=An(Mn(e),id,{preserveWhitespace:!1});return On(t).firstChild},ld=Na({tableGroup:"block",cellContent:"block+",cellAttributes:od});ld.table_row.attrs={...ld.table_row.attrs,...Gc([Ot,"style","class","id"])},ld.table_row.toDOM=e=>["tr",Zc(e.attrs),0],ld.table_row.parseDOM=[{tag:"tr",getAttrs:Uc}],ld.table.attrs={...ld.table.attrs,...Gc(["style","class","id",At,Tt])},ld.table.toDOM=e=>{const t=Qc(e.attrs)?Zc(e.attrs,[At,Tt]):{};let n=null;if(e.attrs[At]&&!(e=>{let t=!1;const n=e.child(0);for(let e=0;e<n.childCount;e++)if(n.child(e).attrs.colwidth){t=!0;break}return t})(e)){const t=sd(e.attrs[At]);if(t){const e=Array.from(t.children).map(e=>["col",Uc(e)]);n=["colgroup",Uc(t)].concat(e)}}return n?["table",t,n,["tbody",0]]:["table",t,["tbody",0]]},ld.table.parseDOM=[{tag:"table",getAttrs:e=>{const t=Uc(e),n=Array.from(e.childNodes).find(e=>"COLGROUP"===e.nodeName);return n&&(t[At]=n.outerHTML),t}}];const ad={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",attrs:{...Yc()},parseDOM:[{tag:"p",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["p",Zc(e.attrs),0]:["p",0]},table_wrapper:{content:"(table_caption_external | table)+",group:"block",defining:!0,attrs:{table:{default:null},style:{default:null}},parseDOM:[{tag:"div[table]",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["div",Zc(e.attrs),0]:["div",0]},table_caption_external:{content:"inline+",group:"block",attrs:{caption:{default:null},...Yc()},parseDOM:[{tag:"div[caption]",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["div",Zc(e.attrs),0]:["div",0]},div:{content:"block*",group:"block",attrs:{...Yc()},parseDOM:[{tag:"div",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["div",Zc(e.attrs),0]:["div",0]},blockquote:{attrs:{...Yc()},content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["blockquote",Zc(e.attrs),0]:Wc},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>qc},heading:{attrs:{...Yc(),level:{default:1}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",getAttrs:e=>({...Uc(e),level:1})},{tag:"h2",getAttrs:e=>({...Uc(e),level:2})},{tag:"h3",getAttrs:e=>({...Uc(e),level:3})},{tag:"h4",getAttrs:e=>({...Uc(e),level:4})},{tag:"h5",getAttrs:e=>({...Uc(e),level:5})},{tag:"h6",getAttrs:e=>({...Uc(e),level:6})}],toDOM:e=>Qc(e.attrs,"level")?["h"+e.attrs.level,Zc(e.attrs,["level"]),0]:["h"+e.attrs.level,0]},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>jc},text:{inline:!0,group:"inline"},image:{inline:!0,attrs:{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null},...Yc()},group:"inline",draggable:!0,parseDOM:[{tag:"img",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["img",Zc(e.attrs)]:["img"]},hard_break:{inline:!0,attrs:{...Yc()},group:"inline",selectable:!1,parseDOM:[{tag:"br",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["br",Zc(e.attrs)]:["br"]},ordered_list:{content:"list_item+",group:"block",attrs:{...Yc(),type:{default:null},order:{default:1}},parseDOM:[{tag:"ol",getAttrs:e=>({...Uc(e),order:e.hasAttribute("start")?parseInt(e.getAttribute("start")||"1",10):1})}],toDOM:e=>1===e.attrs.order?Qc(e.attrs,"order")?["ol",Zc(e.attrs,["order"]),0]:Jc:["ol",{...Zc(e.attrs,["order"]),start:e.attrs.order},0]},bullet_list:{content:"list_item+",group:"block",attrs:{...Yc()},parseDOM:[{tag:"ul",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["ul",Zc(e.attrs),0]:Kc},list_item:{content:"(paragraph | heading) block*",attrs:{...Yc()},parseDOM:[{tag:"li",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["li",Zc(e.attrs),0]:Xc,defining:!0},...ld};var cd=200,dd=function(){};dd.prototype.append=function(e){return e.length?(e=dd.from(e),!this.length&&e||e.length<cd&&this.leafAppend(e)||this.length<cd&&e.leafPrepend(this)||this.appendInner(e)):this},dd.prototype.prepend=function(e){return e.length?dd.from(e).append(this):this},dd.prototype.appendInner=function(e){return new pd(this,e)},dd.prototype.slice=function(e,t){return void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t?dd.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},dd.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},dd.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)},dd.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var o=[];return this.forEach(function(t,n){return o.push(e(t,n))},t,n),o},dd.from=function(e){return e instanceof dd?e:e&&e.length?new hd(e):dd.empty};var hd=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,o){for(var r=t;r<n;r++)if(!1===e(this.values[r],o+r))return!1},t.prototype.forEachInvertedInner=function(e,t,n,o){for(var r=t-1;r>=n;r--)if(!1===e(this.values[r],o+r))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=cd)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=cd)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(dd);dd.empty=new hd([]);var pd=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,o){var r=this.left.length;return!(t<r&&!1===this.left.forEachInner(e,t,Math.min(n,r),o))&&!(n>r&&!1===this.right.forEachInner(e,Math.max(t-r,0),Math.min(this.length,n)-r,o+r))&&void 0},t.prototype.forEachInvertedInner=function(e,t,n,o){var r=this.left.length;return!(t>r&&!1===this.right.forEachInvertedInner(e,t-r,Math.max(n,r)-r,o+r))&&!(n<r&&!1===this.left.forEachInvertedInner(e,Math.min(t,r),n,o))&&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}(dd);const ud=dd;class fd{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,o,r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}t&&(n=this.remapping(r,this.items.length),o=n.maps.length);let i,s,l=e.tr,a=[],c=[];return this.items.forEach((e,t)=>{if(!e.step)return n||(n=this.remapping(r,t+1),o=n.maps.length),o--,void c.push(e);if(n){c.push(new md(e.map));let t,r=e.step.map(n.slice(o));r&&l.maybeStep(r).doc&&(t=l.mapping.maps[l.mapping.maps.length-1],a.push(new md(t,void 0,void 0,a.length+c.length))),o--,t&&n.appendMap(t,o)}else l.maybeStep(e.step);return e.selection?(i=n?e.selection.map(n.slice(o)):e.selection,s=new fd(this.items.slice(0,r).append(c.reverse().concat(a)),this.eventCount-1),!1):void 0},this.items.length,0),{remaining:s,transform:l,selection:i}}addTransform(e,t,n,o){let r=[],i=this.eventCount,s=this.items,l=!o&&s.length?s.get(s.length-1):null;for(let n=0;n<e.steps.length;n++){let a,c=e.steps[n].invert(e.docs[n]),d=new md(e.mapping.maps[n],c,t);(a=l&&l.merge(d))&&(d=a,n?r.pop():s=s.slice(0,s.length-1)),r.push(d),t&&(i++,t=void 0),o||(l=d)}let a=i-n.depth;return a>yd&&(s=function(e,t){let n;return e.forEach((e,o)=>{if(e.selection&&0==t--)return n=o,!1}),e.slice(n)}(s,a),i-=a),new fd(s.append(r),i)}remapping(e,t){let n=new ye;return this.items.forEach((t,o)=>{let r=null!=t.mirrorOffset&&o-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,r)},e,t),n}addMaps(e){return 0==this.eventCount?this:new fd(this.items.append(e.map(e=>new md(e))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],o=Math.max(0,this.items.length-t),r=e.mapping,i=e.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},o);let l=t;this.items.forEach(t=>{let o=r.getMirror(--l);if(null==o)return;i=Math.min(i,o);let a=r.maps[o];if(t.step){let i=e.steps[o].invert(e.docs[o]),c=t.selection&&t.selection.map(r.slice(l+1,o));c&&s++,n.push(new md(a,i,c))}else n.push(new md(a))},o);let a=[];for(let e=t;e<i;e++)a.push(new md(r.maps[e]));let c=this.items.slice(0,o).append(a).append(n),d=new fd(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,o=[],r=0;return this.items.forEach((i,s)=>{if(s>=e)o.push(i),i.selection&&r++;else if(i.step){let e=i.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let l=i.selection&&i.selection.map(t.slice(n));l&&r++;let a,c=new md(s.invert(),e,l),d=o.length-1;(a=o.length&&o[d].merge(c))?o[d]=a:o.push(c)}}else i.map&&n--},this.items.length,0),new fd(ud.from(o.reverse()),r)}}fd.empty=new fd(ud.empty,0);class md{constructor(e,t,n,o){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=o}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new md(t.getMap().invert(),t,this.selection)}}}class gd{constructor(e,t,n,o,r){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=o,this.prevComposition=r}}const yd=20;function wd(e){let t=[];for(let n=e.length-1;n>=0&&0==t.length;n--)e[n].forEach((e,n,o,r)=>t.push(o,r));return t}function vd(e,t){if(!e)return null;let n=[];for(let o=0;o<e.length;o+=2){let r=t.map(e[o],1),i=t.map(e[o+1],-1);r<=i&&n.push(r,i)}return n}let bd=!1,kd=null;function xd(e){let t=e.plugins;if(kd!=t){bd=!1,kd=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){bd=!0;break}}return bd}function Sd(e){return e.setMeta(Md,!0)}const Cd=new Nt("history"),Md=new Nt("closeHistory");function Nd(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new St({key:Cd,state:{init:()=>new gd(fd.empty,fd.empty,null,0,-1),apply:(t,n,o)=>function(e,t,n,o){let r,i=n.getMeta(Cd);if(i)return i.historyState;n.getMeta(Md)&&(e=new gd(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(Cd))return s.getMeta(Cd).redo?new gd(e.done.addTransform(n,void 0,o,xd(t)),e.undone,wd(n.mapping.maps),e.prevTime,e.prevComposition):new gd(e.done,e.undone.addTransform(n,void 0,o,xd(t)),null,e.prevTime,e.prevComposition);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(r=n.getMeta("rebased"))?new gd(e.done.rebased(n,r),e.undone.rebased(n,r),vd(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new gd(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),vd(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);{let r=n.getMeta("composition"),i=0==e.prevTime||!s&&e.prevComposition!=r&&(e.prevTime<(n.time||0)-o.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,o)=>{for(let r=0;r<t.length;r+=2)e<=t[r+1]&&o>=t[r]&&(n=!0)}),n}(n,e.prevRanges)),l=s?vd(e.prevRanges,n.mapping):wd(n.mapping.maps);return new gd(e.done.addTransform(n,i?t.selection.getBookmark():void 0,o,xd(t)),fd.empty,l,n.time,null==r?e.prevComposition:r)}}(n,o,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,o="historyUndo"==n?Ad:"historyRedo"==n?Td:null;return!(!o||!e.editable)&&(t.preventDefault(),o(e.state,e.dispatch))}}}})}function Od(e,t){return(n,o)=>{let r=Cd.getState(n);if(!r||0==(e?r.undone:r.done).eventCount)return!1;if(o){let i=function(e,t,n){let o=xd(t),r=Cd.get(t).spec.config,i=(n?e.undone:e.done).popEvent(t,o);if(!i)return null;let s=i.selection.resolve(i.transform.doc),l=(n?e.done:e.undone).addTransform(i.transform,t.selection.getBookmark(),r,o),a=new gd(n?l:i.remaining,n?i.remaining:l,null,0,-1);return i.transform.setSelection(s).setMeta(Cd,{redo:n,historyState:a})}(r,n,e);i&&o(t?i.scrollIntoView():i)}return!0}}const Ad=Od(!1,!0),Td=Od(!0,!0),Dd=Od(!1,!1),Ed=Od(!0,!1);function Rd(e){let t=Cd.getState(e);return t?t.done.eventCount:0}function $d(e){let t=Cd.getState(e);return t?t.undone.eventCount:0}function Id(e){return null!=e.getMeta(Cd)}class zd{constructor(e,t,n={}){var o;this.match=e,this.match=e,this.handler="string"==typeof t?(o=t,function(e,t,n,r){let i=o;if(t[1]){let e=t[0].lastIndexOf(t[1]);i+=t[0].slice(e+t[1].length);let o=(n+=e)-r;o>0&&(i=t[0].slice(e-o,e)+i,n=r)}return e.tr.insertText(i,n,r)}):t,this.undoable=!1!==n.undoable,this.inCode=n.inCode||!1,this.inCodeMark=!1!==n.inCodeMark}}const Bd=500;function Pd({rules:e}){let t=new St({state:{init:()=>null,apply(e,t){return e.getMeta(this)||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput:(n,o,r,i)=>Vd(n,o,r,i,e,t),handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:o}=n.state.selection;o&&Vd(n,o.pos,o.pos,"",e,t)})}}},isInputRules:!0});return t}function Vd(e,t,n,o,r,i){if(e.composing)return!1;let s=e.state,l=s.doc.resolve(t),a=l.parent.textBetween(Math.max(0,l.parentOffset-Bd),l.parentOffset,null,"")+o;for(let c=0;c<r.length;c++){let d=r[c];if(!d.inCodeMark&&l.marks().some(e=>e.type.spec.code))continue;if(l.parent.type.spec.code){if(!d.inCode)continue}else if("only"===d.inCode)continue;let h=d.match.exec(a);if(!h||h[0].length<o.length)continue;let p=t-(h[0].length-o.length);if(!d.inCodeMark){let e=!1;if(s.doc.nodesBetween(p,l.pos,t=>{t.isInline&&t.marks.some(e=>e.type.spec.code)&&(e=!0)}),e)continue}let u=d.handler(s,h,p,n);if(u)return d.undoable&&u.setMeta(i,{transform:u,from:t,to:n,text:o}),e.dispatch(u),!0}return!1}const Fd=(e,t)=>{let n=e.plugins;for(let o=0;o<n.length;o++){let r,i=n[o];if(i.spec.isInputRules&&(r=i.getState(e))){if(t){let n=e.tr,o=r.transform;for(let e=o.steps.length-1;e>=0;e--)n.step(o.steps[e].invert(o.docs[e]));if(r.text){let t=n.doc.resolve(r.from).marks();n.replaceWith(r.from,r.to,e.schema.text(r.text,t))}else n.delete(r.from,r.to);t(n)}return!0}}return!1},Ld=new zd(/--$/,"—",{inCodeMark:!1}),Hd=new zd(/\.\.\.$/,"…",{inCodeMark:!1}),_d=new zd(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1}),Wd=new zd(/"$/,"”",{inCodeMark:!1}),qd=new zd(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1}),jd=new zd(/'$/,"’",{inCodeMark:!1}),Jd=[_d,Wd,qd,jd];function Kd(e,t,n=null,o){return new zd(e,(e,r,i,s)=>{let l=n instanceof Function?n(r):n,a=e.tr.delete(i,s),c=a.doc.resolve(i).blockRange(),d=c&&Re(c,t,l);if(!d)return null;a.wrap(c,d);let h=a.doc.resolve(i-1).nodeBefore;return h&&h.type==t&&Pe(a.doc,i-1)&&(!o||o(r,h))&&a.join(i-1),a})}function Xd(e,t,n=null){return new zd(e,(e,o,r,i)=>{let s=e.doc.resolve(r),l=n instanceof Function?n(o):n;return s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),t)?e.tr.delete(r,i).setBlockType(r,r,t,l):null})}const Ud={mark:"strong",altMarks:["b"],altStyle:{name:"font-weight",value:/^(bold(er)?|[5-9]\d{2,})$/}},Gd={mark:"em",altMarks:["i"],altStyle:{name:"font-style",value:/^italic$/i}},Yd={mark:"u",altStyle:{name:"text-decoration",value:/^underline$/i}},Qd={mark:"del",altStyle:{name:"text-decoration",value:/^line-through$/i}},Zd={mark:"sub"},eh={mark:"sup"},th={mark:"link"},nh="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),oh=(e,t)=>{const n={},o=t&&t.applyToWord||!1;if(n["Mod-z"]=Ad,n["Shift-Mod-z"]=Td,n.Backspace=wr(Fd,Po,Fo,qo),n.Enter=wr(Zo,nr,or,sr),nh||(n["Mod-y"]=Td),e.marks.strong&&(n["Mod-b"]=an(Zn,{...Ud,applyToWord:o})),e.marks.em&&(n["Mod-i"]=an(Zn,{...Gd,applyToWord:o})),e.marks.u&&(n["Mod-u"]=an(Zn,{...Yd,applyToWord:o})),e.nodes.hard_break){const t=e.nodes.hard_break,o=wr(tr,(e,n)=>(n(e.tr.replaceSelectionWith(t.create()).scrollIntoView()),!0));n["Shift-Enter"]=o}return n},rh=e=>{const t={};var n;return e.nodes.list_item&&(t.Enter=(n=e.nodes.list_item,(e,t)=>Ao(n)(e,n=>{const o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();o&&n.ensureMarks(o),t(n)}))),t},ih=/style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi,sh=e=>/^MsoListParagraph/.test(e.className),lh=e=>e.textContent,ah=(e,t)=>{const n=document.createElement(e);return n.style.listStyleType=t,n},ch=e=>{let t=null;return/^\d/.test(e)||(t=(/^[a-z]/.test(e)?"lower-":"upper-")+(/^[ivxlcdm]/i.test(e)?"roman":"alpha")),t},dh=(e,t)=>{let n=[];Array.from(e).forEach(e=>{if(e.nodeType!==Node.ELEMENT_NODE)return;const o=e;o.getAttribute("datalist")?(n.push(e),t.add(n)):sh(o)&&n.length?n.push(e):(n=[],"DIV"===o.nodeName?dh(o.children,t):"TABLE"===o.nodeName&&Array.from(o.querySelectorAll("td,th")).forEach(e=>{dh(e.children,t)}))})},hh=e=>{const t=e.textContent,n=e=>e.replace(/^(?:&nbsp;|[\u00a0\n\r\s])+/,"");return/^[\u2022\u00b7\u00a7\u00d8oØüvn][\u00a0 ]+/.test(t)?{tag:"ul",style:(o=n(lh(e)),/^[\u2022\u00b7\u00FC\u00D8\u002dv-]/.test(o)?null:/^o/.test(o)?"circle":"square")}:/^\s*\w+[.)][\u00a0 ]{2,}/.test(t)?{tag:"ol",style:ch(n(lh(e)))}:void 0;var o},ph=e=>{const t=e.nodeName.toLowerCase();let n;e.firstChild&&e.firstChild.nodeType===Node.COMMENT_NODE&&e.removeChild(e.firstChild),1===e.childNodes.length?n=e.firstChild.nodeType===Node.TEXT_NODE?lh(e):e.firstChild.innerHTML.replace(/^\w+[.)](&nbsp;)+ /,""):(e.removeChild(e.firstChild),3===e.firstChild.nodeType&&/^[ivxlcdm]+\.$/i.test(e.firstChild.nodeValue)&&e.removeChild(e.firstChild),/^(&nbsp;|\s)+$/i.test(e.firstChild.innerHTML)&&e.removeChild(e.firstChild),n="p"!==t?"<"+t+">"+e.innerHTML+"</"+t+">":e.innerHTML),e.parentNode.removeChild(e);const o=document.createElement("li");return o.appendChild(Mn(n)),o},uh=e=>{const t=Mn((e=>e.replace(ih,(e,t,n)=>`datalist="${t}" datalevel="${n}" ${e}`))(e)),n=new Set;return dh(t.children,n),n.forEach(e=>(e=>{const t={};let n,o,r,i,s,l,a,c,d,h,p,u,f,m=-1;for(c=0;c<e.length;c++){d=e[c],f={datalist:d.getAttribute("datalist"),datalevel:d.getAttribute("datalevel")};const g=f.datalist,y=hh(d);if(h=y&&y.tag,!h){!n||s&&!sh(d)||(d.style.marginLeft&&(d.style.marginLeft=""),d.style.marginLeft&&(d.style.margin=""),n.appendChild(d));continue}if(p=f.datalevel||parseFloat(d.style.marginLeft||0),!f.datalevel&&!d.style.marginLeft)continue;const w=h+g;t[p]||(t[p]={}),(!o||o<0)&&(o=p,r=g,a=e.filter(e=>e.getAttribute("datalist")===String(r)),i=a[a.length-1],l=ah(h,y&&y.style),d.parentNode.insertBefore(l,d),m=p,t[p][w]=l),s=i===d,u=t[p][w],(p>m||!u)&&(u=ah(h,y&&y.style),t[p][w]=u,n.appendChild(u)),n=ph(d),u.appendChild(n),s?o=m=-1:m=p}})(e)),Nn(t)},fh=e=>{let t;e=(e=(e=(e=e.replace(/^[\s\S]+?<!--StartFragment-->\s*([\s\S]*?)\s*<!--EndFragment-->[\s\S]+$/,"$1")).replace(/<\/?[ovw]:[^>]*?>/gi,"")).replace(/<\\?\??xml[^>]*>/gi,"")).replace(/<(?:link|meta) [^>]+?>/gi,"");do{t=e,e=e.replace(/<style[^>]*?>\s*<\/style>/gi,"")}while(e!==t);return(e=(e=(e=(e=e.replace(/<\/?st1:.*?>/gi,"")).replace(/<a name="[a-zA-Z0-9_]+">/gim,"")).replace(/v:shapes?="[^"]+"/gi,"")).replace(/<!\[if !supportLists\]>/gi,"")).replace(/<!\[endif\]>/gi,"")},mh=(e,t)=>e.replace(new RegExp("<\\/?("+t+")(?:\\s[^>]*?)?>","gi"),""),gh=e=>{e.ownerElement&&e.ownerElement.removeAttribute(e.name)},yh=e=>{/^Mso/.test(e.value)&&gh(e)},wh=e=>{const t=cn(e.value),n=e.ownerElement.style;let o="";Object.keys(t).forEach(e=>{void 0!==n[e]&&(o+=`${e}: ${t[e]}; `)}),o=o.trim(),o?e.value=o:gh(e)},vh=(e,t)=>{let n=e;if(t.convertMsLists&&(n=uh(n)),t.stripTags&&(n=mh(n,t.stripTags)),t.attributes){const e=Mn(n);Array.from(e.querySelectorAll("*")).forEach(e=>((e,t)=>{if(e.nodeType===Node.ELEMENT_NODE){for(let n=e.attributes.length-1;n>=0;n--){const o=e.attributes[n];t[o.name]?t[o.name](o):t["*"]&&t["*"](o)}"SPAN"===e.nodeName&&0===e.attributes.length&&(e=>{const t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}})(e)}})(e,t.attributes)),n=Nn(e)}return n};function bh(e){const t=e.length,n=new Array(t/2);for(let o=0;o<t;o+=2)n[o]=String.fromCharCode(parseInt(e.substring(o,o+2),16));return btoa(n.join(""))}const kh=/<img\s[^>]*?src=(?:'|")file:\/[^'"]+(?:'|")[^>]*>/gi,xh=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,Sh=new RegExp("(?:("+xh.source+"))([\\da-fA-F\\s]+)\\}","g"),Ch=/[^\da-fA-F]/g,Mh=/file:\/[^'"]+\.(jpg|png|gif)/i,Nh=/\\(png|jpeg)blip\\/,Oh="text/rtf",Ah=(e,t)=>{const n=e.match(kh);if(!n||-1===t.types.indexOf(Oh))return e;const o=t.getData(Oh),r=[],i=o.match(Sh);if(!o||!i)return e;for(const e of i){const t=Nh.exec(e);if(t){const n=e.replace(xh,"").replace(Ch,"");r.push(`data:image/${t[1]};base64,${bh(n)}`)}}return n.length!==r.length?e:e.replace(kh,e=>{const t=r.shift()||"";return e.replace(Mh,t)})},Th=(e,t,n,o,r)=>{const i=[];let s,l,a,c,d,h;const p=[],{matchCase:u,matchWord:f,useRegExp:m}=t,g=t.text;if(!g)return i;const y=u?"g":"gi",w=m?new RegExp(g,y):new RegExp(Bh(g),y);return e.nodesBetween(n,o,(t,u)=>{if(r(i))return!1;t.inlineContent&&u+t.content.size>=n&&(p.length=0,t.nodesBetween(0,t.content.size,(t,m,g,y)=>{if(r(i))return!1;const v=1+u+m;if(t.isText&&v+t.nodeSize>=n){if(d=t.text||"",h=g.childCount-1>=y+1&&g.child(y+1),p.push(n<=v?{text:d,start:v}:{text:d.slice(n-v),start:n}),h&&h.isText)return;for(l=p.map(e=>e.text).join(""),s=w.exec(l);null!==s;){if(s[0].length>0){if(a=p[0].start+s.index,c=a+s[0].length,n<=a&&o>=c&&zh(s,f)&&i.push(at.create(e,a,c)),r(i))break}else w.lastIndex++;s=w.exec(l)}}else p.length=0}))}),i},Dh=(e,t)=>{const{backward:n,matchCyclic:o,...r}=t,i=n?()=>!1:e=>e.length>0,{doc:s,selection:l}=e;let a=[];return n?(a=Th(s,r,0,l.from,i),!a.length&&o&&(a=Th(s,r,l.from,s.content.size,i))):(a=Th(s,r,l.to,s.content.size,i),!a.length&&o&&(a=Th(s,r,0,l.to,i))),a.length?a[a.length-1]:null},Eh=(e,t)=>Th(e,t,0,e.content.size,()=>!1),Rh=(e,t,n)=>{const{from:o,to:r}=e;return n.insertText(t,o,r).setSelection(at.create(n.doc,o,o+t.length)),n},$h=(e,t,n)=>{const o=Eh(e.doc,n);if(0===o.length)return null;const r=e.tr;for(let e=o.length-1;e>=0;e--)r.insertText(t,o[e].from,o[e].to);return r},Ih=/^[\s0-9~`!@#$%^&*()_\-=+\\|[\]{};:'"?/.,<>]?$/,zh=(e,t)=>{if(t){if(!0===t){const t=e.input,n=t.charAt(e.index-1),o=t.charAt(e.index+e[0].length);return Ih.test(n)&&Ih.test(o)}return t(e)}return!0},Bh=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Ph(e){const t={class:"k-placeholder","data-placeholder":e};return new St({key:new Nt("placeholder"),props:{decorations:e=>{const{doc:n}=e,o=n.content.firstChild;if(!(0===n.childCount||1===n.childCount&&o.inlineContent&&0===o.childCount))return Tl.empty;const r=[];return n.descendants((e,n)=>{r.push(Nl.node(n,n+e.nodeSize,t))}),Tl.create(n,r)}}})}const Vh=/\s+/g,Fh=/text-align/,Lh=()=>new St({key:new Nt("spaces-fix"),props:{decorations:e=>{const t=[],n=e.doc;let o,r,i,s;return n.nodesBetween(0,n.content.size,(e,n,l)=>{if(e.type.isText&&(e=>Fh.test(e&&e.attrs&&e.attrs.style||""))(l))for(r=Vh.exec(e.text||"");null!==r;){if(o=n+r.index,i=r[0].length,r.index+i<r.input.length)for(s=0;s<=i-1;s+=2)t.push(Nl.inline(o+s,o+s+1,{style:"white-space: normal"}));r=Vh.exec(e.text||"")}}),Tl.create(n,t)}}}),Hh=(e,t)=>{for(const n in t)n&&pn(e,n,t[n])};class _h{constructor(e,t,n,o=!1){this.node=e,this.view=t,this.dom=document.createElement(n),Hh(this.dom,e.attrs),this.contentDOM=o?void 0:this.dom}}class Wh{constructor(e,t){this.mark=e,this.view=t,this.dom=document.createElement("span"),Hh(this.dom,e.attrs),this.contentDOM=this.dom}}const qh=()=>new St({key:new Nt("csp-fix"),props:{nodeViews:{paragraph:(e,t)=>new _h(e,t,"p"),div:(e,t)=>new _h(e,t,"div"),table_wrapper:(e,t)=>new _h(e,t,"div"),table_caption_external:(e,t)=>new _h(e,t,"div"),table:(e,t)=>new _h(e,t,"table"),table_row:(e,t)=>new _h(e,t,"tr"),table_cell:(e,t)=>new _h(e,t,"td"),table_header:(e,t)=>new _h(e,t,"th"),image:(e,t)=>new _h(e,t,"img",!0)},markViews:{style:(e,t)=>new Wh(e,t)}}}),jh=new Nt("highlight");function Jh(e=jh){return new St({key:e,state:{init:()=>null,apply(e){return e.getMeta(this.spec.key)}},props:{decorations(e){const t=(this.spec.key.getState(e)||[]).map(e=>Nl.inline(e.from,e.to,e.attrs));return Tl.create(e.doc,t)}}})}const Kh={southeast:{x:1,y:1},east:{x:1,y:0},south:{x:0,y:1},north:{x:0,y:-1},west:{x:-1,y:0},southwest:{x:-1,y:1},northwest:{x:-1,y:-1},northeast:{x:1,y:-1}},Xh=Object.keys(Kh),Uh=new Nt("image-resize"),Gh=(e,t,n)=>{e.style[t]=n+"px"},Yh=/[^-]width:|[^-]height:/,Qh=/^.+$/;class Zh{constructor(e,t,n,o){this.activeHandle=e,this.dragging=t,this.rect=n,this.nodePosition=o}apply(e){const t=e.getMeta(Uh);return t?new Zh(t.activeHandle,t.setDragging,t.rect,t.nodePosition):this}}const ep=(e={node:"image",lockRatio:!0})=>new St({key:Uh,view:t=>({resize(){Uh.getState(t.state).rect&&t.dispatch(t.state.tr.setMeta("resize",!0))},get window(){return t.dom.ownerDocument&&t.dom.ownerDocument.defaultView},attachResize(){const e=this.window;e&&(e.removeEventListener("resize",this.resize),e.addEventListener("resize",this.resize))},removeResize(){const e=this.window;e&&e.removeEventListener("resize",this.resize)},update(t,n){const o=t.state,r=o.selection,i=o.schema.nodes[e.node],s=Uh.getState(o),l=s.rect;if(r instanceof dt&&i===r.node.type){const e=t.nodeDOM(r.from),i={top:e.offsetTop,left:e.offsetLeft,width:e.offsetWidth,height:e.offsetHeight};if(!n.selection.eq(r)||l&&(l.width!==i.width||l.height!==i.height||l.top!==i.top||l.left!==i.left)){const e=o.tr;e.setMeta(Uh,{rect:i,nodePosition:r.from}),t.dispatch(e),this.attachResize()}}else l&&(s.rect=null,s.nodePosition=-1)},destroy(){this.removeResize()}}),state:{init:()=>new Zh("",null,null,-1),apply:(e,t)=>t.apply(e)},props:{handleDOMEvents:{mousedown:(t,n)=>((e,t,n)=>{const o=t.target.getAttribute(Rt);if(!o)return!1;const r=Uh.getState(e.state);t.preventDefault();const i=e.state.tr;function s(t){((e,t,n)=>{const o=Uh.getState(e.state),{rect:r,dragging:i,nodePosition:s,activeHandle:l}=o;if(!i||!r)return;const a=e.nodeDOM(s),c=Kh[l],d=(t.clientX-i.startX)*c.x,h=(t.clientY-i.startY)*c.y;let p=c.x?d+a.width:r.width,u=c.y?h+a.height:r.height;if(n.lockRatio&&c.x&&c.y){const e=Math.min(p/a.width,u/a.height),n=a.width*e,o=a.height*e;i.startX=t.clientX-(p-n)*c.x,i.startY=t.clientY-(u-o)*c.y,p=n,u=o}else i.startX=c.x?t.clientX:i.startX,i.startY=c.y?t.clientY:i.startY;Gh(a,"width",p),Gh(a,"height",u),r.top=a.offsetTop,r.left=a.offsetLeft,r.width=a.offsetWidth,r.height=a.offsetHeight;const f=a.nextElementSibling;f.style.width=r.width+"px",f.style.height=r.height+"px",f.style.top=r.top+"px",f.style.left=r.left+"px"})(e,t,n)}return i.setMeta(Uh,{setDragging:{startX:t.clientX,startY:t.clientY},activeHandle:o,rect:r.rect,nodePosition:r.nodePosition}),i.setMeta("addToHistory",!1),e.dispatch(i),t.view.addEventListener("mouseup",function t(n){n.view.removeEventListener("mouseup",t),n.view.removeEventListener("mousemove",s),(e=>{const{rect:t,dragging:n,nodePosition:o}=Uh.getState(e.state);if(n&&t){const n=e.state.selection;if(n instanceof dt){const r=n.node.attrs,i=t.width,s=t.height;let l;if(Yh.test(r.style||"")){const e=Jt(r.style,{style:"width",value:Qh,newValue:i+"px"}),{style:t}=Jt(e.style||"",{style:"height",value:Qh,newValue:s+"px"});l={...r,style:t}}else l={...r,width:i,height:s};const a=n.node.type.createAndFill(l);if(a){const n=e.state.tr;n.replaceWith(o,o+1,a),n.setSelection(dt.create(n.doc,o)),n.setMeta("commandName","image-resize"),n.setMeta("args",l),n.setMeta(Uh,{setDragging:null,activeHandle:null,rect:t,nodePosition:o}),e.dispatch(n)}}}})(e)}),t.view.addEventListener("mousemove",s),!0})(t,n,e)},decorations(t){const n=t.selection,o=t.schema.nodes[e.node],r=Uh.getState(t).rect;if(r&&n instanceof dt&&o===n.node.type){const e=document.createElement("div");e.className="k-editor-resize-handles-wrapper",e.style.width=r.width+"px",e.style.height=r.height+"px",e.style.top=r.top+"px",e.style.left=r.left+"px";for(let t=0;t<Xh.length;t++){const n=document.createElement("div");n.className=Dt+" "+Xh[t],n.setAttribute(Rt,Xh[t]),e.appendChild(n)}return Tl.create(t.doc,[Nl.widget(t.selection.from+1,e)])}return Tl.empty}}}),tp=new Nt("caret-color");function np(){return new St({key:tp,props:{decorations:e=>{const{doc:t,selection:n,storedMarks:o}=e;if(!n.empty||!o)return Tl.empty;const r=jn((o||[]).find(e=>"style"===e.type.name),{name:"color",value:/^.+$/});if(!r)return Tl.empty;const i=n.$anchor.parent,s=[];return t.descendants((e,t)=>{e.eq(i)&&s.push(Nl.node(t,t+e.nodeSize,{style:"caret-color: "+r}))}),Tl.create(t,s)}}})}class op{constructor(e,t){this.node=e,this.view=t,this.dom=document.createElement("div"),this.dom.className="k-editor-resize-wrap-element",this.table=this.dom.appendChild(document.createElement("table")),e.attrs[At]&&this.renderColgroup(e.attrs[At]);const n=this.table.appendChild(document.createElement("tbody"));this.setAttributes(this.table,e.attrs),this.resizeHandles=Xh.map(e=>{const t=document.createElement("span");return t.className=Dt+" "+e,t.setAttribute(Et,e),t}),this.contentDOM=n}update(e){if(e.type!==this.node.type)return!1;const t=this.node;return this.node=e,e.attrs[Tt]?this.resizeHandles.forEach(e=>{this.dom.appendChild(e)}):Array.from(this.dom.children).filter(e=>e.classList.contains(Dt)).forEach(e=>e.remove()),this.setAttributes(this.table,e.attrs),t.attrs[At]!==e.attrs[At]&&this.renderColgroup(e.attrs[At]),!0}ignoreMutation(e){return"attributes"===e.type&&(e.target===this.table||e.target.firstChild===this.table||this.colgroup&&this.colgroup.contains(e.target))}destroy(){this.node=void 0,this.view=void 0,this.table=void 0,this.colgroup=void 0,this.resizeHandles=void 0}renderColgroup(e){this.table&&this.table.firstChild&&"COLGROUP"===this.table.firstChild.nodeName&&this.table.removeChild(this.table.firstChild),e&&(this.colgroup=sd(e),this.table.insertBefore(this.colgroup,this.table.firstChild))}setAttributes(e,t){const n=[At,Tt];for(const o in t)o&&-1===n.indexOf(o)&&pn(e,o,t[o]);/%$/.test(e.style.width)?(this.dom.style.width=e.style.width,e.style.width=""):this.dom.style.width=""}}class rp{constructor(e,t){this.node=e,this.view=t,this.dom=document.createElement("div"),this.setAttributes(this.dom,e.attrs),this.contentDOM=this.dom}update(e){return e.type===this.node.type&&(this.node=e,this.setAttributes(this.dom,e.attrs),!0)}ignoreMutation(e){return"attributes"===e.type&&"style"===e.attributeName}destroy(){this.node=void 0,this.view=void 0}setAttributes(e,t){for(const n in t)n&&pn(e,n,t[n]);if(e.setAttribute("table",""),/%/.test(e.style.width)){const t=this.node&&this.node.lastChild,n=(t?cn(t.attrs.style):{}).width||"";n&&!/%/.test(n)&&(e.style.width="")}}}const ip=new Nt("table-resize"),sp=new Nt("table-column-resizing"),lp=new Nt("table-row-resizing");function ap(e,t){let n=!1;return n=n||e!==ip&&Boolean(ip.get(t))&&ip.getState(t).dragging,n=n||e!==sp&&Boolean(sp.get(t))&&sp.getState(t).dragging,n=n||e!==lp&&Boolean(lp.get(t))&&lp.getState(t).dragging,n}function cp(e,t){let n=!1;return n=n||e!==sp&&Boolean(sp.get(t))&&sp.getState(t).activeHandle>-1,n=n||e!==lp&&Boolean(lp.get(t))&&lp.getState(t).activeHandle>-1,n}function dp(e){return e&&e.firstChild&&"TABLE"===e.firstChild.nodeName?e.firstChild:e}function hp(e){for(;e&&"TD"!==e.nodeName&&"TH"!==e.nodeName;)e=e.classList.contains("ProseMirror")?null:e.parentNode;return e}function pp(e){const t=function(e){const t=Array.from(e&&e.rows||[]),n=Array.from(t&&t[0]&&t[0].cells||[]).map(e=>e.colSpan).reduce((e,t)=>e+t,0),o=t.map(()=>new Array(n));return t.forEach((e,t)=>{let n=0;Array.from(e.cells).forEach(e=>{for(let r=0;r<e.colSpan;r++){for(let r=0;r<e.rowSpan;r++){const i=o[t+r].findIndex((e,t)=>t>=n&&!e);o[t+r][i]=e}n++}})}),o}(e.closest("table"));let n=null;for(let o=0;o<t.length&&(t[o].forEach((t,r)=>{e===t&&(n={rowIndex:o,cellIndex:r})}),!n);o++);return n||{rowIndex:-1,cellIndex:-1}}function up(e,t,n){const o=e.posAtCoords({left:t.clientX,top:t.clientY});if(!o)return-1;const r=e.state.doc.resolve(o.pos),i=Qt(r,e=>"table"===e.type.spec.tableRole);if(null===i)return-1;const s=r.start(i.depth),l=i.node,a=ka.get(l);return s+a.map[a.width*n.rowIndex+n.cellIndex]}function fp(e){const t=Array.from(e&&e.children||[]);let n=!1;return t.forEach(t=>{for(;t.span>1;){const o=t.cloneNode();o.span=1,e.insertBefore(o,t),t.span-=1,n=!0}}),n}function mp(){const e=new St({key:sp,state:{init:()=>new gp(-1,null),apply:(e,t)=>t.apply(e)},props:{attributes:e=>cp(sp,e)?null:sp.getState(e).activeHandle>-1?{class:"resize-cursor"}:null,handleDOMEvents:{mousemove:(e,t)=>(ap(sp,e.state)||function(e,t){const n=sp.getState(e.state);if(!n.dragging){const o=hp(t.target);let r=-1;if(o){const n=pp(o),{left:i,right:s}=o.getBoundingClientRect();Math.abs(t.clientX-i)<=5&&n.cellIndex>0?(n.cellIndex-=o.colSpan,r=up(e,t,n)):s-t.clientX>0&&s-t.clientX<=5&&(r=up(e,t,n))}r!==n.activeHandle&&yp(e,r)}}(e,t),!1),mouseleave:e=>(function(e){const t=sp.getState(e.state);t.activeHandle>-1&&!t.dragging&&yp(e,-1)}(e),!1),mousedown:(e,t)=>function(e,t){const n=sp.getState(e.state);if(-1===n.activeHandle||n.dragging)return!1;const o=e.state.doc.resolve(n.activeHandle),r=o.parent,i=o.index();let s=0;for(let e=0;e<=i;e++)s+=r.child(e).attrs.colspan;const l=o.node(o.depth-1),a=e.domAtPos(n.activeHandle),c=a.node.childNodes[a.offset].closest("table");let d,h;if(l.attrs[At]){const e=c.firstChild;fp(e)&&(h={...l.attrs,[At]:e.outerHTML}),d=e.children[s-1],d.style.width||(d.style.width=d.offsetWidth+"px")}else{let e=0;for(let t=0;t<r.childCount;t++)e+=r.child(t).attrs.colspan;const t=document.createElement("colgroup"),n=new Array(e);for(let o=0;o<e;o++)n[o]=document.createElement("col"),t.appendChild(n[o]);c.insertBefore(t,c.firstChild),d=n[i],d.style.width=d.offsetWidth+"px",h={...l.attrs,[At]:"<colgroup>"+n.reduce((e,t)=>e+t.outerHTML,"")+"</colgroup>"}}const p=parseFloat(d.style.width),u=e.state.tr.setMeta(sp,{setDragging:{startX:t.clientX,startWidth:p}});if(!c.style.width){const e=Array.from(d.parentNode.children).map(e=>e.style.width);if(e.every(Boolean)){const t=e.reduce((e,t)=>e+parseFloat(t),0);h=Xt(h||l.attrs,"width",t+"px")}}if(h){const e=o.posAtIndex(0,o.depth-1)-1;u.setNodeMarkup(e,null,h)}function f(t){t.view.removeEventListener("mouseup",f),t.view.removeEventListener("mousemove",m);const n=sp.getState(e.state);if(n.dragging){const t=e.state.tr;!function(e,t,n){const o=e.state.doc.resolve(n),r=o.node(-1),i=o.start(-1),s=o.posAtIndex(0,o.depth-1)-1,l=e.nodeDOM(i).closest("table");let a=r.attrs;if(r&&a[At]){const e=l.firstChild;a={...a,[At]:e.outerHTML}}const c=l.style.width;l&&c&&cn(a.style).width!==c&&(a=Xt(a,"width",c)),t.setNodeMarkup(s,null,a)}(e,t,n.activeHandle),e.dispatch(t.setMeta(sp,{setDragging:null}))}}function m(t){if(!t.which)return f(t);const n=sp.getState(e.state),o=function(e,t){const n=t.clientX-e.startX;return Math.max(25,e.startWidth+n)}(n.dragging,t);!function(e,t,n){const o=e.state.doc.resolve(t),r=o.node(-1),i=o.start(-1),s=ka.get(r).colCount(o.pos-i)+o.nodeAfter.attrs.colspan-1;let l=e.domAtPos(o.start(-1)).node;"TABLE"!==l.nodeName&&(l=l.closest("table"));const a=l,c=a.firstChild,d=Array.from(c.children);if(d[s].style.width=n+"px",a.style.width){const e=d.map(e=>e.style.width);if(e.every(Boolean)){const t=e.reduce((e,t)=>e+parseFloat(t),0);a.style.width=t+"px"}}}(e,n.activeHandle,o)}return e.dispatch(u),t.view.addEventListener("mouseup",f),t.view.addEventListener("mousemove",m),t.preventDefault(),!0}(e,t)},decorations(e){if(!ap(sp,e)){const t=sp.getState(e);if(t.activeHandle>-1)return function(e,t){const n=[],o=e.doc.resolve(t),r=o.node(-1),i=ka.get(r),s=o.start(-1),l=[],a=t-s;let c=-1;for(let e=0;e<i.height;e++)l.push(i.map.slice(e*i.width,e*i.width+i.width)),-1===c&&(c=l[e].lastIndexOf(a));const d=[];return l.forEach(e=>{const t=e[c];e[c]!==e[c+1]&&d.push(t)}),d.forEach(e=>{const t=s+e+r.nodeAt(e).nodeSize-1,o=document.createElement("div");o.className="column-resize-handle",n.push(Nl.widget(t,o))}),Tl.create(e.doc,n)}(e,t.activeHandle)}return Tl.empty},nodeViews:{table_wrapper:(e,t)=>new rp(e,t),table:(e,t)=>new op(e,t)}}});return e}class gp{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t;const n=e.getMeta(sp);if(n&&null!=n.setHandle)return new gp(n.setHandle,null);if(n&&void 0!==n.setDragging)return new gp(this.activeHandle,n.setDragging);if(this.activeHandle>-1&&e.docChanged){let n=e.mapping.map(this.activeHandle,-1);o=e.doc.resolve(n),Boolean("row"===o.parent.type.spec.tableRole&&o.nodeAfter)||(n=-1),t=new gp(n,this.dragging)}var o;return t||this}}function yp(e,t){const n=e.state.tr;n.setMeta("addToHistory",!1),n.setMeta(sp,{setHandle:t}),e.dispatch(n)}const wp={southeast:!0,southwest:!0,northwest:!0,northeast:!0},vp={east:!0,west:!0,...wp},bp={south:!0,north:!0,...wp};class kp{constructor(e,t,n){this.activeHandle=e,this.dragging=t,this.nodePosition=n}apply(e){const t=e.getMeta(ip);return t?new kp(t.activeHandle,t.setDragging,t.nodePosition):this}}const xp=e=>{const t=Array.from(e.firstChild.children).map(e=>e.offsetWidth),n=Array.from(e.rows).map(e=>e.offsetHeight),o=t.reduce((e,t)=>e+t,0),r=n.reduce((e,t)=>e+t,0),i=e.offsetHeight;return{width:o,height:r,colsWidth:t,rowsHeight:n,offsetWidth:e.offsetWidth,offsetHeight:i}},Sp=(e,t)=>{const n=t.target.getAttribute(Et);if(!n)return!1;const o=ip.getState(e.state);t.preventDefault();const r=e.state.tr;r.setMeta(ip,{setDragging:{startX:t.clientX,startY:t.clientY},activeHandle:n,nodePosition:o.nodePosition}),r.setMeta("addToHistory",!1),((e,t,n)=>{const o=e.state.doc.nodeAt(n),r=dp(e.nodeDOM(n)),i=r.firstChild;let s=fp(i);const{width:l,height:a,colsWidth:c,rowsHeight:d,offsetWidth:h,offsetHeight:p}=xp(r);Array.from(i&&i.children||[]).forEach((e,t)=>{e.style.width&&!/%$/.test(e.style.width)&&(e.style.width=100*c[t]/l+"%",s=!0)});let u=!1;o.forEach((e,o,r)=>{const i=cn(e.attrs.style).height;i&&!/%$/.test(i)&&(t.setNodeMarkup(n+o+1,null,Xt(e.attrs,"height",100*d[r]/a+"%")),u=!0)});let f=o.attrs;cn(f.style).width!==h+"px"&&(f=Xt(f,"width",h+"px")),s&&(f[At]=i.outerHTML),u&&(f=Xt(f,"height",p+"px")),(s||u)&&t.setNodeMarkup(n,null,f)})(e,r,o.nodePosition),e.dispatch(r);const i=t.view||window;function s(t){((e,t)=>{var n;const o=ip.getState(e.state),{dragging:r,nodePosition:i,activeHandle:s}=o;if(i<0||!r)return;const l=dp(e.nodeDOM(i)),a=l.getBoundingClientRect(),c=Kh[s],d=(t.clientX-r.startX)*c.x,h=(t.clientY-r.startY)*c.y,p=(l.ownerDocument&&l.ownerDocument.defaultView||window).getComputedStyle(l),u=/px/.test(p.width)?parseFloat(p.width):l.offsetWidth,f=/px/.test(p.height)?parseFloat(p.height):l.offsetHeight,m=c.x?d+u:a.width,g=c.y?h+f:a.height;if(r.startX=c.x?t.clientX:r.startX,r.startY=c.y?t.clientY:r.startY,vp[s]&&(l.style.width=m+"px"),bp[s]&&(l.style.height=g+"px"),/px/.test(l.style.width)){const e=null===(n=l.parentNode)||void 0===n?void 0:n.parentNode;e instanceof HTMLDivElement&&e.matches("div[table]")&&/%/.test(e.style.width)&&(e.style.width="")}})(e,t)}return i.addEventListener("mouseup",function t(){i.removeEventListener("mouseup",t),i.removeEventListener("mousemove",s),(e=>{const{dragging:t,nodePosition:n,activeHandle:o}=ip.getState(e.state);if(t){const t=e.state.doc.nodeAt(n),r=dp(e.nodeDOM(n)),i=xp(r);if(t){const s=i.offsetWidth+"px",l=i.offsetHeight+"px",a=e.state.tr;let c=t.attrs;const d=cn(c.style);if(vp[o]&&r.style.width&&d.width!==s&&(c=Xt(c,"width",s)),bp[o]&&r.style.height&&d.height!==l&&(c=Xt(c,"height",l)),c=((e,t,n,o)=>{const r=e.state.doc.nodeAt(n),i=dp(e.nodeDOM(n)),s=(i.ownerDocument&&i.ownerDocument.defaultView||window).getComputedStyle,l=Array.from(i.rows);r.forEach((e,o,r)=>{const i=cn(e.attrs.style).height;i&&!/px$/.test(i)&&t.setNodeMarkup(n+o+1,null,Xt(e.attrs,"height",s(l[r]).height))});const a=i.firstChild,c=Array.from(a&&a.children||[]);let d=!1;c.forEach((e,t)=>{e.style.width&&!/px$/.test(e.style.width)&&(e.style.width=s(c[t]).width,d=!0)});const h={...o};return d&&(h[At]=a.outerHTML),h})(e,a,n,c),a.setNodeMarkup(n,null,c),a.setMeta("commandName","node-resize"),a.setMeta("args",c),a.setMeta(ip,{setDragging:null,activeHandle:null,nodePosition:n}),!/%/.test(cn(c.style).width||"")){const e=a.doc.resolve(n),t=Qt(e,e=>"table_wrapper"===e.type.name);if(t&&/%/.test(cn(t.node.attrs.style).width||"")){const n=Xt(t.node.attrs,"width",""),o=e.start(t.depth)-1;a.setNodeMarkup(o,null,n)}}e.dispatch(a)}}})(e)}),i.addEventListener("mousemove",s),!0},Cp=(e={node:"table"})=>new St({key:ip,view:()=>({selectedNode(e,t){const n=e.selection;if(n instanceof dt&&t===n.node.type&&n instanceof dt)return{node:n.node,pos:n.from};const o=Qt(n.$from,e=>e.type===t),r=o&&o.node;return r?{node:r,pos:n.$from.start(o.depth)-1}:null},update(t,n){const o=t.state,r=o.schema.nodes[e.node],i=this.selectedNode(o,r),s=this.selectedNode(n,r);if((i||!s||n.doc.eq(t.state.doc))&&(i||s)){const e=o.tr;if(e.setMeta("addToHistory",!1),i&&s&&i.pos!==s.pos){e.setMeta(ip,{nodePosition:i.pos});const n=e.doc.nodeAt(s.pos);n&&n.type.name===r.name&&e.setNodeMarkup(s.pos,r,{...s.node.attrs,[Tt]:!1}),e.setNodeMarkup(i.pos,r,{...i.node.attrs,[Tt]:!0}),t.dispatch(e)}else i&&s&&i.pos===s.pos&&!i.node.attrs[Tt]&&!o.selection.eq(n.selection)?(e.setMeta(ip,{nodePosition:i.pos}),t.dispatch(e.setNodeMarkup(i.pos,r,{...i.node.attrs,[Tt]:!0}))):i&&!s?(e.setMeta(ip,{nodePosition:i.pos}),t.dispatch(e.setNodeMarkup(i.pos,r,{...i.node.attrs,[Tt]:!0}))):!i&&s&&(e.setMeta(ip,{nodePosition:-1}),t.dispatch(e.setNodeMarkup(s.pos,r,{...s.node.attrs,[Tt]:!1})))}}}),state:{init:()=>new kp("",null,-1),apply:(e,t)=>t.apply(e)},props:{handleDOMEvents:{mousedown:(e,t)=>Sp(e,t)}}});class Mp{ignoreMutation(e){return"attributes"===e.type&&"style"===e.attributeName&&"TR"===e.target.nodeName}}function Np(){const e=new St({key:lp,state:{init(e,t){return this.spec.props.nodeViews[Oa(t.schema).row.name]=()=>new Mp,new Op(-1,null)},apply:(e,t)=>t.apply(e)},props:{attributes:e=>cp(lp,e)?null:lp.getState(e).activeHandle>-1?{class:"resize-cursor-vertical"}:null,handleDOMEvents:{mousemove:(e,t)=>(ap(lp,e.state)||function(e,t){const n=lp.getState(e.state);if(!n.dragging){const o=hp(t.target);let r=-1;if(o){const n=pp(o),{top:i,bottom:s}=o.getBoundingClientRect();Math.abs(t.clientY-i)<=5&&n.rowIndex>0?(n.rowIndex-=o.rowSpan,r=up(e,t,n)):s-t.clientY>0&&s-t.clientY<=5&&(r=up(e,t,n))}r!==n.activeHandle&&Ap(e,r)}}(e,t),!1),mouseleave:e=>(function(e){const t=lp.getState(e.state);t.activeHandle>-1&&!t.dragging&&Ap(e,-1)}(e),!1),mousedown:(e,t)=>function(e,t){const n=lp.getState(e.state);if(-1===n.activeHandle||n.dragging)return!1;const o=e.state.doc.resolve(n.activeHandle),r=o.parent,i=o.node(-1),s=cn(r.attrs.style).height,l=cn(i.attrs.style).height;let a=s?parseFloat(s):0;function c(t){t.view.removeEventListener("mouseup",c),t.view.removeEventListener("mousemove",d);const n=lp.getState(e.state);if(n.dragging){const t=e.state.tr.setMeta(lp,{setDragging:null});!function(e,t,n){const o=e.state.doc,r=o.resolve(n),i=r.parent,s=r.posAtIndex(0)-1,l=e.nodeDOM(s),a=l.ownerDocument&&l.ownerDocument.defaultView||window;l.style.height=a.getComputedStyle(l).height,t.setNodeMarkup(s,null,Xt(i.attrs,"height",l.style.height));const c=l&&l.closest("table"),d=c&&c.style.height;if(d){const e=o.resolve(s),n=e.start(e.depth)-1;t.setNodeMarkup(n,null,Xt(e.parent.attrs,"height",d))}}(e,t,n.activeHandle),e.dispatch(t)}}function d(t){if(!t.which)return c(t);const n=lp.getState(e.state),o=function(e,t){const n=t.clientY-e.startY;return e.startHeight.rowHeight+n}(n.dragging,t),r=t.clientY-n.dragging.startY;!function(e,t,n,o,r){const i=e.nodeDOM(t),s=i&&i.parentNode;if(s){s.style.height=n+"px";const e=s.ownerDocument&&s.ownerDocument.defaultView||window;s.style.height=e.getComputedStyle(s).height;const t=s.closest("table"),i=parseFloat(r)+o+"px",l=t&&t.style.height;l&&l!==i&&(t.style.height=parseFloat(r)+o+"px",t.style.height=e.getComputedStyle(t).height)}}(e,n.activeHandle,o,r,l)}return s||(a=e.nodeDOM(n.activeHandle).offsetHeight),e.dispatch(e.state.tr.setMeta(lp,{setDragging:{startY:t.clientY,startHeight:{rowHeight:a,tableHeight:l}}})),t.view.addEventListener("mouseup",c),t.view.addEventListener("mousemove",d),t.preventDefault(),!0}(e,t)},decorations(e){if(ap(lp,e))return Tl.empty;const t=lp.getState(e);return t.activeHandle>-1?function(e,t){const n=[];if("number"!=typeof t)return Tl.empty;const o=e.doc.resolve(t),r=o.node(-1),i=ka.get(r),s=o.start(-1),l=[],a=t-s;let c=-1;for(let e=0;e<i.height;e++)l.push(i.map.slice(e*i.width,e*i.width+i.width)),-1!==l[e].indexOf(a)&&(c=e);const d=[];return l[c].forEach((e,t)=>{l[c+1]&&e===l[c+1][t]||d.push(e)}),d.forEach(e=>{const t=r.nodeAt(e),o=s+e+(t?t.nodeSize:0)-1,i=document.createElement("div");i.className="row-resize-handle",n.push(Nl.widget(o,i))}),Tl.create(e.doc,n)}(e,t.activeHandle):void 0},nodeViews:{}}});return e}class Op{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t;const n=e.getMeta(lp);if(n&&null!=n.setHandle)return new Op(n.setHandle,null);if(n&&void 0!==n.setDragging)return new Op(this.activeHandle,n.setDragging);if(this.activeHandle>-1){let n=e.mapping.map(this.activeHandle,-1);"row"===(o=e.doc.resolve(n)).parent.type.spec.tableRole&&o.nodeAfter||(n=null),t=new Op(n,this.dragging)}var o;return t||this}}function Ap(e,t){const n=e.state.tr;n.setMeta("addToHistory",!1),n.setMeta(lp,{setHandle:t}),e.dispatch(n)}const Tp=()=>[Cp(),mp(),Np()],Dp=(e,t,n,o,r)=>{const i=r.resolve(e),s=r.resolve(t),l=o.type.name;let a,c;return!i.nodeBefore&&(a=i.node(i.depth),c=i.node(i.depth-1),a&&c&&c.firstChild===a&&c.type.name===l)?n+o.content.size<=t:!s.nodeAfter&&(a=s.node(s.depth),c=s.node(s.depth-1),a&&c&&c.lastChild===a&&c.type.name===l)?e<=n:e<=n&&n+o.content.size<=t},Ep=(e,t,n)=>{const{tr:o,doc:r,selection:{from:i,to:s}}=t,l=e.getMeta("args");return r.nodesBetween(i,s,(e,t)=>{e.type.name===n.listItem&&Dp(i,s,t,e,r)&&o.setNodeMarkup(t,null,{...e.attrs,style:dn(e.attrs.style,l.style,l.value)})}),o.docChanged?o:void 0},Rp=(e,t,n)=>{const o=Object.keys(n.resetValues),{tr:r,doc:i,selection:{from:s,to:l}}=t;return i.nodesBetween(s,l,(e,t)=>{if(e.type.name===n.listItem&&Dp(s,l,t,e,i)){let n=e.attrs;const i=cn(e.attrs.style);o.forEach(e=>{i[e]&&(n={...n,style:dn(n.style,e,"")})}),n!==e.attrs&&r.setNodeMarkup(t,null,n)}}),e.steps.forEach(e=>{if(e instanceof Se){const t=e.mark;if("style"===t.type.name&&t.attrs.style){const[o]=t.attrs.style.split(/\s*:\s*/),i=Qt(r.doc.resolve(e.from),e=>e.type.name===n.listItem);if(i&&cn(i.node.attrs.style)[o]&&n.resetValues[o]){const i=t.type.create({style:`${o}: ${n.resetValues[o]};`});r.addMark(e.from,e.to,i)}}}}),r.docChanged?r:void 0},$p={listItem:"list_item",resetValues:{"font-size":"","font-family":"",color:""}};function Ip(e=$p){return new St({key:new Nt("list-markers-styles"),appendTransaction:(t,n,o)=>{const r=t.slice().pop(),i=r.getMeta("commandName");let s;return"FontSize"===i||"FontName"===i||"ForeColor"===i?s=Ep(r,o,e):"CleanFormatting"===i&&(s=Rp(r,o,e)),s&&s.setMeta("addToHistory",!0),s}})}function zp(e={}){return new St({view:t=>new Bp(t,e)})}class Bp{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,o=this.editorView.dom,r=o.getBoundingClientRect(),i=r.width/o.offsetWidth,s=r.height/o.offsetHeight;if(n){let n=t.nodeBefore,o=t.nodeAfter;if(n||o){let t=this.editorView.nodeDOM(this.cursorPos-(n?n.nodeSize:0));if(t){let r=t.getBoundingClientRect(),i=n?r.bottom:r.top;n&&o&&(i=(i+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let l=this.width/2*s;e={left:r.left,right:r.right,top:i-l,bottom:i+l}}}}if(!e){let t=this.editorView.coordsAtPos(this.cursorPos),n=this.width/2*i;e={left:t.left-n,right:t.left+n,top:t.top,bottom:t.bottom}}let l,a,c=this.editorView.dom.offsetParent;if(this.element||(this.element=c.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),!c||c==document.body&&"static"==getComputedStyle(c).position)l=-pageXOffset,a=-pageYOffset;else{let e=c.getBoundingClientRect(),t=e.width/c.offsetWidth,n=e.height/c.offsetHeight;l=e.left-c.scrollLeft*t,a=e.top-c.scrollTop*n}this.element.style.left=(e.left-l)/i+"px",this.element.style.top=(e.top-a)/s+"px",this.element.style.width=(e.right-e.left)/i+"px",this.element.style.height=(e.bottom-e.top)/s+"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),o=n&&n.type.spec.disableDropCursor,r="function"==typeof o?o(this.editorView,t,e):o;if(t&&!r){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=He(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){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class Pp extends rt{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return Pp.valid(n)?new Pp(n):rt.near(n)}content(){return p.empty}eq(e){return e instanceof Pp&&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 Pp(e.resolve(t.pos))}getBookmark(){return new Vp(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),o=e.node(t);if(0!=n)for(let e=o.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||Fp(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),o=e.node(t);if(n!=o.childCount)for(let e=o.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||Fp(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let o=t.contentMatchAt(e.index()).defaultType;return o&&o.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&Pp.valid(e))return e;let o=e.pos,r=null;for(let n=e.depth;;n--){let i=e.node(n);if(t>0?e.indexAfter(n)<i.childCount:e.index(n)>0){r=i.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;o+=t;let s=e.doc.resolve(o);if(Pp.valid(s))return s}for(;;){let i=t>0?r.firstChild:r.lastChild;if(!i){if(r.isAtom&&!r.isText&&!dt.isSelectable(r)){e=e.doc.resolve(o+r.nodeSize*t),n=!1;continue e}break}r=i,o+=t;let s=e.doc.resolve(o);if(Pp.valid(s))return s}return null}}}Pp.prototype.visible=!1,Pp.findFrom=Pp.findGapCursorFrom,rt.jsonID("gapcursor",Pp);class Vp{constructor(e){this.pos=e}map(e){return new Vp(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return Pp.valid(t)?new Pp(t):rt.near(t)}}function Fp(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function Lp(){return new St({props:{decorations:jp,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&Pp.valid(n)?new Pp(n):null,handleClick:Wp,handleKeyDown:Hp,handleDOMEvents:{beforeinput:qp}}})}const Hp=wa({ArrowLeft:_p("horiz",-1),ArrowRight:_p("horiz",1),ArrowUp:_p("vert",-1),ArrowDown:_p("vert",1)});function _p(e,t){const n="vert"==e?t>0?"down":"up":t>0?"right":"left";return function(e,o,r){let i=e.selection,s=t>0?i.$to:i.$from,l=i.empty;if(i instanceof at){if(!r.endOfTextblock(n)||0==s.depth)return!1;l=!1,s=e.doc.resolve(t>0?s.after():s.before())}let a=Pp.findGapCursorFrom(s,t,l);return!!a&&(o&&o(e.tr.setSelection(new Pp(a))),!0)}}function Wp(e,t,n){if(!e||!e.editable)return!1;let o=e.state.doc.resolve(t);if(!Pp.valid(o))return!1;let r=e.posAtCoords({left:n.clientX,top:n.clientY});return!(r&&r.inside>-1&&dt.isSelectable(e.state.doc.nodeAt(r.inside))||(e.dispatch(e.state.tr.setSelection(new Pp(o))),0))}function qp(e,t){if("insertCompositionText"!=t.inputType||!(e.state.selection instanceof Pp))return!1;let{$from:n}=e.state.selection,o=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!o)return!1;let r=s.empty;for(let e=o.length-1;e>=0;e--)r=s.from(o[e].createAndFill(null,r));let i=e.state.tr.replace(n.pos,n.pos,new p(r,0,0));return i.setSelection(at.near(i.doc.resolve(n.pos+1))),e.dispatch(i),!1}function jp(e){if(!(e.selection instanceof Pp))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",Tl.create(e.doc,[Nl.widget(e.selection.head,t,{key:"gapcursor"})])}const Jp=(e,t,n)=>{const{table:o,table_row:r,table_cell:i}=e,s=[];let l;for(let e=0;e<t+1;e++){l=[];for(let e=0;e<n+1;e++)l.push(i.createAndFill());s.push(r.createAndFill(void 0,l))}return o.createAndFill(void 0,s)},Kp=/^table$/,Xp=/^table_row$/,Up=/^table_cell|table_header$/,Gp=(e,t)=>{const n=e.$head;for(let e=n.depth;e>0;e--){const o=n.node(e);if(t.test(o.type.name))return{pos:n.before(e),node:o}}return null},Yp=(e,t)=>{const n=t&&(e=>{const n=Gp(e.selection,Xp),o=Gp(e.selection,Kp);if(n&&o&&n.node.attrs[Ot]){let t=0;for(let e=0;e<o.node.nodeSize;e++)if(o.node.child(e).eq(n.node)){t=e;break}const r=o.node.child(t-1),i=n.pos-r.nodeSize;e.setNodeMarkup(i,void 0,{[Ot]:n.node.attrs[Ot]})}return t(e)});return tc(e,n)},Qp=(e,t)=>nc(e,t&&(e=>{const n=Gp(e.selection,Xp);if(n&&n.node.attrs[Ot]){const t=n.pos+n.node.nodeSize;e.setNodeMarkup(t,void 0,{[Ot]:n.node.attrs[Ot]})}return t(e)})),Zp=(e,t)=>{if(!e)return-1;const n=ka.get(e.node),o=Gp(t,Up),r=n.map.indexOf(o.pos-e.pos-1);let i=-1;return-1!==r&&(i=r%n.width),i},eu=(e,t,n)=>{const o=Zp(t,e.selection),r=sd(t.node.attrs[At]);r.insertBefore(r.ownerDocument.createElement("col"),r.children[o+n]),e.setNodeMarkup(t.pos,null,{...t.node.attrs,[At]:r.outerHTML})},tu=(e,t)=>Ua(e,t&&(e=>{const n=Gp(e.selection,Kp);return n.node.attrs[At]?(eu(e,n,-1),t(e)):t(e)})),nu=(e,t)=>Ga(e,t&&(e=>{const n=Gp(e.selection,Kp);return n.node.attrs[At]?(eu(e,n,1),t(e)):t(e)})),ou=(e,t)=>{const n=Gp(e.selection,Kp),o=n&&n.node.attrs[At],r=Zp(n,e.selection),i=t&&(e=>{if(!o)return t(e);const i=e.doc.nodeAt(n.pos);return((e,t,n)=>{const o=sd(t.node.attrs[At]);o.removeChild(o.children[n]),e.setNodeMarkup(t.pos,null,{...t.node.attrs,[At]:o.outerHTML})})(e,{node:i,pos:n.pos},r),t(e)});return Qa(e,i)};return t})());
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.KendoEditorCommon=t():e.KendoEditorCommon=t()}(self,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){this.content=e}e.r(t),e.d(t,{AddMarkStep:()=>xe,AddNodeMarkStep:()=>Ce,AllSelection:()=>pt,AttrStep:()=>Ze,CellSelection:()=>Ha,ContentMatch:()=>$,DOMParser:()=>Y,DOMSerializer:()=>le,Decoration:()=>Nl,DecorationSet:()=>Tl,DocAttrStep:()=>et,EditorState:()=>kt,EditorView:()=>ta,Fragment:()=>s,GapCursor:()=>Pp,InputRule:()=>zd,MapResult:()=>me,Mapping:()=>ye,Mark:()=>d,MarkType:()=>X,Node:()=>D,NodeRange:()=>A,NodeSelection:()=>dt,NodeType:()=>J,Plugin:()=>St,PluginKey:()=>Nt,RemoveMarkStep:()=>Se,RemoveNodeMarkStep:()=>Me,ReplaceAroundStep:()=>Oe,ReplaceError:()=>h,ReplaceStep:()=>Ne,ResolvedPos:()=>C,Schema:()=>U,Selection:()=>rt,SelectionRange:()=>it,Slice:()=>p,Step:()=>ve,StepMap:()=>ge,StepResult:()=>be,TableMap:()=>ka,TextSelection:()=>at,Transaction:()=>gt,Transform:()=>nt,TransformError:()=>tt,__endComposition:()=>ea,__parseFromClipboard:()=>Zl,activeNode:()=>fo,addColSpan:()=>Fa,addColumn:()=>Xa,addColumnAfter:()=>nu,addColumnBefore:()=>tu,addListNodes:()=>Mo,addRow:()=>ec,addRowAfter:()=>Qp,addRowBefore:()=>Yp,alignBlocks:()=>mo,alignCenterRules:()=>qr,alignJustifyRules:()=>jr,alignLeftRules:()=>_r,alignRemoveRules:()=>Jr,alignRightRules:()=>Wr,applyInlineStyle:()=>eo,applyLink:()=>no,autoJoin:()=>yr,baseKeymap:()=>Sr,blockNodes:()=>so,blockquote:()=>Cr,bold:()=>Ud,buildKeymap:()=>oh,buildListKeymap:()=>rh,bulletList:()=>xo,canBeIndented:()=>Dr,canIndentAsListItem:()=>Ar,canInsert:()=>Ut,canJoin:()=>Pe,canOutdentAsListItem:()=>Tr,canSplit:()=>Be,caretColor:()=>np,caretColorKey:()=>tp,cellAround:()=>Ta,chainCommands:()=>wr,changeTextBlock:()=>io,cleanFormatting:()=>yo,cleanMarks:()=>Wn,cleanTextBlockFormatting:()=>ao,closeDoubleQuote:()=>Wd,closeHistory:()=>Sd,closeSingleQuote:()=>jd,colCount:()=>Ba,columnIsHeader:()=>La,columnResizing:()=>zc,columnResizingPluginKey:()=>Ic,convertMsLists:()=>uh,createParagraphNear:()=>nr,createTable:()=>Jp,cspFix:()=>qh,deleteColumn:()=>ou,deleteRow:()=>rc,deleteSelection:()=>Po,deleteTable:()=>gc,domToPmDoc:()=>An,dropCursor:()=>zp,dropPoint:()=>He,ellipsis:()=>Hd,emDash:()=>Ld,exitCode:()=>tr,expandSelection:()=>ln,expandToWordWrap:()=>an,find:()=>Dh,findAll:()=>Eh,findAt:()=>Th,findCell:()=>za,findWrapping:()=>Re,fixTables:()=>Ja,fixTablesKey:()=>qa,flattenNestedSpans:()=>Vn,formatBlockElements:()=>lo,fragmentToHtml:()=>Nn,gapCursor:()=>Lp,getActiveMarks:()=>Xn,getBlockFormats:()=>co,getHtml:()=>Dn,getInlineStyles:()=>Yn,getMark:()=>Kn,getNodeFromSelection:()=>nn,getSelectionText:()=>tn,goToNextCell:()=>mc,hasMark:()=>qn,hasNode:()=>po,hasSameMarkup:()=>Rn,history:()=>Nd,htmlToFragment:()=>Mn,imageResizeKey:()=>Uh,imageResizing:()=>ep,inSameTable:()=>Ia,indent:()=>Er,indentBlocks:()=>Nr,indentHtml:()=>rn,indentRules:()=>zo,inputRules:()=>Pd,insertImage:()=>ro,insertNode:()=>en,insertPoint:()=>Le,insertText:()=>oo,isAligned:()=>go,isHistoryTransaction:()=>Id,isInTable:()=>Da,isIndented:()=>Or,italic:()=>Gd,joinBackward:()=>Fo,joinDown:()=>Yo,joinForward:()=>Ko,joinPoint:()=>Fe,joinTextblockBackward:()=>Lo,joinTextblockForward:()=>Ho,joinUp:()=>Go,keydownHandler:()=>wa,keymap:()=>ya,lift:()=>Qo,liftBlockquote:()=>Mr,liftEmptyBlock:()=>or,liftListItem:()=>Do,liftTarget:()=>Ee,link:()=>th,listItem:()=>So,listMarkersStyles:()=>Ip,listStyle:()=>Pr,macBaseKeymap:()=>xr,marks:()=>td,mergeCells:()=>sc,moveCellForward:()=>$a,newlineInCode:()=>Zo,nextCell:()=>Pa,nodes:()=>ad,openDoubleQuote:()=>_d,openSingleQuote:()=>qd,orderedList:()=>ko,outdent:()=>Rr,outdentRules:()=>Bo,parentBlockFormat:()=>uo,parentNode:()=>Qt,parseContent:()=>Tn,pasteCleanup:()=>vh,pcBaseKeymap:()=>kr,placeholder:()=>Ph,pmAddColumnAfter:()=>Ga,pmAddColumnBefore:()=>Ua,pmAddRowAfter:()=>nc,pmAddRowBefore:()=>tc,pmDeleteColumn:()=>Qa,pmDocToFragment:()=>On,redo:()=>Td,redoDepth:()=>$d,redoNoScroll:()=>Ed,removeAllMarks:()=>_n,removeAttribute:()=>gh,removeColSpan:()=>Va,removeComments:()=>$n,removeLink:()=>to,removeTag:()=>mh,replace:()=>Rh,replaceAll:()=>$h,replaceImageSourcesFromRtf:()=>Ah,replaceStep:()=>_e,rowIsHeader:()=>Za,sanitize:()=>fh,sanitizeClassAttr:()=>yh,sanitizeStyleAttr:()=>wh,selectAll:()=>ar,selectNodeBackward:()=>qo,selectNodeForward:()=>Xo,selectParentNode:()=>lr,selectTextblockEnd:()=>pr,selectTextblockStart:()=>hr,selectedLineTextOnly:()=>on,selectedRect:()=>Ka,selectionCell:()=>Ea,selectionMarks:()=>Jn,setBlockType:()=>fr,setCellAttr:()=>cc,setHtml:()=>En,sinkListItem:()=>Eo,smartQuotes:()=>Jd,spacesFix:()=>Lh,splitBlock:()=>ir,splitBlockAs:()=>rr,splitBlockKeepMarks:()=>sr,splitCell:()=>lc,splitCellWithType:()=>ac,splitListItem:()=>Ao,splitListItemKeepMarks:()=>To,strikethrough:()=>Qd,subscript:()=>Zd,superscript:()=>eh,tableColumnResizeKey:()=>sp,tableEditing:()=>_c,tableEditingKey:()=>Aa,tableNodeTypes:()=>Oa,tableNodes:()=>Na,tableResizeKey:()=>ip,tableResizing:()=>Tp,tableRowResizeKey:()=>lp,textHighlight:()=>Jh,textHighlightKey:()=>jh,textblockTypeInputRule:()=>Xd,toggleHeader:()=>hc,toggleHeaderCell:()=>fc,toggleHeaderColumn:()=>uc,toggleHeaderRow:()=>pc,toggleInlineFormat:()=>Zn,toggleList:()=>Vr,toggleMark:()=>mr,toggleOrderedList:()=>Lr,toggleUnorderedList:()=>Fr,trimWhitespace:()=>vn,underline:()=>Yd,undo:()=>Ad,undoDepth:()=>Rd,undoInputRule:()=>Fd,undoNoScroll:()=>Dd,updateColumnsOnResize:()=>$c,wrapIn:()=>ur,wrapInList:()=>No,wrapRangeInList:()=>Oo,wrappingInputRule:()=>Kd}),n.prototype={constructor:n,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,o){var r=o&&o!=e?this.remove(o):this,i=r.find(e),s=r.content.slice();return-1==i?s.push(o||e,t):(s[i+1]=t,o&&(s[i]=o)),new n(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var o=this.content.slice();return o.splice(t,2),new n(o)},addToStart:function(e,t){return new n([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var o=this.remove(e).content.slice();return o.push(e,t),new n(o)},addBefore:function(e,t,o){var r=this.remove(t),i=r.content.slice(),s=r.find(e);return i.splice(-1==s?i.length:s,0,t,o),new n(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=n.from(e)).size?new n(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=n.from(e)).size?new n(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=n.from(e);for(var o=0;o<e.content.length;o+=2)t=t.remove(e.content[o]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},n.from=function(e){if(e instanceof n)return e;var t=[];if(e)for(var o in e)t.push(o,e[o]);return new n(t)};const o=n;function r(e,t,n){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(o),s=t.child(o);if(i!=s){if(!i.sameMarkup(s))return n;if(i.isText&&i.text!=s.text){for(let e=0;i.text[e]==s.text[e];e++)n++;return n}if(i.content.size||s.content.size){let e=r(i.content,s.content,n+1);if(null!=e)return e}n+=i.nodeSize}else n+=i.nodeSize}}function i(e,t,n,o){for(let r=e.childCount,s=t.childCount;;){if(0==r||0==s)return r==s?null:{a:n,b:o};let l=e.child(--r),a=t.child(--s),c=l.nodeSize;if(l!=a){if(!l.sameMarkup(a))return{a:n,b:o};if(l.isText&&l.text!=a.text){let e=0,t=Math.min(l.text.length,a.text.length);for(;e<t&&l.text[l.text.length-e-1]==a.text[a.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(l.content.size||a.content.size){let e=i(l.content,a.content,n-1,o-1);if(e)return e}n-=c,o-=c}else n-=c,o-=c}}class s{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,o=0,r){for(let i=0,s=0;s<t;i++){let l=this.content[i],a=s+l.nodeSize;if(a>e&&!1!==n(l,o+s,r||null,i)&&l.content.size){let r=s+1;l.nodesBetween(Math.max(0,e-r),Math.min(l.content.size,t-r),n,o+r)}s=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,o){let r="",i=!0;return this.nodesBetween(e,t,(s,l)=>{let a=s.isText?s.text.slice(Math.max(e,l)-l,t-l):s.isLeaf?o?"function"==typeof o?o(s):o:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&a||s.isTextblock)&&n&&(i?i=!1:r+=n),r+=a},0),r}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new s(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let r=0,i=0;i<t;r++){let s=this.content[r],l=i+s.nodeSize;l>e&&((i<e||l>t)&&(s=s.isText?s.cut(Math.max(0,e-i),Math.min(s.text.length,t-i)):s.cut(Math.max(0,e-i-1),Math.min(s.content.size,t-i-1))),n.push(s),o+=s.nodeSize),i=l}return new s(n,o)}cutByIndex(e,t){return e==t?s.empty:0==e&&t==this.content.length?this:new s(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new s(o,r)}addToStart(e){return new s([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new s(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 o=this.content[t];e(o,n,t),n+=o.nodeSize}}findDiffStart(e,t=0){return r(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return i(this,e,t,n)}findIndex(e){if(0==e)return a(0,e);if(e==this.size)return a(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let o=n+this.child(t).nodeSize;if(o>=e)return o==e?a(t+1,o):a(t,n);n=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return s.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new s(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return s.empty;let t,n=0;for(let o=0;o<e.length;o++){let r=e[o];n+=r.nodeSize,o&&r.isText&&e[o-1].sameMarkup(r)?(t||(t=e.slice(0,o)),t[t.length-1]=r.withText(t[t.length-1].text+r.text)):t&&t.push(r)}return new s(t||e,n)}static from(e){if(!e)return s.empty;if(e instanceof s)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new s([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}s.empty=new s([],0);const l={index:0,offset:0};function a(e,t){return l.index=e,l.offset=t,l}function c(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(!c(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!c(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class d{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let o=0;o<e.length;o++){let r=e[o];if(this.eq(r))return e;if(this.type.excludes(r.type))t||(t=e.slice(0,o));else{if(r.type.excludes(this.type))return e;!n&&r.type.rank>this.type.rank&&(t||(t=e.slice(0,o)),t.push(this),n=!0),t&&t.push(r)}}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&&c(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`);let o=n.create(t.attrs);return n.checkAttrs(o.attrs),o}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 d.none;if(e instanceof d)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}d.none=[];class h extends Error{}class p{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=f(this.content,e+this.openStart,t);return n&&new p(n,this.openStart,this.openEnd)}removeBetween(e,t){return new p(u(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 p.empty;let n=t.openStart||0,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new p(s.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,o=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)o++;return new p(e,n,o)}}function u(e,t,n){let{index:o,offset:r}=e.findIndex(t),i=e.maybeChild(o),{index:s,offset:l}=e.findIndex(n);if(r==t||i.isText){if(l!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(o!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(o,i.copy(u(i.content,t-r-1,n-r-1)))}function f(e,t,n,o){let{index:r,offset:i}=e.findIndex(t),s=e.maybeChild(r);if(i==t||s.isText)return o&&!o.canReplace(r,r,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=f(s.content,t-i-1,n,s);return l&&e.replaceChild(r,s.copy(l))}function m(e,t,n){if(n.openStart>e.depth)throw new h("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new h("Inconsistent open depths");return g(e,t,n,0)}function g(e,t,n,o){let r=e.index(o),i=e.node(o);if(r==t.index(o)&&o<e.depth-n.openStart){let s=g(e,t,n,o+1);return i.copy(i.content.replaceChild(r,s))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=o||t.depth!=o){let{start:r,end:l}=function(e,t){let n=t.depth-e.openStart,o=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)o=t.node(e).copy(s.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return k(i,x(e,r,l,t,o))}{let o=e.parent,r=o.content;return k(o,r.cut(0,e.parentOffset).append(n.content).append(r.cut(t.parentOffset)))}}return k(i,S(e,t,o))}function y(e,t){if(!t.type.compatibleContent(e.type))throw new h("Cannot join "+t.type.name+" onto "+e.type.name)}function w(e,t,n){let o=e.node(n);return y(o,t.node(n)),o}function v(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 b(e,t,n,o){let r=(t||e).node(n),i=0,s=t?t.index(n):r.childCount;e&&(i=e.index(n),e.depth>n?i++:e.textOffset&&(v(e.nodeAfter,o),i++));for(let e=i;e<s;e++)v(r.child(e),o);t&&t.depth==n&&t.textOffset&&v(t.nodeBefore,o)}function k(e,t){return e.type.checkContent(t),e.copy(t)}function x(e,t,n,o,r){let i=e.depth>r&&w(e,t,r+1),l=o.depth>r&&w(n,o,r+1),a=[];return b(null,e,r,a),i&&l&&t.index(r)==n.index(r)?(y(i,l),v(k(i,x(e,t,n,o,r+1)),a)):(i&&v(k(i,S(e,t,r+1)),a),b(t,n,r,a),l&&v(k(l,S(n,o,r+1)),a)),b(o,null,r,a),new s(a)}function S(e,t,n){let o=[];return b(null,e,n,o),e.depth>n&&v(k(w(e,t,n+1),S(e,t,n+1)),o),b(t,null,n,o),new s(o)}p.empty=new p(s.empty,0,0);class C{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],o=e.child(t);return n?e.child(t).cut(n):o}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],o=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)o+=n.child(t).nodeSize;return o}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return d.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),o=e.maybeChild(t);if(!n){let e=n;n=o,o=e}let r=n.marks;for(var i=0;i<r.length;i++)!1!==r[i].type.spec.inclusive||o&&r[i].isInSet(o.marks)||(r=r[i--].removeFromSet(r));return r}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,o=e.parent.maybeChild(e.index());for(var r=0;r<n.length;r++)!1!==n[r].type.spec.inclusive||o&&n[r].isInSet(o.marks)||(n=n[r--].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 A(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=[],o=0,r=t;for(let t=e;;){let{index:e,offset:i}=t.content.findIndex(r),s=r-i;if(n.push(t,e,o+i),!s)break;if(t=t.child(e),t.isText)break;r=s-1,o+=i+1}return new C(t,n,r)}static resolveCached(e,t){let n=O.get(e);if(n)for(let e=0;e<n.elts.length;e++){let o=n.elts[e];if(o.pos==t)return o}else O.set(e,n=new M);let o=n.elts[n.i]=C.resolve(e,t);return n.i=(n.i+1)%N,o}}class M{constructor(){this.elts=[],this.i=0}}const N=12,O=new WeakMap;class A{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 T=Object.create(null);class D{constructor(e,t,n,o=d.none){this.type=e,this.attrs=t,this.marks=o,this.content=n||s.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,o=0){this.content.nodesBetween(e,t,n,o,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,o){return this.content.textBetween(e,t,n,o)}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&&c(this.attrs,t||e.defaultAttrs||T)&&d.sameSet(this.marks,n||d.none)}copy(e=null){return e==this.content?this:new D(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new D(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 p.empty;let o=this.resolve(e),r=this.resolve(t),i=n?0:o.sharedDepth(t),s=o.start(i),l=o.node(i).content.cut(o.pos-s,r.pos-s);return new p(l,o.depth-i,r.depth-i)}replace(e,t,n){return m(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:o}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(o==e||t.isText)return t;e-=o+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 o=this.content.child(t-1);return{node:o,index:t-1,offset:n-o.nodeSize}}resolve(e){return C.resolveCached(this,e)}resolveNoCache(e){return C.resolve(this,e)}rangeHasMark(e,t,n){let o=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(o=!0),!o)),o}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()+")"),R(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=s.empty,o=0,r=n.childCount){let i=this.contentMatchAt(e).matchFragment(n,o,r),l=i&&i.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let e=o;e<r;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,o){if(o&&!this.type.allowsMarks(o))return!1;let r=this.contentMatchAt(e).matchType(n),i=r&&r.matchFragment(this.content,t);return!!i&&i.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),this.type.checkAttrs(this.attrs);let e=d.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!d.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;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 o=s.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,o,n);return r.type.checkAttrs(r.attrs),r}}D.prototype.text=void 0;class E extends D{constructor(e,t,n,o){if(super(e,t,null,o),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):R(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 E(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new E(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 R(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class ${constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new I(e,t);if(null==n.next)return $.empty;let o=z(n);n.next&&n.err("Unexpected trailing text");let r=function(e){let t=Object.create(null);return function n(o){let r=[];o.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let o;for(let e=0;e<r.length;e++)r[e][0]==t&&(o=r[e][1]);H(e,n).forEach(e=>{o||r.push([t,o=[]]),-1==o.indexOf(e)&&o.push(e)})})});let i=t[o.join(",")]=new $(o.indexOf(e.length-1)>-1);for(let e=0;e<r.length;e++){let o=r[e][1].sort(L);i.next.push({type:r[e][0],next:t[o.join(",")]||n(o)})}return i}(H(e,0))}(function(e){let t=[[]];return r(function e(t,i){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,i)),[]);if("seq"!=t.type){if("star"==t.type){let s=n();return o(i,s),r(e(t.expr,s),s),[o(s)]}if("plus"==t.type){let s=n();return r(e(t.expr,i),s),r(e(t.expr,s),s),[o(s)]}if("opt"==t.type)return[o(i)].concat(e(t.expr,i));if("range"==t.type){let s=i;for(let o=0;o<t.min;o++){let o=n();r(e(t.expr,s),o),s=o}if(-1==t.max)r(e(t.expr,s),s);else for(let i=t.min;i<t.max;i++){let i=n();o(s,i),r(e(t.expr,s),i),s=i}return[o(s)]}if("name"==t.type)return[o(i,void 0,t.value)];throw new Error("Unknown expr type")}for(let o=0;;o++){let s=e(t.exprs[o],i);if(o==t.exprs.length-1)return s;r(s,i=n())}}(e,0),n()),t;function n(){return t.push([])-1}function o(e,n,o){let r={term:o,to:n};return t[e].push(r),r}function r(e,t){e.forEach(e=>e.to=t)}}(o));return function(e,t){for(let n=0,o=[e];n<o.length;n++){let e=o[n],r=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];i.push(n.name),!r||n.isText||n.hasRequiredAttrs()||(r=!1),-1==o.indexOf(s)&&o.push(s)}r&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(r,n),r}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 o=this;for(let r=t;o&&r<n;r++)o=o.matchType(e.child(r).type);return o}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 o=[this];return function r(i,l){let a=i.matchFragment(e,n);if(a&&(!t||a.validEnd))return s.from(l.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==o.indexOf(n)){o.push(n);let e=r(n,l.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 o=n.shift(),r=o.match;if(r.matchType(e)){let e=[];for(let t=o;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<r.next.length;e++){let{type:i,next:s}=r.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||o.type&&!s.validEnd||(n.push({match:i.contentMatch,type:i,via:o}),t[i.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 o=0;o<n.next.length;o++)-1==e.indexOf(n.next[o].next)&&t(n.next[o].next)}(this),e.map((t,n)=>{let o=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)o+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return o}).join("\n")}}$.empty=new $(!0);class I{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 z(e){let t=[];do{t.push(B(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function B(e){let t=[];do{t.push(P(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function P(e){let t=function(e){if(e.eat("(")){let t=z(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,o=n[t];if(o)return[o];let r=[];for(let e in n){let o=n[e];o.isInGroup(t)&&r.push(o)}return 0==r.length&&e.err("No node type or group '"+t+"' found"),r}(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=F(e,t)}return t}function V(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function F(e,t){let n=V(e),o=n;return e.eat(",")&&(o="}"!=e.next?V(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:o,expr:t}}function L(e,t){return t-e}function H(e,t){let n=[];return function t(o){let r=e[o];if(1==r.length&&!r[0].term)return t(r[0].to);n.push(o);for(let e=0;e<r.length;e++){let{term:o,to:i}=r[e];o||-1!=n.indexOf(i)||t(i)}}(t),n.sort(L)}function _(e){let t=Object.create(null);for(let n in e){let o=e[n];if(!o.hasDefault)return null;t[n]=o.default}return t}function W(e,t){let n=Object.create(null);for(let o in e){let r=t&&t[o];if(void 0===r){let t=e[o];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+o);r=t.default}n[o]=r}return n}function q(e,t,n,o){for(let o in t)if(!(o in e))throw new RangeError(`Unsupported attribute ${o} for ${n} of type ${o}`);for(let n in e){let o=e[n];o.validate&&o.validate(t[n])}}function j(e,t){let n=Object.create(null);if(t)for(let o in t)n[o]=new K(e,o,t[o]);return n}class J{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=j(e,n.attrs),this.defaultAttrs=_(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==$.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:W(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new D(this,this.computeAttrs(e),s.from(t),d.setFrom(n))}createChecked(e=null,t,n){return t=s.from(t),this.checkContent(t),new D(this,this.computeAttrs(e),t,d.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=s.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let o=this.contentMatch.matchFragment(t),r=o&&o.fillBefore(s.empty,!0);return r?new D(this,e,t.append(r),d.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)}`)}checkAttrs(e){q(this.attrs,e,"node",this.name)}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:d.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,o)=>n[e]=new J(e,t,o));let o=t.spec.topNode||"doc";if(!n[o])throw new RangeError("Schema is missing its top node type ('"+o+"')");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 K{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let o=n.split("|");return n=>{let r=null===n?"null":typeof n;if(o.indexOf(r)<0)throw new RangeError(`Expected value of type ${o} for attribute ${t} on type ${e}, got ${r}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class X{constructor(e,t,n,o){this.name=e,this.rank=t,this.schema=n,this.spec=o,this.attrs=j(e,o.attrs),this.excluded=null;let r=_(this.attrs);this.instance=r?new d(this,r):null}create(e=null){return!e&&this.instance?this.instance:new d(this,W(this.attrs,e))}static compile(e,t){let n=Object.create(null),o=0;return e.forEach((e,r)=>n[e]=new X(e,o++,t,r)),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]}checkAttrs(e){q(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class U{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=o.from(e.nodes),t.marks=o.from(e.marks||{}),this.nodes=J.compile(this.spec.nodes,this),this.marks=X.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],o=t.spec.content||"",r=t.spec.marks;if(t.contentMatch=n[o]||(n[o]=$.parse(o,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==r?null:r?G(this,r.split(" ")):""!=r&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:G(this,n.split(" "))}this.nodeFromJSON=e=>D.fromJSON(this,e),this.markFromJSON=e=>d.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,o){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof J))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,o)}text(e,t){let n=this.nodes.text;return new E(n,n.defaultAttrs,e,d.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function G(e,t){let n=[];for(let o=0;o<t.length;o++){let r=t[o],i=e.marks[r],s=i;if(i)n.push(i);else for(let t in e.marks){let o=e.marks[t];("_"==r||o.spec.group&&o.spec.group.split(" ").indexOf(r)>-1)&&n.push(s=o)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[o]+"'")}return n}class Y{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),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 oe(this,t,!1);return n.addAll(e,d.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new oe(this,t,!0);return n.addAll(e,d.none,t.from,t.to),p.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){let n=this.tags[o];if(re(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,o){for(let r=o?this.styles.indexOf(o)+1:0;r<this.styles.length;r++){let o=this.styles[r],i=o.style;if(!(0!=i.indexOf(e)||o.context&&!n.matchesContext(o.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(o.getAttrs){let e=o.getAttrs(t);if(!1===e)continue;o.attrs=e||void 0}return o}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,o=0;for(;o<t.length;o++){let e=t[o];if((null==e.priority?50:e.priority)<n)break}t.splice(o,0,e)}for(let t in e.marks){let o=e.marks[t].spec.parseDOM;o&&o.forEach(e=>{n(e=ie(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let o=e.nodes[t].spec.parseDOM;o&&o.forEach(e=>{n(e=ie(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Y(e,Y.schemaRules(e)))}}const Q={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},Z={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ee={ol:!0,ul:!0};function te(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class ne{constructor(e,t,n,o,r,i){this.type=e,this.attrs=t,this.marks=n,this.solid=o,this.options=i,this.content=[],this.activeMarks=d.none,this.match=r||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(s.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=s.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(s.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Q.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class oe{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let o,r=t.topNode,i=te(null,t.preserveWhitespace,0)|(n?4:0);o=r?new ne(r.type,r.attrs,d.none,!0,t.topMatch||r.type.contentMatch,i):new ne(n?null:e.schema.topNodeType,null,d.none,!0,null,i),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,o=this.top,r=2&o.options?"full":this.localPreserveWS||(1&o.options)>0,{schema:i}=this.parser;if("full"===r||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r)if("full"===r)n=n.replace(/\r\n?/g,"\n");else if(i.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(i.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(i.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(i.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=o.content[o.content.length-1],r=e.previousSibling;(!t||r&&"BR"==r.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(i.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let o=this.localPreserveWS,r=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,s=e.nodeName.toLowerCase();ee.hasOwnProperty(s)&&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&&ee.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(l?l.ignore:Z.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let n,o=this.needsBlock;if(Q.hasOwnProperty(s))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=l&&l.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(r),this.needsBlock=o}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,l,n,!1===l.consuming?i:void 0)}this.localPreserveWS=o}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let o=this.parser.matchedStyles[e],r=n.getPropertyValue(o);if(r)for(let e;;){let n=this.parser.matchStyle(o,r,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1!==n.consuming)break;e=n}}return t}addElementByRule(e,t,n,o){let r,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(r=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,n,o);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let o=e;"string"==typeof t.contentElement?o=e.querySelector(t.contentElement):"function"==typeof t.contentElement?o=t.contentElement(e):t.contentElement&&(o=t.contentElement),this.findAround(e,o,!0),this.addAll(o,n),this.findAround(e,o,!1)}r&&this.sync(s)&&this.open--}addAll(e,t,n,o){let r=n||0;for(let i=n?e.childNodes[n]:e.firstChild,s=null==o?null:e.childNodes[o];i!=s;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i,t);this.findAtPoint(e,r)}findPlace(e,t,n){let o,r;for(let t=this.open,i=0;t>=0;t--){let s=this.nodes[t],l=s.findWrapping(e);if(l&&(!o||o.length>l.length+i)&&(o=l,r=s,!l.length))break;if(s.solid){if(n)break;i+=2}}if(!o)return null;this.sync(r);for(let e=0;e<o.length;e++)t=this.enterInner(o[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let o=this.findPlace(e,t,n);if(o){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=d.none;for(let r of o.concat(e.marks))(t.type?t.type.allowsMarkType(r.type):se(r.type,e.type))&&(n=r.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,o){let r=this.findPlace(e.create(t),n,!1);return r&&(r=this.enterInner(e,t,n,!0,o)),r}enterInner(e,t,n,o=!1,r){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let s=te(e,r,i.options);4&i.options&&0==i.content.length&&(s|=4);let l=d.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):se(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new ne(e,t,l,o,null,s)),this.open++,n}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;this.localPreserveWS&&(this.nodes[t].options|=1)}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 o=0;o<this.find.length;o++)null==this.find[o].pos&&1==e.nodeType&&e.contains(this.find[o].node)&&t.compareDocumentPosition(this.find[o].node)&(n?2:4)&&(this.find[o].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,o=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),r=-(n?n.depth+1:0)+(o?0:1),i=(e,s)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;s>=r;s--)if(i(e-1,s))return!0;return!1}{let e=s>0||0==s&&o?this.nodes[s].type:n&&s>=r?n.node(s-r).type:null;if(!e||e.name!=l&&!e.isInGroup(l))return!1;s--}}return!0};return i(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}}}function re(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ie(e){let t={};for(let n in e)t[n]=e[n];return t}function se(e,t){let n=t.schema.nodes;for(let o in n){let r=n[o];if(!r.allowsMarkType(e))continue;let i=[],s=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:o,next:r}=e.edge(n);if(o==t)return!0;if(i.indexOf(r)<0&&s(r))return!0}};if(s(r.contentMatch))return!0}}class le{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=ce(t).createDocumentFragment());let o=n,r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:o}=he(ce(t),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){let r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){let o=this.marks[e.type.name];return o&&he(ce(n),o(e,t),null,e.attrs)}static renderSpec(e,t,n=null,o){return he(e,t,n,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new le(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ae(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return ae(e.marks)}}function ae(e){let t={};for(let n in e){let o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function ce(e){return e.document||window.document}const de=new WeakMap;function he(e,t,n,o){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];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(o&&(r=function(e){let t=de.get(e);return void 0===t&&de.set(e,t=function(e){let t=null;return function e(n){if(n&&"object"==typeof n)if(Array.isArray(n))if("string"==typeof n[0])t||(t=[]),t.push(n);else for(let t=0;t<n.length;t++)e(n[t]);else for(let t in n)e(n[t])}(e),t}(e)),t}(o))&&r.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?a.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&a.style?a.style.cssText=c[e]:a.setAttribute(e,c[e])}}for(let r=d;r<t.length;r++){let i=t[r];if(0===i){if(r<t.length-1||r>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}{let{dom:t,contentDOM:r}=he(e,i,n,o);if(a.appendChild(t),r){if(s)throw new RangeError("Multiple content holes");s=r}}}return{dom:a,contentDOM:s}}const pe=Math.pow(2,16);function ue(e,t){return e+t*pe}function fe(e){return 65535&e}class me{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 ge{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&ge.empty)return ge.empty}recover(e){let t=0,n=fe(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))/pe}(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 o=0,r=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?o:0);if(l>e)break;let a=this.ranges[s+r],c=this.ranges[s+i],d=l+a;if(e<=d){let r=l+o+((a?e==l?-1:e==d?1:t:t)<0?0:c);if(n)return r;let i=e==(t<0?l:d)?null:ue(s/3,e-l),h=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(h|=8),new me(r,h,i)}o+=c-a}return n?e+o:new me(e+o,0,null)}touches(e,t){let n=0,o=fe(t),r=this.inverted?2:1,i=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 l=this.ranges[t+r];if(e<=s+l&&t==3*o)return!0;n+=this.ranges[t+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,r=0;o<this.ranges.length;o+=3){let i=this.ranges[o],s=i-(this.inverted?r:0),l=i+(this.inverted?0:r),a=this.ranges[o+t],c=this.ranges[o+n];e(s,s+a,l,l+c),r+=c-a}}invert(){return new ge(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?ge.empty:new ge(e<0?[0,-e,0]:[0,0,e])}}ge.empty=new ge([]);class ye{constructor(e,t,n=0,o=(e?e.length:0)){this.mirror=t,this.from=n,this.to=o,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new ye(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),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 o=e.getMirror(t);this.appendMap(e._maps[t],null!=o&&o<t?n+o: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 o=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=o&&o>t?n-o-1:void 0)}}invert(){let e=new ye;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 o=0;for(let n=this.from;n<this.to;n++){let r=this._maps[n].mapResult(e,t);if(null!=r.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(r.recover);continue}}o|=r.delInfo,e=r.pos}return n?e:new me(e,o,null)}}const we=Object.create(null);class ve{getMap(){return ge.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=we[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 we)throw new RangeError("Duplicate use of step JSON ID "+e);return we[e]=t,t.prototype.jsonID=e,t}}class be{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new be(e,null)}static fail(e){return new be(null,e)}static fromReplace(e,t,n,o){try{return be.ok(e.replace(t,n,o))}catch(e){if(e instanceof h)return be.fail(e.message);throw e}}}function ke(e,t,n){let o=[];for(let r=0;r<e.childCount;r++){let i=e.child(r);i.content.size&&(i=i.copy(ke(i.content,t,i))),i.isInline&&(i=t(i,n,r)),o.push(i)}return s.fromArray(o)}class xe extends ve{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),o=n.node(n.sharedDepth(this.to)),r=new p(ke(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,o),t.openStart,t.openEnd);return be.fromReplace(e,this.from,this.to,r)}invert(){return new Se(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 xe(t.pos,n.pos,this.mark)}merge(e){return e instanceof xe&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new xe(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 xe(t.from,t.to,e.markFromJSON(t.mark))}}ve.jsonID("addMark",xe);class Se extends ve{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 p(ke(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return be.fromReplace(e,this.from,this.to,n)}invert(){return new xe(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 Se(t.pos,n.pos,this.mark)}merge(e){return e instanceof Se&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Se(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 Se(t.from,t.to,e.markFromJSON(t.mark))}}ve.jsonID("removeMark",Se);class Ce extends ve{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return be.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return be.fromReplace(e,this.pos,this.pos+1,new p(s.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 Ce(this.pos,t.marks[n]);return new Ce(this.pos,this.mark)}}return new Me(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ce(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 Ce(t.pos,e.markFromJSON(t.mark))}}ve.jsonID("addNodeMark",Ce);class Me extends ve{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return be.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return be.fromReplace(e,this.pos,this.pos+1,new p(s.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Ce(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Me(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 Me(t.pos,e.markFromJSON(t.mark))}}ve.jsonID("removeNodeMark",Me);class Ne extends ve{constructor(e,t,n,o=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=o}apply(e){return this.structure&&Ae(e,this.from,this.to)?be.fail("Structure replace would overwrite content"):be.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ge([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ne(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 Ne(t.pos,Math.max(t.pos,n.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Ne)||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?p.empty:new p(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ne(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?p.empty:new p(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ne(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 Ne(t.from,t.to,p.fromJSON(e,t.slice),!!t.structure)}}ve.jsonID("replace",Ne);class Oe extends ve{constructor(e,t,n,o,r,i,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=o,this.slice=r,this.insert=i,this.structure=s}apply(e){if(this.structure&&(Ae(e,this.from,this.gapFrom)||Ae(e,this.gapTo,this.to)))return be.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return be.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?be.fromReplace(e,this.from,this.to,n):be.fail("Content does not fit in gap")}getMap(){return new ge([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 Oe(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),o=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),r=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||o<t.pos||r>n.pos?null:new Oe(t.pos,n.pos,o,r,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 Oe(t.from,t.to,t.gapFrom,t.gapTo,p.fromJSON(e,t.slice),t.insert,!!t.structure)}}function Ae(e,t,n){let o=e.resolve(t),r=n-t,i=o.depth;for(;r>0&&i>0&&o.indexAfter(i)==o.node(i).childCount;)i--,r--;if(r>0){let e=o.node(i).maybeChild(o.indexAfter(i));for(;r>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,r--}}return!1}function Te(e,t,n,o=n.contentMatch,r=!0){let i=e.doc.nodeAt(t),l=[],a=t+1;for(let t=0;t<i.childCount;t++){let c=i.child(t),d=a+c.nodeSize,h=o.matchType(c.type);if(h){o=h;for(let t=0;t<c.marks.length;t++)n.allowsMarkType(c.marks[t].type)||e.step(new Se(a,d,c.marks[t]));if(r&&c.isText&&"pre"!=n.whitespace){let e,t,o=/\r?\n|\r/g;for(;e=o.exec(c.text);)t||(t=new p(s.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),l.push(new Ne(a+e.index,a+e.index+e[0].length,t))}}else l.push(new Ne(a,d,p.empty));a=d}if(!o.validEnd){let t=o.fillBefore(s.empty,!0);e.replace(a,a,new p(t,0,0))}for(let t=l.length-1;t>=0;t--)e.step(l[t])}function De(e,t,n){return(0==t||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Ee(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,o=0,r=0;;--n){let i=e.$from.node(n),s=e.$from.index(n)+o,l=e.$to.indexAfter(n)-r;if(n<e.depth&&i.canReplace(s,l,t))return n;if(0==n||i.type.spec.isolating||!De(i,s,l))break;s&&(o=1),l<i.childCount&&(r=1)}return null}function Re(e,t,n=null,o=e){let r=function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.contentMatchAt(o).findWrapping(t);if(!i)return null;let s=i.length?i[0]:t;return n.canReplaceWith(o,r,s)?i:null}(e,t),i=r&&function(e,t){let{parent:n,startIndex:o,endIndex:r}=e,i=n.child(o),s=t.contentMatch.findWrapping(i.type);if(!s)return null;let l=(s.length?s[s.length-1]:t).contentMatch;for(let e=o;l&&e<r;e++)l=l.matchType(n.child(e).type);return l&&l.validEnd?s:null}(o,t);return i?r.map($e).concat({type:t,attrs:n}).concat(i.map($e)):null}function $e(e){return{type:e,attrs:null}}function Ie(e,t,n,o){t.forEach((r,i)=>{if(r.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(r.text);){let r=e.mapping.slice(o).map(n+1+i+s.index);e.replaceWith(r,r+1,t.type.schema.linebreakReplacement.create())}}})}function ze(e,t,n,o){t.forEach((r,i)=>{if(r.type==r.type.schema.linebreakReplacement){let r=e.mapping.slice(o).map(n+1+i);e.replaceWith(r,r+1,t.type.schema.text("\n"))}})}function Be(e,t,n=1,o){let r=e.resolve(t),i=r.depth-n,s=o&&o[o.length-1]||r.parent;if(i<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!s.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let e=r.depth-1,t=n-2;e>i;e--,t--){let n=r.node(e),i=r.index(e);if(n.type.spec.isolating)return!1;let s=n.content.cutByIndex(i,n.childCount),l=o&&o[t+1];l&&(s=s.replaceChild(0,l.type.create(l.attrs)));let a=o&&o[t]||n;if(!n.canReplace(i+1,n.childCount)||!a.type.validContent(s))return!1}let l=r.indexAfter(i),a=o&&o[0];return r.node(i).canReplaceWith(l,l,a?a.type:r.node(i+1).type)}function Pe(e,t){let n=e.resolve(t),o=n.index();return Ve(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(o,o+1)}function Ve(e,t){return!(!e||!t||e.isLeaf||!function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:o}=e.type.schema;for(let r=0;r<t.childCount;r++){let i=t.child(r),s=i.type==o?e.type.schema.nodes.text:i.type;if(n=n.matchType(s),!n)return!1;if(!e.type.allowsMarks(i.marks))return!1}return n.validEnd}(e,t))}function Fe(e,t,n=-1){let o=e.resolve(t);for(let e=o.depth;;e--){let r,i,s=o.index(e);if(e==o.depth?(r=o.nodeBefore,i=o.nodeAfter):n>0?(r=o.node(e+1),s++,i=o.node(e).maybeChild(s)):(r=o.node(e).maybeChild(s-1),i=o.node(e+1)),r&&!r.isTextblock&&Ve(r,i)&&o.node(e).canReplace(s,s+1))return t;if(0==e)break;t=n<0?o.before(e):o.after(e)}}function Le(e,t,n){let o=e.resolve(t);if(o.parent.canReplaceWith(o.index(),o.index(),n))return t;if(0==o.parentOffset)for(let e=o.depth-1;e>=0;e--){let t=o.index(e);if(o.node(e).canReplaceWith(t,t,n))return o.before(e+1);if(t>0)return null}if(o.parentOffset==o.parent.content.size)for(let e=o.depth-1;e>=0;e--){let t=o.indexAfter(e);if(o.node(e).canReplaceWith(t,t,n))return o.after(e+1);if(t<o.node(e).childCount)return null}return null}function He(e,t,n){let o=e.resolve(t);if(!n.content.size)return t;let r=n.content;for(let e=0;e<n.openStart;e++)r=r.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=o.depth;t>=0;t--){let n=t==o.depth?0:o.pos<=(o.start(t+1)+o.end(t+1))/2?-1:1,i=o.index(t)+(n>0?1:0),s=o.node(t),l=!1;if(1==e)l=s.canReplace(i,i,r);else{let e=s.contentMatchAt(i).findWrapping(r.firstChild.type);l=e&&s.canReplaceWith(i,i,e[0])}if(l)return 0==n?o.pos:n<0?o.before(t+1):o.after(t+1)}return null}function _e(e,t,n=t,o=p.empty){if(t==n&&!o.size)return null;let r=e.resolve(t),i=e.resolve(n);return We(r,i,o)?new Ne(t,n,o):new qe(r,i,o).fit()}function We(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}ve.jsonID("replaceAround",Oe);class qe{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=s.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=s.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,o=this.close(e<0?this.$to:n.doc.resolve(e));if(!o)return null;let r=this.placed,i=n.depth,s=o.depth;for(;i&&s&&1==r.childCount;)r=r.firstChild.content,i--,s--;let l=new p(r,i,s);return e>-1?new Oe(n.pos,e,this.$to.pos,this.$to.end(),l,t):l.size||n.pos!=this.$to.pos?new Ne(n.pos,o.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,o=this.unplaced.openEnd;n<e;n++){let r=t.firstChild;if(t.childCount>1&&(o=0),r.type.spec.isolating&&o<=n){e=n;break}t=r.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,o=null;n?(o=Ke(this.unplaced.content,n-1).firstChild,e=o.content):e=this.unplaced.content;let r=e.firstChild;for(let e=this.depth;e>=0;e--){let i,{type:l,match:a}=this.frontier[e],c=null;if(1==t&&(r?a.matchType(r.type)||(c=a.fillBefore(s.from(r),!1)):o&&l.compatibleContent(o.type)))return{sliceDepth:n,frontierDepth:e,parent:o,inject:c};if(2==t&&r&&(i=a.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:e,parent:o,wrap:i};if(o&&a.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=Ke(e,t);return!(!o.childCount||o.firstChild.isLeaf||(this.unplaced=new p(e,t+1,Math.max(n,o.size+t>=e.size-n?t+1:0)),0))}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,o=Ke(e,t);if(o.childCount<=1&&t>0){let r=e.size-t<=t+o.size;this.unplaced=new p(je(e,t-1,1),t-1,r?t-1:n)}else this.unplaced=new p(je(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:o,wrap:r}){for(;this.depth>t;)this.closeFrontierNode();if(r)for(let e=0;e<r.length;e++)this.openFrontierNode(r[e]);let i=this.unplaced,l=n?n.content:i.content,a=i.openStart-e,c=0,d=[],{match:h,type:u}=this.frontier[t];if(o){for(let e=0;e<o.childCount;e++)d.push(o.child(e));h=h.matchFragment(o)}let f=l.size+e-(i.content.size-i.openEnd);for(;c<l.childCount;){let e=l.child(c),t=h.matchType(e.type);if(!t)break;c++,(c>1||0==a||e.content.size)&&(h=t,d.push(Xe(e.mark(u.allowedMarks(e.marks)),1==c?a:0,c==l.childCount?f:-1)))}let m=c==l.childCount;m||(f=-1),this.placed=Je(this.placed,t,s.from(d)),this.frontier[t].match=h,m&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=l;e<f;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=m?0==e?p.empty:new p(je(i.content,e-1,1),e-1,f<0?i.openEnd:e-1):new p(je(i.content,e,c),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e,t=this.frontier[this.depth];if(!t.type.isTextblock||!Ue(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,o=this.$to.after(n);for(;n>1&&o==this.$to.end(--n);)++o;return o}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:o}=this.frontier[t],r=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=Ue(e,t,o,n,r);if(i){for(let n=t-1;n>=0;n--){let{match:t,type:o}=this.frontier[n],r=Ue(e,n,o,t,!0);if(!r||r.childCount)continue e}return{depth:t,fit:i,move:r?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=Je(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),o=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,o)}return e}openFrontierNode(e,t=null,n){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=Je(this.placed,this.depth,s.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(s.empty,!0);e.childCount&&(this.placed=Je(this.placed,this.frontier.length,e))}}function je(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(je(e.firstChild.content,t-1,n)))}function Je(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Je(e.lastChild.content,t-1,n)))}function Ke(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 o=e.content;return t>1&&(o=o.replaceChild(0,Xe(o.firstChild,t-1,1==o.childCount?n-1:0))),t>0&&(o=e.type.contentMatch.fillBefore(o).append(o),n<=0&&(o=o.append(e.type.contentMatch.matchFragment(o).fillBefore(s.empty,!0)))),e.copy(o)}function Ue(e,t,n,o,r){let i=e.node(t),s=r?e.indexAfter(t):e.index(t);if(s==i.childCount&&!n.compatibleContent(i.type))return null;let l=o.fillBefore(i.content,!0,s);return l&&!function(e,t,n){for(let o=n;o<t.childCount;o++)if(!e.allowsMarks(t.child(o).marks))return!0;return!1}(n,i.content,s)?l:null}function Ge(e){return e.spec.defining||e.spec.definingForContent}function Ye(e,t,n,o,r){if(t<n){let r=e.firstChild;e=e.replaceChild(0,r.copy(Ye(r.content,t+1,n,o,r)))}if(t>o){let t=r.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(s.empty,!0))}return e}function Qe(e,t){let n=[];for(let o=Math.min(e.depth,t.depth);o>=0;o--){let r=e.start(o);if(r<e.pos-(e.depth-o)||t.end(o)>t.pos+(t.depth-o)||e.node(o).type.spec.isolating||t.node(o).type.spec.isolating)break;(r==t.start(o)||o==e.depth&&o==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&o&&t.start(o-1)==r-1)&&n.push(o)}return n}class Ze extends ve{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 be.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 o=t.type.create(n,null,t.marks);return be.fromReplace(e,this.pos,this.pos+1,new p(s.from(o),0,t.isLeaf?0:1))}getMap(){return ge.empty}invert(e){return new Ze(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 Ze(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 Ze(t.pos,t.attr,t.value)}}ve.jsonID("attr",Ze);class et extends ve{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return be.ok(n)}getMap(){return ge.empty}invert(e){return new et(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new et(t.attr,t.value)}}ve.jsonID("docAttr",et);let tt=class extends Error{};tt=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},tt.prototype=Object.create(Error.prototype),tt.prototype.constructor=tt,tt.prototype.name="TransformError";class nt{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ye}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new tt(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=p.empty){let o=_e(this.doc,e,t,n);return o&&this.step(o),this}replaceWith(e,t,n){return this.replace(e,t,new p(s.from(n),0,0))}delete(e,t){return this.replace(e,t,p.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,o){if(!o.size)return e.deleteRange(t,n);let r=e.doc.resolve(t),i=e.doc.resolve(n);if(We(r,i,o))return e.step(new Ne(t,n,o));let s=Qe(r,i);0==s[s.length-1]&&s.pop();let l=-(r.depth+1);s.unshift(l);for(let e=r.depth,t=r.pos-1;e>0;e--,t--){let n=r.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;s.indexOf(e)>-1?l=e:r.before(e)==t&&s.splice(1,0,-e)}let a=s.indexOf(l),c=[],d=o.openStart;for(let e=o.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==o.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){let t=c[e],n=Ge(t.type);if(n&&!t.sameMarkup(r.node(Math.abs(l)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=o.openStart;t>=0;t--){let l=(t+d+1)%(o.openStart+1),h=c[l];if(h)for(let t=0;t<s.length;t++){let c=s[(t+a)%s.length],d=!0;c<0&&(d=!1,c=-c);let u=r.node(c-1),f=r.index(c-1);if(u.canReplaceWith(f,f,h.type,h.marks))return e.replace(r.before(c),d?i.after(c):n,new p(Ye(o.content,0,o.openStart,l),l,o.openEnd))}}let h=e.steps.length;for(let l=s.length-1;l>=0&&(e.replace(t,n,o),!(e.steps.length>h));l--){let e=s[l];e<0||(t=r.before(e),n=i.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,o){if(!o.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let r=Le(e.doc,t,o.type);null!=r&&(t=n=r)}e.replaceRange(t,n,new p(s.from(o),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let o=e.doc.resolve(t),r=e.doc.resolve(n),i=Qe(o,r);for(let t=0;t<i.length;t++){let n=i[t],s=t==i.length-1;if(s&&0==n||o.node(n).type.contentMatch.validEnd)return e.delete(o.start(n),r.end(n));if(n>0&&(s||o.node(n-1).canReplace(o.index(n-1),r.indexAfter(n-1))))return e.delete(o.before(n),r.after(n))}for(let i=1;i<=o.depth&&i<=r.depth;i++)if(t-o.start(i)==o.depth-i&&n>o.end(i)&&r.end(i)-n!=r.depth-i&&o.start(i-1)==r.start(i-1)&&o.node(i-1).canReplace(o.index(i-1),r.index(i-1)))return e.delete(o.before(i),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:o,$to:r,depth:i}=t,l=o.before(i+1),a=r.after(i+1),c=l,d=a,h=s.empty,u=0;for(let e=i,t=!1;e>n;e--)t||o.index(e)>0?(t=!0,h=s.from(o.node(e).copy(h)),u++):c--;let f=s.empty,m=0;for(let e=i,t=!1;e>n;e--)t||r.after(e+1)<r.end(e)?(t=!0,f=s.from(r.node(e).copy(f)),m++):d++;e.step(new Oe(c,d,l,a,new p(h.append(f),u,m),h.size-u,!0))}(this,e,t),this}join(e,t=1){return function(e,t,n){let o=null,{linebreakReplacement:r}=e.doc.type.schema,i=e.doc.resolve(t-n),s=i.node().type;if(r&&s.inlineContent){let e="pre"==s.whitespace,t=!!s.contentMatch.matchType(r);e&&!t?o=!1:!e&&t&&(o=!0)}let l=e.steps.length;if(!1===o){let o=e.doc.resolve(t+n);ze(e,o.node(),o.before(),l)}s.inlineContent&&Te(e,t+n-1,s,i.node().contentMatchAt(i.index()),null==o);let a=e.mapping.slice(l),c=a.map(t-n);if(e.step(new Ne(c,a.map(t+n,-1),p.empty,!0)),!0===o){let t=e.doc.resolve(c);Ie(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return function(e,t,n){let o=s.empty;for(let e=n.length-1;e>=0;e--){if(o.size){let t=n[e].type.contentMatch.matchFragment(o);if(!t||!t.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=s.from(n[e].type.create(n[e].attrs,o))}let r=t.start,i=t.end;e.step(new Oe(r,i,r,i,new p(o,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,o=null){return function(e,t,n,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let i=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let l="function"==typeof r?r(t):r;if(t.isTextblock&&!t.hasMarkup(o,l)&&function(e,t,n){let o=e.resolve(t),r=o.index();return o.parent.canReplaceWith(r,r+1,n)}(e.doc,e.mapping.slice(i).map(n),o)){let r=null;if(o.schema.linebreakReplacement){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(o.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&ze(e,t,n,i),Te(e,e.mapping.slice(i).map(n,1),o,void 0,null===r);let a=e.mapping.slice(i),c=a.map(n,1),d=a.map(n+t.nodeSize,1);return e.step(new Oe(c,d,c+1,d-1,new p(s.from(o.create(l,null,t.marks)),0,0),1,!0)),!0===r&&Ie(e,t,n,i),!1}})}(this,e,t,n,o),this}setNodeMarkup(e,t,n=null,o){return function(e,t,n,o,r){let i=e.doc.nodeAt(t);if(!i)throw new RangeError("No node at given position");n||(n=i.type);let l=n.create(o,null,r||i.marks);if(i.isLeaf)return e.replaceWith(t,t+i.nodeSize,l);if(!n.validContent(i.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Oe(t,t+i.nodeSize,t+1,t+i.nodeSize-1,new p(s.from(l),0,0),1,!0))}(this,e,t,n,o),this}setNodeAttribute(e,t,n){return this.step(new Ze(e,t,n)),this}setDocAttribute(e,t){return this.step(new et(e,t)),this}addNodeMark(e,t){return this.step(new Ce(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(t instanceof d)t.isInSet(n.marks)&&this.step(new Me(e,t));else{let o,r=n.marks,i=[];for(;o=t.isInSet(r);)i.push(new Me(e,o)),r=o.removeFromSet(r);for(let e=i.length-1;e>=0;e--)this.step(i[e])}return this}split(e,t=1,n){return function(e,t,n=1,o){let r=e.doc.resolve(t),i=s.empty,l=s.empty;for(let e=r.depth,t=r.depth-n,a=n-1;e>t;e--,a--){i=s.from(r.node(e).copy(i));let t=o&&o[a];l=s.from(t?t.type.create(t.attrs,l):r.node(e).copy(l))}e.step(new Ne(t,t,new p(i.append(l),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){return function(e,t,n,o){let r,i,s=[],l=[];e.doc.nodesBetween(t,n,(e,a,c)=>{if(!e.isInline)return;let d=e.marks;if(!o.isInSet(d)&&c.type.allowsMarkType(o.type)){let c=Math.max(a,t),h=Math.min(a+e.nodeSize,n),p=o.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(r&&r.to==c&&r.mark.eq(d[e])?r.to=h:s.push(r=new Se(c,h,d[e])));i&&i.to==c?i.to=h:l.push(i=new xe(c,h,o))}}),s.forEach(t=>e.step(t)),l.forEach(t=>e.step(t))}(this,e,t,n),this}removeMark(e,t,n){return function(e,t,n,o){let r=[],i=0;e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;i++;let l=null;if(o instanceof X){let t,n=e.marks;for(;t=o.isInSet(n);)(l||(l=[])).push(t),n=t.removeFromSet(n)}else o?o.isInSet(e.marks)&&(l=[o]):l=e.marks;if(l&&l.length){let o=Math.min(s+e.nodeSize,n);for(let e=0;e<l.length;e++){let n,a=l[e];for(let e=0;e<r.length;e++){let t=r[e];t.step==i-1&&a.eq(r[e].style)&&(n=t)}n?(n.to=o,n.step=i):r.push({style:a,from:Math.max(s,t),to:o,step:i})}}}),r.forEach(t=>e.step(new Se(t.from,t.to,t.style)))}(this,e,t,n),this}clearIncompatible(e,t,n){return Te(this,e,t,n),this}}const ot=Object.create(null);class rt{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new it(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=p.empty){let n=t.content.lastChild,o=null;for(let e=0;e<t.openEnd;e++)o=n,n=n.lastChild;let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:l,$to:a}=i[s],c=e.mapping.slice(r);e.replaceRange(c.map(l.pos),c.map(a.pos),s?p.empty:t),0==s&&mt(e,r,(n?n.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){let{$from:i,$to:s}=o[r],l=e.mapping.slice(n),a=l.map(i.pos),c=l.map(s.pos);r?e.deleteRange(a,c):(e.replaceRangeWith(a,c,t),mt(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let o=e.parent.inlineContent?new at(e):ft(e.node(0),e.parent,e.pos,e.index(),t,n);if(o)return o;for(let o=e.depth-1;o>=0;o--){let r=t<0?ft(e.node(0),e.node(o),e.before(o+1),e.index(o),t,n):ft(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,n);if(r)return r}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new pt(e.node(0))}static atStart(e){return ft(e,e,0,0,1)||new pt(e)}static atEnd(e){return ft(e,e,e.content.size,e.childCount,-1)||new pt(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=ot[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 ot)throw new RangeError("Duplicate use of selection JSON ID "+e);return ot[e]=t,t.prototype.jsonID=e,t}getBookmark(){return at.between(this.$anchor,this.$head).getBookmark()}}rt.prototype.visible=!0;class it{constructor(e,t){this.$from=e,this.$to=t}}let st=!1;function lt(e){st||e.parent.inlineContent||(st=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class at extends rt{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 rt.near(n);let o=e.resolve(t.map(this.anchor));return new at(o.parent.inlineContent?o:n,n)}replace(e,t=p.empty){if(super.replace(e,t),t==p.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof at&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ct(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 at(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let o=e.resolve(t);return new this(o,n==t?o:e.resolve(n))}static between(e,t,n){let o=e.pos-t.pos;if(n&&!o||(n=o>=0?1:-1),!t.parent.inlineContent){let e=rt.findFrom(t,n,!0)||rt.findFrom(t,-n,!0);if(!e)return rt.near(t,n);t=e.$head}return e.parent.inlineContent||(0==o||(e=(rt.findFrom(e,-n,!0)||rt.findFrom(e,n,!0)).$anchor).pos<t.pos!=o<0)&&(e=t),new at(e,t)}}rt.jsonID("text",at);class ct{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ct(e.map(this.anchor),e.map(this.head))}resolve(e){return at.between(e.resolve(this.anchor),e.resolve(this.head))}}class dt extends rt{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:o}=t.mapResult(this.anchor),r=e.resolve(o);return n?rt.near(r):new dt(r)}content(){return new p(s.from(this.node),0,0)}eq(e){return e instanceof dt&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ht(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new dt(e.resolve(t.anchor))}static create(e,t){return new dt(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}dt.prototype.visible=!1,rt.jsonID("node",dt);class ht{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new ct(n,n):new ht(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&dt.isSelectable(n)?new dt(t):rt.near(t)}}class pt extends rt{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=p.empty){if(t==p.empty){e.delete(0,e.doc.content.size);let t=rt.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new pt(e)}map(e){return new pt(e)}eq(e){return e instanceof pt}getBookmark(){return ut}}rt.jsonID("all",pt);const ut={map(){return this},resolve:e=>new pt(e)};function ft(e,t,n,o,r,i=!1){if(t.inlineContent)return at.create(e,n);for(let s=o-(r>0?0:1);r>0?s<t.childCount:s>=0;s+=r){let o=t.child(s);if(o.isAtom){if(!i&&dt.isSelectable(o))return dt.create(e,n-(r<0?o.nodeSize:0))}else{let t=ft(e,o,n+r,r<0?o.childCount:0,r,i);if(t)return t}n+=o.nodeSize*r}return null}function mt(e,t,n){let o=e.steps.length-1;if(o<t)return;let r,i=e.steps[o];(i instanceof Ne||i instanceof Oe)&&(e.mapping.maps[o].forEach((e,t,n,o)=>{null==r&&(r=o)}),e.setSelection(rt.near(e.doc.resolve(r),n)))}class gt extends nt{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&this.updated|1,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return d.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(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)||d.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let o=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(o.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let r=this.storedMarks;if(!r){let e=this.doc.resolve(t);r=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,o.text(e,r)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(rt.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 yt(e,t){return t&&e?e.bind(t):e}class wt{constructor(e,t,n){this.name=e,this.init=yt(t.init,n),this.apply=yt(t.apply,n)}}const vt=[new wt("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new wt("selection",{init:(e,t)=>e.selection||rt.atStart(t.doc),apply:e=>e.selection}),new wt("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,o)=>o.selection.$cursor?e.storedMarks:null}),new wt("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class bt{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=vt.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 wt(e.key,e.spec.state,e))})}}class kt{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),o=null;for(;;){let r=!1;for(let i=0;i<this.config.plugins.length;i++){let s=this.config.plugins[i];if(s.spec.appendTransaction){let l=o?o[i].n:0,a=o?o[i].state:this,c=l<t.length&&s.spec.appendTransaction.call(s,l?t.slice(l):t,a,n);if(c&&n.filterTransaction(c,i)){if(c.setMeta("appendedTransaction",e),!o){o=[];for(let e=0;e<this.config.plugins.length;e++)o.push(e<i?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),r=!0}o&&(o[i]={state:n,n:t.length})}}if(!r)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new kt(this.config),n=this.config.fields;for(let o=0;o<n.length;o++){let r=n[o];t[r.name]=r.apply(e,this[r.name],this,t)}return t}get tr(){return new gt(this)}static create(e){let t=new bt(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new kt(t);for(let o=0;o<t.fields.length;o++)n[t.fields[o].name]=t.fields[o].init(e,n);return n}reconfigure(e){let t=new bt(this.schema,e.plugins),n=t.fields,o=new kt(t);for(let t=0;t<n.length;t++){let r=n[t].name;o[r]=this.hasOwnProperty(r)?this[r]:n[t].init(e,o)}return o}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 o=e[n],r=o.spec.state;r&&r.toJSON&&(t[n]=r.toJSON.call(o,this[o.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 o=new bt(e.schema,e.plugins),r=new kt(o);return o.fields.forEach(o=>{if("doc"==o.name)r.doc=D.fromJSON(e.schema,t.doc);else if("selection"==o.name)r.selection=rt.fromJSON(r.doc,t.selection);else if("storedMarks"==o.name)t.storedMarks&&(r.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let i in n){let s=n[i],l=s.spec.state;if(s.key==o.name&&l&&l.fromJSON&&Object.prototype.hasOwnProperty.call(t,i))return void(r[o.name]=l.fromJSON.call(s,e,t[i],r))}r[o.name]=o.init(e,r)}}),r}}function xt(e,t,n){for(let o in e){let r=e[o];r instanceof Function?r=r.bind(t):"handleDOMEvents"==o&&(r=xt(r,t,{})),n[o]=r}return n}class St{constructor(e){this.spec=e,this.props={},e.props&&xt(e.props,this,this.props),this.key=e.key?e.key.key:Mt("plugin")}getState(e){return e[this.key]}}const Ct=Object.create(null);function Mt(e){return e in Ct?e+"$"+ ++Ct[e]:(Ct[e]=0,e+"$")}class Nt{constructor(e="key"){this.key=Mt(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Ot="k-parent-node",At="k-colgroup-data",Tt="k-resizable-node",Dt="k-editor-resize-handle",Et="data-dir-table-resize",Rt="data-dir-image-resize";var $t=function(){return"undefined"!=typeof window},It={wp:/(Windows Phone(?: OS)?)\s(\d+)\.(\d+(\.\d+)?)/,fire:/(Silk)\/(\d+)\.(\d+(\.\d+)?)/,android:/(Android|Android.*(?:Opera|Firefox).*?\/)\s*(\d+)(\.(\d+(\.\d+)?))?/,iphone:/(iPhone|iPod).*OS\s+(\d+)[\._]([\d\._]+)/,ipad:/(iPad).*OS\s+(\d+)[\._]([\d_]+)/,meego:/(MeeGo).+NokiaBrowser\/(\d+)\.([\d\._]+)/,webos:/(webOS)\/(\d+)\.(\d+(\.\d+)?)/,blackberry:/(BlackBerry|BB10).*?Version\/(\d+)\.(\d+(\.\d+)?)/,playbook:/(PlayBook).*?Tablet\s*OS\s*(\d+)\.(\d+(\.\d+)?)/,windows:/(MSIE)\s+(\d+)\.(\d+(\.\d+)?)/,tizen:/(tizen).*?Version\/(\d+)\.(\d+(\.\d+)?)/i,sailfish:/(sailfish).*rv:(\d+)\.(\d+(\.\d+)?).*firefox/i,ffos:/(Mobile).*rv:(\d+)\.(\d+(\.\d+)?).*Firefox/},zt={ios:/^i(phone|pad|pod)$/i,android:/^android|fire$/i,blackberry:/^blackberry|playbook/i,windows:/windows/,wp:/wp/,flat:/sailfish|ffos|tizen/i,meego:/meego/},Bt={edge:/(edge)[ \/]([\w.]+)/i,webkit:/(chrome)[ \/]([\w.]+)/i,safari:/(webkit)[ \/]([\w.]+)/i,opera:/(opera)(?:.*version|)[ \/]([\w.]+)/i,msie:/(msie\s|trident.*? rv:)([\w.]+)/i,mozilla:/(mozilla)(?:.*? rv:([\w.]+)|)/i},Pt={omini:/Opera\sMini/i,omobile:/Opera\sMobi/i,firefox:/Firefox|Fennec/i,mobilesafari:/version\/.*safari/i,ie:/MSIE|Windows\sPhone/i,chrome:/chrome|crios/i,webkit:/webkit/i},Vt=function(e,t,n){for(var o in t)if(t.hasOwnProperty(o)&&t[o].test(e))return o;return void 0!==n?n:e},Ft=$t()&&window.navigator?window.navigator.userAgent:null,Lt=Ft?function(e){var t=null,n=[];for(var o in Bt)if(Bt.hasOwnProperty(o)&&(n=e.match(Bt[o]))){(t={})[o]=!0,t[n[1].toLowerCase().split(" ")[0].split("/")[0]]=!0,t.version=parseInt(document.documentMode||n[2],10);break}return t}(Ft):null,Ht=(Ft&&function(e){var t,n=[];for(var o in It)if(It.hasOwnProperty(o)){if(!(n=e.match(It[o])))continue;if("windows"===o&&"plugins"in window.navigator)return null;var r={};return r.device=o,r.browser=Vt(e,Pt,"default"),r.name=Vt(o,zt),r[r.name]=!0,r.majorVersion=n[2],r.minorVersion=n[3]?n[3].replace("_","."):".0",t=r.minorVersion.replace(".","").substr(0,2),r.flatVersion=r.majorVersion+t+new Array(3-(t.length<3?t.length:2)).join("0"),r.cordova=void 0!==typeof window.PhoneGap||void 0!==typeof window.cordova,r.appMode=window.navigator.standalone||/file|local|wmapp/.test(window.location.protocol)||r.cordova,r}}(Ft),$t()&&window,Lt&&!Lt.chrome&&window.MSPointerEvent,Lt&&!Lt.chrome&&window.PointerEvent,{});Ht[void 0]=function(e){return e};var _t=/\/\*[\s\S]*?\*\//g,Wt=/([^\s:;]+?)\s*:\s*((?:(?:url\(\s*(?:(?:[^"')\\]|\\.)*|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')\s*\)|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^;"'])*?)\s*)(?=;|$)/gi,qt=/&quot;|&#34;|&#x22;/gi,jt=/&apos;|&#39;|&#x27;/gi;const Jt=(e,t)=>{const n=t.style,o=t.value,r=t.newValue;if(!e)return{changed:!1,style:null};const i=cn(e),s=Object.keys(i),l=[];for(let e=0;e<s.length;e++){const t=s[e];t.toLowerCase()===n&&o.test(i[t])||l.push(`${t}: ${i[t]}`)}return r&&l.push(`${n}: ${r}`),{style:l.join("; ")+(l.length?";":""),changed:Boolean(r)||l.length!==s.length}},Kt=/^.+$/;function Xt(e,t,n){let o;if(new RegExp("[^-]?"+t+":").test(e.style||"")){const{style:r}=Jt(e.style||"",{style:t,value:Kt,newValue:n});o={...e,style:r}}else o=e.style?{...e,style:e.style.replace(/;$/,"")+"; "+t+": "+n+";"}:{...e,style:t+": "+n+";"};return o}const Ut=(e,t)=>{const n=e.selection.$from;for(let e=n.depth;e>=0;e--){const o=n.index(e);if(n.node(e).canReplaceWith(o,o,t))return!0}return!1},Gt=e=>e instanceof D?e.type.name:e.name,Yt=(e,t=1)=>n=>((e,t=1)=>n=>{const{$from:o}=n;for(let n=o.depth;n>0;n--){const r=o.node(n);if(e(r)&&0==(t-=1))return{depth:n,node:r}}})(t=>Gt(t)===Gt(e),t)(n);function Qt(e,t){for(let n=e.depth;n>0;n--){const o=e.node(n);if(t(o))return{node:o,depth:n}}return null}const Zt=e=>{const t={};for(const n in e)n&&(e[n]||0===e[n])&&(t[n]=e[n]);return t},en=(e,t)=>(n,o)=>{const{selection:r,tr:i}=n;r instanceof dt&&r.node.type.name===e.type.name&&e.isLeaf&&!e.isText&&1===e.nodeSize?(i.setNodeMarkup(r.from,null,{...Zt(r.node.attrs),...Zt(e.attrs)}),i.setSelection(dt.create(i.doc,r.from))):i.replaceSelectionWith(e),t&&i.scrollIntoView(),o(i)},tn=e=>{const t=e.selection;if(t instanceof at||t instanceof pt){const e=t.content().content;return e.textBetween(0,e.size)}return""},nn=e=>{if(e.selection instanceof dt)return e.selection.node},on=e=>{let t="",n=!1;const{selection:o,doc:r}=e,{$from:i,$to:s,from:l,to:a}=o;return i.sameParent(s)&&(r.nodesBetween(l,a,e=>{n=n||e.isLeaf&&!e.isText}),n||(t=tn(e))),t},rn=e=>e.replace(/<\/(p|li|ul|ol|h[1-6]|table|tr|td|th)>/gi,"</$1>\n").replace(/<(ul|ol)([^>]*)><li/gi,"<$1$2>\n<li").replace(/<br \/>/gi,"<br />\n").replace(/\n$/,""),sn={before:/[^ !,?.[\]{}()]+$/i,after:/^[^ !,?.[\]{}()]+/i},ln=(e,t,n)=>{if(!n.applyToWord||!e.selection.empty)return{state:e,dispatch:t};const o=!0===n.applyToWord?sn:n.applyToWord;let r=null;const i=e.tr,s=e.selection,l=s.$head.nodeBefore,a=s.$head.nodeAfter;if(l&&"text"===l.type.name&&l.text&&a&&"text"===a.type.name&&a.text){const n=[];s.$head.parent.descendants((e,t)=>(n.push({node:e,pos:t}),!1));let l=s.$head.parentOffset;const a=n.findIndex(({node:e,pos:t})=>t<=l&&t+e.nodeSize>=l);let c=n[a].node.text,d=!1;for(let e=a-1;e>=0;e--){const t=n[e];!d&&t&&"text"===t.node.type.name?c=t.node.text+c:(d=!0,l-=t.node.nodeSize)}for(let e=a+1;e<n.length;e++){const t=n[e];if(!t||"text"!==t.node.type.name)break;c+=t.node.text}const h=c.substring(0,l),p=c.substring(l),u=o.before.exec(h),f=o.after.exec(p);if(u&&f){const n=u[0].length,o=f[0].length,l=r=s.from;return i.setSelection(at.create(e.doc,l-n,l+o)),{state:{tr:i,selection:i.selection,doc:i.doc,storedMarks:null,schema:i.doc.type.schema},dispatch:e=>{e.setSelection(at.create(e.doc,r)),t(e)}}}}return{state:e,dispatch:t}},an=(e,t)=>(n,o)=>{const{state:r,dispatch:i}=ln(n,o,t);return e(t)(r,i)},cn=e=>function(e){for(var t,n,o={},r=(e||"").replace(_t,"").replace(qt,'"').replace(jt,"'"),i=Wt.exec(r);null!==i;)t=i[1].trim(),n=i[2].trim(),o[t]=n,i=Wt.exec(r);return o}(e),dn=(e,t,n)=>{const o=cn(e);o[t]=n;const r=Object.keys(o).map(e=>o[e]?`${e}: ${o[e]}`:null).filter(Boolean).join("; ");return r?r+";":null},hn=(e,t)=>{const n=cn(t);for(const t in n)t&&void 0!==e.style[t]&&(e.style[t]=n[t])},pn=(e,t,n)=>{const o=e.getAttribute(t);void 0!==n&&n!==o?"style"===t?(e.removeAttribute(t),hn(e,n)):e.setAttribute(t,n):void 0===n&&e.removeAttribute(t)};class un{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 o,r=t[0],i=r.indexOf(" ");i>0&&(n=r.slice(0,i),r=r.slice(i+1));const s=n?e.createElementNS(n,r):e.createElement(r),l=t[1];let a=1;if(l&&"object"==typeof l&&null==l.nodeType&&!Array.isArray(l)){a=2;for(const e in l)null!=l[e]&&(i=e.indexOf(" "),i>0?s.setAttributeNS(e.slice(0,i),e.slice(i+1),l[e]):pn(s,e,l[e]))}for(let r=a;r<t.length;r++){const i=t[r];if(0===i){if(r<t.length-1||r>a)throw new RangeError("Content hole must be the only child of its parent node");return{dom:s,contentDOM:s}}{const{dom:t,contentDOM:r}=un.renderSpec(e,i,n);if(s.appendChild(t),r){if(o)throw new RangeError("Multiple content holes");o=r}}}return{dom:s,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new un(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){const t=fn(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return fn(e.marks)}constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=mn(t).createDocumentFragment());let o=n;const r=[];return e.forEach(e=>{if(r.length||e.marks.length){let n=0,i=0;for(;n<r.length&&i<e.marks.length;){const t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<r.length;)o=r.pop()[1];for(;i<e.marks.length;){const n=e.marks[i++],s=this.serializeMark(n,e.isInline,t);s&&(r.push([n,o]),o.appendChild(s.dom),o=s.contentDOM||s.dom)}}o.appendChild(this.serializeNodeInner(e,t))}),n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){const r=this.serializeMark(e.marks[o],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){const o=this.marks[e.type.name];return o&&un.renderSpec(mn(n),o(e,t))}serializeNodeInner(e,t){const{dom:n,contentDOM:o}=un.renderSpec(mn(t),this.nodes[e.type.name](e));if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}}function fn(e){const t={};for(const n in e)if(e[n]){const o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function mn(e){return e.document||window.document}const gn=["div","ol","ul","li","table","tbody","thead","tfoot","caption","td","th","p","tr","col","colgroup","article","main","nav","header","footer","aside","section"],yn=(e,t)=>{const n=(e.ownerDocument||document).createElement(t);Array.from(e.rows).filter(e=>e.getAttribute(Ot)===t).forEach(e=>{e.removeAttribute(Ot),n.appendChild(e)}),n.children.length&&e.appendChild(n)},wn=(e,t)=>{const n=t.toUpperCase();e.filter(e=>e.nodeName===n).forEach(e=>{Array.from(e.children).forEach(n=>{n.setAttribute(Ot,t),e.parentNode&&e.parentNode.insertBefore(n,e)}),e.remove()})},vn=(e,t=gn)=>{const n=t.join("|");return e.replace(new RegExp("\\s*(<(?:"+n+")(?:\\s[^>]*?)?>)","g"),"$1").replace(new RegExp("(<\\/(?:"+n+")(?:\\s[^>]*?)?>)\\s*","g"),"$1")},bn="data-style",kn=" "+bn+"=",xn=/<[^>]+>/gm,Sn=/\sstyle=/gm,Cn=e=>e.replace(Sn,kn),Mn=e=>{const t=document.createElement("template");var n;return t.innerHTML=(e=>e.replace(xn,Cn))(e),n=t.content,Array.from(n.querySelectorAll("["+bn+"]")).forEach(e=>{const t=e.getAttribute(bn);e.removeAttribute(bn),hn(e,t)}),t.content.cloneNode(!0)},Nn=e=>Array.from(e.childNodes).reduce((e,t)=>e+(t.outerHTML||t.textContent||""),""),On=e=>{const t=un.fromSchema(e.type.schema).serializeFragment(e.content);return(e=>{Array.from(e.querySelectorAll("table")).forEach(e=>{yn(e,"thead"),yn(e,"tbody"),yn(e,"tfoot");const t=Array.from(e.children).find(e=>0===e.children.length);t&&t.remove();const n=e.parentNode instanceof HTMLDivElement?e.parentNode:null;if(n&&n.matches("div[table]")){e.style.marginLeft=n.style.marginLeft,e.style.marginRight=n.style.marginRight;const t=Array.from(n.children).find(e=>e.matches("div[caption]"));if(t&&"<img>"!==t.innerHTML){const n=e.createCaption();for(t.id&&(n.id=t.id),t.className&&(n.className=t.className),Array.from(t.style).forEach(e=>{n.style[e]=t.style[e]});t.firstChild;)n.appendChild(t.firstChild)}n.style.width&&!e.style.width&&(e.style.width=n.style.width),n.parentNode.insertBefore(e,n),n.parentNode.removeChild(n)}})})(t),t},An=(e,t,n)=>Y.fromSchema(t).parse(e,n),Tn=(e,t,n)=>{const o=Mn(e);var r;return r=o,Array.from(r.querySelectorAll("table")).forEach(e=>{const t=Array.from(e.children);t.some(e=>"THEAD"===e.nodeName||"TFOOT"===e.nodeName)&&(wn(t,"thead"),wn(t,"tbody"),wn(t,"tfoot"));const n=t.find(e=>"COLGROUP"===e.nodeName);if(n&&(e.setAttribute(At,n.outerHTML),n.remove()),e.caption||e.style.marginLeft||e.style.marginRight){const t=document.createElement("div");if(t.setAttribute("table",""),t.style.display="table",t.style.marginLeft=e.style.marginLeft,t.style.marginRight=e.style.marginRight,e.caption){const n=document.createElement("div");for(n.setAttribute("caption",""),e.caption.id&&(n.id=e.caption.id),e.caption.className&&(n.className=e.caption.className),Array.from(e.caption.style).forEach(t=>{n.style[t]=e.caption.style[t]});e.caption.firstChild;)n.appendChild(e.caption.firstChild);e.removeChild(e.caption),t.appendChild(n)}e.parentNode.insertBefore(t,e),t.appendChild(e),/%/.test(e.style.width)&&(t.style.width=e.style.width,e.style.width="")}}),An(o,t,n)},Dn=e=>{const t=On(e.doc);return Nn(t)},En=(e,t="setHTML",n={preserveWhitespace:"full"})=>(o,r)=>r(o.tr.setSelection(new pt(o.doc)).replaceSelectionWith(Tn(e,o.schema,n)).setMeta("commandName",t)),Rn=(e,t,n,o)=>{const r=s.from(Tn(e,n,o)),i=s.from(Tn(t,n,o));return r.eq(i)},$n=e=>{const t=Mn(e);return In(t),Nn(t)},In=e=>{var t;const n=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_COMMENT);let o=n.nextNode();for(;o;)null===(t=o.parentNode)||void 0===t||t.removeChild(o),o=n.nextNode()};class zn{constructor(e){this.extractBefore=e=>this._traverseSide({edge:e,next:function(e){return e.previousSibling},insert:function(e,t){e.insertBefore(t,e.firstChild)}}),this.extractAfter=e=>this._traverseSide({edge:e,next:function(e){return e.nextSibling},insert:function(e,t){e.appendChild(t)}}),this._traverseSide=e=>{const t=this.top,n=t.ownerDocument.createDocumentFragment();let o=e.edge;do{const r=o.parentNode;for(o=e.next(o);o;){const t=e.next(o);e.insert(n,o),o=t}if(t===r||t.contains(r)){const t=r.cloneNode(!1);t.innerHTML="",t.appendChild(n),e.insert(n,t)}o=r}while(o&&o!==t);return n},this.top=e}}const Bn=e=>e.querySelector("span span"),Pn=e=>1===e.childNodes.length&&"SPAN"===e.firstChild.nodeName&&0===e.firstChild.childNodes.length,Vn=e=>{const t=Mn(e);let n=Bn(t);for(;n;){const e=n.parentNode.closest("span");if(e){const t=new zn(e),o=t.extractAfter(n),r=t.extractBefore(n);for(let t=0;t<n.style.length;t++){const o=n.style.item(t);e.style[o]=n.style.getPropertyValue(o)}n.removeAttribute("style"),n.classList.length&&Array.from(n.classList).forEach(t=>{e.classList.contains(t)||e.classList.add(t)}),n.removeAttribute("class");for(let t=0;t<n.attributes.length;t++){const o=n.attributes.item(t);o&&null!==o.nodeValue&&e.setAttribute(o.nodeName,o.nodeValue)}for(;n.firstChild&&n.parentNode;)n.parentNode.insertBefore(n.firstChild,n);n.parentNode&&n.parentNode.removeChild(n),e.parentNode&&(Pn(r)||e.parentNode.insertBefore(r,e),Pn(o)||e.parentNode.insertBefore(o,e.nextSibling))}n=Bn(t)}return Nn(t)},Fn=(e,t,n)=>{const o=o=>{const r=t[o],i=r.$from,s=r.$to;let l=0===i.depth&&e.type.allowsMarkType(n);if(e.nodesBetween(i.pos,s.pos,e=>{if(l)return!1;l=e.inlineContent&&e.type.allowsMarkType(n)}),l)return{v:!0}};for(let e=0;e<t.length;e++){const t=o(e);if(t)return t.v}return!1},Ln=(e,t,n)=>(o,r)=>{const{empty:i,$cursor:s,ranges:l}=o.selection;if(i&&!s||!Fn(o.doc,l,e))return!1;if(r)if(s)e.isInSet(o.storedMarks||s.marks())?r(n.removeStoredMark(e)):r(n.addStoredMark(e.create(t)));else{let i=!1;for(let t=0;!i&&t<l.length;t++){const{$from:n,$to:r}=l[t];i=o.doc.rangeHasMark(n.pos,r.pos,e)}for(let o=0;o<l.length;o++){const{$from:r,$to:s}=l[o];i?n.removeMark(r.pos,s.pos,e):n.addMark(r.pos,s.pos,e.create(t))}r(n.scrollIntoView())}return!0},Hn=(e,t,n,o)=>{void 0===o&&(o=null);const r=[];let i=0;return e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;i++;let l=null;if(o instanceof X){const t=o.isInSet(e.marks);t&&(l=[t])}else o?o.isInSet(e.marks)&&(l=[o]):l=e.marks;if(l&&l.length){const o=Math.min(s+e.nodeSize,n);for(let e=0;e<l.length;e++){const n=l[e];let a;for(let e=0;e<r.length;e++){const t=r[e];t.step===i-1&&n.eq(t.style)&&(a=t)}a?(a.to=o,a.step=i):r.push({style:n,from:Math.max(s,t),to:o,step:i})}}}),r.forEach(t=>e.step(new Se(t.from,t.to,t.style))),e},_n=({except:e=[]}={})=>(t,n)=>{const o=t.tr;var r;Wn(o,{except:(r=e,r instanceof Array?r:[r])}),o.docChanged&&n(o)},Wn=(e,{except:t})=>{const{doc:n,selection:o}=e,r=n.type.schema,{empty:i,ranges:s}=o,l=(t||[]).map(e=>e.name);if(!i){const t=Object.keys(r.marks).map(e=>r.marks[e]).filter(e=>-1===l.indexOf(e.name));s.forEach(({$from:n,$to:o})=>{t.forEach(t=>e.removeMark(n.pos,o.pos,t))})}},qn=(e,t)=>{const n=e.schema.marks,o=(t.altMarks||[]).filter(e=>n[e]),r=t.altStyle,{from:i,$from:s,to:l,empty:a}=e.selection,c=n[t.mark],d=e.doc;let h,p=!1;return a?(h=e.storedMarks||s.marks(),p=c&&c.isInSet(h)||o.some(e=>n[e].isInSet(h))):p=c&&d.rangeHasMark(i,l,c)||o.some(e=>d.rangeHasMark(i,l,n[e])),!p&&r&&n.style?Jn(e,n.style).some(e=>null!==jn(e,r)):Boolean(p)},jn=(e,t)=>{const n=e&&e.attrs.style||"",o=cn(n),r=Object.keys(o);for(let e=0;e<r.length;e++){const n=r[e];if(n.toLowerCase()===t.name&&t.value.test(o[n]))return o[n]}return null},Jn=(e,t)=>{const{from:n,$from:o,to:r,empty:i}=e.selection,s=[];return i?s.push(t.isInSet(e.storedMarks||o.marks())):e.doc.nodesBetween(n,r,e=>{e.isInline&&s.push(t.isInSet(e.marks))}),s},Kn=(e,t)=>{const n=Jn(e,t),o=n.filter(e=>Boolean(e));return n.length===o.length?n[0]:void 0},Xn=(e,t)=>{const n=Jn(e,t),o=n.filter(e=>Boolean(e));return{hasNodesWithoutMarks:n.length!==o.length,marks:o}},Un=(e,t)=>{const n=e.find(e=>"style"===e.type.name),o=n&&n.attrs.style;return Jt(o,t)},Gn=(e,t,n,o,r)=>{const i=r.create({style:o.style}),s=[],l=[];let a=null,c=null;return e.doc.nodesBetween(t,n,(e,d,h)=>{if(!e.isInline)return;const p=e.marks;if(!i.isInSet(p)&&h.type.allowsMarkType(i.type)){const i=Math.max(d,t),h=Math.min(d+e.nodeSize,n),u=Un(p,o);if(u.changed||o.newValue){const e=u.changed?{style:u.style||null}:{style:`${o.style}: ${o.newValue};`},t=r.isInSet(p)?p.find(e=>"style"===e.type.name):null,n=t?{...t.attrs,...e}:e,d=r.create(n),f=d.addToSet(p);for(let e=0;e<p.length;e++)p[e].isInSet(f)||(a&&a.to===i&&a.mark.eq(p[e])?a.to=h:(a=new Se(i,h,p[e]),s.push(a)));const m=c&&c.to===i,g=m&&d.attrs.style===c.mark.attrs.style;m&&g?c.to=h:Object.keys(n).some(e=>null!==n[e])&&(c=new xe(i,h,d),l.push(c))}}}),s.forEach(t=>e.step(t)),l.forEach(t=>e.step(t)),s.length+l.length>0},Yn=(e,t)=>{const n=e.schema.marks.style;return(n?Jn(e,n):[]).map(e=>jn(e,t)).filter(e=>null!==e)},Qn=(e,t)=>function(n,o,r){const{empty:i,ranges:s}=n.selection,l=n.selection instanceof at&&n.selection.$cursor;if(i&&!l||!Fn(n.doc,s,e))return!1;let a=!1;if(o){const i=r||n.tr;if(l){const r=n.storedMarks||l.marks();if(e.isInSet(r)){const n=Un(r,t),s=r.find(e=>"style"===e.type.name),l={...s?s.attrs:{},style:n.style||null};if(((e,t)=>{const n=Object.keys(e),o=Object.keys(t);return n.length===o.length&&n.every(n=>e[n]===t[n])})(s.attrs,l))return!1;o(i.removeStoredMark(e)),Object.keys(l).some(e=>null!==l[e])&&o(i.addStoredMark(e.create(l))),a=!0}}else{for(let n=0;n<s.length;n++){const{$from:o,$to:r}=s[n];a=Gn(i,o.pos,r.pos,t,e)||a}a&&(i.scrollIntoView(),o(i))}}return a},Zn=(e,t,n)=>(o,r)=>{const i=o.schema.marks,{altStyle:s,altMarks:l=[],mark:a}=e,c=t||o.tr;let d=!1,h=!1;const p=()=>h=!0;s&&i.style&&(d=Qn(i.style,{style:s.name,value:s.value})(o,p,c));const u=[a,...l].filter(e=>i[e]).map(e=>qn(o,{mark:e})&&i[e]).filter(e=>e);return u.length?((e,t,n,o)=>{const{$cursor:r,ranges:i}=t.selection;if(o=o||t.tr,r)e.forEach(e=>{e.isInSet(t.storedMarks||r.marks())&&n(o.removeStoredMark(e))});else{for(let t=0;t<i.length;t++){const{$from:n,$to:r}=i[t];e.forEach(e=>{Hn(o,n.pos,r.pos,e)})}n(o.scrollIntoView())}})(u,o,p,c):d||Ln(i[a],n,c)(o,p),h&&r(c),h},eo=(e,t)=>(n,o)=>{const r=n.schema.marks.style,i={style:e.style,value:/^.+$/,newValue:e.value},s=n.tr;t&&s.setMeta("commandName",t),s.setMeta("args",e);const{empty:l,$cursor:a,ranges:c}=n.selection;if(l&&!a||!r||!Fn(n.doc,c,r))return!1;if(a){const e=n.storedMarks||a.marks(),t=r.isInSet(e)?e.find(e=>"style"===e.type.name):null,l={style:null};if(t&&t.attrs.style){const e=Jt(t.attrs.style,i);e.changed&&e.style&&(l.style=e.style)}else i.newValue&&(l.style=`${i.style}: ${i.newValue};`);const c=t?{...t.attrs,...l}:l;return Object.keys(c).some(e=>null!==c[e])?o(s.addStoredMark(r.create(c))):o(s.removeStoredMark(r)),!0}return Qn(r,i)(n,o,s)},to=(e,t)=>(n,o)=>{const{$cursor:r}=n.selection;if(r){const i=r.parent,s=r.index(),l=n.schema.marks[e.mark],a=i.child(s).marks.find(e=>e.type===l),c=i.childCount;let d,h,p=r.pos-r.textOffset,u=i.child(s).nodeSize;for(d=s-1;d>=0&&a.isInSet(i.child(d).marks);)h=i.child(d).nodeSize,u+=h,p-=h,d-=1;for(d=s+1;d<c&&a.isInSet(i.child(d).marks);)u+=i.child(d).nodeSize,d+=1;o(Hn(t||n.tr,p,p+u,a))}else Zn(e,t)(n,o)},no=({mark:e,attrs:t},n="link")=>(o,r)=>{const i=o.schema.marks,s=o.tr;n&&(s.setMeta("commandName",n),s.setMeta("args",t));let l=!1;const a=()=>l=!0;if(((e,t)=>{const n=Jn(e,t);return 1===n.length&&n[0]?n[0]:null})(o,i[e]))((e,t)=>(n,o)=>{const{$cursor:r,from:i,to:s}=n.selection,l=n.schema.marks[e.mark];if(r){const n=r.parent,i=r.index(),s=n.child(i).marks.find(e=>e.type===l),a=n.childCount;let c,d,h=r.pos-r.textOffset,p=n.child(i).nodeSize;for(c=i-1;c>=0&&s.isInSet(n.child(c).marks);)d=n.child(c).nodeSize,p+=d,h-=d,c-=1;for(c=i+1;c<a&&s.isInSet(n.child(c).marks);)p+=n.child(c).nodeSize,c+=1;t.removeMark(h,h+p,l),t.addMark(h,h+p,l.create(e.attrs)),o(t)}else t.doc.nodesBetween(i,s,(n,r)=>{n.isInline&&l.isInSet(n.marks)&&(t.removeMark(r,r+n.nodeSize,l),t.addMark(r,r+n.nodeSize,l.create(e.attrs)),o(t))})})({mark:e,attrs:t},s)(o,a);else{let n=o;qn(o,{mark:e})&&(to({mark:e,attrs:t},s)(o,a),n=kt.create({doc:s.doc,selection:s.selection})),l?Ln(i[e],t,s)(n,a):Zn({mark:e},s,t)(n,a)}return l&&r(s),l},oo=e=>(t,n)=>{n(t.tr.insertText(e.text,e.from,e.to))},ro=e=>(t,n)=>{const{image:o}=t.schema.nodes,r=o.createAndFill(e);en(r)(t,t=>n(t.setMeta("commandName","insertImage").setMeta("args",e)))},io=(e,t,n,o)=>{if(!n.isTextblock)return!1;const{ranges:r}=e.selection;r.forEach(r=>{const i=e.steps.length,l=r.$from.pos,a=r.$to.pos;e.doc.nodesBetween(l,a,(r,l)=>{if(r.eq(t)&&r.isTextblock&&!r.hasMarkup(n,o)&&((e,t,n)=>{const o=e.resolve(t),r=o.index();return o.parent.canReplaceWith(r,r+1,n)})(e.doc,e.mapping.slice(i).map(l),n)){e.clearIncompatible(e.mapping.slice(i).map(l,1),n);const t=e.mapping.slice(i),a=t.map(l,1),c=t.map(l+r.nodeSize,1),d=new p(s.from(n.create(o,null,r.marks)),0,0);return e.step(new Oe(a,c,a+1,c-1,d,1,!0)),!1}})})},so=(e,t={blocksInSelection:!1})=>{const{doc:n,selection:o}=e,{$from:r,ranges:i}=o,{blocksInSelection:s}=t,l=[],a=o instanceof dt?o.node:void 0;return a?a.isBlock?(l.push(a),a.nodesBetween(0,a.content.size,e=>{e.isBlock&&l.push(e)})):!s&&r.parent&&r.parent.isBlock&&l.push(r.parent):i.forEach(e=>{const t=e.$from.pos,o=e.$to.pos;n.nodesBetween(t,o,(e,n)=>{e.isBlock&&(!s||n>=t&&n+e.content.size+2<=o)&&l.push(e)})}),l},lo=(e,t)=>(n,o)=>{const r=so(n),i=n.schema.nodes,s=n.tr;s.setMeta("commandName",t),s.setMeta("args",{value:e}),r.forEach(t=>{if(t.type.isTextblock)if("p"===e)io(s,t,i.paragraph,t.attrs);else if(/^h[1-6]$/i.test(e)){const n=parseInt(e.substr(1),10);io(s,t,i.heading,{...t.attrs,level:n})}else"blockquote"===e&&io(s,t,i.blockquote,t.attrs)});const l=s.docChanged;return l&&o(s.scrollIntoView()),l},ao=(e,t={blocksInSelection:!0})=>{const{doc:n,selection:o}=e,{blocksInSelection:r,blockNodeType:i}=t;so({doc:n,selection:o},{blocksInSelection:r}).filter(e=>e.isTextblock).forEach(t=>{const{style:n="",class:o="",...r}=t.attrs||{},s=i||t.type;(n||o||s!==t.type)&&io(e,t,s,r)})},co=e=>{const t=so(e),n=e.schema.nodes,o=[];return t.forEach(e=>{e.type===n.paragraph?o.push("p"):e.type===n.heading?o.push(`h${e.attrs.level}`):e.type===n.blockquote&&n.blockquote.isTextblock&&o.push("blockquote")}),o},ho=(e,t)=>{let n,o,r=e.attrs.style;return r&&t.forEach(e=>{o={style:e.name,value:/^.+$/,newValue:e.value},n=Jt(r,o),r=n.changed?n.style:r}),r=r||t.reduce((e,t)=>(e&&t.value?e+" ":"")+t.value?`${t.name}: ${t.value};`:"",""),Object.assign({},e.attrs,{style:r||null})},po=(e,t)=>{const{from:n,to:o}=e.selection;let r=!1;return e.doc.nodesBetween(n,o,e=>(r=r||e.type===t,!r)),r},uo=e=>{const t=co(e);return 1===new Set(t).size?t[0]:null},fo=e=>({tag:uo(e)||""}),mo=(e,t)=>(n,o)=>{const r=so(n),i=n.tr;i.setMeta("commandName",t),r.forEach(t=>{if(t.type.isTextblock){const n=e.find(e=>e.node===t.type.name);if(n){const e=ho(t,n.style);io(i,t,t.type,e)}}});const s=i.docChanged;return s&&o(i.scrollIntoView()),s},go=(e,t)=>{const n=so(e);let o=!1;return n.forEach(e=>{if(!o&&e.type.isTextblock&&e.attrs.style){const n=t.find(t=>t.node===e.type.name);n&&(o=n.style.every(t=>!!t.value&&new RegExp(`${t.name}:\\s?${t.value}`,"i").test(e.attrs.style)))}}),o},yo=(e={blocksInSelection:!0})=>(t,n)=>{const o=t.tr,{blocksInSelection:r,blockNodeType:i,exceptMarks:s}=e,l=(s||[t.schema.marks.link]).filter(Boolean);Wn(o,{except:l}),ao(o,{blocksInSelection:r,blockNodeType:i});const a=o.docChanged;return a&&n&&n(o),a},wo=["ol",0],vo=["ul",0],bo=["li",0],ko={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs:e=>({order:e.hasAttribute("start")?+e.getAttribute("start"):1})}],toDOM:e=>1==e.attrs.order?wo:["ol",{start:e.attrs.order},0]},xo={parseDOM:[{tag:"ul"}],toDOM:()=>vo},So={parseDOM:[{tag:"li"}],toDOM:()=>bo,defining:!0};function Co(e,t){let n={};for(let t in e)n[t]=e[t];for(let e in t)n[e]=t[e];return n}function Mo(e,t,n){return e.append({ordered_list:Co(ko,{content:"list_item+",group:n}),bullet_list:Co(xo,{content:"list_item+",group:n}),list_item:Co(So,{content:t})})}function No(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i);if(!s)return!1;let l=o?n.tr:null;return!!Oo(l,s,e,t)&&(o&&o(l.scrollIntoView()),!0)}}function Oo(e,t,n,o=null){let r=!1,i=t,l=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=l.resolve(t.start-2);i=new A(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new A(t.$from,l.resolve(t.$to.end(t.depth)),t.depth)),r=!0}let a=Re(i,n,o,t);return!!a&&(e&&function(e,t,n,o,r){let i=s.empty;for(let e=n.length-1;e>=0;e--)i=s.from(n[e].type.create(n[e].attrs,i));e.step(new Oe(t.start-(o?2:0),t.end,t.start,t.end,new p(i,0,0),n.length,!0));let l=0;for(let e=0;e<n.length;e++)n[e].type==r&&(l=e+1);let a=n.length-l,c=t.start+n.length-(o?2:0),d=t.parent;for(let n=t.startIndex,o=t.endIndex,r=!0;n<o;n++,r=!1)!r&&Be(e.doc,c,a)&&(e.split(c,a),c+=2*a),c+=d.child(n).nodeSize}(e,t,a,r,n),!0)}function Ao(e,t){return function(n,o){let{$from:r,$to:i,node:l}=n.selection;if(l&&l.isBlock||r.depth<2||!r.sameParent(i))return!1;let a=r.node(-1);if(a.type!=e)return!1;if(0==r.parent.content.size&&r.node(-1).childCount==r.indexAfter(-1)){if(3==r.depth||r.node(-3).type!=e||r.index(-2)!=r.node(-2).childCount-1)return!1;if(o){let t=s.empty,i=r.index(-1)?1:r.index(-2)?2:3;for(let e=r.depth-i;e>=r.depth-3;e--)t=s.from(r.node(e).copy(t));let l=r.indexAfter(-1)<r.node(-2).childCount?1:r.indexAfter(-2)<r.node(-3).childCount?2:3;t=t.append(s.from(e.createAndFill()));let a=r.before(r.depth-(i-1)),c=n.tr.replace(a,r.after(-l),new p(t,4-i,0)),d=-1;c.doc.nodesBetween(a,c.doc.content.size,(e,t)=>{if(d>-1)return!1;e.isTextblock&&0==e.content.size&&(d=t+1)}),d>-1&&c.setSelection(rt.near(c.doc.resolve(d))),o(c.scrollIntoView())}return!0}let c=i.pos==r.end()?a.contentMatchAt(0).defaultType:null,d=n.tr.delete(r.pos,i.pos),h=c?[t?{type:e,attrs:t}:null,{type:c}]:void 0;return!!Be(d.doc,r.pos,2,h)&&(o&&o(d.split(r.pos,2,h).scrollIntoView()),!0)}}function To(e,t){let n=Ao(e,t);return(e,t)=>n(e,t&&(n=>{let o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();o&&n.ensureMarks(o),t(n)}))}function Do(e){return function(t,n){let{$from:o,$to:r}=t.selection,i=o.blockRange(r,t=>t.childCount>0&&t.firstChild.type==e);return!!i&&(!n||(o.node(i.depth-1).type==e?function(e,t,n,o){let r=e.tr,i=o.end,l=o.$to.end(o.depth);i<l&&(r.step(new Oe(i-1,l,i,l,new p(s.from(n.create(null,o.parent.copy())),1,0),1,!0)),o=new A(r.doc.resolve(o.$from.pos),r.doc.resolve(l),o.depth));const a=Ee(o);if(null==a)return!1;r.lift(o,a);let c=r.doc.resolve(r.mapping.map(i,-1)-1);return Pe(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),t(r.scrollIntoView()),!0}(t,n,e,i):function(e,t,n){let o=e.tr,r=n.parent;for(let e=n.end,t=n.endIndex-1,i=n.startIndex;t>i;t--)e-=r.child(t).nodeSize,o.delete(e-1,e+1);let i=o.doc.resolve(n.start),l=i.nodeAfter;if(o.mapping.map(n.end)!=n.start+i.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,c=n.endIndex==r.childCount,d=i.node(-1),h=i.index(-1);if(!d.canReplace(h+(a?0:1),h+1,l.content.append(c?s.empty:s.from(r))))return!1;let u=i.pos,f=u+l.nodeSize;return o.step(new Oe(u-(a?1:0),f+(c?1:0),u+1,f-1,new p((a?s.empty:s.from(r.copy(s.empty))).append(c?s.empty:s.from(r.copy(s.empty))),a?0:1,c?0:1),a?0:1)),t(o.scrollIntoView()),!0}(t,n,i)))}}function Eo(e){return function(t,n){let{$from:o,$to:r}=t.selection,i=o.blockRange(r,t=>t.childCount>0&&t.firstChild.type==e);if(!i)return!1;let l=i.startIndex;if(0==l)return!1;let a=i.parent,c=a.child(l-1);if(c.type!=e)return!1;if(n){let o=c.lastChild&&c.lastChild.type==a.type,r=s.from(o?e.create():null),l=new p(s.from(e.create(null,s.from(a.type.create(null,r)))),o?3:1,0),d=i.start,h=i.end;n(t.tr.step(new Oe(d-(o?3:1),h,d,h,l,1,!0)).scrollIntoView())}return!0}}const Ro={orderedList:"ordered_list",bulletList:"bullet_list",listItem:"list_item"},$o={listType:Ro.orderedList,types:{...Ro}},Io={listType:Ro.bulletList,types:{...Ro}},zo={nodes:[{node:"paragraph",style:"margin-left",rtlStyle:"margin-right",step:30,unit:"px"},{node:"heading",style:"margin-left",rtlStyle:"margin-right",step:30,unit:"px"}],listsTypes:{...Ro}},Bo={nodes:[{node:"paragraph",style:"margin-left",rtlStyle:"margin-right",step:-30,unit:"px"},{node:"heading",style:"margin-left",rtlStyle:"margin-right",step:-30,unit:"px"}],listsTypes:{...Ro}},Po=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Vo(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("backward",e):n.parentOffset>0)?null:n}const Fo=(e,t,n)=>{let o=Vo(e,n);if(!o)return!1;let r=jo(o);if(!r){let n=o.blockRange(),r=n&&Ee(n);return null!=r&&(t&&t(e.tr.lift(n,r).scrollIntoView()),!0)}let i=r.nodeBefore;if(cr(e,r,t,-1))return!0;if(0==o.parent.content.size&&(Wo(i,"end")||dt.isSelectable(i)))for(let n=o.depth;;n--){let s=_e(e.doc,o.before(n),o.after(n),p.empty);if(s&&s.slice.size<s.to-s.from){if(t){let n=e.tr.step(s);n.setSelection(Wo(i,"end")?rt.findFrom(n.doc.resolve(n.mapping.map(r.pos,-1)),-1):dt.create(n.doc,r.pos-i.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||o.node(n-1).childCount>1)break}return!(!i.isAtom||r.depth!=o.depth-1||(t&&t(e.tr.delete(r.pos-i.nodeSize,r.pos).scrollIntoView()),0))},Lo=(e,t,n)=>{let o=Vo(e,n);if(!o)return!1;let r=jo(o);return!!r&&_o(e,r,t)},Ho=(e,t,n)=>{let o=Jo(e,n);if(!o)return!1;let r=Uo(o);return!!r&&_o(e,r,t)};function _o(e,t,n){let o=t.nodeBefore,r=t.pos-1;for(;!o.isTextblock;r--){if(o.type.spec.isolating)return!1;let e=o.lastChild;if(!e)return!1;o=e}let i=t.nodeAfter,s=t.pos+1;for(;!i.isTextblock;s++){if(i.type.spec.isolating)return!1;let e=i.firstChild;if(!e)return!1;i=e}let l=_e(e.doc,r,s,p.empty);if(!l||l.from!=r||l instanceof Ne&&l.slice.size>=s-r)return!1;if(n){let t=e.tr.step(l);t.setSelection(at.create(t.doc,r)),n(t.scrollIntoView())}return!0}function Wo(e,t,n=!1){for(let o=e;o;o="start"==t?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(n&&1!=o.childCount)return!1}return!1}const qo=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):o.parentOffset>0)return!1;i=jo(o)}let s=i&&i.nodeBefore;return!(!s||!dt.isSelectable(s)||(t&&t(e.tr.setSelection(dt.create(e.doc,i.pos-s.nodeSize)).scrollIntoView()),0))};function jo(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 Jo(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock("forward",e):n.parentOffset<n.parent.content.size)?null:n}const Ko=(e,t,n)=>{let o=Jo(e,n);if(!o)return!1;let r=Uo(o);if(!r)return!1;let i=r.nodeAfter;if(cr(e,r,t,1))return!0;if(0==o.parent.content.size&&(Wo(i,"start")||dt.isSelectable(i))){let n=_e(e.doc,o.before(),o.after(),p.empty);if(n&&n.slice.size<n.to-n.from){if(t){let o=e.tr.step(n);o.setSelection(Wo(i,"start")?rt.findFrom(o.doc.resolve(o.mapping.map(r.pos)),1):dt.create(o.doc,o.mapping.map(r.pos))),t(o.scrollIntoView())}return!0}}return!(!i.isAtom||r.depth!=o.depth-1||(t&&t(e.tr.delete(r.pos,r.pos+i.nodeSize).scrollIntoView()),0))},Xo=(e,t,n)=>{let{$head:o,empty:r}=e.selection,i=o;if(!r)return!1;if(o.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):o.parentOffset<o.parent.content.size)return!1;i=Uo(o)}let s=i&&i.nodeAfter;return!(!s||!dt.isSelectable(s)||(t&&t(e.tr.setSelection(dt.create(e.doc,i.pos)).scrollIntoView()),0))};function Uo(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}const Go=(e,t)=>{let n,o=e.selection,r=o instanceof dt;if(r){if(o.node.isTextblock||!Pe(e.doc,o.from))return!1;n=o.from}else if(n=Fe(e.doc,o.from,-1),null==n)return!1;if(t){let o=e.tr.join(n);r&&o.setSelection(dt.create(o.doc,n-e.doc.resolve(n).nodeBefore.nodeSize)),t(o.scrollIntoView())}return!0},Yo=(e,t)=>{let n,o=e.selection;if(o instanceof dt){if(o.node.isTextblock||!Pe(e.doc,o.to))return!1;n=o.to}else if(n=Fe(e.doc,o.to,1),null==n)return!1;return t&&t(e.tr.join(n).scrollIntoView()),!0},Qo=(e,t)=>{let{$from:n,$to:o}=e.selection,r=n.blockRange(o),i=r&&Ee(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)},Zo=(e,t)=>{let{$head:n,$anchor:o}=e.selection;return!(!n.parent.type.spec.code||!n.sameParent(o)||(t&&t(e.tr.insertText("\n").scrollIntoView()),0))};function er(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}const tr=(e,t)=>{let{$head:n,$anchor:o}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(o))return!1;let r=n.node(-1),i=n.indexAfter(-1),s=er(r.contentMatchAt(i));if(!s||!r.canReplaceWith(i,i,s))return!1;if(t){let o=n.after(),r=e.tr.replaceWith(o,o,s.createAndFill());r.setSelection(rt.near(r.doc.resolve(o),1)),t(r.scrollIntoView())}return!0},nr=(e,t)=>{let n=e.selection,{$from:o,$to:r}=n;if(n instanceof pt||o.parent.inlineContent||r.parent.inlineContent)return!1;let i=er(r.parent.contentMatchAt(r.indexAfter()));if(!i||!i.isTextblock)return!1;if(t){let n=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,s=e.tr.insert(n,i.createAndFill());s.setSelection(at.create(s.doc,n+1)),t(s.scrollIntoView())}return!0},or=(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 o=n.before();if(Be(e.doc,o))return t&&t(e.tr.split(o).scrollIntoView()),!0}let o=n.blockRange(),r=o&&Ee(o);return null!=r&&(t&&t(e.tr.lift(o,r).scrollIntoView()),!0)};function rr(e){return(t,n)=>{let{$from:o,$to:r}=t.selection;if(t.selection instanceof dt&&t.selection.node.isBlock)return!(!o.parentOffset||!Be(t.doc,o.pos)||(n&&n(t.tr.split(o.pos).scrollIntoView()),0));if(!o.depth)return!1;let i,s,l=[],a=!1,c=!1;for(let t=o.depth;;t--){if(o.node(t).isBlock){a=o.end(t)==o.pos+(o.depth-t),c=o.start(t)==o.pos-(o.depth-t),s=er(o.node(t-1).contentMatchAt(o.indexAfter(t-1)));let n=e&&e(r.parent,a,o);l.unshift(n||(a&&s?{type:s}:null)),i=t;break}if(1==t)return!1;l.unshift(null)}let d=t.tr;(t.selection instanceof at||t.selection instanceof pt)&&d.deleteSelection();let h=d.mapping.map(o.pos),p=Be(d.doc,h,l.length,l);if(p||(l[0]=s?{type:s}:null,p=Be(d.doc,h,l.length,l)),!p)return!1;if(d.split(h,l.length,l),!a&&c&&o.node(i).type!=s){let e=d.mapping.map(o.before(i)),t=d.doc.resolve(e);s&&o.node(i-1).canReplaceWith(t.index(),t.index()+1,s)&&d.setNodeMarkup(d.mapping.map(o.before(i)),s)}return n&&n(d.scrollIntoView()),!0}}const ir=rr(),sr=(e,t)=>ir(e,t&&(n=>{let o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();o&&n.ensureMarks(o),t(n)})),lr=(e,t)=>{let n,{$from:o,to:r}=e.selection,i=o.sharedDepth(r);return 0!=i&&(n=o.before(i),t&&t(e.tr.setSelection(dt.create(e.doc,n))),!0)},ar=(e,t)=>(t&&t(e.tr.setSelection(new pt(e.doc))),!0);function cr(e,t,n,o){let r,i,l=t.nodeBefore,a=t.nodeAfter,c=l.type.spec.isolating||a.type.spec.isolating;if(!c&&function(e,t,n){let o=t.nodeBefore,r=t.nodeAfter,i=t.index();return!(!(o&&r&&o.type.compatibleContent(r.type))||(!o.content.size&&t.parent.canReplace(i-1,i)?(n&&n(e.tr.delete(t.pos-o.nodeSize,t.pos).scrollIntoView()),0):!t.parent.canReplace(i,i+1)||!r.isTextblock&&!Pe(e.doc,t.pos)||(n&&n(e.tr.join(t.pos).scrollIntoView()),0)))}(e,t,n))return!0;let d=!c&&t.parent.canReplace(t.index(),t.index()+1);if(d&&(r=(i=l.contentMatchAt(l.childCount)).findWrapping(a.type))&&i.matchType(r[0]||a.type).validEnd){if(n){let o=t.pos+a.nodeSize,i=s.empty;for(let e=r.length-1;e>=0;e--)i=s.from(r[e].create(null,i));i=s.from(l.copy(i));let c=e.tr.step(new Oe(t.pos-1,o,t.pos,o,new p(i,1,0),r.length,!0)),d=c.doc.resolve(o+2*r.length);d.nodeAfter&&d.nodeAfter.type==l.type&&Pe(c.doc,d.pos)&&c.join(d.pos),n(c.scrollIntoView())}return!0}let h=a.type.spec.isolating||o>0&&c?null:rt.findFrom(t,1),u=h&&h.$from.blockRange(h.$to),f=u&&Ee(u);if(null!=f&&f>=t.depth)return n&&n(e.tr.lift(u,f).scrollIntoView()),!0;if(d&&Wo(a,"start",!0)&&Wo(l,"end")){let o=l,r=[];for(;r.push(o),!o.isTextblock;)o=o.lastChild;let i=a,c=1;for(;!i.isTextblock;i=i.firstChild)c++;if(o.canReplace(o.childCount,o.childCount,i.content)){if(n){let o=s.empty;for(let e=r.length-1;e>=0;e--)o=s.from(r[e].copy(o));n(e.tr.step(new Oe(t.pos-r.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new p(o,r.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function dr(e){return function(t,n){let o=t.selection,r=e<0?o.$from:o.$to,i=r.depth;for(;r.node(i).isInline;){if(!i)return!1;i--}return!!r.node(i).isTextblock&&(n&&n(t.tr.setSelection(at.create(t.doc,e<0?r.start(i):r.end(i)))),!0)}}const hr=dr(-1),pr=dr(1);function ur(e,t=null){return function(n,o){let{$from:r,$to:i}=n.selection,s=r.blockRange(i),l=s&&Re(s,e,t);return!!l&&(o&&o(n.tr.wrap(s,l).scrollIntoView()),!0)}}function fr(e,t=null){return function(n,o){let r=!1;for(let o=0;o<n.selection.ranges.length&&!r;o++){let{$from:{pos:i},$to:{pos:s}}=n.selection.ranges[o];n.doc.nodesBetween(i,s,(o,i)=>{if(r)return!1;if(o.isTextblock&&!o.hasMarkup(e,t))if(o.type==e)r=!0;else{let t=n.doc.resolve(i),o=t.index();r=t.parent.canReplaceWith(o,o+1,e)}})}if(!r)return!1;if(o){let r=n.tr;for(let o=0;o<n.selection.ranges.length;o++){let{$from:{pos:i},$to:{pos:s}}=n.selection.ranges[o];r.setBlockType(i,s,e,t)}o(r.scrollIntoView())}return!0}}function mr(e,t=null,n){let o=!1!==(n&&n.removeWhenPresent),r=!1!==(n&&n.enterInlineAtoms),i=!(n&&n.includeWhitespace);return function(n,s){let{empty:l,$cursor:a,ranges:c}=n.selection;if(l&&!a||!function(e,t,n,o){for(let r=0;r<t.length;r++){let{$from:i,$to:s}=t[r],l=0==i.depth&&e.inlineContent&&e.type.allowsMarkType(n);if(e.nodesBetween(i.pos,s.pos,(e,t)=>{if(l||!o&&e.isAtom&&e.isInline&&t>=i.pos&&t+e.nodeSize<=s.pos)return!1;l=e.inlineContent&&e.type.allowsMarkType(n)}),l)return!0}return!1}(n.doc,c,e,r))return!1;if(s)if(a)e.isInSet(n.storedMarks||a.marks())?s(n.tr.removeStoredMark(e)):s(n.tr.addStoredMark(e.create(t)));else{let l,a=n.tr;r||(c=function(e){let t=[];for(let n=0;n<e.length;n++){let{$from:o,$to:r}=e[n];o.doc.nodesBetween(o.pos,r.pos,(e,n)=>{if(e.isAtom&&e.content.size&&e.isInline&&n>=o.pos&&n+e.nodeSize<=r.pos)return n+1>o.pos&&t.push(new it(o,o.doc.resolve(n+1))),o=o.doc.resolve(n+1+e.content.size),!1}),o.pos<r.pos&&t.push(new it(o,r))}return t}(c)),l=o?!c.some(t=>n.doc.rangeHasMark(t.$from.pos,t.$to.pos,e)):!c.every(t=>{let n=!1;return a.doc.nodesBetween(t.$from.pos,t.$to.pos,(o,r,i)=>{if(n)return!1;n=!e.isInSet(o.marks)&&!!i&&i.type.allowsMarkType(e)&&!(o.isText&&/^\s*$/.test(o.textBetween(Math.max(0,t.$from.pos-r),Math.min(o.nodeSize,t.$to.pos-r))))}),!n});for(let n=0;n<c.length;n++){let{$from:o,$to:r}=c[n];if(l){let n=o.pos,s=r.pos,l=o.nodeAfter,c=r.nodeBefore,d=i&&l&&l.isText?/^\s*/.exec(l.text)[0].length:0,h=i&&c&&c.isText?/\s*$/.exec(c.text)[0].length:0;n+d<s&&(n+=d,s-=h),a.addMark(n,s,e.create(t))}else a.removeMark(o.pos,r.pos,e)}s(a.scrollIntoView())}return!0}}function gr(e,t){return n=>{if(!n.isGeneric)return e(n);let o=[];for(let e=0;e<n.mapping.maps.length;e++){let t=n.mapping.maps[e];for(let e=0;e<o.length;e++)o[e]=t.map(o[e]);t.forEach((e,t,n,r)=>o.push(n,r))}let r=[];for(let e=0;e<o.length;e+=2){let i=o[e],s=o[e+1],l=n.doc.resolve(i),a=l.sharedDepth(s),c=l.node(a);for(let e=l.indexAfter(a),n=l.after(a+1);n<=s;++e){let o=c.maybeChild(e);if(!o)break;if(e&&-1==r.indexOf(n)){let i=c.child(e-1);i.type==o.type&&t(i,o)&&r.push(n)}n+=o.nodeSize}}r.sort((e,t)=>e-t);for(let e=r.length-1;e>=0;e--)Pe(n.doc,r[e])&&n.join(r[e]);e(n)}}function yr(e,t){let n=Array.isArray(t)?e=>t.indexOf(e.type.name)>-1:t;return(t,o,r)=>e(t,o&&gr(o,n),r)}function wr(...e){return function(t,n,o){for(let r=0;r<e.length;r++)if(e[r](t,n,o))return!0;return!1}}let vr=wr(Po,Fo,qo),br=wr(Po,Ko,Xo);const kr={Enter:wr(Zo,nr,or,ir),"Mod-Enter":tr,Backspace:vr,"Mod-Backspace":vr,"Shift-Backspace":vr,Delete:br,"Mod-Delete":br,"Mod-a":ar},xr={"Ctrl-h":kr.Backspace,"Alt-Backspace":kr["Mod-Backspace"],"Ctrl-d":kr.Delete,"Ctrl-Alt-Backspace":kr["Mod-Delete"],"Alt-Delete":kr["Mod-Delete"],"Alt-d":kr["Mod-Delete"],"Ctrl-a":hr,"Ctrl-e":pr};for(let e in kr)xr[e]=kr[e];const Sr=("undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&"darwin"==os.platform())?xr:kr,Cr=(e,t)=>ur(e.schema.nodes.blockquote)(e,t),Mr=(e,t)=>{const{$from:n,$to:o}=e.selection,r=e.schema.nodes.blockquote,i=e.doc;let s=-1;const l=n.blockRange(o);l&&i.nodesBetween(l.start,l.end,(e,t)=>{e.type===r&&(s=t)});const a=-1!==s;return t&&a&&t(e.tr.lift(l,i.resolve(s).depth)),a},Nr=(e,t,n)=>(o,r)=>{const i=so(o),s=o.tr;s.setMeta("commandName",t),i.forEach(t=>{if(t.type.isTextblock){let o;const r=e.find(e=>e.node===t.type.name);if(r){const e="rtl"===n?r.rtlStyle:r.style,i={name:e,value:r.step>0?`${r.step}${r.unit}`:""};if(t.attrs.style){const n=new RegExp(`${e}:\\s?(\\d+)${r.unit}`,"i"),o=t.attrs.style.match(n);if(o){let e=parseFloat(o[1])+r.step;e=e<=0?"":e,i.value=`${e}${e?r.unit:""}`}}o=ho(t,[i])}o&&io(s,t,t.type,o)}});const l=s.docChanged;return l&&r(s.scrollIntoView()),l},Or=(e,t,n)=>{const o=so(e);let r=!1;return o.forEach(e=>{if(!r&&e.type.isTextblock&&e.attrs.style){const o=t.find(t=>t.node===e.type.name);if(o){const t="rtl"===n?o.rtlStyle:o.style,i=new RegExp(`${t}:\\s?\\d+${o.unit}`,"i");r=i.test(e.attrs.style)}}}),r},Ar=(e,t)=>Eo(t)(e),Tr=(e,t)=>{const n=e.schema.nodes[t.listsTypes.listItem],o=e.schema.nodes[t.listsTypes.orderedList],r=e.schema.nodes[t.listsTypes.bulletList],i=!!Yt(o,2)(e.selection),s=!!Yt(r,2)(e.selection);return(i||s)&&Do(n)(e)},Dr=(e,t)=>{const n=e.schema.nodes,o=n[zo.listsTypes.listItem];return(Or(e,t.nodes)||zo.nodes.some(t=>n[t.node]&&po(e,n[t.node])))&&!po(e,o)},Er=(e,t)=>{const n=e.schema.nodes[zo.listsTypes.listItem],o=Dr(e,zo);Ar(e,n)?Eo(n)(e,t):o&&Nr(zo.nodes)(e,t)},Rr=(e,t)=>{const n=e.schema.nodes,o=n[Bo.listsTypes.listItem],r=Dr(e,Bo);po(e,n.blockquote)?Mr(e,t):Tr(e,Bo)?Do(o)(e,t):r&&Nr(Bo.nodes)(e,t)},$r=(e,t,n)=>{let o=t.depth;const r=e.nodes[n.bulletList],i=e.nodes[n.orderedList],s=e.nodes[n.listItem];for(let e=t.depth;e>0;e--){const n=t.node(e);if(n.type!==r&&n.type!==i||(o=e),n.type!==r&&n.type!==i&&n.type!==s)break}return o-1};function Ir(e,t,n,o){const r=o||e.schema.nodes.listItem,{$from:i,$to:l}=t;let a=i.blockRange(l,e=>e.childCount&&e.firstChild.type===r);if(!a||a.depth<2||i.node(a.depth-1).type!==r)return n;const c=a.end,d=l.end(a.depth);return c<d&&(n.step(new Oe(c-1,d,c,d,new p(s.from(r.create(void 0,a.parent.copy())),1,0),1,!0)),a=new A(n.doc.resolve(i.pos),n.doc.resolve(d),a.depth)),n.lift(a,Ee(a)).scrollIntoView()}function zr(e){return function(t,n){const{tr:o}=t,{$from:r,$to:i}=t.selection;return o.doc.nodesBetween(r.pos,i.pos,(n,r)=>{if(n.isTextblock||"blockquote"===n.type.name||"div"===n.type.name){const n=new dt(o.doc.resolve(o.mapping.map(r))),i=n.$from.blockRange(n.$to);if(!i||n.$from.parent.type!==t.schema.nodes[e.listItem])return;const s=i&&Ee(i);if(null==s)return!1;o.lift(i,s)}}),n&&n(o),!0}}const Br=/list-style-type:\s?([\w-]+)/,Pr=e=>{const t=e.style||"",n=Br.exec(t);return n&&n[1]||""},Vr=(e,t,n,o,r)=>{const{listType:i,listAttrs:s={style:null}}=o,{selection:l}=e,a=l.$from.node(l.$from.depth-2),c=l.$to.node(l.$to.depth-2);if(a&&a.type.name===i&&Pr(a.attrs)===Pr(s)&&c&&c.type.name===i&&Pr(c.attrs)===Pr(s)){const i=n.state.schema.nodes,s={bulletList:i[o.bulletList],orderedList:i[o.orderedList],listItem:i[o.listItem]},a=((e,t)=>{const{bulletList:n,orderedList:o,listItem:r}=t;let i;for(let t=e.depth-1;t>0;t--){const s=e.node(t);if(s.type!==n&&s.type!==o||(i=t),s.type!==n&&s.type!==o&&s.type!==r)break}return i})(l.$to,s);let c=function(e,t,n,o,r,i){i||(i=e.schema.nodes.listItem);let s=!1;return r.doc.nodesBetween(t,n,(n,l)=>{if(!s&&n.type===i&&l>t){s=!0;let t=o+3;for(;t>o+2;){const o=r.doc.resolve(r.mapping.map(l));t=o.depth;const s=r.doc.resolve(r.mapping.map(l+n.textContent.length)),a=new at(o,s);r=Ir(e,a,r,i)}}}),r}(e,l.$to.pos,l.$to.end(a),a,n.state.tr,s.listItem);return c=function(e,t,n){const{from:o,to:r}=e.selection,{paragraph:i,heading:s}=e.schema.nodes,l=[];t.doc.nodesBetween(o,r,(e,t)=>{e.type!==i&&e.type!==s||l.push({node:e,pos:t})});for(let o=l.length-1;o>=0;o--){const r=l[o],i=t.doc.resolve(t.mapping.map(r.pos));if(i.depth>0){let o;o=r.node.textContent&&r.node.textContent.length>0?t.doc.resolve(t.mapping.map(r.pos+r.node.textContent.length)):t.doc.resolve(t.mapping.map(r.pos+1));const s=i.blockRange(o);s&&t.lift(s,$r(e.schema,i,n))}}return t}(e,c,o),c.setMeta("commandName",r),t(c),!0}return function(e){return function(t,n,o){if(!o)return!1;const r=(t=o.state).schema.nodes[e.listType],{$from:i,$to:s}=t.selection,l=i.node(-2),a=i.node(-3),c=function(e,t,n,o){return 0===function(e,t,n){const o=[],r=function(e,t){const n=["blockquote","bulletList","orderedList"];if(1===t.depth)return t;let o=t.node(t.depth),r=t;for(;t.depth>=1;)o=(t=e.resolve(t.before(t.depth))).node(t.depth),o&&-1!==n.indexOf(o.type.name)&&(r=t);return r}(e,t).depth;let i=e.resolve(t.start(r));for(;i.pos<=n.start(n.depth);){const t=Math.min(i.depth,r),n=i.node(t);if(n&&o.push(n),0===t)break;let s=e.resolve(i.after(t));if(s.start(t)>=e.nodeSize-2)break;s.depth!==i.depth&&(s=e.resolve(s.pos+2)),i=s.depth?e.resolve(s.start(s.depth)):e.resolve(s.end(s.depth))}return o}(e,t,n).filter(e=>e.type!==o).length}(t.doc,i,s,r);return(l&&l.type===r||a&&a.type===r)&&c?zr(e)(t,n):(c||(zr(e)(t,n),t=o.state),function(e,t={}){return yr(No(e,t),(t,n)=>t.type===n.type&&t.type===e)}(r,e.listAttrs)(t,n))}}(o)(e,t,n)};function Fr(e,t,n){return Vr(e,t,n,{listType:Io.listType,...Io.types})}function Lr(e,t,n){return Vr(e,t,n,{listType:$o.listType,...$o.types})}const Hr=(e,t)=>({name:e,value:t}),_r=[{node:"paragraph",style:[Hr("text-align","left")]},{node:"heading",style:[Hr("text-align","left")]},{node:"table_caption_external",style:[Hr("text-align","left")]}],Wr=[{node:"paragraph",style:[Hr("text-align","right")]},{node:"heading",style:[Hr("text-align","right")]},{node:"table_caption_external",style:[Hr("text-align","right")]}],qr=[{node:"paragraph",style:[Hr("text-align","center")]},{node:"heading",style:[Hr("text-align","center")]},{node:"table_caption_external",style:[Hr("text-align","center")]}],jr=[{node:"paragraph",style:[Hr("text-align","justify")]},{node:"heading",style:[Hr("text-align","justify")]},{node:"table_caption_external",style:[Hr("text-align","justify")]}],Jr=[{node:"paragraph",style:[Hr("text-align","")]},{node:"heading",style:[Hr("text-align","")]},{node:"table_caption_external",style:[Hr("text-align","")]}],Kr=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},Xr=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t};let Ur=null;const Gr=function(e,t,n){let o=Ur||(Ur=document.createRange());return o.setEnd(e,null==n?e.nodeValue.length:n),o.setStart(e,t||0),o},Yr=function(e,t,n,o){return n&&(Zr(e,t,n,o,-1)||Zr(e,t,n,o,1))},Qr=/^(img|br|input|textarea|hr)$/i;function Zr(e,t,n,o,r){for(var i;;){if(e==n&&t==o)return!0;if(t==(r<0?0:ei(e))){let n=e.parentNode;if(!n||1!=n.nodeType||ti(e)||Qr.test(e.nodeName)||"false"==e.contentEditable)return!1;t=Kr(e)+(r<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(r<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(i=n.pmViewDesc)||void 0===i?void 0:i.ignoreForSelection))return!1;t+=r}else e=n,t=r<0?ei(e):0}}}}function ei(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function ti(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 ni=function(e){return e.focusNode&&Yr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oi(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const ri="undefined"!=typeof navigator?navigator:null,ii="undefined"!=typeof document?document:null,si=ri&&ri.userAgent||"",li=/Edge\/(\d+)/.exec(si),ai=/MSIE \d/.exec(si),ci=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(si),di=!!(ai||ci||li),hi=ai?document.documentMode:ci?+ci[1]:li?+li[1]:0,pi=!di&&/gecko\/(\d+)/i.test(si);pi&&(/Firefox\/(\d+)/.exec(si)||[0,0])[1];const ui=!di&&/Chrome\/(\d+)/.exec(si),fi=!!ui,mi=ui?+ui[1]:0,gi=!di&&!!ri&&/Apple Computer/.test(ri.vendor),yi=gi&&(/Mobile\/\w+/.test(si)||!!ri&&ri.maxTouchPoints>2),wi=yi||!!ri&&/Mac/.test(ri.platform),vi=!!ri&&/Win/.test(ri.platform),bi=/Android \d/.test(si),ki=!!ii&&"webkitFontSmoothing"in ii.documentElement.style,xi=ki?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Si(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function Ci(e,t){return"number"==typeof e?e:e[t]}function Mi(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,o=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*o}}function Ni(e,t,n){let o=e.someProp("scrollThreshold")||0,r=e.someProp("scrollMargin")||5,i=e.dom.ownerDocument;for(let s=n||e.dom;s;){if(1!=s.nodeType){s=Xr(s);continue}let e=s,n=e==i.body,l=n?Si(i):Mi(e),a=0,c=0;if(t.top<l.top+Ci(o,"top")?c=-(l.top-t.top+Ci(r,"top")):t.bottom>l.bottom-Ci(o,"bottom")&&(c=t.bottom-t.top>l.bottom-l.top?t.top+Ci(r,"top")-l.top:t.bottom-l.bottom+Ci(r,"bottom")),t.left<l.left+Ci(o,"left")?a=-(l.left-t.left+Ci(r,"left")):t.right>l.right-Ci(o,"right")&&(a=t.right-l.right+Ci(r,"right")),a||c)if(n)i.defaultView.scrollBy(a,c);else{let n=e.scrollLeft,o=e.scrollTop;c&&(e.scrollTop+=c),a&&(e.scrollLeft+=a);let r=e.scrollLeft-n,i=e.scrollTop-o;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}let d=n?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s="absolute"==d?s.offsetParent:Xr(s)}}function Oi(e){let t=[],n=e.ownerDocument;for(let o=e;o&&(t.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),e!=n);o=Xr(o));return t}function Ai(e,t){for(let n=0;n<e.length;n++){let{dom:o,top:r,left:i}=e[n];o.scrollTop!=r+t&&(o.scrollTop=r+t),o.scrollLeft!=i&&(o.scrollLeft=i)}}let Ti=null;function Di(e,t){let n,o,r,i,s=2e8,l=0,a=t.top,c=t.top;for(let d=e.firstChild,h=0;d;d=d.nextSibling,h++){let e;if(1==d.nodeType)e=d.getClientRects();else{if(3!=d.nodeType)continue;e=Gr(d).getClientRects()}for(let p=0;p<e.length;p++){let u=e[p];if(u.top<=a&&u.bottom>=c){a=Math.max(u.bottom,a),c=Math.min(u.top,c);let e=u.left>t.left?u.left-t.left:u.right<t.left?t.left-u.right:0;if(e<s){n=d,s=e,o=e&&3==n.nodeType?{left:u.right<t.left?u.right:u.left,top:t.top}:t,1==d.nodeType&&e&&(l=h+(t.left>=(u.left+u.right)/2?1:0));continue}}else u.top>t.top&&!r&&u.left<=t.left&&u.right>=t.left&&(r=d,i={left:Math.max(u.left,Math.min(u.right,t.left)),top:u.top});!n&&(t.left>=u.right&&t.top>=u.top||t.left>=u.left&&t.top>=u.bottom)&&(l=h+1)}}return!n&&r&&(n=r,o=i,s=0),n&&3==n.nodeType?function(e,t){let n,o=e.nodeValue.length,r=document.createRange();for(let i=0;i<o;i++){r.setEnd(e,i+1),r.setStart(e,i);let o=zi(r,1);if(o.top!=o.bottom&&Ei(t,o)){n={node:e,offset:i+(t.left>=(o.left+o.right)/2?1:0)};break}}return r.detach(),n||{node:e,offset:0}}(n,o):!n||s&&1==n.nodeType?{node:e,offset:l}:Di(n,o)}function Ei(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Ri(e,t,n){let o=e.childNodes.length;if(o&&n.top<n.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(t.top-n.top)/(n.bottom-n.top))-2)),i=r;;){let n=e.childNodes[i];if(1==n.nodeType){let e=n.getClientRects();for(let o=0;o<e.length;o++){let r=e[o];if(Ei(t,r))return Ri(n,t,r)}}if((i=(i+1)%o)==r)break}return e}function $i(e,t){let n,o=e.dom.ownerDocument,r=0,i=function(e,t,n){if(e.caretPositionFromPoint)try{let o=e.caretPositionFromPoint(t,n);if(o)return{node:o.offsetNode,offset:Math.min(ei(o.offsetNode),o.offset)}}catch(e){}if(e.caretRangeFromPoint){let o=e.caretRangeFromPoint(t,n);if(o)return{node:o.startContainer,offset:Math.min(ei(o.startContainer),o.startOffset)}}}(o,t.left,t.top);i&&({node:n,offset:r}=i);let s,l=(e.root.elementFromPoint?e.root:o).elementFromPoint(t.left,t.top);if(!l||!e.dom.contains(1!=l.nodeType?l.parentNode:l)){let n=e.dom.getBoundingClientRect();if(!Ei(t,n))return null;if(l=Ri(e.dom,t,n),!l)return null}if(gi)for(let e=l;n&&e;e=Xr(e))e.draggable&&(n=void 0);if(l=function(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}(l,t),n){if(pi&&1==n.nodeType&&(r=Math.min(r,n.childNodes.length),r<n.childNodes.length)){let e,o=n.childNodes[r];"IMG"==o.nodeName&&(e=o.getBoundingClientRect()).right<=t.left&&e.bottom>t.top&&r++}let o;ki&&r&&1==n.nodeType&&1==(o=n.childNodes[r-1]).nodeType&&"false"==o.contentEditable&&o.getBoundingClientRect().top>=t.top&&r--,n==e.dom&&r==n.childNodes.length-1&&1==n.lastChild.nodeType&&t.top>n.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:0!=r&&1==n.nodeType&&"BR"==n.childNodes[r-1].nodeName||(s=function(e,t,n,o){let r=-1;for(let n=t,i=!1;n!=e.dom;){let t,s=e.docView.nearestDesc(n,!0);if(!s)return null;if(1==s.dom.nodeType&&(s.node.isBlock&&s.parent||!s.contentDOM)&&((t=s.dom.getBoundingClientRect()).width||t.height)&&(s.node.isBlock&&s.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(s.dom.nodeName)&&(!i&&t.left>o.left||t.top>o.top?r=s.posBefore:(!i&&t.right<o.left||t.bottom<o.top)&&(r=s.posAfter),i=!0),!s.contentDOM&&r<0&&!s.node.isText))return(s.node.isBlock?o.top<(t.top+t.bottom)/2:o.left<(t.left+t.right)/2)?s.posBefore:s.posAfter;n=s.dom.parentNode}return r>-1?r:e.docView.posFromDOM(t,n,-1)}(e,n,r,t))}null==s&&(s=function(e,t,n){let{node:o,offset:r}=Di(t,n),i=-1;if(1==o.nodeType&&!o.firstChild){let e=o.getBoundingClientRect();i=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(o,r,i)}(e,l,t));let a=e.docView.nearestDesc(l,!0);return{pos:s,inside:a?a.posAtStart-a.border:-1}}function Ii(e){return e.top<e.bottom||e.left<e.right}function zi(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Ii(e))return e}return Array.prototype.find.call(n,Ii)||e.getBoundingClientRect()}const Bi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Pi(e,t,n){let{node:o,offset:r,atom:i}=e.docView.domFromPos(t,n<0?-1:1),s=ki||pi;if(3==o.nodeType){if(!s||!Bi.test(o.nodeValue)&&(n<0?r:r!=o.nodeValue.length)){let e=r,t=r,i=n<0?1:-1;return n<0&&!r?(t++,i=-1):n>=0&&r==o.nodeValue.length?(e--,i=1):n<0?e--:t++,Vi(zi(Gr(o,e,t),i),i<0)}{let e=zi(Gr(o,r,r),n);if(pi&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let t=zi(Gr(o,r-1,r-1),-1);if(t.top==e.top){let n=zi(Gr(o,r,r+1),-1);if(n.top!=e.top)return Vi(n,n.left<t.left)}}return e}}if(!e.state.doc.resolve(t-(i||0)).parent.inlineContent){if(null==i&&r&&(n<0||r==ei(o))){let e=o.childNodes[r-1];if(1==e.nodeType)return Fi(e.getBoundingClientRect(),!1)}if(null==i&&r<ei(o)){let e=o.childNodes[r];if(1==e.nodeType)return Fi(e.getBoundingClientRect(),!0)}return Fi(o.getBoundingClientRect(),n>=0)}if(null==i&&r&&(n<0||r==ei(o))){let e=o.childNodes[r-1],t=3==e.nodeType?Gr(e,ei(e)-(s?0:1)):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return Vi(zi(t,1),!1)}if(null==i&&r<ei(o)){let e=o.childNodes[r];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?Gr(e,0,s?0:1):1==e.nodeType?e:null:null;if(t)return Vi(zi(t,-1),!0)}return Vi(zi(3==o.nodeType?Gr(o):o,-n),n>=0)}function Vi(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 Fi(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 Li(e,t,n){let o=e.state,r=e.root.activeElement;o!=t&&e.updateState(t),r!=e.dom&&e.focus();try{return n()}finally{o!=t&&e.updateState(o),r!=e.dom&&r&&r.focus()}}const Hi=/[\u0590-\u08ac]/;let _i=null,Wi=null,qi=!1;class ji{constructor(e,t,n,o){this.parent=e,this.children=t,this.dom=n,this.contentDOM=o,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 o=this.children[t];if(o==e)return n;n+=o.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,o;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.previousSibling;return n?this.posBeforeChild(o)+o.size:this.posAtStart}{let n,o;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&(!(o=n.pmViewDesc)||o.parent!=this);)n=n.nextSibling;return n?this.posBeforeChild(o):this.posAtEnd}}let o;if(e==this.dom&&this.contentDOM)o=t>Kr(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))o=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!1;break}if(t.previousSibling)break}if(null==o&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){o=!0;break}if(t.nextSibling)break}}return(null==o?n>0:o)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,o=e;o;o=o.parentNode){let r,i=this.getDesc(o);if(i&&(!t||i.node)){if(!n||!(r=i.nodeDOM)||(1==r.nodeType?r.contains(1==e.nodeType?e:e.parentNode):r==e))return i;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 o=e;o;o=o.parentNode){let r=this.getDesc(o);if(r)return r.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let o=this.children[t],r=n+o.size;if(n==e&&r!=n){for(;!o.border&&o.children.length;)for(let e=0;e<o.children.length;e++){let t=o.children[e];if(t.size){o=t;break}}return o}if(e<r)return o.descAt(e-n-o.border);n=r}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,o=0;for(let t=0;n<this.children.length;n++){let r=this.children[n],i=t+r.size;if(i>e||r instanceof Qi){o=e-t;break}t=i}if(o)return this.children[n].domFromPos(o-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof Ji&&e.side>=0;n--);if(t<=0){let e,o=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,o=!1);return e&&t&&o&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Kr(e.dom)+1:0}}{let e,o=!0;for(;e=n<this.children.length?this.children[n]:null,e&&e.dom.parentNode!=this.contentDOM;n++,o=!1);return e&&o&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Kr(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 o=-1,r=-1;for(let i=n,s=0;;s++){let n=this.children[s],l=i+n.size;if(-1==o&&e<=l){let r=i+n.border;if(e>=r&&t<=l-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,r);e=i;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){o=Kr(n.dom)+1;break}e-=n.size}-1==o&&(o=0)}if(o>-1&&(l>t||s==this.children.length-1)){t=l;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)){r=Kr(n.dom);break}t+=n.size}-1==r&&(r=this.contentDOM.childNodes.length);break}i=l}return{node:this.contentDOM,from:e,to:t,fromOffset:o,toOffset:r}}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,o=!1){let r=Math.min(e,t),i=Math.max(e,t);for(let s=0,l=0;s<this.children.length;s++){let a=this.children[s],c=l+a.size;if(r>l&&i<c)return a.setSelection(e-l-a.border,t-l-a.border,n,o);l=c}let s=this.domFromPos(e,e?-1:1),l=t==e?s:this.domFromPos(t,t?-1:1),a=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((pi||gi)&&e==t){let{node:e,offset:t}=s;if(3==e.nodeType){if(d=!(!t||"\n"!=e.nodeValue[t-1]),d&&t==e.nodeValue.length)for(let t,n=e;n;n=n.parentNode){if(t=n.nextSibling){"BR"==t.nodeName&&(s=l={node:t.parentNode,offset:Kr(t)+1});break}let e=n.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(pi&&c.focusNode&&c.focusNode!=l.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(o=!0)}if(!(o||d&&gi)&&Yr(s.node,s.offset,c.anchorNode,c.anchorOffset)&&Yr(l.node,l.offset,c.focusNode,c.focusOffset))return;let h=!1;if((a.extend||e==t)&&(!d||!pi)){a.collapse(s.node,s.offset);try{e!=t&&a.extend(l.node,l.offset),h=!0}catch(e){}}if(!h){if(e>t){let e=s;s=l,l=e}let n=document.createRange();n.setEnd(l.node,l.offset),n.setStart(s.node,s.offset),a.removeAllRanges(),a.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,o=0;o<this.children.length;o++){let r=this.children[o],i=n+r.size;if(n==i?e<=i&&t>=n:e<i&&t>n){let o=n+r.border,s=i-r.border;if(e>=o&&t<=s)return this.dirty=e==n||t==i?2:1,void(e!=o||t!=s||!r.contentLost&&r.dom.parentNode==this.contentDOM?r.markDirty(e-o,t-o):r.dirty=3);r.dirty=r.dom!=r.contentDOM||r.dom.parentNode!=this.contentDOM||r.children.length?3:2}n=i}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}get ignoreForSelection(){return!1}isText(e){return!1}}class Ji extends ji{constructor(e,t,n,o){let r,i=t.type.toDOM;if("function"==typeof i&&(i=i(n,()=>r?r.parent?r.parent.posBeforeChild(r):void 0:o)),!t.type.spec.raw){if(1!=i.nodeType){let e=document.createElement("span");e.appendChild(i),i=e}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,r=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 ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class Ki extends ji{constructor(e,t,n,o){super(e,[],t,null),this.textDOM=n,this.text=o}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 Xi extends ji{constructor(e,t,n,o,r){super(e,[],n,o),this.mark=t,this.spec=r}static create(e,t,n,o){let r=o.nodeViews[t.type.name],i=r&&r(t,o,n);return i&&i.dom||(i=le.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new Xi(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}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 o=Xi.create(this.parent,this.mark,!0,n),r=this.children,i=this.size;t<i&&(r=ps(r,t,i,n)),e>0&&(r=ps(r,0,e,n));for(let e=0;e<r.length;e++)r[e].parent=o;return o.children=r,o}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Ui extends ji{constructor(e,t,n,o,r,i,s,l,a){super(e,[],r,i),this.node=t,this.outerDeco=n,this.innerDeco=o,this.nodeDOM=s}static create(e,t,n,o,r,i){let s,l=r.nodeViews[t.type.name],a=l&&l(t,r,()=>s?s.parent?s.parent.posBeforeChild(s):void 0:i,n,o),c=a&&a.dom,d=a&&a.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 if(!c){let e=le.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let h=c;return c=ls(c,n,t),a?s=new Zi(e,t,n,o,c,d||null,h,a,r,i+1):t.isText?new Yi(e,t,n,o,c,h,r):new Ui(e,t,n,o,c,d||null,h,r,i+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=()=>s.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)&&as(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,o=t,r=e.composing?this.localCompositionInfo(e,t):null,i=r&&r.pos>-1?r:null,s=r&&r.pos<0,l=new ds(this,i&&i.node,e);!function(e,t,n,o){let r=t.locals(e),i=0;if(0==r.length){for(let n=0;n<e.childCount;n++){let s=e.child(n);o(s,r,t.forChild(i,s),n),i+=s.nodeSize}return}let s=0,l=[],a=null;for(let c=0;;){let d,h,p,u;for(;s<r.length&&r[s].to==i;){let e=r[s++];e.widget&&(d?(h||(h=[d])).push(e):d=e)}if(d)if(h){h.sort(hs);for(let e=0;e<h.length;e++)n(h[e],c,!!a)}else n(d,c,!!a);if(a)u=-1,p=a,a=null;else{if(!(c<e.childCount))break;u=c,p=e.child(c++)}for(let e=0;e<l.length;e++)l[e].to<=i&&l.splice(e--,1);for(;s<r.length&&r[s].from<=i&&r[s].to>i;)l.push(r[s++]);let f=i+p.nodeSize;if(p.isText){let e=f;s<r.length&&r[s].from<e&&(e=r[s].from);for(let t=0;t<l.length;t++)l[t].to<e&&(e=l[t].to);e<f&&(a=p.cut(e-i),p=p.cut(0,e-i),f=e,u=-1)}else for(;s<r.length&&r[s].to<f;)s++;o(p,p.isInline&&!p.isLeaf?l.filter(e=>!e.inline):l.slice(),t.forChild(i,p),u),i=f}}(this.node,this.innerDeco,(t,r,i)=>{t.spec.marks?l.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!i&&l.syncToMarks(r==this.node.childCount?d.none:this.node.child(r).marks,n,e),l.placeWidget(t,e,o)},(t,i,a,c)=>{let d;l.syncToMarks(t.marks,n,e),l.findNodeMatch(t,i,a,c)||s&&e.state.selection.from>o&&e.state.selection.to<o+t.nodeSize&&(d=l.findIndexWithChild(r.node))>-1&&l.updateNodeAt(t,i,a,d,e)||l.updateNextNode(t,i,a,e,c,o)||l.addNode(t,i,a,e,o),o+=t.nodeSize}),l.syncToMarks([],n,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||2==this.dirty)&&(i&&this.protectLocalComposition(e,i),es(this.contentDOM,this.children,e),yi&&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:o}=e.state.selection;if(!(e.state.selection instanceof at)||n<t||o>t+this.node.content.size)return null;let r=e.input.compositionNode;if(!r||!this.dom.contains(r.parentNode))return null;if(this.node.inlineContent){let e=r.nodeValue,i=function(e,t,n,o){for(let r=0,i=0;r<e.childCount&&i<=o;){let s=e.child(r++),l=i;if(i+=s.nodeSize,!s.isText)continue;let a=s.text;for(;r<e.childCount;){let t=e.child(r++);if(i+=t.nodeSize,!t.isText)break;a+=t.text}if(i>=n){if(i>=o&&a.slice(o-t.length-l,o-l)==t)return o-t.length;let e=l<o?a.lastIndexOf(t,o-l-1):-1;if(e>=0&&e+t.length+l>=n)return l+e;if(n==o&&a.length>=o+t.length-l&&a.slice(o-l,o-l+t.length)==t)return o}}return-1}(this.node.content,e,n-t,o-t);return i<0?null:{node:r,pos:i,text:e}}return{node:r,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:n,text:o}){if(this.getDesc(t))return;let r=t;for(;r.parentNode!=this.contentDOM;r=r.parentNode){for(;r.previousSibling;)r.parentNode.removeChild(r.previousSibling);for(;r.nextSibling;)r.parentNode.removeChild(r.nextSibling);r.pmViewDesc&&(r.pmViewDesc=void 0)}let i=new Ki(this,r,t,o);e.input.compositionNodes.push(i),this.children=ps(this.children,n,n+o.length,e,i)}update(e,t,n,o){return!(3==this.dirty||!e.sameMarkup(this.node)||(this.updateInner(e,t,n,o),0))}updateInner(e,t,n,o){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(o,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(as(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=is(this.dom,this.nodeDOM,rs(this.outerDeco,this.node,t),rs(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.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),!this.contentDOM&&this.node.type.spec.draggable||this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Gi(e,t,n,o,r){ls(o,t,e);let i=new Ui(void 0,e,t,n,o,o,o,r,0);return i.contentDOM&&i.updateChildren(r,0),i}class Yi extends Ui{constructor(e,t,n,o,r,i,s){super(e,t,n,o,r,null,i,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,o){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,o.trackWrites==this.nodeDOM&&(o.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 o=this.node.cut(e,t),r=document.createTextNode(o.text);return new Yi(this.parent,o,this.outerDeco,this.innerDeco,r,r,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}isText(e){return this.node.text==e}}class Qi extends ji{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 Zi extends Ui{constructor(e,t,n,o,r,i,s,l,a,c){super(e,t,n,o,r,i,s,a,c),this.spec=l}update(e,t,n,o){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let r=this.spec.update(e,t,n);return r&&this.updateInner(e,t,n,o),r}return!(!this.contentDOM&&!e.isLeaf)&&super.update(e,t,n,o)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,o){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,o)}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 es(e,t,n){let o=e.firstChild,r=!1;for(let i=0;i<t.length;i++){let s=t[i],l=s.dom;if(l.parentNode==e){for(;l!=o;)o=cs(o),r=!0;o=o.nextSibling}else r=!0,e.insertBefore(l,o);if(s instanceof Xi){let t=o?o.previousSibling:e.lastChild;es(s.contentDOM,s.children,n),o=t?t.nextSibling:e.firstChild}}for(;o;)o=cs(o),r=!0;r&&n.trackWrites==e&&(n.trackWrites=null)}const ts=function(e){e&&(this.nodeName=e)};ts.prototype=Object.create(null);const ns=[new ts];function rs(e,t,n){if(0==e.length)return ns;let o=n?ns[0]:new ts,r=[o];for(let i=0;i<e.length;i++){let s=e[i].type.attrs;if(s){s.nodeName&&r.push(o=new ts(s.nodeName));for(let e in s){let i=s[e];null!=i&&(n&&1==r.length&&r.push(o=new ts(t.isInline?"span":"div")),"class"==e?o.class=(o.class?o.class+" ":"")+i:"style"==e?o.style=(o.style?o.style+";":"")+i:"nodeName"!=e&&(o[e]=i))}}}return r}function is(e,t,n,o){if(n==ns&&o==ns)return t;let r=t;for(let t=0;t<o.length;t++){let i=o[t],s=n[t];if(t){let t;s&&s.nodeName==i.nodeName&&r!=e&&(t=r.parentNode)&&t.nodeName.toLowerCase()==i.nodeName||(t=document.createElement(i.nodeName),t.pmIsDeco=!0,t.appendChild(r),s=ns[0]),r=t}ss(r,s||ns[0],i)}return r}function ss(e,t,n){for(let o in t)"class"==o||"style"==o||"nodeName"==o||o in n||e.removeAttribute(o);for(let o in n)"class"!=o&&"style"!=o&&"nodeName"!=o&&n[o]!=t[o]&&e.setAttribute(o,n[o]);if(t.class!=n.class){let o=t.class?t.class.split(" ").filter(Boolean):[],r=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<o.length;t++)-1==r.indexOf(o[t])&&e.classList.remove(o[t]);for(let t=0;t<r.length;t++)-1==o.indexOf(r[t])&&e.classList.add(r[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n,o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g;for(;n=o.exec(t.style);)e.style.removeProperty(n[1])}n.style&&(e.style.cssText+=n.style)}}function ls(e,t,n){return is(e,e,ns,rs(t,n,1!=e.nodeType))}function as(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 cs(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class ds{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,o=n.children.length,r=e.childCount,i=new Map,s=[];e:for(;r>0;){let l;for(;;)if(o){let e=n.children[o-1];if(!(e instanceof Xi)){l=e,o--;break}n=e,o=e.children.length}else{if(n==t)break e;o=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=e.child(r-1))break;--r,i.set(l,r),s.push(l)}}return{index:r,matched:i,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 o=0,r=this.stack.length>>1,i=Math.min(r,e.length);for(;o<i&&(o==r-1?this.top:this.stack[o+1<<1]).matchesMark(e[o])&&!1!==e[o].type.spec.spanning;)o++;for(;o<r;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),r--;for(;r<e.length;){this.stack.push(this.top,this.index+1);let o=-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[r])&&!this.isLocked(n.dom)){o=t;break}}if(o>-1)o>this.index&&(this.changed=!0,this.destroyBetween(this.index,o)),this.top=this.top.children[this.index];else{let o=Xi.create(this.top,e[r],t,n);this.top.children.splice(this.index,0,o),this.top=o,this.changed=!0}this.index=0,r++}}findNodeMatch(e,t,n,o){let r,i=-1;if(o>=this.preMatch.index&&(r=this.preMatch.matches[o-this.preMatch.index]).parent==this.top&&r.matchesNode(e,t,n))i=this.top.children.indexOf(r,this.index);else for(let o=this.index,r=Math.min(this.top.children.length,o+5);o<r;o++){let r=this.top.children[o];if(r.matchesNode(e,t,n)&&!this.preMatch.matched.has(r)){i=o;break}}return!(i<0||(this.destroyBetween(this.index,i),this.index++,0))}updateNodeAt(e,t,n,o,r){let i=this.top.children[o];return 3==i.dirty&&i.dom==i.contentDOM&&(i.dirty=2),!!i.update(e,t,n,r)&&(this.destroyBetween(this.index,o),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,o,r,i){for(let s=this.index;s<this.top.children.length;s++){let l=this.top.children[s];if(l instanceof Ui){let a=this.preMatch.matched.get(l);if(null!=a&&a!=r)return!1;let c,d=l.dom,h=this.isLocked(d)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&3!=l.dirty&&as(t,l.outerDeco));if(!h&&l.update(e,t,n,o))return this.destroyBetween(this.index,s),l.dom!=d&&(this.changed=!0),this.index++,!0;if(!h&&(c=this.recreateWrapper(l,e,t,n,o,i)))return this.destroyBetween(this.index,s),this.top.children[this.index]=c,c.contentDOM&&(c.dirty=2,c.updateChildren(o,i+1),c.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,o,r,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!as(n,e.outerDeco)||!o.eq(e.innerDeco))return null;let s=Ui.create(this.top,t,n,o,r,i);if(s.contentDOM){s.children=e.children,e.children=[];for(let e of s.children)e.parent=s}return e.destroy(),s}addNode(e,t,n,o,r){let i=Ui.create(this.top,e,t,n,o,r);i.contentDOM&&i.updateChildren(o,r+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,n){let o=this.index<this.top.children.length?this.top.children[this.index]:null;if(!o||!o.matchesWidget(e)||e!=o.widget&&o.widget.type.toDOM.parentNode){let o=new Ji(this.top,e,t,n);this.top.children.splice(this.index++,0,o),this.changed=!0}else this.index++}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Xi;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Yi)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((gi||fi)&&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 o=new Qi(this.top,[],n,null);t!=this.top?t.children.push(o):t.children.splice(this.index++,0,o),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function hs(e,t){return e.type.side-t.type.side}function ps(e,t,n,o,r){let i=[];for(let s=0,l=0;s<e.length;s++){let a=e[s],c=l,d=l+=a.size;c>=n||d<=t?i.push(a):(c<t&&i.push(a.slice(0,t-c,o)),r&&(i.push(r),r=void 0),d>n&&i.push(a.slice(n-c,a.size,o)))}return i}function us(e,t=null){let n=e.domSelectionRange(),o=e.state.doc;if(!n.focusNode)return null;let r=e.docView.nearestDesc(n.focusNode),i=r&&0==r.size,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l,a,c=o.resolve(s);if(ni(n)){for(l=s;r&&!r.node;)r=r.parent;let e=r.node;if(r&&e.isAtom&&dt.isSelectable(e)&&r.parent&&(!e.isInline||!function(e,t,n){for(let o=0==t,r=t==ei(e);o||r;){if(e==n)return!0;let t=Kr(e);if(!(e=e.parentNode))return!1;o=o&&0==t,r=r&&t==ei(e)}}(n.focusNode,n.focusOffset,r.dom))){let e=r.posBefore;a=new dt(s==e?c:o.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=s,r=s;for(let o=0;o<n.rangeCount;o++){let i=n.getRangeAt(o);t=Math.min(t,e.docView.posFromDOM(i.startContainer,i.startOffset,1)),r=Math.max(r,e.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(t<0)return null;[l,s]=r==e.state.selection.anchor?[r,t]:[t,r],c=o.resolve(s)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=o.resolve(l);return a||(a=xs(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!i?1:-1)),a}function fs(e){return e.editable?e.hasFocus():Cs(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function ms(e,t=!1){let n=e.state.selection;if(bs(e,n),fs(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&fi){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&Yr(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();if(!t)return;let n=e.cursorWrapper.dom,o="IMG"==n.nodeName;o?t.collapse(n.parentNode,Kr(n)+1):t.collapse(n,0),!o&&!e.state.selection.visible&&di&&hi<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let o,r,{anchor:i,head:s}=n;!gs||n instanceof at||(n.$from.parent.inlineContent||(o=ys(e,n.from)),n.empty||n.$from.parent.inlineContent||(r=ys(e,n.to))),e.docView.setSelection(i,s,e,t),gs&&(o&&vs(o),r&&vs(r)),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(),o=n.anchorNode,r=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==o&&n.anchorOffset==r||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{fs(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const gs=gi||fi&&mi<63;function ys(e,t){let{node:n,offset:o}=e.docView.domFromPos(t,0),r=o<n.childNodes.length?n.childNodes[o]:null,i=o?n.childNodes[o-1]:null;if(gi&&r&&"false"==r.contentEditable)return ws(r);if(!(r&&"false"!=r.contentEditable||i&&"false"!=i.contentEditable)){if(r)return ws(r);if(i)return ws(i)}}function ws(e){return e.contentEditable="true",gi&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function vs(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function bs(e,t){if(t instanceof dt){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(ks(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else ks(e)}function ks(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function xs(e,t,n,o){return e.someProp("createSelectionBetween",o=>o(e,t,n))||at.between(t,n,o)}function Ss(e){return!(e.editable&&!e.hasFocus())&&Cs(e)}function Cs(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 Ms(e,t){let{$anchor:n,$head:o}=e.selection,r=t>0?n.max(o):n.min(o),i=r.parent.inlineContent?r.depth?e.doc.resolve(t>0?r.after():r.before()):null:r;return i&&rt.findFrom(i,t)}function Ns(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Os(e,t,n){let o=e.state.selection;if(!(o instanceof at)){if(o instanceof dt&&o.node.isInline)return Ns(e,new at(t>0?o.$to:o.$from));{let n=Ms(e.state,t);return!!n&&Ns(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=o,r=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+r.nodeSize*(t<0?-1:1));return Ns(e,new at(o.$anchor,i))}if(!o.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ms(e.state,t);return!!(n&&n instanceof dt)&&Ns(e,n)}if(!(wi&&n.indexOf("m")>-1)){let n,r=o.$head,i=r.textOffset?null:t<0?r.nodeBefore:r.nodeAfter;if(!i||i.isText)return!1;let s=t<0?r.pos-i.nodeSize:r.pos;return!!(i.isAtom||(n=e.docView.descAt(s))&&!n.contentDOM)&&(dt.isSelectable(i)?Ns(e,new dt(t<0?e.state.doc.resolve(r.pos-i.nodeSize):r)):!!ki&&Ns(e,new at(e.state.doc.resolve(t<0?s:s+i.nodeSize))))}}function As(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Ts(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function Ds(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=!1;for(pi&&1==n.nodeType&&o<As(n)&&Ts(n.childNodes[o],-1)&&(s=!0);;)if(o>0){if(1!=n.nodeType)break;{let e=n.childNodes[o-1];if(Ts(e,-1))r=n,i=--o;else{if(3!=e.nodeType)break;n=e,o=n.nodeValue.length}}}else{if(Es(n))break;{let t=n.previousSibling;for(;t&&Ts(t,-1);)r=n.parentNode,i=Kr(t),t=t.previousSibling;if(t)n=t,o=As(n);else{if(n=n.parentNode,n==e.dom)break;o=0}}}s?Rs(e,n,o):r&&Rs(e,r,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let r,i,s=As(n);for(;;)if(o<s){if(1!=n.nodeType)break;if(!Ts(n.childNodes[o],1))break;r=n,i=++o}else{if(Es(n))break;{let t=n.nextSibling;for(;t&&Ts(t,1);)r=t.parentNode,i=Kr(t)+1,t=t.nextSibling;if(t)n=t,o=0,s=As(n);else{if(n=n.parentNode,n==e.dom)break;o=s=0}}}r&&Rs(e,r,i)}(e)}function Es(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Rs(e,t,n){if(3!=t.nodeType){let e,o;(o=function(e,t){for(;e&&t==e.childNodes.length&&!ti(e);)t=Kr(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=o,n=0):(e=function(e,t){for(;e&&!t&&!ti(e);)t=Kr(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let o=e.domSelection();if(!o)return;if(ni(o)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),o.removeAllRanges(),o.addRange(e)}else o.extend&&o.extend(t,n);e.domObserver.setCurSelection();let{state:r}=e;setTimeout(()=>{e.state==r&&ms(e)},50)}function $s(e,t){let n=e.state.doc.resolve(t);if(!fi&&!vi&&n.parent.inlineContent){let o=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left<o.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),r=(n.top+n.bottom)/2;if(r>o.top&&r<o.bottom&&Math.abs(n.left-o.left)>1)return n.left>o.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Is(e,t,n){let o=e.state.selection;if(o instanceof at&&!o.empty||n.indexOf("s")>-1)return!1;if(wi&&n.indexOf("m")>-1)return!1;let{$from:r,$to:i}=o;if(!r.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ms(e.state,t);if(n&&n instanceof dt)return Ns(e,n)}if(!r.parent.inlineContent){let n=t<0?r:i,s=o instanceof pt?rt.near(n,t):rt.findFrom(n,t);return!!s&&Ns(e,s)}return!1}function zs(e,t){if(!(e.state.selection instanceof at))return!0;let{$head:n,$anchor:o,empty:r}=e.state.selection;if(!n.sameParent(o))return!0;if(!r)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let o=e.state.tr;return t<0?o.delete(n.pos-i.nodeSize,n.pos):o.delete(n.pos,n.pos+i.nodeSize),e.dispatch(o),!0}return!1}function Bs(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Ps(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:o,openStart:r,openEnd:i}=t;for(;r>1&&i>1&&1==o.childCount&&1==o.firstChild.childCount;){r--,i--;let e=o.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),o=e.content}let s=e.someProp("clipboardSerializer")||le.fromSchema(e.state.schema),l=Ks(),a=l.createElement("div");a.appendChild(s.serializeFragment(o,{document:l}));let c,d=a.firstChild,h=0;for(;d&&1==d.nodeType&&(c=js[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=l.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),h++}d=a.firstChild}return d&&1==d.nodeType&&d.setAttribute("data-pm-slice",`${r} ${i}${h?` -${h}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function Vs(e,t,n,o,r){let i,l,a=r.parent.type.spec.code;if(!n&&!t)return null;let c=!!t&&(o||a||!n);if(c){if(e.someProp("transformPastedText",n=>{t=n(t,a||o,e)}),a)return l=new p(s.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{l=t(l,e,!0)}),l;let n=e.someProp("clipboardTextParser",n=>n(t,r,o,e));if(n)l=n;else{let n=r.marks(),{schema:o}=e.state,s=le.fromSchema(o);i=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=i.appendChild(document.createElement("p"));e&&t.appendChild(s.serializeNode(o.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),i=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,o=Ks().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(e);if((n=r&&js[r[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join("")),o.innerHTML=function(e){let t=window.trustedTypes;return t?(Xs||(Xs=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),Xs.createHTML(e)):e}(e),n)for(let e=0;e<n.length;e++)o=o.querySelector(n[e])||o;return o}(n),ki&&function(e){let t=e.querySelectorAll(fi?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let o=t[n];1==o.childNodes.length&&" "==o.textContent&&o.parentNode&&o.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),o)}}(i);let d=i&&i.querySelector("[data-pm-slice]"),h=d&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(d.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let e=+h[3];e>0;e--){let e=i.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;i=e}if(!l){let t=e.someProp("clipboardParser")||e.someProp("domParser")||Y.fromSchema(e.state.schema);l=t.parseSlice(i,{preserveWhitespace:!(!c&&!h),context:r,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||Fs.test(e.parentNode.nodeName)?null:{ignore:!0}})}if(h)l=function(e,t){if(!e.size)return e;let n,o=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(t){return e}let{content:r,openStart:i,openEnd:l}=e;for(let e=n.length-2;e>=0;e-=2){let t=o.nodes[n[e]];if(!t||t.hasRequiredAttrs())break;r=s.from(t.create(n[e+1],r)),i++,l++}return new p(r,i,l)}(qs(l,+h[1],+h[2]),h[4]);else if(l=p.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let o,r=t.node(n).contentMatchAt(t.index(n)),i=[];if(e.forEach(e=>{if(!i)return;let t,n=r.findWrapping(e.type);if(!n)return i=null;if(t=i.length&&o.length&&Hs(n,o,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=_s(i[i.length-1],o.length));let t=Ls(e,n);i.push(t),r=r.matchType(t.type),o=n}}),i)return s.from(i)}return e}(l.content,r),!0),l.openStart||l.openEnd){let e=0,t=0;for(let t=l.content.firstChild;e<l.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=l.content.lastChild;t<l.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);l=qs(l,e,t)}return e.someProp("transformPasted",t=>{l=t(l,e,c)}),l}const Fs=/^(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 Ls(e,t,n=0){for(let o=t.length-1;o>=n;o--)e=t[o].create(null,s.from(e));return e}function Hs(e,t,n,o,r){if(r<e.length&&r<t.length&&e[r]==t[r]){let i=Hs(e,t,n,o.lastChild,r+1);if(i)return o.copy(o.content.replaceChild(o.childCount-1,i));if(o.contentMatchAt(o.childCount).matchType(r==e.length-1?n.type:e[r+1]))return o.copy(o.content.append(s.from(Ls(n,e,r+1))))}}function _s(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,_s(e.lastChild,t-1)),o=e.contentMatchAt(e.childCount).fillBefore(s.empty,!0);return e.copy(n.append(o))}function Ws(e,t,n,o,r,i){let l=t<0?e.firstChild:e.lastChild,a=l.content;return e.childCount>1&&(i=0),r<o-1&&(a=Ws(a,t,n,o,r+1,i)),r>=n&&(a=t<0?l.contentMatchAt(0).fillBefore(a,i<=r).append(a):a.append(l.contentMatchAt(l.childCount).fillBefore(s.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,l.copy(a))}function qs(e,t,n){return t<e.openStart&&(e=new p(Ws(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new p(Ws(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}const js={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 Js=null;function Ks(){return Js||(Js=document.implementation.createHTMLDocument("title"))}let Xs=null;const Us={},Gs={},Ys={touchstart:!0,touchmove:!0};class Qs{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Zs(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function el(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>tl(e,t))})}function tl(e,t){return e.someProp("handleDOMEvents",n=>{let o=n[t.type];return!!o&&(o(e,t)||t.defaultPrevented)})}function nl(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 ol(e){return{left:e.clientX,top:e.clientY}}function rl(e,t,n,o,r){if(-1==o)return!1;let i=e.state.doc.resolve(o);for(let o=i.depth+1;o>0;o--)if(e.someProp(t,t=>o>i.depth?t(e,n,i.nodeAfter,i.before(o),r,!0):t(e,n,i.node(o),i.before(o),r,!1)))return!0;return!1}function il(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let o=e.state.tr.setSelection(t);"pointer"==n&&o.setMeta("pointer",!0),e.dispatch(o)}function sl(e,t,n,o){return rl(e,"handleDoubleClickOn",t,n,o)||e.someProp("handleDoubleClick",n=>n(e,t,o))}function ll(e,t,n,o){return rl(e,"handleTripleClickOn",t,n,o)||e.someProp("handleTripleClick",n=>n(e,t,o))||function(e,t,n){if(0!=n.button)return!1;let o=e.state.doc;if(-1==t)return!!o.inlineContent&&(il(e,at.create(o,0,o.content.size),"pointer"),!0);let r=o.resolve(t);for(let t=r.depth+1;t>0;t--){let n=t>r.depth?r.nodeAfter:r.node(t),i=r.before(t);if(n.inlineContent)il(e,at.create(o,i+1,i+1+n.content.size),"pointer");else{if(!dt.isSelectable(n))continue;il(e,dt.create(o,i),"pointer")}return!0}}(e,n,o)}function al(e){return ml(e)}Gs.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!hl(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!bi||!fi||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!yi||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||function(e,t){let n=t.keyCode,o=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||wi&&72==n&&"c"==o)return zs(e,-1)||Ds(e,-1);if(46==n&&!t.shiftKey||wi&&68==n&&"c"==o)return zs(e,1)||Ds(e,1);if(13==n||27==n)return!0;if(37==n||wi&&66==n&&"c"==o){let t=37==n?"ltr"==$s(e,e.state.selection.from)?-1:1:-1;return Os(e,t,o)||Ds(e,t)}if(39==n||wi&&70==n&&"c"==o){let t=39==n?"ltr"==$s(e,e.state.selection.from)?1:-1:1;return Os(e,t,o)||Ds(e,t)}return 38==n||wi&&80==n&&"c"==o?Is(e,-1,o)||Ds(e,-1):40==n||wi&&78==n&&"c"==o?function(e){if(!gi||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;Bs(e,n,"true"),setTimeout(()=>Bs(e,n,"false"),20)}return!1}(e)||Is(e,1,o)||Ds(e,1):o==(wi?"m":"c")&&(66==n||73==n||89==n||90==n)}(e,n)?n.preventDefault():Zs(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,oi(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},Gs.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},Gs.keypress=(e,t)=>{let n=t;if(hl(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||wi&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let o=e.state.selection;if(!(o instanceof at&&o.$from.sameParent(o.$to))){let t=String.fromCharCode(n.charCode),r=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",n=>n(e,o.$from.pos,o.$to.pos,t,r))||e.dispatch(r()),n.preventDefault()}};const cl=wi?"metaKey":"ctrlKey";Us.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let o=al(e),r=Date.now(),i="singleClick";r-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,o=t.y-e.clientY;return n*n+o*o<100}(n,e.input.lastClick)&&!n[cl]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:r,x:n.clientX,y:n.clientY,type:i,button:n.button};let s=e.posAtCoords(ol(n));s&&("singleClick"==i?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new dl(e,s,n,!!o)):("doubleClick"==i?sl:ll)(e,s.pos,s.inside,n)?n.preventDefault():Zs(e,"pointer"))};class dl{constructor(e,t,n,o){let r,i;if(this.view=e,this.pos=t,this.event=n,this.flushed=o,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[cl],this.allowDefault=n.shiftKey,t.inside>-1)r=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);r=n.parent,i=n.depth?n.before():0}const s=o?null:n.target,l=s?e.docView.nearestDesc(s,!0):null;this.target=l&&1==l.nodeDOM.nodeType?l.nodeDOM:null;let{selection:a}=e.state;(0==n.button&&r.type.spec.draggable&&!1!==r.type.spec.selectable||a instanceof dt&&a.from<=i&&a.to>i)&&(this.mightDrag={node:r,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!pi||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)),Zs(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(()=>ms(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(ol(e))),this.updateAllowDefault(e),this.allowDefault||!t?Zs(this.view,"pointer"):function(e,t,n,o,r){return rl(e,"handleClickOn",t,n,o)||e.someProp("handleClick",n=>n(e,t,o))||(r?function(e,t){if(-1==t)return!1;let n,o,r=e.state.selection;r instanceof dt&&(n=r.node);let i=e.state.doc.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e);if(dt.isSelectable(t)){o=n&&r.$from.depth>0&&e>=r.$from.depth&&i.before(r.$from.depth+1)==r.$from.pos?i.before(r.$from.depth):i.before(e);break}}return null!=o&&(il(e,dt.create(e.state.doc,o),"pointer"),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),o=n.nodeAfter;return!!(o&&o.isAtom&&dt.isSelectable(o))&&(il(e,new dt(n),"pointer"),!0)}(e,n))}(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||gi&&this.mightDrag&&!this.mightDrag.node.isAtom||fi&&!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)?(il(this.view,rt.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Zs(this.view,"pointer")}move(e){this.updateAllowDefault(e),Zs(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 hl(e,t){return!!e.composing||!!(gi&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}Us.touchstart=e=>{e.input.lastTouch=Date.now(),al(e),Zs(e,"pointer")},Us.touchmove=e=>{e.input.lastTouch=Date.now(),Zs(e,"pointer")},Us.contextmenu=e=>al(e);const pl=bi?5e3:-1;function ul(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>ml(e),t))}function fl(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 ml(e,t=!1){if(!(bi&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),fl(e),t||e.docView&&e.docView.dirty){let n=us(e),o=e.state.selection;return n&&!n.eq(o)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}Gs.compositionstart=Gs.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof at&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||fi&&vi&&function(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||1!=t.nodeType||n>=t.childNodes.length)return!1;let o=t.childNodes[n];return 1==o.nodeType&&"false"==o.contentEditable}(e)))e.markCursor=e.state.storedMarks||n.marks(),ml(e,!0),e.markCursor=null;else if(ml(e,!t.selection.empty),pi&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,o=t.focusOffset;n&&1==n.nodeType&&0!=o;){let t=o<0?n.lastChild:n.childNodes[o-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,o=-1}}e.input.composing=!0}ul(e,pl)},Gs.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,ul(e,20))};const gl=di&&hi<15||yi&&xi<604;function yl(e,t,n,o,r){let i=Vs(e,t,n,o,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,r,i||p.empty)))return!0;if(!i)return!1;let s=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=s?e.state.tr.replaceSelectionWith(s,o):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function wl(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Us.copy=Gs.cut=(e,t)=>{let n=t,o=e.state.selection,r="cut"==n.type;if(o.empty)return;let i=gl?null:n.clipboardData,s=o.content(),{dom:l,text:a}=Ps(e,s);i?(n.preventDefault(),i.clearData(),i.setData("text/html",l.innerHTML),i.setData("text/plain",a)):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 o=getSelection(),r=document.createRange();r.selectNodeContents(t),e.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,l),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},Gs.paste=(e,t)=>{let n=t;if(e.composing&&!bi)return;let o=gl?null:n.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;o&&yl(e,wl(o),o.getData("text/html"),r,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,o=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),o.parentNode&&o.parentNode.removeChild(o),n?yl(e,o.value,null,r,t):yl(e,o.textContent,o.innerHTML,r,t)},50)}(e,n)};class vl{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}const bl=wi?"altKey":"ctrlKey";function kl(e,t){let n=e.someProp("dragCopies",e=>!e(t));return null!=n?n:!t[bl]}Us.dragstart=(e,t)=>{let n=t,o=e.input.mouseDown;if(o&&o.done(),!n.dataTransfer)return;let r,i=e.state.selection,s=i.empty?null:e.posAtCoords(ol(n));if(s&&s.pos>=i.from&&s.pos<=(i instanceof dt?i.to-1:i.to));else if(o&&o.mightDrag)r=dt.create(e.state.doc,o.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&&(r=dt.create(e.state.doc,t.posBefore))}let l=(r||e.state.selection).content(),{dom:a,text:c,slice:d}=Ps(e,l);(!n.dataTransfer.files.length||!fi||mi>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(gl?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",gl||n.dataTransfer.setData("text/plain",c),e.dragging=new vl(d,kl(e,n),r)},Us.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},Gs.dragover=Gs.dragenter=(e,t)=>t.preventDefault(),Gs.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let o=e.posAtCoords(ol(t));if(!o)return;let r=e.state.doc.resolve(o.pos),i=n&&n.slice;i?e.someProp("transformPasted",t=>{i=t(i,e,!1)}):i=Vs(e,wl(t.dataTransfer),gl?null:t.dataTransfer.getData("text/html"),!1,r);let s=!(!n||!kl(e,t));if(e.someProp("handleDrop",n=>n(e,t,i||p.empty,s)))return void t.preventDefault();if(!i)return;t.preventDefault();let l=i?He(e.state.doc,r.pos,i):r.pos;null==l&&(l=r.pos);let a=e.state.tr;if(s){let{node:e}=n;e?e.replace(a):a.deleteSelection()}let c=a.mapping.map(l),d=0==i.openStart&&0==i.openEnd&&1==i.content.childCount,h=a.doc;if(d?a.replaceRangeWith(c,c,i.content.firstChild):a.replaceRange(c,c,i),a.doc.eq(h))return;let u=a.doc.resolve(c);if(d&&dt.isSelectable(i.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new dt(u));else{let t=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((e,n,o,r)=>t=r),a.setSelection(xs(e,u,a.doc.resolve(t)))}e.focus(),e.dispatch(a.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},Us.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())&&ms(e)},20))},Us.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)},Us.beforeinput=(e,t)=>{if(fi&&bi&&"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,oi(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 Gs)Us[e]=Gs[e];function xl(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 Sl{constructor(e,t){this.toDOM=e,this.spec=t||Al,this.side=this.spec.side||0}map(e,t,n,o){let{pos:r,deleted:i}=e.mapResult(t.from+o,this.side<0?-1:1);return i?null:new Nl(r-n,r-n,this)}valid(){return!0}eq(e){return this==e||e instanceof Sl&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&xl(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Cl{constructor(e,t){this.attrs=e,this.spec=t||Al}map(e,t,n,o){let r=e.map(t.from+o,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+o,this.spec.inclusiveEnd?1:-1)-n;return r>=i?null:new Nl(r,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Cl&&xl(this.attrs,e.attrs)&&xl(this.spec,e.spec)}static is(e){return e.type instanceof Cl}destroy(){}}class Ml{constructor(e,t){this.attrs=e,this.spec=t||Al}map(e,t,n,o){let r=e.mapResult(t.from+o,1);if(r.deleted)return null;let i=e.mapResult(t.to+o,-1);return i.deleted||i.pos<=r.pos?null:new Nl(r.pos-n,i.pos-n,this)}valid(e,t){let n,{index:o,offset:r}=e.content.findIndex(t.from);return r==t.from&&!(n=e.child(o)).isText&&r+n.nodeSize==t.to}eq(e){return this==e||e instanceof Ml&&xl(this.attrs,e.attrs)&&xl(this.spec,e.spec)}destroy(){}}class Nl{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new Nl(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 Nl(e,e,new Sl(t,n))}static inline(e,t,n,o){return new Nl(e,t,new Cl(n,o))}static node(e,t,n,o){return new Nl(e,t,new Ml(n,o))}get spec(){return this.type.spec}get inline(){return this.type instanceof Cl}get widget(){return this.type instanceof Sl}}const Ol=[],Al={};class Tl{constructor(e,t){this.local=e.length?e:Ol,this.children=t.length?t:Ol}static create(e,t){return t.length?zl(t,e,0,Al):Dl}find(e,t,n){let o=[];return this.findInner(null==e?0:e,null==t?1e9:t,o,0,n),o}findInner(e,t,n,o,r){for(let i=0;i<this.local.length;i++){let s=this.local[i];s.from<=t&&s.to>=e&&(!r||r(s.spec))&&n.push(s.copy(s.from+o,s.to+o))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let s=this.children[i]+1;this.children[i+2].findInner(e-s,t-s,n,o+s,r)}}map(e,t,n){return this==Dl||0==e.maps.length?this:this.mapInner(e,t,0,0,n||Al)}mapInner(e,t,n,o,r){let i;for(let s=0;s<this.local.length;s++){let l=this.local[s].map(e,n,o);l&&l.type.valid(t,l)?(i||(i=[])).push(l):r.onRemove&&r.onRemove(this.local[s].spec)}return this.children.length?function(e,t,n,o,r,i,s){let l=e.slice();for(let e=0,t=i;e<n.maps.length;e++){let o=0;n.maps[e].forEach((e,n,r,i)=>{let s=i-r-(n-e);for(let r=0;r<l.length;r+=3){let i=l[r+1];if(i<0||e>i+t-o)continue;let a=l[r]+t-o;n>=a?l[r+1]=e<=a?-2:-1:e>=t&&s&&(l[r]+=s,l[r+1]+=s)}o+=s}),t=n.maps[e].map(t,-1)}let a=!1;for(let t=0;t<l.length;t+=3)if(l[t+1]<0){if(-2==l[t+1]){a=!0,l[t+1]=-1;continue}let c=n.map(e[t]+i),d=c-r;if(d<0||d>=o.content.size){a=!0;continue}let h=n.map(e[t+1]+i,-1)-r,{index:p,offset:u}=o.content.findIndex(d),f=o.maybeChild(p);if(f&&u==d&&u+f.nodeSize==h){let o=l[t+2].mapInner(n,f,c+1,e[t]+i+1,s);o!=Dl?(l[t]=d,l[t+1]=h,l[t+2]=o):(l[t+1]=-2,a=!0)}else a=!0}if(a){let a=function(e,t,n,o,r,i,s){function l(e,t){for(let i=0;i<e.local.length;i++){let l=e.local[i].map(o,r,t);l?n.push(l):s.onRemove&&s.onRemove(e.local[i].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)-1==e[n+1]&&l(e[n+2],t[n]+i+1);return n}(l,e,t,n,r,i,s),c=zl(a,o,0,s);t=c.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new Tl(t.sort(Bl),l)}(this.children,i||[],e,t,n,o,r):i?new Tl(i.sort(Bl),Ol):Dl}add(e,t){return t.length?this==Dl?Tl.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let o,r=0;e.forEach((e,i)=>{let s,l=i+n;if(s=$l(t,e,l)){for(o||(o=this.children.slice());r<o.length&&o[r]<i;)r+=3;o[r]==i?o[r+2]=o[r+2].addInner(e,s,l+1):o.splice(r,0,i,i+e.nodeSize,zl(s,e,l+1,Al)),r+=3}});let i=Rl(r?Il(t):t,-n);for(let t=0;t<i.length;t++)i[t].type.valid(e,i[t])||i.splice(t--,1);return new Tl(i.length?this.local.concat(i).sort(Bl):this.local,o||this.children)}remove(e){return 0==e.length||this==Dl?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,o=this.local;for(let o=0;o<n.length;o+=3){let r,i=n[o]+t,s=n[o+1]+t;for(let t,n=0;n<e.length;n++)(t=e[n])&&t.from>i&&t.to<s&&(e[n]=null,(r||(r=[])).push(t));if(!r)continue;n==this.children&&(n=this.children.slice());let l=n[o+2].removeInner(r,i+1);l!=Dl?n[o+2]=l:(n.splice(o,3),o-=3)}if(o.length)for(let n,r=0;r<e.length;r++)if(n=e[r])for(let e=0;e<o.length;e++)o[e].eq(n,t)&&(o==this.local&&(o=this.local.slice()),o.splice(e--,1));return n==this.children&&o==this.local?this:o.length||n.length?new Tl(o,n):Dl}forChild(e,t){if(this==Dl)return this;if(t.isLeaf)return Tl.empty;let n,o;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 r=e+1,i=r+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<i&&t.to>r&&t.type instanceof Cl){let e=Math.max(r,t.from)-r,n=Math.min(i,t.to)-r;e<n&&(o||(o=[])).push(t.copy(e,n))}}if(o){let e=new Tl(o.sort(Bl),Ol);return n?new El([e,n]):e}return n||Dl}eq(e){if(this==e)return!0;if(!(e instanceof Tl)||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 Pl(this.localsInner(e))}localsInner(e){if(this==Dl)return Ol;if(e.inlineContent||!this.local.some(Cl.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof Cl||t.push(this.local[e]);return t}forEachSet(e){e(this)}}Tl.empty=new Tl([],[]),Tl.removeOverlap=Pl;const Dl=Tl.empty;class El{constructor(e){this.members=e}map(e,t){const n=this.members.map(n=>n.map(e,t,Al));return El.from(n)}forChild(e,t){if(t.isLeaf)return Tl.empty;let n=[];for(let o=0;o<this.members.length;o++){let r=this.members[o].forChild(e,t);r!=Dl&&(r instanceof El?n=n.concat(r.members):n.push(r))}return El.from(n)}eq(e){if(!(e instanceof El)||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 o=0;o<this.members.length;o++){let r=this.members[o].localsInner(e);if(r.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<r.length;e++)t.push(r[e])}else t=r}return t?Pl(n?t:t.sort(Bl)):Ol}static from(e){switch(e.length){case 0:return Dl;case 1:return e[0];default:return new El(e.every(e=>e instanceof Tl)?e:e.reduce((e,t)=>e.concat(t instanceof Tl?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function Rl(e,t){if(!t||!e.length)return e;let n=[];for(let o=0;o<e.length;o++){let r=e[o];n.push(new Nl(r.from+t,r.to+t,r.type))}return n}function $l(e,t,n){if(t.isLeaf)return null;let o=n+t.nodeSize,r=null;for(let t,i=0;i<e.length;i++)(t=e[i])&&t.from>n&&t.to<o&&((r||(r=[])).push(t),e[i]=null);return r}function Il(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function zl(e,t,n,o){let r=[],i=!1;t.forEach((t,s)=>{let l=$l(e,t,s+n);if(l){i=!0;let e=zl(l,t,n+s+1,o);e!=Dl&&r.push(s,s+t.nodeSize,e)}});let s=Rl(i?Il(e):e,-n).sort(Bl);for(let e=0;e<s.length;e++)s[e].type.valid(t,s[e])||(o.onRemove&&o.onRemove(s[e].spec),s.splice(e--,1));return s.length||r.length?new Tl(s,r):Dl}function Bl(e,t){return e.from-t.from||e.to-t.to}function Pl(e){let t=e;for(let n=0;n<t.length-1;n++){let o=t[n];if(o.from!=o.to)for(let r=n+1;r<t.length;r++){let i=t[r];if(i.from!=o.from){i.from<o.to&&(t==e&&(t=e.slice()),t[n]=o.copy(o.from,i.from),Vl(t,r,o.copy(i.from,o.to)));break}i.to!=o.to&&(t==e&&(t=e.slice()),t[r]=i.copy(i.from,o.to),Vl(t,r+1,i.copy(o.to,i.to)))}}return t}function Vl(e,t,n){for(;t<e.length&&Bl(n,e[t])>0;)t++;e.splice(t,0,n)}function Fl(e){let t=[];return e.someProp("decorations",n=>{let o=n(e.state);o&&o!=Dl&&t.push(o)}),e.cursorWrapper&&t.push(Tl.create(e.state.doc,[e.cursorWrapper.deco])),El.from(t)}const Ll={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Hl=di&&hi<=11;class _l{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 Wl{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new _l,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(e=>{for(let t=0;t<e.length;t++)this.queue.push(e[t]);di&&hi<=11&&e.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),Hl&&(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,Ll)),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(Ss(this.view)){if(this.suppressingSelectionUpdates)return ms(this.view);if(di&&hi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Yr(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=Xr(t))n.add(t);for(let o=e.anchorNode;o;o=Xr(o))if(n.has(o)){t=o;break}let o=t&&this.view.docView.nearestDesc(t);return o&&o.ignoreMutation({type:"selection",target:3==t.nodeType?t.parentNode:t})?(this.setCurSelection(),!0):void 0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),o=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Ss(e)&&!this.ignoreSelectionChange(n),r=-1,i=-1,s=!1,l=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],l);n&&(r=r<0?n.from:Math.min(n.from,r),i=i<0?n.to:Math.max(n.to,i),n.typeOver&&(s=!0))}if(pi&&l.length){let t=l.filter(e=>"BR"==e.nodeName);if(2==t.length){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let o of t){let t=o.parentNode;!t||"LI"!=t.nodeName||n&&Kl(e,n)==t||o.remove()}}}else if((fi||gi)&&l.some(e=>"BR"==e.nodeName)&&(8==e.input.lastKeyCode||46==e.input.lastKeyCode))for(let e of l)if("BR"==e.nodeName&&e.parentNode){let t=e.nextSibling;t&&1==t.nodeType&&"false"==t.contentEditable&&e.parentNode.removeChild(e)}let a=null;r<0&&o&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&ni(n)&&(a=us(e))&&a.eq(rt.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,ms(e),this.currentSelection.set(n),e.scrollToSelection()):(r>-1||o)&&(r>-1&&(e.docView.markDirty(r,i),function(e){if(!ql.has(e)&&(ql.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))){if(e.requiresGeckoHackNode=pi,jl)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."),jl=!0}}(e)),this.handleDOMChange(r,i,s,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||ms(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++){let o=e.addedNodes[n];t.push(o),3==o.nodeType&&(this.lastChangedTextNode=o)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let o=e.previousSibling,r=e.nextSibling;if(di&&hi<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:i}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(o=n),(!i||Array.prototype.indexOf.call(e.addedNodes,i)<0)&&(r=i)}let i=o&&o.parentNode==e.target?Kr(o)+1:0,s=n.localPosFromDOM(e.target,i,-1),l=r&&r.parentNode==e.target?Kr(r):e.target.childNodes.length;return{from:s,to:n.localPosFromDOM(e.target,l,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let ql=new WeakMap,jl=!1;function Jl(e,t){let n=t.startContainer,o=t.startOffset,r=t.endContainer,i=t.endOffset,s=e.domAtPos(e.state.selection.anchor);return Yr(s.node,s.offset,r,i)&&([n,o,r,i]=[r,i,n,o]),{anchorNode:n,anchorOffset:o,focusNode:r,focusOffset:i}}function Kl(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function Xl(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(gi&&/^(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||gi&&/^(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 Ul=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Gl(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:xs(e,t.resolve(n.anchor),t.resolve(n.head))}function Yl(e,t,n){let o=e.depth,r=t?e.end():e.pos;for(;o>0&&(t||e.indexAfter(o)==e.node(o).childCount);)o--,r++,t=!1;if(n){let t=e.node(o).maybeChild(e.indexAfter(o));for(;t&&!t.isLeaf;)t=t.firstChild,r++}return r}function Ql(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}const Zl=Vs,ea=ml;class ta{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 Qs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(sa),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=ra(this),oa(this),this.nodeViews=ia(this),this.docView=Gi(this.state.doc,na(this),Fl(this),this.dom,this),this.domObserver=new Wl(this,(e,t,n,o)=>function(e,t,n,o,r){let i=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=us(e,t);if(n&&!e.state.selection.eq(n)){if(fi&&bi&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oi(13,"Enter"))))return;let o=e.state.tr.setSelection(n);"pointer"==t?o.setMeta("pointer",!0):"key"==t&&o.scrollIntoView(),i&&o.setMeta("composition",i),e.dispatch(o)}return}let l=e.state.doc.resolve(t),a=l.sharedDepth(n);t=l.before(a+1),n=e.state.doc.resolve(n).after(a+1);let c,d,h=e.state.selection,p=function(e,t,n){let o,{node:r,fromOffset:i,toOffset:s,from:l,to:a}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(o=[{node:d,offset:c.anchorOffset}],ni(c)||o.push({node:c.focusNode,offset:c.focusOffset})),fi&&8===e.input.lastKeyCode)for(let e=s;e>i;e--){let t=r.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")||Y.fromSchema(e.state.schema),u=h.resolve(l),f=null,m=p.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:"pre"!=u.parent.type.whitespace||"full",findPositions:o,ruleFromNode:Xl,context:u});if(o&&null!=o[0].pos){let e=o[0].pos,t=o[1]&&o[1].pos;null==t&&(t=e),f={anchor:e+l,head:t+l}}return{doc:m,sel:f,from:l,to:a}}(e,t,n),u=e.state.doc,f=u.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(c=e.state.selection.to,d="end"):(c=e.state.selection.from,d="start"),e.input.lastKeyCode=null;let m=function(e,t,n,o,r){let i=e.findDiffStart(t,n);if(null==i)return null;let{a:s,b:l}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==r&&(o-=s+Math.max(0,i-Math.min(s,l))-i),s<i&&e.size<t.size){let e=o<=i&&o>=s?i-o:0;i-=e,i&&i<t.size&&Ql(t.textBetween(i-1,i+1))&&(i+=e?1:-1),l=i+(l-s),s=i}else if(l<i){let t=o<=i&&o>=l?i-o:0;i-=t,i&&i<e.size&&Ql(e.textBetween(i-1,i+1))&&(i+=t?1:-1),s=i+(s-l),l=i}return{start:i,endA:s,endB:l}}(f.content,p.doc.content,p.from,c,d);if(m&&e.input.domChangeCount++,(yi&&e.input.lastIOSEnter>Date.now()-225||bi)&&r.some(e=>1==e.nodeType&&!Ul.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",t=>t(e,oi(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(!m){if(!(o&&h instanceof at&&!h.empty&&h.$head.sameParent(h.$anchor))||e.composing||p.sel&&p.sel.anchor!=p.sel.head){if(p.sel){let t=Gl(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);i&&n.setMeta("composition",i),e.dispatch(n)}}return}m={start:h.from,endA:h.to,endB:h.to}}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof at&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),di&&hi<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g=p.doc.resolveNoCache(m.start-p.from),y=p.doc.resolveNoCache(m.endB-p.from),w=u.resolve(m.start),v=g.sameParent(y)&&g.parent.inlineContent&&w.end()>=m.endA;if((yi&&e.input.lastIOSEnter>Date.now()-225&&(!v||r.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!v&&g.pos<p.doc.content.size&&(!g.sameParent(y)||!g.parent.inlineContent)&&g.pos<y.pos&&!/\S/.test(p.doc.textBetween(g.pos,y.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oi(13,"Enter"))))return void(e.input.lastIOSEnter=0);if(e.state.selection.anchor>m.start&&function(e,t,n,o,r){if(n-t<=r.pos-o.pos||Yl(o,!0,!1)<r.pos)return!1;let i=e.resolve(t);if(!o.parent.isTextblock){let e=i.nodeAfter;return null!=e&&n==t+e.nodeSize}if(i.parentOffset<i.parent.content.size||!i.parent.isTextblock)return!1;let s=e.resolve(Yl(i,!0,!0));return!(!s.parent.isTextblock||s.pos>n||Yl(s,!0,!1)<n)&&o.parent.content.cut(o.parentOffset).eq(s.parent.content)}(u,m.start,m.endA,g,y)&&e.someProp("handleKeyDown",t=>t(e,oi(8,"Backspace"))))return void(bi&&fi&&e.domObserver.suppressSelectionUpdates());fi&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),bi&&!v&&g.start()!=y.start()&&0==y.parentOffset&&g.depth==y.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,y=p.doc.resolveNoCache(m.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oi(13,"Enter"))})},20));let b,k=m.start,x=m.endA,S=t=>{let n=t||e.state.tr.replace(k,x,p.doc.slice(m.start-p.from,m.endB-p.from));if(p.sel){let t=Gl(e,n.doc,p.sel);t&&!(fi&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==k||t.head==n.mapping.map(x)-1)||di&&t.empty&&t.head==k)&&n.setSelection(t)}return i&&n.setMeta("composition",i),n.scrollIntoView()};if(v)if(g.pos==y.pos){di&&hi<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>ms(e),20));let t=S(e.state.tr.delete(k,x)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(b=function(e,t){let n,o,r,i=e.firstChild.marks,l=t.firstChild.marks,a=i,c=l;for(let e=0;e<l.length;e++)a=l[e].removeFromSet(a);for(let e=0;e<i.length;e++)c=i[e].removeFromSet(c);if(1==a.length&&0==c.length)o=a[0],n="add",r=e=>e.mark(o.addToSet(e.marks));else{if(0!=a.length||1!=c.length)return null;o=c[0],n="remove",r=e=>e.mark(o.removeFromSet(e.marks))}let d=[];for(let e=0;e<t.childCount;e++)d.push(r(t.child(e)));if(s.from(d).eq(e))return{mark:o,type:n}}(g.parent.content.cut(g.parentOffset,y.parentOffset),w.parent.content.cut(w.parentOffset,m.endA-w.start())))){let t=S(e.state.tr);"add"==b.type?t.addMark(k,x,b.mark):t.removeMark(k,x,b.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let t=g.parent.textBetween(g.parentOffset,y.parentOffset),n=()=>S(e.state.tr.insertText(t,k,x));e.someProp("handleTextInput",o=>o(e,k,x,t,n))||e.dispatch(n())}else e.dispatch(S());else e.dispatch(S())}(this,e,t,n,o)),this.domObserver.start(),function(e){for(let t in Us){let n=Us[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!nl(e,t)||tl(e,t)||!e.editable&&t.type in Gs||n(e,t)},Ys[t]?{passive:!0}:void 0)}gi&&e.dom.addEventListener("input",()=>null),el(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&&el(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(sa),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){var n;let o=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(fl(this),i=!0),this.state=e;let s=o.plugins!=e.plugins||this._props.plugins!=t.plugins;if(s||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=ia(this);(function(e,t){let n=0,o=0;for(let o in e){if(e[o]!=t[o])return!0;n++}for(let e in t)o++;return n!=o})(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(s||t.handleDOMEvents!=this._props.handleDOMEvents)&&el(this),this.editable=ra(this),oa(this);let l=Fl(this),a=na(this),c=o.plugins==e.plugins||o.doc.eq(e.doc)?e.scrollToSelection>o.scrollToSelection?"to selection":"preserve":"reset",d=r||!this.docView.matchesNode(e.doc,a,l);!d&&e.selection.eq(o.selection)||(i=!0);let h="preserve"==c&&i&&null==this.dom.style.overflowAnchor&&function(e){let t,n,o=e.dom.getBoundingClientRect(),r=Math.max(0,o.top);for(let i=(o.left+o.right)/2,s=r+1;s<Math.min(innerHeight,o.bottom);s+=5){let o=e.root.elementFromPoint(i,s);if(!o||o==e.dom||!e.dom.contains(o))continue;let l=o.getBoundingClientRect();if(l.top>=r-20){t=o,n=l.top;break}}return{refDOM:t,refTop:n,stack:Oi(e.dom)}}(this);if(i){this.domObserver.stop();let t=d&&(di||fi)&&!this.composing&&!o.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)}(o.selection,e.selection);if(d){let n=fi?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=ei(e=e.childNodes[t-1])}else{if(!e.parentNode||ti(e))return null;t=Kr(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),o=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||ti(e))return null;t=Kr(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&o&&n!=o){let t=o.pmViewDesc,r=e.domObserver.lastChangedTextNode;if(n==r||o==r)return r;if(!t||!t.isText(o.nodeValue))return o;if(e.input.compositionNode==o){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return o}}return n||o}(this)),!r&&this.docView.update(e.doc,a,l,this)||(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Gi(e.doc,a,l,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 Yr(t.node,t.offset,n.anchorNode,n.anchorOffset)}(this))?ms(this,t):(bs(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(o),(null===(n=this.dragging)||void 0===n?void 0:n.node)&&!o.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,o),"reset"==c?this.dom.scrollTop=0:"to selection"==c?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let o=e?e.getBoundingClientRect().top:0;Ai(n,0==o?0:o-t)}(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof dt){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&Ni(this,t.getBoundingClientRect(),e)}else Ni(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))}}}updateDraggedNode(e,t){let n=e.node,o=-1;if(this.state.doc.nodeAt(n.from)==n.node)o=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&this.state.doc.nodeAt(e))==n.node&&(o=e)}this.dragging=new vl(e.slice,e.move,o<0?void 0:dt.create(this.state.doc,o))}someProp(e,t){let n,o=this._props&&this._props[e];if(null!=o&&(n=t?t(o):o))return n;for(let o=0;o<this.directPlugins.length;o++){let r=this.directPlugins[o].props[e];if(null!=r&&(n=t?t(r):r))return n}let r=this.state.plugins;if(r)for(let o=0;o<r.length;o++){let i=r[o].props[e];if(null!=i&&(n=t?t(i):i))return n}}hasFocus(){if(di){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(Ti)return e.focus(Ti);let t=Oi(e);e.focus(null==Ti?{get preventScroll(){return Ti={preventScroll:!0},!0}}:void 0),Ti||(Ti=!1,Ai(t,0))}(this.dom),ms(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}updateRoot(){this._root=null}posAtCoords(e){return $i(this,e)}coordsAtPos(e,t=1){return Pi(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 o=this.docView.posFromDOM(e,t,n);if(null==o)throw new RangeError("DOM position not inside the editor");return o}endOfTextblock(e,t){return function(e,t,n){return _i==t&&Wi==n?qi:(_i=t,Wi=n,qi="up"==n||"down"==n?function(e,t,n){let o=t.selection,r="up"==n?o.$from:o.$to;return Li(e,t,()=>{let{node:t}=e.docView.domFromPos(r.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 o=Pi(e,r.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=Gr(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let r=t[e];if(r.bottom>r.top+1&&("up"==n?o.top-r.top>2*(r.bottom-o.top):r.bottom-o.bottom>2*(o.bottom-r.top)))return!1}}return!0})}(e,t,n):function(e,t,n){let{$head:o}=t.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,i=!r,s=r==o.parent.content.size,l=e.domSelection();return l?Hi.test(o.parent.textContent)&&l.modify?Li(e,t,()=>{let{focusNode:t,focusOffset:r,anchorNode:i,anchorOffset:s}=e.domSelectionRange(),a=l.caretBidiLevel;l.modify("move",n,"character");let c=o.depth?e.docView.domAfterPos(o.before()):e.dom,{focusNode:d,focusOffset:h}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&r==h;try{l.collapse(i,s),t&&(t!=i||r!=s)&&l.extend&&l.extend(t,r)}catch(e){}return null!=a&&(l.caretBidiLevel=a),p}):"left"==n||"backward"==n?i:s:o.pos==o.start()||o.pos==o.end()}(e,t,n))}(this,t||this.state,e)}pasteHTML(e,t){return yl(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return yl(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Ps(this,e)}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,[],Fl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ur=null)}get isDestroyed(){return null==this.docView}dispatchEvent(e){return function(e,t){tl(e,t)||!Us[t.type]||!e.editable&&t.type in Gs||Us[t.type](e,t)}(this,e)}domSelectionRange(){let e=this.domSelection();return e?gi&&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,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Jl(e,n)}let n;function o(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",o,!0),n?Jl(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function na(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),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]))}),t.translate||(t.translate="no"),[Nl.node(0,e.state.doc.content.size,t)]}function oa(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:Nl.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function ra(e){return!e.someProp("editable",t=>!1===t(e.state))}function ia(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 sa(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")}ta.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var la={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:"'"},aa={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ca="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),da="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ha=0;ha<10;ha++)la[48+ha]=la[96+ha]=String(ha);for(ha=1;ha<=24;ha++)la[ha+111]="F"+ha;for(ha=65;ha<=90;ha++)la[ha]=String.fromCharCode(ha+32),aa[ha]=String.fromCharCode(ha);for(var pa in la)aa.hasOwnProperty(pa)||(aa[pa]=la[pa]);const ua="undefined"!=typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),fa="undefined"!=typeof navigator&&/Win/.test(navigator.platform);function ma(e){let t,n,o,r,i=e.split(/-(?!$)/),s=i[i.length-1];"Space"==s&&(s=" ");for(let e=0;e<i.length-1;e++){let s=i[e];if(/^(cmd|meta|m)$/i.test(s))r=!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))o=!0;else{if(!/^mod$/i.test(s))throw new Error("Unrecognized modifier name: "+s);ua?r=!0:n=!0}}return t&&(s="Alt-"+s),n&&(s="Ctrl-"+s),r&&(s="Meta-"+s),o&&(s="Shift-"+s),s}function ga(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 ya(e){return new St({props:{handleKeyDown:wa(e)}})}function wa(e){let t=function(e){let t=Object.create(null);for(let n in e)t[ma(n)]=e[n];return t}(e);return function(e,n){let o,r=function(e){var t=!(ca&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||da&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?aa:la)[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),i=t[ga(r,n)];if(i&&i(e.state,e.dispatch,e))return!0;if(1==r.length&&" "!=r){if(n.shiftKey){let o=t[ga(r,n,!1)];if(o&&o(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(fa&&n.ctrlKey&&n.altKey)&&(o=la[n.keyCode])&&o!=r){let r=t[ga(o,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}let va,ba;if("undefined"!=typeof WeakMap){let e=new WeakMap;va=t=>e.get(t),ba=(t,n)=>(e.set(t,n),n)}else{const e=[],t=10;let n=0;va=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},ba=(o,r)=>(n==t&&(n=0),e[n++]=o,e[n++]=r)}var ka=class{constructor(e,t,n,o){this.width=e,this.height=t,this.map=n,this.problems=o}findCell(e){for(let t=0;t<this.map.length;t++){const n=this.map[t];if(n!=e)continue;const o=t%this.width,r=t/this.width|0;let i=o+1,s=r+1;for(let e=1;i<this.width&&this.map[t+e]==n;e++)i++;for(let e=1;s<this.height&&this.map[t+this.width*e]==n;e++)s++;return{left:o,top:r,right:i,bottom:s}}throw new RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){const{left:o,right:r,top:i,bottom:s}=this.findCell(e);return"horiz"==t?(n<0?0==o:r==this.width)?null:this.map[i*this.width+(n<0?o-1:r)]:(n<0?0==i:s==this.height)?null:this.map[o+this.width*(n<0?i-1:s)]}rectBetween(e,t){const{left:n,right:o,top:r,bottom:i}=this.findCell(e),{left:s,right:l,top:a,bottom:c}=this.findCell(t);return{left:Math.min(n,s),top:Math.min(r,a),right:Math.max(o,l),bottom:Math.max(i,c)}}cellsInRect(e){const t=[],n={};for(let o=e.top;o<e.bottom;o++)for(let r=e.left;r<e.right;r++){const i=o*this.width+r,s=this.map[i];n[s]||(n[s]=!0,r==e.left&&r&&this.map[i-1]==s||o==e.top&&o&&this.map[i-this.width]==s||t.push(s))}return t}positionAt(e,t,n){for(let o=0,r=0;;o++){const i=r+n.child(o).nodeSize;if(o==e){let n=t+e*this.width;const o=(e+1)*this.width;for(;n<o&&this.map[n]<r;)n++;return n==o?i-1:this.map[n]}r=i}}static get(e){return va(e)||ba(e,function(e){if("table"!=e.type.spec.tableRole)throw new RangeError("Not a table node: "+e.type.name);const t=function(e){let t=-1,n=!1;for(let o=0;o<e.childCount;o++){const r=e.child(o);let i=0;if(n)for(let t=0;t<o;t++){const n=e.child(t);for(let e=0;e<n.childCount;e++){const r=n.child(e);t+r.attrs.rowspan>o&&(i+=r.attrs.colspan)}}for(let e=0;e<r.childCount;e++){const t=r.child(e);i+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=i:t!=i&&(t=Math.max(t,i))}return t}(e),n=e.childCount,o=[];let r=0,i=null;const s=[];for(let e=0,r=t*n;e<r;e++)o[e]=0;for(let l=0,a=0;l<n;l++){const c=e.child(l);a++;for(let e=0;;e++){for(;r<o.length&&0!=o[r];)r++;if(e==c.childCount)break;const d=c.child(e),{colspan:h,rowspan:p,colwidth:u}=d.attrs;for(let e=0;e<p;e++){if(e+l>=n){(i||(i=[])).push({type:"overlong_rowspan",pos:a,n:p-e});break}const c=r+e*t;for(let e=0;e<h;e++){0==o[c+e]?o[c+e]=a:(i||(i=[])).push({type:"collision",row:l,pos:a,n:h-e});const n=u&&u[e];if(n){const o=(c+e)%t*2,r=s[o];null==r||r!=n&&1==s[o+1]?(s[o]=n,s[o+1]=1):r==n&&s[o+1]++}}}r+=h,a+=d.nodeSize}const d=(l+1)*t;let h=0;for(;r<d;)0==o[r++]&&h++;h&&(i||(i=[])).push({type:"missing",row:l,n:h}),a++}0!==t&&0!==n||(i||(i=[])).push({type:"zero_sized"});const l=new ka(t,n,o,i);let a=!1;for(let e=0;!a&&e<s.length;e+=2)null!=s[e]&&s[e+1]<n&&(a=!0);return a&&function(e,t,n){e.problems||(e.problems=[]);const o={};for(let r=0;r<e.map.length;r++){const i=e.map[r];if(o[i])continue;o[i]=!0;const s=n.nodeAt(i);if(!s)throw new RangeError(`No cell with offset ${i} found`);let l=null;const a=s.attrs;for(let n=0;n<a.colspan;n++){const o=t[(r+n)%e.width*2];null==o||a.colwidth&&a.colwidth[n]==o||((l||(l=xa(a)))[n]=o)}l&&e.problems.unshift({type:"colwidth mismatch",pos:i,colwidth:l})}}(l,s,e),l}(e))}};function xa(e){if(e.colwidth)return e.colwidth.slice();const t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function Sa(e,t){if("string"==typeof e)return{};const n=e.getAttribute("data-colwidth"),o=n&&/^\d+(,\d+)*$/.test(n)?n.split(",").map(e=>Number(e)):null,r=Number(e.getAttribute("colspan")||1),i={colspan:r,rowspan:Number(e.getAttribute("rowspan")||1),colwidth:o&&o.length==r?o:null};for(const n in t){const o=t[n].getFromDOM,r=o&&o(e);null!=r&&(i[n]=r)}return i}function Ca(e,t){const n={};1!=e.attrs.colspan&&(n.colspan=e.attrs.colspan),1!=e.attrs.rowspan&&(n.rowspan=e.attrs.rowspan),e.attrs.colwidth&&(n["data-colwidth"]=e.attrs.colwidth.join(","));for(const o in t){const r=t[o].setDOMAttr;r&&r(e.attrs[o],n)}return n}function Ma(e){if(null!==e){if(!Array.isArray(e))throw new TypeError("colwidth must be null or an array");for(const t of e)if("number"!=typeof t)throw new TypeError("colwidth must be null or an array of numbers")}}function Na(e){const t=e.cellAttributes||{},n={colspan:{default:1,validate:"number"},rowspan:{default:1,validate:"number"},colwidth:{default:null,validate:Ma}};for(const e in t)n[e]={default:t[e].default,validate:t[e].validate};return{table:{content:"table_row+",tableRole:"table",isolating:!0,group:e.tableGroup,parseDOM:[{tag:"table"}],toDOM:()=>["table",["tbody",0]]},table_row:{content:"(table_cell | table_header)*",tableRole:"row",parseDOM:[{tag:"tr"}],toDOM:()=>["tr",0]},table_cell:{content:e.cellContent,attrs:n,tableRole:"cell",isolating:!0,parseDOM:[{tag:"td",getAttrs:e=>Sa(e,t)}],toDOM:e=>["td",Ca(e,t),0]},table_header:{content:e.cellContent,attrs:n,tableRole:"header_cell",isolating:!0,parseDOM:[{tag:"th",getAttrs:e=>Sa(e,t)}],toDOM:e=>["th",Ca(e,t),0]}}}function Oa(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(const n in e.nodes){const o=e.nodes[n],r=o.spec.tableRole;r&&(t[r]=o)}}return t}const Aa=new Nt("selectingCells");function Ta(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function Da(e){const t=e.selection.$head;for(let e=t.depth;e>0;e--)if("row"==t.node(e).type.spec.tableRole)return!0;return!1}function Ea(e){const t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&"cell"==t.node.type.spec.tableRole)return t.$anchor;const n=Ta(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){const o=t.type.spec.tableRole;if("cell"==o||"header_cell"==o)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw new RangeError(`No cell found around position ${t.head}`)}function Ra(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function $a(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function Ia(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function za(e){return ka.get(e.node(-1)).findCell(e.pos-e.start(-1))}function Ba(e){return ka.get(e.node(-1)).colCount(e.pos-e.start(-1))}function Pa(e,t,n){const o=e.node(-1),r=ka.get(o),i=e.start(-1),s=r.nextCell(e.pos-i,t,n);return null==s?null:e.node(0).resolve(i+s)}function Va(e,t,n=1){const o={...e,colspan:e.colspan-n};return o.colwidth&&(o.colwidth=o.colwidth.slice(),o.colwidth.splice(t,n),o.colwidth.some(e=>e>0)||(o.colwidth=null)),o}function Fa(e,t,n=1){const o={...e,colspan:e.colspan+n};if(o.colwidth){o.colwidth=o.colwidth.slice();for(let e=0;e<n;e++)o.colwidth.splice(t,0,0)}return o}function La(e,t,n){const o=Oa(t.type.schema).header_cell;for(let r=0;r<e.height;r++)if(t.nodeAt(e.map[n+r*e.width]).type!=o)return!1;return!0}var Ha=class e extends rt{constructor(e,t=e){const n=e.node(-1),o=ka.get(n),r=e.start(-1),i=o.rectBetween(e.pos-r,t.pos-r),s=e.node(0),l=o.cellsInRect(i).filter(e=>e!=t.pos-r);l.unshift(t.pos-r);const a=l.map(e=>{const t=n.nodeAt(e);if(!t)throw new RangeError(`No cell with offset ${e} found`);const o=r+e+1;return new it(s.resolve(o),s.resolve(o+t.content.size))});super(a[0].$from,a[0].$to,a),this.$anchorCell=e,this.$headCell=t}map(t,n){const o=t.resolve(n.map(this.$anchorCell.pos)),r=t.resolve(n.map(this.$headCell.pos));if(Ra(o)&&Ra(r)&&Ia(o,r)){const t=this.$anchorCell.node(-1)!=o.node(-1);return t&&this.isRowSelection()?e.rowSelection(o,r):t&&this.isColSelection()?e.colSelection(o,r):new e(o,r)}return at.between(o,r)}content(){const e=this.$anchorCell.node(-1),t=ka.get(e),n=this.$anchorCell.start(-1),o=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),r={},i=[];for(let n=o.top;n<o.bottom;n++){const l=[];for(let i=n*t.width+o.left,s=o.left;s<o.right;s++,i++){const n=t.map[i];if(r[n])continue;r[n]=!0;const s=t.findCell(n);let a=e.nodeAt(n);if(!a)throw new RangeError(`No cell with offset ${n} found`);const c=o.left-s.left,d=s.right-o.right;if(c>0||d>0){let e=a.attrs;if(c>0&&(e=Va(e,0,c)),d>0&&(e=Va(e,e.colspan-d,d)),s.left<o.left){if(a=a.type.createAndFill(e),!a)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else a=a.type.create(e,a.content)}if(s.top<o.top||s.bottom>o.bottom){const e={...a.attrs,rowspan:Math.min(s.bottom,o.bottom)-Math.max(s.top,o.top)};a=s.top<o.top?a.type.createAndFill(e):a.type.create(e,a.content)}l.push(a)}i.push(e.child(n).copy(s.from(l)))}const l=this.isColSelection()&&this.isRowSelection()?e:i;return new p(s.from(l),1,1)}replace(e,t=p.empty){const n=e.steps.length,o=this.ranges;for(let r=0;r<o.length;r++){const{$from:i,$to:s}=o[r],l=e.mapping.slice(n);e.replace(l.map(i.pos),l.map(s.pos),r?p.empty:t)}const r=rt.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);r&&e.setSelection(r)}replaceWith(e,t){this.replace(e,new p(s.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),n=ka.get(t),o=this.$anchorCell.start(-1),r=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-o,this.$headCell.pos-o));for(let n=0;n<r.length;n++)e(t.nodeAt(r[n]),o+r[n])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const n=e+this.$anchorCell.nodeAfter.attrs.rowspan,o=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,o)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){const o=t.node(-1),r=ka.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.top<=l.top?(s.top>0&&(t=a.resolve(i+r.map[s.left])),l.bottom<r.height&&(n=a.resolve(i+r.map[r.width*(r.height-1)+l.right-1]))):(l.top>0&&(n=a.resolve(i+r.map[l.left])),s.bottom<r.height&&(t=a.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new e(t,n)}isRowSelection(){const e=this.$anchorCell.node(-1),t=ka.get(e),n=this.$anchorCell.start(-1),o=t.colCount(this.$anchorCell.pos-n),r=t.colCount(this.$headCell.pos-n);if(Math.min(o,r)>0)return!1;const i=o+this.$anchorCell.nodeAfter.attrs.colspan,s=r+this.$headCell.nodeAfter.attrs.colspan;return Math.max(i,s)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){const o=t.node(-1),r=ka.get(o),i=t.start(-1),s=r.findCell(t.pos-i),l=r.findCell(n.pos-i),a=t.node(0);return s.left<=l.left?(s.left>0&&(t=a.resolve(i+r.map[s.top*r.width])),l.right<r.width&&(n=a.resolve(i+r.map[r.width*(l.top+1)-1]))):(l.left>0&&(n=a.resolve(i+r.map[l.top*r.width])),s.right<r.width&&(t=a.resolve(i+r.map[r.width*(s.top+1)-1]))),new e(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,o=n){return new e(t.resolve(n),t.resolve(o))}getBookmark(){return new _a(this.$anchorCell.pos,this.$headCell.pos)}};Ha.prototype.visible=!1,rt.jsonID("cell",Ha);var _a=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){const t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&Ia(t,n)?new Ha(t,n):rt.near(n,1)}};function Wa(e){if(!(e.selection instanceof Ha))return null;const t=[];return e.selection.forEachCell((e,n)=>{t.push(Nl.node(n,n+e.nodeSize,{class:"selectedCell"}))}),Tl.create(e.doc,t)}const qa=new Nt("fix-tables");function ja(e,t,n,o){const r=e.childCount,i=t.childCount;e:for(let s=0,l=0;s<i;s++){const i=t.child(s);for(let t=l,o=Math.min(r,s+3);t<o;t++)if(e.child(t)==i){l=t+1,n+=i.nodeSize;continue e}o(i,n),l<r&&e.child(l).sameMarkup(i)?ja(e.child(l),i,n+1,o):i.nodesBetween(0,i.content.size,o,n+1),n+=i.nodeSize}}function Ja(e,t){let n;const o=(t,o)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,o){const r=ka.get(t);if(!r.problems)return o;o||(o=e.tr);const i=[];for(let e=0;e<r.height;e++)i.push(0);for(let e=0;e<r.problems.length;e++){const s=r.problems[e];if("collision"==s.type){const e=t.nodeAt(s.pos);if(!e)continue;const r=e.attrs;for(let e=0;e<r.rowspan;e++)i[s.row+e]+=s.n;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,Va(r,r.colspan-s.n,s.n))}else if("missing"==s.type)i[s.row]+=s.n;else if("overlong_rowspan"==s.type){const e=t.nodeAt(s.pos);if(!e)continue;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-s.n})}else if("colwidth mismatch"==s.type){const e=t.nodeAt(s.pos);if(!e)continue;o.setNodeMarkup(o.mapping.map(n+1+s.pos),null,{...e.attrs,colwidth:s.colwidth})}else if("zero_sized"==s.type){const e=o.mapping.map(n);o.delete(e,e+t.nodeSize)}}let s,l;for(let e=0;e<i.length;e++)i[e]&&(null==s&&(s=e),l=e);for(let a=0,c=n+1;a<r.height;a++){const n=t.child(a),r=c+n.nodeSize,d=i[a];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);const i=[];for(let n=0;n<d;n++){const n=Oa(e.schema)[t].createAndFill();n&&i.push(n)}const h=0!=a&&s!=a-1||l!=a?r-1:c+1;o.insert(o.mapping.map(h),i)}c=r}return o.setMeta(qa,{fixTables:!0})}(e,t,o,n))};return t?t.doc!=e.doc&&ja(t.doc,e.doc,0,o):e.doc.descendants(o),n}function Ka(e){const t=e.selection,n=Ea(e),o=n.node(-1),r=n.start(-1),i=ka.get(o);return{...t instanceof Ha?i.rectBetween(t.$anchorCell.pos-r,t.$headCell.pos-r):i.findCell(n.pos-r),tableStart:r,map:i,table:o}}function Xa(e,{map:t,tableStart:n,table:o},r){let i=r>0?-1:0;La(t,o,r+i)&&(i=0==r||r==t.width?null:0);for(let s=0;s<t.height;s++){const l=s*t.width+r;if(r>0&&r<t.width&&t.map[l-1]==t.map[l]){const i=t.map[l],a=o.nodeAt(i);e.setNodeMarkup(e.mapping.map(n+i),null,Fa(a.attrs,r-t.colCount(i))),s+=a.attrs.rowspan-1}else{const a=null==i?Oa(o.type.schema).cell:o.nodeAt(t.map[l+i]).type,c=t.positionAt(s,r,o);e.insert(e.mapping.map(n+c),a.createAndFill())}}return e}function Ua(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(Xa(e.tr,n,n.left))}return!0}function Ga(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(Xa(e.tr,n,n.right))}return!0}function Ya(e,{map:t,table:n,tableStart:o},r){const i=e.mapping.maps.length;for(let s=0;s<t.height;){const l=s*t.width+r,a=t.map[l],c=n.nodeAt(a),d=c.attrs;if(r>0&&t.map[l-1]==a||r<t.width-1&&t.map[l+1]==a)e.setNodeMarkup(e.mapping.slice(i).map(o+a),null,Va(d,r-t.colCount(a)));else{const t=e.mapping.slice(i).map(o+a);e.delete(t,t+c.nodeSize)}s+=d.rowspan}}function Qa(e,t){if(!Da(e))return!1;if(t){const n=Ka(e),o=e.tr;if(0==n.left&&n.right==n.map.width)return!1;for(let e=n.right-1;Ya(o,n,e),e!=n.left;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw new RangeError("No table found");n.table=e,n.map=ka.get(e)}t(o)}return!0}function Za(e,t,n){var o;const r=Oa(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if((null===(o=t.nodeAt(e.map[i+n*e.width]))||void 0===o?void 0:o.type)!=r)return!1;return!0}function ec(e,{map:t,tableStart:n,table:o},r){let i=n;for(let e=0;e<r;e++)i+=o.child(e).nodeSize;const s=[];let l=r>0?-1:0;Za(t,o,r+l)&&(l=0==r||r==t.height?null:0);for(let i=0,c=t.width*r;i<t.width;i++,c++)if(r>0&&r<t.height&&t.map[c]==t.map[c-t.width]){const r=t.map[c],s=o.nodeAt(r).attrs;e.setNodeMarkup(n+r,null,{...s,rowspan:s.rowspan+1}),i+=s.colspan-1}else{var a;const e=null==l?Oa(o.type.schema).cell:null===(a=o.nodeAt(t.map[c+l*t.width]))||void 0===a?void 0:a.type,n=null==e?void 0:e.createAndFill();n&&s.push(n)}return e.insert(i,Oa(o.type.schema).row.create(null,s)),e}function tc(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(ec(e.tr,n,n.top))}return!0}function nc(e,t){if(!Da(e))return!1;if(t){const n=Ka(e);t(ec(e.tr,n,n.bottom))}return!0}function oc(e,{map:t,table:n,tableStart:o},r){let i=0;for(let e=0;e<r;e++)i+=n.child(e).nodeSize;const s=i+n.child(r).nodeSize,l=e.mapping.maps.length;e.delete(i+o,s+o);const a=new Set;for(let i=0,s=r*t.width;i<t.width;i++,s++){const c=t.map[s];if(!a.has(c))if(a.add(c),r>0&&c==t.map[s-t.width]){const t=n.nodeAt(c).attrs;e.setNodeMarkup(e.mapping.slice(l).map(c+o),null,{...t,rowspan:t.rowspan-1}),i+=t.colspan-1}else if(r<t.height&&c==t.map[s+t.width]){const s=n.nodeAt(c),a=s.attrs,d=s.type.create({...a,rowspan:s.attrs.rowspan-1},s.content),h=t.positionAt(r+1,i,n);e.insert(e.mapping.slice(l).map(o+h),d),i+=a.colspan-1}}}function rc(e,t){if(!Da(e))return!1;if(t){const n=Ka(e),o=e.tr;if(0==n.top&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;oc(o,n,e),e!=n.top;e--){const e=n.tableStart?o.doc.nodeAt(n.tableStart-1):o.doc;if(!e)throw new RangeError("No table found");n.table=e,n.map=ka.get(n.table)}t(o)}return!0}function ic(e){const t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function sc(e,t){const n=e.selection;if(!(n instanceof Ha)||n.$anchorCell.pos==n.$headCell.pos)return!1;const o=Ka(e),{map:r}=o;if(function({width:e,height:t,map:n},o){let r=o.top*e+o.left,i=r,s=(o.bottom-1)*e+o.left,l=r+(o.right-o.left-1);for(let t=o.top;t<o.bottom;t++){if(o.left>0&&n[i]==n[i-1]||o.right<e&&n[l]==n[l+1])return!0;i+=e,l+=e}for(let i=o.left;i<o.right;i++){if(o.top>0&&n[r]==n[r-e]||o.bottom<t&&n[s]==n[s+e])return!0;r++,s++}return!1}(r,o))return!1;if(t){const n=e.tr,i={};let l,a,c=s.empty;for(let e=o.top;e<o.bottom;e++)for(let t=o.left;t<o.right;t++){const s=r.map[e*r.width+t],d=o.table.nodeAt(s);if(!i[s]&&d)if(i[s]=!0,null==l)l=s,a=d;else{ic(d)||(c=c.append(d.content));const e=n.mapping.map(s+o.tableStart);n.delete(e,e+d.nodeSize)}}if(null==l||null==a)return!0;if(n.setNodeMarkup(l+o.tableStart,null,{...Fa(a.attrs,a.attrs.colspan,o.right-o.left-a.attrs.colspan),rowspan:o.bottom-o.top}),c.size>0){const e=l+1+a.content.size,t=ic(a)?l+1:e;n.replaceWith(t+o.tableStart,e+o.tableStart,c)}n.setSelection(new Ha(n.doc.resolve(l+o.tableStart))),t(n)}return!0}function lc(e,t){const n=Oa(e.schema);return ac(({node:e})=>n[e.type.spec.tableRole])(e,t)}function ac(e){return(t,n)=>{const o=t.selection;let r,i;if(o instanceof Ha){if(o.$anchorCell.pos!=o.$headCell.pos)return!1;r=o.$anchorCell.nodeAfter,i=o.$anchorCell.pos}else{var s;if(r=function(e){for(let t=e.depth;t>0;t--){const n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(o.$from),!r)return!1;i=null===(s=Ta(o.$from))||void 0===s?void 0:s.pos}if(null==r||null==i)return!1;if(1==r.attrs.colspan&&1==r.attrs.rowspan)return!1;if(n){let s=r.attrs;const l=[],a=s.colwidth;s.rowspan>1&&(s={...s,rowspan:1}),s.colspan>1&&(s={...s,colspan:1});const c=Ka(t),d=t.tr;for(let e=0;e<c.right-c.left;e++)l.push(a?{...s,colwidth:a&&a[e]?[a[e]]:null}:s);let h;for(let t=c.top;t<c.bottom;t++){let n=c.map.positionAt(t,c.left,c.table);t==c.top&&(n+=r.nodeSize);for(let o=c.left,i=0;o<c.right;o++,i++)o==c.left&&t==c.top||d.insert(h=d.mapping.map(n+c.tableStart,1),e({node:r,row:t,col:o}).createAndFill(l[i]))}d.setNodeMarkup(i,e({node:r,row:c.top,col:c.left}),l[0]),o instanceof Ha&&d.setSelection(new Ha(d.doc.resolve(o.$anchorCell.pos),h?d.doc.resolve(h):void 0)),n(d)}return!0}}function cc(e,t){return function(n,o){if(!Da(n))return!1;const r=Ea(n);if(r.nodeAfter.attrs[e]===t)return!1;if(o){const i=n.tr;n.selection instanceof Ha?n.selection.forEachCell((n,o)=>{n.attrs[e]!==t&&i.setNodeMarkup(o,null,{...n.attrs,[e]:t})}):i.setNodeMarkup(r.pos,null,{...r.nodeAfter.attrs,[e]:t}),o(i)}return!0}}function dc(e,t,n){const o=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let e=0;e<o.length;e++){const r=t.table.nodeAt(o[e]);if(r&&r.type!==n.header_cell)return!1}return!0}function hc(e,t){return(t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic?function(e){return function(t,n){if(!Da(t))return!1;if(n){const o=Oa(t.schema),r=Ka(t),i=t.tr,s=r.map.cellsInRect("column"==e?{left:r.left,top:0,right:r.right,bottom:r.map.height}:"row"==e?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),l=s.map(e=>r.table.nodeAt(e));for(let e=0;e<s.length;e++)l[e].type==o.header_cell&&i.setNodeMarkup(r.tableStart+s[e],o.cell,l[e].attrs);if(0===i.steps.length)for(let e=0;e<s.length;e++)i.setNodeMarkup(r.tableStart+s[e],o.header_cell,l[e].attrs);n(i)}return!0}}(e):function(t,n){if(!Da(t))return!1;if(n){const o=Oa(t.schema),r=Ka(t),i=t.tr,s=dc("row",r,o),l=dc("column",r,o),a=("column"===e?s:"row"===e&&l)?1:0,c="column"==e?{left:0,top:a,right:1,bottom:r.map.height}:"row"==e?{left:a,top:0,right:r.map.width,bottom:1}:r,d="column"==e?l?o.cell:o.header_cell:"row"==e?s?o.cell:o.header_cell:o.cell;r.map.cellsInRect(c).forEach(e=>{const t=e+r.tableStart,n=i.doc.nodeAt(t);n&&i.setNodeMarkup(t,d,n.attrs)}),n(i)}return!0}}const pc=hc("row",{useDeprecatedLogic:!0}),uc=hc("column",{useDeprecatedLogic:!0}),fc=hc("cell",{useDeprecatedLogic:!0});function mc(e){return function(t,n){if(!Da(t))return!1;const o=function(e,t){if(t<0){const t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){const o=e.node(-1).child(t),r=o.lastChild;if(r)return n-1-r.nodeSize;n-=o.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;const t=e.node(-1);for(let n=e.indexAfter(-1),o=e.after();n<t.childCount;n++){const e=t.child(n);if(e.childCount)return o+1;o+=e.nodeSize}}return null}(Ea(t),e);if(null==o)return!1;if(n){const e=t.doc.resolve(o);n(t.tr.setSelection(at.between(e,$a(e))).scrollIntoView())}return!0}}function gc(e,t){const n=e.selection.$anchor;for(let o=n.depth;o>0;o--)if("table"==n.node(o).type.spec.tableRole)return t&&t(e.tr.delete(n.before(o),n.after(o)).scrollIntoView()),!0;return!1}function yc(e,t){const n=e.selection;if(!(n instanceof Ha))return!1;if(t){const o=e.tr,r=Oa(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(r)||o.replace(o.mapping.map(t+1),o.mapping.map(t+e.nodeSize-1),new p(r,0,0))}),o.docChanged&&t(o)}return!0}function wc(e,t){const n=e.createAndFill();return new nt(n).replace(0,n.content.size,t).doc}function vc(e,t,n,o,r,i,s,l){if(0==s||s==t.height)return!1;let a=!1;for(let c=r;c<i;c++){const r=s*t.width+c,i=t.map[r];if(t.map[r-t.width]==i){a=!0;const r=n.nodeAt(i),{top:d,left:h}=t.findCell(i);e.setNodeMarkup(e.mapping.slice(l).map(i+o),null,{...r.attrs,rowspan:s-d}),e.insert(e.mapping.slice(l).map(t.positionAt(s,h,n)),r.type.createAndFill({...r.attrs,rowspan:d+r.attrs.rowspan-s})),c+=r.attrs.colspan-1}}return a}function bc(e,t,n,o,r,i,s,l){if(0==s||s==t.width)return!1;let a=!1;for(let c=r;c<i;c++){const r=c*t.width+s,i=t.map[r];if(t.map[r-1]==i){a=!0;const r=n.nodeAt(i),d=t.colCount(i),h=e.mapping.slice(l).map(i+o);e.setNodeMarkup(h,null,Va(r.attrs,s-d,r.attrs.colspan-(s-d))),e.insert(h+r.nodeSize,r.type.createAndFill(Va(r.attrs,0,s-d))),c+=r.attrs.rowspan-1}}return a}function kc(e,t,n,o,r){let i=n?e.doc.nodeAt(n-1):e.doc;if(!i)throw new Error("No table found");let l=ka.get(i);const{top:a,left:c}=o,d=c+r.width,h=a+r.height,u=e.tr;let f=0;function m(){if(i=n?u.doc.nodeAt(n-1):u.doc,!i)throw new Error("No table found");l=ka.get(i),f=u.mapping.maps.length}(function(e,t,n,o,r,i,l){const a=Oa(e.doc.type.schema);let c,d;if(r>t.width)for(let i=0,s=0;i<t.height;i++){const h=n.child(i);s+=h.nodeSize;const p=[];let u;u=null==h.lastChild||h.lastChild.type==a.cell?c||(c=a.cell.createAndFill()):d||(d=a.header_cell.createAndFill());for(let e=t.width;e<r;e++)p.push(u);e.insert(e.mapping.slice(l).map(s-1+o),p)}if(i>t.height){const h=[];for(let e=0,o=(t.height-1)*t.width;e<Math.max(t.width,r);e++){const r=!(e>=t.width)&&n.nodeAt(t.map[o+e]).type==a.header_cell;h.push(r?d||(d=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const p=a.row.create(null,s.from(h)),u=[];for(let e=t.height;e<i;e++)u.push(p);e.insert(e.mapping.slice(l).map(o+n.nodeSize-2),u)}return!(!c&&!d)})(u,l,i,n,d,h,f)&&m(),vc(u,l,i,n,c,d,a,f)&&m(),vc(u,l,i,n,c,d,h,f)&&m(),bc(u,l,i,n,a,h,c,f)&&m(),bc(u,l,i,n,a,h,d,f)&&m();for(let e=a;e<h;e++){const t=l.positionAt(e,c,i),o=l.positionAt(e,d,i);u.replace(u.mapping.slice(f).map(t+n),u.mapping.slice(f).map(o+n),new p(r.rows[e-a],0,0))}m(),u.setSelection(new Ha(u.doc.resolve(n+l.positionAt(a,c,i)),u.doc.resolve(n+l.positionAt(h-1,d-1,i)))),t(u)}const xc=wa({ArrowLeft:Cc("horiz",-1),ArrowRight:Cc("horiz",1),ArrowUp:Cc("vert",-1),ArrowDown:Cc("vert",1),"Shift-ArrowLeft":Mc("horiz",-1),"Shift-ArrowRight":Mc("horiz",1),"Shift-ArrowUp":Mc("vert",-1),"Shift-ArrowDown":Mc("vert",1),Backspace:yc,"Mod-Backspace":yc,Delete:yc,"Mod-Delete":yc});function Sc(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function Cc(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;if(i instanceof Ha)return Sc(n,o,rt.near(i.$headCell,t));if("horiz"!=e&&!i.empty)return!1;const s=Tc(r,e,t);if(null==s)return!1;if("horiz"==e)return Sc(n,o,rt.near(n.doc.resolve(i.head+t),t));{const r=n.doc.resolve(s),i=Pa(r,e,t);let l;return l=i?rt.near(i,1):t<0?rt.near(n.doc.resolve(r.before(-1)),-1):rt.near(n.doc.resolve(r.after(-1)),1),Sc(n,o,l)}}}function Mc(e,t){return(n,o,r)=>{if(!r)return!1;const i=n.selection;let s;if(i instanceof Ha)s=i;else{const o=Tc(r,e,t);if(null==o)return!1;s=new Ha(n.doc.resolve(o))}const l=Pa(s.$headCell,e,t);return!!l&&Sc(n,o,new Ha(s.$anchorCell,l))}}function Nc(e,t){const n=Ta(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new Ha(n))),!0)}function Oc(e,t,n){if(!Da(e.state))return!1;let o=function(e){if(0===e.size)return null;let{content:t,openStart:n,openEnd:o}=e;for(;1==t.childCount&&(n>0&&o>0||"table"==t.child(0).type.spec.tableRole);)n--,o--,t=t.child(0).content;const r=t.child(0),i=r.type.spec.tableRole,l=r.type.schema,a=[];if("row"==i)for(let e=0;e<t.childCount;e++){let r=t.child(e).content;const i=e?0:Math.max(0,n-1),s=e<t.childCount-1?0:Math.max(0,o-1);(i||s)&&(r=wc(Oa(l).row,new p(r,i,s)).content),a.push(r)}else{if("cell"!=i&&"header_cell"!=i)return null;a.push(n||o?wc(Oa(l).row,new p(t,n,o)).content:t)}return function(e,t){const n=[];for(let e=0;e<t.length;e++){const o=t[e];for(let t=o.childCount-1;t>=0;t--){const{rowspan:r,colspan:i}=o.child(t).attrs;for(let t=e;t<e+r;t++)n[t]=(n[t]||0)+i}}let o=0;for(let e=0;e<n.length;e++)o=Math.max(o,n[e]);for(let r=0;r<n.length;r++)if(r>=t.length&&t.push(s.empty),n[r]<o){const i=Oa(e).cell.createAndFill(),l=[];for(let e=n[r];e<o;e++)l.push(i);t[r]=t[r].append(s.from(l))}return{height:t.length,width:o,rows:t}}(l,a)}(n);const r=e.state.selection;if(r instanceof Ha){o||(o={width:1,height:1,rows:[s.from(wc(Oa(e.state.schema).cell,n))]});const t=r.$anchorCell.node(-1),i=r.$anchorCell.start(-1),l=ka.get(t).rectBetween(r.$anchorCell.pos-i,r.$headCell.pos-i);return o=function({width:e,height:t,rows:n},o,r){if(e!=o){const t=[],r=[];for(let e=0;e<n.length;e++){const i=n[e],l=[];for(let n=t[e]||0,r=0;n<o;r++){let s=i.child(r%i.childCount);n+s.attrs.colspan>o&&(s=s.type.createChecked(Va(s.attrs,s.attrs.colspan,n+s.attrs.colspan-o),s.content)),l.push(s),n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+s.attrs.colspan}r.push(s.from(l))}n=r,e=o}if(t!=r){const e=[];for(let o=0,i=0;o<r;o++,i++){const l=[],a=n[i%t];for(let e=0;e<a.childCount;e++){let t=a.child(e);o+t.attrs.rowspan>r&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,r-t.attrs.rowspan)},t.content)),l.push(t)}e.push(s.from(l))}n=e,t=r}return{width:e,height:t,rows:n}}(o,l.right-l.left,l.bottom-l.top),kc(e.state,e.dispatch,i,l,o),!0}if(o){const t=Ea(e.state),n=t.start(-1);return kc(e.state,e.dispatch,n,ka.get(t.node(-1)).findCell(t.pos-n),o),!0}return!1}function Ac(e,t){var n;if(0!=t.button)return;if(t.ctrlKey||t.metaKey)return;const o=Dc(e,t.target);let r;if(t.shiftKey&&e.state.selection instanceof Ha)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&o&&null!=(r=Ta(e.state.selection.$anchor))&&(null===(n=Ec(e,t))||void 0===n?void 0:n.pos)!=r.pos)i(r,t),t.preventDefault();else if(!o)return;function i(t,n){let o=Ec(e,n);const r=null==Aa.getState(e.state);if(!o||!Ia(t,o)){if(!r)return;o=t}const i=new Ha(t,o);if(r||!e.state.selection.eq(i)){const n=e.state.tr.setSelection(i);r&&n.setMeta(Aa,t.pos),e.dispatch(n)}}function s(){e.root.removeEventListener("mouseup",s),e.root.removeEventListener("dragstart",s),e.root.removeEventListener("mousemove",l),null!=Aa.getState(e.state)&&e.dispatch(e.state.tr.setMeta(Aa,-1))}function l(n){const r=n,l=Aa.getState(e.state);let a;if(null!=l)a=e.state.doc.resolve(l);else if(Dc(e,r.target)!=o&&(a=Ec(e,t),!a))return s();a&&i(a,r)}e.root.addEventListener("mouseup",s),e.root.addEventListener("dragstart",s),e.root.addEventListener("mousemove",l)}function Tc(e,t,n){if(!(e.state.selection instanceof at))return null;const{$head:o}=e.state.selection;for(let r=o.depth-1;r>=0;r--){const i=o.node(r);if((n<0?o.index(r):o.indexAfter(r))!=(n<0?0:i.childCount))return null;if("cell"==i.type.spec.tableRole||"header_cell"==i.type.spec.tableRole){const i=o.before(r),s="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(s)?i:null}}return null}function Dc(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function Ec(e,t){const n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:o,pos:r}=n;return o>=0&&Ta(e.state.doc.resolve(o))||Ta(e.state.doc.resolve(r))}var Rc=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),$c(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,$c(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function $c(e,t,n,o,r,i){let s=0,l=!0,a=t.firstChild;const c=e.firstChild;if(c){for(let e=0,n=0;e<c.childCount;e++){const{colspan:d,colwidth:h}=c.child(e).attrs;for(let e=0;e<d;e++,n++){const c=r==n?i:h&&h[e],d=c?c+"px":"";if(s+=c||o,c||(l=!1),a)a.style.width!=d&&(a.style.width=d),a=a.nextSibling;else{const e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;a;){var d;const e=a.nextSibling;null===(d=a.parentNode)||void 0===d||d.removeChild(a),a=e}l?(n.style.width=s+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=s+"px")}}const Ic=new Nt("tableColumnResizing");function zc({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:o=Rc,lastColumnResizable:r=!0}={}){const i=new St({key:Ic,state:{init(e,t){var r;const s=null===(r=i.spec)||void 0===r||null===(r=r.props)||void 0===r?void 0:r.nodeViews,l=Oa(t.schema).table.name;return o&&s&&(s[l]=(e,t)=>new o(e,n,t)),new Bc(-1,!1)},apply:(e,t)=>t.apply(e)},props:{attributes:e=>{const t=Ic.getState(e);return t&&t.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(t,n)=>{!function(e,t,n,o){if(!e.editable)return;const r=Ic.getState(e.state);if(r&&!r.dragging){const i=function(e){for(;e&&"TD"!=e.nodeName&&"TH"!=e.nodeName;)e=e.classList&&e.classList.contains("ProseMirror")?null:e.parentNode;return e}(t.target);let s=-1;if(i){const{left:o,right:r}=i.getBoundingClientRect();t.clientX-o<=n?s=Pc(e,t,"left",n):r-t.clientX<=n&&(s=Pc(e,t,"right",n))}if(s!=r.activeHandle){if(!o&&-1!==s){const t=e.state.doc.resolve(s),n=t.node(-1),o=ka.get(n),r=t.start(-1);if(o.colCount(t.pos-r)+t.nodeAfter.attrs.colspan-1==o.width-1)return}Fc(e,s)}}}(t,n,e,r)},mouseleave:e=>{!function(e){if(!e.editable)return;const t=Ic.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Fc(e,-1)}(e)},mousedown:(e,o)=>{!function(e,t,n,o){var r;if(!e.editable)return!1;const i=null!==(r=e.dom.ownerDocument.defaultView)&&void 0!==r?r:window,s=Ic.getState(e.state);if(!s||-1==s.activeHandle||s.dragging)return!1;const l=e.state.doc.nodeAt(s.activeHandle),a=function(e,t,{colspan:n,colwidth:o}){const r=o&&o[o.length-1];if(r)return r;const i=e.domAtPos(t);let s=i.node.childNodes[i.offset].offsetWidth,l=n;if(o)for(let e=0;e<n;e++)o[e]&&(s-=o[e],l--);return s/l}(e,s.activeHandle,l.attrs);function c(t){i.removeEventListener("mouseup",c),i.removeEventListener("mousemove",d);const o=Ic.getState(e.state);(null==o?void 0:o.dragging)&&(function(e,t,n){const o=e.state.doc.resolve(t),r=o.node(-1),i=ka.get(r),s=o.start(-1),l=i.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1,a=e.state.tr;for(let e=0;e<i.height;e++){const t=e*i.width+l;if(e&&i.map[t]==i.map[t-i.width])continue;const o=i.map[t],c=r.nodeAt(o).attrs,d=1==c.colspan?0:l-i.colCount(o);if(c.colwidth&&c.colwidth[d]==n)continue;const h=c.colwidth?c.colwidth.slice():Hc(c.colspan);h[d]=n,a.setNodeMarkup(s+o,null,{...c,colwidth:h})}a.docChanged&&e.dispatch(a)}(e,o.activeHandle,Vc(o.dragging,t,n)),e.dispatch(e.state.tr.setMeta(Ic,{setDragging:null})))}function d(t){if(!t.which)return c(t);const r=Ic.getState(e.state);if(r&&r.dragging){const i=Vc(r.dragging,t,n);Lc(e,r.activeHandle,i,o)}}e.dispatch(e.state.tr.setMeta(Ic,{setDragging:{startX:t.clientX,startWidth:a}})),Lc(e,s.activeHandle,a,o),i.addEventListener("mouseup",c),i.addEventListener("mousemove",d),t.preventDefault()}(e,o,t,n)}},decorations:e=>{const t=Ic.getState(e);if(t&&t.activeHandle>-1)return function(e,t){const n=[],o=e.doc.resolve(t),r=o.node(-1);if(!r)return Tl.empty;const i=ka.get(r),s=o.start(-1),l=i.colCount(o.pos-s)+o.nodeAfter.attrs.colspan-1;for(let t=0;t<i.height;t++){const o=l+t*i.width;if(!(l!=i.width-1&&i.map[o]==i.map[o+1]||0!=t&&i.map[o]==i.map[o-i.width])){var a;const t=i.map[o],l=s+t+r.nodeAt(t).nodeSize-1,c=document.createElement("div");c.className="column-resize-handle",(null===(a=Ic.getState(e))||void 0===a?void 0:a.dragging)&&n.push(Nl.node(s+t,s+t+r.nodeAt(t).nodeSize,{class:"column-resize-dragging"})),n.push(Nl.widget(l,c))}}return Tl.create(e.doc,n)}(e,t.activeHandle)},nodeViews:{}}});return i}var Bc=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){const n=this,o=t.getMeta(Ic);if(o&&null!=o.setHandle)return new e(o.setHandle,!1);if(o&&void 0!==o.setDragging)return new e(n.activeHandle,o.setDragging);if(n.activeHandle>-1&&t.docChanged){let o=t.mapping.map(n.activeHandle,-1);return Ra(t.doc.resolve(o))||(o=-1),new e(o,n.dragging)}return n}};function Pc(e,t,n,o){const r="right"==n?-o:o,i=e.posAtCoords({left:t.clientX+r,top:t.clientY});if(!i)return-1;const{pos:s}=i,l=Ta(e.state.doc.resolve(s));if(!l)return-1;if("right"==n)return l.pos;const a=ka.get(l.node(-1)),c=l.start(-1),d=a.map.indexOf(l.pos-c);return d%a.width==0?-1:c+a.map[d-1]}function Vc(e,t,n){const o=t.clientX-e.startX;return Math.max(n,e.startWidth+o)}function Fc(e,t){e.dispatch(e.state.tr.setMeta(Ic,{setHandle:t}))}function Lc(e,t,n,o){const r=e.state.doc.resolve(t),i=r.node(-1),s=r.start(-1),l=ka.get(i).colCount(r.pos-s)+r.nodeAfter.attrs.colspan-1;let a=e.domAtPos(r.start(-1)).node;for(;a&&"TABLE"!=a.nodeName;)a=a.parentNode;a&&$c(i,a.firstChild,a,o,l,n)}function Hc(e){return Array(e).fill(0)}function _c({allowTableNodeSelection:e=!1}={}){return new St({key:Aa,state:{init:()=>null,apply(e,t){const n=e.getMeta(Aa);if(null!=n)return-1==n?null:n;if(null==t||!e.docChanged)return t;const{deleted:o,pos:r}=e.mapping.mapResult(t);return o?null:r}},props:{decorations:Wa,handleDOMEvents:{mousedown:Ac},createSelectionBetween:e=>null!=Aa.getState(e.state)?e.state.selection:null,handleTripleClick:Nc,handleKeyDown:xc,handlePaste:Oc},appendTransaction:(t,n,o)=>function(e,t,n){const o=(t||e).selection,r=(t||e).doc;let i,s;if(o instanceof dt&&(s=o.node.type.spec.tableRole)){if("cell"==s||"header_cell"==s)i=Ha.create(r,o.from);else if("row"==s){const e=r.resolve(o.from+1);i=Ha.rowSelection(e,e)}else if(!n){const e=ka.get(o.node),t=o.from+1,n=t+e.map[e.width*e.height-1];i=Ha.create(r,t+1,n)}}else o instanceof at&&function({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,o=t.pos,r=e.depth;for(;r>=0&&!(e.after(r+1)<e.end(r));r--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,o--);return n==o&&/row|table/.test(e.node(r).type.spec.tableRole)}(o)?i=at.create(r,o.from):o instanceof at&&function({$from:e,$to:t}){let n,o;for(let t=e.depth;t>0;t--){const o=e.node(t);if("cell"===o.type.spec.tableRole||"header_cell"===o.type.spec.tableRole){n=o;break}}for(let e=t.depth;e>0;e--){const n=t.node(e);if("cell"===n.type.spec.tableRole||"header_cell"===n.type.spec.tableRole){o=n;break}}return n!==o&&0===t.parentOffset}(o)&&(i=at.create(r,o.$from.start(),o.$from.end()));return i&&(t||(t=e.tr)).setSelection(i),t}(o,Ja(o,n),e)})}const Wc=["blockquote",0],qc=["hr"],jc=["pre",["code",0]],Jc=["ol",0],Kc=["ul",0],Xc=["li",0],Uc=e=>{const t={},n=e.attributes;let o;for(let e=0;e<n.length;e++)o=n[e],t[o.name]=o.value;return t},Gc=e=>{const t={};return e.forEach(e=>{t[e]={default:null}}),t},Yc=()=>Gc(["style","class","id"]),Qc=(e,t)=>{for(const n in e)if(n&&null!==e[n]&&n!==t)return!0;return!1},Zc=(e,t=[])=>{const n={};for(const o in e)o&&null!==e[o]&&!t.find(e=>e===o)&&(n[o]=e[o]);return n},ed=e=>({[e]:{name:e,inclusive:!0,parseDOM:[{tag:e}],toDOM:()=>[e,0]}}),td={link:{attrs:{...Yc(),href:{default:null},target:{default:null},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a",getAttrs:Uc}],toDOM:e=>["a",Zc(e.attrs),0]},...ed("strong"),...ed("b"),...ed("em"),...ed("i"),...ed("del"),...ed("sub"),...ed("sup"),...ed("code"),style:{attrs:{...Yc()},parseDOM:[{tag:"span",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["span",Zc(e.attrs),0]:["span",0]},...ed("u")},nd=e=>({[e]:{default:null,getFromDOM:t=>t.getAttribute(e),setDOMAttr:(t,n)=>{n[e]=t}}}),od={...nd("style"),...nd("class"),...nd("id"),...nd("headers"),...nd("scope")},rd={doc:{content:"colgroup*"},col:{attrs:Gc(["id","class","style","span"]),parseDOM:[{getAttrs:Uc,tag:"col"}],toDOM:e=>["col",e.attrs]},colgroup:{attrs:Gc(["id","class","style","span"]),content:"col*",parseDOM:[{getAttrs:Uc,tag:"colgroup"}],toDOM:e=>["colgroup",e.attrs,0]},text:{inline:!0,group:"inline"}},id=new U({nodes:rd,marks:{}}),sd=e=>{const t=An(Mn(e),id,{preserveWhitespace:!1});return On(t).firstChild},ld=Na({tableGroup:"block",cellContent:"block+",cellAttributes:od});ld.table_row.attrs={...ld.table_row.attrs,...Gc([Ot,"style","class","id"])},ld.table_row.toDOM=e=>["tr",Zc(e.attrs),0],ld.table_row.parseDOM=[{tag:"tr",getAttrs:Uc}],ld.table.attrs={...ld.table.attrs,...Gc(["style","class","id",At,Tt])},ld.table.toDOM=e=>{const t=Qc(e.attrs)?Zc(e.attrs,[At,Tt]):{};let n=null;if(e.attrs[At]&&!(e=>{let t=!1;const n=e.child(0);for(let e=0;e<n.childCount;e++)if(n.child(e).attrs.colwidth){t=!0;break}return t})(e)){const t=sd(e.attrs[At]);if(t){const e=Array.from(t.children).map(e=>["col",Uc(e)]);n=["colgroup",Uc(t)].concat(e)}}return n?["table",t,n,["tbody",0]]:["table",t,["tbody",0]]},ld.table.parseDOM=[{tag:"table",getAttrs:e=>{const t=Uc(e),n=Array.from(e.childNodes).find(e=>"COLGROUP"===e.nodeName);return n&&(t[At]=n.outerHTML),t}}];const ad={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",attrs:{...Yc()},parseDOM:[{tag:"p",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["p",Zc(e.attrs),0]:["p",0]},table_wrapper:{content:"(table_caption_external | table)+",group:"block",defining:!0,attrs:{table:{default:null},style:{default:null}},parseDOM:[{tag:"div[table]",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["div",Zc(e.attrs),0]:["div",0]},table_caption_external:{content:"inline+",group:"block",attrs:{caption:{default:null},...Yc()},parseDOM:[{tag:"div[caption]",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["div",Zc(e.attrs),0]:["div",0]},div:{content:"block*",group:"block",attrs:{...Yc()},parseDOM:[{tag:"div",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["div",Zc(e.attrs),0]:["div",0]},blockquote:{attrs:{...Yc()},content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["blockquote",Zc(e.attrs),0]:Wc},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>qc},heading:{attrs:{...Yc(),level:{default:1}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",getAttrs:e=>({...Uc(e),level:1})},{tag:"h2",getAttrs:e=>({...Uc(e),level:2})},{tag:"h3",getAttrs:e=>({...Uc(e),level:3})},{tag:"h4",getAttrs:e=>({...Uc(e),level:4})},{tag:"h5",getAttrs:e=>({...Uc(e),level:5})},{tag:"h6",getAttrs:e=>({...Uc(e),level:6})}],toDOM:e=>Qc(e.attrs,"level")?["h"+e.attrs.level,Zc(e.attrs,["level"]),0]:["h"+e.attrs.level,0]},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM:()=>jc},text:{inline:!0,group:"inline"},image:{inline:!0,attrs:{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null},...Yc()},group:"inline",draggable:!0,parseDOM:[{tag:"img",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["img",Zc(e.attrs)]:["img"]},hard_break:{inline:!0,attrs:{...Yc()},group:"inline",selectable:!1,parseDOM:[{tag:"br",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["br",Zc(e.attrs)]:["br"]},ordered_list:{content:"list_item+",group:"block",attrs:{...Yc(),type:{default:null},order:{default:1}},parseDOM:[{tag:"ol",getAttrs:e=>({...Uc(e),order:e.hasAttribute("start")?parseInt(e.getAttribute("start")||"1",10):1})}],toDOM:e=>1===e.attrs.order?Qc(e.attrs,"order")?["ol",Zc(e.attrs,["order"]),0]:Jc:["ol",{...Zc(e.attrs,["order"]),start:e.attrs.order},0]},bullet_list:{content:"list_item+",group:"block",attrs:{...Yc()},parseDOM:[{tag:"ul",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["ul",Zc(e.attrs),0]:Kc},list_item:{content:"(paragraph | heading) block*",attrs:{...Yc()},parseDOM:[{tag:"li",getAttrs:Uc}],toDOM:e=>Qc(e.attrs)?["li",Zc(e.attrs),0]:Xc,defining:!0},...ld};var cd=200,dd=function(){};dd.prototype.append=function(e){return e.length?(e=dd.from(e),!this.length&&e||e.length<cd&&this.leafAppend(e)||this.length<cd&&e.leafPrepend(this)||this.appendInner(e)):this},dd.prototype.prepend=function(e){return e.length?dd.from(e).append(this):this},dd.prototype.appendInner=function(e){return new pd(this,e)},dd.prototype.slice=function(e,t){return void 0===e&&(e=0),void 0===t&&(t=this.length),e>=t?dd.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},dd.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},dd.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)},dd.prototype.map=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=this.length);var o=[];return this.forEach(function(t,n){return o.push(e(t,n))},t,n),o},dd.from=function(e){return e instanceof dd?e:e&&e.length?new hd(e):dd.empty};var hd=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,o){for(var r=t;r<n;r++)if(!1===e(this.values[r],o+r))return!1},t.prototype.forEachInvertedInner=function(e,t,n,o){for(var r=t-1;r>=n;r--)if(!1===e(this.values[r],o+r))return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=cd)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=cd)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(dd);dd.empty=new hd([]);var pd=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,o){var r=this.left.length;return!(t<r&&!1===this.left.forEachInner(e,t,Math.min(n,r),o))&&!(n>r&&!1===this.right.forEachInner(e,Math.max(t-r,0),Math.min(this.length,n)-r,o+r))&&void 0},t.prototype.forEachInvertedInner=function(e,t,n,o){var r=this.left.length;return!(t>r&&!1===this.right.forEachInvertedInner(e,t-r,Math.max(n,r)-r,o+r))&&!(n<r&&!1===this.left.forEachInvertedInner(e,Math.min(t,r),n,o))&&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}(dd);const ud=dd;class fd{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(0==this.eventCount)return null;let n,o,r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}t&&(n=this.remapping(r,this.items.length),o=n.maps.length);let i,s,l=e.tr,a=[],c=[];return this.items.forEach((e,t)=>{if(!e.step)return n||(n=this.remapping(r,t+1),o=n.maps.length),o--,void c.push(e);if(n){c.push(new md(e.map));let t,r=e.step.map(n.slice(o));r&&l.maybeStep(r).doc&&(t=l.mapping.maps[l.mapping.maps.length-1],a.push(new md(t,void 0,void 0,a.length+c.length))),o--,t&&n.appendMap(t,o)}else l.maybeStep(e.step);return e.selection?(i=n?e.selection.map(n.slice(o)):e.selection,s=new fd(this.items.slice(0,r).append(c.reverse().concat(a)),this.eventCount-1),!1):void 0},this.items.length,0),{remaining:s,transform:l,selection:i}}addTransform(e,t,n,o){let r=[],i=this.eventCount,s=this.items,l=!o&&s.length?s.get(s.length-1):null;for(let n=0;n<e.steps.length;n++){let a,c=e.steps[n].invert(e.docs[n]),d=new md(e.mapping.maps[n],c,t);(a=l&&l.merge(d))&&(d=a,n?r.pop():s=s.slice(0,s.length-1)),r.push(d),t&&(i++,t=void 0),o||(l=d)}let a=i-n.depth;return a>yd&&(s=function(e,t){let n;return e.forEach((e,o)=>{if(e.selection&&0==t--)return n=o,!1}),e.slice(n)}(s,a),i-=a),new fd(s.append(r),i)}remapping(e,t){let n=new ye;return this.items.forEach((t,o)=>{let r=null!=t.mirrorOffset&&o-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,r)},e,t),n}addMaps(e){return 0==this.eventCount?this:new fd(this.items.append(e.map(e=>new md(e))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let n=[],o=Math.max(0,this.items.length-t),r=e.mapping,i=e.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},o);let l=t;this.items.forEach(t=>{let o=r.getMirror(--l);if(null==o)return;i=Math.min(i,o);let a=r.maps[o];if(t.step){let i=e.steps[o].invert(e.docs[o]),c=t.selection&&t.selection.map(r.slice(l+1,o));c&&s++,n.push(new md(a,i,c))}else n.push(new md(a))},o);let a=[];for(let e=t;e<i;e++)a.push(new md(r.maps[e]));let c=this.items.slice(0,o).append(a).append(n),d=new fd(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,o=[],r=0;return this.items.forEach((i,s)=>{if(s>=e)o.push(i),i.selection&&r++;else if(i.step){let e=i.step.map(t.slice(n)),s=e&&e.getMap();if(n--,s&&t.appendMap(s,n),e){let l=i.selection&&i.selection.map(t.slice(n));l&&r++;let a,c=new md(s.invert(),e,l),d=o.length-1;(a=o.length&&o[d].merge(c))?o[d]=a:o.push(c)}}else i.map&&n--},this.items.length,0),new fd(ud.from(o.reverse()),r)}}fd.empty=new fd(ud.empty,0);class md{constructor(e,t,n,o){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=o}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new md(t.getMap().invert(),t,this.selection)}}}class gd{constructor(e,t,n,o,r){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=o,this.prevComposition=r}}const yd=20;function wd(e){let t=[];for(let n=e.length-1;n>=0&&0==t.length;n--)e[n].forEach((e,n,o,r)=>t.push(o,r));return t}function vd(e,t){if(!e)return null;let n=[];for(let o=0;o<e.length;o+=2){let r=t.map(e[o],1),i=t.map(e[o+1],-1);r<=i&&n.push(r,i)}return n}let bd=!1,kd=null;function xd(e){let t=e.plugins;if(kd!=t){bd=!1,kd=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){bd=!0;break}}return bd}function Sd(e){return e.setMeta(Md,!0)}const Cd=new Nt("history"),Md=new Nt("closeHistory");function Nd(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new St({key:Cd,state:{init:()=>new gd(fd.empty,fd.empty,null,0,-1),apply:(t,n,o)=>function(e,t,n,o){let r,i=n.getMeta(Cd);if(i)return i.historyState;n.getMeta(Md)&&(e=new gd(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(0==n.steps.length)return e;if(s&&s.getMeta(Cd))return s.getMeta(Cd).redo?new gd(e.done.addTransform(n,void 0,o,xd(t)),e.undone,wd(n.mapping.maps),e.prevTime,e.prevComposition):new gd(e.done,e.undone.addTransform(n,void 0,o,xd(t)),null,e.prevTime,e.prevComposition);if(!1===n.getMeta("addToHistory")||s&&!1===s.getMeta("addToHistory"))return(r=n.getMeta("rebased"))?new gd(e.done.rebased(n,r),e.undone.rebased(n,r),vd(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new gd(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),vd(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);{let r=n.getMeta("composition"),i=0==e.prevTime||!s&&e.prevComposition!=r&&(e.prevTime<(n.time||0)-o.newGroupDelay||!function(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,o)=>{for(let r=0;r<t.length;r+=2)e<=t[r+1]&&o>=t[r]&&(n=!0)}),n}(n,e.prevRanges)),l=s?vd(e.prevRanges,n.mapping):wd(n.mapping.maps);return new gd(e.done.addTransform(n,i?t.selection.getBookmark():void 0,o,xd(t)),fd.empty,l,n.time,null==r?e.prevComposition:r)}}(n,o,t,e)},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,o="historyUndo"==n?Ad:"historyRedo"==n?Td:null;return!(!o||!e.editable)&&(t.preventDefault(),o(e.state,e.dispatch))}}}})}function Od(e,t){return(n,o)=>{let r=Cd.getState(n);if(!r||0==(e?r.undone:r.done).eventCount)return!1;if(o){let i=function(e,t,n){let o=xd(t),r=Cd.get(t).spec.config,i=(n?e.undone:e.done).popEvent(t,o);if(!i)return null;let s=i.selection.resolve(i.transform.doc),l=(n?e.done:e.undone).addTransform(i.transform,t.selection.getBookmark(),r,o),a=new gd(n?l:i.remaining,n?i.remaining:l,null,0,-1);return i.transform.setSelection(s).setMeta(Cd,{redo:n,historyState:a})}(r,n,e);i&&o(t?i.scrollIntoView():i)}return!0}}const Ad=Od(!1,!0),Td=Od(!0,!0),Dd=Od(!1,!1),Ed=Od(!0,!1);function Rd(e){let t=Cd.getState(e);return t?t.done.eventCount:0}function $d(e){let t=Cd.getState(e);return t?t.undone.eventCount:0}function Id(e){return null!=e.getMeta(Cd)}class zd{constructor(e,t,n={}){var o;this.match=e,this.match=e,this.handler="string"==typeof t?(o=t,function(e,t,n,r){let i=o;if(t[1]){let e=t[0].lastIndexOf(t[1]);i+=t[0].slice(e+t[1].length);let o=(n+=e)-r;o>0&&(i=t[0].slice(e-o,e)+i,n=r)}return e.tr.insertText(i,n,r)}):t,this.undoable=!1!==n.undoable,this.inCode=n.inCode||!1,this.inCodeMark=!1!==n.inCodeMark}}const Bd=500;function Pd({rules:e}){let t=new St({state:{init:()=>null,apply(e,t){return e.getMeta(this)||(e.selectionSet||e.docChanged?null:t)}},props:{handleTextInput:(n,o,r,i)=>Vd(n,o,r,i,e,t),handleDOMEvents:{compositionend:n=>{setTimeout(()=>{let{$cursor:o}=n.state.selection;o&&Vd(n,o.pos,o.pos,"",e,t)})}}},isInputRules:!0});return t}function Vd(e,t,n,o,r,i){if(e.composing)return!1;let s=e.state,l=s.doc.resolve(t),a=l.parent.textBetween(Math.max(0,l.parentOffset-Bd),l.parentOffset,null,"")+o;for(let c=0;c<r.length;c++){let d=r[c];if(!d.inCodeMark&&l.marks().some(e=>e.type.spec.code))continue;if(l.parent.type.spec.code){if(!d.inCode)continue}else if("only"===d.inCode)continue;let h=d.match.exec(a);if(!h||h[0].length<o.length)continue;let p=t-(h[0].length-o.length);if(!d.inCodeMark){let e=!1;if(s.doc.nodesBetween(p,l.pos,t=>{t.isInline&&t.marks.some(e=>e.type.spec.code)&&(e=!0)}),e)continue}let u=d.handler(s,h,p,n);if(u)return d.undoable&&u.setMeta(i,{transform:u,from:t,to:n,text:o}),e.dispatch(u),!0}return!1}const Fd=(e,t)=>{let n=e.plugins;for(let o=0;o<n.length;o++){let r,i=n[o];if(i.spec.isInputRules&&(r=i.getState(e))){if(t){let n=e.tr,o=r.transform;for(let e=o.steps.length-1;e>=0;e--)n.step(o.steps[e].invert(o.docs[e]));if(r.text){let t=n.doc.resolve(r.from).marks();n.replaceWith(r.from,r.to,e.schema.text(r.text,t))}else n.delete(r.from,r.to);t(n)}return!0}}return!1},Ld=new zd(/--$/,"—",{inCodeMark:!1}),Hd=new zd(/\.\.\.$/,"…",{inCodeMark:!1}),_d=new zd(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1}),Wd=new zd(/"$/,"”",{inCodeMark:!1}),qd=new zd(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1}),jd=new zd(/'$/,"’",{inCodeMark:!1}),Jd=[_d,Wd,qd,jd];function Kd(e,t,n=null,o){return new zd(e,(e,r,i,s)=>{let l=n instanceof Function?n(r):n,a=e.tr.delete(i,s),c=a.doc.resolve(i).blockRange(),d=c&&Re(c,t,l);if(!d)return null;a.wrap(c,d);let h=a.doc.resolve(i-1).nodeBefore;return h&&h.type==t&&Pe(a.doc,i-1)&&(!o||o(r,h))&&a.join(i-1),a})}function Xd(e,t,n=null){return new zd(e,(e,o,r,i)=>{let s=e.doc.resolve(r),l=n instanceof Function?n(o):n;return s.node(-1).canReplaceWith(s.index(-1),s.indexAfter(-1),t)?e.tr.delete(r,i).setBlockType(r,r,t,l):null})}const Ud={mark:"strong",altMarks:["b"],altStyle:{name:"font-weight",value:/^(bold(er)?|[5-9]\d{2,})$/}},Gd={mark:"em",altMarks:["i"],altStyle:{name:"font-style",value:/^italic$/i}},Yd={mark:"u",altStyle:{name:"text-decoration",value:/^underline$/i}},Qd={mark:"del",altStyle:{name:"text-decoration",value:/^line-through$/i}},Zd={mark:"sub"},eh={mark:"sup"},th={mark:"link"},nh="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),oh=(e,t)=>{const n={},o=t&&t.applyToWord||!1;if(n["Mod-z"]=Ad,n["Shift-Mod-z"]=Td,n.Backspace=wr(Fd,Po,Fo,qo),n.Enter=wr(Zo,nr,or,sr),nh||(n["Mod-y"]=Td),e.marks.strong&&(n["Mod-b"]=an(Zn,{...Ud,applyToWord:o})),e.marks.em&&(n["Mod-i"]=an(Zn,{...Gd,applyToWord:o})),e.marks.u&&(n["Mod-u"]=an(Zn,{...Yd,applyToWord:o})),e.nodes.hard_break){const t=e.nodes.hard_break,o=wr(tr,(e,n)=>(n(e.tr.replaceSelectionWith(t.create()).scrollIntoView()),!0));n["Shift-Enter"]=o}return n},rh=e=>{const t={};var n;return e.nodes.list_item&&(t.Enter=(n=e.nodes.list_item,(e,t)=>Ao(n)(e,n=>{const o=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();o&&n.ensureMarks(o),t(n)}))),t},ih=/style=['"]?[^'"]*?mso-list:\s*[a-zA-Z]+(\d+)\s[a-zA-Z]+(\d+)\s(\w+)/gi,sh=e=>/^MsoListParagraph/.test(e.className),lh=e=>e.textContent,ah=(e,t)=>{const n=document.createElement(e);return n.style.listStyleType=t,n},ch=e=>{let t=null;return/^\d/.test(e)||(t=(/^[a-z]/.test(e)?"lower-":"upper-")+(/^[ivxlcdm]/i.test(e)?"roman":"alpha")),t},dh=(e,t)=>{let n=[];Array.from(e).forEach(e=>{if(e.nodeType!==Node.ELEMENT_NODE)return;const o=e;o.getAttribute("datalist")?(n.push(e),t.add(n)):sh(o)&&n.length?n.push(e):(n=[],"DIV"===o.nodeName?dh(o.children,t):"TABLE"===o.nodeName&&Array.from(o.querySelectorAll("td,th")).forEach(e=>{dh(e.children,t)}))})},hh=e=>{const t=e.textContent,n=e=>e.replace(/^(?:&nbsp;|[\u00a0\n\r\s])+/,"");return/^[\u2022\u00b7\u00a7\u00d8oØüvn][\u00a0 ]+/.test(t)?{tag:"ul",style:(o=n(lh(e)),/^[\u2022\u00b7\u00FC\u00D8\u002dv-]/.test(o)?null:/^o/.test(o)?"circle":"square")}:/^\s*\w+[.)][\u00a0 ]{2,}/.test(t)?{tag:"ol",style:ch(n(lh(e)))}:void 0;var o},ph=e=>{const t=e.nodeName.toLowerCase();let n;e.firstChild&&e.firstChild.nodeType===Node.COMMENT_NODE&&e.removeChild(e.firstChild),1===e.childNodes.length?n=e.firstChild.nodeType===Node.TEXT_NODE?lh(e):e.firstChild.innerHTML.replace(/^\w+[.)](&nbsp;)+ /,""):(e.removeChild(e.firstChild),3===e.firstChild.nodeType&&/^[ivxlcdm]+\.$/i.test(e.firstChild.nodeValue)&&e.removeChild(e.firstChild),/^(&nbsp;|\s)+$/i.test(e.firstChild.innerHTML)&&e.removeChild(e.firstChild),n="p"!==t?"<"+t+">"+e.innerHTML+"</"+t+">":e.innerHTML),e.parentNode.removeChild(e);const o=document.createElement("li");return o.appendChild(Mn(n)),o},uh=e=>{const t=Mn((e=>e.replace(ih,(e,t,n)=>`datalist="${t}" datalevel="${n}" ${e}`))(e)),n=new Set;return dh(t.children,n),n.forEach(e=>(e=>{const t={};let n,o,r,i,s,l,a,c,d,h,p,u,f,m=-1;for(c=0;c<e.length;c++){d=e[c],f={datalist:d.getAttribute("datalist"),datalevel:d.getAttribute("datalevel")};const g=f.datalist,y=hh(d);if(h=y&&y.tag,!h){!n||s&&!sh(d)||(d.style.marginLeft&&(d.style.marginLeft=""),d.style.marginLeft&&(d.style.margin=""),n.appendChild(d));continue}if(p=f.datalevel||parseFloat(d.style.marginLeft||0),!f.datalevel&&!d.style.marginLeft)continue;const w=h+g;t[p]||(t[p]={}),(!o||o<0)&&(o=p,r=g,a=e.filter(e=>e.getAttribute("datalist")===String(r)),i=a[a.length-1],l=ah(h,y&&y.style),d.parentNode.insertBefore(l,d),m=p,t[p][w]=l),s=i===d,u=t[p][w],(p>m||!u)&&(u=ah(h,y&&y.style),t[p][w]=u,n.appendChild(u)),n=ph(d),u.appendChild(n),s?o=m=-1:m=p}})(e)),Nn(t)},fh=e=>{let t;e=(e=(e=(e=e.replace(/^[\s\S]+?<!--StartFragment-->\s*([\s\S]*?)\s*<!--EndFragment-->[\s\S]+$/,"$1")).replace(/<\/?[ovw]:[^>]*?>/gi,"")).replace(/<\\?\??xml[^>]*>/gi,"")).replace(/<(?:link|meta) [^>]+?>/gi,"");do{t=e,e=e.replace(/<style[^>]*?>\s*<\/style>/gi,"")}while(e!==t);return(e=(e=(e=(e=e.replace(/<\/?st1:.*?>/gi,"")).replace(/<a name="[a-zA-Z0-9_]+">/gim,"")).replace(/v:shapes?="[^"]+"/gi,"")).replace(/<!\[if !supportLists\]>/gi,"")).replace(/<!\[endif\]>/gi,"")},mh=(e,t)=>e.replace(new RegExp("<\\/?("+t+")(?:\\s[^>]*?)?>","gi"),""),gh=e=>{e.ownerElement&&e.ownerElement.removeAttribute(e.name)},yh=e=>{/^Mso/.test(e.value)&&gh(e)},wh=e=>{const t=cn(e.value),n=e.ownerElement.style;let o="";Object.keys(t).forEach(e=>{void 0!==n[e]&&(o+=`${e}: ${t[e]}; `)}),o=o.trim(),o?e.value=o:gh(e)},vh=(e,t)=>{let n=e;if(t.convertMsLists&&(n=uh(n)),t.stripTags&&(n=mh(n,t.stripTags)),t.attributes){const e=Mn(n);Array.from(e.querySelectorAll("*")).forEach(e=>((e,t)=>{if(e.nodeType===Node.ELEMENT_NODE){for(let n=e.attributes.length-1;n>=0;n--){const o=e.attributes[n];t[o.name]?t[o.name](o):t["*"]&&t["*"](o)}"SPAN"===e.nodeName&&0===e.attributes.length&&(e=>{const t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}})(e)}})(e,t.attributes)),n=Nn(e)}return n};function bh(e){const t=e.length,n=new Array(t/2);for(let o=0;o<t;o+=2)n[o]=String.fromCharCode(parseInt(e.substring(o,o+2),16));return btoa(n.join(""))}const kh=/<img\s[^>]*?src=(?:'|")file:\/[^'"]+(?:'|")[^>]*>/gi,xh=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,Sh=new RegExp("(?:("+xh.source+"))([\\da-fA-F\\s]+)\\}","g"),Ch=/[^\da-fA-F]/g,Mh=/file:\/[^'"]+\.(jpg|png|gif)/i,Nh=/\\(png|jpeg)blip\\/,Oh="text/rtf",Ah=(e,t)=>{const n=e.match(kh);if(!n||-1===t.types.indexOf(Oh))return e;const o=t.getData(Oh),r=[],i=o.match(Sh);if(!o||!i)return e;for(const e of i){const t=Nh.exec(e);if(t){const n=e.replace(xh,"").replace(Ch,"");r.push(`data:image/${t[1]};base64,${bh(n)}`)}}return n.length!==r.length?e:e.replace(kh,e=>{const t=r.shift()||"";return e.replace(Mh,t)})},Th=(e,t,n,o,r)=>{const i=[];let s,l,a,c,d,h;const p=[],{matchCase:u,matchWord:f,useRegExp:m}=t,g=t.text;if(!g)return i;const y=u?"g":"gi",w=m?new RegExp(g,y):new RegExp(Bh(g),y);return e.nodesBetween(n,o,(t,u)=>{if(r(i))return!1;t.inlineContent&&u+t.content.size>=n&&(p.length=0,t.nodesBetween(0,t.content.size,(t,m,g,y)=>{if(r(i))return!1;const v=1+u+m;if(t.isText&&v+t.nodeSize>=n){if(d=t.text||"",h=g.childCount-1>=y+1&&g.child(y+1),p.push(n<=v?{text:d,start:v}:{text:d.slice(n-v),start:n}),h&&h.isText)return;for(l=p.map(e=>e.text).join(""),s=w.exec(l);null!==s;){if(s[0].length>0){if(a=p[0].start+s.index,c=a+s[0].length,n<=a&&o>=c&&zh(s,f)&&i.push(at.create(e,a,c)),r(i))break}else w.lastIndex++;s=w.exec(l)}}else p.length=0}))}),i},Dh=(e,t)=>{const{backward:n,matchCyclic:o,...r}=t,i=n?()=>!1:e=>e.length>0,{doc:s,selection:l}=e;let a=[];return n?(a=Th(s,r,0,l.from,i),!a.length&&o&&(a=Th(s,r,l.from,s.content.size,i))):(a=Th(s,r,l.to,s.content.size,i),!a.length&&o&&(a=Th(s,r,0,l.to,i))),a.length?a[a.length-1]:null},Eh=(e,t)=>Th(e,t,0,e.content.size,()=>!1),Rh=(e,t,n)=>{const{from:o,to:r}=e;return n.insertText(t,o,r).setSelection(at.create(n.doc,o,o+t.length)),n},$h=(e,t,n)=>{const o=Eh(e.doc,n);if(0===o.length)return null;const r=e.tr;for(let e=o.length-1;e>=0;e--)r.insertText(t,o[e].from,o[e].to);return r},Ih=/^[\s0-9~`!@#$%^&*()_\-=+\\|[\]{};:'"?/.,<>]?$/,zh=(e,t)=>{if(t){if(!0===t){const t=e.input,n=t.charAt(e.index-1),o=t.charAt(e.index+e[0].length);return Ih.test(n)&&Ih.test(o)}return t(e)}return!0},Bh=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Ph(e){const t={class:"k-placeholder","data-placeholder":e};return new St({key:new Nt("placeholder"),props:{decorations:e=>{const{doc:n}=e,o=n.content.firstChild;if(!(0===n.childCount||1===n.childCount&&o.inlineContent&&0===o.childCount))return Tl.empty;const r=[];return n.descendants((e,n)=>{r.push(Nl.node(n,n+e.nodeSize,t))}),Tl.create(n,r)}}})}const Vh=/\s+/g,Fh=/text-align/,Lh=()=>new St({key:new Nt("spaces-fix"),props:{decorations:e=>{const t=[],n=e.doc;let o,r,i,s;return n.nodesBetween(0,n.content.size,(e,n,l)=>{if(e.type.isText&&(e=>Fh.test(e&&e.attrs&&e.attrs.style||""))(l))for(r=Vh.exec(e.text||"");null!==r;){if(o=n+r.index,i=r[0].length,r.index+i<r.input.length)for(s=0;s<=i-1;s+=2)t.push(Nl.inline(o+s,o+s+1,{style:"white-space: normal"}));r=Vh.exec(e.text||"")}}),Tl.create(n,t)}}}),Hh=(e,t)=>{for(const n in t)n&&pn(e,n,t[n])};class _h{constructor(e,t,n,o=!1){this.node=e,this.view=t,this.dom=document.createElement(n),Hh(this.dom,e.attrs),this.contentDOM=o?void 0:this.dom}}class Wh{constructor(e,t){this.mark=e,this.view=t,this.dom=document.createElement("span"),Hh(this.dom,e.attrs),this.contentDOM=this.dom}}const qh=()=>new St({key:new Nt("csp-fix"),props:{nodeViews:{paragraph:(e,t)=>new _h(e,t,"p"),div:(e,t)=>new _h(e,t,"div"),table_wrapper:(e,t)=>new _h(e,t,"div"),table_caption_external:(e,t)=>new _h(e,t,"div"),table:(e,t)=>new _h(e,t,"table"),table_row:(e,t)=>new _h(e,t,"tr"),table_cell:(e,t)=>new _h(e,t,"td"),table_header:(e,t)=>new _h(e,t,"th"),image:(e,t)=>new _h(e,t,"img",!0)},markViews:{style:(e,t)=>new Wh(e,t)}}}),jh=new Nt("highlight");function Jh(e=jh){return new St({key:e,state:{init:()=>null,apply(e){return e.getMeta(this.spec.key)}},props:{decorations(e){const t=(this.spec.key.getState(e)||[]).map(e=>Nl.inline(e.from,e.to,e.attrs));return Tl.create(e.doc,t)}}})}const Kh={southeast:{x:1,y:1},east:{x:1,y:0},south:{x:0,y:1},north:{x:0,y:-1},west:{x:-1,y:0},southwest:{x:-1,y:1},northwest:{x:-1,y:-1},northeast:{x:1,y:-1}},Xh=Object.keys(Kh),Uh=new Nt("image-resize"),Gh=(e,t,n)=>{e.style[t]=n+"px"},Yh=/[^-]width:|[^-]height:/,Qh=/^.+$/;class Zh{constructor(e,t,n,o){this.activeHandle=e,this.dragging=t,this.rect=n,this.nodePosition=o}apply(e){const t=e.getMeta(Uh);return t?new Zh(t.activeHandle,t.setDragging,t.rect,t.nodePosition):this}}const ep=(e={node:"image",lockRatio:!0})=>new St({key:Uh,view:t=>({resize(){Uh.getState(t.state).rect&&t.dispatch(t.state.tr.setMeta("resize",!0))},get window(){return t.dom.ownerDocument&&t.dom.ownerDocument.defaultView},attachResize(){const e=this.window;e&&(e.removeEventListener("resize",this.resize),e.addEventListener("resize",this.resize))},removeResize(){const e=this.window;e&&e.removeEventListener("resize",this.resize)},update(t,n){const o=t.state,r=o.selection,i=o.schema.nodes[e.node],s=Uh.getState(o),l=s.rect;if(r instanceof dt&&i===r.node.type){const e=t.nodeDOM(r.from),i={top:e.offsetTop,left:e.offsetLeft,width:e.offsetWidth,height:e.offsetHeight};if(!n.selection.eq(r)||l&&(l.width!==i.width||l.height!==i.height||l.top!==i.top||l.left!==i.left)){const e=o.tr;e.setMeta(Uh,{rect:i,nodePosition:r.from}),t.dispatch(e),this.attachResize()}}else l&&(s.rect=null,s.nodePosition=-1)},destroy(){this.removeResize()}}),state:{init:()=>new Zh("",null,null,-1),apply:(e,t)=>t.apply(e)},props:{handleDOMEvents:{mousedown:(t,n)=>((e,t,n)=>{const o=t.target.getAttribute(Rt);if(!o)return!1;const r=Uh.getState(e.state);t.preventDefault();const i=e.state.tr;function s(t){((e,t,n)=>{const o=Uh.getState(e.state),{rect:r,dragging:i,nodePosition:s,activeHandle:l}=o;if(!i||!r)return;const a=e.nodeDOM(s),c=Kh[l],d=(t.clientX-i.startX)*c.x,h=(t.clientY-i.startY)*c.y;let p=c.x?d+a.width:r.width,u=c.y?h+a.height:r.height;if(n.lockRatio&&c.x&&c.y){const e=Math.min(p/a.width,u/a.height),n=a.width*e,o=a.height*e;i.startX=t.clientX-(p-n)*c.x,i.startY=t.clientY-(u-o)*c.y,p=n,u=o}else i.startX=c.x?t.clientX:i.startX,i.startY=c.y?t.clientY:i.startY;Gh(a,"width",p),Gh(a,"height",u),r.top=a.offsetTop,r.left=a.offsetLeft,r.width=a.offsetWidth,r.height=a.offsetHeight;const f=a.nextElementSibling;f.style.width=r.width+"px",f.style.height=r.height+"px",f.style.top=r.top+"px",f.style.left=r.left+"px"})(e,t,n)}return i.setMeta(Uh,{setDragging:{startX:t.clientX,startY:t.clientY},activeHandle:o,rect:r.rect,nodePosition:r.nodePosition}),i.setMeta("addToHistory",!1),e.dispatch(i),t.view.addEventListener("mouseup",function t(n){n.view.removeEventListener("mouseup",t),n.view.removeEventListener("mousemove",s),(e=>{const{rect:t,dragging:n,nodePosition:o}=Uh.getState(e.state);if(n&&t){const n=e.state.selection;if(n instanceof dt){const r=n.node.attrs,i=t.width,s=t.height;let l;if(Yh.test(r.style||"")){const e=Jt(r.style,{style:"width",value:Qh,newValue:i+"px"}),{style:t}=Jt(e.style||"",{style:"height",value:Qh,newValue:s+"px"});l={...r,style:t}}else l={...r,width:i,height:s};const a=n.node.type.createAndFill(l);if(a){const n=e.state.tr;n.replaceWith(o,o+1,a),n.setSelection(dt.create(n.doc,o)),n.setMeta("commandName","image-resize"),n.setMeta("args",l),n.setMeta(Uh,{setDragging:null,activeHandle:null,rect:t,nodePosition:o}),e.dispatch(n)}}}})(e)}),t.view.addEventListener("mousemove",s),!0})(t,n,e)},decorations(t){const n=t.selection,o=t.schema.nodes[e.node],r=Uh.getState(t).rect;if(r&&n instanceof dt&&o===n.node.type){const e=document.createElement("div");e.className="k-editor-resize-handles-wrapper",e.style.width=r.width+"px",e.style.height=r.height+"px",e.style.top=r.top+"px",e.style.left=r.left+"px";for(let t=0;t<Xh.length;t++){const n=document.createElement("div");n.className=Dt+" "+Xh[t],n.setAttribute(Rt,Xh[t]),e.appendChild(n)}return Tl.create(t.doc,[Nl.widget(t.selection.from+1,e)])}return Tl.empty}}}),tp=new Nt("caret-color");function np(){return new St({key:tp,props:{decorations:e=>{const{doc:t,selection:n,storedMarks:o}=e;if(!n.empty||!o)return Tl.empty;const r=jn((o||[]).find(e=>"style"===e.type.name),{name:"color",value:/^.+$/});if(!r)return Tl.empty;const i=n.$anchor.parent,s=[];return t.descendants((e,t)=>{e.eq(i)&&s.push(Nl.node(t,t+e.nodeSize,{style:"caret-color: "+r}))}),Tl.create(t,s)}}})}class op{constructor(e,t){this.node=e,this.view=t,this.dom=document.createElement("div"),this.dom.className="k-editor-resize-wrap-element",this.table=this.dom.appendChild(document.createElement("table")),e.attrs[At]&&this.renderColgroup(e.attrs[At]);const n=this.table.appendChild(document.createElement("tbody"));this.setAttributes(this.table,e.attrs),this.resizeHandles=Xh.map(e=>{const t=document.createElement("span");return t.className=Dt+" "+e,t.setAttribute(Et,e),t}),this.contentDOM=n}update(e){if(e.type!==this.node.type)return!1;const t=this.node;return this.node=e,e.attrs[Tt]?this.resizeHandles.forEach(e=>{this.dom.appendChild(e)}):Array.from(this.dom.children).filter(e=>e.classList.contains(Dt)).forEach(e=>e.remove()),this.setAttributes(this.table,e.attrs),t.attrs[At]!==e.attrs[At]&&this.renderColgroup(e.attrs[At]),!0}ignoreMutation(e){return"attributes"===e.type&&(e.target===this.table||e.target.firstChild===this.table||this.colgroup&&this.colgroup.contains(e.target))}destroy(){this.node=void 0,this.view=void 0,this.table=void 0,this.colgroup=void 0,this.resizeHandles=void 0}renderColgroup(e){this.table&&this.table.firstChild&&"COLGROUP"===this.table.firstChild.nodeName&&this.table.removeChild(this.table.firstChild),e&&(this.colgroup=sd(e),this.table.insertBefore(this.colgroup,this.table.firstChild))}setAttributes(e,t){const n=[At,Tt];for(const o in t)o&&-1===n.indexOf(o)&&pn(e,o,t[o]);/%$/.test(e.style.width)?(this.dom.style.width=e.style.width,e.style.width=""):this.dom.style.width=""}}class rp{constructor(e,t){this.node=e,this.view=t,this.dom=document.createElement("div"),this.setAttributes(this.dom,e.attrs),this.contentDOM=this.dom}update(e){return e.type===this.node.type&&(this.node=e,this.setAttributes(this.dom,e.attrs),!0)}ignoreMutation(e){return"attributes"===e.type&&"style"===e.attributeName}destroy(){this.node=void 0,this.view=void 0}setAttributes(e,t){for(const n in t)n&&pn(e,n,t[n]);if(e.setAttribute("table",""),/%/.test(e.style.width)){const t=this.node&&this.node.lastChild,n=(t?cn(t.attrs.style):{}).width||"";n&&!/%/.test(n)&&(e.style.width="")}}}const ip=new Nt("table-resize"),sp=new Nt("table-column-resizing"),lp=new Nt("table-row-resizing");function ap(e,t){let n=!1;return n=n||e!==ip&&Boolean(ip.get(t))&&ip.getState(t).dragging,n=n||e!==sp&&Boolean(sp.get(t))&&sp.getState(t).dragging,n=n||e!==lp&&Boolean(lp.get(t))&&lp.getState(t).dragging,n}function cp(e,t){let n=!1;return n=n||e!==sp&&Boolean(sp.get(t))&&sp.getState(t).activeHandle>-1,n=n||e!==lp&&Boolean(lp.get(t))&&lp.getState(t).activeHandle>-1,n}function dp(e){return e&&e.firstChild&&"TABLE"===e.firstChild.nodeName?e.firstChild:e}function hp(e){for(;e&&"TD"!==e.nodeName&&"TH"!==e.nodeName;)e=e.classList.contains("ProseMirror")?null:e.parentNode;return e}function pp(e){const t=function(e){const t=Array.from(e&&e.rows||[]),n=Array.from(t&&t[0]&&t[0].cells||[]).map(e=>e.colSpan).reduce((e,t)=>e+t,0),o=t.map(()=>new Array(n));return t.forEach((e,t)=>{let n=0;Array.from(e.cells).forEach(e=>{for(let r=0;r<e.colSpan;r++){for(let r=0;r<e.rowSpan;r++){const i=o[t+r].findIndex((e,t)=>t>=n&&!e);o[t+r][i]=e}n++}})}),o}(e.closest("table"));let n=null;for(let o=0;o<t.length&&(t[o].forEach((t,r)=>{e===t&&(n={rowIndex:o,cellIndex:r})}),!n);o++);return n||{rowIndex:-1,cellIndex:-1}}function up(e,t,n){const o=e.posAtCoords({left:t.clientX,top:t.clientY});if(!o)return-1;const r=e.state.doc.resolve(o.pos),i=Qt(r,e=>"table"===e.type.spec.tableRole);if(null===i)return-1;const s=r.start(i.depth),l=i.node,a=ka.get(l);return s+a.map[a.width*n.rowIndex+n.cellIndex]}function fp(e){const t=Array.from(e&&e.children||[]);let n=!1;return t.forEach(t=>{for(;t.span>1;){const o=t.cloneNode();o.span=1,e.insertBefore(o,t),t.span-=1,n=!0}}),n}function mp(){const e=new St({key:sp,state:{init:()=>new gp(-1,null),apply:(e,t)=>t.apply(e)},props:{attributes:e=>cp(sp,e)?null:sp.getState(e).activeHandle>-1?{class:"resize-cursor"}:null,handleDOMEvents:{mousemove:(e,t)=>(ap(sp,e.state)||function(e,t){const n=sp.getState(e.state);if(!n.dragging){const o=hp(t.target);let r=-1;if(o){const n=pp(o),{left:i,right:s}=o.getBoundingClientRect();Math.abs(t.clientX-i)<=5&&n.cellIndex>0?(n.cellIndex-=o.colSpan,r=up(e,t,n)):s-t.clientX>0&&s-t.clientX<=5&&(r=up(e,t,n))}r!==n.activeHandle&&yp(e,r)}}(e,t),!1),mouseleave:e=>(function(e){const t=sp.getState(e.state);t.activeHandle>-1&&!t.dragging&&yp(e,-1)}(e),!1),mousedown:(e,t)=>function(e,t){const n=sp.getState(e.state);if(-1===n.activeHandle||n.dragging)return!1;const o=e.state.doc.resolve(n.activeHandle),r=o.parent,i=o.index();let s=0;for(let e=0;e<=i;e++)s+=r.child(e).attrs.colspan;const l=o.node(o.depth-1),a=e.domAtPos(n.activeHandle),c=a.node.childNodes[a.offset].closest("table");let d,h;if(l.attrs[At]){const e=c.firstChild;fp(e)&&(h={...l.attrs,[At]:e.outerHTML}),d=e.children[s-1],d.style.width||(d.style.width=d.offsetWidth+"px")}else{let e=0;for(let t=0;t<r.childCount;t++)e+=r.child(t).attrs.colspan;const t=document.createElement("colgroup"),n=new Array(e);for(let o=0;o<e;o++)n[o]=document.createElement("col"),t.appendChild(n[o]);c.insertBefore(t,c.firstChild),d=n[i],d.style.width=d.offsetWidth+"px",h={...l.attrs,[At]:"<colgroup>"+n.reduce((e,t)=>e+t.outerHTML,"")+"</colgroup>"}}const p=parseFloat(d.style.width),u=e.state.tr.setMeta(sp,{setDragging:{startX:t.clientX,startWidth:p}});if(!c.style.width){const e=Array.from(d.parentNode.children).map(e=>e.style.width);if(e.every(Boolean)){const t=e.reduce((e,t)=>e+parseFloat(t),0);h=Xt(h||l.attrs,"width",t+"px")}}if(h){const e=o.posAtIndex(0,o.depth-1)-1;u.setNodeMarkup(e,null,h)}function f(t){t.view.removeEventListener("mouseup",f),t.view.removeEventListener("mousemove",m);const n=sp.getState(e.state);if(n.dragging){const t=e.state.tr;!function(e,t,n){const o=e.state.doc.resolve(n),r=o.node(-1),i=o.start(-1),s=o.posAtIndex(0,o.depth-1)-1,l=e.nodeDOM(i).closest("table");let a=r.attrs;if(r&&a[At]){const e=l.firstChild;a={...a,[At]:e.outerHTML}}const c=l.style.width;l&&c&&cn(a.style).width!==c&&(a=Xt(a,"width",c)),t.setNodeMarkup(s,null,a)}(e,t,n.activeHandle),e.dispatch(t.setMeta(sp,{setDragging:null}))}}function m(t){if(!t.which)return f(t);const n=sp.getState(e.state),o=function(e,t){const n=t.clientX-e.startX;return Math.max(25,e.startWidth+n)}(n.dragging,t);!function(e,t,n){const o=e.state.doc.resolve(t),r=o.node(-1),i=o.start(-1),s=ka.get(r).colCount(o.pos-i)+o.nodeAfter.attrs.colspan-1;let l=e.domAtPos(o.start(-1)).node;"TABLE"!==l.nodeName&&(l=l.closest("table"));const a=l,c=a.firstChild,d=Array.from(c.children);if(d[s].style.width=n+"px",a.style.width){const e=d.map(e=>e.style.width);if(e.every(Boolean)){const t=e.reduce((e,t)=>e+parseFloat(t),0);a.style.width=t+"px"}}}(e,n.activeHandle,o)}return e.dispatch(u),t.view.addEventListener("mouseup",f),t.view.addEventListener("mousemove",m),t.preventDefault(),!0}(e,t)},decorations(e){if(!ap(sp,e)){const t=sp.getState(e);if(t.activeHandle>-1)return function(e,t){const n=[],o=e.doc.resolve(t),r=o.node(-1),i=ka.get(r),s=o.start(-1),l=[],a=t-s;let c=-1;for(let e=0;e<i.height;e++)l.push(i.map.slice(e*i.width,e*i.width+i.width)),-1===c&&(c=l[e].lastIndexOf(a));const d=[];return l.forEach(e=>{const t=e[c];e[c]!==e[c+1]&&d.push(t)}),d.forEach(e=>{const t=s+e+r.nodeAt(e).nodeSize-1,o=document.createElement("div");o.className="column-resize-handle",n.push(Nl.widget(t,o))}),Tl.create(e.doc,n)}(e,t.activeHandle)}return Tl.empty},nodeViews:{table_wrapper:(e,t)=>new rp(e,t),table:(e,t)=>new op(e,t)}}});return e}class gp{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t;const n=e.getMeta(sp);if(n&&null!=n.setHandle)return new gp(n.setHandle,null);if(n&&void 0!==n.setDragging)return new gp(this.activeHandle,n.setDragging);if(this.activeHandle>-1&&e.docChanged){let n=e.mapping.map(this.activeHandle,-1);o=e.doc.resolve(n),Boolean("row"===o.parent.type.spec.tableRole&&o.nodeAfter)||(n=-1),t=new gp(n,this.dragging)}var o;return t||this}}function yp(e,t){const n=e.state.tr;n.setMeta("addToHistory",!1),n.setMeta(sp,{setHandle:t}),e.dispatch(n)}const wp={southeast:!0,southwest:!0,northwest:!0,northeast:!0},vp={east:!0,west:!0,...wp},bp={south:!0,north:!0,...wp};class kp{constructor(e,t,n){this.activeHandle=e,this.dragging=t,this.nodePosition=n}apply(e){const t=e.getMeta(ip);return t?new kp(t.activeHandle,t.setDragging,t.nodePosition):this}}const xp=e=>{const t=Array.from(e.firstChild.children).map(e=>e.offsetWidth),n=Array.from(e.rows).map(e=>e.offsetHeight),o=t.reduce((e,t)=>e+t,0),r=n.reduce((e,t)=>e+t,0),i=e.offsetHeight;return{width:o,height:r,colsWidth:t,rowsHeight:n,offsetWidth:e.offsetWidth,offsetHeight:i}},Sp=(e,t)=>{const n=t.target.getAttribute(Et);if(!n)return!1;const o=ip.getState(e.state);t.preventDefault();const r=e.state.tr;r.setMeta(ip,{setDragging:{startX:t.clientX,startY:t.clientY},activeHandle:n,nodePosition:o.nodePosition}),r.setMeta("addToHistory",!1),((e,t,n)=>{const o=e.state.doc.nodeAt(n),r=dp(e.nodeDOM(n)),i=r.firstChild;let s=fp(i);const{width:l,height:a,colsWidth:c,rowsHeight:d,offsetWidth:h,offsetHeight:p}=xp(r);Array.from(i&&i.children||[]).forEach((e,t)=>{e.style.width&&!/%$/.test(e.style.width)&&(e.style.width=100*c[t]/l+"%",s=!0)});let u=!1;o.forEach((e,o,r)=>{const i=cn(e.attrs.style).height;i&&!/%$/.test(i)&&(t.setNodeMarkup(n+o+1,null,Xt(e.attrs,"height",100*d[r]/a+"%")),u=!0)});let f=o.attrs;cn(f.style).width!==h+"px"&&(f=Xt(f,"width",h+"px")),s&&(f[At]=i.outerHTML),u&&(f=Xt(f,"height",p+"px")),(s||u)&&t.setNodeMarkup(n,null,f)})(e,r,o.nodePosition),e.dispatch(r);const i=t.view||window;function s(t){((e,t)=>{var n;const o=ip.getState(e.state),{dragging:r,nodePosition:i,activeHandle:s}=o;if(i<0||!r)return;const l=dp(e.nodeDOM(i)),a=l.getBoundingClientRect(),c=Kh[s],d=(t.clientX-r.startX)*c.x,h=(t.clientY-r.startY)*c.y,p=(l.ownerDocument&&l.ownerDocument.defaultView||window).getComputedStyle(l),u=/px/.test(p.width)?parseFloat(p.width):l.offsetWidth,f=/px/.test(p.height)?parseFloat(p.height):l.offsetHeight,m=c.x?d+u:a.width,g=c.y?h+f:a.height;if(r.startX=c.x?t.clientX:r.startX,r.startY=c.y?t.clientY:r.startY,vp[s]&&(l.style.width=m+"px"),bp[s]&&(l.style.height=g+"px"),/px/.test(l.style.width)){const e=null===(n=l.parentNode)||void 0===n?void 0:n.parentNode;e instanceof HTMLDivElement&&e.matches("div[table]")&&/%/.test(e.style.width)&&(e.style.width="")}})(e,t)}return i.addEventListener("mouseup",function t(){i.removeEventListener("mouseup",t),i.removeEventListener("mousemove",s),(e=>{const{dragging:t,nodePosition:n,activeHandle:o}=ip.getState(e.state);if(t){const t=e.state.doc.nodeAt(n),r=dp(e.nodeDOM(n)),i=xp(r);if(t){const s=i.offsetWidth+"px",l=i.offsetHeight+"px",a=e.state.tr;let c=t.attrs;const d=cn(c.style);if(vp[o]&&r.style.width&&d.width!==s&&(c=Xt(c,"width",s)),bp[o]&&r.style.height&&d.height!==l&&(c=Xt(c,"height",l)),c=((e,t,n,o)=>{const r=e.state.doc.nodeAt(n),i=dp(e.nodeDOM(n)),s=(i.ownerDocument&&i.ownerDocument.defaultView||window).getComputedStyle,l=Array.from(i.rows);r.forEach((e,o,r)=>{const i=cn(e.attrs.style).height;i&&!/px$/.test(i)&&t.setNodeMarkup(n+o+1,null,Xt(e.attrs,"height",s(l[r]).height))});const a=i.firstChild,c=Array.from(a&&a.children||[]);let d=!1;c.forEach((e,t)=>{e.style.width&&!/px$/.test(e.style.width)&&(e.style.width=s(c[t]).width,d=!0)});const h={...o};return d&&(h[At]=a.outerHTML),h})(e,a,n,c),a.setNodeMarkup(n,null,c),a.setMeta("commandName","node-resize"),a.setMeta("args",c),a.setMeta(ip,{setDragging:null,activeHandle:null,nodePosition:n}),!/%/.test(cn(c.style).width||"")){const e=a.doc.resolve(n),t=Qt(e,e=>"table_wrapper"===e.type.name);if(t&&/%/.test(cn(t.node.attrs.style).width||"")){const n=Xt(t.node.attrs,"width",""),o=e.start(t.depth)-1;a.setNodeMarkup(o,null,n)}}e.dispatch(a)}}})(e)}),i.addEventListener("mousemove",s),!0},Cp=(e={node:"table"})=>new St({key:ip,view:()=>({selectedNode(e,t){const n=e.selection;if(n instanceof dt&&t===n.node.type&&n instanceof dt)return{node:n.node,pos:n.from};const o=Qt(n.$from,e=>e.type===t),r=o&&o.node;return r?{node:r,pos:n.$from.start(o.depth)-1}:null},update(t,n){const o=t.state,r=o.schema.nodes[e.node],i=this.selectedNode(o,r),s=this.selectedNode(n,r);if((i||!s||n.doc.eq(t.state.doc))&&(i||s)){const e=o.tr;if(e.setMeta("addToHistory",!1),i&&s&&i.pos!==s.pos){e.setMeta(ip,{nodePosition:i.pos});const n=e.doc.nodeAt(s.pos);n&&n.type.name===r.name&&e.setNodeMarkup(s.pos,r,{...s.node.attrs,[Tt]:!1}),e.setNodeMarkup(i.pos,r,{...i.node.attrs,[Tt]:!0}),t.dispatch(e)}else i&&s&&i.pos===s.pos&&!i.node.attrs[Tt]&&!o.selection.eq(n.selection)?(e.setMeta(ip,{nodePosition:i.pos}),t.dispatch(e.setNodeMarkup(i.pos,r,{...i.node.attrs,[Tt]:!0}))):i&&!s?(e.setMeta(ip,{nodePosition:i.pos}),t.dispatch(e.setNodeMarkup(i.pos,r,{...i.node.attrs,[Tt]:!0}))):!i&&s&&(e.setMeta(ip,{nodePosition:-1}),t.dispatch(e.setNodeMarkup(s.pos,r,{...s.node.attrs,[Tt]:!1})))}}}),state:{init:()=>new kp("",null,-1),apply:(e,t)=>t.apply(e)},props:{handleDOMEvents:{mousedown:(e,t)=>Sp(e,t)}}});class Mp{ignoreMutation(e){return"attributes"===e.type&&"style"===e.attributeName&&"TR"===e.target.nodeName}}function Np(){const e=new St({key:lp,state:{init(e,t){return this.spec.props.nodeViews[Oa(t.schema).row.name]=()=>new Mp,new Op(-1,null)},apply:(e,t)=>t.apply(e)},props:{attributes:e=>cp(lp,e)?null:lp.getState(e).activeHandle>-1?{class:"resize-cursor-vertical"}:null,handleDOMEvents:{mousemove:(e,t)=>(ap(lp,e.state)||function(e,t){const n=lp.getState(e.state);if(!n.dragging){const o=hp(t.target);let r=-1;if(o){const n=pp(o),{top:i,bottom:s}=o.getBoundingClientRect();Math.abs(t.clientY-i)<=5&&n.rowIndex>0?(n.rowIndex-=o.rowSpan,r=up(e,t,n)):s-t.clientY>0&&s-t.clientY<=5&&(r=up(e,t,n))}r!==n.activeHandle&&Ap(e,r)}}(e,t),!1),mouseleave:e=>(function(e){const t=lp.getState(e.state);t.activeHandle>-1&&!t.dragging&&Ap(e,-1)}(e),!1),mousedown:(e,t)=>function(e,t){const n=lp.getState(e.state);if(-1===n.activeHandle||n.dragging)return!1;const o=e.state.doc.resolve(n.activeHandle),r=o.parent,i=o.node(-1),s=cn(r.attrs.style).height,l=cn(i.attrs.style).height;let a=s?parseFloat(s):0;function c(t){t.view.removeEventListener("mouseup",c),t.view.removeEventListener("mousemove",d);const n=lp.getState(e.state);if(n.dragging){const t=e.state.tr.setMeta(lp,{setDragging:null});!function(e,t,n){const o=e.state.doc,r=o.resolve(n),i=r.parent,s=r.posAtIndex(0)-1,l=e.nodeDOM(s),a=l.ownerDocument&&l.ownerDocument.defaultView||window;l.style.height=a.getComputedStyle(l).height,t.setNodeMarkup(s,null,Xt(i.attrs,"height",l.style.height));const c=l&&l.closest("table"),d=c&&c.style.height;if(d){const e=o.resolve(s),n=e.start(e.depth)-1;t.setNodeMarkup(n,null,Xt(e.parent.attrs,"height",d))}}(e,t,n.activeHandle),e.dispatch(t)}}function d(t){if(!t.which)return c(t);const n=lp.getState(e.state),o=function(e,t){const n=t.clientY-e.startY;return e.startHeight.rowHeight+n}(n.dragging,t),r=t.clientY-n.dragging.startY;!function(e,t,n,o,r){const i=e.nodeDOM(t),s=i&&i.parentNode;if(s){s.style.height=n+"px";const e=s.ownerDocument&&s.ownerDocument.defaultView||window;s.style.height=e.getComputedStyle(s).height;const t=s.closest("table"),i=parseFloat(r)+o+"px",l=t&&t.style.height;l&&l!==i&&(t.style.height=parseFloat(r)+o+"px",t.style.height=e.getComputedStyle(t).height)}}(e,n.activeHandle,o,r,l)}return s||(a=e.nodeDOM(n.activeHandle).offsetHeight),e.dispatch(e.state.tr.setMeta(lp,{setDragging:{startY:t.clientY,startHeight:{rowHeight:a,tableHeight:l}}})),t.view.addEventListener("mouseup",c),t.view.addEventListener("mousemove",d),t.preventDefault(),!0}(e,t)},decorations(e){if(ap(lp,e))return Tl.empty;const t=lp.getState(e);return t.activeHandle>-1?function(e,t){const n=[];if("number"!=typeof t)return Tl.empty;const o=e.doc.resolve(t),r=o.node(-1),i=ka.get(r),s=o.start(-1),l=[],a=t-s;let c=-1;for(let e=0;e<i.height;e++)l.push(i.map.slice(e*i.width,e*i.width+i.width)),-1!==l[e].indexOf(a)&&(c=e);const d=[];return l[c].forEach((e,t)=>{l[c+1]&&e===l[c+1][t]||d.push(e)}),d.forEach(e=>{const t=r.nodeAt(e),o=s+e+(t?t.nodeSize:0)-1,i=document.createElement("div");i.className="row-resize-handle",n.push(Nl.widget(o,i))}),Tl.create(e.doc,n)}(e,t.activeHandle):void 0},nodeViews:{}}});return e}class Op{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t;const n=e.getMeta(lp);if(n&&null!=n.setHandle)return new Op(n.setHandle,null);if(n&&void 0!==n.setDragging)return new Op(this.activeHandle,n.setDragging);if(this.activeHandle>-1){let n=e.mapping.map(this.activeHandle,-1);"row"===(o=e.doc.resolve(n)).parent.type.spec.tableRole&&o.nodeAfter||(n=null),t=new Op(n,this.dragging)}var o;return t||this}}function Ap(e,t){const n=e.state.tr;n.setMeta("addToHistory",!1),n.setMeta(lp,{setHandle:t}),e.dispatch(n)}const Tp=()=>[Cp(),mp(),Np()],Dp=(e,t,n,o,r)=>{const i=r.resolve(e),s=r.resolve(t),l=o.type.name;let a,c;return!i.nodeBefore&&(a=i.node(i.depth),c=i.node(i.depth-1),a&&c&&c.firstChild===a&&c.type.name===l)?n+o.content.size<=t:!s.nodeAfter&&(a=s.node(s.depth),c=s.node(s.depth-1),a&&c&&c.lastChild===a&&c.type.name===l)?e<=n:e<=n&&n+o.content.size<=t},Ep=(e,t,n)=>{const{tr:o,doc:r,selection:{from:i,to:s}}=t,l=e.getMeta("args");return r.nodesBetween(i,s,(e,t)=>{e.type.name===n.listItem&&Dp(i,s,t,e,r)&&o.setNodeMarkup(t,null,{...e.attrs,style:dn(e.attrs.style,l.style,l.value)})}),o.docChanged?o:void 0},Rp=(e,t,n)=>{const o=Object.keys(n.resetValues),{tr:r,doc:i,selection:{from:s,to:l}}=t;return i.nodesBetween(s,l,(e,t)=>{if(e.type.name===n.listItem&&Dp(s,l,t,e,i)){let n=e.attrs;const i=cn(e.attrs.style);o.forEach(e=>{i[e]&&(n={...n,style:dn(n.style,e,"")})}),n!==e.attrs&&r.setNodeMarkup(t,null,n)}}),e.steps.forEach(e=>{if(e instanceof Se){const t=e.mark;if("style"===t.type.name&&t.attrs.style){const[o]=t.attrs.style.split(/\s*:\s*/),i=Qt(r.doc.resolve(e.from),e=>e.type.name===n.listItem);if(i&&cn(i.node.attrs.style)[o]&&n.resetValues[o]){const i=t.type.create({style:`${o}: ${n.resetValues[o]};`});r.addMark(e.from,e.to,i)}}}}),r.docChanged?r:void 0},$p={listItem:"list_item",resetValues:{"font-size":"","font-family":"",color:""}};function Ip(e=$p){return new St({key:new Nt("list-markers-styles"),appendTransaction:(t,n,o)=>{const r=t.slice().pop(),i=r.getMeta("commandName");let s;return"FontSize"===i||"FontName"===i||"ForeColor"===i?s=Ep(r,o,e):"CleanFormatting"===i&&(s=Rp(r,o,e)),s&&s.setMeta("addToHistory",!0),s}})}function zp(e={}){return new St({view:t=>new Bp(t,e)})}class Bp{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,o=this.editorView.dom,r=o.getBoundingClientRect(),i=r.width/o.offsetWidth,s=r.height/o.offsetHeight;if(n){let n=t.nodeBefore,o=t.nodeAfter;if(n||o){let t=this.editorView.nodeDOM(this.cursorPos-(n?n.nodeSize:0));if(t){let r=t.getBoundingClientRect(),i=n?r.bottom:r.top;n&&o&&(i=(i+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let l=this.width/2*s;e={left:r.left,right:r.right,top:i-l,bottom:i+l}}}}if(!e){let t=this.editorView.coordsAtPos(this.cursorPos),n=this.width/2*i;e={left:t.left-n,right:t.left+n,top:t.top,bottom:t.bottom}}let l,a,c=this.editorView.dom.offsetParent;if(this.element||(this.element=c.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),!c||c==document.body&&"static"==getComputedStyle(c).position)l=-pageXOffset,a=-pageYOffset;else{let e=c.getBoundingClientRect(),t=e.width/c.offsetWidth,n=e.height/c.offsetHeight;l=e.left-c.scrollLeft*t,a=e.top-c.scrollTop*n}this.element.style.left=(e.left-l)/i+"px",this.element.style.top=(e.top-a)/s+"px",this.element.style.width=(e.right-e.left)/i+"px",this.element.style.height=(e.bottom-e.top)/s+"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),o=n&&n.type.spec.disableDropCursor,r="function"==typeof o?o(this.editorView,t,e):o;if(t&&!r){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=He(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){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class Pp extends rt{constructor(e){super(e,e)}map(e,t){let n=e.resolve(t.map(this.head));return Pp.valid(n)?new Pp(n):rt.near(n)}content(){return p.empty}eq(e){return e instanceof Pp&&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 Pp(e.resolve(t.pos))}getBookmark(){return new Vp(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),o=e.node(t);if(0!=n)for(let e=o.child(n-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||Fp(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),o=e.node(t);if(n!=o.childCount)for(let e=o.child(n);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||Fp(e.type))return!0;if(e.inlineContent)return!1}else if(o.type.spec.isolating)return!0}return!0}(e))return!1;let n=t.type.spec.allowGapCursor;if(null!=n)return n;let o=t.contentMatchAt(e.index()).defaultType;return o&&o.isTextblock}static findGapCursorFrom(e,t,n=!1){e:for(;;){if(!n&&Pp.valid(e))return e;let o=e.pos,r=null;for(let n=e.depth;;n--){let i=e.node(n);if(t>0?e.indexAfter(n)<i.childCount:e.index(n)>0){r=i.child(t>0?e.indexAfter(n):e.index(n)-1);break}if(0==n)return null;o+=t;let s=e.doc.resolve(o);if(Pp.valid(s))return s}for(;;){let i=t>0?r.firstChild:r.lastChild;if(!i){if(r.isAtom&&!r.isText&&!dt.isSelectable(r)){e=e.doc.resolve(o+r.nodeSize*t),n=!1;continue e}break}r=i,o+=t;let s=e.doc.resolve(o);if(Pp.valid(s))return s}return null}}}Pp.prototype.visible=!1,Pp.findFrom=Pp.findGapCursorFrom,rt.jsonID("gapcursor",Pp);class Vp{constructor(e){this.pos=e}map(e){return new Vp(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return Pp.valid(t)?new Pp(t):rt.near(t)}}function Fp(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function Lp(){return new St({props:{decorations:jp,createSelectionBetween:(e,t,n)=>t.pos==n.pos&&Pp.valid(n)?new Pp(n):null,handleClick:Wp,handleKeyDown:Hp,handleDOMEvents:{beforeinput:qp}}})}const Hp=wa({ArrowLeft:_p("horiz",-1),ArrowRight:_p("horiz",1),ArrowUp:_p("vert",-1),ArrowDown:_p("vert",1)});function _p(e,t){const n="vert"==e?t>0?"down":"up":t>0?"right":"left";return function(e,o,r){let i=e.selection,s=t>0?i.$to:i.$from,l=i.empty;if(i instanceof at){if(!r.endOfTextblock(n)||0==s.depth)return!1;l=!1,s=e.doc.resolve(t>0?s.after():s.before())}let a=Pp.findGapCursorFrom(s,t,l);return!!a&&(o&&o(e.tr.setSelection(new Pp(a))),!0)}}function Wp(e,t,n){if(!e||!e.editable)return!1;let o=e.state.doc.resolve(t);if(!Pp.valid(o))return!1;let r=e.posAtCoords({left:n.clientX,top:n.clientY});return!(r&&r.inside>-1&&dt.isSelectable(e.state.doc.nodeAt(r.inside))||(e.dispatch(e.state.tr.setSelection(new Pp(o))),0))}function qp(e,t){if("insertCompositionText"!=t.inputType||!(e.state.selection instanceof Pp))return!1;let{$from:n}=e.state.selection,o=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!o)return!1;let r=s.empty;for(let e=o.length-1;e>=0;e--)r=s.from(o[e].createAndFill(null,r));let i=e.state.tr.replace(n.pos,n.pos,new p(r,0,0));return i.setSelection(at.near(i.doc.resolve(n.pos+1))),e.dispatch(i),!1}function jp(e){if(!(e.selection instanceof Pp))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",Tl.create(e.doc,[Nl.widget(e.selection.head,t,{key:"gapcursor"})])}const Jp=(e,t,n)=>{const{table:o,table_row:r,table_cell:i}=e,s=[];let l;for(let e=0;e<t+1;e++){l=[];for(let e=0;e<n+1;e++)l.push(i.createAndFill());s.push(r.createAndFill(void 0,l))}return o.createAndFill(void 0,s)},Kp=/^table$/,Xp=/^table_row$/,Up=/^table_cell|table_header$/,Gp=(e,t)=>{const n=e.$head;for(let e=n.depth;e>0;e--){const o=n.node(e);if(t.test(o.type.name))return{pos:n.before(e),node:o}}return null},Yp=(e,t)=>{const n=t&&(e=>{const n=Gp(e.selection,Xp),o=Gp(e.selection,Kp);if(n&&o&&n.node.attrs[Ot]){let t=0;for(let e=0;e<o.node.nodeSize;e++)if(o.node.child(e).eq(n.node)){t=e;break}const r=o.node.child(t-1),i=n.pos-r.nodeSize;e.setNodeMarkup(i,void 0,{[Ot]:n.node.attrs[Ot]})}return t(e)});return tc(e,n)},Qp=(e,t)=>nc(e,t&&(e=>{const n=Gp(e.selection,Xp);if(n&&n.node.attrs[Ot]){const t=n.pos+n.node.nodeSize;e.setNodeMarkup(t,void 0,{[Ot]:n.node.attrs[Ot]})}return t(e)})),Zp=(e,t)=>{if(!e)return-1;const n=ka.get(e.node),o=Gp(t,Up),r=n.map.indexOf(o.pos-e.pos-1);let i=-1;return-1!==r&&(i=r%n.width),i},eu=(e,t,n)=>{const o=Zp(t,e.selection),r=sd(t.node.attrs[At]);r.insertBefore(r.ownerDocument.createElement("col"),r.children[o+n]),e.setNodeMarkup(t.pos,null,{...t.node.attrs,[At]:r.outerHTML})},tu=(e,t)=>Ua(e,t&&(e=>{const n=Gp(e.selection,Kp);return n.node.attrs[At]?(eu(e,n,-1),t(e)):t(e)})),nu=(e,t)=>Ga(e,t&&(e=>{const n=Gp(e.selection,Kp);return n.node.attrs[At]?(eu(e,n,1),t(e)):t(e)})),ou=(e,t)=>{const n=Gp(e.selection,Kp),o=n&&n.node.attrs[At],r=Zp(n,e.selection),i=t&&(e=>{if(!o)return t(e);const i=e.doc.nodeAt(n.pos);return((e,t,n)=>{const o=sd(t.node.attrs[At]);o.removeChild(o.children[n]),e.setNodeMarkup(t.pos,null,{...t.node.attrs,[At]:o.outerHTML})})(e,{node:i,pos:n.pos},r),t(e)});return Qa(e,i)};return t})());