import{array as b,isFunction as E,constant as $,isArray as O,error as R,truthy as K,identity as Z,debounce as mt,visitArray as A,inherits as x,logger as gt,Error as _t,hasOwnProperty as vt,id as z,extend as wt}from"/-/vega-util@v1.17.2-LUfkDhormMyfWqy3Ts6U/dist=es2020,mode=imports,min/optimized/vega-util.js";import{loader as kt,read as yt,responseType as Ft}from"/-/vega-loader@v4.5.2-1ImBl2TigOVzvurACWyz/dist=es2020,mode=imports,min/optimized/vega-loader.js";import{defaultLocale as Dt}from"/-/vega-format@v1.1.2-rBsMjG1MOmb395qvySoI/dist=es2020,mode=imports,min/optimized/vega-format.js";function q(t){const e=t||Z,n=[],i={};return n.add=s=>{const r=e(s);return i[r]||(i[r]=1,n.push(s)),n},n.remove=s=>{const r=e(s);if(i[r]){i[r]=0;const u=n.indexOf(s);u>=0&&n.splice(u,1)}return n},n}async function I(t,e){try{await e(t)}catch(n){t.error(n)}}const tt=Symbol("vega_id");let Pt=1;function Et(t){return!!(t&&d(t))}function d(t){return t[tt]}function et(t,e){return t[tt]=e,t}function W(t){const e=t===Object(t)?t:{data:t};return d(e)?e:et(e,Pt++)}function Ot(t){return nt(t,W({}))}function nt(t,e){for(const n in t)e[n]=t[n];return e}function At(t,e){return et(e,d(t))}function Mt(t,e){return t?e?(n,i)=>t(n,i)||d(e(n))-d(e(i)):(n,i)=>t(n,i)||d(n)-d(i):null}function it(t){return t&&t.constructor===C}function C(){const t=[],e=[],n=[],i=[],s=[];let r=null,u=!1;return{constructor:C,insert(o){const a=b(o),h=a.length;for(let f=0;f{D(m)&&(h[d(m)]=-1)});for(l=0,c=t.length;l0&&(J(_,D,p.value),o.modifies(D));for(l=0,c=s.length;l{D(m)&&h[d(m)]>0&&J(m,p.field,p.value)}),o.modifies(p.field);if(u)o.mod=e.length||i.length?a.filter(m=>h[d(m)]>0):a.slice();else for(P in f)o.mod.push(f[P]);return(r||r==null&&(e.length||i.length))&&o.clean(!0),o}}}const T="_:mod:_";function U(){Object.defineProperty(this,T,{writable:!0,value:{}})}U.prototype={set(t,e,n,i){const s=this,r=s[t],u=s[T];return e!=null&&e>=0?(r[e]!==n||i)&&(r[e]=n,u[e+":"+t]=-1,u[t]=-1):(r!==n||i)&&(s[t]=n,u[t]=O(n)?1+n.length:-1),s},modified(t,e){const n=this[T];if(arguments.length){if(O(t)){for(let i=0;i=0?e+1{p instanceof g?(p!==this&&(e&&p.targets().add(this),r.push(p)),s.push({op:p,name:l,index:c})):i.set(l,c,p)};for(u in t)if(o=t[u],u===St)b(o).forEach(l=>{l instanceof g?l!==this&&(l.targets().add(this),r.push(l)):R("Pulse parameters must be operator instances.")}),this.source=o;else if(O(o))for(i.set(u,-1,Array(a=o.length)),h=0;h{const n=Date.now();return n-e>t?(e=n,1):0})},debounce(t){const e=k();return this.targets().add(k(null,null,mt(t,n=>{const i=n.dataflow;e.receive(n),i&&i.run&&i.run()}))),e},between(t,e){let n=!1;return t.targets().add(k(null,null,()=>n=!0)),e.targets().add(k(null,null,()=>n=!1)),this.filter(()=>n)},detach(){this._filter=K,this._targets=null}};function Tt(t,e,n,i){const s=this,r=k(n,i),u=function(h){h.dataflow=s;try{r.receive(h)}catch(f){s.error(f)}finally{s.run()}};let o;typeof t=="string"&&typeof document!="undefined"?o=document.querySelectorAll(t):o=b(t);const a=o.length;for(let h=0;he=i);return n.requests=0,n.done=()=>{--n.requests===0&&(t._pending=null,e(t))},t._pending=n}const Wt={skip:!0};function Bt(t,e,n,i,s){const r=t instanceof g?Gt:Ht;return r(this,t,e,n,i,s),this}function Ht(t,e,n,i,s,r){const u=wt({},r,Wt);let o,a;E(n)||(n=$(n)),i===void 0?o=h=>t.touch(n(h)):E(i)?(a=new g(null,i,s,!1),o=h=>{a.evaluate(h);const f=n(h),l=a.value;it(l)?t.pulse(f,l,r):t.update(f,l,u)}):o=h=>t.update(n(h),i,u),e.apply(o)}function Gt(t,e,n,i,s,r){if(i===void 0)e.targets().add(n);else{const u=r||{},o=new g(null,Vt(n,i),s,!1);o.modified(u.force),o.rank=e.rank,e.targets().add(o),n&&(o.skip(!0),o.value=n.value,o.targets().add(n),t.connect(n,[o]))}}function Vt(t,e){return e=E(e)?e:$(e),t?function(n,i){const s=e(n,i);return t.skip()||(t.skip(s!==this.value).value=s),s}:e}function Yt(t){t.rank=++this._rank}function Jt(t){const e=[t];let n,i,s;for(;e.length;)if(this.rank(n=e.pop()),i=n._targets)for(s=i.length;--s>=0;)e.push(n=i[s]),n===t&&R("Cycle detected in dataflow graph.")}const j={},v=1<<0,y=1<<1,w=1<<2,Qt=v|y,rt=v|w,M=v|y|w,ot=1<<3,S=1<<4,lt=1<<5,ut=1<<6;function F(t,e,n){this.dataflow=t,this.stamp=e??-1,this.add=[],this.rem=[],this.mod=[],this.fields=null,this.encode=n||null}function H(t,e){const n=[];return A(t,e,i=>n.push(i)),n}function ht(t,e){const n={};return t.visit(e,i=>{n[d(i)]=1}),i=>n[d(i)]?null:i}function N(t,e){return t?(n,i)=>t(n,i)&&e(n,i):e}F.prototype={StopPropagation:j,ADD:v,REM:y,MOD:w,ADD_REM:Qt,ADD_MOD:rt,ALL:M,REFLOW:ot,SOURCE:S,NO_SOURCE:lt,NO_FIELDS:ut,fork(t){return new F(this.dataflow).init(this,t)},clone(){const t=this.fork(M);return t.add=t.add.slice(),t.rem=t.rem.slice(),t.mod=t.mod.slice(),t.source&&(t.source=t.source.slice()),t.materialize(M|S)},addAll(){let t=this;const e=!t.source||t.add===t.rem||!t.rem.length&&t.source.length===t.add.length;return e||(t=new F(this.dataflow).init(this),t.add=t.source,t.rem=[]),t},init(t,e){const n=this;return n.stamp=t.stamp,n.encode=t.encode,t.fields&&!(e&ut)&&(n.fields=t.fields),e&v?(n.addF=t.addF,n.add=t.add):(n.addF=null,n.add=[]),e&y?(n.remF=t.remF,n.rem=t.rem):(n.remF=null,n.rem=[]),e&w?(n.modF=t.modF,n.mod=t.mod):(n.modF=null,n.mod=[]),e<?(n.srcF=null,n.source=null):(n.srcF=t.srcF,n.source=t.source,t.cleans&&(n.cleans=t.cleans)),n},runAfter(t){this.dataflow.runAfter(t)},changed(t){const e=t||M;return e&v&&this.add.length||e&y&&this.rem.length||e&w&&this.mod.length},reflow(t){if(t)return this.fork(M).reflow();const e=this.add.length,n=this.source&&this.source.length;return n&&n!==e&&(this.mod=this.source,e&&this.filter(w,ht(this,v))),this},clean(t){return arguments.length?(this.cleans=!!t,this):this.cleans},modifies(t){const e=this.fields||(this.fields={});return O(t)?t.forEach(n=>e[n]=!0):e[t]=!0,this},modified(t,e){const n=this.fields;return(e||this.mod.length)&&n?arguments.length?O(t)?t.some(i=>n[i]):n[t]:!!n:!1},filter(t,e){const n=this;return t&v&&(n.addF=N(n.addF,e)),t&y&&(n.remF=N(n.remF,e)),t&w&&(n.modF=N(n.modF,e)),t&S&&(n.srcF=N(n.srcF,e)),n},materialize(t){t=t||M;const e=this;return t&v&&e.addF&&(e.add=H(e.add,e.addF),e.addF=null),t&y&&e.remF&&(e.rem=H(e.rem,e.remF),e.remF=null),t&w&&e.modF&&(e.mod=H(e.mod,e.modF),e.modF=null),t&S&&e.srcF&&(e.source=e.source.filter(e.srcF),e.srcF=null),e},visit(t,e){const n=this,i=e;if(t&S)return A(n.source,n.srcF,i),n;t&v&&A(n.add,n.addF,i),t&y&&A(n.rem,n.remF,i),t&w&&A(n.mod,n.modF,i);const s=n.source;if(t&ot&&s){const r=n.add.length+n.mod.length;r===s.length||(r?A(s,ht(n,rt),i):A(s,n.srcF,i))}return n}};function G(t,e,n,i){const s=this;let r=0;this.dataflow=t,this.stamp=e,this.fields=null,this.encode=i||null,this.pulses=n;for(const u of n){if(u.stamp!==e)continue;if(u.fields){const o=s.fields||(s.fields={});for(const a in u.fields)o[a]=1}u.changed(s.ADD)&&(r|=s.ADD),u.changed(s.REM)&&(r|=s.REM),u.changed(s.MOD)&&(r|=s.MOD)}this.changes=r}x(G,F,{fork(t){const e=new F(this.dataflow).init(this,t&this.NO_FIELDS);return t!==void 0&&(t&e.ADD&&this.visit(e.ADD,n=>e.add.push(n)),t&e.REM&&this.visit(e.REM,n=>e.rem.push(n)),t&e.MOD&&this.visit(e.MOD,n=>e.mod.push(n))),e},changed(t){return this.changes&t},modified(t){const e=this,n=e.fields;return n&&e.changes&e.MOD?O(t)?t.some(i=>n[i]):n[t]:0},filter(){R("MultiPulse does not support filtering.")},materialize(){R("MultiPulse does not support materialization.")},visit(t,e){const n=this,i=n.pulses,s=i.length;let r=0;if(t&n.SOURCE)for(;ri._enqueue(f,!0)),i._touched=q(z);let u=0,o,a,h;try{for(;i._heap.size()>0;){if(o=i._heap.pop(),o.rank!==o.qrank){i._enqueue(o,!0);continue}a=o.run(i._getPulse(o,t)),a.then?a=await a:a.async&&(s.push(a.async),a=j),a!==j&&(o._targets&&o._targets.forEach(f=>i._enqueue(f))),++u}}catch(f){i._heap.clear(),h=f}if(i._input={},i._pulse=null,i.debug(`Pulse ${r}: ${u} operators`),h&&(i._postrun=[],i.error(h)),i._postrun.length){const f=i._postrun.sort((l,c)=>c.priority-l.priority);i._postrun=[];for(let l=0;li.runAsync(null,()=>{f.forEach(l=>{try{l(i)}catch(c){i.error(c)}})})),i}async function Zt(t,e,n){for(;this._running;)await this._running;const i=()=>this._running=null;return(this._running=this.evaluate(t,e,n)).then(i,i),this._running}function xt(t,e,n){return this._pulse?at(this):(this.evaluate(t,e,n),this)}function te(t,e,n){if(this._pulse||e)this._postrun.push({priority:n||0,callback:t});else try{t(this)}catch(i){this.error(i)}}function at(t){return t.error("Dataflow already running. Use runAsync() to chain invocations."),t}function ee(t,e){const n=t.stamps.pulse),e):this._input[t.id]||ie(this._pulse,n&&n.pulse)}function ie(t,e){return e&&e.stamp===t.stamp?e:(t=t.fork(),e&&e!==j&&(t.source=e.source),t)}const V={skip:!1,force:!1};function se(t,e){const n=e||V;return this._pulse?this._enqueue(t):this._touched.add(t),n.skip&&t.skip(!0),this}function re(t,e,n){const i=n||V;return(t.set(e)||i.force)&&this.touch(t,i),this}function oe(t,e,n){this.touch(t,n||V);const i=new F(this,this._clock+(this._pulse?0:1)),s=t.pulse&&t.pulse.source||[];return i.target=t,this._input[t.id]=e.pulse(i,s),this}function le(t){let e=[];return{clear:()=>e=[],size:()=>e.length,peek:()=>e[0],push:n=>(e.push(n),ft(e,0,e.length-1,t)),pop:()=>{const n=e.pop();let i;return e.length?(i=e[0],e[0]=n,ue(e,0,t)):i=n,i}}}function ft(t,e,n,i){let s,r;const u=t[n];for(;n>e;){if(r=n-1>>1,s=t[r],i(u,s)<0){t[n]=s,n=r;continue}break}return t[n]=u}function ue(t,e,n){const i=e,s=t.length,r=t[e];let u=(e<<1)+1,o;for(;u=0&&(u=o),t[e]=t[u],e=u,u=(e<<1)+1;return t[e]=r,ft(t,i,e,n)}function ct(){this.logger(gt()),this.logLevel(_t),this._clock=0,this._rank=0,this._locale=Dt();try{this._loader=kt()}catch(t){}this._touched=q(z),this._input={},this._pulse=null,this._heap=le((t,e)=>t.qrank-e.qrank),this._postrun=[]}function L(t){return function(){return this._log[t].apply(this,arguments)}}ct.prototype={stamp(){return this._clock},loader(t){return arguments.length?(this._loader=t,this):this._loader},locale(t){return arguments.length?(this._locale=t,this):this._locale},logger(t){return arguments.length?(this._log=t,this):this._log},error:L("error"),warn:L("warn"),info:L("info"),debug:L("debug"),logLevel:L("level"),cleanThreshold:1e4,add:zt,connect:It,rank:Yt,rerank:Jt,pulse:oe,touch:se,update:re,changeset:C,ingest:jt,parse:Ut,preload:$t,request:Nt,events:Tt,on:Bt,evaluate:Xt,run:xt,runAsync:Zt,runAfter:te,_enqueue:ee,_getPulse:ne};function dt(t,e){g.call(this,t,null,e)}x(dt,g,{run(t){if(t.stampthis.pulse=n):e!==t.StopPropagation&&(this.pulse=e),e},evaluate(t){const e=this.marshall(t.stamp),n=this.transform(e,t);return e.clear(),n},transform(){}});const Y={};function he(t){const e=pt(t);return e&&e.Definition||null}function pt(t){return t=t&&t.toLowerCase(),vt(Y,t)?Y[t]:null}export{ct as Dataflow,B as EventStream,G as MultiPulse,g as Operator,U as Parameters,F as Pulse,dt as Transform,q as UniqueList,I as asyncCallback,C as changeset,he as definition,Ot as derive,W as ingest,it as isChangeSet,Et as isTuple,nt as rederive,At as replace,Mt as stableCompare,pt as transform,Y as transforms,d as tupleid};export default null;