838eec30a8
- 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.
2 lines
27 KiB
JavaScript
2 lines
27 KiB
JavaScript
const Oe=1024;let ke=0;class M{constructor(e,t){this.from=e,this.to=t}}class A{constructor(e={}){this.id=ke++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=j.match(e)),t=>{let r=e(t);return r===void 0?null:[this,r]}}}A.closedBy=new A({deserialize:l=>l.split(" ")});A.openedBy=new A({deserialize:l=>l.split(" ")});A.group=new A({deserialize:l=>l.split(" ")});A.isolate=new A({deserialize:l=>{if(l&&l!="rtl"&&l!="ltr"&&l!="auto")throw new RangeError("Invalid value for isolate: "+l);return l||"auto"}});A.contextHash=new A({perNode:!0});A.lookAhead=new A({perNode:!0});A.mounted=new A({perNode:!0});class ${constructor(e,t,r,n=!1){this.tree=e,this.overlay=t,this.parser=r,this.bracketed=n}static get(e){return e&&e.props&&e.props[A.mounted.id]}}const Ce=Object.create(null);class j{constructor(e,t,r,n=0){this.name=e,this.props=t,this.id=r,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):Ce,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new j(e.name||"",t,e.id,r);if(e.props){for(let i of e.props)if(Array.isArray(i)||(i=i(n)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[i[0].id]=i[1]}}return n}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(A.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let n of r.split(" "))t[n]=e[r];return r=>{for(let n=r.prop(A.group),i=-1;i<(n?n.length:0);i++){let s=t[i<0?r.name:n[i]];if(s)return s}}}}j.none=new j("",Object.create(null),0,8);class ye{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let r of this.types){let n=null;for(let i of e){let s=i(r);if(s){n||(n=Object.assign({},r.props));let f=s[1],h=s[0];h.combine&&h.id in n&&(f=h.combine(n[h.id],f)),n[h.id]=f}}t.push(n?new j(r.name,n,r.id,r.flags):r)}return new ye(t)}}const Z=new WeakMap,oe=new WeakMap;var w;(function(l){l[l.ExcludeBuffers=1]="ExcludeBuffers",l[l.IncludeAnonymous=2]="IncludeAnonymous",l[l.IgnoreMounts=4]="IgnoreMounts",l[l.IgnoreOverlays=8]="IgnoreOverlays",l[l.EnterBracketed=16]="EnterBracketed"})(w||(w={}));class z{constructor(e,t,r,n,i){if(this.type=e,this.children=t,this.positions=r,this.length=n,this.props=null,i&&i.length){this.props=Object.create(null);for(let[s,f]of i)this.props[typeof s=="number"?s:s.id]=f}}toString(){let e=$.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let r of this.children){let n=r.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new te(this.topNode,e)}cursorAt(e,t=0,r=0){let n=Z.get(this)||this.topNode,i=new te(n);return i.moveTo(e,t),Z.set(this,i._tree),i}get topNode(){return new I(this,0,0,null)}resolve(e,t=0){let r=K(Z.get(this)||this.topNode,e,t,!1);return Z.set(this,r),r}resolveInner(e,t=0){let r=K(oe.get(this)||this.topNode,e,t,!0);return oe.set(this,r),r}resolveStack(e,t=0){return _e(this,e,t)}iterate(e){let{enter:t,leave:r,from:n=0,to:i=this.length}=e,s=e.mode||0,f=(s&w.IncludeAnonymous)>0;for(let h=this.cursor(s|w.IncludeAnonymous);;){let o=!1;if(h.from<=i&&h.to>=n&&(!f&&h.type.isAnonymous||t(h)!==!1)){if(h.firstChild())continue;o=!0}for(;o&&r&&(f||!h.type.isAnonymous)&&r(h),!h.nextSibling();){if(!h.parent())return;o=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:le(j.none,this.children,this.positions,0,this.children.length,0,this.length,(t,r,n)=>new z(this.type,t,r,n,this.propValues),e.makeTree||((t,r,n)=>new z(j.none,t,r,n)))}static build(e){return Be(e)}}z.empty=new z(j.none,[],[],0);class ie{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new ie(this.buffer,this.index)}}class H{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return j.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],r=this.buffer[e+3],n=this.set.types[t],i=n.name;if(/\W/.test(i)&&!n.isError&&(i=JSON.stringify(i)),e+=4,r==e)return i;let s=[];for(;e<r;)s.push(this.childString(e)),e=this.buffer[e+3];return i+"("+s.join(",")+")"}findChild(e,t,r,n,i){let{buffer:s}=this,f=-1;for(let h=e;h!=t&&!(xe(i,n,s[h+1],s[h+2])&&(f=h,r>0));h=s[h+3]);return f}slice(e,t,r){let n=this.buffer,i=new Uint16Array(t-e),s=0;for(let f=e,h=0;f<t;){i[h++]=n[f++],i[h++]=n[f++]-r;let o=i[h++]=n[f++]-r;i[h++]=n[f++]-e,s=Math.max(s,o)}return new H(i,s,this.set)}}function xe(l,e,t,r){switch(l){case-2:return t<e;case-1:return r>=e&&t<e;case 0:return t<e&&r>e;case 1:return t<=e&&r>e;case 2:return r>e;case 4:return!0}}function K(l,e,t,r){for(var n;l.from==l.to||(t<1?l.from>=e:l.from>e)||(t>-1?l.to<=e:l.to<e);){let s=!r&&l instanceof I&&l.index<0?null:l.parent;if(!s)return l;l=s}let i=r?0:w.IgnoreOverlays;if(r)for(let s=l,f=s.parent;f;s=f,f=s.parent)s instanceof I&&s.index<0&&((n=f.enter(e,t,i))===null||n===void 0?void 0:n.from)!=s.from&&(l=f);for(;;){let s=l.enter(e,t,i);if(!s)return l;l=s}}class we{cursor(e=0){return new te(this,e)}getChild(e,t=null,r=null){let n=ue(this,e,t,r);return n.length?n[0]:null}getChildren(e,t=null,r=null){return ue(this,e,t,r)}resolve(e,t=0){return K(this,e,t,!1)}resolveInner(e,t=0){return K(this,e,t,!0)}matchContext(e){return re(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),r=this;for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(r=t,t=n.prevSibling):t=n}return r}get node(){return this}get next(){return this.parent}}class I extends we{constructor(e,t,r,n){super(),this._tree=e,this.from=t,this.index=r,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,r,n,i=0){var s;for(let f=this;;){for(let{children:h,positions:o}=f._tree,u=t>0?h.length:-1;e!=u;e+=t){let p=h[e],c=o[e]+f.from;if(!(!(i&w.EnterBracketed&&p instanceof z&&((s=$.get(p))===null||s===void 0?void 0:s.overlay)===null&&(c>=r||c+p.length<=r))&&!xe(n,r,c,c+p.length))){if(p instanceof H){if(i&w.ExcludeBuffers)continue;let m=p.findChild(0,p.buffer.length,t,r-c,n);if(m>-1)return new D(new Ae(f,p,e,c),null,m)}else if(i&w.IncludeAnonymous||!p.type.isAnonymous||se(p)){let m;if(!(i&w.IgnoreMounts)&&(m=$.get(p))&&!m.overlay)return new I(m.tree,c,e,f);let x=new I(p,c,e,f);return i&w.IncludeAnonymous||!x.type.isAnonymous?x:x.nextChild(t<0?p.children.length-1:0,t,r,n,i)}}}if(i&w.IncludeAnonymous||!f.type.isAnonymous||(f.index>=0?e=f.index+t:e=t<0?-1:f._parent._tree.children.length,f=f._parent,!f))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,r=0){let n;if(!(r&w.IgnoreOverlays)&&(n=$.get(this._tree))&&n.overlay){let i=e-this.from,s=r&w.EnterBracketed&&n.bracketed;for(let{from:f,to:h}of n.overlay)if((t>0||s?f<=i:f<i)&&(t<0||s?h>=i:h>i))return new I(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function ue(l,e,t,r){let n=l.cursor(),i=[];if(!n.firstChild())return i;if(t!=null){for(let s=!1;!s;)if(s=n.type.is(t),!n.nextSibling())return i}for(;;){if(r!=null&&n.type.is(r))return i;if(n.type.is(e)&&i.push(n.node),!n.nextSibling())return r==null?i:[]}}function re(l,e,t=e.length-1){for(let r=l;t>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[t]&&e[t]!=r.name)return!1;t--}}return!0}class Ae{constructor(e,t,r,n){this.parent=e,this.buffer=t,this.index=r,this.start=n}}class D extends we{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,r){super(),this.context=e,this._parent=t,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,t,r){let{buffer:n}=this.context,i=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,r);return i<0?null:new D(this.context,this,i)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,r=0){if(r&w.ExcludeBuffers)return null;let{buffer:n}=this.context,i=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return i<0?null:new D(this.context,this,i)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new D(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new D(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,n=this.index+4,i=r.buffer[this.index+3];if(i>n){let s=r.buffer[this.index+1];e.push(r.slice(n,i,s)),t.push(0)}return new z(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function ve(l){if(!l.length)return null;let e=0,t=l[0];for(let i=1;i<l.length;i++){let s=l[i];(s.from>t.from||s.to<t.to)&&(t=s,e=i)}let r=t instanceof I&&t.index<0?null:t.parent,n=l.slice();return r?n[e]=r:n.splice(e,1),new Se(n,t)}class Se{constructor(e,t){this.heads=e,this.node=t}get next(){return ve(this.heads)}}function _e(l,e,t){let r=l.resolveInner(e,t),n=null;for(let i=r instanceof I?r:r.context.parent;i;i=i.parent)if(i.index<0){let s=i.parent;(n||(n=[r])).push(s.resolve(e,t)),i=s}else{let s=$.get(i.tree);if(s&&s.overlay&&s.overlay[0].from<=e&&s.overlay[s.overlay.length-1].to>=e){let f=new I(s.tree,s.overlay[0].from+i.from,-1,i);(n||(n=[r])).push(K(f,e,t,!1))}}return n?ve(n):r}class te{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~w.EnterBracketed,e instanceof I)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:r,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=r+n.buffer[e+1],this.to=r+n.buffer[e+2],!0}yield(e){return e?e instanceof I?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,r,this.mode));let{buffer:n}=this.buffer,i=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,r);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,r=this.mode){return this.buffer?r&w.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&w.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&w.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,r=this.stack.length-1;if(e<0){let n=r<0?0:this.stack[r]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(n)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,r,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let i=0;i<this.index;i++)if(n.buffer.buffer[i+3]<this.index)return!1;({index:t,parent:r}=n)}else({index:t,_parent:r}=this._tree);for(;r;{index:t,_parent:r}=r)if(t>-1)for(let i=t+e,s=e<0?-1:r._tree.children.length;i!=s;i+=e){let f=r._tree.children[i];if(this.mode&w.IncludeAnonymous||f instanceof H||!f.type.isAnonymous||se(f))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,r=0;if(e&&e.context==this.buffer)e:for(let n=this.index,i=this.stack.length;i>=0;){for(let s=e;s;s=s._parent)if(s.index==n){if(n==this.index)return s;t=s,r=i+1;break e}n=this.stack[--i]}for(let n=r;n<this.stack.length;n++)t=new D(this.buffer,t,this.stack[n]);return this.bufferNode=new D(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let n=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,n=!0}}}matchContext(e){if(!this.buffer)return re(this.node.parent,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let n=e.length-1,i=this.stack.length-1;n>=0;i--){if(i<0)return re(this._tree,e,n);let s=r[t.buffer[this.stack[i]]];if(!s.isAnonymous){if(e[n]&&e[n]!=s.name)return!1;n--}}return!0}}function se(l){return l.children.some(e=>e instanceof H||!e.type.isAnonymous||se(e))}function Be(l){var e;let{buffer:t,nodeSet:r,maxBufferLength:n=1024,reused:i=[],minRepeatType:s=r.types.length}=l,f=Array.isArray(t)?new ie(t,t.length):t,h=r.types,o=0,u=0;function p(b,k,a,S,y,_){let{id:g,start:d,end:v,size:C}=f,N=u,U=o;if(C<0)if(f.next(),C==-1){let W=i[g];a.push(W),S.push(d-b);return}else if(C==-3){o=g;return}else if(C==-4){u=g;return}else throw new RangeError(`Unrecognized record size: ${C}`);let q=h[g],X,J,fe=d-b;if(v-d<=n&&(J=O(f.pos-k,y))){let W=new Uint16Array(J.size-J.skip),T=f.pos-J.size,R=W.length;for(;f.pos>T;)R=F(J.start,W,R);X=new H(W,v-J.start,r),fe=J.start-b}else{let W=f.pos-C;f.next();let T=[],R=[],V=g>=s?g:-1,G=0,Y=v;for(;f.pos>W;)V>=0&&f.id==V&&f.size>=0?(f.end<=Y-n&&(x(T,R,d,G,f.end,Y,V,N,U),G=T.length,Y=f.end),f.next()):_>2500?c(d,W,T,R):p(d,W,T,R,V,_+1);if(V>=0&&G>0&&G<T.length&&x(T,R,d,G,d,Y,V,N,U),T.reverse(),R.reverse(),V>-1&&G>0){let he=m(q,U);X=le(q,T,R,0,T.length,0,v-d,he,he)}else X=P(q,T,R,v-d,N-v,U)}a.push(X),S.push(fe)}function c(b,k,a,S){let y=[],_=0,g=-1;for(;f.pos>k;){let{id:d,start:v,end:C,size:N}=f;if(N>4)f.next();else{if(g>-1&&v<g)break;g<0&&(g=C-n),y.push(d,v,C),_++,f.next()}}if(_){let d=new Uint16Array(_*4),v=y[y.length-2];for(let C=y.length-3,N=0;C>=0;C-=3)d[N++]=y[C],d[N++]=y[C+1]-v,d[N++]=y[C+2]-v,d[N++]=N;a.push(new H(d,y[2]-v,r)),S.push(v-b)}}function m(b,k){return(a,S,y)=>{let _=0,g=a.length-1,d,v;if(g>=0&&(d=a[g])instanceof z){if(!g&&d.type==b&&d.length==y)return d;(v=d.prop(A.lookAhead))&&(_=S[g]+d.length+v)}return P(b,a,S,y,_,k)}}function x(b,k,a,S,y,_,g,d,v){let C=[],N=[];for(;b.length>S;)C.push(b.pop()),N.push(k.pop()+a-y);b.push(P(r.types[g],C,N,_-y,d-_,v)),k.push(y-a)}function P(b,k,a,S,y,_,g){if(_){let d=[A.contextHash,_];g=g?[d].concat(g):[d]}if(y>25){let d=[A.lookAhead,y];g=g?[d].concat(g):[d]}return new z(b,k,a,S,g)}function O(b,k){let a=f.fork(),S=0,y=0,_=0,g=a.end-n,d={size:0,start:0,skip:0};e:for(let v=a.pos-b;a.pos>v;){let C=a.size;if(a.id==k&&C>=0){d.size=S,d.start=y,d.skip=_,_+=4,S+=4,a.next();continue}let N=a.pos-C;if(C<0||N<v||a.start<g)break;let U=a.id>=s?4:0,q=a.start;for(a.next();a.pos>N;){if(a.size<0)if(a.size==-3||a.size==-4)U+=4;else break e;else a.id>=s&&(U+=4);a.next()}y=q,S+=C,_+=U}return(k<0||S==b)&&(d.size=S,d.start=y,d.skip=_),d.size>4?d:void 0}function F(b,k,a){let{id:S,start:y,end:_,size:g}=f;if(f.next(),g>=0&&S<s){let d=a;if(g>4){let v=f.pos-(g-4);for(;f.pos>v;)a=F(b,k,a)}k[--a]=d,k[--a]=_-b,k[--a]=y-b,k[--a]=S}else g==-3?o=S:g==-4&&(u=S);return a}let E=[],B=[];for(;f.pos>0;)p(l.start||0,l.bufferStart||0,E,B,-1,0);let L=(e=l.length)!==null&&e!==void 0?e:E.length?B[0]+E[0].length:0;return new z(h[l.topID],E.reverse(),B.reverse(),L)}const ae=new WeakMap;function ee(l,e){if(!l.isAnonymous||e instanceof H||e.type!=l)return 1;let t=ae.get(e);if(t==null){t=1;for(let r of e.children){if(r.type!=l||!(r instanceof z)){t=1;break}t+=ee(l,r)}ae.set(e,t)}return t}function le(l,e,t,r,n,i,s,f,h){let o=0;for(let x=r;x<n;x++)o+=ee(l,e[x]);let u=Math.ceil(o*1.5/8),p=[],c=[];function m(x,P,O,F,E){for(let B=O;B<F;){let L=B,b=P[B],k=ee(l,x[B]);for(B++;B<F;B++){let a=ee(l,x[B]);if(k+a>=u)break;k+=a}if(B==L+1){if(k>u){let a=x[L];m(a.children,a.positions,0,a.children.length,P[L]+E);continue}p.push(x[L])}else{let a=P[B-1]+x[B-1].length-b;p.push(le(l,x,P,L,B,b,a,null,h))}c.push(b+E-i)}}return m(e,t,r,n,0),(f||h)(p,c,s)}class Fe{constructor(){this.map=new WeakMap}setBuffer(e,t,r){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,r)}getBuffer(e,t){let r=this.map.get(e);return r&&r.get(t)}set(e,t){e instanceof D?this.setBuffer(e.context.buffer,e.index,t):e instanceof I&&this.map.set(e.tree,t)}get(e){return e instanceof D?this.getBuffer(e.context.buffer,e.index):e instanceof I?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Q{constructor(e,t,r,n,i=!1,s=!1){this.from=e,this.to=t,this.tree=r,this.offset=n,this.open=(i?1:0)|(s?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],r=!1){let n=[new Q(0,e.length,e,0,!1,r)];for(let i of t)i.to>e.length&&n.push(i);return n}static applyChanges(e,t,r=128){if(!t.length)return e;let n=[],i=1,s=e.length?e[0]:null;for(let f=0,h=0,o=0;;f++){let u=f<t.length?t[f]:null,p=u?u.fromA:1e9;if(p-h>=r)for(;s&&s.from<p;){let c=s;if(h>=c.from||p<=c.to||o){let m=Math.max(c.from,h)-o,x=Math.min(c.to,p)-o;c=m>=x?null:new Q(m,x,c.tree,c.offset+o,f>0,!!u)}if(c&&n.push(c),s.to>p)break;s=i<e.length?e[i++]:null}if(!u)break;h=u.toA,o=u.toA-u.toB}return n}}class je{startParse(e,t,r){return typeof e=="string"&&(e=new Ne(e)),r=r?r.length?r.map(n=>new M(n.from,n.to)):[new M(0,0)]:[new M(0,e.length)],this.createParse(e,t||[],r)}parse(e,t,r){let n=this.startParse(e,t,r);for(;;){let i=n.advance();if(i)return i}}}class Ne{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function Re(l){return(e,t,r,n)=>new Ie(e,l,t,r,n)}class pe{constructor(e,t,r,n,i,s){this.parser=e,this.parse=t,this.overlay=r,this.bracketed=n,this.target=i,this.from=s}}function de(l){if(!l.length||l.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(l))}class Pe{constructor(e,t,r,n,i,s,f,h){this.parser=e,this.predicate=t,this.mounts=r,this.index=n,this.start=i,this.bracketed=s,this.target=f,this.prev=h,this.depth=0,this.ranges=[]}}const ne=new A({perNode:!0});class Ie{constructor(e,t,r,n,i){this.nest=t,this.input=r,this.fragments=n,this.ranges=i,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let r=this.baseParse.advance();if(!r)return null;if(this.baseParse=null,this.baseTree=r,this.startInner(),this.stoppedAt!=null)for(let n of this.inner)n.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let r=this.baseTree;return this.stoppedAt!=null&&(r=new z(r.type,r.children,r.positions,r.length,r.propValues.concat([[ne,this.stoppedAt]]))),r}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let r=Object.assign(Object.create(null),e.target.props);r[A.mounted.id]=new $(t,e.overlay,e.parser,e.bracketed),e.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Te(this.fragments),t=null,r=null,n=new te(new I(this.baseTree,this.ranges[0].from,0,null),w.IncludeAnonymous|w.IgnoreMounts);e:for(let i,s;;){let f=!0,h;if(this.stoppedAt!=null&&n.from>=this.stoppedAt)f=!1;else if(e.hasNode(n)){if(t){let o=t.mounts.find(u=>u.frag.from<=n.from&&u.frag.to>=n.to&&u.mount.overlay);if(o)for(let u of o.mount.overlay){let p=u.from+o.pos,c=u.to+o.pos;p>=n.from&&c<=n.to&&!t.ranges.some(m=>m.from<c&&m.to>p)&&t.ranges.push({from:p,to:c})}}f=!1}else if(r&&(s=ze(r.ranges,n.from,n.to)))f=s!=2;else if(!n.type.isAnonymous&&(i=this.nest(n,this.input))&&(n.from<n.to||!i.overlay)){n.tree||(Ee(n),t&&t.depth++,r&&r.depth++);let o=e.findMounts(n.from,i.parser);if(typeof i.overlay=="function")t=new Pe(i.parser,i.overlay,o,this.inner.length,n.from,!!i.bracketed,n.tree,t);else{let u=me(this.ranges,i.overlay||(n.from<n.to?[new M(n.from,n.to)]:[]));u.length&&de(u),(u.length||!i.overlay)&&this.inner.push(new pe(i.parser,u.length?i.parser.startParse(this.input,be(o,u),u):i.parser.startParse(""),i.overlay?i.overlay.map(p=>new M(p.from-n.from,p.to-n.from)):null,!!i.bracketed,n.tree,u.length?u[0].from:n.from)),i.overlay?u.length&&(r={ranges:u,depth:0,prev:r}):f=!1}}else if(t&&(h=t.predicate(n))&&(h===!0&&(h=new M(n.from,n.to)),h.from<h.to)){let o=t.ranges.length-1;o>=0&&t.ranges[o].to==h.from?t.ranges[o]={from:t.ranges[o].from,to:h.to}:t.ranges.push(h)}if(f&&n.firstChild())t&&t.depth++,r&&r.depth++;else for(;!n.nextSibling();){if(!n.parent())break e;if(t&&!--t.depth){let o=me(this.ranges,t.ranges);o.length&&(de(o),this.inner.splice(t.index,0,new pe(t.parser,t.parser.startParse(this.input,be(t.mounts,o),o),t.ranges.map(u=>new M(u.from-t.start,u.to-t.start)),t.bracketed,t.target,o[0].from))),t=t.prev}r&&!--r.depth&&(r=r.prev)}}}}function ze(l,e,t){for(let r of l){if(r.from>=t)break;if(r.to>e)return r.from<=e&&r.to>=t?2:1}return 0}function ce(l,e,t,r,n,i){if(e<t){let s=l.buffer[e+1];r.push(l.slice(e,t,s)),n.push(s-i)}}function Ee(l){let{node:e}=l,t=[],r=e.context.buffer;do t.push(l.index),l.parent();while(!l.tree);let n=l.tree,i=n.children.indexOf(r),s=n.children[i],f=s.buffer,h=[i];function o(u,p,c,m,x,P){let O=t[P],F=[],E=[];ce(s,u,O,F,E,m);let B=f[O+1],L=f[O+2];h.push(F.length);let b=P?o(O+4,f[O+3],s.set.types[f[O]],B,L-B,P-1):e.toTree();return F.push(b),E.push(B-m),ce(s,f[O+3],p,F,E,m),new z(c,F,E,x)}n.children[i]=o(0,f.length,j.none,0,s.length,t.length-1);for(let u of h){let p=l.tree.children[u],c=l.tree.positions[u];l.yield(new I(p,c+l.from,u,l._tree))}}class ge{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(w.IncludeAnonymous|w.IgnoreMounts)}moveTo(e){let{cursor:t}=this,r=e-this.offset;for(;!this.done&&t.from<r;)t.to>=e&&t.enter(r,1,w.IgnoreOverlays|w.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof z)t=t.children[0];else break}return!1}}class Te{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let r=this.curFrag=e[0];this.curTo=(t=r.tree.prop(ne))!==null&&t!==void 0?t:r.to,this.inner=new ge(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(ne))!==null&&e!==void 0?e:t.to,this.inner=new ge(t.tree,-t.offset)}}findMounts(e,t){var r;let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let i=this.inner.cursor.node;i;i=i.parent){let s=(r=i.tree)===null||r===void 0?void 0:r.prop(A.mounted);if(s&&s.parser==t)for(let f=this.fragI;f<this.fragments.length;f++){let h=this.fragments[f];if(h.from>=i.to)break;h.tree==this.curFrag.tree&&n.push({frag:h,pos:i.from-h.offset,mount:s})}}}return n}}function me(l,e){let t=null,r=e;for(let n=1,i=0;n<l.length;n++){let s=l[n-1].to,f=l[n].from;for(;i<r.length;i++){let h=r[i];if(h.from>=f)break;h.to<=s||(t||(r=t=e.slice()),h.from<s?(t[i]=new M(h.from,s),h.to>f&&t.splice(i+1,0,new M(f,h.to))):h.to>f?t[i--]=new M(f,h.to):t.splice(i--,1))}}return r}function Me(l,e,t,r){let n=0,i=0,s=!1,f=!1,h=-1e9,o=[];for(;;){let u=n==l.length?1e9:s?l[n].to:l[n].from,p=i==e.length?1e9:f?e[i].to:e[i].from;if(s!=f){let c=Math.max(h,t),m=Math.min(u,p,r);c<m&&o.push(new M(c,m))}if(h=Math.min(u,p),h==1e9)break;u==h&&(s?(s=!1,n++):s=!0),p==h&&(f?(f=!1,i++):f=!0)}return o}function be(l,e){let t=[];for(let{pos:r,mount:n,frag:i}of l){let s=r+(n.overlay?n.overlay[0].from:0),f=s+n.tree.length,h=Math.max(i.from,s),o=Math.min(i.to,f);if(n.overlay){let u=n.overlay.map(c=>new M(c.from+r,c.to+r)),p=Me(e,u,h,o);for(let c=0,m=h;;c++){let x=c==p.length,P=x?o:p[c].from;if(P>m&&t.push(new Q(m,P,n.tree,-s,i.from>=m||i.openStart,i.to<=P||i.openEnd)),x)break;m=p[c].to}}else t.push(new Q(h,o,n.tree,-s,i.from>=s||i.openStart,i.to<=f||i.openEnd))}return t}export{Oe as D,w as I,A as N,je as P,z as T,Fe as a,j as b,ye as c,Q as d,Re as p};
|