UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 23.4 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$ as t,C as n,E as r,F as i,G as a,P as o,U as s,W as c,Y as l,_ as u,at as d,b as f,et as p,g as m,ht as ee,it as h,lt as g,nt as _,ot as te,q as v,rt as ne,t as re,tt as ie,x as ae,y,z as oe}from"./dist-Bqm7i9hf.js";function se(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}function b(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}function ce(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-F,r),o=e.sliceDoc(i,i+F),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=100?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+F),d=e.sliceDoc(i-F,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function le(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function ue(e,t,n=t.selection.ranges){let r=n.map(e=>b(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>ce(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function de(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=b(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}function fe(e={}){return[z,R.of(e),i.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?B:e.inputType==`historyRedo`?V:null;return n?(e.preventDefault(),n(t)):!1}})]}function x(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(z,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}function S(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function pe(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function me(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function he(e,t){return e.length?t.length?e.concat(t):e:t}function ge(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Ue));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),S(e,e.length-1,1e9,n.setSelAfter(r)))}return[H.selection([t])]}function _e(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function ve(e,t){if(!e.length)return e;let n=e.length,r=U;for(;n;){let i=ye(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}t=i.mapped,n--,r=i.selectionsAfter}return r.length?[H.selection(r)]:U}function ye(e,n,r){let i=he(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(n)):U,r);if(!e.changes)return H.selection(i);let a=e.changes.map(n),o=n.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(o):o;return new H(a,t.mapEffects(e.effects,n),s,e.startSelection.map(o),i)}function C(e,t){return v.create(e.ranges.map(t),e.mainIndex)}function w(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function T({state:e,dispatch:t},n){let r=C(e.selection,n);return!r.eq(e.selection,!0)&&(t(w(e,r)),!0)}function E(e,t){return v.cursor(t?e.to:e.from)}function be(e,t){return T(e,n=>n.empty?e.moveByChar(n,t):E(n,t))}function D(e){return e.textDirectionAt(e.state.selection.main.head)==o.LTR}function xe(e,t){return T(e,n=>n.empty?e.moveByGroup(n,t):E(n,t))}function Se(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function O(e,t,i){let a=r(e).resolveInner(t.head),o=i?g.closedBy:g.openedBy;for(let n=t.head;;){let t=i?a.childAfter(n):a.childBefore(n);if(!t)break;Se(e,t,o)?a=t:n=i?t.to:t.from}let s=a.type.prop(o),c,l;return l=s&&(c=i?n(e,a.from,1):n(e,a.to,-1))&&c.matched?i?c.end.to:c.end.from:i?a.to:a.from,v.cursor(l,i?-1:1)}function Ce(e,t){return T(e,n=>{if(!n.empty)return E(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}function we(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,a;if(t){for(let t of e.state.facet(i.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}a=e.scrollDOM.clientHeight-n-r}else a=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,a-5)}}function Te(e,t){let n=we(e),{state:r}=e,a=C(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):E(r,t));if(a.eq(r.selection))return!1;let o;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),s=e.scrollDOM.getBoundingClientRect(),c=s.top+n.marginTop,l=s.bottom-n.marginBottom;t&&t.top>c&&t.bottom<l&&(o=i.scrollIntoView(a.main.head,{y:`start`,yMargin:t.top-c}))}return e.dispatch(w(r,a),{effects:o}),!0}function k(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=v.cursor(r.from+n))}return i}function Ee(e,t,r){let i=!1,a=C(e.selection,t=>{let a=n(e,t.head,-1)||n(e,t.head,1)||t.head>0&&n(e,t.head-1,1)||t.head<e.doc.length&&n(e,t.head+1,-1);if(!a||!a.end)return t;i=!0;let o=a.start.from==t.head?a.end.to:a.end.from;return r?v.range(t.anchor,o):v.cursor(o)});return i?(t(w(e,a)),!0):!1}function A(e,t,n){let r=C(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=v.range(e.head,e.anchor));let r=n(e);return v.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return!r.eq(e.state.selection)&&(e.dispatch(w(e.state,r)),!0)}function De(e,t){return A(e,t,n=>e.moveByChar(n,t))}function Oe(e,t){return A(e,t,n=>e.moveByGroup(n,t))}function ke(e,t){return A(e,t,n=>e.moveVertically(n,t))}function Ae(e,t){return A(e,t,n=>e.moveVertically(n,t,we(e).height))}function je(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}if(r.head==n.head)break;n=r}}return i.length!=r.ranges.length&&(e.dispatch(w(n,v.create(i,i.length-1))),!0)}function j(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,a=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=M(e,o,!1)):o>i&&(n=`delete.forward`,o=M(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=M(e,i,!1),a=M(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:v.cursor(i,i<r.head?-1:1)}});return!a.changes.empty&&(e.dispatch(r.update(a,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?i.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function M(e,t,n){if(e instanceof i)for(let r of e.state.facet(i.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}function N(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Me(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of N(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(v.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(v.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:v.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}function Ne(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of N(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}function Pe(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=r(e).resolveInner(t),i=n.childBefore(t),a=n.childAfter(t),o;return i&&a&&i.to<=t&&a.from>=t&&(o=i.type.prop(g.closedBy))&&o.indexOf(a.name)>-1&&e.doc.lineAt(i.to).from==e.doc.lineAt(a.from).from&&!/\S/.test(e.sliceDoc(i.to,a.from))?{from:i.to,to:a.from}:null}function Fe(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&Pe(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new re(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=u(s,r);for(c??=h(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,y(t,c)];return o&&l.push(y(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:ie.of(l)},range:v.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function P(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:v.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Ie,Le,Re,ze,F,I,Be,L,R,z,B,V,Ve,He,H,U,Ue,We,W,Ge,G,K,Ke,qe,Je,Ye,q,J,Y,X,Xe,Ze,Qe,$e,et,tt,nt,Z,rt,it,at,ot,st,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,Q,vt,yt,bt,xt,St,Ct,wt,Tt,Et,Dt,$,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,Gt,Kt,qt,Jt,Yt,Xt,Zt;function Qt(){return(Qt=e((()=>{te(),oe(),ae(),ee(),Ie=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=b(e.state,n.from);return r.line?Le(e):r.block?ze(e):!1},Le=se(de,0),Re=se(ue,0),ze=se((e,t)=>ue(e,t,le(t)),0),F=50,I=s.define(),Be=s.define(),L=l.define(),R=l.define({combine(e){return ne(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),z=p.define({create(){return W.empty},update(e,t){let n=t.state.facet(R),r=t.annotation(I);if(r){let i=H.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?S(o,o.length,n.minDepth,i):ge(o,t.startState.selection),new W(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(Be);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(_.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=H.fromTransaction(t),o=t.annotation(_.time),s=t.annotation(_.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new W(e.done.map(H.fromJSON),e.undone.map(H.fromJSON))}}),B=x(0,!1),V=x(1,!1),Ve=x(0,!0),He=x(1,!0),H=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&a.fromJSON(t.changes),[],t.mapped&&c.fromJSON(t.mapped),t.startSelection&&v.fromJSON(t.startSelection),t.selectionsAfter.map(v.fromJSON))}static fromTransaction(t,n){let r=U;for(let e of t.startState.facet(L)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,U)}static selection(t){return new e(void 0,U,void 0,void 0,t)}},U=[],Ue=200,We=/^(input\.type|delete)($|\.)/,W=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(n,r,i,a,o){let s=this.done,c=s[s.length-1];return s=c&&c.changes&&!c.changes.empty&&n.changes&&(!i||We.test(i))&&(!c.selectionsAfter.length&&r-this.prevTime<a.newGroupDelay&&a.joinToEvent(o,pe(c.changes,n.changes))||i==`input.type.compose`)?S(s,s.length-1,a.minDepth,new H(n.changes.compose(c.changes),he(t.mapEffects(n.effects,c.changes),c.effects),c.mapped,c.startSelection,U)):S(s,s.length,a.minDepth,n),new e(s,U,r,i)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:U;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&me(a[a.length-1],t)?this:new e(ge(this.done,t),this.undone,n,r)}addMapping(t){return new e(ve(this.done,t),ve(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:I.of({side:e,rest:_e(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?U:r.slice(0,r.length-1);return i.mapped&&(n=ve(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:I.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}return null}},W.empty=new W(U,U),Ge=[{key:`Mod-z`,run:B,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:V,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:V,preventDefault:!0},{key:`Mod-u`,run:Ve,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:He,preventDefault:!0}],G=e=>be(e,!D(e)),K=e=>be(e,D(e)),Ke=e=>xe(e,!D(e)),qe=e=>xe(e,D(e)),typeof Intl<`u`&&Intl.Segmenter,Je=e=>T(e,t=>O(e.state,t,!D(e))),Ye=e=>T(e,t=>O(e.state,t,D(e))),q=e=>Ce(e,!1),J=e=>Ce(e,!0),Y=e=>Te(e,!1),X=e=>Te(e,!0),Xe=e=>T(e,t=>k(e,t,!0)),Ze=e=>T(e,t=>k(e,t,!1)),Qe=e=>T(e,t=>k(e,t,!D(e))),$e=e=>T(e,t=>k(e,t,D(e))),et=e=>T(e,t=>e.moveToLineBoundary(t,!1,!1)),tt=e=>T(e,t=>e.moveToLineBoundary(t,!0,!1)),nt=({state:e,dispatch:t})=>Ee(e,t,!1),Z=e=>De(e,!D(e)),rt=e=>De(e,D(e)),it=e=>Oe(e,!D(e)),at=e=>Oe(e,D(e)),ot=e=>{let t=!D(e);return A(e,t,n=>O(e.state,n,t))},st=e=>{let t=D(e);return A(e,t,n=>O(e.state,n,t))},ct=e=>ke(e,!1),lt=e=>ke(e,!0),ut=e=>Ae(e,!1),dt=e=>Ae(e,!0),ft=e=>A(e,!0,t=>k(e,t,!0)),pt=e=>A(e,!1,t=>k(e,t,!1)),mt=e=>{let t=!D(e);return A(e,t,n=>k(e,n,t))},ht=e=>{let t=D(e);return A(e,t,n=>k(e,n,t))},gt=e=>A(e,!1,t=>v.cursor(e.lineBlockAt(t.head).from)),_t=e=>A(e,!0,t=>v.cursor(e.lineBlockAt(t.head).to)),Q=({state:e,dispatch:t})=>(t(w(e,{anchor:0})),!0),vt=({state:e,dispatch:t})=>(t(w(e,{anchor:e.doc.length})),!0),yt=({state:e,dispatch:t})=>(t(w(e,{anchor:e.selection.main.anchor,head:0})),!0),bt=({state:e,dispatch:t})=>(t(w(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),xt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),St=({state:e,dispatch:t})=>{let n=N(e).map(({from:t,to:n})=>v.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:v.create(n),userEvent:`select`})),!0},Ct=({state:e,dispatch:t})=>{let n=C(e.selection,t=>{let n=r(e),i=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=i.node.from&&e.node.to<=i.node.to&&(i=e)}for(let e=i;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return v.undirectionalRange(n.from,n.to)}return t});return!n.eq(e.selection)&&(t(w(e,n)),!0)},wt=e=>je(e,!1),Tt=e=>je(e,!0),Et=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=v.create([n.main]):n.main.empty||(r=v.create([v.cursor(n.main.head)])),r?(t(w(e,r)),!0):!1},Dt=(e,t,n)=>j(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=h(s,a.tabSize)%m(a)||m(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=d(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=d(o.text,c-o.from,!1,!1)+o.from);return c}),$=e=>Dt(e,!1,!0),Ot=e=>Dt(e,!0,!1),kt=(e,t)=>j(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=d(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),At=e=>kt(e,!1),jt=e=>kt(e,!0),Mt=e=>j(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Nt=e=>j(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Pt=e=>j(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Ft=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:ie.of([``,``])},range:v.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},It=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:d(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:d(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:v.cursor(a)}});return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)},Lt=({state:e,dispatch:t})=>Me(e,t,!1),Rt=({state:e,dispatch:t})=>Me(e,t,!0),zt=({state:e,dispatch:t})=>Ne(e,t,!1),Bt=({state:e,dispatch:t})=>Ne(e,t,!0),Vt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(N(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=C(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0},Ht=({state:e,dispatch:t})=>(t(e.update(e.replaceSelection(e.lineBreak),{scrollIntoView:!0,userEvent:`input`})),!0),Ut=Fe(!1),Wt=Fe(!0),Gt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new re(e,{overrideIndentation:e=>n[e]??-1}),i=P(e,(t,i,a)=>{let o=u(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=y(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},Kt=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(P(e,(t,n)=>{n.push({from:t.from,insert:e.facet(f)})}),{userEvent:`input.indent`})),!0),qt=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(P(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=h(r,e.tabSize),a=0,o=y(e,Math.max(0,i-m(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),Jt=e=>(e.setTabFocusMode(),!0),Yt=[{key:`Ctrl-b`,run:G,shift:Z,preventDefault:!0},{key:`Ctrl-f`,run:K,shift:rt},{key:`Ctrl-p`,run:q,shift:ct},{key:`Ctrl-n`,run:J,shift:lt},{key:`Ctrl-a`,run:et,shift:gt},{key:`Ctrl-e`,run:tt,shift:_t},{key:`Ctrl-d`,run:Ot},{key:`Ctrl-h`,run:$},{key:`Ctrl-k`,run:Mt},{key:`Ctrl-Alt-h`,run:At},{key:`Ctrl-o`,run:Ft},{key:`Ctrl-t`,run:It},{key:`Ctrl-v`,run:X}],Xt=[{key:`ArrowLeft`,run:G,shift:Z,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:Ke,shift:it,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Qe,shift:mt,preventDefault:!0},{key:`ArrowRight`,run:K,shift:rt,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:qe,shift:at,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:$e,shift:ht,preventDefault:!0},{key:`ArrowUp`,run:q,shift:ct,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Q,shift:yt},{mac:`Ctrl-ArrowUp`,run:Y,shift:ut},{key:`ArrowDown`,run:J,shift:lt,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:vt,shift:bt},{mac:`Ctrl-ArrowDown`,run:X,shift:dt},{key:`PageUp`,run:Y,shift:ut},{key:`PageDown`,run:X,shift:dt},{key:`Home`,run:Ze,shift:pt,preventDefault:!0},{key:`Mod-Home`,run:Q,shift:yt},{key:`End`,run:Xe,shift:ft,preventDefault:!0},{key:`Mod-End`,run:vt,shift:bt},{key:`Enter`,run:Ut,shift:Ut},{key:`Mod-a`,run:xt},{key:`Backspace`,run:$,shift:$,preventDefault:!0},{key:`Delete`,run:Ot,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:At,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:jt,preventDefault:!0},{mac:`Mod-Backspace`,run:Nt,preventDefault:!0},{mac:`Mod-Delete`,run:Pt,preventDefault:!0}].concat(Yt.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Zt=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:Je,shift:ot},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Ye,shift:st},{key:`Alt-ArrowUp`,run:Lt},{key:`Shift-Alt-ArrowUp`,run:zt},{key:`Alt-ArrowDown`,run:Rt},{key:`Shift-Alt-ArrowDown`,run:Bt},{key:`Mod-Alt-ArrowUp`,run:wt},{key:`Mod-Alt-ArrowDown`,run:Tt},{key:`Escape`,run:Et},{key:`Mod-Enter`,run:Wt},{key:`Alt-l`,mac:`Ctrl-l`,run:St},{key:`Mod-i`,run:Ct,preventDefault:!0},{key:`Mod-[`,run:qt},{key:`Mod-]`,run:Kt},{key:`Mod-Alt-\\`,run:Gt},{key:`Shift-Mod-k`,run:Vt},{key:`Shift-Mod-\\`,run:nt},{key:`Mod-/`,run:Ie},{key:`Alt-A`,mac:`Ctrl-A`,run:Re},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:Jt}].concat(Xt)})))()}export{Ht as a,Xt as c,Qt as i,fe as n,L as o,Ge as r,Be as s,Zt as t};