"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index-XcBgidt4.cjs");function S(f,t=null){return function(e,n){let{$from:o,$to:l}=e.selection,i=o.blockRange(l);if(!i)return!1;let d=n?e.tr:null;return h(d,i,f,t)?(n&&n(d.scrollIntoView()),!0):!1}}function h(f,t,e,n=null){let o=!1,l=t,i=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(e)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let u=i.resolve(t.start-2);l=new r.NodeRange(u,u,t.depth),t.endIndex<t.parent.childCount&&(t=new r.NodeRange(t.$from,i.resolve(t.$to.end(t.depth)),t.depth)),o=!0}let d=r.findWrapping(l,e,n,t);return d?(f&&$(f,t,d,o,e),!0):!1}function $(f,t,e,n,o){let l=r.Fragment.empty;for(let p=e.length-1;p>=0;p--)l=r.Fragment.from(e[p].type.create(e[p].attrs,l));f.step(new r.ReplaceAroundStep(t.start-(n?2:0),t.end,t.start,t.end,new r.Slice(l,0,0),e.length,!0));let i=0;for(let p=0;p<e.length;p++)e[p].type==o&&(i=p+1);let d=e.length-i,u=t.start+e.length-(n?2:0),m=t.parent;for(let p=t.startIndex,s=t.endIndex,c=!0;p<s;p++,c=!1)!c&&r.canSplit(f.doc,u,d)&&(f.split(u,d),u+=2*d),u+=m.child(p).nodeSize;return f}function R(f){return function(t,e){let{$from:n,$to:o}=t.selection,l=n.blockRange(o,i=>i.childCount>0&&i.firstChild.type==f);return l?e?n.node(l.depth-1).type==f?x(t,e,f,l):F(t,e,l):!0:!1}}function x(f,t,e,n){let o=f.tr,l=n.end,i=n.$to.end(n.depth);l<i&&(o.step(new r.ReplaceAroundStep(l-1,i,l,i,new r.Slice(r.Fragment.from(e.create(null,n.parent.copy())),1,0),1,!0)),n=new r.NodeRange(o.doc.resolve(n.$from.pos),o.doc.resolve(i),n.depth));const d=r.liftTarget(n);if(d==null)return!1;o.lift(n,d);let u=o.doc.resolve(o.mapping.map(l,-1)-1);return r.canJoin(o.doc,u.pos)&&u.nodeBefore.type==u.nodeAfter.type&&o.join(u.pos),t(o.scrollIntoView()),!0}function F(f,t,e){let n=f.tr,o=e.parent;for(let a=e.end,I=e.endIndex-1,y=e.startIndex;I>y;I--)a-=o.child(I).nodeSize,n.delete(a-1,a+1);let l=n.doc.resolve(e.start),i=l.nodeAfter;if(n.mapping.map(e.end)!=e.start+l.nodeAfter.nodeSize)return!1;let d=e.startIndex==0,u=e.endIndex==o.childCount,m=l.node(-1),p=l.index(-1);if(!m.canReplace(p+(d?0:1),p+1,i.content.append(u?r.Fragment.empty:r.Fragment.from(o))))return!1;let s=l.pos,c=s+i.nodeSize;return n.step(new r.ReplaceAroundStep(s-(d?1:0),c+(u?1:0),s+1,c-1,new r.Slice((d?r.Fragment.empty:r.Fragment.from(o.copy(r.Fragment.empty))).append(u?r.Fragment.empty:r.Fragment.from(o.copy(r.Fragment.empty))),d?0:1,u?0:1),d?0:1)),t(n.scrollIntoView()),!0}exports.liftListItem=R;exports.wrapInList=S;exports.wrapRangeInList=h;
