@andresclua/perlindom 0.0.6 → 0.1.1
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/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +426 -0
- package/dist/perlindom.es.js +212 -0
- package/dist/perlindom.umd.js +1 -0
- package/package.json +14 -6
- package/dist/PerlinDOM.es.js +0 -138
- package/dist/PerlinDOM.umd.js +0 -1
- package/docs/examples.html +0 -391
- package/public/vite.svg +0 -1
- package/readme.md +0 -353
- package/src/index.html +0 -819
- package/src/js/PerlinDom.js +0 -318
- package/src/js/animated-button.js +0 -40
- package/src/js/basic-examples.js +0 -43
- package/src/js/index.js +0 -13
- package/src/js/interactive-controls.js +0 -43
- package/src/js/pause-play.js +0 -33
- package/src/js/triangle-animation.js +0 -48
- package/src/scss/style.scss +0 -20
- package/vite.config.js +0 -36
package/readme.md
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
# PerlinDOM
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/js/@andresclua%2Fperlindom)
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://developer.mozilla.org/en-US/docs/Web/JavaScript)
|
|
6
|
-
|
|
7
|
-
A lightweight JavaScript library for creating smooth, organic animations on DOM elements using Perlin noise. Create natural, fluid movements that bring your web interfaces to life.
|
|
8
|
-
|
|
9
|
-
## 📋 Table of Contents
|
|
10
|
-
|
|
11
|
-
- [Features](#-features)
|
|
12
|
-
- [Installation](#-installation)
|
|
13
|
-
- [Quick Start](#-quick-start)
|
|
14
|
-
- [Configuration](#-configuration)
|
|
15
|
-
- [Examples](#-examples)
|
|
16
|
-
- [Best Practices](#-best-practices)
|
|
17
|
-
- [API Reference](#-api-reference)
|
|
18
|
-
- [Troubleshooting](#-troubleshooting)
|
|
19
|
-
- [Browser Compatibility](#-browser-compatibility)
|
|
20
|
-
- [Changelog](#-changelog)
|
|
21
|
-
- [License](#-license)
|
|
22
|
-
|
|
23
|
-
## ✨ Features
|
|
24
|
-
|
|
25
|
-
- **🌊 Organic Animations**: Natural movements using Perlin noise that avoid mechanical rigidity
|
|
26
|
-
- **📱 Responsive Design**: Support for percentage-based values that adapt to container size
|
|
27
|
-
- **🎯 Smart Positioning**: Automatically works from element's current position (CSS or inline styles)
|
|
28
|
-
- **⚡ High Performance**: Uses `transform` and `requestAnimationFrame` for smooth 60fps animations
|
|
29
|
-
- **🎛️ Full Control**: Play, pause, and destroy animations with smooth transitions
|
|
30
|
-
- **📦 Lightweight**: Minimal footprint with zero dependencies
|
|
31
|
-
- **🔧 Easy Integration**: Simple API that works with any DOM element
|
|
32
|
-
- **🎨 Flexible**: Mix pixel and percentage values, animate on single or both axes
|
|
33
|
-
|
|
34
|
-
## 📦 Installation
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm install @andresclua/perlindom
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Or include directly in your HTML:
|
|
41
|
-
|
|
42
|
-
```html
|
|
43
|
-
<script type="module">
|
|
44
|
-
import PerlinDOM from 'https://unpkg.com/@andresclua/perlindom/dist/perlindom.es.js';
|
|
45
|
-
</script>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## 🚀 Quick Start
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
import PerlinDOM from '@andresclua/perlindom';
|
|
52
|
-
|
|
53
|
-
// Basic animation - element will animate from its current position
|
|
54
|
-
const animation = new PerlinDOM({
|
|
55
|
-
element: document.querySelector('.my-element'),
|
|
56
|
-
x: { min: -50, max: 50 }, // Move ±50px horizontally
|
|
57
|
-
y: { min: -30, max: 30 }, // Move ±30px vertically
|
|
58
|
-
speed: 0.01, // Animation speed
|
|
59
|
-
seed: 123 // Reproducible pattern
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Control the animation
|
|
63
|
-
animation.pause(); // Smooth pause
|
|
64
|
-
animation.play(); // Resume
|
|
65
|
-
animation.destroy(); // Clean up
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
```css
|
|
69
|
-
/* Your element needs positioning for transforms to work */
|
|
70
|
-
.my-element {
|
|
71
|
-
position: relative; /* or absolute, or fixed */
|
|
72
|
-
/* PerlinDOM will animate from wherever this element is positioned */
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## ⚙️ Configuration
|
|
77
|
-
|
|
78
|
-
| Option | Type | Default | Description |
|
|
79
|
-
|--------|------|---------|-------------|
|
|
80
|
-
| `element` | `HTMLElement` | **required** | The DOM element to animate |
|
|
81
|
-
| `x` | `Object \| null` | `null` | Horizontal movement: `{min: number, max: number}` |
|
|
82
|
-
| `y` | `Object \| null` | `null` | Vertical movement: `{min: number, max: number}` |
|
|
83
|
-
| `speed` | `number` | `0.01` | Animation speed (lower = slower) |
|
|
84
|
-
| `seed` | `number` | `0` | Seed for reproducible patterns |
|
|
85
|
-
| `lerpSpeed` | `number` | `0.1` | Transition smoothness for pause/play |
|
|
86
|
-
|
|
87
|
-
### Value Types
|
|
88
|
-
|
|
89
|
-
- **Pixels**: `{ min: -50, max: 50 }` - Fixed pixel movement
|
|
90
|
-
- **Percentages**: `{ min: '-10%', max: '10%' }` - Responsive to parent size
|
|
91
|
-
- **Mixed**: `x: { min: '-5%', max: '5%' }, y: { min: -20, max: 20 }`
|
|
92
|
-
- **Single Axis**: Set unused axis to `null`
|
|
93
|
-
|
|
94
|
-
## 📚 Examples
|
|
95
|
-
|
|
96
|
-
### 1. Basic Element Animation
|
|
97
|
-
|
|
98
|
-
```html
|
|
99
|
-
<div class="floating-card">Content</div>
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
```css
|
|
103
|
-
.floating-card {
|
|
104
|
-
position: relative;
|
|
105
|
-
left: 50%;
|
|
106
|
-
top: 50%;
|
|
107
|
-
transform: translate(-50%, -50%);
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
new PerlinDOM({
|
|
113
|
-
element: document.querySelector('.floating-card'),
|
|
114
|
-
x: { min: -20, max: 20 },
|
|
115
|
-
y: { min: -15, max: 15 },
|
|
116
|
-
speed: 0.008,
|
|
117
|
-
seed: 42
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### 2. Responsive Background Elements
|
|
122
|
-
|
|
123
|
-
```javascript
|
|
124
|
-
// Elements adapt to container size changes
|
|
125
|
-
document.querySelectorAll('.bg-particle').forEach((el, index) => {
|
|
126
|
-
new PerlinDOM({
|
|
127
|
-
element: el,
|
|
128
|
-
x: { min: '-15%', max: '15%' }, // 15% of parent width
|
|
129
|
-
y: { min: '-10%', max: '10%' }, // 10% of parent height
|
|
130
|
-
speed: 0.003,
|
|
131
|
-
seed: index * 1000
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### 3. Interactive Hover Effects
|
|
137
|
-
|
|
138
|
-
```javascript
|
|
139
|
-
const button = document.querySelector('.animated-button');
|
|
140
|
-
let animation;
|
|
141
|
-
|
|
142
|
-
button.addEventListener('mouseenter', () => {
|
|
143
|
-
animation = new PerlinDOM({
|
|
144
|
-
element: button.querySelector('.effect'),
|
|
145
|
-
x: { min: -5, max: 5 },
|
|
146
|
-
y: { min: -5, max: 5 },
|
|
147
|
-
speed: 0.02,
|
|
148
|
-
lerpSpeed: 0.15
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
button.addEventListener('mouseleave', () => {
|
|
153
|
-
animation?.pause();
|
|
154
|
-
});
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### 4. Multiple Elements with Synchronized Patterns
|
|
158
|
-
|
|
159
|
-
```javascript
|
|
160
|
-
// Same seed = synchronized movement
|
|
161
|
-
document.querySelectorAll('.sync-element').forEach(el => {
|
|
162
|
-
new PerlinDOM({
|
|
163
|
-
element: el,
|
|
164
|
-
x: { min: -30, max: 30 },
|
|
165
|
-
y: { min: -30, max: 30 },
|
|
166
|
-
speed: 0.01,
|
|
167
|
-
seed: 12345 // Same seed for all elements
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### 5. Custom Animation Patterns
|
|
173
|
-
|
|
174
|
-
```javascript
|
|
175
|
-
// Horizontal-only movement for sliding effects
|
|
176
|
-
new PerlinDOM({
|
|
177
|
-
element: document.querySelector('.slider'),
|
|
178
|
-
x: { min: -100, max: 100 },
|
|
179
|
-
y: null, // No vertical movement
|
|
180
|
-
speed: 0.005
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Vertical-only for floating effects
|
|
184
|
-
new PerlinDOM({
|
|
185
|
-
element: document.querySelector('.floater'),
|
|
186
|
-
x: null, // No horizontal movement
|
|
187
|
-
y: { min: -40, max: 40 },
|
|
188
|
-
speed: 0.008
|
|
189
|
-
});
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### 6. Advanced: SVG Path Animation
|
|
193
|
-
|
|
194
|
-
```javascript
|
|
195
|
-
// Animate SVG elements or paths
|
|
196
|
-
const svgElement = document.querySelector('#animated-path');
|
|
197
|
-
const pathAnimation = new PerlinDOM({
|
|
198
|
-
element: null, // No direct element
|
|
199
|
-
x: { min: -20, max: 20 },
|
|
200
|
-
y: { min: -15, max: 15 },
|
|
201
|
-
speed: 0.01,
|
|
202
|
-
seed: 999
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
function updatePath() {
|
|
206
|
-
const offsetX = pathAnimation.lastX;
|
|
207
|
-
const offsetY = pathAnimation.lastY;
|
|
208
|
-
|
|
209
|
-
// Update SVG path or transform
|
|
210
|
-
svgElement.style.transform = `translate(${offsetX}px, ${offsetY}px)`;
|
|
211
|
-
|
|
212
|
-
requestAnimationFrame(updatePath);
|
|
213
|
-
}
|
|
214
|
-
updatePath();
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## 💡 Best Practices
|
|
218
|
-
|
|
219
|
-
### ✅ Do
|
|
220
|
-
|
|
221
|
-
- **Use CSS for initial positioning**: Position elements with CSS classes rather than inline styles
|
|
222
|
-
- **Set proper positioning**: Ensure elements have `position: relative`, `absolute`, or `fixed`
|
|
223
|
-
- **Use percentage values for responsive designs**: Great for mobile-friendly animations
|
|
224
|
-
- **Choose appropriate speeds**: Start with `0.01` and adjust based on desired effect
|
|
225
|
-
- **Clean up animations**: Call `destroy()` when removing elements from DOM
|
|
226
|
-
|
|
227
|
-
### ❌ Don't
|
|
228
|
-
|
|
229
|
-
- **Don't rely on inline positioning**: PerlinDOM works from any position, but CSS is cleaner
|
|
230
|
-
- **Don't use on static elements**: Transform won't work without proper positioning
|
|
231
|
-
- **Don't forget to destroy**: Memory leaks can occur if animations aren't cleaned up
|
|
232
|
-
- **Don't use extreme speeds**: Very high speeds can cause jittery animations
|
|
233
|
-
|
|
234
|
-
### 🎯 Performance Tips
|
|
235
|
-
|
|
236
|
-
```javascript
|
|
237
|
-
// Good: Reuse animation instances
|
|
238
|
-
const sharedAnimation = new PerlinDOM({...});
|
|
239
|
-
|
|
240
|
-
// Good: Use percentage values for responsive design
|
|
241
|
-
x: { min: '-5%', max: '5%' }
|
|
242
|
-
|
|
243
|
-
// Good: Appropriate speeds for smooth animation
|
|
244
|
-
speed: 0.01 // Smooth and natural
|
|
245
|
-
|
|
246
|
-
// Good: Clean up when done
|
|
247
|
-
animation.destroy();
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## 📖 API Reference
|
|
251
|
-
|
|
252
|
-
### Constructor
|
|
253
|
-
|
|
254
|
-
```javascript
|
|
255
|
-
new PerlinDOM(options)
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### Methods
|
|
259
|
-
|
|
260
|
-
| Method | Description | Returns |
|
|
261
|
-
|--------|-------------|---------|
|
|
262
|
-
| `play()` | Start or resume animation | `void` |
|
|
263
|
-
| `pause()` | Smoothly pause animation | `void` |
|
|
264
|
-
| `destroy()` | Stop animation and clean up resources | `void` |
|
|
265
|
-
| `init(seed?)` | Reinitialize with optional new seed | `void` |
|
|
266
|
-
|
|
267
|
-
### Properties
|
|
268
|
-
|
|
269
|
-
| Property | Type | Description |
|
|
270
|
-
|----------|------|-------------|
|
|
271
|
-
| `lastX` | `number` | Current X offset value |
|
|
272
|
-
| `lastY` | `number` | Current Y offset value |
|
|
273
|
-
| `isPlaying` | `boolean` | Current animation state |
|
|
274
|
-
| `speed` | `number` | Animation speed (writable) |
|
|
275
|
-
| `lerpSpeed` | `number` | Transition speed (writable) |
|
|
276
|
-
|
|
277
|
-
## 🔧 Troubleshooting
|
|
278
|
-
|
|
279
|
-
### Common Issues
|
|
280
|
-
|
|
281
|
-
**❓ Animation not visible**
|
|
282
|
-
```css
|
|
283
|
-
/* Ensure element has positioning */
|
|
284
|
-
.my-element {
|
|
285
|
-
position: relative; /* or absolute/fixed */
|
|
286
|
-
}
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
**❓ Element jumps on initialization**
|
|
290
|
-
- PerlinDOM automatically detects current position
|
|
291
|
-
- If element has conflicting inline styles, consider moving to CSS
|
|
292
|
-
|
|
293
|
-
**❓ Animation too fast/slow**
|
|
294
|
-
```javascript
|
|
295
|
-
// Adjust speed value
|
|
296
|
-
speed: 0.001 // Very slow
|
|
297
|
-
speed: 0.01 // Normal
|
|
298
|
-
speed: 0.1 // Fast
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
**❓ Percentage values not working**
|
|
302
|
-
- Ensure parent container has defined dimensions
|
|
303
|
-
- PerlinDOM calculates percentages based on parent size
|
|
304
|
-
|
|
305
|
-
**❓ Memory leaks**
|
|
306
|
-
```javascript
|
|
307
|
-
// Always clean up when removing elements
|
|
308
|
-
animation.destroy();
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### Browser DevTools
|
|
312
|
-
|
|
313
|
-
Monitor performance in DevTools:
|
|
314
|
-
- Check for smooth 60fps in Performance tab
|
|
315
|
-
- Verify transform properties are being animated (not layout properties)
|
|
316
|
-
|
|
317
|
-
## 🌐 Browser Compatibility
|
|
318
|
-
|
|
319
|
-
PerlinDOM works in all modern browsers supporting:
|
|
320
|
-
|
|
321
|
-
- ✅ **ES6 Modules** (2015+)
|
|
322
|
-
- ✅ **requestAnimationFrame** (IE10+)
|
|
323
|
-
- ✅ **CSS Transforms** (IE9+)
|
|
324
|
-
- ✅ **getComputedStyle** (IE9+)
|
|
325
|
-
|
|
326
|
-
### Tested Browsers
|
|
327
|
-
|
|
328
|
-
- Chrome 60+
|
|
329
|
-
- Firefox 55+
|
|
330
|
-
- Safari 12+
|
|
331
|
-
- Edge 79+
|
|
332
|
-
|
|
333
|
-
## 📝 Changelog
|
|
334
|
-
|
|
335
|
-
See [CHANGELOG.md](./CHANGELOG.md) for detailed version history.
|
|
336
|
-
|
|
337
|
-
### Recent Updates
|
|
338
|
-
|
|
339
|
-
- **v0.0.6**: Enhanced PerlinDOM to preserve design transforms
|
|
340
|
-
- **v0.0.4**: Package now public on npm, enhanced module exports configuration
|
|
341
|
-
- **v0.0.3**: Fixed positioning conflicts, improved automatic position detection
|
|
342
|
-
- **v0.0.2**: Added percentage support and responsive animations
|
|
343
|
-
- **v0.0.1**: Initial release with core Perlin noise animations
|
|
344
|
-
|
|
345
|
-
## 📄 License
|
|
346
|
-
|
|
347
|
-
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
348
|
-
|
|
349
|
-
---
|
|
350
|
-
|
|
351
|
-
**Made with ❤️ by [Andres Clua](https://github.com/andresclua)**
|
|
352
|
-
|
|
353
|
-
*PerlinDOM - Bringing organic motion to the web*
|