@vuu-ui/vuu-data-local 0.8.23 → 0.8.24

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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var $t=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Ze=(o,t)=>{for(var e in t)$t(o,e,{get:t[e],enumerable:!0})},qe=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ke(t))!Je.call(o,r)&&r!==e&&$t(o,r,{get:()=>t[r],enumerable:!(s=Ye(t,r))||s.enumerable});return o};var He=o=>qe($t({},"__esModule",{value:!0}),o);var ye=(o,t,e)=>{if(!t.has(o))throw TypeError("Cannot "+e)};var u=(o,t,e)=>(ye(o,t,"read from private field"),e?e.call(o):t.get(o)),P=(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)},m=(o,t,e,s)=>(ye(o,t,"write to private field"),s?s.call(o,e):t.set(o,e),e);var jt=(o,t,e,s)=>({set _(r){m(o,t,r,e)},get _(){return u(o,t,s)}});var Qs={};Ze(Qs,{ArrayDataSource:()=>ge,JsonDataSource:()=>me});module.exports=He(Qs);var ts=0,Rt=class{constructor(t,e){this.from=t,this.to=e}},C=class{constructor(t={}){this.id=ts++,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=z.match(t)),e=>{let s=t(e);return s===void 0?null:[this,s]}}};C.closedBy=new C({deserialize:o=>o.split(" ")});C.openedBy=new C({deserialize:o=>o.split(" ")});C.group=new C({deserialize:o=>o.split(" ")});C.contextHash=new C({perNode:!0});C.lookAhead=new C({perNode:!0});C.mounted=new C({perNode:!0});var es=Object.create(null),z=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):es,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(C.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(C.group),n=-1;n<(r?r.length:0);n++){let i=e[n<0?s.name:r[n]];if(i)return i}}}};z.none=new z("",Object.create(null),0,8);var It=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 z(s.name,r,s.id,s.flags):s)}return new o(e)}},At=new WeakMap,Se=new WeakMap,T;(function(o){o[o.ExcludeBuffers=1]="ExcludeBuffers",o[o.IncludeAnonymous=2]="IncludeAnonymous",o[o.IgnoreMounts=4]="IgnoreMounts",o[o.IgnoreOverlays=8]="IgnoreOverlays"})(T||(T={}));var E=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(C.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 mt(this.topNode,t)}cursorAt(t,e=0,s=0){let r=At.get(this)||this.topNode,n=new mt(r);return n.moveTo(t,e),At.set(this,n._tree),n}get topNode(){return new ht(this,0,0,null)}resolve(t,e=0){let s=gt(At.get(this)||this.topNode,t,e,!1);return At.set(this,s),s}resolveInner(t,e=0){let s=gt(Se.get(this)||this.topNode,t,e,!0);return Se.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&T.IncludeAnonymous)>0;for(let h=this.cursor(i|T.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:Kt(z.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(z.none,e,s,r)))}static build(t){return ss(t)}};E.empty=new E(z.none,[],[],0);var Wt=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)}},lt=class o{constructor(t,e,s){this.buffer=t,this.length=e,this.set=s}get type(){return z.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&&!(xe(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 xe(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 Ce(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 gt(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 ht&&o.index<0?null:o.parent;if(!i)return o;o=i}let n=s?0:T.IgnoreOverlays;if(s)for(let i=o,l=i.parent;l;i=l,l=i.parent)i instanceof ht&&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 ht=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(xe(r,s,c,c+f.length)){if(f instanceof lt){if(n&T.ExcludeBuffers)continue;let p=f.findChild(0,f.buffer.length,e,s-c,r);if(p>-1)return new Pt(new Ut(i,f,t,c),null,p)}else if(n&T.IncludeAnonymous||!f.type.isAnonymous||Yt(f)){let p;if(!(n&T.IgnoreMounts)&&f.props&&(p=f.prop(C.mounted))&&!p.overlay)return new o(p.tree,c,t,i);let g=new o(f,c,t,i);return n&T.IncludeAnonymous||!g.type.isAnonymous?g:g.nextChild(e<0?f.children.length-1:0,e,s,r)}}}if(n&T.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&T.IgnoreOverlays)&&(r=this._tree.prop(C.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 mt(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return gt(this,t,e,!1)}resolveInner(t,e=0){return gt(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Ce(this,t)}getChild(t,e=null,s=null){let r=Nt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Nt(this,t,e,s)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return Mt(this,t)}};function Nt(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 Mt(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 Ut=class{constructor(t,e,s,r){this.parent=t,this.buffer=e,this.index=s,this.start=r}},Pt=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&T.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 mt(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 E(this.type,t,e,this.to-this.from)}resolve(t,e=0){return gt(this,t,e,!1)}resolveInner(t,e=0){return gt(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Ce(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,s=null){let r=Nt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Nt(this,t,e,s)}get node(){return this}matchContext(t){return Mt(this,t)}},mt=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 ht)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 ht?(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&T.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&T.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&T.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&T.IncludeAnonymous||l instanceof lt||!l.type.isAnonymous||Yt(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 Pt(this.buffer,e,this.stack[r]);return this.bufferNode=new Pt(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 Mt(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 Mt(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 Yt(o){return o.children.some(t=>t instanceof lt||!t.type.isAnonymous||Yt(t))}function ss(o){var t;let{buffer:e,nodeSet:s,maxBufferLength:r=1024,reused:n=[],minRepeatType:i=s.types.length}=o,l=Array.isArray(e)?new Wt(e,e.length):e,h=s.types,a=0,f=0;function c(R,v,b,k,I){let{id:x,start:S,end:D,size:B}=l,$=f;for(;B<0;)if(l.next(),B==-1){let H=n[x];b.push(H),k.push(S-R);return}else if(B==-3){a=x;return}else if(B==-4){f=x;return}else throw new RangeError(`Unrecognized record size: ${B}`);let pt=h[x],q,Y,be=S-R;if(D-S<=r&&(Y=Z(l.pos-v,I))){let H=new Uint16Array(Y.size-Y.skip),j=l.pos-Y.size,K=H.length;for(;l.pos>j;)K=ft(Y.start,H,K);q=new lt(H,D-Y.start,s),be=Y.start-R}else{let H=l.pos-B;l.next();let j=[],K=[],ot=x>=i?x:-1,dt=0,Dt=D;for(;l.pos>H;)ot>=0&&l.id==ot&&l.size>=0?(l.end<=Dt-r&&(g(j,K,S,dt,l.end,Dt,ot,$),dt=j.length,Dt=l.end),l.next()):c(S,H,j,K,ot);if(ot>=0&&dt>0&&dt<j.length&&g(j,K,S,dt,S,Dt,ot,$),j.reverse(),K.reverse(),ot>-1&&dt>0){let we=p(pt);q=Kt(pt,j,K,0,j.length,0,D-S,we,we)}else q=y(pt,j,K,D-S,$-D)}b.push(q),k.push(be)}function p(R){return(v,b,k)=>{let I=0,x=v.length-1,S,D;if(x>=0&&(S=v[x])instanceof E){if(!x&&S.type==R&&S.length==k)return S;(D=S.prop(C.lookAhead))&&(I=b[x]+S.length+D)}return y(R,v,b,k,I)}}function g(R,v,b,k,I,x,S,D){let B=[],$=[];for(;R.length>k;)B.push(R.pop()),$.push(v.pop()+b-I);R.push(y(s.types[S],B,$,x-I,D-x)),v.push(I-b)}function y(R,v,b,k,I=0,x){if(a){let S=[C.contextHash,a];x=x?[S].concat(x):[S]}if(I>25){let S=[C.lookAhead,I];x=x?[S].concat(x):[S]}return new E(R,v,b,k,x)}function Z(R,v){let b=l.fork(),k=0,I=0,x=0,S=b.end-r,D={size:0,start:0,skip:0};t:for(let B=b.pos-R;b.pos>B;){let $=b.size;if(b.id==v&&$>=0){D.size=k,D.start=I,D.skip=x,x+=4,k+=4,b.next();continue}let pt=b.pos-$;if($<0||pt<B||b.start<S)break;let q=b.id>=i?4:0,Y=b.start;for(b.next();b.pos>pt;){if(b.size<0)if(b.size==-3)q+=4;else break t;else b.id>=i&&(q+=4);b.next()}I=Y,k+=$,x+=q}return(v<0||k==R)&&(D.size=k,D.start=I,D.skip=x),D.size>4?D:void 0}function ft(R,v,b){let{id:k,start:I,end:x,size:S}=l;if(l.next(),S>=0&&k<i){let D=b;if(S>4){let B=l.pos-(S-4);for(;l.pos>B;)b=ft(R,v,b)}v[--b]=D,v[--b]=x-R,v[--b]=I-R,v[--b]=k}else S==-3?a=k:S==-4&&(f=k);return b}let nt=[],ct=[];for(;l.pos>0;)c(o.start||0,o.bufferStart||0,nt,ct,-1);let V=(t=o.length)!==null&&t!==void 0?t:nt.length?ct[0]+nt[0].length:0;return new E(h[o.topID],nt.reverse(),ct.reverse(),V)}var ke=new WeakMap;function Tt(o,t){if(!o.isAnonymous||t instanceof lt||t.type!=o)return 1;let e=ke.get(t);if(e==null){e=1;for(let s of t.children){if(s.type!=o||!(s instanceof E)){e=1;break}e+=Tt(o,s)}ke.set(t,e)}return e}function Kt(o,t,e,s,r,n,i,l,h){let a=0;for(let y=s;y<r;y++)a+=Tt(o,t[y]);let f=Math.ceil(a*1.5/8),c=[],p=[];function g(y,Z,ft,nt,ct){for(let V=ft;V<nt;){let R=V,v=Z[V],b=Tt(o,y[V]);for(V++;V<nt;V++){let k=Tt(o,y[V]);if(b+k>=f)break;b+=k}if(V==R+1){if(b>f){let k=y[R];g(k.children,k.positions,0,k.children.length,Z[R]+ct);continue}c.push(y[R])}else{let k=Z[V-1]+y[V-1].length-v;c.push(Kt(o,y,Z,R,V,v,k,null,h))}p.push(v+ct-n)}}return g(t,e,s,r,0),(l||h)(c,p,i)}var Ft=class{startParse(t,e,s){return typeof t=="string"&&(t=new Xt(t)),s=s?s.length?s.map(r=>new Rt(r.from,r.to)):[new Rt(0,0)]:[new Rt(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}}},Xt=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 Gs=new C({perNode:!0});var Zt=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 Vt(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 qt(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 Vt(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()}},Vt=class{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}},Re;(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"})(Re||(Re={}));var qt=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}},Ht=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 Ot(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 bt=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},Pe=new bt,te=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=Pe,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=Pe,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}},tt=class{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;Ne(this.data,t,e,this.id,s.data,s.tokenPrecTable)}};tt.prototype.contextual=tt.prototype.fallback=tt.prototype.extend=!1;var ee=class{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?Ot(t):t}token(t,e){let s=t.pos,r=0;for(;;){let n=t.next<0,i=t.resolveOffset(1,1);if(Ne(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))}};ee.prototype.contextual=tt.prototype.fallback=tt.prototype.extend=!1;function Ne(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 g=i+3;g<a;g+=2)if((o[g+1]&l)>0){let y=o[g];if(h.allows(y)&&(t.token.value==-1||t.token.value==y||is(y,t.token.value,r,n))){t.acceptToken(y);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 g=c+p>>1,y=a+g+(g<<1),Z=o[y],ft=o[y+1]||65536;if(f<Z)p=g;else if(f>=ft)c=g+1;else{i=o[y+2],t.advance();continue t}}break}}function Oe(o,t,e){for(let s=t,r;(r=o[s])!=65535;s++)if(r==e)return s-t;return-1}function is(o,t,e,s){let r=Oe(e,s,t);return r<0||Oe(e,s,o)<r}var W=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Jt=null,ve;(function(o){o[o.Margin=25]="Margin"})(ve||(ve={}));function De(o,t,e){let s=o.cursor(T.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 se=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?De(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?De(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 E){if(i==t){if(i<this.safeFrom)return null;let l=i+n.length;if(l<=this.safeTo){let h=n.prop(C.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}}},re=class{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new bt)}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 bt,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 bt,{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=J(l,a+2);else{r==0&&l[a+1]==2&&(r=this.putAction(J(l,a+2),e,s,r));break}l[a]==e&&(r=this.putAction(J(l,a+1),e,s,r))}return r}},Ae;(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"})(Ae||(Ae={}));var ie=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 te(e,r),this.tokens=new re(t,this.stream),this.topTerm=t.top[1];let{from:n}=r[0];this.stacks=[Zt.start(this,t.top[0],n)],this.fragments=s.length&&this.stream.end-n>t.bufferLength*4?new se(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&&ns(r);if(i)return this.stackToTree(i);if(this.parser.strict)throw W&&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=W?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(C.contextHash)||0)==f))return t.useNode(c,p),W&&console.log(i+this.stackID(t)+` (via reuse of ${n.getName(c.type.id)})`),!0;if(!(c instanceof E)||c.children.length==0||c.positions[0]>0)break;let g=c.children[0];if(g instanceof E&&c.positions[0]==0)c=g;else break}}let l=n.stateSlot(t.state,4);if(l>0)return t.reduce(l),W&&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++],g=a==h.length||!s,y=g?t:t.split();if(y.apply(f,c,p),W&&console.log(i+this.stackID(y)+` (via ${f&65536?`reduce of ${n.getName(f&65535)}`:"shift"} for ${n.getName(c)} @ ${r}${y==t?"":", split"})`),g)return!0;y.pos>r?e.push(y):s.push(y)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return Te(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=W?this.stackID(l)+" -> ":"";if(l.deadEnd&&(n||(n=!0,l.restart(),W&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,s))))continue;let c=l.split(),p=f;for(let g=0;c.forceReduce()&&g<10&&(W&&console.log(p+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,s));g++)W&&(p=this.stackID(c)+" -> ");for(let g of l.recoverByInsert(h))W&&console.log(f+this.stackID(g)+" (via recover-insert)"),this.advanceFully(g,s);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),W&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),Te(l,s)):(!r||r.score<l.score)&&(r=l)}return r}stackToTree(t){return t.close(),E.build({buffer:Ht.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=(Jt||(Jt=new WeakMap)).get(t);return e||Jt.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}};function Te(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 ne=class{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}};var Bt=class o extends Ft{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=C[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 It(e.map((l,h)=>z.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=Ot(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(Ie),this.states=Ot(t.states,Uint32Array),this.data=Ot(t.stateData),this.goto=Ot(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new tt(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 ie(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=J(s,n+2)];else{if(s[n+1]==2)return J(s,n+2);break}if(i==e||i==0)return J(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=J(this.data,n+2);else break;r=e(J(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=J(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]=Ie(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 ne(t,s,r)}static deserialize(t){return new o(t)}};function J(o,t){return o[t]|o[t+1]<<16}function ns(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 Ie(o){if(o.external){let t=o.extend?1:0;return(e,s)=>o.external(e,s)<<1|t}return o.get}var oe=Bt.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});var U=require("@vuu-ui/vuu-utils");var Q,le=class{constructor(){P(this,Q,void 0)}setFilterCombinatorOp(t,e=u(this,Q)){(0,U.isMultiClauseFilter)(e)&&e.op===t||m(this,Q,{op:t,filters:[u(this,Q)]})}add(t){if(u(this,Q)===void 0)m(this,Q,t);else if((0,U.isMultiClauseFilter)(u(this,Q)))u(this,Q).filters.push(t);else throw Error("Invalid filter passed to FilterExpression")}setColumn(t,e=u(this,Q)){if((0,U.isMultiClauseFilter)(e)){let s=e.filters.at(-1);s&&this.setColumn(t,s)}else e&&(e.column=t)}setOp(t,e=u(this,Q)){if((0,U.isMultiClauseFilter)(e)){let s=e.filters.at(-1);s&&this.setOp(t,s)}else e&&(e.op=t)}setValue(t,e=u(this,Q)){var s;if((0,U.isMultiClauseFilter)(e)){let r=e.filters.at(-1);r&&this.setValue(t,r)}else(0,U.isMultiValueFilter)(e)?((s=e.values)!=null||(e.values=[]),e.values.push(t)):(0,U.isSingleValueFilter)(e)&&(e.value=t)}toJSON(t=u(this,Q)){return this.name?{...t,name:this.name}:t}};Q=new WeakMap;var he=(o,t)=>{let e=new le,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 os=oe.configure({strict:!0}),wt=o=>{let t=os.parse(o);return he(t,o)};function Et(o,t){switch(t.op){case"in":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"<=":return cs(o,t);case"ends":return ps(o,t);case"starts":return ds(o,t);case"and":return gs(o,t);case"or":return ms(o,t);default:return console.log(`unrecognized filter type ${t.op}`),()=>!0}}var ls=(o,t)=>e=>t.values.indexOf(e[o[t.column]])!==-1,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)=>e=>e[o[t.column]]<=t.value,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().endsWith(e.toLowerCase())}},ds=(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())}},gs=(o,t)=>{let e=t.filters.map(s=>Et(o,s));return s=>e.every(r=>r(s))};function ms(o,t){let e=t.filters.map(s=>Et(o,s));return s=>e.some(r=>r(s))}var d=require("@vuu-ui/vuu-utils");var Me=(o,t,e,s,r,n)=>{let i=o[o.length-1].aggType,l=e.map(h=>r[h]);switch(i){case 1:return Ve(n,s,r,o,t,l);case 2:return bs(n,s,r,o,t,l);case 3:return Fe(n,r,o,t,l);case 4:return ys(n,s,r,o,t,l);case 5:return Ss(n,s,r,o,t,l);case 6:return ws(n,s,r,o,t,l)}};function Fe(o,t,e,s,r){let n={},i=yt(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 yt(o,t){console.log("!!!! aggregation length",t.length);let e=t[t.length-1].column;return o[e]}function Ve(o,t,e,s,r,n){let i={},l=yt(e,s);function h(a,f,c){if(Array.isArray(a)){let p=0;for(let g of a)p+=Number(f[g][c]);return p}else{let p=0;for(let g in a)p+=h(a[g],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 bs(o,t,e,s,r,n){let i={},l=yt(e,s),h=Fe(o,e,s,r,n),a=Ve(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 Qt(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(...Qt(o[r],t,e));return s}function ws(o,t,e,s,r,n){let i={},l=yt(e,s);for(let h in o){let a=Qt(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 ys(o,t,e,s,r,n){let i={},l=yt(e,s);for(let h in o){let a=Qt(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 Ss(o,t,e,s,r,n){let i={},l=yt(e,s);for(let h in o){let a=Qt(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}var at=require("@vuu-ui/vuu-utils"),{RENDER_IDX:ks,SELECTED:xs}=at.metadataKeys,ae=(o,t,e,s)=>{let[r]=o,n;if(s){let{count:i}=at.metadataKeys;n=o.slice(0,i).concat(s.map(l=>o[l]))}else n=o.slice();return n[ks]=t.keyFor(r),n[xs]=(0,at.getSelectionStatus)(e,r),n},Cs=(o,t)=>{if(t){let{count:e}=at.metadataKeys;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}=at.metadataKeys,s=[];return Object.entries(o).forEach(([r])=>{s.push(t[r]+e)}),s},ue=(o,t)=>{if(t&&Cs(o,t))return Rs(o,t)};var Be=require("@vuu-ui/vuu-utils"),{DEPTH:fe,IS_EXPANDED:Ee,KEY:ce}=Be.metadataKeys,Qe=(o,t)=>{let e=[];for(let s=0,r=0,n=!1,i=t.length;s<i;s++){let l=t[s],{[fe]:h,[ce]:a}=l;if(a===o){let f=l.slice();for(f[Ee]=!1,e.push(f),r+=1,n=!0;s<i-1&&t[s+1][fe]>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},pe=(o,t,e,s,r,n)=>{let i=e.map(l=>s[l]);return ze(r,i,o,t,void 0,void 0,void 0,n)},ze=(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[Ee]=!0,Array.isArray(o[a])?Ps(i,o[a],s,c,n+1):ze(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[fe]=r,l[ce]=`${s}|${l[ce]}`,o.push(l)}},Ge=(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},Le=(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:G,info:St}=(0,d.logger)("ArrayDataSource"),{KEY:_e}=d.metadataKeys,de=o=>(t,e)=>[e,e,!0,!1,1,0,String(t[o]),0,...t],Ms=(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"}}),F,w,A,zt,O,vt,Gt,L,kt,ge=class extends d.EventEmitter{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=[];P(this,F,void 0);P(this,w,d.vanillaConfig);P(this,A,void 0);P(this,zt,void 0);P(this,O,d.NULL_RANGE);P(this,vt,0);P(this,Gt,0);P(this,L,"initialising");P(this,kt,void 0);this.selectedRows=[];this.keys=new d.KeySet(u(this,O));this.processedData=void 0;this.insert=e=>{let s=de(this.key)(e,this.size);u(this,A).push(s);let{from:r,to:n}=u(this,O),[i]=s;i>=r&&i<n&&this.sendRowsToClient()};this.update=(e,s)=>{var h;let r=e[this.key],n=u(this,F)[s],i=(h=this.dataMap)==null?void 0:h[s],l=u(this,A).findIndex(a=>a[_e]===r);if(l!==-1&&i!==void 0){let a=u(this,A)[l];a[n]=e[i];let{from:f,to:c}=u(this,O),[p]=a;p>=f&&p<c&&this.sendRowsToClient(!1,a)}};this.updateRow=e=>{let s=e[this.key],r=u(this,A).findIndex(n=>n[_e]===s);if(r!==-1){let n=de(this.key)(e,r);u(this,A)[r]=n;let{from:i,to:l}=u(this,O);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(y=>y.name===h):0,this.rangeChangeRowset=a,this.tableSchema=Ms(s,h),this.viewport=p||(0,d.uuid)(),m(this,Gt,r.length),m(this,kt,c);let g=s.map(y=>y.name);m(this,F,(0,d.buildColumnMap)(g)),this.dataIndices=ue(u(this,F),this.dataMap),m(this,A,r.map(de(this.key))),this.config={...u(this,w),aggregations:e||u(this,w).aggregations,columns:g,filter:i||u(this,w).filter,groupBy:l||u(this,w).groupBy,sort:f||u(this,w).sort},G==null||G(`columnMap: ${JSON.stringify(u(this,F))}`)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:(0,d.uuid)())(),columns:s,aggregations:r,range:n,sort:i,groupBy:l,filter:h},a){var g;this.clientCallback=a,this.viewport=e,m(this,L,"subscribed"),this.lastRangeServed={from:0,to:0};let c=u(this,w),p=r||s||h||l||i;p&&(n&&m(this,O,n),c={...c,aggregations:r||u(this,w).aggregations,columns:s||u(this,w).columns,filter:h||u(this,w).filter,groupBy:l||u(this,w).groupBy,sort:i||u(this,w).sort}),(g=this.clientCallback)==null||g.call(this,{...c,type:"subscribed",clientViewportId:this.viewport,range:u(this,O),tableSchema:this.tableSchema}),p?this.config=c:(this.clientCallback({clientViewportId:this.viewport,mode:"size-only",type:"viewport-update",size:u(this,A).length}),n?(this.range=n,this.sendRowsToClient()):u(this,O)!==d.NULL_RANGE&&this.sendRowsToClient())}unsubscribe(){console.log("unsubscribe noop")}suspend(){return console.log(`suspend #${this.viewport}, current status ${u(this,L)}`),St==null||St(`suspend #${this.viewport}, current status ${u(this,L)}`),m(this,L,"suspended"),this}resume(){console.log(`resume #${this.viewport}, current status ${u(this,L)}`);let e=u(this,L)==="suspended";return St==null||St(`resume #${this.viewport}, current status ${u(this,L)}`),console.log("resume noop"),e&&m(this,L,"subscribed"),this}disable(){return console.log("disable noop"),this}enable(){return console.log("enable noop"),this}select(e){m(this,vt,e.length),G==null||G(`select ${JSON.stringify(e)}`),this.selectedRows=e,this.setRange((0,d.resetRange)(u(this,O)),!0)}openTreeNode(e){this.openTreeNodes.push(e),this.processedData=pe(this.openTreeNodes,u(this,A),u(this,w).groupBy,u(this,F),this.groupMap,this.processedData),this.setRange((0,d.resetRange)(u(this,O)),!0)}closeTreeNode(e){this.openTreeNodes=this.openTreeNodes.filter(s=>s!==e),this.processedData&&(this.processedData=Qe(e,this.processedData),this.setRange((0,d.resetRange)(u(this,O)),!0))}get links(){return u(this,zt)}get menu(){return this._menu}get status(){return u(this,L)}get data(){return u(this,A)}get currentData(){var e;return(e=this.processedData)!=null?e:u(this,A)}get table(){return this.tableSchema.table}get config(){return u(this,w)}set config(e){var s;if(this.applyConfig(e)){if(e){let r=u(this,w),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:wt(e.filter.filter)}}:e;m(this,w,(0,d.withConfigDefaults)(n));let i;if((0,d.hasFilter)(e)){let{filter:l,filterStruct:h=wt(l)}=e.filter;if(h){let a=Et(u(this,F),h);i=u(this,A).filter(a)}else throw Error("filter must include filterStruct")}if((0,d.hasSort)(e)&&(i=Le(i!=null?i:u(this,A),e.sort,u(this,F))),this.openTreeNodes.length>0&&(0,d.groupByChanged)(r,e)&&(u(this,w).groupBy.length===0?this.openTreeNodes.length=0:console.log("adjust the openTReeNodes groupBy changed ",{originalGroupBy:r.groupBy,newGroupBy:n.groupBy})),(0,d.hasGroupBy)(e)){let[l,h]=Ge(i!=null?i:u(this,A),e.groupBy,u(this,F));this.groupMap=h,i=l,this.openTreeNodes.length>0&&(i=pe(this.openTreeNodes,u(this,A),u(this,w).groupBy,u(this,F),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((0,d.resetRange)(u(this,O)),!0),this.emit("config",u(this,w))}}applyConfig(e){var s;if((0,d.configChanged)(u(this,w),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:wt(e.filter.filter)}}:e;return m(this,w,(0,d.withConfigDefaults)(r)),!0}}get selectedRowsCount(){return u(this,vt)}get size(){var e,s;return(s=(e=this.processedData)==null?void 0:e.length)!=null?s:u(this,A).length}get range(){return u(this,O)}set range(e){this.setRange(e)}delete(e){console.log(`delete row ${e.join(",")}`)}setRange(e,s=!1){if(e.from!==u(this,O).from||e.to!==u(this,O).to){m(this,O,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:[ae(s,this.keys,this.selectedRows,this.dataIndices)],type:"viewport-update"});else{let l=this.rangeChangeRowset==="delta"&&!e?(0,d.rangeNewItems)(this.lastRangeServed,u(this,O)):u(this,O),h=(n=this.processedData)!=null?n:u(this,A),a=h.slice(l.from,l.to).map(f=>ae(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,O).from,to:Math.min(u(this,O).to,u(this,O).from+a.length)}}}get columns(){return u(this,w).columns}set columns(e){let s=(0,d.getAddedItems)(this.config.columns,e);if(s.length>0){let r=(0,d.getMissingItems)(this.columnDescriptors,s,n=>n.name);console.log("columnsWithoutDescriptors",{columnsWithoutDescriptors:r})}m(this,F,(0,d.buildColumnMap)(e)),this.dataIndices=ue(u(this,F),this.dataMap),this.config={...u(this,w),columns:e}}get aggregations(){return u(this,w).aggregations}set aggregations(e){var n;m(this,w,{...u(this,w),aggregations:e});let s=(n=this.processedData)!=null?n:u(this,A),r=u(this,A);Me(e,s,u(this,w).groupBy,r,u(this,F),this.groupMap),this.setRange((0,d.resetRange)(u(this,O)),!0),this.emit("config",u(this,w))}get sort(){return u(this,w).sort}set sort(e){G==null||G(`sort ${JSON.stringify(e)}`),this.config={...u(this,w),sort:e}}get filter(){return u(this,w).filter}set filter(e){G==null||G(`filter ${JSON.stringify(e)}`),this.config={...u(this,w),filter:e}}get groupBy(){return u(this,w).groupBy}set groupBy(e){this.config={...u(this,w),groupBy:e}}get title(){return u(this,kt)}set title(e){m(this,kt,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,A)[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)}})}};F=new WeakMap,w=new WeakMap,A=new WeakMap,zt=new WeakMap,O=new WeakMap,vt=new WeakMap,Gt=new WeakMap,L=new WeakMap,kt=new WeakMap;var M=require("@vuu-ui/vuu-utils");var Fs={columns:[],key:"",table:{module:"",table:""}},{DEPTH:ut,IDX:$e,IS_EXPANDED:Vs,IS_LEAF:Bs,KEY:Xe,SELECTED:je}=M.metadataKeys,We=(o,t)=>{let[e]=o,s=o.slice();return s[1]=t.keyFor(e),s},et,_,N,st,rt,X,Lt,_t,it,xt,Ct,me=class extends M.EventEmitter{constructor({aggregations:e,data:s,filter:r,groupBy:n,sort:i,title:l,viewport:h}){super();this.expandedRows=new Set;this.visibleRows=[];P(this,et,[]);P(this,_,M.vanillaConfig);P(this,N,void 0);P(this,st,{filter:""});P(this,rt,[]);P(this,X,{from:0,to:0});P(this,Lt,0);P(this,_t,0);P(this,it,{sortDefs:[]});P(this,xt,"initialising");P(this,Ct,void 0);this.keys=new M.KeySet(u(this,X));if(!s)throw Error("JsonDataSource constructor called without data");[this.columnDescriptors,jt(this,N)._]=(0,M.jsonToDataSourceRows)(s),this.visibleRows=u(this,N).filter(a=>a[ut]===0).map((a,f)=>[f,f].concat(a.slice(2))),this.viewport=h||(0,M.uuid)(),e&&m(this,et,e),this.columnDescriptors&&m(this,_,{...u(this,_),columns:this.columnDescriptors.map(a=>a.name)}),r&&m(this,st,r),n&&m(this,rt,n),i&&m(this,it,i),m(this,Ct,l)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:(0,M.uuid)())(),columns:s,aggregations:r,range:n,sort:i,groupBy:l,filter:h},a){var c;this.clientCallback=a,r&&m(this,et,r),s&&m(this,_,{...u(this,_),columns:s}),h&&m(this,st,h),l&&m(this,rt,l),n&&m(this,X,n),i&&m(this,it,i),u(this,xt)==="initialising"&&(this.viewport=e,m(this,xt,"subscribed"),(c=this.clientCallback)==null||c.call(this,{aggregations:u(this,et),type:"subscribed",clientViewportId:this.viewport,columns:u(this,_).columns,filter:u(this,st),groupBy:u(this,rt),range:u(this,X),sort:u(this,it),tableSchema:Fs}),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,jt(this,N)._]=(0,M.jsonToDataSourceRows)(e),this.visibleRows=u(this,N).filter(s=>s[ut]===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,N)){let{[$e]:i,[je]:l}=n,h=l===1,a=(0,M.isSelected)(e,i);if(a!==h){let f=n.slice();f[je]=a?1:0,u(this,N)[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=Ue(u(this,N),this.expandedRows);let{from:s,to:r}=u(this,X);(n=this.clientCallback)==null||n.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(s,r).map(i=>We(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=Ue(u(this,N),this.expandedRows),this.sendRowsToClient()}get status(){return u(this,xt)}get config(){return u(this,_)}applyConfig(){return!0}get selectedRowsCount(){return u(this,Lt)}get size(){return u(this,_t)}get range(){return u(this,X)}set range(e){m(this,X,e),this.keys.reset(e),requestAnimationFrame(()=>{this.sendRowsToClient()})}sendRowsToClient(){var r;let{from:e,to:s}=u(this,X);(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(e,s).map(n=>We(n,this.keys)),size:this.visibleRows.length,type:"viewport-update"})}get columns(){return u(this,_).columns}set columns(e){m(this,_,{...u(this,_),columns:e})}get aggregations(){return u(this,et)}set aggregations(e){m(this,et,e)}get sort(){return u(this,it)}set sort(e){m(this,it,e)}get filter(){return u(this,st)}set filter(e){m(this,st,e)}get groupBy(){return u(this,rt)}set groupBy(e){m(this,rt,e)}get title(){return u(this,Ct)}set title(e){m(this,Ct,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,N).find(r=>r[Xe]===e);if(s){let{[$e]:r,[ut]:n}=s,i=r+1,l=[];do{let{[ut]:h}=u(this,N)[i];if(h===n+1)l.push(u(this,N)[i]);else if(h<=n)break;i+=1}while(i<u(this,N).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,N)).filter(n=>n[ut]===e)}};et=new WeakMap,_=new WeakMap,N=new WeakMap,st=new WeakMap,rt=new WeakMap,X=new WeakMap,Lt=new WeakMap,_t=new WeakMap,it=new WeakMap,xt=new WeakMap,Ct=new WeakMap;function Ue(o,t){let e=[],s={value:0};for(let r=0;r<o.length;r++){let n=o[r],{[ut]:i,[Xe]:l,[Bs]:h}=n,a=t.has(l);if(e.push(Es(n,s,a)),!h&&!a)do r+=1;while(r<o.length-1&&o[r+1][ut]>i)}return e}var Es=(o,t,e)=>{let s=o.slice();return s[0]=t.value,s[1]=t.value,e&&(s[Vs]=!0),t.value+=1,s};
1
+ "use strict";var $t=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var Ze=(o,t)=>{for(var e in t)$t(o,e,{get:t[e],enumerable:!0})},qe=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ke(t))!Je.call(o,r)&&r!==e&&$t(o,r,{get:()=>t[r],enumerable:!(s=Ye(t,r))||s.enumerable});return o};var He=o=>qe($t({},"__esModule",{value:!0}),o);var Se=(o,t,e)=>{if(!t.has(o))throw TypeError("Cannot "+e)};var u=(o,t,e)=>(Se(o,t,"read from private field"),e?e.call(o):t.get(o)),P=(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)},m=(o,t,e,s)=>(Se(o,t,"write to private field"),s?s.call(o,e):t.set(o,e),e);var jt=(o,t,e,s)=>({set _(r){m(o,t,r,e)},get _(){return u(o,t,s)}});var Qs={};Ze(Qs,{ArrayDataSource:()=>ge,JsonDataSource:()=>me});module.exports=He(Qs);var ts=0,Rt=class{constructor(t,e){this.from=t,this.to=e}},C=class{constructor(t={}){this.id=ts++,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=z.match(t)),e=>{let s=t(e);return s===void 0?null:[this,s]}}};C.closedBy=new C({deserialize:o=>o.split(" ")});C.openedBy=new C({deserialize:o=>o.split(" ")});C.group=new C({deserialize:o=>o.split(" ")});C.contextHash=new C({perNode:!0});C.lookAhead=new C({perNode:!0});C.mounted=new C({perNode:!0});var es=Object.create(null),z=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):es,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 i of t.props)if(Array.isArray(i)||(i=i(r)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[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(C.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(C.group),i=-1;i<(r?r.length:0);i++){let n=e[i<0?s.name:r[i]];if(n)return n}}}};z.none=new z("",Object.create(null),0,8);var It=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 i of t){let n=i(s);n&&(r||(r=Object.assign({},s.props)),r[n[0].id]=n[1])}e.push(r?new z(s.name,r,s.id,s.flags):s)}return new o(e)}},At=new WeakMap,ye=new WeakMap,T;(function(o){o[o.ExcludeBuffers=1]="ExcludeBuffers",o[o.IncludeAnonymous=2]="IncludeAnonymous",o[o.IgnoreMounts=4]="IgnoreMounts",o[o.IgnoreOverlays=8]="IgnoreOverlays"})(T||(T={}));var E=class o{constructor(t,e,s,r,i){if(this.type=t,this.children=e,this.positions=s,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[n,l]of i)this.props[typeof n=="number"?n:n.id]=l}}toString(){let t=this.prop(C.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 mt(this.topNode,t)}cursorAt(t,e=0,s=0){let r=At.get(this)||this.topNode,i=new mt(r);return i.moveTo(t,e),At.set(this,i._tree),i}get topNode(){return new ht(this,0,0,null)}resolve(t,e=0){let s=gt(At.get(this)||this.topNode,t,e,!1);return At.set(this,s),s}resolveInner(t,e=0){let s=gt(ye.get(this)||this.topNode,t,e,!0);return ye.set(this,s),s}iterate(t){let{enter:e,leave:s,from:r=0,to:i=this.length}=t,n=t.mode||0,l=(n&T.IncludeAnonymous)>0;for(let h=this.cursor(n|T.IncludeAnonymous);;){let a=!1;if(h.from<=i&&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:Kt(z.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(z.none,e,s,r)))}static build(t){return ss(t)}};E.empty=new E(z.none,[],[],0);var Wt=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)}},lt=class o{constructor(t,e,s){this.buffer=t,this.length=e,this.set=s}get type(){return z.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],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),t+=4,s==t)return i;let n=[];for(;t<s;)n.push(this.childString(t)),t=this.buffer[t+3];return i+"("+n.join(",")+")"}findChild(t,e,s,r,i){let{buffer:n}=this,l=-1;for(let h=t;h!=e&&!(xe(i,r,n[h+1],n[h+2])&&(l=h,s>0));h=n[h+3]);return l}slice(t,e,s){let r=this.buffer,i=new Uint16Array(e-t),n=0;for(let l=t,h=0;l<e;){i[h++]=r[l++],i[h++]=r[l++]-s;let a=i[h++]=r[l++]-s;i[h++]=r[l++]-t,n=Math.max(n,a)}return new o(i,n,this.set)}};function xe(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 Ce(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 gt(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 n=!s&&o instanceof ht&&o.index<0?null:o.parent;if(!n)return o;o=n}let i=s?0:T.IgnoreOverlays;if(s)for(let n=o,l=n.parent;l;n=l,l=n.parent)n instanceof ht&&n.index<0&&((r=l.enter(t,e,i))===null||r===void 0?void 0:r.from)!=n.from&&(o=l);for(;;){let n=o.enter(t,e,i);if(!n)return o;o=n}}var ht=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,i=0){for(let n=this;;){for(let{children:l,positions:h}=n._tree,a=e>0?l.length:-1;t!=a;t+=e){let f=l[t],c=h[t]+n.from;if(xe(r,s,c,c+f.length)){if(f instanceof lt){if(i&T.ExcludeBuffers)continue;let p=f.findChild(0,f.buffer.length,e,s-c,r);if(p>-1)return new Pt(new Ut(n,f,t,c),null,p)}else if(i&T.IncludeAnonymous||!f.type.isAnonymous||Yt(f)){let p;if(!(i&T.IgnoreMounts)&&f.props&&(p=f.prop(C.mounted))&&!p.overlay)return new o(p.tree,c,t,n);let g=new o(f,c,t,n);return i&T.IncludeAnonymous||!g.type.isAnonymous?g:g.nextChild(e<0?f.children.length-1:0,e,s,r)}}}if(i&T.IncludeAnonymous||!n.type.isAnonymous||(n.index>=0?t=n.index+e:t=e<0?-1:n._parent._tree.children.length,n=n._parent,!n))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&T.IgnoreOverlays)&&(r=this._tree.prop(C.mounted))&&r.overlay){let i=t-this.from;for(let{from:n,to:l}of r.overlay)if((e>0?n<=i:n<i)&&(e<0?l>=i:l>i))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 mt(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return gt(this,t,e,!1)}resolveInner(t,e=0){return gt(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Ce(this,t)}getChild(t,e=null,s=null){let r=Nt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Nt(this,t,e,s)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return Mt(this,t)}};function Nt(o,t,e,s){let r=o.cursor(),i=[];if(!r.firstChild())return i;if(e!=null){for(;!r.type.is(e);)if(!r.nextSibling())return i}for(;;){if(s!=null&&r.type.is(s))return i;if(r.type.is(t)&&i.push(r.node),!r.nextSibling())return s==null?i:[]}}function Mt(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 Ut=class{constructor(t,e,s,r){this.parent=t,this.buffer=e,this.index=s,this.start=r}},Pt=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,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,s);return i<0?null:new o(this.context,this,i)}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&T.ExcludeBuffers)return null;let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return i<0?null:new o(this.context,this,i)}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 mt(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:s}=this.context,r=this.index+4,i=s.buffer[this.index+3];if(i>r){let n=s.buffer[this.index+1];t.push(s.slice(r,i,n)),e.push(0)}return new E(this.type,t,e,this.to-this.from)}resolve(t,e=0){return gt(this,t,e,!1)}resolveInner(t,e=0){return gt(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Ce(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,s=null){let r=Nt(this,t,e,s);return r.length?r[0]:null}getChildren(t,e=null,s=null){return Nt(this,t,e,s)}get node(){return this}matchContext(t){return Mt(this,t)}},mt=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 ht)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 ht?(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,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,s);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(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&T.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&T.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&T.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 i=0;i<this.index;i++)if(r.buffer.buffer[i+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 i=e+t,n=t<0?-1:s._tree.children.length;i!=n;i+=t){let l=s._tree.children[i];if(this.mode&T.IncludeAnonymous||l instanceof lt||!l.type.isAnonymous||Yt(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,i=this.stack.length;i>=0;){for(let n=t;n;n=n._parent)if(n.index==r){if(r==this.index)return n;e=n,s=i+1;break t}r=this.stack[--i]}for(let r=s;r<this.stack.length;r++)e=new Pt(this.buffer,e,this.stack[r]);return this.bufferNode=new Pt(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 Mt(this.node,t);let{buffer:e}=this.buffer,{types:s}=e.set;for(let r=t.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return Mt(this.node,t,r);let n=s[e.buffer[this.stack[i]]];if(!n.isAnonymous){if(t[r]&&t[r]!=n.name)return!1;r--}}return!0}};function Yt(o){return o.children.some(t=>t instanceof lt||!t.type.isAnonymous||Yt(t))}function ss(o){var t;let{buffer:e,nodeSet:s,maxBufferLength:r=1024,reused:i=[],minRepeatType:n=s.types.length}=o,l=Array.isArray(e)?new Wt(e,e.length):e,h=s.types,a=0,f=0;function c(R,v,b,k,N){let{id:x,start:y,end:D,size:B}=l,$=f;for(;B<0;)if(l.next(),B==-1){let H=i[x];b.push(H),k.push(y-R);return}else if(B==-3){a=x;return}else if(B==-4){f=x;return}else throw new RangeError(`Unrecognized record size: ${B}`);let pt=h[x],q,Y,be=y-R;if(D-y<=r&&(Y=Z(l.pos-v,N))){let H=new Uint16Array(Y.size-Y.skip),j=l.pos-Y.size,K=H.length;for(;l.pos>j;)K=ft(Y.start,H,K);q=new lt(H,D-Y.start,s),be=Y.start-R}else{let H=l.pos-B;l.next();let j=[],K=[],ot=x>=n?x:-1,dt=0,Dt=D;for(;l.pos>H;)ot>=0&&l.id==ot&&l.size>=0?(l.end<=Dt-r&&(g(j,K,y,dt,l.end,Dt,ot,$),dt=j.length,Dt=l.end),l.next()):c(y,H,j,K,ot);if(ot>=0&&dt>0&&dt<j.length&&g(j,K,y,dt,y,Dt,ot,$),j.reverse(),K.reverse(),ot>-1&&dt>0){let we=p(pt);q=Kt(pt,j,K,0,j.length,0,D-y,we,we)}else q=S(pt,j,K,D-y,$-D)}b.push(q),k.push(be)}function p(R){return(v,b,k)=>{let N=0,x=v.length-1,y,D;if(x>=0&&(y=v[x])instanceof E){if(!x&&y.type==R&&y.length==k)return y;(D=y.prop(C.lookAhead))&&(N=b[x]+y.length+D)}return S(R,v,b,k,N)}}function g(R,v,b,k,N,x,y,D){let B=[],$=[];for(;R.length>k;)B.push(R.pop()),$.push(v.pop()+b-N);R.push(S(s.types[y],B,$,x-N,D-x)),v.push(N-b)}function S(R,v,b,k,N=0,x){if(a){let y=[C.contextHash,a];x=x?[y].concat(x):[y]}if(N>25){let y=[C.lookAhead,N];x=x?[y].concat(x):[y]}return new E(R,v,b,k,x)}function Z(R,v){let b=l.fork(),k=0,N=0,x=0,y=b.end-r,D={size:0,start:0,skip:0};t:for(let B=b.pos-R;b.pos>B;){let $=b.size;if(b.id==v&&$>=0){D.size=k,D.start=N,D.skip=x,x+=4,k+=4,b.next();continue}let pt=b.pos-$;if($<0||pt<B||b.start<y)break;let q=b.id>=n?4:0,Y=b.start;for(b.next();b.pos>pt;){if(b.size<0)if(b.size==-3)q+=4;else break t;else b.id>=n&&(q+=4);b.next()}N=Y,k+=$,x+=q}return(v<0||k==R)&&(D.size=k,D.start=N,D.skip=x),D.size>4?D:void 0}function ft(R,v,b){let{id:k,start:N,end:x,size:y}=l;if(l.next(),y>=0&&k<n){let D=b;if(y>4){let B=l.pos-(y-4);for(;l.pos>B;)b=ft(R,v,b)}v[--b]=D,v[--b]=x-R,v[--b]=N-R,v[--b]=k}else y==-3?a=k:y==-4&&(f=k);return b}let nt=[],ct=[];for(;l.pos>0;)c(o.start||0,o.bufferStart||0,nt,ct,-1);let V=(t=o.length)!==null&&t!==void 0?t:nt.length?ct[0]+nt[0].length:0;return new E(h[o.topID],nt.reverse(),ct.reverse(),V)}var ke=new WeakMap;function Tt(o,t){if(!o.isAnonymous||t instanceof lt||t.type!=o)return 1;let e=ke.get(t);if(e==null){e=1;for(let s of t.children){if(s.type!=o||!(s instanceof E)){e=1;break}e+=Tt(o,s)}ke.set(t,e)}return e}function Kt(o,t,e,s,r,i,n,l,h){let a=0;for(let S=s;S<r;S++)a+=Tt(o,t[S]);let f=Math.ceil(a*1.5/8),c=[],p=[];function g(S,Z,ft,nt,ct){for(let V=ft;V<nt;){let R=V,v=Z[V],b=Tt(o,S[V]);for(V++;V<nt;V++){let k=Tt(o,S[V]);if(b+k>=f)break;b+=k}if(V==R+1){if(b>f){let k=S[R];g(k.children,k.positions,0,k.children.length,Z[R]+ct);continue}c.push(S[R])}else{let k=Z[V-1]+S[V-1].length-v;c.push(Kt(o,S,Z,R,V,v,k,null,h))}p.push(v+ct-i)}}return g(t,e,s,r,0),(l||h)(c,p,n)}var Ft=class{startParse(t,e,s){return typeof t=="string"&&(t=new Xt(t)),s=s?s.length?s.map(r=>new Rt(r.from,r.to)):[new Rt(0,0)]:[new Rt(0,t.length)],this.createParse(t,e||[],s)}parse(t,e,s){let r=this.startParse(t,e,s);for(;;){let i=r.advance();if(i)return i}}},Xt=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 Gs=new C({perNode:!0});var Zt=class o{constructor(t,e,s,r,i,n,l,h,a,f=0,c){this.p=t,this.stack=e,this.state=s,this.reducePos=r,this.pos=i,this.score=n,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 Vt(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:i}=this.p,n=i.dynamicPrecedence(r);if(n&&(this.score+=n),s==0){this.pushState(i.getGoto(this.state,r,!0),this.reducePos),r<i.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<i.minRepeatTerm||t&131072){let p=i.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=i.getGoto(p,r,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(r,h)}storeNode(t,e,s,r=4,i=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let n=this,l=this.buffer.length;if(l==0&&n.parent&&(l=n.bufferBase-n.parent.bufferBase,n=n.parent),l>0&&n.buffer[l-4]==0&&n.buffer[l-1]>-1){if(e==s)return;if(n.buffer[l-2]>=e){n.buffer[l-2]=s;return}}}if(!i||this.pos==s)this.buffer.push(t,e,s,r);else{let n=this.buffer.length;if(n>0&&this.buffer[n-4]!=0)for(;n>0&&this.buffer[n-2]>s;)this.buffer[n]=this.buffer[n-4],this.buffer[n+1]=this.buffer[n-3],this.buffer[n+2]=this.buffer[n-2],this.buffer[n+3]=this.buffer[n-1],n-=4,r>4&&(r-=4);this.buffer[n]=t,this.buffer[n+1]=e,this.buffer[n+2]=s,this.buffer[n+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 i=t,{parser:n}=this.p;(s>this.pos||e<=n.maxNode)&&(this.pos=s,n.stateFlag(i,1)||(this.reducePos=s)),this.pushState(i,r),this.shiftContext(e,r),e<=n.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 qt(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 i=0,n;i<e.length;i+=2)(n=e[i+1])!=this.state&&this.p.parser.hasAction(n,t)&&r.push(e[i],n);if(this.stack.length<120)for(let i=0;r.length<8&&i<e.length;i+=2){let n=e[i+1];r.some((l,h)=>h&1&&l==n)||r.push(e[i],n)}e=r}let s=[];for(let r=0;r<e.length&&s.length<4;r+=2){let i=e[r+1];if(i==this.state)continue;let n=this.split();n.pushState(i,this.pos),n.storeNode(0,n.pos,n.pos,4,!0),n.shiftContext(e[r],this.pos),n.score-=200,s.push(n)}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,i=this.stack.length-s*3;if(i<0||t.getGoto(this.stack[i],r,!1)<0){let n=this.findForcedReduction();if(n==null)return!1;e=n}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,i)=>{if(!e.includes(r))return e.push(r),t.allActions(r,n=>{if(!(n&393216))if(n&65536){let l=(n>>19)-i;if(l>1){let h=n&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(n,i+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 Vt(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()}},Vt=class{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}},Re;(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"})(Re||(Re={}));var qt=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}},Ht=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 Ot(o,t=Uint16Array){if(typeof o!="string")return o;let e=null;for(let s=0,r=0;s<o.length;){let i=0;for(;;){let n=o.charCodeAt(s++),l=!1;if(n==126){i=65535;break}n>=92&&n--,n>=34&&n--;let h=n-32;if(h>=46&&(h-=46,l=!0),i+=h,l)break;i*=46}e?e[r++]=i:e=new t(i)}return e}var bt=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},Pe=new bt,te=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=Pe,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,i=this.pos+t;for(;i<s.from;){if(!r)return null;let n=this.ranges[--r];i-=s.from-n.to,s=n}for(;e<0?i>s.to:i>=s.to;){if(r==this.ranges.length-1)return null;let n=this.ranges[++r];i+=n.from-s.to,s=n}return i}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 i=this.resolveOffset(t,1);if(i==null)return-1;if(s=i,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let n=this.rangeIndex,l=this.range;for(;l.to<=s;)l=this.ranges[++n];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=Pe,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}},tt=class{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;Ne(this.data,t,e,this.id,s.data,s.tokenPrecTable)}};tt.prototype.contextual=tt.prototype.fallback=tt.prototype.extend=!1;var ee=class{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?Ot(t):t}token(t,e){let s=t.pos,r=0;for(;;){let i=t.next<0,n=t.resolveOffset(1,1);if(Ne(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(i||r++,n==null)break;t.reset(n,t.token)}r&&(t.reset(s,t.token),t.acceptToken(this.elseToken,r))}};ee.prototype.contextual=tt.prototype.fallback=tt.prototype.extend=!1;function Ne(o,t,e,s,r,i){let n=0,l=1<<s,{dialect:h}=e.p.parser;t:for(;l&o[n];){let a=o[n+1];for(let g=n+3;g<a;g+=2)if((o[g+1]&l)>0){let S=o[g];if(h.allows(S)&&(t.token.value==-1||t.token.value==S||is(S,t.token.value,r,i))){t.acceptToken(S);break}}let f=t.next,c=0,p=o[n+2];if(t.next<0&&p>c&&o[a+p*3-3]==65535&&o[a+p*3-3]==65535){n=o[a+p*3-1];continue t}for(;c<p;){let g=c+p>>1,S=a+g+(g<<1),Z=o[S],ft=o[S+1]||65536;if(f<Z)p=g;else if(f>=ft)c=g+1;else{n=o[S+2],t.advance();continue t}}break}}function Oe(o,t,e){for(let s=t,r;(r=o[s])!=65535;s++)if(r==e)return s-t;return-1}function is(o,t,e,s){let r=Oe(e,s,t);return r<0||Oe(e,s,o)<r}var W=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Jt=null,ve;(function(o){o[o.Margin=25]="Margin"})(ve||(ve={}));function De(o,t,e){let s=o.cursor(T.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 se=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?De(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?De(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 i=s.children[r],n=this.start[e]+s.positions[r];if(n>t)return this.nextStart=n,null;if(i instanceof E){if(n==t){if(n<this.safeFrom)return null;let l=n+i.length;if(l<=this.safeTo){let h=i.prop(C.lookAhead);if(!h||l+h<this.fragment.to)return i}}this.index[e]++,n+i.length>=Math.max(this.safeFrom,t)&&(this.trees.push(i),this.start.push(n),this.index.push(0))}else this.index[e]++,this.nextStart=n+i.length}}},re=class{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new bt)}getActions(t){let e=0,s=null,{parser:r}=t.p,{tokenizers:i}=r,n=r.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let a=0;a<i.length;a++){if(!(1<<a&n))continue;let f=i[a],c=this.tokens[a];if(!(s&&!f.fallback)&&((f.contextual||c.start!=t.pos||c.mask!=n||c.context!=l)&&(this.updateCachedToken(c,f,t),c.mask=n,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 bt,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 bt,{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:i}=s.p;for(let n=0;n<i.specialized.length;n++)if(i.specialized[n]==t.value){let l=i.specializers[n](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 i=0;i<r;i+=3)if(this.actions[i]==t)return r;return this.actions[r++]=t,this.actions[r++]=e,this.actions[r++]=s,r}addActions(t,e,s,r){let{state:i}=t,{parser:n}=t.p,{data:l}=n;for(let h=0;h<2;h++)for(let a=n.stateSlot(i,h?2:1);;a+=3){if(l[a]==65535)if(l[a+1]==1)a=J(l,a+2);else{r==0&&l[a+1]==2&&(r=this.putAction(J(l,a+2),e,s,r));break}l[a]==e&&(r=this.putAction(J(l,a+1),e,s,r))}return r}},Ae;(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"})(Ae||(Ae={}));var ie=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 te(e,r),this.tokens=new re(t,this.stream),this.topTerm=t.top[1];let{from:i}=r[0];this.stacks=[Zt.start(this,t.top[0],i)],this.fragments=s.length&&this.stream.end-i>t.bufferLength*4?new se(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],r,i;if(this.bigReductionCount>300&&t.length==1){let[n]=t;for(;n.forceReduce()&&n.stack.length&&n.stack[n.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let n=0;n<t.length;n++){let l=t[n];for(;;){if(this.tokens.mainToken=null,l.pos>e)s.push(l);else{if(this.advanceStack(l,s,t))continue;{r||(r=[],i=[]),r.push(l);let h=this.tokens.getMainToken(l);i.push(h.value,h.end)}}break}}if(!s.length){let n=r&&ns(r);if(n)return this.stackToTree(n);if(this.parser.strict)throw W&&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 n=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,i,s);if(n)return this.stackToTree(n.forceAll())}if(this.recovering){let n=this.recovering==1?1:this.recovering*3;if(s.length>n)for(s.sort((l,h)=>h.score-l.score);s.length>n;)s.pop();s.some(l=>l.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let n=0;n<s.length-1;n++){let l=s[n];for(let h=n+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(n--,1);continue t}}}s.length>12&&s.splice(12,s.length-12)}this.minStackPos=s[0].pos;for(let n=1;n<s.length;n++)s[n].pos<this.minStackPos&&(this.minStackPos=s[n].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:i}=this,n=W?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?i.getGoto(t.state,c.type.id):-1;if(p>-1&&c.length&&(!a||(c.prop(C.contextHash)||0)==f))return t.useNode(c,p),W&&console.log(n+this.stackID(t)+` (via reuse of ${i.getName(c.type.id)})`),!0;if(!(c instanceof E)||c.children.length==0||c.positions[0]>0)break;let g=c.children[0];if(g instanceof E&&c.positions[0]==0)c=g;else break}}let l=i.stateSlot(t.state,4);if(l>0)return t.reduce(l),W&&console.log(n+this.stackID(t)+` (via always-reduce ${i.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++],g=a==h.length||!s,S=g?t:t.split();if(S.apply(f,c,p),W&&console.log(n+this.stackID(S)+` (via ${f&65536?`reduce of ${i.getName(f&65535)}`:"shift"} for ${i.getName(c)} @ ${r}${S==t?"":", split"})`),g)return!0;S.pos>r?e.push(S):s.push(S)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return Te(t,e),!0}}runRecovery(t,e,s){let r=null,i=!1;for(let n=0;n<t.length;n++){let l=t[n],h=e[n<<1],a=e[(n<<1)+1],f=W?this.stackID(l)+" -> ":"";if(l.deadEnd&&(i||(i=!0,l.restart(),W&&console.log(f+this.stackID(l)+" (restarted)"),this.advanceFully(l,s))))continue;let c=l.split(),p=f;for(let g=0;c.forceReduce()&&g<10&&(W&&console.log(p+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,s));g++)W&&(p=this.stackID(c)+" -> ");for(let g of l.recoverByInsert(h))W&&console.log(f+this.stackID(g)+" (via recover-insert)"),this.advanceFully(g,s);this.stream.end>l.pos?(a==l.pos&&(a++,h=0),l.recoverByDelete(h,a),W&&console.log(f+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),Te(l,s)):(!r||r.score<l.score)&&(r=l)}return r}stackToTree(t){return t.close(),E.build({buffer:Ht.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=(Jt||(Jt=new WeakMap)).get(t);return e||Jt.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}};function Te(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 ne=class{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}};var Bt=class o extends Ft{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 i(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=C[h]);for(let a=1;a<l.length;){let f=l[a++];if(f>=0)i(f,h,l[a++]);else{let c=l[a+-f];for(let p=-f;p>0;p--)i(l[a++],h,c);a++}}}this.nodeSet=new It(e.map((l,h)=>z.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 n=Ot(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(Ie),this.states=Ot(t.states,Uint32Array),this.data=Ot(t.stateData),this.goto=Ot(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new tt(n,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 ie(this,t,e,s);for(let i of this.wrappers)r=i(r,t,e,s);return r}getGoto(t,e,s=!1){let r=this.goto;if(e>=r[0])return-1;for(let i=r[e+1];;){let n=r[i++],l=n&1,h=r[i++];if(l&&s)return h;for(let a=i+(n>>1);i<a;i++)if(r[i]==t)return h;if(l)return-1}}hasAction(t,e){let s=this.data;for(let r=0;r<2;r++)for(let i=this.stateSlot(t,r?2:1),n;;i+=3){if((n=s[i])==65535)if(s[i+1]==1)n=s[i=J(s,i+2)];else{if(s[i+1]==2)return J(s,i+2);break}if(n==e||n==0)return J(s,i+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 i=this.stateSlot(t,1);r==null;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=J(this.data,i+2);else break;r=e(J(this.data,i+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=J(this.data,s+2);else break;if(!(this.data[s+2]&1)){let r=this.data[s+1];e.some((i,n)=>n&1&&i==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(i=>i.from==s);return r?r.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,r)=>{let i=t.specializers.find(l=>l.from==s.external);if(!i)return s;let n=Object.assign(Object.assign({},s),{external:i.to});return e.specializers[r]=Ie(n),n})),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 i of t.split(" ")){let n=e.indexOf(i);n>=0&&(s[n]=!0)}let r=null;for(let i=0;i<e.length;i++)if(!s[i])for(let n=this.dialects[e[i]],l;(l=this.data[n++])!=65535;)(r||(r=new Uint8Array(this.maxTerm+1)))[l]=1;return new ne(t,s,r)}static deserialize(t){return new o(t)}};function J(o,t){return o[t]|o[t+1]<<16}function ns(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 Ie(o){if(o.external){let t=o.extend?1:0;return(e,s)=>o.external(e,s)<<1|t}return o.get}var oe=Bt.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});var U=require("@vuu-ui/vuu-utils");var Q,le=class{constructor(){P(this,Q,void 0)}setFilterCombinatorOp(t,e=u(this,Q)){(0,U.isMultiClauseFilter)(e)&&e.op===t||m(this,Q,{op:t,filters:[u(this,Q)]})}add(t){if(u(this,Q)===void 0)m(this,Q,t);else if((0,U.isMultiClauseFilter)(u(this,Q)))u(this,Q).filters.push(t);else throw Error("Invalid filter passed to FilterExpression")}setColumn(t,e=u(this,Q)){if((0,U.isMultiClauseFilter)(e)){let s=e.filters.at(-1);s&&this.setColumn(t,s)}else e&&(e.column=t)}setOp(t,e=u(this,Q)){if((0,U.isMultiClauseFilter)(e)){let s=e.filters.at(-1);s&&this.setOp(t,s)}else e&&(e.op=t)}setValue(t,e=u(this,Q)){var s;if((0,U.isMultiClauseFilter)(e)){let r=e.filters.at(-1);r&&this.setValue(t,r)}else(0,U.isMultiValueFilter)(e)?((s=e.values)!=null||(e.values=[]),e.values.push(t)):(0,U.isSingleValueFilter)(e)&&(e.value=t)}toJSON(t=u(this,Q)){return this.name?{...t,name:this.name}:t}};Q=new WeakMap;var he=(o,t)=>{let e=new le,s=o.cursor();do{let{name:r,from:i,to:n}=s;switch(r){case"ColumnValueExpression":e.add({});break;case"ColumnSetExpression":e.add({op:"in"});break;case"Or":case"And":e.setFilterCombinatorOp(t.substring(i,n));break;case"Column":e.setColumn(t.substring(i,n));break;case"Operator":e.setOp(t.substring(i,n));break;case"String":e.setValue(t.substring(i+1,n-1));break;case"Number":e.setValue(parseFloat(t.substring(i,n)));break;case"True":e.setValue(!0);break;case"False":e.setValue(!1);break;case"FilterName":e.name=t.substring(i,n);break;default:}}while(s.next());return e.toJSON()};var os=oe.configure({strict:!0}),wt=o=>{let t=os.parse(o);return he(t,o)};function Et(o,t){switch(t.op){case"in":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"<=":return cs(o,t);case"ends":return ps(o,t);case"starts":return ds(o,t);case"and":return gs(o,t);case"or":return ms(o,t);default:return console.log(`unrecognized filter type ${t.op}`),()=>!0}}var ls=(o,t)=>e=>t.values.indexOf(e[o[t.column]])!==-1,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)=>e=>e[o[t.column]]<=t.value,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().endsWith(e.toLowerCase())}},ds=(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())}},gs=(o,t)=>{let e=t.filters.map(s=>Et(o,s));return s=>e.every(r=>r(s))};function ms(o,t){let e=t.filters.map(s=>Et(o,s));return s=>e.some(r=>r(s))}var d=require("@vuu-ui/vuu-utils");var Me=(o,t,e,s,r,i)=>{let n=o[o.length-1].aggType,l=e.map(h=>r[h]);switch(n){case 1:return Ve(i,s,r,o,t,l);case 2:return bs(i,s,r,o,t,l);case 3:return Fe(i,r,o,t,l);case 4:return Ss(i,s,r,o,t,l);case 5:return ys(i,s,r,o,t,l);case 6:return ws(i,s,r,o,t,l)}};function Fe(o,t,e,s,r){let i={},n=St(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]);i[h]=a}for(let h=0;h<s.length;h++)for(let a in i)s[h][r[0]]===a&&(s[h][n]=i[a]);return console.log("!!!! targetData",s),console.log("!!!! counts",i),i}function St(o,t){console.log("!!!! aggregation length",t.length);let e=t[t.length-1].column;return o[e]}function Ve(o,t,e,s,r,i){let n={},l=St(e,s);function h(a,f,c){if(Array.isArray(a)){let p=0;for(let g of a)p+=Number(f[g][c]);return p}else{let p=0;for(let g in a)p+=h(a[g],f,c);return p}}for(let a in o){console.log(a);let f=Number(h(o[a],t,l));n[a]=f}for(let a=0;a<r.length;a++)for(let f in n)r[a][i[0]]===f&&(r[a][l]=n[f]);return console.log("!!!! targetData",r),console.log("!!!! sums",n),n}function bs(o,t,e,s,r,i){let n={},l=St(e,s),h=Fe(o,e,s,r,i),a=Ve(o,t,e,s,r,i);for(let f in h){let c=0;c=a[f]/h[f],n[f]=c}for(let f=0;f<r.length;f++)for(let c in n)r[f][i[0]]===c&&(r[f][l]=n[c]);return console.log("!!!! targetData",r),console.log("!!!! averages",n),n}function Qt(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(...Qt(o[r],t,e));return s}function ws(o,t,e,s,r,i){let n={},l=St(e,s);for(let h in o){let a=Qt(o[h],t,l),f=[...new Set(a)];n[h]=f}for(let h=0;h<r.length;h++)for(let a in n)r[h][i[0]]===a&&(r[h][l]=n[a]);return n}function Ss(o,t,e,s,r,i){let n={},l=St(e,s);for(let h in o){let a=Qt(o[h],t,l),f=Math.max(...a);n[h]=f}for(let h=0;h<r.length;h++)for(let a in n)r[h][i[0]]===a&&(r[h][l]=n[a]);return n}function ys(o,t,e,s,r,i){let n={},l=St(e,s);for(let h in o){let a=Qt(o[h],t,l),f=Math.min(...a);n[h]=f}for(let h=0;h<r.length;h++)for(let a in n)r[h][i[0]]===a&&(r[h][l]=n[a]);return n}var at=require("@vuu-ui/vuu-utils"),{RENDER_IDX:ks,SELECTED:xs}=at.metadataKeys,ae=(o,t,e,s)=>{let[r]=o,i;if(s){let{count:n}=at.metadataKeys;i=o.slice(0,n).concat(s.map(l=>o[l]))}else i=o.slice();return i[ks]=t.keyFor(r),i[xs]=(0,at.getSelectionStatus)(e,r),i},Cs=(o,t)=>{if(t){let{count:e}=at.metadataKeys;for(let[s,r]of Object.entries(o)){let i=t[s];if(i===void 0)throw Error(`ArrayDataSource column ${s} is not in underlying data set`);if(i!==r-e)return!0}}return!1},Rs=(o,t)=>{let{count:e}=at.metadataKeys,s=[];return Object.entries(o).forEach(([r])=>{s.push(t[r]+e)}),s},ue=(o,t)=>{if(t&&Cs(o,t))return Rs(o,t)};var Be=require("@vuu-ui/vuu-utils"),{DEPTH:fe,IS_EXPANDED:Ee,KEY:ce}=Be.metadataKeys,Qe=(o,t)=>{let e=[];for(let s=0,r=0,i=!1,n=t.length;s<n;s++){let l=t[s],{[fe]:h,[ce]:a}=l;if(a===o){let f=l.slice();for(f[Ee]=!1,e.push(f),r+=1,i=!0;s<n-1&&t[s+1][fe]>h;)s+=1}else if(i){let f=l.slice();f[0]=r,f[1]=r,e.push(f),r+=1}else e.push(l),r+=1}return e},pe=(o,t,e,s,r,i)=>{let n=e.map(l=>s[l]);return ze(r,n,o,t,void 0,void 0,void 0,i)},ze=(o,t,e,s=[],r="$root",i=1,n=[],l)=>{console.log("dataRowsFromGroups2 1)");let h=Object.keys(o).sort();for(let a of h){let f=n.length,c=`${r}|${a}`,p=[f,f,!1,!1,i,0,c,0];p[t[i-1]]=a,n.push(p),e.includes(c)&&(p[Ee]=!0,Array.isArray(o[a])?Ps(n,o[a],s,c,i+1):ze(o[a],t,e,s,c,i+1,n,l))}console.log("dataRowsFromGroups2 2)");for(let a in n)for(let f in n)if(n[a][2]===!1&&l[f]!=null&&n[a][t[0]]===l[f][t[0]]){n[a]=n[a].splice(0,8).concat(l[f].slice(8,l[f].length));break}return console.log("dataRowsFromGroups2 3)"),n},Ps=(o,t,e,s,r)=>{for(let i of t){let n=o.length,l=e[i].slice();l[0]=n,l[1]=n,l[fe]=r,l[ce]=`${s}|${l[ce]}`,o.push(l)}},Ge=(o,t,e)=>{let s=t.map(n=>e[n]),r=vs(o,s);return[Os(r,s),r]},Os=(o,t)=>{let s=[],r=0,i=Object.keys(o).sort();for(let n of i){let l=[r,r,!1,!1,1,0,`$root|${n}`,0];l[t[0]]=n,s.push(l),r+=1}return s};function vs(o,t){let e={},s=t.length,r=s-1;for(let i=0,n=o.length;i<n;i++){let l=o[i],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(i):a?h=a:!a&&c<r?h=h[f]={}:a||(h[f]=[i])}}return console.log("!! groups",e),e}var Ds=(o,t,[e,s])=>{let r=s==="D"?t[e]:o[e],i=s==="D"?o[e]:t[e];return r===i?0:i===null||r>i?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],i=t==="D"?e[o]:s[o];return r>i?1:i>r?-1:0},Is=([[o,t],[e,s]])=>(r,i)=>{let n=t==="D"?i[o]:r[o],l=t==="D"?r[o]:i[o],h=s==="D"?i[e]:r[e],a=s==="D"?r[e]:i[e];return n>l?1:l>n?-1:h>a?1:a>h?-1:0},Ns=(o,t=Ds)=>(e,s)=>{for(let r of o){let i=t(e,s,r);if(i!==0)return i}return 0},Le=(o,{sortDefs:t},e)=>{let s=t.map(({column:i,sortType:n})=>[e[i],n]),r=As(s);return o.slice().sort(r)};var{debug:G,info:yt}=(0,d.logger)("ArrayDataSource"),{KEY:_e}=d.metadataKeys,de=o=>(t,e)=>[e,e,!0,!1,1,0,String(t[o]),0,...t],Ms=(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"}}),F,w,A,zt,O,vt,Gt,L,kt,ge=class extends d.EventEmitter{constructor({aggregations:e,columnDescriptors:s,data:r,dataMap:i,filter:n,groupBy:l,keyColumn:h,rangeChangeRowset:a="delta",sort:f,title:c,viewport:p}){super();this.lastRangeServed={from:0,to:0};this.openTreeNodes=[];P(this,F,void 0);P(this,w,d.vanillaConfig);P(this,A,void 0);P(this,zt,void 0);P(this,O,d.NULL_RANGE);P(this,vt,0);P(this,Gt,0);P(this,L,"initialising");P(this,kt,void 0);this.selectedRows=[];this.keys=new d.KeySet(u(this,O));this.processedData=void 0;this.insert=e=>{let s=de(this.key)(e,this.size);u(this,A).push(s);let{from:r,to:i}=u(this,O),[n]=s;n>=r&&n<i&&this.sendRowsToClient()};this.update=(e,s)=>{var h;let r=e[this.key],i=u(this,F)[s],n=(h=this.dataMap)==null?void 0:h[s],l=u(this,A).findIndex(a=>a[_e]===r);if(l!==-1&&n!==void 0){let a=u(this,A)[l];a[i]=e[n];let{from:f,to:c}=u(this,O),[p]=a;p>=f&&p<c&&this.sendRowsToClient(!1,a)}};this.updateRow=e=>{let s=e[this.key],r=u(this,A).findIndex(i=>i[_e]===s);if(r!==-1){let i=de(this.key)(e,r);u(this,A)[r]=i;let{from:n,to:l}=u(this,O);r>=n&&r<l&&this.sendRowsToClient(!1,i)}};if(!r||!s)throw Error("ArrayDataSource constructor called without data or without columnDescriptors");this.columnDescriptors=s,this.dataMap=i,this.key=h?this.columnDescriptors.findIndex(S=>S.name===h):0,this.rangeChangeRowset=a,this.tableSchema=Ms(s,h),this.viewport=p||(0,d.uuid)(),m(this,Gt,r.length),m(this,kt,c);let g=s.map(S=>S.name);m(this,F,(0,d.buildColumnMap)(g)),this.dataIndices=ue(u(this,F),this.dataMap),m(this,A,r.map(de(this.key))),this.config={...u(this,w),aggregations:e||u(this,w).aggregations,columns:g,filter:n||u(this,w).filter,groupBy:l||u(this,w).groupBy,sort:f||u(this,w).sort},G==null||G(`columnMap: ${JSON.stringify(u(this,F))}`)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:(0,d.uuid)())(),columns:s,aggregations:r,range:i,sort:n,groupBy:l,filter:h},a){var g;this.clientCallback=a,this.viewport=e,m(this,L,"subscribed"),this.lastRangeServed={from:0,to:0};let c=u(this,w),p=r||s||h||l||n;p&&(i&&m(this,O,i),c={...c,aggregations:r||u(this,w).aggregations,columns:s||u(this,w).columns,filter:h||u(this,w).filter,groupBy:l||u(this,w).groupBy,sort:n||u(this,w).sort}),(g=this.clientCallback)==null||g.call(this,{...c,type:"subscribed",clientViewportId:this.viewport,range:u(this,O),tableSchema:this.tableSchema}),p?this.config=c:(this.clientCallback({clientViewportId:this.viewport,mode:"size-only",type:"viewport-update",size:u(this,A).length}),i?(this.range=i,this.sendRowsToClient()):u(this,O)!==d.NULL_RANGE&&this.sendRowsToClient())}unsubscribe(){console.log("unsubscribe noop")}suspend(){return console.log(`suspend #${this.viewport}, current status ${u(this,L)}`),yt==null||yt(`suspend #${this.viewport}, current status ${u(this,L)}`),m(this,L,"suspended"),this}resume(){console.log(`resume #${this.viewport}, current status ${u(this,L)}`);let e=u(this,L)==="suspended";return yt==null||yt(`resume #${this.viewport}, current status ${u(this,L)}`),console.log("resume noop"),e&&m(this,L,"subscribed"),this}disable(){return console.log("disable noop"),this}enable(){return console.log("enable noop"),this}select(e){m(this,vt,e.length),G==null||G(`select ${JSON.stringify(e)}`),this.selectedRows=e,this.setRange((0,d.resetRange)(u(this,O)),!0)}openTreeNode(e){this.openTreeNodes.push(e),this.processedData=pe(this.openTreeNodes,u(this,A),u(this,w).groupBy,u(this,F),this.groupMap,this.processedData),this.setRange((0,d.resetRange)(u(this,O)),!0)}closeTreeNode(e){this.openTreeNodes=this.openTreeNodes.filter(s=>s!==e),this.processedData&&(this.processedData=Qe(e,this.processedData),this.setRange((0,d.resetRange)(u(this,O)),!0))}get links(){return u(this,zt)}get menu(){return this._menu}get status(){return u(this,L)}get data(){return u(this,A)}get currentData(){var e;return(e=this.processedData)!=null?e:u(this,A)}get table(){return this.tableSchema.table}get config(){return u(this,w)}set config(e){var r;let s=this.applyConfig(e);if(s){if(e){let i=u(this,w),n=(r=e==null?void 0:e.filter)!=null&&r.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:wt(e.filter.filter)}}:e;m(this,w,(0,d.withConfigDefaults)(n));let l;if((0,d.hasFilter)(e)){let{filter:h,filterStruct:a=wt(h)}=e.filter;if(a){let f=Et(u(this,F),a);l=u(this,A).filter(f)}else throw Error("filter must include filterStruct")}if((0,d.hasSort)(e)&&(l=Le(l!=null?l:u(this,A),e.sort,u(this,F))),this.openTreeNodes.length>0&&(0,d.isGroupByChanged)(i,e)&&(u(this,w).groupBy.length===0?this.openTreeNodes.length=0:console.log("adjust the openTReeNodes groupBy changed ",{originalGroupBy:i.groupBy,newGroupBy:n.groupBy})),(0,d.hasGroupBy)(e)){let[h,a]=Ge(l!=null?l:u(this,A),e.groupBy,u(this,F));this.groupMap=a,l=h,this.openTreeNodes.length>0&&(l=pe(this.openTreeNodes,u(this,A),u(this,w).groupBy,u(this,F),this.groupMap,l))}this.processedData=l==null?void 0:l.map((h,a)=>{let f=h.slice();return f[0]=a,f[1]=a,f})}this.setRange((0,d.resetRange)(u(this,O)),!0),this.emit("config",u(this,w),void 0,s)}}applyConfig(e){var i;let{noChanges:s,...r}=(0,d.isConfigChanged)(u(this,w),e);if(s!==!0&&e){let n=(i=e==null?void 0:e.filter)!=null&&i.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:wt(e.filter.filter)}}:e;return m(this,w,(0,d.withConfigDefaults)(n)),r}}get selectedRowsCount(){return u(this,vt)}get size(){var e,s;return(s=(e=this.processedData)==null?void 0:e.length)!=null?s:u(this,A).length}get range(){return u(this,O)}set range(e){this.setRange(e)}delete(e){console.log(`delete row ${e.join(",")}`)}setRange(e,s=!1){if(e.from!==u(this,O).from||e.to!==u(this,O).to){m(this,O,e);let r=this.keys.reset(e);this.sendRowsToClient(s||r)}else s&&this.sendRowsToClient(s)}sendRowsToClient(e=!1,s){var r,i,n;if(s)(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"update",rows:[ae(s,this.keys,this.selectedRows,this.dataIndices)],type:"viewport-update"});else{let l=this.rangeChangeRowset==="delta"&&!e?(0,d.rangeNewItems)(this.lastRangeServed,u(this,O)):u(this,O),h=(i=this.processedData)!=null?i:u(this,A),a=h.slice(l.from,l.to).map(f=>ae(f,this.keys,this.selectedRows,this.dataIndices));(n=this.clientCallback)==null||n.call(this,{clientViewportId:this.viewport,mode:"batch",rows:a,size:h.length,type:"viewport-update"}),this.lastRangeServed={from:u(this,O).from,to:Math.min(u(this,O).to,u(this,O).from+a.length)}}}get columns(){return u(this,w).columns}set columns(e){let s=(0,d.getAddedItems)(this.config.columns,e);if(s.length>0){let r=(0,d.getMissingItems)(this.columnDescriptors,s,i=>i.name);console.log("columnsWithoutDescriptors",{columnsWithoutDescriptors:r})}m(this,F,(0,d.buildColumnMap)(e)),this.dataIndices=ue(u(this,F),this.dataMap),this.config={...u(this,w),columns:e}}get aggregations(){return u(this,w).aggregations}set aggregations(e){var i;m(this,w,{...u(this,w),aggregations:e});let s=(i=this.processedData)!=null?i:u(this,A),r=u(this,A);Me(e,s,u(this,w).groupBy,r,u(this,F),this.groupMap),this.setRange((0,d.resetRange)(u(this,O)),!0),this.emit("config",u(this,w))}get sort(){return u(this,w).sort}set sort(e){G==null||G(`sort ${JSON.stringify(e)}`),this.config={...u(this,w),sort:e}}get filter(){return u(this,w).filter}set filter(e){G==null||G(`filter ${JSON.stringify(e)}`),this.config={...u(this,w),filter:e}}get groupBy(){return u(this,w).groupBy}set groupBy(e){this.config={...u(this,w),groupBy:e}}get title(){return u(this,kt)}set title(e){m(this,kt,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,A)[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)}})}};F=new WeakMap,w=new WeakMap,A=new WeakMap,zt=new WeakMap,O=new WeakMap,vt=new WeakMap,Gt=new WeakMap,L=new WeakMap,kt=new WeakMap;var I=require("@vuu-ui/vuu-utils");var Fs={columns:[],key:"",table:{module:"",table:""}},{DEPTH:ut,IDX:$e,IS_EXPANDED:Vs,IS_LEAF:Bs,KEY:Xe,SELECTED:je}=I.metadataKeys,We=(o,t)=>{let[e]=o,s=o.slice();return s[1]=t.keyFor(e),s},et,_,M,st,rt,X,Lt,_t,it,xt,Ct,me=class extends I.EventEmitter{constructor({aggregations:e,data:s,filter:r,groupBy:i,sort:n,title:l,viewport:h}){super();this.expandedRows=new Set;this.visibleRows=[];P(this,et,[]);P(this,_,I.vanillaConfig);P(this,M,void 0);P(this,st,{filter:""});P(this,rt,[]);P(this,X,{from:0,to:0});P(this,Lt,0);P(this,_t,0);P(this,it,{sortDefs:[]});P(this,xt,"initialising");P(this,Ct,void 0);this.keys=new I.KeySet(u(this,X));if(!s)throw Error("JsonDataSource constructor called without data");[this.columnDescriptors,jt(this,M)._]=(0,I.jsonToDataSourceRows)(s),this.visibleRows=u(this,M).filter(a=>a[ut]===0).map((a,f)=>[f,f].concat(a.slice(2))),this.viewport=h||(0,I.uuid)(),e&&m(this,et,e),this.columnDescriptors&&m(this,_,{...u(this,_),columns:this.columnDescriptors.map(a=>a.name)}),r&&m(this,st,r),i&&m(this,rt,i),n&&m(this,it,n),m(this,Ct,l)}async subscribe({viewport:e=(f=>(f=this.viewport)!=null?f:(0,I.uuid)())(),columns:s,aggregations:r,range:i,sort:n,groupBy:l,filter:h},a){var c;this.clientCallback=a,r&&m(this,et,r),s&&m(this,_,{...u(this,_),columns:s}),h&&m(this,st,h),l&&m(this,rt,l),i&&m(this,X,i),n&&m(this,it,n),u(this,xt)==="initialising"&&(this.viewport=e,m(this,xt,"subscribed"),(c=this.clientCallback)==null||c.call(this,{aggregations:u(this,et),type:"subscribed",clientViewportId:this.viewport,columns:u(this,_).columns,filter:u(this,st),groupBy:u(this,rt),range:u(this,X),sort:u(this,it),tableSchema:Fs}),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,jt(this,M)._]=(0,I.jsonToDataSourceRows)(e),this.visibleRows=u(this,M).filter(s=>s[ut]===0).map((s,r)=>[r,r].concat(s.slice(2))),requestAnimationFrame(()=>{this.sendRowsToClient()})}select(e){var r;let s=[];for(let i of u(this,M)){let{[$e]:n,[je]:l}=i,h=l===1,a=(0,I.isSelected)(e,n);if(a!==h){let f=i.slice();f[je]=a?1:0,u(this,M)[n]=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 i;this.expandedRows.add(e),this.visibleRows=Ue(u(this,M),this.expandedRows);let{from:s,to:r}=u(this,X);(i=this.clientCallback)==null||i.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(s,r).map(n=>We(n,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=Ue(u(this,M),this.expandedRows),this.sendRowsToClient()}get status(){return u(this,xt)}get config(){return u(this,_)}applyConfig(){return I.NO_CONFIG_CHANGES}get selectedRowsCount(){return u(this,Lt)}get size(){return u(this,_t)}get range(){return u(this,X)}set range(e){m(this,X,e),this.keys.reset(e),requestAnimationFrame(()=>{this.sendRowsToClient()})}sendRowsToClient(){var r;let{from:e,to:s}=u(this,X);(r=this.clientCallback)==null||r.call(this,{clientViewportId:this.viewport,mode:"batch",rows:this.visibleRows.slice(e,s).map(i=>We(i,this.keys)),size:this.visibleRows.length,type:"viewport-update"})}get columns(){return u(this,_).columns}set columns(e){m(this,_,{...u(this,_),columns:e})}get aggregations(){return u(this,et)}set aggregations(e){m(this,et,e)}get sort(){return u(this,it)}set sort(e){m(this,it,e)}get filter(){return u(this,st)}set filter(e){m(this,st,e)}get groupBy(){return u(this,rt)}set groupBy(e){m(this,rt,e)}get title(){return u(this,Ct)}set title(e){m(this,Ct,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,M).find(r=>r[Xe]===e);if(s){let{[$e]:r,[ut]:i}=s,n=r+1,l=[];do{let{[ut]:h}=u(this,M)[n];if(h===i+1)l.push(u(this,M)[n]);else if(h<=i)break;n+=1}while(n<u(this,M).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,M)).filter(i=>i[ut]===e)}};et=new WeakMap,_=new WeakMap,M=new WeakMap,st=new WeakMap,rt=new WeakMap,X=new WeakMap,Lt=new WeakMap,_t=new WeakMap,it=new WeakMap,xt=new WeakMap,Ct=new WeakMap;function Ue(o,t){let e=[],s={value:0};for(let r=0;r<o.length;r++){let i=o[r],{[ut]:n,[Xe]:l,[Bs]:h}=i,a=t.has(l);if(e.push(Es(i,s,a)),!h&&!a)do r+=1;while(r<o.length-1&&o[r+1][ut]>n)}return e}var Es=(o,t,e)=>{let s=o.slice();return s[0]=t.value,s[1]=t.value,e&&(s[Vs]=!0),t.value+=1,s};
2
2
  //# sourceMappingURL=index.js.map