ngx-countdown
Version:
Simple, easy and performance countdown for angular
149 lines (142 loc) • 4.77 kB
TypeScript
import * as i0 from '@angular/core';
import { OnInit, OnChanges, OnDestroy, TemplateRef, EventEmitter, SimpleChange, SimpleChanges, InjectionToken, EnvironmentProviders } from '@angular/core';
type CountdownFormatFn = (opt: CountdownFormatFnOption) => string;
interface CountdownFormatFnOption {
date: number;
formatStr: string;
timezone?: string;
}
declare enum CountdownStatus {
ing = 0,
pause = 1,
stop = 2,
done = 3
}
interface CountdownConfig {
/**
* Start the counter on demand, must call `begin()` to starting, Default: `false`
*/
demand?: boolean;
/**
* Calculate the remaining time based on the server, e.g: `10`,`5.5`, (Unit: seconds)
*/
leftTime?: number;
/**
* Refers to counting down from local time to end time (Unit: Milliseconds second UNIX timestamp)
*/
stopTime?: number;
/**
* Formats a date value, pls refer to [Accepted patterns](https://angular.io/api/common/DatePipe#usage-notes), Default: `HH:mm:ss`
*/
format?: string;
/**
* Beautify text, generally used to convert formatted time text into HTML
*/
prettyText?: (text: string) => string;
/**
* Should be trigger type `notify` event on the x second. When values is `0` will be trigger every time.
*/
notify?: number[] | number;
/**
* Default based on the implementation of `formatDate` in `@angular/common`
*
* You can changed to other libs, e.g: [date-fns](https://date-fns.org/v2.0.1/docs/format)
*/
formatDate?: CountdownFormatFn;
/**
* A timezone offset (such as '+0430'), or a standard UTC/GMT.
* When not supplied, uses the end-user's local system timezone, Default: `+0000`
*/
timezone?: string;
}
type CountdownEventAction = 'start' | 'stop' | 'restart' | 'pause' | 'resume' | 'notify' | 'done';
interface CountdownEvent {
action: CountdownEventAction;
status: CountdownStatus;
left: number;
text: string;
}
interface CountdownItem {
text?: string;
value?: number;
}
declare class CountdownComponent implements OnInit, OnChanges, OnDestroy {
private locale;
private timer;
private cdr;
private ngZone;
private defCog;
private frequency;
private _notify;
private status;
private isDestroy;
private _config;
i: CountdownItem;
left: number;
set config(i: CountdownConfig);
get config(): CountdownConfig;
render?: TemplateRef<{
$implicit: CountdownItem;
}>;
readonly event: EventEmitter<CountdownEvent>;
/**
* Start countdown, you must manually call when `demand: false`
*/
begin(): void;
/**
* Restart countdown
*/
restart(): void;
/**
* Stop countdown, must call `restart` when stopped, it's different from pause, unable to recover
*/
stop(): void;
/**
* Pause countdown, you can use `resume` to recover again
*/
pause(): void;
/**
* Resume countdown
*/
resume(): void;
private callEvent;
private init;
private destroy;
/**
* 更新时钟
*/
private reflow;
/**
* 获取倒计时剩余帧数
*/
private getLeft;
ngOnInit(): void;
ngOnDestroy(): void;
ngOnChanges(changes: {
[P in keyof this]?: SimpleChange;
} & SimpleChanges): void;
static ɵfac: i0.ɵɵFactoryDeclaration<CountdownComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<CountdownComponent, "countdown", never, { "config": { "alias": "config"; "required": true; }; "render": { "alias": "render"; "required": false; }; }, { "event": "event"; }, never, never, true, never>;
}
declare class CountdownTimer {
private ngZone;
private fns;
private commands;
private nextTime;
private ing;
start(): void;
private process;
add(fn: () => void, frequency: number): this;
remove(fn: () => void): this;
static ɵfac: i0.ɵɵFactoryDeclaration<CountdownTimer, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<CountdownTimer>;
}
declare class CountdownModule {
static ɵfac: i0.ɵɵFactoryDeclaration<CountdownModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<CountdownModule, never, [typeof CountdownComponent], [typeof CountdownComponent]>;
static ɵinj: i0.ɵɵInjectorDeclaration<CountdownModule>;
}
declare const COUNTDOWN_CONFIG: InjectionToken<CountdownConfig>;
declare function provideCountdown(config?: CountdownConfig): EnvironmentProviders;
export { COUNTDOWN_CONFIG, CountdownComponent, CountdownModule, CountdownStatus, CountdownTimer, provideCountdown };
export type { CountdownConfig, CountdownEvent, CountdownEventAction, CountdownFormatFn, CountdownFormatFnOption, CountdownItem };