@hilux/ngx-motion 2.1.0 → 2.3.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
@@ -54,6 +54,7 @@ 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
+ - **Layout animations:** `motionLayout` glides elements to their new place and size after any layout change, and `motionLayoutId` makes shared-element transitions.
57
58
  - **Exit animations:** `*motionIf` and `*motionPresence` keep elements in the DOM until their exit animation finishes. If shown again mid-exit, they animate back in.
58
59
  - **Variants:** named, reusable animation states.
59
60
  - **Timelines:** sequence several steps on one element.
@@ -328,6 +329,48 @@ Drag-to-reorder lists, like Framer Motion's `Reorder.Group` and `Reorder.Item`.
328
329
  - Keyboard: on a focused item (give it `tabindex="0"`), Alt + arrow keys move it one place.
329
330
  - Track items by identity in `@for` (not `$index`) so elements move with their values. Items can be different sizes.
330
331
 
332
+ ### Layout Animations
333
+ 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
+
335
+ ```html
336
+ <!-- Glides to its new place in the list -->
337
+ @for (item of items(); track item.id) {
338
+ <li motionLayout="position">{{ item.name }}</li>
339
+ }
340
+
341
+ <!-- Moved by justify-content alone -->
342
+ <button [class.justify-end]="on()" (click)="on.set(!on())">
343
+ <span class="knob" motionLayout></span>
344
+ </button>
345
+
346
+ <!-- Shared element: each tab renders its own pill, and the new pill starts where the old one was -->
347
+ @for (tab of tabs; track tab) {
348
+ <button (click)="active.set(tab)">
349
+ @if (active() === tab) { <span class="pill" motionLayoutId="tab-pill"></span> }
350
+ {{ tab }}
351
+ </button>
352
+ }
353
+ ```
354
+
355
+ - `motionLayout`: what animates. Empty (the default) animates position and size, `"position"` only moves (size changes jump, so text never stretches), and `"size"` only resizes.
356
+ - `motionLayoutId`: a shared id. When an element with the same id appears (in the same render or soon after the old one is removed), it starts from the old one's position and size. Works on its own or with `motionLayout`, and across scroll containers.
357
+ - Shared elements that stay mounted, like a thumbnail and its lightbox: while both are mounted the newer one is shown and the older one hidden (`visibility: hidden`). Remove the newer one and the older one reappears and flies back from where it was:
358
+
359
+ ```html
360
+ @for (p of photos; track p.id) {
361
+ <button class="thumb" [motionLayoutId]="p.id" (click)="open.set(p)"><img [src]="p.src" /></button>
362
+ }
363
+ @if (open(); as p) {
364
+ <div class="lightbox" [motionLayoutId]="p.id" (click)="open.set(null)"><img [src]="p.src" /></div>
365
+ }
366
+ ```
367
+ - `layoutTransition`: the transition (a spring by default). `layoutAnimationStart` and `layoutAnimationComplete` are emitted, and `animating()` is a signal, via `exportAs: 'motionLayout'`.
368
+ - Size is animated with scale. Corner radii (in px) are corrected so they stay round. Mark content inside with `motionLayoutCorrect` and it is counter-scaled, so text keeps its size while the box grows or shrinks: `<li motionLayout><span motionLayoutCorrect>{{ item }}</span></li>`. Or use `"position"` to animate position only.
369
+ - Every layout element is measured after every render, so elements whose own component wasn't re-rendered (OnPush siblings) still animate when something else pushes them. There is no `LayoutGroup` to add.
370
+ - While it moves the element has the class `motion-layout-animating`, for example to raise it above its neighbours with `z-index`.
371
+ - Layout animations use the element's `transform`, so don't give it a CSS transform of its own; wrap it instead.
372
+ - Interrupted animations continue from where the element is drawn. Resizing the window re-measures without animating, and with reduced motion nothing animates.
373
+
331
374
  ## Angular Control Flow Integration
332
375
 
333
376
  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.
@@ -420,9 +463,46 @@ The directives work seamlessly with Angular's new control flow syntax:
420
463
  | `drag`, `dragConstraints`, `dragElastic`, `dragMomentum` | `motionDrag`, `dragConstraints`, `dragElastic`, `dragMomentum` |
421
464
  | `onPan`, `whilePan` | `motionPan` with `(pan)`, `[whilePan]` |
422
465
  | `<Reorder.Group values onReorder>` / `<Reorder.Item value>` | `[(motionReorderGroup)]` / `[motionReorderItem]` |
466
+ | `layout`, `layout="position"` | `motionLayout`, `motionLayout="position"` |
467
+ | `layoutId` | `motionLayoutId` |
468
+ | `<LayoutGroup>` | not needed: every layout element is measured after every render |
469
+
470
+ ## CSS or ngx-motion?
471
+ A lot of animation is plain CSS now, and where CSS is enough it is the better choice: no JavaScript, and it runs off the main thread. ngx-motion is for what CSS can't do: physics, the pointer's position and speed, smooth interruption, removing elements after they animate out, and layout animations on a page that stays interactive. Browser support below is as of mid-2026.
472
+
473
+ | Feature | Plain CSS | What ngx-motion adds |
474
+ |---|---|---|
475
+ | Transitions and keyframes | ✅ `transition`, `@keyframes`, separate `translate` / `scale` / `rotate` | Plain objects in the template, values that can change at runtime (signals) |
476
+ | Easing and springs | ⚠️ `linear()` can draw a spring-shaped curve, but it has a fixed duration and no physics | Real springs: an interrupted spring carries its speed into the next one |
477
+ | Interrupting an animation | ⚠️ Transitions re-aim from the current value but lose their speed; keyframes restart | Continues from where the element is and how fast it's moving |
478
+ | Hover, tap, focus | ✅ `:hover`, `:active`, `:focus-visible` | Physics spring-back; `whileTap` on touch screens; composes with drag and pointer effects |
479
+ | Enter animations | ✅ `@starting-style`; Angular's `animate.enter` | Declarative `initial` → `animate` states |
480
+ | Exit animations | ⚠️ Only for elements that stay in the DOM (`allow-discrete`, popovers, dialogs); Angular's `animate.leave` waits for a CSS animation | `*motionIf` / `*motionPresence` with `exit` states; shown again mid-exit, it animates back in |
481
+ | Stagger | ⚠️ A delay per item via custom properties; `sibling-index()` only in Chrome | `staggerChildren`, `delayChildren`, direction, nested parents |
482
+ | Sequences | ⚠️ Percentages in one `@keyframes`; several elements need hand-tuned delays | Timelines, `repeat` with `mirror` / `reverse`, per-property transitions |
483
+ | Play once when scrolled into view | ❌ No trigger yet (`animation-trigger` is experimental); needs IntersectionObserver | `runInView`, `whileInView` |
484
+ | 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 |
485
+ | Magnetic, tilt, follow-pointer | ❌ CSS can't read the pointer position | `motionMagnetic`, `motionTilt` (sets `--motion-pointer-x/y` for CSS), `motionFollowPointer` |
486
+ | Drag | ❌ | Constraints, elastic edges, momentum, snap points |
487
+ | Pan and swipe | ❌ Only `touch-action` and scroll snap | Offset, delta, velocity and swipe direction |
488
+ | Drag to reorder | ❌ | Two-way bound order, keyboard moves, neighbours glide aside |
489
+ | Layout changes | ⚠️ View Transitions animate layout changes, but snapshot the whole page as an image, run one at a time and restart if interrupted; `interpolate-size` animates `height: auto` (Chrome only) | `motionLayout`: the real elements animate and stay clickable, several at once, interruptible, on springs; text can keep its size and corners stay round |
490
+ | Shared elements | ✅ / ⚠️ `view-transition-name` covers a thumbnail growing into a detail view | `motionLayoutId`: across scroll containers, while the page stays interactive, no `startViewTransition` call |
491
+ | Reduced motion | ✅ `@media (prefers-reduced-motion)` | Respected by every directive automatically |
492
+ | Change detection and SSR | No JavaScript | Runs outside Angular's change detection; does nothing on the server |
493
+
494
+ **Use CSS for** hover and focus styling, simple enter animations, looping decorations and fixed-length transitions. **Use ngx-motion for** gestures and pointer effects, interruptible springs, exits from `@if` and `@for`, scroll triggers, and layout animations inside a page. For full-page route changes, View Transitions are often the better tool (the demo's Route Transitions examples use them).
423
495
 
424
496
  ## Changelog
425
497
 
498
+ **2.3.0**
499
+ - 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
+ - Layout animations keep corner radii round while scaling, and add the class `motion-layout-animating` while an element moves.
501
+ - Fixed: a window resize no longer leaves a shared element starting from its pre-resize position, and a late frame after a layout animation finished can no longer leave a small offset behind.
502
+
503
+ **2.2.0**
504
+ - New layout animations: `motionLayout` animates elements to their new position and size after any layout change (with `motionLayoutCorrect` to keep content from stretching), and `motionLayoutId` makes shared-element transitions. See [Layout Animations](#layout-animations).
505
+
426
506
  **2.1.0**
427
507
  - 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
508
  - New drag-to-reorder lists: `motionReorderGroup` and `motionReorderItem`, with two-way bound order and keyboard support. See [Reorder](#reorder).
@@ -538,6 +618,9 @@ It's the closest equivalent. Framer Motion (now Motion for React) is React-only.
538
618
  ### Which Angular versions are supported?
539
619
  2.x supports Angular 22 and later. 1.x supports Angular 19.
540
620
 
621
+ ### Do I need it, or is CSS enough?
622
+ Often CSS is enough. See [CSS or ngx-motion?](#css-or-ngx-motion) for a feature-by-feature table.
623
+
541
624
  ### How is it different from Angular's built-in animations?
542
625
  Angular's `animate.enter` / `animate.leave` (and the older `@angular/animations`) are built around CSS classes and state-transition triggers. ngx-motion adds things those don't cover:
543
626
  - physics springs
@@ -1,5 +1,5 @@
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, 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, effect, forwardRef, inject, input, isDevMode, 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";
@@ -3490,7 +3490,7 @@ i0.ɵɵngDeclareClassMetadata({
3490
3490
  }]
3491
3491
  }
3492
3492
  });
3493
- const LAYOUT_SPRING = {
3493
+ const LAYOUT_SPRING$1 = {
3494
3494
  type: "spring",
3495
3495
  stiffness: 550,
3496
3496
  damping: 45
@@ -3498,7 +3498,7 @@ const LAYOUT_SPRING = {
3498
3498
  var MotionReorderGroupDirective = class MotionReorderGroupDirective {
3499
3499
  motionReorderGroup = model.required(...ngDevMode ? [{ debugName: "motionReorderGroup" }] : /* istanbul ignore next */ []);
3500
3500
  reorderAxis = input("y", ...ngDevMode ? [{ debugName: "reorderAxis" }] : /* istanbul ignore next */ []);
3501
- reorderTransition = input(LAYOUT_SPRING, ...ngDevMode ? [{ debugName: "reorderTransition" }] : /* istanbul ignore next */ []);
3501
+ reorderTransition = input(LAYOUT_SPRING$1, ...ngDevMode ? [{ debugName: "reorderTransition" }] : /* istanbul ignore next */ []);
3502
3502
  reorderEnd = output();
3503
3503
  items = /* @__PURE__ */ new Set();
3504
3504
  motion = inject(MotionAnimationService);
@@ -3528,7 +3528,6 @@ var MotionReorderGroupDirective = class MotionReorderGroupDirective {
3528
3528
  const next = [...values];
3529
3529
  next.splice(to, 0, ...next.splice(from, 1));
3530
3530
  this.pending = true;
3531
- this.zone.run(() => this.motionReorderGroup.set(next));
3532
3531
  afterNextRender(() => {
3533
3532
  this.pending = false;
3534
3533
  const axis = this.reorderAxis();
@@ -3546,6 +3545,7 @@ var MotionReorderGroupDirective = class MotionReorderGroupDirective {
3546
3545
  }
3547
3546
  }
3548
3547
  }, { injector: this.injector });
3548
+ this.zone.run(() => this.motionReorderGroup.set(next));
3549
3549
  return true;
3550
3550
  }
3551
3551
  ended() {
@@ -3786,6 +3786,374 @@ i0.ɵɵngDeclareClassMetadata({
3786
3786
  }]
3787
3787
  }] }
3788
3788
  });
3789
- export { MotionAnimationService, MotionDragDirective, MotionFollowPointerDirective, MotionIfDirective, MotionMagneticDirective, MotionOneDirective, MotionOneService, MotionPanDirective, MotionPresenceDirective, MotionReorderGroupDirective, MotionReorderItemDirective, MotionScrollDirective, MotionTiltDirective, POINTER_SPRING, SCROLL_THROUGH, SCROLL_WHILE_VISIBLE };
3789
+ const NONE = {
3790
+ x: 0,
3791
+ y: 0,
3792
+ sx: 1,
3793
+ sy: 1
3794
+ };
3795
+ const LAYOUT_SPRING = {
3796
+ type: "spring",
3797
+ stiffness: 300,
3798
+ damping: 34,
3799
+ mass: 1
3800
+ };
3801
+ const CORNERS = [
3802
+ "TopLeft",
3803
+ "TopRight",
3804
+ "BottomRight",
3805
+ "BottomLeft"
3806
+ ];
3807
+ var MotionLayoutRegistry = class MotionLayoutRegistry {
3808
+ seen = /* @__PURE__ */ new Map();
3809
+ stacks = /* @__PURE__ */ new Map();
3810
+ record(id, owner, box) {
3811
+ this.seen.set(id, {
3812
+ owner,
3813
+ box
3814
+ });
3815
+ }
3816
+ from(id, owner) {
3817
+ const s = this.seen.get(id);
3818
+ return s && s.owner !== owner ? s.box : void 0;
3819
+ }
3820
+ join(id, m) {
3821
+ const stack = this.stacks.get(id) ?? [];
3822
+ stack.at(-1)?.setHidden(true);
3823
+ stack.push(m);
3824
+ this.stacks.set(id, stack);
3825
+ }
3826
+ leave(id, m) {
3827
+ const stack = this.stacks.get(id) ?? [];
3828
+ const wasLead = stack.at(-1) === m;
3829
+ const i = stack.indexOf(m);
3830
+ if (i >= 0) stack.splice(i, 1);
3831
+ if (!stack.length) this.stacks.delete(id);
3832
+ const last = this.seen.get(id);
3833
+ if (wasLead && stack.length) stack.at(-1).resume(last?.owner === m ? last.box : void 0);
3834
+ else if (last?.owner === m) setTimeout(() => {
3835
+ if (this.seen.get(id) === last) this.seen.delete(id);
3836
+ }, 1e3);
3837
+ }
3838
+ static ɵfac = i0.ɵɵngDeclareFactory({
3839
+ minVersion: "12.0.0",
3840
+ version: "22.3.2",
3841
+ ngImport: i0,
3842
+ type: MotionLayoutRegistry,
3843
+ deps: [],
3844
+ target: i0.ɵɵFactoryTarget.Injectable
3845
+ });
3846
+ static ɵprov = i0.ɵɵngDeclareInjectable({
3847
+ minVersion: "12.0.0",
3848
+ version: "22.3.2",
3849
+ ngImport: i0,
3850
+ type: MotionLayoutRegistry,
3851
+ providedIn: "root"
3852
+ });
3853
+ };
3854
+ i0.ɵɵngDeclareClassMetadata({
3855
+ minVersion: "12.0.0",
3856
+ version: "22.3.2",
3857
+ ngImport: i0,
3858
+ type: MotionLayoutRegistry,
3859
+ decorators: [{
3860
+ type: Injectable,
3861
+ args: [{ providedIn: "root" }]
3862
+ }]
3863
+ });
3864
+ var MotionLayoutDirective = class MotionLayoutDirective {
3865
+ motionLayout = input("", ...ngDevMode ? [{ debugName: "motionLayout" }] : /* istanbul ignore next */ []);
3866
+ motionLayoutId = input(null, ...ngDevMode ? [{ debugName: "motionLayoutId" }] : /* istanbul ignore next */ []);
3867
+ layoutTransition = input(LAYOUT_SPRING, ...ngDevMode ? [{ debugName: "layoutTransition" }] : /* istanbul ignore next */ []);
3868
+ layoutAnimationStart = output();
3869
+ layoutAnimationComplete = output();
3870
+ _animating = signal(false, ...ngDevMode ? [{ debugName: "_animating" }] : /* istanbul ignore next */ []);
3871
+ animating = this._animating.asReadonly();
3872
+ el = inject(ElementRef).nativeElement;
3873
+ motion = inject(MotionAnimationService);
3874
+ registry = inject(MotionLayoutRegistry);
3875
+ prev = null;
3876
+ shift = {
3877
+ x: 0,
3878
+ y: 0
3879
+ };
3880
+ cur = NONE;
3881
+ controls;
3882
+ run;
3883
+ resnap = false;
3884
+ joined = null;
3885
+ resumeFrom;
3886
+ radii = null;
3887
+ inlineRadius = "";
3888
+ reduced = typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
3889
+ constructor() {
3890
+ const destroyRef = inject(DestroyRef);
3891
+ if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
3892
+ afterEveryRender({
3893
+ earlyRead: () => this.measure(),
3894
+ write: (box) => this.update(box)
3895
+ });
3896
+ let raf = 0;
3897
+ const resize = () => {
3898
+ this.resnap = true;
3899
+ this.controls?.stop();
3900
+ this.controls = void 0;
3901
+ if (this.run) {
3902
+ this.run = void 0;
3903
+ this._animating.set(false);
3904
+ }
3905
+ if (this.cur !== NONE) this.apply(NONE);
3906
+ this.prev = this.measure() ?? this.prev;
3907
+ const id = this.motionLayoutId();
3908
+ if (id && this.prev) this.registry.record(id, this, this.shifted(this.visual(this.prev)));
3909
+ cancelAnimationFrame(raf);
3910
+ raf = requestAnimationFrame(() => this.resnap = false);
3911
+ };
3912
+ inject(NgZone).runOutsideAngular(() => window.addEventListener("resize", resize));
3913
+ destroyRef.onDestroy(() => {
3914
+ window.removeEventListener("resize", resize);
3915
+ cancelAnimationFrame(raf);
3916
+ this.controls?.stop();
3917
+ if (this.joined) this.registry.leave(this.joined, this);
3918
+ });
3919
+ }
3920
+ setHidden(hidden) {
3921
+ this.el.style.visibility = hidden ? "hidden" : "";
3922
+ }
3923
+ resume(from) {
3924
+ this.setHidden(false);
3925
+ this.resumeFrom = from;
3926
+ }
3927
+ mode() {
3928
+ const m = this.motionLayout();
3929
+ return m === "position" || m === "size" ? m : "both";
3930
+ }
3931
+ measure() {
3932
+ const el = this.el;
3933
+ if (!el.isConnected || !el.offsetWidth && !el.offsetHeight && !el.offsetParent) return null;
3934
+ let x = 0, y = 0;
3935
+ for (let n = el; n; n = n.offsetParent) {
3936
+ x += n.offsetLeft;
3937
+ y += n.offsetTop;
3938
+ }
3939
+ const w = el.offsetWidth, h = el.offsetHeight;
3940
+ const box = {
3941
+ cx: x + w / 2,
3942
+ cy: y + h / 2,
3943
+ w,
3944
+ h
3945
+ };
3946
+ if (this.motionLayoutId()) {
3947
+ const r = el.getBoundingClientRect();
3948
+ this.shift = {
3949
+ x: r.left + r.width / 2 - this.cur.x - box.cx,
3950
+ y: r.top + r.height / 2 - this.cur.y - box.cy
3951
+ };
3952
+ }
3953
+ return box;
3954
+ }
3955
+ shifted(b, sign = 1) {
3956
+ return {
3957
+ ...b,
3958
+ cx: b.cx + sign * this.shift.x,
3959
+ cy: b.cy + sign * this.shift.y
3960
+ };
3961
+ }
3962
+ visual(b, o = this.cur) {
3963
+ return {
3964
+ cx: b.cx + o.x,
3965
+ cy: b.cy + o.y,
3966
+ w: b.w * o.sx,
3967
+ h: b.h * o.sy
3968
+ };
3969
+ }
3970
+ update(box) {
3971
+ const id = this.motionLayoutId() || null;
3972
+ if (id !== this.joined) {
3973
+ if (this.joined) this.registry.leave(this.joined, this);
3974
+ if (id) this.registry.join(id, this);
3975
+ this.joined = id;
3976
+ }
3977
+ if (!box) return;
3978
+ let from;
3979
+ if (this.resumeFrom) {
3980
+ from = this.shifted(this.resumeFrom, -1);
3981
+ this.resumeFrom = void 0;
3982
+ } else if (!this.prev) {
3983
+ const seen = id && this.registry.from(id, this);
3984
+ if (seen) from = this.shifted(seen, -1);
3985
+ } else if (!same(this.prev, box)) from = this.visual(this.prev);
3986
+ this.prev = box;
3987
+ if (from && !this.resnap && !this.reduced) this.animateFrom(from, box);
3988
+ if (id) this.registry.record(id, this, this.shifted(this.visual(box)));
3989
+ }
3990
+ animateFrom(from, to) {
3991
+ const mode = this.mode();
3992
+ const start = {
3993
+ x: mode === "size" ? 0 : from.cx - to.cx,
3994
+ y: mode === "size" ? 0 : from.cy - to.cy,
3995
+ sx: mode === "position" || !to.w ? 1 : from.w / to.w,
3996
+ sy: mode === "position" || !to.h ? 1 : from.h / to.h
3997
+ };
3998
+ if (Math.abs(start.x) < .5 && Math.abs(start.y) < .5 && Math.abs(start.sx - 1) < .005 && Math.abs(start.sy - 1) < .005) return;
3999
+ this.controls?.stop();
4000
+ if (!this.radii) this.readRadii();
4001
+ this.apply(start);
4002
+ if (!this._animating()) {
4003
+ this._animating.set(true);
4004
+ this.layoutAnimationStart.emit();
4005
+ }
4006
+ const id = this.motionLayoutId();
4007
+ const run = {};
4008
+ this.run = run;
4009
+ const controls = this.motion.animate(0, 1, {
4010
+ ...this.layoutTransition(),
4011
+ onUpdate: (p) => {
4012
+ if (this.run !== run) return;
4013
+ this.apply(lerp(start, NONE, p));
4014
+ if (id && this.prev) this.registry.record(id, this, this.shifted(this.visual(this.prev)));
4015
+ }
4016
+ });
4017
+ this.controls = controls;
4018
+ Promise.resolve(controls).then(() => {
4019
+ if (this.run !== run) return;
4020
+ this.run = void 0;
4021
+ this.controls = void 0;
4022
+ this.apply(NONE);
4023
+ this._animating.set(false);
4024
+ this.layoutAnimationComplete.emit();
4025
+ }, () => {});
4026
+ }
4027
+ readRadii() {
4028
+ if (this.mode() === "position") return;
4029
+ const cs = getComputedStyle(this.el);
4030
+ const r = CORNERS.map((c) => cs[`border${c}Radius`]);
4031
+ if (r.some((v) => v.includes("%"))) return;
4032
+ const px = r.map((v) => parseFloat(v) || 0);
4033
+ if (px.some((v) => v > 0)) {
4034
+ this.radii = px;
4035
+ this.inlineRadius = this.el.style.borderRadius;
4036
+ }
4037
+ }
4038
+ apply(o) {
4039
+ this.cur = o;
4040
+ const still = o === NONE;
4041
+ this.el.style.transform = still ? "" : `translate(${o.x}px, ${o.y}px) scale(${o.sx}, ${o.sy})`;
4042
+ this.el.classList.toggle("motion-layout-animating", !still);
4043
+ if (this.mode() === "position") return;
4044
+ const flat = still || o.sx === 1 && o.sy === 1;
4045
+ if (this.radii) {
4046
+ const r = this.radii;
4047
+ this.el.style.borderRadius = flat ? this.inlineRadius : `${r.map((v) => `${v / o.sx}px`).join(" ")} / ${r.map((v) => `${v / o.sy}px`).join(" ")}`;
4048
+ if (still) this.radii = null;
4049
+ }
4050
+ const inverse = flat ? "" : `scale(${1 / o.sx}, ${1 / o.sy})`;
4051
+ this.el.querySelectorAll("[motionLayoutCorrect]").forEach((c) => c.style.transform = inverse);
4052
+ }
4053
+ static ɵfac = i0.ɵɵngDeclareFactory({
4054
+ minVersion: "12.0.0",
4055
+ version: "22.3.2",
4056
+ ngImport: i0,
4057
+ type: MotionLayoutDirective,
4058
+ deps: [],
4059
+ target: i0.ɵɵFactoryTarget.Directive
4060
+ });
4061
+ static ɵdir = i0.ɵɵngDeclareDirective({
4062
+ minVersion: "17.1.0",
4063
+ version: "22.3.2",
4064
+ type: MotionLayoutDirective,
4065
+ isStandalone: true,
4066
+ selector: "[motionLayout], [motionLayoutId]",
4067
+ inputs: {
4068
+ motionLayout: {
4069
+ classPropertyName: "motionLayout",
4070
+ publicName: "motionLayout",
4071
+ isSignal: true,
4072
+ isRequired: false,
4073
+ transformFunction: null
4074
+ },
4075
+ motionLayoutId: {
4076
+ classPropertyName: "motionLayoutId",
4077
+ publicName: "motionLayoutId",
4078
+ isSignal: true,
4079
+ isRequired: false,
4080
+ transformFunction: null
4081
+ },
4082
+ layoutTransition: {
4083
+ classPropertyName: "layoutTransition",
4084
+ publicName: "layoutTransition",
4085
+ isSignal: true,
4086
+ isRequired: false,
4087
+ transformFunction: null
4088
+ }
4089
+ },
4090
+ outputs: {
4091
+ layoutAnimationStart: "layoutAnimationStart",
4092
+ layoutAnimationComplete: "layoutAnimationComplete"
4093
+ },
4094
+ exportAs: ["motionLayout"],
4095
+ ngImport: i0
4096
+ });
4097
+ };
4098
+ i0.ɵɵngDeclareClassMetadata({
4099
+ minVersion: "12.0.0",
4100
+ version: "22.3.2",
4101
+ ngImport: i0,
4102
+ type: MotionLayoutDirective,
4103
+ decorators: [{
4104
+ type: Directive,
4105
+ args: [{
4106
+ selector: "[motionLayout], [motionLayoutId]",
4107
+ exportAs: "motionLayout"
4108
+ }]
4109
+ }],
4110
+ ctorParameters: () => [],
4111
+ propDecorators: {
4112
+ motionLayout: [{
4113
+ type: i0.Input,
4114
+ args: [{
4115
+ isSignal: true,
4116
+ alias: "motionLayout",
4117
+ required: false
4118
+ }]
4119
+ }],
4120
+ motionLayoutId: [{
4121
+ type: i0.Input,
4122
+ args: [{
4123
+ isSignal: true,
4124
+ alias: "motionLayoutId",
4125
+ required: false
4126
+ }]
4127
+ }],
4128
+ layoutTransition: [{
4129
+ type: i0.Input,
4130
+ args: [{
4131
+ isSignal: true,
4132
+ alias: "layoutTransition",
4133
+ required: false
4134
+ }]
4135
+ }],
4136
+ layoutAnimationStart: [{
4137
+ type: i0.Output,
4138
+ args: ["layoutAnimationStart"]
4139
+ }],
4140
+ layoutAnimationComplete: [{
4141
+ type: i0.Output,
4142
+ args: ["layoutAnimationComplete"]
4143
+ }]
4144
+ }
4145
+ });
4146
+ function same(a, b) {
4147
+ return Math.abs(a.cx - b.cx) < .5 && Math.abs(a.cy - b.cy) < .5 && Math.abs(a.w - b.w) < .5 && Math.abs(a.h - b.h) < .5;
4148
+ }
4149
+ function lerp(a, b, p) {
4150
+ return {
4151
+ x: a.x + (b.x - a.x) * p,
4152
+ y: a.y + (b.y - a.y) * p,
4153
+ sx: a.sx + (b.sx - a.sx) * p,
4154
+ sy: a.sy + (b.sy - a.sy) * p
4155
+ };
4156
+ }
4157
+ export { MotionAnimationService, MotionDragDirective, MotionFollowPointerDirective, MotionIfDirective, MotionLayoutDirective, MotionLayoutRegistry, MotionMagneticDirective, MotionOneDirective, MotionOneService, MotionPanDirective, MotionPresenceDirective, MotionReorderGroupDirective, MotionReorderItemDirective, MotionScrollDirective, MotionTiltDirective, POINTER_SPRING, SCROLL_THROUGH, SCROLL_WHILE_VISIBLE };
3790
4158
 
3791
4159
  //# sourceMappingURL=hilux-ngx-motion.mjs.map