@uwdata/mosaic-inputs 0.12.0 → 0.12.1

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # mosaic-inputs
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@uwdata/mosaic-inputs.svg)](https://www.npmjs.com/package/@uwdata/mosaic-inputs)
4
+
3
5
  Standalone data-driven components such as input menus, text search boxes, and sortable, load-on-scroll data tables. Input widgets integrate with Mosaic Params and Selections, and can either be used in a standalone fashion or draw values from a backing data table.
4
6
 
5
7
  The `mosaic-inputs` package is included as part of the [vgplot](https://github.com/uwdata/mosaic/tree/main/packages/vgplot) API.
@@ -6265,7 +6265,7 @@ function clausePoint(field2, value, {
6265
6265
  source,
6266
6266
  clients = source ? /* @__PURE__ */ new Set([source]) : void 0
6267
6267
  }) {
6268
- const predicate = value !== void 0 ? isNotDistinct(field2, literal(value)) : null;
6268
+ const predicate = value !== void 0 ? isIn(field2, [literal(value)]) : null;
6269
6269
  return {
6270
6270
  meta: { type: "point" },
6271
6271
  source,
@@ -6429,6 +6429,11 @@ var Menu = class extends MosaicClient {
6429
6429
  this.selectedValue(value2);
6430
6430
  }
6431
6431
  });
6432
+ } else {
6433
+ this.select.addEventListener("pointerenter", (evt) => {
6434
+ if (!evt.buttons) this.activate();
6435
+ });
6436
+ this.select.addEventListener("focus", () => this.activate());
6432
6437
  }
6433
6438
  }
6434
6439
  }
@@ -6448,6 +6453,9 @@ var Menu = class extends MosaicClient {
6448
6453
  reset() {
6449
6454
  this.select.selectedIndex = this.from ? 0 : -1;
6450
6455
  }
6456
+ activate() {
6457
+ this.selection.activate(clausePoint(this.field, 0, { source: this }));
6458
+ }
6451
6459
  publish(value) {
6452
6460
  const { selection, field: field2 } = this;
6453
6461
  if (isSelection(selection)) {
@@ -6554,17 +6562,28 @@ var Search = class extends MosaicClient {
6554
6562
  this.searchbox.value = value;
6555
6563
  }
6556
6564
  });
6565
+ } else {
6566
+ this.searchbox.addEventListener("pointerenter", (evt) => {
6567
+ if (!evt.buttons) this.activate();
6568
+ });
6569
+ this.searchbox.addEventListener("focus", () => this.activate());
6557
6570
  }
6558
6571
  }
6559
6572
  }
6560
6573
  reset() {
6561
6574
  this.searchbox.value = "";
6562
6575
  }
6576
+ clause(value) {
6577
+ const { field: field2, type } = this;
6578
+ return clauseMatch(field2, value, { source: this, method: type });
6579
+ }
6580
+ activate() {
6581
+ this.selection.activate(this.clause(""));
6582
+ }
6563
6583
  publish(value) {
6564
- const { selection, field: field2, type } = this;
6584
+ const { selection } = this;
6565
6585
  if (isSelection(selection)) {
6566
- const clause = clauseMatch(field2, value, { source: this, method: type });
6567
- selection.update(clause);
6586
+ selection.update(this.clause(value));
6568
6587
  } else if (isParam(selection)) {
6569
6588
  selection.update(value);
6570
6589
  }
@@ -6684,13 +6703,20 @@ var Slider = class extends MosaicClient {
6684
6703
  this.curval.innerText = value2;
6685
6704
  if (this.selection) this.publish(+value2);
6686
6705
  });
6687
- if (this.selection && !isSelection(this.selection)) {
6688
- this.selection.addEventListener("value", (value2) => {
6689
- if (value2 !== +this.slider.value) {
6690
- this.slider.value = value2;
6691
- this.curval.innerText = value2;
6692
- }
6693
- });
6706
+ if (this.selection) {
6707
+ if (!isSelection(this.selection)) {
6708
+ this.selection.addEventListener("value", (value2) => {
6709
+ if (value2 !== +this.slider.value) {
6710
+ this.slider.value = value2;
6711
+ this.curval.innerText = value2;
6712
+ }
6713
+ });
6714
+ } else {
6715
+ this.slider.addEventListener("pointerenter", (evt) => {
6716
+ if (!evt.buttons) this.activate();
6717
+ });
6718
+ this.slider.addEventListener("focus", () => this.activate());
6719
+ }
6694
6720
  }
6695
6721
  }
6696
6722
  query(filter = []) {
@@ -6714,20 +6740,27 @@ var Slider = class extends MosaicClient {
6714
6740
  }
6715
6741
  return this;
6716
6742
  }
6743
+ clause(value) {
6744
+ const { field: field2, selectionType } = this;
6745
+ if (selectionType === "interval") {
6746
+ const domain = [this.min ?? 0, value];
6747
+ return clauseInterval(field2, domain, {
6748
+ source: this,
6749
+ bin: "ceil",
6750
+ scale: { type: "identity", domain },
6751
+ pixelSize: this.step
6752
+ });
6753
+ } else {
6754
+ return clausePoint(field2, value, { source: this });
6755
+ }
6756
+ }
6757
+ activate() {
6758
+ this.selection.activate(this.clause(0));
6759
+ }
6717
6760
  publish(value) {
6718
- const { field: field2, selectionType, selection } = this;
6761
+ const { selection } = this;
6719
6762
  if (isSelection(selection)) {
6720
- if (selectionType === "interval") {
6721
- const domain = [this.min ?? 0, value];
6722
- selection.update(clauseInterval(field2, domain, {
6723
- source: this,
6724
- bin: "ceil",
6725
- scale: { type: "identity", domain },
6726
- pixelSize: this.step
6727
- }));
6728
- } else {
6729
- selection.update(clausePoint(field2, value, { source: this }));
6730
- }
6763
+ selection.update(this.clause(value));
6731
6764
  } else if (isParam(this.selection)) {
6732
6765
  selection.update(value);
6733
6766
  }
@@ -1,2 +1,2 @@
1
- var io={};function ts(e,t=!1){let r,n,s=io;function o(u){r=e(u).catch(()=>{}).finally(()=>{if(n){let{value:f}=n;n=null,o(f)}else r=null})}function i(u){n={event:u}}function c(u){r?i(u):o(u)}function a(u){s!==u&&requestAnimationFrame(()=>{let f=s;s=io,c(f)}),s=u}return t?a:c}var z=class{constructor(t){this._filterBy=t,this._requestUpdate=ts(()=>this.requestQuery(),!0),this._coordinator=null}get coordinator(){return this._coordinator}set coordinator(t){this._coordinator=t}get filterBy(){return this._filterBy}get filterStable(){return!0}fields(){return null}fieldInfo(t){return this}query(t){return null}queryPending(){return this}queryResult(t){return this}queryError(t){return this}requestQuery(t){let r=t||this.query(this.filterBy?.predicate(this));return this._coordinator.requestQuery(this,r)}requestUpdate(){this._requestUpdate()}initialize(){return this._coordinator.initializeClient(this)}update(){return this}};var pe=Uint8Array.of(65,82,82,79,87,49),j={V1:0,V2:1,V3:2,V4:3,V5:4};var V={NONE:0,Schema:1,DictionaryBatch:2,RecordBatch:3,Tensor:4,SparseTensor:5},l={Dictionary:-1,NONE:0,Null:1,Int:2,Float:3,Binary:4,Utf8:5,Bool:6,Decimal:7,Date:8,Time:9,Timestamp:10,Interval:11,List:12,Struct:13,Union:14,FixedSizeBinary:15,FixedSizeList:16,Map:17,Duration:18,LargeBinary:19,LargeUtf8:20,LargeList:21,RunEndEncoded:22,BinaryView:23,Utf8View:24,ListView:25,LargeListView:26},Wt={HALF:0,SINGLE:1,DOUBLE:2},rt={DAY:0,MILLISECOND:1},v={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},W={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},nt={Sparse:0,Dense:1};var Qt=Uint8Array,nr=Uint16Array,sr=Uint32Array,or=BigUint64Array,de=Int8Array,co=Int16Array,B=Int32Array,$=BigInt64Array,es=Float32Array,pt=Float64Array;function ao(e,t){let r=Math.log2(e)-3;return(t?[de,co,B,$]:[Qt,nr,sr,or])[r]}var Oa=Object.getPrototypeOf(Int8Array);function Yt(e,t){let r=0,n=e.length;if(n<=2147483648)do{let s=r+n>>>1;e[s]<=t?r=s+1:n=s}while(r<n);else do{let s=Math.trunc((r+n)/2);e[s]<=t?r=s+1:n=s}while(r<n);return r}function ir(e,t,r){if(t(e))return e;throw new Error(r(e))}function U(e,t,r){return t=Array.isArray(t)?t:Object.values(t),ir(e,n=>t.includes(n),r??(()=>`${e} must be one of ${t}`))}function cr(e,t){for(let[r,n]of Object.entries(e))if(n===t)return r;return"<Unknown>"}var st=e=>`Unsupported data type: "${cr(l,e)}" (id ${e})`,me=(e,t,r=!0,n=null)=>({name:e,type:t,nullable:r,metadata:n});function uo(e){return Object.hasOwn(e,"name")&&lo(e.type)}function lo(e){return typeof e?.typeId=="number"}function dt(e,t="",r=!0){return uo(e)?e:me(t,ir(e,lo,()=>"Data type expected."),r)}var ar=(e,t,r=!1,n=-1)=>({typeId:l.Dictionary,id:n,dictionary:e,indices:t||zt(),ordered:r});var ur=(e=32,t=!0)=>({typeId:l.Int,bitWidth:U(e,[8,16,32,64]),signed:t,values:ao(e,t)});var zt=()=>ur(32);var rs=(e=2)=>({typeId:l.Float,precision:U(e,Wt),values:[nr,es,pt][e]});var ns=()=>({typeId:l.Binary,offsets:B}),lr=()=>({typeId:l.Utf8,offsets:B});var ss=(e,t,r=128)=>({typeId:l.Decimal,precision:e,scale:t,bitWidth:U(r,[128,256]),values:or}),os=e=>({typeId:l.Date,unit:U(e,rt),values:e===rt.DAY?B:$});var is=(e=v.MILLISECOND,t=32)=>({typeId:l.Time,unit:U(e,v),bitWidth:U(t,[32,64]),values:t===32?B:$});var fr=(e=v.MILLISECOND,t=null)=>({typeId:l.Timestamp,unit:U(e,v),timezone:t,values:$}),cs=(e=W.MONTH_DAY_NANO)=>({typeId:l.Interval,unit:U(e,W),values:e===W.MONTH_DAY_NANO?void 0:B}),pr=e=>({typeId:l.List,children:[dt(e)],offsets:B}),dr=e=>({typeId:l.Struct,children:Array.isArray(e)&&uo(e[0])?e:Object.entries(e).map(([t,r])=>me(t,r))}),as=(e,t,r,n)=>(r??=t.map((s,o)=>o),{typeId:l.Union,mode:U(e,nt),typeIds:r,typeMap:r.reduce((s,o,i)=>(s[o]=i,s),{}),children:t.map((s,o)=>dt(s,`_${o}`)),typeIdForValue:n,offsets:B}),us=e=>({typeId:l.FixedSizeBinary,stride:e}),mr=(e,t)=>({typeId:l.FixedSizeList,stride:t,children:[dt(e)]}),fo=(e,t)=>({typeId:l.Map,keysSorted:e,children:[t],offsets:B});var ls=(e=v.MILLISECOND)=>({typeId:l.Duration,unit:U(e,v),values:$}),fs=()=>({typeId:l.LargeBinary,offsets:$}),ps=()=>({typeId:l.LargeUtf8,offsets:$}),ds=e=>({typeId:l.LargeList,children:[dt(e)],offsets:$}),ms=(e,t)=>({typeId:l.RunEndEncoded,children:[ir(dt(e,"run_ends"),r=>r.type.typeId===l.Int,()=>"Run-ends must have an integer type."),dt(t,"values")]});var hs=e=>({typeId:l.ListView,children:[dt(e,"value")],offsets:B}),xs=e=>({typeId:l.LargeListView,children:[dt(e,"value")],offsets:$});var ai=new pt(2),hr=ai.buffer,Ua=new $(hr),qa=new sr(hr),$a=new B(hr),Pa=new Qt(hr);function Z(e){if(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)throw Error(`BigInt exceeds integer number representation: ${e}`);return Number(e)}function xr(e,t){return Number(e/t)+Number(e%t)/Number(t)}var Gt=e=>BigInt.asUintN(64,e);function mo(e,t){let r=t<<1,n;return BigInt.asIntN(64,e[r+1])<0?(n=Gt(~e[r])|Gt(~e[r+1])<<64n,n=-(n+1n)):n=e[r]|e[r+1]<<64n,n}function ho(e,t){let r=t<<2,n;return BigInt.asIntN(64,e[r+3])<0?(n=Gt(~e[r])|Gt(~e[r+1])<<64n|Gt(~e[r+2])<<128n|Gt(~e[r+3])<<192n,n=-(n+1n)):n=e[r]|e[r+1]<<64n|e[r+2]<<128n|e[r+3]<<192n,n}var li=new TextDecoder("utf-8"),Qa=new TextEncoder;function Ht(e){return li.decode(e)}var St=4;function ys(e,t){return(e[t>>3]&1<<t%8)!==0}function L(e,t){let r=t+y(e,t),n=r-y(e,r),s=T(e,n);return(o,i,c=null)=>{if(o<s){let a=T(e,n+o);if(a)return i(e,r+a)}return c}}function G(e,t){return t}function mt(e,t){return!!fi(e,t)}function fi(e,t){return he(e,t)<<24>>24}function he(e,t){return e[t]}function T(e,t){return pi(e,t)<<16>>16}function pi(e,t){return e[t]|e[t+1]<<8}function y(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function xo(e,t){return y(e,t)>>>0}function O(e,t){return Z(BigInt.asIntN(64,BigInt(xo(e,t))+(BigInt(xo(e,t+St))<<32n)))}function vt(e,t){let r=t+y(e,t),n=y(e,r);return r+=St,Ht(e.subarray(r,r+n))}function P(e,t,r,n){if(!t)return[];let s=t+y(e,t);return Array.from({length:y(e,s)},(o,i)=>n(e,s+St+i*r))}var gs=Symbol("rowIndex");function xe(e,t){class r{constructor(o){this[gs]=o}toJSON(){return yo(e,t,this[gs])}}let n=r.prototype;for(let s=0;s<e.length;++s){if(Object.hasOwn(n,e[s]))continue;let o=t[s];Object.defineProperty(n,e[s],{get(){return o.at(this[gs])},enumerable:!0})}return s=>new r(s)}function yr(e,t){return r=>yo(e,t,r)}function yo(e,t,r){let n={};for(let s=0;s<e.length;++s)n[e[s]]=t[s].at(r);return n}function go(e){return e instanceof ht}var Ot=class{static ArrayType=null;constructor({length:t,nullCount:r,type:n,validity:s,values:o,offsets:i,sizes:c,children:a}){this.length=t,this.nullCount=r,this.type=n,this.validity=s,this.values=o,this.offsets=i,this.sizes=c,this.children=a,(!r||!this.validity)&&(this.at=u=>this.value(u))}get[Symbol.toStringTag](){return"Batch"}at(t){return this.isValid(t)?this.value(t):null}isValid(t){return ys(this.validity,t)}value(t){return this.values[t]}slice(t,r){let n=r-t,s=Array(n);for(let o=0;o<n;++o)s[o]=this.at(t+o);return s}*[Symbol.iterator](){for(let t=0;t<this.length;++t)yield this.at(t)}},ht=class extends Ot{constructor(t){super(t);let{length:r,values:n}=this;this.values=n.subarray(0,r)}slice(t,r){return this.nullCount?super.slice(t,r):this.values.subarray(t,r)}[Symbol.iterator](){return this.nullCount?super[Symbol.iterator]():this.values[Symbol.iterator]()}},ye=class extends Ot{static ArrayType=pt},_=class extends Ot{static ArrayType=Array},ge=class extends _{value(t){return null}},K=class extends ye{value(t){return Z(this.values[t])}},gr=class extends ye{value(t){let r=this.values[t],n=(r&31744)>>10,s=(r&1023)/1024,o=(-1)**((r&32768)>>15);switch(n){case 31:return o*(s?Number.NaN:1/0);case 0:return o*(s?6103515625e-14*s:0)}return o*2**(n-15)*(1+s)}},Er=class extends _{value(t){return ys(this.values,t)}},wr=class extends Ot{constructor(t){super(t);let{bitWidth:r,scale:n}=this.type;this.decimal=r===128?mo:ho,this.scale=10n**BigInt(n)}},br=class extends wr{static ArrayType=pt;value(t){return xr(this.decimal(this.values,t),this.scale)}},Ir=class extends wr{static ArrayType=Array;value(t){return this.decimal(this.values,t)}},Ee=class extends _{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}},_r=class extends ye{value(t){return 864e5*this.values[t]}},Eo=K,Ar=class extends K{value(t){return super.value(t)*1e3}},wo=K,Nr=class extends K{value(t){return xr(this.values[t],1000n)}},Sr=class extends K{value(t){return xr(this.values[t],1000000n)}},vr=class extends _{value(t){return this.values.subarray(t<<1,t+1<<1)}},Or=class extends _{value(t){let r=this.values,n=t<<4;return Float64Array.of(y(r,n),y(r,n+4),O(r,n+8))}},bo=({values:e,offsets:t},r)=>e.subarray(t[r],t[r+1]),Io=({values:e,offsets:t},r)=>e.subarray(Z(t[r]),Z(t[r+1])),Tr=class extends _{value(t){return bo(this,t)}},Lr=class extends _{value(t){return Io(this,t)}},Cr=class extends _{value(t){return Ht(bo(this,t))}},Rr=class extends _{value(t){return Ht(Io(this,t))}},Dr=class extends _{value(t){let r=this.offsets;return this.children[0].slice(r[t],r[t+1])}},Mr=class extends _{value(t){let r=this.offsets;return this.children[0].slice(Z(r[t]),Z(r[t+1]))}},Fr=class extends _{value(t){let r=this.offsets[t],n=r+this.sizes[t];return this.children[0].slice(r,n)}},Br=class extends _{value(t){let r=this.offsets[t],n=r+this.sizes[t];return this.children[0].slice(Z(r),Z(n))}},Ur=class extends _{constructor(t){super(t),this.stride=this.type.stride}},qr=class extends Ur{value(t){let{stride:r,values:n}=this;return n.subarray(t*r,(t+1)*r)}},$r=class extends Ur{value(t){let{children:r,stride:n}=this;return r[0].slice(t*n,(t+1)*n)}};function _o({children:e,offsets:t},r){let[n,s]=e[0].children,o=t[r],i=t[r+1],c=[];for(let a=o;a<i;++a)c.push([n.at(a),s.at(a)]);return c}var Pr=class extends _{value(t){return _o(this,t)}},kr=class extends _{value(t){return new Map(_o(this,t))}},we=class extends _{constructor({typeIds:t,...r}){super(r),this.typeIds=t,this.typeMap=this.type.typeMap}value(t,r=t){let{typeIds:n,children:s,typeMap:o}=this;return s[o[n[t]]].at(r)}},jr=class extends we{value(t){return super.value(t,this.offsets[t])}},be=class extends _{constructor(t,r=yr){super(t),this.names=this.type.children.map(n=>n.name),this.factory=r(this.names,this.children)}value(t){return this.factory(t)}},Vr=class extends be{constructor(t){super(t,xe)}},Wr=class extends _{value(t){let[{values:r},n]=this.children;return n.at(Yt(r,t))}},Qr=class extends _{setDictionary(t){return this.dictionary=t,this.cache=t.cache(),this}value(t){return this.cache[this.key(t)]}key(t){return this.values[t]}},Yr=class extends _{constructor({data:t,...r}){super(r),this.data=t}view(t){let{values:r,data:n}=this,s=t<<4,o=s+4,i=r,c=y(i,s);return c>12&&(o=y(i,s+12),i=n[y(i,s+8)]),i.subarray(o,o+c)}},zr=class extends Yr{value(t){return this.view(t)}},Gr=class extends Yr{value(t){return Ht(this.view(t))}};function Es(e){let t=[];return{add(r){return t.push(r),this},clear:()=>t=[],done:()=>new Tt(t,e)}}var Tt=class{constructor(t,r=t[0]?.type){this.type=r,this.length=t.reduce((o,i)=>o+i.length,0),this.nullCount=t.reduce((o,i)=>o+i.nullCount,0),this.data=t;let n=t.length,s=new Int32Array(n+1);if(n===1){let[o]=t;s[1]=o.length,this.at=i=>o.at(i)}else for(let o=0,i=0;o<n;++o)s[o+1]=i+=t[o].length;this.offsets=s}get[Symbol.toStringTag](){return"Column"}[Symbol.iterator](){let t=this.data;return t.length===1?t[0][Symbol.iterator]():di(t)}at(t){let{data:r,offsets:n}=this,s=Yt(n,t)-1;return r[s]?.at(t-n[s])}get(t){return this.at(t)}toArray(){let{length:t,nullCount:r,data:n}=this,s=!r&&go(n[0]),o=n.length;if(s&&o===1)return n[0].values;let i=!o||r>0?Array:n[0].constructor.ArrayType??n[0].values.constructor,c=new i(t);return s?mi(c,n):hi(c,n)}cache(){return this._cache??(this._cache=this.toArray())}};function*di(e){for(let t=0;t<e.length;++t){let r=e[t][Symbol.iterator]();for(let n=r.next();!n.done;n=r.next())yield n.value}}function mi(e,t){for(let r=0,n=0;r<t.length;++r){let{values:s}=t[r];e.set(s,n),n+=s.length}return e}function hi(e,t){let r=-1;for(let n=0;n<t.length;++n){let s=t[n];for(let o=0;o<s.length;++o)e[++r]=s.at(o)}return e}var Xt=class e{constructor(t,r,n=!1){let s=t.fields.map(i=>i.name);this.schema=t,this.names=s,this.children=r,this.factory=n?xe:yr;let o=[];this.getFactory=i=>o[i]??(o[i]=this.factory(s,r.map(c=>c.data[i])))}get[Symbol.toStringTag](){return"Table"}get numCols(){return this.names.length}get numRows(){return this.children[0]?.length??0}getChildAt(t){return this.children[t]}getChild(t){let r=this.names.findIndex(n=>n===t);return r>-1?this.children[r]:void 0}selectAt(t,r=[]){let{children:n,factory:s,schema:o}=this,{fields:i}=o;return new e({...o,fields:t.map((c,a)=>xi(i[c],r[a]))},t.map(c=>n[c]),s===xe)}select(t,r){let n=this.names,s=t.map(o=>n.indexOf(o));return this.selectAt(s,r)}toColumns(){let{children:t,names:r}=this,n={};return r.forEach((s,o)=>n[s]=t[o]?.toArray()??[]),n}toArray(){let{children:t,getFactory:r,numRows:n}=this,s=t[0]?.data??[],o=Array(n);for(let i=0,c=-1;i<s.length;++i){let a=r(i);for(let u=0;u<s[i].length;++u)o[++c]=a(u)}return o}*[Symbol.iterator](){let{children:t,getFactory:r}=this,n=t[0]?.data??[];for(let s=0;s<n.length;++s){let o=r(s);for(let i=0;i<n[s].length;++i)yield o(i)}}at(t){let{children:r,getFactory:n,numRows:s}=this;if(t<0||t>=s)return null;let[{offsets:o}]=r,i=Yt(o,t)-1;return n(i)(t-o[i])}get(t){return this.at(t)}};function xi(e,t){return t!=null&&t!==e.name?{...e,name:t}:e}function Ie(e,t={}){let{typeId:r,bitWidth:n,precision:s,unit:o}=e,{useBigInt:i,useDate:c,useDecimalBigInt:a,useMap:u,useProxy:f}=t;switch(r){case l.Null:return ge;case l.Bool:return Er;case l.Int:case l.Time:case l.Duration:return i||n<64?ht:K;case l.Float:return s?ht:gr;case l.Date:return Ao(o===rt.DAY?_r:Eo,c&&Ee);case l.Timestamp:return Ao(o===v.SECOND?Ar:o===v.MILLISECOND?wo:o===v.MICROSECOND?Nr:Sr,c&&Ee);case l.Decimal:return a?Ir:br;case l.Interval:return o===W.DAY_TIME?vr:o===W.YEAR_MONTH?ht:Or;case l.FixedSizeBinary:return qr;case l.Utf8:return Cr;case l.LargeUtf8:return Rr;case l.Binary:return Tr;case l.LargeBinary:return Lr;case l.BinaryView:return zr;case l.Utf8View:return Gr;case l.List:return Dr;case l.LargeList:return Mr;case l.Map:return u?kr:Pr;case l.ListView:return Fr;case l.LargeListView:return Br;case l.FixedSizeList:return $r;case l.Struct:return f?Vr:be;case l.RunEndEncoded:return Wr;case l.Dictionary:return Qr;case l.Union:return e.mode?jr:we}throw new Error(st(r))}function Ao(e,t){return t?class extends t{constructor(n){super(new e(n))}}:e}function yi(e,t){return{offset:O(e,t),metadataLength:y(e,t+8),bodyLength:O(e,t+16)}}function ws(e,t){return P(e,t,24,yi)}function Hr(e,t,r){let n=L(e,t);if(n(10,G,0))throw new Error("Record batch compression not implemented");let s=r<j.V4?8:0;return{length:n(4,O,0),nodes:P(e,n(6,G),16,(o,i)=>({length:O(o,i),nullCount:O(o,i+8)})),regions:P(e,n(8,G),16+s,(o,i)=>({offset:O(o,i+s),length:O(o,i+s+8)})),variadic:P(e,n(12,G),8,O)}}function No(e,t,r){let n=L(e,t);return{id:n(4,O,0),data:n(6,(s,o)=>Hr(s,o,r)),isDelta:n(8,mt,!1)}}function bs(e,t,r,n){U(r,l,st);let s=L(e,t);switch(r){case l.Binary:return ns();case l.Utf8:return lr();case l.LargeBinary:return fs();case l.LargeUtf8:return ps();case l.List:return pr(n[0]);case l.ListView:return hs(n[0]);case l.LargeList:return ds(n[0]);case l.LargeListView:return xs(n[0]);case l.Struct:return dr(n);case l.RunEndEncoded:return ms(n[0],n[1]);case l.Int:return ur(s(4,y,0),s(6,mt,!1));case l.Float:return rs(s(4,T,Wt.HALF));case l.Decimal:return ss(s(4,y,0),s(6,y,0),s(8,y,128));case l.Date:return os(s(4,T,rt.MILLISECOND));case l.Time:return is(s(4,T,v.MILLISECOND),s(6,y,32));case l.Timestamp:return fr(s(4,T,v.SECOND),s(6,vt));case l.Interval:return cs(s(4,T,W.YEAR_MONTH));case l.Duration:return ls(s(4,T,v.MILLISECOND));case l.FixedSizeBinary:return us(s(4,y,0));case l.FixedSizeList:return mr(n[0],s(4,y,0));case l.Map:return fo(s(4,mt,!1),n[0]);case l.Union:return as(s(4,T,nt.Sparse),n,P(e,s(6,G),4,y))}return{typeId:r}}function _e(e,t){let r=P(e,t,4,(n,s)=>{let o=L(n,s);return[o(4,vt),o(6,vt)]});return r.length?new Map(r):null}function Xr(e,t,r){let n=L(e,t);return{version:r,endianness:n(4,T,0),fields:n(6,gi,[]),metadata:n(8,_e)}}function gi(e,t){return P(e,t,4,So)}function So(e,t){let r=L(e,t),n=r(8,he,l.NONE),s=r(10,G,0),o=r(12,wi),i=r(14,(a,u)=>Ei(a,u)),c=bs(e,s,n,i);return o&&(o.dictionary=c,c=o),{name:r(4,vt),type:c,nullable:r(6,mt,!1),metadata:r(16,_e)}}function Ei(e,t){let r=P(e,t,4,So);return r.length?r:null}function wi(e,t){if(!t)return null;let r=L(e,t);return ar(null,r(6,bi,zt()),r(8,mt,!1),r(4,O,0))}function bi(e,t){return bs(e,t,l.Int)}var Ii=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,_i=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,Ai=e=>`Unsupported message type: ${e} (${cr(V,e)})`;function Jr(e,t){let r=y(e,t)||0;if(t+=St,r===-1&&(r=y(e,t)||0,t+=St),r===0)return null;let n=e.subarray(t,t+=r);if(n.byteLength<r)throw new Error(Ii(r,n.byteLength));let s=L(n,0),o=s(4,T,j.V1),i=s(6,he,V.NONE),c=s(8,G,0),a=s(10,O,0),u;if(c){let f=i===V.Schema?Xr:i===V.DictionaryBatch?No:i===V.RecordBatch?Hr:null;if(!f)throw new Error(Ai(i));if(u=f(n,c,o),a>0){let p=e.subarray(t,t+=a);if(p.byteLength<a)throw new Error(_i(a,p.byteLength));u.body=p}}return{version:o,type:i,index:t,content:u}}function vo(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;return t instanceof Uint8Array&&Ni(t)?vi(t):Si(t)}function Ni(e){if(!e||e.length<4)return!1;for(let t=0;t<6;++t)if(pe[t]!==e[t])return!1;return!0}function Si(e){let t=[e].flat(),r,n=[],s=[];for(let o of t){if(!(o instanceof Uint8Array))throw new Error("IPC data batch was not a Uint8Array.");let i=0;for(;;){let c=Jr(o,i);if(c===null)break;if(i=c.index,!!c.content)switch(c.type){case V.Schema:r||(r=c.content);break;case V.RecordBatch:n.push(c.content);break;case V.DictionaryBatch:s.push(c.content);break}}}return{schema:r,dictionaries:s,records:n,metadata:null}}function vi(e){let t=e.byteLength-(pe.length+4),r=y(e,t),n=L(e,t-r),s=n(4,T,j.V1),o=n(8,ws,[]),i=n(10,ws,[]);return{schema:n(6,(c,a)=>Xr(c,a,s)),dictionaries:o.map(({offset:c})=>Jr(e,c).content),records:i.map(({offset:c})=>Jr(e,c).content),metadata:n(12,_e)}}function _s(e,t){return Oi(vo(e),t)}function Oi(e,t={}){let{schema:r={fields:[]},dictionaries:n,records:s}=e,{version:o,fields:i}=r,c=new Map,a=Li(t,o,c),u=new Map;Ti(r,d=>{let h=d.type;h.typeId===l.Dictionary&&u.set(h.id,h.dictionary)});let f=new Map;for(let d of n){let{id:h,data:m,isDelta:E,body:F}=d,ft=u.get(h),Vt=Is(ft,a({...m,body:F}));if(f.has(h)){let rr=f.get(h);E||rr.clear(),rr.add(Vt)}else{if(E)throw new Error("Delta update can not be first dictionary batch.");f.set(h,Es(ft).add(Vt))}}f.forEach((d,h)=>c.set(h,d.done()));let p=i.map(d=>Es(d.type));for(let d of s){let h=a(d);i.forEach((m,E)=>p[E].add(Is(m.type,h)))}return new Xt(r,p.map(d=>d.done()),t.useProxy)}function Ti(e,t){e.fields.forEach(function r(n){t(n),n.type.dictionary?.children?.forEach(r),n.type.children?.forEach(r)})}function Li(e,t,r){let n={version:t,options:e,dictionary:s=>r.get(s)};return s=>{let{length:o,nodes:i,regions:c,variadic:a,body:u}=s,f=-1,p=-1,d=-1;return{...n,length:o,node:()=>i[++f],buffer:h=>{let{length:m,offset:E}=c[++p];return h?new h(u.buffer,u.byteOffset+E,m/h.BYTES_PER_ELEMENT):u.subarray(E,E+m)},variadic:()=>a[++d],visit(h){return h.map(m=>Is(m.type,this))}}}}function Is(e,t){let{typeId:r}=e,{length:n,options:s,node:o,buffer:i,variadic:c,version:a}=t,u=Ie(e,s);if(r===l.Null)return new u({length:n,nullCount:n,type:e});let f={...o(),type:e};switch(r){case l.Bool:case l.Int:case l.Time:case l.Duration:case l.Float:case l.Decimal:case l.Date:case l.Timestamp:case l.Interval:case l.FixedSizeBinary:return new u({...f,validity:i(),values:i(e.values)});case l.Utf8:case l.LargeUtf8:case l.Binary:case l.LargeBinary:return new u({...f,validity:i(),offsets:i(e.offsets),values:i()});case l.BinaryView:case l.Utf8View:return new u({...f,validity:i(),values:i(),data:Array.from({length:c()},()=>i())});case l.List:case l.LargeList:case l.Map:return new u({...f,validity:i(),offsets:i(e.offsets),children:t.visit(e.children)});case l.ListView:case l.LargeListView:return new u({...f,validity:i(),offsets:i(e.offsets),sizes:i(e.offsets),children:t.visit(e.children)});case l.FixedSizeList:case l.Struct:return new u({...f,validity:i(),children:t.visit(e.children)});case l.RunEndEncoded:return new u({...f,children:t.visit(e.children)});case l.Dictionary:{let{id:p,indices:d}=e;return new u({...f,validity:i(),values:i(d.values)}).setDictionary(t.dictionary(p))}case l.Union:return a<j.V5&&i(),new u({...f,typeIds:i(de),offsets:e.mode===nt.Sparse?null:i(e.offsets),children:t.visit(e.children)});default:throw new Error(st(r))}}var wl=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function Ae(e){return _s(e,{useDate:!0})}function As(e="ws://localhost:3000/"){let t=[],r=!1,n=null,s,o={open(){r=!0,a()},close(){for(r=!1,n=null,s=null;t.length;)t.shift().reject("Socket closed")},error(u){if(n){let{reject:f}=n;n=null,a(),f(u)}else console.error("WebSocket error: ",u)},message({data:u}){if(n){let{query:f,resolve:p,reject:d}=n;if(n=null,a(),typeof u=="string"){let h=JSON.parse(u);h.error?d(h.error):p(h)}else if(f.type==="exec")p();else if(f.type==="arrow")p(Ae(u));else throw new Error(`Unexpected socket data: ${u}`)}else console.log("WebSocket message: ",u)}};function i(){s=new WebSocket(e),s.binaryType="arraybuffer";for(let u in o)s.addEventListener(u,o[u])}function c(u,f,p){s==null&&i(),t.push({query:u,resolve:f,reject:p}),r&&!n&&a()}function a(){t.length&&(n=t.shift(),s.send(JSON.stringify(n.query)))}return{get connected(){return r},query(u){return new Promise((f,p)=>c(u,f,p))}}}var Jt="COLUMN_REF",Zr="COLUMN_PARAM",Mo="TABLE_REF",Fo="LITERAL";var Kr="ORDER_BY",tn="CAST",Ns="CASE",Ss="WHEN",vs="UNARY",Bo="UNARY_POSTFIX",en="BINARY",rn="BETWEEN",nn="NOT_BETWEEN",sn="LOGICAL_OPERATOR",on="IN",cn="FUNCTION",Ct="AGGREGATE",Zt="WINDOW",an="WINDOW_DEF",un="WINDOW_FRAME",Uo="EXPRESSION",Kt="FRAGMENT",ln="VERBATIM",Ne="PARAM",qo="WITH_CLAUSE",fn="SELECT_CLAUSE",pn="FROM_CLAUSE";var $o="SAMPLE_CLAUSE";var dn="WINDOW_CLAUSE";var mn="SELECT_QUERY",hn="DESCRIBE_QUERY",xn="SET_OPERATION";function Q(e){return e instanceof N}var N=class{constructor(t){this.type=t}},x=class extends N{};var Rt=class extends x{constructor(t){super(Fo),this.value=t}toString(){return Os(this.value)}};function Os(e){switch(typeof e){case"number":return Number.isFinite(e)?`${e}`:"NULL";case"string":return`'${e.replace("'","''")}'`;case"boolean":return e?"TRUE":"FALSE";default:if(e==null)return"NULL";if(e instanceof Date){let t=+e;if(Number.isNaN(t))return"NULL";let r=e.getUTCFullYear(),n=e.getUTCMonth(),s=e.getUTCDate();return t===Date.UTC(r,n,s)?`DATE '${r}-${n+1}-${s}'`:`epoch_ms(${t})`}else return e instanceof RegExp?`'${e.source}'`:`${e}`}}var H=class extends x{constructor(t){super(Ne),this.param=t}get value(){return this.param.value}toString(){return Os(this.value)}};function Ts(e){return e.split(".")}function X(e){return`"${e}"`}function yn(e){return e&&Ki(e)?e.slice(1,-1):e}function Ki(e){return e[0]==='"'&&e[e.length-1]==='"'}function xt(e){return e instanceof te}var te=class extends x{constructor(t){super(Mo),this.table=[t].flat()}get name(){return this.table[this.table.length-1]}toString(){return this.table.map(t=>X(t)).join(".")}};var ee=class extends x{constructor(t,r=[]){super(cn),this.name=t,this.args=r}toString(){let{name:t,args:r}=this;return`${t}(${r.join(", ")})`}};function R(e,...t){return new ee(e,gn(t).map(g))}function tt(e,...t){return new Se(e,gn(t).map(g))}function q(e,t=g){return e.flat().filter(r=>r!=null).map(r=>t(r))}function gn(e){let t=e.length,r=t;for(;r>0&&e[r-1]===void 0;--r);return r<t?e.slice(0,r):e}function Y(e){return typeof e=="string"}function ve(e){return Array.isArray(e)}function it(e){return e&&typeof e.addEventListener=="function"&&e.dynamic!==!1&&"value"in e}var Te=class extends N{constructor(t,r){super(dn),this.name=t,this.def=r}toString(){return`${X(this.name)} AS ${this.def}`}},re=class e extends x{constructor(t,r=new ne){super(Zt),this.func=t,this.def=r}over(t){return new e(this.func,this.def.over(t))}partitionby(...t){return new e(this.func,this.def.partitionby(...t))}orderby(...t){return new e(this.func,this.def.orderby(...t))}rows(t){return new e(this.func,this.def.rows(t))}range(t){return new e(this.func,this.def.range(t))}toString(){return`${this.func} OVER ${this.def}`}};var ne=class extends N{constructor(t,r,n,s){super(an),this.name=t,this.partition=r,this.order=n,this.frame=s}over(t){return Oe(this,{name:t})}partitionby(...t){return Oe(this,{partition:q(t)})}orderby(...t){return Oe(this,{order:q(t)})}rows(t){return Oe(this,{frame:new Le(t)})}range(t){return Oe(this,{frame:new Le(t,!0)})}toString(){let{name:t,partition:r,order:n,frame:s}=this,o=t&&X(t),i=[o,r?.length&&`PARTITION BY ${r.join(", ")}`,n?.length&&`ORDER BY ${n.join(", ")}`,s].filter(c=>c);return o&&i.length<2?o:`(${i.join(" ")})`}},Le=class extends N{constructor(t,r=!1,n=void 0){super(un),this.extent=it(t)?new H(t):t,this.range=r,this.exclude=n}toString(){let{range:t,exclude:r,extent:n}=this,s=t?"RANGE":"ROWS",[o,i]=Q(n)?n.value:n,c=Po(o,"PRECEDING"),a=Po(i,"FOLLOWING");return`${s} BETWEEN ${c} AND ${a}${r?` ${r}`:""}`}};function Oe(e,t){return new ne(t.name??e.name,t.partition??e.partition,t.order??e.order,t.frame??e.frame)}function Po(e,t){return e===0?"CURRENT ROW":Number.isFinite(e)?`${Math.abs(e)} ${t}`:`UNBOUNDED ${t}`}function se(e){return e instanceof ct}var ct=class extends x{constructor(t,r){super(t),this.table=r}get column(){return null}toString(){let{column:t,table:r}=this,n=`${r??""}`,s=t==="*"?"*":X(t);return(n?n+".":"")+s}},Ce=class extends ct{constructor(t,r){super(Jt,r),this.name=t}get column(){return this.name}};var Re=class extends ct{constructor(t,r){super(Zr,r),this.param=t}get column(){return`${this.param.value}`}};function De(e,t){let r=Dt(t);return it(e)?new Re(new H(e),r):new Ce(e,r)}var Mt=class extends x{constructor(t){super(ln),this.value=t}toString(){return this.value}};function C(e){return new Rt(e)}function ko(e){return new Mt(e)}function En(...e){let t=q(e,String);return t?.length?new te(t):void 0}function g(e){return Y(e)?ec(e):oe(e)}function Ft(e){return Y(e)?ko(e):oe(e)}function oe(e){return e instanceof x?e:it(e)?new H(e):C(e)}function Dt(e){return Y(e)?rc(e):ve(e)?En(e):e}function ec(e){let t=Ts(e);return De(t.pop(),En(t))}function rc(e){return En(Ts(e))}var Se=class e extends x{constructor(t,r,n,s){super(Ct),this.name=t,this.args=r,this.isDistinct=n,this.filter=s}distinct(t=!0){return new e(this.name,this.args,t,this.filter)}where(t){return Y(t)&&(t=Ft(t)),new e(this.name,this.args,this.isDistinct,t)}window(){return new re(this)}partitionby(...t){return this.window().partitionby(...t)}orderby(...t){return this.window().orderby(...t)}toString(){let{name:t,args:r,isDistinct:n,filter:s}=this,o=n?"DISTINCT ":"",i=r?.length?r.join(", "):"*",c=s?` FILTER (WHERE ${s})`:"";return`${t}(${o}${i})${c}`}},jo=["any_value","approx_count_distinct","approx_quantile","arbitrary","arg_max","arg_max_null","arg_min","arg_min_null","array_agg","avg","bit_and","bit_or","bit_xor","bitstring_agg","bool_and","bool_or","corr","count","covar_pop","covar_samp","entropy","favg","first","fsum","geomean","kurtosis_pop","kurtosis","last","mad","max","max_by","median","min","min_by","mode","product","quantile","quantile_cont","quantile_disc","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_sxx","regr_sxy","regr_syy","regr_slope","reservoir_quantile","skewness","stddev","stddev_pop","stddev_samp","string_agg","sum","variance","var_pop","var_samp"];var wn=class extends x{constructor(t,r,n){super(t),this.expr=r,this.extent=n}toSQL(t){let{extent:r,expr:n}=this;return r?`(${n} ${t} ${r[0]} AND ${r[1]})`:""}},Me=class extends wn{constructor(t,r){super(rn,t,r)}toString(){return super.toSQL("BETWEEN")}},Fe=class extends wn{constructor(t,r){super(nn,t,r)}toString(){return super.toSQL("NOT BETWEEN")}};var Be=class extends x{constructor(t,r,n){super(en),this.op=t,this.left=r,this.right=n}toString(){return`(${this.left} ${this.op} ${this.right})`}};var Ue=class extends x{constructor(t,r){super(tn),this.expr=t,this.cast=r}toString(){return`(${this.expr})::${this.cast}`}};var qe=class extends x{constructor(t){super(Kt),this.spans=t}toString(){return this.spans.join("")}};var $e=class extends N{constructor(t,r=!1,n=void 0,s=void 0){super($o),this.size=t,this.perc=r,this.method=n,this.seed=s}toString(){let{size:t,perc:r,method:n,seed:s}=this,o=r?"%":" ROWS",i=s!=null?`, ${s}`:"";return`${t}${o}${n?` (${n}${i})`:""}`}};var Pe=class extends N{constructor(t,r){super(fn),this.expr=t,this.alias=r}toString(){let{expr:t,alias:r}=this;return!r||nc(t,r)?`${t}`:`${t} AS ${X(r)}`}};function nc(e,t){return e instanceof ct&&e.table==null&&e.column===t}var ke=class extends N{constructor(t,r){super(qo),this.name=t,this.query=r}toString(){return`"${this.name}" AS (${this.query})`}};function bn(e){return e instanceof w}function yt(e){return e instanceof Ut}function Ls(e){return e instanceof je}var w=class extends x{static select(...t){return new Ut().select(...t)}static from(...t){return new Ut().from(...t)}static with(...t){return new Ut().with(...t)}static union(...t){return new Bt("UNION",t.flat())}static unionAll(...t){return new Bt("UNION ALL",t.flat())}static intersect(...t){return new Bt("INTERSECT",t.flat())}static except(...t){return new Bt("EXCEPT",t.flat())}static describe(t){return new je(t)}constructor(t){super(t),this._orderby=[],this._limit=void 0,this._offset=void 0,this.cteFor=null}get subqueries(){return[]}clone(){return this}orderby(...t){return this._orderby=this._orderby.concat(q(t)),this}limit(t){return this._limit=Number.isFinite(t)?t:void 0,this}offset(t){return this._offset=Number.isFinite(t)?t:void 0,this}},Ut=class e extends w{constructor(){super(mn),this._with=[],this._select=[],this._from=[],this._where=[],this._sample=void 0,this._groupby=[],this._having=[],this._window=[],this._qualify=[]}get subqueries(){let t=this.cteFor||this,n=(t instanceof e?t._with:[]).reduce((o,i)=>(o[i.name]=i.query,o),{}),s=[];return this._from.forEach(({expr:o})=>{if(bn(o))s.push(o);else if(xt(o)){let i=n[o.name];i&&s.push(i)}}),s}clone(){return Object.assign(new e,this)}with(...t){let r=[],n=(s,o)=>{let i=o.clone();i.cteFor=this,r.push(new ke(s,i))};return t.flat().forEach(s=>{if(s!=null)for(let o in s)n(o,s[o])}),this._with=this._with.concat(r),this}select(...t){let r=[],n=(o,i)=>r.push(new Pe(o==null?o:g(o),yn(i)));t.flat().forEach(o=>{if(o!=null)if(Y(o))n(o,o);else if(se(o))n(o,o.column);else if(ve(o))n(o[1],o[0]);else for(let i in o)n(o[i],i)});let s=new Set(r.map(o=>o.alias));return this._select=this._select.filter(o=>!s.has(o.alias)).concat(r.filter(o=>o.expr)),this}setSelect(...t){return this._select=[],this.select(...t)}distinct(t=!0){return this._distinct=!!t,this}from(...t){let r=[],n=(s,o)=>r.push(new Ve(Dt(s),yn(o)));return t.flat().forEach(s=>{if(s!=null)if(Y(s))n(s,s);else if(xt(s))n(s,s.name);else if(Q(s))n(s);else if(ve(s))n(s[1],s[0]);else for(let o in s)n(s[o],o)}),this._from=this._from.concat(r),this}setFrom(...t){return this._from=[],this.from(...t)}sample(t,r,n){let s;if(typeof t=="number"){let o=t>0&&t<1,i=o?t*100:Math.floor(t);s=new $e(i,o,r,n)}else s=t;return this._sample=s,this}where(...t){return this._where=this._where.concat(q(t,Ft)),this}setWhere(...t){return this._where=[],this.where(...t)}groupby(...t){return this._groupby=this._groupby.concat(q(t)),this}setGroupby(...t){return this._groupby=[],this.groupby(...t)}having(...t){return this._having=this._having.concat(q(t,Ft)),this}window(...t){let r=[];return t.flat().forEach(n=>{if(n!=null)for(let s in n)r.push(new Te(yn(s),n[s]))}),this._window=this._window.concat(r),this}qualify(...t){return this._qualify=this._qualify.concat(q(t,Ft)),this}toString(){let{_with:t,_select:r,_distinct:n,_from:s,_sample:o,_where:i,_groupby:c,_having:a,_window:u,_qualify:f,_orderby:p,_limit:d,_offset:h}=this,m=[];if(t.length&&m.push(`WITH ${t.join(", ")}`),m.push(`SELECT${n?" DISTINCT":""} ${r.join(", ")}`),s.length&&m.push(`FROM ${s.join(", ")}`),i.length){let E=i.map(String).filter(F=>F).join(" AND ");E&&m.push(`WHERE ${E}`)}if(o&&m.push(`USING SAMPLE ${o}`),c.length&&m.push(`GROUP BY ${c.join(", ")}`),a.length){let E=a.map(String).filter(F=>F).join(" AND ");E&&m.push(`HAVING ${E}`)}if(u.length&&m.push(`WINDOW ${u.join(", ")}`),f.length){let E=f.map(String).filter(F=>F).join(" AND ");E&&m.push(`QUALIFY ${E}`)}return p.length&&m.push(`ORDER BY ${p.join(", ")}`),Number.isFinite(d)&&m.push(`LIMIT ${d}`),Number.isFinite(h)&&m.push(`OFFSET ${h}`),m.join(" ")}},je=class e extends N{constructor(t){super(hn),this.query=t}clone(){return new e(this.query.clone())}toString(){return`DESCRIBE ${this.query}`}},Bt=class e extends w{constructor(t,r){super(xn),this.op=t,this.queries=r}get subqueries(){let{queries:t,cteFor:r}=this;return r&&t.forEach(n=>n.cteFor=r),t}clone(){let{op:t,queries:r,...n}=this;return Object.assign(new e(t,r),n)}toString(){let{op:t,queries:r,_orderby:n,_limit:s,_offset:o}=this,i=[r.join(` ${t} `)];return n.length&&i.push(`ORDER BY ${n.join(", ")}`),Number.isFinite(s)&&i.push(`LIMIT ${s}`),Number.isFinite(o)&&i.push(`OFFSET ${o}`),i.join(" ")}};var Ve=class extends N{constructor(t,r){super(pn),this.expr=t,this.alias=r}toString(){let{expr:t,alias:r}=this,n=bn(t)?`(${t})`:`${t}`;return r&&!(xt(t)&&t.table.join(".")===r)?`${n} AS ${X(r)}`:`${n}`}};var We=class extends x{constructor(t,r){super(on),this.expr=t,this.values=r}toString(){return`(${this.expr} IN (${this.values.join(", ")}))`}};var In=class extends x{constructor(t,r){super(sn),this.op=t,this.clauses=r}toString(){let t=this.clauses;return t.length===0?"":t.length===1?`${t[0]}`:`(${t.join(` ${this.op} `)})`}},Qe=class extends In{constructor(t){super("AND",t)}},Ye=class extends In{constructor(t){super("OR",t)}};var ze=class extends x{constructor(t,r,n){super(Kr),this.expr=t,this.desc=r,this.nullsFirst=n}toString(){let{expr:t,desc:r,nullsFirst:n}=this;return`${t}${r?" DESC":r===!1?" ASC":""}${n?" NULLS FIRST":n===!1?" NULLS LAST":""}`}};var Cs=class extends x{constructor(t,r,n){super(t),this.op=r,this.expr=n}};var Ge=class extends Cs{constructor(t,r){super(Bo,t,r)}toString(){return`(${this.expr} ${this.op})`}};function _n(e,t){return tt("arg_max",e,t)}function An(e,t){return tt("arg_min",e,t)}function gt(e){return tt("count",e)}function at(e){return tt("max",e)}function Et(e){return tt("min",e)}function Rs(e,t){return tt("regr_avgx",e,t)}function Ds(e,t){return tt("regr_avgy",e,t)}function Ms(e,t){return tt("regr_count",e,t)}function A(e){return tt("sum",e)}function Fs(e,t){return new Ue(g(e),t)}function wt(e){return Fs(e,"INTEGER")}function He(e){return Fs(e,"DOUBLE")}function Bs(e){return R("epoch_ms",e)}function Nn(e){return R("exp",e)}function Us(e){return R("log",e)}function ie(e){return R("ln",e)}function ut(e){return R("sign",e)}function bt(e){return R("abs",e)}function qt(e){return R("sqrt",e)}function qs(e){return R("ceil",e)}function It(e){return R("floor",e)}function Sn(e,t){return R("round",e,t)}function Vo(e,t){return new Ge(e,g(t))}function ce(e,t,r){return new Be(e,g(t),g(r))}function ac(e,t,r=!1){let n=r?Fe:Me;return new n(g(e),t?.map(g))}function $t(...e){return new Qe(q(e))}function ae(...e){return new Ye(q(e))}function vn(e){return Vo("IS NULL",e)}function On(e){return Vo("IS NOT NULL",e)}function Pt(e,t){return ce("+",e,t)}function b(e,t){return ce("-",e,t)}function I(e,t){return ce("*",e,t)}function S(e,t){return ce("/",e,t)}function D(e,t){return ce("**",e,t)}function Tn(e,t){return ce("IS NOT DISTINCT FROM",e,t)}function ue(e,t){return ac(e,t,!1)}function $s(e,t){return new We(g(e),t.map(g))}function Ps(e,t){return new ze(g(e),!0,t)}function _t(e,...t){return new qe(uc(e,t))}function uc(e,t){let r=[e[0]],n=t.length;for(let s=0,o=0;s<n;){let i=t[s];Q(i)?r[++o]=i:it(i)?r[++o]=new H(i):r[o]+=Y(i)?i:C(i);let c=e[++s];Q(r[o])?r[++o]=c:r[o]+=c}return r.filter(s=>s).map(s=>Y(s)?new Mt(s):s)}function Ln(e,t,...r){return R(e,t,...gn(r).map(oe))}function ks(e,t,r){return Ln("regexp_matches",e,t,r)}function js(e,t){return Ln("contains",e,t)}function Vs(e,t){return Ln("starts_with",e,t)}function Ws(e,t){return Ln("ends_with",e,t)}var Cn={[Ct]:["args","filter"],[rn]:["expr","extent"],[en]:["left","right"],[Ns]:["expr","_when","_else"],[tn]:["expr"],[Zr]:["param","table"],[Jt]:["table"],[hn]:["query"],[Uo]:["node"],[Kt]:["spans"],[pn]:["expr"],[cn]:["args"],[on]:["expr","values"],[sn]:["clauses"],[nn]:["expr","extent"],[Kr]:["expr"],[Ne]:["value"],[fn]:["expr"],[mn]:["_with","_select","_from","_where","_sample","_groupby","_having","_window","_qualify","_orderby"],[xn]:["subqueries","_orderby"],[vs]:["expr"],[Ss]:["when","then"],[Zt]:["func","def"],[dn]:["def"],[an]:["partition","order","frame"],[un]:["extent"]};function Xe(e,t){if(t.has(e))return t.get(e);if(Q(e)){let r=Cn[e.type],n=r?.length??0;for(let s=0;s<n;++s){let o=r[s],i=e[o];if(Array.isArray(i)){let c=i.length;for(let a=0;a<c;++a)i[a]=Xe(i[a],t)}else i&&(e[o]=Xe(i,t))}}return e}function kt(e,t){if(!Q(e))return;let r=t(e);if(r)return r;let n=Cn[e.type],s=n?.length??0;for(let o=0;o<s;++o){let i=e[n[o]];if(Array.isArray(i)){let c=i.length;for(let a=0;a<c;++a)if(i[a]&&+kt(i[a],t)<0)return r}else if(i&&+kt(i,t)<0)return-1}}var lc=new RegExp(`^(${jo.join("|")})$`),fc=/(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\()/g;function pc(e){return e.split(fc).some(t=>t.endsWith("(")&&lc.test(t.slice(0,-1)))}function Je(e){let t=0;return kt(e,r=>{switch(r.type){case Zt:return-1;case Ct:return t|=1,-1;case Kt:case ln:{let n=`${r}`.toLowerCase(),s=n.indexOf("(select ");return s>=0&&(n=n.slice(0,s)),n.includes(") over ")?-1:pc(n)?(t|=2,-1):1}}}),t}function Qs(e){let t=new Set;return kt(e,r=>{r.type===Ct&&t.add(r)}),Array.from(t)}function Rn(e){let t={};return kt(e,r=>{r.type===Jt&&(t[r]=r)}),Object.values(t)}function Dn(e,t,{replace:r=!1,temp:n=!1,view:s=!1}={}){return"CREATE"+(r?" OR REPLACE ":" ")+(n?"TEMP ":"")+(s?"VIEW":"TABLE")+(r?" ":" IF NOT EXISTS ")+e+" AS "+t}var Mn=e=>e;function Qo(){return{apply:Mn,invert:Mn,sqlApply:g,sqlInvert:Mn}}function wc({base:e=null}={}){if(e==null||e===Math.E)return{apply:Math.log,invert:Math.exp,sqlApply:t=>ie(t),sqlInvert:t=>Nn(t)};if(e===10)return{apply:Math.log10,invert:t=>Math.pow(10,t),sqlApply:t=>Us(t),sqlInvert:t=>D(10,t)};{let t=+e;return{apply:r=>Math.log(r)/Math.log(t),invert:r=>Math.pow(t,r),sqlApply:r=>S(ie(r),ie(t)),sqlInvert:r=>D(t,r)}}}function bc({constant:e=1}={}){let t=+e;return{apply:r=>Math.sign(r)*Math.log1p(Math.abs(r)),invert:r=>Math.sign(r)*Math.exp(Math.abs(r)-t),sqlApply:r=>(r=g(r),I(ut(r),ie(Pt(t,bt(r))))),sqlInvert:r=>I(ut(r),b(Nn(bt(r)),t))}}function Ic(){return{apply:e=>Math.sign(e)*Math.sqrt(Math.abs(e)),invert:e=>Math.sign(e)*e*e,sqlApply:e=>(e=g(e),I(ut(e),qt(bt(e)))),sqlInvert:e=>I(ut(e),D(e,2))}}function _c({exponent:e=1}={}){let t=+e;return{apply:r=>Math.sign(r)*Math.pow(Math.abs(r),t),invert:r=>Math.sign(r)*Math.pow(Math.abs(r),1/t),sqlApply:r=>(r=g(r),I(ut(r),D(bt(r),t))),sqlInvert:r=>I(ut(r),D(bt(r),S(1,t)))}}function Yo(){return{apply:e=>+e,invert:e=>new Date(e),sqlApply:e=>e instanceof Date?C(+e):Nc(e)?C(+e.value):Bs(e),sqlInvert:Mn}}var Ac={identity:Qo,linear:Qo,log:wc,symlog:bc,sqrt:Ic,pow:_c,time:Yo,utc:Yo};function Ys(e){let t=Ac[e.type];return t?{...e,...t(e)}:null}function Nc(e){return e instanceof Rt&&e.value instanceof Date}function Fn(e){let t=2166136261;for(let r=0,n=e.length;r<n;++r){let s=e.charCodeAt(r),o=s&65280;o&&(t=zo(t^o>>8)),t=zo(t^s&255)}return Sc(t)>>>0}function zo(e){return e+(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24)}function Sc(e){return e+=e<<13,e^=e>>>7,e+=e<<3,e^=e>>>17,e+=e<<5,e&4294967295}function Ho(e,t,r){switch(e.name){case"count":case"sum":return vc(t,e);case"avg":return Oc(t,e);case"arg_max":return Tc(t,e);case"arg_min":return Lc(t,e);case"variance":case"var_samp":return Bn(t,e,r);case"var_pop":return Bn(t,e,r,!1);case"stddev":case"stddev_samp":return qt(Bn(t,e,r));case"stddev_pop":return qt(Bn(t,e,r,!1));case"covar_samp":return Un(t,e,r);case"covar_pop":return Un(t,e,r,!1);case"corr":return Go(t,e,r);case"regr_count":return le(t,e).expr;case"regr_avgx":return Ko(t,e);case"regr_avgy":return ti(t,e);case"regr_syy":return Gs(t,0,e,r);case"regr_sxx":return Gs(t,1,e,r);case"regr_sxy":return Un(t,e,r,null);case"regr_slope":return ei(t,e,r);case"regr_intercept":return Cc(t,e,r);case"regr_r2":return D(Go(t,e,r),2);case"max":case"min":case"bit_and":case"bit_or":case"bit_xor":case"bool_and":case"bool_or":case"product":{let n=Xo(e);return t[n]=e,_t`${e.name}("${n}")`}default:return null}}function Xo(e){return"pre_"+Fn(`${e}`).toString(16)}function M(e,t,r){let n=r?.filter;n&&(t=t.filter?t.where($t(n,t.filter)):t.where(n));let s=Xo(t);return e[s]=t,s}function Jo(e,t){let r=M(e,gt(t.args[0]),t);return{expr:A(r),name:r}}function vc(e,t){return A(M(e,t))}function Oc(e,t){let r=M(e,t),{expr:n,name:s}=Jo(e,t);return S(A(I(r,s)),n)}function Tc(e,t){let r=M(e,t),n=M(e,at(t.args[1]),t);return _n(r,n)}function Lc(e,t){let r=M(e,t),n=M(e,Et(t.args[1]),t);return An(r,n)}function Bn(e,t,r,n=!0){let s=t.args[0],{expr:o}=Jo(e,t),i=b(s,r(s)),c=M(e,A(D(i,2)),t),a=M(e,A(i),t),u=n?b(o,1):o;return S(b(A(c),S(D(A(a),2),o)),u)}function Un(e,t,r,n=!0){let{expr:s}=le(e,t),o=Zo(e,t,r),i=Ze(e,1,t,r),c=Ze(e,0,t,r),a=b(o,S(I(i,c),s));return n===null?a:n?S(a,b(s,1)):S(a,s)}function Go(e,t,r){let{expr:n}=le(e,t),s=Zo(e,t,r),o=zs(e,1,t,r),i=zs(e,0,t,r),c=Ze(e,1,t,r),a=Ze(e,0,t,r),u=b(o,S(D(c,2),n)),f=b(i,S(D(a,2),n));return S(b(s,S(I(c,a),n)),qt(I(u,f)))}function le(e,t){let[r,n]=t.args,s=M(e,Ms(r,n),t);return{expr:A(s),name:s}}function Ze(e,t,r,n){let s=r.args,o=s[t],i=s[1-t],c=A(b(o,n(o))).where(On(i));return A(M(e,c,r))}function zs(e,t,r,n){let s=r.args,o=s[t],i=s[1-t],c=A(D(b(o,n(o)),2)).where(On(i));return A(M(e,c,r))}function Zo(e,t,r){let[n,s]=t.args,o=A(I(b(s,r(s)),b(n,r(n))));return A(M(e,o,t))}function Ko(e,t){let[r,n]=t.args,{expr:s,name:o}=le(e,t),i=M(e,Rs(r,n),t);return S(A(I(i,o)),s)}function ti(e,t){let[r,n]=t.args,{expr:s,name:o}=le(e,t),i=M(e,Ds(r,n),t);return S(A(I(i,o)),s)}function Gs(e,t,r,n){let{expr:s}=le(e,r),o=Ze(e,t,r,n),i=zs(e,t,r,n);return b(i,S(D(o,2),s))}function ei(e,t,r){let n=Un(e,t,r,null),s=Gs(e,1,t,r);return S(n,s)}function Cc(e,t,r){let n=Ko(e,t),s=ti(e,t),o=ei(e,t,r);return b(s,I(o,n))}function ri(e){if(!e.filterStable)return null;let t=e.query();if(!yt(t))return null;let r=qn(t,a=>{let u=a._from[0]?.expr;return xt(u)?u.name:u});if(typeof r!="string")return null;let n=new Map,s={},o={},i=[],c=a=>{let u=a.column,f=qn(t,p=>p._select.find(d=>d.alias===u)?.expr);return _t`(SELECT avg(${f??a}) FROM "${r}")`};for(let{alias:a,expr:u}of t._select){if(Je(u)>1)return null;let f=Qs(u);if(f.length===0)i.push(a),s[a]=u;else{for(let p of f){if(p.isDistinct)return null;let d=Ho(p,s,c);if(!d)return null;n.set(p,d)}o[a]=Xe(u,n)}}return n.size?{group:i,preagg:s,output:o}:null}function qn(e,t){let r=e.subqueries;if(yt(e)&&r.length===0)return t(e);let n=qn(r[0],t);for(let s=1;s<r.length;++s){let o=qn(r[s],t);if(o!==void 0&&o!==n)return NaN}return n}var Rc={skip:!0,result:null},$n=class{constructor(t,{schema:r="mosaic",enabled:n=!0}={}){this.entries=new Map,this.active=null,this.mc=t,this._schema=r,this._enabled=n}set enabled(t){this._enabled!==t&&(t||this.clear(),this._enabled=t)}get enabled(){return this._enabled}set schema(t){this._schema!==t&&(this.clear(),this._schema=t)}get schema(){return this._schema}dropSchema(){return this.clear(),this.mc.exec(`DROP SCHEMA IF EXISTS "${this.schema}" CASCADE`)}clear(){this.entries.clear(),this.active=null}request(t,r,n){if(!this.enabled)return null;let{entries:s,mc:o,schema:i}=this,{source:c}=n;if(!c||this.active&&(this.active.source!==c&&this.clear(),this.active?.source===null))return null;let{active:a}=this;if(!a&&(this.active=a=Dc(n),a.source===null))return null;if(s.has(t))return s.get(t);let u=ri(t),f;if(!u)f=null;else if(r.skip(t,n))f=Rc;else{let p=r.remove(c).predicate(t);f=Bc(t.query(p),a,u,i),f.result=o.exec([`CREATE SCHEMA IF NOT EXISTS ${i}`,Dn(f.table,f.create,{temp:!1})]),f.result.catch(d=>o.logger().error(d))}return s.set(t,f),f}};function Dc(e){let{source:t,meta:r}=e,n=e.predicate,s=Rn(n).map(p=>p.column),o,i;if(!r||!s)return{source:null,columns:i,predicate:o};let{type:c,scales:a,bin:u,pixelSize:f=1}=r;if(c==="point")o=p=>p,i=Object.fromEntries(s.map(p=>[`${p}`,g(p)]));else if(c==="interval"&&a){let p=a.map(d=>Fc(d,f,u));p.some(d=>!d)||(p.length===1?(o=d=>d?ue("active0",d.extent.map(p[0])):[],i={active0:p[0](n.expr)}):(o=d=>d?$t(d.clauses.map((h,m)=>ue(`active${m}`,h.extent.map(p[m])))):[],i=Object.fromEntries(n.clauses.map((d,h)=>[`active${h}`,p[h](d.expr)]))))}return{source:i?t:null,columns:i,predicate:o}}var Mc={ceil:qs,round:Sn};function Fc(e,t,r){let{type:n,domain:s,range:o,apply:i,sqlApply:c}=Ys(e);if(!i)return;let a=Mc[`${r}`.toLowerCase()]||It,u=i(Math.min(...s)),f=i(Math.max(...s)),p=(n==="identity"?1:Math.abs(o[1]-o[0])/(f-u))/t,d=p===1?m=>m:m=>I(He(p),m),h=u===0?m=>m:m=>b(m,He(u));return m=>wt(a(d(h(c(m)))))}function Bc(e,t,r,n){let{group:s,output:o,preagg:i}=r,{columns:c}=t,a=e.setSelect({...i,...c}).groupby(Object.keys(c)),[u]=a.subqueries;if(u){let F=Object.values(c).flatMap(ft=>Rn(ft).map(Vt=>Vt.column));Uc(u,F)}let f=a._having,p=a._orderby;a._having=[],a._orderby=[];let d=a.toString(),h=(Fn(d)>>>0).toString(16),m=`${n}.preagg_${h}`,E=w.select(s,o).from(m).groupby(s).having(f).orderby(p);return new Hs({table:m,create:d,active:t,select:E})}function Uc(e,t){let r=new Set,n=s=>{r.has(s)||(r.add(s),yt(s)&&s._from.length&&s.select(t),s.subqueries.forEach(n))};n(e)}var Hs=class{constructor({table:t,create:r,active:n,select:s}){this.table=t,this.create=r,this.result=null,this.active=n,this.select=s,this.skip=!1}query(t){return this.select.clone().where(this.active.predicate(t))}};function Xs(e){switch(e){case"BIGINT":case"HUGEINT":case"INTEGER":case"SMALLINT":case"TINYINT":case"UBIGINT":case"UINTEGER":case"USMALLINT":case"UTINYINT":case"DOUBLE":case"FLOAT":case"REAL":return"number";case"DATE":case"TIMESTAMP":case"TIMESTAMPTZ":case"TIMESTAMP WITH TIME ZONE":case"TIME":case"TIMESTAMP_NS":return"date";case"BOOLEAN":return"boolean";case"VARCHAR":case"UUID":case"JSON":return"string";case"ARRAY":case"LIST":return"array";case"BLOB":case"STRUCT":case"MAP":case"GEOMETRY":return"object";default:if(e.startsWith("DECIMAL"))return"number";if(e.startsWith("STRUCT")||e.startsWith("MAP"))return"object";if(e.endsWith("]"))return"array";throw new Error(`Unsupported type: ${e}`)}}var qc="count",$c="nulls",Pc="max",kc="min",jc="distinct";var Vc={[qc]:gt,[jc]:e=>gt(e).distinct(),[Pc]:at,[kc]:Et,[$c]:e=>gt().where(vn(e))};function Wc(e,t,r){return w.from(e).select(Array.from(r,n=>({[n]:Vc[n](t)})))}async function ni(e,t){return t.length===1&&t[0].column==="*"?Yc(e,t[0].table):(await Promise.all(t.map(r=>Qc(e,r)))).filter(r=>r)}async function Qc(e,{table:t,column:r,stats:n}){let s=w.from({source:t}).select({column:r}).groupby(r.aggregate?_t`ALL`:[]),[o]=Array.from(await e.query(w.describe(s))),i={table:t,column:`${r}`,sqlType:o.column_type,type:Xs(o.column_type),nullable:o.null==="YES"};if(!(n?.length||n?.size))return i;let[c]=await e.query(Wc(t,r,n),{persist:!0});return Object.assign(i,c)}async function Yc(e,t){let r=await e.query(`DESCRIBE ${Dt(t)}`);return Array.from(r).map(n=>({table:t,column:n.column_name,sqlType:n.column_type,type:Xs(n.column_type),nullable:n.null==="YES"}))}var At=Object.freeze({pending:Symbol("pending"),ready:Symbol("ready"),error:Symbol("error"),done:Symbol("done")}),jt=class extends Promise{constructor(){let t,r;super((n,s)=>{t=n,r=s}),this._resolve=t,this._reject=r,this._state=At.pending,this._value=void 0}fulfill(t){if(this._value!==void 0){if(t!==void 0)throw Error("Promise is ready and fulfill has a provided value");this._resolve(this._value)}else{if(t===void 0)throw Error("Promise is neither ready nor has provided value");this._resolve(t)}return this._state=At.done,this}ready(t){return this._state=At.ready,this._value=t,this}reject(t){return this._state=At.error,this._reject(t),this}get state(){return this._state}};jt.prototype.constructor=Promise;function Pn(){return{debug(...e){},info(...e){},log(...e){},warn(...e){},error(...e){}}}function zc(e){return(typeof requestAnimationFrame<"u"?requestAnimationFrame:typeof setImmediate<"u"?setImmediate:setTimeout)(e)}function si(e,t){let r=[],n=0;function s(){let o=Gc(r,t);r=[],n=0;for(let i of o)Xc(i,e),Kc(i,t)}return{add(o,i){o.request.type==="arrow"?(n=n||zc(()=>s()),r.push({entry:o,priority:i,index:r.length})):e(o,i)}}}function Gc(e,t){let r=[],n=new Map;for(let s of e){let{entry:{request:o}}=s,i=Hc(o.query,t);if(!n.has(i)){let c=[];r.push(c),n.set(i,c)}n.get(i).push(s)}return r}function Hc(e,t){let r=`${e}`;if(yt(e)&&!t.get(r)){if(e._orderby.length||e._where.length||e._qualify.length||e._having.length)return r;let n=e.clone().setSelect("*"),s=e._groupby;if(s.length){let o={};e._select.forEach(({alias:i,expr:c})=>o[i]=c),n.setGroupby(s.map(i=>se(i)&&o[i.column]||i))}else e._select.some(o=>Je(o.expr))&&n.setGroupby("ALL");return`${n}`}else return r}function Xc(e,t){if(Jc(e))t({request:{type:"arrow",cache:!1,query:e.query=Zc(e)},result:e.result=new jt});else for(let{entry:r,priority:n}of e)t(r,n)}function Jc(e){if(e.length>1){let t=`${e[0].entry.request.query}`;for(let r=1;r<e.length;++r)if(t!==`${e[r].entry.request.query}`)return!0}return!1}function Zc(e){let t=e.maps=[],r=new Map;for(let o of e){let{query:i}=o.entry.request,c=[];t.push(c);for(let{alias:a,expr:u}of i._select){let f=`${u}`;r.has(f)||r.set(f,[`col${r.size}`,u]);let[p]=r.get(f);c.push([p,a])}}let n=e[0].entry.request.query.clone(),s=n._groupby;if(s.length){let o={};e.maps[0].forEach(([i,c])=>o[c]=i),n.setGroupby(s.map(i=>se(i)&&o[i.column]||i))}return n.setSelect(Array.from(r.values()))}async function Kc(e,t){let{maps:r,query:n,result:s}=e;if(!r)return;let o;try{o=await s}catch(c){for(let{entry:a}of e)a.result.reject(c);return}let i=Ls(n);e.forEach(({entry:c},a)=>{let{request:u,result:f}=c,p=r[a],d=i&&p?ea(o,p):p?ta(o,p):o;u.cache&&t.set(String(u.query),d),f.fulfill(d)})}function ta(e,t){return e.select(t.map(r=>r[0]),t.map(r=>r[1]))}function ea(e,t){let r=new Map(t),n=[];for(let s of e)r.has(s.column_name)&&n.push({...s,column_name:r.get(s.column_name)});return n}var ra=typeof requestIdleCallback<"u"?requestIdleCallback:setTimeout,oi=()=>({get:()=>{},set:(e,t)=>t,clear:()=>{}});function ii({max:e=1e3,ttl:t=3*60*60*1e3}={}){let r=new Map;function n(){let s=performance.now()-t,o=null,i=1/0;for(let[c,a]of r){let{last:u}=a;u<i&&(o=c,i=u),s>u&&r.delete(c)}o&&r.delete(o)}return{get(s){let o=r.get(s);if(o)return o.last=performance.now(),o.value},set(s,o){return r.set(s,{last:performance.now(),value:o}),r.size>e&&ra(n),o},clear(){r=new Map}}}var kn=class{constructor(t){this.queue=Array.from({length:t},()=>({head:null,tail:null}))}isEmpty(){return this.queue.every(t=>!t.head)}insert(t,r){let n=this.queue[r];if(!n)throw new Error(`Invalid queue priority rank: ${r}`);let s={item:t,next:null};n.head===null?n.head=n.tail=s:n.tail=n.tail.next=s}remove(t){for(let r of this.queue){let{head:n,tail:s}=r;for(let o=null,i=n;i;o=i,i=i.next)t(i.item)&&(i===n?n=i.next:o.next=i.next,i===s&&(s=o||n));r.head=n,r.tail=s}}next(){for(let t of this.queue){let{head:r}=t;if(r!==null)return t.head=r.next,t.tail===r&&(t.tail=null),r.item}}};var et=Object.freeze({High:0,Normal:1,Low:2}),jn=class{constructor(t=32){this.queue=new kn(3),this.db=null,this.clientCache=null,this._logger=Pn(),this._logQueries=!1,this._consolidate=null,this.pendingResults=[],this.maxConcurrentRequests=t,this.pendingExec=!1}next(){if(this.queue.isEmpty()||this.pendingResults.length>this.maxConcurrentRequests||this.pendingExec)return;let{request:t,result:r}=this.queue.next();this.pendingResults.push(r),t.type==="exec"&&(this.pendingExec=!0),this.submit(t,r).finally(()=>{for(;this.pendingResults.length&&this.pendingResults[0].state!==At.pending;){let n=this.pendingResults.shift();n.state===At.ready?n.fulfill():n.state===At.done&&this._logger.warn("Found resolved query in pending results.")}t.type==="exec"&&(this.pendingExec=!1),this.next()})}enqueue(t,r=et.Normal){this.queue.insert(t,r),this.next()}async submit(t,r){try{let{query:n,type:s,cache:o=!1,options:i}=t,c=n?`${n}`:null;if(o){let p=this.clientCache.get(c);if(p){let d=await p;this._logger.debug("Cache"),r.ready(d);return}}let a=performance.now();this._logQueries&&this._logger.debug("Query",{type:s,sql:c,...i});let u=this.db.query({type:s,sql:c,...i});o&&this.clientCache.set(c,u);let f=await u;o&&this.clientCache.set(c,f),this._logger.debug(`Request: ${(performance.now()-a).toFixed(1)}`),r.ready(s==="exec"?null:f)}catch(n){r.reject(n)}}cache(t){return t!==void 0?this.clientCache=t===!0?ii():t||oi():this.clientCache}logger(t){return t?this._logger=t:this._logger}logQueries(t){return t!==void 0?this._logQueries=!!t:this._logQueries}connector(t){return t?this.db=t:this.db}consolidate(t){t&&!this._consolidate?this._consolidate=si(this.enqueue.bind(this),this.clientCache):!t&&this._consolidate&&(this._consolidate=null)}request(t,r=et.Normal){let n=new jt,s={request:t,result:n};return this._consolidate?this._consolidate.add(s,r):this.enqueue(s,r),n}cancel(t){let r=new Set(t);if(r.size){this.queue.remove(({result:n})=>r.has(n)?(n.reject("Canceled"),!0):!1);for(let n of this.pendingResults)r.has(n)&&n.reject("Canceled")}}clear(){this.queue.remove(({result:t})=>(t.reject("Cleared"),!0));for(let t of this.pendingResults)t.reject("Cleared");this.pendingResults=[]}};var Vn;function Ke(e){return e?Vn=e:Vn==null&&(Vn=new Wn),Vn}var Wn=class{constructor(t=As(),{logger:r=console,manager:n=new jn,cache:s=!0,consolidate:o=!0,preagg:i={}}={}){this.manager=n,this.manager.cache(s),this.manager.consolidate(o),this.databaseConnector(t),this.logger(r),this.clear(),this.preaggregator=new $n(this,i)}clear({clients:t=!0,cache:r=!0}={}){this.manager.clear(),t&&(this.filterGroups?.forEach(n=>n.disconnect()),this.filterGroups=new Map,this.clients?.forEach(n=>this.disconnect(n)),this.clients=new Set),r&&this.manager.cache().clear()}databaseConnector(t){return this.manager.connector(t)}logger(t){return arguments.length&&(this._logger=t||Pn(),this.manager.logger(this._logger)),this._logger}cancel(t){this.manager.cancel(t)}exec(t,{priority:r=et.Normal}={}){return t=Array.isArray(t)?t.filter(n=>n).join(`;
2
- `):t,this.manager.request({type:"exec",query:t},r)}query(t,{type:r="arrow",cache:n=!0,priority:s=et.Normal,...o}={}){return this.manager.request({type:r,query:t,cache:n,options:o},s)}prefetch(t,r={}){return this.query(t,{...r,cache:!0,priority:et.Low})}createBundle(t,r,n=et.Low){let s={name:t,queries:r.map(o=>typeof o=="string"?{sql:o}:o)};return this.manager.request({type:"create-bundle",options:s},n)}loadBundle(t,r=et.High){let n={name:t};return this.manager.request({type:"load-bundle",options:n},r)}updateClient(t,r,n=et.Normal){return t.queryPending(),this.query(r,{priority:n}).then(s=>t.queryResult(s).update(),s=>{this._logger.error(s),t.queryError(s)}).catch(s=>this._logger.error(s))}requestQuery(t,r){return this.preaggregator.clear(),r?this.updateClient(t,r):Promise.resolve(t.update())}async connect(t){let{clients:r}=this;if(r.has(t))throw new Error("Client already connected.");r.add(t),t.coordinator=this,this.initializeClient(t),na(this,t.filterBy,t)}async initializeClient(t){let r=t.fields();return r?.length&&t.fieldInfo(await ni(this,r)),t.requestQuery()}disconnect(t){let{clients:r,filterGroups:n}=this;if(!r.has(t))return;r.delete(t),t.coordinator=null;let s=n.get(t.filterBy);s&&s.clients.delete(t)}};function na(e,t,r){if(!t)return;let n=e.filterGroups.get(t);if(!n){let s=i=>sa(e,t,i),o=()=>oa(e,t);t.addEventListener("activate",s),t.addEventListener("value",o),n={selection:t,clients:new Set,disconnect(){t.removeEventListener("activate",s),t.removeEventListener("value",o)}},e.filterGroups.set(t,n)}n.clients.add(r)}function sa(e,t,r){let{preaggregator:n,filterGroups:s}=e,{clients:o}=s.get(t);for(let i of o)n.request(i,t,r)}function oa(e,t){let{preaggregator:r,filterGroups:n}=e,{clients:s}=n.get(t),{active:o}=t;return Promise.allSettled(Array.from(s,i=>{let c=r.request(i,t,o),a=c?null:t.predicate(i);if(c?.skip||!c&&!a)return;let u=c?.query(o.predicate)??i.query(a);return e.updateClient(i,u)}))}var Qn=class{constructor(){this._callbacks=new Map}addEventListener(t,r){this._callbacks.has(t)||this._callbacks.set(t,{callbacks:new Set,pending:null,queue:new Js}),this._callbacks.get(t).callbacks.add(r)}removeEventListener(t,r){let n=this._callbacks.get(t);n&&n.callbacks.delete(r)}willEmit(t,r){return r}emitQueueFilter(t,r){return null}cancel(t){this._callbacks.get(t)?.queue.clear()}async pending(t){await this._callbacks.get(t)?.pending}emit(t,r){let n=this._callbacks.get(t)||{};if(n.pending)n.queue.enqueue(r,this.emitQueueFilter(t,r));else{let s=this.willEmit(t,r),{callbacks:o,queue:i}=n;if(o?.size){let c=Array.from(o,a=>a(s));n.pending=Promise.allSettled(c).then(()=>{n.pending=null,i.isEmpty()||this.emit(t,i.dequeue())})}}}},Js=class{constructor(){this.clear()}clear(){this.next=null}isEmpty(){return!this.next}enqueue(t,r){let n={value:t};if(r&&this.next){let s=this;for(;s.next;)r(s.next.value)?s=s.next:s.next=s.next.next;s.next=n}else this.next=n}dequeue(){let{next:t}=this;return this.next=t?.next,t?.value}};function Zs(e,t){return e===t?!1:e instanceof Date&&t instanceof Date?+e!=+t:Array.isArray(e)&&Array.isArray(t)?ia(e,t):!0}function ia(e,t){if(e.length!==t.length)return!0;for(let r=0;r<e.length;++r)if(e[r]!==t[r])return!0;return!1}function k(e){return e instanceof fe}var fe=class e extends Qn{constructor(t){super(),this._value=t}static value(t){return new e(t)}static array(t){if(t.some(r=>k(r))){let r=new e,n=()=>{r.update(t.map(s=>k(s)?s.value:s))};return n(),t.forEach(s=>k(s)?s.addEventListener("value",n):0),r}return new e(t)}get value(){return this._value}update(t,{force:r}={}){return Zs(this._value,t)||r?this.emit("value",t):this.cancel("value"),this}willEmit(t,r){return t==="value"&&(this._value=r),r}};function J(e){return e instanceof tr}function Yn(e,t){return new tr(new zn(e),t&&[t].flat())}var tr=class e extends fe{static intersect({cross:t=!1,empty:r=!1,include:n=[]}={}){return Yn({cross:t,empty:r},n)}static union({cross:t=!1,empty:r=!1,include:n=[]}={}){return Yn({cross:t,empty:r,union:!0},n)}static single({cross:t=!1,empty:r=!1,include:n=[]}={}){return Yn({cross:t,empty:r,single:!0},n)}static crossfilter({empty:t=!1,include:r=[]}={}){return Yn({cross:!0,empty:t},r)}constructor(t=new zn,r=[]){if(super([]),this._resolved=this._value,this._resolver=t,this._relay=new Set,Array.isArray(r))for(let n of r)n._relay.add(this)}clone(){let t=new e(this._resolver);return t._value=t._resolved=this._value,t}remove(t){let r=this.clone();return r._value=r._resolved=r._resolver.resolve(this._resolved,{source:t}),r._value.active={source:t},r}get resolver(){return this._resolver}get single(){return this._resolver.single}get clauses(){return super.value}get active(){return this.clauses.active}get value(){return this.active?.value}valueFor(t){return this.clauses.find(r=>r.source===t)?.value}activate(t){this.emit("activate",t),this._relay.forEach(r=>r.activate(t))}update(t){return this._resolved=this._resolver.resolve(this._resolved,t,!0),this._resolved.active=t,this._relay.forEach(r=>r.update(t)),super.update(this._resolved)}willEmit(t,r){return t==="value"?(this._value=r,this.value):r}emitQueueFilter(t,r){return t==="value"?this._resolver.queueFilter(r):null}skip(t,r){return this._resolver.skip(t,r)}predicate(t,r=!1){let{clauses:n}=this,s=r?null:n.active;return this._resolver.predicate(n,s,t)}},zn=class{constructor({union:t,cross:r,single:n,empty:s}={}){this.union=!!t,this.cross=!!r,this.single=!!n,this.empty=!!s}resolve(t,r,n=!1){let{source:s,predicate:o}=r,i=t.filter(a=>s!==a.source),c=this.single?[]:i;return this.single&&n&&i.forEach(a=>a.source?.reset?.()),o&&c.push(r),c}skip(t,r){return this.cross&&r?.clients?.has(t)}predicate(t,r,n){let{empty:s,union:o}=this;if(s&&!t.length)return[C(!1)];if(this.skip(n,r))return;let i=t.filter(c=>!this.skip(n,c)).map(c=>c.predicate);return o&&i.length>1?ae(i):i}queueFilter(t){if(this.cross){let r=t.active?.source;return n=>n.active?.source!==r}return null}};function er(e,t,{source:r,clients:n=r?new Set([r]):void 0}){let s=t!==void 0?Tn(e,C(t)):null;return{meta:{type:"point"},source:r,clients:n,value:t,predicate:s}}function Ks(e,t,{source:r,clients:n=r?new Set([r]):void 0}){let s=null;if(t){let o=t.length&&e.length===1?[$s(e[0],t.map(i=>C(i[0])))]:t.map(i=>$t(i.map((c,a)=>Tn(e[a],C(c)))));s=t.length===0?C(!1):o.length>1?ae(o):o[0]}return{meta:{type:"point"},source:r,clients:n,value:t,predicate:s}}function to(e,t,{source:r,clients:n=r?new Set([r]):void 0,bin:s,scale:o,pixelSize:i=1}){let c=t!=null?ue(e,t):null;return{meta:{type:"interval",scales:o&&[o],bin:s,pixelSize:i},source:r,clients:n,value:t,predicate:c}}var ca={contains:js,prefix:Vs,suffix:Ws,regexp:ks};function eo(e,t,{source:r,clients:n=void 0,method:s="contains"}){let o=ca[s],i=t?o(e,C(t)):null;return{meta:{type:"match",method:s},source:r,clients:n,value:t,predicate:i}}function ro(e){return typeof e?.getChild=="function"}function no(e){return ro(e)?aa(e):ua(e)}function aa(e){let{numRows:t}=e;return{numRows:t,columns:e.toColumns()}}function ua(e){let t=e.length;if(typeof e[0]=="object"){let r=t?Object.keys(e[0]):[],n={};return r.length>0&&r.forEach(s=>{n[s]=e.map(o=>o[s])}),{numRows:t,columns:n}}else return{numRows:t,values:e}}function Nt(e,t){let r=new e(t);return Ke().connect(r),r.element}var la=e=>e&&typeof e=="object"&&!Array.isArray(e),fa=e=>Nt(Gn,e),Gn=class extends z{constructor({element:t,filterBy:r,from:n,column:s,label:o=s,format:i=p=>p,options:c,value:a,field:u=s,as:f}={}){super(r),this.from=n,this.column=s,this.format=i,this.field=u;let p=this.selection=f;this.element=t??document.createElement("div"),this.element.setAttribute("class","input"),Object.defineProperty(this.element,"value",{value:this});let d=document.createElement("label");if(d.innerText=o||s,this.element.appendChild(d),this.select=document.createElement("select"),this.element.appendChild(this.select),c&&(this.data=c.map(h=>la(h)?h:{value:h}),this.selectedValue(a??""),this.update()),p){let h=!J(p);a!=null&&(!h||p.value===void 0)&&this.publish(a),this.select.addEventListener("input",()=>{this.publish(this.selectedValue()??null)}),h&&this.selection.addEventListener("value",m=>{m!==this.select.value&&this.selectedValue(m)})}}selectedValue(t){if(arguments.length===0){let r=this.select.selectedIndex;return this.data[r].value}else{let r=this.data?.findIndex(n=>n.value===t);r>=0?this.select.selectedIndex=r:this.select.value=String(t)}}reset(){this.select.selectedIndex=this.from?0:-1}publish(t){let{selection:r,field:n}=this;if(J(r)){t===""&&(t=void 0);let s=er(n,t,{source:this});r.update(s)}else k(r)&&r.update(t)}query(t=[]){let{from:r,column:n}=this;return r?w.from(r).select({value:n}).distinct().where(t).orderby(n):null}queryResult(t){return this.data=[{value:"",label:"All"},...t],this}update(){let{data:t,format:r,select:n,selection:s}=this;n.replaceChildren();for(let{value:o,label:i}of t){let c=document.createElement("option");c.setAttribute("value",o),c.innerText=i??r(o),this.select.appendChild(c)}if(s){let o=J(s)?s.valueFor(this):s.value;this.selectedValue(o??"")}return this}};var pa=0,da=e=>Nt(Hn,e),Hn=class extends z{constructor({element:t,filterBy:r,from:n,column:s,label:o,type:i="contains",field:c=s,as:a}={}){if(super(r),this.id="search_"+ ++pa,this.type=i,this.from=n,this.column=s,this.selection=a,this.field=c,this.element=t??document.createElement("div"),this.element.setAttribute("class","input"),Object.defineProperty(this.element,"value",{value:this}),o){let u=document.createElement("label");u.setAttribute("for",this.id),u.innerText=o,this.element.appendChild(u)}this.searchbox=document.createElement("input"),this.searchbox.setAttribute("id",this.id),this.searchbox.setAttribute("type","text"),this.searchbox.setAttribute("placeholder","Query"),this.element.appendChild(this.searchbox),this.selection&&(this.searchbox.addEventListener("input",()=>{this.publish(this.searchbox.value||null)}),J(this.selection)||this.selection.addEventListener("value",u=>{u!==this.searchbox.value&&(this.searchbox.value=u)}))}reset(){this.searchbox.value=""}publish(t){let{selection:r,field:n,type:s}=this;if(J(r)){let o=eo(n,t,{source:this,method:s});r.update(o)}else k(r)&&r.update(t)}query(t=[]){let{from:r,column:n}=this;return r?w.from(r).select({list:n}).distinct().where(t):null}queryResult(t){return this.data=t,this}update(){let t=document.createElement("datalist"),r=`${this.id}_list`;t.setAttribute("id",r);for(let n of this.data){let s=document.createElement("option");s.setAttribute("value",n.list),t.append(s)}return this.datalist&&this.datalist.remove(),this.element.appendChild(this.datalist=t),this.searchbox.setAttribute("list",r),this}};var ma=0,ha=e=>Nt(Xn,e),Xn=class extends z{constructor({element:t,filterBy:r,as:n,min:s,max:o,step:i,from:c,column:a,label:u=a,value:f=n?.value,select:p="point",field:d=a,width:h}={}){if(super(r),this.id="slider_"+ ++ma,this.from=c,this.column=a||"value",this.selection=n,this.selectionType=p,this.field=d,this.min=s,this.max=o,this.step=i,this.element=t||document.createElement("div"),this.element.setAttribute("class","input"),Object.defineProperty(this.element,"value",{value:this}),u){let m=document.createElement("label");m.setAttribute("for",this.id),m.innerText=u,this.element.appendChild(m)}this.slider=document.createElement("input"),this.slider.setAttribute("id",this.id),this.slider.setAttribute("type","range"),h!=null&&(this.slider.style.width=`${+h}px`),s!=null&&this.slider.setAttribute("min",`${s}`),o!=null&&this.slider.setAttribute("max",`${o}`),i!=null&&this.slider.setAttribute("step",`${i}`),this.element.appendChild(this.slider),this.curval=document.createElement("label"),this.curval.setAttribute("for",this.id),this.curval.setAttribute("class","value"),this.element.appendChild(this.curval),f!=null&&(this.slider.setAttribute("value",`${f}`),this.selection?.value===void 0&&this.publish(f)),this.curval.innerText=this.slider.value,this.slider.addEventListener("input",()=>{let{value:m}=this.slider;this.curval.innerText=m,this.selection&&this.publish(+m)}),this.selection&&!J(this.selection)&&this.selection.addEventListener("value",m=>{m!==+this.slider.value&&(this.slider.value=m,this.curval.innerText=m)})}query(t=[]){let{from:r,column:n}=this;return!r||this.min!=null&&this.max!=null?null:w.select({min:Et(n),max:at(n)}).from(r).where(t)}queryResult(t){let{min:r,max:n}=Array.from(t)[0];return this.min==null&&(this.min=r,this.slider.setAttribute("min",`${r}`)),this.max==null&&(this.max=n,this.slider.setAttribute("max",`${n}`)),this.step==null&&(this.step=(n-r)/500,this.slider.setAttribute("step",`${this.step}`)),this}publish(t){let{field:r,selectionType:n,selection:s}=this;if(J(s))if(n==="interval"){let o=[this.min??0,t];s.update(to(r,o,{source:this,bin:"ceil",scale:{type:"identity",domain:o},pixelSize:this.step}))}else s.update(er(r,t,{source:this}));else k(this.selection)&&s.update(t)}};function Jn(e,t){if(e instanceof Date||(e=new Date(+e)),isNaN(e))return typeof t=="function"?t(e):t;let r=e.getUTCHours(),n=e.getUTCMinutes(),s=e.getUTCSeconds(),o=e.getUTCMilliseconds();return`${xa(e.getUTCFullYear(),4)}-${lt(e.getUTCMonth()+1,2)}-${lt(e.getUTCDate(),2)}${r||n||s||o?`T${lt(r,2)}:${lt(n,2)}${s||o?`:${lt(s,2)}${o?`.${lt(o,3)}`:""}`:""}Z`:""}`}function xa(e){return e<0?`-${lt(-e,6)}`:e>9999?`+${lt(e,6)}`:lt(e,4)}function lt(e,t){return`${e}`.padStart(t,"0")}var so=ci(e=>{let t=Zn(e);return r=>r==null?"":typeof r=="number"?t(r):r instanceof Date?oo(r):`${r}`}),Zn=ci(e=>t=>t===0?"0":t.toLocaleString(e)),EI=so(),wI=Zn();function oo(e){return Jn(e,"Invalid Date")}function ci(e){let t=null,r;return(n="en")=>n===t?r:r=e(t=n)}var ya=-1,ga=e=>Nt(Kn,e),Kn=class extends z{constructor({element:t,filterBy:r,from:n,columns:s=["*"],align:o={},format:i,width:c,maxWidth:a,height:u=500,rowBatch:f=100,as:p}={}){super(r),this.id=`table-${++ya}`,this.from=n,this.columns=s,this.format=i,this.align=o,this.widths=typeof c=="object"?c:{},k(n)&&n.addEventListener("value",()=>this.initialize()),this.offset=0,this.limit=+f,this.pending=!1,this.selection=p,this.currentRow=-1,this.sortHeader=null,this.sortColumn=null,this.sortDesc=!1,this.element=t||document.createElement("div"),this.element.setAttribute("id",this.id),Object.defineProperty(this.element,"value",{value:this}),typeof c=="number"&&(this.element.style.width=`${c}px`),a&&(this.element.style.maxWidth=`${a}px`),this.element.style.maxHeight=`${u}px`,this.element.style.overflow="auto";let d=-1;this.element.addEventListener("scroll",h=>{let{pending:m,loaded:E}=this,{scrollHeight:F,scrollTop:ft,clientHeight:Vt}=h.target,rr=ft<d;d=ft,!(rr||m||E)&&F-ft<2*Vt&&(this.pending=!0,this.requestData(this.offset+this.limit))}),this.tbl=document.createElement("table"),this.element.appendChild(this.tbl),this.head=document.createElement("thead"),this.tbl.appendChild(this.head),this.body=document.createElement("tbody"),this.tbl.appendChild(this.body),this.selection&&(this.body.addEventListener("pointerover",h=>{let m=Ea(h.target);m>-1&&m!==this.currentRow&&(this.currentRow=m,this.selection.update(this.clause([m])))}),this.body.addEventListener("pointerleave",()=>{this.currentRow=-1,this.selection.update(this.clause())})),this.style=document.createElement("style"),this.element.appendChild(this.style)}sourceTable(){return k(this.from)?this.from.value:this.from}clause(t=[]){let{data:r,limit:n,schema:s}=this,o=s.map(c=>c.column),i=t.map(c=>{let{columns:a}=r[~~(c/n)];return o.map(u=>a[u][c%n])});return Ks(o,i,{source:this})}requestData(t=0){this.offset=t;let r=this.query(this.filterBy?.predicate(this));this.requestQuery(r),Ke().prefetch(r.clone().offset(t+this.limit))}fields(){let t=this.sourceTable();return this.columns.map(r=>De(r,t))}fieldInfo(t){this.schema=t;let r=this.head;r.innerHTML="";let n=document.createElement("tr");for(let{column:s}of t){let o=document.createElement("th");o.addEventListener("click",i=>this.sort(i,s)),o.appendChild(document.createElement("span")),o.appendChild(document.createTextNode(s)),n.appendChild(o)}return r.appendChild(n),this.formats=wa(this.format,t),this.style.innerText=_a(this.id,ba(this.align,t),Ia(this.widths,t)),this}query(t=[]){let{limit:r,offset:n,schema:s,sortColumn:o,sortDesc:i}=this;return w.from(this.sourceTable()).select(s.map(c=>c.column)).where(t).orderby(o?i?Ps(o):o:[]).limit(r).offset(n)}queryResult(t){return this.pending||(this.loaded=!1,this.data=[],this.body.replaceChildren(),this.offset=0),this.data.push(no(t)),this}update(){let{body:t,formats:r,data:n,schema:s,limit:o}=this,i=s.length,c=n.length-1,a=o*c,{numRows:u,columns:f}=n[c],p=s.map(d=>f[d.column]);for(let d=0;d<u;++d){let h=document.createElement("tr");Object.assign(h,{__row__:a+d});for(let m=0;m<i;++m){let E=p[m][d],F=document.createElement("td");F.innerText=E==null?"":r[m](E),h.appendChild(F)}t.appendChild(h)}return u<o&&(this.loaded=!0),this.pending=!1,this}sort(t,r){r===this.sortColumn?this.sortDesc=!this.sortDesc:(this.sortColumn=r,this.sortDesc=!1);let n=t.currentTarget,s=this.sortHeader;s===n&&t.metaKey?(s.firstChild.textContent="",this.sortHeader=null,this.sortColumn=null):(s&&(s.firstChild.textContent=""),this.sortHeader=n,n.firstChild.textContent=this.sortDesc?"\u25BE":"\u25B4"),this.requestData()}};function Ea(e){let t=e.parentElement;return Object.hasOwn(t,"__row__")?+t.__row__:-1}function wa(e={},t,r){return t.map(({column:n,type:s})=>{if(n in e)return e[n];switch(s){case"number":return Zn(r);case"date":return oo;default:return so(r)}})}function ba(e={},t){return t.map(({column:r,type:n})=>r in e?e[r]:n==="number"?"right":"left")}function Ia(e={},t){return t.map(({column:r})=>e[r])}function _a(e,t,r){let n=[];return t.forEach((s,o)=>{let i=+r[o];if(s!=="left"||i){let c=s!=="left"?`text-align:${s};`:"",a=i?`width:${i}px;max-width:${i}px;`:"";n.push(`#${e} tr>:nth-child(${o+1}) {${c}${a}}`)}}),n.join(" ")}export{Gn as Menu,Hn as Search,Xn as Slider,Kn as Table,fa as menu,da as search,ha as slider,ga as table};
1
+ var io={};function ts(e,t=!1){let r,n,s=io;function o(u){r=e(u).catch(()=>{}).finally(()=>{if(n){let{value:f}=n;n=null,o(f)}else r=null})}function i(u){n={event:u}}function c(u){r?i(u):o(u)}function a(u){s!==u&&requestAnimationFrame(()=>{let f=s;s=io,c(f)}),s=u}return t?a:c}var z=class{constructor(t){this._filterBy=t,this._requestUpdate=ts(()=>this.requestQuery(),!0),this._coordinator=null}get coordinator(){return this._coordinator}set coordinator(t){this._coordinator=t}get filterBy(){return this._filterBy}get filterStable(){return!0}fields(){return null}fieldInfo(t){return this}query(t){return null}queryPending(){return this}queryResult(t){return this}queryError(t){return this}requestQuery(t){let r=t||this.query(this.filterBy?.predicate(this));return this._coordinator.requestQuery(this,r)}requestUpdate(){this._requestUpdate()}initialize(){return this._coordinator.initializeClient(this)}update(){return this}};var de=Uint8Array.of(65,82,82,79,87,49),j={V1:0,V2:1,V3:2,V4:3,V5:4};var V={NONE:0,Schema:1,DictionaryBatch:2,RecordBatch:3,Tensor:4,SparseTensor:5},l={Dictionary:-1,NONE:0,Null:1,Int:2,Float:3,Binary:4,Utf8:5,Bool:6,Decimal:7,Date:8,Time:9,Timestamp:10,Interval:11,List:12,Struct:13,Union:14,FixedSizeBinary:15,FixedSizeList:16,Map:17,Duration:18,LargeBinary:19,LargeUtf8:20,LargeList:21,RunEndEncoded:22,BinaryView:23,Utf8View:24,ListView:25,LargeListView:26},Wt={HALF:0,SINGLE:1,DOUBLE:2},rt={DAY:0,MILLISECOND:1},S={SECOND:0,MILLISECOND:1,MICROSECOND:2,NANOSECOND:3},W={YEAR_MONTH:0,DAY_TIME:1,MONTH_DAY_NANO:2},nt={Sparse:0,Dense:1};var Qt=Uint8Array,nr=Uint16Array,sr=Uint32Array,or=BigUint64Array,he=Int8Array,co=Int16Array,B=Int32Array,$=BigInt64Array,es=Float32Array,pt=Float64Array;function ao(e,t){let r=Math.log2(e)-3;return(t?[he,co,B,$]:[Qt,nr,sr,or])[r]}var Oa=Object.getPrototypeOf(Int8Array);function Yt(e,t){let r=0,n=e.length;if(n<=2147483648)do{let s=r+n>>>1;e[s]<=t?r=s+1:n=s}while(r<n);else do{let s=Math.trunc((r+n)/2);e[s]<=t?r=s+1:n=s}while(r<n);return r}function ir(e,t,r){if(t(e))return e;throw new Error(r(e))}function U(e,t,r){return t=Array.isArray(t)?t:Object.values(t),ir(e,n=>t.includes(n),r??(()=>`${e} must be one of ${t}`))}function cr(e,t){for(let[r,n]of Object.entries(e))if(n===t)return r;return"<Unknown>"}var st=e=>`Unsupported data type: "${cr(l,e)}" (id ${e})`,me=(e,t,r=!0,n=null)=>({name:e,type:t,nullable:r,metadata:n});function uo(e){return Object.hasOwn(e,"name")&&lo(e.type)}function lo(e){return typeof e?.typeId=="number"}function dt(e,t="",r=!0){return uo(e)?e:me(t,ir(e,lo,()=>"Data type expected."),r)}var ar=(e,t,r=!1,n=-1)=>({typeId:l.Dictionary,id:n,dictionary:e,indices:t||zt(),ordered:r});var ur=(e=32,t=!0)=>({typeId:l.Int,bitWidth:U(e,[8,16,32,64]),signed:t,values:ao(e,t)});var zt=()=>ur(32);var rs=(e=2)=>({typeId:l.Float,precision:U(e,Wt),values:[nr,es,pt][e]});var ns=()=>({typeId:l.Binary,offsets:B}),lr=()=>({typeId:l.Utf8,offsets:B});var ss=(e,t,r=128)=>({typeId:l.Decimal,precision:e,scale:t,bitWidth:U(r,[128,256]),values:or}),os=e=>({typeId:l.Date,unit:U(e,rt),values:e===rt.DAY?B:$});var is=(e=S.MILLISECOND,t=32)=>({typeId:l.Time,unit:U(e,S),bitWidth:U(t,[32,64]),values:t===32?B:$});var fr=(e=S.MILLISECOND,t=null)=>({typeId:l.Timestamp,unit:U(e,S),timezone:t,values:$}),cs=(e=W.MONTH_DAY_NANO)=>({typeId:l.Interval,unit:U(e,W),values:e===W.MONTH_DAY_NANO?void 0:B}),pr=e=>({typeId:l.List,children:[dt(e)],offsets:B}),dr=e=>({typeId:l.Struct,children:Array.isArray(e)&&uo(e[0])?e:Object.entries(e).map(([t,r])=>me(t,r))}),as=(e,t,r,n)=>(r??=t.map((s,o)=>o),{typeId:l.Union,mode:U(e,nt),typeIds:r,typeMap:r.reduce((s,o,i)=>(s[o]=i,s),{}),children:t.map((s,o)=>dt(s,`_${o}`)),typeIdForValue:n,offsets:B}),us=e=>({typeId:l.FixedSizeBinary,stride:e}),hr=(e,t)=>({typeId:l.FixedSizeList,stride:t,children:[dt(e)]}),fo=(e,t)=>({typeId:l.Map,keysSorted:e,children:[t],offsets:B});var ls=(e=S.MILLISECOND)=>({typeId:l.Duration,unit:U(e,S),values:$}),fs=()=>({typeId:l.LargeBinary,offsets:$}),ps=()=>({typeId:l.LargeUtf8,offsets:$}),ds=e=>({typeId:l.LargeList,children:[dt(e)],offsets:$}),hs=(e,t)=>({typeId:l.RunEndEncoded,children:[ir(dt(e,"run_ends"),r=>r.type.typeId===l.Int,()=>"Run-ends must have an integer type."),dt(t,"values")]});var ms=e=>({typeId:l.ListView,children:[dt(e,"value")],offsets:B}),xs=e=>({typeId:l.LargeListView,children:[dt(e,"value")],offsets:$});var ai=new pt(2),mr=ai.buffer,Ua=new $(mr),qa=new sr(mr),$a=new B(mr),Pa=new Qt(mr);function Z(e){if(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)throw Error(`BigInt exceeds integer number representation: ${e}`);return Number(e)}function xr(e,t){return Number(e/t)+Number(e%t)/Number(t)}var Gt=e=>BigInt.asUintN(64,e);function ho(e,t){let r=t<<1,n;return BigInt.asIntN(64,e[r+1])<0?(n=Gt(~e[r])|Gt(~e[r+1])<<64n,n=-(n+1n)):n=e[r]|e[r+1]<<64n,n}function mo(e,t){let r=t<<2,n;return BigInt.asIntN(64,e[r+3])<0?(n=Gt(~e[r])|Gt(~e[r+1])<<64n|Gt(~e[r+2])<<128n|Gt(~e[r+3])<<192n,n=-(n+1n)):n=e[r]|e[r+1]<<64n|e[r+2]<<128n|e[r+3]<<192n,n}var li=new TextDecoder("utf-8"),Qa=new TextEncoder;function Ht(e){return li.decode(e)}var Nt=4;function ys(e,t){return(e[t>>3]&1<<t%8)!==0}function L(e,t){let r=t+y(e,t),n=r-y(e,r),s=T(e,n);return(o,i,c=null)=>{if(o<s){let a=T(e,n+o);if(a)return i(e,r+a)}return c}}function G(e,t){return t}function ht(e,t){return!!fi(e,t)}function fi(e,t){return xe(e,t)<<24>>24}function xe(e,t){return e[t]}function T(e,t){return pi(e,t)<<16>>16}function pi(e,t){return e[t]|e[t+1]<<8}function y(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function xo(e,t){return y(e,t)>>>0}function O(e,t){return Z(BigInt.asIntN(64,BigInt(xo(e,t))+(BigInt(xo(e,t+Nt))<<32n)))}function St(e,t){let r=t+y(e,t),n=y(e,r);return r+=Nt,Ht(e.subarray(r,r+n))}function P(e,t,r,n){if(!t)return[];let s=t+y(e,t);return Array.from({length:y(e,s)},(o,i)=>n(e,s+Nt+i*r))}var gs=Symbol("rowIndex");function ye(e,t){class r{constructor(o){this[gs]=o}toJSON(){return yo(e,t,this[gs])}}let n=r.prototype;for(let s=0;s<e.length;++s){if(Object.hasOwn(n,e[s]))continue;let o=t[s];Object.defineProperty(n,e[s],{get(){return o.at(this[gs])},enumerable:!0})}return s=>new r(s)}function yr(e,t){return r=>yo(e,t,r)}function yo(e,t,r){let n={};for(let s=0;s<e.length;++s)n[e[s]]=t[s].at(r);return n}function go(e){return e instanceof mt}var Ot=class{static ArrayType=null;constructor({length:t,nullCount:r,type:n,validity:s,values:o,offsets:i,sizes:c,children:a}){this.length=t,this.nullCount=r,this.type=n,this.validity=s,this.values=o,this.offsets=i,this.sizes=c,this.children=a,(!r||!this.validity)&&(this.at=u=>this.value(u))}get[Symbol.toStringTag](){return"Batch"}at(t){return this.isValid(t)?this.value(t):null}isValid(t){return ys(this.validity,t)}value(t){return this.values[t]}slice(t,r){let n=r-t,s=Array(n);for(let o=0;o<n;++o)s[o]=this.at(t+o);return s}*[Symbol.iterator](){for(let t=0;t<this.length;++t)yield this.at(t)}},mt=class extends Ot{constructor(t){super(t);let{length:r,values:n}=this;this.values=n.subarray(0,r)}slice(t,r){return this.nullCount?super.slice(t,r):this.values.subarray(t,r)}[Symbol.iterator](){return this.nullCount?super[Symbol.iterator]():this.values[Symbol.iterator]()}},ge=class extends Ot{static ArrayType=pt},_=class extends Ot{static ArrayType=Array},Ee=class extends _{value(t){return null}},K=class extends ge{value(t){return Z(this.values[t])}},gr=class extends ge{value(t){let r=this.values[t],n=(r&31744)>>10,s=(r&1023)/1024,o=(-1)**((r&32768)>>15);switch(n){case 31:return o*(s?Number.NaN:1/0);case 0:return o*(s?6103515625e-14*s:0)}return o*2**(n-15)*(1+s)}},Er=class extends _{value(t){return ys(this.values,t)}},wr=class extends Ot{constructor(t){super(t);let{bitWidth:r,scale:n}=this.type;this.decimal=r===128?ho:mo,this.scale=10n**BigInt(n)}},br=class extends wr{static ArrayType=pt;value(t){return xr(this.decimal(this.values,t),this.scale)}},Ir=class extends wr{static ArrayType=Array;value(t){return this.decimal(this.values,t)}},we=class extends _{constructor(t){super(t),this.source=t}value(t){return new Date(this.source.value(t))}},_r=class extends ge{value(t){return 864e5*this.values[t]}},Eo=K,Ar=class extends K{value(t){return super.value(t)*1e3}},wo=K,vr=class extends K{value(t){return xr(this.values[t],1000n)}},Nr=class extends K{value(t){return xr(this.values[t],1000000n)}},Sr=class extends _{value(t){return this.values.subarray(t<<1,t+1<<1)}},Or=class extends _{value(t){let r=this.values,n=t<<4;return Float64Array.of(y(r,n),y(r,n+4),O(r,n+8))}},bo=({values:e,offsets:t},r)=>e.subarray(t[r],t[r+1]),Io=({values:e,offsets:t},r)=>e.subarray(Z(t[r]),Z(t[r+1])),Tr=class extends _{value(t){return bo(this,t)}},Lr=class extends _{value(t){return Io(this,t)}},Cr=class extends _{value(t){return Ht(bo(this,t))}},Rr=class extends _{value(t){return Ht(Io(this,t))}},Dr=class extends _{value(t){let r=this.offsets;return this.children[0].slice(r[t],r[t+1])}},Mr=class extends _{value(t){let r=this.offsets;return this.children[0].slice(Z(r[t]),Z(r[t+1]))}},Fr=class extends _{value(t){let r=this.offsets[t],n=r+this.sizes[t];return this.children[0].slice(r,n)}},Br=class extends _{value(t){let r=this.offsets[t],n=r+this.sizes[t];return this.children[0].slice(Z(r),Z(n))}},Ur=class extends _{constructor(t){super(t),this.stride=this.type.stride}},qr=class extends Ur{value(t){let{stride:r,values:n}=this;return n.subarray(t*r,(t+1)*r)}},$r=class extends Ur{value(t){let{children:r,stride:n}=this;return r[0].slice(t*n,(t+1)*n)}};function _o({children:e,offsets:t},r){let[n,s]=e[0].children,o=t[r],i=t[r+1],c=[];for(let a=o;a<i;++a)c.push([n.at(a),s.at(a)]);return c}var Pr=class extends _{value(t){return _o(this,t)}},kr=class extends _{value(t){return new Map(_o(this,t))}},be=class extends _{constructor({typeIds:t,...r}){super(r),this.typeIds=t,this.typeMap=this.type.typeMap}value(t,r=t){let{typeIds:n,children:s,typeMap:o}=this;return s[o[n[t]]].at(r)}},jr=class extends be{value(t){return super.value(t,this.offsets[t])}},Ie=class extends _{constructor(t,r=yr){super(t),this.names=this.type.children.map(n=>n.name),this.factory=r(this.names,this.children)}value(t){return this.factory(t)}},Vr=class extends Ie{constructor(t){super(t,ye)}},Wr=class extends _{value(t){let[{values:r},n]=this.children;return n.at(Yt(r,t))}},Qr=class extends _{setDictionary(t){return this.dictionary=t,this.cache=t.cache(),this}value(t){return this.cache[this.key(t)]}key(t){return this.values[t]}},Yr=class extends _{constructor({data:t,...r}){super(r),this.data=t}view(t){let{values:r,data:n}=this,s=t<<4,o=s+4,i=r,c=y(i,s);return c>12&&(o=y(i,s+12),i=n[y(i,s+8)]),i.subarray(o,o+c)}},zr=class extends Yr{value(t){return this.view(t)}},Gr=class extends Yr{value(t){return Ht(this.view(t))}};function Es(e){let t=[];return{add(r){return t.push(r),this},clear:()=>t=[],done:()=>new Tt(t,e)}}var Tt=class{constructor(t,r=t[0]?.type){this.type=r,this.length=t.reduce((o,i)=>o+i.length,0),this.nullCount=t.reduce((o,i)=>o+i.nullCount,0),this.data=t;let n=t.length,s=new Int32Array(n+1);if(n===1){let[o]=t;s[1]=o.length,this.at=i=>o.at(i)}else for(let o=0,i=0;o<n;++o)s[o+1]=i+=t[o].length;this.offsets=s}get[Symbol.toStringTag](){return"Column"}[Symbol.iterator](){let t=this.data;return t.length===1?t[0][Symbol.iterator]():di(t)}at(t){let{data:r,offsets:n}=this,s=Yt(n,t)-1;return r[s]?.at(t-n[s])}get(t){return this.at(t)}toArray(){let{length:t,nullCount:r,data:n}=this,s=!r&&go(n[0]),o=n.length;if(s&&o===1)return n[0].values;let i=!o||r>0?Array:n[0].constructor.ArrayType??n[0].values.constructor,c=new i(t);return s?hi(c,n):mi(c,n)}cache(){return this._cache??(this._cache=this.toArray())}};function*di(e){for(let t=0;t<e.length;++t){let r=e[t][Symbol.iterator]();for(let n=r.next();!n.done;n=r.next())yield n.value}}function hi(e,t){for(let r=0,n=0;r<t.length;++r){let{values:s}=t[r];e.set(s,n),n+=s.length}return e}function mi(e,t){let r=-1;for(let n=0;n<t.length;++n){let s=t[n];for(let o=0;o<s.length;++o)e[++r]=s.at(o)}return e}var Xt=class e{constructor(t,r,n=!1){let s=t.fields.map(i=>i.name);this.schema=t,this.names=s,this.children=r,this.factory=n?ye:yr;let o=[];this.getFactory=i=>o[i]??(o[i]=this.factory(s,r.map(c=>c.data[i])))}get[Symbol.toStringTag](){return"Table"}get numCols(){return this.names.length}get numRows(){return this.children[0]?.length??0}getChildAt(t){return this.children[t]}getChild(t){let r=this.names.findIndex(n=>n===t);return r>-1?this.children[r]:void 0}selectAt(t,r=[]){let{children:n,factory:s,schema:o}=this,{fields:i}=o;return new e({...o,fields:t.map((c,a)=>xi(i[c],r[a]))},t.map(c=>n[c]),s===ye)}select(t,r){let n=this.names,s=t.map(o=>n.indexOf(o));return this.selectAt(s,r)}toColumns(){let{children:t,names:r}=this,n={};return r.forEach((s,o)=>n[s]=t[o]?.toArray()??[]),n}toArray(){let{children:t,getFactory:r,numRows:n}=this,s=t[0]?.data??[],o=Array(n);for(let i=0,c=-1;i<s.length;++i){let a=r(i);for(let u=0;u<s[i].length;++u)o[++c]=a(u)}return o}*[Symbol.iterator](){let{children:t,getFactory:r}=this,n=t[0]?.data??[];for(let s=0;s<n.length;++s){let o=r(s);for(let i=0;i<n[s].length;++i)yield o(i)}}at(t){let{children:r,getFactory:n,numRows:s}=this;if(t<0||t>=s)return null;let[{offsets:o}]=r,i=Yt(o,t)-1;return n(i)(t-o[i])}get(t){return this.at(t)}};function xi(e,t){return t!=null&&t!==e.name?{...e,name:t}:e}function _e(e,t={}){let{typeId:r,bitWidth:n,precision:s,unit:o}=e,{useBigInt:i,useDate:c,useDecimalBigInt:a,useMap:u,useProxy:f}=t;switch(r){case l.Null:return Ee;case l.Bool:return Er;case l.Int:case l.Time:case l.Duration:return i||n<64?mt:K;case l.Float:return s?mt:gr;case l.Date:return Ao(o===rt.DAY?_r:Eo,c&&we);case l.Timestamp:return Ao(o===S.SECOND?Ar:o===S.MILLISECOND?wo:o===S.MICROSECOND?vr:Nr,c&&we);case l.Decimal:return a?Ir:br;case l.Interval:return o===W.DAY_TIME?Sr:o===W.YEAR_MONTH?mt:Or;case l.FixedSizeBinary:return qr;case l.Utf8:return Cr;case l.LargeUtf8:return Rr;case l.Binary:return Tr;case l.LargeBinary:return Lr;case l.BinaryView:return zr;case l.Utf8View:return Gr;case l.List:return Dr;case l.LargeList:return Mr;case l.Map:return u?kr:Pr;case l.ListView:return Fr;case l.LargeListView:return Br;case l.FixedSizeList:return $r;case l.Struct:return f?Vr:Ie;case l.RunEndEncoded:return Wr;case l.Dictionary:return Qr;case l.Union:return e.mode?jr:be}throw new Error(st(r))}function Ao(e,t){return t?class extends t{constructor(n){super(new e(n))}}:e}function yi(e,t){return{offset:O(e,t),metadataLength:y(e,t+8),bodyLength:O(e,t+16)}}function ws(e,t){return P(e,t,24,yi)}function Hr(e,t,r){let n=L(e,t);if(n(10,G,0))throw new Error("Record batch compression not implemented");let s=r<j.V4?8:0;return{length:n(4,O,0),nodes:P(e,n(6,G),16,(o,i)=>({length:O(o,i),nullCount:O(o,i+8)})),regions:P(e,n(8,G),16+s,(o,i)=>({offset:O(o,i+s),length:O(o,i+s+8)})),variadic:P(e,n(12,G),8,O)}}function vo(e,t,r){let n=L(e,t);return{id:n(4,O,0),data:n(6,(s,o)=>Hr(s,o,r)),isDelta:n(8,ht,!1)}}function bs(e,t,r,n){U(r,l,st);let s=L(e,t);switch(r){case l.Binary:return ns();case l.Utf8:return lr();case l.LargeBinary:return fs();case l.LargeUtf8:return ps();case l.List:return pr(n[0]);case l.ListView:return ms(n[0]);case l.LargeList:return ds(n[0]);case l.LargeListView:return xs(n[0]);case l.Struct:return dr(n);case l.RunEndEncoded:return hs(n[0],n[1]);case l.Int:return ur(s(4,y,0),s(6,ht,!1));case l.Float:return rs(s(4,T,Wt.HALF));case l.Decimal:return ss(s(4,y,0),s(6,y,0),s(8,y,128));case l.Date:return os(s(4,T,rt.MILLISECOND));case l.Time:return is(s(4,T,S.MILLISECOND),s(6,y,32));case l.Timestamp:return fr(s(4,T,S.SECOND),s(6,St));case l.Interval:return cs(s(4,T,W.YEAR_MONTH));case l.Duration:return ls(s(4,T,S.MILLISECOND));case l.FixedSizeBinary:return us(s(4,y,0));case l.FixedSizeList:return hr(n[0],s(4,y,0));case l.Map:return fo(s(4,ht,!1),n[0]);case l.Union:return as(s(4,T,nt.Sparse),n,P(e,s(6,G),4,y))}return{typeId:r}}function Ae(e,t){let r=P(e,t,4,(n,s)=>{let o=L(n,s);return[o(4,St),o(6,St)]});return r.length?new Map(r):null}function Xr(e,t,r){let n=L(e,t);return{version:r,endianness:n(4,T,0),fields:n(6,gi,[]),metadata:n(8,Ae)}}function gi(e,t){return P(e,t,4,No)}function No(e,t){let r=L(e,t),n=r(8,xe,l.NONE),s=r(10,G,0),o=r(12,wi),i=r(14,(a,u)=>Ei(a,u)),c=bs(e,s,n,i);return o&&(o.dictionary=c,c=o),{name:r(4,St),type:c,nullable:r(6,ht,!1),metadata:r(16,Ae)}}function Ei(e,t){let r=P(e,t,4,No);return r.length?r:null}function wi(e,t){if(!t)return null;let r=L(e,t);return ar(null,r(6,bi,zt()),r(8,ht,!1),r(4,O,0))}function bi(e,t){return bs(e,t,l.Int)}var Ii=(e,t)=>`Expected to read ${e} metadata bytes, but only read ${t}.`,_i=(e,t)=>`Expected to read ${e} bytes for message body, but only read ${t}.`,Ai=e=>`Unsupported message type: ${e} (${cr(V,e)})`;function Jr(e,t){let r=y(e,t)||0;if(t+=Nt,r===-1&&(r=y(e,t)||0,t+=Nt),r===0)return null;let n=e.subarray(t,t+=r);if(n.byteLength<r)throw new Error(Ii(r,n.byteLength));let s=L(n,0),o=s(4,T,j.V1),i=s(6,xe,V.NONE),c=s(8,G,0),a=s(10,O,0),u;if(c){let f=i===V.Schema?Xr:i===V.DictionaryBatch?vo:i===V.RecordBatch?Hr:null;if(!f)throw new Error(Ai(i));if(u=f(n,c,o),a>0){let p=e.subarray(t,t+=a);if(p.byteLength<a)throw new Error(_i(a,p.byteLength));u.body=p}}return{version:o,type:i,index:t,content:u}}function So(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;return t instanceof Uint8Array&&vi(t)?Si(t):Ni(t)}function vi(e){if(!e||e.length<4)return!1;for(let t=0;t<6;++t)if(de[t]!==e[t])return!1;return!0}function Ni(e){let t=[e].flat(),r,n=[],s=[];for(let o of t){if(!(o instanceof Uint8Array))throw new Error("IPC data batch was not a Uint8Array.");let i=0;for(;;){let c=Jr(o,i);if(c===null)break;if(i=c.index,!!c.content)switch(c.type){case V.Schema:r||(r=c.content);break;case V.RecordBatch:n.push(c.content);break;case V.DictionaryBatch:s.push(c.content);break}}}return{schema:r,dictionaries:s,records:n,metadata:null}}function Si(e){let t=e.byteLength-(de.length+4),r=y(e,t),n=L(e,t-r),s=n(4,T,j.V1),o=n(8,ws,[]),i=n(10,ws,[]);return{schema:n(6,(c,a)=>Xr(c,a,s)),dictionaries:o.map(({offset:c})=>Jr(e,c).content),records:i.map(({offset:c})=>Jr(e,c).content),metadata:n(12,Ae)}}function _s(e,t){return Oi(So(e),t)}function Oi(e,t={}){let{schema:r={fields:[]},dictionaries:n,records:s}=e,{version:o,fields:i}=r,c=new Map,a=Li(t,o,c),u=new Map;Ti(r,h=>{let m=h.type;m.typeId===l.Dictionary&&u.set(m.id,m.dictionary)});let f=new Map;for(let h of n){let{id:m,data:d,isDelta:E,body:F}=h,ft=u.get(m),Vt=Is(ft,a({...d,body:F}));if(f.has(m)){let rr=f.get(m);E||rr.clear(),rr.add(Vt)}else{if(E)throw new Error("Delta update can not be first dictionary batch.");f.set(m,Es(ft).add(Vt))}}f.forEach((h,m)=>c.set(m,h.done()));let p=i.map(h=>Es(h.type));for(let h of s){let m=a(h);i.forEach((d,E)=>p[E].add(Is(d.type,m)))}return new Xt(r,p.map(h=>h.done()),t.useProxy)}function Ti(e,t){e.fields.forEach(function r(n){t(n),n.type.dictionary?.children?.forEach(r),n.type.children?.forEach(r)})}function Li(e,t,r){let n={version:t,options:e,dictionary:s=>r.get(s)};return s=>{let{length:o,nodes:i,regions:c,variadic:a,body:u}=s,f=-1,p=-1,h=-1;return{...n,length:o,node:()=>i[++f],buffer:m=>{let{length:d,offset:E}=c[++p];return m?new m(u.buffer,u.byteOffset+E,d/m.BYTES_PER_ELEMENT):u.subarray(E,E+d)},variadic:()=>a[++h],visit(m){return m.map(d=>Is(d.type,this))}}}}function Is(e,t){let{typeId:r}=e,{length:n,options:s,node:o,buffer:i,variadic:c,version:a}=t,u=_e(e,s);if(r===l.Null)return new u({length:n,nullCount:n,type:e});let f={...o(),type:e};switch(r){case l.Bool:case l.Int:case l.Time:case l.Duration:case l.Float:case l.Decimal:case l.Date:case l.Timestamp:case l.Interval:case l.FixedSizeBinary:return new u({...f,validity:i(),values:i(e.values)});case l.Utf8:case l.LargeUtf8:case l.Binary:case l.LargeBinary:return new u({...f,validity:i(),offsets:i(e.offsets),values:i()});case l.BinaryView:case l.Utf8View:return new u({...f,validity:i(),values:i(),data:Array.from({length:c()},()=>i())});case l.List:case l.LargeList:case l.Map:return new u({...f,validity:i(),offsets:i(e.offsets),children:t.visit(e.children)});case l.ListView:case l.LargeListView:return new u({...f,validity:i(),offsets:i(e.offsets),sizes:i(e.offsets),children:t.visit(e.children)});case l.FixedSizeList:case l.Struct:return new u({...f,validity:i(),children:t.visit(e.children)});case l.RunEndEncoded:return new u({...f,children:t.visit(e.children)});case l.Dictionary:{let{id:p,indices:h}=e;return new u({...f,validity:i(),values:i(h.values)}).setDictionary(t.dictionary(p))}case l.Union:return a<j.V5&&i(),new u({...f,typeIds:i(he),offsets:e.mode===nt.Sparse?null:i(e.offsets),children:t.visit(e.children)});default:throw new Error(st(r))}}var wl=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;function ve(e){return _s(e,{useDate:!0})}function As(e="ws://localhost:3000/"){let t=[],r=!1,n=null,s,o={open(){r=!0,a()},close(){for(r=!1,n=null,s=null;t.length;)t.shift().reject("Socket closed")},error(u){if(n){let{reject:f}=n;n=null,a(),f(u)}else console.error("WebSocket error: ",u)},message({data:u}){if(n){let{query:f,resolve:p,reject:h}=n;if(n=null,a(),typeof u=="string"){let m=JSON.parse(u);m.error?h(m.error):p(m)}else if(f.type==="exec")p();else if(f.type==="arrow")p(ve(u));else throw new Error(`Unexpected socket data: ${u}`)}else console.log("WebSocket message: ",u)}};function i(){s=new WebSocket(e),s.binaryType="arraybuffer";for(let u in o)s.addEventListener(u,o[u])}function c(u,f,p){s==null&&i(),t.push({query:u,resolve:f,reject:p}),r&&!n&&a()}function a(){t.length&&(n=t.shift(),s.send(JSON.stringify(n.query)))}return{get connected(){return r},query(u){return new Promise((f,p)=>c(u,f,p))}}}var Jt="COLUMN_REF",Zr="COLUMN_PARAM",Mo="TABLE_REF",Fo="LITERAL";var Kr="ORDER_BY",tn="CAST",vs="CASE",Ns="WHEN",Ss="UNARY",Bo="UNARY_POSTFIX",en="BINARY",rn="BETWEEN",nn="NOT_BETWEEN",sn="LOGICAL_OPERATOR",on="IN",cn="FUNCTION",Ct="AGGREGATE",Zt="WINDOW",an="WINDOW_DEF",un="WINDOW_FRAME",Uo="EXPRESSION",Kt="FRAGMENT",ln="VERBATIM",Ne="PARAM",qo="WITH_CLAUSE",fn="SELECT_CLAUSE",pn="FROM_CLAUSE";var $o="SAMPLE_CLAUSE";var dn="WINDOW_CLAUSE";var hn="SELECT_QUERY",mn="DESCRIBE_QUERY",xn="SET_OPERATION";function Q(e){return e instanceof v}var v=class{constructor(t){this.type=t}},x=class extends v{};var Rt=class extends x{constructor(t){super(Fo),this.value=t}toString(){return Os(this.value)}};function Os(e){switch(typeof e){case"number":return Number.isFinite(e)?`${e}`:"NULL";case"string":return`'${e.replace("'","''")}'`;case"boolean":return e?"TRUE":"FALSE";default:if(e==null)return"NULL";if(e instanceof Date){let t=+e;if(Number.isNaN(t))return"NULL";let r=e.getUTCFullYear(),n=e.getUTCMonth(),s=e.getUTCDate();return t===Date.UTC(r,n,s)?`DATE '${r}-${n+1}-${s}'`:`epoch_ms(${t})`}else return e instanceof RegExp?`'${e.source}'`:`${e}`}}var H=class extends x{constructor(t){super(Ne),this.param=t}get value(){return this.param.value}toString(){return Os(this.value)}};function Ts(e){return e.split(".")}function X(e){return`"${e}"`}function yn(e){return e&&Ki(e)?e.slice(1,-1):e}function Ki(e){return e[0]==='"'&&e[e.length-1]==='"'}function xt(e){return e instanceof te}var te=class extends x{constructor(t){super(Mo),this.table=[t].flat()}get name(){return this.table[this.table.length-1]}toString(){return this.table.map(t=>X(t)).join(".")}};var ee=class extends x{constructor(t,r=[]){super(cn),this.name=t,this.args=r}toString(){let{name:t,args:r}=this;return`${t}(${r.join(", ")})`}};function R(e,...t){return new ee(e,gn(t).map(g))}function tt(e,...t){return new Se(e,gn(t).map(g))}function q(e,t=g){return e.flat().filter(r=>r!=null).map(r=>t(r))}function gn(e){let t=e.length,r=t;for(;r>0&&e[r-1]===void 0;--r);return r<t?e.slice(0,r):e}function Y(e){return typeof e=="string"}function Oe(e){return Array.isArray(e)}function it(e){return e&&typeof e.addEventListener=="function"&&e.dynamic!==!1&&"value"in e}var Le=class extends v{constructor(t,r){super(dn),this.name=t,this.def=r}toString(){return`${X(this.name)} AS ${this.def}`}},re=class e extends x{constructor(t,r=new ne){super(Zt),this.func=t,this.def=r}over(t){return new e(this.func,this.def.over(t))}partitionby(...t){return new e(this.func,this.def.partitionby(...t))}orderby(...t){return new e(this.func,this.def.orderby(...t))}rows(t){return new e(this.func,this.def.rows(t))}range(t){return new e(this.func,this.def.range(t))}toString(){return`${this.func} OVER ${this.def}`}};var ne=class extends v{constructor(t,r,n,s){super(an),this.name=t,this.partition=r,this.order=n,this.frame=s}over(t){return Te(this,{name:t})}partitionby(...t){return Te(this,{partition:q(t)})}orderby(...t){return Te(this,{order:q(t)})}rows(t){return Te(this,{frame:new Ce(t)})}range(t){return Te(this,{frame:new Ce(t,!0)})}toString(){let{name:t,partition:r,order:n,frame:s}=this,o=t&&X(t),i=[o,r?.length&&`PARTITION BY ${r.join(", ")}`,n?.length&&`ORDER BY ${n.join(", ")}`,s].filter(c=>c);return o&&i.length<2?o:`(${i.join(" ")})`}},Ce=class extends v{constructor(t,r=!1,n=void 0){super(un),this.extent=it(t)?new H(t):t,this.range=r,this.exclude=n}toString(){let{range:t,exclude:r,extent:n}=this,s=t?"RANGE":"ROWS",[o,i]=Q(n)?n.value:n,c=Po(o,"PRECEDING"),a=Po(i,"FOLLOWING");return`${s} BETWEEN ${c} AND ${a}${r?` ${r}`:""}`}};function Te(e,t){return new ne(t.name??e.name,t.partition??e.partition,t.order??e.order,t.frame??e.frame)}function Po(e,t){return e===0?"CURRENT ROW":Number.isFinite(e)?`${Math.abs(e)} ${t}`:`UNBOUNDED ${t}`}function se(e){return e instanceof ct}var ct=class extends x{constructor(t,r){super(t),this.table=r}get column(){return null}toString(){let{column:t,table:r}=this,n=`${r??""}`,s=t==="*"?"*":X(t);return(n?n+".":"")+s}},Re=class extends ct{constructor(t,r){super(Jt,r),this.name=t}get column(){return this.name}};var De=class extends ct{constructor(t,r){super(Zr,r),this.param=t}get column(){return`${this.param.value}`}};function Me(e,t){let r=Dt(t);return it(e)?new De(new H(e),r):new Re(e,r)}var Mt=class extends x{constructor(t){super(ln),this.value=t}toString(){return this.value}};function C(e){return new Rt(e)}function ko(e){return new Mt(e)}function En(...e){let t=q(e,String);return t?.length?new te(t):void 0}function g(e){return Y(e)?ec(e):oe(e)}function Ft(e){return Y(e)?ko(e):oe(e)}function oe(e){return e instanceof x?e:it(e)?new H(e):C(e)}function Dt(e){return Y(e)?rc(e):Oe(e)?En(e):e}function ec(e){let t=Ts(e);return Me(t.pop(),En(t))}function rc(e){return En(Ts(e))}var Se=class e extends x{constructor(t,r,n,s){super(Ct),this.name=t,this.args=r,this.isDistinct=n,this.filter=s}distinct(t=!0){return new e(this.name,this.args,t,this.filter)}where(t){return Y(t)&&(t=Ft(t)),new e(this.name,this.args,this.isDistinct,t)}window(){return new re(this)}partitionby(...t){return this.window().partitionby(...t)}orderby(...t){return this.window().orderby(...t)}toString(){let{name:t,args:r,isDistinct:n,filter:s}=this,o=n?"DISTINCT ":"",i=r?.length?r.join(", "):"*",c=s?` FILTER (WHERE ${s})`:"";return`${t}(${o}${i})${c}`}},jo=["any_value","approx_count_distinct","approx_quantile","arbitrary","arg_max","arg_max_null","arg_min","arg_min_null","array_agg","avg","bit_and","bit_or","bit_xor","bitstring_agg","bool_and","bool_or","corr","count","covar_pop","covar_samp","entropy","favg","first","fsum","geomean","kurtosis_pop","kurtosis","last","mad","max","max_by","median","min","min_by","mode","product","quantile","quantile_cont","quantile_disc","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_sxx","regr_sxy","regr_syy","regr_slope","reservoir_quantile","skewness","stddev","stddev_pop","stddev_samp","string_agg","sum","variance","var_pop","var_samp"];var wn=class extends x{constructor(t,r,n){super(t),this.expr=r,this.extent=n}toSQL(t){let{extent:r,expr:n}=this;return r?`(${n} ${t} ${r[0]} AND ${r[1]})`:""}},Fe=class extends wn{constructor(t,r){super(rn,t,r)}toString(){return super.toSQL("BETWEEN")}},Be=class extends wn{constructor(t,r){super(nn,t,r)}toString(){return super.toSQL("NOT BETWEEN")}};var Ue=class extends x{constructor(t,r,n){super(en),this.op=t,this.left=r,this.right=n}toString(){return`(${this.left} ${this.op} ${this.right})`}};var qe=class extends x{constructor(t,r){super(tn),this.expr=t,this.cast=r}toString(){return`(${this.expr})::${this.cast}`}};var $e=class extends x{constructor(t){super(Kt),this.spans=t}toString(){return this.spans.join("")}};var Pe=class extends v{constructor(t,r=!1,n=void 0,s=void 0){super($o),this.size=t,this.perc=r,this.method=n,this.seed=s}toString(){let{size:t,perc:r,method:n,seed:s}=this,o=r?"%":" ROWS",i=s!=null?`, ${s}`:"";return`${t}${o}${n?` (${n}${i})`:""}`}};var ke=class extends v{constructor(t,r){super(fn),this.expr=t,this.alias=r}toString(){let{expr:t,alias:r}=this;return!r||nc(t,r)?`${t}`:`${t} AS ${X(r)}`}};function nc(e,t){return e instanceof ct&&e.table==null&&e.column===t}var je=class extends v{constructor(t,r){super(qo),this.name=t,this.query=r}toString(){return`"${this.name}" AS (${this.query})`}};function bn(e){return e instanceof w}function yt(e){return e instanceof Ut}function Ls(e){return e instanceof Ve}var w=class extends x{static select(...t){return new Ut().select(...t)}static from(...t){return new Ut().from(...t)}static with(...t){return new Ut().with(...t)}static union(...t){return new Bt("UNION",t.flat())}static unionAll(...t){return new Bt("UNION ALL",t.flat())}static intersect(...t){return new Bt("INTERSECT",t.flat())}static except(...t){return new Bt("EXCEPT",t.flat())}static describe(t){return new Ve(t)}constructor(t){super(t),this._orderby=[],this._limit=void 0,this._offset=void 0,this.cteFor=null}get subqueries(){return[]}clone(){return this}orderby(...t){return this._orderby=this._orderby.concat(q(t)),this}limit(t){return this._limit=Number.isFinite(t)?t:void 0,this}offset(t){return this._offset=Number.isFinite(t)?t:void 0,this}},Ut=class e extends w{constructor(){super(hn),this._with=[],this._select=[],this._from=[],this._where=[],this._sample=void 0,this._groupby=[],this._having=[],this._window=[],this._qualify=[]}get subqueries(){let t=this.cteFor||this,n=(t instanceof e?t._with:[]).reduce((o,i)=>(o[i.name]=i.query,o),{}),s=[];return this._from.forEach(({expr:o})=>{if(bn(o))s.push(o);else if(xt(o)){let i=n[o.name];i&&s.push(i)}}),s}clone(){return Object.assign(new e,this)}with(...t){let r=[],n=(s,o)=>{let i=o.clone();i.cteFor=this,r.push(new je(s,i))};return t.flat().forEach(s=>{if(s!=null)for(let o in s)n(o,s[o])}),this._with=this._with.concat(r),this}select(...t){let r=[],n=(o,i)=>r.push(new ke(o==null?o:g(o),yn(i)));t.flat().forEach(o=>{if(o!=null)if(Y(o))n(o,o);else if(se(o))n(o,o.column);else if(Oe(o))n(o[1],o[0]);else for(let i in o)n(o[i],i)});let s=new Set(r.map(o=>o.alias));return this._select=this._select.filter(o=>!s.has(o.alias)).concat(r.filter(o=>o.expr)),this}setSelect(...t){return this._select=[],this.select(...t)}distinct(t=!0){return this._distinct=!!t,this}from(...t){let r=[],n=(s,o)=>r.push(new We(Dt(s),yn(o)));return t.flat().forEach(s=>{if(s!=null)if(Y(s))n(s,s);else if(xt(s))n(s,s.name);else if(Q(s))n(s);else if(Oe(s))n(s[1],s[0]);else for(let o in s)n(s[o],o)}),this._from=this._from.concat(r),this}setFrom(...t){return this._from=[],this.from(...t)}sample(t,r,n){let s;if(typeof t=="number"){let o=t>0&&t<1,i=o?t*100:Math.floor(t);s=new Pe(i,o,r,n)}else s=t;return this._sample=s,this}where(...t){return this._where=this._where.concat(q(t,Ft)),this}setWhere(...t){return this._where=[],this.where(...t)}groupby(...t){return this._groupby=this._groupby.concat(q(t)),this}setGroupby(...t){return this._groupby=[],this.groupby(...t)}having(...t){return this._having=this._having.concat(q(t,Ft)),this}window(...t){let r=[];return t.flat().forEach(n=>{if(n!=null)for(let s in n)r.push(new Le(yn(s),n[s]))}),this._window=this._window.concat(r),this}qualify(...t){return this._qualify=this._qualify.concat(q(t,Ft)),this}toString(){let{_with:t,_select:r,_distinct:n,_from:s,_sample:o,_where:i,_groupby:c,_having:a,_window:u,_qualify:f,_orderby:p,_limit:h,_offset:m}=this,d=[];if(t.length&&d.push(`WITH ${t.join(", ")}`),d.push(`SELECT${n?" DISTINCT":""} ${r.join(", ")}`),s.length&&d.push(`FROM ${s.join(", ")}`),i.length){let E=i.map(String).filter(F=>F).join(" AND ");E&&d.push(`WHERE ${E}`)}if(o&&d.push(`USING SAMPLE ${o}`),c.length&&d.push(`GROUP BY ${c.join(", ")}`),a.length){let E=a.map(String).filter(F=>F).join(" AND ");E&&d.push(`HAVING ${E}`)}if(u.length&&d.push(`WINDOW ${u.join(", ")}`),f.length){let E=f.map(String).filter(F=>F).join(" AND ");E&&d.push(`QUALIFY ${E}`)}return p.length&&d.push(`ORDER BY ${p.join(", ")}`),Number.isFinite(h)&&d.push(`LIMIT ${h}`),Number.isFinite(m)&&d.push(`OFFSET ${m}`),d.join(" ")}},Ve=class e extends v{constructor(t){super(mn),this.query=t}clone(){return new e(this.query.clone())}toString(){return`DESCRIBE ${this.query}`}},Bt=class e extends w{constructor(t,r){super(xn),this.op=t,this.queries=r}get subqueries(){let{queries:t,cteFor:r}=this;return r&&t.forEach(n=>n.cteFor=r),t}clone(){let{op:t,queries:r,...n}=this;return Object.assign(new e(t,r),n)}toString(){let{op:t,queries:r,_orderby:n,_limit:s,_offset:o}=this,i=[r.join(` ${t} `)];return n.length&&i.push(`ORDER BY ${n.join(", ")}`),Number.isFinite(s)&&i.push(`LIMIT ${s}`),Number.isFinite(o)&&i.push(`OFFSET ${o}`),i.join(" ")}};var We=class extends v{constructor(t,r){super(pn),this.expr=t,this.alias=r}toString(){let{expr:t,alias:r}=this,n=bn(t)?`(${t})`:`${t}`;return r&&!(xt(t)&&t.table.join(".")===r)?`${n} AS ${X(r)}`:`${n}`}};var Qe=class extends x{constructor(t,r){super(on),this.expr=t,this.values=r}toString(){return`(${this.expr} IN (${this.values.join(", ")}))`}};var In=class extends x{constructor(t,r){super(sn),this.op=t,this.clauses=r}toString(){let t=this.clauses;return t.length===0?"":t.length===1?`${t[0]}`:`(${t.join(` ${this.op} `)})`}},Ye=class extends In{constructor(t){super("AND",t)}},ze=class extends In{constructor(t){super("OR",t)}};var Ge=class extends x{constructor(t,r,n){super(Kr),this.expr=t,this.desc=r,this.nullsFirst=n}toString(){let{expr:t,desc:r,nullsFirst:n}=this;return`${t}${r?" DESC":r===!1?" ASC":""}${n?" NULLS FIRST":n===!1?" NULLS LAST":""}`}};var Cs=class extends x{constructor(t,r,n){super(t),this.op=r,this.expr=n}};var He=class extends Cs{constructor(t,r){super(Bo,t,r)}toString(){return`(${this.expr} ${this.op})`}};function _n(e,t){return tt("arg_max",e,t)}function An(e,t){return tt("arg_min",e,t)}function gt(e){return tt("count",e)}function at(e){return tt("max",e)}function Et(e){return tt("min",e)}function Rs(e,t){return tt("regr_avgx",e,t)}function Ds(e,t){return tt("regr_avgy",e,t)}function Ms(e,t){return tt("regr_count",e,t)}function A(e){return tt("sum",e)}function Fs(e,t){return new qe(g(e),t)}function wt(e){return Fs(e,"INTEGER")}function Xe(e){return Fs(e,"DOUBLE")}function Bs(e){return R("epoch_ms",e)}function vn(e){return R("exp",e)}function Us(e){return R("log",e)}function ie(e){return R("ln",e)}function ut(e){return R("sign",e)}function bt(e){return R("abs",e)}function qt(e){return R("sqrt",e)}function qs(e){return R("ceil",e)}function It(e){return R("floor",e)}function Nn(e,t){return R("round",e,t)}function Vo(e,t){return new He(e,g(t))}function ce(e,t,r){return new Ue(e,g(t),g(r))}function ac(e,t,r=!1){let n=r?Be:Fe;return new n(g(e),t?.map(g))}function $t(...e){return new Ye(q(e))}function ae(...e){return new ze(q(e))}function Sn(e){return Vo("IS NULL",e)}function On(e){return Vo("IS NOT NULL",e)}function Pt(e,t){return ce("+",e,t)}function b(e,t){return ce("-",e,t)}function I(e,t){return ce("*",e,t)}function N(e,t){return ce("/",e,t)}function D(e,t){return ce("**",e,t)}function $s(e,t){return ce("IS NOT DISTINCT FROM",e,t)}function ue(e,t){return ac(e,t,!1)}function Tn(e,t){return new Qe(g(e),t.map(g))}function Ps(e,t){return new Ge(g(e),!0,t)}function _t(e,...t){return new $e(uc(e,t))}function uc(e,t){let r=[e[0]],n=t.length;for(let s=0,o=0;s<n;){let i=t[s];Q(i)?r[++o]=i:it(i)?r[++o]=new H(i):r[o]+=Y(i)?i:C(i);let c=e[++s];Q(r[o])?r[++o]=c:r[o]+=c}return r.filter(s=>s).map(s=>Y(s)?new Mt(s):s)}function Ln(e,t,...r){return R(e,t,...gn(r).map(oe))}function ks(e,t,r){return Ln("regexp_matches",e,t,r)}function js(e,t){return Ln("contains",e,t)}function Vs(e,t){return Ln("starts_with",e,t)}function Ws(e,t){return Ln("ends_with",e,t)}var Cn={[Ct]:["args","filter"],[rn]:["expr","extent"],[en]:["left","right"],[vs]:["expr","_when","_else"],[tn]:["expr"],[Zr]:["param","table"],[Jt]:["table"],[mn]:["query"],[Uo]:["node"],[Kt]:["spans"],[pn]:["expr"],[cn]:["args"],[on]:["expr","values"],[sn]:["clauses"],[nn]:["expr","extent"],[Kr]:["expr"],[Ne]:["value"],[fn]:["expr"],[hn]:["_with","_select","_from","_where","_sample","_groupby","_having","_window","_qualify","_orderby"],[xn]:["subqueries","_orderby"],[Ss]:["expr"],[Ns]:["when","then"],[Zt]:["func","def"],[dn]:["def"],[an]:["partition","order","frame"],[un]:["extent"]};function Je(e,t){if(t.has(e))return t.get(e);if(Q(e)){let r=Cn[e.type],n=r?.length??0;for(let s=0;s<n;++s){let o=r[s],i=e[o];if(Array.isArray(i)){let c=i.length;for(let a=0;a<c;++a)i[a]=Je(i[a],t)}else i&&(e[o]=Je(i,t))}}return e}function kt(e,t){if(!Q(e))return;let r=t(e);if(r)return r;let n=Cn[e.type],s=n?.length??0;for(let o=0;o<s;++o){let i=e[n[o]];if(Array.isArray(i)){let c=i.length;for(let a=0;a<c;++a)if(i[a]&&+kt(i[a],t)<0)return r}else if(i&&+kt(i,t)<0)return-1}}var lc=new RegExp(`^(${jo.join("|")})$`),fc=/(\\'|\\"|"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|\w+\()/g;function pc(e){return e.split(fc).some(t=>t.endsWith("(")&&lc.test(t.slice(0,-1)))}function Ze(e){let t=0;return kt(e,r=>{switch(r.type){case Zt:return-1;case Ct:return t|=1,-1;case Kt:case ln:{let n=`${r}`.toLowerCase(),s=n.indexOf("(select ");return s>=0&&(n=n.slice(0,s)),n.includes(") over ")?-1:pc(n)?(t|=2,-1):1}}}),t}function Qs(e){let t=new Set;return kt(e,r=>{r.type===Ct&&t.add(r)}),Array.from(t)}function Rn(e){let t={};return kt(e,r=>{r.type===Jt&&(t[r]=r)}),Object.values(t)}function Dn(e,t,{replace:r=!1,temp:n=!1,view:s=!1}={}){return"CREATE"+(r?" OR REPLACE ":" ")+(n?"TEMP ":"")+(s?"VIEW":"TABLE")+(r?" ":" IF NOT EXISTS ")+e+" AS "+t}var Mn=e=>e;function Qo(){return{apply:Mn,invert:Mn,sqlApply:g,sqlInvert:Mn}}function wc({base:e=null}={}){if(e==null||e===Math.E)return{apply:Math.log,invert:Math.exp,sqlApply:t=>ie(t),sqlInvert:t=>vn(t)};if(e===10)return{apply:Math.log10,invert:t=>Math.pow(10,t),sqlApply:t=>Us(t),sqlInvert:t=>D(10,t)};{let t=+e;return{apply:r=>Math.log(r)/Math.log(t),invert:r=>Math.pow(t,r),sqlApply:r=>N(ie(r),ie(t)),sqlInvert:r=>D(t,r)}}}function bc({constant:e=1}={}){let t=+e;return{apply:r=>Math.sign(r)*Math.log1p(Math.abs(r)),invert:r=>Math.sign(r)*Math.exp(Math.abs(r)-t),sqlApply:r=>(r=g(r),I(ut(r),ie(Pt(t,bt(r))))),sqlInvert:r=>I(ut(r),b(vn(bt(r)),t))}}function Ic(){return{apply:e=>Math.sign(e)*Math.sqrt(Math.abs(e)),invert:e=>Math.sign(e)*e*e,sqlApply:e=>(e=g(e),I(ut(e),qt(bt(e)))),sqlInvert:e=>I(ut(e),D(e,2))}}function _c({exponent:e=1}={}){let t=+e;return{apply:r=>Math.sign(r)*Math.pow(Math.abs(r),t),invert:r=>Math.sign(r)*Math.pow(Math.abs(r),1/t),sqlApply:r=>(r=g(r),I(ut(r),D(bt(r),t))),sqlInvert:r=>I(ut(r),D(bt(r),N(1,t)))}}function Yo(){return{apply:e=>+e,invert:e=>new Date(e),sqlApply:e=>e instanceof Date?C(+e):vc(e)?C(+e.value):Bs(e),sqlInvert:Mn}}var Ac={identity:Qo,linear:Qo,log:wc,symlog:bc,sqrt:Ic,pow:_c,time:Yo,utc:Yo};function Ys(e){let t=Ac[e.type];return t?{...e,...t(e)}:null}function vc(e){return e instanceof Rt&&e.value instanceof Date}function Fn(e){let t=2166136261;for(let r=0,n=e.length;r<n;++r){let s=e.charCodeAt(r),o=s&65280;o&&(t=zo(t^o>>8)),t=zo(t^s&255)}return Nc(t)>>>0}function zo(e){return e+(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24)}function Nc(e){return e+=e<<13,e^=e>>>7,e+=e<<3,e^=e>>>17,e+=e<<5,e&4294967295}function Ho(e,t,r){switch(e.name){case"count":case"sum":return Sc(t,e);case"avg":return Oc(t,e);case"arg_max":return Tc(t,e);case"arg_min":return Lc(t,e);case"variance":case"var_samp":return Bn(t,e,r);case"var_pop":return Bn(t,e,r,!1);case"stddev":case"stddev_samp":return qt(Bn(t,e,r));case"stddev_pop":return qt(Bn(t,e,r,!1));case"covar_samp":return Un(t,e,r);case"covar_pop":return Un(t,e,r,!1);case"corr":return Go(t,e,r);case"regr_count":return le(t,e).expr;case"regr_avgx":return Ko(t,e);case"regr_avgy":return ti(t,e);case"regr_syy":return Gs(t,0,e,r);case"regr_sxx":return Gs(t,1,e,r);case"regr_sxy":return Un(t,e,r,null);case"regr_slope":return ei(t,e,r);case"regr_intercept":return Cc(t,e,r);case"regr_r2":return D(Go(t,e,r),2);case"max":case"min":case"bit_and":case"bit_or":case"bit_xor":case"bool_and":case"bool_or":case"product":{let n=Xo(e);return t[n]=e,_t`${e.name}("${n}")`}default:return null}}function Xo(e){return"pre_"+Fn(`${e}`).toString(16)}function M(e,t,r){let n=r?.filter;n&&(t=t.filter?t.where($t(n,t.filter)):t.where(n));let s=Xo(t);return e[s]=t,s}function Jo(e,t){let r=M(e,gt(t.args[0]),t);return{expr:A(r),name:r}}function Sc(e,t){return A(M(e,t))}function Oc(e,t){let r=M(e,t),{expr:n,name:s}=Jo(e,t);return N(A(I(r,s)),n)}function Tc(e,t){let r=M(e,t),n=M(e,at(t.args[1]),t);return _n(r,n)}function Lc(e,t){let r=M(e,t),n=M(e,Et(t.args[1]),t);return An(r,n)}function Bn(e,t,r,n=!0){let s=t.args[0],{expr:o}=Jo(e,t),i=b(s,r(s)),c=M(e,A(D(i,2)),t),a=M(e,A(i),t),u=n?b(o,1):o;return N(b(A(c),N(D(A(a),2),o)),u)}function Un(e,t,r,n=!0){let{expr:s}=le(e,t),o=Zo(e,t,r),i=Ke(e,1,t,r),c=Ke(e,0,t,r),a=b(o,N(I(i,c),s));return n===null?a:n?N(a,b(s,1)):N(a,s)}function Go(e,t,r){let{expr:n}=le(e,t),s=Zo(e,t,r),o=zs(e,1,t,r),i=zs(e,0,t,r),c=Ke(e,1,t,r),a=Ke(e,0,t,r),u=b(o,N(D(c,2),n)),f=b(i,N(D(a,2),n));return N(b(s,N(I(c,a),n)),qt(I(u,f)))}function le(e,t){let[r,n]=t.args,s=M(e,Ms(r,n),t);return{expr:A(s),name:s}}function Ke(e,t,r,n){let s=r.args,o=s[t],i=s[1-t],c=A(b(o,n(o))).where(On(i));return A(M(e,c,r))}function zs(e,t,r,n){let s=r.args,o=s[t],i=s[1-t],c=A(D(b(o,n(o)),2)).where(On(i));return A(M(e,c,r))}function Zo(e,t,r){let[n,s]=t.args,o=A(I(b(s,r(s)),b(n,r(n))));return A(M(e,o,t))}function Ko(e,t){let[r,n]=t.args,{expr:s,name:o}=le(e,t),i=M(e,Rs(r,n),t);return N(A(I(i,o)),s)}function ti(e,t){let[r,n]=t.args,{expr:s,name:o}=le(e,t),i=M(e,Ds(r,n),t);return N(A(I(i,o)),s)}function Gs(e,t,r,n){let{expr:s}=le(e,r),o=Ke(e,t,r,n),i=zs(e,t,r,n);return b(i,N(D(o,2),s))}function ei(e,t,r){let n=Un(e,t,r,null),s=Gs(e,1,t,r);return N(n,s)}function Cc(e,t,r){let n=Ko(e,t),s=ti(e,t),o=ei(e,t,r);return b(s,I(o,n))}function ri(e){if(!e.filterStable)return null;let t=e.query();if(!yt(t))return null;let r=qn(t,a=>{let u=a._from[0]?.expr;return xt(u)?u.name:u});if(typeof r!="string")return null;let n=new Map,s={},o={},i=[],c=a=>{let u=a.column,f=qn(t,p=>p._select.find(h=>h.alias===u)?.expr);return _t`(SELECT avg(${f??a}) FROM "${r}")`};for(let{alias:a,expr:u}of t._select){if(Ze(u)>1)return null;let f=Qs(u);if(f.length===0)i.push(a),s[a]=u;else{for(let p of f){if(p.isDistinct)return null;let h=Ho(p,s,c);if(!h)return null;n.set(p,h)}o[a]=Je(u,n)}}return n.size?{group:i,preagg:s,output:o}:null}function qn(e,t){let r=e.subqueries;if(yt(e)&&r.length===0)return t(e);let n=qn(r[0],t);for(let s=1;s<r.length;++s){let o=qn(r[s],t);if(o!==void 0&&o!==n)return NaN}return n}var Rc={skip:!0,result:null},$n=class{constructor(t,{schema:r="mosaic",enabled:n=!0}={}){this.entries=new Map,this.active=null,this.mc=t,this._schema=r,this._enabled=n}set enabled(t){this._enabled!==t&&(t||this.clear(),this._enabled=t)}get enabled(){return this._enabled}set schema(t){this._schema!==t&&(this.clear(),this._schema=t)}get schema(){return this._schema}dropSchema(){return this.clear(),this.mc.exec(`DROP SCHEMA IF EXISTS "${this.schema}" CASCADE`)}clear(){this.entries.clear(),this.active=null}request(t,r,n){if(!this.enabled)return null;let{entries:s,mc:o,schema:i}=this,{source:c}=n;if(!c||this.active&&(this.active.source!==c&&this.clear(),this.active?.source===null))return null;let{active:a}=this;if(!a&&(this.active=a=Dc(n),a.source===null))return null;if(s.has(t))return s.get(t);let u=ri(t),f;if(!u)f=null;else if(r.skip(t,n))f=Rc;else{let p=r.remove(c).predicate(t);f=Bc(t.query(p),a,u,i),f.result=o.exec([`CREATE SCHEMA IF NOT EXISTS ${i}`,Dn(f.table,f.create,{temp:!1})]),f.result.catch(h=>o.logger().error(h))}return s.set(t,f),f}};function Dc(e){let{source:t,meta:r}=e,n=e.predicate,s=Rn(n).map(p=>p.column),o,i;if(!r||!s)return{source:null,columns:i,predicate:o};let{type:c,scales:a,bin:u,pixelSize:f=1}=r;if(c==="point")o=p=>p,i=Object.fromEntries(s.map(p=>[`${p}`,g(p)]));else if(c==="interval"&&a){let p=a.map(h=>Fc(h,f,u));p.some(h=>!h)||(p.length===1?(o=h=>h?ue("active0",h.extent.map(p[0])):[],i={active0:p[0](n.expr)}):(o=h=>h?$t(h.clauses.map((m,d)=>ue(`active${d}`,m.extent.map(p[d])))):[],i=Object.fromEntries(n.clauses.map((h,m)=>[`active${m}`,p[m](h.expr)]))))}return{source:i?t:null,columns:i,predicate:o}}var Mc={ceil:qs,round:Nn};function Fc(e,t,r){let{type:n,domain:s,range:o,apply:i,sqlApply:c}=Ys(e);if(!i)return;let a=Mc[`${r}`.toLowerCase()]||It,u=i(Math.min(...s)),f=i(Math.max(...s)),p=(n==="identity"?1:Math.abs(o[1]-o[0])/(f-u))/t,h=p===1?d=>d:d=>I(Xe(p),d),m=u===0?d=>d:d=>b(d,Xe(u));return d=>wt(a(h(m(c(d)))))}function Bc(e,t,r,n){let{group:s,output:o,preagg:i}=r,{columns:c}=t,a=e.setSelect({...i,...c}).groupby(Object.keys(c)),[u]=a.subqueries;if(u){let F=Object.values(c).flatMap(ft=>Rn(ft).map(Vt=>Vt.column));Uc(u,F)}let f=a._having,p=a._orderby;a._having=[],a._orderby=[];let h=a.toString(),m=(Fn(h)>>>0).toString(16),d=`${n}.preagg_${m}`,E=w.select(s,o).from(d).groupby(s).having(f).orderby(p);return new Hs({table:d,create:h,active:t,select:E})}function Uc(e,t){let r=new Set,n=s=>{r.has(s)||(r.add(s),yt(s)&&s._from.length&&s.select(t),s.subqueries.forEach(n))};n(e)}var Hs=class{constructor({table:t,create:r,active:n,select:s}){this.table=t,this.create=r,this.result=null,this.active=n,this.select=s,this.skip=!1}query(t){return this.select.clone().where(this.active.predicate(t))}};function Xs(e){switch(e){case"BIGINT":case"HUGEINT":case"INTEGER":case"SMALLINT":case"TINYINT":case"UBIGINT":case"UINTEGER":case"USMALLINT":case"UTINYINT":case"DOUBLE":case"FLOAT":case"REAL":return"number";case"DATE":case"TIMESTAMP":case"TIMESTAMPTZ":case"TIMESTAMP WITH TIME ZONE":case"TIME":case"TIMESTAMP_NS":return"date";case"BOOLEAN":return"boolean";case"VARCHAR":case"UUID":case"JSON":return"string";case"ARRAY":case"LIST":return"array";case"BLOB":case"STRUCT":case"MAP":case"GEOMETRY":return"object";default:if(e.startsWith("DECIMAL"))return"number";if(e.startsWith("STRUCT")||e.startsWith("MAP"))return"object";if(e.endsWith("]"))return"array";throw new Error(`Unsupported type: ${e}`)}}var qc="count",$c="nulls",Pc="max",kc="min",jc="distinct";var Vc={[qc]:gt,[jc]:e=>gt(e).distinct(),[Pc]:at,[kc]:Et,[$c]:e=>gt().where(Sn(e))};function Wc(e,t,r){return w.from(e).select(Array.from(r,n=>({[n]:Vc[n](t)})))}async function ni(e,t){return t.length===1&&t[0].column==="*"?Yc(e,t[0].table):(await Promise.all(t.map(r=>Qc(e,r)))).filter(r=>r)}async function Qc(e,{table:t,column:r,stats:n}){let s=w.from({source:t}).select({column:r}).groupby(r.aggregate?_t`ALL`:[]),[o]=Array.from(await e.query(w.describe(s))),i={table:t,column:`${r}`,sqlType:o.column_type,type:Xs(o.column_type),nullable:o.null==="YES"};if(!(n?.length||n?.size))return i;let[c]=await e.query(Wc(t,r,n),{persist:!0});return Object.assign(i,c)}async function Yc(e,t){let r=await e.query(`DESCRIBE ${Dt(t)}`);return Array.from(r).map(n=>({table:t,column:n.column_name,sqlType:n.column_type,type:Xs(n.column_type),nullable:n.null==="YES"}))}var At=Object.freeze({pending:Symbol("pending"),ready:Symbol("ready"),error:Symbol("error"),done:Symbol("done")}),jt=class extends Promise{constructor(){let t,r;super((n,s)=>{t=n,r=s}),this._resolve=t,this._reject=r,this._state=At.pending,this._value=void 0}fulfill(t){if(this._value!==void 0){if(t!==void 0)throw Error("Promise is ready and fulfill has a provided value");this._resolve(this._value)}else{if(t===void 0)throw Error("Promise is neither ready nor has provided value");this._resolve(t)}return this._state=At.done,this}ready(t){return this._state=At.ready,this._value=t,this}reject(t){return this._state=At.error,this._reject(t),this}get state(){return this._state}};jt.prototype.constructor=Promise;function Pn(){return{debug(...e){},info(...e){},log(...e){},warn(...e){},error(...e){}}}function zc(e){return(typeof requestAnimationFrame<"u"?requestAnimationFrame:typeof setImmediate<"u"?setImmediate:setTimeout)(e)}function si(e,t){let r=[],n=0;function s(){let o=Gc(r,t);r=[],n=0;for(let i of o)Xc(i,e),Kc(i,t)}return{add(o,i){o.request.type==="arrow"?(n=n||zc(()=>s()),r.push({entry:o,priority:i,index:r.length})):e(o,i)}}}function Gc(e,t){let r=[],n=new Map;for(let s of e){let{entry:{request:o}}=s,i=Hc(o.query,t);if(!n.has(i)){let c=[];r.push(c),n.set(i,c)}n.get(i).push(s)}return r}function Hc(e,t){let r=`${e}`;if(yt(e)&&!t.get(r)){if(e._orderby.length||e._where.length||e._qualify.length||e._having.length)return r;let n=e.clone().setSelect("*"),s=e._groupby;if(s.length){let o={};e._select.forEach(({alias:i,expr:c})=>o[i]=c),n.setGroupby(s.map(i=>se(i)&&o[i.column]||i))}else e._select.some(o=>Ze(o.expr))&&n.setGroupby("ALL");return`${n}`}else return r}function Xc(e,t){if(Jc(e))t({request:{type:"arrow",cache:!1,query:e.query=Zc(e)},result:e.result=new jt});else for(let{entry:r,priority:n}of e)t(r,n)}function Jc(e){if(e.length>1){let t=`${e[0].entry.request.query}`;for(let r=1;r<e.length;++r)if(t!==`${e[r].entry.request.query}`)return!0}return!1}function Zc(e){let t=e.maps=[],r=new Map;for(let o of e){let{query:i}=o.entry.request,c=[];t.push(c);for(let{alias:a,expr:u}of i._select){let f=`${u}`;r.has(f)||r.set(f,[`col${r.size}`,u]);let[p]=r.get(f);c.push([p,a])}}let n=e[0].entry.request.query.clone(),s=n._groupby;if(s.length){let o={};e.maps[0].forEach(([i,c])=>o[c]=i),n.setGroupby(s.map(i=>se(i)&&o[i.column]||i))}return n.setSelect(Array.from(r.values()))}async function Kc(e,t){let{maps:r,query:n,result:s}=e;if(!r)return;let o;try{o=await s}catch(c){for(let{entry:a}of e)a.result.reject(c);return}let i=Ls(n);e.forEach(({entry:c},a)=>{let{request:u,result:f}=c,p=r[a],h=i&&p?ea(o,p):p?ta(o,p):o;u.cache&&t.set(String(u.query),h),f.fulfill(h)})}function ta(e,t){return e.select(t.map(r=>r[0]),t.map(r=>r[1]))}function ea(e,t){let r=new Map(t),n=[];for(let s of e)r.has(s.column_name)&&n.push({...s,column_name:r.get(s.column_name)});return n}var ra=typeof requestIdleCallback<"u"?requestIdleCallback:setTimeout,oi=()=>({get:()=>{},set:(e,t)=>t,clear:()=>{}});function ii({max:e=1e3,ttl:t=3*60*60*1e3}={}){let r=new Map;function n(){let s=performance.now()-t,o=null,i=1/0;for(let[c,a]of r){let{last:u}=a;u<i&&(o=c,i=u),s>u&&r.delete(c)}o&&r.delete(o)}return{get(s){let o=r.get(s);if(o)return o.last=performance.now(),o.value},set(s,o){return r.set(s,{last:performance.now(),value:o}),r.size>e&&ra(n),o},clear(){r=new Map}}}var kn=class{constructor(t){this.queue=Array.from({length:t},()=>({head:null,tail:null}))}isEmpty(){return this.queue.every(t=>!t.head)}insert(t,r){let n=this.queue[r];if(!n)throw new Error(`Invalid queue priority rank: ${r}`);let s={item:t,next:null};n.head===null?n.head=n.tail=s:n.tail=n.tail.next=s}remove(t){for(let r of this.queue){let{head:n,tail:s}=r;for(let o=null,i=n;i;o=i,i=i.next)t(i.item)&&(i===n?n=i.next:o.next=i.next,i===s&&(s=o||n));r.head=n,r.tail=s}}next(){for(let t of this.queue){let{head:r}=t;if(r!==null)return t.head=r.next,t.tail===r&&(t.tail=null),r.item}}};var et=Object.freeze({High:0,Normal:1,Low:2}),jn=class{constructor(t=32){this.queue=new kn(3),this.db=null,this.clientCache=null,this._logger=Pn(),this._logQueries=!1,this._consolidate=null,this.pendingResults=[],this.maxConcurrentRequests=t,this.pendingExec=!1}next(){if(this.queue.isEmpty()||this.pendingResults.length>this.maxConcurrentRequests||this.pendingExec)return;let{request:t,result:r}=this.queue.next();this.pendingResults.push(r),t.type==="exec"&&(this.pendingExec=!0),this.submit(t,r).finally(()=>{for(;this.pendingResults.length&&this.pendingResults[0].state!==At.pending;){let n=this.pendingResults.shift();n.state===At.ready?n.fulfill():n.state===At.done&&this._logger.warn("Found resolved query in pending results.")}t.type==="exec"&&(this.pendingExec=!1),this.next()})}enqueue(t,r=et.Normal){this.queue.insert(t,r),this.next()}async submit(t,r){try{let{query:n,type:s,cache:o=!1,options:i}=t,c=n?`${n}`:null;if(o){let p=this.clientCache.get(c);if(p){let h=await p;this._logger.debug("Cache"),r.ready(h);return}}let a=performance.now();this._logQueries&&this._logger.debug("Query",{type:s,sql:c,...i});let u=this.db.query({type:s,sql:c,...i});o&&this.clientCache.set(c,u);let f=await u;o&&this.clientCache.set(c,f),this._logger.debug(`Request: ${(performance.now()-a).toFixed(1)}`),r.ready(s==="exec"?null:f)}catch(n){r.reject(n)}}cache(t){return t!==void 0?this.clientCache=t===!0?ii():t||oi():this.clientCache}logger(t){return t?this._logger=t:this._logger}logQueries(t){return t!==void 0?this._logQueries=!!t:this._logQueries}connector(t){return t?this.db=t:this.db}consolidate(t){t&&!this._consolidate?this._consolidate=si(this.enqueue.bind(this),this.clientCache):!t&&this._consolidate&&(this._consolidate=null)}request(t,r=et.Normal){let n=new jt,s={request:t,result:n};return this._consolidate?this._consolidate.add(s,r):this.enqueue(s,r),n}cancel(t){let r=new Set(t);if(r.size){this.queue.remove(({result:n})=>r.has(n)?(n.reject("Canceled"),!0):!1);for(let n of this.pendingResults)r.has(n)&&n.reject("Canceled")}}clear(){this.queue.remove(({result:t})=>(t.reject("Cleared"),!0));for(let t of this.pendingResults)t.reject("Cleared");this.pendingResults=[]}};var Vn;function tr(e){return e?Vn=e:Vn==null&&(Vn=new Wn),Vn}var Wn=class{constructor(t=As(),{logger:r=console,manager:n=new jn,cache:s=!0,consolidate:o=!0,preagg:i={}}={}){this.manager=n,this.manager.cache(s),this.manager.consolidate(o),this.databaseConnector(t),this.logger(r),this.clear(),this.preaggregator=new $n(this,i)}clear({clients:t=!0,cache:r=!0}={}){this.manager.clear(),t&&(this.filterGroups?.forEach(n=>n.disconnect()),this.filterGroups=new Map,this.clients?.forEach(n=>this.disconnect(n)),this.clients=new Set),r&&this.manager.cache().clear()}databaseConnector(t){return this.manager.connector(t)}logger(t){return arguments.length&&(this._logger=t||Pn(),this.manager.logger(this._logger)),this._logger}cancel(t){this.manager.cancel(t)}exec(t,{priority:r=et.Normal}={}){return t=Array.isArray(t)?t.filter(n=>n).join(`;
2
+ `):t,this.manager.request({type:"exec",query:t},r)}query(t,{type:r="arrow",cache:n=!0,priority:s=et.Normal,...o}={}){return this.manager.request({type:r,query:t,cache:n,options:o},s)}prefetch(t,r={}){return this.query(t,{...r,cache:!0,priority:et.Low})}createBundle(t,r,n=et.Low){let s={name:t,queries:r.map(o=>typeof o=="string"?{sql:o}:o)};return this.manager.request({type:"create-bundle",options:s},n)}loadBundle(t,r=et.High){let n={name:t};return this.manager.request({type:"load-bundle",options:n},r)}updateClient(t,r,n=et.Normal){return t.queryPending(),this.query(r,{priority:n}).then(s=>t.queryResult(s).update(),s=>{this._logger.error(s),t.queryError(s)}).catch(s=>this._logger.error(s))}requestQuery(t,r){return this.preaggregator.clear(),r?this.updateClient(t,r):Promise.resolve(t.update())}async connect(t){let{clients:r}=this;if(r.has(t))throw new Error("Client already connected.");r.add(t),t.coordinator=this,this.initializeClient(t),na(this,t.filterBy,t)}async initializeClient(t){let r=t.fields();return r?.length&&t.fieldInfo(await ni(this,r)),t.requestQuery()}disconnect(t){let{clients:r,filterGroups:n}=this;if(!r.has(t))return;r.delete(t),t.coordinator=null;let s=n.get(t.filterBy);s&&s.clients.delete(t)}};function na(e,t,r){if(!t)return;let n=e.filterGroups.get(t);if(!n){let s=i=>sa(e,t,i),o=()=>oa(e,t);t.addEventListener("activate",s),t.addEventListener("value",o),n={selection:t,clients:new Set,disconnect(){t.removeEventListener("activate",s),t.removeEventListener("value",o)}},e.filterGroups.set(t,n)}n.clients.add(r)}function sa(e,t,r){let{preaggregator:n,filterGroups:s}=e,{clients:o}=s.get(t);for(let i of o)n.request(i,t,r)}function oa(e,t){let{preaggregator:r,filterGroups:n}=e,{clients:s}=n.get(t),{active:o}=t;return Promise.allSettled(Array.from(s,i=>{let c=r.request(i,t,o),a=c?null:t.predicate(i);if(c?.skip||!c&&!a)return;let u=c?.query(o.predicate)??i.query(a);return e.updateClient(i,u)}))}var Qn=class{constructor(){this._callbacks=new Map}addEventListener(t,r){this._callbacks.has(t)||this._callbacks.set(t,{callbacks:new Set,pending:null,queue:new Js}),this._callbacks.get(t).callbacks.add(r)}removeEventListener(t,r){let n=this._callbacks.get(t);n&&n.callbacks.delete(r)}willEmit(t,r){return r}emitQueueFilter(t,r){return null}cancel(t){this._callbacks.get(t)?.queue.clear()}async pending(t){await this._callbacks.get(t)?.pending}emit(t,r){let n=this._callbacks.get(t)||{};if(n.pending)n.queue.enqueue(r,this.emitQueueFilter(t,r));else{let s=this.willEmit(t,r),{callbacks:o,queue:i}=n;if(o?.size){let c=Array.from(o,a=>a(s));n.pending=Promise.allSettled(c).then(()=>{n.pending=null,i.isEmpty()||this.emit(t,i.dequeue())})}}}},Js=class{constructor(){this.clear()}clear(){this.next=null}isEmpty(){return!this.next}enqueue(t,r){let n={value:t};if(r&&this.next){let s=this;for(;s.next;)r(s.next.value)?s=s.next:s.next=s.next.next;s.next=n}else this.next=n}dequeue(){let{next:t}=this;return this.next=t?.next,t?.value}};function Zs(e,t){return e===t?!1:e instanceof Date&&t instanceof Date?+e!=+t:Array.isArray(e)&&Array.isArray(t)?ia(e,t):!0}function ia(e,t){if(e.length!==t.length)return!0;for(let r=0;r<e.length;++r)if(e[r]!==t[r])return!0;return!1}function k(e){return e instanceof fe}var fe=class e extends Qn{constructor(t){super(),this._value=t}static value(t){return new e(t)}static array(t){if(t.some(r=>k(r))){let r=new e,n=()=>{r.update(t.map(s=>k(s)?s.value:s))};return n(),t.forEach(s=>k(s)?s.addEventListener("value",n):0),r}return new e(t)}get value(){return this._value}update(t,{force:r}={}){return Zs(this._value,t)||r?this.emit("value",t):this.cancel("value"),this}willEmit(t,r){return t==="value"&&(this._value=r),r}};function J(e){return e instanceof er}function Yn(e,t){return new er(new zn(e),t&&[t].flat())}var er=class e extends fe{static intersect({cross:t=!1,empty:r=!1,include:n=[]}={}){return Yn({cross:t,empty:r},n)}static union({cross:t=!1,empty:r=!1,include:n=[]}={}){return Yn({cross:t,empty:r,union:!0},n)}static single({cross:t=!1,empty:r=!1,include:n=[]}={}){return Yn({cross:t,empty:r,single:!0},n)}static crossfilter({empty:t=!1,include:r=[]}={}){return Yn({cross:!0,empty:t},r)}constructor(t=new zn,r=[]){if(super([]),this._resolved=this._value,this._resolver=t,this._relay=new Set,Array.isArray(r))for(let n of r)n._relay.add(this)}clone(){let t=new e(this._resolver);return t._value=t._resolved=this._value,t}remove(t){let r=this.clone();return r._value=r._resolved=r._resolver.resolve(this._resolved,{source:t}),r._value.active={source:t},r}get resolver(){return this._resolver}get single(){return this._resolver.single}get clauses(){return super.value}get active(){return this.clauses.active}get value(){return this.active?.value}valueFor(t){return this.clauses.find(r=>r.source===t)?.value}activate(t){this.emit("activate",t),this._relay.forEach(r=>r.activate(t))}update(t){return this._resolved=this._resolver.resolve(this._resolved,t,!0),this._resolved.active=t,this._relay.forEach(r=>r.update(t)),super.update(this._resolved)}willEmit(t,r){return t==="value"?(this._value=r,this.value):r}emitQueueFilter(t,r){return t==="value"?this._resolver.queueFilter(r):null}skip(t,r){return this._resolver.skip(t,r)}predicate(t,r=!1){let{clauses:n}=this,s=r?null:n.active;return this._resolver.predicate(n,s,t)}},zn=class{constructor({union:t,cross:r,single:n,empty:s}={}){this.union=!!t,this.cross=!!r,this.single=!!n,this.empty=!!s}resolve(t,r,n=!1){let{source:s,predicate:o}=r,i=t.filter(a=>s!==a.source),c=this.single?[]:i;return this.single&&n&&i.forEach(a=>a.source?.reset?.()),o&&c.push(r),c}skip(t,r){return this.cross&&r?.clients?.has(t)}predicate(t,r,n){let{empty:s,union:o}=this;if(s&&!t.length)return[C(!1)];if(this.skip(n,r))return;let i=t.filter(c=>!this.skip(n,c)).map(c=>c.predicate);return o&&i.length>1?ae(i):i}queueFilter(t){if(this.cross){let r=t.active?.source;return n=>n.active?.source!==r}return null}};function pe(e,t,{source:r,clients:n=r?new Set([r]):void 0}){let s=t!==void 0?Tn(e,[C(t)]):null;return{meta:{type:"point"},source:r,clients:n,value:t,predicate:s}}function Ks(e,t,{source:r,clients:n=r?new Set([r]):void 0}){let s=null;if(t){let o=t.length&&e.length===1?[Tn(e[0],t.map(i=>C(i[0])))]:t.map(i=>$t(i.map((c,a)=>$s(e[a],C(c)))));s=t.length===0?C(!1):o.length>1?ae(o):o[0]}return{meta:{type:"point"},source:r,clients:n,value:t,predicate:s}}function to(e,t,{source:r,clients:n=r?new Set([r]):void 0,bin:s,scale:o,pixelSize:i=1}){let c=t!=null?ue(e,t):null;return{meta:{type:"interval",scales:o&&[o],bin:s,pixelSize:i},source:r,clients:n,value:t,predicate:c}}var ca={contains:js,prefix:Vs,suffix:Ws,regexp:ks};function eo(e,t,{source:r,clients:n=void 0,method:s="contains"}){let o=ca[s],i=t?o(e,C(t)):null;return{meta:{type:"match",method:s},source:r,clients:n,value:t,predicate:i}}function ro(e){return typeof e?.getChild=="function"}function no(e){return ro(e)?aa(e):ua(e)}function aa(e){let{numRows:t}=e;return{numRows:t,columns:e.toColumns()}}function ua(e){let t=e.length;if(typeof e[0]=="object"){let r=t?Object.keys(e[0]):[],n={};return r.length>0&&r.forEach(s=>{n[s]=e.map(o=>o[s])}),{numRows:t,columns:n}}else return{numRows:t,values:e}}function vt(e,t){let r=new e(t);return tr().connect(r),r.element}var la=e=>e&&typeof e=="object"&&!Array.isArray(e),fa=e=>vt(Gn,e),Gn=class extends z{constructor({element:t,filterBy:r,from:n,column:s,label:o=s,format:i=p=>p,options:c,value:a,field:u=s,as:f}={}){super(r),this.from=n,this.column=s,this.format=i,this.field=u;let p=this.selection=f;this.element=t??document.createElement("div"),this.element.setAttribute("class","input"),Object.defineProperty(this.element,"value",{value:this});let h=document.createElement("label");if(h.innerText=o||s,this.element.appendChild(h),this.select=document.createElement("select"),this.element.appendChild(this.select),c&&(this.data=c.map(m=>la(m)?m:{value:m}),this.selectedValue(a??""),this.update()),p){let m=!J(p);a!=null&&(!m||p.value===void 0)&&this.publish(a),this.select.addEventListener("input",()=>{this.publish(this.selectedValue()??null)}),m?this.selection.addEventListener("value",d=>{d!==this.select.value&&this.selectedValue(d)}):(this.select.addEventListener("pointerenter",d=>{d.buttons||this.activate()}),this.select.addEventListener("focus",()=>this.activate()))}}selectedValue(t){if(arguments.length===0){let r=this.select.selectedIndex;return this.data[r].value}else{let r=this.data?.findIndex(n=>n.value===t);r>=0?this.select.selectedIndex=r:this.select.value=String(t)}}reset(){this.select.selectedIndex=this.from?0:-1}activate(){this.selection.activate(pe(this.field,0,{source:this}))}publish(t){let{selection:r,field:n}=this;if(J(r)){t===""&&(t=void 0);let s=pe(n,t,{source:this});r.update(s)}else k(r)&&r.update(t)}query(t=[]){let{from:r,column:n}=this;return r?w.from(r).select({value:n}).distinct().where(t).orderby(n):null}queryResult(t){return this.data=[{value:"",label:"All"},...t],this}update(){let{data:t,format:r,select:n,selection:s}=this;n.replaceChildren();for(let{value:o,label:i}of t){let c=document.createElement("option");c.setAttribute("value",o),c.innerText=i??r(o),this.select.appendChild(c)}if(s){let o=J(s)?s.valueFor(this):s.value;this.selectedValue(o??"")}return this}};var pa=0,da=e=>vt(Hn,e),Hn=class extends z{constructor({element:t,filterBy:r,from:n,column:s,label:o,type:i="contains",field:c=s,as:a}={}){if(super(r),this.id="search_"+ ++pa,this.type=i,this.from=n,this.column=s,this.selection=a,this.field=c,this.element=t??document.createElement("div"),this.element.setAttribute("class","input"),Object.defineProperty(this.element,"value",{value:this}),o){let u=document.createElement("label");u.setAttribute("for",this.id),u.innerText=o,this.element.appendChild(u)}this.searchbox=document.createElement("input"),this.searchbox.setAttribute("id",this.id),this.searchbox.setAttribute("type","text"),this.searchbox.setAttribute("placeholder","Query"),this.element.appendChild(this.searchbox),this.selection&&(this.searchbox.addEventListener("input",()=>{this.publish(this.searchbox.value||null)}),J(this.selection)?(this.searchbox.addEventListener("pointerenter",u=>{u.buttons||this.activate()}),this.searchbox.addEventListener("focus",()=>this.activate())):this.selection.addEventListener("value",u=>{u!==this.searchbox.value&&(this.searchbox.value=u)}))}reset(){this.searchbox.value=""}clause(t){let{field:r,type:n}=this;return eo(r,t,{source:this,method:n})}activate(){this.selection.activate(this.clause(""))}publish(t){let{selection:r}=this;J(r)?r.update(this.clause(t)):k(r)&&r.update(t)}query(t=[]){let{from:r,column:n}=this;return r?w.from(r).select({list:n}).distinct().where(t):null}queryResult(t){return this.data=t,this}update(){let t=document.createElement("datalist"),r=`${this.id}_list`;t.setAttribute("id",r);for(let n of this.data){let s=document.createElement("option");s.setAttribute("value",n.list),t.append(s)}return this.datalist&&this.datalist.remove(),this.element.appendChild(this.datalist=t),this.searchbox.setAttribute("list",r),this}};var ha=0,ma=e=>vt(Xn,e),Xn=class extends z{constructor({element:t,filterBy:r,as:n,min:s,max:o,step:i,from:c,column:a,label:u=a,value:f=n?.value,select:p="point",field:h=a,width:m}={}){if(super(r),this.id="slider_"+ ++ha,this.from=c,this.column=a||"value",this.selection=n,this.selectionType=p,this.field=h,this.min=s,this.max=o,this.step=i,this.element=t||document.createElement("div"),this.element.setAttribute("class","input"),Object.defineProperty(this.element,"value",{value:this}),u){let d=document.createElement("label");d.setAttribute("for",this.id),d.innerText=u,this.element.appendChild(d)}this.slider=document.createElement("input"),this.slider.setAttribute("id",this.id),this.slider.setAttribute("type","range"),m!=null&&(this.slider.style.width=`${+m}px`),s!=null&&this.slider.setAttribute("min",`${s}`),o!=null&&this.slider.setAttribute("max",`${o}`),i!=null&&this.slider.setAttribute("step",`${i}`),this.element.appendChild(this.slider),this.curval=document.createElement("label"),this.curval.setAttribute("for",this.id),this.curval.setAttribute("class","value"),this.element.appendChild(this.curval),f!=null&&(this.slider.setAttribute("value",`${f}`),this.selection?.value===void 0&&this.publish(f)),this.curval.innerText=this.slider.value,this.slider.addEventListener("input",()=>{let{value:d}=this.slider;this.curval.innerText=d,this.selection&&this.publish(+d)}),this.selection&&(J(this.selection)?(this.slider.addEventListener("pointerenter",d=>{d.buttons||this.activate()}),this.slider.addEventListener("focus",()=>this.activate())):this.selection.addEventListener("value",d=>{d!==+this.slider.value&&(this.slider.value=d,this.curval.innerText=d)}))}query(t=[]){let{from:r,column:n}=this;return!r||this.min!=null&&this.max!=null?null:w.select({min:Et(n),max:at(n)}).from(r).where(t)}queryResult(t){let{min:r,max:n}=Array.from(t)[0];return this.min==null&&(this.min=r,this.slider.setAttribute("min",`${r}`)),this.max==null&&(this.max=n,this.slider.setAttribute("max",`${n}`)),this.step==null&&(this.step=(n-r)/500,this.slider.setAttribute("step",`${this.step}`)),this}clause(t){let{field:r,selectionType:n}=this;if(n==="interval"){let s=[this.min??0,t];return to(r,s,{source:this,bin:"ceil",scale:{type:"identity",domain:s},pixelSize:this.step})}else return pe(r,t,{source:this})}activate(){this.selection.activate(this.clause(0))}publish(t){let{selection:r}=this;J(r)?r.update(this.clause(t)):k(this.selection)&&r.update(t)}};function Jn(e,t){if(e instanceof Date||(e=new Date(+e)),isNaN(e))return typeof t=="function"?t(e):t;let r=e.getUTCHours(),n=e.getUTCMinutes(),s=e.getUTCSeconds(),o=e.getUTCMilliseconds();return`${xa(e.getUTCFullYear(),4)}-${lt(e.getUTCMonth()+1,2)}-${lt(e.getUTCDate(),2)}${r||n||s||o?`T${lt(r,2)}:${lt(n,2)}${s||o?`:${lt(s,2)}${o?`.${lt(o,3)}`:""}`:""}Z`:""}`}function xa(e){return e<0?`-${lt(-e,6)}`:e>9999?`+${lt(e,6)}`:lt(e,4)}function lt(e,t){return`${e}`.padStart(t,"0")}var so=ci(e=>{let t=Zn(e);return r=>r==null?"":typeof r=="number"?t(r):r instanceof Date?oo(r):`${r}`}),Zn=ci(e=>t=>t===0?"0":t.toLocaleString(e)),EI=so(),wI=Zn();function oo(e){return Jn(e,"Invalid Date")}function ci(e){let t=null,r;return(n="en")=>n===t?r:r=e(t=n)}var ya=-1,ga=e=>vt(Kn,e),Kn=class extends z{constructor({element:t,filterBy:r,from:n,columns:s=["*"],align:o={},format:i,width:c,maxWidth:a,height:u=500,rowBatch:f=100,as:p}={}){super(r),this.id=`table-${++ya}`,this.from=n,this.columns=s,this.format=i,this.align=o,this.widths=typeof c=="object"?c:{},k(n)&&n.addEventListener("value",()=>this.initialize()),this.offset=0,this.limit=+f,this.pending=!1,this.selection=p,this.currentRow=-1,this.sortHeader=null,this.sortColumn=null,this.sortDesc=!1,this.element=t||document.createElement("div"),this.element.setAttribute("id",this.id),Object.defineProperty(this.element,"value",{value:this}),typeof c=="number"&&(this.element.style.width=`${c}px`),a&&(this.element.style.maxWidth=`${a}px`),this.element.style.maxHeight=`${u}px`,this.element.style.overflow="auto";let h=-1;this.element.addEventListener("scroll",m=>{let{pending:d,loaded:E}=this,{scrollHeight:F,scrollTop:ft,clientHeight:Vt}=m.target,rr=ft<h;h=ft,!(rr||d||E)&&F-ft<2*Vt&&(this.pending=!0,this.requestData(this.offset+this.limit))}),this.tbl=document.createElement("table"),this.element.appendChild(this.tbl),this.head=document.createElement("thead"),this.tbl.appendChild(this.head),this.body=document.createElement("tbody"),this.tbl.appendChild(this.body),this.selection&&(this.body.addEventListener("pointerover",m=>{let d=Ea(m.target);d>-1&&d!==this.currentRow&&(this.currentRow=d,this.selection.update(this.clause([d])))}),this.body.addEventListener("pointerleave",()=>{this.currentRow=-1,this.selection.update(this.clause())})),this.style=document.createElement("style"),this.element.appendChild(this.style)}sourceTable(){return k(this.from)?this.from.value:this.from}clause(t=[]){let{data:r,limit:n,schema:s}=this,o=s.map(c=>c.column),i=t.map(c=>{let{columns:a}=r[~~(c/n)];return o.map(u=>a[u][c%n])});return Ks(o,i,{source:this})}requestData(t=0){this.offset=t;let r=this.query(this.filterBy?.predicate(this));this.requestQuery(r),tr().prefetch(r.clone().offset(t+this.limit))}fields(){let t=this.sourceTable();return this.columns.map(r=>Me(r,t))}fieldInfo(t){this.schema=t;let r=this.head;r.innerHTML="";let n=document.createElement("tr");for(let{column:s}of t){let o=document.createElement("th");o.addEventListener("click",i=>this.sort(i,s)),o.appendChild(document.createElement("span")),o.appendChild(document.createTextNode(s)),n.appendChild(o)}return r.appendChild(n),this.formats=wa(this.format,t),this.style.innerText=_a(this.id,ba(this.align,t),Ia(this.widths,t)),this}query(t=[]){let{limit:r,offset:n,schema:s,sortColumn:o,sortDesc:i}=this;return w.from(this.sourceTable()).select(s.map(c=>c.column)).where(t).orderby(o?i?Ps(o):o:[]).limit(r).offset(n)}queryResult(t){return this.pending||(this.loaded=!1,this.data=[],this.body.replaceChildren(),this.offset=0),this.data.push(no(t)),this}update(){let{body:t,formats:r,data:n,schema:s,limit:o}=this,i=s.length,c=n.length-1,a=o*c,{numRows:u,columns:f}=n[c],p=s.map(h=>f[h.column]);for(let h=0;h<u;++h){let m=document.createElement("tr");Object.assign(m,{__row__:a+h});for(let d=0;d<i;++d){let E=p[d][h],F=document.createElement("td");F.innerText=E==null?"":r[d](E),m.appendChild(F)}t.appendChild(m)}return u<o&&(this.loaded=!0),this.pending=!1,this}sort(t,r){r===this.sortColumn?this.sortDesc=!this.sortDesc:(this.sortColumn=r,this.sortDesc=!1);let n=t.currentTarget,s=this.sortHeader;s===n&&t.metaKey?(s.firstChild.textContent="",this.sortHeader=null,this.sortColumn=null):(s&&(s.firstChild.textContent=""),this.sortHeader=n,n.firstChild.textContent=this.sortDesc?"\u25BE":"\u25B4"),this.requestData()}};function Ea(e){let t=e.parentElement;return Object.hasOwn(t,"__row__")?+t.__row__:-1}function wa(e={},t,r){return t.map(({column:n,type:s})=>{if(n in e)return e[n];switch(s){case"number":return Zn(r);case"date":return oo;default:return so(r)}})}function ba(e={},t){return t.map(({column:r,type:n})=>r in e?e[r]:n==="number"?"right":"left")}function Ia(e={},t){return t.map(({column:r})=>e[r])}function _a(e,t,r){let n=[];return t.forEach((s,o)=>{let i=+r[o];if(s!=="left"||i){let c=s!=="left"?`text-align:${s};`:"",a=i?`width:${i}px;max-width:${i}px;`:"";n.push(`#${e} tr>:nth-child(${o+1}) {${c}${a}}`)}}),n.join(" ")}export{Gn as Menu,Hn as Search,Xn as Slider,Kn as Table,fa as menu,da as search,ma as slider,ga as table};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uwdata/mosaic-inputs",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Mosaic input components.",
5
5
  "keywords": [
6
6
  "inputs",
@@ -25,9 +25,9 @@
25
25
  "prepublishOnly": "npm run test && npm run lint && npm run build"
26
26
  },
27
27
  "dependencies": {
28
- "@uwdata/mosaic-core": "^0.12.0",
29
- "@uwdata/mosaic-sql": "^0.12.0",
28
+ "@uwdata/mosaic-core": "^0.12.1",
29
+ "@uwdata/mosaic-sql": "^0.12.1",
30
30
  "isoformat": "^0.2.1"
31
31
  },
32
- "gitHead": "523b1afe2a0880291c92f81e4a7b91829362d285"
32
+ "gitHead": "fe3a7c34352da54ec36a1ebf557846f46a649782"
33
33
  }
package/src/Menu.js CHANGED
@@ -96,6 +96,12 @@ export class Menu extends MosaicClient {
96
96
  this.selectedValue(value);
97
97
  }
98
98
  });
99
+ } else {
100
+ // trigger selection activation
101
+ this.select.addEventListener('pointerenter', evt => {
102
+ if (!evt.buttons) this.activate();
103
+ });
104
+ this.select.addEventListener('focus', () => this.activate());
99
105
  }
100
106
  }
101
107
  }
@@ -118,6 +124,11 @@ export class Menu extends MosaicClient {
118
124
  this.select.selectedIndex = this.from ? 0 : -1;
119
125
  }
120
126
 
127
+ activate() {
128
+ // @ts-ignore - activate is only called for a Selection
129
+ this.selection.activate(clausePoint(this.field, 0, { source: this }));
130
+ }
131
+
121
132
  publish(value) {
122
133
  const { selection, field } = this;
123
134
  if (isSelection(selection)) {
package/src/Search.js CHANGED
@@ -77,6 +77,12 @@ export class Search extends MosaicClient {
77
77
  this.searchbox.value = value;
78
78
  }
79
79
  });
80
+ } else {
81
+ // trigger selection activation
82
+ this.searchbox.addEventListener('pointerenter', evt => {
83
+ if (!evt.buttons) this.activate();
84
+ });
85
+ this.searchbox.addEventListener('focus', () => this.activate());
80
86
  }
81
87
  }
82
88
  }
@@ -85,11 +91,20 @@ export class Search extends MosaicClient {
85
91
  this.searchbox.value = '';
86
92
  }
87
93
 
94
+ clause(value) {
95
+ const { field, type } = this;
96
+ return clauseMatch(field, value, { source: this, method: type });
97
+ }
98
+
99
+ activate() {
100
+ // @ts-ignore - activate is only called for a Selection
101
+ this.selection.activate(this.clause(''));
102
+ }
103
+
88
104
  publish(value) {
89
- const { selection, field, type } = this;
105
+ const { selection } = this;
90
106
  if (isSelection(selection)) {
91
- const clause = clauseMatch(field, value, { source: this, method: type });
92
- selection.update(clause);
107
+ selection.update(this.clause(value));
93
108
  } else if (isParam(selection)) {
94
109
  selection.update(value);
95
110
  }
package/src/Slider.js CHANGED
@@ -102,14 +102,23 @@ export class Slider extends MosaicClient {
102
102
  if (this.selection) this.publish(+value);
103
103
  });
104
104
 
105
- // track param updates
106
- if (this.selection && !isSelection(this.selection)) {
107
- this.selection.addEventListener('value', value => {
108
- if (value !== +this.slider.value) {
109
- this.slider.value = value;
110
- this.curval.innerText = value;
111
- }
112
- });
105
+
106
+ if (this.selection) {
107
+ if (!isSelection(this.selection)) {
108
+ // track param updates
109
+ this.selection.addEventListener('value', value => {
110
+ if (value !== +this.slider.value) {
111
+ this.slider.value = value;
112
+ this.curval.innerText = value;
113
+ }
114
+ });
115
+ } else {
116
+ // trigger selection activation
117
+ this.slider.addEventListener('pointerenter', evt => {
118
+ if (!evt.buttons) this.activate();
119
+ });
120
+ this.slider.addEventListener('focus', () => this.activate());
121
+ }
113
122
  }
114
123
  }
115
124
 
@@ -139,21 +148,31 @@ export class Slider extends MosaicClient {
139
148
  return this;
140
149
  }
141
150
 
151
+ clause(value) {
152
+ const { field, selectionType } = this;
153
+ if (selectionType === 'interval') {
154
+ /** @type {[number, number]} */
155
+ const domain = [this.min ?? 0, value];
156
+ return clauseInterval(field, domain, {
157
+ source: this,
158
+ bin: 'ceil',
159
+ scale: { type: 'identity', domain },
160
+ pixelSize: this.step
161
+ });
162
+ } else {
163
+ return clausePoint(field, value, { source: this });
164
+ }
165
+ }
166
+
167
+ activate() {
168
+ // @ts-ignore - activate is only called for a Selection
169
+ this.selection.activate(this.clause(0));
170
+ }
171
+
142
172
  publish(value) {
143
- const { field, selectionType, selection } = this;
173
+ const { selection } = this;
144
174
  if (isSelection(selection)) {
145
- if (selectionType === 'interval') {
146
- /** @type {[number, number]} */
147
- const domain = [this.min ?? 0, value];
148
- selection.update(clauseInterval(field, domain, {
149
- source: this,
150
- bin: 'ceil',
151
- scale: { type: 'identity', domain },
152
- pixelSize: this.step
153
- }));
154
- } else {
155
- selection.update(clausePoint(field, value, { source: this }));
156
- }
175
+ selection.update(this.clause(value));
157
176
  } else if (isParam(this.selection)) {
158
177
  selection.update(value);
159
178
  }