/*!
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 e=require("../../prosemirror-keymap/dist/index.js"),t=require("../../prosemirror-state/dist/index.js"),r=require("../../prosemirror-model/dist/index.js"),n=require("../../prosemirror-view/dist/index.js");class o extends t.Selection{constructor(e){super(e,e)}map(e,r){let n=e.resolve(r.map(this.head));return o.valid(n)?new o(n):t.Selection.near(n)}content(){return r.Slice.empty}eq(e){return e instanceof o&&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 o(e.resolve(t.pos))}getBookmark(){return new i(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!function(e){for(let t=e.depth;t>=0;t--){let r=e.index(t),n=e.node(t);if(0!=r)for(let e=n.child(r-1);;e=e.lastChild){if(0==e.childCount&&!e.inlineContent||l(e.type))return!0;if(e.inlineContent)return!1}else if(n.type.spec.isolating)return!0}return!0}(e)||!function(e){for(let t=e.depth;t>=0;t--){let r=e.indexAfter(t),n=e.node(t);if(r!=n.childCount)for(let e=n.child(r);;e=e.firstChild){if(0==e.childCount&&!e.inlineContent||l(e.type))return!0;if(e.inlineContent)return!1}else if(n.type.spec.isolating)return!0}return!0}(e))return!1;let r=t.type.spec.allowGapCursor;if(null!=r)return r;let n=t.contentMatchAt(e.index()).defaultType;return n&&n.isTextblock}static findGapCursorFrom(e,r,n=!1){e:for(;;){if(!n&&o.valid(e))return e;let i=e.pos,l=null;for(let t=e.depth;;t--){let n=e.node(t);if(r>0?e.indexAfter(t)<n.childCount:e.index(t)>0){l=n.child(r>0?e.indexAfter(t):e.index(t)-1);break}if(0==t)return null;i+=r;let s=e.doc.resolve(i);if(o.valid(s))return s}for(;;){let s=r>0?l.firstChild:l.lastChild;if(!s){if(l.isAtom&&!l.isText&&!t.NodeSelection.isSelectable(l)){e=e.doc.resolve(i+l.nodeSize*r),n=!1;continue e}break}l=s,i+=r;let c=e.doc.resolve(i);if(o.valid(c))return c}return null}}}o.prototype.visible=!1,o.findFrom=o.findGapCursorFrom,t.Selection.jsonID("gapcursor",o);class i{constructor(e){this.pos=e}map(e){return new i(e.map(this.pos))}resolve(e){let r=e.resolve(this.pos);return o.valid(r)?new o(r):t.Selection.near(r)}}function l(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}const s=e.keydownHandler({ArrowLeft:c("horiz",-1),ArrowRight:c("horiz",1),ArrowUp:c("vert",-1),ArrowDown:c("vert",1)});function c(e,r){const n="vert"==e?r>0?"down":"up":r>0?"right":"left";return function(e,i,l){let s=e.selection,c=r>0?s.$to:s.$from,a=s.empty;if(s instanceof t.TextSelection){if(!l.endOfTextblock(n)||0==c.depth)return!1;a=!1,c=e.doc.resolve(r>0?c.after():c.before())}let d=o.findGapCursorFrom(c,r,a);return!!d&&(i&&i(e.tr.setSelection(new o(d))),!0)}}function a(e,r,n){if(!e||!e.editable)return!1;let i=e.state.doc.resolve(r);if(!o.valid(i))return!1;let l=e.posAtCoords({left:n.clientX,top:n.clientY});return!(l&&l.inside>-1&&t.NodeSelection.isSelectable(e.state.doc.nodeAt(l.inside)))&&(e.dispatch(e.state.tr.setSelection(new o(i))),!0)}function d(e,n){if("insertCompositionText"!=n.inputType||!(e.state.selection instanceof o))return!1;let{$from:i}=e.state.selection,l=i.parent.contentMatchAt(i.index()).findWrapping(e.state.schema.nodes.text);if(!l)return!1;let s=r.Fragment.empty;for(let t=l.length-1;t>=0;t--)s=r.Fragment.from(l[t].createAndFill(null,s));let c=e.state.tr.replace(i.pos,i.pos,new r.Slice(s,0,0));return c.setSelection(t.TextSelection.near(c.doc.resolve(i.pos+1))),e.dispatch(c),!1}function u(e){if(!(e.selection instanceof o))return null;let t=document.createElement("div");return t.className="ProseMirror-gapcursor",n.DecorationSet.create(e.doc,[n.Decoration.widget(e.selection.head,t,{key:"gapcursor"})])}exports.GapCursor=o,exports.gapCursor=function(){return new t.Plugin({props:{decorations:u,createSelectionBetween:(e,t,r)=>t.pos==r.pos&&o.valid(r)?new o(r):null,handleClick:a,handleKeyDown:s,handleDOMEvents:{beforeinput:d}}})};