@thebase/ui
Version:
CDN-installable Owl and Bootstrap 5 UI component library.
5 lines (4 loc) • 46.4 kB
JavaScript
function g(s){this.content=s}g.prototype={constructor:g,find:function(s){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===s)return t;return-1},get:function(s){var t=this.find(s);return t==-1?void 0:this.content[t+1]},update:function(s,t,e){var n=e&&e!=s?this.remove(e):this,i=n.find(s),r=n.content.slice();return i==-1?r.push(e||s,t):(r[i+1]=t,e&&(r[i]=e)),new g(r)},remove:function(s){var t=this.find(s);if(t==-1)return this;var e=this.content.slice();return e.splice(t,2),new g(e)},addToStart:function(s,t){return new g([s,t].concat(this.remove(s).content))},addToEnd:function(s,t){var e=this.remove(s).content.slice();return e.push(s,t),new g(e)},addBefore:function(s,t,e){var n=this.remove(t),i=n.content.slice(),r=n.find(s);return i.splice(r==-1?i.length:r,0,t,e),new g(i)},forEach:function(s){for(var t=0;t<this.content.length;t+=2)s(this.content[t],this.content[t+1])},prepend:function(s){return s=g.from(s),s.size?new g(s.content.concat(this.subtract(s).content)):this},append:function(s){return s=g.from(s),s.size?new g(this.subtract(s).content.concat(s.content)):this},subtract:function(s){var t=this;s=g.from(s);for(var e=0;e<s.content.length;e+=2)t=t.remove(s.content[e]);return t},toObject:function(){var s={};return this.forEach(function(t,e){s[t]=e}),s},get size(){return this.content.length>>1}};g.from=function(s){if(s instanceof g)return s;var t=[];if(s)for(var e in s)t.push(e,s[e]);return new g(t)};var D=g;function it(s,t,e){for(let n=0;;n++){if(n==s.childCount||n==t.childCount)return s.childCount==t.childCount?null:e;let i=s.child(n),r=t.child(n);if(i==r){e+=i.nodeSize;continue}if(!i.sameMarkup(r))return e;if(i.isText&&i.text!=r.text){let l=i.text,h=r.text,o=0;for(;l[o]==h[o];o++)e++;return o&&o<l.length&&o<h.length&<(l.charCodeAt(o-1))&&st(l.charCodeAt(o))&&e--,e}if(i.content.size||r.content.size){let l=it(i.content,r.content,e+1);if(l!=null)return l}e+=i.nodeSize}}function rt(s,t,e,n){for(let i=s.childCount,r=t.childCount;;){if(i==0||r==0)return i==r?null:{a:e,b:n};let l=s.child(--i),h=t.child(--r),o=l.nodeSize;if(l==h){e-=o,n-=o;continue}if(!l.sameMarkup(h))return{a:e,b:n};if(l.isText&&l.text!=h.text){let a=l.text,f=h.text,c=a.length,d=f.length;for(;c>0&&d>0&&a[c-1]==f[d-1];)c--,d--,e--,n--;return c&&d&&c<a.length&<(a.charCodeAt(c-1))&&st(a.charCodeAt(c))&&(e++,n++),{a:e,b:n}}if(l.content.size||h.content.size){let a=rt(l.content,h.content,e-1,n-1);if(a)return a}e-=o,n-=o}}function st(s){return s>=56320&&s<57344}function lt(s){return s>=55296&&s<56320}var p=class s{constructor(t,e){if(this.content=t,this.size=e||0,e==null)for(let n=0;n<t.length;n++)this.size+=t[n].nodeSize}nodesBetween(t,e,n,i=0,r){for(let l=0,h=0;h<e;l++){let o=this.content[l],a=h+o.nodeSize;if(a>t&&n(o,i+h,r||null,l)!==!1&&o.content.size){let f=h+1;o.nodesBetween(Math.max(0,t-f),Math.min(o.content.size,e-f),n,i+f)}h=a}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,n,i){let r="",l=!0;return this.nodesBetween(t,e,(h,o)=>{let a=h.isText?h.text.slice(Math.max(t,o)-o,e-o):h.isLeaf?i?typeof i=="function"?i(h):i:h.type.spec.leafText?h.type.spec.leafText(h):"":"";h.isBlock&&(h.isLeaf&&a||h.isTextblock)&&n&&(l?l=!1:r+=n),r+=a},0),r}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,n=t.firstChild,i=this.content.slice(),r=0;for(e.isText&&e.sameMarkup(n)&&(i[i.length-1]=e.withText(e.text+n.text),r=1);r<t.content.length;r++)i.push(t.content[r]);return new s(i,this.size+t.size)}cut(t,e=this.size){if(t==0&&e==this.size)return this;let n=[],i=0;if(e>t)for(let r=0,l=0;l<e;r++){let h=this.content[r],o=l+h.nodeSize;o>t&&((l<t||o>e)&&(h.isText?h=h.cut(Math.max(0,t-l),Math.min(h.text.length,e-l)):h=h.cut(Math.max(0,t-l-1),Math.min(h.content.size,e-l-1))),n.push(h),i+=h.nodeSize),l=o}return new s(n,i)}cutByIndex(t,e){return t==e?s.empty:t==0&&e==this.content.length?this:new s(this.content.slice(t,e))}replaceChild(t,e){let n=this.content[t];if(n==e)return this;let i=this.content.slice(),r=this.size+e.nodeSize-n.nodeSize;return i[t]=e,new s(i,r)}addToStart(t){return new s([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new s(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))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(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,n=0;e<this.content.length;e++){let i=this.content[e];t(i,n,e),n+=i.nodeSize}}findDiffStart(t,e=0){return it(this,t,e)}findDiffEnd(t,e=this.size,n=t.size){return rt(this,t,e,n)}findIndex(t){if(t==0)return T(0,t);if(t==this.size)return T(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let e=0,n=0;;e++){let i=this.child(e),r=n+i.nodeSize;if(r>=t)return r==t?T(e+1,r):T(e,n);n=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(t=>t.toJSON()):null}static fromJSON(t,e){if(!e)return s.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return s.fromArray(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return s.empty;let e,n=0;for(let i=0;i<t.length;i++){let r=t[i];n+=r.nodeSize,i&&r.isText&&t[i-1].sameMarkup(r)?(e||(e=t.slice(0,i)),e[e.length-1]=r.withText(e[e.length-1].text+r.text)):e&&e.push(r)}return new s(e||t,n)}static from(t){if(!t)return s.empty;if(t instanceof s)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new s([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};p.empty=new p([],0);var F={index:0,offset:0};function T(s,t){return F.index=s,F.offset=t,F}function A(s,t){if(s===t)return!0;if(!(s&&typeof s=="object")||!(t&&typeof t=="object"))return!1;let e=Array.isArray(s);if(Array.isArray(t)!=e)return!1;if(e){if(s.length!=t.length)return!1;for(let n=0;n<s.length;n++)if(!A(s[n],t[n]))return!1}else{for(let n in s)if(!(n in t)||!A(s[n],t[n]))return!1;for(let n in t)if(!(n in s))return!1}return!0}var u=class s{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,n=!1;for(let i=0;i<t.length;i++){let r=t[i];if(this.eq(r))return t;if(this.type.excludes(r.type))e||(e=t.slice(0,i));else{if(r.type.excludes(this.type))return t;!n&&r.type.rank>this.type.rank&&(e||(e=t.slice(0,i)),e.push(this),n=!0),e&&e.push(r)}}return e||(e=t.slice()),n||e.push(this),e}removeFromSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t}isInSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return!0;return!1}eq(t){return this==t||this.type==t.type&&A(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let n=t.marks[e.type];if(!n)throw new RangeError(`There is no mark type ${e.type} in this schema`);let i=n.create(e.attrs);return n.checkAttrs(i.attrs),i}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].eq(e[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return s.none;if(t instanceof s)return[t];let e=t.slice();return e.sort((n,i)=>n.type.rank-i.type.rank),e}};u.none=[];var E=class extends Error{},w=class s{constructor(t,e,n){this.content=t,this.openStart=e,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let n=ht(this.content,t+this.openStart,e,this.openStart+1,this.openEnd+1);return n&&new s(n,this.openStart,this.openEnd)}removeBetween(t,e){return new s(ot(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,e){if(!e)return s.empty;let n=e.openStart||0,i=e.openEnd||0;if(typeof n!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new s(p.fromJSON(t,e.content),n,i)}static maxOpen(t,e=!0){let n=0,i=0;for(let r=t.firstChild;r&&!r.isLeaf&&(e||!r.type.spec.isolating);r=r.firstChild)n++;for(let r=t.lastChild;r&&!r.isLeaf&&(e||!r.type.spec.isolating);r=r.lastChild)i++;return new s(t,n,i)}};w.empty=new w(p.empty,0,0);function ot(s,t,e){let{index:n,offset:i}=s.findIndex(t),r=s.maybeChild(n),{index:l,offset:h}=s.findIndex(e);if(i==t||r.isText){if(h!=e&&!s.child(l).isText)throw new RangeError("Removing non-flat range");return s.cut(0,t).append(s.cut(e))}if(n!=l)throw new RangeError("Removing non-flat range");return s.replaceChild(n,r.copy(ot(r.content,t-i-1,e-i-1)))}function ht(s,t,e,n,i,r){let{index:l,offset:h}=s.findIndex(t),o=s.maybeChild(l);if(h==t||o.isText)return r&&n<=0&&i<=0&&!r.canReplace(l,l,e)?null:s.cut(0,t).append(e).append(s.cut(t));let a=ht(o.content,t-h-1,e,l==0?n-1:0,l==s.childCount-1?i-1:0,o);return a&&s.replaceChild(l,o.copy(a))}function Et(s,t,e){if(e.openStart>s.depth)throw new E("Inserted content deeper than insertion position");if(s.depth-e.openStart!=t.depth-e.openEnd)throw new E("Inconsistent open depths");return at(s,t,e,0)}function at(s,t,e,n){let i=s.index(n),r=s.node(n);if(i==t.index(n)&&n<s.depth-e.openStart){let l=at(s,t,e,n+1);return r.copy(r.content.replaceChild(i,l))}else if(e.content.size)if(!e.openStart&&!e.openEnd&&s.depth==n&&t.depth==n){let l=s.parent,h=l.content;return m(l,h.cut(0,s.parentOffset).append(e.content).append(h.cut(t.parentOffset)))}else{let{start:l,end:h}=Ct(e,s);return m(r,ct(s,l,h,t,n))}else return m(r,z(s,t,n))}function ft(s,t){if(!t.type.compatibleContent(s.type))throw new E("Cannot join "+t.type.name+" onto "+s.type.name)}function B(s,t,e){let n=s.node(e);return ft(n,t.node(e)),n}function x(s,t){let e=t.length-1;e>=0&&s.isText&&s.sameMarkup(t[e])?t[e]=s.withText(t[e].text+s.text):t.push(s)}function C(s,t,e,n){let i=(t||s).node(e),r=0,l=t?t.index(e):i.childCount;s&&(r=s.index(e),s.depth>e?r++:s.textOffset&&(x(s.nodeAfter,n),r++));for(let h=r;h<l;h++)x(i.child(h),n);t&&t.depth==e&&t.textOffset&&x(t.nodeBefore,n)}function m(s,t){if(!s.type.validContent(t))throw new E("Invalid content for node "+s.type.name);return s.copy(t)}function ct(s,t,e,n,i){let r=s.depth>i&&B(s,t,i+1),l=n.depth>i&&B(e,n,i+1),h=[];return C(null,s,i,h),r&&l&&t.index(i)==e.index(i)?(ft(r,l),x(m(r,ct(s,t,e,n,i+1)),h)):(r&&x(m(r,z(s,t,i+1)),h),C(t,e,i,h),l&&x(m(l,z(e,n,i+1)),h)),C(n,null,i,h),new p(h)}function z(s,t,e){let n=[];if(C(null,s,e,n),s.depth>e){let i=B(s,t,e+1);x(m(i,z(s,t,e+1)),n)}return C(t,null,e,n),new p(n)}function Ct(s,t){let e=t.depth-s.openStart,i=t.node(e).copy(s.content);for(let r=e-1;r>=0;r--)i=t.node(r).copy(p.from(i));return{start:i.resolveNoCache(s.openStart+e),end:i.resolveNoCache(i.content.size-s.openEnd-e)}}var N=class s{constructor(t,e,n){this.pos=t,this.path=e,this.parentOffset=n,this.depth=e.length/3-1}resolveDepth(t){return t==null?this.depth:t<0?this.depth+t:t}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(t){return this.path[this.resolveDepth(t)*3]}index(t){return this.path[this.resolveDepth(t)*3+1]}indexAfter(t){return t=this.resolveDepth(t),this.index(t)+(t==this.depth&&!this.textOffset?0:1)}start(t){return t=this.resolveDepth(t),t==0?0:this.path[t*3-1]+1}end(t){return t=this.resolveDepth(t),this.start(t)+this.node(t).content.size}before(t){if(t=this.resolveDepth(t),!t)throw new RangeError("There is no position before the top-level node");return t==this.depth+1?this.pos:this.path[t*3-1]}after(t){if(t=this.resolveDepth(t),!t)throw new RangeError("There is no position after the top-level node");return t==this.depth+1?this.pos:this.path[t*3-1]+this.path[t*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let t=this.parent,e=this.index(this.depth);if(e==t.childCount)return null;let n=this.pos-this.path[this.path.length-1],i=t.child(e);return n?t.child(e).cut(n):i}get nodeBefore(){let t=this.index(this.depth),e=this.pos-this.path[this.path.length-1];return e?this.parent.child(t).cut(0,e):t==0?null:this.parent.child(t-1)}posAtIndex(t,e){e=this.resolveDepth(e);let n=this.path[e*3],i=e==0?0:this.path[e*3-1]+1;for(let r=0;r<t;r++)i+=n.child(r).nodeSize;return i}marks(){let t=this.parent,e=this.index();if(t.content.size==0)return u.none;if(this.textOffset)return t.child(e).marks;let n=t.maybeChild(e-1),i=t.maybeChild(e);if(!n){let h=n;n=i,i=h}let r=n.marks;for(var l=0;l<r.length;l++)r[l].type.spec.inclusive===!1&&(!i||!r[l].isInSet(i.marks))&&(r=r[l--].removeFromSet(r));return r}marksAcross(t){let e=this.parent.maybeChild(this.index());if(!e||!e.isInline)return null;let n=e.marks,i=t.parent.maybeChild(t.index());for(var r=0;r<n.length;r++)n[r].type.spec.inclusive===!1&&(!i||!n[r].isInSet(i.marks))&&(n=n[r--].removeFromSet(n));return n}sharedDepth(t){for(let e=this.depth;e>0;e--)if(this.start(e)<=t&&this.end(e)>=t)return e;return 0}blockRange(t=this,e){if(t.pos<this.pos)return t.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==t.pos?1:0);n>=0;n--)if(t.pos<=this.end(n)&&(!e||e(this.node(n))))return new J(this,t,n);return null}sameParent(t){return this.pos-this.parentOffset==t.pos-t.parentOffset}max(t){return t.pos>this.pos?t:this}min(t){return t.pos<this.pos?t:this}toString(){let t="";for(let e=1;e<=this.depth;e++)t+=(t?"/":"")+this.node(e).type.name+"_"+this.index(e-1);return t+":"+this.parentOffset}static resolve(t,e){if(!(e>=0&&e<=t.content.size))throw new RangeError("Position "+e+" out of range");let n=[],i=0,r=e;for(let l=t;;){let{index:h,offset:o}=l.content.findIndex(r),a=r-o;if(n.push(l,h,i+o),!a||(l=l.child(h),l.isText))break;r=a-1,i+=o+1}return new s(e,n,r)}static resolveCached(t,e){let n=G.get(t);if(n)for(let r=0;r<n.elts.length;r++){let l=n.elts[r];if(l.pos==e)return l}else G.set(t,n=new P);let i=n.elts[n.i]=s.resolve(t,e);return n.i=(n.i+1)%Ot,i}},P=class{constructor(){this.elts=[],this.i=0}},Ot=12,G=new WeakMap,J=class{constructor(t,e,n){this.$from=t,this.$to=e,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)}},bt=Object.create(null),y=class s{constructor(t,e,n,i=u.none){this.type=t,this.attrs=e,this.marks=i,this.content=n||p.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(t){return this.content.child(t)}maybeChild(t){return this.content.maybeChild(t)}forEach(t){this.content.forEach(t)}nodesBetween(t,e,n,i=0){this.content.nodesBetween(t,e,n,i,this)}descendants(t){this.nodesBetween(0,this.content.size,t)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(t,e,n,i){return this.content.textBetween(t,e,n,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(t){return this==t||this.sameMarkup(t)&&this.content.eq(t.content)}sameMarkup(t){return this.hasMarkup(t.type,t.attrs,t.marks)}hasMarkup(t,e,n){return this.type==t&&A(this.attrs,e||t.defaultAttrs||bt)&&u.sameSet(this.marks,n||u.none)}copy(t=null){return t==this.content?this:new s(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new s(this.type,this.attrs,this.content,t)}cut(t,e=this.content.size){return t==0&&e==this.content.size?this:this.copy(this.content.cut(t,e))}slice(t,e=this.content.size,n=!1){if(t==e)return w.empty;let i=this.resolve(t),r=this.resolve(e),l=n?0:i.sharedDepth(e),h=i.start(l),a=i.node(l).content.cut(i.pos-h,r.pos-h);return new w(a,i.depth-l,r.depth-l)}replace(t,e,n){return Et(this.resolve(t),this.resolve(e),n)}nodeAt(t){for(let e=this;;){let{index:n,offset:i}=e.content.findIndex(t);if(e=e.maybeChild(n),!e)return null;if(i==t||e.isText)return e;t-=i+1}}childAfter(t){let{index:e,offset:n}=this.content.findIndex(t);return{node:this.content.maybeChild(e),index:e,offset:n}}childBefore(t){if(t==0)return{node:null,index:0,offset:0};let{index:e,offset:n}=this.content.findIndex(t);if(n<t)return{node:this.content.child(e),index:e,offset:n};let i=this.content.child(e-1);return{node:i,index:e-1,offset:n-i.nodeSize}}resolve(t){return N.resolveCached(this,t)}resolveNoCache(t){return N.resolve(this,t)}rangeHasMark(t,e,n){let i=!1;return e>t&&this.nodesBetween(t,e,r=>(n.isInSet(r.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let t=this.type.name;return this.content.size&&(t+="("+this.content.toStringInner()+")"),ut(this.marks,t)}contentMatchAt(t){let e=this.type.contentMatch.matchFragment(this.content,0,t);if(!e)throw new Error("Called contentMatchAt on a node with invalid content");return e}canReplace(t,e,n=p.empty,i=0,r=n.childCount){let l=this.contentMatchAt(t).matchFragment(n,i,r),h=l&&l.matchFragment(this.content,e);if(!h||!h.validEnd)return!1;for(let o=i;o<r;o++)if(!this.type.allowsMarks(n.child(o).marks))return!1;return!0}canReplaceWith(t,e,n,i){if(i&&!this.type.allowsMarks(i))return!1;let r=this.contentMatchAt(t).matchType(n),l=r&&r.matchFragment(this.content,e);return l?l.validEnd:!1}canAppend(t){return t.content.size?this.canReplace(this.childCount,this.childCount,t.content):this.type.compatibleContent(t.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let t=u.none;for(let e=0;e<this.marks.length;e++){let n=this.marks[e];n.type.checkAttrs(n.attrs),t=n.addToSet(t)}if(!u.sameSet(t,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 t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return this.content.size&&(t.content=this.content.toJSON()),this.marks.length&&(t.marks=this.marks.map(e=>e.toJSON())),t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Node.fromJSON");let n;if(e.marks){if(!Array.isArray(e.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=e.marks.map(t.markFromJSON)}if(e.type=="text"){if(typeof e.text!="string")throw new RangeError("Invalid text node in JSON");return t.text(e.text,n)}let i=p.fromJSON(t,e.content),r=t.nodeType(e.type).create(e.attrs,i,n);return r.type.checkAttrs(r.attrs),r}};y.prototype.text=void 0;var q=class s extends y{constructor(t,e,n,i){if(super(t,e,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ut(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(t,e){return this.text.slice(t,e)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new s(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new s(this.type,this.attrs,t,this.marks)}cut(t=0,e=this.text.length){return t==0&&e==this.text.length?this:this.withText(this.text.slice(t,e))}eq(t){return this.sameMarkup(t)&&this.text==t.text}toJSON(){let t=super.toJSON();return t.text=this.text,t}};function ut(s,t){for(let e=s.length-1;e>=0;e--)t=s[e].type.name+"("+t+")";return t}var k=class s{constructor(t){this.validEnd=t,this.next=[],this.wrapCache=[]}static parse(t,e){let n=new L(t,e);if(n.next==null)return s.empty;let i=pt(n);n.next&&n.err("Unexpected trailing text");let r=Rt(Nt(i));return It(r,n),r}matchType(t){for(let e=0;e<this.next.length;e++)if(this.next[e].type==t)return this.next[e].next;return null}matchFragment(t,e=0,n=t.childCount){let i=this;for(let r=e;i&&r<n;r++)i=i.matchType(t.child(r).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let t=0;t<this.next.length;t++){let{type:e}=this.next[t];if(!(e.isText||e.hasRequiredAttrs()))return e}return null}compatible(t){for(let e=0;e<this.next.length;e++)for(let n=0;n<t.next.length;n++)if(this.next[e].type==t.next[n].type)return!0;return!1}fillBefore(t,e=!1,n=0){let i=[this];function r(l,h){let o=l.matchFragment(t,n);if(o&&(!e||o.validEnd))return p.from(h.map(a=>a.createAndFill()));for(let a=0;a<l.next.length;a++){let{type:f,next:c}=l.next[a];if(!(f.isText||f.hasRequiredAttrs())&&i.indexOf(c)==-1){i.push(c);let d=r(c,h.concat(f));if(d)return d}}return null}return r(this,[])}findWrapping(t){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==t)return this.wrapCache[n+1];let e=this.computeWrapping(t);return this.wrapCache.push(t,e),e}computeWrapping(t){let e=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let i=n.shift(),r=i.match;if(r.matchType(t)){let l=[];for(let h=i;h.type;h=h.via)l.push(h.type);return l.reverse()}for(let l=0;l<r.next.length;l++){let{type:h,next:o}=r.next[l];!h.isLeaf&&!h.hasRequiredAttrs()&&!(h.name in e)&&(!i.type||o.validEnd)&&(n.push({match:h.contentMatch,type:h,via:i}),e[h.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(t){if(t>=this.next.length)throw new RangeError(`There's no ${t}th edge in this content match`);return this.next[t]}toString(){let t=[];function e(n){t.push(n);for(let i=0;i<n.next.length;i++)t.indexOf(n.next[i].next)==-1&&e(n.next[i].next)}return e(this),t.map((n,i)=>{let r=i+(n.validEnd?"*":" ")+" ";for(let l=0;l<n.next.length;l++)r+=(l?", ":"")+n.next[l].type.name+"->"+t.indexOf(n.next[l].next);return r}).join(`
`)}};k.empty=new k(!0);var L=class{constructor(t,e){this.string=t,this.nodeTypes=e,this.inline=null,this.pos=0,this.tokens=t.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(t){return this.next==t&&(this.pos++||!0)}err(t){throw new SyntaxError(t+" (in content expression '"+this.string+"')")}};function pt(s){let t=[];do t.push(Tt(s));while(s.eat("|"));return t.length==1?t[0]:{type:"choice",exprs:t}}function Tt(s){let t=[];do t.push(vt(s));while(s.next&&s.next!=")"&&s.next!="|");return t.length==1?t[0]:{type:"seq",exprs:t}}function vt(s){let t=zt(s);for(;;)if(s.eat("+"))t={type:"plus",expr:t};else if(s.eat("*"))t={type:"star",expr:t};else if(s.eat("?"))t={type:"opt",expr:t};else if(s.eat("{"))t=Mt(s,t);else break;return t}function H(s){/\D/.test(s.next)&&s.err("Expected number, got '"+s.next+"'");let t=Number(s.next);return s.pos++,t}function Mt(s,t){let e=H(s),n=e;return s.eat(",")&&(s.next!="}"?n=H(s):n=-1),s.eat("}")||s.err("Unclosed braced range"),{type:"range",min:e,max:n,expr:t}}function At(s,t){let e=s.nodeTypes,n=e[t];if(n)return[n];let i=[];for(let r in e){let l=e[r];l.isInGroup(t)&&i.push(l)}return i.length==0&&s.err("No node type or group '"+t+"' found"),i}function zt(s){if(s.eat("(")){let t=pt(s);return s.eat(")")||s.err("Missing closing paren"),t}else if(/\W/.test(s.next))s.err("Unexpected token '"+s.next+"'");else{let t=At(s,s.next).map(e=>(s.inline==null?s.inline=e.isInline:s.inline!=e.isInline&&s.err("Mixing inline and block content"),{type:"name",value:e}));return s.pos++,t.length==1?t[0]:{type:"choice",exprs:t}}}function Nt(s){let t=[[]];return i(r(s,0),e()),t;function e(){return t.push([])-1}function n(l,h,o){let a={term:o,to:h};return t[l].push(a),a}function i(l,h){l.forEach(o=>o.to=h)}function r(l,h){if(l.type=="choice")return l.exprs.reduce((o,a)=>o.concat(r(a,h)),[]);if(l.type=="seq")for(let o=0;;o++){let a=r(l.exprs[o],h);if(o==l.exprs.length-1)return a;i(a,h=e())}else if(l.type=="star"){let o=e();return n(h,o),i(r(l.expr,o),o),[n(o)]}else if(l.type=="plus"){let o=e();return i(r(l.expr,h),o),i(r(l.expr,o),o),[n(o)]}else{if(l.type=="opt")return[n(h)].concat(r(l.expr,h));if(l.type=="range"){let o=h;for(let a=0;a<l.min;a++){let f=e();i(r(l.expr,o),f),o=f}if(l.max==-1)i(r(l.expr,o),o);else for(let a=l.min;a<l.max;a++){let f=e();n(o,f),i(r(l.expr,o),f),o=f}return[n(o)]}else{if(l.type=="name")return[n(h,void 0,l.value)];throw new Error("Unknown expr type")}}}}function dt(s,t){return t-s}function Q(s,t){let e=[];return n(t),e.sort(dt);function n(i){let r=s[i];if(r.length==1&&!r[0].term)return n(r[0].to);e.push(i);for(let l=0;l<r.length;l++){let{term:h,to:o}=r[l];!h&&e.indexOf(o)==-1&&n(o)}}}function Rt(s){let t=Object.create(null);return e(Q(s,0));function e(n){let i=[];n.forEach(l=>{s[l].forEach(({term:h,to:o})=>{if(!h)return;let a;for(let f=0;f<i.length;f++)i[f][0]==h&&(a=i[f][1]);Q(s,o).forEach(f=>{a||i.push([h,a=[]]),a.indexOf(f)==-1&&a.push(f)})})});let r=t[n.join(",")]=new k(n.indexOf(s.length-1)>-1);for(let l=0;l<i.length;l++){let h=i[l][1].sort(dt);r.next.push({type:i[l][0],next:t[h.join(",")]||e(h)})}return r}}function It(s,t){for(let e=0,n=[s];e<n.length;e++){let i=n[e],r=!i.validEnd,l=[];for(let h=0;h<i.next.length;h++){let{type:o,next:a}=i.next[h];l.push(o.name),r&&!(o.isText||o.hasRequiredAttrs())&&(r=!1),n.indexOf(a)==-1&&n.push(a)}r&&t.err("Only non-generatable nodes ("+l.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function gt(s){let t=Object.create(null);for(let e in s){let n=s[e];if(!n.hasDefault)return null;t[e]=n.default}return t}function yt(s,t){let e=Object.create(null);for(let n in s){let i=t&&t[n];if(i===void 0){let r=s[n];if(r.hasDefault)i=r.default;else throw new RangeError("No value supplied for attribute "+n)}e[n]=i}return e}function xt(s,t,e,n){for(let i in t)if(!(i in s))throw new RangeError(`Unsupported attribute ${i} for ${e} of type ${n}`);for(let i in s)s[i].validate&&s[i].validate(t[i])}function mt(s,t){let e=Object.create(null);if(t)for(let n in t)e[n]=new W(s,n,t[n]);return e}var R=class s{constructor(t,e,n){this.name=t,this.schema=e,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=mt(t,n.attrs),this.defaultAttrs=gt(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||t=="text"),this.isText=t=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==k.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(t){return this.groups.indexOf(t)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let t in this.attrs)if(this.attrs[t].isRequired)return!0;return!1}compatibleContent(t){return this==t||this.contentMatch.compatible(t.contentMatch)}computeAttrs(t){return!t&&this.defaultAttrs?this.defaultAttrs:yt(this.attrs,t)}create(t=null,e,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new y(this,this.computeAttrs(t),p.from(e),u.setFrom(n))}createChecked(t=null,e,n){return e=p.from(e),this.checkContent(e),new y(this,this.computeAttrs(t),e,u.setFrom(n))}createAndFill(t=null,e,n){if(t=this.computeAttrs(t),e=p.from(e),e.size){let l=this.contentMatch.fillBefore(e);if(!l)return null;e=l.append(e)}let i=this.contentMatch.matchFragment(e),r=i&&i.fillBefore(p.empty,!0);return r?new y(this,t,e.append(r),u.setFrom(n)):null}validContent(t){let e=this.contentMatch.matchFragment(t);if(!e||!e.validEnd)return!1;for(let n=0;n<t.childCount;n++)if(!this.allowsMarks(t.child(n).marks))return!1;return!0}checkContent(t){if(!this.validContent(t))throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0,50)}`)}checkAttrs(t){xt(this.attrs,t,"node",this.name)}allowsMarkType(t){return this.markSet==null||this.markSet.indexOf(t)>-1}allowsMarks(t){if(this.markSet==null)return!0;for(let e=0;e<t.length;e++)if(!this.allowsMarkType(t[e].type))return!1;return!0}allowedMarks(t){if(this.markSet==null)return t;let e;for(let n=0;n<t.length;n++)this.allowsMarkType(t[n].type)?e&&e.push(t[n]):e||(e=t.slice(0,n));return e?e.length?e:u.none:t}static compile(t,e){let n=Object.create(null);t.forEach((r,l)=>n[r]=new s(r,e,l));let i=e.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let r in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}};function Dt(s,t,e){let n=e.split("|");return i=>{let r=i===null?"null":typeof i;if(n.indexOf(r)<0)throw new RangeError(`Expected value of type ${n} for attribute ${t} on type ${s}, got ${r}`)}}var W=class{constructor(t,e,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate=typeof n.validate=="string"?Dt(t,e,n.validate):n.validate}get isRequired(){return!this.hasDefault}},j=class s{constructor(t,e,n,i){this.name=t,this.rank=e,this.schema=n,this.spec=i,this.attrs=mt(t,i.attrs),this.excluded=null;let r=gt(this.attrs);this.instance=r?new u(this,r):null}create(t=null){return!t&&this.instance?this.instance:new u(this,yt(this.attrs,t))}static compile(t,e){let n=Object.create(null),i=0;return t.forEach((r,l)=>n[r]=new s(r,i++,e,l)),n}removeFromSet(t){for(var e=0;e<t.length;e++)t[e].type==this&&(t=t.slice(0,e).concat(t.slice(e+1)),e--);return t}isInSet(t){for(let e=0;e<t.length;e++)if(t[e].type==this)return t[e]}checkAttrs(t){xt(this.attrs,t,"mark",this.name)}excludes(t){return this.excluded.indexOf(t)>-1}},X=class{constructor(t){this.linebreakReplacement=null,this.cached=Object.create(null);let e=this.spec={};for(let i in t)e[i]=t[i];e.nodes=D.from(t.nodes),e.marks=D.from(t.marks||{}),this.nodes=R.compile(this.spec.nodes,this),this.marks=j.compile(this.spec.marks,this);let n=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let r=this.nodes[i],l=r.spec.content||"",h=r.spec.marks;if(r.contentMatch=n[l]||(n[l]=k.parse(l,this.nodes)),r.inlineContent=r.contentMatch.inlineContent,r.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!r.isInline||!r.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=r}r.markSet=h=="_"?null:h?Y(this,h.split(" ")):h==""||!r.inlineContent?[]:null}for(let i in this.marks){let r=this.marks[i],l=r.spec.excludes;r.excluded=l==null?[r]:l==""?[]:Y(this,l.split(" "))}this.nodeFromJSON=i=>y.fromJSON(this,i),this.markFromJSON=i=>u.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(t,e=null,n,i){if(typeof t=="string")t=this.nodeType(t);else if(t instanceof R){if(t.schema!=this)throw new RangeError("Node type from different schema used ("+t.name+")")}else throw new RangeError("Invalid node type: "+t);return t.createChecked(e,n,i)}text(t,e){let n=this.nodes.text;return new q(n,n.defaultAttrs,t,u.setFrom(e))}mark(t,e){return typeof t=="string"&&(t=this.marks[t]),t.create(e)}nodeType(t){let e=this.nodes[t];if(!e)throw new RangeError("Unknown node type: "+t);return e}};function Y(s,t){let e=[];for(let n=0;n<t.length;n++){let i=t[n],r=s.marks[i],l=r;if(r)e.push(r);else for(let h in s.marks){let o=s.marks[h];(i=="_"||o.spec.group&&o.spec.group.split(" ").indexOf(i)>-1)&&e.push(l=o)}if(!l)throw new SyntaxError("Unknown mark type: '"+t[n]+"'")}return e}function Ft(s){return s.tag!=null}function Bt(s){return s.style!=null}var Z=class s{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[];let n=this.matchedStyles=[];e.forEach(i=>{if(Ft(i))this.tags.push(i);else if(Bt(i)){let r=/[^=]*/.exec(i.style)[0];n.indexOf(r)<0&&n.push(r),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let r=t.nodes[i.node];return r.contentMatch.matchType(r)})}parse(t,e={}){let n=new I(this,e,!1);return n.addAll(t,u.none,e.from,e.to),n.finish()}parseSlice(t,e={}){let n=new I(this,e,!0);return n.addAll(t,u.none,e.from,e.to),w.maxOpen(n.finish())}matchTag(t,e,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let r=this.tags[i];if(qt(t,r.tag)&&(r.namespace===void 0||t.namespaceURI==r.namespace)&&(!r.context||e.matchesContext(r.context))){if(r.getAttrs){let l=r.getAttrs(t);if(l===!1)continue;r.attrs=l||void 0}return r}}}matchStyle(t,e,n,i){for(let r=i?this.styles.indexOf(i)+1:0;r<this.styles.length;r++){let l=this.styles[r],h=l.style;if(!(h.indexOf(t)!=0||l.context&&!n.matchesContext(l.context)||h.length>t.length&&(h.charCodeAt(t.length)!=61||h.slice(t.length+1)!=e))){if(l.getAttrs){let o=l.getAttrs(e);if(o===!1)continue;l.attrs=o||void 0}return l}}}static schemaRules(t){let e=[];function n(i){let r=i.priority==null?50:i.priority,l=0;for(;l<e.length;l++){let h=e[l];if((h.priority==null?50:h.priority)<r)break}e.splice(l,0,i)}for(let i in t.marks){let r=t.marks[i].spec.parseDOM;r&&r.forEach(l=>{n(l=_(l)),l.mark||l.ignore||l.clearMark||(l.mark=i)})}for(let i in t.nodes){let r=t.nodes[i].spec.parseDOM;r&&r.forEach(l=>{n(l=_(l)),l.node||l.ignore||l.mark||(l.node=i)})}return e}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new s(t,s.schemaRules(t)))}},wt={address:!0,article:!0,aside:!0,blockquote:!0,body:!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},Pt={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},kt={ol:!0,ul:!0},b=1,U=2,O=4;function K(s,t,e){return t!=null?(t?b:0)|(t==="full"?U:0):s&&s.whitespace=="pre"?b|U:e&~O}var S=class{constructor(t,e,n,i,r,l){this.type=t,this.attrs=e,this.marks=n,this.solid=i,this.options=l,this.content=[],this.activeMarks=u.none,this.match=r||(l&O?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(p.from(t));if(e)this.match=this.type.contentMatch.matchFragment(e);else{let n=this.type.contentMatch,i;return(i=n.findWrapping(t.type))?(this.match=n,i):null}}return this.match.findWrapping(t.type)}finish(t){if(!(this.options&b)){let n=this.content[this.content.length-1],i;if(n&&n.isText&&(i=/[ \t\r\n\u000c]+$/.exec(n.text))){let r=n;n.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=r.withText(r.text.slice(0,r.text.length-i[0].length))}}let e=p.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(p.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!wt.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}},I=class{constructor(t,e,n){this.parser=t,this.options=e,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i=e.topNode,r,l=K(null,e.preserveWhitespace,0)|(n?O:0);i?r=new S(i.type,i.attrs,u.none,!0,e.topMatch||i.type.contentMatch,l):n?r=new S(null,null,u.none,!0,null,l):r=new S(t.schema.topNodeType,null,u.none,!0,null,l),this.nodes=[r],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){t.nodeType==3?this.addTextNode(t,e):t.nodeType==1&&this.addElement(t,e)}addTextNode(t,e){let n=t.nodeValue,i=this.top,r=i.options&U?"full":this.localPreserveWS||(i.options&b)>0,{schema:l}=this.parser;if(r==="full"||i.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(r)if(r==="full")n=n.replace(/\r\n?/g,`
`);else if(l.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(l.linebreakReplacement.create())){let h=n.split(/\r?\n|\r/);for(let o=0;o<h.length;o++)o&&this.insertNode(l.linebreakReplacement.create(),e,!0),h[o]&&this.insertNode(l.text(h[o]),e,!/\S/.test(h[o]));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 h=i.content[i.content.length-1],o=t.previousSibling;(!h||o&&o.nodeName=="BR"||h.isText&&/[ \t\r\n\u000c]$/.test(h.text))&&(n=n.slice(1))}n&&this.insertNode(l.text(n),e,!/\S/.test(n)),this.findInText(t)}else this.findInside(t)}addElement(t,e,n){let i=this.localPreserveWS,r=this.top;(t.tagName=="PRE"||/pre/.test(t.style&&t.style.whiteSpace))&&(this.localPreserveWS=!0);let l=t.nodeName.toLowerCase(),h;kt.hasOwnProperty(l)&&this.parser.normalizeLists&&Jt(t);let o=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(h=this.parser.matchTag(t,this,n));t:if(o?o.ignore:Pt.hasOwnProperty(l))this.findInside(t),this.ignoreFallback(t,e);else if(!o||o.skip||o.closeParent){o&&o.closeParent?this.open=Math.max(0,this.open-1):o&&o.skip.nodeType&&(t=o.skip);let a,f=this.needsBlock;if(wt.hasOwnProperty(l))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),a=!0,r.type||(this.needsBlock=!0);else if(!t.firstChild){this.leafFallback(t,e);break t}let c=o&&o.skip?e:this.readStyles(t,e);c&&this.addAll(t,c),a&&this.sync(r),this.needsBlock=f}else{let a=this.readStyles(t,e);a&&this.addElementByRule(t,o,a,o.consuming===!1?h:void 0)}this.localPreserveWS=i}leafFallback(t,e){t.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode(`
`),e)}ignoreFallback(t,e){t.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),e,!0)}readStyles(t,e){let n=t.style;if(n&&n.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let r=this.parser.matchedStyles[i],l=n.getPropertyValue(r);if(l)for(let h=void 0;;){let o=this.parser.matchStyle(r,l,this,h);if(!o)break;if(o.ignore)return null;if(o.clearMark?e=e.filter(a=>!o.clearMark(a)):e=e.concat(this.parser.schema.marks[o.mark].create(o.attrs)),o.consuming===!1)h=o;else break}}return e}addElementByRule(t,e,n,i){let r,l;if(e.node)if(l=this.parser.schema.nodes[e.node],l.isLeaf)this.insertNode(l.create(e.attrs),n,t.nodeName=="BR")||this.leafFallback(t,n);else{let o=this.enter(l,e.attrs||null,n,e.preserveWhitespace);o&&(r=!0,n=o)}else{let o=this.parser.schema.marks[e.mark];n=n.concat(o.create(e.attrs))}let h=this.top;if(l&&l.isLeaf)this.findInside(t);else if(i)this.addElement(t,n,i);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach(o=>this.insertNode(o,n,!1));else{let o=t;typeof e.contentElement=="string"?o=t.querySelector(e.contentElement):typeof e.contentElement=="function"?o=e.contentElement(t):e.contentElement&&(o=e.contentElement),this.findAround(t,o,!0),this.addAll(o,n),this.findAround(t,o,!1)}r&&this.sync(h)&&this.open--}addAll(t,e,n,i){let r=n||0;for(let l=n?t.childNodes[n]:t.firstChild,h=i==null?null:t.childNodes[i];l!=h;l=l.nextSibling,++r)this.findAtPoint(t,r),this.addDOM(l,e);this.findAtPoint(t,r)}findPlace(t,e,n){let i,r;for(let l=this.open,h=0;l>=0;l--){let o=this.nodes[l],a=o.findWrapping(t);if(a&&(!i||i.length>a.length+h)&&(i=a,r=o,!a.length))break;if(o.solid){if(n)break;h+=2}}if(!i)return null;this.sync(r);for(let l=0;l<i.length;l++)e=this.enterInner(i[l],null,e,!1);return e}insertNode(t,e,n){if(t.isInline&&this.needsBlock&&!this.top.type){let r=this.textblockFromContext();r&&(e=this.enterInner(r,null,e))}let i=this.findPlace(t,e,n);if(i){this.closeExtra();let r=this.top;r.match&&(r.match=r.match.matchType(t.type));let l=u.none;for(let h of i.concat(t.marks))(r.type?r.type.allowsMarkType(h.type):$(h.type,t.type))&&(l=h.addToSet(l));return r.content.push(t.mark(l)),!0}return!1}enter(t,e,n,i){let r=this.findPlace(t.create(e),n,!1);return r&&(r=this.enterInner(t,e,n,!0,i)),r}enterInner(t,e,n,i=!1,r){this.closeExtra();let l=this.top;l.match=l.match&&l.match.matchType(t);let h=K(t,r,l.options);l.options&O&&l.content.length==0&&(h|=O);let o=u.none;return n=n.filter(a=>(l.type?l.type.allowsMarkType(a.type):$(a.type,t))?(o=a.addToSet(o),!1):!0),this.nodes.push(new S(t,e,o,i,null,h)),this.open++,n}closeExtra(t=!1){let e=this.nodes.length-1;if(e>this.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].finish(t));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(t){for(let e=this.open;e>=0;e--){if(this.nodes[e]==t)return this.open=e,!0;this.localPreserveWS&&(this.nodes[e].options|=b)}return!1}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let n=this.nodes[e].content;for(let i=n.length-1;i>=0;i--)t+=n[i].nodeSize;e&&t++}return t}findAtPoint(t,e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&this.find[n].offset==e&&(this.find[n].pos=this.currentPos)}findInside(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].pos==null&&t.nodeType==1&&t.contains(this.find[e].node)&&(this.find[e].pos=this.currentPos)}findAround(t,e,n){if(t!=e&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&t.nodeType==1&&t.contains(this.find[i].node)&&e.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].pos=this.currentPos)}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),n=this.options.context,i=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),r=-(n?n.depth+1:0)+(i?0:1),l=(h,o)=>{for(;h>=0;h--){let a=e[h];if(a==""){if(h==e.length-1||h==0)continue;for(;o>=r;o--)if(l(h-1,o))return!0;return!1}else{let f=o>0||o==0&&i?this.nodes[o].type:n&&o>=r?n.node(o-r).type:null;if(!f||f.name!=a&&!f.isInGroup(a))return!1;o--}}return!0};return l(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let n=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let n=this.parser.schema.nodes[e];if(n.isTextblock&&n.defaultAttrs)return n}}};function Jt(s){for(let t=s.firstChild,e=null;t;t=t.nextSibling){let n=t.nodeType==1?t.nodeName.toLowerCase():null;n&&kt.hasOwnProperty(n)&&e?(e.appendChild(t),t=e):n=="li"?e=t:n&&(e=null)}}function qt(s,t){return(s.matches||s.msMatchesSelector||s.webkitMatchesSelector||s.mozMatchesSelector).call(s,t)}function _(s){let t={};for(let e in s)t[e]=s[e];return t}function $(s,t){let e=t.schema.nodes;for(let n in e){let i=e[n];if(!i.allowsMarkType(s))continue;let r=[],l=h=>{r.push(h);for(let o=0;o<h.edgeCount;o++){let{type:a,next:f}=h.edge(o);if(a==t||r.indexOf(f)<0&&l(f))return!0}};if(l(i.contentMatch))return!0}}var tt=class s{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},n){n||(n=v(e).createDocumentFragment());let i=n,r=[];return t.forEach(l=>{if(r.length||l.marks.length){let h=0,o=0;for(;h<r.length&&o<l.marks.length;){let a=l.marks[o];if(!this.marks[a.type.name]){o++;continue}if(!a.eq(r[h][0])||a.type.spec.spanning===!1)break;h++,o++}for(;h<r.length;)i=r.pop()[1];for(;o<l.marks.length;){let a=l.marks[o++],f=this.serializeMark(a,l.isInline,e);f&&(r.push([a,i]),i.appendChild(f.dom),i=f.contentDOM||f.dom)}}i.appendChild(this.serializeNodeInner(l,e))}),n}serializeNodeInner(t,e){if(t.isText)return v(e).createTextNode(t.text);let{dom:n,contentDOM:i}=M(v(e),this.nodes[t.type.name](t),null,t.attrs);if(i){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,i)}return n}serializeNode(t,e={}){let n=this.serializeNodeInner(t,e);for(let i=t.marks.length-1;i>=0;i--){let r=this.serializeMark(t.marks[i],t.isInline,e);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(t,e,n={}){let i=this.marks[t.type.name];return i&&M(v(n),i(t,e),null,t.attrs)}static renderSpec(t,e,n=null,i){return typeof e=="string"?{dom:t.createTextNode(e)}:M(t,e,n,i)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new s(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=et(t.nodes);return e.text||(e.text=n=>n.text),e}static marksFromSchema(t){return et(t.marks)}};function et(s){let t={};for(let e in s){let n=s[e].spec.toDOM;n&&(t[e]=n)}return t}function v(s){return s.document||window.document}var nt=new WeakMap;function Lt(s){let t=nt.get(s);return t===void 0&&nt.set(s,t=Wt(s)),t}function Wt(s){let t=null;function e(n){if(n&&typeof n=="object")if(Array.isArray(n))if(typeof n[0]=="string")t||(t=[]),t.push(n);else for(let i=0;i<n.length;i++)e(n[i]);else for(let i in n)e(n[i])}return e(s),t}function M(s,t,e,n){if(t.nodeType==1)return{dom:t};if(t.dom&&t.dom.nodeType==1)return t;let i=t[0],r;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(n&&(r=Lt(n))&&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 l=i.indexOf(" ");l>0&&(e=i.slice(0,l),i=i.slice(l+1));let h,o=e?s.createElementNS(e,i):s.createElement(i),a=t[1],f=1;if(a&&typeof a=="object"&&a.nodeType==null&&!Array.isArray(a)){f=2;for(let c in a)if(a[c]!=null){let d=c.indexOf(" ");d>0?o.setAttributeNS(c.slice(0,d),c.slice(d+1),a[c]):c=="style"&&o.style?o.style.cssText=a[c]:o.setAttribute(c,a[c])}}for(let c=f;c<t.length;c++){let d=t[c];if(d===0){if(c<t.length-1||c>f)throw new RangeError("Content hole must be the only child of its parent node");return{dom:o,contentDOM:o}}else if(typeof d=="string")o.appendChild(s.createTextNode(d));else{let{dom:St,contentDOM:V}=M(s,d,e,n);if(o.appendChild(St),V){if(h)throw new RangeError("Multiple content holes");h=V}}}return{dom:o,contentDOM:h}}export{p as a,u as b,E as c,w as d,N as e,J as f,y as g,k as h,R as i,j,X as k,Z as l,tt as m};