/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../prosemirror-model/dist/index.js"),e=Math.pow(2,16);function r(t,r){return t+r*e}function n(t){return 65535&t}class i{constructor(t,e,r){this.pos=t,this.delInfo=e,this.recover=r}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 o{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&o.empty)return o.empty}recover(t){let r=0,i=n(t);if(!this.inverted)for(let e=0;e<i;e++)r+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*i]+r+function(t){return(t-(65535&t))/e}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,n){let o=0,s=this.inverted?2:1,l=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let p=this.ranges[a]-(this.inverted?o:0);if(p>t)break;let h=this.ranges[a+s],c=this.ranges[a+l],f=p+h;if(t<=f){let s=p+o+((h?t==p?-1:t==f?1:e:e)<0?0:c);if(n)return s;let l=t==(e<0?p:f)?null:r(a/3,t-p),d=t==p?2:t==f?1:4;return(e<0?t!=p:t!=f)&&(d|=8),new i(s,d,l)}o+=c-h}return n?t+o:new i(t+o,0,null)}touches(t,e){let r=0,i=n(e),o=this.inverted?2:1,s=this.inverted?1:2;for(let n=0;n<this.ranges.length;n+=3){let e=this.ranges[n]-(this.inverted?r:0);if(e>t)break;let l=this.ranges[n+o];if(t<=e+l&&n==3*i)return!0;r+=this.ranges[n+s]-l}return!1}forEach(t){let e=this.inverted?2:1,r=this.inverted?1:2;for(let n=0,i=0;n<this.ranges.length;n+=3){let o=this.ranges[n],s=o-(this.inverted?i:0),l=o+(this.inverted?0:i),a=this.ranges[n+e],p=this.ranges[n+r];t(s,s+a,l,l+p),i+=p-a}}invert(){return new o(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?o.empty:new o(t<0?[0,-t,0]:[0,0,t])}}o.empty=new o([]);class s{constructor(t,e,r=0,n=(t?t.length:0)){this.mirror=e,this.from=r,this.to=n,this._maps=t||[],this.ownData=!(t||e)}get maps(){return this._maps}slice(t=0,e=this.maps.length){return new s(this._maps,this.mirror,t,e)}appendMap(t,e){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(t),null!=e&&this.setMirror(this._maps.length-1,e)}appendMapping(t){for(let e=0,r=this._maps.length;e<t._maps.length;e++){let n=t.getMirror(e);this.appendMap(t._maps[e],null!=n&&n<e?r+n:void 0)}}getMirror(t){if(this.mirror)for(let e=0;e<this.mirror.length;e++)if(this.mirror[e]==t)return this.mirror[e+(e%2?-1:1)]}setMirror(t,e){this.mirror||(this.mirror=[]),this.mirror.push(t,e)}appendMappingInverted(t){for(let e=t.maps.length-1,r=this._maps.length+t._maps.length;e>=0;e--){let n=t.getMirror(e);this.appendMap(t._maps[e].invert(),null!=n&&n>e?r-n-1:void 0)}}invert(){let t=new s;return t.appendMappingInverted(this),t}map(t,e=1){if(this.mirror)return this._map(t,e,!0);for(let r=this.from;r<this.to;r++)t=this._maps[r].map(t,e);return t}mapResult(t,e=1){return this._map(t,e,!1)}_map(t,e,r){let n=0;for(let i=this.from;i<this.to;i++){let r=this._maps[i].mapResult(t,e);if(null!=r.recover){let e=this.getMirror(i);if(null!=e&&e>i&&e<this.to){i=e,t=this._maps[e].recover(r.recover);continue}}n|=r.delInfo,t=r.pos}return r?t:new i(t,n,null)}}const l=Object.create(null);class a{getMap(){return o.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=l[e.stepType];if(!r)throw new RangeError(`No step type ${e.stepType} defined`);return r.fromJSON(t,e)}static jsonID(t,e){if(t in l)throw new RangeError("Duplicate use of step JSON ID "+t);return l[t]=e,e.prototype.jsonID=t,e}}class p{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new p(t,null)}static fail(t){return new p(null,t)}static fromReplace(e,r,n,i){try{return p.ok(e.replace(r,n,i))}catch(o){if(o instanceof t.ReplaceError)return p.fail(o.message);throw o}}}function h(e,r,n){let i=[];for(let t=0;t<e.childCount;t++){let o=e.child(t);o.content.size&&(o=o.copy(h(o.content,r,o))),o.isInline&&(o=r(o,n,t)),i.push(o)}return t.Fragment.fromArray(i)}class c extends a{constructor(t,e,r){super(),this.from=t,this.to=e,this.mark=r}apply(e){let r=e.slice(this.from,this.to),n=e.resolve(this.from),i=n.node(n.sharedDepth(this.to)),o=new t.Slice(h(r.content,(t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t,i),r.openStart,r.openEnd);return p.fromReplace(e,this.from,this.to,o)}invert(){return new f(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deleted&&r.deleted||e.pos>=r.pos?null:new c(e.pos,r.pos,this.mark)}merge(t){return t instanceof c&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new c(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new c(e.from,e.to,t.markFromJSON(e.mark))}}a.jsonID("addMark",c);class f extends a{constructor(t,e,r){super(),this.from=t,this.to=e,this.mark=r}apply(e){let r=e.slice(this.from,this.to),n=new t.Slice(h(r.content,t=>t.mark(this.mark.removeFromSet(t.marks)),e),r.openStart,r.openEnd);return p.fromReplace(e,this.from,this.to,n)}invert(){return new c(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deleted&&r.deleted||e.pos>=r.pos?null:new f(e.pos,r.pos,this.mark)}merge(t){return t instanceof f&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new f(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new f(e.from,e.to,t.markFromJSON(e.mark))}}a.jsonID("removeMark",f);class d extends a{constructor(t,e){super(),this.pos=t,this.mark=e}apply(e){let r=e.nodeAt(this.pos);if(!r)return p.fail("No node at mark step's position");let n=r.type.create(r.attrs,null,this.mark.addToSet(r.marks));return p.fromReplace(e,this.pos,this.pos+1,new t.Slice(t.Fragment.from(n),0,r.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let r=0;r<e.marks.length;r++)if(!e.marks[r].isInSet(t))return new d(this.pos,e.marks[r]);return new d(this.pos,this.mark)}}return new u(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new d(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new d(e.pos,t.markFromJSON(e.mark))}}a.jsonID("addNodeMark",d);class u extends a{constructor(t,e){super(),this.pos=t,this.mark=e}apply(e){let r=e.nodeAt(this.pos);if(!r)return p.fail("No node at mark step's position");let n=r.type.create(r.attrs,null,this.mark.removeFromSet(r.marks));return p.fromReplace(e,this.pos,this.pos+1,new t.Slice(t.Fragment.from(n),0,r.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new d(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new u(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new u(e.pos,t.markFromJSON(e.mark))}}a.jsonID("removeNodeMark",u);class m extends a{constructor(t,e,r,n=!1){super(),this.from=t,this.to=e,this.slice=r,this.structure=n}apply(t){return this.structure&&y(t,this.from,this.to)?p.fail("Structure replace would overwrite content"):p.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new o([this.from,this.to-this.from,this.slice.size])}invert(t){return new m(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return e.deletedAcross&&r.deletedAcross?null:new m(e.pos,Math.max(e.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof m)||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 r=this.slice.size+e.slice.size==0?t.Slice.empty:new t.Slice(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new m(e.from,this.to,r,this.structure)}}{let r=this.slice.size+e.slice.size==0?t.Slice.empty:new t.Slice(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new m(this.from,this.to+(e.to-e.from),r,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(e,r){if("number"!=typeof r.from||"number"!=typeof r.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new m(r.from,r.to,t.Slice.fromJSON(e,r.slice),!!r.structure)}}a.jsonID("replace",m);class g extends a{constructor(t,e,r,n,i,o,s=!1){super(),this.from=t,this.to=e,this.gapFrom=r,this.gapTo=n,this.slice=i,this.insert=o,this.structure=s}apply(t){if(this.structure&&(y(t,this.from,this.gapFrom)||y(t,this.gapTo,this.to)))return p.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return p.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,e.content);return r?p.fromReplace(t,this.from,this.to,r):p.fail("Content does not fit in gap")}getMap(){return new o([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new g(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),n=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),i=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return e.deletedAcross&&r.deletedAcross||n<e.pos||i>r.pos?null:new g(e.pos,r.pos,n,i,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(e,r){if("number"!=typeof r.from||"number"!=typeof r.to||"number"!=typeof r.gapFrom||"number"!=typeof r.gapTo||"number"!=typeof r.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new g(r.from,r.to,r.gapFrom,r.gapTo,t.Slice.fromJSON(e,r.slice),r.insert,!!r.structure)}}function y(t,e,r){let n=t.resolve(e),i=r-e,o=n.depth;for(;i>0&&o>0&&n.indexAfter(o)==n.node(o).childCount;)o--,i--;if(i>0){let t=n.node(o).maybeChild(n.indexAfter(o));for(;i>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,i--}}return!1}function w(e,r,n,i=n.contentMatch,o=!0){let s=e.doc.nodeAt(r),l=[],a=r+1;for(let p=0;p<s.childCount;p++){let r=s.child(p),h=a+r.nodeSize,c=i.matchType(r.type);if(c){i=c;for(let t=0;t<r.marks.length;t++)n.allowsMarkType(r.marks[t].type)||e.step(new f(a,h,r.marks[t]));if(o&&r.isText&&"pre"!=n.whitespace){let e,i,o=/\r?\n|\r/g;for(;e=o.exec(r.text);)i||(i=new t.Slice(t.Fragment.from(n.schema.text(" ",n.allowedMarks(r.marks))),0,0)),l.push(new m(a+e.index,a+e.index+e[0].length,i))}}else l.push(new m(a,h,t.Slice.empty));a=h}if(!i.validEnd){let r=i.fillBefore(t.Fragment.empty,!0);e.replace(a,a,new t.Slice(r,0,0))}for(let t=l.length-1;t>=0;t--)e.step(l[t])}function S(t,e,r){return(0==e||t.canReplace(e,t.childCount))&&(r==t.childCount||t.canReplace(0,r))}function k(t){return{type:t,attrs:null}}function v(t,e,r,n){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let i=t.mapping.slice(n).map(r+1+o+s.index);t.replaceWith(i,i+1,e.type.schema.linebreakReplacement.create())}}})}function x(t,e,r,n){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let i=t.mapping.slice(n).map(r+1+o);t.replaceWith(i,i+1,e.type.schema.text("\n"))}})}function M(t,e){return!(!t||!e||t.isLeaf||!function(t,e){e.content.size||t.type.compatibleContent(e.type);let r=t.contentMatchAt(t.childCount),{linebreakReplacement:n}=t.type.schema;for(let i=0;i<e.childCount;i++){let o=e.child(i),s=o.type==n?t.type.schema.nodes.text:o.type;if(r=r.matchType(s),!r)return!1;if(!t.type.allowsMarks(o.marks))return!1}return r.validEnd}(t,e))}function R(t,e,r){let n=t.resolve(e);if(n.parent.canReplaceWith(n.index(),n.index(),r))return e;if(0==n.parentOffset)for(let i=n.depth-1;i>=0;i--){let t=n.index(i);if(n.node(i).canReplaceWith(t,t,r))return n.before(i+1);if(t>0)return null}if(n.parentOffset==n.parent.content.size)for(let i=n.depth-1;i>=0;i--){let t=n.indexAfter(i);if(n.node(i).canReplaceWith(t,t,r))return n.after(i+1);if(t<n.node(i).childCount)return null}return null}function b(e,r,n=r,i=t.Slice.empty){if(r==n&&!i.size)return null;let o=e.resolve(r),s=e.resolve(n);return C(o,s,i)?new m(r,n,i):new N(o,s,i).fit()}function C(t,e,r){return!r.openStart&&!r.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),r.content)}a.jsonID("replaceAround",g);class N{constructor(e,r,n){this.$from=e,this.$to=r,this.unplaced=n,this.frontier=[],this.placed=t.Fragment.empty;for(let t=0;t<=e.depth;t++){let r=e.node(t);this.frontier.push({type:r.type,match:r.contentMatchAt(e.indexAfter(t))})}for(let i=e.depth;i>0;i--)this.placed=t.Fragment.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let t=this.findFittable();t?this.placeNodes(t):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),r=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let o=this.placed,s=n.depth,l=i.depth;for(;s&&l&&1==o.childCount;)o=o.firstChild.content,s--,l--;let a=new t.Slice(o,s,l);return e>-1?new g(n.pos,e,this.$to.pos,this.$to.end(),a,r):a.size||n.pos!=this.$to.pos?new m(n.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,n=this.unplaced.openEnd;r<e;r++){let i=t.firstChild;if(t.childCount>1&&(n=0),i.type.spec.isolating&&n<=r){e=r;break}t=i.content}for(let r=1;r<=2;r++)for(let n=1==r?e:this.unplaced.openStart;n>=0;n--){let e,i=null;n?(i=A(this.unplaced.content,n-1).firstChild,e=i.content):e=this.unplaced.content;let o=e.firstChild;for(let s=this.depth;s>=0;s--){let e,{type:l,match:a}=this.frontier[s],p=null;if(1==r&&(o?a.matchType(o.type)||(p=a.fillBefore(t.Fragment.from(o),!1)):i&&l.compatibleContent(i.type)))return{sliceDepth:n,frontierDepth:s,parent:i,inject:p};if(2==r&&o&&(e=a.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:s,parent:i,wrap:e};if(i&&a.matchType(i.type))break}}}openMore(){let{content:e,openStart:r,openEnd:n}=this.unplaced,i=A(e,r);return!(!i.childCount||i.firstChild.isLeaf)&&(this.unplaced=new t.Slice(e,r+1,Math.max(n,i.size+r>=e.size-n?r+1:0)),!0)}dropNode(){let{content:e,openStart:r,openEnd:n}=this.unplaced,i=A(e,r);if(i.childCount<=1&&r>0){let o=e.size-r<=r+i.size;this.unplaced=new t.Slice(T(e,r-1,1),r-1,o?r-1:n)}else this.unplaced=new t.Slice(T(e,r,1),r,n)}placeNodes({sliceDepth:e,frontierDepth:r,parent:n,inject:i,wrap:o}){for(;this.depth>r;)this.closeFrontierNode();if(o)for(let t=0;t<o.length;t++)this.openFrontierNode(o[t]);let s=this.unplaced,l=n?n.content:s.content,a=s.openStart-e,p=0,h=[],{match:c,type:f}=this.frontier[r];if(i){for(let t=0;t<i.childCount;t++)h.push(i.child(t));c=c.matchFragment(i)}let d=l.size+e-(s.content.size-s.openEnd);for(;p<l.childCount;){let t=l.child(p),e=c.matchType(t.type);if(!e)break;p++,(p>1||0==a||t.content.size)&&(c=e,h.push(E(t.mark(f.allowedMarks(t.marks)),1==p?a:0,p==l.childCount?d:-1)))}let u=p==l.childCount;u||(d=-1),this.placed=F(this.placed,r,t.Fragment.from(h)),this.frontier[r].match=c,u&&d<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let t=0,m=l;t<d;t++){let t=m.lastChild;this.frontier.push({type:t.type,match:t.contentMatchAt(t.childCount)}),m=t.content}this.unplaced=u?0==e?t.Slice.empty:new t.Slice(T(s.content,e-1,1),e-1,d<0?s.openEnd:e-1):new t.Slice(T(s.content,e,p),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let t,e=this.frontier[this.depth];if(!e.type.isTextblock||!I(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:r}=this.$to,n=this.$to.after(r);for(;r>1&&n==this.$to.end(--r);)++n;return n}findCloseLevel(t){t:for(let e=Math.min(this.depth,t.depth);e>=0;e--){let{match:r,type:n}=this.frontier[e],i=e<t.depth&&t.end(e+1)==t.pos+(t.depth-(e+1)),o=I(t,e,n,r,i);if(o){for(let r=e-1;r>=0;r--){let{match:e,type:n}=this.frontier[r],i=I(t,r,n,e,!0);if(!i||i.childCount)continue t}return{depth:e,fit:o,move:i?t.doc.resolve(t.after(e+1)):t}}}}close(t){let e=this.findCloseLevel(t);if(!e)return null;for(;this.depth>e.depth;)this.closeFrontierNode();e.fit.childCount&&(this.placed=F(this.placed,e.depth,e.fit)),t=e.move;for(let r=e.depth+1;r<=t.depth;r++){let e=t.node(r),n=e.type.contentMatch.fillBefore(e.content,!0,t.index(r));this.openFrontierNode(e.type,e.attrs,n)}return t}openFrontierNode(e,r=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=F(this.placed,this.depth,t.Fragment.from(e.create(r,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(t.Fragment.empty,!0);e.childCount&&(this.placed=F(this.placed,this.frontier.length,e))}}function T(t,e,r){return 0==e?t.cutByIndex(r,t.childCount):t.replaceChild(0,t.firstChild.copy(T(t.firstChild.content,e-1,r)))}function F(t,e,r){return 0==e?t.append(r):t.replaceChild(t.childCount-1,t.lastChild.copy(F(t.lastChild.content,e-1,r)))}function A(t,e){for(let r=0;r<e;r++)t=t.firstChild.content;return t}function E(e,r,n){if(r<=0)return e;let i=e.content;return r>1&&(i=i.replaceChild(0,E(i.firstChild,r-1,1==i.childCount?n-1:0))),r>0&&(i=e.type.contentMatch.fillBefore(i).append(i),n<=0&&(i=i.append(e.type.contentMatch.matchFragment(i).fillBefore(t.Fragment.empty,!0)))),e.copy(i)}function I(t,e,r,n,i){let o=t.node(e),s=i?t.indexAfter(e):t.index(e);if(s==o.childCount&&!r.compatibleContent(o.type))return null;let l=n.fillBefore(o.content,!0,s);return l&&!function(t,e,r){for(let n=r;n<e.childCount;n++)if(!t.allowsMarks(e.child(n).marks))return!0;return!1}(r,o.content,s)?l:null}function O(t){return t.spec.defining||t.spec.definingForContent}function J(e,r,n,i,o){if(r<n){let t=e.firstChild;e=e.replaceChild(0,t.copy(J(t.content,r+1,n,i,t)))}if(r>i){let r=o.contentMatchAt(0),n=r.fillBefore(e).append(e);e=n.append(r.matchFragment(n).fillBefore(t.Fragment.empty,!0))}return e}function z(t,e){let r=[];for(let n=Math.min(t.depth,e.depth);n>=0;n--){let i=t.start(n);if(i<t.pos-(t.depth-n)||e.end(n)>e.pos+(e.depth-n)||t.node(n).type.spec.isolating||e.node(n).type.spec.isolating)break;(i==e.start(n)||n==t.depth&&n==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&n&&e.start(n-1)==i-1)&&r.push(n)}return r}class _ extends a{constructor(t,e,r){super(),this.pos=t,this.attr=e,this.value=r}apply(e){let r=e.nodeAt(this.pos);if(!r)return p.fail("No node at attribute step's position");let n=Object.create(null);for(let t in r.attrs)n[t]=r.attrs[t];n[this.attr]=this.value;let i=r.type.create(n,null,r.marks);return p.fromReplace(e,this.pos,this.pos+1,new t.Slice(t.Fragment.from(i),0,r.isLeaf?0:1))}getMap(){return o.empty}invert(t){return new _(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new _(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new _(e.pos,e.attr,e.value)}}a.jsonID("attr",_);class D extends a{constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let n in t.attrs)e[n]=t.attrs[n];e[this.attr]=this.value;let r=t.type.create(e,t.content,t.marks);return p.ok(r)}getMap(){return o.empty}invert(t){return new D(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new D(e.attr,e.value)}}a.jsonID("docAttr",D),exports.TransformError=class extends Error{},exports.TransformError=function t(e){let r=Error.call(this,e);return r.__proto__=t.prototype,r},exports.TransformError.prototype=Object.create(Error.prototype),exports.TransformError.prototype.constructor=exports.TransformError,exports.TransformError.prototype.name="TransformError";exports.AddMarkStep=c,exports.AddNodeMarkStep=d,exports.AttrStep=_,exports.DocAttrStep=D,exports.MapResult=i,exports.Mapping=s,exports.RemoveMarkStep=f,exports.RemoveNodeMarkStep=u,exports.ReplaceAroundStep=g,exports.ReplaceStep=m,exports.Step=a,exports.StepMap=o,exports.StepResult=p,exports.Transform=class{constructor(t){this.doc=t,this.steps=[],this.docs=[],this.mapping=new s}get before(){return this.docs.length?this.docs[0]:this.doc}step(t){let e=this.maybeStep(t);if(e.failed)throw new exports.TransformError(e.failed);return this}maybeStep(t){let e=t.apply(this.doc);return e.failed||this.addStep(t,e.doc),e}get docChanged(){return this.steps.length>0}changedRange(){let t=1e9,e=-1e9;for(let r=0;r<this.mapping.maps.length;r++){let n=this.mapping.maps[r];r&&(t=n.map(t,1),e=n.map(e,-1)),n.forEach((r,n,i,o)=>{t=Math.min(t,i),e=Math.max(e,o)})}return 1e9==t?null:{from:t,to:e}}addStep(t,e){this.docs.push(this.doc),this.steps.push(t),this.mapping.appendMap(t.getMap()),this.doc=e}replace(e,r=e,n=t.Slice.empty){let i=b(this.doc,e,r,n);return i&&this.step(i),this}replaceWith(e,r,n){return this.replace(e,r,new t.Slice(t.Fragment.from(n),0,0))}delete(e,r){return this.replace(e,r,t.Slice.empty)}insert(t,e){return this.replaceWith(t,t,e)}replaceRange(e,r,n){return function(e,r,n,i){if(!i.size)return e.deleteRange(r,n);let o=e.doc.resolve(r),s=e.doc.resolve(n);if(C(o,s,i))return e.step(new m(r,n,i));let l=z(o,s);0==l[l.length-1]&&l.pop();let a=-(o.depth+1);l.unshift(a);for(let t=o.depth,d=o.pos-1;t>0;t--,d--){let e=o.node(t).type.spec;if(e.defining||e.definingAsContext||e.isolating)break;l.indexOf(t)>-1?a=t:o.before(t)==d&&l.splice(1,0,-t)}let p=l.indexOf(a),h=[],c=i.openStart;for(let t=i.content,d=0;;d++){let e=t.firstChild;if(h.push(e),d==i.openStart)break;t=e.content}for(let t=c-1;t>=0;t--){let e=h[t],r=O(e.type);if(r&&!e.sameMarkup(o.node(Math.abs(a)-1)))c=t;else if(r||!e.type.isTextblock)break}for(let d=i.openStart;d>=0;d--){let r=(d+c+1)%(i.openStart+1),a=h[r];if(a)for(let h=0;h<l.length;h++){let c=l[(h+p)%l.length],f=!0;c<0&&(f=!1,c=-c);let d=o.node(c-1),u=o.index(c-1);if(d.canReplaceWith(u,u,a.type,a.marks))return e.replace(o.before(c),f?s.after(c):n,new t.Slice(J(i.content,0,i.openStart,r),r,i.openEnd))}}let f=e.steps.length;for(let t=l.length-1;t>=0&&(e.replace(r,n,i),!(e.steps.length>f));t--){let e=l[t];e<0||(r=o.before(e),n=s.after(e))}}(this,e,r,n),this}replaceRangeWith(e,r,n){return function(e,r,n,i){if(!i.isInline&&r==n&&e.doc.resolve(r).parent.content.size){let t=R(e.doc,r,i.type);null!=t&&(r=n=t)}e.replaceRange(r,n,new t.Slice(t.Fragment.from(i),0,0))}(this,e,r,n),this}deleteRange(t,e){return function(t,e,r){let n=t.doc.resolve(e),i=t.doc.resolve(r),o=z(n,i);for(let s=0;s<o.length;s++){let e=o[s],r=s==o.length-1;if(r&&0==e||n.node(e).type.contentMatch.validEnd)return t.delete(n.start(e),i.end(e));if(e>0&&(r||n.node(e-1).canReplace(n.index(e-1),i.indexAfter(e-1))))return t.delete(n.before(e),i.after(e))}for(let s=1;s<=n.depth&&s<=i.depth;s++)if(e-n.start(s)==n.depth-s&&r>n.end(s)&&i.end(s)-r!=i.depth-s&&n.start(s-1)==i.start(s-1)&&n.node(s-1).canReplace(n.index(s-1),i.index(s-1)))return t.delete(n.before(s),r);t.delete(e,r)}(this,t,e),this}lift(e,r){return function(e,r,n){let{$from:i,$to:o,depth:s}=r,l=i.before(s+1),a=o.after(s+1),p=l,h=a,c=t.Fragment.empty,f=0;for(let m=s,g=!1;m>n;m--)g||i.index(m)>0?(g=!0,c=t.Fragment.from(i.node(m).copy(c)),f++):p--;let d=t.Fragment.empty,u=0;for(let m=s,g=!1;m>n;m--)g||o.after(m+1)<o.end(m)?(g=!0,d=t.Fragment.from(o.node(m).copy(d)),u++):h++;e.step(new g(p,h,l,a,new t.Slice(c.append(d),f,u),c.size-f,!0))}(this,e,r),this}join(e,r=1){return function(e,r,n){let i=null,{linebreakReplacement:o}=e.doc.type.schema,s=e.doc.resolve(r-n),l=s.node().type;if(o&&l.inlineContent){let t="pre"==l.whitespace,e=!!l.contentMatch.matchType(o);t&&!e?i=!1:!t&&e&&(i=!0)}let a=e.steps.length;if(!1===i){let t=e.doc.resolve(r+n);x(e,t.node(),t.before(),a)}l.inlineContent&&w(e,r+n-1,l,s.node().contentMatchAt(s.index()),null==i);let p=e.mapping.slice(a),h=p.map(r-n);if(e.step(new m(h,p.map(r+n,-1),t.Slice.empty,!0)),!0===i){let t=e.doc.resolve(h);v(e,t.node(),t.before(),e.steps.length)}}(this,e,r),this}wrap(e,r){return function(e,r,n){let i=t.Fragment.empty;for(let l=n.length-1;l>=0;l--){if(i.size){let t=n[l].type.contentMatch.matchFragment(i);if(!t||!t.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}i=t.Fragment.from(n[l].type.create(n[l].attrs,i))}let o=r.start,s=r.end;e.step(new g(o,s,o,s,new t.Slice(i,0,0),n.length,!0))}(this,e,r),this}setBlockType(e,r=e,n,i=null){return function(e,r,n,i,o){if(!i.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=e.steps.length;e.doc.nodesBetween(r,n,(r,n)=>{let l="function"==typeof o?o(r):o;if(r.isTextblock&&!r.hasMarkup(i,l)&&function(t,e,r){let n=t.resolve(e),i=n.index();return n.parent.canReplaceWith(i,i+1,r)}(e.doc,e.mapping.slice(s).map(n),i)){let o=null;if(i.schema.linebreakReplacement){let t="pre"==i.whitespace,e=!!i.contentMatch.matchType(i.schema.linebreakReplacement);t&&!e?o=!1:!t&&e&&(o=!0)}!1===o&&x(e,r,n,s),w(e,e.mapping.slice(s).map(n,1),i,void 0,null===o);let a=e.mapping.slice(s),p=a.map(n,1),h=a.map(n+r.nodeSize,1);return e.step(new g(p,h,p+1,h-1,new t.Slice(t.Fragment.from(i.create(l,null,r.marks)),0,0),1,!0)),!0===o&&v(e,r,n,s),!1}})}(this,e,r,n,i),this}setNodeMarkup(e,r,n=null,i){return function(e,r,n,i,o){let s=e.doc.nodeAt(r);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let l=n.create(i,null,o||s.marks);if(s.isLeaf)return e.replaceWith(r,r+s.nodeSize,l);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new g(r,r+s.nodeSize,r+1,r+s.nodeSize-1,new t.Slice(t.Fragment.from(l),0,0),1,!0))}(this,e,r,n,i),this}setNodeAttribute(t,e,r){return this.step(new _(t,e,r)),this}setDocAttribute(t,e){return this.step(new D(t,e)),this}addNodeMark(t,e){return this.step(new d(t,e)),this}removeNodeMark(e,r){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(r instanceof t.Mark)r.isInSet(n.marks)&&this.step(new u(e,r));else{let t,i=n.marks,o=[];for(;t=r.isInSet(i);)o.push(new u(e,t)),i=t.removeFromSet(i);for(let e=o.length-1;e>=0;e--)this.step(o[e])}return this}split(e,r=1,n){return function(e,r,n=1,i){let o=e.doc.resolve(r),s=t.Fragment.empty,l=t.Fragment.empty;for(let a=o.depth,p=o.depth-n,h=n-1;a>p;a--,h--){s=t.Fragment.from(o.node(a).copy(s));let e=i&&i[h];l=t.Fragment.from(e?e.type.create(e.attrs,l):o.node(a).copy(l))}e.step(new m(r,r,new t.Slice(s.append(l),n,n),!0))}(this,e,r,n),this}addMark(t,e,r){return function(t,e,r,n){let i,o,s=[],l=[];t.doc.nodesBetween(e,r,(t,a,p)=>{if(!t.isInline)return;let h=t.marks;if(!n.isInSet(h)&&p.type.allowsMarkType(n.type)){let p=Math.max(a,e),d=Math.min(a+t.nodeSize,r),u=n.addToSet(h);for(let t=0;t<h.length;t++)h[t].isInSet(u)||(i&&i.to==p&&i.mark.eq(h[t])?i.to=d:s.push(i=new f(p,d,h[t])));o&&o.to==p?o.to=d:l.push(o=new c(p,d,n))}}),s.forEach(e=>t.step(e)),l.forEach(e=>t.step(e))}(this,t,e,r),this}removeMark(e,r,n){return function(e,r,n,i){let o=[],s=0;e.doc.nodesBetween(r,n,(e,l)=>{if(!e.isInline)return;s++;let a=null;if(i instanceof t.MarkType){let t,r=e.marks;for(;t=i.isInSet(r);)(a||(a=[])).push(t),r=t.removeFromSet(r)}else i?i.isInSet(e.marks)&&(a=[i]):a=e.marks;if(a&&a.length){let t=Math.min(l+e.nodeSize,n);for(let e=0;e<a.length;e++){let n,i=a[e];for(let t=0;t<o.length;t++){let e=o[t];e.step==s-1&&i.eq(o[t].style)&&(n=e)}n?(n.to=t,n.step=s):o.push({style:i,from:Math.max(l,r),to:t,step:s})}}}),o.forEach(t=>e.step(new f(t.from,t.to,t.style)))}(this,e,r,n),this}clearIncompatible(t,e,r){return w(this,t,e,r),this}},exports.canJoin=function(t,e){let r=t.resolve(e),n=r.index();return M(r.nodeBefore,r.nodeAfter)&&r.parent.canReplace(n,n+1)},exports.canSplit=function(t,e,r=1,n){let i=t.resolve(e),o=i.depth-r,s=n&&n[n.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let p=i.depth-1,h=r-2;p>o;p--,h--){let t=i.node(p),e=i.index(p);if(t.type.spec.isolating)return!1;let r=t.content.cutByIndex(e,t.childCount),o=n&&n[h+1];o&&(r=r.replaceChild(0,o.type.create(o.attrs)));let s=n&&n[h]||t;if(!t.canReplace(e+1,t.childCount)||!s.type.validContent(r))return!1}let l=i.indexAfter(o),a=n&&n[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)},exports.dropPoint=function(t,e,r){let n=t.resolve(e);if(!r.content.size)return e;let i=r.content;for(let o=0;o<r.openStart;o++)i=i.firstChild.content;for(let o=1;o<=(0==r.openStart&&r.size?2:1);o++)for(let t=n.depth;t>=0;t--){let e=t==n.depth?0:n.pos<=(n.start(t+1)+n.end(t+1))/2?-1:1,r=n.index(t)+(e>0?1:0),s=n.node(t),l=!1;if(1==o)l=s.canReplace(r,r,i);else{let t=s.contentMatchAt(r).findWrapping(i.firstChild.type);l=t&&s.canReplaceWith(r,r,t[0])}if(l)return 0==e?n.pos:e<0?n.before(t+1):n.after(t+1)}return null},exports.findWrapping=function(t,e,r=null,n=t){let i=function(t,e){let{parent:r,startIndex:n,endIndex:i}=t,o=r.contentMatchAt(n).findWrapping(e);if(!o)return null;let s=o.length?o[0]:e;return r.canReplaceWith(n,i,s)?o:null}(t,e),o=i&&function(t,e){let{parent:r,startIndex:n,endIndex:i}=t,o=r.child(n),s=e.contentMatch.findWrapping(o.type);if(!s)return null;let l=(s.length?s[s.length-1]:e).contentMatch;for(let a=n;l&&a<i;a++)l=l.matchType(r.child(a).type);return l&&l.validEnd?s:null}(n,e);return o?i.map(k).concat({type:e,attrs:r}).concat(o.map(k)):null},exports.insertPoint=R,exports.joinPoint=function(t,e,r=-1){let n=t.resolve(e);for(let i=n.depth;;i--){let t,o,s=n.index(i);if(i==n.depth?(t=n.nodeBefore,o=n.nodeAfter):r>0?(t=n.node(i+1),s++,o=n.node(i).maybeChild(s)):(t=n.node(i).maybeChild(s-1),o=n.node(i+1)),t&&!t.isTextblock&&M(t,o)&&n.node(i).canReplace(s,s+1))return e;if(0==i)break;e=r<0?n.before(i):n.after(i)}},exports.liftTarget=function(t){let e=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,n=0,i=0;;--r){let o=t.$from.node(r),s=t.$from.index(r)+n,l=t.$to.indexAfter(r)-i;if(r<t.depth&&o.canReplace(s,l,e))return r;if(0==r||o.type.spec.isolating||!S(o,s,l))break;s&&(n=1),l<o.childCount&&(i=1)}return null},exports.replaceStep=b;