motionrail 0.0.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/README.md +275 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# MotionRail
|
|
2
|
+
|
|
3
|
+
> â ī¸ **Not Ready for Production** - This library is currently in development and not yet ready for production use.
|
|
4
|
+
|
|
5
|
+
A lightweight, smooth carousel library with momentum-based scrolling, snap alignment, and responsive breakpoints.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- đ¯ **Momentum-based scrolling** - Natural drag physics with smooth animations
|
|
10
|
+
- đą **Responsive breakpoints** - Configure columns and gaps for different screen sizes
|
|
11
|
+
- âŋ **Snap alignment** - Automatic snap-to-item positioning
|
|
12
|
+
- đ **Autoplay support** - Optional auto-scrolling with pause on interaction
|
|
13
|
+
- âī¸ **RTL support** - Built-in right-to-left layout support
|
|
14
|
+
- đ¨ **CSS Grid based** - Modern layout with customizable styling
|
|
15
|
+
- đĒļ **Lightweight** - Zero dependencies, minimal bundle size
|
|
16
|
+
- đŽ **Full control API** - Programmatic navigation and playback control
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install motionrail
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### HTML Structure
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<div class="motion-rail" id="carousel">
|
|
30
|
+
<div class="motion-rail-container">
|
|
31
|
+
<div class="motion-rail-item">Item 1</div>
|
|
32
|
+
<div class="motion-rail-item">Item 2</div>
|
|
33
|
+
<div class="motion-rail-item">Item 3</div>
|
|
34
|
+
<!-- Add more items -->
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### CSS Import
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import 'motionrail/style.css';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### JavaScript
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { MotionRail } from 'motionrail';
|
|
49
|
+
|
|
50
|
+
const element = document.getElementById('carousel');
|
|
51
|
+
|
|
52
|
+
const carousel = new MotionRail(element, {
|
|
53
|
+
autoplay: false,
|
|
54
|
+
rtl: false,
|
|
55
|
+
delay: 3000, // Time between auto-scrolls (ms)
|
|
56
|
+
resumeDelay: 4000, // Time to resume after interaction (ms)
|
|
57
|
+
breakpoints: [
|
|
58
|
+
{ columns: 1, gap: '16px' }, // Mobile (default)
|
|
59
|
+
{ width: 768, columns: 2, gap: '16px' }, // Tablet
|
|
60
|
+
{ width: 1024, columns: 3, gap: '20px' } // Desktop
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Configuration Options
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
|--------|------|---------|-------------|
|
|
69
|
+
| `autoplay` | `boolean` | `false` | Enable automatic scrolling |
|
|
70
|
+
| `rtl` | `boolean` | `false` | Enable right-to-left layout |
|
|
71
|
+
| `delay` | `number` | `3000` | Delay between auto-scrolls (milliseconds) |
|
|
72
|
+
| `resumeDelay` | `number` | `4000` | Time to resume autoplay after user interaction (milliseconds) |
|
|
73
|
+
| `breakpoints` | `MotionRailBreakpoint[]` | `[]` | Array of responsive breakpoint configurations |
|
|
74
|
+
|
|
75
|
+
### Breakpoint Configuration
|
|
76
|
+
|
|
77
|
+
Each breakpoint can specify:
|
|
78
|
+
|
|
79
|
+
| Property | Type | Description |
|
|
80
|
+
|----------|------|-------------|
|
|
81
|
+
| `width` | `number` (optional) | Maximum viewport width for this breakpoint |
|
|
82
|
+
| `columns` | `number` (optional) | Number of visible columns |
|
|
83
|
+
| `gap` | `string` (optional) | Gap between items (CSS value) |
|
|
84
|
+
|
|
85
|
+
**Important:** Breakpoints are applied mobile-first. Start with your default (no `width`), then add breakpoints with increasing `width` values.
|
|
86
|
+
|
|
87
|
+
**Example ordering:**
|
|
88
|
+
```js
|
|
89
|
+
breakpoints: [
|
|
90
|
+
{ columns: 1, gap: '12px' }, // Default (mobile)
|
|
91
|
+
{ width: 768, columns: 2, gap: '16px' }, // Tablets
|
|
92
|
+
{ width: 1024, columns: 3, gap: '20px' } // Desktop
|
|
93
|
+
]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## API Methods
|
|
97
|
+
|
|
98
|
+
### `play()`
|
|
99
|
+
Start autoplay scrolling.
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
carousel.play();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### `pause()`
|
|
106
|
+
Pause autoplay scrolling.
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
carousel.pause();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### `next()`
|
|
113
|
+
Navigate to the next page. Pauses autoplay.
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
carousel.next();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `prev()`
|
|
120
|
+
Navigate to the previous page. Pauses autoplay.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
carousel.prev();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `scrollToIndex(index: number)`
|
|
127
|
+
Scroll to a specific item by index. Pauses autoplay.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
carousel.scrollToIndex(2); // Scroll to the third item
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### `destroy()`
|
|
134
|
+
Clean up event listeners and timers.
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
carousel.destroy();
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Examples
|
|
141
|
+
|
|
142
|
+
### Basic Carousel
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
const carousel = new MotionRail(
|
|
146
|
+
document.getElementById('carousel'),
|
|
147
|
+
{
|
|
148
|
+
breakpoints: [
|
|
149
|
+
{ columns: 1, gap: '16px' }, // Mobile (default)
|
|
150
|
+
{ width: 768, columns: 2, gap: '16px' }, // Tablet
|
|
151
|
+
{ width: 1024, columns: 3, gap: '20px' } // Desktop
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Autoplay Carousel with RTL
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
const carousel = new MotionRail(
|
|
161
|
+
document.getElementById('carousel'),
|
|
162
|
+
{
|
|
163
|
+
autoplay: true,
|
|
164
|
+
rtl: true,
|
|
165
|
+
delay: 2500, // Auto-scroll every 2.5 seconds
|
|
166
|
+
resumeDelay: 4000, // Resume after 4 seconds of inactivity
|
|
167
|
+
breakpoints: [
|
|
168
|
+
{ columns: 1, gap: '16px' },
|
|
169
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
170
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Variable Columns (4 â 3 â 2 â 1)
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
const carousel = new MotionRail(
|
|
180
|
+
document.getElementById('carousel'),
|
|
181
|
+
{
|
|
182
|
+
breakpoints: [
|
|
183
|
+
{ columns: 1, gap: '12px' }, // < 480px
|
|
184
|
+
{ width: 480, columns: 2, gap: '16px' }, // 480px - 768px
|
|
185
|
+
{ width: 768, columns: 3, gap: '20px' }, // 768px - 1024px
|
|
186
|
+
{ width: 1024, columns: 4, gap: '24px' } // > 1024px
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Fixed Layout (No Responsiveness)
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
const carousel = new MotionRail(
|
|
196
|
+
document.getElementById('carousel'),
|
|
197
|
+
{
|
|
198
|
+
breakpoints: [
|
|
199
|
+
{ columns: 2, gap: '20px' } // Always 2 columns
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### With Navigation Controls
|
|
206
|
+
|
|
207
|
+
```html
|
|
208
|
+
<div class="motion-rail" id="carousel">
|
|
209
|
+
<div class="motion-rail-container">
|
|
210
|
+
<div class="motion-rail-item">Item 1</div>
|
|
211
|
+
<div class="motion-rail-item">Item 2</div>
|
|
212
|
+
<div class="motion-rail-item">Item 3</div>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
<div class="controls">
|
|
217
|
+
<button id="prev">Previous</button>
|
|
218
|
+
<button id="next">Next</button>
|
|
219
|
+
<button id="play">Play</button>
|
|
220
|
+
<button id="pause">Pause</button>
|
|
221
|
+
</div>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
const carousel = new MotionRail(
|
|
226
|
+
document.getElementById('carousel'),
|
|
227
|
+
{
|
|
228
|
+
autoplay: true,
|
|
229
|
+
breakpoints: [
|
|
230
|
+
{ columns: 1, gap: '16px' },
|
|
231
|
+
{ width: 768, columns: 2, gap: '16px' },
|
|
232
|
+
{ width: 1024, columns: 3, gap: '20px' }
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
document.getElementById('prev').addEventListener('click', () => carousel.prev());
|
|
238
|
+
document.getElementById('next').addEventListener('click', () => carousel.next());
|
|
239
|
+
document.getElementById('play').addEventListener('click', () => carousel.play());
|
|
240
|
+
document.getElementById('pause').addEventListener('click', () => carousel.pause());
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Styling
|
|
244
|
+
|
|
245
|
+
The library includes base styles via `motionrail/style.css`. You can customize the appearance of items with your own CSS:
|
|
246
|
+
|
|
247
|
+
```css
|
|
248
|
+
.motion-rail {
|
|
249
|
+
height: 400px; /* Set carousel height */
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.motion-rail-item {
|
|
253
|
+
/* Style your carousel items */
|
|
254
|
+
background: #f0f0f0;
|
|
255
|
+
border-radius: 8px;
|
|
256
|
+
padding: 20px;
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Browser Support
|
|
261
|
+
|
|
262
|
+
- Chrome/Edge (latest)
|
|
263
|
+
- Firefox (latest)
|
|
264
|
+
- Safari (latest)
|
|
265
|
+
- Modern mobile browsers
|
|
266
|
+
|
|
267
|
+
Requires support for:
|
|
268
|
+
- CSS Grid
|
|
269
|
+
- Pointer Events API
|
|
270
|
+
- Container Queries
|
|
271
|
+
- Scroll Snap
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "motionrail",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/motionrail.umd.cjs",
|
|
6
|
+
"module": "./dist/motionrail.js",
|
|
7
|
+
"types": "./dist/motionrail.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/motionrail.js",
|
|
11
|
+
"require": "./dist/motionrail.umd.cjs",
|
|
12
|
+
"types": "./dist/motionrail.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./style.css": "./dist/style.css"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite",
|
|
21
|
+
"build": "vite build && tsc",
|
|
22
|
+
"preview": "vite preview",
|
|
23
|
+
"prepare": "husky"
|
|
24
|
+
},
|
|
25
|
+
"lint-staged": {
|
|
26
|
+
"*.{ts,js,json,css,html}": [
|
|
27
|
+
"prettier --write"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^25.0.8",
|
|
32
|
+
"lint-staged": "^16.2.7",
|
|
33
|
+
"prettier": "^3.7.4",
|
|
34
|
+
"typescript": "~5.9.3",
|
|
35
|
+
"vite": "npm:rolldown-vite@7.2.5"
|
|
36
|
+
},
|
|
37
|
+
"overrides": {
|
|
38
|
+
"vite": "npm:rolldown-vite@7.2.5"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"husky": "^9.1.7"
|
|
42
|
+
}
|
|
43
|
+
}
|