Files
llm-in-text/.build-check/assets/cm-language-CDsY7zq0.js
T
ydy0615 838eec30a8 feat: add theme management with light and dark modes
- Implemented a new composable `useTheme` for managing theme state.
- Added functions to read and write theme preference to local storage.
- Applied theme styles to the DOM based on user preference.
- Introduced a toggle function to switch between light and dark themes.

refactor: enhance copilot plugin functionality

- Improved request handling with sequence and document versioning.
- Refactored ghost text handling to improve clarity and efficiency.
- Updated markdown insertion logic to handle parsed content more robustly.
- Enhanced error handling and logging for better debugging.

style: update global styles for light and dark themes

- Defined CSS variables for light and dark themes to streamline styling.
- Improved overall styling consistency and responsiveness.
- Added transitions for smoother theme changes and interactions.
2026-02-15 15:44:09 +08:00

4 lines
33 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{N as b,T as d,I as re,P as pe,b as W,c as qe,d as E}from"./vendor-lezer-common-tVQBIsvN.js";import{P as Ge,F as v,l as O,m as me,b as Z,S as U,e as ge,h as Je,R as Ke}from"./cm-state-X9WpHEQO.js";import{E as y,V as _,D as g,b as Qe,G as Xe,l as Ye,W as ke,a as se}from"./cm-view-CiSFjroV.js";import{a as Ze,h as _e,t as f,s as et}from"./vendor-lezer-highlight-DuEf3ZFH.js";import{S as ie}from"./vendor-style-mod-Bs6eFhZE.js";var j;const P=new b;function be(n){return v.define({combine:n?e=>e.concat(n):void 0})}const tt=new b;class m{constructor(e,t,r=[],s=""){this.data=e,this.name=s,O.prototype.hasOwnProperty("tree")||Object.defineProperty(O.prototype,"tree",{get(){return w(this)}}),this.parser=t,this.extension=[S.of(this),O.languageData.of((i,o,l)=>{let a=oe(i,o,l),h=a.type.prop(P);if(!h)return[];let u=i.facet(h),c=a.type.prop(tt);if(c){let k=a.resolve(o-a.from,l);for(let p of c)if(p.test(k,i)){let x=i.facet(p.facet);return p.type=="replace"?x:x.concat(u)}}return u})].concat(r)}isActiveAt(e,t,r=-1){return oe(e,t,r).type.prop(P)==this.data}findRegions(e){let t=e.facet(S);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],s=(i,o)=>{if(i.prop(P)==this.data){r.push({from:o,to:o+i.length});return}let l=i.prop(b.mounted);if(l){if(l.tree.prop(P)==this.data){if(l.overlay)for(let a of l.overlay)r.push({from:a.from+o,to:a.to+o});else r.push({from:o,to:o+i.length});return}else if(l.overlay){let a=r.length;if(s(l.tree,l.overlay[0].from+o),r.length>a)return}}for(let a=0;a<i.children.length;a++){let h=i.children[a];h instanceof d&&s(h,i.positions[a]+o)}};return s(w(e),0),r}get allowsNesting(){return!0}}m.setState=U.define();function oe(n,e,t){let r=n.facet(S),s=w(n).topNode;if(!r||r.allowsNesting)for(let i=s;i;i=i.enter(e,t,re.ExcludeBuffers|re.EnterBracketed))i.type.isTop&&(s=i);return s}class K extends m{constructor(e,t,r){super(e,t,[],r),this.parser=t}static define(e){let t=be(e.languageData);return new K(t,e.parser.configure({props:[P.add(r=>r.isTop?t:void 0)]}),e.name)}configure(e,t){return new K(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function w(n){let e=n.field(m.state,!1);return e?e.tree:d.empty}class nt{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 r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}}let D=null;class A{constructor(e,t,r=[],s,i,o,l,a){this.parser=e,this.state=t,this.fragments=r,this.tree=s,this.treeLen=i,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new A(e,t,[],d.empty,0,r,[],null)}startParse(){return this.parser.startParse(new nt(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=d.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(E.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||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(E.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=D;D=this;try{return e()}finally{D=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=ae(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:s,treeLen:i,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,u,c,k)=>a.push({fromA:h,toA:u,fromB:c,toB:k})),r=E.applyChanges(r,a),s=d.empty,i=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let u=e.mapPos(h.from,1),c=e.mapPos(h.to,-1);u<c&&l.push({from:u,to:c})}}}return new A(this.parser,t,r,s,i,o,l,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 r=0;r<this.skipped.length;r++){let{from:s,to:i}=this.skipped[r];s<e.to&&i>e.from&&(this.fragments=ae(this.fragments,s,i),this.skipped.splice(r--,1))}return this.skipped.length>=t?!1:(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 pe{createParse(t,r,s){let i=s[0].from,o=s[s.length-1].to;return{parsedPos:i,advance(){let a=D;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new d(W.none,[],[],o-i)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return D}}function ae(n,e,t){return E.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class I{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),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new I(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=A.create(e.facet(S).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new I(r)}}m.state=Z.define({create:I.init,update(n,e){for(let t of e.effects)if(t.is(m.setState))return t.value;return e.startState.facet(S)!=e.state.facet(S)?I.init(e.state):n.apply(e)}});let we=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(we=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const z=typeof navigator<"u"&&(!((j=navigator.scheduling)===null||j===void 0)&&j.isInputPending)?()=>navigator.scheduling.isInputPending():null,rt=_.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(m.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(m.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=we(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:r,viewport:{to:s}}=this.view,i=r.field(m.state);if(i.tree==i.context.tree&&i.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!z?Math.max(25,e.timeRemaining()-5):1e9),l=i.context.treeLen<s&&r.doc.length>s+1e3,a=i.context.work(()=>z&&z()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:m.setState.of(new I(i.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Ye(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),S=v.define({combine(n){return n.length?n[0]:null},enables:n=>[m.state,rt,y.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Yt{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class ye{constructor(e,t,r,s,i,o=void 0){this.name=e,this.alias=t,this.extensions=r,this.filename=s,this.loadFunc=i,this.support=o,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:r}=e;if(!t){if(!r)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(r)}return new ye(e.name,(e.alias||[]).concat(e.name).map(s=>s.toLowerCase()),e.extensions||[],e.filename,t,r)}static matchFilename(e,t){for(let s of e)if(s.filename&&s.filename.test(t))return s;let r=/\.([^.]+)$/.exec(t);if(r){for(let s of e)if(s.extensions.indexOf(r[1])>-1)return s}return null}static matchLanguageName(e,t,r=!0){t=t.toLowerCase();for(let s of e)if(s.alias.some(i=>i==t))return s;if(r)for(let s of e)for(let i of s.alias){let o=t.indexOf(i);if(o>-1&&(i.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+i.length])))return s}return null}}const st=v.define(),ve=v.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function F(n){let e=n.facet(ve);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function it(n,e){let t="",r=n.tabSize,s=n.facet(ve)[0];if(s==" "){for(;e>=r;)t+=" ",e-=r;s=" "}for(let i=0;i<e;i++)t+=s;return t}function ot(n,e){n instanceof O&&(n=new Se(n));for(let r of n.state.facet(st)){let s=r(n,e);if(s!==void 0)return s}let t=w(n.state);return t.length>=e?at(n,t,e):null}class Se{constructor(e,t={}){this.state=e,this.options=t,this.unit=F(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:i}=this.options;return s!=null&&s>=r.from&&s<=r.to?i&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:r.text.slice(s-r.from),from:s}:{text:r.text.slice(0,s-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:s}=this.lineAt(e,t);return r.slice(e-s,Math.min(r.length,e+100-s))}column(e,t=1){let{text:r,from:s}=this.lineAt(e,t),i=this.countColumn(r,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(i+=o-this.countColumn(r,r.search(/\S|$/))),i}countColumn(e,t=e.length){return Je(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:s}=this.lineAt(e,t),i=this.options.overrideIndentation;if(i){let o=i(s);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Pe=new b;function at(n,e,t){let r=e.resolveStack(t),s=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(s!=r.node){let i=[];for(let o=s;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)i.push(o);for(let o=i.length-1;o>=0;o--)r={node:i[o],next:r}}return Te(r,n,t)}function Te(n,e,t){for(let r=n;r;r=r.next){let s=ht(r.node);if(s)return s(ee.create(e,t,r))}return 0}function lt(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function ht(n){let e=n.type.prop(Pe);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(b.closedBy))){let s=n.lastChild,i=s&&r.indexOf(s.name)>-1;return o=>xe(o,!0,1,void 0,i&&!lt(o)?s.from:void 0)}return n.parent==null?ut:null}function ut(){return 0}class ee extends Se{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new ee(e,t,r)}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 r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(ft(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return Te(this.context.next,this.base,this.pos)}}function ft(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function ct(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,i=n.state.doc.lineAt(t.from),o=s==null||s<=i.from?i.to:Math.min(i.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==r)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let h=/^ */.exec(i.text.slice(t.to-i.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function Zt({closing:n,align:e=!0,units:t=1}){return r=>xe(r,e,t,n)}function xe(n,e,t,r,s){let i=n.textAfter,o=i.match(/^\s*/)[0].length,l=r&&i.slice(o,o+r.length)==r||s==n.pos+o,a=e?ct(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const _t=n=>n.baseIndent;function en({except:n,units:e=1}={}){return t=>{let r=n&&n.test(t.textAfter);return t.baseIndent+(r?0:e*t.unit)}}const dt=200;function tn(){return O.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:r}=n.newSelection.main,s=t.lineAt(r);if(r>s.from+dt)return n;let i=t.sliceString(s.from,r);if(!e.some(h=>h.test(i)))return n;let{state:o}=n,l=-1,a=[];for(let{head:h}of o.selection.ranges){let u=o.doc.lineAt(h);if(u.from==l)continue;l=u.from;let c=ot(o,u.from);if(c==null)continue;let k=/^\s*/.exec(u.text)[0],p=it(o,c);k!=p&&a.push({from:u.from,to:u.from+k.length,insert:p})}return a.length?[n,{changes:a,sequential:!0}]:n})}const pt=v.define(),mt=new b;function nn(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function gt(n,e,t){let r=w(n);if(r.length<t)return null;let s=r.resolveStack(t,1),i=null;for(let o=s;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(i&&l.from<e)break;let a=l.type.prop(mt);if(a&&(l.to<r.length-50||r.length==n.doc.length||!kt(l))){let h=a(l,n);h&&h.from<=t&&h.from>=e&&h.to>t&&(i=h)}}return i}function kt(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function L(n,e,t){for(let r of n.facet(pt)){let s=r(n,e,t);if(s)return s}return gt(n,e,t)}function Ce(n,e){let t=e.mapPos(n.from,1),r=e.mapPos(n.to,-1);return t>=r?void 0:{from:t,to:r}}const H=U.define({map:Ce}),M=U.define({map:Ce});function Ae(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(r=>r.from<=t&&r.to>=t)||e.push(n.lineBlockAt(t));return e}const T=Z.define({create(){return g.none},update(n,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,r)=>n=le(n,t,r)),n=n.map(e.changes);for(let t of e.effects)if(t.is(H)&&!bt(n,t.value.from,t.value.to)){let{preparePlaceholder:r}=e.state.facet(Oe),s=r?g.replace({widget:new Tt(r(e.state,t.value))}):he;n=n.update({add:[s.range(t.value.from,t.value.to)]})}else t.is(M)&&(n=n.update({filter:(r,s)=>t.value.from!=r||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(n=le(n,e.selection.main.head)),n},provide:n=>y.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(r,s)=>{t.push(r,s)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let r=n[t++],s=n[t++];if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(he.range(r,s))}return g.set(e,!0)}});function le(n,e,t=e){let r=!1;return n.between(e,t,(s,i)=>{s<t&&i>e&&(r=!0)}),r?n.update({filterFrom:e,filterTo:t,filter:(s,i)=>s>=t||i<=e}):n}function R(n,e,t){var r;let s=null;return(r=n.field(T,!1))===null||r===void 0||r.between(e,t,(i,o)=>{(!s||s.from>i)&&(s={from:i,to:o})}),s}function bt(n,e,t){let r=!1;return n.between(e,e,(s,i)=>{s==e&&i==t&&(r=!0)}),r}function Ie(n,e){return n.field(T,!1)?e:e.concat(U.appendConfig.of(Ne()))}const wt=n=>{for(let e of Ae(n)){let t=L(n.state,e.from,e.to);if(t)return n.dispatch({effects:Ie(n.state,[H.of(t),De(n,t)])}),!0}return!1},yt=n=>{if(!n.state.field(T,!1))return!1;let e=[];for(let t of Ae(n)){let r=R(n.state,t.from,t.to);r&&e.push(M.of(r),De(n,r,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function De(n,e,t=!0){let r=n.state.doc.lineAt(e.from).number,s=n.state.doc.lineAt(e.to).number;return y.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${r} ${n.state.phrase("to")} ${s}.`)}const vt=n=>{let{state:e}=n,t=[];for(let r=0;r<e.doc.length;){let s=n.lineBlockAt(r),i=L(e,s.from,s.to);i&&t.push(H.of(i)),r=(i?n.lineBlockAt(i.to):s).to+1}return t.length&&n.dispatch({effects:Ie(n.state,t)}),!!t.length},St=n=>{let e=n.state.field(T,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(r,s)=>{t.push(M.of({from:r,to:s}))}),n.dispatch({effects:t}),!0},rn=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:wt},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:yt},{key:"Ctrl-Alt-[",run:vt},{key:"Ctrl-Alt-]",run:St}],Pt={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Oe=v.define({combine(n){return ge(n,Pt)}});function Ne(n){return[T,Ct]}function Me(n,e){let{state:t}=n,r=t.facet(Oe),s=o=>{let l=n.lineBlockAt(n.posAtDOM(o.target)),a=R(n.state,l.from,l.to);a&&n.dispatch({effects:M.of(a)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(n,s,e);let i=document.createElement("span");return i.textContent=r.placeholderText,i.setAttribute("aria-label",t.phrase("folded code")),i.title=t.phrase("unfold"),i.className="cm-foldPlaceholder",i.onclick=s,i}const he=g.replace({widget:new class extends ke{toDOM(n){return Me(n,null)}}});class Tt extends ke{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Me(e,this.value)}}const xt={openText:"⌄",closedText:"",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class q extends Xe{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 sn(n={}){let e={...xt,...n},t=new q(e,!0),r=new q(e,!1),s=_.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(S)!=o.state.facet(S)||o.startState.field(T,!1)!=o.state.field(T,!1)||w(o.startState)!=w(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new me;for(let a of o.viewportLineBlocks){let h=R(o.state,a.from,a.to)?r:L(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:i}=e;return[s,Qe({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||Ke.empty},initialSpacer(){return new q(e,!1)},domEventHandlers:{...i,click:(o,l,a)=>{if(i.click&&i.click(o,l,a))return!0;let h=R(o.state,l.from,l.to);if(h)return o.dispatch({effects:M.of(h)}),!0;let u=L(o.state,l.from,l.to);return u?(o.dispatch({effects:H.of(u)}),!0):!1}}}),Ne()]}const Ct=y.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 V{constructor(e,t){this.specs=e;let r;function s(l){let a=ie.newName();return(r||(r=Object.create(null)))["."+a]=l,a}const i=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof m?l=>l.prop(P)==o.data:o?l=>l==o:void 0,this.style=Ze(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:i}).style,this.module=r?new ie(r):null,this.themeType=t.themeType}static define(e,t){return new V(e,t||{})}}const Q=v.define(),Be=v.define({combine(n){return n.length?[n[0]]:null}});function G(n){let e=n.facet(Q);return e.length?e:n.facet(Be)}function on(n,e){let t=[It],r;return n instanceof V&&(n.module&&t.push(y.styleModule.of(n.module)),r=n.themeType),e?.fallback?t.push(Be.of(n)):r?t.push(Q.computeN([y.darkTheme],s=>s.facet(y.darkTheme)==(r=="dark")?[n]:[])):t.push(Q.of(n)),t}class At{constructor(e){this.markCache=Object.create(null),this.tree=w(e.state),this.decorations=this.buildDeco(e,G(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=w(e.state),r=G(e.state),s=r!=G(e.startState),{viewport:i}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<i.to&&!s&&t.type==this.tree.type&&o>=i.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=i.to)}buildDeco(e,t){if(!t||!this.tree.length)return g.none;let r=new me;for(let{from:s,to:i}of e.visibleRanges)_e(this.tree,t,(o,l,a)=>{r.add(o,l,this.markCache[a]||(this.markCache[a]=g.mark({class:a})))},s,i);return r.finish()}}const It=Ge.high(_.fromClass(At,{decorations:n=>n.decorations})),an=V.define([{tag:f.meta,color:"#404740"},{tag:f.link,textDecoration:"underline"},{tag:f.heading,textDecoration:"underline",fontWeight:"bold"},{tag:f.emphasis,fontStyle:"italic"},{tag:f.strong,fontWeight:"bold"},{tag:f.strikethrough,textDecoration:"line-through"},{tag:f.keyword,color:"#708"},{tag:[f.atom,f.bool,f.url,f.contentSeparator,f.labelName],color:"#219"},{tag:[f.literal,f.inserted],color:"#164"},{tag:[f.string,f.deleted],color:"#a11"},{tag:[f.regexp,f.escape,f.special(f.string)],color:"#e40"},{tag:f.definition(f.variableName),color:"#00f"},{tag:f.local(f.variableName),color:"#30a"},{tag:[f.typeName,f.namespace],color:"#085"},{tag:f.className,color:"#167"},{tag:[f.special(f.variableName),f.macroName],color:"#256"},{tag:f.definition(f.propertyName),color:"#00c"},{tag:f.comment,color:"#940"},{tag:f.invalid,color:"#f00"}]),Dt=y.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ee=1e4,Fe="()[]{}",Le=v.define({combine(n){return ge(n,{afterCursor:!0,brackets:Fe,maxScanDistance:Ee,renderMatch:Mt})}}),Ot=g.mark({class:"cm-matchingBracket"}),Nt=g.mark({class:"cm-nonmatchingBracket"});function Mt(n){let e=[],t=n.matched?Ot:Nt;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const Bt=Z.define({create(){return g.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],r=e.state.facet(Le);for(let s of e.state.selection.ranges){if(!s.empty)continue;let i=B(e.state,s.head,-1,r)||s.head>0&&B(e.state,s.head-1,1,r)||r.afterCursor&&(B(e.state,s.head,1,r)||s.head<e.state.doc.length&&B(e.state,s.head+1,-1,r));i&&(t=t.concat(r.renderMatch(i,e.state)))}return g.set(t,!0)},provide:n=>y.decorations.from(n)}),Et=[Bt,Dt];function ln(n={}){return[Le.of(n),Et]}const Ft=new b;function X(n,e,t){let r=n.prop(e<0?b.openedBy:b.closedBy);if(r)return r;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function Y(n){let e=n.type.prop(Ft);return e?e(n.node):n}function B(n,e,t,r={}){let s=r.maxScanDistance||Ee,i=r.brackets||Fe,o=w(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=X(a.type,t,i);if(h&&a.from<a.to){let u=Y(a);if(u&&(t>0?e>=u.from&&e<u.to:e>u.from&&e<=u.to))return Lt(n,e,t,a,u,h,i)}}return Rt(n,e,t,o,l.type,s,i)}function Lt(n,e,t,r,s,i,o){let l=r.parent,a={from:s.from,to:s.to},h=0,u=l?.cursor();if(u&&(t<0?u.childBefore(r.from):u.childAfter(r.to)))do if(t<0?u.to<=r.from:u.from>=r.to){if(h==0&&i.indexOf(u.type.name)>-1&&u.from<u.to){let c=Y(u);return{start:a,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(X(u.type,t,o))h++;else if(X(u.type,-t,o)){if(h==0){let c=Y(u);return{start:a,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}h--}}while(t<0?u.prevSibling():u.nextSibling());return{start:a,matched:!1}}function Rt(n,e,t,r,s,i,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},u=n.doc.iterRange(e,t>0?n.doc.length:0),c=0;for(let k=0;!u.next().done&&k<=i;){let p=u.value;t<0&&(k+=p.length);let x=e+k*t;for(let C=t>0?0:p.length-1,ze=t>0?p.length:-1;C!=ze;C+=t){let $=o.indexOf(p[C]);if(!($<0||r.resolveInner(x+C,1).type!=s))if($%2==0==t>0)c++;else{if(c==1)return{start:h,end:{from:x+C,to:x+C+1},matched:$>>1==a>>1};c--}}t>0&&(k+=p.length)}return u.done?{start:h,matched:!1}:null}function ue(n,e,t,r=0,s=0){e==null&&(e=n.search(/[^\s\u00a0]/),e==-1&&(e=n.length));let i=s;for(let o=r;o<e;o++)n.charCodeAt(o)==9?i+=t-i%t:i++;return i}class Re{constructor(e,t,r,s){this.string=e,this.tabSize=t,this.indentUnit=r,this.overrideIndent=s,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}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=this.string.charAt(this.pos),r;if(typeof e=="string"?r=t==e:r=t&&(e instanceof RegExp?e.test(t):e(t)),r)return++this.pos,t}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=ue(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:ue(this.string,null,this.tabSize)}match(e,t,r){if(typeof e=="string"){let s=o=>r?o.toLowerCase():o,i=this.string.substr(this.pos,e.length);return s(i)==s(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let s=this.string.slice(this.pos).match(e);return s&&s.index>0?null:(s&&t!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}}function Wt(n){return{name:n.name||"",token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||Ut,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||ne,mergeTokens:n.mergeTokens!==!1}}function Ut(n){if(typeof n!="object")return n;let e={};for(let t in n){let r=n[t];e[t]=r instanceof Array?r.slice():r}return e}const fe=new WeakMap;class We extends m{constructor(e){let t=be(e.languageData),r=Wt(e),s,i=new class extends pe{createParse(o,l,a){return new Vt(s,o,l,a)}};super(t,i,[],e.name),this.topNode=zt(t,this),s=this,this.streamParser=r,this.stateAfter=new b({perNode:!0}),this.tokenTable=e.tokenTable?new $e(r.tokenTable):jt}static define(e){return new We(e)}getIndent(e){let t,{overrideIndentation:r}=e.options;r&&(t=fe.get(e.state),t!=null&&t<e.pos-1e4&&(t=void 0));let s=te(this,e.node.tree,e.node.from,e.node.from,t??e.pos),i,o;if(s?(o=s.state,i=s.pos+1):(o=this.streamParser.startState(e.unit),i=e.node.from),e.pos-i>1e4)return null;for(;i<e.pos;){let a=e.state.doc.lineAt(i),h=Math.min(e.pos,a.to);if(a.length){let u=r?r(a.from):-1,c=new Re(a.text,e.state.tabSize,e.unit,u<0?void 0:u);for(;c.pos<h-a.from;)He(this.streamParser.token,c,o)}else this.streamParser.blankLine(o,e.unit);if(h==e.pos)break;i=a.to+1}let l=e.lineAt(e.pos);return r&&t==null&&fe.set(e.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],e)}get allowsNesting(){return!1}}function te(n,e,t,r,s){let i=t>=r&&t+e.length<=s&&e.prop(n.stateAfter);if(i)return{state:n.streamParser.copyState(i),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof d&&a<s&&te(n,l,a,r,s);if(h)return h}return null}function Ue(n,e,t,r,s){if(s&&t<=0&&r>=e.length)return e;!s&&t==0&&e.type==n.topNode&&(s=!0);for(let i=e.children.length-1;i>=0;i--){let o=e.positions[i],l=e.children[i],a;if(o<r&&l instanceof d){if(!(a=Ue(n,l,t-o,r-o,s)))break;return s?new d(e.type,e.children.slice(0,i).concat(a),e.positions.slice(0,i+1),o+a.length):a}}return null}function Ht(n,e,t,r,s){for(let i of e){let o=i.from+(i.openStart?25:0),l=i.to-(i.openEnd?25:0),a=o<=t&&l>t&&te(n,i.tree,0-i.offset,t,l),h;if(a&&a.pos<=r&&(h=Ue(n,i.tree,t+i.offset,a.pos+i.offset,!1)))return{state:a.state,tree:h}}return{state:n.streamParser.startState(s?F(s):4),tree:d.empty}}class Vt{constructor(e,t,r,s){this.lang=e,this.input=t,this.fragments=r,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let i=A.get(),o=s[0].from,{state:l,tree:a}=Ht(e,r,o,this.to,i?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);i&&this.parsedPos<i.viewport.from-1e5&&s.some(h=>h.from<=i.viewport.from&&h.to>=i.viewport.from)&&(this.state=this.lang.streamParser.startState(F(i.state)),i.skipUntilInView(this.parsedPos,i.viewport.from),this.parsedPos=i.viewport.from),this.moveRangeIndex()}advance(){let e=A.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),r=Math.min(t,this.chunkStart+512);for(e&&(r=Math.min(r,e.viewport.to));this.parsedPos<r;)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)t==`
`&&(t="");else{let r=t.indexOf(`
`);r>-1&&(t=t.slice(0,r))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),r=e+t.length;for(let s=this.rangeIndex;;){let i=this.ranges[s].to;if(i>=r||(t=t.slice(0,i-(r-t.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);t+=l,r=o+l.length}return{line:t,end:r}}skipGapsTo(e,t,r){for(;;){let s=this.ranges[this.rangeIndex].to,i=e+t;if(r>0?s>i:s>=i)break;let o=this.ranges[++this.rangeIndex].from;t+=o-s}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,r,s){let i=4;if(this.ranges.length>1){s=this.skipGapsTo(t,s,1),t+=s;let l=this.chunk.length;s=this.skipGapsTo(r,s,-1),r+=s,i+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&i==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==t?this.chunk[o+2]=r:this.chunk.push(e,t,r,i),s}parseLine(e){let{line:t,end:r}=this.nextLine(),s=0,{streamParser:i}=this.lang,o=new Re(t,e?e.state.tabSize:4,e?F(e.state):2);if(o.eol())i.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=He(i.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=d.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:$t,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new d(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 d(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function He(n,e,t){e.start=e.pos;for(let r=0;r<10;r++){let s=n(e,t);if(e.pos>e.start)return s}throw new Error("Stream parser failed to advance stream.")}const ne=Object.create(null),N=[W.none],$t=new qe(N),ce=[],de=Object.create(null),Ve=Object.create(null);for(let[n,e]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"]])Ve[n]=je(ne,e);class $e{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),Ve)}resolve(e){return e?this.table[e]||(this.table[e]=je(this.extra,e)):0}}const jt=new $e(ne);function J(n,e){ce.indexOf(n)>-1||(ce.push(n),console.warn(e))}function je(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let u=n[h]||f[h];u?typeof u=="function"?a.length?a=a.map(u):J(h,`Modifier ${h} used at start of tag`):a.length?J(h,`Tag ${h} used as modifier`):a=Array.isArray(u)?u:[u]:J(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),s=r+" "+t.map(l=>l.id),i=de[s];if(i)return i.id;let o=de[s]=W.define({id:N.length,name:r,props:[et({[r]:t})]});return N.push(o),o.id}function zt(n,e){let t=W.define({id:N.length,name:"Document",props:[P.add(()=>n),Pe.add(()=>r=>e.getIndent(r))],top:!0});return N.push(t),t}se.RTL,se.LTR;export{V as H,Se as I,K as L,A as P,We as S,it as a,F as b,Yt as c,Pe as d,en as e,mt as f,ot as g,Zt as h,ve as i,_t as j,nn as k,Ft as l,B as m,tt as n,be as o,m as p,pt as q,P as r,w as s,ye as t,on as u,sn as v,tn as w,ln as x,an as y,rn as z};