import{field as R,extend as V,array as D,toNumber as v,error as X,peek as F,hasOwnProperty as L,isDate as P,isArray as M,inrange as y}from"/-/vega-util@v1.17.0-uRskU0IBL2vWCP4Va8OC/dist=es2020,mode=imports,min/optimized/vega-util.js";import{Literal as B}from"/-/vega-expression@v5.0.0-kP0F2avA8xgwhtleXksI/dist=es2020,mode=imports,min/optimized/vega-expression.js";function S(n,t){return n<t?-1:n>t?1:n>=t?0:NaN}function W(n){let t=n,i=n;n.length===1&&(t=(r,u)=>n(r)-u,i=q(n));function e(r,u,s,l){for(s==null&&(s=0),l==null&&(l=r.length);s<l;){const o=s+l>>>1;i(r[o],u)<0?s=o+1:l=o}return s}function c(r,u,s,l){for(s==null&&(s=0),l==null&&(l=r.length);s<l;){const o=s+l>>>1;i(r[o],u)>0?l=o:s=o+1}return s}function f(r,u,s,l){s==null&&(s=0),l==null&&(l=r.length);const o=e(r,u,s,l-1);return o>s&&t(r[o-1],u)>-t(r[o],u)?o-1:o}return{left:e,center:f,right:c}}function q(n){return(t,i)=>S(n(t),i)}const O="intersect",j="union",H="vlMulti",J="vlPoint",z="or",K="and",Q="_vgsid_",Z="E",$="R",b="R-E",ee="R-LE",te="R-RE",N="index:unit";function U(n,t){for(var i=t.fields,e=t.values,c=i.length,f=0,r,u;f<c;++f)if(u=i[f],u.getter=R.getter||R(u.field),r=u.getter(n),P(r)&&(r=v(r)),P(e[f])&&(e[f]=v(e[f])),P(e[f][0])&&(e[f]=e[f].map(v)),u.type===Z){if(M(e[f])?e[f].indexOf(r)<0:r!==e[f])return!1}else if(u.type===$){if(!y(r,e[f]))return!1}else if(u.type===te){if(!y(r,e[f],!0,!1))return!1}else if(u.type===b){if(!y(r,e[f],!1,!1))return!1}else if(u.type===ee&&!y(r,e[f],!1,!0))return!1;return!0}function ne(n,t,i){for(var e=this.context.data[n],c=e?e.values.value:[],f=e?e[N]&&e[N].value:void 0,r=i===O,u=c.length,s=0,l,o,p,g,d;s<u;++s)if(l=c[s],f&&r){if(o=o||{},p=o[g=l.unit]||0,p===-1)continue;if(d=U(t,l),o[g]=d?-1:++p,d&&f.size===1)return!0;if(!d&&p===f.get(g).count)return!1}else if(d=U(t,l),r^d)return d;return u&&r}const T=R(Q),Y=W(T),ie=Y.left,re=Y.right;function fe(n,t,i){const e=this.context.data[n],c=e?e.values.value:[],f=e?e[N]&&e[N].value:void 0,r=i===O,u=T(t),s=ie(c,u);if(s===c.length)return!1;if(T(c[s])!==u)return!1;if(f&&r){if(f.size===1)return!0;if(re(c,u)-s<f.size)return!1}return!0}function ue(n,t){return n.map(i=>V({values:t.fields.map(e=>(e.getter||(e.getter=R(e.field)))(i.datum))},t))}function se(n,t,i,e){for(var c=this.context.data[n],f=c?c.values.value:[],r={},u={},s={},l,o,p,g,d,_,x,k,A,G=f.length,I=0,E,C;I<G;++I){for(l=f[I],g=l.unit,o=l.fields,p=l.values,E=0,C=o.length;E<C;++E)d=o[E],_=r[d.field]||(r[d.field]={}),x=_[g]||(_[g]=[]),s[d.field]=k=d.type.charAt(0),A=w[k+"_union"],_[g]=A(x,D(p[E]));i&&(x=u[g]||(u[g]=[]),x.push(D(p).reduce((m,a,h)=>(m[o[h].field]=a,m),{})))}if(t=t||j,Object.keys(r).forEach(m=>{r[m]=Object.keys(r[m]).map(a=>r[m][a]).reduce((a,h)=>a===void 0?h:w[s[m]+"_"+t](a,h))}),f=Object.keys(u),i&&f.length){const m=e?J:H;r[m]=t===j?{[z]:f.reduce((a,h)=>(a.push(...u[h]),a),[])}:{[K]:f.map(a=>({[z]:u[a]}))}}return r}var w={E_union:function(n,t){if(!n.length)return t;for(var i=0,e=t.length;i<e;++i)n.indexOf(t[i])<0&&n.push(t[i]);return n},E_intersect:function(n,t){return n.length?n.filter(i=>t.indexOf(i)>=0):t},R_union:function(n,t){var i=v(t[0]),e=v(t[1]);return i>e&&(i=t[1],e=t[0]),n.length?(n[0]>i&&(n[0]=i),n[1]<e&&(n[1]=e),n):[i,e]},R_intersect:function(n,t){var i=v(t[0]),e=v(t[1]);return i>e&&(i=t[1],e=t[0]),n.length?e<n[0]||n[1]<i?[]:(n[0]<i&&(n[0]=i),n[1]>e&&(n[1]=e),n):[i,e]}};const le=":",oe="@";function ce(n,t,i,e){t[0].type!==B&&X("First argument to selection functions must be a string literal.");const c=t[0].value,f=t.length>=2&&F(t).value,r="unit",u=oe+r,s=le+c;f===O&&!L(e,u)&&(e[u]=i.getData(c).indataRef(i,r)),L(e,s)||(e[s]=i.getData(c).tuplesRef())}export{fe as selectionIdTest,se as selectionResolve,ne as selectionTest,ue as selectionTuples,ce as selectionVisitor};export default null;
