1 line
41 KiB
JavaScript
1 line
41 KiB
JavaScript
import{NodeType,NodeProp,IterMode,Tree,TreeFragment,Parser,NodeSet}from"@lezer/common";import{Facet,EditorState,StateEffect,StateField,countColumn,RangeSet,combineConfig,RangeSetBuilder,Prec}from"@codemirror/state";import{ViewPlugin,logException,EditorView,Decoration,WidgetType,gutter,GutterMarker}from"@codemirror/view";import{tags,styleTags,tagHighlighter,highlightTree}from"@lezer/highlight";const C="ͼ",COUNT="undefined"==typeof Symbol?"__ͼ":Symbol.for(C),SET="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),top="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class StyleModule{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function o(e,t,i,s){let a=[],l=/^@(\w+)\b/.exec(e[0]),h=l&&"keyframes"==l[1];if(l&&null==t)return i.push(e[0]+";");for(let n in t){let s=t[n];if(/&/.test(n))o(n.split(/,\s*/).map((t=>e.map((e=>t.replace(/&/,e))))).reduce(((e,t)=>e.concat(t))),s,i);else if(s&&"object"==typeof s){if(!l)throw new RangeError("The value of a property ("+n+") should be a primitive value.");o(r(n),s,a,h)}else null!=s&&a.push(n.replace(/_.*/,"").replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))+": "+s+";")}(a.length||h)&&i.push((!n||l||s?e:e.map(n)).join(", ")+" {"+a.join(" ")+"}")}for(let t in e)o(r(t),e[t],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let e=top[COUNT]||1;return top[COUNT]=e+1,C+e.toString(36)}static mount(e,t,n){let r=e[SET],o=n&&n.nonce;r?o&&r.setNonce(o):r=new StyleSet(e,o),r.mount(Array.isArray(t)?t:[t])}}let adoptedSet=new Map;class StyleSet{constructor(e,t){let n=e.ownerDocument||e,r=n.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let t=adoptedSet.get(n);if(t)return e.adoptedStyleSheets=[t.sheet,...e.adoptedStyleSheets],e[SET]=t;this.sheet=new r.CSSStyleSheet,e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets],adoptedSet.set(n,this)}else{this.styleTag=n.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);let r=e.head||e;r.insertBefore(this.styleTag,r.firstChild)}this.modules=[],e[SET]=this}mount(e){let t=this.sheet,n=0,r=0;for(let o=0;o<e.length;o++){let i=e[o],s=this.modules.indexOf(i);if(s<r&&s>-1&&(this.modules.splice(s,1),r--,s=-1),-1==s){if(this.modules.splice(r++,0,i),t)for(let e=0;e<i.rules.length;e++)t.insertRule(i.rules[e],n++)}else{for(;r<s;)n+=this.modules[r++].rules.length;n+=i.rules.length,r++}}if(!t){let e="";for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+"\n";this.styleTag.textContent=e}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var _a;const languageDataProp=new NodeProp;function defineLanguageFacet(e){return Facet.define({combine:e?t=>t.concat(e):void 0})}const sublanguageProp=new NodeProp;class Language{constructor(e,t,n=[],r=""){this.data=e,this.name=r,EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(EditorState.prototype,"tree",{get(){return syntaxTree(this)}}),this.parser=t,this.extension=[language.of(this),EditorState.languageData.of(((e,t,n)=>{let r=topNodeAt(e,t,n),o=r.type.prop(languageDataProp);if(!o)return[];let i=e.facet(o),s=r.type.prop(sublanguageProp);if(s){let o=r.resolve(t-r.from,n);for(let t of s)if(t.test(o,e)){let n=e.facet(t.facet);return"replace"==t.type?n:n.concat(i)}}return i}))].concat(n)}isActiveAt(e,t,n=-1){return topNodeAt(e,t,n).type.prop(languageDataProp)==this.data}findRegions(e){let t=e.facet(language);if((null==t?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(e,t)=>{if(e.prop(languageDataProp)==this.data)return void n.push({from:t,to:t+e.length});let o=e.prop(NodeProp.mounted);if(o){if(o.tree.prop(languageDataProp)==this.data){if(o.overlay)for(let e of o.overlay)n.push({from:e.from+t,to:e.to+t});else n.push({from:t,to:t+e.length});return}if(o.overlay){let e=n.length;if(r(o.tree,o.overlay[0].from+t),n.length>e)return}}for(let n=0;n<e.children.length;n++){let o=e.children[n];o instanceof Tree&&r(o,e.positions[n]+t)}};return r(syntaxTree(e),0),n}get allowsNesting(){return!0}}function topNodeAt(e,t,n){let r=e.facet(language),o=syntaxTree(e).topNode;if(!r||r.allowsNesting)for(let e=o;e;e=e.enter(t,n,IterMode.ExcludeBuffers))e.type.isTop&&(o=e);return o}Language.setState=StateEffect.define();class LRLanguage extends Language{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(e){let t=defineLanguageFacet(e.languageData);return new LRLanguage(t,e.parser.configure({props:[languageDataProp.add((e=>e.isTop?t:void 0))]}),e.name)}configure(e,t){return new LRLanguage(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function syntaxTree(e){let t=e.field(Language.state,!1);return t?t.tree:Tree.empty}function ensureSyntaxTree(e,t,n=50){var r;let o=null===(r=e.field(Language.state,!1))||void 0===r?void 0:r.context;if(!o)return null;let i=o.viewport;o.updateViewport({from:0,to:t});let s=o.isDone(t)||o.work(n,t)?o.tree:null;return o.updateViewport(i),s}function syntaxTreeAvailable(e,t=e.doc.length){var n;return(null===(n=e.field(Language.state,!1))||void 0===n?void 0:n.context.isDone(t))||!1}function forceParsing(e,t=e.viewport.to,n=100){let r=ensureSyntaxTree(e.state,t,n);return r!=syntaxTree(e.state)&&e.dispatch({}),!!r}function syntaxParserRunning(e){var t;return(null===(t=e.plugin(parseWorker))||void 0===t?void 0:t.isWorking())||!1}class DocInput{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}}let currentContext=null;class ParseContext{constructor(e,t,n=[],r,o,i,s,a){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=o,this.viewport=i,this.skipped=s,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new ParseContext(e,t,[],Tree.empty,0,n,[],null)}startParse(){return this.parser.startParse(new DocInput(this.state.doc),this.fragments)}work(e,t){return null!=t&&t>=this.state.doc.length&&(t=void 0),this.tree!=Tree.empty&&this.isDone(null!=t?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var n;if("number"==typeof e){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||(this.parse=this.startParse()),null!=t&&(null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let r=this.parse.advance();if(r){if(this.fragments=this.withoutTempSkipped(TreeFragment.addTree(r,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(n=this.parse.stoppedAt)&&void 0!==n?n:this.state.doc.length,this.tree=r,this.parse=null,!(this.treeLen<(null!=t?t:this.state.doc.length)))return!0;this.parse=this.startParse()}if(e())return!1}}))}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext((()=>{for(;!(t=this.parse.advance()););})),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(TreeFragment.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=currentContext;currentContext=this;try{return e()}finally{currentContext=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=cutFragments(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:r,treeLen:o,viewport:i,skipped:s}=this;if(this.takeTree(),!e.empty){let t=[];if(e.iterChangedRanges(((e,n,r,o)=>t.push({fromA:e,toA:n,fromB:r,toB:o}))),n=TreeFragment.applyChanges(n,t),r=Tree.empty,o=0,i={from:e.mapPos(i.from,-1),to:e.mapPos(i.to,1)},this.skipped.length){s=[];for(let t of this.skipped){let n=e.mapPos(t.from,1),r=e.mapPos(t.to,-1);n<r&&s.push({from:n,to:r})}}}return new ParseContext(this.parser,t,n,r,o,i,s,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let t=0;t<this.skipped.length;t++){let{from:n,to:r}=this.skipped[t];n<e.to&&r>e.from&&(this.fragments=cutFragments(this.fragments,n,r),this.skipped.splice(t--,1))}return!(this.skipped.length>=t)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Parser{createParse(t,n,r){let o=r[0].from,i=r[r.length-1].to;return{parsedPos:o,advance(){let t=currentContext;if(t){for(let e of r)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=i,new Tree(NodeType.none,[],[],i-o)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&0==t[0].from&&t[0].to>=e}static get(){return currentContext}}function cutFragments(e,t,n){return TreeFragment.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}class LanguageState{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new LanguageState(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=ParseContext.create(e.facet(language).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new LanguageState(n)}}Language.state=StateField.define({create:LanguageState.init,update(e,t){for(let e of t.effects)if(e.is(Language.setState))return e.value;return t.startState.facet(language)!=t.state.facet(language)?LanguageState.init(t.state):e.apply(t)}});let requestIdle=e=>{let t=setTimeout((()=>e()),500);return()=>clearTimeout(t)};"undefined"!=typeof requestIdleCallback&&(requestIdle=e=>{let t=-1,n=setTimeout((()=>{t=requestIdleCallback(e,{timeout:400})}),100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const isInputPending="undefined"!=typeof navigator&&(null===(_a=navigator.scheduling)||void 0===_a?void 0:_a.isInputPending)?()=>navigator.scheduling.isInputPending():null,parseWorker=ViewPlugin.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Language.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Language.state);t.tree==t.context.tree&&t.context.isDone(e.doc.length)||(this.working=requestIdle(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:r}}=this.view,o=n.field(Language.state);if(o.tree==o.context.tree&&o.context.isDone(r+1e5))return;let i=Date.now()+Math.min(this.chunkBudget,100,e&&!isInputPending?Math.max(25,e.timeRemaining()-5):1e9),s=o.context.treeLen<r&&n.doc.length>r+1e3,a=o.context.work((()=>isInputPending&&isInputPending()||Date.now()>i),r+(s?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(o.context.takeTree(),this.view.dispatch({effects:Language.setState.of(new LanguageState(o.context))})),this.chunkBudget>0&&(!a||s)&&this.scheduleWork(),this.checkAsyncSchedule(o.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then((()=>this.scheduleWork())).catch((e=>logException(this.view.state,e))).then((()=>this.workScheduled--)),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),language=Facet.define({combine:e=>e.length?e[0]:null,enables:e=>[Language.state,parseWorker,EditorView.contentAttributes.compute([e],(t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}}))]});class LanguageSupport{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class LanguageDescription{constructor(e,t,n,r,o,i=void 0){this.name=e,this.alias=t,this.extensions=n,this.filename=r,this.loadFunc=o,this.support=i,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then((e=>this.support=e),(e=>{throw this.loading=null,e})))}static of(e){let{load:t,support:n}=e;if(!t){if(!n)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(n)}return new LanguageDescription(e.name,(e.alias||[]).concat(e.name).map((e=>e.toLowerCase())),e.extensions||[],e.filename,t,n)}static matchFilename(e,t){for(let n of e)if(n.filename&&n.filename.test(t))return n;let n=/\.([^.]+)$/.exec(t);if(n)for(let t of e)if(t.extensions.indexOf(n[1])>-1)return t;return null}static matchLanguageName(e,t,n=!0){t=t.toLowerCase();for(let n of e)if(n.alias.some((e=>e==t)))return n;if(n)for(let n of e)for(let e of n.alias){let r=t.indexOf(e);if(r>-1&&(e.length>2||!/\w/.test(t[r-1])&&!/\w/.test(t[r+e.length])))return n}return null}}const indentService=Facet.define(),indentUnit=Facet.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some((e=>e!=t[0])))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function getIndentUnit(e){let t=e.facet(indentUnit);return 9==t.charCodeAt(0)?e.tabSize*t.length:t.length}function indentString(e,t){let n="",r=e.tabSize,o=e.facet(indentUnit)[0];if("\t"==o){for(;t>=r;)n+="\t",t-=r;o=" "}for(let e=0;e<t;e++)n+=o;return n}function getIndentation(e,t){e instanceof EditorState&&(e=new IndentContext(e));for(let n of e.state.facet(indentService)){let r=n(e,t);if(void 0!==r)return r}let n=syntaxTree(e.state);return n.length>=t?syntaxIndentation(e,n,t):null}function indentRange(e,t,n){let r=Object.create(null),o=new IndentContext(e,{overrideIndentation:e=>{var t;return null!==(t=r[e])&&void 0!==t?t:-1}}),i=[];for(let s=t;s<=n;){let t=e.doc.lineAt(s);s=t.to+1;let n=getIndentation(o,t.from);if(null==n)continue;/\S/.test(t.text)||(n=0);let a=/^\s*/.exec(t.text)[0],l=indentString(e,n);a!=l&&(r[t.from]=n,i.push({from:t.from,to:t.from+a.length,insert:l}))}return e.changes(i)}class IndentContext{constructor(e,t={}){this.state=e,this.options=t,this.unit=getIndentUnit(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:o}=this.options;return null!=r&&r>=n.from&&r<=n.to?o&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:n.text.slice(r-n.from),from:r}:{text:n.text.slice(0,r-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:r}=this.lineAt(e,t);return n.slice(e-r,Math.min(n.length,e+100-r))}column(e,t=1){let{text:n,from:r}=this.lineAt(e,t),o=this.countColumn(n,e-r),i=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return i>-1&&(o+=i-this.countColumn(n,n.search(/\S|$/))),o}countColumn(e,t=e.length){return countColumn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:r}=this.lineAt(e,t),o=this.options.overrideIndentation;if(o){let e=o(r);if(e>-1)return e}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const indentNodeProp=new NodeProp;function syntaxIndentation(e,t,n){return indentFrom(t.resolveInner(n).enterUnfinishedNodesBefore(n),n,e)}function ignoreClosed(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}function indentStrategy(e){let t=e.type.prop(indentNodeProp);if(t)return t;let n,r=e.firstChild;if(r&&(n=r.type.prop(NodeProp.closedBy))){let t=e.lastChild,r=t&&n.indexOf(t.name)>-1;return e=>delimitedStrategy(e,!0,1,void 0,r&&!ignoreClosed(e)?t.from:void 0)}return null==e.parent?topIndent:null}function indentFrom(e,t,n){for(;e;e=e.parent){let r=indentStrategy(e);if(r)return r(TreeIndentContext.create(n,t,e))}return null}function topIndent(){return 0}class TreeIndentContext extends IndentContext{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.node=n}static create(e,t,n){return new TreeIndentContext(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(isParent(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){let e=this.node.parent;return e?indentFrom(e,this.pos,this.base):0}}function isParent(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function bracketedAligned(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let o=e.options.simulateBreak,i=e.state.doc.lineAt(n.from),s=null==o||o<=i.from?i.to:Math.min(i.to,o);for(let e=n.to;;){let o=t.childAfter(e);if(!o||o==r)return null;if(!o.type.isSkipped)return o.from<s?n:null;e=o.to}}function delimitedIndent({closing:e,align:t=!0,units:n=1}){return r=>delimitedStrategy(r,t,n,e)}function delimitedStrategy(e,t,n,r,o){let i=e.textAfter,s=i.match(/^\s*/)[0].length,a=r&&i.slice(s,s+r.length)==r||o==e.pos+s,l=t?bracketedAligned(e):null;return l?a?e.column(l.from):e.column(l.to):e.baseIndent+(a?0:e.unit*n)}const flatIndent=e=>e.baseIndent;function continuedIndent({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}const DontIndentBeyond=200;function indentOnInput(){return EditorState.transactionFilter.of((e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let n=e.newDoc,{head:r}=e.newSelection.main,o=n.lineAt(r);if(r>o.from+200)return e;let i=n.sliceString(o.from,r);if(!t.some((e=>e.test(i))))return e;let{state:s}=e,a=-1,l=[];for(let{head:e}of s.selection.ranges){let t=s.doc.lineAt(e);if(t.from==a)continue;a=t.from;let n=getIndentation(s,t.from);if(null==n)continue;let r=/^\s*/.exec(t.text)[0],o=indentString(s,n);r!=o&&l.push({from:t.from,to:t.from+r.length,insert:o})}return l.length?[e,{changes:l,sequential:!0}]:e}))}const foldService=Facet.define(),foldNodeProp=new NodeProp;function foldInside(e){let t=e.firstChild,n=e.lastChild;return t&&t.to<n.from?{from:t.to,to:n.type.isError?e.to:n.from}:null}function syntaxFolding(e,t,n){let r=syntaxTree(e);if(r.length<n)return null;let o=null;for(let i=r.resolveInner(n,1);i;i=i.parent){if(i.to<=n||i.from>n)continue;if(o&&i.from<t)break;let s=i.type.prop(foldNodeProp);if(s&&(i.to<r.length-50||r.length==e.doc.length||!isUnfinished(i))){let r=s(i,e);r&&r.from<=n&&r.from>=t&&r.to>n&&(o=r)}}return o}function isUnfinished(e){let t=e.lastChild;return t&&t.to==e.to&&t.type.isError}function foldable(e,t,n){for(let r of e.facet(foldService)){let o=r(e,t,n);if(o)return o}return syntaxFolding(e,t,n)}function mapRange(e,t){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);return n>=r?void 0:{from:n,to:r}}const foldEffect=StateEffect.define({map:mapRange}),unfoldEffect=StateEffect.define({map:mapRange});function selectedLines(e){let t=[];for(let{head:n}of e.state.selection.ranges)t.some((e=>e.from<=n&&e.to>=n))||t.push(e.lineBlockAt(n));return t}const foldState=StateField.define({create:()=>Decoration.none,update(e,t){e=e.map(t.changes);for(let n of t.effects)if(n.is(foldEffect)&&!foldExists(e,n.value.from,n.value.to)){let{preparePlaceholder:r}=t.state.facet(foldConfig),o=r?Decoration.replace({widget:new PreparedFoldWidget(r(t.state,n.value))}):foldWidget;e=e.update({add:[o.range(n.value.from,n.value.to)]})}else n.is(unfoldEffect)&&(e=e.update({filter:(e,t)=>n.value.from!=e||n.value.to!=t,filterFrom:n.value.from,filterTo:n.value.to}));if(t.selection){let n=!1,{head:r}=t.selection.main;e.between(r,r,((e,t)=>{e<r&&t>r&&(n=!0)})),n&&(e=e.update({filterFrom:r,filterTo:r,filter:(e,t)=>t<=r||e>=r}))}return e},provide:e=>EditorView.decorations.from(e),toJSON(e,t){let n=[];return e.between(0,t.doc.length,((e,t)=>{n.push(e,t)})),n},fromJSON(e){if(!Array.isArray(e)||e.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let n=0;n<e.length;){let r=e[n++],o=e[n++];if("number"!=typeof r||"number"!=typeof o)throw new RangeError("Invalid JSON for fold state");t.push(foldWidget.range(r,o))}return Decoration.set(t,!0)}});function foldedRanges(e){return e.field(foldState,!1)||RangeSet.empty}function findFold(e,t,n){var r;let o=null;return null===(r=e.field(foldState,!1))||void 0===r||r.between(t,n,((e,t)=>{(!o||o.from>e)&&(o={from:e,to:t})})),o}function foldExists(e,t,n){let r=!1;return e.between(t,t,((e,o)=>{e==t&&o==n&&(r=!0)})),r}function maybeEnable(e,t){return e.field(foldState,!1)?t:t.concat(StateEffect.appendConfig.of(codeFolding()))}const foldCode=e=>{for(let t of selectedLines(e)){let n=foldable(e.state,t.from,t.to);if(n)return e.dispatch({effects:maybeEnable(e.state,[foldEffect.of(n),announceFold(e,n)])}),!0}return!1},unfoldCode=e=>{if(!e.state.field(foldState,!1))return!1;let t=[];for(let n of selectedLines(e)){let r=findFold(e.state,n.from,n.to);r&&t.push(unfoldEffect.of(r),announceFold(e,r,!1))}return t.length&&e.dispatch({effects:t}),t.length>0};function announceFold(e,t,n=!0){let r=e.state.doc.lineAt(t.from).number,o=e.state.doc.lineAt(t.to).number;return EditorView.announce.of(`${e.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${e.state.phrase("to")} ${o}.`)}const foldAll=e=>{let{state:t}=e,n=[];for(let r=0;r<t.doc.length;){let o=e.lineBlockAt(r),i=foldable(t,o.from,o.to);i&&n.push(foldEffect.of(i)),r=(i?e.lineBlockAt(i.to):o).to+1}return n.length&&e.dispatch({effects:maybeEnable(e.state,n)}),!!n.length},unfoldAll=e=>{let t=e.state.field(foldState,!1);if(!t||!t.size)return!1;let n=[];return t.between(0,e.state.doc.length,((e,t)=>{n.push(unfoldEffect.of({from:e,to:t}))})),e.dispatch({effects:n}),!0};function foldableContainer(e,t){for(let n=t;;){let r=foldable(e.state,n.from,n.to);if(r&&r.to>t.from)return r;if(!n.from)return null;n=e.lineBlockAt(n.from-1)}}const toggleFold=e=>{let t=[];for(let n of selectedLines(e)){let r=findFold(e.state,n.from,n.to);if(r)t.push(unfoldEffect.of(r),announceFold(e,r,!1));else{let r=foldableContainer(e,n);r&&t.push(foldEffect.of(r),announceFold(e,r))}}return t.length>0&&e.dispatch({effects:maybeEnable(e.state,t)}),!!t.length},foldKeymap=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:foldCode},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:unfoldCode},{key:"Ctrl-Alt-[",run:foldAll},{key:"Ctrl-Alt-]",run:unfoldAll}],defaultConfig={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},foldConfig=Facet.define({combine:e=>combineConfig(e,defaultConfig)});function codeFolding(e){let t=[foldState,baseTheme$1];return e&&t.push(foldConfig.of(e)),t}function widgetToDOM(e,t){let{state:n}=e,r=n.facet(foldConfig),o=t=>{let n=e.lineBlockAt(e.posAtDOM(t.target)),r=findFold(e.state,n.from,n.to);r&&e.dispatch({effects:unfoldEffect.of(r)}),t.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(e,o,t);let i=document.createElement("span");return i.textContent=r.placeholderText,i.setAttribute("aria-label",n.phrase("folded code")),i.title=n.phrase("unfold"),i.className="cm-foldPlaceholder",i.onclick=o,i}const foldWidget=Decoration.replace({widget:new class extends WidgetType{toDOM(e){return widgetToDOM(e,null)}}});class PreparedFoldWidget extends WidgetType{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return widgetToDOM(e,this.value)}}const foldGutterDefaults={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class FoldMarker extends GutterMarker{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function foldGutter(e={}){let t=Object.assign(Object.assign({},foldGutterDefaults),e),n=new FoldMarker(t,!0),r=new FoldMarker(t,!1),o=ViewPlugin.fromClass(class{constructor(e){this.from=e.viewport.from,this.markers=this.buildMarkers(e)}update(e){(e.docChanged||e.viewportChanged||e.startState.facet(language)!=e.state.facet(language)||e.startState.field(foldState,!1)!=e.state.field(foldState,!1)||syntaxTree(e.startState)!=syntaxTree(e.state)||t.foldingChanged(e))&&(this.markers=this.buildMarkers(e.view))}buildMarkers(e){let t=new RangeSetBuilder;for(let o of e.viewportLineBlocks){let i=findFold(e.state,o.from,o.to)?r:foldable(e.state,o.from,o.to)?n:null;i&&t.add(o.from,o.from,i)}return t.finish()}}),{domEventHandlers:i}=t;return[o,gutter({class:"cm-foldGutter",markers(e){var t;return(null===(t=e.plugin(o))||void 0===t?void 0:t.markers)||RangeSet.empty},initialSpacer:()=>new FoldMarker(t,!1),domEventHandlers:Object.assign(Object.assign({},i),{click:(e,t,n)=>{if(i.click&&i.click(e,t,n))return!0;let r=findFold(e.state,t.from,t.to);if(r)return e.dispatch({effects:unfoldEffect.of(r)}),!0;let o=foldable(e.state,t.from,t.to);return!!o&&(e.dispatch({effects:foldEffect.of(o)}),!0)}})}),codeFolding()]}const baseTheme$1=EditorView.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class HighlightStyle{constructor(e,t){let n;function r(e){let t=StyleModule.newName();return(n||(n=Object.create(null)))["."+t]=e,t}this.specs=e;const o="string"==typeof t.all?t.all:t.all?r(t.all):void 0,i=t.scope;this.scope=i instanceof Language?e=>e.prop(languageDataProp)==i.data:i?e=>e==i:void 0,this.style=tagHighlighter(e.map((e=>({tag:e.tag,class:e.class||r(Object.assign({},e,{tag:null}))}))),{all:o}).style,this.module=n?new StyleModule(n):null,this.themeType=t.themeType}static define(e,t){return new HighlightStyle(e,t||{})}}const highlighterFacet=Facet.define(),fallbackHighlighter=Facet.define({combine:e=>e.length?[e[0]]:null});function getHighlighters(e){let t=e.facet(highlighterFacet);return t.length?t:e.facet(fallbackHighlighter)}function syntaxHighlighting(e,t){let n,r=[treeHighlighter];return e instanceof HighlightStyle&&(e.module&&r.push(EditorView.styleModule.of(e.module)),n=e.themeType),(null==t?void 0:t.fallback)?r.push(fallbackHighlighter.of(e)):n?r.push(highlighterFacet.computeN([EditorView.darkTheme],(t=>t.facet(EditorView.darkTheme)==("dark"==n)?[e]:[]))):r.push(highlighterFacet.of(e)),r}function highlightingFor(e,t,n){let r=getHighlighters(e),o=null;if(r)for(let e of r)if(!e.scope||n&&e.scope(n)){let n=e.style(t);n&&(o=o?o+" "+n:n)}return o}class TreeHighlighter{constructor(e){this.markCache=Object.create(null),this.tree=syntaxTree(e.state),this.decorations=this.buildDeco(e,getHighlighters(e.state))}update(e){let t=syntaxTree(e.state),n=getHighlighters(e.state),r=n!=getHighlighters(e.startState);t.length<e.view.viewport.to&&!r&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n))}buildDeco(e,t){if(!t||!this.tree.length)return Decoration.none;let n=new RangeSetBuilder;for(let{from:r,to:o}of e.visibleRanges)highlightTree(this.tree,t,((e,t,r)=>{n.add(e,t,this.markCache[r]||(this.markCache[r]=Decoration.mark({class:r})))}),r,o);return n.finish()}}const treeHighlighter=Prec.high(ViewPlugin.fromClass(TreeHighlighter,{decorations:e=>e.decorations})),defaultHighlightStyle=HighlightStyle.define([{tag:tags.meta,color:"#404740"},{tag:tags.link,textDecoration:"underline"},{tag:tags.heading,textDecoration:"underline",fontWeight:"bold"},{tag:tags.emphasis,fontStyle:"italic"},{tag:tags.strong,fontWeight:"bold"},{tag:tags.strikethrough,textDecoration:"line-through"},{tag:tags.keyword,color:"#708"},{tag:[tags.atom,tags.bool,tags.url,tags.contentSeparator,tags.labelName],color:"#219"},{tag:[tags.literal,tags.inserted],color:"#164"},{tag:[tags.string,tags.deleted],color:"#a11"},{tag:[tags.regexp,tags.escape,tags.special(tags.string)],color:"#e40"},{tag:tags.definition(tags.variableName),color:"#00f"},{tag:tags.local(tags.variableName),color:"#30a"},{tag:[tags.typeName,tags.namespace],color:"#085"},{tag:tags.className,color:"#167"},{tag:[tags.special(tags.variableName),tags.macroName],color:"#256"},{tag:tags.definition(tags.propertyName),color:"#00c"},{tag:tags.comment,color:"#940"},{tag:tags.invalid,color:"#f00"}]),baseTheme=EditorView.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),DefaultScanDist=1e4,DefaultBrackets="()[]{}",bracketMatchingConfig=Facet.define({combine:e=>combineConfig(e,{afterCursor:!0,brackets:"()[]{}",maxScanDistance:1e4,renderMatch:defaultRenderMatch})}),matchingMark=Decoration.mark({class:"cm-matchingBracket"}),nonmatchingMark=Decoration.mark({class:"cm-nonmatchingBracket"});function defaultRenderMatch(e){let t=[],n=e.matched?matchingMark:nonmatchingMark;return t.push(n.range(e.start.from,e.start.to)),e.end&&t.push(n.range(e.end.from,e.end.to)),t}const bracketMatchingState=StateField.define({create:()=>Decoration.none,update(e,t){if(!t.docChanged&&!t.selection)return e;let n=[],r=t.state.facet(bracketMatchingConfig);for(let e of t.state.selection.ranges){if(!e.empty)continue;let o=matchBrackets(t.state,e.head,-1,r)||e.head>0&&matchBrackets(t.state,e.head-1,1,r)||r.afterCursor&&(matchBrackets(t.state,e.head,1,r)||e.head<t.state.doc.length&&matchBrackets(t.state,e.head+1,-1,r));o&&(n=n.concat(r.renderMatch(o,t.state)))}return Decoration.set(n,!0)},provide:e=>EditorView.decorations.from(e)}),bracketMatchingUnique=[bracketMatchingState,baseTheme];function bracketMatching(e={}){return[bracketMatchingConfig.of(e),bracketMatchingUnique]}const bracketMatchingHandle=new NodeProp;function matchingNodes(e,t,n){let r=e.prop(t<0?NodeProp.openedBy:NodeProp.closedBy);if(r)return r;if(1==e.name.length){let r=n.indexOf(e.name);if(r>-1&&r%2==(t<0?1:0))return[n[r+t]]}return null}function findHandle(e){let t=e.type.prop(bracketMatchingHandle);return t?t(e.node):e}function matchBrackets(e,t,n,r={}){let o=r.maxScanDistance||1e4,i=r.brackets||"()[]{}",s=syntaxTree(e),a=s.resolveInner(t,n);for(let r=a;r;r=r.parent){let o=matchingNodes(r.type,n,i);if(o&&r.from<r.to){let s=findHandle(r);if(s&&(n>0?t>=s.from&&t<s.to:t>s.from&&t<=s.to))return matchMarkedBrackets(e,t,n,r,s,o,i)}}return matchPlainBrackets(e,t,n,s,a.type,o,i)}function matchMarkedBrackets(e,t,n,r,o,i,s){let a=r.parent,l={from:o.from,to:o.to},h=0,d=null==a?void 0:a.cursor();if(d&&(n<0?d.childBefore(r.from):d.childAfter(r.to)))do{if(n<0?d.to<=r.from:d.from>=r.to){if(0==h&&i.indexOf(d.type.name)>-1&&d.from<d.to){let e=findHandle(d);return{start:l,end:e?{from:e.from,to:e.to}:void 0,matched:!0}}if(matchingNodes(d.type,n,s))h++;else if(matchingNodes(d.type,-n,s)){if(0==h){let e=findHandle(d);return{start:l,end:e&&e.from<e.to?{from:e.from,to:e.to}:void 0,matched:!1}}h--}}}while(n<0?d.prevSibling():d.nextSibling());return{start:l,matched:!1}}function matchPlainBrackets(e,t,n,r,o,i,s){let a=n<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),l=s.indexOf(a);if(l<0||l%2==0!=n>0)return null;let h={from:n<0?t-1:t,to:n>0?t+1:t},d=e.doc.iterRange(t,n>0?e.doc.length:0),u=0;for(let e=0;!d.next().done&&e<=i;){let i=d.value;n<0&&(e+=i.length);let a=t+e*n;for(let e=n>0?0:i.length-1,t=n>0?i.length:-1;e!=t;e+=n){let t=s.indexOf(i[e]);if(!(t<0||r.resolveInner(a+e,1).type!=o))if(t%2==0==n>0)u++;else{if(1==u)return{start:h,end:{from:a+e,to:a+e+1},matched:t>>1==l>>1};u--}}n>0&&(e+=i.length)}return d.done?{start:h,matched:!1}:null}function countCol(e,t,n,r=0,o=0){null==t&&-1==(t=e.search(/[^\s\u00a0]/))&&(t=e.length);let i=o;for(let o=r;o<t;o++)9==e.charCodeAt(o)?i+=n-i%n:i++;return i}class StringStream{constructor(e,t,n,r){this.string=e,this.tabSize=t,this.indentUnit=n,this.overrideIndent=r,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return 0==this.pos}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t,n=this.string.charAt(this.pos);if(t="string"==typeof e?n==e:n&&(e instanceof RegExp?e.test(n):e(n)),t)return++this.pos,n}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=countCol(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return null!==(e=this.overrideIndent)&&void 0!==e?e:countCol(this.string,null,this.tabSize)}match(e,t,n){if("string"==typeof e){let r=e=>n?e.toLowerCase():e;return r(this.string.substr(this.pos,e.length))==r(e)?(!1!==t&&(this.pos+=e.length),!0):null}{let n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&!1!==t&&(this.pos+=n[0].length),n)}}current(){return this.string.slice(this.start,this.pos)}}function fullParser(e){return{name:e.name||"",token:e.token,blankLine:e.blankLine||(()=>{}),startState:e.startState||(()=>!0),copyState:e.copyState||defaultCopyState,indent:e.indent||(()=>null),languageData:e.languageData||{},tokenTable:e.tokenTable||noTokens}}function defaultCopyState(e){if("object"!=typeof e)return e;let t={};for(let n in e){let r=e[n];t[n]=r instanceof Array?r.slice():r}return t}const IndentedFrom=new WeakMap;class StreamLanguage extends Language{constructor(e){let t,n=defineLanguageFacet(e.languageData),r=fullParser(e);super(n,new class extends Parser{createParse(e,n,r){return new Parse(t,e,n,r)}},[indentService.of(((e,t)=>this.getIndent(e,t)))],e.name),this.topNode=docID(n),t=this,this.streamParser=r,this.stateAfter=new NodeProp({perNode:!0}),this.tokenTable=e.tokenTable?new TokenTable(r.tokenTable):defaultTokenTable}static define(e){return new StreamLanguage(e)}getIndent(e,t){let n,r=syntaxTree(e.state),o=r.resolve(t);for(;o&&o.type!=this.topNode;)o=o.parent;if(!o)return null;let{overrideIndentation:i}=e.options;i&&(n=IndentedFrom.get(e.state),null!=n&&n<t-1e4&&(n=void 0));let s,a,l=findState(this,r,0,o.from,null!=n?n:t);if(l?(a=l.state,s=l.pos+1):(a=this.streamParser.startState(e.unit),s=0),t-s>1e4)return null;for(;s<t;){let n=e.state.doc.lineAt(s),r=Math.min(t,n.to);if(n.length){let t=i?i(n.from):-1,o=new StringStream(n.text,e.state.tabSize,e.unit,t<0?void 0:t);for(;o.pos<r-n.from;)readToken(this.streamParser.token,o,a)}else this.streamParser.blankLine(a,e.unit);if(r==t)break;s=n.to+1}let h=e.lineAt(t);return i&&null==n&&IndentedFrom.set(e.state,h.from),this.streamParser.indent(a,/^\s*(.*)/.exec(h.text)[1],e)}get allowsNesting(){return!1}}function findState(e,t,n,r,o){let i=n>=r&&n+t.length<=o&&t.prop(e.stateAfter);if(i)return{state:e.streamParser.copyState(i),pos:n+t.length};for(let i=t.children.length-1;i>=0;i--){let s=t.children[i],a=n+t.positions[i],l=s instanceof Tree&&a<o&&findState(e,s,a,r,o);if(l)return l}return null}function cutTree(e,t,n,r,o){if(o&&n<=0&&r>=t.length)return t;o||t.type!=e.topNode||(o=!0);for(let i=t.children.length-1;i>=0;i--){let s,a=t.positions[i],l=t.children[i];if(a<r&&l instanceof Tree){if(!(s=cutTree(e,l,n-a,r-a,o)))break;return o?new Tree(t.type,t.children.slice(0,i).concat(s),t.positions.slice(0,i+1),a+s.length):s}}return null}function findStartInFragments(e,t,n,r){for(let r of t){let t,o=r.from+(r.openStart?25:0),i=r.to-(r.openEnd?25:0),s=o<=n&&i>n&&findState(e,r.tree,0-r.offset,n,i);if(s&&(t=cutTree(e,r.tree,n+r.offset,s.pos+r.offset,!1)))return{state:s.state,tree:t}}return{state:e.streamParser.startState(r?getIndentUnit(r):4),tree:Tree.empty}}class Parse{constructor(e,t,n,r){this.lang=e,this.input=t,this.fragments=n,this.ranges=r,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=r[r.length-1].to;let o=ParseContext.get(),i=r[0].from,{state:s,tree:a}=findStartInFragments(e,n,i,null==o?void 0:o.state);this.state=s,this.parsedPos=this.chunkStart=i+a.length;for(let e=0;e<a.children.length;e++)this.chunks.push(a.children[e]),this.chunkPos.push(a.positions[e]);o&&this.parsedPos<o.viewport.from-1e5&&(this.state=this.lang.streamParser.startState(getIndentUnit(o.state)),o.skipUntilInView(this.parsedPos,o.viewport.from),this.parsedPos=o.viewport.from),this.moveRangeIndex()}advance(){let e=ParseContext.get(),t=null==this.stoppedAt?this.to:Math.min(this.to,this.stoppedAt),n=Math.min(t,this.chunkStart+2048);for(e&&(n=Math.min(n,e.viewport.to));this.parsedPos<n;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)"\n"==t&&(t="");else{let e=t.indexOf("\n");e>-1&&(t=t.slice(0,e))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),n=e+t.length;for(let e=this.rangeIndex;;){let r=this.ranges[e].to;if(r>=n)break;if(t=t.slice(0,r-(n-t.length)),e++,e==this.ranges.length)break;let o=this.ranges[e].from,i=this.lineAfter(o);t+=i,n=o+i.length}return{line:t,end:n}}skipGapsTo(e,t,n){for(;;){let r=this.ranges[this.rangeIndex].to,o=e+t;if(n>0?r>o:r>=o)break;t+=this.ranges[++this.rangeIndex].from-r}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,n,r,o){if(this.ranges.length>1){t+=o=this.skipGapsTo(t,o,1);let e=this.chunk.length;n+=o=this.skipGapsTo(n,o,-1),r+=this.chunk.length-e}return this.chunk.push(e,t,n,r),o}parseLine(e){let{line:t,end:n}=this.nextLine(),r=0,{streamParser:o}=this.lang,i=new StringStream(t,e?e.state.tabSize:4,e?getIndentUnit(e.state):2);if(i.eol())o.blankLine(this.state,i.indentUnit);else for(;!i.eol();){let e=readToken(o.token,i,this.state);if(e&&(r=this.emitToken(this.lang.tokenTable.resolve(e),this.parsedPos+i.start,this.parsedPos+i.pos,4,r)),i.start>1e4)break}this.parsedPos=n,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=Tree.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:nodeSet,topID:0,maxBufferLength:2048,reused:this.chunkReused});e=new Tree(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new Tree(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function readToken(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let r=e(t,n);if(t.pos>t.start)return r}throw new Error("Stream parser failed to advance stream.")}const noTokens=Object.create(null),typeArray=[NodeType.none],nodeSet=new NodeSet(typeArray),warned=[],defaultTable=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])defaultTable[e]=createTokenType(noTokens,t);class TokenTable{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),defaultTable)}resolve(e){return e?this.table[e]||(this.table[e]=createTokenType(this.extra,e)):0}}const defaultTokenTable=new TokenTable(noTokens);function warnForPart(e,t){warned.indexOf(e)>-1||(warned.push(e),console.warn(t))}function createTokenType(e,t){let n=null;for(let r of t.split(".")){let t=e[r]||tags[r];t?"function"==typeof t?n?n=t(n):warnForPart(r,`Modifier ${r} used at start of tag`):n?warnForPart(r,`Tag ${r} used as modifier`):n=t:warnForPart(r,`Unknown highlighting tag ${r}`)}if(!n)return 0;let r=t.replace(/ /g,"_"),o=NodeType.define({id:typeArray.length,name:r,props:[styleTags({[r]:n})]});return typeArray.push(o),o.id}function docID(e){let t=NodeType.define({id:typeArray.length,name:"Document",props:[languageDataProp.add((()=>e))],top:!0});return typeArray.push(t),t}export{DocInput,HighlightStyle,IndentContext,LRLanguage,Language,LanguageDescription,LanguageSupport,ParseContext,StreamLanguage,StringStream,TreeIndentContext,bracketMatching,bracketMatchingHandle,codeFolding,continuedIndent,defaultHighlightStyle,defineLanguageFacet,delimitedIndent,ensureSyntaxTree,flatIndent,foldAll,foldCode,foldEffect,foldGutter,foldInside,foldKeymap,foldNodeProp,foldService,foldState,foldable,foldedRanges,forceParsing,getIndentUnit,getIndentation,highlightingFor,indentNodeProp,indentOnInput,indentRange,indentService,indentString,indentUnit,language,languageDataProp,matchBrackets,sublanguageProp,syntaxHighlighting,syntaxParserRunning,syntaxTree,syntaxTreeAvailable,toggleFold,unfoldAll,unfoldCode,unfoldEffect}; |