@hilux/ngx-motion 2.0.0 → 2.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/README.md CHANGED
@@ -49,6 +49,11 @@ export class CardComponent {}
49
49
  - **Gestures:** `whileHover`, `whileTap` and `whileFocus` animate in and spring back out.
50
50
  - **Stagger orchestration:** `staggerChildren`, `delayChildren` and `staggerDirection`. Nested parents orchestrate their own children.
51
51
  - **Scroll / in-view:** `runInView="once"` or `"always"`, and `whileInView`.
52
+ - **Scroll-linked values:** `[motionScroll]` maps scroll progress to styles (parallax, progress bars, pinned sections) and exposes `progress()` and `velocity()` signals.
53
+ - **Pointer motion:** `motionMagnetic`, `motionTilt` and `motionFollowPointer` for magnetic buttons, 3D tilt cards and cursor followers, on springs.
54
+ - **Drag:** `motionDrag` with constraints, elastic edges, momentum and snap points (carousels, sliders, card stacks).
55
+ - **Pan and swipe:** `motionPan` reports pointer movement and swipe directions, with `whilePan` styles.
56
+ - **Reorder:** `motionReorderGroup` and `motionReorderItem` for drag-to-reorder lists, with keyboard support.
52
57
  - **Exit animations:** `*motionIf` and `*motionPresence` keep elements in the DOM until their exit animation finishes. If shown again mid-exit, they animate back in.
53
58
  - **Variants:** named, reusable animation states.
54
59
  - **Timelines:** sequence several steps on one element.
@@ -186,6 +191,143 @@ export class TimelineExample {
186
191
  }
187
192
  ```
188
193
 
194
+ ### Scroll-Linked Values
195
+ `motionScroll` spreads style keyframes across a scroll range, like Framer Motion's `useScroll` + `useTransform`. The keyframes run as a scroll-driven animation (the browser's ScrollTimeline where available), so scrolling never triggers change detection.
196
+
197
+ ```typescript
198
+ import { MotionScrollDirective, SCROLL_THROUGH } from '@hilux/ngx-motion';
199
+
200
+ @Component({
201
+ imports: [MotionScrollDirective],
202
+ template: `
203
+ <!-- Page progress bar -->
204
+ <div class="bar" [motionScroll]="{ scaleX: [0, 1] }" scrollTarget="container"></div>
205
+
206
+ <!-- Parallax: rises 120px and fades while it crosses the viewport -->
207
+ <img src="hero.png" [motionScroll]="{ y: [0, -120], opacity: [1, 0] }">
208
+
209
+ <!-- Pinned section: read progress as a signal -->
210
+ <section motionScroll #story="motionScroll" [scrollOffset]="through" style="height: 300vh">
211
+ <div style="position: sticky; top: 0">{{ story.progress() | percent }}</div>
212
+ </section>
213
+ `
214
+ })
215
+ export class ScrollExample {
216
+ through = SCROLL_THROUGH; // ['start start', 'end end']
217
+ }
218
+ ```
219
+
220
+ | Input | Default | |
221
+ |---|---|---|
222
+ | `motionScroll` | none | Keyframes per style, e.g. `{ y: [0, -100] }`. Leave empty to only track progress. |
223
+ | `scrollTarget` | `'self'` | Element to track, or `'container'` for the whole scroll container. |
224
+ | `scrollContainer` | `'auto'` | Nearest scrollable ancestor, `'page'`, or an element. A scrolling ancestor must be positioned (`position: relative`). |
225
+ | `scrollOffset` | `['start end', 'end start']` | Start and end of the range, in Motion's offset syntax. |
226
+ | `scrollAxis` | `'y'` | `'x'` for horizontal scrollers. |
227
+ | `scrollTransition` | none | Extra options for the keyframes, e.g. `{ times: [0, 0.3, 1] }` or `{ ease: 'easeOut' }`. |
228
+ | `respectReducedMotion` | `true` | With reduced motion the keyframes are not applied. Progress is still tracked. |
229
+
230
+ `progress()` (0 to 1) and `velocity()` (px/s) are signals on the directive (`exportAs: 'motionScroll'`). Reading them in a template re-renders that view as you scroll, so keep those reads small.
231
+
232
+ ### Pointer Motion
233
+ Springs that react to the pointer. Each moves the element with `x` / `y` / `rotate`, so it composes with `whileHover` and `whileTap`. Touch input is ignored, and with `prefers-reduced-motion` they stay still.
234
+
235
+ ```html
236
+ <!-- Leans toward the pointer (0 to 1; default 0.3), springs back when it leaves -->
237
+ <button motionMagnetic>Get started</button>
238
+
239
+ <!-- Tilts in 3D toward the pointer (max degrees; default 10) -->
240
+ <article class="card" [motionTilt]="12">…</article>
241
+
242
+ <!-- Follows the pointer around its parent; scales in on enter, out on leave -->
243
+ <section style="position: relative">
244
+ <div class="glow" motionFollowPointer></div>
245
+ </section>
246
+ ```
247
+
248
+ `motionTilt` also sets `--motion-pointer-x` / `--motion-pointer-y` (0% to 100%) on the element, for a glare in CSS:
249
+
250
+ ```css
251
+ .card::after { background: radial-gradient(circle at var(--motion-pointer-x) var(--motion-pointer-y), #fff3, transparent 50%); }
252
+ ```
253
+
254
+ | Directive | Inputs |
255
+ |---|---|
256
+ | `motionMagnetic` | strength (0 to 1), `magneticRadius` (px of extra reach, 24), `magneticTransition` |
257
+ | `motionTilt` | max degrees, `tiltScale` (1.02), `tiltPerspective` (900), `tiltTransition` |
258
+ | `motionFollowPointer` | `'parent'` (default), `'window'` or an element; `followTransition`; `followHide` (true) |
259
+
260
+ Each exposes signals: `active()` (magnetic, follow) and `hovering()` (tilt).
261
+
262
+ ### Drag
263
+ `motionDrag` makes an element draggable, like Framer Motion's `drag` prop.
264
+
265
+ ```html
266
+ <!-- Free drag -->
267
+ <div motionDrag>Drag me</div>
268
+
269
+ <!-- A track that can't be dragged past the edges of its window -->
270
+ <div class="window"><div class="track" motionDrag="x" dragConstraints="parent">…</div></div>
271
+
272
+ <!-- A carousel that snaps to slides; buttons call moveTo() -->
273
+ <div class="track" motionDrag="x" [dragSnap]="{ x: [0, -320, -640] }" #drag="motionDrag" (dragEnd)="onEnd($event)">…</div>
274
+ <button (click)="drag.moveTo(-320)">Next</button>
275
+ ```
276
+
277
+ | Input | Default | What it does |
278
+ |---|---|---|
279
+ | `motionDrag` | both | Axis: `'x'`, `'y'` or both |
280
+ | `dragConstraints` | none | `'parent'`, an element, or `{ top, right, bottom, left }` px from the resting position |
281
+ | `dragElastic` | 0.35 | How far it stretches past the constraints (0 to 1) |
282
+ | `dragMomentum` | true | Glide on after release in the direction it was thrown |
283
+ | `dragSnap` | none | `{ x: [...], y: [...] }`: settle on the point nearest where it was heading |
284
+ | `dragTransition` | spring | Spring for settling and `moveTo()` |
285
+ | `dragThreshold` | 3 | Pixels to move before a drag starts, so clicks inside still work |
286
+
287
+ Outputs: `dragStart`, `dragMove` and `dragEnd`, each with `{ x, y, offset, velocity }`. Signals: `x()`, `y()`, `dragging()`. Method: `moveTo(x, y?)`.
288
+
289
+ The click that ends a drag is swallowed, so links inside a draggable don't open by accident. It sets `touch-action` for the axis (dragging along x still lets the page scroll vertically on touch screens). Don't give the dragged element a CSS transform of its own; wrap it instead.
290
+
291
+ ### Pan and Swipe
292
+ `motionPan` reports pointer movement without moving the element, like Framer Motion's `onPan` and `whilePan`. Use it to drive your own effects, or for swipe gestures.
293
+
294
+ ```html
295
+ <!-- Pan: offset, delta, velocity and point -->
296
+ <div motionPan [whilePan]="{ scale: 0.97 }" (pan)="offset.set($event.offset)" (panEnd)="offset.set({ x: 0, y: 0 })">…</div>
297
+
298
+ <!-- Swipe: fires on release with 'left' | 'right' | 'up' | 'down' -->
299
+ <div motionPan="x" (swipe)="$event.direction === 'left' ? next() : prev()">…</div>
300
+ ```
301
+
302
+ | Input | Default | What it does |
303
+ |---|---|---|
304
+ | `motionPan` | both | Axis: `'x'`, `'y'` or both. One axis lets the other scroll on touch screens |
305
+ | `whilePan` | none | Styles while panning. On release, transforms return to neutral and other styles to what they were |
306
+ | `panThreshold` | 3 | Pixels to move before a pan starts, so clicks inside still work |
307
+ | `swipeDistance` | 50 | A pan this long along its main axis is a swipe |
308
+ | `swipeVelocity` | 500 | A flick this fast (px/s) is a swipe, even if short |
309
+
310
+ Outputs: `panStart`, `pan`, `panEnd` (each `{ point, delta, offset, velocity }`) and `swipe` (the same plus `direction`). Signal: `panning()`. The element gets the `motion-panning` class while panning.
311
+
312
+ ### Reorder
313
+ Drag-to-reorder lists, like Framer Motion's `Reorder.Group` and `Reorder.Item`. The order is two-way bound, so your array updates as you drag, and the other items glide into their new places.
314
+
315
+ ```html
316
+ <ul [(motionReorderGroup)]="tasks" (reorderEnd)="save($event)">
317
+ @for (task of tasks(); track task) {
318
+ <li [motionReorderItem]="task" tabindex="0">{{ task }}</li>
319
+ }
320
+ </ul>
321
+
322
+ <!-- Horizontal -->
323
+ <div [(motionReorderGroup)]="colors" reorderAxis="x">…</div>
324
+ ```
325
+
326
+ - `motionReorderGroup`: the values in order (a signal, bound with `[( )]`), `reorderAxis` (`'y'` by default), `reorderTransition` (the spring the others move on) and `reorderEnd` (the order after a drag or key move).
327
+ - `motionReorderItem`: the item's value. It drags along the group's axis and springs into its slot on release. It accepts `dragTransition` and `dragDisabled`, and emits `dragStart`, `dragMove` and `dragEnd`.
328
+ - Keyboard: on a focused item (give it `tabindex="0"`), Alt + arrow keys move it one place.
329
+ - Track items by identity in `@for` (not `$index`) so elements move with their values. Items can be different sizes.
330
+
189
331
  ## Angular Control Flow Integration
190
332
 
191
333
  Angular's control flow (`@if`, `@for`, etc.) removes elements immediately from the DOM when conditions change. To support exit animations, `@hilux/ngx-motion` provides structural directives that manage the animation lifecycle.
@@ -274,6 +416,24 @@ The directives work seamlessly with Angular's new control flow syntax:
274
416
  | `variants` + `staggerChildren` | `[variants]` + `[transition]="{ staggerChildren }"` |
275
417
  | `transition={{ type: 'spring' }}` | `[transition]="{ type: 'spring' }"` |
276
418
  | `<AnimatePresence>` | `*motionIf` or `*motionPresence` |
419
+ | `useScroll` + `useTransform` | `[motionScroll]` |
420
+ | `drag`, `dragConstraints`, `dragElastic`, `dragMomentum` | `motionDrag`, `dragConstraints`, `dragElastic`, `dragMomentum` |
421
+ | `onPan`, `whilePan` | `motionPan` with `(pan)`, `[whilePan]` |
422
+ | `<Reorder.Group values onReorder>` / `<Reorder.Item value>` | `[(motionReorderGroup)]` / `[motionReorderItem]` |
423
+
424
+ ## Changelog
425
+
426
+ **2.1.0**
427
+ - New `motionPan` directive: pan events with offset, delta and velocity, `whilePan` styles, and `swipe` with a direction. See [Pan and Swipe](#pan-and-swipe).
428
+ - New drag-to-reorder lists: `motionReorderGroup` and `motionReorderItem`, with two-way bound order and keyboard support. See [Reorder](#reorder).
429
+ - New pointer directives: `motionMagnetic`, `motionTilt` and `motionFollowPointer`. See [Pointer Motion](#pointer-motion).
430
+ - New `motionDrag` directive: drag with constraints, elastic edges, momentum, snap points, `moveTo()` and `rebase()`. See [Drag](#drag).
431
+ - New `motionScroll` directive for scroll-linked values: keyframes mapped to scroll progress, plus `progress()` and `velocity()` signals. See [Scroll-Linked Values](#scroll-linked-values).
432
+ - A `runInView` element nested inside another motion parent now plays its own children when it scrolls into view. Before, only the element itself animated (so, for example, split-text letters inside an in-view group never appeared).
433
+
434
+ **2.0.1**
435
+ - `delayChildren` set inside `[transition]` is now honoured, as in Framer Motion. Before, only the `[delayChildren]` input was read.
436
+ - A `runInView` parent now orchestrates its children fully when it scrolls into view: stagger slots, `delayChildren`, each child's own `delay`, and nested children. Before, its direct children animated flat, grandchildren never played, and an in-view child inside it never played.
277
437
 
278
438
  ## Upgrading from 1.x
279
439
 
@@ -396,7 +556,7 @@ No. Animations, timers and gesture listeners run outside Angular's zone.
396
556
  Put `motionone` on each `@for` item for enter animations. Wrap items in `*motionPresence` (or `*motionIf`) to animate them out before they are removed. See the [Dynamic List example](https://rikisommers.github.io/angular-motion-poc/examples/dynamic-list).
397
557
 
398
558
  ### How do I animate on scroll?
399
- Add `runInView="once"` to play `animate` the first time the element scrolls into view. Use `runInView="always"` to reset it when it leaves and replay it when it returns. See the [Run In View example](https://rikisommers.github.io/angular-motion-poc/examples/in-view).
559
+ Add `runInView="once"` to play `animate` the first time the element scrolls into view. Use `runInView="always"` to reset it when it leaves and replay it when it returns. See the [Run In View example](https://rikisommers.github.io/angular-motion-poc/examples/in-view). To tie styles to the scroll position itself (parallax, progress bars, pinned sections), use [`motionScroll`](#scroll-linked-values).
400
560
 
401
561
  ## Project Structure
402
562