@cioky/ripple-transitions 0.1.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.
package/src/stagger.ts ADDED
@@ -0,0 +1,64 @@
1
+ export function stagger(
2
+ ref: (el: HTMLElement) => void | (() => void),
3
+ options: { amount?: number; index?: number } = {}
4
+ ) {
5
+ const { amount = 50, index = 0 } = options;
6
+ const delay = index * amount;
7
+
8
+ return (el: HTMLElement) => {
9
+ if (!el) return;
10
+
11
+ // Override el.animate temporarily to inject delay during initial mount animation
12
+ const origAnimate = el.animate.bind(el);
13
+ el.animate = ((...args: any[]) => {
14
+ const opts: KeyframeAnimationOptions = (args[1] || {}) as KeyframeAnimationOptions;
15
+ opts.delay = (opts.delay || 0) + delay;
16
+ return origAnimate(args[0], opts);
17
+ }) as typeof el.animate;
18
+
19
+ const cleanup = ref(el);
20
+
21
+ // Restore original animate
22
+ el.animate = origAnimate;
23
+
24
+ // Wrap exit handler to inject delay during exit phase
25
+ const origExit = (el as any).__ripple_exit;
26
+ if (origExit) {
27
+ (el as any).__ripple_exit = (target: HTMLElement) => {
28
+ const tOrigAnimate = target.animate.bind(target);
29
+ target.animate = ((...args: any[]) => {
30
+ const opts: KeyframeAnimationOptions = (args[1] || {}) as KeyframeAnimationOptions;
31
+ opts.delay = (opts.delay || 0) + delay;
32
+ return tOrigAnimate(args[0], opts);
33
+ }) as typeof target.animate;
34
+
35
+ const exitPromise = origExit(target);
36
+ target.animate = tOrigAnimate;
37
+ return exitPromise;
38
+ };
39
+ }
40
+
41
+ // Wrap enter handler to inject delay during enter phase (interruption case)
42
+ const origEnter = (el as any).__ripple_enter;
43
+ if (origEnter) {
44
+ (el as any).__ripple_enter = (target: HTMLElement) => {
45
+ const tOrigAnimate = target.animate.bind(target);
46
+ target.animate = ((...args: any[]) => {
47
+ const opts: KeyframeAnimationOptions = (args[1] || {}) as KeyframeAnimationOptions;
48
+ opts.delay = (opts.delay || 0) + delay;
49
+ return tOrigAnimate(args[0], opts);
50
+ }) as typeof target.animate;
51
+
52
+ const enterPromise = origEnter(target);
53
+ target.animate = tOrigAnimate;
54
+ return enterPromise;
55
+ };
56
+ }
57
+
58
+ return () => {
59
+ if (typeof cleanup === 'function') {
60
+ cleanup();
61
+ }
62
+ };
63
+ };
64
+ }
package/src/types.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { type Children } from 'ripple';
2
+
3
+ export interface TransitionOptions {
4
+ delay?: number;
5
+ duration?: number;
6
+ easing?: string;
7
+ type?: 'tween' | 'spring';
8
+ /** Spring physics (only when type='spring') */
9
+ stiffness?: number;
10
+ damping?: number;
11
+ mass?: number;
12
+ }
13
+
14
+ export interface MotionTiming {
15
+ delay: number;
16
+ duration: number;
17
+ type: 'tween' | 'spring';
18
+ stiffness: number;
19
+ damping: number;
20
+ mass: number;
21
+ easing?: string;
22
+ }
23
+
24
+ export interface MotionConfig {
25
+ initial?: Keyframe | Record<string, any>;
26
+ animate?: Keyframe | Record<string, any>;
27
+ exit?: Keyframe | Record<string, any>;
28
+ transition?: TransitionOptions;
29
+ }
30
+
31
+ export interface LayoutOptions extends TransitionOptions {}
32
+
33
+ export interface GestureConfig {
34
+ hover?: Record<string, any>;
35
+ tap?: Record<string, any>;
36
+ focus?: Record<string, any>;
37
+ transition?: TransitionOptions;
38
+ }
39
+
40
+ export interface SvelteTransitionConfig {
41
+ delay?: number;
42
+ duration?: number;
43
+ easing?: (t: number) => number;
44
+ css?: (t: number, u: number) => string;
45
+ tick?: (t: number, u: number) => void;
46
+ }
47
+
48
+ export type SvelteTransitionFn = (node: HTMLElement, params?: any) => SvelteTransitionConfig;