@hilux/ngx-motion 2.3.0 → 2.5.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 +93 -0
- package/fesm2022/hilux-ngx-motion.mjs +416 -5
- package/fesm2022/hilux-ngx-motion.mjs.map +1 -1
- package/package.json +1 -1
- package/types/hilux-ngx-motion.d.ts +148 -1
package/README.md
CHANGED
|
@@ -54,6 +54,8 @@ export class CardComponent {}
|
|
|
54
54
|
- **Drag:** `motionDrag` with constraints, elastic edges, momentum and snap points (carousels, sliders, card stacks).
|
|
55
55
|
- **Pan and swipe:** `motionPan` reports pointer movement and swipe directions, with `whilePan` styles.
|
|
56
56
|
- **Reorder:** `motionReorderGroup` and `motionReorderItem` for drag-to-reorder lists, with keyboard support.
|
|
57
|
+
- **Motion values:** `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal` and `scrollSignal`: values that change every frame, as Angular signals, bound to styles with `[motionStyle]` without change detection.
|
|
58
|
+
- **SVG line drawing:** `pathLength`, `pathOffset` and `pathSpacing` on any SVG shape, with every trigger (enter, hover, in view, scroll, `[motionStyle]`).
|
|
57
59
|
- **Layout animations:** `motionLayout` glides elements to their new place and size after any layout change, and `motionLayoutId` makes shared-element transitions.
|
|
58
60
|
- **Exit animations:** `*motionIf` and `*motionPresence` keep elements in the DOM until their exit animation finishes. If shown again mid-exit, they animate back in.
|
|
59
61
|
- **Variants:** named, reusable animation states.
|
|
@@ -329,6 +331,82 @@ Drag-to-reorder lists, like Framer Motion's `Reorder.Group` and `Reorder.Item`.
|
|
|
329
331
|
- Keyboard: on a focused item (give it `tabindex="0"`), Alt + arrow keys move it one place.
|
|
330
332
|
- Track items by identity in `@for` (not `$index`) so elements move with their values. Items can be different sizes.
|
|
331
333
|
|
|
334
|
+
### Motion Values
|
|
335
|
+
Values that change every frame, like Framer Motion's `useMotionValue`, `useTransform`, `useSpring`, `useVelocity` and `useScroll`, as Angular signals. Read one in a template like any signal, or bind it with `[motionStyle]`: the directive writes each change straight to the element, so nothing re-renders while it moves.
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
import { MotionStyleDirective, mapSignal, motionSignal, scrollSignal, springSignal, velocitySignal } from '@hilux/ngx-motion';
|
|
339
|
+
|
|
340
|
+
@Component({
|
|
341
|
+
imports: [MotionStyleDirective, MotionPanDirective],
|
|
342
|
+
template: `
|
|
343
|
+
<div motionPan="x" (pan)="drag.set($event.offset.x)" (panEnd)="drag.set(0)"
|
|
344
|
+
[motionStyle]="{ x: x, backgroundColor: colour }">{{ label() }}</div>
|
|
345
|
+
<div class="bar" [motionStyle]="{ scaleX: scroll.progress, skewY: skew }"></div>
|
|
346
|
+
`,
|
|
347
|
+
})
|
|
348
|
+
export class Example {
|
|
349
|
+
readonly drag = motionSignal(0); // useMotionValue
|
|
350
|
+
readonly x = springSignal(this.drag, { stiffness: 500, damping: 40 }); // useSpring: follows drag
|
|
351
|
+
readonly colour = mapSignal(this.x, [-140, 0, 140], ['#f87171', '#3a3a3a', '#86efac']); // useTransform
|
|
352
|
+
readonly label = mapSignal(this.x, v => `${Math.round(v)}px`);
|
|
353
|
+
readonly scroll = scrollSignal(); // useScroll: progress, offset, velocity
|
|
354
|
+
readonly skew = mapSignal(velocitySignal(this.scroll.offset), [-3000, 3000], [-10, 10]); // useVelocity
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
| Function | What it gives you |
|
|
359
|
+
|---|---|
|
|
360
|
+
| `motionSignal(initial)` | A writable value: `x()` (tracked), `x.get()` (untracked), `x.set(v)`, `x.on(fn)` (every change, outside change detection), `x.getVelocity()` |
|
|
361
|
+
| `mapSignal(source, [in], [out], { clamp, ease })` | Maps a range to another: numbers, colours, or strings with units. Clamped by default |
|
|
362
|
+
| `mapSignal(source, fn)` / `mapSignal([a, b], fn)` | Any function of one or more values |
|
|
363
|
+
| `springSignal(target \| source, { stiffness, damping, mass })` | Springs to `set()` targets, or follows a source; keeps its speed when the target changes. `jump(v)` skips the spring |
|
|
364
|
+
| `velocitySignal(source)` | Speed per second; back to 0 when the source stops |
|
|
365
|
+
| `scrollSignal({ container, target, offset, axis })` | `progress` (0 to 1), `offset` (px) and `velocity` for the page or an element; `container` and `target` can be `viewChild` signals |
|
|
366
|
+
|
|
367
|
+
- Sources can be motion signals or any Angular signal (those update with change detection).
|
|
368
|
+
- `springSignal`, `velocitySignal` and `scrollSignal` must be created in an injection context (a field or the constructor), or given `{ injector }`. They clean up when it's destroyed.
|
|
369
|
+
- `[motionStyle]`: transform shortcuts `x`, `y`, `z` (px), `scale`, `scaleX`, `scaleY`, `rotate`, `rotateX/Y/Z`, `skewX/Y` (deg) are combined into `transform`, so don't animate the same element's transform another way. Other styles use camelCase names; numbers get px except unitless ones such as `opacity`. CSS custom properties (`'--progress'`) take any value.
|
|
370
|
+
- With reduced motion, and on the server, springs go straight to their target.
|
|
371
|
+
|
|
372
|
+
### SVG Line Drawing
|
|
373
|
+
Like Framer Motion's `pathLength`. Animate how much of a line is drawn, from 0 to 1, on any SVG shape: `path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`. It works with every trigger.
|
|
374
|
+
|
|
375
|
+
A simple hover draw is fine in plain CSS: give the shape `pathLength="1"`, set `stroke-dasharray: 1; stroke-dashoffset: 1` and transition `stroke-dashoffset`. Use ngx-motion when a line should draw when it scrolls into view, one part after another, as the page scrolls (in every browser), on exit, follow a value on a spring, or spring and loop on hover and settle smoothly when the pointer leaves (a CSS loop snaps back).
|
|
376
|
+
|
|
377
|
+
```html
|
|
378
|
+
<!-- Draws when scrolled into view, one part after another -->
|
|
379
|
+
<svg viewBox="0 0 100 100" fill="none" stroke="currentColor" stroke-width="6"
|
|
380
|
+
motionone runInView="once" [staggerChildren]="0.12" [initial]="{}" [animate]="{}">
|
|
381
|
+
<circle cx="50" cy="50" r="42"
|
|
382
|
+
motionone [initial]="{ pathLength: 0 }" [animate]="{ pathLength: 1 }" />
|
|
383
|
+
<path d="M30 52 L45 66 L72 36"
|
|
384
|
+
motionone [initial]="{ pathLength: 0 }" [animate]="{ pathLength: 1 }" />
|
|
385
|
+
</svg>
|
|
386
|
+
|
|
387
|
+
<!-- Draws as the page scrolls -->
|
|
388
|
+
<path d="…" [motionScroll]="{ pathLength: [0, 1] }" />
|
|
389
|
+
|
|
390
|
+
<!-- On hover: draws in and runs off the end, round and round; on leave it finishes forward -->
|
|
391
|
+
<path d="…" motionone
|
|
392
|
+
[initial]="{ pathLength: 0, pathOffset: 1 }"
|
|
393
|
+
[whileHover]="{ pathLength: [0, 1, 0], pathOffset: [0, 0, 1], transition: { duration: 1.6, repeat: Infinity } }" />
|
|
394
|
+
|
|
395
|
+
<!-- A dash running round a circle: dash 0.25 + gap 0.75 = 1, so it loops seamlessly -->
|
|
396
|
+
<circle cx="50" cy="50" r="40"
|
|
397
|
+
motionone [initial]="{ pathLength: 0.25, pathSpacing: 0.75, pathOffset: 0 }" [animate]="{ pathOffset: 1 }"
|
|
398
|
+
[transition]="{ duration: 1.2, ease: 'linear', repeat: Infinity }" />
|
|
399
|
+
|
|
400
|
+
<!-- Or follow a value on a spring (a gauge) -->
|
|
401
|
+
<path d="…" [motionStyle]="{ pathLength: length }" />
|
|
402
|
+
<!-- readonly length = mapSignal(springSignal(this.value), [0, 100], [0, 1]); -->
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
- `pathLength`: how much is drawn (0 to 1). `pathOffset`: where the drawn part starts. `pathSpacing`: the gap after each drawn part (default 1).
|
|
406
|
+
- They are fractions of the shape's own length: the shape gets `pathLength="1"`, and `stroke-dasharray` / `stroke-dashoffset` are set for you.
|
|
407
|
+
- With round or square line caps a line at `pathLength: 0` still shows a dot, so fade it in too (`opacity: 0` → `1`).
|
|
408
|
+
- Animating only `pathOffset` or `pathSpacing` keeps the dash length it had.
|
|
409
|
+
|
|
332
410
|
### Layout Animations
|
|
333
411
|
Like Framer Motion's `layout` and `layoutId`. Change the layout however you like (reorder or filter a list, switch flex to grid, toggle a class) and `motionLayout` animates each element from where it was drawn to where it is now. No positions to calculate.
|
|
334
412
|
|
|
@@ -463,6 +541,9 @@ The directives work seamlessly with Angular's new control flow syntax:
|
|
|
463
541
|
| `drag`, `dragConstraints`, `dragElastic`, `dragMomentum` | `motionDrag`, `dragConstraints`, `dragElastic`, `dragMomentum` |
|
|
464
542
|
| `onPan`, `whilePan` | `motionPan` with `(pan)`, `[whilePan]` |
|
|
465
543
|
| `<Reorder.Group values onReorder>` / `<Reorder.Item value>` | `[(motionReorderGroup)]` / `[motionReorderItem]` |
|
|
544
|
+
| `useMotionValue`, `useTransform`, `useSpring`, `useVelocity`, `useScroll` | `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal`, `scrollSignal` |
|
|
545
|
+
| `style={{ x, opacity }}` with motion values | `[motionStyle]="{ x: x, opacity: opacity }"` |
|
|
546
|
+
| `pathLength`, `pathOffset`, `pathSpacing` | the same keys in `[initial]`, `[animate]`, `[whileHover]`, `[motionScroll]`, `[motionStyle]` |
|
|
466
547
|
| `layout`, `layout="position"` | `motionLayout`, `motionLayout="position"` |
|
|
467
548
|
| `layoutId` | `motionLayoutId` |
|
|
468
549
|
| `<LayoutGroup>` | not needed: every layout element is measured after every render |
|
|
@@ -482,6 +563,7 @@ A lot of animation is plain CSS now, and where CSS is enough it is the better ch
|
|
|
482
563
|
| Sequences | ⚠️ Percentages in one `@keyframes`; several elements need hand-tuned delays | Timelines, `repeat` with `mirror` / `reverse`, per-property transitions |
|
|
483
564
|
| Play once when scrolled into view | ❌ No trigger yet (`animation-trigger` is experimental); needs IntersectionObserver | `runInView`, `whileInView` |
|
|
484
565
|
| Scroll-linked values | ✅ / ⚠️ `animation-timeline: scroll()` / `view()` in Chrome and Safari 26, not in Firefox by default | Same API everywhere (uses the native timeline where available), plus `progress()` and `velocity()` signals |
|
|
566
|
+
| SVG line drawing | ✅ / ⚠️ `pathLength="1"` plus a `stroke-dashoffset` transition or `@keyframes` covers simple hover, enter and looping spinners; no springs, a loop snaps back when hover ends, no in-view trigger, scroll-linked only with scroll timelines | Hover that springs or loops and settles on leave; draw when scrolled into view, staggered; scroll-linked in every browser; undraw on exit; follow a value on a spring |
|
|
485
567
|
| Magnetic, tilt, follow-pointer | ❌ CSS can't read the pointer position | `motionMagnetic`, `motionTilt` (sets `--motion-pointer-x/y` for CSS), `motionFollowPointer` |
|
|
486
568
|
| Drag | ❌ | Constraints, elastic edges, momentum, snap points |
|
|
487
569
|
| Pan and swipe | ❌ Only `touch-action` and scroll snap | Offset, delta, velocity and swipe direction |
|
|
@@ -495,6 +577,15 @@ A lot of animation is plain CSS now, and where CSS is enough it is the better ch
|
|
|
495
577
|
|
|
496
578
|
## Changelog
|
|
497
579
|
|
|
580
|
+
**2.5.0**
|
|
581
|
+
- SVG line drawing: `pathLength`, `pathOffset` and `pathSpacing` on any SVG shape, in every state (`initial`, `animate`, `whileHover`, `whileInView`, `exit`), in `[motionScroll]` and in `[motionStyle]`. See [SVG Line Drawing](#svg-line-drawing).
|
|
582
|
+
- Fixed: SVG shapes (path, circle…) with styles in `initial`, such as `opacity: 0`, stayed at those values. The starting values are now written as attributes, which is how Motion animates SVG, so the animation shows.
|
|
583
|
+
- Fixed: Motion's easing names (`'linear'`, `'easeOut'`, `'backOut'`, `'anticipate'`…) and easing functions were replaced by ease-in-out. They are now passed to Motion as given.
|
|
584
|
+
- Fixed: `springSignal` following a value that changes every frame (pointer, drag) no longer jitters: the spring keeps its position and speed, and only its target moves.
|
|
585
|
+
|
|
586
|
+
**2.4.0**
|
|
587
|
+
- Motion values as Angular signals: `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal` and `scrollSignal`, and the `[motionStyle]` directive, which writes them to the element without change detection. See [Motion Values](#motion-values).
|
|
588
|
+
|
|
498
589
|
**2.3.0**
|
|
499
590
|
- Shared layout elements that stay mounted: while two elements with the same `motionLayoutId` are mounted, the newer one is shown and the older hidden, and when the newer one is removed the older one flies back from it (thumbnail and lightbox).
|
|
500
591
|
- Layout animations keep corner radii round while scaling, and add the class `motion-layout-animating` while an element moves.
|
|
@@ -607,6 +698,8 @@ interface TransitionOptions {
|
|
|
607
698
|
- `'ease-in'` - CSS ease-in
|
|
608
699
|
- `'ease-out'` - CSS ease-out
|
|
609
700
|
- `'ease-in-out'` - CSS ease-in-out
|
|
701
|
+
- `'linear'`, `'easeIn'`, `'easeOut'`, `'easeInOut'`, `'circIn'`, `'circOut'`, `'circInOut'`, `'backIn'`, `'backOut'`, `'backInOut'`, `'anticipate'` - Motion's named easings
|
|
702
|
+
- `(t) => number` - An easing function
|
|
610
703
|
- `[0.4, 0, 0.2, 1]` - Custom cubic bezier
|
|
611
704
|
- `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
|
|
612
705
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { ChangeDetectorRef, DOCUMENT, DestroyRef, Directive, ElementRef, EventEmitter, HostListener, Inject, Injectable, Injector, Input, NgZone, Output, PLATFORM_ID, TemplateRef, ViewContainerRef, afterEveryRender, afterNextRender, afterRenderEffect, effect, forwardRef, inject, input, isDevMode, model, output, signal, untracked } from "@angular/core";
|
|
2
|
+
import { ChangeDetectorRef, DOCUMENT, DestroyRef, Directive, ElementRef, EventEmitter, HostListener, Inject, Injectable, Injector, Input, NgZone, Output, PLATFORM_ID, TemplateRef, ViewContainerRef, afterEveryRender, afterNextRender, afterRenderEffect, assertInInjectionContext, effect, forwardRef, inject, input, isDevMode, isSignal, model, output, signal, untracked } from "@angular/core";
|
|
3
3
|
import { isPlatformBrowser } from "@angular/common";
|
|
4
4
|
import { Subject, timer } from "rxjs";
|
|
5
5
|
import { map, take } from "rxjs/operators";
|
|
6
|
-
import { animate, easeIn, easeInOut, easeOut, inView, scroll, spring, stagger } from "motion";
|
|
6
|
+
import { animate, easeIn, easeInOut, easeOut, inView, scroll, spring, stagger, transform } from "motion";
|
|
7
7
|
var MotionOneService = class MotionOneService {
|
|
8
8
|
document;
|
|
9
9
|
platformId;
|
|
@@ -227,6 +227,69 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
227
227
|
{ type: NgZone }
|
|
228
228
|
]
|
|
229
229
|
});
|
|
230
|
+
const SVG_PATH_KEYS = /* @__PURE__ */ new Set([
|
|
231
|
+
"pathLength",
|
|
232
|
+
"pathOffset",
|
|
233
|
+
"pathSpacing"
|
|
234
|
+
]);
|
|
235
|
+
function isSvgPathKey(key) {
|
|
236
|
+
return SVG_PATH_KEYS.has(key);
|
|
237
|
+
}
|
|
238
|
+
function readSvgPath(el) {
|
|
239
|
+
if (!el.hasAttribute("pathLength")) return {};
|
|
240
|
+
const out = {};
|
|
241
|
+
const dash = el.getAttribute("stroke-dasharray")?.trim().split(/[\s,]+/).map(parseFloat);
|
|
242
|
+
if (dash && !isNaN(dash[0])) {
|
|
243
|
+
out.pathLength = dash[0];
|
|
244
|
+
if (dash.length > 1 && !isNaN(dash[1]) && dash[1] !== 1) out.pathSpacing = dash[1];
|
|
245
|
+
}
|
|
246
|
+
const offset = parseFloat(el.getAttribute("stroke-dashoffset") ?? "");
|
|
247
|
+
if (!isNaN(offset) && offset !== 0) out.pathOffset = -offset;
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
function applySvgPath(el, values) {
|
|
251
|
+
if (typeof SVGElement === "undefined" || !(el instanceof SVGElement)) return;
|
|
252
|
+
const current = readSvgPath(el);
|
|
253
|
+
for (const key of SVG_PATH_KEYS) {
|
|
254
|
+
if (!(key in values)) continue;
|
|
255
|
+
const v = values[key];
|
|
256
|
+
current[key] = v == null || v === "" ? void 0 : Number(v);
|
|
257
|
+
}
|
|
258
|
+
if (current.pathLength === void 0 && current.pathOffset === void 0 && current.pathSpacing === void 0) {
|
|
259
|
+
el.removeAttribute("pathLength");
|
|
260
|
+
el.removeAttribute("stroke-dasharray");
|
|
261
|
+
el.removeAttribute("stroke-dashoffset");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
el.setAttribute("pathLength", "1");
|
|
265
|
+
el.setAttribute("stroke-dasharray", `${current.pathLength ?? 1} ${current.pathSpacing ?? 1}`);
|
|
266
|
+
el.setAttribute("stroke-dashoffset", `${-(current.pathOffset ?? 0)}`);
|
|
267
|
+
}
|
|
268
|
+
function withSvgPathContext(target, keyframes) {
|
|
269
|
+
if (typeof SVGElement === "undefined" || !(target instanceof SVGElement) || !keyframes || typeof keyframes !== "object") return keyframes;
|
|
270
|
+
if (!Object.keys(keyframes).some(isSvgPathKey)) return keyframes;
|
|
271
|
+
const current = readSvgPath(target);
|
|
272
|
+
const out = { ...keyframes };
|
|
273
|
+
const defaults = {
|
|
274
|
+
pathLength: 1,
|
|
275
|
+
pathOffset: 0,
|
|
276
|
+
pathSpacing: 1
|
|
277
|
+
};
|
|
278
|
+
for (const key of SVG_PATH_KEYS) {
|
|
279
|
+
const v = out[key];
|
|
280
|
+
if (v === void 0 || Array.isArray(v)) continue;
|
|
281
|
+
const k = key;
|
|
282
|
+
out[key] = [current[k] ?? defaults[k], v];
|
|
283
|
+
}
|
|
284
|
+
const hold = (key, fallback) => {
|
|
285
|
+
const v = current[key] ?? fallback;
|
|
286
|
+
if (!(key in out) && v !== void 0) out[key] = [v, v];
|
|
287
|
+
};
|
|
288
|
+
hold("pathLength", 1);
|
|
289
|
+
hold("pathSpacing");
|
|
290
|
+
hold("pathOffset");
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
230
293
|
const noopControls = () => ({ stop: () => {} });
|
|
231
294
|
const linear = (t) => t;
|
|
232
295
|
var MotionAnimationService = class MotionAnimationService {
|
|
@@ -236,7 +299,7 @@ var MotionAnimationService = class MotionAnimationService {
|
|
|
236
299
|
animate(target, keyframes, options) {
|
|
237
300
|
if (!this.isBrowser) return noopControls();
|
|
238
301
|
try {
|
|
239
|
-
return this.ngZone.runOutsideAngular(() => animate(target, keyframes, options));
|
|
302
|
+
return this.ngZone.runOutsideAngular(() => animate(target, withSvgPathContext(target, keyframes), options));
|
|
240
303
|
} catch (e) {
|
|
241
304
|
console.error("[ngx-motion] Error in animate:", e);
|
|
242
305
|
return noopControls();
|
|
@@ -303,6 +366,19 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
303
366
|
args: [{ providedIn: "root" }]
|
|
304
367
|
}]
|
|
305
368
|
});
|
|
369
|
+
const MOTION_EASINGS = /* @__PURE__ */ new Set([
|
|
370
|
+
"linear",
|
|
371
|
+
"easeIn",
|
|
372
|
+
"easeOut",
|
|
373
|
+
"easeInOut",
|
|
374
|
+
"circIn",
|
|
375
|
+
"circOut",
|
|
376
|
+
"circInOut",
|
|
377
|
+
"backIn",
|
|
378
|
+
"backOut",
|
|
379
|
+
"backInOut",
|
|
380
|
+
"anticipate"
|
|
381
|
+
]);
|
|
306
382
|
function getEasing(easingString, motionAnimation) {
|
|
307
383
|
if (!easingString) return motionAnimation.easeInOut;
|
|
308
384
|
if (Array.isArray(easingString)) return easingString;
|
|
@@ -310,11 +386,13 @@ function getEasing(easingString, motionAnimation) {
|
|
|
310
386
|
stiffness: easingString.stiffness || 100,
|
|
311
387
|
damping: easingString.damping || 10
|
|
312
388
|
});
|
|
389
|
+
if (typeof easingString === "function") return easingString;
|
|
313
390
|
if (typeof easingString === "string") {
|
|
314
391
|
if (easingString === "ease-in") return motionAnimation.easeIn;
|
|
315
392
|
if (easingString === "ease-out") return motionAnimation.easeOut;
|
|
316
393
|
if (easingString === "ease-in-out" || easingString === "ease") return motionAnimation.easeInOut;
|
|
317
394
|
if (easingString === "spring") return motionAnimation.spring();
|
|
395
|
+
if (MOTION_EASINGS.has(easingString)) return easingString;
|
|
318
396
|
}
|
|
319
397
|
return motionAnimation.easeInOut;
|
|
320
398
|
}
|
|
@@ -909,6 +987,7 @@ function transformFunction(key, value) {
|
|
|
909
987
|
default: return `${key}(${v})`;
|
|
910
988
|
}
|
|
911
989
|
}
|
|
990
|
+
const kebab = (key) => key.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase());
|
|
912
991
|
function firstFrame(value) {
|
|
913
992
|
return Array.isArray(value) ? value[0] : value;
|
|
914
993
|
}
|
|
@@ -916,12 +995,21 @@ function applyInlineStyles(el, styles) {
|
|
|
916
995
|
if (!el?.style || !styles) return;
|
|
917
996
|
const transforms = [];
|
|
918
997
|
let rawTransform;
|
|
998
|
+
let path;
|
|
999
|
+
const svgShape = typeof SVGElement !== "undefined" && el instanceof SVGElement && !(el instanceof SVGSVGElement);
|
|
919
1000
|
for (const key of Object.keys(styles)) {
|
|
920
1001
|
const value = firstFrame(styles[key]);
|
|
921
1002
|
if (value === void 0 || value === null) continue;
|
|
922
1003
|
if (key === "transform") rawTransform = String(value);
|
|
923
|
-
else if (
|
|
1004
|
+
else if (isSvgPathKey(key)) (path ??= {})[key] = value;
|
|
1005
|
+
else if (!TRANSFORM_KEYS.has(key)) {
|
|
1006
|
+
if (svgShape && !key.startsWith("--")) {
|
|
1007
|
+
el.style.removeProperty(kebab(key));
|
|
1008
|
+
el.setAttribute(kebab(key), String(value));
|
|
1009
|
+
} else el.style[key] = value;
|
|
1010
|
+
}
|
|
924
1011
|
}
|
|
1012
|
+
if (path) applySvgPath(el, path);
|
|
925
1013
|
for (const key of TRANSFORM_ORDER) if (key in styles) {
|
|
926
1014
|
const value = firstFrame(styles[key]);
|
|
927
1015
|
if (value !== void 0 && value !== null) transforms.push(transformFunction(key, value));
|
|
@@ -4154,6 +4242,329 @@ function lerp(a, b, p) {
|
|
|
4154
4242
|
sy: a.sy + (b.sy - a.sy) * p
|
|
4155
4243
|
};
|
|
4156
4244
|
}
|
|
4157
|
-
|
|
4245
|
+
const BRAND = Symbol("MotionSignal");
|
|
4246
|
+
function isMotionSignal(value) {
|
|
4247
|
+
return typeof value === "function" && value[BRAND] === true;
|
|
4248
|
+
}
|
|
4249
|
+
const SETTLE_MS = 50;
|
|
4250
|
+
const MIN_SPAN_MS = 16;
|
|
4251
|
+
function motionSignal(initial) {
|
|
4252
|
+
const state = signal(initial, ...ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []);
|
|
4253
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
4254
|
+
let samples = [];
|
|
4255
|
+
let lastTime = 0;
|
|
4256
|
+
const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
4257
|
+
const read = (() => state());
|
|
4258
|
+
Object.defineProperty(read, BRAND, { value: true });
|
|
4259
|
+
read.get = () => untracked(state);
|
|
4260
|
+
read.on = (listener) => {
|
|
4261
|
+
listeners.add(listener);
|
|
4262
|
+
return () => listeners.delete(listener);
|
|
4263
|
+
};
|
|
4264
|
+
read.getVelocity = () => {
|
|
4265
|
+
if (now() - lastTime > SETTLE_MS || samples.length < 2) return 0;
|
|
4266
|
+
const last = samples[samples.length - 1];
|
|
4267
|
+
let ref = samples[0];
|
|
4268
|
+
for (let i = samples.length - 2; i >= 0; i--) if (last.t - samples[i].t >= MIN_SPAN_MS) {
|
|
4269
|
+
ref = samples[i];
|
|
4270
|
+
break;
|
|
4271
|
+
}
|
|
4272
|
+
const dt = last.t - ref.t;
|
|
4273
|
+
return dt >= MIN_SPAN_MS / 2 ? (last.v - ref.v) / dt * 1e3 : 0;
|
|
4274
|
+
};
|
|
4275
|
+
read.set = (value) => {
|
|
4276
|
+
const previous = untracked(state);
|
|
4277
|
+
if (Object.is(previous, value)) return;
|
|
4278
|
+
const t = now();
|
|
4279
|
+
if (typeof value === "number") {
|
|
4280
|
+
if (t - lastTime > SETTLE_MS) samples = [];
|
|
4281
|
+
samples.push({
|
|
4282
|
+
t,
|
|
4283
|
+
v: value
|
|
4284
|
+
});
|
|
4285
|
+
if (samples.length > 8) samples = samples.slice(-8);
|
|
4286
|
+
}
|
|
4287
|
+
lastTime = t;
|
|
4288
|
+
state.set(value);
|
|
4289
|
+
for (const listener of [...listeners]) listener(value);
|
|
4290
|
+
};
|
|
4291
|
+
return read;
|
|
4292
|
+
}
|
|
4293
|
+
function mapSignal(source, mapOrInput, outputOrOptions, rangeOptions) {
|
|
4294
|
+
const sources = Array.isArray(source) ? source : [source];
|
|
4295
|
+
let compute;
|
|
4296
|
+
let options;
|
|
4297
|
+
const value = (s) => isMotionSignal(s) ? s.get() : untracked(s);
|
|
4298
|
+
if (typeof mapOrInput === "function") {
|
|
4299
|
+
const map = mapOrInput;
|
|
4300
|
+
options = outputOrOptions;
|
|
4301
|
+
compute = Array.isArray(source) ? () => map(sources.map(value)) : () => map(value(sources[0]));
|
|
4302
|
+
} else {
|
|
4303
|
+
options = rangeOptions;
|
|
4304
|
+
const mapper = transform(mapOrInput, outputOrOptions, {
|
|
4305
|
+
clamp: rangeOptions?.clamp ?? true,
|
|
4306
|
+
ease: rangeOptions?.ease
|
|
4307
|
+
});
|
|
4308
|
+
compute = () => mapper(value(sources[0]));
|
|
4309
|
+
}
|
|
4310
|
+
const out = motionSignal(compute());
|
|
4311
|
+
connect(sources, () => out.set(compute()), options);
|
|
4312
|
+
return out;
|
|
4313
|
+
}
|
|
4314
|
+
function springSignal(source, options = {}) {
|
|
4315
|
+
const injector = injectorFor(springSignal, options);
|
|
4316
|
+
const zone = injector.get(NgZone);
|
|
4317
|
+
const browser = isPlatformBrowser(injector.get(PLATFORM_ID)) && typeof requestAnimationFrame !== "undefined";
|
|
4318
|
+
const reduced = browser && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
4319
|
+
const { stiffness = 300, damping = 30, mass = 1, restDelta = .01, restSpeed = .05 } = options;
|
|
4320
|
+
const start = typeof source === "number" ? source : isMotionSignal(source) ? source.get() : untracked(source);
|
|
4321
|
+
const value = motionSignal(start);
|
|
4322
|
+
let position = start;
|
|
4323
|
+
let velocity = 0;
|
|
4324
|
+
let target = start;
|
|
4325
|
+
let raf = 0;
|
|
4326
|
+
let last = 0;
|
|
4327
|
+
const stop = () => {
|
|
4328
|
+
if (raf) cancelAnimationFrame(raf);
|
|
4329
|
+
raf = 0;
|
|
4330
|
+
};
|
|
4331
|
+
const step = (time) => {
|
|
4332
|
+
let dt = Math.min(time > last ? time - last : 16, 64) / 1e3;
|
|
4333
|
+
last = time;
|
|
4334
|
+
while (dt > 0) {
|
|
4335
|
+
const h = Math.min(dt, .004);
|
|
4336
|
+
const accel = (-stiffness * (position - target) - damping * velocity) / mass;
|
|
4337
|
+
velocity += accel * h;
|
|
4338
|
+
position += velocity * h;
|
|
4339
|
+
dt -= h;
|
|
4340
|
+
}
|
|
4341
|
+
if (Math.abs(velocity) < restSpeed && Math.abs(position - target) < restDelta) {
|
|
4342
|
+
position = target;
|
|
4343
|
+
velocity = 0;
|
|
4344
|
+
raf = 0;
|
|
4345
|
+
} else raf = requestAnimationFrame(step);
|
|
4346
|
+
value.set(position);
|
|
4347
|
+
};
|
|
4348
|
+
const out = (() => value());
|
|
4349
|
+
Object.defineProperty(out, BRAND, { value: true });
|
|
4350
|
+
out.get = value.get;
|
|
4351
|
+
out.on = value.on;
|
|
4352
|
+
out.getVelocity = () => velocity;
|
|
4353
|
+
out.jump = (v) => {
|
|
4354
|
+
stop();
|
|
4355
|
+
position = target = v;
|
|
4356
|
+
velocity = 0;
|
|
4357
|
+
value.set(v);
|
|
4358
|
+
};
|
|
4359
|
+
out.set = (next) => {
|
|
4360
|
+
if (!browser || reduced) return out.jump(next);
|
|
4361
|
+
target = next;
|
|
4362
|
+
if (raf || position === target && velocity === 0) return;
|
|
4363
|
+
last = performance.now();
|
|
4364
|
+
zone.runOutsideAngular(() => raf = requestAnimationFrame(step));
|
|
4365
|
+
};
|
|
4366
|
+
if (typeof source !== "number") connect([source], () => out.set(isMotionSignal(source) ? source.get() : untracked(source)), options);
|
|
4367
|
+
injector.get(DestroyRef).onDestroy(stop);
|
|
4368
|
+
return out;
|
|
4369
|
+
}
|
|
4370
|
+
function velocitySignal(source, options = {}) {
|
|
4371
|
+
const injector = injectorFor(velocitySignal, options);
|
|
4372
|
+
const zone = injector.get(NgZone);
|
|
4373
|
+
const out = motionSignal(0);
|
|
4374
|
+
let raf = 0;
|
|
4375
|
+
const check = () => {
|
|
4376
|
+
raf = 0;
|
|
4377
|
+
const v = source.getVelocity();
|
|
4378
|
+
out.set(v);
|
|
4379
|
+
if (v !== 0) raf = requestAnimationFrame(check);
|
|
4380
|
+
};
|
|
4381
|
+
const stop = source.on(() => {
|
|
4382
|
+
out.set(source.getVelocity());
|
|
4383
|
+
if (!raf && typeof requestAnimationFrame !== "undefined") zone.runOutsideAngular(() => raf = requestAnimationFrame(check));
|
|
4384
|
+
});
|
|
4385
|
+
injector.get(DestroyRef).onDestroy(() => {
|
|
4386
|
+
stop();
|
|
4387
|
+
if (raf) cancelAnimationFrame(raf);
|
|
4388
|
+
});
|
|
4389
|
+
return out;
|
|
4390
|
+
}
|
|
4391
|
+
function scrollSignal(options = {}) {
|
|
4392
|
+
const injector = injectorFor(scrollSignal, options);
|
|
4393
|
+
const progress = motionSignal(0);
|
|
4394
|
+
const offset = motionSignal(0);
|
|
4395
|
+
const velocity = motionSignal(0);
|
|
4396
|
+
let cancel;
|
|
4397
|
+
if (isPlatformBrowser(injector.get(PLATFORM_ID))) afterNextRender(() => {
|
|
4398
|
+
const resolve = (e) => {
|
|
4399
|
+
const v = typeof e === "function" ? e() : e;
|
|
4400
|
+
return v instanceof ElementRef ? v.nativeElement : v ?? void 0;
|
|
4401
|
+
};
|
|
4402
|
+
const container = resolve(options.container);
|
|
4403
|
+
const target = resolve(options.target);
|
|
4404
|
+
const axis = options.axis ?? "y";
|
|
4405
|
+
injector.get(NgZone).runOutsideAngular(() => {
|
|
4406
|
+
cancel = scroll((p, info) => {
|
|
4407
|
+
progress.set(p);
|
|
4408
|
+
offset.set(info[axis].current);
|
|
4409
|
+
velocity.set(info[axis].velocity);
|
|
4410
|
+
}, {
|
|
4411
|
+
container,
|
|
4412
|
+
target,
|
|
4413
|
+
offset: options.offset,
|
|
4414
|
+
axis
|
|
4415
|
+
});
|
|
4416
|
+
});
|
|
4417
|
+
}, { injector });
|
|
4418
|
+
injector.get(DestroyRef).onDestroy(() => cancel?.());
|
|
4419
|
+
return {
|
|
4420
|
+
progress,
|
|
4421
|
+
offset,
|
|
4422
|
+
velocity
|
|
4423
|
+
};
|
|
4424
|
+
}
|
|
4425
|
+
function connect(sources, update, options) {
|
|
4426
|
+
const stops = sources.filter(isMotionSignal).map((s) => s.on(update));
|
|
4427
|
+
const plain = sources.filter((s) => !isMotionSignal(s));
|
|
4428
|
+
const injector = options?.injector ?? tryInject();
|
|
4429
|
+
if (plain.length) {
|
|
4430
|
+
if (!injector) throw new Error("ngx-motion: a plain Angular signal source needs an injection context or the `injector` option.");
|
|
4431
|
+
effect(() => {
|
|
4432
|
+
for (const s of plain) s();
|
|
4433
|
+
untracked(update);
|
|
4434
|
+
}, { injector });
|
|
4435
|
+
}
|
|
4436
|
+
if (stops.length && injector) injector.get(DestroyRef).onDestroy(() => stops.forEach((stop) => stop()));
|
|
4437
|
+
}
|
|
4438
|
+
function tryInject() {
|
|
4439
|
+
try {
|
|
4440
|
+
return inject(Injector);
|
|
4441
|
+
} catch {
|
|
4442
|
+
return;
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
function injectorFor(fn, options) {
|
|
4446
|
+
if (options.injector) return options.injector;
|
|
4447
|
+
assertInInjectionContext(fn);
|
|
4448
|
+
return inject(Injector);
|
|
4449
|
+
}
|
|
4450
|
+
const TRANSFORMS = [
|
|
4451
|
+
"x",
|
|
4452
|
+
"y",
|
|
4453
|
+
"z",
|
|
4454
|
+
"scale",
|
|
4455
|
+
"scaleX",
|
|
4456
|
+
"scaleY",
|
|
4457
|
+
"rotate",
|
|
4458
|
+
"rotateX",
|
|
4459
|
+
"rotateY",
|
|
4460
|
+
"rotateZ",
|
|
4461
|
+
"skewX",
|
|
4462
|
+
"skewY"
|
|
4463
|
+
];
|
|
4464
|
+
const TRANSFORM_FN = {
|
|
4465
|
+
x: "translateX",
|
|
4466
|
+
y: "translateY",
|
|
4467
|
+
z: "translateZ"
|
|
4468
|
+
};
|
|
4469
|
+
const UNITLESS = /* @__PURE__ */ new Set([
|
|
4470
|
+
"opacity",
|
|
4471
|
+
"zIndex",
|
|
4472
|
+
"fontWeight",
|
|
4473
|
+
"lineHeight",
|
|
4474
|
+
"flex",
|
|
4475
|
+
"flexGrow",
|
|
4476
|
+
"flexShrink",
|
|
4477
|
+
"order",
|
|
4478
|
+
"zoom",
|
|
4479
|
+
"fillOpacity",
|
|
4480
|
+
"strokeOpacity"
|
|
4481
|
+
]);
|
|
4482
|
+
var MotionStyleDirective = class MotionStyleDirective {
|
|
4483
|
+
motionStyle = input(null, ...ngDevMode ? [{ debugName: "motionStyle" }] : /* istanbul ignore next */ []);
|
|
4484
|
+
el = inject(ElementRef).nativeElement;
|
|
4485
|
+
transform = /* @__PURE__ */ new Map();
|
|
4486
|
+
constructor() {
|
|
4487
|
+
effect((onCleanup) => {
|
|
4488
|
+
const styles = this.motionStyle() ?? {};
|
|
4489
|
+
const stops = [];
|
|
4490
|
+
for (const [key, v] of Object.entries(styles)) if (isMotionSignal(v)) {
|
|
4491
|
+
this.write(key, v.get());
|
|
4492
|
+
stops.push(v.on((value) => this.write(key, value)));
|
|
4493
|
+
} else if (isSignal(v) || typeof v === "function") {
|
|
4494
|
+
const value = v();
|
|
4495
|
+
untracked(() => this.write(key, value));
|
|
4496
|
+
} else this.write(key, v);
|
|
4497
|
+
onCleanup(() => {
|
|
4498
|
+
stops.forEach((stop) => stop());
|
|
4499
|
+
for (const key of Object.keys(styles)) if (!(key in (untracked(this.motionStyle) ?? {}))) this.write(key, null);
|
|
4500
|
+
});
|
|
4501
|
+
});
|
|
4502
|
+
}
|
|
4503
|
+
write(key, value) {
|
|
4504
|
+
if (isSvgPathKey(key)) return applySvgPath(this.el, { [key]: value });
|
|
4505
|
+
if (TRANSFORMS.includes(key)) {
|
|
4506
|
+
if (value == null) this.transform.delete(key);
|
|
4507
|
+
else this.transform.set(key, value);
|
|
4508
|
+
this.el.style.transform = this.transformString();
|
|
4509
|
+
return;
|
|
4510
|
+
}
|
|
4511
|
+
const css = value == null ? "" : typeof value === "number" && !UNITLESS.has(key) && !key.startsWith("--") ? `${value}px` : String(value);
|
|
4512
|
+
if (key.startsWith("--")) this.el.style.setProperty(key, css);
|
|
4513
|
+
else this.el.style[key] = css;
|
|
4514
|
+
}
|
|
4515
|
+
transformString() {
|
|
4516
|
+
let out = "";
|
|
4517
|
+
for (const key of TRANSFORMS) {
|
|
4518
|
+
const v = this.transform.get(key);
|
|
4519
|
+
if (v === void 0) continue;
|
|
4520
|
+
const unit = typeof v !== "number" ? "" : key === "x" || key === "y" || key === "z" ? "px" : key.startsWith("scale") ? "" : "deg";
|
|
4521
|
+
out += `${TRANSFORM_FN[key] ?? key}(${v}${unit}) `;
|
|
4522
|
+
}
|
|
4523
|
+
return out.trim();
|
|
4524
|
+
}
|
|
4525
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
4526
|
+
minVersion: "12.0.0",
|
|
4527
|
+
version: "22.3.2",
|
|
4528
|
+
ngImport: i0,
|
|
4529
|
+
type: MotionStyleDirective,
|
|
4530
|
+
deps: [],
|
|
4531
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
4532
|
+
});
|
|
4533
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
4534
|
+
minVersion: "17.1.0",
|
|
4535
|
+
version: "22.3.2",
|
|
4536
|
+
type: MotionStyleDirective,
|
|
4537
|
+
isStandalone: true,
|
|
4538
|
+
selector: "[motionStyle]",
|
|
4539
|
+
inputs: { motionStyle: {
|
|
4540
|
+
classPropertyName: "motionStyle",
|
|
4541
|
+
publicName: "motionStyle",
|
|
4542
|
+
isSignal: true,
|
|
4543
|
+
isRequired: false,
|
|
4544
|
+
transformFunction: null
|
|
4545
|
+
} },
|
|
4546
|
+
ngImport: i0
|
|
4547
|
+
});
|
|
4548
|
+
};
|
|
4549
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
4550
|
+
minVersion: "12.0.0",
|
|
4551
|
+
version: "22.3.2",
|
|
4552
|
+
ngImport: i0,
|
|
4553
|
+
type: MotionStyleDirective,
|
|
4554
|
+
decorators: [{
|
|
4555
|
+
type: Directive,
|
|
4556
|
+
args: [{ selector: "[motionStyle]" }]
|
|
4557
|
+
}],
|
|
4558
|
+
ctorParameters: () => [],
|
|
4559
|
+
propDecorators: { motionStyle: [{
|
|
4560
|
+
type: i0.Input,
|
|
4561
|
+
args: [{
|
|
4562
|
+
isSignal: true,
|
|
4563
|
+
alias: "motionStyle",
|
|
4564
|
+
required: false
|
|
4565
|
+
}]
|
|
4566
|
+
}] }
|
|
4567
|
+
});
|
|
4568
|
+
export { MotionAnimationService, MotionDragDirective, MotionFollowPointerDirective, MotionIfDirective, MotionLayoutDirective, MotionLayoutRegistry, MotionMagneticDirective, MotionOneDirective, MotionOneService, MotionPanDirective, MotionPresenceDirective, MotionReorderGroupDirective, MotionReorderItemDirective, MotionScrollDirective, MotionStyleDirective, MotionTiltDirective, POINTER_SPRING, SCROLL_THROUGH, SCROLL_WHILE_VISIBLE, isMotionSignal, mapSignal, motionSignal, scrollSignal, springSignal, velocitySignal };
|
|
4158
4569
|
|
|
4159
4570
|
//# sourceMappingURL=hilux-ngx-motion.mjs.map
|