laymur 0.27.1 → 0.28.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 (82) hide show
  1. package/README.md +46 -1
  2. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +2 -1
  3. package/dist/core/constraints/UICustomConstraint.js +1 -1
  4. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +2 -1
  5. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +2 -1
  6. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +2 -1
  7. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +2 -1
  8. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +2 -1
  9. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +2 -1
  10. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +2 -1
  11. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +2 -1
  12. package/dist/core/constraints/constraintAsserts.d.ts +41 -0
  13. package/dist/core/constraints/constraintAsserts.js +171 -0
  14. package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
  15. package/dist/core/elements/UIDummy/UIDummy.js +21 -10
  16. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
  17. package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
  18. package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
  19. package/dist/core/elements/UIElement/UIElement.js +14 -7
  20. package/dist/core/elements/UIText/UIText.d.ts +6 -1
  21. package/dist/core/elements/UIText/UIText.js +22 -12
  22. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +1 -1
  23. package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
  24. package/dist/core/miscellaneous/UIBlendMode.js +7 -0
  25. package/dist/core/miscellaneous/asserts.d.ts +0 -41
  26. package/dist/core/miscellaneous/asserts.js +0 -170
  27. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
  28. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
  29. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +4 -1
  30. package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +4 -1
  31. package/dist/core/miscellaneous/text-style/UITextStyle.js +4 -1
  32. package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
  33. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +6 -2
  34. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -0
  35. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +18 -9
  36. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
  37. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
  38. package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
  39. package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
  40. package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
  41. package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
  42. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
  43. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
  44. package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
  45. package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
  46. package/dist/particles/elements/UIEmitter.Internal.d.ts +45 -1
  47. package/dist/particles/elements/UIEmitter.Internal.js +25 -1
  48. package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
  49. package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
  50. package/dist/particles/elements/UIEmitter.d.ts +79 -9
  51. package/dist/particles/elements/UIEmitter.js +239 -82
  52. package/dist/particles/index.d.ts +13 -1
  53. package/dist/particles/index.js +11 -1
  54. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
  55. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
  56. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
  57. package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
  58. package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
  59. package/dist/particles/miscellaneous/miscellaneous.js +38 -0
  60. package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
  61. package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
  62. package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
  63. package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
  64. package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
  65. package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
  66. package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
  67. package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
  68. package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
  69. package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
  70. package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
  71. package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
  72. package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
  73. package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
  74. package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
  75. package/dist/particles/shaders/UIRenderingShape.js +15 -0
  76. package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
  77. package/dist/particles/shaders/UIRenderingTexture.js +27 -2
  78. package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
  79. package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
  80. package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
  81. package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
  82. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import type { UIEmitterPlayOptions } from "./UIEmitter.Internal.js";
2
+ /**
3
+ * Receives the particles due within a frame: `count` of them, at `firstMoment + k * interval`
4
+ * seconds from the frame start
5
+ */
6
+ export type UIEmissionSpawn = (count: number, firstMoment: number, interval: number) => void;
7
+ /**
8
+ * Timing of an emission: a stream by time and by distance, and bursts at an interval. Knows when
9
+ * particles are due, not where or how they are spawned.
10
+ */
11
+ export declare class UIEmissionSchedule {
12
+ private playing;
13
+ private rate;
14
+ private ratePerDistance;
15
+ private duration;
16
+ private burstInterval;
17
+ private burstCount;
18
+ private elapsed;
19
+ /** Particles of the stream due but not spawned yet, below 1 after each frame */
20
+ private accumulator;
21
+ private nextBurst;
22
+ /** Whether the emission has not ended yet */
23
+ get isPlaying(): boolean;
24
+ start(rate: number, options: Partial<UIEmitterPlayOptions>): void;
25
+ stop(): void;
26
+ /**
27
+ * Advances the emission by a frame and hands the particles due within it to `spawn`
28
+ * @param distance Distance the emitter moved during the frame
29
+ */
30
+ advance(deltaTime: number, distance: number, spawn: UIEmissionSpawn): void;
31
+ }
@@ -0,0 +1,81 @@
1
+ import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
2
+ import { assertValidNonNegativeInteger } from "../miscellaneous/miscellaneous.js";
3
+ /**
4
+ * Timing of an emission: a stream by time and by distance, and bursts at an interval. Knows when
5
+ * particles are due, not where or how they are spawned.
6
+ */
7
+ export class UIEmissionSchedule {
8
+ constructor() {
9
+ this.playing = false;
10
+ this.rate = 0;
11
+ this.ratePerDistance = 0;
12
+ this.duration = Infinity;
13
+ this.burstInterval = Infinity;
14
+ this.burstCount = 0;
15
+ this.elapsed = 0;
16
+ /** Particles of the stream due but not spawned yet, below 1 after each frame */
17
+ this.accumulator = 0;
18
+ this.nextBurst = 0;
19
+ }
20
+ /** Whether the emission has not ended yet */
21
+ get isPlaying() {
22
+ return this.playing;
23
+ }
24
+ start(rate, options) {
25
+ assertValidNonNegativeNumber(rate, "UIEmitter.play.rate");
26
+ this.ratePerDistance = options.ratePerDistance ?? 0;
27
+ assertValidNonNegativeNumber(this.ratePerDistance, "UIEmitter.play.options.ratePerDistance");
28
+ // Infinite unless given: endless emission, a single burst
29
+ this.duration = options.duration ?? Infinity;
30
+ if (options.duration !== undefined) {
31
+ assertValidNonNegativeNumber(options.duration, "UIEmitter.play.options.duration");
32
+ }
33
+ this.burstInterval = options.burstInterval ?? Infinity;
34
+ if (options.burstInterval !== undefined) {
35
+ assertValidPositiveNumber(options.burstInterval, "UIEmitter.play.options.burstInterval");
36
+ }
37
+ this.burstCount = options.burstCount ?? 0;
38
+ assertValidNonNegativeInteger(this.burstCount, "UIEmitter.play.options.burstCount");
39
+ this.playing = true;
40
+ this.rate = rate;
41
+ this.elapsed = 0;
42
+ this.accumulator = 0;
43
+ this.nextBurst = 0;
44
+ }
45
+ stop() {
46
+ this.playing = false;
47
+ }
48
+ /**
49
+ * Advances the emission by a frame and hands the particles due within it to `spawn`
50
+ * @param distance Distance the emitter moved during the frame
51
+ */
52
+ advance(deltaTime, distance, spawn) {
53
+ if (!this.playing) {
54
+ return;
55
+ }
56
+ const before = this.elapsed;
57
+ this.elapsed += deltaTime;
58
+ const end = Math.min(this.elapsed, this.duration);
59
+ const emittingTime = end - before;
60
+ while (this.burstCount > 0 && this.nextBurst <= end) {
61
+ spawn(this.burstCount, this.nextBurst - before, 0);
62
+ this.nextBurst += this.burstInterval;
63
+ }
64
+ if (emittingTime > 0) {
65
+ // The emitter is taken to move at a constant speed within the frame.
66
+ const added = this.rate * emittingTime + (this.ratePerDistance * distance * emittingTime) / deltaTime;
67
+ const accumulatorBefore = this.accumulator;
68
+ this.accumulator += added;
69
+ const count = Math.floor(this.accumulator);
70
+ if (count > 0) {
71
+ // The k-th particle of the frame, from 0, is due once the accumulator reaches k + 1.
72
+ const interval = emittingTime / added;
73
+ spawn(count, (1 - accumulatorBefore) * interval, interval);
74
+ this.accumulator -= count;
75
+ }
76
+ }
77
+ if (this.elapsed >= this.duration) {
78
+ this.playing = false;
79
+ }
80
+ }
81
+ }
@@ -1,13 +1,17 @@
1
+ import type { FerrsignView2 } from "ferrsign";
1
2
  import { UIAnchor } from "../../core/elements/UIAnchor/UIAnchor.js";
2
- import type { UILayer } from "../../core/index.js";
3
+ import type { UIBlendMode, UILayer } from "../../core/index.js";
3
4
  import type { UIBehaviorModule } from "../behaviorModules/UIBehaviorModule.js";
4
5
  import type { UIRenderingModule } from "../renderingModules/UIRenderingModule.js";
5
6
  import type { UISpawnModule } from "../spawnModules/UISpawnModule.js";
6
7
  import type { UIEmitterMode, UIEmitterOptions, UIEmitterPlayOptions } from "./UIEmitter.Internal.js";
8
+ import { UIEmitterSpace } from "./UIEmitter.Internal.js";
7
9
  /**
8
10
  * Particle emitter element.
9
11
  *
10
- * Spawns, updates, and renders particles using modular spawn/behavior/rendering pipeline.
12
+ * Spawns, updates, and renders particles using modular spawn/behavior/rendering pipeline. Each
13
+ * frame ages the particles and removes the dead ones, spawns the particles due, runs the behavior
14
+ * modules and moves the particles along their velocity.
11
15
  */
12
16
  export declare class UIEmitter extends UIAnchor {
13
17
  private readonly spawnSequence;
@@ -17,15 +21,26 @@ export declare class UIEmitter extends UIAnchor {
17
21
  automaticallyDestroyModules: boolean;
18
22
  private readonly mesh;
19
23
  private readonly catcherHandler;
20
- private emissionRate;
21
- private emissionAccumulator;
22
- private emissionDuration;
23
- private emissionElapsed;
24
+ private readonly emission;
25
+ /** Path of the emitter over the current frame, along which emission places particles */
26
+ private readonly framePath;
27
+ /** Path of a single point and moment, for bursts */
28
+ private readonly pointPath;
29
+ /** Layer positions of the particles that died this frame, x and y in turn */
30
+ private readonly deadPositions;
31
+ private readonly signalParticleDiedInternal;
24
32
  private modeInternal;
33
+ private blendModeInternal;
34
+ private spaceInternal;
25
35
  private maxDeltaTimeInternal;
26
36
  private seedInternal;
27
37
  /** Particles spawned since the seed was set; picks the seed of the next particle */
28
38
  private spawnedCount;
39
+ /** Emitter position at the end of the last frame, where the emission of this frame starts */
40
+ private previousX;
41
+ private previousY;
42
+ /** Whether `play` was called since the last frame: its emission starts at the current position */
43
+ private emissionStarted;
29
44
  /**
30
45
  * @param layer - Layer containing this emitter
31
46
  * @param spawnSequence - Modules that initialize new particles
@@ -34,19 +49,38 @@ export declare class UIEmitter extends UIAnchor {
34
49
  * @param options - Configuration options
35
50
  */
36
51
  constructor(layer: UILayer, spawnSequence: UISpawnModule[], behaviorSequence: readonly UIBehaviorModule[], renderingSequence: readonly UIRenderingModule[], options?: Partial<UIEmitterOptions>);
52
+ /**
53
+ * Fires for every particle that dies, with its position in layer coordinates. Fires after the
54
+ * frame removed its dead particles, so a callback may spawn particles, also on this emitter.
55
+ */
56
+ get signalParticleDied(): FerrsignView2<number, number>;
37
57
  /** Seed of the random values */
38
58
  get seed(): number;
39
59
  /** Longest frame step in seconds; longer frames are clamped */
40
60
  get maxDeltaTime(): number;
41
61
  /** Visibility mode */
42
62
  get mode(): UIEmitterMode;
63
+ /** Color blending of the particles with what is drawn under them */
64
+ get blendMode(): UIBlendMode;
65
+ /** Coordinate space of particle positions */
66
+ get space(): UIEmitterSpace;
43
67
  /**
44
68
  * Rendering order among the elements of the layer. Higher values on top; elements with equal
45
69
  * values keep the order of creation, a later one on top.
46
70
  */
47
71
  get zIndex(): number;
72
+ /**
73
+ * Layer point particle positions are relative to: the emitter in LOCAL space, where live
74
+ * particles move with it, the layer origin in WORLD space
75
+ */
76
+ private get originX();
77
+ private get originY();
48
78
  /** Visibility mode */
49
79
  set mode(value: UIEmitterMode);
80
+ /** Color blending of the particles with what is drawn under them */
81
+ set blendMode(value: UIBlendMode);
82
+ /** Coordinate space of particle positions. Live particles keep their place on the layer. */
83
+ set space(value: UIEmitterSpace);
50
84
  /** Longest frame step in seconds; longer frames are clamped */
51
85
  set maxDeltaTime(value: number);
52
86
  /**
@@ -66,18 +100,54 @@ export declare class UIEmitter extends UIAnchor {
66
100
  * @param count - Number of particles to create, a non-negative integer
67
101
  */
68
102
  burst(count: number): void;
103
+ /**
104
+ * Spawns particles immediately as if the emitter stood at a point, such as where a particle of
105
+ * another emitter died
106
+ *
107
+ * @param count - Number of particles to create, a non-negative integer
108
+ * @param x - Point in layer coordinates
109
+ * @param y - Point in layer coordinates
110
+ */
111
+ burstAt(count: number, x: number, y: number): void;
112
+ /**
113
+ * Runs the simulation ahead without drawing, so that an emission started with `play` shows
114
+ * its particles in full from the first frame. The emitter stays where it is meanwhile.
115
+ *
116
+ * @param duration - Seconds to simulate
117
+ * @param step - Simulation step in seconds; the last step is shorter if needed
118
+ */
119
+ prewarm(duration: number, step?: number): void;
69
120
  /** Removes all active particles */
70
121
  clear(): void;
71
122
  /**
72
- * Starts continuous particle emission.
123
+ * Starts particle emission: a stream by time and by distance moved, and bursts. Particles due
124
+ * within a frame are spread over it.
73
125
  *
74
126
  * @param rate - Particles per second
75
- * @param options - Emission duration and other settings
127
+ * @param options - Duration, particles per distance and bursts
76
128
  */
77
129
  play(rate: number, options?: Partial<UIEmitterPlayOptions>): void;
78
- /** Stops continuous particle emission */
130
+ /** Stops particle emission; live particles play out */
79
131
  stop(): void;
80
132
  /** Frees the particles and the input catcher, optionally destroys modules */
81
133
  protected destroyInternal(): void;
134
+ /** Sets the point path to a point at the end of the last frame */
135
+ private setPointPath;
136
+ /**
137
+ * Spawns particles at moments `firstMoment + k * interval` seconds from the start of a frame.
138
+ * Spawn modules write a particle relative to the emitter; it is then placed at the point of the
139
+ * path at its moment and aged by the rest of the frame.
140
+ */
141
+ private spawnParticles;
142
+ /** Spawns the particles the emission schedule hands out, along the frame path */
143
+ private readonly spawnDue;
144
+ /** Spawns the particles of the emission due within a frame of `deltaTime` seconds */
145
+ private emit;
146
+ /** Removes the dead particles and reports them through the signal */
147
+ private removeDeadParticles;
148
+ /** Records the layer position of a dead particle */
149
+ private readonly collectDeadParticle;
150
+ /** Advances the particles and the emission by `deltaTime` seconds */
151
+ private simulate;
82
152
  private readonly onRendering;
83
153
  }