import{toSet as h,stringValue as p,error as d,isArray as w,isObject as m,hasOwnProperty as E,truthy as O,accessor as g,key as j,field as S,array as P,compare as C}from"/-/vega-util@v1.17.2-LUfkDhormMyfWqy3Ts6U/dist=es2020,mode=imports,min/optimized/vega-util.js";import{tupleid as $}from"/-/vega-dataflow@v5.7.6-WDoszrJUyhTwz7sPwzda/dist=es2020,mode=imports,min/optimized/vega-dataflow.js";function z(t){const e=this,r=t.operators||[];return t.background&&(e.background=t.background),t.eventConfig&&(e.eventConfig=t.eventConfig),t.locale&&(e.locale=t.locale),r.forEach(n=>e.parseOperator(n)),r.forEach(n=>e.parseOperatorParameters(n)),(t.streams||[]).forEach(n=>e.parseStream(n)),(t.updates||[]).forEach(n=>e.parseUpdate(n)),e.resolve()}const U=h(["rule"]),v=h(["group","image","rect"]);function D(t,e){let r="";return U[e]||(t.x2&&(t.x?(v[e]&&(r+="if(o.x>o.x2)$=o.x,o.x=o.x2,o.x2=$;"),r+="o.width=o.x2-o.x;"):r+="o.x=o.x2-(o.width||0);"),t.xc&&(r+="o.x=o.xc-(o.width||0)/2;"),t.y2&&(t.y?(v[e]&&(r+="if(o.y>o.y2)$=o.y,o.y=o.y2,o.y2=$;"),r+="o.height=o.y2-o.y;"):r+="o.y=o.y2-(o.height||0);"),t.yc&&(r+="o.y=o.yc-(o.height||0)/2;")),r}function c(t){return(t+"").toLowerCase()}function F(t){return c(t)==="operator"}function I(t){return c(t)==="collect"}function f(t,e,r){r.endsWith(";")||(r="return("+r+");");const n=Function(...e.concat(r));return t&&t.functions?n.bind(t.functions):n}function T(t,e,r,n){return`((u = ${t}) < (v = ${e}) || u == null) && v != null ? ${r} : (u > v || v == null) && u != null ? ${n} : ((v = v instanceof Date ? +v : v), (u = u instanceof Date ? +u : u)) !== u && v === v ? ${r} : v !== v && u === u ? ${n} : `}var q={operator:(t,e)=>f(t,["_"],e.code),parameter:(t,e)=>f(t,["datum","_"],e.code),event:(t,e)=>f(t,["event"],e.code),handler:(t,e)=>{const r=`var datum=event.item&&event.item.datum;return ${e.code};`;return f(t,["_","event"],r)},encode:(t,e)=>{const{marktype:r,channels:n}=e;let o="var o=item,datum=o.datum,m=0,$;";for(const a in n){const s="o["+p(a)+"]";o+=`$=${n[a].code};if(${s}!==$)${s}=$,m=1;`}return o+=D(n,r),o+="return m;",f(t,["item","_"],o)},codegen:{get(t){const e=`[${t.map(p).join("][")}]`,r=Function("_",`return _${e};`);return r.path=e,r},comparator(t,e){let r;const n=(a,s)=>{const i=e[s];let u,l;return a.path?(u=`a${a.path}`,l=`b${a.path}`):((r=r||{})["f"+s]=a,u=`this.f${s}(a)`,l=`this.f${s}(b)`),T(u,l,-i,i)},o=Function("a","b","var u, v; return "+t.map(n).join("")+"0;");return r?o.bind(r):o}}};function W(t){const e=this;F(t.type)||!t.type?e.operator(t,t.update?e.operatorExpression(t.update):null):e.transform(t,t.type)}function A(t){const e=this;if(t.params){const r=e.get(t.id);r||d("Invalid operator id: "+t.id),e.dataflow.connect(r,r.parameters(e.parseParameters(t.params),t.react,t.initonly))}}function J(t,e){e=e||{};const r=this;for(const n in t){const o=t[n];e[n]=w(o)?o.map(a=>x(a,r,e)):x(o,r,e)}return e}function x(t,e,r){if(!t||!m(t))return t;for(let n=0,o=y.length,a;no&&o.$tupleid?$:o);return e.fn[r]||(e.fn[r]=C(n,t.$order,e.expr.codegen))}function V(t,e){const r=t.$encode,n={};for(const o in r){const a=r[o];n[o]=g(e.encodeExpression(a.$expr),a.$fields),n[o].output=a.$output}return n}function B(t,e){return e}function G(t,e){const r=t.$subflow;return function(n,o,a){const s=e.fork().parse(r),i=s.get(r.operators[0].id),u=s.signals.parent;return u&&u.set(a),i.detachSubflow=()=>e.detach(s),i}}function H(){return $}function Q(t){var e=this,r=t.filter!=null?e.eventExpression(t.filter):void 0,n=t.stream!=null?e.get(t.stream):void 0,o;t.source?n=e.events(t.source,t.type,r):t.merge&&(o=t.merge.map(a=>e.get(a)),n=o[0].merge.apply(o[0],o.slice(1))),t.between&&(o=t.between.map(a=>e.get(a)),n=n.between(o[0],o[1])),t.filter&&(n=n.filter(r)),t.throttle!=null&&(n=n.throttle(+t.throttle)),t.debounce!=null&&(n=n.debounce(+t.debounce)),n==null&&d("Invalid stream definition: "+JSON.stringify(t)),t.consume&&n.consume(!0),e.stream(t,n)}function X(t){var e=this,r=m(r=t.source)?r.$ref:r,n=e.get(r),o=null,a=t.update,s=void 0;n||d("Source not defined: "+t.source),o=t.target&&t.target.$expr?e.eventExpression(t.target.$expr):e.get(t.target),a&&a.$expr&&(a.$params&&(s=e.parseParameters(a.$params)),a=e.handlerExpression(a.$expr)),e.update(t,n,o,a,s)}const Y={skip:!0};function Z(t){var e=this,r={};if(t.signals){var n=r.signals={};Object.keys(e.signals).forEach(a=>{const s=e.signals[a];t.signals(a,s)&&(n[a]=s.value)})}if(t.data){var o=r.data={};Object.keys(e.data).forEach(a=>{const s=e.data[a];t.data(a,s)&&(o[a]=s.input.value)})}return e.subcontext&&t.recurse!==!1&&(r.subcontext=e.subcontext.map(a=>a.getState(t))),r}function _(t){var e=this,r=e.dataflow,n=t.data,o=t.signals;Object.keys(o||{}).forEach(a=>{r.update(e.signals[a],o[a],Y)}),Object.keys(n||{}).forEach(a=>{r.pulse(e.data[a].input,r.changeset().remove(O).insert(n[a]))}),(t.subcontext||[]).forEach((a,s)=>{const i=e.subcontext[s];i&&i.setState(a)})}function tt(t,e,r,n){return new b(t,e,r,n)}function b(t,e,r,n){this.dataflow=t,this.transforms=e,this.events=t.events.bind(t),this.expr=n||q,this.signals={},this.scales={},this.nodes={},this.data={},this.fn={},r&&(this.functions=Object.create(r),this.functions.context=this)}function k(t){this.dataflow=t.dataflow,this.transforms=t.transforms,this.events=t.events,this.expr=t.expr,this.signals=Object.create(t.signals),this.scales=Object.create(t.scales),this.nodes=Object.create(t.nodes),this.data=Object.create(t.data),this.fn=Object.create(t.fn),t.functions&&(this.functions=Object.create(t.functions),this.functions.context=this)}b.prototype=k.prototype={fork(){const t=new k(this);return(this.subcontext||(this.subcontext=[])).push(t),t},detach(t){this.subcontext=this.subcontext.filter(r=>r!==t);const e=Object.keys(t.nodes);for(const r of e)t.nodes[r]._targets=null;for(const r of e)t.nodes[r].detach();t.nodes=null},get(t){return this.nodes[t]},set(t,e){return this.nodes[t]=e},add(t,e){const r=this,n=r.dataflow,o=t.value;if(r.set(t.id,e),I(t.type)&&o&&(o.$ingest?n.ingest(e,o.$ingest,o.$format):o.$request?n.preload(e,o.$request,o.$format):n.pulse(e,n.changeset().insert(o))),t.root&&(r.root=e),t.parent){let a=r.get(t.parent.$ref);a?(n.connect(a,[e]),e.targets().add(a)):(r.unresolved=r.unresolved||[]).push(()=>{a=r.get(t.parent.$ref),n.connect(a,[e]),e.targets().add(a)})}if(t.signal&&(r.signals[t.signal]=e),t.scale&&(r.scales[t.scale]=e),t.data)for(const a in t.data){const s=r.data[a]||(r.data[a]={});t.data[a].forEach(i=>s[i]=e)}},resolve(){return(this.unresolved||[]).forEach(t=>t()),delete this.unresolved,this},operator(t,e){this.add(t,this.dataflow.add(t.value,e))},transform(t,e){this.add(t,this.dataflow.add(this.transforms[c(e)]))},stream(t,e){this.set(t.id,e)},update(t,e,r,n,o){this.dataflow.on(e,r,n,o,t.options)},operatorExpression(t){return this.expr.operator(this,t)},parameterExpression(t){return this.expr.parameter(this,t)},eventExpression(t){return this.expr.event(this,t)},handlerExpression(t){return this.expr.handler(this,t)},encodeExpression(t){return this.expr.encode(this,t)},parse:z,parseOperator:W,parseOperatorParameters:A,parseParameters:J,parseStream:Q,parseUpdate:X,getState:Z,setState:_};export{tt as context};export default null;