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