Icard/angular-clarity-master(work.../node_modules/primeng/esm2022/ripple/ripple.mjs

141 lines
18 KiB
JavaScript
Raw Normal View History

2024-07-16 14:55:36 +00:00
import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';
import { Directive, Inject, NgModule, Optional, PLATFORM_ID } from '@angular/core';
import { DomHandler } from 'primeng/dom';
import * as i0 from "@angular/core";
import * as i1 from "primeng/api";
/**
* Ripple directive adds ripple effect to the host element.
* @group Components
*/
export class Ripple {
document;
platformId;
renderer;
el;
zone;
config;
constructor(document, platformId, renderer, el, zone, config) {
this.document = document;
this.platformId = platformId;
this.renderer = renderer;
this.el = el;
this.zone = zone;
this.config = config;
}
animationListener;
mouseDownListener;
timeout;
ngAfterViewInit() {
if (isPlatformBrowser(this.platformId)) {
if (this.config && this.config.ripple) {
this.zone.runOutsideAngular(() => {
this.create();
this.mouseDownListener = this.renderer.listen(this.el.nativeElement, 'mousedown', this.onMouseDown.bind(this));
});
}
}
}
onMouseDown(event) {
let ink = this.getInk();
if (!ink || this.document.defaultView?.getComputedStyle(ink, null).display === 'none') {
return;
}
DomHandler.removeClass(ink, 'p-ink-active');
if (!DomHandler.getHeight(ink) && !DomHandler.getWidth(ink)) {
let d = Math.max(DomHandler.getOuterWidth(this.el.nativeElement), DomHandler.getOuterHeight(this.el.nativeElement));
ink.style.height = d + 'px';
ink.style.width = d + 'px';
}
let offset = DomHandler.getOffset(this.el.nativeElement);
let x = event.pageX - offset.left + this.document.body.scrollTop - DomHandler.getWidth(ink) / 2;
let y = event.pageY - offset.top + this.document.body.scrollLeft - DomHandler.getHeight(ink) / 2;
this.renderer.setStyle(ink, 'top', y + 'px');
this.renderer.setStyle(ink, 'left', x + 'px');
DomHandler.addClass(ink, 'p-ink-active');
this.timeout = setTimeout(() => {
let ink = this.getInk();
if (ink) {
DomHandler.removeClass(ink, 'p-ink-active');
}
}, 401);
}
getInk() {
const children = this.el.nativeElement.children;
for (let i = 0; i < children.length; i++) {
if (typeof children[i].className === 'string' && children[i].className.indexOf('p-ink') !== -1) {
return children[i];
}
}
return null;
}
resetInk() {
let ink = this.getInk();
if (ink) {
DomHandler.removeClass(ink, 'p-ink-active');
}
}
onAnimationEnd(event) {
if (this.timeout) {
clearTimeout(this.timeout);
}
DomHandler.removeClass(event.currentTarget, 'p-ink-active');
}
create() {
let ink = this.renderer.createElement('span');
this.renderer.addClass(ink, 'p-ink');
this.renderer.appendChild(this.el.nativeElement, ink);
this.renderer.setAttribute(ink, 'aria-hidden', 'true');
this.renderer.setAttribute(ink, 'role', 'presentation');
if (!this.animationListener) {
this.animationListener = this.renderer.listen(ink, 'animationend', this.onAnimationEnd.bind(this));
}
}
remove() {
let ink = this.getInk();
if (ink) {
this.mouseDownListener && this.mouseDownListener();
this.animationListener && this.animationListener();
this.mouseDownListener = null;
this.animationListener = null;
DomHandler.removeElement(ink);
}
}
ngOnDestroy() {
if (this.config && this.config.ripple) {
this.remove();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Ripple, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }, { token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i0.NgZone }, { token: i1.PrimeNGConfig, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.7", type: Ripple, selector: "[pRipple]", host: { classAttribute: "p-ripple p-element" }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Ripple, decorators: [{
type: Directive,
args: [{
selector: '[pRipple]',
host: {
class: 'p-ripple p-element'
}
}]
}], ctorParameters: () => [{ type: Document, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: undefined, decorators: [{
type: Inject,
args: [PLATFORM_ID]
}] }, { type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i0.NgZone }, { type: i1.PrimeNGConfig, decorators: [{
type: Optional
}] }] });
export class RippleModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: RippleModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: RippleModule, declarations: [Ripple], imports: [CommonModule], exports: [Ripple] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: RippleModule, imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: RippleModule, decorators: [{
type: NgModule,
args: [{
imports: [CommonModule],
exports: [Ripple],
declarations: [Ripple]
}]
}] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmlwcGxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwcC9jb21wb25lbnRzL3JpcHBsZS9yaXBwbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxRQUFRLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUM1RSxPQUFPLEVBQWlCLFNBQVMsRUFBYyxNQUFNLEVBQUUsUUFBUSxFQUFxQixRQUFRLEVBQUUsV0FBVyxFQUFhLE1BQU0sZUFBZSxDQUFDO0FBRTVJLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxhQUFhLENBQUM7OztBQUV6Qzs7O0dBR0c7QUFPSCxNQUFNLE9BQU8sTUFBTTtJQUN1QjtJQUFpRDtJQUF5QjtJQUE0QjtJQUF1QjtJQUFpQztJQUFwTSxZQUFzQyxRQUFrQixFQUErQixVQUFlLEVBQVUsUUFBbUIsRUFBUyxFQUFjLEVBQVMsSUFBWSxFQUFxQixNQUFxQjtRQUFuTCxhQUFRLEd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