var e=/^(\s*)(\d+)([.)])(\s+)(.*)$/,t=/^(\s*)([-+*])(\s+)(.*)$/,n=/^(\s*)(?:\d+[.)]|[-+*])\s+/,r=5,i=4,a=` `.repeat(i);function o(e){let t=e.includes(`	`)?(e.match(/\t/g)||[]).length:Math.floor(e.length/i);return Math.max(0,Math.min(t,r))}function s(n,r,i){let a=n.match(e);if(a){let e=a[1].length;return{number:i,from:r,leadLen:e,level:o(a[1]),ordered:!0,markFrom:r+e,markLen:a[2].length,sep:a[3],newLevel:o(a[1])}}let s=n.match(t);if(s){let e=s[1].length;return{number:i,from:r,leadLen:e,level:o(s[1]),ordered:!1,markFrom:r+e,markLen:s[2].length,sep:``,newLevel:o(s[1])}}return null}function c(e,t){let{state:i}=e,o=i.doc,c=i.selection.main,l=o.lineAt(c.from).number,u=o.lineAt(c.to).number,d=e=>n.test(o.line(e).text),f=!1;for(let e=l;e<=u;e++)if(d(e)){f=!0;break}if(!f)return!1;let p=l;for(;p>1&&d(p-1);)p--;let m=u;for(;m<o.lines&&d(m+1);)m++;let h=[];for(let e=p;e<=m;e++){let t=o.line(e),n=s(t.text,t.from,e);n&&h.push(n)}if(h.length===0)return!1;let g=h.findIndex(e=>e.number>=l&&e.number<=u),_=h[g],v=g>0?h[g-1].level:-1,y=(t>0?Math.min(_.level+1,v<0?_.level:Math.min(v+1,r)):Math.max(_.level-1,0))-_.level;if(y===0)return!0;for(let e of h)e.newLevel=e.number>=l&&e.number<=u?Math.max(0,Math.min(e.level+y,r)):e.level;let b=[],x=[];for(let e of h){let t=a.repeat(e.newLevel);if((t.length!==e.leadLen||/\t/.test(o.sliceString(e.from,e.from+e.leadLen)))&&x.push({from:e.from,to:e.from+e.leadLen,insert:t}),!e.ordered)continue;let n=e.newLevel;b[n]===void 0&&(b[n]=n===0&&parseInt(o.sliceString(e.markFrom,e.markFrom+e.markLen),10)||1);let r=b[n];b[n]++,b.length=n+1;let i=String(r);i!==o.sliceString(e.markFrom,e.markFrom+e.markLen)&&x.push({from:e.markFrom,to:e.markFrom+e.markLen,insert:i})}return x.length===0||e.dispatch(i.update({changes:x,userEvent:t>0?`input.indent`:`delete.dedent`,scrollIntoView:!0})),!0}var l=e=>c(e,1),u=e=>c(e,-1);export{u as listIndentLess,l as listIndentMore};