@silentstatestudio/perseon 0.0.0-stage → 0.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/LICENSE.md +30 -0
  3. package/README.md +848 -2
  4. package/dist/authoring/index.cjs +213 -0
  5. package/dist/authoring/index.d.cts +866 -0
  6. package/dist/authoring/index.d.ts +866 -0
  7. package/dist/authoring/index.js +214 -0
  8. package/dist/authoring/index.js.map +1 -0
  9. package/dist/chunk-GDXCMDJ6.js +5462 -0
  10. package/dist/chunk-GDXCMDJ6.js.map +1 -0
  11. package/dist/chunk-ON4JV4BI.js +8432 -0
  12. package/dist/chunk-ON4JV4BI.js.map +1 -0
  13. package/dist/chunk-PT7F7TTB.cjs +8431 -0
  14. package/dist/chunk-Q2HLLGJ7.cjs +5461 -0
  15. package/dist/chunk-SVI6WUOB.js +1 -0
  16. package/dist/chunk-SVI6WUOB.js.map +1 -0
  17. package/dist/chunk-ZIMCQTYK.cjs +1 -0
  18. package/dist/colors-CUEeQ78V.d.cts +2247 -0
  19. package/dist/colors-pshUJaKB.d.ts +2247 -0
  20. package/dist/core/index.cjs +29 -0
  21. package/dist/core/index.d.cts +39 -0
  22. package/dist/core/index.d.ts +39 -0
  23. package/dist/core/index.js +30 -0
  24. package/dist/core/index.js.map +1 -0
  25. package/dist/index.cjs +29 -0
  26. package/dist/index.d.cts +3 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.js +30 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/pixi-v7/index.cjs +513 -0
  31. package/dist/pixi-v7/index.d.cts +372 -0
  32. package/dist/pixi-v7/index.d.ts +372 -0
  33. package/dist/pixi-v7/index.js +514 -0
  34. package/dist/pixi-v7/index.js.map +1 -0
  35. package/dist/pixi-v8/index.cjs +608 -0
  36. package/dist/pixi-v8/index.d.cts +380 -0
  37. package/dist/pixi-v8/index.d.ts +380 -0
  38. package/dist/pixi-v8/index.js +609 -0
  39. package/dist/pixi-v8/index.js.map +1 -0
  40. package/dist/rendering-DeUo1BsK.d.cts +237 -0
  41. package/dist/rendering-DeUo1BsK.d.ts +237 -0
  42. package/dist/testing/index.cjs +159 -0
  43. package/dist/testing/index.d.cts +85 -0
  44. package/dist/testing/index.d.ts +85 -0
  45. package/dist/testing/index.js +160 -0
  46. package/dist/testing/index.js.map +1 -0
  47. package/package.json +148 -6
@@ -0,0 +1,2247 @@
1
+ import { b as IParticleVisualState, g as ITextureRef, i as IShape, f as IRenderer, P as ParticleBlendMode, e as ITicker } from './rendering-DeUo1BsK.js';
2
+
3
+ type PointValue = {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ interface VectorValue {
8
+ angle: number;
9
+ magnitude: number;
10
+ }
11
+ interface RectangleArea {
12
+ center: PointValue;
13
+ width: number;
14
+ height: number;
15
+ rotation?: number;
16
+ }
17
+ interface CircleArea {
18
+ center: PointValue;
19
+ radius: number;
20
+ }
21
+ interface RingArea {
22
+ center: PointValue;
23
+ innerRadius: number;
24
+ outerRadius: number;
25
+ }
26
+ interface CapsuleArea {
27
+ center: PointValue;
28
+ radius: number;
29
+ length: number;
30
+ rotation?: number;
31
+ }
32
+ interface PolygonArea {
33
+ points: PointValue[];
34
+ }
35
+ type ShapeArea = RectangleArea | CircleArea | RingArea | CapsuleArea | PolygonArea;
36
+
37
+ interface CurveDefinition {
38
+ points: {
39
+ x: number;
40
+ y: number;
41
+ }[];
42
+ segmentBends: number[];
43
+ }
44
+ type ProbabilityCurvePresetId = 'uniform' | 'lowBias' | 'highBias' | 'centerBias' | 'edgeBias' | 'bell' | 'doublePeak';
45
+ type ProbabilityCurveKind = {
46
+ type: 'preset';
47
+ presetId: ProbabilityCurvePresetId;
48
+ } | {
49
+ type: 'custom';
50
+ };
51
+ interface ProbabilityCurvePreset {
52
+ id: ProbabilityCurvePresetId;
53
+ label: string;
54
+ description: string;
55
+ curve: CurveDefinition;
56
+ iconKey?: string;
57
+ }
58
+
59
+ /**
60
+ * Events — named hooks the host declares once on the engine and binds to
61
+ * lifecycle moments of emitters and particles.
62
+ *
63
+ * An event is just a unique name. Emitters and particles bind that name to a
64
+ * trigger; when the trigger fires, the engine hands a `PerseonEvent` describing
65
+ * who fired it to the listeners of `on`, in three levels: the playback, its
66
+ * animation and `Perseon`. The engine never interprets an
67
+ * event — it only routes it — so hosts are free to give names any meaning they
68
+ * want (spawn a sound, chain another emitter, score a hit).
69
+ *
70
+ * Names are the identity: `ParticleAnimationOptions.events` registers them and both
71
+ * binding maps are keyed by them. A name that is not registered does not fire.
72
+ */
73
+
74
+ /** Lifecycle moments a particle can bind an event to. */
75
+ declare const PARTICLE_EVENT_TRIGGERS: readonly ["onSpawn", "onDeath", "onRegionEnter", "onRegionExit"];
76
+ /**
77
+ * Lifecycle moments an emitter can bind an event to.
78
+ *
79
+ * `onFinished` is the one that describes the emitter rather than its emission:
80
+ * it has run its cycles out **and** the last particle it spawned has died. The
81
+ * other two straddle that moment — emission stops while the particles it made
82
+ * are still on screen — so neither of them says "this emitter is done".
83
+ */
84
+ declare const EMITTER_EVENT_TRIGGERS: readonly ["onEmitStart", "onEmitStop", "onFinished"];
85
+ type ParticleEventTrigger = (typeof PARTICLE_EVENT_TRIGGERS)[number];
86
+ type EmitterEventTrigger = (typeof EMITTER_EVENT_TRIGGERS)[number];
87
+ type EventTrigger = ParticleEventTrigger | EmitterEventTrigger;
88
+ declare function isValidEventName(value: unknown): value is string;
89
+ declare function isParticleEventTrigger(value: unknown): value is ParticleEventTrigger;
90
+ declare function isEmitterEventTrigger(value: unknown): value is EmitterEventTrigger;
91
+ declare function isEventTrigger(value: unknown): value is EventTrigger;
92
+
93
+ /**
94
+ * Renderer-agnostic particle. Holds physics, lifecycle, and visual state as
95
+ * plain fields. The render adapter mirrors these fields to its backend each
96
+ * frame via `IParticleGroup.syncFrame`.
97
+ *
98
+ * A host extends it to give its particles state and behavior of their own, and
99
+ * hands the subclass to an emitter as `EmitterOptions.ParticleClass`: the hooks
100
+ * are `onInit` and `onUpdate`, and an override of `reset` that calls
101
+ * `super.reset()` clears its own state when the particle goes back to the pool.
102
+ *
103
+ * The engine pools its particles and calls `reset` and `destroy` on them; the
104
+ * setup of a recycled particle and its step on every tick are the engine's own
105
+ * and not part of this class's public surface.
106
+ *
107
+ * Names reserved for the engine, which a subclass cannot declare (doing so is a
108
+ * compile error):
109
+ * - `init`, `updatePhysics`, `updateEnvironment`, `updateTexture`: what the
110
+ * engine does with a particle, declared here as reserved methods.
111
+ * - `layer`, `mem`, `bornX`, `bornY`: the engine's per-particle state,
112
+ * declared here as private members.
113
+ *
114
+ * The rest of the public fields are the particle's state, which the engine
115
+ * writes as it simulates it: a hook may read them and write the visual and
116
+ * physical ones (`x`, `velocityX`, `alpha`, `tint`…); a subclass must not
117
+ * redeclare them with another meaning.
118
+ */
119
+ declare class ParticleItem implements IParticleVisualState {
120
+ /** Horizontal position, in pixels, in the space its emitter draws in. */
121
+ x: number;
122
+ /** Vertical position, in pixels, in the same space as `x`. */
123
+ y: number;
124
+ /** Horizontal scale factor: 1 draws the texture at its own width. */
125
+ scaleX: number;
126
+ /** Vertical scale factor: 1 draws the texture at its own height. */
127
+ scaleY: number;
128
+ /** Rotation, in radians, around the anchor. */
129
+ rotation: number;
130
+ /** Opacity, from 0 (invisible) to 1 (opaque). */
131
+ alpha: number;
132
+ /** Color multiplied over the texture, as a `0xRRGGBB` number; `0xffffff` leaves it as it is. */
133
+ tint: number;
134
+ /** Horizontal anchor as a fraction of the texture's width; 0.5 is the center. */
135
+ anchorX: number;
136
+ /** Vertical anchor as a fraction of the texture's height; 0.5 is the center. */
137
+ anchorY: number;
138
+ /** The texture drawn now; the sprite-sheet animation swaps it as frames advance. */
139
+ texture: ITextureRef;
140
+ /**
141
+ * Opaque backend slot (see `IParticleVisualState.renderHandle`). The render
142
+ * adapter stashes this particle's mirror object here so its per-frame sync
143
+ * skips a map lookup. Cleared on `reset()` before the item is recycled.
144
+ */
145
+ renderHandle: unknown;
146
+ /** Whether the particle is waiting in its pool rather than alive. Written by the engine; a host only reads it. */
147
+ inPool: boolean;
148
+ /**
149
+ * Id of the particle type this instance was spawned from
150
+ * (`ParticleLayerOptions.id`). `undefined` when the host supplied no id. The
151
+ * engine reads this on kill to keep its per-type alive counts accurate.
152
+ */
153
+ sourceParticleId: string | undefined;
154
+ /**
155
+ * The Particle Layer this instance was spawned from, or `null` while it is
156
+ * in the pool. The engine reads it on add/kill to route the particle to its
157
+ * own render group (one group per layer) — the layer itself rather than an
158
+ * index into its emitter, because a layer added or removed at runtime
159
+ * renumbers that index under every particle already alive.
160
+ *
161
+ * Reserved for the engine: private so a subclass cannot declare the name,
162
+ * and read by the engine's other classes as `particle['layer']`.
163
+ */
164
+ private layer;
165
+ /**
166
+ * The layer's list memory, captured at spawn so the update path points the
167
+ * context at it without going through the layer.
168
+ */
169
+ protected _listState: RandomListState;
170
+ protected _seed: number;
171
+ protected _spriteAnimation: ParticleSpriteAnimationParameters | null;
172
+ /**
173
+ * The state the layer's program keeps per particle: frozen
174
+ * bases of modulated values, the polar components of a recomposed vector,
175
+ * point-force factors, the `'particle'` locals it reads. Indexed by the
176
+ * layout of the program its layer runs (`compiledParameters.layout`), and only written by that program.
177
+ *
178
+ * Sized once to the most any layer of the emitter needs, so the pool can
179
+ * hand the same particle to any of them without allocating at birth;
180
+ * zeroed when the particle goes back to the pool.
181
+ *
182
+ * Reserved for the engine, as `layer`: the compiled operations reach it as `particle['mem']`.
183
+ */
184
+ private mem;
185
+ /**
186
+ * The emission transform it was born with: the layer's,
187
+ * its emitter's and the playback's, summed at birth. A position the layer
188
+ * writes live (Linked or modulated) is written over it, so a change of
189
+ * transform never moves a live particle.
190
+ *
191
+ * Reserved for the engine, as `layer`: the compiled operations reach it as `particle['bornX']`.
192
+ */
193
+ private bornX;
194
+ /** Reserved for the engine, as `bornX`. */
195
+ private bornY;
196
+ /** Horizontal velocity, in pixels per second. */
197
+ velocityX: number;
198
+ /** Vertical velocity, in pixels per second. */
199
+ velocityY: number;
200
+ /** Horizontal acceleration, in pixels per second squared. */
201
+ accelerationX: number;
202
+ /** Vertical acceleration, in pixels per second squared. */
203
+ accelerationY: number;
204
+ /** Rate of change of `scaleX`, per second. */
205
+ scaleVelocityX: number;
206
+ /** Rate of change of `scaleY`, per second. */
207
+ scaleVelocityY: number;
208
+ /** Rate of change of `scaleVelocityX`, per second squared. */
209
+ scaleAccelerationX: number;
210
+ /** Rate of change of `scaleVelocityY`, per second squared. */
211
+ scaleAccelerationY: number;
212
+ /** Rate of change of `rotation`, in radians per second. */
213
+ rotationVelocity: number;
214
+ /** Rate of change of `rotationVelocity`, in radians per second squared. */
215
+ rotationAcceleration: number;
216
+ /** Rate of change of `alpha`, per second. */
217
+ alphaVelocity: number;
218
+ /** Rate of change of `alphaVelocity`, per second squared. */
219
+ alphaAcceleration: number;
220
+ /** Cap on the absolute value of `velocityX`, in pixels per second; negative means no cap. */
221
+ maxVelocityX: number;
222
+ /** Cap on the absolute value of `velocityY`, in pixels per second; negative means no cap. */
223
+ maxVelocityY: number;
224
+ /** Cap on the absolute value of `scaleVelocityX`; negative means no cap. */
225
+ maxScaleVelocityX: number;
226
+ /** Cap on the absolute value of `scaleVelocityY`; negative means no cap. */
227
+ maxScaleVelocityY: number;
228
+ /** Cap on the absolute value of `rotationVelocity`, in radians per second; negative means no cap. */
229
+ maxRotationVelocity: number;
230
+ /** Cap on the absolute value of `alphaVelocity`; negative means no cap. */
231
+ maxAlphaVelocity: number;
232
+ /** How long the particle lives, in seconds; `Infinity` until its layer gives it one. */
233
+ lifetime: number;
234
+ /** Seconds lived so far. */
235
+ currentLife: number;
236
+ /** Fraction of the lifetime lived, from 0 to 1; 0 while `lifetime` is 0. */
237
+ lifeProgress: number;
238
+ /** How strongly the playback's gravity pulls this particle; 0 leaves it unaffected. */
239
+ gravityFactor: number;
240
+ /** How strongly the playback's damping slows this particle; 0 leaves it unaffected. */
241
+ dampingFactor: number;
242
+ /** How strongly the playback's wind pushes this particle; 0 leaves it unaffected. */
243
+ windFactor: number;
244
+ /** The shape of the region this particle is bound to, or `null` when it has none. */
245
+ regionShape: IShape | null;
246
+ /** Whether its region kills the particle inside it (`killInside`) or outside it (`killOutside`); `null` when it has none. */
247
+ regionBehavior: RegionBehavior | null;
248
+ /** Id of the assigned region, carried so region events can name it in their payload. */
249
+ regionId: string | null;
250
+ /**
251
+ * Which side of the region the particle was on last frame. `onRegionEnter` /
252
+ * `onRegionExit` fire on the change of side, so this is seeded at spawn with
253
+ * the particle's actual containment — being born inside is not an entry.
254
+ * Written by the engine; a host only reads it.
255
+ */
256
+ wasInsideRegion: boolean;
257
+ /**
258
+ * Event names bound to this particle's triggers, copied from its compiled
259
+ * parameters at spawn. The particle carries them because its triggers fire
260
+ * from the engine's update loop, far from the compiler that grouped them.
261
+ *
262
+ * Read-only for the particle's whole life: it points at the compiled group
263
+ * (shared by every particle of the type) or at the shared empty one.
264
+ * Written by the engine at birth and when the particle goes back to its pool.
265
+ */
266
+ events: Readonly<Record<ParticleEventTrigger, readonly string[]>>;
267
+ /**
268
+ * Time elapsed since the particle was born, in seconds. Alias of currentLife.
269
+ * When used as a linked-parameter source, particles with no configured lifetime
270
+ * (lifetime = Infinity) feed Infinity into the transfer function curve, which
271
+ * clamps to the curve's last y-value for the entire particle lifetime.
272
+ */
273
+ get lifeElapsed(): number;
274
+ /** The random value drawn for this particle at birth, from its emitter's generator. */
275
+ get seed(): number;
276
+ /** Same as `x`. */
277
+ get positionX(): number;
278
+ /** Same as `y`. */
279
+ get positionY(): number;
280
+ /** Speed, in pixels per second: the length of the velocity vector. */
281
+ get velocityMagnitude(): number;
282
+ /** Direction of the velocity vector, in radians, as `Math.atan2(velocityY, velocityX)`. */
283
+ get velocityAngle(): number;
284
+ /** Length of the acceleration vector, in pixels per second squared. */
285
+ get accelerationMagnitude(): number;
286
+ /** Direction of the acceleration vector, in radians, as `Math.atan2(accelerationY, accelerationX)`. */
287
+ get accelerationAngle(): number;
288
+ /**
289
+ * Per-particle sensitivity to each global point force that acts on it,
290
+ * keyed by force id. A new map on each read, built from the state the
291
+ * engine keeps for the particle: a factor of 0 — declared so, or cleared
292
+ * because the force was removed — leaves the force out, as the particle is
293
+ * unaffected by it.
294
+ */
295
+ get pointForceFactors(): ReadonlyMap<string, number>;
296
+ /**
297
+ * Configures sprite-sheet animation for this particle. All source ids are
298
+ * pre-resolved to `ITextureRef` via the renderer's cache here, so the hot
299
+ * update loop only indexes into the resolved array — no per-frame lookups.
300
+ */
301
+ setSpriteAnimation(options: SpriteAnimationTexturesOptions, renderer: IRenderer, rng?: {
302
+ next(): number;
303
+ }): void;
304
+ /**
305
+ * Reserved for the engine, which sets up through it every particle it takes
306
+ * from its pool. A subclass does its own setup in `onInit`: declaring a
307
+ * member of this name is a compile error, and there is nothing to call.
308
+ */
309
+ init(...reserved: never[]): never;
310
+ /**
311
+ * Reserved for the engine, which advances the particle's sprite-sheet
312
+ * animation through it on every tick. Declaring a member of this name is a
313
+ * compile error, and there is nothing to call.
314
+ */
315
+ updateTexture(...reserved: never[]): never;
316
+ /**
317
+ * Reserved for the engine, which steps every live particle through it on
318
+ * every tick. A subclass does its own step in `onUpdate`: declaring a member
319
+ * of this name is a compile error, and there is nothing to call.
320
+ */
321
+ updatePhysics(...reserved: never[]): never;
322
+ /**
323
+ * Reserved for the engine, which adds the playback's gravity, damping and
324
+ * wind through it. Declaring a member of this name is a compile error, and
325
+ * there is nothing to call.
326
+ */
327
+ updateEnvironment(...reserved: never[]): never;
328
+ /**
329
+ * Called once when the particle is born, after the engine has set it up and
330
+ * after its layer's `ParticleLayerOptions.onInit`. Empty here: a
331
+ * `ParticleClass` overrides it, as a method or as an arrow-function field.
332
+ * @param _options the particle, its emitter and the emitter's random generator.
333
+ */
334
+ onInit(_options: ParameterInitOptions): void;
335
+ /**
336
+ * Called on every tick the particle lives, after the engine has stepped it
337
+ * and after its layer's `ParticleLayerOptions.onUpdate`. Empty here, as `onInit`.
338
+ * @param _options the seconds elapsed in this step, the particle, its emitter and the emitter's random generator.
339
+ */
340
+ onUpdate(_options: ParameterUpdateOptions): void;
341
+ /**
342
+ * Reset all particle values to defaults. Called when the particle goes back to its pool.
343
+ * A `ParticleClass` with state of its own overrides it, calls `super.reset()`, and clears that state.
344
+ */
345
+ reset(): void;
346
+ /** Called when the engine discards the particle; clears it like `reset`. */
347
+ destroy(): void;
348
+ }
349
+
350
+ /**
351
+ * The default of one of an animation's locals: the only thing of the template
352
+ * the API changes. A table of values, not a configuration: it compiles nothing
353
+ * and the data is never written. Each instance copies the table when it is prepared, as
354
+ * pinned values, so a default reaches only the instances prepared after it:
355
+ * a Range, a List or a `'particle'` local stops being drawn in them, for the
356
+ * whole session and for every particle. An instance draws again with
357
+ * `pb.param(id).set(config)`.
358
+ *
359
+ * Built by `PerseonAnimation.param(id)`.
360
+ */
361
+ declare class LocalDefaultHandle {
362
+ /** The local's id, as `param` was given it. */
363
+ readonly id: string;
364
+ /** Built by the engine; a host gets it from `PerseonAnimation.param(id)`. */
365
+ private constructor();
366
+ /** The default, as it was set (a number clipped to the domain, or a label); `undefined` without one. */
367
+ get(): number | string | undefined;
368
+ /**
369
+ * Set the default to a number, clipped to the local's domain with a
370
+ * warning, or to one of its labels. A strategy is not a default: it is
371
+ * set on an instance. A rejected value throws a `PerseonConfigError` and
372
+ * leaves the entry as it was.
373
+ */
374
+ set(value: number | string): void;
375
+ /** Erase the entry: the instances prepared after it start from the data. */
376
+ reset(): void;
377
+ }
378
+
379
+ /**
380
+ * The addressable nodes of each scope: what
381
+ * `option(path)` reaches, the node type, when the engine reads it, and
382
+ * how a value for it is checked and clipped. The paths are those of the
383
+ * format, relative to the scope; `<id>` stands for the one open
384
+ * segment a point force, a region or a point force factor has.
385
+ *
386
+ * Left out, each for a reason of the design: identities (`id`), structure the
387
+ * editor rebuilds (`emitters`, `particles`), the lists changed by
388
+ * their own methods (`pointForces`, `regions`, `events`), the parameters
389
+ * (`param()`), functions and constructors, the animation's
390
+ * `randomness.seed` (a play option) and the inside of a node replaced whole
391
+ * (a texture's sprite fields, an event binding's trigger).
392
+ */
393
+ type OptionScope = 'playback' | 'emitter' | 'layer';
394
+ /** The four node types. */
395
+ type OptionNodeKind = 'value' | 'composite' | 'record' | 'constant';
396
+ /** When the engine reads a node; `ParameterDescription.stage`. */
397
+ type OptionStage = 'construction' | 'session' | 'cycle' | 'birth' | 'tick' | 'immediate';
398
+ /** A value's strategy; `ParameterDescription.strategy`. */
399
+ type OptionStrategy = 'fixed' | 'range' | 'list' | 'linked' | 'modulated';
400
+ interface OptionPathEntry {
401
+ /** As the dev writes it, with `<id>` for an open segment. */
402
+ readonly path: string;
403
+ readonly kind: OptionNodeKind;
404
+ readonly stage: OptionStage;
405
+ /**
406
+ * The strategies read at another stage than `stage`: a Fixed or Linked
407
+ * `rate` in the tick, a layer value in the tick when Linked or
408
+ * modulated. A composite that can be a single value (`scale.value`
409
+ * uniform, `color.value` as a live gradient) carries it too.
410
+ */
411
+ readonly stageByStrategy?: Readonly<Partial<Record<OptionStrategy, OptionStage>>>;
412
+ /**
413
+ * Throws on a shape the format does not have, a wrong type or a number that
414
+ * is not finite. A number out of the node's domain is not an error: it is
415
+ * `sanitize`'s to clip. `path` is the concrete path the
416
+ * errors name (`'regions.water.area'`); by default, the catalog's.
417
+ */
418
+ readonly validate: (value: unknown, path?: string) => void;
419
+ /**
420
+ * Every number clipped to its domain. The input is not touched: what it
421
+ * clips is rebuilt, but the rest may be the input's own objects (a node
422
+ * with nothing to clip, an event binding, a region reference, comes back
423
+ * as the same reference). `set` takes its own deep copy of the config before it sanitizes it.
424
+ */
425
+ readonly sanitize: (value: unknown) => unknown;
426
+ /**
427
+ * The domain a plain number of this node is clipped to, when one is all
428
+ * `validate` and `sanitize` do with it (a constant number, an emitter
429
+ * value): a shortcut checks and clips it in place, with nothing built.
430
+ */
431
+ readonly numberDomain?: NumericDomain;
432
+ /** The same for each number of a node that is a pair of them (the wind). */
433
+ readonly pairDomains?: Readonly<Record<string, NumericDomain>>;
434
+ }
435
+ declare const OPTION_PATH_CATALOG: Readonly<Record<OptionScope, readonly OptionPathEntry[]>>;
436
+ /**
437
+ * The entry of a concrete path (`'pointForces.toCounter.position'`), or
438
+ * `undefined` if the scope has no such node. The id is a single segment, as
439
+ * the names of emitters, regions and point forces take no dot:
440
+ * `'pointForces.a.position'` is the `position` of the force `'a'`, and
441
+ * `'pointForces.a.b'` names no node. Whether the id exists is the caller's to
442
+ * check, against the ids it has.
443
+ */
444
+ declare const findOptionPathEntry: (scope: OptionScope, path: string) => OptionPathEntry | undefined;
445
+
446
+ /**
447
+ * What a recoverable misuse does (`PerseonOptions.diagnostics`):
448
+ * `'warn'` prints it once, `'throw'` turns it into an error, `'silent'` drops it.
449
+ */
450
+ type DiagnosticsPolicy = 'warn' | 'throw' | 'silent';
451
+
452
+ /**
453
+ * The handle of one of the animation's locals in one instance: the pair
454
+ * (instance, id), which holds nothing of the local. Two handles of one id are
455
+ * two views of it; what they read and write is the instance's: its pins and
456
+ * its overlay.
457
+ *
458
+ * - `set(number | label)` pins the value, clipped to the declared domain, in
459
+ * every store of the local's scope, and drops a substituted strategy. No
460
+ * draw or Linked evaluation overwrites it, and each node that reads it
461
+ * notices it at its stage: a Linked of the tick at once, what
462
+ * is read at birth in the particles born after. A `'particle'` local is
463
+ * the particle's own: those alive keep theirs. Nothing is
464
+ * built nor allocated: it is the game loop's call.
465
+ * - `set(config)` substitutes the local's strategy, in this instance only,
466
+ * with copy-on-write units, and unpins it. It takes effect at the scope's
467
+ * next draw: the next session, the next cycle, or the particles born after;
468
+ * until then the local keeps its value. A unit that starts reading a local through it draws that local in
469
+ * the act, unless it is pinned.
470
+ * - The last call wins. `reset()` drops both and goes back to the value the
471
+ * instance started from: the template's default it copied, or the data.
472
+ *
473
+ * Built by `PerseonPlayback.param(id)`, with the generation of that playback:
474
+ * once it is over, `set` and `reset` change nothing and say so, as a node's handle does.
475
+ */
476
+ declare class LocalParameterHandle {
477
+ /** The local's id, as `param` was given it. */
478
+ readonly path: string;
479
+ /** Always `'value'`: a local is a single value, whatever strategy it holds. */
480
+ readonly kind = "value";
481
+ /** Built by the engine; a host gets it from `PerseonPlayback.param(id)`. */
482
+ private constructor();
483
+ /** A local is always there: it has no parent whose mode could leave it out. */
484
+ get active(): boolean;
485
+ /** Whether the instance set the local: a pin of its own or a strategy it substituted, not a default it copied. */
486
+ get overridden(): boolean;
487
+ /** Whether no draw or evaluation overwrites the local: the instance set a number, or copied a default. */
488
+ get pinned(): boolean;
489
+ /**
490
+ * The local's value in this instance, the label in a `'label'` local. A
491
+ * `'playback'` one has one value, whatever its strategy. An `'emitter'` or
492
+ * `'particle'` one has a value per emitter or per particle, so it has none
493
+ * of its own unless it is pinned: then `undefined`.
494
+ */
495
+ get current(): number | string | undefined;
496
+ /**
497
+ * A copy of the local's config in this instance: the number it is pinned
498
+ * to (a label's index, as the format holds it), the strategy it
499
+ * substituted, or the data's.
500
+ */
501
+ get(): CustomParameterValue;
502
+ /**
503
+ * A number or a label pins the local; a config (Fixed, Range, List,
504
+ * Linked) substitutes its strategy. A rejected one throws a
505
+ * `PerseonConfigError` and leaves the instance as it was.
506
+ */
507
+ set(value: CustomParameterValue | string): void;
508
+ /**
509
+ * Drop the pin and the substitution: the local goes back to the default
510
+ * the instance copied from the template, if any, and if not to the data.
511
+ * On a local the instance never touched it does nothing.
512
+ */
513
+ reset(): void;
514
+ /**
515
+ * What the local is in this instance: a pinned one takes
516
+ * effect at once; a Linked one is read in each tick; any other, at its
517
+ * scope's draw. A read of shape, allowed in a dead handle.
518
+ */
519
+ describe(): ParameterDescription;
520
+ }
521
+
522
+ /**
523
+ * Why a play session ended: it ran its course (`'completed'`), or
524
+ * a host called `stop()`, `release()` or `destroy()`, or destroyed the
525
+ * container it draws under (`'hostDestroyed'`).
526
+ */
527
+ type PlaybackFinishedReason = 'completed' | 'stopped' | 'released' | 'destroyed' | 'hostDestroyed';
528
+ /** How a play session ended, handed to `finished` and to the `onFinished` listeners alike. */
529
+ interface PlaybackFinishedResult {
530
+ readonly reason: PlaybackFinishedReason;
531
+ }
532
+
533
+ /** What `describe()` tells of a node. */
534
+ interface ParameterDescription {
535
+ /** The node's path from its owner, as `option` was given it. */
536
+ path: string;
537
+ /** The kind of node: a value, a composite, a record or a constant. */
538
+ kind: OptionNodeKind;
539
+ /** When the engine reads the node with the strategy it has now. */
540
+ stage: OptionStage;
541
+ /** A value's strategy, and a composite's when it is a single value. */
542
+ strategy?: OptionStrategy;
543
+ /** A composite's mode: `'axes'`, `'polar'`, `'area'`, `'list'`, `'uniform'`, `'gradient'`. */
544
+ mode?: string;
545
+ /** The range a number of the node is clipped to; not in a node without a single one (a record, the wind's pair). */
546
+ domain?: NumericDomain;
547
+ /** Whether the instance sets this node, or a node that holds it or that it holds. */
548
+ overridden: boolean;
549
+ /** Only a local is pinned (`param(id)`): never a node of `option()`. */
550
+ pinned: boolean;
551
+ /** `false` while the node's parent is in a mode without it. */
552
+ active: boolean;
553
+ /**
554
+ * In a record, the stage of each field it holds, by the field's strategy:
555
+ * a block (`kinetics`, `alpha`…) is read at birth, but its `maxVelocity`
556
+ * is read in the tick, and so is a Linked or modulated value.
557
+ */
558
+ fields?: Record<string, OptionStage>;
559
+ }
560
+ /**
561
+ * The handle of one node of an instance: the pair (owner, path), which no
562
+ * change of strategy or mode invalidates. It holds nothing of the node: two
563
+ * handles of one path are two views of the same node, and what they read and
564
+ * write is the instance's overlay: one holder per node set, the playback's
565
+ * nodes and the emitter's fields included.
566
+ *
567
+ * `set` validates the whole config against what the instance runs, copies,
568
+ * clips with a warning and freezes it, and takes effect the
569
+ * next time the engine reads the node. Without a change of shape it
570
+ * rebuilds only the unit that holds the node. Never in the tick.
571
+ *
572
+ * Built by `option(path)` of the playback, an emitter or a layer. It carries
573
+ * the generation of the playback that handed it out: once
574
+ * that playback is over, `set`, `reset` and the rest change nothing and say
575
+ * so, by the animation's diagnostics policy, even if the instance has a new
576
+ * owner by then. What it reads is the instance's, as it is.
577
+ */
578
+ declare class ParameterHandle<T> {
579
+ /** The node's path from its owner, as `option` was given it. */
580
+ readonly path: string;
581
+ /** Built by the engine; a host gets it from `option(path)` of a playback, an emitter or a layer. */
582
+ private constructor();
583
+ /** The kind of node this handle points at: a value, a composite, a record or a constant. */
584
+ get kind(): OptionNodeKind;
585
+ /** false while its parent is in a mode without this node: then `get`, `set` and `current` throw. */
586
+ get active(): boolean;
587
+ /** Whether the instance sets this node, or a node that holds it or that it holds. */
588
+ get overridden(): boolean;
589
+ /** Always `false`: only a local, through `param(id)`, is pinned. */
590
+ get pinned(): boolean;
591
+ /**
592
+ * The value in force, in a node of the playback or an emitter: the number
593
+ * or label of a Fixed or constant node, what a drawn or Linked value
594
+ * holds now (`spawnRate`…). `undefined` in a layer, whose values are each
595
+ * particle's, and in a node that is not a number nor a label.
596
+ */
597
+ get current(): number | string | undefined;
598
+ /** A copy of the config in force: the instance's, or the data's. */
599
+ get(): T;
600
+ /**
601
+ * The node's whole config, in the shape of the format. Validated
602
+ * against what the instance runs before anything changes: a rejected one
603
+ * throws a `PerseonConfigError` and leaves the instance as it was.
604
+ */
605
+ set(config: T | number | string): void;
606
+ /**
607
+ * Take the node back to the data: drop what the instance set at
608
+ * it and under it. A node it holds through a node above it (a field of a
609
+ * block set whole) takes the data's value there. On a node never set, or
610
+ * inactive, it does nothing.
611
+ */
612
+ reset(): void;
613
+ /** Describe the node: its kind, the stage the engine reads it at, its strategy and mode, and whether the instance overrides it. */
614
+ describe(): ParameterDescription;
615
+ }
616
+
617
+ /** Translation of the emission coordinates. */
618
+ interface EmissionTransform {
619
+ x: number;
620
+ y: number;
621
+ }
622
+
623
+ /**
624
+ * One layer of an emitter of a playback, as the host sees it: the
625
+ * host's view of one layer of the emitter, made by the emitter the first time
626
+ * it is asked and kept there. It answers for its playback's generation, as the
627
+ * emitter does: once it is over, what it is asked to change does nothing and
628
+ * its counts are 0.
629
+ */
630
+ declare class ParticleLayerView {
631
+ /** Host-supplied id (`ParticleLayerOptions.id`); `undefined` when not given. */
632
+ readonly id: string | undefined;
633
+ /**
634
+ * How the layer's particles blend with what is behind them, as `ParticleLayerOptions.blendMode` declared;
635
+ * fixed for the playback.
636
+ */
637
+ readonly blendMode: ParticleBlendMode;
638
+ /** Built by the engine; a host gets it from `Emitter.layers`. */
639
+ private constructor();
640
+ /** Draw order among the layers of its emitter; higher draws on top. */
641
+ get zIndex(): number;
642
+ set zIndex(value: number);
643
+ /**
644
+ * Whether this layer is drawn; drawn only while its emitter is drawn too.
645
+ * Hidden, it still spawns, simulates, counts and fires its events.
646
+ * Starts as `ParticleLayerOptions.visible` and goes back to it in the pool.
647
+ */
648
+ get visible(): boolean;
649
+ set visible(value: boolean);
650
+ /** Live particles spawned from this layer; 0 once its playback is over. */
651
+ get aliveCount(): number;
652
+ /** Particles currently drawn by this layer; 0 once its playback is over. */
653
+ get size(): number;
654
+ /**
655
+ * The handle of one of this layer's nodes, by its
656
+ * path from the layer: `'alpha.value'`, `'kinetics.position'`. It answers
657
+ * for this view's playback.
658
+ */
659
+ option<P extends LayerOptionPath>(path: P): ParameterHandle<LayerOptionType<P>>;
660
+ /**
661
+ * This layer's emission transform: added, with its
662
+ * emitter's and the playback's, to where each of its particles is born. The same
663
+ * object every time it is asked.
664
+ */
665
+ get transform(): EmissionTransform;
666
+ }
667
+
668
+ /**
669
+ * One emitter of a playback, as the host sees it: the host's view
670
+ * of one emitter of the playback, made by the playback the first time it is
671
+ * asked and kept there. It answers for that playback's generation: once the
672
+ * playback is over, what it is asked to change does nothing and says so, as
673
+ * the playback does, and what it reads of the session answers for the
674
+ * generation that ended (not emitting, finished, no particles). What it reads
675
+ * of its shape and config is the emitter's, as it is.
676
+ *
677
+ * It only stands between the host and the emitter: the tick never goes
678
+ * through it.
679
+ */
680
+ declare class EmitterView {
681
+ /** Host-supplied id (`EmitterOptions.id`); `undefined` when not given. */
682
+ readonly id: string | undefined;
683
+ /** Built by the engine; a host gets it from `PerseonPlayback.emitters` or `getEmitter(id)`. */
684
+ private constructor();
685
+ /** The playback this view belongs to. */
686
+ get playback(): PerseonPlayback;
687
+ /** Whether the emission is open. Setting it opens or closes it; set from inside an update, it applies when that tick ends. */
688
+ get spawn(): boolean;
689
+ set spawn(value: boolean);
690
+ /** Particles of a burst, born in one frame. 0 when the emitter emits at a rate instead. Read at the next cycle. */
691
+ get spawnCount(): number;
692
+ set spawnCount(value: number);
693
+ /** Particles per second while a rate emission runs. 0 means no rate emission. */
694
+ get spawnRate(): number;
695
+ set spawnRate(value: number);
696
+ /** Seconds a rate emission lasts per cycle; 0 means it never ends. */
697
+ get spawnDuration(): number;
698
+ set spawnDuration(value: number);
699
+ /** Seconds the emitter waits after a session starts before it begins to emit. */
700
+ get startDelay(): number;
701
+ set startDelay(value: number);
702
+ /** How many times the emission cycle repeats after the first. The highest value allowed means forever. */
703
+ get repeat(): number;
704
+ set repeat(value: number);
705
+ /** Seconds between the end of one emission cycle and the start of the next. */
706
+ get repeatInterval(): number;
707
+ set repeatInterval(value: number);
708
+ /** Seconds of simulation run when a session starts (warm-up), so the emitter begins already populated. Capped by `effectiveWarmUpMaxTicks`. */
709
+ get simulateTime(): number;
710
+ set simulateTime(value: number);
711
+ /** Minimum number of live particles to have once the warm-up ends; the emitter spawns up to it, within `maxPoolSize`. */
712
+ get ensureAliveCount(): number;
713
+ set ensureAliveCount(value: number);
714
+ /** Shortcut of `option('capacity.maxAlive')`, read at the next birth. */
715
+ get maxPoolSize(): number;
716
+ set maxPoolSize(value: number);
717
+ /** Shortcut of `option('capacity.limitStrategy')`, read at the next birth. */
718
+ get particleLimitStrategy(): ParticleLimitStrategy;
719
+ set particleLimitStrategy(value: ParticleLimitStrategy);
720
+ /** Shortcut of `option('emission.spawnStrategy')`, read at the next birth. */
721
+ get particleSpawnStrategy(): ParticleSpawnStrategy;
722
+ set particleSpawnStrategy(value: ParticleSpawnStrategy);
723
+ /**
724
+ * Warm-up tick budget: the animation's is the default and the ceiling.
725
+ * Only `undefined` inherits it; the getter gives what was assigned, or
726
+ * `undefined` when inheriting.
727
+ */
728
+ get warmUpMaxTicks(): number | undefined;
729
+ /** The warm-up tick budget in force: the lower of this emitter's and the animation's. */
730
+ get effectiveWarmUpMaxTicks(): number;
731
+ set warmUpMaxTicks(value: number | undefined);
732
+ /** Simulation rate, like `warmUpMaxTicks`: the animation's is the default and the ceiling. */
733
+ get maxUpdateRate(): number | undefined;
734
+ /** The simulation rate in force: the lower of this emitter's and the animation's. */
735
+ get effectiveMaxUpdateRate(): number;
736
+ set maxUpdateRate(value: number | undefined);
737
+ /** Whether the emission is open (`spawn`) while the playback is running; false once the playback is over. */
738
+ get isEmitting(): boolean;
739
+ /** Whether this emitter can never spawn again before a reset. */
740
+ get isExhausted(): boolean;
741
+ /** Whether it can never spawn again and nothing it spawned is alive. */
742
+ get isFinished(): boolean;
743
+ /** Live particles of this emitter, across all its layers; 0 once its playback is over. */
744
+ get numberOfParticles(): number;
745
+ /** Live particles spawned from the given particle-type id. 0 for unknown ids. */
746
+ getParticlesAliveById(particleId: string): number;
747
+ /** Its layers, in compiled order: views of this playback, the same objects every time. */
748
+ get layers(): readonly ParticleLayerView[];
749
+ /** A layer by its host-supplied id (`ParticleLayerOptions.id`), or `undefined` when unknown. */
750
+ getLayer(id: string): ParticleLayerView | undefined;
751
+ /**
752
+ * Re-sequence the draw order of this emitter's layers, bottom to top;
753
+ * layers left out keep their relative order after the listed ones.
754
+ */
755
+ setLayerOrder(layerIndices: number[]): void;
756
+ /**
757
+ * The handle of one of this emitter's nodes, by its
758
+ * path from the emitter: `'emission.rate'`, `'playback.startDelay'`. It
759
+ * answers for this view's playback.
760
+ */
761
+ option<P extends EmitterOptionPath>(path: P): ParameterHandle<EmitterOptionType<P>>;
762
+ /** Whether this emitter (and its layers) are drawn. */
763
+ get visible(): boolean;
764
+ set visible(value: boolean);
765
+ /**
766
+ * This emitter's emission transform: added, with its layer's and the
767
+ * playback's, to where each of its particles is born. It moves no node and
768
+ * no live particle. The same object every time it is asked.
769
+ */
770
+ get transform(): EmissionTransform;
771
+ }
772
+
773
+ /**
774
+ * What every integration is, minus the host.
775
+ *
776
+ * `@silentstatestudio/perseon/pixi-v8` and `@silentstatestudio/perseon/pixi-v7` each export a `Perseon` — same name, one
777
+ * import path apart — and both are this class plus a constructor that turns
778
+ * their host's objects into a renderer. That split is the whole argument for a
779
+ * class per integration: what a host needs cannot be unified without lying
780
+ * (Pixi hands over a ticker, Three has none and steps the world itself, Canvas
781
+ * 2D has a context and no scene graph at all), while what happens above the
782
+ * renderer is identical everywhere and belongs here, once.
783
+ *
784
+ * So a backend is an `IRenderer` plus a constructor. Everything below — pooling,
785
+ * seeding, the single frame callback, teardown — comes for free, and none of it
786
+ * can drift between backends.
787
+ *
788
+ * The ticker is optional for the same reason. Given one, every playback shares a
789
+ * single subscription to it; given none, they share the renderer's. A host that
790
+ * does not run on a Pixi ticker, and steps the world from its own loop, passes an
791
+ * `ITicker` of its own and calls its listeners with each frame's delta.
792
+ */
793
+ declare class PerseonIntegration<TParent = unknown> {
794
+ /**
795
+ * The renderer every animation is built with. Public because a host that
796
+ * needs the layer below — resolving a texture by hand, dropping the texture
797
+ * cache after republishing an atlas, or driving a `PerseonPlayback` of its
798
+ * own, as the editor does — should not have to build a second one.
799
+ */
800
+ readonly renderer: IRenderer<TParent>;
801
+ /**
802
+ * @param renderer the backend, built by the integration from its host's own
803
+ * objects.
804
+ * @param ticker the host's frame source. Optional because the renderer
805
+ * usually carries it already; pass one only to override that.
806
+ *
807
+ * Whether an integration is manual is therefore decided by the **renderer**,
808
+ * which is where the answer actually lives — a Pixi adapter has a ticker, a
809
+ * Three one does not. Deciding it by whether this argument was passed would
810
+ * make a backend author who simply forgot it end up with animations that
811
+ * mount, never advance and report nothing wrong.
812
+ * @param diagnostics what a recoverable misuse (an unresolved source, a
813
+ * clip, a stale handle) does: `'warn'` prints it once per animation,
814
+ * `'throw'` turns it into an error, `'silent'` drops it. `'warn'` by default.
815
+ */
816
+ constructor(renderer: IRenderer<TParent>, ticker?: ITicker, diagnostics?: DiagnosticsPolicy);
817
+ /** Every animation created here and not destroyed. */
818
+ get animations(): readonly PerseonAnimation<TParent>[];
819
+ /**
820
+ * The ticker handed to every playback: one subscription to the host's frame
821
+ * source, fanned out in order. It only listens while something is playing.
822
+ */
823
+ get ticker(): ITicker;
824
+ /** Whether `destroy()` has run. */
825
+ get isDestroyed(): boolean;
826
+ /**
827
+ * Compile one animation config, ready to be played. This is the expensive
828
+ * call — it walks and validates the whole option tree — so it belongs with
829
+ * asset loading, not with the impact that needs the explosion.
830
+ */
831
+ createAnimation(options: ParticleAnimationOptions): PerseonAnimation<TParent>;
832
+ /**
833
+ * The game's value of the global `id` for every animation that declares
834
+ * it, before or after this call. Each one
835
+ * reads it clipped to the domain IT declares (a label, as its index
836
+ * there) from its next tick on. A label an animation does not declare,
837
+ * or a value of the other type (a label for a number global, a number for
838
+ * a label one), leaves that animation's global at its `value`, and that
839
+ * animation says so, once per global.
840
+ *
841
+ * Meant for every frame: nothing is allocated once `id` was set. An id no
842
+ * live animation declares is kept for the animations that come, and not
843
+ * told: who reads the game's state is not the game's business. A number that is not finite throws a `PerseonConfigError`.
844
+ */
845
+ setGlobalParameter(id: string, value: number | string): void;
846
+ /**
847
+ * What the game set for the global `id`, as it set it (not clipped: each
848
+ * animation clips to its own domain), or `undefined` until it does.
849
+ */
850
+ getGlobalParameter(id: string): number | string | undefined;
851
+ /**
852
+ * Listen to an event of every playback of every animation created here,
853
+ * before or after this call: `listener` is handed one
854
+ * `PerseonEvent`, whose `target` and `animation` say who fired it, after
855
+ * the listeners of the playback and of the animation.
856
+ *
857
+ * The name is not checked: an animation that declares it may come later,
858
+ * and a name no animation fires never reaches the listener.
859
+ *
860
+ * @returns an unsubscribe function, which takes out this registration and
861
+ * no other: the same function registered twice is two registrations.
862
+ */
863
+ on(eventName: string, listener: (event: PerseonEvent) => void): Unsubscribe;
864
+ /**
865
+ * Tear the integration down: every animation, every playback of each, the
866
+ * frame subscription and the renderer's own resources. The host's ticker is
867
+ * the host's and is left running.
868
+ */
869
+ destroy(): void;
870
+ }
871
+
872
+ /**
873
+ * What a host passes to a playback it builds without a pool: the `Perseon` whose globals it reads. Without it, every global holds
874
+ * the `value` its config declares.
875
+ */
876
+ interface PlaybackHost {
877
+ /**
878
+ * A `Perseon` (or `PerseonIntegration`) of any parent type: the playback
879
+ * reads only its globals, the values `setGlobalParameter` sets on it. Any
880
+ * other object has none to read: the playback says so through the
881
+ * diagnostics, and every global holds the `value` its config declares.
882
+ */
883
+ globals?: Pick<PerseonIntegration, 'setGlobalParameter' | 'getGlobalParameter'>;
884
+ }
885
+ /**
886
+ * One playback of an animation, as the host holds it: the handle of one
887
+ * generation of an instance the animation pools, with the surface a playback
888
+ * has always had.
889
+ *
890
+ * `animation.play()` and `prepare()` hand out a new one each time. When its
891
+ * instance goes back to the pool (the natural end with `autoRelease`, or
892
+ * `release()`) or is destroyed, the
893
+ * generation of the instance goes up and this handle is over: `alive` is
894
+ * `false`, and whatever is asked of it — or of what it handed out: its
895
+ * `param` and `option` handles, its emitter and layer views, its
896
+ * `Unsubscribe`s — does nothing and says so by the animation's diagnostics
897
+ * policy (`'warn'` once, `'throw'`, `'silent'`). So a late `stop()` cannot
898
+ * stop whoever plays the instance next. What it reads of the session answers
899
+ * for its own generation, which ended: not running, not paused, not
900
+ * emitting, finished, no particles, and `finished` resolved with how it
901
+ * ended. What it reads of its shape and config (`emitters`, `seed`, the
902
+ * forces…) is silent and is the instance's as it is now.
903
+ *
904
+ * A host with no pool builds one directly, as it always could:
905
+ *
906
+ * ```ts
907
+ * const playback = new PerseonPlayback(options, renderer)
908
+ * ```
909
+ *
910
+ * That instance has no pool, so nothing takes it back: its generation is
911
+ * fixed, it is `alive` until `destroy()`, and what it was set survives
912
+ * `reset()`, `stop()` and the natural end, which leaves it stopped for
913
+ * `start()` to play it again. Given `{ globals: perseon }`, it
914
+ * reads the globals the game sets on that `Perseon`, live:
915
+ *
916
+ * ```ts
917
+ * const playback = new PerseonPlayback(options, renderer, ticker, { globals: perseon })
918
+ * ```
919
+ *
920
+ * The tick runs on the instance, never through the handle: the handle only
921
+ * stands between the host and the instance.
922
+ */
923
+ declare class PerseonPlayback {
924
+ /**
925
+ * @param config the animation — pure configuration, straight from a scene
926
+ * file. Holds no live object.
927
+ * @param renderer the host's renderer, which the animation cannot carry
928
+ * because it is host infrastructure rather than configuration.
929
+ * @param ticker optional override. When omitted the renderer's own ticker
930
+ * drives the playback, which is what a host wants unless it runs the
931
+ * simulation from its own game loop.
932
+ * @param host the `Perseon` whose globals it reads (`{ globals }`); without
933
+ * it, every global holds the `value` its config declares.
934
+ */
935
+ constructor(config: ParticleAnimationOptions, renderer: IRenderer, ticker?: ITicker, host?: PlaybackHost);
936
+ /**
937
+ * `false` once its instance went back to the pool or was destroyed: from
938
+ * then on whatever is asked of this playback does nothing.
939
+ */
940
+ get alive(): boolean;
941
+ /** The renderer this playback draws with: its `Perseon`'s, or the one passed to `new PerseonPlayback`. */
942
+ get renderer(): IRenderer;
943
+ /**
944
+ * The handle of one of this playback's nodes, by
945
+ * its path from the playback: `'externalForces.gravity'`,
946
+ * `'pointForces.toCounter.position'`, `'regions.water.area'`. Throws a
947
+ * `PerseonConfigError` for a path a playback does not have. It answers for
948
+ * this playback: once it is over, it changes nothing.
949
+ */
950
+ option<P extends PlaybackOptionPath>(path: P): ParameterHandle<PlaybackOptionType<P>>;
951
+ /**
952
+ * The handle of one of the animation's locals in this playback:
953
+ * `set(number | label)` pins its value, `set(config)`
954
+ * substitutes its strategy, `reset()` goes back to the template's default
955
+ * or to the data. Throws a `PerseonConfigError` for an id that is not a
956
+ * local. It answers for this playback: once it is over, it changes nothing.
957
+ */
958
+ param(id: string): LocalParameterHandle;
959
+ /**
960
+ * Every emitter of the animation, in declaration order: views of this
961
+ * playback, the same objects every time it is asked.
962
+ */
963
+ get emitters(): readonly EmitterView[];
964
+ /** An emitter by its host-supplied id, or `undefined` when unknown. */
965
+ getEmitter(id: string): EmitterView | undefined;
966
+ /** Live particles across every emitter; 0 once the playback is over. */
967
+ get numberOfParticles(): number;
968
+ /** Live particles spawned from the given particle-type id, across every emitter; 0 once it is over. */
969
+ getParticlesAliveById(particleId: string): number;
970
+ /** The playback's seed, or `undefined` when it was not given one. */
971
+ get seed(): number | undefined;
972
+ /** Total simulated time in seconds. */
973
+ get elapsedTotal(): number;
974
+ /** Simulation rate of the whole animation, and the ceiling of every emitter's. */
975
+ get maxUpdateRate(): number;
976
+ set maxUpdateRate(value: number);
977
+ /**
978
+ * The factor of this playback's simulated step, 1 by
979
+ * default: 0.2 is bullet time, 0 freezes it without pausing. The gate of
980
+ * `maxUpdateRate` counts real time. Throws a `PerseonConfigError` for a
981
+ * negative or non-finite value, also in `play`/`prepare`.
982
+ */
983
+ get timeScale(): number;
984
+ set timeScale(value: number);
985
+ /** Warm-up tick budget of the animation: the default and the ceiling of every emitter's. */
986
+ get warmUpMaxTicks(): number;
987
+ set warmUpMaxTicks(value: number);
988
+ /**
989
+ * Whether its instance goes back to the pool at its natural end. `play()` brings it at `true`: fire and forget. `prepare()` at
990
+ * `false`: the playback is the game's, and at its natural end it is left
991
+ * stopped (`isRunning` false, `isFinished` true), still alive, and
992
+ * `start()` plays it again as a new session; it goes back with
993
+ * `release()`, or by setting this to `true`, which gives it back in the
994
+ * act if it is already stopped at its end. A `stop()` is the host's and
995
+ * never gives it back. One built with `new PerseonPlayback` has no pool:
996
+ * it is `false`, and its natural end always leaves it stopped.
997
+ */
998
+ get autoRelease(): boolean;
999
+ set autoRelease(value: boolean);
1000
+ /** Whether its session is running; `false` once the playback is over. */
1001
+ get isRunning(): boolean;
1002
+ /** Whether its session is paused; `false` once the playback is over. */
1003
+ get isPaused(): boolean;
1004
+ /**
1005
+ * Put this animation under a container of the host's own graph, or move it
1006
+ * to another one. Nothing is drawn until it is mounted somewhere.
1007
+ */
1008
+ mount(parent: unknown): void;
1009
+ /** Detach without destroying. */
1010
+ unmount(): void;
1011
+ /** Position of the whole animation within its parent. */
1012
+ get x(): number;
1013
+ set x(value: number);
1014
+ /** Vertical position of the whole animation within its parent, like `x`. */
1015
+ get y(): number;
1016
+ set y(value: number);
1017
+ /**
1018
+ * The playback's emission transform: added to where every
1019
+ * particle of the animation is born, without moving any node or any live
1020
+ * particle. `x`/`y` place the node; this moves only the origin of what is
1021
+ * born afterwards, which is what a trail writes every frame. The
1022
+ * same object every time it is asked.
1023
+ */
1024
+ get transform(): EmissionTransform;
1025
+ /** Hide or show the whole animation. Hiding does not pause the simulation. */
1026
+ get visible(): boolean;
1027
+ set visible(value: boolean);
1028
+ /** Whether `destroy()` has run on its instance. */
1029
+ get isDestroyed(): boolean;
1030
+ /** Whether any emitter is currently emitting; `false` once the playback is over. */
1031
+ get isEmitting(): boolean;
1032
+ /**
1033
+ * Whether the animation has run its course: no emitter can emit again and
1034
+ * nothing spawned is still alive. `true`
1035
+ * once the playback is over: its generation ended.
1036
+ */
1037
+ get isFinished(): boolean;
1038
+ /**
1039
+ * Subscribe to the end of a play session of this playback, told with its
1040
+ * `reason`: `'completed'`, `'stopped'`, `'released'`, `'destroyed'` or
1041
+ * `'hostDestroyed'`. Only the ends of this playback's generation reach it.
1042
+ *
1043
+ * @returns an unsubscribe function, which takes out this registration and
1044
+ * no other — never the same function registered by a later owner of the
1045
+ * instance. Calling it once the playback is over is harmless.
1046
+ */
1047
+ onFinished(listener: (result: PlaybackFinishedResult) => void): () => void;
1048
+ /**
1049
+ * The end of this play session, as something a host can `await`. It
1050
+ * resolves and never rejects, with the `{ reason }` the `onFinished`
1051
+ * listeners are told. Once the playback is
1052
+ * over it stays resolved with how its generation ended, whoever plays the
1053
+ * instance afterwards.
1054
+ */
1055
+ get finished(): Promise<PlaybackFinishedResult>;
1056
+ /** Gravitational acceleration applied to the particles whose layer declares a gravity factor. */
1057
+ get gravity(): number;
1058
+ set gravity(value: number);
1059
+ /** Movement damping that opposes the particles' velocity, for the layers that declare a damping factor. */
1060
+ get damping(): number;
1061
+ set damping(value: number);
1062
+ /** `damping` scaled to the constant the physics step integrates with; read-only. */
1063
+ get dampingCoefficient(): number;
1064
+ /** A copy: writing to it does not change the wind. */
1065
+ get wind(): PointValue;
1066
+ set wind(value: PointValue);
1067
+ /** A copy, like `wind`. */
1068
+ get windVector(): VectorValue;
1069
+ set windVector(value: VectorValue);
1070
+ /** Strength of the wind, the `magnitude` of `windVector`; read-only, set it through `windVector`. */
1071
+ get windMagnitude(): number;
1072
+ /** Direction of the wind in radians, the `angle` of `windVector`; read-only, set it through `windVector`. */
1073
+ get windAngle(): number;
1074
+ /** Register a point force, or put it over the one with its id: a shortcut of `set` on `pointForces.<id>`. */
1075
+ addPointForce(config: PointForceConfig): void;
1076
+ /** Patch a point force by id: the patch is merged with the force and the whole of it is `set`. */
1077
+ updatePointForce(id: string, patch: Partial<Omit<PointForceConfig, 'id'>>): void;
1078
+ /** Remove a point force from this instance. No-op for unknown ids. */
1079
+ removePointForce(id: string): void;
1080
+ /** Snapshot of all registered point forces (enabled and disabled). */
1081
+ getPointForces(): PointForceConfig[];
1082
+ /** A single point force config by id, or `undefined` when unknown. */
1083
+ getPointForce(id: string): PointForceConfig | undefined;
1084
+ /** Register a region, or put it over the one with its id: a shortcut of `set` on `regions.<id>`. */
1085
+ addRegion(region: RegionOptions): void;
1086
+ /** Ids of every declared region. */
1087
+ get regionIds(): Set<string>;
1088
+ /**
1089
+ * Listen to an event of this playback: `listener` is
1090
+ * handed one `PerseonEvent`, synchronously, at the point of the loop where
1091
+ * the trigger happens, before the listeners of its animation and of
1092
+ * `Perseon`. The listeners of a playback stay through `stop()` and
1093
+ * `reset()` and go when its instance goes back to the pool.
1094
+ *
1095
+ * Throws for a name the playback does not register (`getEventNames()`),
1096
+ * whatever the diagnostics policy: a typo would otherwise listen forever
1097
+ * to nothing.
1098
+ *
1099
+ * @returns an unsubscribe function, which takes out this registration and
1100
+ * no other: the same function registered twice is two registrations. Once
1101
+ * the playback is over it does nothing and says so by the diagnostics
1102
+ * policy.
1103
+ */
1104
+ on(eventName: string, listener: (event: PerseonEvent) => void): Unsubscribe;
1105
+ /** Whether `eventName` is registered and can therefore fire. */
1106
+ hasEvent(eventName: string): boolean;
1107
+ /** Register an event name. Idempotent; blank names are ignored. */
1108
+ addEventName(eventName: string): void;
1109
+ /**
1110
+ * Unregister an event name and drop its listeners.
1111
+ * @returns whether the name was registered.
1112
+ */
1113
+ removeEventName(eventName: string): boolean;
1114
+ /** Registered event names. */
1115
+ getEventNames(): string[];
1116
+ /**
1117
+ * Start a play session: every emitter is armed, the declared warm-up is
1118
+ * simulated, and the ticker is connected. The second step of `play`, after
1119
+ * `animation.prepare()`. On a paused playback it resumes
1120
+ * it where it was; on one already running it does nothing, and says so.
1121
+ * @param emit whether emitters open their emission immediately; `true` by
1122
+ * default, as in `play`. Pass a predicate to decide per emitter. It only
1123
+ * counts when the session begins from stopped: on a paused playback,
1124
+ * also one a `reset()` left clean, each emitter keeps its `spawn` as it
1125
+ * is, as a `reset()` while running does.
1126
+ */
1127
+ start(emit?: boolean | ((emitter: EmitterView) => boolean)): void;
1128
+ /** Pause a running session: the simulation stops where it is and `start()` resumes it. */
1129
+ pause(): void;
1130
+ /**
1131
+ * Stop the animation, clear its session and tell its end as `'stopped'`.
1132
+ * The playback stays the host's: the pool does not take it back.
1133
+ */
1134
+ stop(): void;
1135
+ /**
1136
+ * Start the session over without ending it: running it goes on, paused it
1137
+ * stays paused, stopped it is only cleared. Keeps what was set on the
1138
+ * playback.
1139
+ */
1140
+ reset(): void;
1141
+ /**
1142
+ * Hand the instance back to its pool in the act, telling its end as
1143
+ * `'released'`; asked from its own tick, at the end of it. One built with `new PerseonPlayback` has
1144
+ * no pool to go back to and its host is its only owner: it is destroyed,
1145
+ * with a diagnostic.
1146
+ */
1147
+ release(): void;
1148
+ /**
1149
+ * Destroy the instance. Once it is destroyed, destroying it again does
1150
+ * nothing, as it always did.
1151
+ */
1152
+ destroy(): void;
1153
+ }
1154
+
1155
+ /** What an animation tells of itself; each list is a copy. */
1156
+ interface AnimationDescription {
1157
+ globalParameters: GlobalParameterOption[];
1158
+ /** The locals as declared, with the `sampleScope` resolved and the template's default as `value`. */
1159
+ localParameters: (CustomParameterOption & {
1160
+ sampleScope: CustomParameterSampleScope;
1161
+ })[];
1162
+ events: string[];
1163
+ emitters: {
1164
+ id: string | undefined;
1165
+ layers: {
1166
+ id: string | undefined;
1167
+ }[];
1168
+ }[];
1169
+ pointForces: string[];
1170
+ regions: string[];
1171
+ }
1172
+
1173
+ /** The half of `AnimationPlayOptions` every host shares. */
1174
+ interface AnimationPlacementOptions {
1175
+ /** Position within `parent`. Both default to 0. */
1176
+ x?: number;
1177
+ y?: number;
1178
+ /**
1179
+ * Whether every emitter opens its emission immediately. Default `true`: an
1180
+ * animation played and then sitting still just looks broken. The editor is
1181
+ * the case that wants `false`, gating emission from its own panel. Only
1182
+ * `play` reads it: after `prepare`, `start(emit)` decides.
1183
+ */
1184
+ emit?: boolean;
1185
+ /**
1186
+ * The seed of this playback: the same seed with the
1187
+ * same customization gives the same sequence, whether the instance is new
1188
+ * or recycled. By default, the one the animation derives for each play.
1189
+ */
1190
+ seed?: number;
1191
+ /**
1192
+ * The values of its locals for this playback, by id: each
1193
+ * one pins its local, as `playback.param(id).set(value)` does, on top of
1194
+ * the template's defaults. A number is clipped to the local's domain; a
1195
+ * label is one the local declares.
1196
+ */
1197
+ params?: Record<string, number | string>;
1198
+ /**
1199
+ * The emission transform of this playback, as
1200
+ * `playback.transform` takes it: added to where every particle is born,
1201
+ * without moving the node (that is `x`/`y`). An axis left out is 0.
1202
+ */
1203
+ transform?: {
1204
+ x?: number;
1205
+ y?: number;
1206
+ };
1207
+ /**
1208
+ * The factor of the simulated step of this playback, as
1209
+ * `playback.timeScale` takes it. Default 1.
1210
+ */
1211
+ timeScale?: number;
1212
+ /**
1213
+ * Whether the instance goes back to the pool at its natural end, as
1214
+ * `playback.autoRelease` takes it. Default `true` in `play`
1215
+ * (fire and forget) and `false` in `prepare` (the playback is the game's:
1216
+ * left stopped at its end, `start()` plays it again, `release()` gives it
1217
+ * back).
1218
+ */
1219
+ autoRelease?: boolean;
1220
+ }
1221
+ /**
1222
+ * Whether this host's containers may be `undefined` — which is how a backend
1223
+ * with no scene graph at all (a Canvas 2D one, say) declares itself:
1224
+ * `IRenderer<undefined>`. There is nothing to mount under, so writing
1225
+ * `parent: undefined` at every call site would be ceremony, and the key is
1226
+ * optional instead.
1227
+ *
1228
+ * `unknown` is excluded deliberately: it means "nobody typed this host", not
1229
+ * "this host has no parent", and dropping the requirement there would turn a
1230
+ * forgotten `parent` from a compile error into a crash on `mount`.
1231
+ */
1232
+ type HostMountsWithoutParent<TParent> = unknown extends TParent ? false : undefined extends TParent ? true : false;
1233
+ /**
1234
+ * Where and how one playback of an animation appears.
1235
+ *
1236
+ * `TParent` is the host's container type, carried over from the renderer the
1237
+ * animation was built with — a `Container` for the Pixi adapters. It defaults to
1238
+ * `unknown`, so a reference that does not care about the host stays valid
1239
+ * without an argument (same rule as `IRenderer`).
1240
+ */
1241
+ type AnimationPlayOptions<TParent = unknown> = AnimationPlacementOptions & (HostMountsWithoutParent<TParent> extends true ? {
1242
+ /** The host container this playback mounts under, if it has one. */
1243
+ parent?: TParent;
1244
+ } : {
1245
+ /** The host container this playback mounts under. */
1246
+ parent: TParent;
1247
+ });
1248
+ /**
1249
+ * One particle animation, compiled once and playable many times.
1250
+ *
1251
+ * This is the expensive object and the reusable one. Building it walks the whole
1252
+ * option tree and compiles every parameter into closures; playing it does not.
1253
+ * A game loads its animations when it loads its assets and then plays them for
1254
+ * free — one per thruster, one per impact — which is the whole reason the
1255
+ * compilation was separated from the playback.
1256
+ *
1257
+ * Playbacks are pooled. A one-shot needs no bookkeeping from the host:
1258
+ *
1259
+ * ```ts
1260
+ * explosion.play({ parent: world, x: hit.x, y: hit.y })
1261
+ * ```
1262
+ *
1263
+ * When it runs out it detaches, resets and goes back in the pool, so the next
1264
+ * impact reuses it. A long-lived one is held and stopped by the host instead:
1265
+ *
1266
+ * ```ts
1267
+ * const left = thruster.play({ parent: ship, x: -12, y: 8 })
1268
+ * left.stop()
1269
+ * ```
1270
+ *
1271
+ * A playback the host stopped is NOT reclaimed: `stop()` is the host taking
1272
+ * control of that object, and recycling it out from under the reference it
1273
+ * still holds is the classic pooling surprise. It stays parked and unmounted,
1274
+ * to be destroyed or kept by whoever stopped it. The same goes for
1275
+ * `play({ emit: false })` — an animation that never opened its emission never
1276
+ * runs out, so it is the host's to manage.
1277
+ *
1278
+ * The corollary for a one-shot: **the returned playback is yours only until it
1279
+ * finishes.** After that its instance belongs to the pool and may already be
1280
+ * playing somewhere else under another playback, so the one the host kept is
1281
+ * over (`alive` is `false`) and does nothing it is asked.
1282
+ *
1283
+ * A host that wants to keep one past its end, to play it again, takes it with
1284
+ * `prepare()` (or `play({ autoRelease: false })`) instead: at
1285
+ * its natural end it is left stopped and still the host's, `start()` plays it
1286
+ * again, and `release()` — or `autoRelease = true` — gives it back:
1287
+ *
1288
+ * ```ts
1289
+ * const shot = muzzle.prepare({ parent: gun })
1290
+ * shot.start() // and again at every shot
1291
+ * shot.release() // when the gun goes away
1292
+ * ```
1293
+ */
1294
+ declare class PerseonAnimation<TParent = unknown> {
1295
+ /**
1296
+ * An animation outside any integration, which a host plays and pools itself.
1297
+ * Usually it comes from `perseon.createAnimation(config)` instead, which
1298
+ * also gives it the integration's globals, listeners and diagnostics policy.
1299
+ *
1300
+ * @param config the animation — pure configuration, straight from a scene
1301
+ * file. Copied and frozen here; the host's object is not kept.
1302
+ * @param renderer the host's renderer, shared by every playback.
1303
+ * @param ticker optional override. When omitted the renderer's own ticker
1304
+ * drives every playback.
1305
+ */
1306
+ constructor(config: ParticleAnimationOptions, renderer: IRenderer<TParent>, ticker?: ITicker);
1307
+ /** The animation as it was declared: a frozen copy of the config it was built from. */
1308
+ get options(): ParticleAnimationOptions;
1309
+ /** Playbacks currently parked in the pool. */
1310
+ get idleCount(): number;
1311
+ /**
1312
+ * The playbacks in force of the instances that are not in the pool, in
1313
+ * the order the instances were built: the handles a host was given and
1314
+ * still owns. A new array at each read.
1315
+ */
1316
+ get playbacks(): readonly PerseonPlayback[];
1317
+ /** Whether `destroy()` has run. Mirrors `PerseonPlayback.isDestroyed`. */
1318
+ get isDestroyed(): boolean;
1319
+ /**
1320
+ * The default of one of its locals for the instances prepared after it:
1321
+ * `set(number | label)`, `get()` and `reset()`. Throws a
1322
+ * `PerseonConfigError` for an id that is not a local: a global is the
1323
+ * game's.
1324
+ */
1325
+ param(id: string): LocalDefaultHandle;
1326
+ /**
1327
+ * What this animation declares: globals, locals with
1328
+ * their `sampleScope`, events, emitters and layers, point forces and
1329
+ * regions. Copies of the data and of the template's defaults; nothing
1330
+ * of what an instance does.
1331
+ */
1332
+ describe(): AnimationDescription;
1333
+ /**
1334
+ * Play this animation: `prepare(options).start(options.emit ?? true)`,
1335
+ * with `autoRelease` at `true` unless `options` says
1336
+ * otherwise: at its natural end the instance goes back to the pool.
1337
+ */
1338
+ play(options: AnimationPlayOptions<TParent>): PerseonPlayback;
1339
+ /**
1340
+ * The first step of `play`: take an instance from the
1341
+ * pool (or build one), give it its seed, the template's defaults and
1342
+ * `params`, and put it where the host asked — without drawing anything or
1343
+ * starting the session. What the host customizes then is already there
1344
+ * when `start()` draws the session nodes and runs the warm-up. It returns
1345
+ * a new playback: the handle of this generation of the instance,
1346
+ * with `autoRelease` at `false` unless `options` says otherwise: the
1347
+ * playback is the game's, and at its natural end it is left stopped.
1348
+ *
1349
+ * A local in `params` that the animation does not declare, or a value it
1350
+ * rejects, or a `transform` that is not finite, or a `timeScale` that is negative or not finite, throws a
1351
+ * `PerseonConfigError` before any instance is taken.
1352
+ */
1353
+ prepare(options: AnimationPlayOptions<TParent>): PerseonPlayback;
1354
+ /**
1355
+ * Listen to an event of every playback of this animation:
1356
+ * `listener` is handed one `PerseonEvent`, whose `target` says
1357
+ * which playback fired it, after the listeners of that playback and
1358
+ * before those of `Perseon`. They stay while the animation lives: the pool
1359
+ * does not drop them.
1360
+ *
1361
+ * Throws for a name the animation does not declare
1362
+ * (`options.events`), whatever the diagnostics policy.
1363
+ *
1364
+ * @returns an unsubscribe function, which takes out this registration and
1365
+ * no other: the same function registered twice is two registrations.
1366
+ */
1367
+ on(eventName: string, listener: (event: PerseonEvent) => void): Unsubscribe;
1368
+ /**
1369
+ * Destroy every playback and forget the compilation. The renderer is the
1370
+ * host's and is left alone.
1371
+ */
1372
+ destroy(): void;
1373
+ }
1374
+
1375
+ /** A particle's binding of one registered event name to one of its triggers. */
1376
+ interface ParticleEventBinding {
1377
+ particleTrigger: ParticleEventTrigger;
1378
+ }
1379
+ /** An emitter's binding of one registered event name to one of its triggers. */
1380
+ interface EmitterEventBinding {
1381
+ emitterTrigger: EmitterEventTrigger;
1382
+ }
1383
+ /** `ParticleLayerOptions.events` — registered event name → the trigger that fires it. */
1384
+ type ParticleEventBindings = Record<string, ParticleEventBinding>;
1385
+ /** `EmitterOptions.eventBindings` — registered event name → the trigger that fires it. */
1386
+ type EmitterEventBindings = Record<string, EmitterEventBinding>;
1387
+ /**
1388
+ * What every listener of an event is handed, at every
1389
+ * level: the playback's (`pb.on`), the animation's (`animation.on`) and
1390
+ * `Perseon`'s (`perseon.on`). One object per event, the same for the three
1391
+ * levels; it holds nothing of the pool: `target` is the handle of the
1392
+ * generation that fired it, and the particle is a copy.
1393
+ */
1394
+ interface PerseonEvent {
1395
+ /** The registered name that fired. */
1396
+ readonly name: string;
1397
+ /** The trigger the name is bound to. */
1398
+ readonly trigger: ParticleEventTrigger | EmitterEventTrigger;
1399
+ /** The playback that fired it: the handle of its generation, over once that generation is. */
1400
+ readonly target: PerseonPlayback;
1401
+ /**
1402
+ * The animation the playback is of. `undefined` only for a playback a
1403
+ * host built with `new PerseonPlayback`, which is of none.
1404
+ */
1405
+ readonly animation: PerseonAnimation | undefined;
1406
+ /** The emitter, by its id and its declaration index. */
1407
+ readonly emitter: {
1408
+ readonly id: string | undefined;
1409
+ readonly index: number;
1410
+ };
1411
+ /** The layer of the particle, by its id and its index in the emitter, in a particle trigger; `undefined` in an emitter trigger. */
1412
+ readonly layer: {
1413
+ readonly id: string | undefined;
1414
+ readonly index: number;
1415
+ } | undefined;
1416
+ /** The region crossed, in `onRegionEnter` / `onRegionExit`; `undefined` otherwise. */
1417
+ readonly regionId: string | undefined;
1418
+ /** A copy of the particle taken at the trigger, in a particle trigger; `undefined` in an emitter trigger. */
1419
+ readonly particle: ParticleSnapshot | undefined;
1420
+ }
1421
+ /**
1422
+ * A copy of a particle taken at the trigger: numbers
1423
+ * only, so a listener can keep it without holding the pooled particle, which
1424
+ * is another particle's by the next birth.
1425
+ *
1426
+ * One per event, the same object for all its listeners, and read-only for
1427
+ * real: its fields are getters of a class, with no setter, so
1428
+ * assigning one throws a `TypeError` in strict mode. Being getters, they are
1429
+ * not own properties: `{ ...particle }` and `Object.keys` see none of them.
1430
+ * To copy the data, `event.particle.toObject()`; `JSON.stringify` works too
1431
+ * (`toJSON`). Either builds its object only when called: nothing per event.
1432
+ */
1433
+ interface ParticleSnapshot {
1434
+ /** Position in the space of the animation. */
1435
+ readonly x: number;
1436
+ readonly y: number;
1437
+ /** Position in the space of the playback's parent: `x + pb.x`, `y + pb.y`. */
1438
+ readonly parentX: number;
1439
+ readonly parentY: number;
1440
+ readonly velocityX: number;
1441
+ readonly velocityY: number;
1442
+ readonly rotation: number;
1443
+ readonly scaleX: number;
1444
+ readonly scaleY: number;
1445
+ readonly alpha: number;
1446
+ readonly tint: number;
1447
+ readonly lifetime: number;
1448
+ readonly currentLife: number;
1449
+ /** A new plain object with every field: a mutable copy, the caller's. */
1450
+ toObject(): ParticleSnapshotObject;
1451
+ /** The same as `toObject()`, so that `JSON.stringify` writes the fields. */
1452
+ toJSON(): ParticleSnapshotObject;
1453
+ }
1454
+ /** The fields of a `ParticleSnapshot` as a plain, mutable object (`toObject()`). */
1455
+ type ParticleSnapshotObject = {
1456
+ -readonly [K in Exclude<keyof ParticleSnapshot, 'toObject' | 'toJSON'>]: ParticleSnapshot[K];
1457
+ };
1458
+ /** Takes out the registration it was handed for, and no other. */
1459
+ type Unsubscribe = () => void;
1460
+ /**
1461
+ * Event names grouped by the trigger that fires them. Produced at compile time
1462
+ * so the hot loop tests `array.length` instead of walking a `Record` and
1463
+ * branching on a trigger string.
1464
+ */
1465
+ type ParticleEventsByTrigger = Record<ParticleEventTrigger, string[]>;
1466
+ type EmitterEventsByTrigger = Record<EmitterEventTrigger, string[]>;
1467
+
1468
+ interface ExternalForcesOptions {
1469
+ /** Global gravitational acceleration */
1470
+ gravity?: number;
1471
+ /** Global movement damping coefficient (opposes movement) */
1472
+ damping?: number;
1473
+ /** Global wind force applied to particles */
1474
+ wind?: VectorValue;
1475
+ }
1476
+ interface ExternalForcesForEmitterUse {
1477
+ /** Global gravitational acceleration */
1478
+ gravity: number;
1479
+ /** Global movement damping coefficient (opposes movement) */
1480
+ damping: number;
1481
+ /** Global wind force applied to particles */
1482
+ wind: PointValue;
1483
+ }
1484
+ type PointForceMode = 'attract' | 'repel';
1485
+ type PointForceFalloff = 'none' | 'linear' | 'smooth';
1486
+ /**
1487
+ * A reusable positional external force (attractor / repeller). Declared at
1488
+ * engine level (sibling of `regions` / `globalParameters`). The force owns its own
1489
+ * behavior (`mode`); each particle only opts in to it through a
1490
+ * `pointForceFactors[id]` sensitivity factor.
1491
+ *
1492
+ * - `mode`: `attract` pulls particles toward `position`; `repel` pushes them away.
1493
+ * - `strength`: acceleration magnitude at full influence (>= 0).
1494
+ * - `radius`: influence radius in pixels (>= 0). Outside it the contribution is 0.
1495
+ * - `falloff`: how strength decays with distance inside the radius.
1496
+ * - `enabled`: when false the force is inert.
1497
+ */
1498
+ interface PointForceConfig {
1499
+ id: string;
1500
+ name: string;
1501
+ position: PointValue;
1502
+ mode: PointForceMode;
1503
+ strength: number;
1504
+ radius: number;
1505
+ falloff: PointForceFalloff;
1506
+ enabled: boolean;
1507
+ }
1508
+ interface ExternalForcesFactorOptions {
1509
+ /** Global gravitational acceleration factor. Without it, 0: the gravity does not reach the particle */
1510
+ gravityFactor?: ModulatableNumber;
1511
+ /** Global movement damping coefficient factor (opposes movement). Without it, 0: no damping */
1512
+ dampingFactor?: ModulatableNumber;
1513
+ /** Global wind force factor applied to particles. Without it, 0: the wind does not reach the particle */
1514
+ windFactor?: ModulatableNumber;
1515
+ /**
1516
+ * Per-particle sensitivity to each global point force, keyed by the point
1517
+ * force's `id`. A particle is affected by a point force only when it carries
1518
+ * a factor entry for it. Uses the same value system as the other factors
1519
+ * (Fixed / Range / List / Linked / Modifiers).
1520
+ */
1521
+ pointForceFactors?: Record<string, ModulatableNumber>;
1522
+ }
1523
+ type ExternalForcesTypes = keyof ExternalForcesOptions;
1524
+
1525
+ /**
1526
+ * How a particle assigned to a region is culled relative to that region's area:
1527
+ * - `killOutside`: the particle dies once it is fully outside the area (classic containment).
1528
+ * - `killInside`: the particle dies once it is fully inside the area (a "death zone").
1529
+ */
1530
+ type RegionBehavior = 'killInside' | 'killOutside';
1531
+ /**
1532
+ * A named containment area declared at engine level. Regions are global to the
1533
+ * engine (siblings of `externalForces` / `globalParameters`); particles opt in to
1534
+ * one by referencing its `id` through `ParticleLayerOptions.region`.
1535
+ */
1536
+ interface RegionOptions {
1537
+ id: string;
1538
+ area: ShapeArea;
1539
+ }
1540
+ /** Per-particle assignment to a single region plus the kill behavior to apply. */
1541
+ interface ParticleRegionRef {
1542
+ regionId: string;
1543
+ behavior: RegionBehavior;
1544
+ }
1545
+
1546
+ /**
1547
+ * Texture source identifier. Strings reference renderer-preloaded resources.
1548
+ * The renderer's `resolveTexture(source)` turns this into an `ITextureRef`.
1549
+ */
1550
+ type SingleTextureOption = string;
1551
+ interface SpriteAnimationOptions {
1552
+ textures: SingleTextureOption[];
1553
+ animationFPS?: number;
1554
+ animationLoop?: boolean;
1555
+ /**
1556
+ * Starting frame for the animation. Undefined means it will start from the first frame.
1557
+ * Can be set to a random frame by using value of -1.
1558
+ */
1559
+ startFrame?: number;
1560
+ }
1561
+ interface SpriteAnimationTexturesOptions extends Omit<SpriteAnimationOptions, 'textures'> {
1562
+ textures: string[];
1563
+ }
1564
+ type TextureElement = SingleTextureOption | SpriteAnimationOptions;
1565
+ /**
1566
+ * Runtime state of a sprite-sheet animation on a live particle. Textures are
1567
+ * pre-resolved to renderer-opaque `ITextureRef` so the hot update loop doesn't
1568
+ * touch any string-keyed cache.
1569
+ */
1570
+ interface ParticleSpriteAnimationParameters {
1571
+ textures: ITextureRef[];
1572
+ elapsedTime: number;
1573
+ intervalSec: number;
1574
+ currentIndex: number;
1575
+ loop: boolean;
1576
+ }
1577
+ interface KineticsOptions {
1578
+ position?: SpawnPosition;
1579
+ velocity?: SpawnVector;
1580
+ acceleration?: SpawnVector;
1581
+ maxVelocity?: number;
1582
+ }
1583
+ interface ScaleOptions {
1584
+ value: ModulatableNumber | SpawnPoint;
1585
+ velocity?: ModulatableNumber | SpawnPoint;
1586
+ acceleration?: ModulatableNumber | SpawnPoint;
1587
+ /** Maximum speed cap applied equally to both X and Y scale velocity components. */
1588
+ maxVelocity?: number;
1589
+ }
1590
+ interface NumberOptions {
1591
+ value: ModulatableNumber;
1592
+ velocity?: ModulatableNumber;
1593
+ acceleration?: ModulatableNumber;
1594
+ maxVelocity?: number;
1595
+ }
1596
+ interface ColorOptions {
1597
+ value: SpawnColor;
1598
+ }
1599
+ /**
1600
+ * Configuration options for individual particle spawn behavior.
1601
+ * Defines all the visual and physical properties a particle can have when created.
1602
+ */
1603
+ interface ParticleLayerOptions {
1604
+ /**
1605
+ * Stable identifier for this particle type, supplied by the host (e.g. the
1606
+ * editor's particle id). Optional; when present it is stamped onto every
1607
+ * spawned particle (`ParticleItem.sourceParticleId`) so the engine can report
1608
+ * alive counts per type via `getParticlesAliveById`.
1609
+ */
1610
+ id?: string;
1611
+ /**
1612
+ * Whether this layer is drawn when its playback is built or comes back
1613
+ * from its pool. Defaults to `true`. Hidden, it still spawns, simulates,
1614
+ * counts and fires its events. Drawn only while its emitter is drawn too.
1615
+ * Live: `ParticleLayer.visible`.
1616
+ */
1617
+ visible?: boolean;
1618
+ texture: TextureElement | RandomValueList<TextureElement>;
1619
+ /** Particle lifetime in seconds */
1620
+ lifetime?: ModulatableNumber;
1621
+ /** Kinetics configuration with physics properties for the particle */
1622
+ kinetics?: KineticsOptions;
1623
+ /** Scale configuration options for the particle */
1624
+ scale?: ScaleOptions;
1625
+ /** Rotation configuration with physics properties for the particle */
1626
+ rotation?: NumberOptions;
1627
+ /** Alpha transparency options for the particle */
1628
+ alpha?: NumberOptions;
1629
+ /** Color tint options for the particle */
1630
+ color?: ColorOptions;
1631
+ /**
1632
+ * Fixed compositing/blend mode for this particle. Defaults to `'normal'`.
1633
+ * This is a static rendering setting, not a dynamic parameter — it does not
1634
+ * support randomness, curves, modifiers, or animation. Applied at the
1635
+ * render-group container level by the renderer adapter.
1636
+ */
1637
+ blendMode?: ParticleBlendMode;
1638
+ /** External forces factors for particle */
1639
+ externalForces?: ExternalForcesFactorOptions;
1640
+ /** Optional assignment to one engine-level region, with a kill behavior. */
1641
+ region?: ParticleRegionRef;
1642
+ /**
1643
+ * This particle type's bindings: registered event name (see
1644
+ * `ParticleAnimationOptions.events`) → the particle trigger that fires it.
1645
+ *
1646
+ * `onRegionEnter` / `onRegionExit` evaluate the region assigned in `region`
1647
+ * above; without one they never fire, since there is nothing to cross.
1648
+ */
1649
+ events?: ParticleEventBindings;
1650
+ /**
1651
+ * Called once for each particle of this layer when it is born, after the
1652
+ * engine has set it up from this config. When the emitter's `ParticleClass`
1653
+ * overrides `ParticleItem.onInit` too, both run: this one first.
1654
+ */
1655
+ onInit?: (options: ParameterInitOptions) => void;
1656
+ /**
1657
+ * Called for each live particle of this layer on every tick, after the
1658
+ * engine has stepped it. Before `ParticleItem.onUpdate`, as `onInit`.
1659
+ */
1660
+ onUpdate?: (options: ParameterUpdateOptions) => void;
1661
+ }
1662
+ /**
1663
+ * The random generator a particle hook draws from: its emitter's, seeded with
1664
+ * the playback. Drawing from it, rather than from `Math.random`, keeps a seeded
1665
+ * animation the same on every replay, hooks included.
1666
+ */
1667
+ interface ParticleHookRandom {
1668
+ /** The next number of the sequence, from 0 (inclusive) to 1 (exclusive). */
1669
+ next(): number;
1670
+ }
1671
+ /**
1672
+ * The playback a particle hook's emitter belongs to: the very `PerseonPlayback`
1673
+ * the host was given for it, seen through the three calls a hook needs. A
1674
+ * `stop()` or `start()` asked from a hook takes effect at the end of the tick,
1675
+ * so every particle of this tick is stepped the same way.
1676
+ *
1677
+ * It answers for that playback only. Kept after the playback is over (back in
1678
+ * its animation's pool, maybe already playing for someone else), it is over
1679
+ * too: what is asked of it does nothing and is reported by the animation's
1680
+ * diagnostics policy, as on any `PerseonPlayback` that is over.
1681
+ */
1682
+ interface ParticleHookPlayback {
1683
+ /** Start the playback again, as `PerseonPlayback.start`: `emit` (default `true`) opens every emitter. */
1684
+ start(emit?: boolean): void;
1685
+ /** Stop the playback, as `PerseonPlayback.stop`. */
1686
+ stop(): void;
1687
+ /** One of the animation's locals in this playback, as `PerseonPlayback.param`. */
1688
+ param(id: string): LocalParameterHandle;
1689
+ }
1690
+ /**
1691
+ * The emitter that spawned the particle a hook is called for. The same object
1692
+ * for every hook of the same playback; kept past that playback, its `playback`
1693
+ * is over as `ParticleHookPlayback` says.
1694
+ */
1695
+ interface ParticleHookEmitter {
1696
+ /** Its `EmitterOptions.id`, or `undefined` when the config gave it none. */
1697
+ readonly id: string | undefined;
1698
+ /** The playback it belongs to. */
1699
+ readonly playback: ParticleHookPlayback;
1700
+ }
1701
+ /**
1702
+ * What an `onInit` receives: the `onInit` of a layer's config
1703
+ * (`ParticleLayerOptions.onInit`) and the one a `ParticleClass` overrides
1704
+ * (`ParticleItem.onInit`). A new object on every call.
1705
+ *
1706
+ * `particle` is the particle only until it dies: the engine pools particles,
1707
+ * and the same object is born again later as another one. Keep what a hook
1708
+ * needs from it, not the particle.
1709
+ */
1710
+ interface ParameterInitOptions {
1711
+ /** The particle being born. */
1712
+ particle: ParticleItem;
1713
+ /** The emitter that spawned it. */
1714
+ emitter: ParticleHookEmitter;
1715
+ /** Its emitter's random generator. */
1716
+ rng: ParticleHookRandom;
1717
+ }
1718
+ /** What an `onUpdate` receives: the same as `onInit`, and the step of the tick. */
1719
+ interface ParameterUpdateOptions extends ParameterInitOptions {
1720
+ /** The simulated time of this step, in seconds. */
1721
+ elapsedSec: number;
1722
+ }
1723
+
1724
+ type ParticleLimitStrategy = 'preventNew' | 'killOldest' | 'killRandom';
1725
+ interface CapacityOptions {
1726
+ /** Maximum number of particles that can exist simultaneously */
1727
+ maxAlive: number;
1728
+ /** Strategy to apply when the pool is full */
1729
+ limitStrategy?: ParticleLimitStrategy;
1730
+ /** Initial number of particles to create in the pool */
1731
+ initialPoolSize?: number;
1732
+ }
1733
+ type ParticleSpawnStrategy = 'front' | 'back' | 'random';
1734
+ interface EmissionOptions {
1735
+ duration?: SpawnNumber;
1736
+ count?: SpawnNumber;
1737
+ rate?: SpawnNumber;
1738
+ spawnStrategy?: ParticleSpawnStrategy;
1739
+ }
1740
+ interface InitialStateOptions {
1741
+ simulateTime?: SpawnNumber;
1742
+ ensureAliveCount?: SpawnNumber;
1743
+ }
1744
+ interface PlaybackOptions {
1745
+ startDelay?: SpawnNumber;
1746
+ interval?: SpawnNumber;
1747
+ repeat?: SpawnNumber;
1748
+ }
1749
+ /**
1750
+ * How an emitter seeds itself when it does not inherit from the animation.
1751
+ * - `'fixed'`: always the same `seed`; `reset()` returns to it, so the emitter
1752
+ * replays even when the animation as a whole does not.
1753
+ * - `'auto'`: a fresh random seed per construction — deliberately unrepeatable,
1754
+ * even inside a seeded animation.
1755
+ */
1756
+ type RandomnessSeedMode = 'fixed' | 'auto';
1757
+ interface RandomnessOptions {
1758
+ /**
1759
+ * Absent → inherit the animation's seeding: a seed derived from
1760
+ * `ParticleAnimationOptions.randomness.seed`, or none when the animation is
1761
+ * unseeded. Deriving (rather than reusing the animation seed) is what keeps two
1762
+ * emitters of the same animation from running identical streams.
1763
+ */
1764
+ seedMode?: RandomnessSeedMode;
1765
+ /** Only read with `seedMode: 'fixed'`. */
1766
+ seed?: number;
1767
+ }
1768
+ interface PerformanceOptions {
1769
+ maxUpdateRate?: number;
1770
+ warmUpMaxTicks?: number;
1771
+ }
1772
+ /**
1773
+ * Configuration for one emitter of a `PerseonPlayback`.
1774
+ *
1775
+ * An emitter owns its emission cycle, its particle pool and its Particle
1776
+ * Layers. Everything shared by the animation — regions, event names, point forces,
1777
+ * external forces, global parameters, the renderer and the clock — belongs to
1778
+ * the engine (`ParticleAnimationOptions`).
1779
+ *
1780
+ * Multi-layer: declare one or more particle parameter sets in `particles`. Each
1781
+ * one becomes a `ParticleLayer` with its own render group and blend mode, and on
1782
+ * spawn the `RandomValueList`'s `selectionMode` (`ordered` | `shuffle` |
1783
+ * `random` with optional weights) picks which layer the particle is born into.
1784
+ */
1785
+ interface EmitterOptions {
1786
+ /**
1787
+ * Stable identifier for this emitter, supplied by the host (e.g. the
1788
+ * editor's emitter id). Exposed via `Emitter.id`, and how
1789
+ * `PerseonPlayback.getEmitter` and `randomness.parentEmitterId` address it.
1790
+ */
1791
+ id?: string;
1792
+ /**
1793
+ * Constructor of the particle class. Unique per emitter — its pool is
1794
+ * homogeneous in class.
1795
+ *
1796
+ * Optional, defaulting to `ParticleItem`. A constructor is a live object, so
1797
+ * it cannot travel in an animation file the way the rest of these options
1798
+ * can — it is the one member here a JSON payload never declares. A host
1799
+ * supplies it in code, and only when it extends `ParticleItem` with its own
1800
+ * per-particle state.
1801
+ */
1802
+ ParticleClass?: new () => ParticleItem;
1803
+ /**
1804
+ * Whether this emitter is drawn when its playback is built or comes back
1805
+ * from its pool. Defaults to `true`. Hidden, it still spawns, simulates,
1806
+ * counts and fires its events. Live: `Emitter.visible`.
1807
+ */
1808
+ visible?: boolean;
1809
+ /**
1810
+ * One or more Particle Layers. The pool, live list, and order strategy do
1811
+ * not differentiate between layers — they operate over the union.
1812
+ */
1813
+ particles: RandomValueList<ParticleLayerOptions> | ParticleLayerOptions;
1814
+ /**
1815
+ * This emitter's bindings: registered event name → the emitter trigger that
1816
+ * fires it (`onEmitStart` / `onEmitStop`). The names themselves are
1817
+ * registered on the engine (`ParticleAnimationOptions.events`).
1818
+ */
1819
+ eventBindings?: EmitterEventBindings;
1820
+ /** Pool capacity for this emitter. Does not differentiate by layer. */
1821
+ capacity?: CapacityOptions;
1822
+ /** How and when the emitter spawns particles: burst or rate, and how long it lasts. */
1823
+ emission?: EmissionOptions;
1824
+ /** What the emitter has already simulated by the time it is first shown: warm-up time and a minimum live count. */
1825
+ initialState?: InitialStateOptions;
1826
+ /** The emitter's cycle: the delay before it starts and how many times, and how often, it repeats. */
1827
+ playback?: PlaybackOptions;
1828
+ /** The emitter's random seed. Absent, it inherits the animation's seeding. */
1829
+ randomness?: RandomnessOptions;
1830
+ /** Limits on how much simulation work the emitter does per second and while warming up. */
1831
+ performance?: PerformanceOptions;
1832
+ }
1833
+
1834
+ /**
1835
+ * The paths `option(path)` takes, per scope, and the type of the format at each.
1836
+ * Each type is read off the format's own types, so a path gives exactly what the
1837
+ * JSON holds there.
1838
+ *
1839
+ * The maps are written out path by path, not derived from the option types: a
1840
+ * recursive path type over the whole format is what makes `tsc` slow, and the
1841
+ * addressable paths are not all the format's paths anyway.
1842
+ *
1843
+ * `${string}` stands only for an id: a point force's, a region's or a point
1844
+ * force factor's, and it is a single segment: those ids take no dot. A path that
1845
+ * ends in a field name is that field (`'pointForces.a.position'`, the force
1846
+ * `'a'`); any other is the whole force (`'pointForces.a'`). A template literal cannot say "no dot", so the types
1847
+ * still let a dotted path through; `findOptionPathEntry` refuses it at run
1848
+ * time, and whether the id exists is for the runtime to find.
1849
+ */
1850
+ type PlaybackOptionTypes = {
1851
+ 'externalForces.gravity': NonNullable<ExternalForcesOptions['gravity']>;
1852
+ 'externalForces.damping': NonNullable<ExternalForcesOptions['damping']>;
1853
+ 'externalForces.wind': NonNullable<ExternalForcesOptions['wind']>;
1854
+ 'performance.maxUpdateRate': NonNullable<PerformanceOptions['maxUpdateRate']>;
1855
+ 'performance.warmUpMaxTicks': NonNullable<PerformanceOptions['warmUpMaxTicks']>;
1856
+ };
1857
+ /** A point force's fields as nodes; its id is the path. */
1858
+ type PointForceField = Exclude<keyof PointForceConfig, 'id'>;
1859
+ /** The field a point force path ends in, or `never` for the whole force. */
1860
+ type PointForceFieldOf<P extends string> = {
1861
+ [F in PointForceField]: P extends `pointForces.${string}.${F}` ? F : never;
1862
+ }[PointForceField];
1863
+ type PlaybackOptionPath = keyof PlaybackOptionTypes | `pointForces.${string}` | `pointForces.${string}.${PointForceField}` | `regions.${string}` | `regions.${string}.area`;
1864
+ type PlaybackOptionType<P extends PlaybackOptionPath> = P extends keyof PlaybackOptionTypes ? PlaybackOptionTypes[P] : P extends `pointForces.${string}` ? [PointForceFieldOf<P>] extends [never] ? PointForceConfig : PointForceConfig[PointForceFieldOf<P>] : P extends `regions.${string}.area` ? RegionOptions['area'] : RegionOptions;
1865
+ type EmitterOptionTypes = {
1866
+ 'emission.rate': NonNullable<EmissionOptions['rate']>;
1867
+ 'emission.duration': NonNullable<EmissionOptions['duration']>;
1868
+ 'emission.count': NonNullable<EmissionOptions['count']>;
1869
+ 'emission.spawnStrategy': NonNullable<EmissionOptions['spawnStrategy']>;
1870
+ 'playback.startDelay': NonNullable<PlaybackOptions['startDelay']>;
1871
+ 'playback.interval': NonNullable<PlaybackOptions['interval']>;
1872
+ 'playback.repeat': NonNullable<PlaybackOptions['repeat']>;
1873
+ 'initialState.simulateTime': NonNullable<InitialStateOptions['simulateTime']>;
1874
+ 'initialState.ensureAliveCount': NonNullable<InitialStateOptions['ensureAliveCount']>;
1875
+ 'capacity.maxAlive': CapacityOptions['maxAlive'];
1876
+ 'capacity.limitStrategy': NonNullable<CapacityOptions['limitStrategy']>;
1877
+ 'capacity.initialPoolSize': NonNullable<CapacityOptions['initialPoolSize']>;
1878
+ 'randomness.seedMode': NonNullable<RandomnessOptions['seedMode']>;
1879
+ 'randomness.seed': NonNullable<RandomnessOptions['seed']>;
1880
+ 'performance.maxUpdateRate': NonNullable<PerformanceOptions['maxUpdateRate']>;
1881
+ 'performance.warmUpMaxTicks': NonNullable<PerformanceOptions['warmUpMaxTicks']>;
1882
+ eventBindings: NonNullable<EmitterOptions['eventBindings']>;
1883
+ };
1884
+ type EmitterOptionPath = keyof EmitterOptionTypes;
1885
+ type EmitterOptionType<P extends EmitterOptionPath> = EmitterOptionTypes[P];
1886
+ /** One axis of a composite in its split mode: `{x, y}` or `{angle, magnitude}`. */
1887
+ type Axis = ModulatableNumber;
1888
+ type LayerOptionTypes = {
1889
+ lifetime: NonNullable<ParticleLayerOptions['lifetime']>;
1890
+ texture: ParticleLayerOptions['texture'];
1891
+ region: NonNullable<ParticleLayerOptions['region']>;
1892
+ events: NonNullable<ParticleLayerOptions['events']>;
1893
+ blendMode: NonNullable<ParticleLayerOptions['blendMode']>;
1894
+ kinetics: KineticsOptions;
1895
+ 'kinetics.position': NonNullable<KineticsOptions['position']>;
1896
+ 'kinetics.position.x': Axis;
1897
+ 'kinetics.position.y': Axis;
1898
+ 'kinetics.velocity': NonNullable<KineticsOptions['velocity']>;
1899
+ 'kinetics.velocity.angle': Axis;
1900
+ 'kinetics.velocity.magnitude': Axis;
1901
+ 'kinetics.acceleration': NonNullable<KineticsOptions['acceleration']>;
1902
+ 'kinetics.acceleration.angle': Axis;
1903
+ 'kinetics.acceleration.magnitude': Axis;
1904
+ 'kinetics.maxVelocity': NonNullable<KineticsOptions['maxVelocity']>;
1905
+ scale: ScaleOptions;
1906
+ 'scale.value': ScaleOptions['value'];
1907
+ 'scale.value.x': Axis;
1908
+ 'scale.value.y': Axis;
1909
+ 'scale.velocity': NonNullable<ScaleOptions['velocity']>;
1910
+ 'scale.velocity.x': Axis;
1911
+ 'scale.velocity.y': Axis;
1912
+ 'scale.acceleration': NonNullable<ScaleOptions['acceleration']>;
1913
+ 'scale.acceleration.x': Axis;
1914
+ 'scale.acceleration.y': Axis;
1915
+ 'scale.maxVelocity': NonNullable<ScaleOptions['maxVelocity']>;
1916
+ rotation: NumberOptions;
1917
+ 'rotation.value': NumberOptions['value'];
1918
+ 'rotation.velocity': NonNullable<NumberOptions['velocity']>;
1919
+ 'rotation.acceleration': NonNullable<NumberOptions['acceleration']>;
1920
+ 'rotation.maxVelocity': NonNullable<NumberOptions['maxVelocity']>;
1921
+ alpha: NumberOptions;
1922
+ 'alpha.value': NumberOptions['value'];
1923
+ 'alpha.velocity': NonNullable<NumberOptions['velocity']>;
1924
+ 'alpha.acceleration': NonNullable<NumberOptions['acceleration']>;
1925
+ 'alpha.maxVelocity': NonNullable<NumberOptions['maxVelocity']>;
1926
+ 'color.value': ColorOptions['value'];
1927
+ 'externalForces.gravityFactor': NonNullable<ExternalForcesFactorOptions['gravityFactor']>;
1928
+ 'externalForces.dampingFactor': NonNullable<ExternalForcesFactorOptions['dampingFactor']>;
1929
+ 'externalForces.windFactor': NonNullable<ExternalForcesFactorOptions['windFactor']>;
1930
+ 'externalForces.pointForceFactors': NonNullable<ExternalForcesFactorOptions['pointForceFactors']>;
1931
+ };
1932
+ type PointForceFactors = NonNullable<ExternalForcesFactorOptions['pointForceFactors']>;
1933
+ type LayerOptionPath = keyof LayerOptionTypes | `externalForces.pointForceFactors.${string}`;
1934
+ type LayerOptionType<P extends LayerOptionPath> = P extends keyof LayerOptionTypes ? LayerOptionTypes[P] : PointForceFactors[string];
1935
+
1936
+ /**
1937
+ * Randomness of the animation itself — what drives the sampling of its
1938
+ * `'playback'` locals.
1939
+ * Emitters seed themselves separately (`EmitterOptions.randomness`).
1940
+ */
1941
+ interface AnimationRandomnessOptions {
1942
+ /**
1943
+ * Fixed seed for animation-scope sampling. With one, the animation replays
1944
+ * identically and `reset()` returns to it; without one, a fresh random seed
1945
+ * is drawn when the engine is constructed and a reset keeps rolling forward.
1946
+ */
1947
+ seed?: number;
1948
+ }
1949
+ /**
1950
+ * An animation: pure configuration, and the whole of it. This is what a
1951
+ * `.json` scene file holds and what `PerseonPlayback` is constructed from —
1952
+ * there is no parallel "serialized" schema to keep in sync, because nothing
1953
+ * here is a live object.
1954
+ *
1955
+ * The host's own infrastructure (its `IRenderer`, its `ITicker`) is *not*
1956
+ * configuration: the host builds it and passes it to the constructor
1957
+ * alongside these options, exactly as `Emitter` receives its playback and
1958
+ * render node.
1959
+ *
1960
+ * Textures travel as ids, not images. A `texture.source` names a resource the
1961
+ * host must have registered with its renderer beforehand (for the Pixi
1962
+ * adapters, anything `Assets.cache` resolves — typically the frames of a
1963
+ * particle atlas). The animation file therefore stays small and shares one
1964
+ * atlas across every particle that uses it.
1965
+ *
1966
+ * Each entry of `emitters` becomes one `Emitter` with its own emission cycle,
1967
+ * pool and Particle Layers; everything else is shared by all of them.
1968
+ */
1969
+ interface ParticleAnimationOptions {
1970
+ /** Format of this file: `ANIMATION_FORMAT_VERSION`. Mandatory. */
1971
+ formatVersion: number;
1972
+ /** One or more emitters, rendered in declaration order. */
1973
+ emitters: EmitterOptions[];
1974
+ /**
1975
+ * Named containment areas, shared by every emitter. A particle opts in to
1976
+ * one via `ParticleLayerOptions.region`, picking a `killInside` /
1977
+ * `killOutside` behavior. Pass a single `RegionOptions` or an array. When
1978
+ * omitted (or when a particle declares no region), only `lifetime` decides
1979
+ * when it dies.
1980
+ */
1981
+ regions?: RegionOptions | RegionOptions[];
1982
+ /**
1983
+ * Event names registered on this engine. Names are unique identities: both
1984
+ * `EmitterOptions.eventBindings` and `ParticleLayerOptions.events` reference
1985
+ * them, and the engine dispatches them to the listeners of `on`.
1986
+ *
1987
+ * Registration is what makes a name live — binding a name absent from this
1988
+ * list is inert. Manage the registry at runtime with `addEventName` /
1989
+ * `removeEventName` / `hasEvent`.
1990
+ */
1991
+ events?: string[];
1992
+ /**
1993
+ * Reusable positional external forces (attractors / repellers). Declared
1994
+ * once for the animation and offered to every particle: a particle is affected
1995
+ * by one only when it carries a matching
1996
+ * `externalForces.pointForceFactors[id]` sensitivity factor.
1997
+ */
1998
+ pointForces?: PointForceConfig[];
1999
+ /** Gravity / damping / wind, shared by every emitter. */
2000
+ externalForces?: ExternalForcesOptions;
2001
+ /** Values the game sets (`setGlobalParameter`). Each one holds its `value` until then. */
2002
+ globalParameters?: GlobalParameterOption[];
2003
+ /**
2004
+ * The animation's locals, declared once for every emitter and layer. Their
2005
+ * `sampleScope` says when they are drawn; names are shared with the globals.
2006
+ */
2007
+ localParameters?: CustomParameterOption[];
2008
+ /** Seeding of the animation's own RNG, which samples the `'playback'` locals. */
2009
+ randomness?: AnimationRandomnessOptions;
2010
+ /** Frame-rate cap for the whole simulation. */
2011
+ performance?: PerformanceOptions;
2012
+ }
2013
+
2014
+ /**
2015
+ * Per-instance memory of every compiled `RandomValueList` an owner holds, one
2016
+ * slot per list, assigned at compile time.
2017
+ *
2018
+ * It lives out here rather than inside the compiled list because **the compiled
2019
+ * tree is immutable and shared between playbacks** while this changes on every
2020
+ * spawn: it is the cursor of `ordered` and the bag of `shuffle`. Sharing it
2021
+ * would correlate every playback of the same animation and break seeded replay.
2022
+ *
2023
+ * `random` needs no memory — it is weighted sampling with no history — so a slot
2024
+ * is created only when first written, and an animation whose lists are all
2025
+ * `random` allocates nothing at all.
2026
+ */
2027
+ type RandomListState = number[][];
2028
+ /**
2029
+ * When a local parameter's Range / Random list value is drawn.
2030
+ *
2031
+ * - `'playback'` (default): once per play session, when the playback starts or
2032
+ * resets, with the playback's RNG.
2033
+ * - `'emitter'`: once per emission cycle, by each emitter that reads it, with
2034
+ * that emitter's RNG.
2035
+ * - `'particle'`: once per particle, at birth, by each layer that reads it.
2036
+ *
2037
+ * Only the emitters and layers that read a local draw it (`readersOf`), so an
2038
+ * unread local consumes no randomness. Has no effect on Fixed or Linked values:
2039
+ * Fixed ones never draw, and Linked ones are evaluated every frame.
2040
+ */
2041
+ type CustomParameterSampleScope = 'playback' | 'emitter' | 'particle';
2042
+
2043
+ /**
2044
+ * The value space a numeric parameter lives in: the range, the step and the
2045
+ * decimals the engine declares for it.
2046
+ */
2047
+ type NumericDomain = {
2048
+ min: number;
2049
+ max: number;
2050
+ step?: number;
2051
+ decimals?: number;
2052
+ };
2053
+ /**
2054
+ * The value space a name-like string lives in — the text counterpart of
2055
+ * `NumericDomain`. `maxLength` bounds it; `minLength` is how short it may be
2056
+ * (0 means "may be empty" — required-ness is enforced by the caller, not here)
2057
+ * `trim` says whether leading/trailing whitespace is stripped before measuring
2058
+ * and sanitizing, so " Fire " and "Fire" are treated as the same name.
2059
+ */
2060
+ type TextDomain = {
2061
+ minLength: number;
2062
+ maxLength: number;
2063
+ trim: boolean;
2064
+ };
2065
+
2066
+ interface RandomValueRange {
2067
+ min: number;
2068
+ max: number;
2069
+ distribution?: CurveDefinition;
2070
+ distributionKind?: ProbabilityCurveKind;
2071
+ }
2072
+ type RandomValueListMode = 'ordered' | 'shuffle' | 'random';
2073
+ type ValueProbability<T> = {
2074
+ value: T;
2075
+ weight?: number;
2076
+ };
2077
+ interface RandomValueList<T> {
2078
+ values: ValueProbability<T>[];
2079
+ selectionMode: RandomValueListMode;
2080
+ }
2081
+ interface ParameterLinkRelation {
2082
+ sourceParameterId: string;
2083
+ transferFunction: CurveDefinition;
2084
+ }
2085
+ type SpawnNumber = number | RandomValueRange | RandomValueList<number> | ParameterLinkRelation;
2086
+ /**
2087
+ * Blend operations a modifier applies to the running parameter value `v`
2088
+ * with its source sample `s` and signed strength `k`:
2089
+ * - `add`: v_next = v + k * s
2090
+ * - `multiply`: v_next = v * (1 + k * (s - 1))
2091
+ *
2092
+ * The `multiply` form is deliberate (NOT `v * (k * s)`): it keeps `k = 0`
2093
+ * meaning "no effect" in BOTH blends, so a single strength slider reads the
2094
+ * same way for the artist regardless of blend.
2095
+ */
2096
+ type ModifierBlendMode = 'add' | 'multiply';
2097
+ /**
2098
+ * Where a modifier reads its per-tick source value `s` from. Both kinds are
2099
+ * CONTINUOUS — sampled every tick, unlike the (possibly spawn-frozen) base.
2100
+ * - `paramRef`: the live value of another parameter (same resolution as a
2101
+ * Linked relation's source, minus the transfer curve).
2102
+ * - `modulator`: a waveform owned by this modifier, declared inline.
2103
+ */
2104
+ type ParameterModifierSource = {
2105
+ type: 'paramRef';
2106
+ sourceParameterId: string;
2107
+ } | {
2108
+ type: 'modulator';
2109
+ modulator: ModulatorOptions;
2110
+ };
2111
+ /**
2112
+ * A single entry in a parameter's ordered modifier stack. Each modifier takes
2113
+ * the previous step's value as its `v`, samples its `source` for `s`, and
2114
+ * blends them by `strength` (`k`), whose range is `MODIFIER_DOMAINS.strength`.
2115
+ */
2116
+ interface ParameterModifier {
2117
+ source: ParameterModifierSource;
2118
+ blend: ModifierBlendMode;
2119
+ strength: number;
2120
+ }
2121
+ /**
2122
+ * A numeric parameter wrapped with an ordered modifier stack on top of its
2123
+ * base value type. Backwards compatible: a bare `SpawnNumber` (no wrapper) is
2124
+ * unchanged. The base resolves with the usual timing (Range/List frozen at
2125
+ * spawn, Fixed/Linked as before); the modifiers run every tick.
2126
+ */
2127
+ interface ModulatedValue {
2128
+ base: SpawnNumber;
2129
+ modifiers: ParameterModifier[];
2130
+ }
2131
+ /** A numeric slot that may optionally carry a modifier stack. */
2132
+ type ModulatableNumber = SpawnNumber | ModulatedValue;
2133
+ type SpawnPosition = {
2134
+ x: ModulatableNumber;
2135
+ y: ModulatableNumber;
2136
+ } | ShapeArea | RandomValueList<PointValue>;
2137
+ type SpawnPoint = {
2138
+ x: ModulatableNumber;
2139
+ y: ModulatableNumber;
2140
+ } | RandomValueList<PointValue>;
2141
+ type SpawnVector = {
2142
+ angle: ModulatableNumber;
2143
+ magnitude: ModulatableNumber;
2144
+ } | RandomValueList<VectorValue>;
2145
+ type ModulatorShape = 'sine' | 'square' | 'sawtooth' | 'triangle' | 'noise' | 'custom';
2146
+ /**
2147
+ * A cyclic value source: a waveform owned by a single parameter modifier and
2148
+ * declared inline in its `source`. Sampled every tick against a driving value
2149
+ * `t` chosen by `timeSource`.
2150
+ *
2151
+ * Output per tick: `offset + amplitude * shape(phase + t * frequency)`,
2152
+ * looping indefinitely.
2153
+ *
2154
+ * `'noise'` is smooth value noise that repeats every cycle like the other
2155
+ * shapes: 4 random values per cycle, joined smoothly, the last one back to the
2156
+ * first, so it loops without a jump. It is per particle (derived from the
2157
+ * particle's seed, so a fixed animation seed reproduces it), each particle read
2158
+ * from its own point within the cycle, and stays in `offset ± |amplitude|`.
2159
+ */
2160
+ interface ModulatorOptions {
2161
+ shape: ModulatorShape;
2162
+ /**
2163
+ * What drives the waveform's `t`:
2164
+ * - `'timeElapsed'` (default): the engine's total elapsed seconds — one
2165
+ * shared value per tick, so every particle sees the same output. The
2166
+ * exception is `'noise'`: each particle keeps its own noise.
2167
+ * - any particle parameter path accepted by a `paramRef` source
2168
+ * (`'lifeProgress'`, `'velocity.x'`, a custom local parameter id...):
2169
+ * `t` is that particle's live value, so the output is per-particle.
2170
+ */
2171
+ timeSource?: string;
2172
+ /** Cycles per unit of `timeSource` (per second for `'timeElapsed'`). */
2173
+ frequency: number;
2174
+ amplitude: number;
2175
+ /** Centre value of the oscillation. */
2176
+ offset: number;
2177
+ /** Initial phase as a fraction of one cycle, for every shape (`'noise'` too). */
2178
+ phase: number;
2179
+ /**
2180
+ * Custom waveform — only used when `shape === 'custom'`. The curve maps a
2181
+ * cycle fraction x∈[0,1] to y∈[0,1]; y is remapped to [-1,1] so amplitude
2182
+ * and offset keep the same meaning as the analytic shapes.
2183
+ */
2184
+ curve?: CurveDefinition;
2185
+ }
2186
+ type CustomParameterType = 'continuous' | 'discrete' | 'label';
2187
+ /**
2188
+ * A value the game sets (`setGlobalParameter`). Just one value, without modes:
2189
+ * anything that draws or follows a source is a local linked to it.
2190
+ */
2191
+ type GlobalParameterOption = {
2192
+ /** Public name: what the game and every `sourceParameterId` address it by. */
2193
+ id: string;
2194
+ type: CustomParameterType;
2195
+ label: string;
2196
+ domain: NumericDomain | string[];
2197
+ /** Default value; the label index for a `'label'` global. */
2198
+ value: number;
2199
+ };
2200
+ /**
2201
+ * Allowed shapes for `CustomParameterOption.value`.
2202
+ *
2203
+ * - `number` (Fixed): a constant scalar. Backwards-compatible with
2204
+ * the original API; existing callers passing a plain number keep
2205
+ * working unchanged.
2206
+ * - `RandomValueRange` (Range): min / max with optional distribution
2207
+ * curve. Sampled at the scope's re-sample moment (see
2208
+ * `CustomParameterSampleScope`).
2209
+ * - `RandomValueList<number>` (Random list): weighted list with a
2210
+ * selection mode (ordered / shuffle / random). Same sampling
2211
+ * timing as Range.
2212
+ * - `ParameterLinkRelation` (Linked): expression tying this
2213
+ * parameter's value to another source through a transfer curve.
2214
+ * Evaluated per frame against the live source.
2215
+ */
2216
+ type CustomParameterValue = number | RandomValueRange | RandomValueList<number> | ParameterLinkRelation;
2217
+ type CustomParameterOption = {
2218
+ /** Public name, unique among the animation's globals and locals. */
2219
+ id: string;
2220
+ type: CustomParameterType;
2221
+ label: string;
2222
+ domain: NumericDomain | string[];
2223
+ value: CustomParameterValue;
2224
+ /** Sampling scope for Range / Random list values. Default `'playback'`. */
2225
+ sampleScope?: CustomParameterSampleScope;
2226
+ };
2227
+
2228
+ type ColorStop = [number, number];
2229
+ interface ColorGradientDefinition {
2230
+ stops: ColorStop[];
2231
+ sourceParameterId: string;
2232
+ }
2233
+ /**
2234
+ * A gradient the particle samples ONCE at spawn to freeze a random color for
2235
+ * its whole life. `stops` positions are normalized to [0,1]; a random position
2236
+ * `x∈[0,1]` is drawn (optionally biased by `distribution`) and mapped through
2237
+ * the gradient. Distinguished from `ColorGradientDefinition` by the absence of
2238
+ * `sourceParameterId` (that one re-samples every frame against a live source).
2239
+ */
2240
+ interface ColorRandomRange {
2241
+ stops: ColorStop[];
2242
+ distribution?: CurveDefinition;
2243
+ distributionKind?: ProbabilityCurveKind;
2244
+ }
2245
+ type SpawnColor = number | ColorGradientDefinition | ColorRandomRange | RandomValueList<number>;
2246
+
2247
+ export { type ParameterModifier as $, type AnimationDescription as A, type ExternalForcesTypes as B, type CapacityOptions as C, type DiagnosticsPolicy as D, type EmissionOptions as E, type LayerOptionType as F, type GlobalParameterOption as G, LocalDefaultHandle as H, type InitialStateOptions as I, LocalParameterHandle as J, type KineticsOptions as K, type LayerOptionPath as L, type ModifierBlendMode as M, type ModulatableNumber as N, type ModulatedValue as O, PerseonIntegration as P, type ModulatorOptions as Q, type ModulatorShape as R, type NumberOptions as S, type NumericDomain as T, type OptionNodeKind as U, type OptionStage as V, type OptionStrategy as W, type ParameterDescription as X, ParameterHandle as Y, type ParameterInitOptions as Z, type ParameterLinkRelation as _, type AnimationPlayOptions as a, OPTION_PATH_CATALOG as a$, type ParameterModifierSource as a0, type ParameterUpdateOptions as a1, type ParticleAnimationOptions as a2, type ParticleEventBinding as a3, type ParticleEventBindings as a4, type ParticleEventTrigger as a5, type ParticleEventsByTrigger as a6, type ParticleHookEmitter as a7, type ParticleHookPlayback as a8, type ParticleHookRandom as a9, type ProbabilityCurvePresetId as aA, type RandomListState as aB, type RandomValueList as aC, type RandomValueListMode as aD, type RandomValueRange as aE, type RandomnessOptions as aF, type RandomnessSeedMode as aG, type RectangleArea as aH, type RegionBehavior as aI, type RegionOptions as aJ, type RingArea as aK, type ScaleOptions as aL, type ShapeArea as aM, type SingleTextureOption as aN, type SpawnColor as aO, type SpawnNumber as aP, type SpawnPoint as aQ, type SpawnPosition as aR, type SpawnVector as aS, type SpriteAnimationOptions as aT, type SpriteAnimationTexturesOptions as aU, type TextDomain as aV, type TextureElement as aW, type Unsubscribe as aX, type ValueProbability as aY, type VectorValue as aZ, EMITTER_EVENT_TRIGGERS as a_, ParticleItem as aa, ParticleLayerView as ab, type ParticleLayerOptions as ac, type ParticleLimitStrategy as ad, type ParticleRegionRef as ae, type ParticleSnapshot as af, type ParticleSnapshotObject as ag, type ParticleSpawnStrategy as ah, type ParticleSpriteAnimationParameters as ai, type PerformanceOptions as aj, PerseonAnimation as ak, type PerseonEvent as al, PerseonPlayback as am, type PlaybackFinishedReason as an, type PlaybackFinishedResult as ao, type PlaybackHost as ap, type PlaybackOptionPath as aq, type PlaybackOptionType as ar, type PlaybackOptions as as, type PointForceConfig as at, type PointForceFalloff as au, type PointForceMode as av, type PointValue as aw, type PolygonArea as ax, type ProbabilityCurveKind as ay, type ProbabilityCurvePreset as az, type AnimationRandomnessOptions as b, type OptionPathEntry as b0, type OptionScope as b1, PARTICLE_EVENT_TRIGGERS as b2, findOptionPathEntry as b3, isEmitterEventTrigger as b4, isEventTrigger as b5, isParticleEventTrigger as b6, isValidEventName as b7, type CapsuleArea as c, type CircleArea as d, type ColorGradientDefinition as e, type ColorOptions as f, type ColorRandomRange as g, type ColorStop as h, type CurveDefinition as i, type CustomParameterOption as j, type CustomParameterSampleScope as k, type CustomParameterType as l, type CustomParameterValue as m, type EmissionTransform as n, EmitterView as o, type EmitterEventBinding as p, type EmitterEventBindings as q, type EmitterEventTrigger as r, type EmitterEventsByTrigger as s, type EmitterOptionPath as t, type EmitterOptionType as u, type EmitterOptions as v, type EventTrigger as w, type ExternalForcesFactorOptions as x, type ExternalForcesForEmitterUse as y, type ExternalForcesOptions as z };