@prtcl/plonk 1.0.10 → 1.1.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/dist/index.d.ts CHANGED
@@ -17,12 +17,21 @@ type RandState = {
17
17
  */
18
18
  declare class Rand {
19
19
  state: RandState;
20
+ /** Returns a single random value. One-off form of `new Rand(opts).value()`. */
20
21
  static rand(opts?: RandOptions): number;
21
22
  constructor(opts?: RandOptions);
23
+ /** Updates the range bounds, clamping the current value if needed. */
22
24
  setRange(partialOpts: RandOptions): void;
25
+ /** Returns the current value. */
23
26
  value(): number;
27
+ /** Generates a new random value within the range. */
24
28
  next(): number;
25
29
  }
30
+ /**
31
+ * Random number generator that produces values within a bounded range.
32
+ * One-off form of `new Rand(opts).value()`.
33
+ */
34
+ declare const rand: typeof Rand.rand;
26
35
 
27
36
  /** Options for configuring a Drunk random walk. */
28
37
  type DrunkOptions = {
@@ -51,13 +60,25 @@ declare class Drunk {
51
60
  state: DrunkState;
52
61
  protected _initialValue: Rand;
53
62
  protected _step: Rand;
63
+ /** Creates a new Drunk instance. Alternative form of `new Drunk(opts)`. */
64
+ static drunk(opts?: DrunkOptions): Drunk;
54
65
  constructor(opts?: DrunkOptions);
66
+ /** Updates the walk bounds, clamping the current value if needed. */
55
67
  setRange(partialOpts?: Pick<DrunkOptions, 'min' | 'max'>): void;
68
+ /** Updates the maximum step size. */
56
69
  setStepSize(partialOpts?: Pick<DrunkOptions, 'step'>): void;
70
+ /** Resets the walk with optional new options. */
57
71
  reset(opts?: DrunkOptions): void;
72
+ /** Returns the current value. */
58
73
  value(): number;
74
+ /** Advances one step and returns the new value. */
59
75
  next(): number;
60
76
  }
77
+ /**
78
+ * Stochastic random walk generator that produces values within a bounded range.
79
+ * Alternative form of `new Drunk(opts)`.
80
+ */
81
+ declare const drunk: typeof Drunk.drunk;
61
82
 
62
83
  /** A numeric range with min and max bounds. */
63
84
  type ScaleRange = {
@@ -88,13 +109,23 @@ type ScaleState = {
88
109
  */
89
110
  declare class Scale {
90
111
  state: ScaleState;
112
+ /** Scales a single value. One-off form of `new Scale(opts).scale(n)`. */
91
113
  static scale(n: number, opts?: ScaleOptions): number;
92
114
  constructor(opts?: ScaleOptions);
115
+ /** Updates input and/or output ranges, recomputing the internal ratio. */
93
116
  setRanges(opts: ScaleOptions): void;
117
+ /** Resets with new range options. */
94
118
  reset(opts: ScaleOptions): void;
119
+ /** Returns the last scaled value. */
95
120
  value(): number;
121
+ /** Maps a value from the input range to the output range. */
96
122
  scale(n: number): number;
97
123
  }
124
+ /**
125
+ * Linear map of values from one range to another, supports negative values and inversion.
126
+ * One-off form of `new Scale(opts).scale(n)`.
127
+ */
128
+ declare const scale: typeof Scale.scale;
98
129
 
99
130
  /** Snapshot of an Env's internal state. */
100
131
  type EnvState = {
@@ -121,13 +152,60 @@ type EnvOptions = {
121
152
  declare class Env {
122
153
  state: EnvState;
123
154
  protected _interpolator: Scale;
155
+ /** Creates a new Env instance. Alternative form of `new Env(opts)`. */
156
+ static env(opts: EnvOptions): Env;
124
157
  constructor(opts: EnvOptions);
158
+ /** Updates the envelope duration. */
125
159
  setDuration(duration: number): void;
160
+ /** Restarts the envelope with optional new options. */
126
161
  reset(opts?: EnvOptions): void;
162
+ /** Returns true when the envelope has completed. */
127
163
  done(): boolean;
164
+ /** Returns the current interpolated value. */
128
165
  value(): number;
166
+ /** Advances the envelope and returns the new value. */
129
167
  next(): number;
130
168
  }
169
+ /**
170
+ * Linear envelope which interpolates between two values over a duration. Useful for audio envelopes, transitions, and animations.
171
+ * Alternative form of `new Env(opts)`.
172
+ */
173
+ declare const env: typeof Env.env;
174
+
175
+ /** Options for configuring a Fold transformer. */
176
+ type FoldOptions = {
177
+ /** Lower bound of the range. Defaults to 0. */
178
+ min?: number;
179
+ /** Upper bound of the range. Defaults to 1. */
180
+ max?: number;
181
+ };
182
+ /** Snapshot of a Fold transformer's internal state. */
183
+ type FoldState = {
184
+ min: number;
185
+ max: number;
186
+ value: number;
187
+ };
188
+ /**
189
+ * Folds (reflects) values back and forth within a configured range.
190
+ * @param opts - {@link FoldOptions} for configuring the range.
191
+ */
192
+ declare class Fold {
193
+ state: FoldState;
194
+ /** Folds a single value. One-off form of `new Fold(opts).fold(n)`. */
195
+ static fold(n: number, opts?: FoldOptions): number;
196
+ constructor(opts?: FoldOptions);
197
+ /** Updates the range bounds, folding the current value into the new range. */
198
+ setRange(partialOpts: FoldOptions): void;
199
+ /** Returns the last folded value. */
200
+ value(): number;
201
+ /** Folds a value into the configured range and caches the result. */
202
+ fold(n: number): number;
203
+ }
204
+ /**
205
+ * Folds (reflects) values back and forth within a configured range.
206
+ * One-off form of `new Fold(opts).fold(n)`.
207
+ */
208
+ declare const fold: typeof Fold.fold;
131
209
 
132
210
  declare const SINE_PERIOD: number;
133
211
  /** Options for configuring a Sine oscillator. */
@@ -150,12 +228,58 @@ type SineState = {
150
228
  declare class Sine {
151
229
  state: SineState;
152
230
  protected _interpolator: Scale;
231
+ /** Creates a new Sine instance. Alternative form of `new Sine(opts)`. */
232
+ static sine(opts: SineOptions): Sine;
153
233
  constructor(opts: SineOptions);
234
+ /** Updates the cycle duration. */
154
235
  setDuration(duration: number): void;
236
+ /** Resets the oscillator with optional new options. */
155
237
  reset(opts?: SineOptions): void;
238
+ /** Returns the current oscillator value. */
156
239
  value(): number;
240
+ /** Advances the oscillator and returns the new value. */
157
241
  next(): number;
158
242
  }
243
+ /**
244
+ * Time-based sine wave oscillator that outputs values between -1 and 1.
245
+ * Alternative form of `new Sine(opts)`.
246
+ */
247
+ declare const sine: typeof Sine.sine;
248
+
249
+ /** Options for configuring a Wrap transformer. */
250
+ type WrapOptions = {
251
+ /** Lower bound of the range. Defaults to 0. */
252
+ min?: number;
253
+ /** Upper bound of the range. Defaults to 1. */
254
+ max?: number;
255
+ };
256
+ /** Snapshot of a Wrap transformer's internal state. */
257
+ type WrapState = {
258
+ min: number;
259
+ max: number;
260
+ value: number;
261
+ };
262
+ /**
263
+ * Wraps values around a configured range using modular arithmetic.
264
+ * @param opts - {@link WrapOptions} for configuring the range.
265
+ */
266
+ declare class Wrap {
267
+ state: WrapState;
268
+ /** Wraps a single value. One-off form of `new Wrap(opts).wrap(n)`. */
269
+ static wrap(n: number, opts?: WrapOptions): number;
270
+ constructor(opts?: WrapOptions);
271
+ /** Updates the range bounds, wrapping the current value into the new range. */
272
+ setRange(partialOpts: WrapOptions): void;
273
+ /** Returns the last wrapped value. */
274
+ value(): number;
275
+ /** Wraps a value into the configured range and caches the result. */
276
+ wrap(n: number): number;
277
+ }
278
+ /**
279
+ * Wraps values around a configured range using modular arithmetic.
280
+ * One-off form of `new Wrap(opts).wrap(n)`.
281
+ */
282
+ declare const wrap: typeof Wrap.wrap;
159
283
 
160
284
  /** Snapshot of a running timer's internal state. */
161
285
  type TimerState = {
@@ -183,14 +307,25 @@ declare class Metro {
183
307
  state: TimerState;
184
308
  protected _listeners: TimerCallback<Metro>[];
185
309
  protected _timerId: ReturnType<typeof setTimeout> | number;
310
+ /** Creates a new Metro instance. Alternative form of `new Metro(callback, opts)`. */
311
+ static metro(callback: TimerCallback<Metro>, opts?: MetroOptions): Metro;
186
312
  constructor(callback: TimerCallback<Metro>, opts?: MetroOptions);
187
313
  protected asyncHandler(callback: () => void): void;
188
314
  protected clearAsyncHandler(): void;
315
+ /** Stops the timer and returns total elapsed time in milliseconds. */
189
316
  stop: () => number;
317
+ /** Resets state to initial values. */
190
318
  reset: () => void;
319
+ /** Updates the tick interval in milliseconds. */
191
320
  setTime: (updatedTime?: number) => void;
321
+ /** Starts the timer loop. */
192
322
  run: () => void;
193
323
  }
324
+ /**
325
+ * High-resolution recursive timer with variable interval, provides runtime metrics via callback for time-based calculations.
326
+ * Alternative form of `new Metro(callback, opts)`.
327
+ */
328
+ declare const metro: typeof Metro.metro;
194
329
 
195
330
  type FPS = 15 | 30 | 60;
196
331
  declare enum TimeFormat {
@@ -217,11 +352,19 @@ type FramesOptions = {
217
352
  */
218
353
  declare class Frames extends Metro {
219
354
  protected _timerId: ReturnType<typeof requestAnimationFrame>;
355
+ /** Creates a new Frames instance. Alternative form of `new Frames(callback, opts)`. */
356
+ static frames(callback: TimerCallback<Frames>, opts?: FramesOptions): Frames;
220
357
  constructor(callback: TimerCallback<Frames>, opts?: FramesOptions);
221
358
  protected asyncHandler(callback: () => void): void;
222
359
  protected clearAsyncHandler(): void;
360
+ /** Updates the target frames per second. */
223
361
  setFPS: (fps?: FPS) => void;
224
362
  }
363
+ /**
364
+ * Animation-loop timer that uses requestAnimationFrame when available.
365
+ * Alternative form of `new Frames(callback, opts)`.
366
+ */
367
+ declare const frames: typeof Frames.frames;
225
368
 
226
369
  declare function clamp(n: number): number;
227
370
  declare function clamp(n: number, max: number): number;
@@ -252,4 +395,4 @@ declare const MS_IN_SECOND = 1000;
252
395
  declare const MS_IN_MINUTE: number;
253
396
  declare const MS_IN_HOUR: number;
254
397
 
255
- export { Drunk, type DrunkOptions, type DrunkState, Env, type EnvOptions, type EnvState, type FPS, Frames, type FramesOptions, MS_IN_HOUR, MS_IN_MINUTE, MS_IN_SECOND, Metro, type MetroOptions, Rand, type RandOptions, type RandState, SINE_PERIOD, SIXTY_FPS, Scale, type ScaleOptions, type ScaleRange, type ScaleState, Sine, type SineOptions, type SineState, TimeFormat, type TimerCallback, clamp, expo, ms, now, wait };
398
+ export { Drunk, type DrunkOptions, type DrunkState, Env, type EnvOptions, type EnvState, type FPS, Fold, type FoldOptions, type FoldState, Frames, type FramesOptions, MS_IN_HOUR, MS_IN_MINUTE, MS_IN_SECOND, Metro, type MetroOptions, Rand, type RandOptions, type RandState, SINE_PERIOD, SIXTY_FPS, Scale, type ScaleOptions, type ScaleRange, type ScaleState, Sine, type SineOptions, type SineState, TimeFormat, type TimerCallback, Wrap, type WrapOptions, type WrapState, clamp, drunk, env, expo, fold, frames, metro, ms, now, rand, scale, sine, wait, wrap };