@tempo-kit/plugin-ticker 0.0.0-stage → 3.0.0-rc.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,120 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `@tempo-kit/plugin-ticker` project will be documented in this file.
4
+
5
+ ## [3.0.0] - 2026-11-27
6
+
7
+ ### Breaking Changes
8
+ - Migrated package namespace from `@magmacomputing/tempo-plugin-ticker` to `@tempo-kit/plugin-ticker`.
9
+ - Updated `peerDependencies` to `tempo-kit@^5.0.0`.
10
+
11
+
12
+ ### Added
13
+ - **TC39 Signal Reactivity (`ticker.signal`, `ticker.toSignal()`)**:
14
+ - Added `ticker.signal` getter returning a `ReadonlySignal<Tempo>` bound to the ticker cadence.
15
+ - Added `ticker.toSignal(fallback?)` method returning an explicit reactive signal initialized to seed or custom fallback value.
16
+ - Added auto-disposable static constructor `Tempo.ticker.signal(interval)` returning a `ReadonlySignal<Tempo> & Disposable` that stops and tears down the underlying ticker when disposed or garbage collected.
17
+ ### Fixed & Changed
18
+ - **Null Schedule Option Handling**:
19
+ - Updated `options.interval` fallback guard to check `isNullish` on `seconds`, `cron`, and `rrule` so explicit `null` schedule options (e.g. `{ interval: 60, cron: null }`) do not bypass the configured `interval`.
20
+ - **Tempo v5.0.0 Guard & Enum Alignment**:
21
+ - Migrated internal presence checks to `isNotNullish` / `isNullish` and updated duration/element key lookups to static `Enum.has(...)`.
22
+ ### Fixed & Memory Safety
23
+ - **Signal Lifecycle & Retained Ticker Ownership**:
24
+ - Managed mutual lifetime ownership between ticker proxies and derived signal wrappers (`ticker.signal`, `ticker.toSignal()`) ensuring the underlying ticker remains active and updates reactive consumers (e.g. `Signify.computed`) even when the temporary ticker proxy is dropped and only the signal wrapper is retained.
25
+ - Preserved automatic teardown upon signal disposal (`signal.dispose()`, `signal[Symbol.dispose]()`), and ensured both proxy and signal wrapper are collected cleanly without circular leaks when dropped by consumer code.
26
+
27
+ ## [2.6.1] - 2026-10-06
28
+
29
+ ### Fixed
30
+ - **Standardized Diagnostic Logging & Error Boundaries**:
31
+ - Routed error messages in catch mode through [`logError`](../../tempo/src/plugin/plugin.sdk.ts) from `@magmacomputing/tempo/plugin/sdk`.
32
+ - Added support for `{ silent: true }` configuration to suppress expected error output during tests and headless tasks.
33
+
34
+ ## [2.6.0] - 2026-10-02
35
+
36
+ ### Added
37
+ - **NTP Clock Drift Compensation (`ntp: true`)**:
38
+ - Integrated optional NTP clock synchronization support via `options.ntp: true`.
39
+ - When enabled, seeds ticker cadence baseline from `Tempo.ntp.now()` and compensates cadence scheduling delays against remote server drift (`Tempo.ntp.offset`).
40
+ - Added graceful fallback to system clock if `@magmacomputing/tempo-plugin-ntp` is not loaded or uncalibrated.
41
+ - Added `ntp: boolean` status flag to `ticker.info` and `Tempo.tickers` snapshot registry.
42
+
43
+ ### Changed & Refactored
44
+ - **Runtime Introspection & Branding (`Symbol.toStringTag`)**:
45
+ - Added `[Symbol.toStringTag]` getter returning `'Tempo.Ticker'` on `TickerInstance` for structured runtime type identification and DevTools inspection.
46
+ - **Reactive Stream Engine Migration (`Reactive<Tempo>`)**:
47
+ - Re-architected internal async iteration, push event dispatching, and pull queuing to delegate directly to `Reactive<Tempo>` from the Tempo Plugin SDK (`#library`).
48
+ - Eliminated manual promise queue state and listener dispatch boilerplate.
49
+ - Added native direct pull support (`await ticker.pull()`) and composable termination (`ticker.until(signal)`).
50
+
51
+ ## [2.5.1] - 2026-09-29
52
+
53
+ ### Added & Changed
54
+ - **Dual-Layer Lifecycle & Automatic GC Finalization (`FinalizationRegistry`)**:
55
+ - Integrated `Finalizer.register` from `@magmacomputing/tempo/plugin/sdk` / `#library/finalizer.class.js`.
56
+ - Registered Ticker proxy instances with the garbage collection finalizer: if user code drops a Ticker handle without calling `.stop()`, the Garbage Collector automatically stops the ticker and tears down underlying `setTimeout` / `setInterval` timer handles.
57
+ - Upgraded internal active registry `ACTIVE_TICKERS` to store `WeakRef<Ticker.Instance>` entries, ensuring active tickers are not strongly pinned in memory and dead references are automatically pruned during `Tempo.tickers` inspection.
58
+ - Updated documentation (`resource-management.md`) to reflect the dual-layer lifecycle model (deterministic `using` / `stop()` + background GC safety-net).
59
+
60
+ ## [2.5.0] - 2026-09-18
61
+
62
+ ### Added
63
+ - **Subpath Side-Effect Installation (`/install`)**:
64
+ - Added dedicated `@tempo-kit/plugin-ticker/install` entrypoint for zero-boilerplate side-effect registration on the global `Tempo` instance via `autoInstall`.
65
+ - Configured `package.json` with `"sideEffects": ["./dist/install.js"]` to ensure the root package entrypoint remains 100% pure and tree-shakeable.
66
+
67
+ ## [2.4.0] - 2026-09-16
68
+
69
+ ### Added
70
+ - **Colocated Plugin Options & Factory Support**:
71
+ - Exported `TickerPluginOptions` interface for typed call-site configuration.
72
+ - Updated `TickerPlugin.install()` to accept resolved plugin options from `Tempo.use(TickerPlugin({ ... }))` or `[TickerPlugin, { ... }]`.
73
+ - Configured plugin options are automatically applied as defaults to all subsequent `Tempo.ticker()` calls on the host class.
74
+ - Added support for the top-level `interval` option key, which automatically resolves cron strings, RFC 5545 RRULE patterns, numeric seconds, and seed timestamps.
75
+
76
+ ## [2.3.1] - 2026-09-06
77
+
78
+ ### Changed & Security
79
+ - **Deterministic Resource Disposal (`[Symbol.dispose]` / `[Symbol.asyncDispose]`)**:
80
+ - Upgraded Ticker instances to use `Proxy.revocable()`.
81
+ - Calling `[Symbol.dispose]()` or `[Symbol.asyncDispose]()` (e.g. via TC39 `using ticker = Tempo.ticker(...)`) permanently revokes the proxy handle, preventing zombie operations or memory leaks.
82
+ - Calling `ticker.stop()` remains non-destructive, allowing safe inspection of `ticker.info` and stopped status.
83
+
84
+ ## [2.3.0] - 2026-08-20
85
+
86
+ ### Changed
87
+ - **Community Edition Transition**: Open-sourced under the MIT license as a native Community plugin within the Magma monorepo.
88
+ - Removed obfuscation and proprietary license key requirement.
89
+
90
+ ### Added
91
+ - **5-Field Cron Expression Support**: Added native support for standard 5-part cron syntax (e.g. `Tempo.ticker("0 9 * * 1-5")` or `{ cron: "*/15 * * * *" }`) powered by `@magmacomputing/tempo-fns`.
92
+ - **RFC 5545 RRULE Support**: Integrated native RRULE string and `TempoRecurrenceRule` support into `Ticker` and `Ticker.Options`. Tickers can now step using deterministic calendar recurrence rules (e.g. `FREQ=DAILY;INTERVAL=1`, `FREQ=WEEKLY;BYDAY=MO`).
93
+ - **Snapshot Alignment**: Included `rrule?: string` on `Ticker.Snapshot` and `info` properties so active tickers list their active recurrence rule.
94
+
95
+ ## [2.2.1] - 2026-07-18
96
+
97
+ ### Changed
98
+ - **Ticker Plugin Documentation**: Expanded the Ticker documentation to explicitly clarify the difference between snapping (using directional shorthands like `>`) and relative shifting (using numeric values).
99
+
100
+ ## [2.2.0] - 2026-07-06
101
+
102
+ ### Added
103
+ - **Shorthand Duration Keys**: `Ticker.Options` now natively supports Tempo shorthand keys (e.g., `yy`, `mm`, `ww`, `dd`, `hh`, `mi`, `ss`, etc.). This enables writing compact and highly ergonomic intervals (e.g., `Tempo.ticker({ mi: 5, ss: 30 })`), achieving total API consistency with the broader v3.6.0 Tempo ecosystem.
104
+
105
+ ## [1.0.4] - 2026-06-11
106
+
107
+ ### Added
108
+ - **Label Identification**: Added the `label?: string` property to `Ticker.Options`. Developers can now easily tag and group tickers without needing external memory-tracking structures (like `WeakMap`). This label is natively exposed on `Tempo.tickers` snapshots.
109
+
110
+ ### Fixed
111
+ - **NPM Registry Metadata**: Explicitly added `README.md`, `CHANGELOG.md`, and `LICENSE` to the `files` array in `package.json` to ensure the npmjs.com registry correctly renders package documentation.
112
+ - **Test Integrity**: Updated internal test fixtures to correctly align with Tempo Core's standard capitalization and the recent rename of the `period` term to `timeOfDay`.
113
+
114
+ ## [1.0.0] - 2026-06-01
115
+
116
+ ### Added
117
+ - Initial release of the Ticker plugin.
118
+ - A highly accurate and CPU-efficient periodic timer designed as an alternative to native `setInterval`.
119
+ - Features pause, resume, reset, and configurable jitter compensation.
120
+ - Supports both `EventEmitter` and callback-based listener patterns.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Magma Computing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ ![Tempo Plugin](https://raw.githubusercontent.com/magmacomputing/magma/main/packages/tempo/public/plugin-logo.svg)
2
+
3
+ # @tempo-kit/plugin-ticker
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@tempo-kit/plugin-ticker"><img src="https://img.shields.io/npm/v/@tempo-kit/plugin-ticker?style=flat-square" alt="npm version" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.npmjs.com/package/tempo-kit"><img src="https://img.shields.io/npm/dependency-version/@tempo-kit/plugin-ticker/peer/tempo-kit?style=flat-square" alt="npm peer dependency version" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.npmjs.com/package/@tempo-kit/plugin-ticker"><img src="https://img.shields.io/npm/l/@tempo-kit/plugin-ticker?style=flat-square" alt="License" style="display: inline-block; margin: 0 4px;"></a> <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-Ready-blue?logo=typescript&style=flat-square" alt="TypeScript Ready" style="display: inline-block; margin: 0 4px;"></a> <a href="https://magmacomputing.github.io/magma/doc/9-plugins/ticker.index.html"><img src="https://img.shields.io/badge/Docs-VitePress-brightgreen?logo=vitepress&style=flat-square" alt="Documentation" style="display: inline-block; margin: 0 4px;"></a>
7
+ </p>
8
+
9
+ This is a Community plugin for the [Tempo](https://github.com/magmacomputing/magma) library that provides a high-performance continuous execution loop (Ticker) based on temporal mathematics.
10
+
11
+ 👉 **[View the full documentation on our GitHub Pages](https://magmacomputing.github.io/magma/doc/9-plugins/ticker.index.html)**
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @tempo-kit/plugin-ticker
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { Tempo } from 'tempo-kit';
23
+ import { TickerPlugin } from '@tempo-kit/plugin-ticker';
24
+
25
+ Tempo.init({
26
+ extends: [TickerPlugin]
27
+ });
28
+
29
+ // You can now access Ticker-based execution loops through the Tempo API:
30
+ const ticker = Tempo.ticker({ seconds: 1 }, (t, stop) => {
31
+ console.log('Tick:', t.format('isoTime'));
32
+ });
33
+ ```
34
+
35
+ > ⚡ **[Try this live in the interactive Tempo Sandbox ↗](https://magmacomputing.github.io/magma/repl/index.html?plugin=ticker)**
36
+
37
+ ## Documentation
38
+
39
+ For full API reference, advanced options, and detailed usage patterns, please visit the official 📖 **[Ticker Plugin Documentation](https://magmacomputing.github.io/magma/doc/9-plugins/ticker.index.html)**.
40
+
41
+ ## Licensing
42
+
43
+ This is a **Community** plugin. It is completely free and open-source for personal and commercial use under the MIT license.
2
44
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
@@ -0,0 +1,129 @@
1
+ import { Tempo } from 'tempo-kit';
2
+ import { isCronString, Reactive, type ReadonlySignal } from 'tempo-kit/plugin/sdk';
3
+ export { isCronString };
4
+ declare module 'tempo-kit' {
5
+ namespace Tempo {
6
+ /** An array of snapshots for all currently active tickers. */
7
+ const tickers: Ticker.Snapshot[];
8
+ /**
9
+ * Creates a new Ticker instance to schedule recurring events.
10
+ *
11
+ * @param interval - The ticker interval, cron string, rrule, or options configuration
12
+ * @param callback - Optional callback to execute on each tick
13
+ * @returns A Ticker.Instance that can be awaited, iterated, or listened to
14
+ */
15
+ function ticker(options: Ticker.Options): Ticker.Instance;
16
+ function ticker(interval?: Ticker.Interval): Ticker.Instance;
17
+ function ticker(callback: Ticker.Callback): Ticker.Instance;
18
+ function ticker(interval: Ticker.Interval, callback: Ticker.Callback): Ticker.Instance;
19
+ function ticker(interval: Ticker.Interval, options: Ticker.Options): Ticker.Instance;
20
+ function ticker(options: Ticker.Options, callback: Ticker.Callback): Ticker.Instance;
21
+ function ticker(options: Ticker.Options, extraOptions: Ticker.Options): Ticker.Instance;
22
+ namespace ticker {
23
+ /**
24
+ * Spawns an auto-ticking ReadonlySignal<Tempo> ticking at the specified interval.
25
+ * Supports explicit disposal via `using clock = Tempo.ticker.signal(...)`.
26
+ */
27
+ function signal(interval?: number | string | Ticker.Options): ReadonlySignal<Tempo> & Disposable;
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * ## Ticker
33
+ * Ticker namespace object.
34
+ * Provides access to currently active tickers.
35
+ */
36
+ export declare const Ticker: {
37
+ readonly active: Ticker.Snapshot[];
38
+ };
39
+ /**
40
+ * Unified namespace for Ticker types and public API.
41
+ */
42
+ export declare namespace Ticker {
43
+ /** ticker interval allowed types (interpreted as seconds) */
44
+ type Interval = number | string | bigint;
45
+ /** ticker configuration and stop conditions */
46
+ type Options = {
47
+ label?: string;
48
+ cron?: string;
49
+ rrule?: string | {
50
+ rrule: string;
51
+ [key: string]: any;
52
+ };
53
+ years?: number;
54
+ months?: number;
55
+ weeks?: number;
56
+ days?: number;
57
+ hours?: number;
58
+ minutes?: number;
59
+ seconds?: number;
60
+ milliseconds?: number;
61
+ microseconds?: number;
62
+ nanoseconds?: number;
63
+ yy?: number;
64
+ mm?: number;
65
+ ww?: number;
66
+ dd?: number;
67
+ hh?: number;
68
+ mi?: number;
69
+ ss?: number;
70
+ ms?: number;
71
+ us?: number;
72
+ ns?: number;
73
+ limit?: number;
74
+ until?: Tempo.DateTime | Tempo.Options;
75
+ seed?: Tempo.DateTime | Tempo.Options;
76
+ catch?: boolean;
77
+ ntp?: boolean;
78
+ timeZone?: Tempo.BaseOptions['timeZone'];
79
+ [key: `#${string}`]: number | string;
80
+ };
81
+ /** callback function for Tempo.ticker() */
82
+ type Callback = (t: Tempo, stop: () => void) => void;
83
+ /** Internal descriptor for Ticker methods and properties */
84
+ interface Descriptor extends AsyncGenerator<Tempo, any>, AsyncDisposable, Disposable {
85
+ pulse(): Tempo;
86
+ pull(): Promise<Tempo | undefined>;
87
+ until(notifier: AbortSignal | Promise<any> | Reactive<any>): Reactive<Tempo>;
88
+ on(event: 'pulse' | 'catch' | 'stop', cb: (t: Tempo, stop: () => void) => void): this;
89
+ stop(terminalValue?: Tempo): void;
90
+ readonly signal: ReadonlySignal<Tempo>;
91
+ toSignal(): ReadonlySignal<Tempo>;
92
+ toSignal<D>(initialValue: D): ReadonlySignal<Tempo | D>;
93
+ readonly info: {
94
+ label: string | undefined;
95
+ next: Tempo;
96
+ ticks: number;
97
+ limit: number | undefined;
98
+ interval: Record<string, any>;
99
+ rrule: string | undefined;
100
+ cron: string | undefined;
101
+ stopped: boolean;
102
+ ntp: boolean;
103
+ };
104
+ }
105
+ /** Unified Ticker interface supporting generators, events, and manual pulsing (callable as stop()) */
106
+ interface Instance extends Descriptor {
107
+ (): void;
108
+ }
109
+ /** Summary of an active ticker */
110
+ type Snapshot = Descriptor['info'] & {
111
+ ticker: Instance;
112
+ };
113
+ }
114
+ /**
115
+ * Options for configuring the Ticker plugin.
116
+ */
117
+ export type TickerPluginOptions = Ticker.Options & {
118
+ interval?: Ticker.Interval;
119
+ };
120
+ /**
121
+ * ## TickerPlugin
122
+ * The Community Ticker Plugin.
123
+ * Exposes the `Tempo.ticker()` factory and `Tempo.tickers` registry.
124
+ */
125
+ export declare const TickerPlugin: import("tempo-kit/plugin/plugin.type").PluginFactory<{
126
+ name: string;
127
+ install(this: typeof Tempo, TempoClass: typeof Tempo, options?: any): void;
128
+ }, any>;
129
+ export default TickerPlugin;
@@ -0,0 +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);})();