/*!
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-transform/dist/index.js"),t=require("../../prosemirror-model/dist/index.js"),o=require("../../prosemirror-state/dist/index.js"),n=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function r(e,t){let{$cursor:o}=e.selection;return!o||(t?!t.endOfTextblock("backward",e):o.parentOffset>0)?null:o}const l=(n,l,i)=>{let s=r(n,i);if(!s)return!1;let f=p(s);if(!f){let t=s.blockRange(),o=t&&e.liftTarget(t);return null!=o&&(l&&l(n.tr.lift(t,o).scrollIntoView()),!0)}let a=f.nodeBefore;if(k(n,f,l,-1))return!0;if(0==s.parent.content.size&&(c(a,"end")||o.NodeSelection.isSelectable(a)))for(let r=s.depth;;r--){let i=e.replaceStep(n.doc,s.before(r),s.after(r),t.Slice.empty);if(i&&i.slice.size<i.to-i.from){if(l){let e=n.tr.step(i);e.setSelection(c(a,"end")?o.Selection.findFrom(e.doc.resolve(e.mapping.map(f.pos,-1)),-1):o.NodeSelection.create(e.doc,f.pos-a.nodeSize)),l(e.scrollIntoView())}return!0}if(1==r||s.node(r-1).childCount>1)break}return!(!a.isAtom||f.depth!=s.depth-1)&&(l&&l(n.tr.delete(f.pos-a.nodeSize,f.pos).scrollIntoView()),!0)};function i(n,r,l){let i=r.nodeBefore,c=r.pos-1;for(;!i.isTextblock;c--){if(i.type.spec.isolating)return!1;let e=i.lastChild;if(!e)return!1;i=e}let s=r.nodeAfter,p=r.pos+1;for(;!s.isTextblock;p++){if(s.type.spec.isolating)return!1;let e=s.firstChild;if(!e)return!1;s=e}let f=e.replaceStep(n.doc,c,p,t.Slice.empty);if(!f||f.from!=c||f instanceof e.ReplaceStep&&f.slice.size>=p-c)return!1;if(l){let e=n.tr.step(f);e.setSelection(o.TextSelection.create(e.doc,c)),l(e.scrollIntoView())}return!0}function c(e,t,o=!1){for(let n=e;n;n="start"==t?n.firstChild:n.lastChild){if(n.isTextblock)return!0;if(o&&1!=n.childCount)return!1}return!1}const s=(e,t,n)=>{let{$head:r,empty:l}=e.selection,i=r;if(!l)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;i=p(r)}let c=i&&i.nodeBefore;return!(!c||!o.NodeSelection.isSelectable(c))&&(t&&t(e.tr.setSelection(o.NodeSelection.create(e.doc,i.pos-c.nodeSize)).scrollIntoView()),!0)};function p(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function f(e,t){let{$cursor:o}=e.selection;return!o||(t?!t.endOfTextblock("forward",e):o.parentOffset<o.parent.content.size)?null:o}const a=(n,r,l)=>{let i=f(n,l);if(!i)return!1;let s=u(i);if(!s)return!1;let p=s.nodeAfter;if(k(n,s,r,1))return!0;if(0==i.parent.content.size&&(c(p,"start")||o.NodeSelection.isSelectable(p))){let l=e.replaceStep(n.doc,i.before(),i.after(),t.Slice.empty);if(l&&l.slice.size<l.to-l.from){if(r){let e=n.tr.step(l);e.setSelection(c(p,"start")?o.Selection.findFrom(e.doc.resolve(e.mapping.map(s.pos)),1):o.NodeSelection.create(e.doc,e.mapping.map(s.pos))),r(e.scrollIntoView())}return!0}}return!(!p.isAtom||s.depth!=i.depth-1)&&(r&&r(n.tr.delete(s.pos,s.pos+p.nodeSize).scrollIntoView()),!0)},d=(e,t,n)=>{let{$head:r,empty:l}=e.selection,i=r;if(!l)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset<r.parent.content.size)return!1;i=u(r)}let c=i&&i.nodeAfter;return!(!c||!o.NodeSelection.isSelectable(c))&&(t&&t(e.tr.setSelection(o.NodeSelection.create(e.doc,i.pos)).scrollIntoView()),!0)};function u(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let o=e.node(t);if(e.index(t)+1<o.childCount)return e.doc.resolve(e.after(t+1));if(o.type.spec.isolating)break}return null}const S=(e,t)=>{let{$head:o,$anchor:n}=e.selection;return!(!o.parent.type.spec.code||!o.sameParent(n))&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function x(e){for(let t=0;t<e.edgeCount;t++){let{type:o}=e.edge(t);if(o.isTextblock&&!o.hasRequiredAttrs())return o}return null}const h=(e,t)=>{let n=e.selection,{$from:r,$to:l}=n;if(n instanceof o.AllSelection||r.parent.inlineContent||l.parent.inlineContent)return!1;let i=x(l.parent.contentMatchAt(l.indexAfter()));if(!i||!i.isTextblock)return!1;if(t){let n=(!r.parentOffset&&l.index()<l.parent.childCount?r:l).pos,c=e.tr.insert(n,i.createAndFill());c.setSelection(o.TextSelection.create(c.doc,n+1)),t(c.scrollIntoView())}return!0},m=(t,o)=>{let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(e.canSplit(t.doc,r))return o&&o(t.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),l=r&&e.liftTarget(r);return null!=l&&(o&&o(t.tr.lift(r,l).scrollIntoView()),!0)};function g(t){return(t,n)=>{let{$from:r,$to:l}=t.selection;if(t.selection instanceof o.NodeSelection&&t.selection.node.isBlock)return!(!r.parentOffset||!e.canSplit(t.doc,r.pos))&&(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let i,c,s=[],p=!1,f=!1;for(let e=r.depth;;e--){if(r.node(e).isBlock){p=r.end(e)==r.pos+(r.depth-e),f=r.start(e)==r.pos-(r.depth-e),c=x(r.node(e-1).contentMatchAt(r.indexAfter(e-1))),s.unshift(p&&c?{type:c}:null),i=e;break}if(1==e)return!1;s.unshift(null)}let a=t.tr;(t.selection instanceof o.TextSelection||t.selection instanceof o.AllSelection)&&a.deleteSelection();let d=a.mapping.map(r.pos),u=e.canSplit(a.doc,d,s.length,s);if(u||(s[0]=c?{type:c}:null,u=e.canSplit(a.doc,d,s.length,s)),!u)return!1;if(a.split(d,s.length,s),!p&&f&&r.node(i).type!=c){let e=a.mapping.map(r.before(i)),t=a.doc.resolve(e);c&&r.node(i-1).canReplaceWith(t.index(),t.index()+1,c)&&a.setNodeMarkup(a.mapping.map(r.before(i)),c)}return n&&n(a.scrollIntoView()),!0}}const b=g();function k(n,r,l,i){let s,p,f=r.nodeBefore,a=r.nodeAfter,d=f.type.spec.isolating||a.type.spec.isolating;if(!d&&function(t,o,n){let r=o.nodeBefore,l=o.nodeAfter,i=o.index();return!(!(r&&l&&r.type.compatibleContent(l.type))||(!r.content.size&&o.parent.canReplace(i-1,i)?(n&&n(t.tr.delete(o.pos-r.nodeSize,o.pos).scrollIntoView()),0):!o.parent.canReplace(i,i+1)||!l.isTextblock&&!e.canJoin(t.doc,o.pos)||(n&&n(t.tr.join(o.pos).scrollIntoView()),0)))}(n,r,l))return!0;let u=!d&&r.parent.canReplace(r.index(),r.index()+1);if(u&&(s=(p=f.contentMatchAt(f.childCount)).findWrapping(a.type))&&p.matchType(s[0]||a.type).validEnd){if(l){let o=r.pos+a.nodeSize,i=t.Fragment.empty;for(let e=s.length-1;e>=0;e--)i=t.Fragment.from(s[e].create(null,i));i=t.Fragment.from(f.copy(i));let c=n.tr.step(new e.ReplaceAroundStep(r.pos-1,o,r.pos,o,new t.Slice(i,1,0),s.length,!0)),p=c.doc.resolve(o+2*s.length);p.nodeAfter&&p.nodeAfter.type==f.type&&e.canJoin(c.doc,p.pos)&&c.join(p.pos),l(c.scrollIntoView())}return!0}let S=a.type.spec.isolating||i>0&&d?null:o.Selection.findFrom(r,1),x=S&&S.$from.blockRange(S.$to),h=x&&e.liftTarget(x);if(null!=h&&h>=r.depth)return l&&l(n.tr.lift(x,h).scrollIntoView()),!0;if(u&&c(a,"start",!0)&&c(f,"end")){let o=f,i=[];for(;i.push(o),!o.isTextblock;)o=o.lastChild;let c=a,s=1;for(;!c.isTextblock;c=c.firstChild)s++;if(o.canReplace(o.childCount,o.childCount,c.content)){if(l){let o=t.Fragment.empty;for(let e=i.length-1;e>=0;e--)o=t.Fragment.from(i[e].copy(o));l(n.tr.step(new e.ReplaceAroundStep(r.pos-i.length,r.pos+a.nodeSize,r.pos+s,r.pos+a.nodeSize-s,new t.Slice(o,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function w(e){return function(t,n){let r=t.selection,l=e<0?r.$from:r.$to,i=l.depth;for(;l.node(i).isInline;){if(!i)return!1;i--}return!!l.node(i).isTextblock&&(n&&n(t.tr.setSelection(o.TextSelection.create(t.doc,e<0?l.start(i):l.end(i)))),!0)}}const y=w(-1),T=w(1);function I(...e){return function(t,o,n){for(let r=0;r<e.length;r++)if(e[r](t,o,n))return!0;return!1}}I(n,l,s),I(n,a,d),I(S,h,m,b),"undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&os.platform(),exports.chainCommands=I,exports.createParagraphNear=h,exports.deleteSelection=n,exports.exitCode=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let l=n.node(-1),i=n.indexAfter(-1),c=x(l.contentMatchAt(i));if(!c||!l.canReplaceWith(i,i,c))return!1;if(t){let r=n.after(),l=e.tr.replaceWith(r,r,c.createAndFill());l.setSelection(o.Selection.near(l.doc.resolve(r),1)),t(l.scrollIntoView())}return!0},exports.joinBackward=l,exports.joinDown=(t,n)=>{let r,l=t.selection;if(l instanceof o.NodeSelection){if(l.node.isTextblock||!e.canJoin(t.doc,l.to))return!1;r=l.to}else if(r=e.joinPoint(t.doc,l.to,1),null==r)return!1;return n&&n(t.tr.join(r).scrollIntoView()),!0},exports.joinForward=a,exports.joinTextblockBackward=(e,t,o)=>{let n=r(e,o);if(!n)return!1;let l=p(n);return!!l&&i(e,l,t)},exports.joinTextblockForward=(e,t,o)=>{let n=f(e,o);if(!n)return!1;let r=u(n);return!!r&&i(e,r,t)},exports.joinUp=(t,n)=>{let r,l=t.selection,i=l instanceof o.NodeSelection;if(i){if(l.node.isTextblock||!e.canJoin(t.doc,l.from))return!1;r=l.from}else if(r=e.joinPoint(t.doc,l.from,-1),null==r)return!1;if(n){let e=t.tr.join(r);i&&e.setSelection(o.NodeSelection.create(e.doc,r-t.doc.resolve(r).nodeBefore.nodeSize)),n(e.scrollIntoView())}return!0},exports.lift=(t,o)=>{let{$from:n,$to:r}=t.selection,l=n.blockRange(r),i=l&&e.liftTarget(l);return null!=i&&(o&&o(t.tr.lift(l,i).scrollIntoView()),!0)},exports.liftEmptyBlock=m,exports.newlineInCode=S,exports.selectNodeBackward=s,exports.selectNodeForward=d,exports.selectParentNode=(e,t)=>{let n,{$from:r,to:l}=e.selection,i=r.sharedDepth(l);return 0!=i&&(n=r.before(i),t&&t(e.tr.setSelection(o.NodeSelection.create(e.doc,n))),!0)},exports.selectTextblockEnd=T,exports.selectTextblockStart=y,exports.setBlockType=function(e,t=null){return function(o,n){let r=!1;for(let l=0;l<o.selection.ranges.length&&!r;l++){let{$from:{pos:n},$to:{pos:i}}=o.selection.ranges[l];o.doc.nodesBetween(n,i,(n,l)=>{if(r)return!1;if(n.isTextblock&&!n.hasMarkup(e,t))if(n.type==e)r=!0;else{let t=o.doc.resolve(l),n=t.index();r=t.parent.canReplaceWith(n,n+1,e)}})}if(!r)return!1;if(n){let r=o.tr;for(let n=0;n<o.selection.ranges.length;n++){let{$from:{pos:l},$to:{pos:i}}=o.selection.ranges[n];r.setBlockType(l,i,e,t)}n(r.scrollIntoView())}return!0}},exports.splitBlock=b,exports.splitBlockAs=g,exports.wrapIn=function(t,o=null){return function(n,r){let{$from:l,$to:i}=n.selection,c=l.blockRange(i),s=c&&e.findWrapping(c,t,o);return!!s&&(r&&r(n.tr.wrap(c,s).scrollIntoView()),!0)}};