@vuu-ui/vuu-data-local 0.8.22 → 0.8.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +3 -3
- package/esm/index.js +1 -1
- package/esm/index.js.map +3 -3
- package/package.json +6 -6
- package/types/array-data-source/array-data-source.d.ts +1 -1
package/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var ge=(o,t,e)=>{if(!t.has(o))throw TypeError("Cannot "+e)};var u=(o,t,e)=>(ge(o,t,"read from private field"),e?e.call(o):t.get(o)),C=(o,t,e)=>{if(t.has(o))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(o):t.set(o,e)},g=(o,t,e,s)=>(ge(o,t,"write to private field"),s?s.call(o,e):t.set(o,e),e);var _t=(o,t,e,s)=>({set _(r){g(o,t,r,e)},get _(){return u(o,t,s)}});var Ze=0,yt=class{constructor(t,e){this.from=t,this.to=e}},x=class{constructor(t={}){this.id=Ze++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=E.match(t)),e=>{let s=t(e);return s===void 0?null:[this,s]}}};x.closedBy=new x({deserialize:o=>o.split(" ")});x.openedBy=new x({deserialize:o=>o.split(" ")});x.group=new x({deserialize:o=>o.split(" ")});x.contextHash=new x({perNode:!0});x.lookAhead=new x({perNode:!0});x.mounted=new x({perNode:!0});var qe=Object.create(null),E=class o{constructor(t,e,s,r=0){this.name=t,this.props=e,this.id=s,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):qe,s=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),r=new o(t.name||"",e,t.id,s);if(t.props){for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}}return r}prop(t){return this.props[t.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(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(x.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let s in t)for(let r of s.split(" "))e[r]=t[s];return s=>{for(let r=s.prop(x.group),n=-1;n<(r?r.length:0);n++){let i=e[n<0?s.name:r[n]];if(i)return i}}}};E.none=new E("",Object.create(null),0,8);var At=class o{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let s of this.types){let r=null;for(let n of t){let i=n(s);i&&(r||(r=Object.assign({},s.props)),r[i[0].id]=i[1])}e.push(r?new E(s.name,r,s.id,s.flags):s)}return new o(e)}},vt=new WeakMap,me=new WeakMap,A;(function(o){o[o.ExcludeBuffers=1]="ExcludeBuffers",o[o.IncludeAnonymous=2]="IncludeAnonymous",o[o.IgnoreMounts=4]="IgnoreMounts",o[o.IgnoreOverlays=8]="IgnoreOverlays"})(A||(A={}));var V=class o{constructor(t,e,s,r,n){if(this.type=t,this.children=e,this.positions=s,this.length=r,this.props=null,n&&n.length){this.props=Object.create(null);for(let[i,l]of n)this.props[typeof i=="number"?i:i.id]=l}}toString(){let t=this.prop(x.mounted);if(t&&!t.overlay)return t.tree.toString();let e="";for(let s of this.children){let r=s.toString();r&&(e&&(e+=","),e+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new pt(this.topNode,t)}cursorAt(t,e=0,s=0){let r=vt.get(this)||this.topNode,n=new pt(r);return n.moveTo(t,e),vt.set(this,n._tree),n}get topNode(){return new nt(this,0,0,null)}resolve(t,e=0){let s=ct(vt.get(this)||this.topNode,t,e,!1);return vt.set(this,s),s}resolveInner(t,e=0){let s=ct(me.get(this)||this.topNode,t,e,!0);return me.set(this,s),s}iterate(t){let{enter:e,leave:s,from:r=0,to:n=this.length}=t,i=t.mode||0,l=(i&A.IncludeAnonymous)>0;for(let h=this.cursor(i|A.IncludeAnonymous);;){let a=!1;if(h.from<=n&&h.to>=r&&(!l&&h.type.isAnonymous||e(h)!==!1)){if(h.firstChild())continue;a=!0}for(;a&&s&&(l||!h.type.isAnonymous)&&s(h),!h.nextSibling();){if(!h.parent())return;a=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Xt(E.none,this.children,this.positions,0,this.children.length,0,this.length,(e,s,r)=>new o(this.type,e,s,r,this.propValues),t.makeTree||((e,s,r)=>new o(E.none,e,s,r)))}static build(t){return He(t)}};V.empty=new V(E.none,[],[],0);var $t=class o{constructor(t,e){this.buffer=t,this.index=e}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 o(this.buffer,this.index)}},it=class o{constructor(t,e,s){this.buffer=t,this.length=e,this.set=s}get type(){return E.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],s=this.buffer[t+3],r=this.set.types[e],n=r.name;if(/\W/.test(n)&&!r.isError&&(n=JSON.stringify(n)),t+=4,s==t)return n;let i=[];for(;t<s;)i.push(this.childString(t)),t=this.buffer[t+3];return n+"("+i.join(",")+")"}findChild(t,e,s,r,n){let{buffer:i}=this,l=-1;for(let h=t;h!=e&&!(we(n,r,i[h+1],i[h+2])&&(l=h,s>0));h=i[h+3]);return l}slice(t,e,s){let r=this.buffer,n=new Uint16Array(e-t),i=0;for(let l=t,h=0;l<e;){n[h++]=r[l++],n[h++]=r[l++]-s;let a=n[h++]=r[l++]-s;n[h++]=r[l++]-t,i=Math.max(i,a)}return new o(n,i,this.set)}};function we(o,t,e,s){switch(o){case-2:return e<t;case-1:return s>=t&&e<t;case 0:return e<t&&s>t;case 1:return e<=t&&s>t;case 2:return s>t;case 4:return!0}}function Se(o,t){let e=o.childBefore(t);for(;e;){let s=e.lastChild;if(!s||s.to!=e.to)break;s.type.isError&&s.from==s.to?(o=e,e=s.prevSibling):e=s}return o}function ct(o,t,e,s){for(var r;o.from==o.to||(e<1?o.from>=t:o.from>t)||(e>-1?o.to<=t:o.to<t);){let i=!s&&o instanceof nt&&o.index<0?null:o.parent;if(!i)return o;o=i}let n=s?0:A.IgnoreOverlays;if(s)for(let i=o,l=i.parent;l;i=l,l=i.parent)i instanceof nt&&i.index<0&&((r=l.enter(t,e,n))===null||r===void 0?void 0:r.from)!=i.from&&(o=l);for(;;){let i=o.enter(t,e,n);if(!i)return o;o=i}}var nt=class o{constructor(t,e,s,r){this._tree=t,this.from=e,this.index=s,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,s,r,n=0){for(let i=this;;){for(let{children:l,positions:h}=i._tree,a=e>0?l.length:-1;t!=a;t+=e){let f=l[t],c=h[t]+i.from;if(we(r,s,c,c+f.length)){if(f instanceof it){if(n&A.ExcludeBuffers)continue;let p=f.findChild(0,f.buffer.length,e,s-c,r);if(p>-1)return new kt(new jt(i,f,t,c),null,p)}else if(n&A.IncludeAnonymous||!f.type.isAnonymous||Wt(f)){let p;if(!(n&A.IgnoreMounts)&&f.props&&(p=f.prop(x.mounted))&&!p.overlay)return new o(p.tree,c,t,i);let d=new o(f,c,t,i);return n&A.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(e<0?f.children.length-1:0,e,s,r)}}}if(n&A.IncludeAnonymous||!i.type.isAnonymous||(i.index>=0?t=i.index+e:t=e<0?-1:i._parent._tree.children.length,i=i._parent,!i))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(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,s=0){let r;if(!(s&A.IgnoreOverlays)&&(r=this._tree.prop(x.mounted))&&r.overlay){let n=t-this.from;for(let{from:i,to:l}of r.overlay)if((e>0?i<=n:i<n)&&(e<0?l>=n:l>n))return new o(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,s)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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}cursor(t=0){return new pt(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return ct(this,t,e,!1)}resolveInner(t,e=0){return ct(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Se(this,t)}getChild(t,e=null,s=null){let r=Tt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Tt(this,t,e,s)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return It(this,t)}};function Tt(o,t,e,s){let r=o.cursor(),n=[];if(!r.firstChild())return n;if(e!=null){for(;!r.type.is(e);)if(!r.nextSibling())return n}for(;;){if(s!=null&&r.type.is(s))return n;if(r.type.is(t)&&n.push(r.node),!r.nextSibling())return s==null?n:[]}}function It(o,t,e=t.length-1){for(let s=o.parent;e>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(t[e]&&t[e]!=s.name)return!1;e--}}return!0}var jt=class{constructor(t,e,s,r){this.parent=t,this.buffer=e,this.index=s,this.start=r}},kt=class o{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(t,e,s){this.context=t,this._parent=e,this.index=s,this.type=t.buffer.set.types[t.buffer.buffer[s]]}child(t,e,s){let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,s);return n<0?null:new o(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,s=0){if(s&A.ExcludeBuffers)return null;let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return n<0?null:new o(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new o(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new o(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new pt(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:s}=this.context,r=this.index+4,n=s.buffer[this.index+3];if(n>r){let i=s.buffer[this.index+1];t.push(s.slice(r,n,i)),e.push(0)}return new V(this.type,t,e,this.to-this.from)}resolve(t,e=0){return ct(this,t,e,!1)}resolveInner(t,e=0){return ct(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Se(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,s=null){let r=Tt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Tt(this,t,e,s)}get node(){return this}matchContext(t){return It(this,t)}},pt=class{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof nt)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let s=t._parent;s;s=s._parent)this.stack.unshift(s.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:s,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=s+r.buffer[t+1],this.to=s+r.buffer[t+2],!0}yield(t){return t?t instanceof nt?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,s){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,s,this.mode));let{buffer:r}=this.buffer,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,s);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,s=this.mode){return this.buffer?s&A.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&A.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&A.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,s=this.stack.length-1;if(t<0){let r=s<0?0:this.stack[s]+4;if(this.index!=r)return this.yieldBuf(e.findChild(r,this.index,-1,0,4))}else{let r=e.buffer[this.index+3];if(r<(s<0?e.buffer.length:e.buffer[this.stack[s]+3]))return this.yieldBuf(r)}return s<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,s,{buffer:r}=this;if(r){if(t>0){if(this.index<r.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(r.buffer.buffer[n+3]<this.index)return!1;({index:e,parent:s}=r)}else({index:e,_parent:s}=this._tree);for(;s;{index:e,_parent:s}=s)if(e>-1)for(let n=e+t,i=t<0?-1:s._tree.children.length;n!=i;n+=t){let l=s._tree.children[n];if(this.mode&A.IncludeAnonymous||l instanceof it||!l.type.isAnonymous||Wt(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,s=0;if(t&&t.context==this.buffer)t:for(let r=this.index,n=this.stack.length;n>=0;){for(let i=t;i;i=i._parent)if(i.index==r){if(r==this.index)return i;e=i,s=n+1;break t}r=this.stack[--n]}for(let r=s;r<this.stack.length;r++)e=new kt(this.buffer,e,this.stack[r]);return this.bufferNode=new kt(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let s=0;;){let r=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){s++;continue}this.type.isAnonymous||(r=!0)}for(;r&&e&&e(this),r=this.type.isAnonymous,!this.nextSibling();){if(!s)return;this.parent(),s--,r=!0}}}matchContext(t){if(!this.buffer)return It(this.node,t);let{buffer:e}=this.buffer,{types:s}=e.set;for(let r=t.length-1,n=this.stack.length-1;r>=0;n--){if(n<0)return It(this.node,t,r);let i=s[e.buffer[this.stack[n]]];if(!i.isAnonymous){if(t[r]&&t[r]!=i.name)return!1;r--}}return!0}};function Wt(o){return o.children.some(t=>t instanceof it||!t.type.isAnonymous||Wt(t))}function He(o){var t;let{buffer:e,nodeSet:s,maxBufferLength:r=1024,reused:n=[],minRepeatType:i=s.types.length}=o,l=Array.isArray(e)?new $t(e,e.length):e,h=s.types,a=0,f=0;function c(R,O,m,y,T){let{id:k,start:S,end:v,size:F}=l,L=f;for(;F<0;)if(l.next(),F==-1){let J=n[k];m.push(J),y.push(S-R);return}else if(F==-3){a=k;return}else if(F==-4){f=k;return}else throw new RangeError(`Unrecognized record size: ${F}`);let ut=h[k],K,U,pe=S-R;if(v-S<=r&&(U=Y(l.pos-O,T))){let J=new Uint16Array(U.size-U.skip),_=l.pos-U.size,W=J.length;for(;l.pos>_;)W=ht(U.start,J,W);K=new it(J,v-U.start,s),pe=U.start-R}else{let J=l.pos-F;l.next();let _=[],W=[],rt=k>=i?k:-1,ft=0,Ot=v;for(;l.pos>J;)rt>=0&&l.id==rt&&l.size>=0?(l.end<=Ot-r&&(d(_,W,S,ft,l.end,Ot,rt,L),ft=_.length,Ot=l.end),l.next()):c(S,J,_,W,rt);if(rt>=0&&ft>0&&ft<_.length&&d(_,W,S,ft,S,Ot,rt,L),_.reverse(),W.reverse(),rt>-1&&ft>0){let de=p(ut);K=Xt(ut,_,W,0,_.length,0,v-S,de,de)}else K=w(ut,_,W,v-S,L-v)}m.push(K),y.push(pe)}function p(R){return(O,m,y)=>{let T=0,k=O.length-1,S,v;if(k>=0&&(S=O[k])instanceof V){if(!k&&S.type==R&&S.length==y)return S;(v=S.prop(x.lookAhead))&&(T=m[k]+S.length+v)}return w(R,O,m,y,T)}}function d(R,O,m,y,T,k,S,v){let F=[],L=[];for(;R.length>y;)F.push(R.pop()),L.push(O.pop()+m-T);R.push(w(s.types[S],F,L,k-T,v-k)),O.push(T-m)}function w(R,O,m,y,T=0,k){if(a){let S=[x.contextHash,a];k=k?[S].concat(k):[S]}if(T>25){let S=[x.lookAhead,T];k=k?[S].concat(k):[S]}return new V(R,O,m,y,k)}function Y(R,O){let m=l.fork(),y=0,T=0,k=0,S=m.end-r,v={size:0,start:0,skip:0};t:for(let F=m.pos-R;m.pos>F;){let L=m.size;if(m.id==O&&L>=0){v.size=y,v.start=T,v.skip=k,k+=4,y+=4,m.next();continue}let ut=m.pos-L;if(L<0||ut<F||m.start<S)break;let K=m.id>=i?4:0,U=m.start;for(m.next();m.pos>ut;){if(m.size<0)if(m.size==-3)K+=4;else break t;else m.id>=i&&(K+=4);m.next()}T=U,y+=L,k+=K}return(O<0||y==R)&&(v.size=y,v.start=T,v.skip=k),v.size>4?v:void 0}function ht(R,O,m){let{id:y,start:T,end:k,size:S}=l;if(l.next(),S>=0&&y<i){let v=m;if(S>4){let F=l.pos-(S-4);for(;l.pos>F;)m=ht(R,O,m)}O[--m]=v,O[--m]=k-R,O[--m]=T-R,O[--m]=y}else S==-3?a=y:S==-4&&(f=y);return m}let st=[],at=[];for(;l.pos>0;)c(o.start||0,o.bufferStart||0,st,at,-1);let M=(t=o.length)!==null&&t!==void 0?t:st.length?at[0]+st[0].length:0;return new V(h[o.topID],st.reverse(),at.reverse(),M)}var be=new WeakMap;function Dt(o,t){if(!o.isAnonymous||t instanceof it||t.type!=o)return 1;let e=be.get(t);if(e==null){e=1;for(let s of t.children){if(s.type!=o||!(s instanceof V)){e=1;break}e+=Dt(o,s)}be.set(t,e)}return e}function Xt(o,t,e,s,r,n,i,l,h){let a=0;for(let w=s;w<r;w++)a+=Dt(o,t[w]);let f=Math.ceil(a*1.5/8),c=[],p=[];function d(w,Y,ht,st,at){for(let M=ht;M<st;){let R=M,O=Y[M],m=Dt(o,w[M]);for(M++;M<st;M++){let y=Dt(o,w[M]);if(m+y>=f)break;m+=y}if(M==R+1){if(m>f){let y=w[R];d(y.children,y.positions,0,y.children.length,Y[R]+at);continue}c.push(w[R])}else{let y=Y[M-1]+w[M-1].length-O;c.push(Xt(o,w,Y,R,M,O,y,null,h))}p.push(O+at-n)}}return d(t,e,s,r,0),(l||h)(c,p,i)}var Nt=class{startParse(t,e,s){return typeof t=="string"&&(t=new Ut(t)),s=s?s.length?s.map(r=>new yt(r.from,r.to)):[new yt(0,0)]:[new yt(0,t.length)],this.createParse(t,e||[],s)}parse(t,e,s){let r=this.startParse(t,e,s);for(;;){let n=r.advance();if(n)return n}}},Ut=class{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}};var rr=new x({perNode:!0});var Kt=class o{constructor(t,e,s,r,n,i,l,h,a,f=0,c){this.p=t,this.stack=e,this.state=s,this.reducePos=r,this.pos=n,this.score=i,this.buffer=l,this.bufferBase=h,this.curContext=a,this.lookAhead=f,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let r=t.parser.context;return new o(t,[],e,s,s,0,[],0,r?new Mt(r,r.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,r=t&65535,{parser:n}=this.p,i=n.dynamicPrecedence(r);if(i&&(this.score+=i),s==0){this.pushState(n.getGoto(this.state,r,!0),this.reducePos),r<n.minRepeatTerm&&this.storeNode(r,this.reducePos,this.reducePos,4,!0),this.reduceContext(r,this.reducePos);return}let l=this.stack.length-(s-1)*3-(t&262144?6:0),h=l?this.stack[l-2]:this.p.ranges[0].from,a=this.reducePos-h;a>=2e3&&!(!((e=this.p.parser.nodeSet.types[r])===null||e===void 0)&&e.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=a):this.p.lastBigReductionSize<a&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=a));let f=l?this.stack[l-1]:0,c=this.bufferBase+this.buffer.length-f;if(r<n.minRepeatTerm||t&131072){let p=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(r,h,p,c+4,!0)}if(t&262144)this.state=this.stack[l];else{let p=this.stack[l-3];this.state=n.getGoto(p,r,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(r,h)}storeNode(t,e,s,r=4,n=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let i=this,l=this.buffer.length;if(l==0&&i.parent&&(l=i.bufferBase-i.parent.bufferBase,i=i.parent),l>0&&i.buffer[l-4]==0&&i.buffer[l-1]>-1){if(e==s)return;if(i.buffer[l-2]>=e){i.buffer[l-2]=s;return}}}if(!n||this.pos==s)this.buffer.push(t,e,s,r);else{let i=this.buffer.length;if(i>0&&this.buffer[i-4]!=0)for(;i>0&&this.buffer[i-2]>s;)this.buffer[i]=this.buffer[i-4],this.buffer[i+1]=this.buffer[i-3],this.buffer[i+2]=this.buffer[i-2],this.buffer[i+3]=this.buffer[i-1],i-=4,r>4&&(r-=4);this.buffer[i]=t,this.buffer[i+1]=e,this.buffer[i+2]=s,this.buffer[i+3]=r}}shift(t,e,s){let r=this.pos;if(t&131072)this.pushState(t&65535,this.pos);else if(t&262144)this.pos=s,this.shiftContext(e,r),e<=this.p.parser.maxNode&&this.buffer.push(e,r,s,4);else{let n=t,{parser:i}=this.p;(s>this.pos||e<=i.maxNode)&&(this.pos=s,i.stateFlag(n,1)||(this.reducePos=s)),this.pushState(n,r),this.shiftContext(e,r),e<=i.maxNode&&this.buffer.push(e,r,s,4)}}apply(t,e,s){t&65536?this.reduce(t):this.shift(t,e,s)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let r=this.pos;this.reducePos=this.pos=r+t.length,this.pushState(e,r),this.buffer.push(s,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),r=t.bufferBase+e;for(;t&&r==t.bufferBase;)t=t.parent;return new o(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,r,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Jt(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(s==0)return!1;if(!(s&65536))return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let r=[];for(let n=0,i;n<e.length;n+=2)(i=e[n+1])!=this.state&&this.p.parser.hasAction(i,t)&&r.push(e[n],i);if(this.stack.length<120)for(let n=0;r.length<8&&n<e.length;n+=2){let i=e[n+1];r.some((l,h)=>h&1&&l==i)||r.push(e[n],i)}e=r}let s=[];for(let r=0;r<e.length&&s.length<4;r+=2){let n=e[r+1];if(n==this.state)continue;let i=this.split();i.pushState(n,this.pos),i.storeNode(0,i.pos,i.pos,4,!0),i.shiftContext(e[r],this.pos),i.score-=200,s.push(i)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if(!(e&65536))return!1;if(!t.validAction(this.state,e)){let s=e>>19,r=e&65535,n=this.stack.length-s*3;if(n<0||t.getGoto(this.stack[n],r,!1)<0){let i=this.findForcedReduction();if(i==null)return!1;e=i}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(r,n)=>{if(!e.includes(r))return e.push(r),t.allActions(r,i=>{if(!(i&393216))if(i&65536){let l=(i>>19)-n;if(l>1){let h=i&65535,a=this.stack.length-l*3;if(a>=0&&t.getGoto(this.stack[a],h,!1)>=0)return l<<19|65536|h}}else{let l=s(i,n+1);if(l!=null)return l}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new Mt(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){t>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=t)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},Mt=class{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}},ye;(function(o){o[o.Insert=200]="Insert",o[o.Delete=190]="Delete",o[o.Reduce=100]="Reduce",o[o.MaxNext=4]="MaxNext",o[o.MaxInsertStackDepth=300]="MaxInsertStackDepth",o[o.DampenInsertStackDepth=120]="DampenInsertStackDepth",o[o.MinBigReduction=2e3]="MinBigReduction"})(ye||(ye={}));var Jt=class{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,s=t>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let r=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=r}},Zt=class o{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new o(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}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]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new o(this.stack,this.pos,this.index)}};function xt(o,t=Uint16Array){if(typeof o!="string")return o;let e=null;for(let s=0,r=0;s<o.length;){let n=0;for(;;){let i=o.charCodeAt(s++),l=!1;if(i==126){n=65535;break}i>=92&&i--,i>=34&&i--;let h=i-32;if(h>=46&&(h-=46,l=!0),n+=h,l)break;n*=46}e?e[r++]=n:e=new t(n)}return e}var dt=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},ke=new dt,qt=class{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=ke,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,r=this.rangeIndex,n=this.pos+t;for(;n<s.from;){if(!r)return null;let i=this.ranges[--r];n-=s.from-i.to,s=i}for(;e<0?n>s.to:n>=s.to;){if(r==this.ranges.length-1)return null;let i=this.ranges[++r];n+=i.from-s.to,s=i}return n}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,s,r;if(e>=0&&e<this.chunk.length)s=this.pos+t,r=this.chunk.charCodeAt(e);else{let n=this.resolveOffset(t,1);if(n==null)return-1;if(s=n,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let i=this.rangeIndex,l=this.range;for(;l.to<=s;)l=this.ranges[++i];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-s)),r=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),r}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=ke,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let r of this.ranges){if(r.from>=e)break;r.to>t&&(s+=this.input.read(Math.max(r.from,t),Math.min(r.to,e)))}return s}},Z=class{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;De(this.data,t,e,this.id,s.data,s.tokenPrecTable)}};Z.prototype.contextual=Z.prototype.fallback=Z.prototype.extend=!1;var Ht=class{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?xt(t):t}token(t,e){let s=t.pos,r=0;for(;;){let n=t.next<0,i=t.resolveOffset(1,1);if(De(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(n||r++,i==null)break;t.reset(i,t.token)}r&&(t.reset(s,t.token),t.acceptToken(this.elseToken,r))}};Ht.prototype.contextual=Z.prototype.fallback=Z.prototype.extend=!1;function De(o,t,e,s,r,n){let i=0,l=1<<s,{dialect:h}=e.p.parser;t:for(;l&o[i];){let a=o[i+1];for(let d=i+3;d<a;d+=2)if((o[d+1]&l)>0){let w=o[d];if(h.allows(w)&&(t.token.value==-1||t.token.value==w||es(w,t.token.value,r,n))){t.acceptToken(w);break}}let f=t.next,c=0,p=o[i+2];if(t.next<0&&p>c&&o[a+p*3-3]==65535&&o[a+p*3-3]==65535){i=o[a+p*3-1];continue t}for(;c<p;){let d=c+p>>1,w=a+d+(d<<1),Y=o[w],ht=o[w+1]||65536;if(f<Y)p=d;else if(f>=ht)c=d+1;else{i=o[w+2],t.advance();continue t}}break}}function xe(o,t,e){for(let s=t,r;(r=o[s])!=65535;s++)if(r==e)return s-t;return-1}function es(o,t,e,s){let r=xe(e,s,t);return r<0||xe(e,s,o)<r}var $=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Yt=null,Re;(function(o){o[o.Margin=25]="Margin"})(Re||(Re={}));function Ce(o,t,e){let s=o.cursor(A.IncludeAnonymous);for(s.moveTo(t);;)if(!(e<0?s.childBefore(t):s.childAfter(t)))for(;;){if((e<0?s.to<t:s.from>t)&&!s.type.isError)return e<0?Math.max(0,Math.min(s.to-1,t-25)):Math.min(o.length,Math.max(s.from+1,t+25));if(e<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return e<0?0:o.length}}var te=class{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?Ce(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?Ce(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let s=this.trees[e],r=this.index[e];if(r==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=s.children[r],i=this.start[e]+s.positions[r];if(i>t)return this.nextStart=i,null;if(n instanceof V){if(i==t){if(i<this.safeFrom)return null;let l=i+n.length;if(l<=this.safeTo){let h=n.prop(x.lookAhead);if(!h||l+h<this.fragment.to)return n}}this.index[e]++,i+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(i),this.index.push(0))}else this.index[e]++,this.nextStart=i+n.length}}},ee=class{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new dt)}getActions(t){let e=0,s=null,{parser:r}=t.p,{tokenizers:n}=r,i=r.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let a=0;a<n.length;a++){if(!(1<<a&i))continue;let f=n[a],c=this.tokens[a];if(!(s&&!f.fallback)&&((f.contextual||c.start!=t.pos||c.mask!=i||c.context!=l)&&(this.updateCachedToken(c,f,t),c.mask=i,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let p=e;if(c.extended>-1&&(e=this.addActions(t,c.extended,c.end,e)),e=this.addActions(t,c.value,c.end,e),!f.extend&&(s=c,e>p))break}}for(;this.actions.length>e;)this.actions.pop();return h&&t.setLookAhead(h),!s&&t.pos==this.stream.end&&(s=new dt,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new dt,{pos:s,p:r}=t;return e.start=s,e.end=Math.min(s+1,r.stream.end),e.value=s==r.stream.end?r.parser.eofTerm:0,e}updateCachedToken(t,e,s){let r=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(r,t),s),t.value>-1){let{parser:n}=s.p;for(let i=0;i<n.specialized.length;i++)if(n.specialized[i]==t.value){let l=n.specializers[i](this.stream.read(t.start,t.end),s);if(l>=0&&s.p.parser.dialect.allows(l>>1)){l&1?t.extended=l>>1:t.value=l>>1;break}}}else t.value=0,t.end=this.stream.clipPos(r+1)}putAction(t,e,s,r){for(let n=0;n<r;n+=3)if(this.actions[n]==t)return r;return this.actions[r++]=t,this.actions[r++]=e,this.actions[r++]=s,r}addActions(t,e,s,r){let{state:n}=t,{parser:i}=t.p,{data:l}=i;for(let h=0;h<2;h++)for(let a=i.stateSlot(n,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=X(l,a+2);else{r==0&&l[a+1]==2&&(r=this.putAction(X(l,a+2),e,s,r));break}l[a]==e&&(r=this.putAction(X(l,a+1),e,s,r))}return r}},Pe;(function(o){o[o.Distance=5]="Distance",o[o.MaxRemainingPerStep=3]="MaxRemainingPerStep",o[o.MinBufferLengthPrune=500]="MinBufferLengthPrune",o[o.ForceReduceLimit=10]="ForceReduceLimit",o[o.CutDepth=15e3]="CutDepth",o[o.CutTo=9e3]="CutTo",o[o.MaxLeftAssociativeReductionCount=300]="MaxLeftAssociativeReductionCount",o[o.MaxStackCount=12]="MaxStackCount"})(Pe||(Pe={}));var se=class{constructor(t,e,s,r){this.parser=t,this.input=e,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new qt(e,r),this.tokens=new ee(t,this.stream),this.topTerm=t.top[1];let{from:n}=r[0];this.stacks=[Kt.start(this,t.top[0],n)],this.fragments=s.length&&this.stream.end-n>t.bufferLength*4?new te(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],r,n;if(this.bigReductionCount>300&&t.length==1){let[i]=t;for(;i.forceReduce()&&i.stack.length&&i.stack[i.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let i=0;i<t.length;i++){let l=t[i];for(;;){if(this.tokens.mainToken=null,l.pos>e)s.push(l);else{if(this.advanceStack(l,s,t))continue;{r||(r=[],n=[]),r.push(l);let h=this.tokens.getMainToken(l);n.push(h.value,h.end)}}break}}if(!s.length){let i=r&&ss(r);if(i)return this.stackToTree(i);if(this.parser.strict)throw $&&r&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&r){let i=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,n,s);if(i)return this.stackToTree(i.forceAll())}if(this.recovering){let i=this.recovering==1?1:this.recovering*3;if(s.length>i)for(s.sort((l,h)=>h.score-l.score);s.length>i;)s.pop();s.some(l=>l.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let i=0;i<s.length-1;i++){let l=s[i];for(let h=i+1;h<s.length;h++){let a=s[h];if(l.sameState(a)||l.buffer.length>500&&a.buffer.length>500)if((l.score-a.score||l.buffer.length-a.buffer.length)>0)s.splice(h--,1);else{s.splice(i--,1);continue t}}}s.length>12&&s.splice(12,s.length-12)}this.minStackPos=s[0].pos;for(let i=1;i<s.length;i++)s[i].pos<this.minStackPos&&(this.minStackPos=s[i].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,s){let r=t.pos,{parser:n}=this,i=$?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&r>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,f=a?t.curContext.hash:0;for(let c=this.fragments.nodeAt(r);c;){let p=this.parser.nodeSet.types[c.type.id]==c.type?n.getGoto(t.state,c.type.id):-1;if(p>-1&&c.length&&(!a||(c.prop(x.contextHash)||0)==f))return t.useNode(c,p),$&&console.log(i+this.stackID(t)+` (via reuse of ${n.getName(c.type.id)})`),!0;if(!(c instanceof V)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof V&&c.positions[0]==0)c=d;else break}}let l=n.stateSlot(t.state,4);if(l>0)return t.reduce(l),$&&console.log(i+this.stackID(t)+` (via always-reduce ${n.getName(l&65535)})`),!0;if(t.stack.length>=15e3)for(;t.stack.length>9e3&&t.forceReduce(););let h=this.tokens.getActions(t);for(let a=0;a<h.length;){let f=h[a++],c=h[a++],p=h[a++],d=a==h.length||!s,w=d?t:t.split();if(w.apply(f,c,p),$&&console.log(i+this.stackID(w)+` (via ${f&65536?`reduce of ${n.getName(f&65535)}`:"shift"} for ${n.getName(c)} @ ${r}${w==t?"":", split"})`),d)return!0;w.pos>r?e.push(w):s.push(w)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return Oe(t,e),!0}}runRecovery(t,e,s){let r=null,n=!1;for(let i=0;i<t.length;i++){let l=t[i],h=e[i<<1],a=e[(i<<1)+1],f=$?this.stackID(l)+" -> ":"";if(l.deadEnd&&(n||(n=!0,l.restart(),$&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,s))))continue;let c=l.split(),p=f;for(let d=0;c.forceReduce()&&d<10&&($&&console.log(p+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,s));d++)$&&(p=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))$&&console.log(f+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,s);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),$&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),Oe(l,s)):(!r||r.score<l.score)&&(r=l)}return r}stackToTree(t){return t.close(),V.build({buffer:Zt.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(Yt||(Yt=new WeakMap)).get(t);return e||Yt.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}};function Oe(o,t){for(let e=0;e<t.length;e++){let s=t[e];if(s.pos==o.pos&&s.sameState(o)){t[e].score<o.score&&(t[e]=o);return}}t.push(o)}var re=class{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}};var Ft=class o extends Nt{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let l=0;l<t.repeatNodeCount;l++)e.push("");let s=Object.keys(t.topRules).map(l=>t.topRules[l][1]),r=[];for(let l=0;l<e.length;l++)r.push([]);function n(l,h,a){r[l].push([h,h.deserialize(String(a))])}if(t.nodeProps)for(let l of t.nodeProps){let h=l[0];typeof h=="string"&&(h=x[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)n(f,h,l[a++]);else{let c=l[a+-f];for(let p=-f;p>0;p--)n(l[a++],h,c);a++}}}this.nodeSet=new At(e.map((l,h)=>E.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:r[h],top:s.indexOf(h)>-1,error:h==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(h)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=1024;let i=xt(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(ve),this.states=xt(t.states,Uint32Array),this.data=xt(t.stateData),this.goto=xt(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new Z(i,l):l),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let r=new se(this,t,e,s);for(let n of this.wrappers)r=n(r,t,e,s);return r}getGoto(t,e,s=!1){let r=this.goto;if(e>=r[0])return-1;for(let n=r[e+1];;){let i=r[n++],l=i&1,h=r[n++];if(l&&s)return h;for(let a=n+(i>>1);n<a;n++)if(r[n]==t)return h;if(l)return-1}}hasAction(t,e){let s=this.data;for(let r=0;r<2;r++)for(let n=this.stateSlot(t,r?2:1),i;;n+=3){if((i=s[n])==65535)if(s[n+1]==1)i=s[n=X(s,n+2)];else{if(s[n+1]==2)return X(s,n+2);break}if(i==e||i==0)return X(s,n+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,s=>s==e?!0:null)}allActions(t,e){let s=this.stateSlot(t,4),r=s?e(s):void 0;for(let n=this.stateSlot(t,1);r==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=X(this.data,n+2);else break;r=e(X(this.data,n+1))}return r}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=X(this.data,s+2);else break;if(!(this.data[s+2]&1)){let r=this.data[s+1];e.some((n,i)=>i&1&&n==r)||e.push(this.data[s],r)}}return e}configure(t){let e=Object.assign(Object.create(o.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(s=>{let r=t.tokenizers.find(n=>n.from==s);return r?r.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,r)=>{let n=t.specializers.find(l=>l.from==s.external);if(!n)return s;let i=Object.assign(Object.assign({},s),{external:n.to});return e.specializers[r]=ve(i),i})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let n of t.split(" ")){let i=e.indexOf(n);i>=0&&(s[i]=!0)}let r=null;for(let n=0;n<e.length;n++)if(!s[n])for(let i=this.dialects[e[n]],l;(l=this.data[i++])!=65535;)(r||(r=new Uint8Array(this.maxTerm+1)))[l]=1;return new re(t,s,r)}static deserialize(t){return new o(t)}};function X(o,t){return o[t]|o[t+1]<<16}function ss(o){let t=null;for(let e of o){let s=e.p.stoppedAt;(e.pos==e.p.stream.end||s!=null&&e.pos>s)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function ve(o){if(o.external){let t=o.extend?1:0;return(e,s)=>o.external(e,s)<<1|t}return o.get}var ie=Ft.deserialize({version:14,states:"%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",stateData:"#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",goto:"#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",nodeNames:"\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",maxTerm:39,skippedNodes:[0],repeatNodeCount:1,tokenData:"6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",tokenizers:[0,1],topRules:{Filter:[0,1]},tokenPrec:0});import{isMultiClauseFilter as Rt,isMultiValueFilter as rs,isSingleValueFilter as is}from"@vuu-ui/vuu-utils";var B,ne=class{constructor(){C(this,B,void 0)}setFilterCombinatorOp(t,e=u(this,B)){Rt(e)&&e.op===t||g(this,B,{op:t,filters:[u(this,B)]})}add(t){if(u(this,B)===void 0)g(this,B,t);else if(Rt(u(this,B)))u(this,B).filters.push(t);else throw Error("Invalid filter passed to FilterExpression")}setColumn(t,e=u(this,B)){if(Rt(e)){let s=e.filters.at(-1);s&&this.setColumn(t,s)}else e&&(e.column=t)}setOp(t,e=u(this,B)){if(Rt(e)){let s=e.filters.at(-1);s&&this.setOp(t,s)}else e&&(e.op=t)}setValue(t,e=u(this,B)){var s;if(Rt(e)){let r=e.filters.at(-1);r&&this.setValue(t,r)}else rs(e)?((s=e.values)!=null||(e.values=[]),e.values.push(t)):is(e)&&(e.value=t)}toJSON(t=u(this,B)){return this.name?{...t,name:this.name}:t}};B=new WeakMap;var oe=(o,t)=>{let e=new ne,s=o.cursor();do{let{name:r,from:n,to:i}=s;switch(r){case"ColumnValueExpression":e.add({});break;case"ColumnSetExpression":e.add({op:"in"});break;case"Or":case"And":e.setFilterCombinatorOp(t.substring(n,i));break;case"Column":e.setColumn(t.substring(n,i));break;case"Operator":e.setOp(t.substring(n,i));break;case"String":e.setValue(t.substring(n+1,i-1));break;case"Number":e.setValue(parseFloat(t.substring(n,i)));break;case"True":e.setValue(!0);break;case"False":e.setValue(!1);break;case"FilterName":e.name=t.substring(n,i);break;default:}}while(s.next());return e.toJSON()};var ns=ie.configure({strict:!0}),gt=o=>{let t=ns.parse(o);return oe(t,o)};function Vt(o,t){switch(t.op){case"in":return os(o,t);case"=":return ls(o,t);case">":return hs(o,t);case">=":return as(o,t);case"<":return us(o,t);case"<=":return fs(o,t);case"starts":return cs(o,t);case"and":return ps(o,t);case"or":return ds(o,t);default:return console.log(`unrecognized filter type ${t.op}`),()=>!0}}var os=(o,t)=>e=>t.values.indexOf(e[o[t.column]])!==-1,ls=(o,t)=>e=>e[o[t.column]]===t.value,hs=(o,t)=>e=>e[o[t.column]]>t.value,as=(o,t)=>e=>e[o[t.column]]>=t.value,us=(o,t)=>e=>e[o[t.column]]<t.value,fs=(o,t)=>e=>e[o[t.column]]<=t.value,cs=(o,t)=>{let e=t.value;if(typeof e!="string")throw Error("string filter applied to value of wrong type");return s=>{let r=s[o[t.column]];if(typeof r!="string")throw Error("string filter applied to value of wrong type");return r.toLowerCase().startsWith(e.toLowerCase())}},ps=(o,t)=>{let e=t.filters.map(s=>Vt(o,s));return s=>e.every(r=>r(s))};function ds(o,t){let e=t.filters.map(s=>Vt(o,s));return s=>e.some(r=>r(s))}import{buildColumnMap as Ee,configChanged as Ms,EventEmitter as Fs,getAddedItems as Vs,getMissingItems as Bs,groupByChanged as Es,hasFilter as Qs,hasGroupBy as zs,hasSort as Gs,KeySet as Ls,logger as _s,metadataKeys as $s,NULL_RANGE as Qe,rangeNewItems as js,resetRange as Ct,uuid as ze,vanillaConfig as Us,withConfigDefaults as Ge}from"@vuu-ui/vuu-utils";var Ae=(o,t,e,s,r,n)=>{let i=ot(r,o),l=o[o.length-1].aggType,h=e.map(a=>r[a]);switch(l){case 1:return Ie(n,s,r,o,t,h);case 2:return gs(n,s,r,o,t,h);case 3:return Te(n,r,o,t,h);case 4:return bs(n,s,r,o,t,h);case 5:return ws(n,s,r,o,t,h);case 6:return ms(n,s,r,o,t,h)}};function Te(o,t,e,s,r){let n={},i=ot(t,e);function l(h){if(Array.isArray(h))return h.length;{let a=0;for(let f in h)a+=1+l(h[f]);return a}}for(let h in o){let a=l(o[h]);n[h]=a}for(let h=0;h<s.length;h++)for(let a in n)s[h][r[0]]===a&&(s[h][i]=n[a]);return console.log("!!!! targetData",s),console.log("!!!! counts",n),n}function ot(o,t){console.log("!!!! aggregation length",t.length);let e=t[t.length-1].column;return o[e]}function Ie(o,t,e,s,r,n){let i={},l=ot(e,s);function h(a,f,c){if(Array.isArray(a)){let p=0;for(let d of a)p+=Number(f[d][c]);return p}else{let p=0;for(let d in a)p+=h(a[d],f,c);return p}}for(let a in o){console.log(a);let f=Number(h(o[a],t,l));i[a]=f}for(let a=0;a<r.length;a++)for(let f in i)r[a][n[0]]===f&&(r[a][l]=i[f]);return console.log("!!!! targetData",r),console.log("!!!! sums",i),i}function gs(o,t,e,s,r,n){let i={},l=ot(e,s),h=Te(o,e,s,r,n),a=Ie(o,t,e,s,r,n);for(let f in h){let c=0;c=a[f]/h[f],i[f]=c}for(let f=0;f<r.length;f++)for(let c in i)r[f][n[0]]===c&&(r[f][l]=i[c]);return console.log("!!!! targetData",r),console.log("!!!! averages",i),i}function Bt(o,t,e){let s=[];if(Array.isArray(o))for(let r of o)s.push(t[r][e]);else for(let r in o)s.push(...Bt(o[r],t,e));return s}function ms(o,t,e,s,r,n){let i={},l=ot(e,s);for(let h in o){let a=Bt(o[h],t,l),f=[...new Set(a)];i[h]=f}for(let h=0;h<r.length;h++)for(let a in i)r[h][n[0]]===a&&(r[h][l]=i[a]);return i}function bs(o,t,e,s,r,n){let i={},l=ot(e,s);for(let h in o){let a=Bt(o[h],t,l),f=Math.max(...a);i[h]=f}for(let h=0;h<r.length;h++)for(let a in i)r[h][n[0]]===a&&(r[h][l]=i[a]);return i}function ws(o,t,e,s,r,n){let i={},l=ot(e,s);for(let h in o){let a=Bt(o[h],t,l),f=Math.min(...a);i[h]=f}for(let h=0;h<r.length;h++)for(let a in i)r[h][n[0]]===a&&(r[h][l]=i[a]);return i}import{getSelectionStatus as Ss,metadataKeys as Et}from"@vuu-ui/vuu-utils";var{RENDER_IDX:ys,SELECTED:ks}=Et,le=(o,t,e,s)=>{let[r]=o,n;if(s){let{count:i}=Et;n=o.slice(0,i).concat(s.map(l=>o[l]))}else n=o.slice();return n[ys]=t.keyFor(r),n[ks]=Ss(e,r),n},xs=(o,t)=>{if(t){let{count:e}=Et;for(let[s,r]of Object.entries(o)){let n=t[s];if(n===void 0)throw Error(`ArrayDataSource column ${s} is not in underlying data set`);if(n!==r-e)return!0}}return!1},Rs=(o,t)=>{let{count:e}=Et,s=[];return Object.entries(o).forEach(([r])=>{s.push(t[r]+e)}),s},he=(o,t)=>{if(t&&xs(o,t))return Rs(o,t)};import{metadataKeys as Cs}from"@vuu-ui/vuu-utils";var{DEPTH:ae,IS_EXPANDED:Ne,KEY:ue}=Cs,Me=(o,t)=>{let e=[];for(let s=0,r=0,n=!1,i=t.length;s<i;s++){let l=t[s],{[ae]:h,[ue]:a}=l;if(a===o){let f=l.slice();for(f[Ne]=!1,e.push(f),r+=1,n=!0;s<i-1&&t[s+1][ae]>h;)s+=1}else if(n){let f=l.slice();f[0]=r,f[1]=r,e.push(f),r+=1}else e.push(l),r+=1}return e},fe=(o,t,e,s,r,n)=>{let i=e.map(l=>s[l]);return Fe(r,i,o,t,void 0,void 0,void 0,n)},Fe=(o,t,e,s=[],r="$root",n=1,i=[],l)=>{console.log("dataRowsFromGroups2 1)");let h=Object.keys(o).sort();for(let a of h){let f=i.length,c=`${r}|${a}`,p=[f,f,!1,!1,n,0,c,0];p[t[n-1]]=a,i.push(p),e.includes(c)&&(p[Ne]=!0,Array.isArray(o[a])?Ps(i,o[a],s,c,n+1):Fe(o[a],t,e,s,c,n+1,i,l))}console.log("dataRowsFromGroups2 2)");for(let a in i)for(let f in i)if(i[a][2]===!1&&l[f]!=null&&i[a][t[0]]===l[f][t[0]]){i[a]=i[a].splice(0,8).concat(l[f].slice(8,l[f].length));break}return console.log("dataRowsFromGroups2 3)"),i},Ps=(o,t,e,s,r)=>{for(let n of t){let i=o.length,l=e[n].slice();l[0]=i,l[1]=i,l[ae]=r,l[ue]=`${s}|${l[ue]}`,o.push(l)}},Ve=(o,t,e)=>{let s=t.map(i=>e[i]),r=vs(o,s);return[Os(r,s),r]},Os=(o,t)=>{let s=[],r=0,n=Object.keys(o).sort();for(let i of n){let l=[r,r,!1,!1,1,0,`$root|${i}`,0];l[t[0]]=i,s.push(l),r+=1}return s};function vs(o,t){let e={},s=t.length,r=s-1;for(let n=0,i=o.length;n<i;n++){let l=o[n],h=e,a,f;for(let c=0;c<s;c++){let p=t[c];f=l[p].toString(),a=h[f],a&&c===r?a.push(n):a?h=a:!a&&c<r?h=h[f]={}:a||(h[f]=[n])}}return console.log("!! groups",e),e}var Ds=(o,t,[e,s])=>{let r=s==="D"?t[e]:o[e],n=s==="D"?o[e]:t[e];return r===n?0:n===null||r>n?1:-1},As=o=>o.length===1?Ts(o):o.length===2?Is(o):Ns(o),Ts=([[o,t]])=>(e,s)=>{let r=t==="D"?s[o]:e[o],n=t==="D"?e[o]:s[o];return r>n?1:n>r?-1:0},Is=([[o,t],[e,s]])=>(r,n)=>{let i=t==="D"?n[o]:r[o],l=t==="D"?r[o]:n[o],h=s==="D"?n[e]:r[e],a=s==="D"?r[e]:n[e];return i>l?1:l>i?-1:h>a?1:a>h?-1:0},Ns=(o,t=Ds)=>(e,s)=>{for(let r of o){let n=t(e,s,r);if(n!==0)return n}return 0},Be=(o,{sortDefs:t},e)=>{let s=t.map(({column:n,sortType:i})=>[e[n],i]),r=As(s);return o.slice().sort(r)};var{debug:Q,info:mt}=_s("ArrayDataSource"),{KEY:Le}=$s,ce=o=>(t,e)=>[e,e,!0,!1,1,0,String(t[o]),0,...t],Ws=(o,t)=>({columns:o.map(({name:s,serverDataType:r="string"})=>({name:s,serverDataType:r})),key:t!=null?t:o[0].name,table:{module:"",table:"Array"}}),N,b,D,Qt,P,Pt,zt,z,bt,_e=class extends Fs{constructor({aggregations:e,columnDescriptors:s,data:r,dataMap:n,filter:i,groupBy:l,keyColumn:h,rangeChangeRowset:a="delta",sort:f,title:c,viewport:p}){super();this.lastRangeServed={from:0,to:0};this.openTreeNodes=[];C(this,N,void 0);C(this,b,Us);C(this,D,void 0);C(this,Qt,void 0);C(this,P,Qe);C(this,Pt,0);C(this,zt,0);C(this,z,"initialising");C(this,bt,void 0);this.selectedRows=[];this.keys=new Ls(u(this,P));this.processedData=void 0;this.insert=e=>{let s=ce(this.key)(e,this.size);u(this,D).push(s);let{from:r,to:n}=u(this,P),[i]=s;i>=r&&i<n&&this.sendRowsToClient()};this.update=(e,s)=>{var h;let r=e[this.key],n=u(this,N)[s],i=(h=this.dataMap)==null?void 0:h[s],l=u(this,D).findIndex(a=>a[Le]===r);if(l!==-1&&i!==void 0){let a=u(this,D)[l];a[n]=e[i];let{from:f,to:c}=u(this,P),[p]=a;p>=f&&p<c&&this.sendRowsToClient(!1,a)}};this.updateRow=e=>{let s=e[this.key],r=u(this,D).findIndex(n=>n[Le]===s);if(r!==-1){let n=ce(this.key)(e,r);u(this,D)[r]=n;let{from:i,to:l}=u(this,P);r>=i&&r<l&&this.sendRowsToClient(!1,n)}};if(!r||!s)throw Error("ArrayDataSource constructor called without data or without columnDescriptors");this.columnDescriptors=s,this.dataMap=n,this.key=h?this.columnDescriptors.findIndex(w=>w.name===h):0,this.rangeChangeRowset=a,this.tableSchema=Ws(s,h),this.viewport=p||ze(),g(this,zt,r.length),g(this,bt,c);let d=s.map(w=>w.name);g(this,N,Ee(d)),this.dataIndices=he(u(this,N),this.dataMap),g(this,D,r.map(ce(this.key))),this.config={...u(this,b),aggregations:e||u(this,b).aggregations,columns:d,filter:i||u(this,b).filter,groupBy:l||u(this,b).groupBy,sort:f||u(this,b).sort},Q==null||Q(`columnMap: ${JSON.stringify(u(this,N))}`)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:ze())(),columns:s,aggregations:r,range:n,sort:i,groupBy:l,filter:h},a){var d;this.clientCallback=a,this.viewport=e,g(this,z,"subscribed"),this.lastRangeServed={from:0,to:0};let c=u(this,b),p=r||s||h||l||i;p&&(n&&g(this,P,n),c={...c,aggregations:r||u(this,b).aggregations,columns:s||u(this,b).columns,filter:h||u(this,b).filter,groupBy:l||u(this,b).groupBy,sort:i||u(this,b).sort}),(d=this.clientCallback)==null||d.call(this,{...c,type:"subscribed",clientViewportId:this.viewport,range:u(this,P),tableSchema:this.tableSchema}),p?this.config=c:(this.clientCallback({clientViewportId:this.viewport,mode:"size-only",type:"viewport-update",size:u(this,D).length}),n?(this.range=n,this.sendRowsToClient()):u(this,P)!==Qe&&this.sendRowsToClient())}unsubscribe(){console.log("unsubscribe noop")}suspend(){return console.log(`suspend #${this.viewport}, current status ${u(this,z)}`),mt==null||mt(`suspend #${this.viewport}, current status ${u(this,z)}`),g(this,z,"suspended"),this}resume(){console.log(`resume #${this.viewport}, current status ${u(this,z)}`);let e=u(this,z)==="suspended";return mt==null||mt(`resume #${this.viewport}, current status ${u(this,z)}`),console.log("resume noop"),e&&g(this,z,"subscribed"),this}disable(){return console.log("disable noop"),this}enable(){return console.log("enable noop"),this}select(e){g(this,Pt,e.length),Q==null||Q(`select ${JSON.stringify(e)}`),this.selectedRows=e,this.setRange(Ct(u(this,P)),!0)}openTreeNode(e){this.openTreeNodes.push(e),this.processedData=fe(this.openTreeNodes,u(this,D),u(this,b).groupBy,u(this,N),this.groupMap,this.processedData),this.setRange(Ct(u(this,P)),!0)}closeTreeNode(e){this.openTreeNodes=this.openTreeNodes.filter(s=>s!==e),this.processedData&&(this.processedData=Me(e,this.processedData),this.setRange(Ct(u(this,P)),!0))}get links(){return u(this,Qt)}get menu(){return this._menu}get status(){return u(this,z)}get data(){return u(this,D)}get currentData(){var e;return(e=this.processedData)!=null?e:u(this,D)}get table(){return this.tableSchema.table}get config(){return u(this,b)}set config(e){var s;if(this.applyConfig(e)){if(e){let r=u(this,b),n=(s=e==null?void 0:e.filter)!=null&&s.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:gt(e.filter.filter)}}:e;g(this,b,Ge(n));let i;if(Qs(e)){let{filter:l,filterStruct:h=gt(l)}=e.filter;if(h){let a=Vt(u(this,N),h);i=u(this,D).filter(a)}else throw Error("filter must include filterStruct")}if(Gs(e)&&(i=Be(i!=null?i:u(this,D),e.sort,u(this,N))),this.openTreeNodes.length>0&&Es(r,e)&&(u(this,b).groupBy.length===0?this.openTreeNodes.length=0:console.log("adjust the openTReeNodes groupBy changed ",{originalGroupBy:r.groupBy,newGroupBy:n.groupBy})),zs(e)){let[l,h]=Ve(i!=null?i:u(this,D),e.groupBy,u(this,N));this.groupMap=h,i=l,this.openTreeNodes.length>0&&(i=fe(this.openTreeNodes,u(this,D),u(this,b).groupBy,u(this,N),this.groupMap,i))}this.processedData=i==null?void 0:i.map((l,h)=>{let a=l.slice();return a[0]=h,a[1]=h,a})}this.setRange(Ct(u(this,P)),!0),this.emit("config",u(this,b))}}applyConfig(e){var s;if(Ms(u(this,b),e)&&e){let r=(s=e==null?void 0:e.filter)!=null&&s.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:gt(e.filter.filter)}}:e;return g(this,b,Ge(r)),!0}}get selectedRowsCount(){return u(this,Pt)}get size(){var e,s;return(s=(e=this.processedData)==null?void 0:e.length)!=null?s:u(this,D).length}get range(){return u(this,P)}set range(e){this.setRange(e)}delete(e){console.log(`delete row ${e.join(",")}`)}setRange(e,s=!1){e.from!==u(this,P).from||e.to!==u(this,P).to?(g(this,P,e),this.keys.reset(e),this.sendRowsToClient(s)):s&&this.sendRowsToClient(s)}sendRowsToClient(e=!1,s){var r,n,i;if(s)(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"update",rows:[le(s,this.keys,this.selectedRows,this.dataIndices)],type:"viewport-update"});else{let l=this.rangeChangeRowset==="delta"&&!e?js(this.lastRangeServed,u(this,P)):u(this,P),h=(n=this.processedData)!=null?n:u(this,D),a=h.slice(l.from,l.to).map(f=>le(f,this.keys,this.selectedRows,this.dataIndices));(i=this.clientCallback)==null||i.call(this,{clientViewportId:this.viewport,mode:"batch",rows:a,size:h.length,type:"viewport-update"}),this.lastRangeServed={from:u(this,P).from,to:Math.min(u(this,P).to,u(this,P).from+a.length)}}}get columns(){return u(this,b).columns}set columns(e){let s=Vs(this.config.columns,e);if(s.length>0){let r=Bs(this.columnDescriptors,s,n=>n.name);console.log("columnsWithoutDescriptors",{columnsWithoutDescriptors:r})}g(this,N,Ee(e)),this.dataIndices=he(u(this,N),this.dataMap),this.config={...u(this,b),columns:e}}get aggregations(){return u(this,b).aggregations}set aggregations(e){var n;g(this,b,{...u(this,b),aggregations:e});let s=(n=this.processedData)!=null?n:u(this,D),r=u(this,D);Ae(e,s,u(this,b).groupBy,r,u(this,N),this.groupMap),this.setRange(Ct(u(this,P)),!0),this.emit("config",u(this,b))}get sort(){return u(this,b).sort}set sort(e){Q==null||Q(`sort ${JSON.stringify(e)}`),this.config={...u(this,b),sort:e}}get filter(){return u(this,b).filter}set filter(e){Q==null||Q(`filter ${JSON.stringify(e)}`),this.config={...u(this,b),filter:e}}get groupBy(){return u(this,b).groupBy}set groupBy(e){this.config={...u(this,b),groupBy:e}}get title(){return u(this,bt)}set title(e){g(this,bt,e)}get _clientCallback(){return this.clientCallback}createLink({parentVpId:e,link:{fromColumn:s,toColumn:r}}){console.log("create link",{parentVpId:e,fromColumn:s,toColumn:r})}removeLink(){console.log("remove link")}findRow(e){let s=u(this,D)[e];if(s)return s;throw`no row found for key ${e}`}applyEdit(e,s,r){return console.log(`ArrayDataSource applyEdit ${e[0]} ${s} ${r}`),Promise.resolve(!0)}async menuRpcCall(e){return new Promise(s=>{let{type:r}=e;switch(r){case"VP_EDIT_CELL_RPC":break;default:s(void 0)}})}};N=new WeakMap,b=new WeakMap,D=new WeakMap,Qt=new WeakMap,P=new WeakMap,Pt=new WeakMap,zt=new WeakMap,z=new WeakMap,bt=new WeakMap;import{EventEmitter as Xs,isSelected as Ys,jsonToDataSourceRows as $e,KeySet as Ks,metadataKeys as Js,uuid as je,vanillaConfig as Zs}from"@vuu-ui/vuu-utils";var qs={columns:[],key:"",table:{module:"",table:""}},{DEPTH:lt,IDX:Ue,IS_EXPANDED:Hs,IS_LEAF:tr,KEY:Je,SELECTED:We}=Js,Xe=(o,t)=>{let[e]=o,s=o.slice();return s[1]=t.keyFor(e),s},q,G,I,H,tt,j,Gt,Lt,et,wt,St,Ye=class extends Xs{constructor({aggregations:e,data:s,filter:r,groupBy:n,sort:i,title:l,viewport:h}){super();this.expandedRows=new Set;this.visibleRows=[];C(this,q,[]);C(this,G,Zs);C(this,I,void 0);C(this,H,{filter:""});C(this,tt,[]);C(this,j,{from:0,to:0});C(this,Gt,0);C(this,Lt,0);C(this,et,{sortDefs:[]});C(this,wt,"initialising");C(this,St,void 0);this.keys=new Ks(u(this,j));if(!s)throw Error("JsonDataSource constructor called without data");[this.columnDescriptors,_t(this,I)._]=$e(s),this.visibleRows=u(this,I).filter(a=>a[lt]===0).map((a,f)=>[f,f].concat(a.slice(2))),this.viewport=h||je(),e&&g(this,q,e),this.columnDescriptors&&g(this,G,{...u(this,G),columns:this.columnDescriptors.map(a=>a.name)}),r&&g(this,H,r),n&&g(this,tt,n),i&&g(this,et,i),g(this,St,l)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:je())(),columns:s,aggregations:r,range:n,sort:i,groupBy:l,filter:h},a){var c;this.clientCallback=a,r&&g(this,q,r),s&&g(this,G,{...u(this,G),columns:s}),h&&g(this,H,h),l&&g(this,tt,l),n&&g(this,j,n),i&&g(this,et,i),u(this,wt)==="initialising"&&(this.viewport=e,g(this,wt,"subscribed"),(c=this.clientCallback)==null||c.call(this,{aggregations:u(this,q),type:"subscribed",clientViewportId:this.viewport,columns:u(this,G).columns,filter:u(this,H),groupBy:u(this,tt),range:u(this,j),sort:u(this,et),tableSchema:qs}),this.clientCallback({clientViewportId:this.viewport,mode:"size-only",type:"viewport-update",size:this.visibleRows.length}))}unsubscribe(){console.log("noop")}suspend(){return console.log("noop"),this}resume(){return console.log("noop"),this}disable(){return console.log("noop"),this}enable(){return console.log("noop"),this}set data(e){console.log("set JsonDataSource data"),[this.columnDescriptors,_t(this,I)._]=$e(e),this.visibleRows=u(this,I).filter(s=>s[lt]===0).map((s,r)=>[r,r].concat(s.slice(2))),requestAnimationFrame(()=>{this.sendRowsToClient()})}select(e){var r;let s=[];for(let n of u(this,I)){let{[Ue]:i,[We]:l}=n,h=l===1,a=Ys(e,i);if(a!==h){let f=n.slice();f[We]=a?1:0,u(this,I)[i]=f,s.push(f)}}s.length>0&&((r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"update",type:"viewport-update",rows:s}))}openTreeNode(e){var n;this.expandedRows.add(e),this.visibleRows=Ke(u(this,I),this.expandedRows);let{from:s,to:r}=u(this,j);(n=this.clientCallback)==null||n.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(s,r).map(i=>Xe(i,this.keys)),size:this.visibleRows.length,type:"viewport-update"})}closeTreeNode(e,s=!1){if(this.expandedRows.delete(e),s)for(let r of this.expandedRows.keys())r.startsWith(e)&&this.expandedRows.delete(r);this.visibleRows=Ke(u(this,I),this.expandedRows),this.sendRowsToClient()}get status(){return u(this,wt)}get config(){return u(this,G)}applyConfig(){return!0}get selectedRowsCount(){return u(this,Gt)}get size(){return u(this,Lt)}get range(){return u(this,j)}set range(e){g(this,j,e),this.keys.reset(e),requestAnimationFrame(()=>{this.sendRowsToClient()})}sendRowsToClient(){var r;let{from:e,to:s}=u(this,j);(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(e,s).map(n=>Xe(n,this.keys)),size:this.visibleRows.length,type:"viewport-update"})}get columns(){return u(this,G).columns}set columns(e){g(this,G,{...u(this,G),columns:e})}get aggregations(){return u(this,q)}set aggregations(e){g(this,q,e)}get sort(){return u(this,et)}set sort(e){g(this,et,e)}get filter(){return u(this,H)}set filter(e){g(this,H,e)}get groupBy(){return u(this,tt)}set groupBy(e){g(this,tt,e)}get title(){return u(this,St)}set title(e){g(this,St,e)}createLink({parentVpId:e,link:{fromColumn:s,toColumn:r}}){console.log("create link",{parentVpId:e,fromColumn:s,toColumn:r})}removeLink(){console.log("remove link")}async menuRpcCall(e){console.log("rmenuRpcCall",{rpcRequest:e})}applyEdit(e,s,r){return console.log(`ArrayDataSource applyEdit ${e.join(",")} ${s} ${r}`),Promise.resolve(!0)}getChildRows(e){let s=u(this,I).find(r=>r[Je]===e);if(s){let{[Ue]:r,[lt]:n}=s,i=r+1,l=[];do{let{[lt]:h}=u(this,I)[i];if(h===n+1)l.push(u(this,I)[i]);else if(h<=n)break;i+=1}while(i<u(this,I).length);return l}else console.warn(`JsonDataSource getChildRows row not found for key ${e}`);return[]}getRowsAtDepth(e,s=!0){return(s?this.visibleRows:u(this,I)).filter(n=>n[lt]===e)}};q=new WeakMap,G=new WeakMap,I=new WeakMap,H=new WeakMap,tt=new WeakMap,j=new WeakMap,Gt=new WeakMap,Lt=new WeakMap,et=new WeakMap,wt=new WeakMap,St=new WeakMap;function Ke(o,t){let e=[],s={value:0};for(let r=0;r<o.length;r++){let n=o[r],{[lt]:i,[Je]:l,[tr]:h}=n,a=t.has(l);if(e.push(er(n,s,a)),!h&&!a)do r+=1;while(r<o.length-1&&o[r+1][lt]>i)}return e}var er=(o,t,e)=>{let s=o.slice();return s[0]=t.value,s[1]=t.value,e&&(s[Hs]=!0),t.value+=1,s};export{_e as ArrayDataSource,Ye as JsonDataSource};
|
|
1
|
+
var ge=(o,t,e)=>{if(!t.has(o))throw TypeError("Cannot "+e)};var u=(o,t,e)=>(ge(o,t,"read from private field"),e?e.call(o):t.get(o)),R=(o,t,e)=>{if(t.has(o))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(o):t.set(o,e)},g=(o,t,e,s)=>(ge(o,t,"write to private field"),s?s.call(o,e):t.set(o,e),e);var _t=(o,t,e,s)=>({set _(r){g(o,t,r,e)},get _(){return u(o,t,s)}});var Ze=0,St=class{constructor(t,e){this.from=t,this.to=e}},x=class{constructor(t={}){this.id=Ze++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=E.match(t)),e=>{let s=t(e);return s===void 0?null:[this,s]}}};x.closedBy=new x({deserialize:o=>o.split(" ")});x.openedBy=new x({deserialize:o=>o.split(" ")});x.group=new x({deserialize:o=>o.split(" ")});x.contextHash=new x({perNode:!0});x.lookAhead=new x({perNode:!0});x.mounted=new x({perNode:!0});var qe=Object.create(null),E=class o{constructor(t,e,s,r=0){this.name=t,this.props=e,this.id=s,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):qe,s=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),r=new o(t.name||"",e,t.id,s);if(t.props){for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}}return r}prop(t){return this.props[t.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(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(x.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let s in t)for(let r of s.split(" "))e[r]=t[s];return s=>{for(let r=s.prop(x.group),n=-1;n<(r?r.length:0);n++){let i=e[n<0?s.name:r[n]];if(i)return i}}}};E.none=new E("",Object.create(null),0,8);var At=class o{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let s of this.types){let r=null;for(let n of t){let i=n(s);i&&(r||(r=Object.assign({},s.props)),r[i[0].id]=i[1])}e.push(r?new E(s.name,r,s.id,s.flags):s)}return new o(e)}},vt=new WeakMap,me=new WeakMap,A;(function(o){o[o.ExcludeBuffers=1]="ExcludeBuffers",o[o.IncludeAnonymous=2]="IncludeAnonymous",o[o.IgnoreMounts=4]="IgnoreMounts",o[o.IgnoreOverlays=8]="IgnoreOverlays"})(A||(A={}));var V=class o{constructor(t,e,s,r,n){if(this.type=t,this.children=e,this.positions=s,this.length=r,this.props=null,n&&n.length){this.props=Object.create(null);for(let[i,l]of n)this.props[typeof i=="number"?i:i.id]=l}}toString(){let t=this.prop(x.mounted);if(t&&!t.overlay)return t.tree.toString();let e="";for(let s of this.children){let r=s.toString();r&&(e&&(e+=","),e+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new ct(this.topNode,t)}cursorAt(t,e=0,s=0){let r=vt.get(this)||this.topNode,n=new ct(r);return n.moveTo(t,e),vt.set(this,n._tree),n}get topNode(){return new nt(this,0,0,null)}resolve(t,e=0){let s=ft(vt.get(this)||this.topNode,t,e,!1);return vt.set(this,s),s}resolveInner(t,e=0){let s=ft(me.get(this)||this.topNode,t,e,!0);return me.set(this,s),s}iterate(t){let{enter:e,leave:s,from:r=0,to:n=this.length}=t,i=t.mode||0,l=(i&A.IncludeAnonymous)>0;for(let h=this.cursor(i|A.IncludeAnonymous);;){let a=!1;if(h.from<=n&&h.to>=r&&(!l&&h.type.isAnonymous||e(h)!==!1)){if(h.firstChild())continue;a=!0}for(;a&&s&&(l||!h.type.isAnonymous)&&s(h),!h.nextSibling();){if(!h.parent())return;a=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Xt(E.none,this.children,this.positions,0,this.children.length,0,this.length,(e,s,r)=>new o(this.type,e,s,r,this.propValues),t.makeTree||((e,s,r)=>new o(E.none,e,s,r)))}static build(t){return He(t)}};V.empty=new V(E.none,[],[],0);var $t=class o{constructor(t,e){this.buffer=t,this.index=e}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 o(this.buffer,this.index)}},it=class o{constructor(t,e,s){this.buffer=t,this.length=e,this.set=s}get type(){return E.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],s=this.buffer[t+3],r=this.set.types[e],n=r.name;if(/\W/.test(n)&&!r.isError&&(n=JSON.stringify(n)),t+=4,s==t)return n;let i=[];for(;t<s;)i.push(this.childString(t)),t=this.buffer[t+3];return n+"("+i.join(",")+")"}findChild(t,e,s,r,n){let{buffer:i}=this,l=-1;for(let h=t;h!=e&&!(we(n,r,i[h+1],i[h+2])&&(l=h,s>0));h=i[h+3]);return l}slice(t,e,s){let r=this.buffer,n=new Uint16Array(e-t),i=0;for(let l=t,h=0;l<e;){n[h++]=r[l++],n[h++]=r[l++]-s;let a=n[h++]=r[l++]-s;n[h++]=r[l++]-t,i=Math.max(i,a)}return new o(n,i,this.set)}};function we(o,t,e,s){switch(o){case-2:return e<t;case-1:return s>=t&&e<t;case 0:return e<t&&s>t;case 1:return e<=t&&s>t;case 2:return s>t;case 4:return!0}}function ye(o,t){let e=o.childBefore(t);for(;e;){let s=e.lastChild;if(!s||s.to!=e.to)break;s.type.isError&&s.from==s.to?(o=e,e=s.prevSibling):e=s}return o}function ft(o,t,e,s){for(var r;o.from==o.to||(e<1?o.from>=t:o.from>t)||(e>-1?o.to<=t:o.to<t);){let i=!s&&o instanceof nt&&o.index<0?null:o.parent;if(!i)return o;o=i}let n=s?0:A.IgnoreOverlays;if(s)for(let i=o,l=i.parent;l;i=l,l=i.parent)i instanceof nt&&i.index<0&&((r=l.enter(t,e,n))===null||r===void 0?void 0:r.from)!=i.from&&(o=l);for(;;){let i=o.enter(t,e,n);if(!i)return o;o=i}}var nt=class o{constructor(t,e,s,r){this._tree=t,this.from=e,this.index=s,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,s,r,n=0){for(let i=this;;){for(let{children:l,positions:h}=i._tree,a=e>0?l.length:-1;t!=a;t+=e){let f=l[t],c=h[t]+i.from;if(we(r,s,c,c+f.length)){if(f instanceof it){if(n&A.ExcludeBuffers)continue;let p=f.findChild(0,f.buffer.length,e,s-c,r);if(p>-1)return new kt(new jt(i,f,t,c),null,p)}else if(n&A.IncludeAnonymous||!f.type.isAnonymous||Ut(f)){let p;if(!(n&A.IgnoreMounts)&&f.props&&(p=f.prop(x.mounted))&&!p.overlay)return new o(p.tree,c,t,i);let d=new o(f,c,t,i);return n&A.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(e<0?f.children.length-1:0,e,s,r)}}}if(n&A.IncludeAnonymous||!i.type.isAnonymous||(i.index>=0?t=i.index+e:t=e<0?-1:i._parent._tree.children.length,i=i._parent,!i))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(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,s=0){let r;if(!(s&A.IgnoreOverlays)&&(r=this._tree.prop(x.mounted))&&r.overlay){let n=t-this.from;for(let{from:i,to:l}of r.overlay)if((e>0?i<=n:i<n)&&(e<0?l>=n:l>n))return new o(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,s)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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}cursor(t=0){return new ct(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return ft(this,t,e,!1)}resolveInner(t,e=0){return ft(this,t,e,!0)}enterUnfinishedNodesBefore(t){return ye(this,t)}getChild(t,e=null,s=null){let r=Tt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Tt(this,t,e,s)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return It(this,t)}};function Tt(o,t,e,s){let r=o.cursor(),n=[];if(!r.firstChild())return n;if(e!=null){for(;!r.type.is(e);)if(!r.nextSibling())return n}for(;;){if(s!=null&&r.type.is(s))return n;if(r.type.is(t)&&n.push(r.node),!r.nextSibling())return s==null?n:[]}}function It(o,t,e=t.length-1){for(let s=o.parent;e>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(t[e]&&t[e]!=s.name)return!1;e--}}return!0}var jt=class{constructor(t,e,s,r){this.parent=t,this.buffer=e,this.index=s,this.start=r}},kt=class o{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(t,e,s){this.context=t,this._parent=e,this.index=s,this.type=t.buffer.set.types[t.buffer.buffer[s]]}child(t,e,s){let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,s);return n<0?null:new o(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,s=0){if(s&A.ExcludeBuffers)return null;let{buffer:r}=this.context,n=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return n<0?null:new o(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new o(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new o(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new ct(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:s}=this.context,r=this.index+4,n=s.buffer[this.index+3];if(n>r){let i=s.buffer[this.index+1];t.push(s.slice(r,n,i)),e.push(0)}return new V(this.type,t,e,this.to-this.from)}resolve(t,e=0){return ft(this,t,e,!1)}resolveInner(t,e=0){return ft(this,t,e,!0)}enterUnfinishedNodesBefore(t){return ye(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,s=null){let r=Tt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Tt(this,t,e,s)}get node(){return this}matchContext(t){return It(this,t)}},ct=class{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof nt)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let s=t._parent;s;s=s._parent)this.stack.unshift(s.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:s,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=s+r.buffer[t+1],this.to=s+r.buffer[t+2],!0}yield(t){return t?t instanceof nt?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,s){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,s,this.mode));let{buffer:r}=this.buffer,n=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,s);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,s=this.mode){return this.buffer?s&A.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&A.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&A.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,s=this.stack.length-1;if(t<0){let r=s<0?0:this.stack[s]+4;if(this.index!=r)return this.yieldBuf(e.findChild(r,this.index,-1,0,4))}else{let r=e.buffer[this.index+3];if(r<(s<0?e.buffer.length:e.buffer[this.stack[s]+3]))return this.yieldBuf(r)}return s<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,s,{buffer:r}=this;if(r){if(t>0){if(this.index<r.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(r.buffer.buffer[n+3]<this.index)return!1;({index:e,parent:s}=r)}else({index:e,_parent:s}=this._tree);for(;s;{index:e,_parent:s}=s)if(e>-1)for(let n=e+t,i=t<0?-1:s._tree.children.length;n!=i;n+=t){let l=s._tree.children[n];if(this.mode&A.IncludeAnonymous||l instanceof it||!l.type.isAnonymous||Ut(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,s=0;if(t&&t.context==this.buffer)t:for(let r=this.index,n=this.stack.length;n>=0;){for(let i=t;i;i=i._parent)if(i.index==r){if(r==this.index)return i;e=i,s=n+1;break t}r=this.stack[--n]}for(let r=s;r<this.stack.length;r++)e=new kt(this.buffer,e,this.stack[r]);return this.bufferNode=new kt(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let s=0;;){let r=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){s++;continue}this.type.isAnonymous||(r=!0)}for(;r&&e&&e(this),r=this.type.isAnonymous,!this.nextSibling();){if(!s)return;this.parent(),s--,r=!0}}}matchContext(t){if(!this.buffer)return It(this.node,t);let{buffer:e}=this.buffer,{types:s}=e.set;for(let r=t.length-1,n=this.stack.length-1;r>=0;n--){if(n<0)return It(this.node,t,r);let i=s[e.buffer[this.stack[n]]];if(!i.isAnonymous){if(t[r]&&t[r]!=i.name)return!1;r--}}return!0}};function Ut(o){return o.children.some(t=>t instanceof it||!t.type.isAnonymous||Ut(t))}function He(o){var t;let{buffer:e,nodeSet:s,maxBufferLength:r=1024,reused:n=[],minRepeatType:i=s.types.length}=o,l=Array.isArray(e)?new $t(e,e.length):e,h=s.types,a=0,f=0;function c(C,O,m,S,T){let{id:k,start:y,end:v,size:F}=l,L=f;for(;F<0;)if(l.next(),F==-1){let J=n[k];m.push(J),S.push(y-C);return}else if(F==-3){a=k;return}else if(F==-4){f=k;return}else throw new RangeError(`Unrecognized record size: ${F}`);let at=h[k],K,W,pe=y-C;if(v-y<=r&&(W=Y(l.pos-O,T))){let J=new Uint16Array(W.size-W.skip),_=l.pos-W.size,U=J.length;for(;l.pos>_;)U=lt(W.start,J,U);K=new it(J,v-W.start,s),pe=W.start-C}else{let J=l.pos-F;l.next();let _=[],U=[],rt=k>=i?k:-1,ut=0,Ot=v;for(;l.pos>J;)rt>=0&&l.id==rt&&l.size>=0?(l.end<=Ot-r&&(d(_,U,y,ut,l.end,Ot,rt,L),ut=_.length,Ot=l.end),l.next()):c(y,J,_,U,rt);if(rt>=0&&ut>0&&ut<_.length&&d(_,U,y,ut,y,Ot,rt,L),_.reverse(),U.reverse(),rt>-1&&ut>0){let de=p(at);K=Xt(at,_,U,0,_.length,0,v-y,de,de)}else K=w(at,_,U,v-y,L-v)}m.push(K),S.push(pe)}function p(C){return(O,m,S)=>{let T=0,k=O.length-1,y,v;if(k>=0&&(y=O[k])instanceof V){if(!k&&y.type==C&&y.length==S)return y;(v=y.prop(x.lookAhead))&&(T=m[k]+y.length+v)}return w(C,O,m,S,T)}}function d(C,O,m,S,T,k,y,v){let F=[],L=[];for(;C.length>S;)F.push(C.pop()),L.push(O.pop()+m-T);C.push(w(s.types[y],F,L,k-T,v-k)),O.push(T-m)}function w(C,O,m,S,T=0,k){if(a){let y=[x.contextHash,a];k=k?[y].concat(k):[y]}if(T>25){let y=[x.lookAhead,T];k=k?[y].concat(k):[y]}return new V(C,O,m,S,k)}function Y(C,O){let m=l.fork(),S=0,T=0,k=0,y=m.end-r,v={size:0,start:0,skip:0};t:for(let F=m.pos-C;m.pos>F;){let L=m.size;if(m.id==O&&L>=0){v.size=S,v.start=T,v.skip=k,k+=4,S+=4,m.next();continue}let at=m.pos-L;if(L<0||at<F||m.start<y)break;let K=m.id>=i?4:0,W=m.start;for(m.next();m.pos>at;){if(m.size<0)if(m.size==-3)K+=4;else break t;else m.id>=i&&(K+=4);m.next()}T=W,S+=L,k+=K}return(O<0||S==C)&&(v.size=S,v.start=T,v.skip=k),v.size>4?v:void 0}function lt(C,O,m){let{id:S,start:T,end:k,size:y}=l;if(l.next(),y>=0&&S<i){let v=m;if(y>4){let F=l.pos-(y-4);for(;l.pos>F;)m=lt(C,O,m)}O[--m]=v,O[--m]=k-C,O[--m]=T-C,O[--m]=S}else y==-3?a=S:y==-4&&(f=S);return m}let st=[],ht=[];for(;l.pos>0;)c(o.start||0,o.bufferStart||0,st,ht,-1);let M=(t=o.length)!==null&&t!==void 0?t:st.length?ht[0]+st[0].length:0;return new V(h[o.topID],st.reverse(),ht.reverse(),M)}var be=new WeakMap;function Dt(o,t){if(!o.isAnonymous||t instanceof it||t.type!=o)return 1;let e=be.get(t);if(e==null){e=1;for(let s of t.children){if(s.type!=o||!(s instanceof V)){e=1;break}e+=Dt(o,s)}be.set(t,e)}return e}function Xt(o,t,e,s,r,n,i,l,h){let a=0;for(let w=s;w<r;w++)a+=Dt(o,t[w]);let f=Math.ceil(a*1.5/8),c=[],p=[];function d(w,Y,lt,st,ht){for(let M=lt;M<st;){let C=M,O=Y[M],m=Dt(o,w[M]);for(M++;M<st;M++){let S=Dt(o,w[M]);if(m+S>=f)break;m+=S}if(M==C+1){if(m>f){let S=w[C];d(S.children,S.positions,0,S.children.length,Y[C]+ht);continue}c.push(w[C])}else{let S=Y[M-1]+w[M-1].length-O;c.push(Xt(o,w,Y,C,M,O,S,null,h))}p.push(O+ht-n)}}return d(t,e,s,r,0),(l||h)(c,p,i)}var Nt=class{startParse(t,e,s){return typeof t=="string"&&(t=new Wt(t)),s=s?s.length?s.map(r=>new St(r.from,r.to)):[new St(0,0)]:[new St(0,t.length)],this.createParse(t,e||[],s)}parse(t,e,s){let r=this.startParse(t,e,s);for(;;){let n=r.advance();if(n)return n}}},Wt=class{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}};var ir=new x({perNode:!0});var Kt=class o{constructor(t,e,s,r,n,i,l,h,a,f=0,c){this.p=t,this.stack=e,this.state=s,this.reducePos=r,this.pos=n,this.score=i,this.buffer=l,this.bufferBase=h,this.curContext=a,this.lookAhead=f,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let r=t.parser.context;return new o(t,[],e,s,s,0,[],0,r?new Mt(r,r.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,r=t&65535,{parser:n}=this.p,i=n.dynamicPrecedence(r);if(i&&(this.score+=i),s==0){this.pushState(n.getGoto(this.state,r,!0),this.reducePos),r<n.minRepeatTerm&&this.storeNode(r,this.reducePos,this.reducePos,4,!0),this.reduceContext(r,this.reducePos);return}let l=this.stack.length-(s-1)*3-(t&262144?6:0),h=l?this.stack[l-2]:this.p.ranges[0].from,a=this.reducePos-h;a>=2e3&&!(!((e=this.p.parser.nodeSet.types[r])===null||e===void 0)&&e.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=a):this.p.lastBigReductionSize<a&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=a));let f=l?this.stack[l-1]:0,c=this.bufferBase+this.buffer.length-f;if(r<n.minRepeatTerm||t&131072){let p=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(r,h,p,c+4,!0)}if(t&262144)this.state=this.stack[l];else{let p=this.stack[l-3];this.state=n.getGoto(p,r,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(r,h)}storeNode(t,e,s,r=4,n=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let i=this,l=this.buffer.length;if(l==0&&i.parent&&(l=i.bufferBase-i.parent.bufferBase,i=i.parent),l>0&&i.buffer[l-4]==0&&i.buffer[l-1]>-1){if(e==s)return;if(i.buffer[l-2]>=e){i.buffer[l-2]=s;return}}}if(!n||this.pos==s)this.buffer.push(t,e,s,r);else{let i=this.buffer.length;if(i>0&&this.buffer[i-4]!=0)for(;i>0&&this.buffer[i-2]>s;)this.buffer[i]=this.buffer[i-4],this.buffer[i+1]=this.buffer[i-3],this.buffer[i+2]=this.buffer[i-2],this.buffer[i+3]=this.buffer[i-1],i-=4,r>4&&(r-=4);this.buffer[i]=t,this.buffer[i+1]=e,this.buffer[i+2]=s,this.buffer[i+3]=r}}shift(t,e,s){let r=this.pos;if(t&131072)this.pushState(t&65535,this.pos);else if(t&262144)this.pos=s,this.shiftContext(e,r),e<=this.p.parser.maxNode&&this.buffer.push(e,r,s,4);else{let n=t,{parser:i}=this.p;(s>this.pos||e<=i.maxNode)&&(this.pos=s,i.stateFlag(n,1)||(this.reducePos=s)),this.pushState(n,r),this.shiftContext(e,r),e<=i.maxNode&&this.buffer.push(e,r,s,4)}}apply(t,e,s){t&65536?this.reduce(t):this.shift(t,e,s)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let r=this.pos;this.reducePos=this.pos=r+t.length,this.pushState(e,r),this.buffer.push(s,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),r=t.bufferBase+e;for(;t&&r==t.bufferBase;)t=t.parent;return new o(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,r,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Jt(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(s==0)return!1;if(!(s&65536))return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let r=[];for(let n=0,i;n<e.length;n+=2)(i=e[n+1])!=this.state&&this.p.parser.hasAction(i,t)&&r.push(e[n],i);if(this.stack.length<120)for(let n=0;r.length<8&&n<e.length;n+=2){let i=e[n+1];r.some((l,h)=>h&1&&l==i)||r.push(e[n],i)}e=r}let s=[];for(let r=0;r<e.length&&s.length<4;r+=2){let n=e[r+1];if(n==this.state)continue;let i=this.split();i.pushState(n,this.pos),i.storeNode(0,i.pos,i.pos,4,!0),i.shiftContext(e[r],this.pos),i.score-=200,s.push(i)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if(!(e&65536))return!1;if(!t.validAction(this.state,e)){let s=e>>19,r=e&65535,n=this.stack.length-s*3;if(n<0||t.getGoto(this.stack[n],r,!1)<0){let i=this.findForcedReduction();if(i==null)return!1;e=i}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(r,n)=>{if(!e.includes(r))return e.push(r),t.allActions(r,i=>{if(!(i&393216))if(i&65536){let l=(i>>19)-n;if(l>1){let h=i&65535,a=this.stack.length-l*3;if(a>=0&&t.getGoto(this.stack[a],h,!1)>=0)return l<<19|65536|h}}else{let l=s(i,n+1);if(l!=null)return l}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new Mt(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){t>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=t)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},Mt=class{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}},Se;(function(o){o[o.Insert=200]="Insert",o[o.Delete=190]="Delete",o[o.Reduce=100]="Reduce",o[o.MaxNext=4]="MaxNext",o[o.MaxInsertStackDepth=300]="MaxInsertStackDepth",o[o.DampenInsertStackDepth=120]="DampenInsertStackDepth",o[o.MinBigReduction=2e3]="MinBigReduction"})(Se||(Se={}));var Jt=class{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,s=t>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let r=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=r}},Zt=class o{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new o(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}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]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new o(this.stack,this.pos,this.index)}};function xt(o,t=Uint16Array){if(typeof o!="string")return o;let e=null;for(let s=0,r=0;s<o.length;){let n=0;for(;;){let i=o.charCodeAt(s++),l=!1;if(i==126){n=65535;break}i>=92&&i--,i>=34&&i--;let h=i-32;if(h>=46&&(h-=46,l=!0),n+=h,l)break;n*=46}e?e[r++]=n:e=new t(n)}return e}var pt=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},ke=new pt,qt=class{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=ke,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,r=this.rangeIndex,n=this.pos+t;for(;n<s.from;){if(!r)return null;let i=this.ranges[--r];n-=s.from-i.to,s=i}for(;e<0?n>s.to:n>=s.to;){if(r==this.ranges.length-1)return null;let i=this.ranges[++r];n+=i.from-s.to,s=i}return n}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,s,r;if(e>=0&&e<this.chunk.length)s=this.pos+t,r=this.chunk.charCodeAt(e);else{let n=this.resolveOffset(t,1);if(n==null)return-1;if(s=n,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let i=this.rangeIndex,l=this.range;for(;l.to<=s;)l=this.ranges[++i];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-s)),r=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),r}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=ke,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let r of this.ranges){if(r.from>=e)break;r.to>t&&(s+=this.input.read(Math.max(r.from,t),Math.min(r.to,e)))}return s}},Z=class{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;De(this.data,t,e,this.id,s.data,s.tokenPrecTable)}};Z.prototype.contextual=Z.prototype.fallback=Z.prototype.extend=!1;var Ht=class{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?xt(t):t}token(t,e){let s=t.pos,r=0;for(;;){let n=t.next<0,i=t.resolveOffset(1,1);if(De(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(n||r++,i==null)break;t.reset(i,t.token)}r&&(t.reset(s,t.token),t.acceptToken(this.elseToken,r))}};Ht.prototype.contextual=Z.prototype.fallback=Z.prototype.extend=!1;function De(o,t,e,s,r,n){let i=0,l=1<<s,{dialect:h}=e.p.parser;t:for(;l&o[i];){let a=o[i+1];for(let d=i+3;d<a;d+=2)if((o[d+1]&l)>0){let w=o[d];if(h.allows(w)&&(t.token.value==-1||t.token.value==w||es(w,t.token.value,r,n))){t.acceptToken(w);break}}let f=t.next,c=0,p=o[i+2];if(t.next<0&&p>c&&o[a+p*3-3]==65535&&o[a+p*3-3]==65535){i=o[a+p*3-1];continue t}for(;c<p;){let d=c+p>>1,w=a+d+(d<<1),Y=o[w],lt=o[w+1]||65536;if(f<Y)p=d;else if(f>=lt)c=d+1;else{i=o[w+2],t.advance();continue t}}break}}function xe(o,t,e){for(let s=t,r;(r=o[s])!=65535;s++)if(r==e)return s-t;return-1}function es(o,t,e,s){let r=xe(e,s,t);return r<0||xe(e,s,o)<r}var $=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Yt=null,Ce;(function(o){o[o.Margin=25]="Margin"})(Ce||(Ce={}));function Re(o,t,e){let s=o.cursor(A.IncludeAnonymous);for(s.moveTo(t);;)if(!(e<0?s.childBefore(t):s.childAfter(t)))for(;;){if((e<0?s.to<t:s.from>t)&&!s.type.isError)return e<0?Math.max(0,Math.min(s.to-1,t-25)):Math.min(o.length,Math.max(s.from+1,t+25));if(e<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return e<0?0:o.length}}var te=class{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?Re(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?Re(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let s=this.trees[e],r=this.index[e];if(r==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=s.children[r],i=this.start[e]+s.positions[r];if(i>t)return this.nextStart=i,null;if(n instanceof V){if(i==t){if(i<this.safeFrom)return null;let l=i+n.length;if(l<=this.safeTo){let h=n.prop(x.lookAhead);if(!h||l+h<this.fragment.to)return n}}this.index[e]++,i+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(i),this.index.push(0))}else this.index[e]++,this.nextStart=i+n.length}}},ee=class{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new pt)}getActions(t){let e=0,s=null,{parser:r}=t.p,{tokenizers:n}=r,i=r.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let a=0;a<n.length;a++){if(!(1<<a&i))continue;let f=n[a],c=this.tokens[a];if(!(s&&!f.fallback)&&((f.contextual||c.start!=t.pos||c.mask!=i||c.context!=l)&&(this.updateCachedToken(c,f,t),c.mask=i,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let p=e;if(c.extended>-1&&(e=this.addActions(t,c.extended,c.end,e)),e=this.addActions(t,c.value,c.end,e),!f.extend&&(s=c,e>p))break}}for(;this.actions.length>e;)this.actions.pop();return h&&t.setLookAhead(h),!s&&t.pos==this.stream.end&&(s=new pt,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new pt,{pos:s,p:r}=t;return e.start=s,e.end=Math.min(s+1,r.stream.end),e.value=s==r.stream.end?r.parser.eofTerm:0,e}updateCachedToken(t,e,s){let r=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(r,t),s),t.value>-1){let{parser:n}=s.p;for(let i=0;i<n.specialized.length;i++)if(n.specialized[i]==t.value){let l=n.specializers[i](this.stream.read(t.start,t.end),s);if(l>=0&&s.p.parser.dialect.allows(l>>1)){l&1?t.extended=l>>1:t.value=l>>1;break}}}else t.value=0,t.end=this.stream.clipPos(r+1)}putAction(t,e,s,r){for(let n=0;n<r;n+=3)if(this.actions[n]==t)return r;return this.actions[r++]=t,this.actions[r++]=e,this.actions[r++]=s,r}addActions(t,e,s,r){let{state:n}=t,{parser:i}=t.p,{data:l}=i;for(let h=0;h<2;h++)for(let a=i.stateSlot(n,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=X(l,a+2);else{r==0&&l[a+1]==2&&(r=this.putAction(X(l,a+2),e,s,r));break}l[a]==e&&(r=this.putAction(X(l,a+1),e,s,r))}return r}},Pe;(function(o){o[o.Distance=5]="Distance",o[o.MaxRemainingPerStep=3]="MaxRemainingPerStep",o[o.MinBufferLengthPrune=500]="MinBufferLengthPrune",o[o.ForceReduceLimit=10]="ForceReduceLimit",o[o.CutDepth=15e3]="CutDepth",o[o.CutTo=9e3]="CutTo",o[o.MaxLeftAssociativeReductionCount=300]="MaxLeftAssociativeReductionCount",o[o.MaxStackCount=12]="MaxStackCount"})(Pe||(Pe={}));var se=class{constructor(t,e,s,r){this.parser=t,this.input=e,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new qt(e,r),this.tokens=new ee(t,this.stream),this.topTerm=t.top[1];let{from:n}=r[0];this.stacks=[Kt.start(this,t.top[0],n)],this.fragments=s.length&&this.stream.end-n>t.bufferLength*4?new te(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],r,n;if(this.bigReductionCount>300&&t.length==1){let[i]=t;for(;i.forceReduce()&&i.stack.length&&i.stack[i.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let i=0;i<t.length;i++){let l=t[i];for(;;){if(this.tokens.mainToken=null,l.pos>e)s.push(l);else{if(this.advanceStack(l,s,t))continue;{r||(r=[],n=[]),r.push(l);let h=this.tokens.getMainToken(l);n.push(h.value,h.end)}}break}}if(!s.length){let i=r&&ss(r);if(i)return this.stackToTree(i);if(this.parser.strict)throw $&&r&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&r){let i=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,n,s);if(i)return this.stackToTree(i.forceAll())}if(this.recovering){let i=this.recovering==1?1:this.recovering*3;if(s.length>i)for(s.sort((l,h)=>h.score-l.score);s.length>i;)s.pop();s.some(l=>l.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let i=0;i<s.length-1;i++){let l=s[i];for(let h=i+1;h<s.length;h++){let a=s[h];if(l.sameState(a)||l.buffer.length>500&&a.buffer.length>500)if((l.score-a.score||l.buffer.length-a.buffer.length)>0)s.splice(h--,1);else{s.splice(i--,1);continue t}}}s.length>12&&s.splice(12,s.length-12)}this.minStackPos=s[0].pos;for(let i=1;i<s.length;i++)s[i].pos<this.minStackPos&&(this.minStackPos=s[i].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,s){let r=t.pos,{parser:n}=this,i=$?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&r>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,f=a?t.curContext.hash:0;for(let c=this.fragments.nodeAt(r);c;){let p=this.parser.nodeSet.types[c.type.id]==c.type?n.getGoto(t.state,c.type.id):-1;if(p>-1&&c.length&&(!a||(c.prop(x.contextHash)||0)==f))return t.useNode(c,p),$&&console.log(i+this.stackID(t)+` (via reuse of ${n.getName(c.type.id)})`),!0;if(!(c instanceof V)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof V&&c.positions[0]==0)c=d;else break}}let l=n.stateSlot(t.state,4);if(l>0)return t.reduce(l),$&&console.log(i+this.stackID(t)+` (via always-reduce ${n.getName(l&65535)})`),!0;if(t.stack.length>=15e3)for(;t.stack.length>9e3&&t.forceReduce(););let h=this.tokens.getActions(t);for(let a=0;a<h.length;){let f=h[a++],c=h[a++],p=h[a++],d=a==h.length||!s,w=d?t:t.split();if(w.apply(f,c,p),$&&console.log(i+this.stackID(w)+` (via ${f&65536?`reduce of ${n.getName(f&65535)}`:"shift"} for ${n.getName(c)} @ ${r}${w==t?"":", split"})`),d)return!0;w.pos>r?e.push(w):s.push(w)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return Oe(t,e),!0}}runRecovery(t,e,s){let r=null,n=!1;for(let i=0;i<t.length;i++){let l=t[i],h=e[i<<1],a=e[(i<<1)+1],f=$?this.stackID(l)+" -> ":"";if(l.deadEnd&&(n||(n=!0,l.restart(),$&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,s))))continue;let c=l.split(),p=f;for(let d=0;c.forceReduce()&&d<10&&($&&console.log(p+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,s));d++)$&&(p=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))$&&console.log(f+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,s);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),$&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),Oe(l,s)):(!r||r.score<l.score)&&(r=l)}return r}stackToTree(t){return t.close(),V.build({buffer:Zt.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(Yt||(Yt=new WeakMap)).get(t);return e||Yt.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}};function Oe(o,t){for(let e=0;e<t.length;e++){let s=t[e];if(s.pos==o.pos&&s.sameState(o)){t[e].score<o.score&&(t[e]=o);return}}t.push(o)}var re=class{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}};var Ft=class o extends Nt{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let l=0;l<t.repeatNodeCount;l++)e.push("");let s=Object.keys(t.topRules).map(l=>t.topRules[l][1]),r=[];for(let l=0;l<e.length;l++)r.push([]);function n(l,h,a){r[l].push([h,h.deserialize(String(a))])}if(t.nodeProps)for(let l of t.nodeProps){let h=l[0];typeof h=="string"&&(h=x[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)n(f,h,l[a++]);else{let c=l[a+-f];for(let p=-f;p>0;p--)n(l[a++],h,c);a++}}}this.nodeSet=new At(e.map((l,h)=>E.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:r[h],top:s.indexOf(h)>-1,error:h==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(h)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=1024;let i=xt(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(ve),this.states=xt(t.states,Uint32Array),this.data=xt(t.stateData),this.goto=xt(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new Z(i,l):l),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let r=new se(this,t,e,s);for(let n of this.wrappers)r=n(r,t,e,s);return r}getGoto(t,e,s=!1){let r=this.goto;if(e>=r[0])return-1;for(let n=r[e+1];;){let i=r[n++],l=i&1,h=r[n++];if(l&&s)return h;for(let a=n+(i>>1);n<a;n++)if(r[n]==t)return h;if(l)return-1}}hasAction(t,e){let s=this.data;for(let r=0;r<2;r++)for(let n=this.stateSlot(t,r?2:1),i;;n+=3){if((i=s[n])==65535)if(s[n+1]==1)i=s[n=X(s,n+2)];else{if(s[n+1]==2)return X(s,n+2);break}if(i==e||i==0)return X(s,n+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,s=>s==e?!0:null)}allActions(t,e){let s=this.stateSlot(t,4),r=s?e(s):void 0;for(let n=this.stateSlot(t,1);r==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=X(this.data,n+2);else break;r=e(X(this.data,n+1))}return r}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=X(this.data,s+2);else break;if(!(this.data[s+2]&1)){let r=this.data[s+1];e.some((n,i)=>i&1&&n==r)||e.push(this.data[s],r)}}return e}configure(t){let e=Object.assign(Object.create(o.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(s=>{let r=t.tokenizers.find(n=>n.from==s);return r?r.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,r)=>{let n=t.specializers.find(l=>l.from==s.external);if(!n)return s;let i=Object.assign(Object.assign({},s),{external:n.to});return e.specializers[r]=ve(i),i})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let n of t.split(" ")){let i=e.indexOf(n);i>=0&&(s[i]=!0)}let r=null;for(let n=0;n<e.length;n++)if(!s[n])for(let i=this.dialects[e[n]],l;(l=this.data[i++])!=65535;)(r||(r=new Uint8Array(this.maxTerm+1)))[l]=1;return new re(t,s,r)}static deserialize(t){return new o(t)}};function X(o,t){return o[t]|o[t+1]<<16}function ss(o){let t=null;for(let e of o){let s=e.p.stoppedAt;(e.pos==e.p.stream.end||s!=null&&e.pos>s)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function ve(o){if(o.external){let t=o.extend?1:0;return(e,s)=>o.external(e,s)<<1|t}return o.get}var ie=Ft.deserialize({version:14,states:"%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",stateData:"#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",goto:"#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",nodeNames:"\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",maxTerm:39,skippedNodes:[0],repeatNodeCount:1,tokenData:"6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",tokenizers:[0,1],topRules:{Filter:[0,1]},tokenPrec:0});import{isMultiClauseFilter as Ct,isMultiValueFilter as rs,isSingleValueFilter as is}from"@vuu-ui/vuu-utils";var B,ne=class{constructor(){R(this,B,void 0)}setFilterCombinatorOp(t,e=u(this,B)){Ct(e)&&e.op===t||g(this,B,{op:t,filters:[u(this,B)]})}add(t){if(u(this,B)===void 0)g(this,B,t);else if(Ct(u(this,B)))u(this,B).filters.push(t);else throw Error("Invalid filter passed to FilterExpression")}setColumn(t,e=u(this,B)){if(Ct(e)){let s=e.filters.at(-1);s&&this.setColumn(t,s)}else e&&(e.column=t)}setOp(t,e=u(this,B)){if(Ct(e)){let s=e.filters.at(-1);s&&this.setOp(t,s)}else e&&(e.op=t)}setValue(t,e=u(this,B)){var s;if(Ct(e)){let r=e.filters.at(-1);r&&this.setValue(t,r)}else rs(e)?((s=e.values)!=null||(e.values=[]),e.values.push(t)):is(e)&&(e.value=t)}toJSON(t=u(this,B)){return this.name?{...t,name:this.name}:t}};B=new WeakMap;var oe=(o,t)=>{let e=new ne,s=o.cursor();do{let{name:r,from:n,to:i}=s;switch(r){case"ColumnValueExpression":e.add({});break;case"ColumnSetExpression":e.add({op:"in"});break;case"Or":case"And":e.setFilterCombinatorOp(t.substring(n,i));break;case"Column":e.setColumn(t.substring(n,i));break;case"Operator":e.setOp(t.substring(n,i));break;case"String":e.setValue(t.substring(n+1,i-1));break;case"Number":e.setValue(parseFloat(t.substring(n,i)));break;case"True":e.setValue(!0);break;case"False":e.setValue(!1);break;case"FilterName":e.name=t.substring(n,i);break;default:}}while(s.next());return e.toJSON()};var ns=ie.configure({strict:!0}),dt=o=>{let t=ns.parse(o);return oe(t,o)};function Vt(o,t){switch(t.op){case"in":return os(o,t);case"=":return ls(o,t);case">":return hs(o,t);case">=":return as(o,t);case"<":return us(o,t);case"<=":return fs(o,t);case"ends":return cs(o,t);case"starts":return ps(o,t);case"and":return ds(o,t);case"or":return gs(o,t);default:return console.log(`unrecognized filter type ${t.op}`),()=>!0}}var os=(o,t)=>e=>t.values.indexOf(e[o[t.column]])!==-1,ls=(o,t)=>e=>e[o[t.column]]===t.value,hs=(o,t)=>e=>e[o[t.column]]>t.value,as=(o,t)=>e=>e[o[t.column]]>=t.value,us=(o,t)=>e=>e[o[t.column]]<t.value,fs=(o,t)=>e=>e[o[t.column]]<=t.value,cs=(o,t)=>{let e=t.value;if(typeof e!="string")throw Error("string filter applied to value of wrong type");return s=>{let r=s[o[t.column]];if(typeof r!="string")throw Error("string filter applied to value of wrong type");return r.toLowerCase().endsWith(e.toLowerCase())}},ps=(o,t)=>{let e=t.value;if(typeof e!="string")throw Error("string filter applied to value of wrong type");return s=>{let r=s[o[t.column]];if(typeof r!="string")throw Error("string filter applied to value of wrong type");return r.toLowerCase().startsWith(e.toLowerCase())}},ds=(o,t)=>{let e=t.filters.map(s=>Vt(o,s));return s=>e.every(r=>r(s))};function gs(o,t){let e=t.filters.map(s=>Vt(o,s));return s=>e.some(r=>r(s))}import{buildColumnMap as Ee,configChanged as Fs,EventEmitter as Vs,getAddedItems as Bs,getMissingItems as Es,groupByChanged as Qs,hasFilter as zs,hasGroupBy as Gs,hasSort as Ls,KeySet as _s,logger as $s,metadataKeys as js,NULL_RANGE as Qe,rangeNewItems as Ws,resetRange as Rt,uuid as ze,vanillaConfig as Us,withConfigDefaults as Ge}from"@vuu-ui/vuu-utils";var Ae=(o,t,e,s,r,n)=>{let i=o[o.length-1].aggType,l=e.map(h=>r[h]);switch(i){case 1:return Ie(n,s,r,o,t,l);case 2:return ms(n,s,r,o,t,l);case 3:return Te(n,r,o,t,l);case 4:return ws(n,s,r,o,t,l);case 5:return ys(n,s,r,o,t,l);case 6:return bs(n,s,r,o,t,l)}};function Te(o,t,e,s,r){let n={},i=gt(t,e);function l(h){if(Array.isArray(h))return h.length;{let a=0;for(let f in h)a+=1+l(h[f]);return a}}for(let h in o){let a=l(o[h]);n[h]=a}for(let h=0;h<s.length;h++)for(let a in n)s[h][r[0]]===a&&(s[h][i]=n[a]);return console.log("!!!! targetData",s),console.log("!!!! counts",n),n}function gt(o,t){console.log("!!!! aggregation length",t.length);let e=t[t.length-1].column;return o[e]}function Ie(o,t,e,s,r,n){let i={},l=gt(e,s);function h(a,f,c){if(Array.isArray(a)){let p=0;for(let d of a)p+=Number(f[d][c]);return p}else{let p=0;for(let d in a)p+=h(a[d],f,c);return p}}for(let a in o){console.log(a);let f=Number(h(o[a],t,l));i[a]=f}for(let a=0;a<r.length;a++)for(let f in i)r[a][n[0]]===f&&(r[a][l]=i[f]);return console.log("!!!! targetData",r),console.log("!!!! sums",i),i}function ms(o,t,e,s,r,n){let i={},l=gt(e,s),h=Te(o,e,s,r,n),a=Ie(o,t,e,s,r,n);for(let f in h){let c=0;c=a[f]/h[f],i[f]=c}for(let f=0;f<r.length;f++)for(let c in i)r[f][n[0]]===c&&(r[f][l]=i[c]);return console.log("!!!! targetData",r),console.log("!!!! averages",i),i}function Bt(o,t,e){let s=[];if(Array.isArray(o))for(let r of o)s.push(t[r][e]);else for(let r in o)s.push(...Bt(o[r],t,e));return s}function bs(o,t,e,s,r,n){let i={},l=gt(e,s);for(let h in o){let a=Bt(o[h],t,l),f=[...new Set(a)];i[h]=f}for(let h=0;h<r.length;h++)for(let a in i)r[h][n[0]]===a&&(r[h][l]=i[a]);return i}function ws(o,t,e,s,r,n){let i={},l=gt(e,s);for(let h in o){let a=Bt(o[h],t,l),f=Math.max(...a);i[h]=f}for(let h=0;h<r.length;h++)for(let a in i)r[h][n[0]]===a&&(r[h][l]=i[a]);return i}function ys(o,t,e,s,r,n){let i={},l=gt(e,s);for(let h in o){let a=Bt(o[h],t,l),f=Math.min(...a);i[h]=f}for(let h=0;h<r.length;h++)for(let a in i)r[h][n[0]]===a&&(r[h][l]=i[a]);return i}import{getSelectionStatus as Ss,metadataKeys as Et}from"@vuu-ui/vuu-utils";var{RENDER_IDX:ks,SELECTED:xs}=Et,le=(o,t,e,s)=>{let[r]=o,n;if(s){let{count:i}=Et;n=o.slice(0,i).concat(s.map(l=>o[l]))}else n=o.slice();return n[ks]=t.keyFor(r),n[xs]=Ss(e,r),n},Cs=(o,t)=>{if(t){let{count:e}=Et;for(let[s,r]of Object.entries(o)){let n=t[s];if(n===void 0)throw Error(`ArrayDataSource column ${s} is not in underlying data set`);if(n!==r-e)return!0}}return!1},Rs=(o,t)=>{let{count:e}=Et,s=[];return Object.entries(o).forEach(([r])=>{s.push(t[r]+e)}),s},he=(o,t)=>{if(t&&Cs(o,t))return Rs(o,t)};import{metadataKeys as Ps}from"@vuu-ui/vuu-utils";var{DEPTH:ae,IS_EXPANDED:Ne,KEY:ue}=Ps,Me=(o,t)=>{let e=[];for(let s=0,r=0,n=!1,i=t.length;s<i;s++){let l=t[s],{[ae]:h,[ue]:a}=l;if(a===o){let f=l.slice();for(f[Ne]=!1,e.push(f),r+=1,n=!0;s<i-1&&t[s+1][ae]>h;)s+=1}else if(n){let f=l.slice();f[0]=r,f[1]=r,e.push(f),r+=1}else e.push(l),r+=1}return e},fe=(o,t,e,s,r,n)=>{let i=e.map(l=>s[l]);return Fe(r,i,o,t,void 0,void 0,void 0,n)},Fe=(o,t,e,s=[],r="$root",n=1,i=[],l)=>{console.log("dataRowsFromGroups2 1)");let h=Object.keys(o).sort();for(let a of h){let f=i.length,c=`${r}|${a}`,p=[f,f,!1,!1,n,0,c,0];p[t[n-1]]=a,i.push(p),e.includes(c)&&(p[Ne]=!0,Array.isArray(o[a])?Os(i,o[a],s,c,n+1):Fe(o[a],t,e,s,c,n+1,i,l))}console.log("dataRowsFromGroups2 2)");for(let a in i)for(let f in i)if(i[a][2]===!1&&l[f]!=null&&i[a][t[0]]===l[f][t[0]]){i[a]=i[a].splice(0,8).concat(l[f].slice(8,l[f].length));break}return console.log("dataRowsFromGroups2 3)"),i},Os=(o,t,e,s,r)=>{for(let n of t){let i=o.length,l=e[n].slice();l[0]=i,l[1]=i,l[ae]=r,l[ue]=`${s}|${l[ue]}`,o.push(l)}},Ve=(o,t,e)=>{let s=t.map(i=>e[i]),r=Ds(o,s);return[vs(r,s),r]},vs=(o,t)=>{let s=[],r=0,n=Object.keys(o).sort();for(let i of n){let l=[r,r,!1,!1,1,0,`$root|${i}`,0];l[t[0]]=i,s.push(l),r+=1}return s};function Ds(o,t){let e={},s=t.length,r=s-1;for(let n=0,i=o.length;n<i;n++){let l=o[n],h=e,a,f;for(let c=0;c<s;c++){let p=t[c];f=l[p].toString(),a=h[f],a&&c===r?a.push(n):a?h=a:!a&&c<r?h=h[f]={}:a||(h[f]=[n])}}return console.log("!! groups",e),e}var As=(o,t,[e,s])=>{let r=s==="D"?t[e]:o[e],n=s==="D"?o[e]:t[e];return r===n?0:n===null||r>n?1:-1},Ts=o=>o.length===1?Is(o):o.length===2?Ns(o):Ms(o),Is=([[o,t]])=>(e,s)=>{let r=t==="D"?s[o]:e[o],n=t==="D"?e[o]:s[o];return r>n?1:n>r?-1:0},Ns=([[o,t],[e,s]])=>(r,n)=>{let i=t==="D"?n[o]:r[o],l=t==="D"?r[o]:n[o],h=s==="D"?n[e]:r[e],a=s==="D"?r[e]:n[e];return i>l?1:l>i?-1:h>a?1:a>h?-1:0},Ms=(o,t=As)=>(e,s)=>{for(let r of o){let n=t(e,s,r);if(n!==0)return n}return 0},Be=(o,{sortDefs:t},e)=>{let s=t.map(({column:n,sortType:i})=>[e[n],i]),r=Ts(s);return o.slice().sort(r)};var{debug:Q,info:mt}=$s("ArrayDataSource"),{KEY:Le}=js,ce=o=>(t,e)=>[e,e,!0,!1,1,0,String(t[o]),0,...t],Xs=(o,t)=>({columns:o.map(({name:s,serverDataType:r="string"})=>({name:s,serverDataType:r})),key:t!=null?t:o[0].name,table:{module:"",table:"Array"}}),N,b,D,Qt,P,Pt,zt,z,bt,_e=class extends Vs{constructor({aggregations:e,columnDescriptors:s,data:r,dataMap:n,filter:i,groupBy:l,keyColumn:h,rangeChangeRowset:a="delta",sort:f,title:c,viewport:p}){super();this.lastRangeServed={from:0,to:0};this.openTreeNodes=[];R(this,N,void 0);R(this,b,Us);R(this,D,void 0);R(this,Qt,void 0);R(this,P,Qe);R(this,Pt,0);R(this,zt,0);R(this,z,"initialising");R(this,bt,void 0);this.selectedRows=[];this.keys=new _s(u(this,P));this.processedData=void 0;this.insert=e=>{let s=ce(this.key)(e,this.size);u(this,D).push(s);let{from:r,to:n}=u(this,P),[i]=s;i>=r&&i<n&&this.sendRowsToClient()};this.update=(e,s)=>{var h;let r=e[this.key],n=u(this,N)[s],i=(h=this.dataMap)==null?void 0:h[s],l=u(this,D).findIndex(a=>a[Le]===r);if(l!==-1&&i!==void 0){let a=u(this,D)[l];a[n]=e[i];let{from:f,to:c}=u(this,P),[p]=a;p>=f&&p<c&&this.sendRowsToClient(!1,a)}};this.updateRow=e=>{let s=e[this.key],r=u(this,D).findIndex(n=>n[Le]===s);if(r!==-1){let n=ce(this.key)(e,r);u(this,D)[r]=n;let{from:i,to:l}=u(this,P);r>=i&&r<l&&this.sendRowsToClient(!1,n)}};if(!r||!s)throw Error("ArrayDataSource constructor called without data or without columnDescriptors");this.columnDescriptors=s,this.dataMap=n,this.key=h?this.columnDescriptors.findIndex(w=>w.name===h):0,this.rangeChangeRowset=a,this.tableSchema=Xs(s,h),this.viewport=p||ze(),g(this,zt,r.length),g(this,bt,c);let d=s.map(w=>w.name);g(this,N,Ee(d)),this.dataIndices=he(u(this,N),this.dataMap),g(this,D,r.map(ce(this.key))),this.config={...u(this,b),aggregations:e||u(this,b).aggregations,columns:d,filter:i||u(this,b).filter,groupBy:l||u(this,b).groupBy,sort:f||u(this,b).sort},Q==null||Q(`columnMap: ${JSON.stringify(u(this,N))}`)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:ze())(),columns:s,aggregations:r,range:n,sort:i,groupBy:l,filter:h},a){var d;this.clientCallback=a,this.viewport=e,g(this,z,"subscribed"),this.lastRangeServed={from:0,to:0};let c=u(this,b),p=r||s||h||l||i;p&&(n&&g(this,P,n),c={...c,aggregations:r||u(this,b).aggregations,columns:s||u(this,b).columns,filter:h||u(this,b).filter,groupBy:l||u(this,b).groupBy,sort:i||u(this,b).sort}),(d=this.clientCallback)==null||d.call(this,{...c,type:"subscribed",clientViewportId:this.viewport,range:u(this,P),tableSchema:this.tableSchema}),p?this.config=c:(this.clientCallback({clientViewportId:this.viewport,mode:"size-only",type:"viewport-update",size:u(this,D).length}),n?(this.range=n,this.sendRowsToClient()):u(this,P)!==Qe&&this.sendRowsToClient())}unsubscribe(){console.log("unsubscribe noop")}suspend(){return console.log(`suspend #${this.viewport}, current status ${u(this,z)}`),mt==null||mt(`suspend #${this.viewport}, current status ${u(this,z)}`),g(this,z,"suspended"),this}resume(){console.log(`resume #${this.viewport}, current status ${u(this,z)}`);let e=u(this,z)==="suspended";return mt==null||mt(`resume #${this.viewport}, current status ${u(this,z)}`),console.log("resume noop"),e&&g(this,z,"subscribed"),this}disable(){return console.log("disable noop"),this}enable(){return console.log("enable noop"),this}select(e){g(this,Pt,e.length),Q==null||Q(`select ${JSON.stringify(e)}`),this.selectedRows=e,this.setRange(Rt(u(this,P)),!0)}openTreeNode(e){this.openTreeNodes.push(e),this.processedData=fe(this.openTreeNodes,u(this,D),u(this,b).groupBy,u(this,N),this.groupMap,this.processedData),this.setRange(Rt(u(this,P)),!0)}closeTreeNode(e){this.openTreeNodes=this.openTreeNodes.filter(s=>s!==e),this.processedData&&(this.processedData=Me(e,this.processedData),this.setRange(Rt(u(this,P)),!0))}get links(){return u(this,Qt)}get menu(){return this._menu}get status(){return u(this,z)}get data(){return u(this,D)}get currentData(){var e;return(e=this.processedData)!=null?e:u(this,D)}get table(){return this.tableSchema.table}get config(){return u(this,b)}set config(e){var s;if(this.applyConfig(e)){if(e){let r=u(this,b),n=(s=e==null?void 0:e.filter)!=null&&s.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:dt(e.filter.filter)}}:e;g(this,b,Ge(n));let i;if(zs(e)){let{filter:l,filterStruct:h=dt(l)}=e.filter;if(h){let a=Vt(u(this,N),h);i=u(this,D).filter(a)}else throw Error("filter must include filterStruct")}if(Ls(e)&&(i=Be(i!=null?i:u(this,D),e.sort,u(this,N))),this.openTreeNodes.length>0&&Qs(r,e)&&(u(this,b).groupBy.length===0?this.openTreeNodes.length=0:console.log("adjust the openTReeNodes groupBy changed ",{originalGroupBy:r.groupBy,newGroupBy:n.groupBy})),Gs(e)){let[l,h]=Ve(i!=null?i:u(this,D),e.groupBy,u(this,N));this.groupMap=h,i=l,this.openTreeNodes.length>0&&(i=fe(this.openTreeNodes,u(this,D),u(this,b).groupBy,u(this,N),this.groupMap,i))}this.processedData=i==null?void 0:i.map((l,h)=>{let a=l.slice();return a[0]=h,a[1]=h,a})}this.setRange(Rt(u(this,P)),!0),this.emit("config",u(this,b))}}applyConfig(e){var s;if(Fs(u(this,b),e)&&e){let r=(s=e==null?void 0:e.filter)!=null&&s.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:dt(e.filter.filter)}}:e;return g(this,b,Ge(r)),!0}}get selectedRowsCount(){return u(this,Pt)}get size(){var e,s;return(s=(e=this.processedData)==null?void 0:e.length)!=null?s:u(this,D).length}get range(){return u(this,P)}set range(e){this.setRange(e)}delete(e){console.log(`delete row ${e.join(",")}`)}setRange(e,s=!1){if(e.from!==u(this,P).from||e.to!==u(this,P).to){g(this,P,e);let r=this.keys.reset(e);this.sendRowsToClient(s||r)}else s&&this.sendRowsToClient(s)}sendRowsToClient(e=!1,s){var r,n,i;if(s)(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"update",rows:[le(s,this.keys,this.selectedRows,this.dataIndices)],type:"viewport-update"});else{let l=this.rangeChangeRowset==="delta"&&!e?Ws(this.lastRangeServed,u(this,P)):u(this,P),h=(n=this.processedData)!=null?n:u(this,D),a=h.slice(l.from,l.to).map(f=>le(f,this.keys,this.selectedRows,this.dataIndices));(i=this.clientCallback)==null||i.call(this,{clientViewportId:this.viewport,mode:"batch",rows:a,size:h.length,type:"viewport-update"}),this.lastRangeServed={from:u(this,P).from,to:Math.min(u(this,P).to,u(this,P).from+a.length)}}}get columns(){return u(this,b).columns}set columns(e){let s=Bs(this.config.columns,e);if(s.length>0){let r=Es(this.columnDescriptors,s,n=>n.name);console.log("columnsWithoutDescriptors",{columnsWithoutDescriptors:r})}g(this,N,Ee(e)),this.dataIndices=he(u(this,N),this.dataMap),this.config={...u(this,b),columns:e}}get aggregations(){return u(this,b).aggregations}set aggregations(e){var n;g(this,b,{...u(this,b),aggregations:e});let s=(n=this.processedData)!=null?n:u(this,D),r=u(this,D);Ae(e,s,u(this,b).groupBy,r,u(this,N),this.groupMap),this.setRange(Rt(u(this,P)),!0),this.emit("config",u(this,b))}get sort(){return u(this,b).sort}set sort(e){Q==null||Q(`sort ${JSON.stringify(e)}`),this.config={...u(this,b),sort:e}}get filter(){return u(this,b).filter}set filter(e){Q==null||Q(`filter ${JSON.stringify(e)}`),this.config={...u(this,b),filter:e}}get groupBy(){return u(this,b).groupBy}set groupBy(e){this.config={...u(this,b),groupBy:e}}get title(){return u(this,bt)}set title(e){g(this,bt,e)}get _clientCallback(){return this.clientCallback}createLink({parentVpId:e,link:{fromColumn:s,toColumn:r}}){console.log("create link",{parentVpId:e,fromColumn:s,toColumn:r})}removeLink(){console.log("remove link")}findRow(e){let s=u(this,D)[e];if(s)return s;throw`no row found for key ${e}`}applyEdit(e,s,r){return console.log(`ArrayDataSource applyEdit ${e[0]} ${s} ${r}`),Promise.resolve(!0)}async menuRpcCall(e){return new Promise(s=>{let{type:r}=e;switch(r){case"VP_EDIT_CELL_RPC":break;default:s(void 0)}})}};N=new WeakMap,b=new WeakMap,D=new WeakMap,Qt=new WeakMap,P=new WeakMap,Pt=new WeakMap,zt=new WeakMap,z=new WeakMap,bt=new WeakMap;import{EventEmitter as Ys,isSelected as Ks,jsonToDataSourceRows as $e,KeySet as Js,metadataKeys as Zs,uuid as je,vanillaConfig as qs}from"@vuu-ui/vuu-utils";var Hs={columns:[],key:"",table:{module:"",table:""}},{DEPTH:ot,IDX:We,IS_EXPANDED:tr,IS_LEAF:er,KEY:Je,SELECTED:Ue}=Zs,Xe=(o,t)=>{let[e]=o,s=o.slice();return s[1]=t.keyFor(e),s},q,G,I,H,tt,j,Gt,Lt,et,wt,yt,Ye=class extends Ys{constructor({aggregations:e,data:s,filter:r,groupBy:n,sort:i,title:l,viewport:h}){super();this.expandedRows=new Set;this.visibleRows=[];R(this,q,[]);R(this,G,qs);R(this,I,void 0);R(this,H,{filter:""});R(this,tt,[]);R(this,j,{from:0,to:0});R(this,Gt,0);R(this,Lt,0);R(this,et,{sortDefs:[]});R(this,wt,"initialising");R(this,yt,void 0);this.keys=new Js(u(this,j));if(!s)throw Error("JsonDataSource constructor called without data");[this.columnDescriptors,_t(this,I)._]=$e(s),this.visibleRows=u(this,I).filter(a=>a[ot]===0).map((a,f)=>[f,f].concat(a.slice(2))),this.viewport=h||je(),e&&g(this,q,e),this.columnDescriptors&&g(this,G,{...u(this,G),columns:this.columnDescriptors.map(a=>a.name)}),r&&g(this,H,r),n&&g(this,tt,n),i&&g(this,et,i),g(this,yt,l)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:je())(),columns:s,aggregations:r,range:n,sort:i,groupBy:l,filter:h},a){var c;this.clientCallback=a,r&&g(this,q,r),s&&g(this,G,{...u(this,G),columns:s}),h&&g(this,H,h),l&&g(this,tt,l),n&&g(this,j,n),i&&g(this,et,i),u(this,wt)==="initialising"&&(this.viewport=e,g(this,wt,"subscribed"),(c=this.clientCallback)==null||c.call(this,{aggregations:u(this,q),type:"subscribed",clientViewportId:this.viewport,columns:u(this,G).columns,filter:u(this,H),groupBy:u(this,tt),range:u(this,j),sort:u(this,et),tableSchema:Hs}),this.clientCallback({clientViewportId:this.viewport,mode:"size-only",type:"viewport-update",size:this.visibleRows.length}))}unsubscribe(){console.log("noop")}suspend(){return console.log("noop"),this}resume(){return console.log("noop"),this}disable(){return console.log("noop"),this}enable(){return console.log("noop"),this}set data(e){console.log("set JsonDataSource data"),[this.columnDescriptors,_t(this,I)._]=$e(e),this.visibleRows=u(this,I).filter(s=>s[ot]===0).map((s,r)=>[r,r].concat(s.slice(2))),requestAnimationFrame(()=>{this.sendRowsToClient()})}select(e){var r;let s=[];for(let n of u(this,I)){let{[We]:i,[Ue]:l}=n,h=l===1,a=Ks(e,i);if(a!==h){let f=n.slice();f[Ue]=a?1:0,u(this,I)[i]=f,s.push(f)}}s.length>0&&((r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"update",type:"viewport-update",rows:s}))}openTreeNode(e){var n;this.expandedRows.add(e),this.visibleRows=Ke(u(this,I),this.expandedRows);let{from:s,to:r}=u(this,j);(n=this.clientCallback)==null||n.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(s,r).map(i=>Xe(i,this.keys)),size:this.visibleRows.length,type:"viewport-update"})}closeTreeNode(e,s=!1){if(this.expandedRows.delete(e),s)for(let r of this.expandedRows.keys())r.startsWith(e)&&this.expandedRows.delete(r);this.visibleRows=Ke(u(this,I),this.expandedRows),this.sendRowsToClient()}get status(){return u(this,wt)}get config(){return u(this,G)}applyConfig(){return!0}get selectedRowsCount(){return u(this,Gt)}get size(){return u(this,Lt)}get range(){return u(this,j)}set range(e){g(this,j,e),this.keys.reset(e),requestAnimationFrame(()=>{this.sendRowsToClient()})}sendRowsToClient(){var r;let{from:e,to:s}=u(this,j);(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(e,s).map(n=>Xe(n,this.keys)),size:this.visibleRows.length,type:"viewport-update"})}get columns(){return u(this,G).columns}set columns(e){g(this,G,{...u(this,G),columns:e})}get aggregations(){return u(this,q)}set aggregations(e){g(this,q,e)}get sort(){return u(this,et)}set sort(e){g(this,et,e)}get filter(){return u(this,H)}set filter(e){g(this,H,e)}get groupBy(){return u(this,tt)}set groupBy(e){g(this,tt,e)}get title(){return u(this,yt)}set title(e){g(this,yt,e)}createLink({parentVpId:e,link:{fromColumn:s,toColumn:r}}){console.log("create link",{parentVpId:e,fromColumn:s,toColumn:r})}removeLink(){console.log("remove link")}async menuRpcCall(e){console.log("rmenuRpcCall",{rpcRequest:e})}applyEdit(e,s,r){return console.log(`ArrayDataSource applyEdit ${e.join(",")} ${s} ${r}`),Promise.resolve(!0)}getChildRows(e){let s=u(this,I).find(r=>r[Je]===e);if(s){let{[We]:r,[ot]:n}=s,i=r+1,l=[];do{let{[ot]:h}=u(this,I)[i];if(h===n+1)l.push(u(this,I)[i]);else if(h<=n)break;i+=1}while(i<u(this,I).length);return l}else console.warn(`JsonDataSource getChildRows row not found for key ${e}`);return[]}getRowsAtDepth(e,s=!0){return(s?this.visibleRows:u(this,I)).filter(n=>n[ot]===e)}};q=new WeakMap,G=new WeakMap,I=new WeakMap,H=new WeakMap,tt=new WeakMap,j=new WeakMap,Gt=new WeakMap,Lt=new WeakMap,et=new WeakMap,wt=new WeakMap,yt=new WeakMap;function Ke(o,t){let e=[],s={value:0};for(let r=0;r<o.length;r++){let n=o[r],{[ot]:i,[Je]:l,[er]:h}=n,a=t.has(l);if(e.push(sr(n,s,a)),!h&&!a)do r+=1;while(r<o.length-1&&o[r+1][ot]>i)}return e}var sr=(o,t,e)=>{let s=o.slice();return s[0]=t.value,s[1]=t.value,e&&(s[tr]=!0),t.value+=1,s};export{_e as ArrayDataSource,Ye as JsonDataSource};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|