14 lines
136 KiB
JavaScript
14 lines
136 KiB
JavaScript
|
import{S as Pe,i as be,s as xe,e as Xe,f as ye,T as TO,g as Re,y as PO,o as Ze,K as ke,M as We,N as _e}from"./index.a3407df6.js";import{P as we,N as je,u as qe,D as ve,v as lO,T as V,I as KO,w as QO,x as o,y as ze,L as cO,z as hO,A as U,B as dO,F as HO,G as uO,H as z,J as Ge,K as Ce,E as R,M as v,O as Ye,Q as Ve,R as m,U as Ue,a as w,h as Ae,b as Ie,c as Ee,d as De,e as Ne,s as Me,f as Be,g as Je,i as Le,r as Fe,j as Ke,k as He,l as Ot,m as et,n as tt,o as at,p as it,q as rt,t as bO,C as G}from"./index.30b22912.js";class D{constructor(O,t,a,i,r,n,s,Q,c,h=0,l){this.p=O,this.stack=t,this.state=a,this.reducePos=i,this.pos=r,this.score=n,this.buffer=s,this.bufferBase=Q,this.curContext=c,this.lookAhead=h,this.parent=l}toString(){return`[${this.stack.filter((O,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(O,t,a=0){let i=O.parser.context;return new D(O,[],t,a,a,0,[],0,i?new xO(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(O,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=O}reduce(O){let t=O>>19,a=O&65535,{parser:i}=this.p,r=i.dynamicPrecedence(a);if(r&&(this.score+=r),t==0){this.pushState(i.getGoto(this.state,a,!0),this.reducePos),a<i.minRepeatTerm&&this.storeNode(a,this.reducePos,this.reducePos,4,!0),this.reduceContext(a,this.reducePos);return}let n=this.stack.length-(t-1)*3-(O&262144?6:0),s=this.stack[n-2],Q=this.stack[n-1],c=this.bufferBase+this.buffer.length-Q;if(a<i.minRepeatTerm||O&131072){let h=i.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(a,s,h,c+4,!0)}if(O&262144)this.state=this.stack[n];else{let h=this.stack[n-3];this.state=i.getGoto(h,a,!0)}for(;this.stack.length>n;)this.stack.pop();this.reduceContext(a,s)}storeNode(O,t,a,i=4,r=!1){if(O==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let n=this,s=this.buffer.length;if(s==0&&n.parent&&(s=n.bufferBase-n.parent.bufferBase,n=n.parent),s>0&&n.buffer[s-4]==0&&n.buffer[s-1]>-1){if(t==a)return;if(n.buffer[s-2]>=t){n.buffer[s-2]=a;return}}}if(!r||this.pos==a)this.buffer.push(O,t,a,i);else{let n=this.buffer.length;if(n>0&&this.buffer[n-4]!=0)for(;n>0&&this.buffer[n-2]>a;)this.buffer[n]=this.buffer[n-4],this.buffer[n+1]=this.buffer[n-3],this.buffer[n+2]=this.buffer[n-2],this.buffer[n+3]=this.buffer[n-1],n-=4,i>4&&(i-=4);this.buffer[n]=O,this.buffer[n+1]=t,this.buffer[n+2]=a,this.buffer[n+3]=i}}shift(O,t,a){let i=this.pos;if(O&131072)this.pushState(O&65535,this.pos);else if((O&262144)==0){let r=O,{parser:n}=this.p;(a>this.pos||t<=n.maxNode)&&(this.pos=a,n.stateFlag(r,1)||(this.reducePos=a)),this.pushState(r,i),this.shiftContext(t,i),t<=n.maxNode&&this.buffer.push(t,i,a,4)}else this.pos=a,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,a,4)}apply(O,t,a){O&65536?this.reduce(O):this.shift(O,t,a)}useNode(O,t){let a=this.p.reused.length-1;(a<0||this.p.reused[a]!=O)&&(this.p.reused.push(O),a++);let i=this.pos;this.reducePos=this.pos=i+O.length,this.pushState(t,i),this.buffer.push(a,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,O,this,this.p.stream.reset(this.pos-O.length)))}split(){let O=this,t=O.buffer.length;for(;t>0&&O.buffer[t-2]>O.reducePos;)t-=4;let a=O.buffer.slice(t),i=O.bufferBase+t;for(;O&&i==O.bufferBase;)O=O.parent;return new D(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,a,i,this.curContext,this.lookAhead,O)}recoverByDelete(O,t){let a=O<=this.p.parser.maxNode;a&&this.storeNode(O,this.pos,t,4),this.storeNode(0,this.pos,t,a?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(O){for(let t=new nt(this);;){let a=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,O);if(a==0)return!1;if((a&65536)==0)return!0;t.reduce(a)}}recoverByInsert(O){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>4<<1||this.stack.length>=120){let i=[];for(let r=0,n;r<t.length;r+=2)(n=t[r+1])!=this.state&&this.p.parser.hasAction(n,O)&&i.push
|
||
|
\${}
|
||
|
} catch (\${error}) {
|
||
|
\${}
|
||
|
}`,{label:"try",detail:"/ catch block",type:"keyword"}),m("if (${}) {\n ${}\n}",{label:"if",detail:"block",type:"keyword"}),m(`if (\${}) {
|
||
|
\${}
|
||
|
} else {
|
||
|
\${}
|
||
|
}`,{label:"if",detail:"/ else block",type:"keyword"}),m(`class \${name} {
|
||
|
constructor(\${params}) {
|
||
|
\${}
|
||
|
}
|
||
|
}`,{label:"class",detail:"definition",type:"keyword"}),m('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),m('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],MO=new Ue,he=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function j(e){return(O,t)=>{let a=O.node.getChild("VariableDefinition");return a&&t(a,e),!0}}const Ea=["FunctionDeclaration"],Da={FunctionDeclaration:j("function"),ClassDeclaration:j("class"),ClassExpression:()=>!0,EnumDeclaration:j("constant"),TypeAliasDeclaration:j("type"),NamespaceDeclaration:j("namespace"),VariableDefinition(e,O){e.matchContext(Ea)||O(e,"variable")},TypeDefinition(e,O){O(e,"type")},__proto__:null};function de(e,O){let t=MO.get(O);if(t)return t;let a=[],i=!0;function r(n,s){let Q=e.sliceString(n.from,n.to);a.push({label:Q,type:s})}return O.cursor(KO.IncludeAnonymous).iterate(n=>{if(i)i=!1;else if(n.name){let s=Da[n.name];if(s&&s(n,r)||he.has(n.name))return!1}else if(n.to-n.from>8192){for(let s of de(e,n.node))a.push(s);return!1}}),MO.set(O,a),a}const BO=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,ue=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName"];function Na(e){let O=z(e.state).resolveInner(e.pos,-1);if(ue.indexOf(O.name)>-1)return null;let t=O.name=="VariableName"||O.to-O.from<20&&BO.test(e.state.sliceDoc(O.from,O.to));if(!t&&!e.explicit)return null;let a=[];for(let i=O;i;i=i.parent)he.has(i.name)&&(a=a.concat(de(e.state.doc,i)));return{options:a,from:t?O.from:e.pos,validFor:BO}}const y=cO.define({name:"javascript",parser:Aa.configure({props:[hO.add({IfStatement:U({except:/^\s*({|else\b)/}),TryStatement:U({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Ye,SwitchBody:e=>{let O=e.textAfter,t=/^\s*\}/.test(O),a=/^\s*(case|default)\b/.test(O);return e.baseIndent+(t?0:a?1:2)*e.unit},Block:Ve({closing:"}"}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":U({except:/^{/}),JSXElement(e){let O=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(O?0:e.unit)},JSXEscape(e){let O=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(O?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),dO.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression":HO,BlockComment(e){return{from:e.from+2,to:e.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),$e=y.configure({dialect:"ts"},"typescript"),pe=y.configure({dialect:"jsx"}),fe=y.configure({dialect:"jsx ts"},"typescript"),Ma="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(e=>({label:e,type:"keyword"}));function ge(e={}){let O=e.jsx?e.typescript?fe:pe:e.typescript?$e:y;return new uO(O,[y.data.of({autocomplete:Ge(ue,Ce(Ia.concat(Ma)))}),y.data.of({autocomplete:Na}),e.jsx?Ja:[]])}function JO(e,O,t=e.length){if(!O)return"";let a=O.getChild("JSXIdentifier");return a?e.sliceString(a.from,Math.min(a.to,t)):""}const Ba=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Ja=R.inputHandler.of((e,O,t,a)=>{if((Ba?e.composing:e.compositionStarted)||e.state.readOnly||O!=t||a!=">"&&a!="/"||!y.isActiveAt(e.state,O,-1))return!1;let{state:i}=e,r=i.changeByRange(n=>{var s,Q,c;let{head:h}=n,l=z(i).resolveInner(h,-1),u;if(l.name=="JSXStartTag"&&(l=l.parent),a==">"&&l.name=="JSXFragmentTag")return{range:v.cursor(h+1),changes:{from:h,insert:"><>"}};if(a==">"&&l.name=="JSXIdentifier"){if(((Q=(s=l.parent)===null||s===void 0?void 0:s.lastChild)===null||Q===void 0?void 0:Q.name)!="JSXEndTag"&&(u=JO(i.doc,l.parent,h)))return{range:v.cursor(h+1),changes:{from:h,insert:`></${u}>`}}}else if(a=="/
|