laymur-animations 0.25.0 → 0.26.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.
@@ -0,0 +1,64 @@
1
+ import gsap from "gsap";
2
+ import { iterationsToRepeat, resolveTargets, UICallTracker } from "./miscellaneous.js";
3
+ const swipeCalls = new UICallTracker(["x", "y"]);
4
+ const DEFAULT_DX = 25;
5
+ const DEFAULT_DY = 0;
6
+ const DEFAULT_ITERATIONS = -1;
7
+ const DEFAULT_COOLDOWN = 0;
8
+ const DEFAULT_START_WITH_COOLDOWN = false;
9
+ const DEFAULT_DURATION = 0.4;
10
+ const DEFAULT_EASE_IN = "power1.inOut";
11
+ const DEFAULT_EASE_OUT = "power1.inOut";
12
+ const DEFAULT_STOP_DURATION = 0.25;
13
+ const DEFAULT_STOP_EASE = "power1.inOut";
14
+ /**
15
+ * Animator for swipe call attention effects with pingpong movement along an arbitrary vector.
16
+ */
17
+ export class UISwipeCallAnimator {
18
+ /**
19
+ * Starts a pingpong swipe animation along the vector (dx, dy) from the rest position.
20
+ * Replaces a swipe running on the same element.
21
+ * @param target - Single element or array of elements to animate
22
+ * @param options - Animation configuration options
23
+ */
24
+ static swipe(target, options = {}) {
25
+ const { dx = DEFAULT_DX, dy = DEFAULT_DY, iterations = DEFAULT_ITERATIONS, cooldown = DEFAULT_COOLDOWN, startWithCooldown = DEFAULT_START_WITH_COOLDOWN, duration = DEFAULT_DURATION, easeIn = DEFAULT_EASE_IN, easeOut = DEFAULT_EASE_OUT, onComplete, } = options;
26
+ for (const element of resolveTargets(target)) {
27
+ const micro = element.micro;
28
+ swipeCalls.start(micro, (rest) => {
29
+ const timeline = gsap.timeline({ repeat: iterationsToRepeat(iterations) });
30
+ if (startWithCooldown && cooldown > 0) {
31
+ timeline.to({}, { duration: cooldown });
32
+ }
33
+ timeline
34
+ .to(micro, {
35
+ x: rest.x + dx,
36
+ y: rest.y + dy,
37
+ duration,
38
+ ease: easeIn,
39
+ })
40
+ .to(micro, {
41
+ x: rest.x,
42
+ y: rest.y,
43
+ duration,
44
+ ease: easeOut,
45
+ });
46
+ if (!startWithCooldown && cooldown > 0) {
47
+ timeline.to({}, { duration: cooldown });
48
+ }
49
+ return timeline;
50
+ }, onComplete);
51
+ }
52
+ }
53
+ /**
54
+ * Stops the swipe animation and returns elements to rest position.
55
+ * @param target - Single element or array of elements to stop animating
56
+ * @param options - Stop animation configuration options
57
+ */
58
+ static stopSwipe(target, options = {}) {
59
+ const { duration = DEFAULT_STOP_DURATION, ease = DEFAULT_STOP_EASE } = options;
60
+ for (const element of resolveTargets(target)) {
61
+ swipeCalls.stop(element.micro, duration, ease);
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,64 @@
1
+ import type { UIMicroAnimatedElement } from "./UIAnimatedElement.js";
2
+ /**
3
+ * Configuration options for tap call animations.
4
+ */
5
+ export interface UITapCallAnimatorCallOptions {
6
+ /** Scale factor while pressed, relative to the rest scale */
7
+ pressScale: number;
8
+ /** Horizontal shift while pressed in world units */
9
+ pressX: number;
10
+ /** Vertical shift while pressed in world units */
11
+ pressY: number;
12
+ /** Anchor point X coordinate (0-1) the press scales around, such as the fingertip */
13
+ anchorX: number;
14
+ /** Anchor point Y coordinate (0-1) the press scales around */
15
+ anchorY: number;
16
+ /** Number of taps in a row per iteration; 2 for a double tap */
17
+ taps: number;
18
+ /** Pause between taps in a row in seconds */
19
+ tapInterval: number;
20
+ /** Number of animation iterations (-1 for infinite) */
21
+ iterations: number;
22
+ /** Cooldown time between iterations in seconds */
23
+ cooldown: number;
24
+ /** Whether to start with cooldown delay */
25
+ startWithCooldown: boolean;
26
+ /** Duration of the press in seconds */
27
+ durationIn: number;
28
+ /** Duration of the release in seconds */
29
+ durationOut: number;
30
+ /** GSAP easing function for the press */
31
+ easeIn: gsap.EaseString;
32
+ /** GSAP easing function for the release */
33
+ easeOut: gsap.EaseString;
34
+ /** Called once the call ends: completed, stopped or replaced by another tap */
35
+ onComplete: () => void;
36
+ }
37
+ /**
38
+ * Configuration options for stopping tap animations.
39
+ */
40
+ export interface UITapCallAnimatorStopOptions {
41
+ /** Duration to return to rest in seconds */
42
+ duration: number;
43
+ /** GSAP easing function for stop transition */
44
+ ease: gsap.EaseString;
45
+ }
46
+ /**
47
+ * Animator for tap hints, such as a tutorial hand tapping a button.
48
+ */
49
+ export declare class UITapCallAnimator {
50
+ /**
51
+ * Starts a tapping animation: the element presses in, shrinking and shifting, and releases.
52
+ * Replaces a tap running on the same element; the anchor is restored once the element is
53
+ * back at rest.
54
+ * @param target - Single element or array of elements to animate
55
+ * @param options - Animation configuration options
56
+ */
57
+ static tap(target: UIMicroAnimatedElement | UIMicroAnimatedElement[], options?: Partial<UITapCallAnimatorCallOptions>): void;
58
+ /**
59
+ * Stops the tapping animation and returns elements to rest.
60
+ * @param target - Single element or array of elements to stop animating
61
+ * @param options - Stop animation configuration options
62
+ */
63
+ static stopTap(target: UIMicroAnimatedElement | UIMicroAnimatedElement[], options?: Partial<UITapCallAnimatorStopOptions>): void;
64
+ }
@@ -0,0 +1,83 @@
1
+ import gsap from "gsap";
2
+ import { iterationsToRepeat, resolveTargets, UICallTracker } from "./miscellaneous.js";
3
+ const tapCalls = new UICallTracker(["x", "y", "scaleX", "scaleY", "anchorX", "anchorY"]);
4
+ const DEFAULT_PRESS_SCALE = 0.85;
5
+ const DEFAULT_PRESS_X = 0;
6
+ const DEFAULT_PRESS_Y = -10;
7
+ const DEFAULT_ANCHOR_X = 0.5;
8
+ const DEFAULT_ANCHOR_Y = 0.5;
9
+ const DEFAULT_TAPS = 1;
10
+ const DEFAULT_TAP_INTERVAL = 0.15;
11
+ const DEFAULT_ITERATIONS = -1;
12
+ const DEFAULT_COOLDOWN = 1;
13
+ const DEFAULT_START_WITH_COOLDOWN = false;
14
+ const DEFAULT_DURATION_IN = 0.15;
15
+ const DEFAULT_DURATION_OUT = 0.25;
16
+ const DEFAULT_EASE_IN = "power1.out";
17
+ const DEFAULT_EASE_OUT = "power1.inOut";
18
+ const DEFAULT_STOP_DURATION = 0.25;
19
+ const DEFAULT_STOP_EASE = "power1.inOut";
20
+ /**
21
+ * Animator for tap hints, such as a tutorial hand tapping a button.
22
+ */
23
+ export class UITapCallAnimator {
24
+ /**
25
+ * Starts a tapping animation: the element presses in, shrinking and shifting, and releases.
26
+ * Replaces a tap running on the same element; the anchor is restored once the element is
27
+ * back at rest.
28
+ * @param target - Single element or array of elements to animate
29
+ * @param options - Animation configuration options
30
+ */
31
+ static tap(target, options = {}) {
32
+ const { pressScale = DEFAULT_PRESS_SCALE, pressX = DEFAULT_PRESS_X, pressY = DEFAULT_PRESS_Y, anchorX = DEFAULT_ANCHOR_X, anchorY = DEFAULT_ANCHOR_Y, taps = DEFAULT_TAPS, tapInterval = DEFAULT_TAP_INTERVAL, iterations = DEFAULT_ITERATIONS, cooldown = DEFAULT_COOLDOWN, startWithCooldown = DEFAULT_START_WITH_COOLDOWN, durationIn = DEFAULT_DURATION_IN, durationOut = DEFAULT_DURATION_OUT, easeIn = DEFAULT_EASE_IN, easeOut = DEFAULT_EASE_OUT, onComplete, } = options;
33
+ for (const element of resolveTargets(target)) {
34
+ const micro = element.micro;
35
+ tapCalls.start(micro, (rest) => {
36
+ micro.anchorX = anchorX;
37
+ micro.anchorY = anchorY;
38
+ const timeline = gsap.timeline({ repeat: iterationsToRepeat(iterations) });
39
+ if (startWithCooldown && cooldown > 0) {
40
+ timeline.to({}, { duration: cooldown });
41
+ }
42
+ const count = Math.max(Math.round(taps), 1);
43
+ for (let tap = 0; tap < count; tap++) {
44
+ if (tap > 0 && tapInterval > 0) {
45
+ timeline.to({}, { duration: tapInterval });
46
+ }
47
+ timeline
48
+ .to(micro, {
49
+ x: rest.x + pressX,
50
+ y: rest.y + pressY,
51
+ scaleX: rest.scaleX * pressScale,
52
+ scaleY: rest.scaleY * pressScale,
53
+ duration: durationIn,
54
+ ease: easeIn,
55
+ })
56
+ .to(micro, {
57
+ x: rest.x,
58
+ y: rest.y,
59
+ scaleX: rest.scaleX,
60
+ scaleY: rest.scaleY,
61
+ duration: durationOut,
62
+ ease: easeOut,
63
+ });
64
+ }
65
+ if (!startWithCooldown && cooldown > 0) {
66
+ timeline.to({}, { duration: cooldown });
67
+ }
68
+ return timeline;
69
+ }, onComplete);
70
+ }
71
+ }
72
+ /**
73
+ * Stops the tapping animation and returns elements to rest.
74
+ * @param target - Single element or array of elements to stop animating
75
+ * @param options - Stop animation configuration options
76
+ */
77
+ static stopTap(target, options = {}) {
78
+ const { duration = DEFAULT_STOP_DURATION, ease = DEFAULT_STOP_EASE } = options;
79
+ for (const element of resolveTargets(target)) {
80
+ tapCalls.stop(element.micro, duration, ease);
81
+ }
82
+ }
83
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,27 @@
1
- export { UIAppearAnimator } from "./UIAppearAnimator";
2
- export { UIClickAnimator } from "./UIClickAnimator";
3
- export { UIDisappearAnimator } from "./UIDisappearAnimator";
4
- export { UIJumpCallAnimator } from "./UIJumpCallAnimator";
5
- export { UIPulseCallAnimator } from "./UIPulseCallAnimator";
6
- export { UISpinCallAnimator } from "./UISpinCallAnimator";
7
- export { UISwipeCallAnimator } from "./UISwipeCallAnimator";
1
+ export type { UIAnimatedElement, UIMicroAnimatedElement } from "./UIAnimatedElement.js";
2
+ export { UIAppearAnimator } from "./UIAppearAnimator.js";
3
+ export type { UIAppearAnimatorOptions } from "./UIAppearAnimator.js";
4
+ export { UIClickAnimator } from "./UIClickAnimator.js";
5
+ export type { UIClickAnimatorOptions } from "./UIClickAnimator.js";
6
+ export { UIDisappearAnimator } from "./UIDisappearAnimator.js";
7
+ export type { UIDisappearAnimatorOptions } from "./UIDisappearAnimator.js";
8
+ export { UIFlashAnimator } from "./UIFlashAnimator.js";
9
+ export type { UIFlashAnimatorOptions, UIFlashElement } from "./UIFlashAnimator.js";
10
+ export { UIFloatCallAnimator } from "./UIFloatCallAnimator.js";
11
+ export type { UIFloatCallAnimatorCallOptions, UIFloatCallAnimatorStopOptions, } from "./UIFloatCallAnimator.js";
12
+ export { UIFlyToAnimator } from "./UIFlyToAnimator.js";
13
+ export type { UIFlyToAnimatorOptions, UIFlyToElement, UIFlyToTarget } from "./UIFlyToAnimator.js";
14
+ export { UIJumpCallAnimator } from "./UIJumpCallAnimator.js";
15
+ export type { UIJumpCallAnimatorCallOptions, UIJumpCallAnimatorStopOptions, } from "./UIJumpCallAnimator.js";
16
+ export { UIPulseCallAnimator } from "./UIPulseCallAnimator.js";
17
+ export type { UIPulseCallAnimatorOptions, UIPulseCallAnimatorStopOptions, } from "./UIPulseCallAnimator.js";
18
+ export { UIShakeAnimator } from "./UIShakeAnimator.js";
19
+ export type { UIShakeAnimatorOptions } from "./UIShakeAnimator.js";
20
+ export { UIShineCallAnimator } from "./UIShineCallAnimator.js";
21
+ export type { UIShineCallAnimatorCallOptions } from "./UIShineCallAnimator.js";
22
+ export { UISpinCallAnimator } from "./UISpinCallAnimator.js";
23
+ export type { UISpinCallAnimatorCallOptions, UISpinCallAnimatorStopOptions, } from "./UISpinCallAnimator.js";
24
+ export { UISwipeCallAnimator } from "./UISwipeCallAnimator.js";
25
+ export type { UISwipeCallAnimatorCallOptions, UISwipeCallAnimatorStopOptions, } from "./UISwipeCallAnimator.js";
26
+ export { UITapCallAnimator } from "./UITapCallAnimator.js";
27
+ export type { UITapCallAnimatorCallOptions, UITapCallAnimatorStopOptions, } from "./UITapCallAnimator.js";