Comparing version 1.2.1 to 1.3.0
@@ -15,2 +15,11 @@ import EventEmitter from 'eventemitter3'; | ||
} | ||
interface SetOptions { | ||
from?: AnimatableValue; | ||
to?: AnimatableValue; | ||
duration?: number; | ||
easing?: TEasing; | ||
delay?: number; | ||
direction?: 'normal' | 'reverse' | 'alternate'; | ||
loop?: number; | ||
} | ||
export declare class Animate extends EventEmitter { | ||
@@ -37,3 +46,4 @@ private from; | ||
stop(): this; | ||
set(options: SetOptions): void; | ||
} | ||
export {}; |
@@ -157,3 +157,52 @@ "use strict"; | ||
} | ||
set(options) { | ||
if (options.from !== undefined) { | ||
if (!this.isValidAnimatableValue(options.from)) { | ||
throw new Error('Invalid animatable value'); | ||
} | ||
this.from = options.from; | ||
} | ||
if (options.to !== undefined) { | ||
if (!this.isValidAnimatableValue(options.to)) { | ||
throw new Error('Invalid animatable value'); | ||
} | ||
this.to = options.to; | ||
} | ||
if (options.duration !== undefined) { | ||
if (typeof options.duration !== 'number' || options.duration <= 0) { | ||
throw new Error('Duration must be a positive number'); | ||
} | ||
this.duration = options.duration; | ||
} | ||
if (options.easing !== undefined) { | ||
this.easing = options.easing; | ||
} | ||
if (options.delay !== undefined) { | ||
if (typeof options.delay !== 'number' || options.delay < 0) { | ||
throw new Error('Delay must be a non-negative number'); | ||
} | ||
this.delay = options.delay; | ||
} | ||
if (options.direction !== undefined) { | ||
if (!['normal', 'reverse', 'alternate'].includes(options.direction)) { | ||
throw new Error('Invalid direction'); | ||
} | ||
this.direction = options.direction; | ||
this.isReversed = options.direction === 'reverse'; | ||
} | ||
if (options.loop !== undefined) { | ||
if (typeof options.loop !== 'number' || options.loop < 0) { | ||
throw new Error('Loop must be a non-negative number'); | ||
} | ||
this.loop = options.loop; | ||
this.loopsCompleted = 0; | ||
} | ||
// Restart the animation with updated properties | ||
this.startTime = performance.now(); | ||
if (this.process !== undefined) { | ||
framesync_1.cancelSync.update(this.process); | ||
} | ||
this.process = framesync_1.default.update(this.tick, true); | ||
} | ||
} | ||
exports.Animate = Animate; |
{ | ||
"name": "nimate", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "A simple, flexible animation library.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
24790
429