@stellix-agency/motion 1.0.0 → 1.0.2
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/README.md +357 -0
- package/dist/chunk-YEOCNWCQ.js +0 -0
- package/dist/index.d.ts +123 -21
- package/dist/index.js +1 -1
- package/dist/jsx.d.ts +221 -0
- package/dist/jsx.js +1 -0
- package/package.json +30 -6
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# Magic Motion 🎬
|
|
2
|
+
|
|
3
|
+
An intuitive and powerful GSAP wrapper for creating stunning animations with ease. Built for Solid.js and Astro projects.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
✨ **Fluent API** - Chain animations naturally with an intuitive syntax
|
|
8
|
+
🎯 **TypeScript First** - Full type safety with comprehensive JSDoc
|
|
9
|
+
📜 **Scroll Animations** - Easy ScrollTrigger integration
|
|
10
|
+
🎨 **Rich Presets** - Common animation patterns out of the box
|
|
11
|
+
🔧 **Utility Functions** - Stagger, batch, parallax, and more
|
|
12
|
+
⚡ **Lightweight** - Minimal wrapper over GSAP's powerful engine
|
|
13
|
+
🔥 **Auto Types** - No manual type declarations needed (v1.0.1+)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @stellix-agency/motion gsap
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> **Note**: As of v1.0.1, you no longer need to create a manual `directives.d.ts` file! Types are now automatically included.
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### Basic Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Motion } from '@stellix-agency/motion';
|
|
29
|
+
|
|
30
|
+
const element = document.querySelector('.box');
|
|
31
|
+
const motion = new Motion(element);
|
|
32
|
+
|
|
33
|
+
motion
|
|
34
|
+
.fadeIn()
|
|
35
|
+
.slideUp(50)
|
|
36
|
+
.scale(1.2)
|
|
37
|
+
.rotate(360);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Solid.js Directive
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { animate, easings } from '@stellix-agency/motion';
|
|
44
|
+
|
|
45
|
+
function MyComponent() {
|
|
46
|
+
return (
|
|
47
|
+
<h1
|
|
48
|
+
use:animate={(m) =>
|
|
49
|
+
m.fadeIn({ ease: easings.smoothOut })
|
|
50
|
+
.wait(0.5)
|
|
51
|
+
.rotate(360, { ease: easings.elasticOut })
|
|
52
|
+
}
|
|
53
|
+
class="opacity-0 font-bold text-2xl mt-20 text-center"
|
|
54
|
+
>
|
|
55
|
+
Hello World
|
|
56
|
+
</h1>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> **Note**: You may see a "'animate' is declared but its value is never read" warning. This is expected and can be ignored - the import is required for the directive to work. See [USAGE.md](./USAGE.md) for details.
|
|
62
|
+
|
|
63
|
+
## Core API
|
|
64
|
+
|
|
65
|
+
### Motion Class
|
|
66
|
+
|
|
67
|
+
The `Motion` class provides a fluent API for chaining animations:
|
|
68
|
+
|
|
69
|
+
#### Fade Animations
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
motion.fadeIn(options?) // Fade in
|
|
73
|
+
motion.fadeOut(options?) // Fade out
|
|
74
|
+
motion.fade('in' | 'out' | 'inOut', options?) // Fade variant
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Slide Animations
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
motion.slideUp(distance?, options?) // Slide up
|
|
81
|
+
motion.slideDown(distance?, options?) // Slide down
|
|
82
|
+
motion.slideLeft(distance?, options?) // Slide left
|
|
83
|
+
motion.slideRight(distance?, options?) // Slide right
|
|
84
|
+
motion.slide(direction, distance?, options?) // Slide in any direction
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Transform Animations
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
motion.scale(scale, options?) // Scale element
|
|
91
|
+
motion.rotate(degrees, options?) // Rotate element
|
|
92
|
+
motion.skew(x, y, options?) // Skew element
|
|
93
|
+
motion.moveTo(x, y, options?) // Move to coordinates
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Effects
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
motion.blur(amount, options?) // Blur effect
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Custom Animations
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
motion.animate(vars, options?) // Custom GSAP properties
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Timeline Control
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
motion.wait(duration) // Add delay
|
|
112
|
+
motion.setDuration(duration) // Set default duration
|
|
113
|
+
motion.setEase(ease) // Set default easing
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Playback Control
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
motion.play() // Play animation
|
|
120
|
+
motion.pause() // Pause animation
|
|
121
|
+
motion.restart() // Restart animation
|
|
122
|
+
motion.reverse() // Reverse animation
|
|
123
|
+
motion.kill() // Kill and cleanup
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Scroll Trigger
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
motion.onScroll(options?) // Add ScrollTrigger
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Animation Options
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
interface AnimationOptions {
|
|
136
|
+
duration?: number; // Animation duration (default: 0.8s)
|
|
137
|
+
ease?: string; // Easing function (default: "power4.out")
|
|
138
|
+
delay?: number; // Delay before start
|
|
139
|
+
// ...all GSAP TweenVars
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Scroll Options
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
interface ScrollAnimationOptions {
|
|
147
|
+
start?: string; // Start position (default: "top 85%")
|
|
148
|
+
end?: string; // End position
|
|
149
|
+
toggleActions?: string; // Actions (default: "play none none reverse")
|
|
150
|
+
// ...all ScrollTrigger.Vars
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Presets
|
|
155
|
+
|
|
156
|
+
Pre-configured animation settings for common use cases:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { presets } from '@stellix-agency/motion';
|
|
160
|
+
|
|
161
|
+
motion.fadeIn(presets.fast) // Quick animation (0.3s)
|
|
162
|
+
motion.fadeIn(presets.normal) // Standard animation (0.8s)
|
|
163
|
+
motion.fadeIn(presets.slow) // Slow animation (1.5s)
|
|
164
|
+
motion.scale(1.2, presets.bounce) // Bouncy animation
|
|
165
|
+
motion.fadeIn(presets.spring) // Spring-like animation
|
|
166
|
+
motion.fadeIn(presets.smooth) // Smooth ease in/out
|
|
167
|
+
motion.fadeIn(presets.elastic) // Elastic bounce
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Easings
|
|
171
|
+
|
|
172
|
+
Common easing functions:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { easings } from '@stellix-agency/motion';
|
|
176
|
+
|
|
177
|
+
motion.fadeIn({ ease: easings.smoothOut })
|
|
178
|
+
motion.scale(1.2, { ease: easings.backOut })
|
|
179
|
+
motion.rotate(360, { ease: easings.elasticOut })
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Available easings: `linear`, `easeIn`, `easeOut`, `easeInOut`, `smoothIn`, `smoothOut`, `smoothInOut`, `bounceOut`, `bounceIn`, `bounceInOut`, `elasticOut`, `elasticIn`, `backOut`, `backIn`, `circOut`, `circIn`, `expoOut`, `expoIn`
|
|
183
|
+
|
|
184
|
+
## Utility Functions
|
|
185
|
+
|
|
186
|
+
### Stagger
|
|
187
|
+
|
|
188
|
+
Animate multiple elements with a stagger delay:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { stagger } from '@stellix-agency/motion';
|
|
192
|
+
|
|
193
|
+
stagger('.card', (motion, index) => {
|
|
194
|
+
motion.fadeIn().slideUp().onScroll();
|
|
195
|
+
}, 0.1); // 0.1s delay between each
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Batch
|
|
199
|
+
|
|
200
|
+
Apply the same animation to multiple elements:
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { batch } from '@stellix-agency/motion';
|
|
204
|
+
|
|
205
|
+
batch('.item', (motion) => {
|
|
206
|
+
motion.fadeIn({ duration: 0.5 });
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Scroll Entrance
|
|
211
|
+
|
|
212
|
+
Quick scroll-triggered entrance animation:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { scrollEntrance } from '@stellix-agency/motion';
|
|
216
|
+
|
|
217
|
+
const element = document.querySelector('.hero');
|
|
218
|
+
scrollEntrance(element, { duration: 1 });
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Hover
|
|
222
|
+
|
|
223
|
+
Create hover animations:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { hover } from '@stellix-agency/motion';
|
|
227
|
+
|
|
228
|
+
const cleanup = hover(
|
|
229
|
+
element,
|
|
230
|
+
{ scale: 1.1, y: -10 },
|
|
231
|
+
{ duration: 0.3 }
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// Call cleanup() when done
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Parallax
|
|
238
|
+
|
|
239
|
+
Create parallax scroll effects:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { parallax } from '@stellix-agency/motion';
|
|
243
|
+
|
|
244
|
+
parallax(element, 0.5); // 0.5 = speed multiplier
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Reveal
|
|
248
|
+
|
|
249
|
+
Reveal animation from a direction:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import { reveal } from '@stellix-agency/motion';
|
|
253
|
+
|
|
254
|
+
reveal(element, 'bottom', { duration: 1 });
|
|
255
|
+
// directions: 'left' | 'right' | 'top' | 'bottom'
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Examples
|
|
259
|
+
|
|
260
|
+
### Hero Section with Scroll Trigger
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
const hero = new Motion(heroElement);
|
|
264
|
+
hero
|
|
265
|
+
.fadeIn({ duration: 1.2 })
|
|
266
|
+
.slideUp(100, { duration: 1 })
|
|
267
|
+
.scale(1, { ease: 'back.out(1.7)' })
|
|
268
|
+
.onScroll({ start: 'top center' });
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Staggered Cards
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
stagger('.card', (motion, index) => {
|
|
275
|
+
motion
|
|
276
|
+
.fadeIn()
|
|
277
|
+
.slideUp(30)
|
|
278
|
+
.scale(1)
|
|
279
|
+
.onScroll();
|
|
280
|
+
}, 0.15);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Complex Sequence
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
const element = new Motion(box);
|
|
287
|
+
element
|
|
288
|
+
.fadeIn({ duration: 0.5 })
|
|
289
|
+
.wait(0.2)
|
|
290
|
+
.slideUp(50, { duration: 0.8 })
|
|
291
|
+
.scale(1.2, { duration: 0.5, ease: 'back.out(1.7)' })
|
|
292
|
+
.rotate(360, { duration: 1 })
|
|
293
|
+
.wait(0.5)
|
|
294
|
+
.slideDown(20, { duration: 0.3 });
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Solid.js Component
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
import { animate } from '@stellix-agency/motion';
|
|
301
|
+
|
|
302
|
+
function AnimatedCard() {
|
|
303
|
+
return (
|
|
304
|
+
<div
|
|
305
|
+
class="card"
|
|
306
|
+
use:animate={(m) =>
|
|
307
|
+
m.fadeIn()
|
|
308
|
+
.slideUp(50)
|
|
309
|
+
.scale(1)
|
|
310
|
+
.onScroll({ start: 'top 90%' })
|
|
311
|
+
}
|
|
312
|
+
>
|
|
313
|
+
<h2>Card Title</h2>
|
|
314
|
+
<p>Card content</p>
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Custom Animation with GSAP Properties
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
motion.animate({
|
|
324
|
+
background: 'linear-gradient(45deg, #667eea 0%, #764ba2 100%)',
|
|
325
|
+
borderRadius: '50%',
|
|
326
|
+
boxShadow: '0 10px 30px rgba(0,0,0,0.3)'
|
|
327
|
+
}, { duration: 1.5, ease: 'power2.inOut' });
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## TypeScript Support
|
|
331
|
+
|
|
332
|
+
Full TypeScript support with exported types:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import type {
|
|
336
|
+
AnimationOptions,
|
|
337
|
+
ScrollAnimationOptions,
|
|
338
|
+
SlideDirection,
|
|
339
|
+
FadeVariant,
|
|
340
|
+
AnimationPreset
|
|
341
|
+
} from '@stellix-agency/motion';
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Browser Support
|
|
345
|
+
|
|
346
|
+
- Modern browsers with ES6+ support
|
|
347
|
+
- Requires GSAP 3.14.2+
|
|
348
|
+
- ScrollTrigger plugin included
|
|
349
|
+
|
|
350
|
+
## License
|
|
351
|
+
|
|
352
|
+
MIT © Stellix Agency
|
|
353
|
+
|
|
354
|
+
## Credits
|
|
355
|
+
|
|
356
|
+
Built with ❤️ by [Stellix Agency](https://stellix.agency)
|
|
357
|
+
Powered by [GSAP](https://gsap.com)
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
e?: string;
|
|
4
|
-
}
|
|
5
|
-
declare class MotionCore {
|
|
6
|
-
private tl;
|
|
7
|
-
private el;
|
|
8
|
-
private defaults;
|
|
9
|
-
constructor(el: HTMLElement);
|
|
10
|
-
private add;
|
|
11
|
-
in(options?: MotionOptions): this;
|
|
12
|
-
move(x: number, y: number, options?: MotionOptions): this;
|
|
13
|
-
scale(s: number, options?: MotionOptions): this;
|
|
14
|
-
wait(d: number): this;
|
|
15
|
-
/**
|
|
16
|
-
* Utilisation du type Vars de ScrollTrigger (le plus moderne)
|
|
17
|
-
*/
|
|
18
|
-
onScroll(st?: ScrollTrigger.Vars): this;
|
|
19
|
-
}
|
|
1
|
+
import { M as Motion, A as AnimationOptions } from './jsx.js';
|
|
2
|
+
export { a as AnimationPreset, F as FadeVariant, S as ScrollAnimationOptions, b as SlideDirection } from './jsx.js';
|
|
20
3
|
|
|
21
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Solid.js directive for declarative animations
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { animate } from '@stellix-agency/motion';
|
|
10
|
+
*
|
|
11
|
+
* // The directive is used via use:animate, not called directly
|
|
12
|
+
* <div use:animate={(m) => m.fadeIn().slideUp().onScroll()}>
|
|
13
|
+
* Content
|
|
14
|
+
* </div>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This function is used as a Solid.js directive and should be imported
|
|
19
|
+
* even if your IDE shows it as unused. The import is required for the
|
|
20
|
+
* directive to work properly.
|
|
21
|
+
*/
|
|
22
|
+
declare function animate(element: HTMLElement, accessor: () => (motion: Motion) => void): void;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Create a stagger animation for multiple elements
|
|
26
|
+
* @param elements - Array of elements or CSS selector
|
|
27
|
+
* @param callback - Function that receives Motion instance for each element
|
|
28
|
+
* @param staggerDelay - Delay between each element animation (default: 0.1s)
|
|
29
|
+
*/
|
|
30
|
+
declare function stagger(elements: HTMLElement[] | NodeListOf<HTMLElement> | string, callback: (motion: Motion, index: number) => void, staggerDelay?: number): Motion[];
|
|
31
|
+
/**
|
|
32
|
+
* Batch multiple elements with the same animation
|
|
33
|
+
* @param elements - Array of elements or CSS selector
|
|
34
|
+
* @param callback - Function that receives Motion instance
|
|
35
|
+
*/
|
|
36
|
+
declare function batch(elements: HTMLElement[] | NodeListOf<HTMLElement> | string, callback: (motion: Motion) => void): Motion[];
|
|
37
|
+
/**
|
|
38
|
+
* Create a scroll-triggered entrance animation
|
|
39
|
+
* @param element - Element to animate
|
|
40
|
+
* @param options - Animation options
|
|
41
|
+
*/
|
|
42
|
+
declare function scrollEntrance(element: HTMLElement, options?: AnimationOptions): Motion;
|
|
43
|
+
/**
|
|
44
|
+
* Create a hover animation using GSAP
|
|
45
|
+
* @param element - Element to animate on hover
|
|
46
|
+
* @param hoverVars - Animation properties on hover
|
|
47
|
+
* @param options - Animation options
|
|
48
|
+
*/
|
|
49
|
+
declare function hover(element: HTMLElement, hoverVars: gsap.TweenVars, options?: AnimationOptions): () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Create a parallax scroll effect
|
|
52
|
+
* @param element - Element to apply parallax
|
|
53
|
+
* @param speed - Parallax speed multiplier (default: 0.5)
|
|
54
|
+
*/
|
|
55
|
+
declare function parallax(element: HTMLElement, speed?: number): gsap.core.Tween;
|
|
56
|
+
/**
|
|
57
|
+
* Create a reveal animation (commonly used for text/images)
|
|
58
|
+
* @param element - Element to reveal
|
|
59
|
+
* @param direction - Direction from which to reveal
|
|
60
|
+
* @param options - Animation options
|
|
61
|
+
*/
|
|
62
|
+
declare function reveal(element: HTMLElement, direction?: 'left' | 'right' | 'top' | 'bottom', options?: AnimationOptions): Motion;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Predefined animation presets for common use cases
|
|
66
|
+
*/
|
|
67
|
+
declare const presets: {
|
|
68
|
+
/**
|
|
69
|
+
* Quick and snappy animation
|
|
70
|
+
*/
|
|
71
|
+
fast: AnimationOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Standard animation speed
|
|
74
|
+
*/
|
|
75
|
+
normal: AnimationOptions;
|
|
76
|
+
/**
|
|
77
|
+
* Slow and smooth animation
|
|
78
|
+
*/
|
|
79
|
+
slow: AnimationOptions;
|
|
80
|
+
/**
|
|
81
|
+
* Bouncy entrance animation
|
|
82
|
+
*/
|
|
83
|
+
bounce: AnimationOptions;
|
|
84
|
+
/**
|
|
85
|
+
* Spring-like animation
|
|
86
|
+
*/
|
|
87
|
+
spring: AnimationOptions;
|
|
88
|
+
/**
|
|
89
|
+
* Smooth ease in and out
|
|
90
|
+
*/
|
|
91
|
+
smooth: AnimationOptions;
|
|
92
|
+
/**
|
|
93
|
+
* Sharp entrance
|
|
94
|
+
*/
|
|
95
|
+
sharp: AnimationOptions;
|
|
96
|
+
/**
|
|
97
|
+
* Elastic bounce effect
|
|
98
|
+
*/
|
|
99
|
+
elastic: AnimationOptions;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Common easing functions
|
|
103
|
+
*/
|
|
104
|
+
declare const easings: {
|
|
105
|
+
linear: string;
|
|
106
|
+
easeIn: string;
|
|
107
|
+
easeOut: string;
|
|
108
|
+
easeInOut: string;
|
|
109
|
+
smoothIn: string;
|
|
110
|
+
smoothOut: string;
|
|
111
|
+
smoothInOut: string;
|
|
112
|
+
bounceOut: string;
|
|
113
|
+
bounceIn: string;
|
|
114
|
+
bounceInOut: string;
|
|
115
|
+
elasticOut: string;
|
|
116
|
+
elasticIn: string;
|
|
117
|
+
backOut: string;
|
|
118
|
+
backIn: string;
|
|
119
|
+
circOut: string;
|
|
120
|
+
circIn: string;
|
|
121
|
+
expoOut: string;
|
|
122
|
+
expoIn: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { AnimationOptions, Motion, Motion as MotionCore, animate, batch, easings, hover, parallax, presets, reveal, scrollEntrance, stagger };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{gsap as
|
|
1
|
+
import"./chunk-YEOCNWCQ.js";import{gsap as b}from"gsap";import{ScrollTrigger as M}from"gsap/ScrollTrigger";import{gsap as l}from"gsap";import{ScrollTrigger as p}from"gsap/ScrollTrigger";var r=class{timeline;element;defaultDuration=.8;defaultEase="power4.out";hasScrollTrigger=!1;constructor(t,i=!0){this.element=t,l.set(this.element,{opacity:0,y:20}),this.timeline=l.timeline({paused:!0}),i&&Promise.resolve().then(()=>{this.hasScrollTrigger||this.play()})}addAnimation(t,i){let{duration:n,ease:o,delay:a,...s}=i||{};return this.timeline.to(this.element,{...t,duration:n??this.defaultDuration,ease:o??this.defaultEase,delay:a??0,...s},">"),this}fadeIn(t){return this.addAnimation({opacity:1},t)}fadeOut(t){return this.addAnimation({opacity:0},t)}fade(t="in",i){switch(t){case"in":return this.fadeIn(i);case"out":return this.fadeOut(i);case"inOut":return this.fadeIn(i).fadeOut(i);default:return this.fadeIn(i)}}slide(t,i=50,n){let o={up:{y:0,x:0},down:{y:i,x:0},left:{x:0,y:0},right:{x:i,y:0}};return this.addAnimation(o[t],n)}slideUp(t=50,i){return this.addAnimation({y:0},i)}slideDown(t=50,i){return this.addAnimation({y:t},i)}slideLeft(t=50,i){return this.addAnimation({x:-t},i)}slideRight(t=50,i){return this.addAnimation({x:t},i)}moveTo(t,i,n){return this.addAnimation({x:t,y:i},n)}scale(t,i){return this.addAnimation({scale:t},{ease:"back.out(1.7)",...i})}rotate(t,i){return this.addAnimation({rotation:t},i)}blur(t,i){return this.addAnimation({filter:`blur(${t}px)`},i)}skew(t,i,n){return this.addAnimation({skewX:t,skewY:i},n)}animate(t,i){return this.addAnimation(t,i)}wait(t){return this.timeline.to({},{duration:t},">"),this}setDuration(t){return this.defaultDuration=t,this}setEase(t){return this.defaultEase=t,this}onScroll(t){return this.hasScrollTrigger=!0,p.create({trigger:this.element,start:"top 85%",animation:this.timeline,toggleActions:"play none none reverse",...t}),this}play(){return this.timeline.play(),this}pause(){return this.timeline.pause(),this}restart(){return this.timeline.restart(),this}reverse(){return this.timeline.reverse(),this}getTimeline(){return this.timeline}kill(){this.timeline.kill(),this.hasScrollTrigger&&p.getById(this.timeline.scrollTrigger?.vars.id)?.kill()}};import{onCleanup as c}from"solid-js";function d(e,t){try{let i=t();if(typeof i!="function"){console.warn("[Magic Motion] animate directive expects a function");return}let n=new r(e);setTimeout(()=>{try{i(n)}catch(o){console.error("[Magic Motion] Error setting up animation:",o)}},0),c(()=>{n.kill()})}catch(i){console.error("[Magic Motion] Error initializing animation:",i)}}import{gsap as m}from"gsap";function h(e,t,i=.1){return Array.from(typeof e=="string"?document.querySelectorAll(e):e).map((o,a)=>{let s=new r(o,!1);return a>0&&s.wait(i*a),t(s,a),s.play(),s})}function f(e,t){return Array.from(typeof e=="string"?document.querySelectorAll(e):e).map(n=>{let o=new r(n);return t(o),o})}function g(e,t){return new r(e,!1).fadeIn(t).slideUp(30,t).onScroll()}function A(e,t,i){let{duration:n=.3,ease:o="power2.out",...a}=i||{},s=()=>{m.to(e,{...t,duration:n,ease:o,...a})},u=()=>{m.to(e,{scale:1,x:0,y:0,rotation:0,duration:n,ease:o,...a})};return e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",u),()=>{e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",u)}}function O(e,t=.5){return m.to(e,{y:()=>window.innerHeight*t,ease:"none",scrollTrigger:{trigger:e,start:"top bottom",end:"bottom top",scrub:!0}})}function y(e,t="bottom",i){let n=new r(e,!1);return{left:()=>n.slideRight(100,i),right:()=>n.slideLeft(100,i),top:()=>n.slideDown(100,i),bottom:()=>n.slideUp(100,i)}[t]().fadeIn(i)}var w={fast:{duration:.3,ease:"power2.out"},normal:{duration:.8,ease:"power4.out"},slow:{duration:1.5,ease:"power4.out"},bounce:{duration:.8,ease:"elastic.out(1, 0.5)"},spring:{duration:.6,ease:"back.out(1.7)"},smooth:{duration:1,ease:"power2.inOut"},sharp:{duration:.4,ease:"power4.in"},elastic:{duration:1,ease:"elastic.out(1, 0.3)"}},v={linear:"none",easeIn:"power2.in",easeOut:"power2.out",easeInOut:"power2.inOut",smoothIn:"power4.in",smoothOut:"power4.out",smoothInOut:"power4.inOut",bounceOut:"bounce.out",bounceIn:"bounce.in",bounceInOut:"bounce.inOut",elasticOut:"elastic.out(1, 0.3)",elasticIn:"elastic.in(1, 0.3)",backOut:"back.out(1.7)",backIn:"back.in(1.7)",circOut:"circ.out",circIn:"circ.in",expoOut:"expo.out",expoIn:"expo.in"};typeof window<"u"&&b.registerPlugin(M);export{r as Motion,r as MotionCore,d as animate,f as batch,v as easings,A as hover,O as parallax,w as presets,y as reveal,g as scrollEntrance,h as stagger};
|
package/dist/jsx.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base animation options that extend GSAP's TweenVars
|
|
3
|
+
*/
|
|
4
|
+
interface AnimationOptions extends Omit<gsap.TweenVars, 'duration' | 'ease'> {
|
|
5
|
+
/**
|
|
6
|
+
* Animation duration in seconds
|
|
7
|
+
* @default 0.8
|
|
8
|
+
*/
|
|
9
|
+
duration?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Easing function for the animation
|
|
12
|
+
* @default "power4.out"
|
|
13
|
+
*/
|
|
14
|
+
ease?: string | gsap.EaseFunction;
|
|
15
|
+
/**
|
|
16
|
+
* Delay before animation starts in seconds
|
|
17
|
+
* @default 0
|
|
18
|
+
*/
|
|
19
|
+
delay?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for scroll-triggered animations
|
|
23
|
+
*/
|
|
24
|
+
interface ScrollAnimationOptions extends ScrollTrigger.Vars {
|
|
25
|
+
/**
|
|
26
|
+
* When the animation should start relative to the viewport
|
|
27
|
+
* @default "top 85%"
|
|
28
|
+
*/
|
|
29
|
+
start?: string;
|
|
30
|
+
/**
|
|
31
|
+
* When the animation should end relative to the viewport
|
|
32
|
+
*/
|
|
33
|
+
end?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Actions to perform: onEnter, onLeave, onEnterBack, onLeaveBack
|
|
36
|
+
* @default "play none none reverse"
|
|
37
|
+
*/
|
|
38
|
+
toggleActions?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Direction for slide animations
|
|
42
|
+
*/
|
|
43
|
+
type SlideDirection = 'up' | 'down' | 'left' | 'right';
|
|
44
|
+
/**
|
|
45
|
+
* Fade animation variants
|
|
46
|
+
*/
|
|
47
|
+
type FadeVariant = 'in' | 'out' | 'inOut';
|
|
48
|
+
/**
|
|
49
|
+
* Preset animation configurations
|
|
50
|
+
*/
|
|
51
|
+
interface AnimationPreset {
|
|
52
|
+
duration: number;
|
|
53
|
+
ease: string;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Core animation class providing a fluent API for GSAP animations
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const motion = new Motion(element);
|
|
63
|
+
* motion.fadeIn().slideUp(50).scale(1.2).onScroll();
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class Motion {
|
|
67
|
+
private timeline;
|
|
68
|
+
private element;
|
|
69
|
+
private defaultDuration;
|
|
70
|
+
private defaultEase;
|
|
71
|
+
private hasScrollTrigger;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new Motion instance
|
|
74
|
+
* @param element - The HTML element to animate
|
|
75
|
+
* @param autoStart - Whether to automatically start the animation (default: true)
|
|
76
|
+
*/
|
|
77
|
+
constructor(element: HTMLElement, autoStart?: boolean);
|
|
78
|
+
/**
|
|
79
|
+
* Internal method to add animations to the timeline
|
|
80
|
+
*/
|
|
81
|
+
private addAnimation;
|
|
82
|
+
/**
|
|
83
|
+
* Fade in animation
|
|
84
|
+
* @param options - Animation options
|
|
85
|
+
*/
|
|
86
|
+
fadeIn(options?: AnimationOptions): this;
|
|
87
|
+
/**
|
|
88
|
+
* Fade out animation
|
|
89
|
+
* @param options - Animation options
|
|
90
|
+
*/
|
|
91
|
+
fadeOut(options?: AnimationOptions): this;
|
|
92
|
+
/**
|
|
93
|
+
* Fade animation with variant
|
|
94
|
+
* @param variant - Fade variant ('in', 'out', or 'inOut')
|
|
95
|
+
* @param options - Animation options
|
|
96
|
+
*/
|
|
97
|
+
fade(variant?: FadeVariant, options?: AnimationOptions): this;
|
|
98
|
+
/**
|
|
99
|
+
* Slide animation in a specific direction
|
|
100
|
+
* @param direction - Direction to slide ('up', 'down', 'left', 'right')
|
|
101
|
+
* @param distance - Distance to slide in pixels (default: 50)
|
|
102
|
+
* @param options - Animation options
|
|
103
|
+
*/
|
|
104
|
+
slide(direction: SlideDirection, distance?: number, options?: AnimationOptions): this;
|
|
105
|
+
/**
|
|
106
|
+
* Slide up animation (commonly used for entrance)
|
|
107
|
+
* @param distance - Distance to slide in pixels
|
|
108
|
+
* @param options - Animation options
|
|
109
|
+
*/
|
|
110
|
+
slideUp(distance?: number, options?: AnimationOptions): this;
|
|
111
|
+
/**
|
|
112
|
+
* Slide down animation
|
|
113
|
+
* @param distance - Distance to slide in pixels
|
|
114
|
+
* @param options - Animation options
|
|
115
|
+
*/
|
|
116
|
+
slideDown(distance?: number, options?: AnimationOptions): this;
|
|
117
|
+
/**
|
|
118
|
+
* Slide left animation
|
|
119
|
+
* @param distance - Distance to slide in pixels
|
|
120
|
+
* @param options - Animation options
|
|
121
|
+
*/
|
|
122
|
+
slideLeft(distance?: number, options?: AnimationOptions): this;
|
|
123
|
+
/**
|
|
124
|
+
* Slide right animation
|
|
125
|
+
* @param distance - Distance to slide in pixels
|
|
126
|
+
* @param options - Animation options
|
|
127
|
+
*/
|
|
128
|
+
slideRight(distance?: number, options?: AnimationOptions): this;
|
|
129
|
+
/**
|
|
130
|
+
* Move to specific coordinates
|
|
131
|
+
* @param x - X coordinate in pixels
|
|
132
|
+
* @param y - Y coordinate in pixels
|
|
133
|
+
* @param options - Animation options
|
|
134
|
+
*/
|
|
135
|
+
moveTo(x: number, y: number, options?: AnimationOptions): this;
|
|
136
|
+
/**
|
|
137
|
+
* Scale animation
|
|
138
|
+
* @param scale - Scale factor (1 = original size)
|
|
139
|
+
* @param options - Animation options (default ease: "back.out(1.7)")
|
|
140
|
+
*/
|
|
141
|
+
scale(scale: number, options?: AnimationOptions): this;
|
|
142
|
+
/**
|
|
143
|
+
* Rotate animation
|
|
144
|
+
* @param degrees - Rotation in degrees
|
|
145
|
+
* @param options - Animation options
|
|
146
|
+
*/
|
|
147
|
+
rotate(degrees: number, options?: AnimationOptions): this;
|
|
148
|
+
/**
|
|
149
|
+
* Blur animation (requires CSS filters support)
|
|
150
|
+
* @param amount - Blur amount in pixels
|
|
151
|
+
* @param options - Animation options
|
|
152
|
+
*/
|
|
153
|
+
blur(amount: number, options?: AnimationOptions): this;
|
|
154
|
+
/**
|
|
155
|
+
* Skew animation
|
|
156
|
+
* @param x - Skew X in degrees
|
|
157
|
+
* @param y - Skew Y in degrees
|
|
158
|
+
* @param options - Animation options
|
|
159
|
+
*/
|
|
160
|
+
skew(x: number, y: number, options?: AnimationOptions): this;
|
|
161
|
+
/**
|
|
162
|
+
* Custom animation with any GSAP-supported properties
|
|
163
|
+
* @param vars - GSAP animation variables
|
|
164
|
+
* @param options - Animation options
|
|
165
|
+
*/
|
|
166
|
+
animate(vars: gsap.TweenVars, options?: AnimationOptions): this;
|
|
167
|
+
/**
|
|
168
|
+
* Add a delay/pause in the animation sequence
|
|
169
|
+
* @param duration - Wait duration in seconds
|
|
170
|
+
*/
|
|
171
|
+
wait(duration: number): this;
|
|
172
|
+
/**
|
|
173
|
+
* Set the default duration for subsequent animations
|
|
174
|
+
* @param duration - Duration in seconds
|
|
175
|
+
*/
|
|
176
|
+
setDuration(duration: number): this;
|
|
177
|
+
/**
|
|
178
|
+
* Set the default easing for subsequent animations
|
|
179
|
+
* @param ease - Easing function or string
|
|
180
|
+
*/
|
|
181
|
+
setEase(ease: string | gsap.EaseFunction): this;
|
|
182
|
+
/**
|
|
183
|
+
* Add ScrollTrigger to the animation
|
|
184
|
+
* @param options - ScrollTrigger options
|
|
185
|
+
*/
|
|
186
|
+
onScroll(options?: ScrollAnimationOptions): this;
|
|
187
|
+
/**
|
|
188
|
+
* Play the animation timeline
|
|
189
|
+
*/
|
|
190
|
+
play(): this;
|
|
191
|
+
/**
|
|
192
|
+
* Pause the animation timeline
|
|
193
|
+
*/
|
|
194
|
+
pause(): this;
|
|
195
|
+
/**
|
|
196
|
+
* Restart the animation timeline
|
|
197
|
+
*/
|
|
198
|
+
restart(): this;
|
|
199
|
+
/**
|
|
200
|
+
* Reverse the animation timeline
|
|
201
|
+
*/
|
|
202
|
+
reverse(): this;
|
|
203
|
+
/**
|
|
204
|
+
* Get the underlying GSAP timeline
|
|
205
|
+
*/
|
|
206
|
+
getTimeline(): gsap.core.Timeline;
|
|
207
|
+
/**
|
|
208
|
+
* Kill the animation and clean up
|
|
209
|
+
*/
|
|
210
|
+
kill(): void;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
declare module 'solid-js' {
|
|
214
|
+
namespace JSX {
|
|
215
|
+
interface Directives {
|
|
216
|
+
animate: (motion: Motion) => void;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export { type AnimationOptions as A, type FadeVariant as F, Motion as M, type ScrollAnimationOptions as S, type AnimationPreset as a, type SlideDirection as b };
|
package/dist/jsx.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-YEOCNWCQ.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellix-agency/motion",
|
|
3
|
-
"publishConfig": {
|
|
4
|
-
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "1.0.2",
|
|
5
7
|
"description": "An intuitive GSAP wrapper for creating stunning animations with ease.",
|
|
6
8
|
"author": "Stellix Agency",
|
|
7
9
|
"license": "MIT",
|
|
@@ -15,10 +17,32 @@
|
|
|
15
17
|
"main": "./dist/index.js",
|
|
16
18
|
"module": "./dist/index.js",
|
|
17
19
|
"types": "./dist/index.d.ts",
|
|
18
|
-
"
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./jsx": {
|
|
27
|
+
"types": "./dist/jsx.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"typesVersions": {
|
|
34
|
+
"*": {
|
|
35
|
+
"*": [
|
|
36
|
+
"./dist/index.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"jsx": [
|
|
39
|
+
"./dist/jsx.d.ts"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
19
43
|
"scripts": {
|
|
20
|
-
"build": "tsup
|
|
21
|
-
"dev": "tsup
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"dev": "tsup --watch"
|
|
22
46
|
},
|
|
23
47
|
"peerDependencies": {
|
|
24
48
|
"gsap": "^3.14.2",
|
|
@@ -30,4 +54,4 @@
|
|
|
30
54
|
"gsap": "^3.14.2",
|
|
31
55
|
"solid-js": "^1.9.11"
|
|
32
56
|
}
|
|
33
|
-
}
|
|
57
|
+
}
|