/*!
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
*/
import{Slice as e,Fragment as t,Node as r,Mark as n}from"../../prosemirror-model/dist/index.js";import{ReplaceStep as s,ReplaceAroundStep as i,Transform as o}from"../../prosemirror-transform/dist/index.js";const a=/* @__PURE__ */Object.create(null);class l{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new c(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(t,r=e.empty){let n=r.content.lastChild,s=null;for(let e=0;e<r.openEnd;e++)s=n,n=n.lastChild;let i=t.steps.length,o=this.ranges;for(let a=0;a<o.length;a++){let{$from:l,$to:c}=o[a],h=t.mapping.slice(i);t.replaceRange(h.map(l.pos),h.map(c.pos),a?e.empty:r),0==a&&k(t,i,(n?n.isInline:s&&s.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,n=this.ranges;for(let s=0;s<n.length;s++){let{$from:i,$to:o}=n[s],a=e.mapping.slice(r),l=a.map(i.pos),c=a.map(o.pos);s?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),k(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let n=e.parent.inlineContent?new u(e):y(e.node(0),e.parent,e.pos,e.index(),t,r);if(n)return n;for(let s=e.depth-1;s>=0;s--){let n=t<0?y(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):y(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(n)return n}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new g(e.node(0))}static atStart(e){return y(e,e,0,0,1)||new g(e)}static atEnd(e){return y(e,e,e.content.size,e.childCount,-1)||new g(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=a[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in a)throw new RangeError("Duplicate use of selection JSON ID "+e);return a[e]=t,t.prototype.jsonID=e,t}getBookmark(){return u.between(this.$anchor,this.$head).getBookmark()}}l.prototype.visible=!0;class c{constructor(e,t){this.$from=e,this.$to=t}}let h=!1;function p(e){h||e.parent.inlineContent||(h=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class u extends l{constructor(e,t=e){p(e),p(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return l.near(r);let n=e.resolve(t.map(this.anchor));return new u(n.parent.inlineContent?n:r,r)}replace(t,r=e.empty){if(super.replace(t,r),r==e.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(e){return e instanceof u&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new d(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 u(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let n=e.resolve(t);return new this(n,r==t?n:e.resolve(r))}static between(e,t,r){let n=e.pos-t.pos;if(r&&!n||(r=n>=0?1:-1),!t.parent.inlineContent){let e=l.findFrom(t,r,!0)||l.findFrom(t,-r,!0);if(!e)return l.near(t,r);t=e.$head}return e.parent.inlineContent||(0==n||(e=(l.findFrom(e,-r,!0)||l.findFrom(e,r,!0)).$anchor).pos<t.pos!=n<0)&&(e=t),new u(e,t)}}l.jsonID("text",u);class d{constructor(e,t){this.anchor=e,this.head=t}map(e){return new d(e.map(this.anchor),e.map(this.head))}resolve(e){return u.between(e.resolve(this.anchor),e.resolve(this.head))}}class f extends l{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:n}=t.mapResult(this.anchor),s=e.resolve(n);return r?l.near(s):new f(s)}content(){return new e(t.from(this.node),0,0)}eq(e){return e instanceof f&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new m(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new f(e.resolve(t.anchor))}static create(e,t){return new f(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}f.prototype.visible=!1,l.jsonID("node",f);class m{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new d(r,r):new m(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&f.isSelectable(r)?new f(t):l.near(t)}}class g extends l{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(t,r=e.empty){if(r==e.empty){t.delete(0,t.doc.content.size);let e=l.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,r)}toJSON(){return{type:"all"}}static fromJSON(e){return new g(e)}map(e){return new g(e)}eq(e){return e instanceof g}getBookmark(){return S}}l.jsonID("all",g);const S={map(){return this},resolve:e=>new g(e)};function y(e,t,r,n,s,i=!1){if(t.inlineContent)return u.create(e,r);for(let o=n-(s>0?0:1);s>0?o<t.childCount:o>=0;o+=s){let n=t.child(o);if(n.isAtom){if(!i&&f.isSelectable(n))return f.create(e,r-(s<0?n.nodeSize:0))}else{let t=y(e,n,r+s,s<0?n.childCount:0,s,i);if(t)return t}r+=n.nodeSize*s}return null}function k(e,t,r){let n=e.steps.length-1;if(n<t)return;let o,a=e.steps[n];(a instanceof s||a instanceof i)&&(e.mapping.maps[n].forEach((e,t,r,n)=>{null==o&&(o=n)}),e.setSelection(l.near(e.doc.resolve(o),r)))}class w extends o{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=/* @__PURE__ */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 n.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 r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||n.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let n=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(n.text(e),!0):this.deleteSelection();{if(null==r&&(r=t),!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let e=this.doc.resolve(t);s=r==t?e.marks():e.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,n.text(e,s)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(l.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 $(e,t){return t&&e?e.bind(t):e}class O{constructor(e,t,r){this.name=e,this.init=$(t.init,r),this.apply=$(t.apply,r)}}const M=[new O("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new O("selection",{init:(e,t)=>e.selection||l.atStart(t.doc),apply:e=>e.selection}),new O("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,r,n)=>n.selection.$cursor?e.storedMarks:null}),new O("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class v{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=/* @__PURE__ */Object.create(null),this.fields=M.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 O(e.key,e.spec.state,e))})}}class N{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=t){let t=this.config.plugins[r];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],r=this.applyInner(e),n=null;for(;;){let s=!1;for(let i=0;i<this.config.plugins.length;i++){let o=this.config.plugins[i];if(o.spec.appendTransaction){let a=n?n[i].n:0,l=n?n[i].state:this,c=a<t.length&&o.spec.appendTransaction.call(o,a?t.slice(a):t,l,r);if(c&&r.filterTransaction(c,i)){if(c.setMeta("appendedTransaction",e),!n){n=[];for(let e=0;e<this.config.plugins.length;e++)n.push(e<i?{state:r,n:t.length}:{state:this,n:0})}t.push(c),r=r.applyInner(c),s=!0}n&&(n[i]={state:r,n:t.length})}}if(!s)return{state:r,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new N(this.config),r=this.config.fields;for(let n=0;n<r.length;n++){let s=r[n];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new w(this)}static create(e){let t=new v(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new N(t);for(let n=0;n<t.fields.length;n++)r[t.fields[n].name]=t.fields[n].init(e,r);return r}reconfigure(e){let t=new v(this.schema,e.plugins),r=t.fields,n=new N(t);for(let s=0;s<r.length;s++){let t=r[s].name;n[t]=this.hasOwnProperty(t)?this[t]:r[s].init(e,n)}return n}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 r in e){if("doc"==r||"selection"==r)throw new RangeError("The JSON fields `doc` and `selection` are reserved");let n=e[r],s=n.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(n,this[n.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 s=new v(e.schema,e.plugins),i=new N(s);return s.fields.forEach(s=>{if("doc"==s.name)i.doc=r.fromJSON(e.schema,t.doc);else if("selection"==s.name)i.selection=l.fromJSON(i.doc,t.selection);else if("storedMarks"==s.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let r in n){let o=n[r],a=o.spec.state;if(o.key==s.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,r))return void(i[s.name]=a.fromJSON.call(o,e,t[r],i))}i[s.name]=s.init(e,i)}}),i}}function J(e,t,r){for(let n in e){let s=e[n];s instanceof Function?s=s.bind(t):"handleDOMEvents"==n&&(s=J(s,t,{})),r[n]=s}return r}class b{constructor(e){this.spec=e,this.props={},e.props&&J(e.props,this,this.props),this.key=e.key?e.key.key:T("plugin")}getState(e){return e[this.key]}}const x=/* @__PURE__ */Object.create(null);function T(e){return e in x?e+"$"+ ++x[e]:(x[e]=0,e+"$")}class R{constructor(e="key"){this.key=T(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}export{g as AllSelection,N as EditorState,f as NodeSelection,b as Plugin,R as PluginKey,l as Selection,c as SelectionRange,u as TextSelection,w as Transaction};