@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.10

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 (91) hide show
  1. package/ReadMe.md +1 -1
  2. package/dist/core/Interpolation.d.ts +30 -0
  3. package/dist/core/Interpolation.js +200 -0
  4. package/dist/core/Scene.d.ts +94 -0
  5. package/dist/core/Scene.js +157 -0
  6. package/dist/core/Signal.d.ts +133 -0
  7. package/dist/core/Signal.js +255 -0
  8. package/dist/core/SignalUtils.d.ts +133 -0
  9. package/dist/core/SignalUtils.js +333 -0
  10. package/dist/core/ThreadScheduler.d.ts +38 -0
  11. package/dist/core/ThreadScheduler.js +74 -0
  12. package/dist/core/index.d.ts +5 -0
  13. package/dist/core/index.js +21 -0
  14. package/dist/helpers/Filters.js +1 -1
  15. package/dist/helpers/FontsList.js +18 -18
  16. package/dist/helpers/Utlis.d.ts +3 -3
  17. package/dist/helpers/Utlis.js +25 -36
  18. package/dist/helpers/index.d.ts +3 -3
  19. package/dist/index.d.ts +4 -1
  20. package/dist/index.js +4 -1
  21. package/dist/jsx-runtime.d.ts +17 -0
  22. package/dist/jsx-runtime.js +111 -0
  23. package/dist/structures/LazyCanvas.d.ts +10 -48
  24. package/dist/structures/LazyCanvas.js +17 -78
  25. package/dist/structures/components/BaseLayer.d.ts +78 -32
  26. package/dist/structures/components/BaseLayer.js +106 -37
  27. package/dist/structures/components/BezierLayer.d.ts +25 -38
  28. package/dist/structures/components/BezierLayer.js +88 -53
  29. package/dist/structures/components/{Group.d.ts → Div.d.ts} +37 -18
  30. package/dist/structures/components/Div.js +202 -0
  31. package/dist/structures/components/ImageLayer.d.ts +1 -1
  32. package/dist/structures/components/ImageLayer.js +28 -29
  33. package/dist/structures/components/LineLayer.d.ts +18 -36
  34. package/dist/structures/components/LineLayer.js +43 -45
  35. package/dist/structures/components/MorphLayer.d.ts +4 -33
  36. package/dist/structures/components/MorphLayer.js +37 -51
  37. package/dist/structures/components/Path2DLayer.d.ts +7 -35
  38. package/dist/structures/components/Path2DLayer.js +32 -41
  39. package/dist/structures/components/PolygonLayer.d.ts +3 -32
  40. package/dist/structures/components/PolygonLayer.js +37 -42
  41. package/dist/structures/components/QuadraticLayer.d.ts +25 -34
  42. package/dist/structures/components/QuadraticLayer.js +83 -47
  43. package/dist/structures/components/TextLayer.d.ts +5 -34
  44. package/dist/structures/components/TextLayer.js +88 -71
  45. package/dist/structures/components/index.d.ts +10 -11
  46. package/dist/structures/components/index.js +1 -2
  47. package/dist/structures/helpers/Exporter.d.ts +13 -4
  48. package/dist/structures/helpers/Exporter.js +82 -46
  49. package/dist/structures/helpers/Font.js +1 -17
  50. package/dist/structures/helpers/Gradient.js +35 -49
  51. package/dist/structures/helpers/Link.js +2 -14
  52. package/dist/structures/helpers/Pattern.js +10 -18
  53. package/dist/structures/helpers/index.d.ts +7 -7
  54. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  55. package/dist/structures/helpers/readers/JSONReader.js +44 -48
  56. package/dist/structures/helpers/readers/YAMLReader.js +11 -11
  57. package/dist/structures/managers/FontsManager.js +9 -18
  58. package/dist/structures/managers/LayersManager.d.ts +18 -28
  59. package/dist/structures/managers/LayersManager.js +14 -36
  60. package/dist/structures/managers/LayoutManager.d.ts +23 -0
  61. package/dist/structures/managers/LayoutManager.js +409 -0
  62. package/dist/structures/managers/index.d.ts +3 -5
  63. package/dist/structures/managers/index.js +1 -3
  64. package/dist/structures/managers/{RenderManager.d.ts → piplines/ClassicRenderPipeline.d.ts} +4 -30
  65. package/dist/structures/managers/piplines/ClassicRenderPipeline.js +90 -0
  66. package/dist/structures/managers/piplines/ModernRenderPipeline.d.ts +44 -0
  67. package/dist/structures/managers/piplines/ModernRenderPipeline.js +123 -0
  68. package/dist/structures/managers/piplines/index.d.ts +24 -0
  69. package/dist/structures/managers/piplines/index.js +18 -0
  70. package/dist/types/enum.d.ts +1 -2
  71. package/dist/types/enum.js +1 -2
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/types.d.ts +257 -107
  74. package/dist/utils/APNGEncoder.d.ts +67 -0
  75. package/dist/utils/APNGEncoder.js +205 -0
  76. package/dist/utils/DrawUtils.d.ts +9 -0
  77. package/dist/utils/DrawUtils.js +42 -0
  78. package/dist/utils/LazyUtil.js +1 -2
  79. package/dist/utils/index.d.ts +4 -0
  80. package/dist/utils/index.js +20 -0
  81. package/dist/utils/utils.d.ts +4 -7
  82. package/dist/utils/utils.js +140 -78
  83. package/package.json +61 -59
  84. package/dist/structures/components/ClearLayer.d.ts +0 -147
  85. package/dist/structures/components/ClearLayer.js +0 -158
  86. package/dist/structures/components/Group.js +0 -153
  87. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  88. package/dist/structures/managers/AnimationManager.js +0 -99
  89. package/dist/structures/managers/PluginManager.d.ts +0 -230
  90. package/dist/structures/managers/PluginManager.js +0 -182
  91. package/dist/structures/managers/RenderManager.js +0 -183
package/ReadMe.md CHANGED
@@ -1,4 +1,4 @@
1
- ![Logo](./resources/logo.svg)
1
+ ![Logo](https://raw.githubusercontent.com/NMMTY/LazyCanvas/refs/heads/main/packages/lazycanvas/resources/logo.svg)
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40nmmty%2Flazycanvas.svg)](https://www.npmjs.com/package/@nmmty/lazycanvas)
4
4
  [![downloads](https://img.shields.io/npm/dm/%40nmmty%2Flazycanvas.svg)](https://www.npmjs.com/package/@nmmty/lazycanvas)
@@ -0,0 +1,30 @@
1
+ export type Interpolator<T> = (from: T, to: T, progress: number) => T;
2
+ /**
3
+ * Linear interpolation for numbers
4
+ */
5
+ export declare function lerpNumber(from: number, to: number, progress: number): number;
6
+ /**
7
+ * Interpolate colors in RGB space
8
+ */
9
+ export declare function lerpColorRGB(from: string, to: string, progress: number): string;
10
+ /**
11
+ * Interpolate colors in HSL space (smoother for hue transitions)
12
+ */
13
+ export declare function lerpColorHSL(from: string, to: string, progress: number): string;
14
+ /**
15
+ * Interpolate 2D vectors/points
16
+ */
17
+ export declare function lerpVector(from: {
18
+ x: number;
19
+ y: number;
20
+ }, to: {
21
+ x: number;
22
+ y: number;
23
+ }, progress: number): {
24
+ x: number;
25
+ y: number;
26
+ };
27
+ /**
28
+ * Auto-detect interpolator based on value type
29
+ */
30
+ export declare function getInterpolator<T>(from: T, to: T): Interpolator<T>;
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lerpNumber = lerpNumber;
4
+ exports.lerpColorRGB = lerpColorRGB;
5
+ exports.lerpColorHSL = lerpColorHSL;
6
+ exports.lerpVector = lerpVector;
7
+ exports.getInterpolator = getInterpolator;
8
+ /**
9
+ * Linear interpolation for numbers
10
+ */
11
+ function lerpNumber(from, to, progress) {
12
+ return from + (to - from) * progress;
13
+ }
14
+ /**
15
+ * Parse color string to RGBA components
16
+ */
17
+ function parseColor(color) {
18
+ // Handle hex colors
19
+ if (color.startsWith("#")) {
20
+ const hex = color.slice(1);
21
+ let r, g, b, a = 1;
22
+ if (hex.length === 3 || hex.length === 4) {
23
+ r = parseInt(hex[0] + hex[0], 16);
24
+ g = parseInt(hex[1] + hex[1], 16);
25
+ b = parseInt(hex[2] + hex[2], 16);
26
+ a = hex.length === 4 ? parseInt(hex[3] + hex[3], 16) / 255 : 1;
27
+ }
28
+ else if (hex.length === 6 || hex.length === 8) {
29
+ r = parseInt(hex.slice(0, 2), 16);
30
+ g = parseInt(hex.slice(2, 4), 16);
31
+ b = parseInt(hex.slice(4, 6), 16);
32
+ a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
33
+ }
34
+ else {
35
+ return null;
36
+ }
37
+ return { r, g, b, a };
38
+ }
39
+ // Handle rgb/rgba
40
+ const rgbaMatch = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
41
+ if (rgbaMatch) {
42
+ return {
43
+ r: parseInt(rgbaMatch[1]),
44
+ g: parseInt(rgbaMatch[2]),
45
+ b: parseInt(rgbaMatch[3]),
46
+ a: rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1,
47
+ };
48
+ }
49
+ // Handle hsl/hsla
50
+ const hslaMatch = color.match(/hsla?\((\d+),\s*(\d+)%,\s*(\d+)%(?:,\s*([\d.]+))?\)/);
51
+ if (hslaMatch) {
52
+ const h = parseInt(hslaMatch[1]) / 360;
53
+ const s = parseInt(hslaMatch[2]) / 100;
54
+ const l = parseInt(hslaMatch[3]) / 100;
55
+ const a = hslaMatch[4] ? parseFloat(hslaMatch[4]) : 1;
56
+ // Convert HSL to RGB
57
+ const { r, g, b } = hslToRgb(h, s, l);
58
+ return { r, g, b, a };
59
+ }
60
+ return null;
61
+ }
62
+ /**
63
+ * Convert HSL to RGB
64
+ */
65
+ function hslToRgb(h, s, l) {
66
+ let r, g, b;
67
+ if (s === 0) {
68
+ r = g = b = l;
69
+ }
70
+ else {
71
+ const hue2rgb = (p, q, t) => {
72
+ if (t < 0)
73
+ t += 1;
74
+ if (t > 1)
75
+ t -= 1;
76
+ if (t < 1 / 6)
77
+ return p + (q - p) * 6 * t;
78
+ if (t < 1 / 2)
79
+ return q;
80
+ if (t < 2 / 3)
81
+ return p + (q - p) * (2 / 3 - t) * 6;
82
+ return p;
83
+ };
84
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
85
+ const p = 2 * l - q;
86
+ r = hue2rgb(p, q, h + 1 / 3);
87
+ g = hue2rgb(p, q, h);
88
+ b = hue2rgb(p, q, h - 1 / 3);
89
+ }
90
+ return {
91
+ r: Math.round(r * 255),
92
+ g: Math.round(g * 255),
93
+ b: Math.round(b * 255),
94
+ };
95
+ }
96
+ /**
97
+ * Convert RGB to HSL
98
+ */
99
+ function rgbToHsl(r, g, b) {
100
+ r /= 255;
101
+ g /= 255;
102
+ b /= 255;
103
+ const max = Math.max(r, g, b);
104
+ const min = Math.min(r, g, b);
105
+ let h = 0, s = 0;
106
+ const l = (max + min) / 2;
107
+ if (max !== min) {
108
+ const d = max - min;
109
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
110
+ switch (max) {
111
+ case r:
112
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
113
+ break;
114
+ case g:
115
+ h = ((b - r) / d + 2) / 6;
116
+ break;
117
+ case b:
118
+ h = ((r - g) / d + 4) / 6;
119
+ break;
120
+ }
121
+ }
122
+ return { h, s, l };
123
+ }
124
+ /**
125
+ * Interpolate colors in RGB space
126
+ */
127
+ function lerpColorRGB(from, to, progress) {
128
+ const fromColor = parseColor(from);
129
+ const toColor = parseColor(to);
130
+ if (!fromColor || !toColor) {
131
+ return progress < 0.5 ? from : to;
132
+ }
133
+ const r = Math.round(lerpNumber(fromColor.r, toColor.r, progress));
134
+ const g = Math.round(lerpNumber(fromColor.g, toColor.g, progress));
135
+ const b = Math.round(lerpNumber(fromColor.b, toColor.b, progress));
136
+ const a = lerpNumber(fromColor.a, toColor.a, progress);
137
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
138
+ }
139
+ /**
140
+ * Interpolate colors in HSL space (smoother for hue transitions)
141
+ */
142
+ function lerpColorHSL(from, to, progress) {
143
+ const fromColor = parseColor(from);
144
+ const toColor = parseColor(to);
145
+ if (!fromColor || !toColor) {
146
+ return progress < 0.5 ? from : to;
147
+ }
148
+ const fromHSL = rgbToHsl(fromColor.r, fromColor.g, fromColor.b);
149
+ const toHSL = rgbToHsl(toColor.r, toColor.g, toColor.b);
150
+ // Interpolate hue with shortest path
151
+ let deltaH = toHSL.h - fromHSL.h;
152
+ if (deltaH > 0.5)
153
+ deltaH -= 1;
154
+ if (deltaH < -0.5)
155
+ deltaH += 1;
156
+ const h = fromHSL.h + deltaH * progress;
157
+ const s = lerpNumber(fromHSL.s, toHSL.s, progress);
158
+ const l = lerpNumber(fromHSL.l, toHSL.l, progress);
159
+ const a = lerpNumber(fromColor.a, toColor.a, progress);
160
+ const { r, g, b } = hslToRgb(h, s, l);
161
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
162
+ }
163
+ /**
164
+ * Interpolate 2D vectors/points
165
+ */
166
+ function lerpVector(from, to, progress) {
167
+ return {
168
+ x: lerpNumber(from.x, to.x, progress),
169
+ y: lerpNumber(from.y, to.y, progress),
170
+ };
171
+ }
172
+ /**
173
+ * Auto-detect interpolator based on value type
174
+ */
175
+ function getInterpolator(from, to) {
176
+ // Number
177
+ if (typeof from === "number" && typeof to === "number") {
178
+ return lerpNumber;
179
+ }
180
+ // String (assume color)
181
+ if (typeof from === "string" && typeof to === "string") {
182
+ // Try to detect if it's a color
183
+ if (from.startsWith("#") || from.startsWith("rgb") || from.startsWith("hsl")) {
184
+ return lerpColorRGB;
185
+ }
186
+ }
187
+ // Vector/Point
188
+ if (typeof from === "object" &&
189
+ from !== null &&
190
+ typeof to === "object" &&
191
+ to !== null &&
192
+ "x" in from &&
193
+ "y" in from &&
194
+ "x" in to &&
195
+ "y" in to) {
196
+ return lerpVector;
197
+ }
198
+ // Default: snap to end value
199
+ return ((from, to, progress) => (progress < 1 ? from : to));
200
+ }
@@ -0,0 +1,94 @@
1
+ import { Div } from "../structures/components";
2
+ import { AnyLayer } from "../types";
3
+ import { ThreadGenerator, Signal } from "./Signal";
4
+ import { LazyCanvas } from "../structures/LazyCanvas";
5
+ import { Canvas } from "@napi-rs/canvas";
6
+ /**
7
+ * Scene class - manages canvas, context, layers, and animation timeline
8
+ */
9
+ export declare class Scene {
10
+ readonly lazyCanvas: LazyCanvas;
11
+ private allLayers;
12
+ private scheduler;
13
+ private lastFrameTime;
14
+ /**
15
+ * Create a new Scene
16
+ * @param width - Canvas width in pixels
17
+ * @param height - Canvas height in pixels
18
+ * @param opts
19
+ */
20
+ constructor(width: number, height: number, opts?: {
21
+ debug?: boolean;
22
+ });
23
+ /**
24
+ * Load a layer tree created via JSX
25
+ * Registers all layers with IDs into the manager
26
+ * @param tree - Root layer or group
27
+ */
28
+ load(tree: AnyLayer | Div): void;
29
+ /**
30
+ * Render a single frame at the given time
31
+ * @param time - Time in seconds
32
+ */
33
+ renderFrame(time: number): Promise<void>;
34
+ renderFirstFrame(): Promise<Canvas>;
35
+ /**
36
+ * Get current frame as ImageData (Uint8ClampedArray)
37
+ * Much faster than encoding to PNG
38
+ */
39
+ getImageData(): Uint8ClampedArray;
40
+ /**
41
+ * Get canvas width
42
+ */
43
+ get width(): number;
44
+ /**
45
+ * Get canvas height
46
+ */
47
+ get height(): number;
48
+ /**
49
+ * Update state for all layers that have signals
50
+ * @param time - Current time in seconds
51
+ */
52
+ private updateAllStates;
53
+ /**
54
+ * Render multiple frames and return as animation
55
+ * @param startTime - Start time in seconds
56
+ * @param endTime - End time in seconds
57
+ * @param fps - Frames per second (default: 30)
58
+ * @returns Array of PNG buffers for each frame
59
+ */
60
+ renderAnimation(startTime: number, endTime: number, fps?: number): Promise<Buffer[]>;
61
+ /**
62
+ * Render multiple frames and return as ImageData array (much faster)
63
+ * @param startTime - Start time in seconds
64
+ * @param endTime - End time in seconds
65
+ * @param fps - Frames per second (default: 30)
66
+ * @returns Array of Uint8ClampedArray for each frame
67
+ */
68
+ renderAnimationData(startTime: number, endTime: number, fps?: number): Promise<Uint8ClampedArray[]>;
69
+ /**
70
+ * Get a layer by ID from the manager
71
+ * @param id - Layer ID
72
+ * @returns Layer or undefined
73
+ */
74
+ getLayer(id: string): AnyLayer | Div | undefined;
75
+ /**
76
+ * Add animation generator to scheduler
77
+ * @param generator - Animation generator to run
78
+ */
79
+ addAnimation(generator: ThreadGenerator): void;
80
+ /**
81
+ * Play animation on a signal
82
+ * @param signal - Signal to animate
83
+ * @param generator - Animation generator
84
+ */
85
+ playAnimation<T>(signal: Signal<T>, generator: ThreadGenerator): void;
86
+ /**
87
+ * Clear all animations
88
+ */
89
+ clearAnimations(): void;
90
+ /**
91
+ * Reset scene timeline
92
+ */
93
+ resetTimeline(): void;
94
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Scene = void 0;
4
+ const types_1 = require("../types");
5
+ const ThreadScheduler_1 = require("./ThreadScheduler");
6
+ const LazyCanvas_1 = require("../structures/LazyCanvas");
7
+ const managers_1 = require("../structures/managers");
8
+ /**
9
+ * Scene class - manages canvas, context, layers, and animation timeline
10
+ */
11
+ class Scene {
12
+ /**
13
+ * Create a new Scene
14
+ * @param width - Canvas width in pixels
15
+ * @param height - Canvas height in pixels
16
+ * @param opts
17
+ */
18
+ constructor(width, height, opts = {}) {
19
+ this.allLayers = [];
20
+ this.scheduler = new ThreadScheduler_1.ThreadScheduler();
21
+ this.lastFrameTime = 0;
22
+ this.lazyCanvas = new LazyCanvas_1.LazyCanvas(managers_1.ModernRenderPipeline, opts).create(width, height);
23
+ }
24
+ /**
25
+ * Load a layer tree created via JSX
26
+ * Registers all layers with IDs into the manager
27
+ * @param tree - Root layer or group
28
+ */
29
+ load(tree) {
30
+ this.lazyCanvas.manager.layers.add(tree);
31
+ this.allLayers = this.lazyCanvas.manager.layers.toArray();
32
+ }
33
+ /**
34
+ * Render a single frame at the given time
35
+ * @param time - Time in seconds
36
+ */
37
+ async renderFrame(time) {
38
+ if (this.lazyCanvas.manager.layers.size() === 0) {
39
+ throw new Error("Scene: No root layer loaded. Call scene.load(tree) first.");
40
+ }
41
+ // 1. Update scheduler with current time
42
+ this.scheduler.update(time);
43
+ // 2. Clear canvas
44
+ this.lazyCanvas.ctx.clearRect(0, 0, this.lazyCanvas.canvas.width, this.lazyCanvas.canvas.height);
45
+ // 3. PHASE 1: Update all layer states from signals
46
+ this.updateAllStates(time);
47
+ // 4. PHASE 2: Draw the layer tree using RenderManager
48
+ await this.lazyCanvas.manager.render.render(types_1.Export.CTX);
49
+ this.lastFrameTime = time;
50
+ }
51
+ async renderFirstFrame() {
52
+ await this.renderFrame(0);
53
+ return this.lazyCanvas.canvas;
54
+ }
55
+ /**
56
+ * Get current frame as ImageData (Uint8ClampedArray)
57
+ * Much faster than encoding to PNG
58
+ */
59
+ getImageData() {
60
+ const imageData = this.lazyCanvas.ctx.getImageData(0, 0, this.width, this.height);
61
+ return imageData.data;
62
+ }
63
+ /**
64
+ * Get canvas width
65
+ */
66
+ get width() {
67
+ return this.lazyCanvas.canvas.width;
68
+ }
69
+ /**
70
+ * Get canvas height
71
+ */
72
+ get height() {
73
+ return this.lazyCanvas.canvas.height;
74
+ }
75
+ /**
76
+ * Update state for all layers that have signals
77
+ * @param time - Current time in seconds
78
+ */
79
+ updateAllStates(time) {
80
+ for (const layer of this.allLayers) {
81
+ // Check if layer has updateState method (added by BaseLayer)
82
+ if ("updateState" in layer && typeof layer.updateState === "function") {
83
+ layer.updateState(time);
84
+ }
85
+ }
86
+ }
87
+ /**
88
+ * Render multiple frames and return as animation
89
+ * @param startTime - Start time in seconds
90
+ * @param endTime - End time in seconds
91
+ * @param fps - Frames per second (default: 30)
92
+ * @returns Array of PNG buffers for each frame
93
+ */
94
+ async renderAnimation(startTime, endTime, fps = 30) {
95
+ const frames = [];
96
+ const frameDuration = 1 / fps;
97
+ for (let time = startTime; time <= endTime; time += frameDuration) {
98
+ await this.renderFrame(time);
99
+ frames.push(await this.lazyCanvas.canvas.encode("png"));
100
+ }
101
+ return frames;
102
+ }
103
+ /**
104
+ * Render multiple frames and return as ImageData array (much faster)
105
+ * @param startTime - Start time in seconds
106
+ * @param endTime - End time in seconds
107
+ * @param fps - Frames per second (default: 30)
108
+ * @returns Array of Uint8ClampedArray for each frame
109
+ */
110
+ async renderAnimationData(startTime, endTime, fps = 30) {
111
+ const frames = [];
112
+ const frameDuration = 1 / fps;
113
+ for (let time = startTime; time <= endTime; time += frameDuration) {
114
+ await this.renderFrame(time);
115
+ frames.push(this.getImageData());
116
+ }
117
+ return frames;
118
+ }
119
+ /**
120
+ * Get a layer by ID from the manager
121
+ * @param id - Layer ID
122
+ * @returns Layer or undefined
123
+ */
124
+ getLayer(id) {
125
+ return this.lazyCanvas.manager.layers.get(id, true);
126
+ }
127
+ /**
128
+ * Add animation generator to scheduler
129
+ * @param generator - Animation generator to run
130
+ */
131
+ addAnimation(generator) {
132
+ this.scheduler.add(generator);
133
+ }
134
+ /**
135
+ * Play animation on a signal
136
+ * @param signal - Signal to animate
137
+ * @param generator - Animation generator
138
+ */
139
+ playAnimation(signal, generator) {
140
+ signal.run(generator);
141
+ this.scheduler.add(generator);
142
+ }
143
+ /**
144
+ * Clear all animations
145
+ */
146
+ clearAnimations() {
147
+ this.scheduler.clear();
148
+ }
149
+ /**
150
+ * Reset scene timeline
151
+ */
152
+ resetTimeline() {
153
+ this.scheduler.reset();
154
+ this.lastFrameTime = 0;
155
+ }
156
+ }
157
+ exports.Scene = Scene;
@@ -0,0 +1,133 @@
1
+ import { Interpolator } from "./Interpolation";
2
+ /**
3
+ * Easing function type
4
+ */
5
+ export type EasingFunction = (t: number) => number;
6
+ /**
7
+ * Standard easing functions
8
+ */
9
+ export declare const Easing: {
10
+ linear: (t: number) => number;
11
+ easeIn: (t: number) => number;
12
+ easeOut: (t: number) => number;
13
+ easeInOut: (t: number) => number;
14
+ easeInCubic: (t: number) => number;
15
+ easeOutCubic: (t: number) => number;
16
+ easeInOutCubic: (t: number) => number;
17
+ easeInQuart: (t: number) => number;
18
+ easeOutQuart: (t: number) => number;
19
+ easeInOutQuart: (t: number) => number;
20
+ easeInQuint: (t: number) => number;
21
+ easeOutQuint: (t: number) => number;
22
+ easeInOutQuint: (t: number) => number;
23
+ easeInSine: (t: number) => number;
24
+ easeOutSine: (t: number) => number;
25
+ easeInOutSine: (t: number) => number;
26
+ easeInExpo: (t: number) => number;
27
+ easeOutExpo: (t: number) => number;
28
+ easeInOutExpo: (t: number) => number;
29
+ easeInCirc: (t: number) => number;
30
+ easeOutCirc: (t: number) => number;
31
+ easeInOutCirc: (t: number) => number;
32
+ easeInBack: (t: number) => number;
33
+ easeOutBack: (t: number) => number;
34
+ easeInOutBack: (t: number) => number;
35
+ easeInElastic: (t: number) => number;
36
+ easeOutElastic: (t: number) => number;
37
+ easeInOutElastic: (t: number) => number;
38
+ easeInBounce: (t: number) => number;
39
+ easeOutBounce: (t: number) => number;
40
+ easeInOutBounce: (t: number) => number;
41
+ };
42
+ /**
43
+ * Thread generator type - the core of animation system
44
+ */
45
+ export type ThreadGenerator = Generator<void | number, void, number | void>;
46
+ /**
47
+ * Tween configuration
48
+ */
49
+ export interface TweenConfig<T> {
50
+ to: T;
51
+ duration: number;
52
+ easing?: EasingFunction;
53
+ interpolator?: Interpolator<T>;
54
+ colorSpace?: "rgb" | "hsl";
55
+ }
56
+ /**
57
+ * Signal options
58
+ */
59
+ export interface SignalOptions<T> {
60
+ interpolator?: Interpolator<T>;
61
+ colorSpace?: "rgb" | "hsl";
62
+ }
63
+ /**
64
+ * Signal class - reactive value that can be animated
65
+ */
66
+ export declare class Signal<T = number> {
67
+ private _value;
68
+ private _initialValue;
69
+ private _currentThread;
70
+ private _interpolator;
71
+ private _colorSpace;
72
+ constructor(initial: T, options?: SignalOptions<T>);
73
+ /**
74
+ * Get current value at specific time (backward compatibility)
75
+ */
76
+ get(time: number): T;
77
+ /**
78
+ * Get current value (sync)
79
+ */
80
+ value(): T;
81
+ /**
82
+ * Set value directly
83
+ */
84
+ set(value: T): void;
85
+ /**
86
+ * Reset to initial value
87
+ */
88
+ reset(): void;
89
+ /**
90
+ * Animate to a new value - returns a generator
91
+ */
92
+ to(value: T, duration: number, config?: Partial<TweenConfig<T>> & {
93
+ easing?: EasingFunction;
94
+ }): ThreadGenerator;
95
+ /**
96
+ * Wait for a duration without changing value
97
+ */
98
+ wait(duration: number): ThreadGenerator;
99
+ /**
100
+ * Run animation from generator
101
+ */
102
+ run(generator: ThreadGenerator): this;
103
+ /**
104
+ * Update signal (called by scheduler)
105
+ */
106
+ update(delta: number): boolean;
107
+ /**
108
+ * Check if signal has active animation
109
+ */
110
+ isAnimating(): boolean;
111
+ /**
112
+ * Internal: get interpolator for values
113
+ */
114
+ private _getInterpolator;
115
+ }
116
+ /**
117
+ * Create a new signal
118
+ */
119
+ export declare function createSignal<T = number>(initial: T, options?: SignalOptions<T>): Signal<T>;
120
+ /**
121
+ * Type guard for signals
122
+ */
123
+ export declare function isSignal<T>(value: any): value is Signal<T>;
124
+ /**
125
+ * Unwrap signal or return value
126
+ */
127
+ export declare function unwrap<T>(value: T | Signal<T>): T extends Signal<infer U> ? U : T;
128
+ /**
129
+ * Reset multiple signals to their initial values
130
+ */
131
+ export declare function resetSignals(...signals: Signal<any>[]): void;
132
+ export type SignalValue<T> = T | Signal<T>;
133
+ export default Signal;