@hilux/ngx-motion 2.2.0 → 2.4.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 -2
- package/fesm2022/hilux-ngx-motion.mjs +404 -14
- package/fesm2022/hilux-ngx-motion.mjs.map +1 -1
- package/package.json +1 -1
- package/types/hilux-ngx-motion.d.ts +193 -14
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { AfterContentInit, ChangeDetectorRef, ElementRef, EventEmitter, NgZone, OnChanges, OnDestroy, OnInit, SimpleChanges, TemplateRef, ViewContainerRef, WritableSignal } from "@angular/core";
|
|
2
|
+
import { AfterContentInit, ChangeDetectorRef, ElementRef, EventEmitter, Injector, NgZone, OnChanges, OnDestroy, OnInit, Signal, SimpleChanges, TemplateRef, ViewContainerRef, WritableSignal } from "@angular/core";
|
|
3
3
|
import { Observable } from "rxjs";
|
|
4
4
|
import { AnimationOptions } from "motion";
|
|
5
5
|
export interface MotionElement {
|
|
@@ -1389,18 +1389,28 @@ interface Box {
|
|
|
1389
1389
|
w: number;
|
|
1390
1390
|
h: number;
|
|
1391
1391
|
}
|
|
1392
|
+
/** What the registry needs from a member. @internal */
|
|
1393
|
+
interface Member {
|
|
1394
|
+
/** Become the visible one again and fly in from where the last lead was (viewport box). */
|
|
1395
|
+
resume(from: Box | undefined): void;
|
|
1396
|
+
setHidden(hidden: boolean): void;
|
|
1397
|
+
}
|
|
1392
1398
|
/**
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1399
|
+
* Shared layout ids. For each id: the mounted elements (the newest one, the
|
|
1400
|
+
* lead, is shown and the others are hidden) and where the id was last drawn,
|
|
1401
|
+
* in viewport coordinates so it holds across scroll containers.
|
|
1396
1402
|
* @internal
|
|
1397
1403
|
*/
|
|
1398
1404
|
export declare class MotionLayoutRegistry {
|
|
1399
1405
|
private readonly seen;
|
|
1406
|
+
private readonly stacks;
|
|
1400
1407
|
record(id: string, owner: object, box: Box): void;
|
|
1401
1408
|
/** The box another element left for this id, if any. */
|
|
1402
1409
|
from(id: string, owner: object): Box | undefined;
|
|
1403
|
-
|
|
1410
|
+
/** A new element with this id: it leads, and the one it took over from is hidden. */
|
|
1411
|
+
join(id: string, m: Member): void;
|
|
1412
|
+
/** An element with this id is going: if it led, the one before it comes back from its box. */
|
|
1413
|
+
leave(id: string, m: Member): void;
|
|
1404
1414
|
static ɵfac: i0.ɵɵFactoryDeclaration<MotionLayoutRegistry, never>;
|
|
1405
1415
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
1406
1416
|
}
|
|
@@ -1409,7 +1419,7 @@ export declare class MotionLayoutRegistry {
|
|
|
1409
1419
|
*
|
|
1410
1420
|
* <!-- Glides to its new place (and size) whenever the layout changes -->
|
|
1411
1421
|
* <li motionLayout>…</li>
|
|
1412
|
-
* <div motionLayout="position">only moves; size changes jump
|
|
1422
|
+
* <div motionLayout="position">only moves; size changes jump</div>
|
|
1413
1423
|
*
|
|
1414
1424
|
* <!-- Shared element: a new element with the same id starts where the old one was -->
|
|
1415
1425
|
* @for (tab of tabs; track tab) {
|
|
@@ -1421,19 +1431,28 @@ export declare class MotionLayoutRegistry {
|
|
|
1421
1431
|
* After every render it measures the element's layout box (offsets, so
|
|
1422
1432
|
* transforms and scrolling don't count). When the box has changed, it jumps
|
|
1423
1433
|
* back to where it was drawn (FLIP) and springs to the new place: x/y for
|
|
1424
|
-
* position, scaleX/scaleY for size.
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
1434
|
+
* position, scaleX/scaleY for size. Every element is measured after every
|
|
1435
|
+
* render, so siblings that weren't re-rendered animate too (no LayoutGroup
|
|
1436
|
+
* needed). Interrupted animations continue from where they are. Resizing the
|
|
1437
|
+
* window re-measures without animating, and with reduced motion it doesn't
|
|
1438
|
+
* animate.
|
|
1439
|
+
*
|
|
1440
|
+
* Shared ids: while two elements with the same id are mounted (a thumbnail
|
|
1441
|
+
* and its open lightbox), the newer one is shown and the older one hidden;
|
|
1442
|
+
* when the newer one is removed, the older one reappears and flies back from
|
|
1443
|
+
* where it was.
|
|
1427
1444
|
*
|
|
1428
|
-
* - Size changes scale the element
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1445
|
+
* - Size changes scale the element. Corner radii are corrected; mark content
|
|
1446
|
+
* with `motionLayoutCorrect` to counter-scale it (it keeps its own size),
|
|
1447
|
+
* or use "position".
|
|
1431
1448
|
* - Uses transform (centre origin); don't give the element a CSS transform
|
|
1432
1449
|
* of its own, wrap it instead.
|
|
1450
|
+
* - Has the class `motion-layout-animating` while it moves (to raise it with
|
|
1451
|
+
* a z-index, for example).
|
|
1433
1452
|
*/
|
|
1434
|
-
export declare class MotionLayoutDirective {
|
|
1453
|
+
export declare class MotionLayoutDirective implements Member {
|
|
1435
1454
|
/** What animates: both (default, also for an empty attribute), 'position' or 'size'. */
|
|
1436
|
-
readonly motionLayout: import("@angular/core").InputSignal<boolean | "" | "position" | "
|
|
1455
|
+
readonly motionLayout: import("@angular/core").InputSignal<boolean | "" | "position" | "both" | "size">;
|
|
1437
1456
|
/** Shared layout id: an element with the same id that appears takes over from this one. */
|
|
1438
1457
|
readonly motionLayoutId: import("@angular/core").InputSignal<string | null | undefined>;
|
|
1439
1458
|
readonly layoutTransition: import("@angular/core").InputSignal<Record<string, unknown>>;
|
|
@@ -1449,10 +1468,23 @@ export declare class MotionLayoutDirective {
|
|
|
1449
1468
|
private shift;
|
|
1450
1469
|
private cur;
|
|
1451
1470
|
private controls?;
|
|
1471
|
+
private run?;
|
|
1452
1472
|
/** Measure again without animating (after a window resize). */
|
|
1453
1473
|
private resnap;
|
|
1474
|
+
/** The id this element joined the registry with. */
|
|
1475
|
+
private joined;
|
|
1476
|
+
/** Fly in from here (a viewport box) at the next update: the lead with our id went away. */
|
|
1477
|
+
private resumeFrom;
|
|
1478
|
+
/** Corner radii (px) while scaling; null when there are none to correct. */
|
|
1479
|
+
private radii;
|
|
1480
|
+
/** The element's own inline border-radius, put back afterwards. */
|
|
1481
|
+
private inlineRadius;
|
|
1454
1482
|
private readonly reduced;
|
|
1455
1483
|
constructor();
|
|
1484
|
+
/** @internal */
|
|
1485
|
+
setHidden(hidden: boolean): void;
|
|
1486
|
+
/** @internal */
|
|
1487
|
+
resume(from: Box | undefined): void;
|
|
1456
1488
|
private mode;
|
|
1457
1489
|
/** Layout box from offsets: unaffected by transforms (ours or anyone's) and by scrolling. */
|
|
1458
1490
|
private measure;
|
|
@@ -1462,6 +1494,8 @@ export declare class MotionLayoutDirective {
|
|
|
1462
1494
|
private visual;
|
|
1463
1495
|
private update;
|
|
1464
1496
|
private animateFrom;
|
|
1497
|
+
/** The element's own corner radii in px (percentages scale with the box already, so they're left alone). */
|
|
1498
|
+
private readRadii;
|
|
1465
1499
|
/**
|
|
1466
1500
|
* Set our transform. Written straight to the style (not through Motion's
|
|
1467
1501
|
* next frame), so what's drawn always matches `cur`: measuring and
|
|
@@ -1490,4 +1524,149 @@ export declare class MotionLayoutDirective {
|
|
|
1490
1524
|
"layoutAnimationComplete": "layoutAnimationComplete";
|
|
1491
1525
|
}, never, never, true, never>;
|
|
1492
1526
|
}
|
|
1527
|
+
/**
|
|
1528
|
+
* A value that changes often (every frame while something moves), like
|
|
1529
|
+
* Framer Motion's MotionValue, that is also an Angular signal.
|
|
1530
|
+
*
|
|
1531
|
+
* - Read it in a template (`{{ x() }}`) and that view updates as it changes.
|
|
1532
|
+
* - Or bind it with `[motionStyle]`: the directive listens with `on()` and
|
|
1533
|
+
* writes the style directly, so nothing re-renders while it moves.
|
|
1534
|
+
*/
|
|
1535
|
+
export interface MotionSignal<T = number> extends Signal<T> {
|
|
1536
|
+
/** The current value, without tracking it. */
|
|
1537
|
+
get(): T;
|
|
1538
|
+
/** Called synchronously on every change, outside change detection. Returns a function that stops listening. */
|
|
1539
|
+
on(listener: (value: T) => void): () => void;
|
|
1540
|
+
/** How fast it is changing, per second (numbers only; 0 once it settles). */
|
|
1541
|
+
getVelocity(): number;
|
|
1542
|
+
}
|
|
1543
|
+
export interface WritableMotionSignal<T = number> extends MotionSignal<T> {
|
|
1544
|
+
set(value: T): void;
|
|
1545
|
+
}
|
|
1546
|
+
/** A spring-driven value: `set()` springs to the new target, `jump()` goes there at once. */
|
|
1547
|
+
export interface SpringSignal extends MotionSignal<number> {
|
|
1548
|
+
set(target: number): void;
|
|
1549
|
+
jump(value: number): void;
|
|
1550
|
+
}
|
|
1551
|
+
/** Anything these functions accept as an input: a motion signal or any Angular signal. */
|
|
1552
|
+
export type MotionSource<T = number> = MotionSignal<T> | Signal<T>;
|
|
1553
|
+
export interface MotionSignalOptions {
|
|
1554
|
+
/** For calls outside an injection context (constructor or field initialiser). */
|
|
1555
|
+
injector?: Injector;
|
|
1556
|
+
}
|
|
1557
|
+
export declare function isMotionSignal<T = unknown>(value: unknown): value is MotionSignal<T>;
|
|
1558
|
+
/**
|
|
1559
|
+
* A writable motion signal (Framer Motion's `useMotionValue`).
|
|
1560
|
+
*
|
|
1561
|
+
* readonly x = motionSignal(0);
|
|
1562
|
+
* (dragMove)="x.set($event.x)"
|
|
1563
|
+
*/
|
|
1564
|
+
export declare function motionSignal<T = number>(initial: T): WritableMotionSignal<T>;
|
|
1565
|
+
/**
|
|
1566
|
+
* A value derived from others (Framer Motion's `useTransform`).
|
|
1567
|
+
*
|
|
1568
|
+
* // Map a range: -200..200 px → 0..1..0 opacity (clamped; colours and units work too)
|
|
1569
|
+
* readonly opacity = mapSignal(x, [-200, 0, 200], [0, 1, 0]);
|
|
1570
|
+
* readonly colour = mapSignal(x, [-200, 200], ['#f43f5e', '#22c55e']);
|
|
1571
|
+
*
|
|
1572
|
+
* // Or a function of one or more sources
|
|
1573
|
+
* readonly label = mapSignal(x, v => `${Math.round(v)}px`);
|
|
1574
|
+
* readonly area = mapSignal([w, h], ([w, h]) => w * h);
|
|
1575
|
+
*
|
|
1576
|
+
* Plain Angular signals are accepted as sources too; they update it on the
|
|
1577
|
+
* next change detection, so call it in an injection context for those.
|
|
1578
|
+
*/
|
|
1579
|
+
export declare function mapSignal<O>(source: MotionSource<number>, input: number[], output: O[], options?: MotionSignalOptions & {
|
|
1580
|
+
clamp?: boolean;
|
|
1581
|
+
ease?: unknown;
|
|
1582
|
+
}): MotionSignal<O>;
|
|
1583
|
+
export declare function mapSignal<I, O>(source: MotionSource<I>, map: (value: I) => O, options?: MotionSignalOptions): MotionSignal<O>;
|
|
1584
|
+
export declare function mapSignal<O>(sources: MotionSource<any>[], map: (values: any[]) => O, options?: MotionSignalOptions): MotionSignal<O>;
|
|
1585
|
+
/**
|
|
1586
|
+
* A value that follows a target on a spring (Framer Motion's `useSpring`).
|
|
1587
|
+
*
|
|
1588
|
+
* // Springs towards whatever it's set to
|
|
1589
|
+
* readonly count = springSignal(0, { stiffness: 120, damping: 20 });
|
|
1590
|
+
* count.set(1200);
|
|
1591
|
+
*
|
|
1592
|
+
* // Or follows another value, smoothing it out
|
|
1593
|
+
* readonly smoothX = springSignal(x);
|
|
1594
|
+
*
|
|
1595
|
+
* Keeps its speed when the target changes mid-way. With reduced motion (and
|
|
1596
|
+
* on the server) it goes straight to the target. Call it in an injection
|
|
1597
|
+
* context, or pass `injector`.
|
|
1598
|
+
*/
|
|
1599
|
+
export declare function springSignal(source: number | MotionSource<number>, options?: MotionSignalOptions & {
|
|
1600
|
+
stiffness?: number;
|
|
1601
|
+
damping?: number;
|
|
1602
|
+
mass?: number;
|
|
1603
|
+
restDelta?: number;
|
|
1604
|
+
restSpeed?: number;
|
|
1605
|
+
}): SpringSignal;
|
|
1606
|
+
/**
|
|
1607
|
+
* How fast another value is changing, per second (Framer Motion's
|
|
1608
|
+
* `useVelocity`); back to 0 once it stops. Call it in an injection context,
|
|
1609
|
+
* or pass `injector`.
|
|
1610
|
+
*
|
|
1611
|
+
* readonly speed = velocitySignal(scrollY);
|
|
1612
|
+
* readonly skew = mapSignal(speed, [-2000, 2000], [-8, 8]);
|
|
1613
|
+
*/
|
|
1614
|
+
export declare function velocitySignal(source: MotionSignal<number>, options?: MotionSignalOptions): MotionSignal<number>;
|
|
1615
|
+
export interface ScrollSignals {
|
|
1616
|
+
/** 0 to 1 through the scroll range. */
|
|
1617
|
+
progress: MotionSignal<number>;
|
|
1618
|
+
/** Scroll position in px. */
|
|
1619
|
+
offset: MotionSignal<number>;
|
|
1620
|
+
/** Scroll speed in px per second. */
|
|
1621
|
+
velocity: MotionSignal<number>;
|
|
1622
|
+
}
|
|
1623
|
+
type ElementSource = Element | ElementRef<Element> | (() => Element | ElementRef<Element> | null | undefined) | null | undefined;
|
|
1624
|
+
/**
|
|
1625
|
+
* Scroll position as motion signals (Framer Motion's `useScroll`). The page by
|
|
1626
|
+
* default; pass a scrolling `container` and/or a `target` element whose
|
|
1627
|
+
* progress through it you want (with `offset`). Element options can be
|
|
1628
|
+
* functions, so `viewChild` signals work. Call it in an injection context, or
|
|
1629
|
+
* pass `injector`.
|
|
1630
|
+
*
|
|
1631
|
+
* readonly scrollY = scrollSignal();
|
|
1632
|
+
* readonly width = mapSignal(this.scrollY.progress, [0, 1], ['0%', '100%']);
|
|
1633
|
+
*/
|
|
1634
|
+
export declare function scrollSignal(options?: MotionSignalOptions & {
|
|
1635
|
+
container?: ElementSource;
|
|
1636
|
+
target?: ElementSource;
|
|
1637
|
+
offset?: string[];
|
|
1638
|
+
axis?: 'x' | 'y';
|
|
1639
|
+
}): ScrollSignals;
|
|
1640
|
+
export type MotionStyleValue = MotionSignal<number | string> | (() => number | string) | number | string | null | undefined;
|
|
1641
|
+
/**
|
|
1642
|
+
* Binds styles to motion signals (Framer Motion's `style={{ x, opacity }}`).
|
|
1643
|
+
* Each change is written straight to the element, without change detection,
|
|
1644
|
+
* so values that change every frame cost nothing to render.
|
|
1645
|
+
*
|
|
1646
|
+
* <div [motionStyle]="{ x: smoothX, rotate: tilt, opacity: fade, backgroundColor: colour }"></div>
|
|
1647
|
+
*
|
|
1648
|
+
* - Transform shortcuts: x, y, z (px), scale, scaleX, scaleY, rotate,
|
|
1649
|
+
* rotateX/Y/Z, skewX/Y (deg). They are combined into `transform`, so don't
|
|
1650
|
+
* animate the same element's transform another way.
|
|
1651
|
+
* - Other styles take camelCase names; numbers get px except unitless ones
|
|
1652
|
+
* (opacity, zIndex, …). CSS custom properties (`'--progress'`) take any value.
|
|
1653
|
+
* - Values can be motion signals, plain Angular signals (updated with change
|
|
1654
|
+
* detection) or constants.
|
|
1655
|
+
*/
|
|
1656
|
+
export declare class MotionStyleDirective {
|
|
1657
|
+
readonly motionStyle: import("@angular/core").InputSignal<Record<string, MotionStyleValue> | null>;
|
|
1658
|
+
private readonly el;
|
|
1659
|
+
private readonly transform;
|
|
1660
|
+
constructor();
|
|
1661
|
+
private write;
|
|
1662
|
+
private transformString;
|
|
1663
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MotionStyleDirective, never>;
|
|
1664
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<MotionStyleDirective, "[motionStyle]", never, {
|
|
1665
|
+
"motionStyle": {
|
|
1666
|
+
"alias": "motionStyle";
|
|
1667
|
+
"required": false;
|
|
1668
|
+
"isSignal": true;
|
|
1669
|
+
};
|
|
1670
|
+
}, {}, never, never, true, never>;
|
|
1671
|
+
}
|
|
1493
1672
|
export type { TimelineStep, TransitionOptions, VariantWithTransition };
|