@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 63.2 kB
JavaScript
import{A as e,F as t,H as n,U as r,V as i,Y as a}from"./web-BWdORzMO.js";import{$ as o,A as s,At as c,Bt as l,Ct as u,E as d,Et as f,Ft as p,G as ee,It as te,J as ne,K as m,L as re,Lt as ie,Mt as h,Nt as g,O as _,Ot as ae,P as v,Pt as oe,Q as se,Rt as y,S as ce,St as b,T as x,Tt as le,Vt as ue,W as S,X as de,Y as fe,Z as pe,at as me,bt as he,c as ge,ct as _e,d as ve,dt as ye,et as be,ft as xe,g as Se,gt as C,ht as Ce,it as we,j as Te,kt as Ee,lt as De,mt as Oe,n as ke,nt as Ae,ot as je,pt as Me,q as Ne,rt as Pe,st as Fe,t as Ie,v as Le,w as Re,wt as w,x as ze,xt as Be,yt as Ve,zt as He}from"./dist-CrVLAEWP.js";import{i as Ue,n as We,o as Ge,r as Ke}from"./dist-H6yvDjb0.js";var qe=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Qe(e.state,n.from);return r.line?Ye(e):r.block?Ze(e):!1};function Je(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}}var Ye=Je(nt,0),Xe=Je(tt,0),Ze=Je((e,t)=>tt(e,t,et(t)),0);function Qe(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var T=50;function $e(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-T,r),o=e.sliceDoc(i,i+T),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<=2*T?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+T),d=e.sliceDoc(i-T,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,ee=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(ee,ee+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(ee-1))}}:null}function et(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 tt(e,t,n=t.selection.ranges){let r=n.map(e=>Qe(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>$e(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 nt(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=Qe(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)}}else 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}var rt=Ve.define(),it=Ve.define(),at=f.define(),ot=f.define({combine(e){return y(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)})}}),st=g.define({create(){return A.empty},update(e,t){let n=t.state.facet(ot),r=t.annotation(rt);if(r){let i=D.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?O(o,o.length,n.minDepth,i):_t(o,t.startState.selection),new A(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(it);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(p.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=D.fromTransaction(t),o=t.annotation(p.time),s=t.annotation(p.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 A(e.done.map(D.fromJSON),e.undone.map(D.fromJSON))}});function ct(e={}){return[st,ot.of(e),m.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?lt:e.inputType==`historyRedo`?ut:null;return n?(e.preventDefault(),n(t)):!1}})]}function E(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(st,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var lt=E(0,!1),ut=E(1,!1),dt=E(0,!0),ft=E(1,!0),D=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&&Be.fromJSON(t.changes),[],t.mapped&&he.fromJSON(t.mapped),t.startSelection&&w.fromJSON(t.startSelection),t.selectionsAfter.map(w.fromJSON))}static fromTransaction(t,n){let r=k;for(let e of t.startState.facet(at)){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,k)}static selection(t){return new e(void 0,k,void 0,void 0,t)}};function O(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 pt(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 mt(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function ht(e,t){return e.length?t.length?e.concat(t):e:t}var k=[],gt=200;function _t(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-gt));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),O(e,e.length-1,1e9,n.setSelAfter(r)))}else return[D.selection([t])]}function vt(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 yt(e,t){if(!e.length)return e;let n=e.length,r=k;for(;n;){let i=bt(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}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[D.selection(r)]:k}function bt(e,t,n){let r=ht(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):k,n);if(!e.changes)return D.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new D(i,h.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var xt=/^(input\.type|delete)($|\.)/,A=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(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||xt.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,pt(s.changes,t.changes))||r==`input.type.compose`)?O(o,o.length-1,i.minDepth,new D(t.changes.compose(s.changes),ht(h.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,k)):O(o,o.length,i.minDepth,t),new e(o,k,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:k;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&mt(a[a.length-1],t)?this:new e(_t(this.done,t),this.undone,n,r)}addMapping(t){return new e(yt(this.done,t),yt(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:rt.of({side:e,rest:vt(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?k:r.slice(0,r.length-1);return i.mapped&&(n=yt(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:rt.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};A.empty=new A(k,k);var St=[{key:`Mod-z`,run:lt,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:ut,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:ut,preventDefault:!0},{key:`Mod-u`,run:dt,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:ft,preventDefault:!0}];function j(e,t){return w.create(e.ranges.map(t),e.mainIndex)}function M(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function N({state:e,dispatch:t},n){let r=j(e.selection,n);return r.eq(e.selection,!0)?!1:(t(M(e,r)),!0)}function Ct(e,t){return w.cursor(t?e.to:e.from)}function wt(e,t){return N(e,n=>n.empty?e.moveByChar(n,t):Ct(n,t))}function P(e){return e.textDirectionAt(e.state.selection.main.head)==ee.LTR}var Tt=e=>wt(e,!P(e)),Et=e=>wt(e,P(e));function Dt(e,t){return N(e,n=>n.empty?e.moveByGroup(n,t):Ct(n,t))}var Ot=e=>Dt(e,!P(e)),kt=e=>Dt(e,P(e));typeof Intl<`u`&&Intl.Segmenter;function At(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 F(e,t,n){let r=Te(e).resolveInner(t.head),i=n?re.closedBy:re.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;At(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?_(e,r.from,1):_(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,w.cursor(s,n?-1:1)}var jt=e=>N(e,t=>F(e.state,t,!P(e))),Mt=e=>N(e,t=>F(e.state,t,P(e)));function Nt(e,t){return N(e,n=>{if(!n.empty)return Ct(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var Pt=e=>Nt(e,!1),Ft=e=>Nt(e,!0);function It(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(m.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function Lt(e,t){let n=It(e),{state:r}=e,i=j(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):Ct(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=m.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(M(r,i),{effects:a}),!0}var Rt=e=>Lt(e,!1),zt=e=>Lt(e,!0);function I(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=w.cursor(r.from+n))}return i}var Bt=e=>N(e,t=>I(e,t,!0)),Vt=e=>N(e,t=>I(e,t,!1)),Ht=e=>N(e,t=>I(e,t,!P(e))),Ut=e=>N(e,t=>I(e,t,P(e))),Wt=e=>N(e,t=>w.cursor(e.lineBlockAt(t.head).from,1)),Gt=e=>N(e,t=>w.cursor(e.lineBlockAt(t.head).to,-1));function Kt(e,t,n){let r=!1,i=j(e.selection,t=>{let i=_(e,t.head,-1)||_(e,t.head,1)||t.head>0&&_(e,t.head-1,1)||t.head<e.doc.length&&_(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?w.range(t.anchor,a):w.cursor(a)});return r?(t(M(e,i)),!0):!1}var qt=({state:e,dispatch:t})=>Kt(e,t,!1);function L(e,t,n){let r=j(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=w.range(e.head,e.anchor));let r=n(e);return w.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return r.eq(e.state.selection)?!1:(e.dispatch(M(e.state,r)),!0)}function Jt(e,t){return L(e,t,n=>e.moveByChar(n,t))}var Yt=e=>Jt(e,!P(e)),Xt=e=>Jt(e,P(e));function Zt(e,t){return L(e,t,n=>e.moveByGroup(n,t))}var Qt=e=>Zt(e,!P(e)),$t=e=>Zt(e,P(e)),en=e=>{let t=!P(e);return L(e,t,n=>F(e.state,n,t))},tn=e=>{let t=P(e);return L(e,t,n=>F(e.state,n,t))};function nn(e,t){return L(e,t,n=>e.moveVertically(n,t))}var rn=e=>nn(e,!1),an=e=>nn(e,!0);function on(e,t){return L(e,t,n=>e.moveVertically(n,t,It(e).height))}var sn=e=>on(e,!1),cn=e=>on(e,!0),ln=e=>L(e,!0,t=>I(e,t,!0)),un=e=>L(e,!1,t=>I(e,t,!1)),dn=e=>{let t=!P(e);return L(e,t,n=>I(e,n,t))},fn=e=>{let t=P(e);return L(e,t,n=>I(e,n,t))},pn=e=>L(e,!1,t=>w.cursor(e.lineBlockAt(t.head).from)),mn=e=>L(e,!0,t=>w.cursor(e.lineBlockAt(t.head).to)),hn=({state:e,dispatch:t})=>(t(M(e,{anchor:0})),!0),gn=({state:e,dispatch:t})=>(t(M(e,{anchor:e.doc.length})),!0),_n=({state:e,dispatch:t})=>(t(M(e,{anchor:e.selection.main.anchor,head:0})),!0),vn=({state:e,dispatch:t})=>(t(M(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),yn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),bn=({state:e,dispatch:t})=>{let n=Rn(e).map(({from:t,to:n})=>w.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:w.create(n),userEvent:`select`})),!0},xn=({state:e,dispatch:t})=>{let n=j(e.selection,t=>{let n=Te(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;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 w.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(M(e,n)),!0)};function Sn(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}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(M(n,w.create(i,i.length-1))),!0)}var Cn=e=>Sn(e,!1),wn=e=>Sn(e,!0),Tn=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=w.create([n.main]):n.main.empty||(r=w.create([w.cursor(n.main.head)])),r?(t(M(e,r)),!0):!1};function R(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=En(e,o,!1)):o>i&&(n=`delete.forward`,o=En(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=En(e,i,!1),a=En(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:w.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?m.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function En(e,t,n){if(e instanceof m)for(let r of e.state.facet(m.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var Dn=(e,t,n)=>R(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=He(s,a.tabSize)%ze(a)||ze(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=l(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=l(o.text,c-o.from,!1,!1)+o.from);return c}),On=e=>Dn(e,!1,!0),kn=e=>Dn(e,!0,!1),An=(e,t)=>R(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=l(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),u=o(c);if(e!=null&&u!=e)break;(c!=` `||r!=n.head)&&(e=u),r=s}return r}),jn=e=>An(e,!1),Mn=e=>An(e,!0),Nn=e=>R(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Pn=e=>R(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Fn=e=>R(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),In=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:oe.of([``,``])},range:w.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},Ln=({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:l(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:l(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:w.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Rn(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 zn(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Rn(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(w.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(w.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:w.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var Bn=({state:e,dispatch:t})=>zn(e,t,!1),Vn=({state:e,dispatch:t})=>zn(e,t,!0);function Hn(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Rn(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}var Un=({state:e,dispatch:t})=>Hn(e,t,!1),Wn=({state:e,dispatch:t})=>Hn(e,t,!0),Gn=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Rn(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=j(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};function Kn(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Te(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(re.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var qn=Yn(!1),Jn=Yn(!0);function Yn(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&&Kn(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new ke(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=ce(s,r);for(c??=He(/^\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=[``,x(t,c)];return o&&l.push(x(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:oe.of(l)},range:w.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function Xn(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:w.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Zn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new ke(e,{overrideIndentation:e=>n[e]??-1}),i=Xn(e,(t,i,a)=>{let o=ce(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=x(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},Qn=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(Xn(e,(t,n)=>{n.push({from:t.from,insert:e.facet(d)})}),{userEvent:`input.indent`})),!0),$n=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(Xn(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=He(r,e.tabSize),a=0,o=x(e,Math.max(0,i-ze(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),er=e=>(e.setTabFocusMode(),!0),tr=[{key:`Ctrl-b`,run:Tt,shift:Yt,preventDefault:!0},{key:`Ctrl-f`,run:Et,shift:Xt},{key:`Ctrl-p`,run:Pt,shift:rn},{key:`Ctrl-n`,run:Ft,shift:an},{key:`Ctrl-a`,run:Wt,shift:pn},{key:`Ctrl-e`,run:Gt,shift:mn},{key:`Ctrl-d`,run:kn},{key:`Ctrl-h`,run:On},{key:`Ctrl-k`,run:Nn},{key:`Ctrl-Alt-h`,run:jn},{key:`Ctrl-o`,run:In},{key:`Ctrl-t`,run:Ln},{key:`Ctrl-v`,run:zt}],nr=[{key:`ArrowLeft`,run:Tt,shift:Yt,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:Ot,shift:Qt,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Ht,shift:dn,preventDefault:!0},{key:`ArrowRight`,run:Et,shift:Xt,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:kt,shift:$t,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Ut,shift:fn,preventDefault:!0},{key:`ArrowUp`,run:Pt,shift:rn,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:hn,shift:_n},{mac:`Ctrl-ArrowUp`,run:Rt,shift:sn},{key:`ArrowDown`,run:Ft,shift:an,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:gn,shift:vn},{mac:`Ctrl-ArrowDown`,run:zt,shift:cn},{key:`PageUp`,run:Rt,shift:sn},{key:`PageDown`,run:zt,shift:cn},{key:`Home`,run:Vt,shift:un,preventDefault:!0},{key:`Mod-Home`,run:hn,shift:_n},{key:`End`,run:Bt,shift:ln,preventDefault:!0},{key:`Mod-End`,run:gn,shift:vn},{key:`Enter`,run:qn,shift:qn},{key:`Mod-a`,run:yn},{key:`Backspace`,run:On,shift:On,preventDefault:!0},{key:`Delete`,run:kn,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:jn,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:Mn,preventDefault:!0},{mac:`Mod-Backspace`,run:Pn,preventDefault:!0},{mac:`Mod-Delete`,run:Fn,preventDefault:!0}].concat(tr.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),rr=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:jt,shift:en},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Mt,shift:tn},{key:`Alt-ArrowUp`,run:Bn},{key:`Shift-Alt-ArrowUp`,run:Un},{key:`Alt-ArrowDown`,run:Vn},{key:`Shift-Alt-ArrowDown`,run:Wn},{key:`Mod-Alt-ArrowUp`,run:Cn},{key:`Mod-Alt-ArrowDown`,run:wn},{key:`Escape`,run:Tn},{key:`Mod-Enter`,run:Jn},{key:`Alt-l`,mac:`Ctrl-l`,run:bn},{key:`Mod-i`,run:xn,preventDefault:!0},{key:`Mod-[`,run:$n},{key:`Mod-]`,run:Qn},{key:`Mod-Alt-\\`,run:Zn},{key:`Shift-Mod-k`,run:Gn},{key:`Shift-Mod-\\`,run:qt},{key:`Mod-/`,run:qe},{key:`Alt-A`,run:Xe},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:er}].concat(nr),ir={key:`Tab`,run:Qn,shift:$n},ar=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,z=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(ar(e)):ar,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return te(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=ue(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=ie(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n,a=!0;;e++){let n=r.charCodeAt(e),o=this.match(n,i,a,this.bufferPos+this.bufferStart,e==r.length-1);if(o)return this.value=o,this;if(e==r.length-1)break;a&&e<t.length&&t.charCodeAt(e)==n?i++:a=!1}}}match(e,t,n,r,i){let a=null;for(let t=0;t<this.matches.length;){let n=this.matches[t],o=!1;this.query.charCodeAt(n.index)==e&&(n.index==this.query.length-1?a={from:n.from,to:r,precise:i&&n.precise}:(n.index++,o=!0)),o?t++:this.matches.splice(t,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?a={from:t,to:r,precise:n&&i}:this.matches.push({from:t,index:1,precise:n})),a&&this.test&&!this.test(a.from,a.to,this.buffer,this.bufferStart)&&(a=null),a}};typeof Symbol<`u`&&(z.prototype[Symbol.iterator]=function(){return this});var or={from:-1,to:-1,match:/.*/.exec(``),precise:!0},sr=`gm`+(/x/.unicode==null?``:`u`),cr=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=or,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new dr(e,t,n,r,i);this.re=new RegExp(t,sr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter();let a=e.lineAt(r);this.curLineStart=a.from,this.matchPos=B(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=B(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},lr=new WeakMap,ur=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=lr.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return lr.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),lr.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},dr=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=or,this.matchPos=B(e,r),this.re=new RegExp(t,sr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=ur.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,precise:!0,match:t},this.matchPos=B(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=ur.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(cr.prototype[Symbol.iterator]=dr.prototype[Symbol.iterator]=function(){return this});function fr(e){try{return new RegExp(e,sr),!0}catch{return!1}}function B(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var pr=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=Me(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=w.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,m.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},mr={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},hr=f.define({combine(e){return y(e,mr,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function gr(e){let t=[Sr,xr];return e&&t.push(hr.of(e)),t}var _r=S.mark({class:`cm-selectionMatch`}),vr=S.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function yr(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=b.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=b.Word)}function br(e,t,n,r){return e(t.sliceDoc(n,n+1))==b.Word&&e(t.sliceDoc(r-1,r))==b.Word}var xr=ne.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(hr),{state:n}=e,r=n.selection;if(r.ranges.length>1)return S.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return S.none;let e=n.wordAt(i.head);if(!e)return S.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return S.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(yr(o,n,i.from,i.to)&&br(o,n,i.from,i.to)))return S.none}else if(a=n.sliceDoc(i.from,i.to),!a)return S.none}let s=[];for(let r of e.visibleRanges){let e=new z(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||yr(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(vr.range(r,a)):(r>=i.to||a<=i.from)&&s.push(_r.range(r,a)),s.length>t.maxMatches))return S.none}}return S.set(s)}},{decorations:e=>e.decorations}),Sr=m.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Cr=({state:e,dispatch:t})=>{let{selection:n}=e,r=w.create(n.ranges.map(t=>e.wordAt(t.head)||w.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function wr(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new z(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new z(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Tr=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Cr({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=wr(e,r);return i?(t(e.update({selection:e.selection.addRange(w.range(i.from,i.to),!1),effects:m.scrollIntoView(i.to)})),!0):!1},V=f.define({combine(e){return y(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Qr(e),scrollToMatch:e=>m.scrollIntoView(e)})}}),Er=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||fr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
`:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Nr(this):new Ar(this)}getCursor(e,t=0,n){let r=e.doc?e:le.create({doc:e});return n??=r.doc.length,this.regexp?U(this,r,t,n):H(this,r,t,n)}},Dr=class{constructor(e){this.spec=e}};function Or(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function H(e,t,n,r){let i;return e.wholeWord&&(i=kr(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=Or(e.test,t,i)),new z(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function kr(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(W(i,n-a))!=b.Word||t(G(i,n-a))!=b.Word)&&(t(G(i,r-a))!=b.Word||t(W(i,r-a))!=b.Word))}var Ar=class extends Dr{constructor(e){super(e)}nextMatch(e,t,n){let r=H(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=H(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=H(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=H(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=H(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function jr(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function U(e,t,n,r){let i;return e.wholeWord&&(i=Mr(t.charCategorizer(t.selection.main.head))),e.test&&(i=jr(e.test,t,i)),new cr(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function W(e,t){return e.slice(l(e,t,!1),t)}function G(e,t){return e.slice(t,l(e,t))}function Mr(e){return(t,n,r)=>!r[0].length||(e(W(r.input,r.index))!=b.Word||e(G(r.input,r.index))!=b.Word)&&(e(G(r.input,r.index+r[0].length))!=b.Word||e(W(r.input,r.index+r[0].length))!=b.Word)}var Nr=class extends Dr{nextMatch(e,t,n){let r=U(this.spec,e,n,e.doc.length).next();return r.done&&(r=U(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=U(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=U(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=U(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},K=h.define(),Pr=h.define(),q=g.define({create(e){return new Fr(Kr(e).create(),null)},update(e,t){for(let n of t.effects)n.is(K)?e=new Fr(n.value.create(),e.panel):n.is(Pr)&&(e=new Fr(e.query,n.value?Gr:null));return e},provide:e=>Oe.from(e,e=>e.panel)}),Fr=class{constructor(e,t){this.query=e,this.panel=t}},Ir=S.mark({class:`cm-searchMatch`}),Lr=S.mark({class:`cm-searchMatch cm-searchMatch-selected`}),Rr=ne.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(q))}update(e){let t=e.state.field(q);(t!=e.startState.field(q)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return S.none;let{view:n}=this,r=new c;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?Lr:Ir)})}return r.finish()}},{decorations:e=>e.decorations});function J(e){return t=>{let n=t.state.field(q,!1);return n&&n.query.spec.valid?e(t,n):Yr(t)}}var zr=J((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=w.single(r.from,r.to),a=e.state.facet(V);return e.dispatch({selection:i,effects:[ti(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),Jr(e),!0}),Br=J((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=w.single(i.from,i.to),o=e.state.facet(V);return e.dispatch({selection:a,effects:[ti(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),Jr(e),!0}),Vr=J((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:w.create(n.map(e=>w.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),Hr=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new z(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(w.range(t.value.from,t.value.to))}return t(e.update({selection:w.create(a,o),userEvent:`select.search.matches`})),!0},Ur=J((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.precise?o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(m.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`))):o=t.nextMatch(n,o.from,o.to);let d=e.state.changes(s);return o&&(c=w.single(o.from,o.to).map(d),u.push(ti(e,o)),u.push(n.facet(V).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),Wr=J((e,{query:t})=>{if(e.state.readOnly)return!1;let n=[];for(let r of t.matchAll(e.state,1e9)){let{from:e,to:i,precise:a}=r;a&&n.push({from:e,to:i,insert:t.getReplacement(r)})}if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:m.announce.of(r),userEvent:`input.replace.all`}),!0});function Gr(e){return e.state.facet(V).createPanel(e)}function Kr(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(V);return new Er({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function qr(e){let t=be(e,Gr);return t&&t.dom.querySelector(`[main-field]`)}function Jr(e){let t=qr(e);t&&t==e.root.activeElement&&t.select()}var Yr=e=>{let t=e.state.field(q,!1);if(t&&t.panel){let n=qr(e);if(n&&n!=e.root.activeElement){let r=Kr(e.state,t.query.spec);r.valid&&e.dispatch({effects:K.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[Pr.of(!0),t?K.of(Kr(e.state,t.query.spec)):h.appendConfig.of(ri)]});return!0},Xr=e=>{let t=e.state.field(q,!1);if(!t||!t.panel)return!1;let n=be(e,Gr);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Pr.of(!1)}),!0},Zr=[{key:`Mod-f`,run:Yr,scope:`editor search-panel`},{key:`F3`,run:zr,shift:Br,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:zr,shift:Br,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:Xr,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:Hr},{key:`Mod-Alt-g`,run:pr},{key:`Mod-d`,run:Tr,preventDefault:!0}],Qr=class{constructor(e){this.view=e;let t=this.query=e.state.field(q).query.spec;this.commit=this.commit.bind(this),this.searchField=C(`input`,{value:t.search,placeholder:Y(e,`Find`),"aria-label":Y(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=C(`input`,{value:t.replace,placeholder:Y(e,`Replace`),"aria-label":Y(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=C(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=C(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=C(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return C(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=C(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>zr(e),[Y(e,`next`)]),n(`prev`,()=>Br(e),[Y(e,`previous`)]),n(`select`,()=>Vr(e),[Y(e,`all`)]),C(`label`,null,[this.caseField,Y(e,`match case`)]),C(`label`,null,[this.reField,Y(e,`regexp`)]),C(`label`,null,[this.wordField,Y(e,`by word`)]),...e.state.readOnly?[]:[C(`br`),this.replaceField,n(`replace`,()=>Ur(e),[Y(e,`replace`)]),n(`replaceAll`,()=>Wr(e),[Y(e,`replace all`)])],C(`button`,{name:`close`,onclick:()=>Xr(e),"aria-label":Y(e,`close`),type:`button`},[`×`])])}commit(){let e=new Er({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:K.of(e)}))}keydown(e){xe(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Br:zr)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Ur(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(K)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(V).top}};function Y(e,t){return e.state.phrase(t)}var $r=30,ei=/[\s\.,:;?!]/;function ti(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-$r),o=Math.min(i,n+$r),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<$r;e++)if(!ei.test(s[e+1])&&ei.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-$r;e--)if(!ei.test(s[e-1])&&ei.test(s[e])){s=s.slice(0,e);break}}return m.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var ni=m.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),ri=[q,ae.low(Rr),ni],ii=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},X=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet($).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new c,s=[],l=0,u=r.doc.iter(),d=0,f=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=l,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>f)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,f);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==f))&&(i=n==r,!i&&r-n<10)){let e=n-(d+u.value.length);e>0&&(u.next(e),d=n);for(let e=n;;){if(e>=r){i=!0;break}if(!u.lineBreak&&d+u.value.length>e)break;e=d+u.value.length,d+=u.value.length,u.next()}}let c=Ai(s);if(i)o.add(n,n,S.widget({widget:new Ci(c),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,S.mark({class:`cm-lintRange cm-lintRange-`+c+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(l=r,l==f)break;for(let e=0;e<s.length;e++)s[e].to<=l&&s.splice(e--,1)}let p=o.finish();return new e(p,n,Z(p))}};function Z(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new ii(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new ii(r.from,n,r.diagnostic)}),r}function ai(e,t){let n=t.pos,r=t.end||n,i=e.state.facet($).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(ci))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function oi(e,t){return e.field(Q,!1)?t:t.concat(h.appendConfig.of(Vi))}function si(e,t){return{effects:oi(e,[ci.of(t)])}}var ci=h.define(),li=h.define(),ui=h.define(),Q=g.define({create(){return new X(S.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=Z(n,e.selected.diagnostic,i)||Z(n,null,i)}!n.size&&i&&t.state.facet($).autoPanel&&(i=null),e=new X(n,i,r)}for(let n of t.effects)if(n.is(ci)){let r=t.state.facet($).autoPanel?n.value.length?Ti.open:null:e.panel;e=X.init(n.value,r,t.state)}else n.is(li)?e=new X(e.diagnostics,n.value?Ti.open:null,e.selected):n.is(ui)&&(e=new X(e.diagnostics,e.panel,n.value));return e},provide:e=>[Oe.from(e,e=>e.panel),m.decorations.from(e,e=>e.diagnostics)]}),di=S.mark({class:`cm-lintRange cm-lintRange-active`});function fi(e,t,n){let{diagnostics:r}=e.state.field(Q),i,a=-1,o=-1;r.between(t-+(n<0),t+ +(n>0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet($).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:!0,create(){return{dom:pi(e,i)}}}:null}function pi(e,t){return C(`ul`,{class:`cm-tooltip-lint`},t.map(t=>Si(e,t,!1)))}var mi=e=>{let t=e.state.field(Q,!1);(!t||!t.panel)&&e.dispatch({effects:oi(e.state,[li.of(!0)])});let n=be(e,Ti.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},hi=e=>{let t=e.state.field(Q,!1);return!t||!t.panel?!1:(e.dispatch({effects:li.of(!1)}),!0)},gi=[{key:`Mod-Shift-m`,run:mi,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(Q,!1);if(!t)return!1;let n=e.state.selection.main,r=Z(t.diagnostics,null,n.to+1);return!r&&(r=Z(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),de(e,r.from,1,{tooltip:Bi,until:e=>e.docChanged||e.newSelection.main.head<r.from||e.newSelection.main.head>r.to}),!0)}}],_i=ne.fromClass(class{constructor(e){this.view=e,this.timeout=-1,this.set=!0;let{delay:t}=e.state.facet($);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let e=Date.now();if(e<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-e);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet($);t.length&&vi(t.map(e=>Promise.resolve(e(this.view))),t=>{this.view.state.doc==e.doc&&this.view.dispatch(si(this.view.state,t.reduce((e,t)=>e.concat(t))))},e=>{De(this.view.state,e)})}}update(e){let t=e.state.facet($);(e.docChanged||t!=e.startState.facet($)||t.needsRefresh&&t.needsRefresh(e))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function vi(e,t,n){let r=[],i=-1;for(let a of e)a.then(n=>{r.push(n),clearTimeout(i),r.length==e.length?t(r):i=setTimeout(()=>t(r),200)},n)}var $=f.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...y(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:yi,tooltipFilter:yi,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function yi(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function bi(e,t={}){return[$.of({source:e,config:t}),_i,Vi]}function xi(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function Si(e,t,n){let r=n?xi(t.actions):[];return C(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},C(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=Z(e.state.field(Q).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),C(`u`,s.slice(c,c+1)),s.slice(c+1)];return C(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&C(`div`,{class:`cm-diagnosticSource`},t.source))}var Ci=class extends fe{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return C(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},wi=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=Si(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},Ti=class e{constructor(e){this.view=e,this.items=[];let t=t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)hi(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this