@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.3

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 (80) hide show
  1. package/ReadMe.md +1 -1
  2. package/biome.json +41 -0
  3. package/dist/core/Interpolation.d.ts +30 -0
  4. package/dist/core/Interpolation.js +200 -0
  5. package/dist/core/Scene.d.ts +96 -0
  6. package/dist/core/Scene.js +172 -0
  7. package/dist/core/Signal.d.ts +133 -0
  8. package/dist/core/Signal.js +255 -0
  9. package/dist/core/SignalUtils.d.ts +133 -0
  10. package/dist/core/SignalUtils.js +333 -0
  11. package/dist/core/ThreadScheduler.d.ts +38 -0
  12. package/dist/core/ThreadScheduler.js +74 -0
  13. package/dist/helpers/Filters.js +1 -1
  14. package/dist/helpers/FontsList.js +18 -18
  15. package/dist/helpers/Utlis.d.ts +3 -3
  16. package/dist/helpers/Utlis.js +15 -18
  17. package/dist/helpers/index.d.ts +3 -3
  18. package/dist/index.d.ts +10 -0
  19. package/dist/index.js +10 -0
  20. package/dist/jsx-runtime.d.ts +17 -0
  21. package/dist/jsx-runtime.js +111 -0
  22. package/dist/structures/LazyCanvas.d.ts +3 -45
  23. package/dist/structures/LazyCanvas.js +11 -74
  24. package/dist/structures/components/BaseLayer.d.ts +34 -12
  25. package/dist/structures/components/BaseLayer.js +68 -35
  26. package/dist/structures/components/BezierLayer.d.ts +16 -37
  27. package/dist/structures/components/BezierLayer.js +83 -46
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +22 -16
  29. package/dist/structures/components/{Group.js → Div.js} +38 -39
  30. package/dist/structures/components/ImageLayer.d.ts +1 -1
  31. package/dist/structures/components/ImageLayer.js +24 -25
  32. package/dist/structures/components/LineLayer.d.ts +11 -37
  33. package/dist/structures/components/LineLayer.js +42 -42
  34. package/dist/structures/components/MorphLayer.d.ts +3 -32
  35. package/dist/structures/components/MorphLayer.js +32 -46
  36. package/dist/structures/components/Path2DLayer.d.ts +4 -32
  37. package/dist/structures/components/Path2DLayer.js +28 -33
  38. package/dist/structures/components/PolygonLayer.d.ts +2 -31
  39. package/dist/structures/components/PolygonLayer.js +35 -38
  40. package/dist/structures/components/QuadraticLayer.d.ts +16 -33
  41. package/dist/structures/components/QuadraticLayer.js +80 -42
  42. package/dist/structures/components/TextLayer.d.ts +4 -33
  43. package/dist/structures/components/TextLayer.js +60 -62
  44. package/dist/structures/components/index.d.ts +10 -11
  45. package/dist/structures/components/index.js +1 -2
  46. package/dist/structures/helpers/Exporter.d.ts +13 -4
  47. package/dist/structures/helpers/Exporter.js +79 -42
  48. package/dist/structures/helpers/Font.js +1 -17
  49. package/dist/structures/helpers/Gradient.js +32 -45
  50. package/dist/structures/helpers/Link.js +2 -14
  51. package/dist/structures/helpers/Pattern.js +9 -17
  52. package/dist/structures/helpers/index.d.ts +7 -7
  53. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  54. package/dist/structures/helpers/readers/JSONReader.js +32 -40
  55. package/dist/structures/helpers/readers/YAMLReader.js +5 -5
  56. package/dist/structures/managers/FontsManager.js +9 -18
  57. package/dist/structures/managers/LayersManager.d.ts +18 -28
  58. package/dist/structures/managers/LayersManager.js +14 -36
  59. package/dist/structures/managers/RenderManager.d.ts +1 -15
  60. package/dist/structures/managers/RenderManager.js +17 -110
  61. package/dist/structures/managers/index.d.ts +3 -5
  62. package/dist/structures/managers/index.js +0 -2
  63. package/dist/types/enum.d.ts +1 -2
  64. package/dist/types/enum.js +1 -2
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/utils/APNGEncoder.d.ts +67 -0
  67. package/dist/utils/APNGEncoder.js +205 -0
  68. package/dist/utils/DrawUtils.d.ts +9 -0
  69. package/dist/utils/DrawUtils.js +42 -0
  70. package/dist/utils/LazyUtil.js +1 -2
  71. package/dist/utils/utils.d.ts +4 -7
  72. package/dist/utils/utils.js +133 -76
  73. package/package.json +62 -59
  74. package/dist/structures/components/ClearLayer.d.ts +0 -147
  75. package/dist/structures/components/ClearLayer.js +0 -158
  76. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  77. package/dist/structures/managers/AnimationManager.js +0 -99
  78. package/dist/structures/managers/PluginManager.d.ts +0 -230
  79. package/dist/structures/managers/PluginManager.js +0 -182
  80. package/dist/types/types.d.ts +0 -107
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Signal = exports.Easing = void 0;
4
+ exports.createSignal = createSignal;
5
+ exports.isSignal = isSignal;
6
+ exports.unwrap = unwrap;
7
+ exports.resetSignals = resetSignals;
8
+ const Interpolation_1 = require("./Interpolation");
9
+ /**
10
+ * Standard easing functions
11
+ */
12
+ exports.Easing = {
13
+ linear: (t) => t,
14
+ // Quadratic
15
+ easeIn: (t) => t * t,
16
+ easeOut: (t) => 1 - Math.pow(1 - t, 2),
17
+ easeInOut: (t) => (t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2),
18
+ // Cubic
19
+ easeInCubic: (t) => t * t * t,
20
+ easeOutCubic: (t) => 1 - Math.pow(1 - t, 3),
21
+ easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2),
22
+ // Quartic
23
+ easeInQuart: (t) => t * t * t * t,
24
+ easeOutQuart: (t) => 1 - Math.pow(1 - t, 4),
25
+ easeInOutQuart: (t) => (t < 0.5 ? 8 * t * t * t * t : 1 - Math.pow(-2 * t + 2, 4) / 2),
26
+ // Quintic
27
+ easeInQuint: (t) => t * t * t * t * t,
28
+ easeOutQuint: (t) => 1 - Math.pow(1 - t, 5),
29
+ easeInOutQuint: (t) => t < 0.5 ? 16 * t * t * t * t * t : 1 - Math.pow(-2 * t + 2, 5) / 2,
30
+ // Sine
31
+ easeInSine: (t) => 1 - Math.cos((t * Math.PI) / 2),
32
+ easeOutSine: (t) => Math.sin((t * Math.PI) / 2),
33
+ easeInOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
34
+ // Exponential
35
+ easeInExpo: (t) => (t === 0 ? 0 : Math.pow(2, 10 * t - 10)),
36
+ easeOutExpo: (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)),
37
+ easeInOutExpo: (t) => {
38
+ if (t === 0)
39
+ return 0;
40
+ if (t === 1)
41
+ return 1;
42
+ return t < 0.5 ? Math.pow(2, 20 * t - 10) / 2 : (2 - Math.pow(2, -20 * t + 10)) / 2;
43
+ },
44
+ // Circular
45
+ easeInCirc: (t) => 1 - Math.sqrt(1 - Math.pow(t, 2)),
46
+ easeOutCirc: (t) => Math.sqrt(1 - Math.pow(t - 1, 2)),
47
+ easeInOutCirc: (t) => t < 0.5
48
+ ? (1 - Math.sqrt(1 - Math.pow(2 * t, 2))) / 2
49
+ : (Math.sqrt(1 - Math.pow(-2 * t + 2, 2)) + 1) / 2,
50
+ // Back
51
+ easeInBack: (t) => {
52
+ const c1 = 1.70158;
53
+ const c3 = c1 + 1;
54
+ return c3 * t * t * t - c1 * t * t;
55
+ },
56
+ easeOutBack: (t) => {
57
+ const c1 = 1.70158;
58
+ const c3 = c1 + 1;
59
+ return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
60
+ },
61
+ easeInOutBack: (t) => {
62
+ const c1 = 1.70158;
63
+ const c2 = c1 * 1.525;
64
+ return t < 0.5
65
+ ? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
66
+ : (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
67
+ },
68
+ // Elastic
69
+ easeInElastic: (t) => {
70
+ const c4 = (2 * Math.PI) / 3;
71
+ return t === 0 ? 0 : t === 1 ? 1 : -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
72
+ },
73
+ easeOutElastic: (t) => {
74
+ const c4 = (2 * Math.PI) / 3;
75
+ return t === 0 ? 0 : t === 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
76
+ },
77
+ easeInOutElastic: (t) => {
78
+ const c5 = (2 * Math.PI) / 4.5;
79
+ return t === 0
80
+ ? 0
81
+ : t === 1
82
+ ? 1
83
+ : t < 0.5
84
+ ? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
85
+ : (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
86
+ },
87
+ // Bounce
88
+ easeInBounce: (t) => 1 - exports.Easing.easeOutBounce(1 - t),
89
+ easeOutBounce: (t) => {
90
+ const n1 = 7.5625;
91
+ const d1 = 2.75;
92
+ if (t < 1 / d1) {
93
+ return n1 * t * t;
94
+ }
95
+ else if (t < 2 / d1) {
96
+ return n1 * (t -= 1.5 / d1) * t + 0.75;
97
+ }
98
+ else if (t < 2.5 / d1) {
99
+ return n1 * (t -= 2.25 / d1) * t + 0.9375;
100
+ }
101
+ else {
102
+ return n1 * (t -= 2.625 / d1) * t + 0.984375;
103
+ }
104
+ },
105
+ easeInOutBounce: (t) => t < 0.5 ? (1 - exports.Easing.easeOutBounce(1 - 2 * t)) / 2 : (1 + exports.Easing.easeOutBounce(2 * t - 1)) / 2,
106
+ };
107
+ /**
108
+ * Signal class - reactive value that can be animated
109
+ */
110
+ class Signal {
111
+ constructor(initial, options) {
112
+ this._currentThread = null;
113
+ this._value = initial;
114
+ this._initialValue = initial;
115
+ this._interpolator = options?.interpolator || (0, Interpolation_1.getInterpolator)(initial, initial);
116
+ this._colorSpace = options?.colorSpace || "rgb";
117
+ }
118
+ /**
119
+ * Get current value at specific time (backward compatibility)
120
+ */
121
+ get(time) {
122
+ return this._value;
123
+ }
124
+ /**
125
+ * Get current value (sync)
126
+ */
127
+ value() {
128
+ return this._value;
129
+ }
130
+ /**
131
+ * Set value directly
132
+ */
133
+ set(value) {
134
+ this._value = value;
135
+ this._currentThread = null;
136
+ }
137
+ /**
138
+ * Reset to initial value
139
+ */
140
+ reset() {
141
+ this._value = this._initialValue;
142
+ this._currentThread = null;
143
+ }
144
+ /**
145
+ * Animate to a new value - returns a generator
146
+ */
147
+ *to(value, duration, config) {
148
+ const from = this._value;
149
+ const easing = config?.easing || exports.Easing.linear;
150
+ const interpolator = config?.interpolator || this._getInterpolator(from, value);
151
+ if (duration <= 0) {
152
+ this._value = value;
153
+ return;
154
+ }
155
+ let elapsed = 0;
156
+ while (elapsed < duration) {
157
+ const delta = yield;
158
+ const actualDelta = typeof delta === "number" ? delta : 1 / 60; // Default 60fps
159
+ elapsed += actualDelta;
160
+ const progress = Math.min(elapsed / duration, 1);
161
+ const easedProgress = easing(progress);
162
+ this._value = interpolator(from, value, easedProgress);
163
+ // Critical: ensure we don't overshoot
164
+ if (elapsed >= duration) {
165
+ this._value = value;
166
+ break;
167
+ }
168
+ }
169
+ // Final value assignment
170
+ this._value = value;
171
+ }
172
+ /**
173
+ * Wait for a duration without changing value
174
+ */
175
+ *wait(duration) {
176
+ let elapsed = 0;
177
+ while (elapsed < duration) {
178
+ const delta = yield;
179
+ const actualDelta = typeof delta === "number" ? delta : 1 / 60;
180
+ elapsed += actualDelta;
181
+ }
182
+ }
183
+ /**
184
+ * Run animation from generator
185
+ */
186
+ run(generator) {
187
+ this._currentThread = generator;
188
+ return this;
189
+ }
190
+ /**
191
+ * Update signal (called by scheduler)
192
+ */
193
+ update(delta) {
194
+ if (!this._currentThread)
195
+ return false;
196
+ const result = this._currentThread.next(delta);
197
+ if (result.done) {
198
+ this._currentThread = null;
199
+ return false;
200
+ }
201
+ return true;
202
+ }
203
+ /**
204
+ * Check if signal has active animation
205
+ */
206
+ isAnimating() {
207
+ return this._currentThread !== null;
208
+ }
209
+ /**
210
+ * Internal: get interpolator for values
211
+ */
212
+ _getInterpolator(from, to) {
213
+ // Check if it's a color string
214
+ if (typeof from === "string" && typeof to === "string") {
215
+ const fromStr = from;
216
+ if (fromStr.startsWith("#") || fromStr.startsWith("rgb") || fromStr.startsWith("hsl")) {
217
+ return (this._colorSpace === "hsl"
218
+ ? Interpolation_1.lerpColorHSL
219
+ : Interpolation_1.lerpColorRGB);
220
+ }
221
+ }
222
+ return this._interpolator;
223
+ }
224
+ }
225
+ exports.Signal = Signal;
226
+ /**
227
+ * Create a new signal
228
+ */
229
+ function createSignal(initial, options) {
230
+ return new Signal(initial, options);
231
+ }
232
+ /**
233
+ * Type guard for signals
234
+ */
235
+ function isSignal(value) {
236
+ return value instanceof Signal;
237
+ }
238
+ /**
239
+ * Unwrap signal or return value
240
+ */
241
+ function unwrap(value) {
242
+ if (isSignal(value)) {
243
+ return value.value();
244
+ }
245
+ return value;
246
+ }
247
+ /**
248
+ * Reset multiple signals to their initial values
249
+ */
250
+ function resetSignals(...signals) {
251
+ for (const signal of signals) {
252
+ signal.reset();
253
+ }
254
+ }
255
+ exports.default = Signal;
@@ -0,0 +1,133 @@
1
+ import { ThreadGenerator, Signal } from "./Signal";
2
+ /**
3
+ * Run multiple animations in parallel
4
+ * @param generators - Array of animation generators
5
+ */
6
+ export declare function all(...generators: ThreadGenerator[]): ThreadGenerator;
7
+ /**
8
+ * Run animations in sequence
9
+ * @param generators - Array of animation generators
10
+ */
11
+ export declare function chain(...generators: ThreadGenerator[]): ThreadGenerator;
12
+ /**
13
+ * Run animation in a loop
14
+ * @param generator - Animation generator factory
15
+ * @param times - Number of iterations (Infinity for endless)
16
+ */
17
+ export declare function loop(generator: () => ThreadGenerator, times?: number): ThreadGenerator;
18
+ /**
19
+ * Run animation for a specific duration
20
+ * @param generator - Animation generator factory
21
+ * @param duration - Total duration in seconds
22
+ */
23
+ export declare function loopFor(generator: () => ThreadGenerator, duration: number): ThreadGenerator;
24
+ /**
25
+ * Wait for a specific duration
26
+ * @param duration - Duration in seconds
27
+ */
28
+ export declare function waitFor(duration: number): ThreadGenerator;
29
+ /**
30
+ * Delay an animation by a specific duration
31
+ * @param duration - Delay in seconds
32
+ * @param generator - Animation generator
33
+ */
34
+ export declare function delay(duration: number, generator: ThreadGenerator): ThreadGenerator;
35
+ /**
36
+ * Run animations until any one completes
37
+ * @param generators - Array of animation generators
38
+ */
39
+ export declare function any(...generators: ThreadGenerator[]): ThreadGenerator;
40
+ /**
41
+ * Conditional animation
42
+ * @param condition - Condition function
43
+ * @param trueGen - Generator if condition is true
44
+ * @param falseGen - Generator if condition is false
45
+ */
46
+ export declare function conditional(condition: () => boolean, trueGen: ThreadGenerator, falseGen?: ThreadGenerator): ThreadGenerator;
47
+ /**
48
+ * Repeat animation while condition is true
49
+ * @param condition - Condition function
50
+ * @param generator - Animation generator factory
51
+ */
52
+ export declare function repeatWhile(condition: () => boolean, generator: () => ThreadGenerator): ThreadGenerator;
53
+ /**
54
+ * Run animation at specific intervals
55
+ * @param interval - Interval duration in seconds
56
+ * @param generator - Animation generator factory
57
+ * @param times - Number of times to run (Infinity for endless)
58
+ */
59
+ export declare function every(interval: number, generator: () => ThreadGenerator, times?: number): ThreadGenerator;
60
+ /**
61
+ * Spring animation utility
62
+ * @param signal - Signal to animate
63
+ * @param target - Target value
64
+ * @param config - Spring configuration
65
+ */
66
+ export declare function spring<T>(signal: Signal<T>, target: T, config?: {
67
+ stiffness?: number;
68
+ damping?: number;
69
+ mass?: number;
70
+ precision?: number;
71
+ }): ThreadGenerator;
72
+ /**
73
+ * Tween between multiple values in sequence
74
+ * @param signal - Signal to animate
75
+ * @param values - Array of target values
76
+ * @param duration - Duration for each tween
77
+ * @param config - Tween configuration
78
+ */
79
+ export declare function sequence<T>(signal: Signal<T>, values: T[], duration: number, config?: Parameters<Signal<T>["to"]>[2]): ThreadGenerator;
80
+ /**
81
+ * Animate signal back and forth
82
+ * @param signal - Signal to animate
83
+ * @param from - Start value
84
+ * @param to - End value
85
+ * @param duration - Duration for each direction
86
+ * @param config - Tween configuration
87
+ */
88
+ export declare function yoyo<T>(signal: Signal<T>, from: T, to: T, duration: number, config?: Parameters<Signal<T>["to"]>[2]): ThreadGenerator;
89
+ /**
90
+ * Create a timeline builder for complex animations
91
+ */
92
+ export declare class Timeline {
93
+ private generators;
94
+ private currentTime;
95
+ /**
96
+ * Add animation at specific time
97
+ */
98
+ at(time: number, generator: ThreadGenerator): this;
99
+ /**
100
+ * Add animation after previous
101
+ */
102
+ then(generator: ThreadGenerator): this;
103
+ /**
104
+ * Set current time cursor
105
+ */
106
+ seek(time: number): this;
107
+ /**
108
+ * Execute timeline
109
+ */
110
+ play(): ThreadGenerator;
111
+ }
112
+ /**
113
+ * Create a timeline
114
+ */
115
+ export declare function timeline(): Timeline;
116
+ /**
117
+ * Calculate the total duration of an animation by running it with a fixed timestep
118
+ * @param generatorFactory - Function that creates the animation generator
119
+ * @param maxDuration - Maximum duration to simulate (safety limit, default: 3600s = 1 hour)
120
+ * @param timestep - Simulation timestep in seconds (default: 1/60)
121
+ * @returns Total duration in seconds
122
+ */
123
+ export declare function calculateDuration(generatorFactory: () => ThreadGenerator, maxDuration?: number, timestep?: number): number;
124
+ /**
125
+ * Calculate duration from multiple animation factories running in parallel
126
+ * Returns the duration of the longest animation
127
+ */
128
+ export declare function calculateParallelDuration(generatorFactories: (() => ThreadGenerator)[], maxDuration?: number, timestep?: number): number;
129
+ /**
130
+ * Calculate duration from multiple animation factories running in sequence
131
+ * Returns the sum of all animation durations
132
+ */
133
+ export declare function calculateSequentialDuration(generatorFactories: (() => ThreadGenerator)[], maxDuration?: number, timestep?: number): number;