ngx-sparklefall
Version:
Angular directive and component for SparkleFall - Beautiful falling sparkle animations
137 lines (136 loc) • 4.56 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Component, ElementRef, EventEmitter, Input, Output } from '@angular/core';
import SparkleFallCore from 'sparklefall';
let SparkleFallComponent = class SparkleFallComponent {
host;
sparkles = ['✨', '⭐', '💫', '🌟'];
colors = null;
interval = 800;
minSize = 10;
maxSize = 30;
minDuration = 2;
maxDuration = 5;
wind = 0;
spin = true;
maxSparkles = 50;
autoStart = true;
zIndex = 9999;
paused = false;
sparkleStart = new EventEmitter();
sparkleStop = new EventEmitter();
instance;
constructor(host) {
this.host = host;
}
ngOnInit() {
const container = this.host.nativeElement;
this.instance = new SparkleFallCore({
container,
sparkles: this.sparkles,
colors: this.colors,
interval: this.interval,
minSize: this.minSize,
maxSize: this.maxSize,
minDuration: this.minDuration,
maxDuration: this.maxDuration,
wind: this.wind,
spin: this.spin,
maxSparkles: this.maxSparkles,
autoStart: this.autoStart,
zIndex: this.zIndex,
});
if (!this.paused) {
this.instance.start();
this.sparkleStart.emit();
}
}
ngOnDestroy() {
if (this.instance) {
this.instance.destroy();
this.instance = null;
this.sparkleStop.emit();
}
}
// API methods
start() { this.instance?.start(); this.sparkleStart.emit(); }
stop() { this.instance?.stop(); this.sparkleStop.emit(); }
clear() { this.instance?.clear(); }
burst(count) { this.instance?.burst(count); }
};
__decorate([
Input(),
__metadata("design:type", Array)
], SparkleFallComponent.prototype, "sparkles", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "colors", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "interval", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "minSize", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "maxSize", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "minDuration", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "maxDuration", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "wind", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "spin", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "maxSparkles", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "autoStart", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "zIndex", void 0);
__decorate([
Input(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "paused", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "sparkleStart", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], SparkleFallComponent.prototype, "sparkleStop", void 0);
SparkleFallComponent = __decorate([
Component({
selector: 'sparkle-fall',
standalone: true,
template: `<ng-content></ng-content>`,
}),
__metadata("design:paramtypes", [ElementRef])
], SparkleFallComponent);
export { SparkleFallComponent };