@tempo-kit/plugin-ticker 3.0.0-rc.0 → 3.0.0

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.
@@ -1 +1 @@
1
- "use strict";var Magma;((Magma||={}).plugins||={}).ticker=(()=>{var V=Object.create;var S=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var K=(c,t)=>()=>{try{return t||c((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},C=(c,t)=>{for(var i in t)S(c,i,{get:t[i],enumerable:!0})},g=(c,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of $(t))!B.call(c,n)&&n!==i&&S(c,n,{get:()=>t[n],enumerable:!(s=F(t,n))||s.enumerable});return c},k=(c,t,i)=>(g(c,t,"default"),i&&g(i,t,"default")),N=(c,t,i)=>(i=c!=null?V(j(c)):{},g(t||!c||!c.__esModule?S(i,"default",{value:c,enumerable:!0}):i,c)),q=c=>g(S({},"__esModule",{value:!0}),c);var R=K((X,M)=>{"use strict";M.exports=window.Magma.pluginSdk});var G={};C(G,{Ticker:()=>A,TickerPlugin:()=>W,default:()=>z,isCronString:()=>e.isCronString});var e={};C(e,{definePlugin:()=>I,defineTerm:()=>U});k(e,N(R()));var v=N(R()),I=c=>(0,v.definePlugin)({...c,version:"3.0.0-rc.0"}),U=c=>(0,v.defineTerm)({...c,version:"3.0.0-rc.0"});var b=new Set,p=Symbol.for("Tempo.ticker.cachedSignal"),Y=Symbol.for("Tempo.ticker.instance"),A={get active(){let c=[];for(let t of b){let i=t.ref.deref();if((0,e.isUndefined)(i)||i.info.stopped)b.delete(t);else{let{label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d}=i.info;c.push({ticker:i,label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d})}}return c}},O=class{#t;#x;#i={};#h;#l;#e;#o;#a;#b=0;#s=!1;#E=!1;#u=!0;#d=!1;#g=!1;#f;#n;#y=new Set;#R=new Set;#I=!1;#T=!1;#k=!1;#O=!1;#P=!1;#S;#p;#m=void 0;#r=void 0;constructor(t,i,s){this.#t=t;let n={},a,o=h=>(0,e.isObject)(h)&&("epoch"in h||"epochMilliseconds"in h||"toZonedDateTimeISO"in h||"getTime"in h),r=h=>(0,e.isObject)(h)&&!o(h);switch(!0){case(0,e.isFunction)(i):a=i;break;case r(i):Object.assign(n,i),(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s);break;default:if((0,e.isNotNullish)(i))if((0,e.isCronString)(i))n.cron=i;else if((0,e.isRRuleString)(i))n.rrule=i;else{let h=Number(i);(0,e.isNumeric)(i)?n.seconds=h:n.seed=i}(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s)}if((0,e.isNotNullish)(n.interval)&&(0,e.isNullish)(n.seconds)&&(0,e.isNullish)(n.cron)&&(0,e.isNullish)(n.rrule)){let h=n.interval;(0,e.isCronString)(h)?n.cron=h:(0,e.isRRuleString)(h)?n.rrule=h:(0,e.isNumeric)(h)?n.seconds=Number(h):n.seed=h}let{label:l,limit:m,until:u,seed:d,rrule:T,cron:f,ntp:x,...y}=n;this.#S=y,this.#x=l,this.#a=m,this.#k=!!x,this.#O=!!(this.#k&&this.#t.ntp?.isCalibrated),T&&(this.#h=(0,e.isString)(T)?T:T.rrule),this.#T=!!(n.catch??this.#t.config?.catch),this.#n=new e.Reactive({tag:this.#x??"Ticker",catch:this.#T}),(0,e.isNotNullish)(f)&&((0,e.isCronString)(f)?this.#l=f:(this.#I=!0,(0,e.logError)(new Error(`Invalid Ticker cron schedule: ${String(f)}`),{...this.#S,catch:this.#T}))),a&&this.#n.on("data",h=>a(h,()=>this.stop()));for(let[h,P]of Object.entries(y))(0,e.isNotNullish)(P)&&(h.startsWith("#")||e.Enum.has(e.enums.DURATIONS,h)||e.Enum.has(e.enums.ELEMENT,h))&&(this.#i[h]=P);let _=(0,e.isNotNullish)(n.seed),D=(0,e.isNotNullish)(this.#h),E=(0,e.isNotNullish)(this.#l),L=!(0,e.isEmpty)(this.#i)||(0,e.isNotNullish)(n.seconds)&&(0,e.isNumber)(n.seconds);(0,e.isNotNullish)(i)&&!r(i)&&!L&&!_&&!D&&!E&&!a&&(0,e.logError)(new Error(`Invalid Ticker interval, seed, cron, or rrule: ${String(i)}`),{...this.#S,catch:this.#T}),this.#o=u?new this.#t(r(u)?void 0:u,r(u)?{...y,...u}:y):void 0,(0,e.isEmpty)(this.#i)&&!D&&!E&&!this.#I&&((0,e.isNotNullish)(d)?this.#a??=1:this.#i.seconds=1),(0,e.normaliseFractionalDurations)(this.#i),(0,e.isNotNullish)(d)?(this.#e=new this.#t(r(d)?void 0:d,r(d)?{...y,...d}:y),this.#P=(!r(d)||(0,e.isNotNullish)(d.epoch))&&this.#e.epoch.ms>(0,e.instant)().epochMilliseconds):this.#k&&(0,e.isFunction)(this.#t.ntp?.now)?this.#e=this.#t.ntp.now(y):this.#e=new this.#t(void 0,y)}bootstrap(t){if(this.#p=new WeakRef(t),this.#m={ref:this.#p,token:Object.create(null)},this.#a===0)return this.stop(),t;if(this.#I)return this.stop(),t;if(!this.#e.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker seed: ${String(this.#e)}`),this.#e.config);else if(this.#o&&!this.#o.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker boundary: ${String(this.#o)}`),this.#e.config);else try{if(this.#l||this.#h)this.#u=!0,this.#d=!1,b.add(this.#m),this.#c();else{let i=Object.entries(this.#i).some(([o,r])=>o.startsWith("#")&&(0,e.isString)(r)&&/^[<>]/.test(r.trim())),s=Object.keys(this.#i).some(o=>!o.startsWith("#"));if(i&&s)throw new Error("Ambiguous Ticker payload: cannot mix directional shorthand terms (e.g. '>') with relative durations (e.g. 'hours'). Use one or the other.");this.#g=i;let n=Object.keys(this.#i).some(o=>o.startsWith("#")),a=this.#g?this.#e.set(this.#i):this.#e.add(this.#i);if(!a.isValid)throw new Error(`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`);this.#u=this.#t.compare(a,this.#e)>=0,this.#d=a.epoch.ns===this.#e.epoch.ns,n&&(this.#e=a),b.add(this.#m),this.#c()}}catch{this.stop();let s=`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`;(0,e.logError)(new Error(s),this.#e.config),queueMicrotask(()=>this.#y.forEach(n=>n(this.#e,()=>this.stop()))),this.#u=!0,this.#d=!1}return t}#D(){let t=this.#k&&!!this.#t.ntp?.isCalibrated;t&&!this.#O&&!this.#P&&this.#b===0&&(0,e.isFunction)(this.#t.ntp?.now)&&(this.#e=this.#t.ntp.now(this.#S),Object.keys(this.#i).some(a=>a.startsWith("#"))&&(this.#e=this.#g?this.#e.set(this.#i):this.#e.add(this.#i)),this.#O=!0);let i=t&&(0,e.isFunction)(this.#t.ntp?.now)?this.#t.ntp.now().epoch.ms:(0,e.instant)().epochMilliseconds,s=Math.round(this.#e.epoch.ms-i);if(s>0)return Math.min(s,2147483647);if(!this.#u){let n=Math.abs(Math.round(this.#e.add(this.#i).epoch.ms-this.#e.epoch.ms));return Math.max(20,Math.min(50,n||1e3))}return 0}#v(){try{return this.pulse()}catch(t){let i=[...this.#y];if(this.stop(),i.forEach(s=>s(this.#e,()=>this.stop())),!this.#T)throw t;return this.#e}}#w(){this.#s||this.#d||(this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},this.#D()))}#c(){if((this.#n.state.subscribers>0||this.#n.state.queued>0)&&!this.#s&&!this.#f){let t=this.#D();t>0?this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},t):(this.#v(),this.#w())}}pulse(){if(this.#s)return new this.#t(null,this.#e.config);let t=this.#e;if(!t.isValid){let s=[...this.#y];return this.stop(),s.forEach(n=>n(t,()=>this.stop())),t}if(this.#l){let s=(0,e.getNextCronEpoch)(this.#l,t.epoch.ms,t.tz);this.#e=new this.#t(s,t.config)}else if(this.#h){let s=(0,e.getNextRRuleEpoch)(this.#h,t.epoch.ms);this.#e=new this.#t(s,t.config)}else this.#e=this.#d?t:this.#g?t.set(this.#i):t.add(this.#i);this.#b++;let i=this.#a!==void 0&&this.#b>=this.#a||(0,e.isNotNullish)(this.#o)&&(this.#u&&this.#t.compare(t,this.#o)>=0||!this.#u&&this.#t.compare(t,this.#o)<=0);return this.#s&&this.#a===0||(this.#n.cast(t),i&&this.stop()),t}on(t,i){return t==="pulse"?(this.#n.on("data",s=>i(s,()=>this.stop())),this.#c()):t==="catch"?this.#y.add(i):t==="stop"&&this.#R.add(i),this}stop(t){if(this.#s)return;this.#s=!0,this.#m&&(b.delete(this.#m),this.#m=void 0),this.#f&&(clearTimeout(this.#f),this.#f=void 0),t!==void 0&&(this.#e=t),this.#n.complete(t);let i=this.#p?.deref();i&&i[p]&&(i[p].dispose?.(),delete i[p]),this.#r&&(this.#r.dispose?.(),this.#r=void 0);let s=[...this.#R];this.#R.clear(),this.#y.clear();for(let n of s)n(this.#e,()=>{})}get[Symbol.toStringTag](){return"Tempo.Ticker"}get info(){return{label:this.#x,next:this.#e,ticks:this.#b,limit:this.#a,interval:{...this.#i},rrule:this.#h,cron:this.#l,stopped:this.#s,ntp:this.#k}}async pull(){let t=await this.next();return t.done?void 0:t.value}until(t){let i=this.#n.until(t);return this.#c(),i}toSignal(...t){let i=this,s=t.length>0?t[0]:this.#e,n=this.#n.toSignal(s);this.#c();let a=!1,o=this.#p?.deref(),r=function(){return n.apply(this,arguments)},l=new Proxy(r,{get(m,u){return u===Y?o:u==="disposed"?a:u==="dispose"||u===Symbol.dispose?()=>{a||(a=!0,o&&o[p]===l&&delete o[p],o=void 0,i.#r===l&&(i.#r=void 0),n.dispose?.())}:u==="get"?()=>n.get():n[u]},apply(m,u,d){return n.apply(u,d)}});return l}get signal(){let t=this.#p?.deref();return t?t.signal:((!this.#r||this.#r.disposed)&&(this.#r=this.toSignal()),this.#r)}async next(){if(this.#s||this.#d)return{done:!0,value:void 0};let t=this.#n.next();this.#E?this.#c():(this.#E=!0,this.#D()>0?this.#c():queueMicrotask(()=>{(!this.#s||this.#n.state.queued>0)&&(this.#v(),this.#w())}));let i=await t;return i.done?{done:!0,value:void 0}:i.value&&i.value.isValid?{done:!1,value:i.value}:{done:!0,value:void 0}}async return(){return this.stop(),{done:!0,value:void 0}}async throw(t){throw this.stop(),t}async[Symbol.asyncDispose](){this.stop()}[Symbol.asyncIterator](){return this.#p?.deref()??this}[Symbol.dispose](){this.stop()}};function w(c,t,i){let s=new O(c,t,i),n=new Proxy((()=>s.stop()),{get:(o,r)=>{if(r==="pulse")return s.pulse.bind(s);if(r==="pull")return s.pull.bind(s);if(r==="until")return s.until.bind(s);if(r==="on")return(l,m)=>(s.on(l,m),n);if(r==="stop")return s.stop.bind(s);if(r==="signal"){let l=o[p];return(!l||l.disposed)&&(l=s.toSignal(),o[p]=l),l}return r===p?o[p]:r==="toSignal"?s.toSignal.bind(s):r==="next"?s.next.bind(s):r==="return"?s.return.bind(s):r==="throw"?s.throw.bind(s):r==="info"?s.info:r===Symbol.asyncIterator?()=>n:r===Symbol.asyncDispose?s[Symbol.asyncDispose].bind(s):r===Symbol.dispose?s[Symbol.dispose].bind(s):s[r]},deleteProperty:(o,r)=>r===p?(delete o[p],!0):Reflect.deleteProperty(o,r),apply:o=>o()}),a=new WeakRef(s);return e.Finalizer.register(n,()=>{a.deref()?.stop()}),s.bootstrap((0,e.cast)(n))}var Z={get:()=>A.active},W=I({name:"ticker",install(c,t){let i=t,s=c||this,n=function(a,o){let r=(0,e.hasKey)(this,"prototype")?this:(0,e.hasKey)(this?.constructor,"prototype")?this.constructor:s,l=i??r?.config?.pluginOptions?.ticker;if(l&&(0,e.isObject)(l)){if((0,e.isUndefined)(a))return w(r,l);if((0,e.isFunction)(a)&&(0,e.isUndefined)(o))return w(r,l,a);if((0,e.isObject)(a)&&!(0,e.isFunction)(a))return w(r,{...l,...a},o)}return w(r,a,o)};n.signal=function(a){let o=n(a),r=o.signal,l=()=>{o.stop(),r.dispose?.()},m=function(){return r()},u=new Proxy(m,{get(T,f){return f==="dispose"||f===Symbol.dispose?l:f==="get"?()=>r.get():r[f]},apply(T,f,x){return r.apply(f,x)}}),d=new WeakRef(o);return e.Finalizer.register(u,()=>{d.deref()?.stop()}),u},(0,e.attachStatics)(s,{ticker:n,tickers:Z})}}),z=W;return q(G);})();
1
+ "use strict";var Magma;((Magma||={}).plugins||={}).ticker=(()=>{var V=Object.create;var S=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var K=(c,t)=>()=>{try{return t||c((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},C=(c,t)=>{for(var i in t)S(c,i,{get:t[i],enumerable:!0})},g=(c,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of $(t))!B.call(c,n)&&n!==i&&S(c,n,{get:()=>t[n],enumerable:!(s=F(t,n))||s.enumerable});return c},k=(c,t,i)=>(g(c,t,"default"),i&&g(i,t,"default")),N=(c,t,i)=>(i=c!=null?V(j(c)):{},g(t||!c||!c.__esModule?S(i,"default",{value:c,enumerable:!0}):i,c)),q=c=>g(S({},"__esModule",{value:!0}),c);var R=K((X,M)=>{"use strict";M.exports=window.Magma.pluginSdk});var G={};C(G,{Ticker:()=>A,TickerPlugin:()=>W,default:()=>z,isCronString:()=>e.isCronString});var e={};C(e,{definePlugin:()=>I,defineTerm:()=>U});k(e,N(R()));var v=N(R()),I=c=>(0,v.definePlugin)({...c,version:"3.0.0"}),U=c=>(0,v.defineTerm)({...c,version:"3.0.0"});var b=new Set,p=Symbol.for("Tempo.ticker.cachedSignal"),Y=Symbol.for("Tempo.ticker.instance"),A={get active(){let c=[];for(let t of b){let i=t.ref.deref();if((0,e.isUndefined)(i)||i.info.stopped)b.delete(t);else{let{label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d}=i.info;c.push({ticker:i,label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d})}}return c}},O=class{#t;#x;#i={};#h;#l;#e;#o;#a;#b=0;#s=!1;#E=!1;#u=!0;#d=!1;#g=!1;#f;#n;#y=new Set;#R=new Set;#I=!1;#T=!1;#k=!1;#O=!1;#P=!1;#S;#p;#m=void 0;#r=void 0;constructor(t,i,s){this.#t=t;let n={},a,o=h=>(0,e.isObject)(h)&&("epoch"in h||"epochMilliseconds"in h||"toZonedDateTimeISO"in h||"getTime"in h),r=h=>(0,e.isObject)(h)&&!o(h);switch(!0){case(0,e.isFunction)(i):a=i;break;case r(i):Object.assign(n,i),(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s);break;default:if((0,e.isNotNullish)(i))if((0,e.isCronString)(i))n.cron=i;else if((0,e.isRRuleString)(i))n.rrule=i;else{let h=Number(i);(0,e.isNumeric)(i)?n.seconds=h:n.seed=i}(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s)}if((0,e.isNotNullish)(n.interval)&&(0,e.isNullish)(n.seconds)&&(0,e.isNullish)(n.cron)&&(0,e.isNullish)(n.rrule)){let h=n.interval;(0,e.isCronString)(h)?n.cron=h:(0,e.isRRuleString)(h)?n.rrule=h:(0,e.isNumeric)(h)?n.seconds=Number(h):n.seed=h}let{label:l,limit:m,until:u,seed:d,rrule:T,cron:f,ntp:x,...y}=n;this.#S=y,this.#x=l,this.#a=m,this.#k=!!x,this.#O=!!(this.#k&&this.#t.ntp?.isCalibrated),T&&(this.#h=(0,e.isString)(T)?T:T.rrule),this.#T=!!(n.catch??this.#t.config?.catch),this.#n=new e.Reactive({tag:this.#x??"Ticker",catch:this.#T}),(0,e.isNotNullish)(f)&&((0,e.isCronString)(f)?this.#l=f:(this.#I=!0,(0,e.logError)(new Error(`Invalid Ticker cron schedule: ${String(f)}`),{...this.#S,catch:this.#T}))),a&&this.#n.on("data",h=>a(h,()=>this.stop()));for(let[h,P]of Object.entries(y))(0,e.isNotNullish)(P)&&(h.startsWith("#")||e.Enum.has(e.enums.DURATIONS,h)||e.Enum.has(e.enums.ELEMENT,h))&&(this.#i[h]=P);let _=(0,e.isNotNullish)(n.seed),D=(0,e.isNotNullish)(this.#h),E=(0,e.isNotNullish)(this.#l),L=!(0,e.isEmpty)(this.#i)||(0,e.isNotNullish)(n.seconds)&&(0,e.isNumber)(n.seconds);(0,e.isNotNullish)(i)&&!r(i)&&!L&&!_&&!D&&!E&&!a&&(0,e.logError)(new Error(`Invalid Ticker interval, seed, cron, or rrule: ${String(i)}`),{...this.#S,catch:this.#T}),this.#o=u?new this.#t(r(u)?void 0:u,r(u)?{...y,...u}:y):void 0,(0,e.isEmpty)(this.#i)&&!D&&!E&&!this.#I&&((0,e.isNotNullish)(d)?this.#a??=1:this.#i.seconds=1),(0,e.normaliseFractionalDurations)(this.#i),(0,e.isNotNullish)(d)?(this.#e=new this.#t(r(d)?void 0:d,r(d)?{...y,...d}:y),this.#P=(!r(d)||(0,e.isNotNullish)(d.epoch))&&this.#e.epoch.ms>(0,e.instant)().epochMilliseconds):this.#k&&(0,e.isFunction)(this.#t.ntp?.now)?this.#e=this.#t.ntp.now(y):this.#e=new this.#t(void 0,y)}bootstrap(t){if(this.#p=new WeakRef(t),this.#m={ref:this.#p,token:Object.create(null)},this.#a===0)return this.stop(),t;if(this.#I)return this.stop(),t;if(!this.#e.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker seed: ${String(this.#e)}`),this.#e.config);else if(this.#o&&!this.#o.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker boundary: ${String(this.#o)}`),this.#e.config);else try{if(this.#l||this.#h)this.#u=!0,this.#d=!1,b.add(this.#m),this.#c();else{let i=Object.entries(this.#i).some(([o,r])=>o.startsWith("#")&&(0,e.isString)(r)&&/^[<>]/.test(r.trim())),s=Object.keys(this.#i).some(o=>!o.startsWith("#"));if(i&&s)throw new Error("Ambiguous Ticker payload: cannot mix directional shorthand terms (e.g. '>') with relative durations (e.g. 'hours'). Use one or the other.");this.#g=i;let n=Object.keys(this.#i).some(o=>o.startsWith("#")),a=this.#g?this.#e.set(this.#i):this.#e.add(this.#i);if(!a.isValid)throw new Error(`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`);this.#u=this.#t.compare(a,this.#e)>=0,this.#d=a.epoch.ns===this.#e.epoch.ns,n&&(this.#e=a),b.add(this.#m),this.#c()}}catch{this.stop();let s=`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`;(0,e.logError)(new Error(s),this.#e.config),queueMicrotask(()=>this.#y.forEach(n=>n(this.#e,()=>this.stop()))),this.#u=!0,this.#d=!1}return t}#D(){let t=this.#k&&!!this.#t.ntp?.isCalibrated;t&&!this.#O&&!this.#P&&this.#b===0&&(0,e.isFunction)(this.#t.ntp?.now)&&(this.#e=this.#t.ntp.now(this.#S),Object.keys(this.#i).some(a=>a.startsWith("#"))&&(this.#e=this.#g?this.#e.set(this.#i):this.#e.add(this.#i)),this.#O=!0);let i=t&&(0,e.isFunction)(this.#t.ntp?.now)?this.#t.ntp.now().epoch.ms:(0,e.instant)().epochMilliseconds,s=Math.round(this.#e.epoch.ms-i);if(s>0)return Math.min(s,2147483647);if(!this.#u){let n=Math.abs(Math.round(this.#e.add(this.#i).epoch.ms-this.#e.epoch.ms));return Math.max(20,Math.min(50,n||1e3))}return 0}#v(){try{return this.pulse()}catch(t){let i=[...this.#y];if(this.stop(),i.forEach(s=>s(this.#e,()=>this.stop())),!this.#T)throw t;return this.#e}}#w(){this.#s||this.#d||(this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},this.#D()))}#c(){if((this.#n.state.subscribers>0||this.#n.state.queued>0)&&!this.#s&&!this.#f){let t=this.#D();t>0?this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},t):(this.#v(),this.#w())}}pulse(){if(this.#s)return new this.#t(null,this.#e.config);let t=this.#e;if(!t.isValid){let s=[...this.#y];return this.stop(),s.forEach(n=>n(t,()=>this.stop())),t}if(this.#l){let s=(0,e.getNextCronEpoch)(this.#l,t.epoch.ms,t.tz);this.#e=new this.#t(s,t.config)}else if(this.#h){let s=(0,e.getNextRRuleEpoch)(this.#h,t.epoch.ms);this.#e=new this.#t(s,t.config)}else this.#e=this.#d?t:this.#g?t.set(this.#i):t.add(this.#i);this.#b++;let i=this.#a!==void 0&&this.#b>=this.#a||(0,e.isNotNullish)(this.#o)&&(this.#u&&this.#t.compare(t,this.#o)>=0||!this.#u&&this.#t.compare(t,this.#o)<=0);return this.#s&&this.#a===0||(this.#n.cast(t),i&&this.stop()),t}on(t,i){return t==="pulse"?(this.#n.on("data",s=>i(s,()=>this.stop())),this.#c()):t==="catch"?this.#y.add(i):t==="stop"&&this.#R.add(i),this}stop(t){if(this.#s)return;this.#s=!0,this.#m&&(b.delete(this.#m),this.#m=void 0),this.#f&&(clearTimeout(this.#f),this.#f=void 0),t!==void 0&&(this.#e=t),this.#n.complete(t);let i=this.#p?.deref();i&&i[p]&&(i[p].dispose?.(),delete i[p]),this.#r&&(this.#r.dispose?.(),this.#r=void 0);let s=[...this.#R];this.#R.clear(),this.#y.clear();for(let n of s)n(this.#e,()=>{})}get[Symbol.toStringTag](){return"Tempo.Ticker"}get info(){return{label:this.#x,next:this.#e,ticks:this.#b,limit:this.#a,interval:{...this.#i},rrule:this.#h,cron:this.#l,stopped:this.#s,ntp:this.#k}}async pull(){let t=await this.next();return t.done?void 0:t.value}until(t){let i=this.#n.until(t);return this.#c(),i}toSignal(...t){let i=this,s=t.length>0?t[0]:this.#e,n=this.#n.toSignal(s);this.#c();let a=!1,o=this.#p?.deref(),r=function(){return n.apply(this,arguments)},l=new Proxy(r,{get(m,u){return u===Y?o:u==="disposed"?a:u==="dispose"||u===Symbol.dispose?()=>{a||(a=!0,o&&o[p]===l&&delete o[p],o=void 0,i.#r===l&&(i.#r=void 0),n.dispose?.())}:u==="get"?()=>n.get():n[u]},apply(m,u,d){return n.apply(u,d)}});return l}get signal(){let t=this.#p?.deref();return t?t.signal:((!this.#r||this.#r.disposed)&&(this.#r=this.toSignal()),this.#r)}async next(){if(this.#s||this.#d)return{done:!0,value:void 0};let t=this.#n.next();this.#E?this.#c():(this.#E=!0,this.#D()>0?this.#c():queueMicrotask(()=>{(!this.#s||this.#n.state.queued>0)&&(this.#v(),this.#w())}));let i=await t;return i.done?{done:!0,value:void 0}:i.value&&i.value.isValid?{done:!1,value:i.value}:{done:!0,value:void 0}}async return(){return this.stop(),{done:!0,value:void 0}}async throw(t){throw this.stop(),t}async[Symbol.asyncDispose](){this.stop()}[Symbol.asyncIterator](){return this.#p?.deref()??this}[Symbol.dispose](){this.stop()}};function w(c,t,i){let s=new O(c,t,i),n=new Proxy((()=>s.stop()),{get:(o,r)=>{if(r==="pulse")return s.pulse.bind(s);if(r==="pull")return s.pull.bind(s);if(r==="until")return s.until.bind(s);if(r==="on")return(l,m)=>(s.on(l,m),n);if(r==="stop")return s.stop.bind(s);if(r==="signal"){let l=o[p];return(!l||l.disposed)&&(l=s.toSignal(),o[p]=l),l}return r===p?o[p]:r==="toSignal"?s.toSignal.bind(s):r==="next"?s.next.bind(s):r==="return"?s.return.bind(s):r==="throw"?s.throw.bind(s):r==="info"?s.info:r===Symbol.asyncIterator?()=>n:r===Symbol.asyncDispose?s[Symbol.asyncDispose].bind(s):r===Symbol.dispose?s[Symbol.dispose].bind(s):s[r]},deleteProperty:(o,r)=>r===p?(delete o[p],!0):Reflect.deleteProperty(o,r),apply:o=>o()}),a=new WeakRef(s);return e.Finalizer.register(n,()=>{a.deref()?.stop()}),s.bootstrap((0,e.cast)(n))}var Z={get:()=>A.active},W=I({name:"ticker",install(c,t){let i=t,s=c||this,n=function(a,o){let r=(0,e.hasKey)(this,"prototype")?this:(0,e.hasKey)(this?.constructor,"prototype")?this.constructor:s,l=i??r?.config?.pluginOptions?.ticker;if(l&&(0,e.isObject)(l)){if((0,e.isUndefined)(a))return w(r,l);if((0,e.isFunction)(a)&&(0,e.isUndefined)(o))return w(r,l,a);if((0,e.isObject)(a)&&!(0,e.isFunction)(a))return w(r,{...l,...a},o)}return w(r,a,o)};n.signal=function(a){let o=n(a),r=o.signal,l=()=>{o.stop(),r.dispose?.()},m=function(){return r()},u=new Proxy(m,{get(T,f){return f==="dispose"||f===Symbol.dispose?l:f==="get"?()=>r.get():r[f]},apply(T,f,x){return r.apply(f,x)}}),d=new WeakRef(o);return e.Finalizer.register(u,()=>{d.deref()?.stop()}),u},(0,e.attachStatics)(s,{ticker:n,tickers:Z})}}),z=W;return q(G);})();
package/dist/index.js CHANGED
@@ -25,8 +25,8 @@ __export(sdk_exports, {
25
25
  __reExport(sdk_exports, sdk_star);
26
26
  import * as sdk_star from "tempo-kit/plugin/sdk";
27
27
  import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
28
- var definePlugin = (config) => originalPlugin({ ...config, version: "3.0.0-rc.0" });
29
- var defineTerm = (config) => originalTerm({ ...config, version: "3.0.0-rc.0" });
28
+ var definePlugin = (config) => originalPlugin({ ...config, version: "3.0.0" });
29
+ var defineTerm = (config) => originalTerm({ ...config, version: "3.0.0" });
30
30
 
31
31
  // src/index.ts
32
32
  var ACTIVE_TICKERS = /* @__PURE__ */ new Set();
@@ -1 +1 @@
1
- "use strict";var Magma;((Magma||={}).plugins||={}).ticker=(()=>{var F=Object.create;var v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var q=(c,t)=>()=>{try{return t||c((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},N=(c,t)=>{for(var i in t)v(c,i,{get:t[i],enumerable:!0})},S=(c,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!K.call(c,n)&&n!==i&&v(c,n,{get:()=>t[n],enumerable:!(s=$(t,n))||s.enumerable});return c},k=(c,t,i)=>(S(c,t,"default"),i&&S(i,t,"default")),M=(c,t,i)=>(i=c!=null?F(B(c)):{},S(t||!c||!c.__esModule?v(i,"default",{value:c,enumerable:!0}):i,c)),U=c=>S(v({},"__esModule",{value:!0}),c);var R=q((X,A)=>{"use strict";A.exports=window.Magma.pluginSdk});var G={};N(G,{Ticker:()=>W,TickerPlugin:()=>g,default:()=>_,isCronString:()=>e.isCronString});var e={};N(e,{definePlugin:()=>O,defineTerm:()=>Y});k(e,M(R()));var w=M(R()),O=c=>(0,w.definePlugin)({...c,version:"3.0.0-rc.0"}),Y=c=>(0,w.defineTerm)({...c,version:"3.0.0-rc.0"});var b=new Set,p=Symbol.for("Tempo.ticker.cachedSignal"),Z=Symbol.for("Tempo.ticker.instance"),W={get active(){let c=[];for(let t of b){let i=t.ref.deref();if((0,e.isUndefined)(i)||i.info.stopped)b.delete(t);else{let{label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d}=i.info;c.push({ticker:i,label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d})}}return c}},D=class{#t;#x;#i={};#h;#l;#e;#o;#a;#b=0;#s=!1;#E=!1;#u=!0;#d=!1;#g=!1;#f;#n;#y=new Set;#I=new Set;#R=!1;#T=!1;#k=!1;#O=!1;#P=!1;#S;#p;#m=void 0;#r=void 0;constructor(t,i,s){this.#t=t;let n={},a,o=h=>(0,e.isObject)(h)&&("epoch"in h||"epochMilliseconds"in h||"toZonedDateTimeISO"in h||"getTime"in h),r=h=>(0,e.isObject)(h)&&!o(h);switch(!0){case(0,e.isFunction)(i):a=i;break;case r(i):Object.assign(n,i),(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s);break;default:if((0,e.isNotNullish)(i))if((0,e.isCronString)(i))n.cron=i;else if((0,e.isRRuleString)(i))n.rrule=i;else{let h=Number(i);(0,e.isNumeric)(i)?n.seconds=h:n.seed=i}(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s)}if((0,e.isNotNullish)(n.interval)&&(0,e.isNullish)(n.seconds)&&(0,e.isNullish)(n.cron)&&(0,e.isNullish)(n.rrule)){let h=n.interval;(0,e.isCronString)(h)?n.cron=h:(0,e.isRRuleString)(h)?n.rrule=h:(0,e.isNumeric)(h)?n.seconds=Number(h):n.seed=h}let{label:l,limit:m,until:u,seed:d,rrule:T,cron:f,ntp:I,...y}=n;this.#S=y,this.#x=l,this.#a=m,this.#k=!!I,this.#O=!!(this.#k&&this.#t.ntp?.isCalibrated),T&&(this.#h=(0,e.isString)(T)?T:T.rrule),this.#T=!!(n.catch??this.#t.config?.catch),this.#n=new e.Reactive({tag:this.#x??"Ticker",catch:this.#T}),(0,e.isNotNullish)(f)&&((0,e.isCronString)(f)?this.#l=f:(this.#R=!0,(0,e.logError)(new Error(`Invalid Ticker cron schedule: ${String(f)}`),{...this.#S,catch:this.#T}))),a&&this.#n.on("data",h=>a(h,()=>this.stop()));for(let[h,C]of Object.entries(y))(0,e.isNotNullish)(C)&&(h.startsWith("#")||e.Enum.has(e.enums.DURATIONS,h)||e.Enum.has(e.enums.ELEMENT,h))&&(this.#i[h]=C);let L=(0,e.isNotNullish)(n.seed),E=(0,e.isNotNullish)(this.#h),P=(0,e.isNotNullish)(this.#l),V=!(0,e.isEmpty)(this.#i)||(0,e.isNotNullish)(n.seconds)&&(0,e.isNumber)(n.seconds);(0,e.isNotNullish)(i)&&!r(i)&&!V&&!L&&!E&&!P&&!a&&(0,e.logError)(new Error(`Invalid Ticker interval, seed, cron, or rrule: ${String(i)}`),{...this.#S,catch:this.#T}),this.#o=u?new this.#t(r(u)?void 0:u,r(u)?{...y,...u}:y):void 0,(0,e.isEmpty)(this.#i)&&!E&&!P&&!this.#R&&((0,e.isNotNullish)(d)?this.#a??=1:this.#i.seconds=1),(0,e.normaliseFractionalDurations)(this.#i),(0,e.isNotNullish)(d)?(this.#e=new this.#t(r(d)?void 0:d,r(d)?{...y,...d}:y),this.#P=(!r(d)||(0,e.isNotNullish)(d.epoch))&&this.#e.epoch.ms>(0,e.instant)().epochMilliseconds):this.#k&&(0,e.isFunction)(this.#t.ntp?.now)?this.#e=this.#t.ntp.now(y):this.#e=new this.#t(void 0,y)}bootstrap(t){if(this.#p=new WeakRef(t),this.#m={ref:this.#p,token:Object.create(null)},this.#a===0)return this.stop(),t;if(this.#R)return this.stop(),t;if(!this.#e.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker seed: ${String(this.#e)}`),this.#e.config);else if(this.#o&&!this.#o.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker boundary: ${String(this.#o)}`),this.#e.config);else try{if(this.#l||this.#h)this.#u=!0,this.#d=!1,b.add(this.#m),this.#c();else{let i=Object.entries(this.#i).some(([o,r])=>o.startsWith("#")&&(0,e.isString)(r)&&/^[<>]/.test(r.trim())),s=Object.keys(this.#i).some(o=>!o.startsWith("#"));if(i&&s)throw new Error("Ambiguous Ticker payload: cannot mix directional shorthand terms (e.g. '>') with relative durations (e.g. 'hours'). Use one or the other.");this.#g=i;let n=Object.keys(this.#i).some(o=>o.startsWith("#")),a=this.#g?this.#e.set(this.#i):this.#e.add(this.#i);if(!a.isValid)throw new Error(`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`);this.#u=this.#t.compare(a,this.#e)>=0,this.#d=a.epoch.ns===this.#e.epoch.ns,n&&(this.#e=a),b.add(this.#m),this.#c()}}catch{this.stop();let s=`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`;(0,e.logError)(new Error(s),this.#e.config),queueMicrotask(()=>this.#y.forEach(n=>n(this.#e,()=>this.stop()))),this.#u=!0,this.#d=!1}return t}#D(){let t=this.#k&&!!this.#t.ntp?.isCalibrated;t&&!this.#O&&!this.#P&&this.#b===0&&(0,e.isFunction)(this.#t.ntp?.now)&&(this.#e=this.#t.ntp.now(this.#S),Object.keys(this.#i).some(a=>a.startsWith("#"))&&(this.#e=this.#g?this.#e.set(this.#i):this.#e.add(this.#i)),this.#O=!0);let i=t&&(0,e.isFunction)(this.#t.ntp?.now)?this.#t.ntp.now().epoch.ms:(0,e.instant)().epochMilliseconds,s=Math.round(this.#e.epoch.ms-i);if(s>0)return Math.min(s,2147483647);if(!this.#u){let n=Math.abs(Math.round(this.#e.add(this.#i).epoch.ms-this.#e.epoch.ms));return Math.max(20,Math.min(50,n||1e3))}return 0}#v(){try{return this.pulse()}catch(t){let i=[...this.#y];if(this.stop(),i.forEach(s=>s(this.#e,()=>this.stop())),!this.#T)throw t;return this.#e}}#w(){this.#s||this.#d||(this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},this.#D()))}#c(){if((this.#n.state.subscribers>0||this.#n.state.queued>0)&&!this.#s&&!this.#f){let t=this.#D();t>0?this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},t):(this.#v(),this.#w())}}pulse(){if(this.#s)return new this.#t(null,this.#e.config);let t=this.#e;if(!t.isValid){let s=[...this.#y];return this.stop(),s.forEach(n=>n(t,()=>this.stop())),t}if(this.#l){let s=(0,e.getNextCronEpoch)(this.#l,t.epoch.ms,t.tz);this.#e=new this.#t(s,t.config)}else if(this.#h){let s=(0,e.getNextRRuleEpoch)(this.#h,t.epoch.ms);this.#e=new this.#t(s,t.config)}else this.#e=this.#d?t:this.#g?t.set(this.#i):t.add(this.#i);this.#b++;let i=this.#a!==void 0&&this.#b>=this.#a||(0,e.isNotNullish)(this.#o)&&(this.#u&&this.#t.compare(t,this.#o)>=0||!this.#u&&this.#t.compare(t,this.#o)<=0);return this.#s&&this.#a===0||(this.#n.cast(t),i&&this.stop()),t}on(t,i){return t==="pulse"?(this.#n.on("data",s=>i(s,()=>this.stop())),this.#c()):t==="catch"?this.#y.add(i):t==="stop"&&this.#I.add(i),this}stop(t){if(this.#s)return;this.#s=!0,this.#m&&(b.delete(this.#m),this.#m=void 0),this.#f&&(clearTimeout(this.#f),this.#f=void 0),t!==void 0&&(this.#e=t),this.#n.complete(t);let i=this.#p?.deref();i&&i[p]&&(i[p].dispose?.(),delete i[p]),this.#r&&(this.#r.dispose?.(),this.#r=void 0);let s=[...this.#I];this.#I.clear(),this.#y.clear();for(let n of s)n(this.#e,()=>{})}get[Symbol.toStringTag](){return"Tempo.Ticker"}get info(){return{label:this.#x,next:this.#e,ticks:this.#b,limit:this.#a,interval:{...this.#i},rrule:this.#h,cron:this.#l,stopped:this.#s,ntp:this.#k}}async pull(){let t=await this.next();return t.done?void 0:t.value}until(t){let i=this.#n.until(t);return this.#c(),i}toSignal(...t){let i=this,s=t.length>0?t[0]:this.#e,n=this.#n.toSignal(s);this.#c();let a=!1,o=this.#p?.deref(),r=function(){return n.apply(this,arguments)},l=new Proxy(r,{get(m,u){return u===Z?o:u==="disposed"?a:u==="dispose"||u===Symbol.dispose?()=>{a||(a=!0,o&&o[p]===l&&delete o[p],o=void 0,i.#r===l&&(i.#r=void 0),n.dispose?.())}:u==="get"?()=>n.get():n[u]},apply(m,u,d){return n.apply(u,d)}});return l}get signal(){let t=this.#p?.deref();return t?t.signal:((!this.#r||this.#r.disposed)&&(this.#r=this.toSignal()),this.#r)}async next(){if(this.#s||this.#d)return{done:!0,value:void 0};let t=this.#n.next();this.#E?this.#c():(this.#E=!0,this.#D()>0?this.#c():queueMicrotask(()=>{(!this.#s||this.#n.state.queued>0)&&(this.#v(),this.#w())}));let i=await t;return i.done?{done:!0,value:void 0}:i.value&&i.value.isValid?{done:!1,value:i.value}:{done:!0,value:void 0}}async return(){return this.stop(),{done:!0,value:void 0}}async throw(t){throw this.stop(),t}async[Symbol.asyncDispose](){this.stop()}[Symbol.asyncIterator](){return this.#p?.deref()??this}[Symbol.dispose](){this.stop()}};function x(c,t,i){let s=new D(c,t,i),n=new Proxy((()=>s.stop()),{get:(o,r)=>{if(r==="pulse")return s.pulse.bind(s);if(r==="pull")return s.pull.bind(s);if(r==="until")return s.until.bind(s);if(r==="on")return(l,m)=>(s.on(l,m),n);if(r==="stop")return s.stop.bind(s);if(r==="signal"){let l=o[p];return(!l||l.disposed)&&(l=s.toSignal(),o[p]=l),l}return r===p?o[p]:r==="toSignal"?s.toSignal.bind(s):r==="next"?s.next.bind(s):r==="return"?s.return.bind(s):r==="throw"?s.throw.bind(s):r==="info"?s.info:r===Symbol.asyncIterator?()=>n:r===Symbol.asyncDispose?s[Symbol.asyncDispose].bind(s):r===Symbol.dispose?s[Symbol.dispose].bind(s):s[r]},deleteProperty:(o,r)=>r===p?(delete o[p],!0):Reflect.deleteProperty(o,r),apply:o=>o()}),a=new WeakRef(s);return e.Finalizer.register(n,()=>{a.deref()?.stop()}),s.bootstrap((0,e.cast)(n))}var z={get:()=>W.active},g=O({name:"ticker",install(c,t){let i=t,s=c||this,n=function(a,o){let r=(0,e.hasKey)(this,"prototype")?this:(0,e.hasKey)(this?.constructor,"prototype")?this.constructor:s,l=i??r?.config?.pluginOptions?.ticker;if(l&&(0,e.isObject)(l)){if((0,e.isUndefined)(a))return x(r,l);if((0,e.isFunction)(a)&&(0,e.isUndefined)(o))return x(r,l,a);if((0,e.isObject)(a)&&!(0,e.isFunction)(a))return x(r,{...l,...a},o)}return x(r,a,o)};n.signal=function(a){let o=n(a),r=o.signal,l=()=>{o.stop(),r.dispose?.()},m=function(){return r()},u=new Proxy(m,{get(T,f){return f==="dispose"||f===Symbol.dispose?l:f==="get"?()=>r.get():r[f]},apply(T,f,I){return r.apply(f,I)}}),d=new WeakRef(o);return e.Finalizer.register(u,()=>{d.deref()?.stop()}),u},(0,e.attachStatics)(s,{ticker:n,tickers:z})}}),_=g;(0,e.autoInstall)(g);return U(G);})();
1
+ "use strict";var Magma;((Magma||={}).plugins||={}).ticker=(()=>{var F=Object.create;var v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var q=(c,t)=>()=>{try{return t||c((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},N=(c,t)=>{for(var i in t)v(c,i,{get:t[i],enumerable:!0})},S=(c,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of j(t))!K.call(c,n)&&n!==i&&v(c,n,{get:()=>t[n],enumerable:!(s=$(t,n))||s.enumerable});return c},k=(c,t,i)=>(S(c,t,"default"),i&&S(i,t,"default")),M=(c,t,i)=>(i=c!=null?F(B(c)):{},S(t||!c||!c.__esModule?v(i,"default",{value:c,enumerable:!0}):i,c)),U=c=>S(v({},"__esModule",{value:!0}),c);var R=q((X,A)=>{"use strict";A.exports=window.Magma.pluginSdk});var G={};N(G,{Ticker:()=>W,TickerPlugin:()=>g,default:()=>_,isCronString:()=>e.isCronString});var e={};N(e,{definePlugin:()=>O,defineTerm:()=>Y});k(e,M(R()));var w=M(R()),O=c=>(0,w.definePlugin)({...c,version:"3.0.0"}),Y=c=>(0,w.defineTerm)({...c,version:"3.0.0"});var b=new Set,p=Symbol.for("Tempo.ticker.cachedSignal"),Z=Symbol.for("Tempo.ticker.instance"),W={get active(){let c=[];for(let t of b){let i=t.ref.deref();if((0,e.isUndefined)(i)||i.info.stopped)b.delete(t);else{let{label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d}=i.info;c.push({ticker:i,label:s,next:n,ticks:a,limit:o,interval:r,rrule:l,cron:m,stopped:u,ntp:d})}}return c}},D=class{#t;#x;#i={};#h;#l;#e;#o;#a;#b=0;#s=!1;#E=!1;#u=!0;#d=!1;#g=!1;#f;#n;#y=new Set;#I=new Set;#R=!1;#T=!1;#k=!1;#O=!1;#P=!1;#S;#p;#m=void 0;#r=void 0;constructor(t,i,s){this.#t=t;let n={},a,o=h=>(0,e.isObject)(h)&&("epoch"in h||"epochMilliseconds"in h||"toZonedDateTimeISO"in h||"getTime"in h),r=h=>(0,e.isObject)(h)&&!o(h);switch(!0){case(0,e.isFunction)(i):a=i;break;case r(i):Object.assign(n,i),(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s);break;default:if((0,e.isNotNullish)(i))if((0,e.isCronString)(i))n.cron=i;else if((0,e.isRRuleString)(i))n.rrule=i;else{let h=Number(i);(0,e.isNumeric)(i)?n.seconds=h:n.seed=i}(0,e.isFunction)(s)?a=s:r(s)&&Object.assign(n,s)}if((0,e.isNotNullish)(n.interval)&&(0,e.isNullish)(n.seconds)&&(0,e.isNullish)(n.cron)&&(0,e.isNullish)(n.rrule)){let h=n.interval;(0,e.isCronString)(h)?n.cron=h:(0,e.isRRuleString)(h)?n.rrule=h:(0,e.isNumeric)(h)?n.seconds=Number(h):n.seed=h}let{label:l,limit:m,until:u,seed:d,rrule:T,cron:f,ntp:I,...y}=n;this.#S=y,this.#x=l,this.#a=m,this.#k=!!I,this.#O=!!(this.#k&&this.#t.ntp?.isCalibrated),T&&(this.#h=(0,e.isString)(T)?T:T.rrule),this.#T=!!(n.catch??this.#t.config?.catch),this.#n=new e.Reactive({tag:this.#x??"Ticker",catch:this.#T}),(0,e.isNotNullish)(f)&&((0,e.isCronString)(f)?this.#l=f:(this.#R=!0,(0,e.logError)(new Error(`Invalid Ticker cron schedule: ${String(f)}`),{...this.#S,catch:this.#T}))),a&&this.#n.on("data",h=>a(h,()=>this.stop()));for(let[h,C]of Object.entries(y))(0,e.isNotNullish)(C)&&(h.startsWith("#")||e.Enum.has(e.enums.DURATIONS,h)||e.Enum.has(e.enums.ELEMENT,h))&&(this.#i[h]=C);let L=(0,e.isNotNullish)(n.seed),E=(0,e.isNotNullish)(this.#h),P=(0,e.isNotNullish)(this.#l),V=!(0,e.isEmpty)(this.#i)||(0,e.isNotNullish)(n.seconds)&&(0,e.isNumber)(n.seconds);(0,e.isNotNullish)(i)&&!r(i)&&!V&&!L&&!E&&!P&&!a&&(0,e.logError)(new Error(`Invalid Ticker interval, seed, cron, or rrule: ${String(i)}`),{...this.#S,catch:this.#T}),this.#o=u?new this.#t(r(u)?void 0:u,r(u)?{...y,...u}:y):void 0,(0,e.isEmpty)(this.#i)&&!E&&!P&&!this.#R&&((0,e.isNotNullish)(d)?this.#a??=1:this.#i.seconds=1),(0,e.normaliseFractionalDurations)(this.#i),(0,e.isNotNullish)(d)?(this.#e=new this.#t(r(d)?void 0:d,r(d)?{...y,...d}:y),this.#P=(!r(d)||(0,e.isNotNullish)(d.epoch))&&this.#e.epoch.ms>(0,e.instant)().epochMilliseconds):this.#k&&(0,e.isFunction)(this.#t.ntp?.now)?this.#e=this.#t.ntp.now(y):this.#e=new this.#t(void 0,y)}bootstrap(t){if(this.#p=new WeakRef(t),this.#m={ref:this.#p,token:Object.create(null)},this.#a===0)return this.stop(),t;if(this.#R)return this.stop(),t;if(!this.#e.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker seed: ${String(this.#e)}`),this.#e.config);else if(this.#o&&!this.#o.isValid)this.stop(),(0,e.logError)(new Error(`Invalid Ticker boundary: ${String(this.#o)}`),this.#e.config);else try{if(this.#l||this.#h)this.#u=!0,this.#d=!1,b.add(this.#m),this.#c();else{let i=Object.entries(this.#i).some(([o,r])=>o.startsWith("#")&&(0,e.isString)(r)&&/^[<>]/.test(r.trim())),s=Object.keys(this.#i).some(o=>!o.startsWith("#"));if(i&&s)throw new Error("Ambiguous Ticker payload: cannot mix directional shorthand terms (e.g. '>') with relative durations (e.g. 'hours'). Use one or the other.");this.#g=i;let n=Object.keys(this.#i).some(o=>o.startsWith("#")),a=this.#g?this.#e.set(this.#i):this.#e.add(this.#i);if(!a.isValid)throw new Error(`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`);this.#u=this.#t.compare(a,this.#e)>=0,this.#d=a.epoch.ns===this.#e.epoch.ns,n&&(this.#e=a),b.add(this.#m),this.#c()}}catch{this.stop();let s=`Invalid Ticker payload resolution for ${JSON.stringify(this.#i)}`;(0,e.logError)(new Error(s),this.#e.config),queueMicrotask(()=>this.#y.forEach(n=>n(this.#e,()=>this.stop()))),this.#u=!0,this.#d=!1}return t}#D(){let t=this.#k&&!!this.#t.ntp?.isCalibrated;t&&!this.#O&&!this.#P&&this.#b===0&&(0,e.isFunction)(this.#t.ntp?.now)&&(this.#e=this.#t.ntp.now(this.#S),Object.keys(this.#i).some(a=>a.startsWith("#"))&&(this.#e=this.#g?this.#e.set(this.#i):this.#e.add(this.#i)),this.#O=!0);let i=t&&(0,e.isFunction)(this.#t.ntp?.now)?this.#t.ntp.now().epoch.ms:(0,e.instant)().epochMilliseconds,s=Math.round(this.#e.epoch.ms-i);if(s>0)return Math.min(s,2147483647);if(!this.#u){let n=Math.abs(Math.round(this.#e.add(this.#i).epoch.ms-this.#e.epoch.ms));return Math.max(20,Math.min(50,n||1e3))}return 0}#v(){try{return this.pulse()}catch(t){let i=[...this.#y];if(this.stop(),i.forEach(s=>s(this.#e,()=>this.stop())),!this.#T)throw t;return this.#e}}#w(){this.#s||this.#d||(this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},this.#D()))}#c(){if((this.#n.state.subscribers>0||this.#n.state.queued>0)&&!this.#s&&!this.#f){let t=this.#D();t>0?this.#f=setTimeout(()=>{this.#s||(this.#v(),this.#w())},t):(this.#v(),this.#w())}}pulse(){if(this.#s)return new this.#t(null,this.#e.config);let t=this.#e;if(!t.isValid){let s=[...this.#y];return this.stop(),s.forEach(n=>n(t,()=>this.stop())),t}if(this.#l){let s=(0,e.getNextCronEpoch)(this.#l,t.epoch.ms,t.tz);this.#e=new this.#t(s,t.config)}else if(this.#h){let s=(0,e.getNextRRuleEpoch)(this.#h,t.epoch.ms);this.#e=new this.#t(s,t.config)}else this.#e=this.#d?t:this.#g?t.set(this.#i):t.add(this.#i);this.#b++;let i=this.#a!==void 0&&this.#b>=this.#a||(0,e.isNotNullish)(this.#o)&&(this.#u&&this.#t.compare(t,this.#o)>=0||!this.#u&&this.#t.compare(t,this.#o)<=0);return this.#s&&this.#a===0||(this.#n.cast(t),i&&this.stop()),t}on(t,i){return t==="pulse"?(this.#n.on("data",s=>i(s,()=>this.stop())),this.#c()):t==="catch"?this.#y.add(i):t==="stop"&&this.#I.add(i),this}stop(t){if(this.#s)return;this.#s=!0,this.#m&&(b.delete(this.#m),this.#m=void 0),this.#f&&(clearTimeout(this.#f),this.#f=void 0),t!==void 0&&(this.#e=t),this.#n.complete(t);let i=this.#p?.deref();i&&i[p]&&(i[p].dispose?.(),delete i[p]),this.#r&&(this.#r.dispose?.(),this.#r=void 0);let s=[...this.#I];this.#I.clear(),this.#y.clear();for(let n of s)n(this.#e,()=>{})}get[Symbol.toStringTag](){return"Tempo.Ticker"}get info(){return{label:this.#x,next:this.#e,ticks:this.#b,limit:this.#a,interval:{...this.#i},rrule:this.#h,cron:this.#l,stopped:this.#s,ntp:this.#k}}async pull(){let t=await this.next();return t.done?void 0:t.value}until(t){let i=this.#n.until(t);return this.#c(),i}toSignal(...t){let i=this,s=t.length>0?t[0]:this.#e,n=this.#n.toSignal(s);this.#c();let a=!1,o=this.#p?.deref(),r=function(){return n.apply(this,arguments)},l=new Proxy(r,{get(m,u){return u===Z?o:u==="disposed"?a:u==="dispose"||u===Symbol.dispose?()=>{a||(a=!0,o&&o[p]===l&&delete o[p],o=void 0,i.#r===l&&(i.#r=void 0),n.dispose?.())}:u==="get"?()=>n.get():n[u]},apply(m,u,d){return n.apply(u,d)}});return l}get signal(){let t=this.#p?.deref();return t?t.signal:((!this.#r||this.#r.disposed)&&(this.#r=this.toSignal()),this.#r)}async next(){if(this.#s||this.#d)return{done:!0,value:void 0};let t=this.#n.next();this.#E?this.#c():(this.#E=!0,this.#D()>0?this.#c():queueMicrotask(()=>{(!this.#s||this.#n.state.queued>0)&&(this.#v(),this.#w())}));let i=await t;return i.done?{done:!0,value:void 0}:i.value&&i.value.isValid?{done:!1,value:i.value}:{done:!0,value:void 0}}async return(){return this.stop(),{done:!0,value:void 0}}async throw(t){throw this.stop(),t}async[Symbol.asyncDispose](){this.stop()}[Symbol.asyncIterator](){return this.#p?.deref()??this}[Symbol.dispose](){this.stop()}};function x(c,t,i){let s=new D(c,t,i),n=new Proxy((()=>s.stop()),{get:(o,r)=>{if(r==="pulse")return s.pulse.bind(s);if(r==="pull")return s.pull.bind(s);if(r==="until")return s.until.bind(s);if(r==="on")return(l,m)=>(s.on(l,m),n);if(r==="stop")return s.stop.bind(s);if(r==="signal"){let l=o[p];return(!l||l.disposed)&&(l=s.toSignal(),o[p]=l),l}return r===p?o[p]:r==="toSignal"?s.toSignal.bind(s):r==="next"?s.next.bind(s):r==="return"?s.return.bind(s):r==="throw"?s.throw.bind(s):r==="info"?s.info:r===Symbol.asyncIterator?()=>n:r===Symbol.asyncDispose?s[Symbol.asyncDispose].bind(s):r===Symbol.dispose?s[Symbol.dispose].bind(s):s[r]},deleteProperty:(o,r)=>r===p?(delete o[p],!0):Reflect.deleteProperty(o,r),apply:o=>o()}),a=new WeakRef(s);return e.Finalizer.register(n,()=>{a.deref()?.stop()}),s.bootstrap((0,e.cast)(n))}var z={get:()=>W.active},g=O({name:"ticker",install(c,t){let i=t,s=c||this,n=function(a,o){let r=(0,e.hasKey)(this,"prototype")?this:(0,e.hasKey)(this?.constructor,"prototype")?this.constructor:s,l=i??r?.config?.pluginOptions?.ticker;if(l&&(0,e.isObject)(l)){if((0,e.isUndefined)(a))return x(r,l);if((0,e.isFunction)(a)&&(0,e.isUndefined)(o))return x(r,l,a);if((0,e.isObject)(a)&&!(0,e.isFunction)(a))return x(r,{...l,...a},o)}return x(r,a,o)};n.signal=function(a){let o=n(a),r=o.signal,l=()=>{o.stop(),r.dispose?.()},m=function(){return r()},u=new Proxy(m,{get(T,f){return f==="dispose"||f===Symbol.dispose?l:f==="get"?()=>r.get():r[f]},apply(T,f,I){return r.apply(f,I)}}),d=new WeakRef(o);return e.Finalizer.register(u,()=>{d.deref()?.stop()}),u},(0,e.attachStatics)(s,{ticker:n,tickers:z})}}),_=g;(0,e.autoInstall)(g);return U(G);})();
package/dist/install.js CHANGED
@@ -25,8 +25,8 @@ __export(sdk_exports, {
25
25
  __reExport(sdk_exports, sdk_star);
26
26
  import * as sdk_star from "tempo-kit/plugin/sdk";
27
27
  import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
28
- var definePlugin = (config) => originalPlugin({ ...config, version: "3.0.0-rc.0" });
29
- var defineTerm = (config) => originalTerm({ ...config, version: "3.0.0-rc.0" });
28
+ var definePlugin = (config) => originalPlugin({ ...config, version: "3.0.0" });
29
+ var defineTerm = (config) => originalTerm({ ...config, version: "3.0.0" });
30
30
 
31
31
  // src/index.ts
32
32
  var ACTIVE_TICKERS = /* @__PURE__ */ new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempo-kit/plugin-ticker",
3
- "version": "3.0.0-rc.0",
3
+ "version": "3.0.0",
4
4
  "description": "Tempo plugin that provides a high-performance continuous execution loop (Ticker) based on temporal mathematics.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",