/** * Animated figure. * * @augments IvComponent */ export class Countup extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Countup|undefined} The instance or `undefined`. */ static get(el: Element): Countup | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Countup} The instance. */ static getOrCreate(el: Element, options?: Partial): Countup; /** * Instantiates every `[data-iv-component="countup"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Countup[]} Newly created instances. */ static initAll(root?: ParentNode): Countup[]; /** * @param {Element} el Element holding the figure. * @param {Partial} [options] Options passed in JavaScript. */ constructor(el: Element, options?: Partial); /** @type {string} The served text, the figure to reach. */ _text: string; /** @type {ChildNode[]} The served nodes, put back on every end. */ _served: ChildNode[]; /** @type {string} Text before the number. */ _prefix: string; /** @type {string} Text after the number. */ _suffix: string; /** @type {number} The figure as served. */ _to: number; /** @type {number} Decimal places in use. */ _decimals: number; /** @type {number} The number currently rendered. */ _value: number; /** @type {boolean} Whether a count has finished. */ _done: boolean; /** @type {boolean} Whether the served text carries a number at all. */ _parsed: boolean; /** @type {Intl.NumberFormat|null} Formatter for the frames. */ _format: Intl.NumberFormat | null; /** @type {IntersectionObserver|null} The observer, when there is one. */ _observer: IntersectionObserver | null; /** @type {number} Pending animation frame. */ _frame: number; /** @type {number} Timestamp of the first frame; `-1` before it arrives. */ _start: number; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * The number currently rendered. * * @returns {number} The value on screen. */ get value(): number; /** * Whether the count has finished. A figure that never counts (reduced * motion, no observer, no number in the text) is done from the start: what * it shows is already the final value. * * @returns {boolean} `true` when nothing is left to count. */ get done(): boolean; /** * The figure as served. * * @returns {number} The target value. */ get to(): number; /** * Whether this figure must stay still: reduced motion is a request, not a * preference to negotiate. * * @returns {boolean} `true` when nothing may animate. */ _still(): boolean; /** * Reacts to the observer. * * @param {IntersectionObserverEntry[]} entries Reported entries. * @returns {void} */ _onIntersect(entries: IntersectionObserverEntry[]): void; /** * Counts from `from` to the served figure. * * @returns {void} */ start(): void; /** * Puts the served figure back so it can count again. * * @returns {void} */ reset(): void; /** * Puts the served nodes back, exactly the ones the page shipped. * * @returns {void} */ _restore(): void; /** * Writes one frame. * * @param {number} value Number to render. * @returns {void} */ _render(value: number): void; /** * Ends the count on the served text, exactly as it was written. * * @returns {void} */ _finish(): void; /** * Stops a running count without touching the text. * * @returns {void} */ _cancel(): void; } export type CountupOptions = { /** * Where the count starts. */ from: number; /** * Length of the count in milliseconds. */ duration: number; /** * Decimal places; `-1` takes them from the figure. */ decimals: number; /** * Whether thousands are grouped while counting. */ grouping: boolean; /** * Whether the count runs only the first time. */ once: boolean; /** * Whether it counts at `init` instead of in view. */ autostart: boolean; }; import { IvComponent } from "../core/component.js";