@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/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 {
|
|
@@ -1524,4 +1524,151 @@ export declare class MotionLayoutDirective implements Member {
|
|
|
1524
1524
|
"layoutAnimationComplete": "layoutAnimationComplete";
|
|
1525
1525
|
}, never, never, true, never>;
|
|
1526
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
|
+
* - SVG line drawing: pathLength, pathOffset, pathSpacing (0 to 1), e.g.
|
|
1652
|
+
* `{ pathLength: scroll.progress }` draws a line as the page scrolls.
|
|
1653
|
+
* - Other styles take camelCase names; numbers get px except unitless ones
|
|
1654
|
+
* (opacity, zIndex, …). CSS custom properties (`'--progress'`) take any value.
|
|
1655
|
+
* - Values can be motion signals, plain Angular signals (updated with change
|
|
1656
|
+
* detection) or constants.
|
|
1657
|
+
*/
|
|
1658
|
+
export declare class MotionStyleDirective {
|
|
1659
|
+
readonly motionStyle: import("@angular/core").InputSignal<Record<string, MotionStyleValue> | null>;
|
|
1660
|
+
private readonly el;
|
|
1661
|
+
private readonly transform;
|
|
1662
|
+
constructor();
|
|
1663
|
+
private write;
|
|
1664
|
+
private transformString;
|
|
1665
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MotionStyleDirective, never>;
|
|
1666
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<MotionStyleDirective, "[motionStyle]", never, {
|
|
1667
|
+
"motionStyle": {
|
|
1668
|
+
"alias": "motionStyle";
|
|
1669
|
+
"required": false;
|
|
1670
|
+
"isSignal": true;
|
|
1671
|
+
};
|
|
1672
|
+
}, {}, never, never, true, never>;
|
|
1673
|
+
}
|
|
1527
1674
|
export type { TimelineStep, TransitionOptions, VariantWithTransition };
|