/*!
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{ReplaceAroundStep as e,liftTarget as t,canJoin as n,findWrapping as r,canSplit as o}from"../../prosemirror-transform/dist/index.js";import{Fragment as l,Slice as d,NodeRange as p}from"../../prosemirror-model/dist/index.js";function i(e,t=null){return function(n,r){let{$from:o,$to:l}=n.selection,d=o.blockRange(l);if(!d)return!1;let p=r?n.tr:null;return!!f(p,d,e,t)&&(r&&r(p.scrollIntoView()),!0)}}function f(t,n,i,f=null){let c=!1,s=n,u=n.$from.doc;if(n.depth>=2&&n.$from.node(n.depth-1).type.compatibleContent(i)&&0==n.startIndex){if(0==n.$from.index(n.depth-1))return!1;let e=u.resolve(n.start-2);s=new p(e,e,n.depth),n.endIndex<n.parent.childCount&&(n=new p(n.$from,u.resolve(n.$to.end(n.depth)),n.depth)),c=!0}let a=r(s,i,f,n);return!!a&&(t&&function(t,n,r,p,i){let f=l.empty;for(let e=r.length-1;e>=0;e--)f=l.from(r[e].type.create(r[e].attrs,f));t.step(new e(n.start-(p?2:0),n.end,n.start,n.end,new d(f,0,0),r.length,!0));let c=0;for(let e=0;e<r.length;e++)r[e].type==i&&(c=e+1);let s=r.length-c,u=n.start+r.length-(p?2:0),a=n.parent;for(let e=n.startIndex,l=n.endIndex,d=!0;e<l;e++,d=!1)!d&&o(t.doc,u,s)&&(t.split(u,s),u+=2*s),u+=a.child(e).nodeSize}(t,n,a,c,i),!0)}function c(r){return function(o,i){let{$from:f,$to:c}=o.selection,s=f.blockRange(c,e=>e.childCount>0&&e.firstChild.type==r);return!!s&&(!i||(f.node(s.depth-1).type==r?function(r,o,i,f){let c=r.tr,s=f.end,u=f.$to.end(f.depth);s<u&&(c.step(new e(s-1,u,s,u,new d(l.from(i.create(null,f.parent.copy())),1,0),1,!0)),f=new p(c.doc.resolve(f.$from.pos),c.doc.resolve(u),f.depth));const a=t(f);if(null==a)return!1;c.lift(f,a);let m=c.doc.resolve(c.mapping.map(s,-1)-1);n(c.doc,m.pos)&&m.nodeBefore.type==m.nodeAfter.type&&c.join(m.pos);return o(c.scrollIntoView()),!0}(o,i,r,s):function(t,n,r){let o=t.tr,p=r.parent;for(let e=r.end,l=r.endIndex-1,d=r.startIndex;l>d;l--)e-=p.child(l).nodeSize,o.delete(e-1,e+1);let i=o.doc.resolve(r.start),f=i.nodeAfter;if(o.mapping.map(r.end)!=r.start+i.nodeAfter.nodeSize)return!1;let c=0==r.startIndex,s=r.endIndex==p.childCount,u=i.node(-1),a=i.index(-1);if(!u.canReplace(a+(c?0:1),a+1,f.content.append(s?l.empty:l.from(p))))return!1;let m=i.pos,h=m+f.nodeSize;return o.step(new e(m-(c?1:0),h+(s?1:0),m+1,h-1,new d((c?l.empty:l.from(p.copy(l.empty))).append(s?l.empty:l.from(p.copy(l.empty))),c?0:1,s?0:1),c?0:1)),n(o.scrollIntoView()),!0}(o,i,s)))}}function s(t){return function(n,r){let{$from:o,$to:p}=n.selection,i=o.blockRange(p,e=>e.childCount>0&&e.firstChild.type==t);if(!i)return!1;let f=i.startIndex;if(0==f)return!1;let c=i.parent,s=c.child(f-1);if(s.type!=t)return!1;if(r){let o=s.lastChild&&s.lastChild.type==c.type,p=l.from(o?t.create():null),f=new d(l.from(t.create(null,l.from(c.type.create(null,p)))),o?3:1,0),u=i.start,a=i.end;r(n.tr.step(new e(u-(o?3:1),a,u,a,f,1,!0)).scrollIntoView())}return!0}}export{c as liftListItem,s as sinkListItem,i as wrapInList,f as wrapRangeInList};