UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

401 lines (400 loc) • 13 kB
import { coerceCssPixelValue } from "@angular/cdk/coercion"; import * as i0 from "@angular/core"; import { ANIMATION_MODULE_TYPE, Directive, ElementRef, Injectable, NgModule, assertInInjectionContext, booleanAttribute, computed, effect, inject, input, signal } from "@angular/core"; import { Subject } from "rxjs"; import { debounceTime, take } from "rxjs/operators"; import { requestAnimationFrame } from "ng-zorro-antd/core/polyfill"; var AnimationDuration = class { static SLOW = "0.3s"; static BASE = "0.2s"; static FAST = "0.1s"; }; var AnimationCurves = class { static EASE_BASE_OUT = "cubic-bezier(0.7, 0.3, 0.1, 1)"; static EASE_BASE_IN = "cubic-bezier(0.9, 0, 0.3, 0.7)"; static EASE_OUT = "cubic-bezier(0.215, 0.61, 0.355, 1)"; static EASE_IN = "cubic-bezier(0.55, 0.055, 0.675, 0.19)"; static EASE_IN_OUT = "cubic-bezier(0.645, 0.045, 0.355, 1)"; static EASE_OUT_BACK = "cubic-bezier(0.12, 0.4, 0.29, 1.46)"; static EASE_IN_BACK = "cubic-bezier(0.71, -0.46, 0.88, 0.6)"; static EASE_IN_OUT_BACK = "cubic-bezier(0.71, -0.46, 0.29, 1.46)"; static EASE_OUT_CIRC = "cubic-bezier(0.08, 0.82, 0.17, 1)"; static EASE_IN_CIRC = "cubic-bezier(0.6, 0.04, 0.98, 0.34)"; static EASE_IN_OUT_CIRC = "cubic-bezier(0.78, 0.14, 0.15, 0.86)"; static EASE_OUT_QUINT = "cubic-bezier(0.23, 1, 0.32, 1)"; static EASE_IN_QUINT = "cubic-bezier(0.755, 0.05, 0.855, 0.06)"; static EASE_IN_OUT_QUINT = "cubic-bezier(0.86, 0, 0.07, 1)"; }; const NZ_NO_ANIMATION_CLASS = "nz-animate-disabled"; var NzNoAnimationDirective = class NzNoAnimationDirective { animationType = inject(ANIMATION_MODULE_TYPE, { optional: true }); nzNoAnimation = input(false, { ...ngDevMode ? { debugName: "nzNoAnimation" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzNoAnimationDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.2", type: NzNoAnimationDirective, isStandalone: true, selector: "[nzNoAnimation]", inputs: { nzNoAnimation: { classPropertyName: "nzNoAnimation", publicName: "nzNoAnimation", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.nz-animate-disabled": "nzNoAnimation() || animationType === 'NoopAnimations'" } }, exportAs: ["nzNoAnimation"], ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzNoAnimationDirective, decorators: [{ type: Directive, args: [{ selector: "[nzNoAnimation]", exportAs: "nzNoAnimation", host: { [`[class.${NZ_NO_ANIMATION_CLASS}]`]: `nzNoAnimation() || animationType === 'NoopAnimations'` } }] }], propDecorators: { nzNoAnimation: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzNoAnimation", required: false }] }] } }); var NzNoAnimationModule = class NzNoAnimationModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzNoAnimationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzNoAnimationModule, imports: [NzNoAnimationDirective], exports: [NzNoAnimationDirective] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzNoAnimationModule }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzNoAnimationModule, decorators: [{ type: NgModule, args: [{ imports: [NzNoAnimationDirective], exports: [NzNoAnimationDirective] }] }] }); function provideNzNoAnimation() { return [{ provide: ANIMATION_MODULE_TYPE, useValue: "NoopAnimations" }]; } function _internalAnimationEnabled() { return inject(ANIMATION_MODULE_TYPE, { optional: true }) !== "NoopAnimations"; } function isAnimationEnabled(getter) { if (typeof ngDevMode !== "undefined" && ngDevMode) assertInInjectionContext(isAnimationEnabled); return _internalAnimationEnabled() ? computed(getter) : signal(false); } function withAnimationCheck(classNameGetter) { if (typeof ngDevMode !== "undefined" && ngDevMode) assertInInjectionContext(withAnimationCheck); return _internalAnimationEnabled() ? computed(classNameGetter) : signal(NZ_NO_ANIMATION_CLASS); } const COLLAPSE_MOTION_CLASS = "ant-motion-collapse"; var NzAnimationCollapseDirective = class NzAnimationCollapseDirective { elementRef = inject(ElementRef); noAnimation = inject(NzNoAnimationDirective, { optional: true, host: true }); animationEnabled = isAnimationEnabled(() => !this.noAnimation?.nzNoAnimation()); open = input(false, ...ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []); leavedClassName = input("", ...ngDevMode ? [{ debugName: "leavedClassName" }] : /* istanbul ignore next */ []); firstRender = true; constructor() { effect(() => { const open = this.open(); const animationEnabled = this.animationEnabled() && !this.firstRender; const element = this.elementRef.nativeElement; const leavedClassName = this.leavedClassName(); if (open && leavedClassName) element.classList.remove(leavedClassName); if (animationEnabled) { element.classList.add(COLLAPSE_MOTION_CLASS); if (open) requestAnimationFrame(() => { const scrollHeight = this.getActualScrollHeight(element); element.style.height = coerceCssPixelValue(scrollHeight); element.style.opacity = "1"; }); else { const scrollHeight = this.getActualScrollHeight(element); element.style.height = coerceCssPixelValue(scrollHeight); requestAnimationFrame(() => { element.style.height = coerceCssPixelValue(0); element.style.opacity = "0"; }); } } else if (open) { element.style.height = "auto"; element.style.opacity = "1"; } else { element.style.height = coerceCssPixelValue(0); element.style.opacity = "0"; if (leavedClassName) element.classList.add(leavedClassName); } this.firstRender = false; }); } getActualScrollHeight(element) { return Array.from(element.children).reduce((acc, child) => acc + child.offsetHeight, 0); } onTransitionEnd(event) { if (!this.animationEnabled() || event.target !== this.elementRef.nativeElement) return; if (this.open()) this.elementRef.nativeElement.style.height = "auto"; else if (this.leavedClassName()) this.elementRef.nativeElement.classList.add(this.leavedClassName()); this.elementRef.nativeElement.classList.remove(COLLAPSE_MOTION_CLASS); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationCollapseDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.2", type: NzAnimationCollapseDirective, isStandalone: true, selector: "[animation-collapse]", inputs: { open: { classPropertyName: "open", publicName: "open", isSignal: true, isRequired: false, transformFunction: null }, leavedClassName: { classPropertyName: "leavedClassName", publicName: "leavedClassName", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "transitionend": "onTransitionEnd($event)" } }, ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationCollapseDirective, decorators: [{ type: Directive, args: [{ selector: "[animation-collapse]", host: { "(transitionend)": "onTransitionEnd($event)" } }] }], ctorParameters: () => [], propDecorators: { open: [{ type: i0.Input, args: [{ isSignal: true, alias: "open", required: false }] }], leavedClassName: [{ type: i0.Input, args: [{ isSignal: true, alias: "leavedClassName", required: false }] }] } }); var NzAnimationTreeCollapseService = class NzAnimationTreeCollapseService { firstRender = true; virtualScroll = false; animationDone$ = new Subject(); constructor() { this.animationDone$.pipe(debounceTime(50), take(1)).subscribe(() => { this.firstRender = false; }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationTreeCollapseService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationTreeCollapseService }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationTreeCollapseService, decorators: [{ type: Injectable }], ctorParameters: () => [] }); var NzAnimationTreeCollapseDirective = class NzAnimationTreeCollapseDirective { treeCollapseService = inject(NzAnimationTreeCollapseService, { optional: true }); noAnimation = inject(NzNoAnimationDirective, { optional: true, host: true }); animationEnabled = isAnimationEnabled(() => !this.noAnimation?.nzNoAnimation() && !(this.treeCollapseService?.virtualScroll ?? false)); get firstRender() { return this.treeCollapseService?.firstRender ?? false; } onAnimationEnter(event) { if (!this.animationEnabled() || this.firstRender) { this.treeCollapseService?.animationDone$.next(); event.animationComplete(); return; } const element = event.target; element.style.height = coerceCssPixelValue(0); element.style.opacity = "0"; element.classList.add(COLLAPSE_MOTION_CLASS); const onTransitionEnd = (e) => { if (e.propertyName !== "height") return; element.removeEventListener("transitionend", onTransitionEnd); element.style.height = "auto"; element.classList.remove(COLLAPSE_MOTION_CLASS); event.animationComplete(); }; requestAnimationFrame(() => { element.style.height = coerceCssPixelValue(element.scrollHeight); element.style.opacity = "1"; }); element.addEventListener("transitionend", onTransitionEnd); } onAnimationLeave(event) { if (!this.animationEnabled()) { event.animationComplete(); return; } const element = event.target; element.style.height = coerceCssPixelValue(element.scrollHeight); element.style.opacity = "1"; element.classList.add(COLLAPSE_MOTION_CLASS); const onTransitionEnd = (e) => { if (e.propertyName !== "height") return; element.removeEventListener("transitionend", onTransitionEnd); event.animationComplete(); }; requestAnimationFrame(() => { element.style.height = coerceCssPixelValue(0); element.style.opacity = "0"; element.style.marginBottom = "0"; }); element.addEventListener("transitionend", onTransitionEnd); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationTreeCollapseDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzAnimationTreeCollapseDirective, isStandalone: true, selector: "[animation-tree-collapse]", host: { listeners: { "animate.enter": "onAnimationEnter($event)", "animate.leave": "onAnimationLeave($event)" } }, ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzAnimationTreeCollapseDirective, decorators: [{ type: Directive, args: [{ selector: "[animation-tree-collapse]", host: { "(animate.enter)": "onAnimationEnter($event)", "(animate.leave)": "onAnimationLeave($event)" } }] }] }); const SLIDE_UP_ANIMATION_CLASS = { enter: "ant-slide-up-enter ant-slide-up-enter-active", leave: "ant-slide-up-leave ant-slide-up-leave-active" }; const SLIDE_DOWN_ANIMATION_CLASS = { enter: "ant-slide-down-enter ant-slide-down-enter-active", leave: "ant-slide-down-leave ant-slide-down-leave-active" }; function slideAnimationEnter(directionFn = () => "up") { return withAnimationCheck(() => { if (directionFn() === "up") return SLIDE_UP_ANIMATION_CLASS.enter; else return SLIDE_DOWN_ANIMATION_CLASS.enter; }); } function slideAnimationLeave(directionFn = () => "up") { return withAnimationCheck(() => { if (directionFn() === "up") return SLIDE_UP_ANIMATION_CLASS.leave; else return SLIDE_DOWN_ANIMATION_CLASS.leave; }); } export { AnimationCurves, AnimationDuration, NZ_NO_ANIMATION_CLASS, NzAnimationCollapseDirective, NzAnimationTreeCollapseDirective, NzAnimationTreeCollapseService, NzNoAnimationDirective, NzNoAnimationModule, SLIDE_DOWN_ANIMATION_CLASS, SLIDE_UP_ANIMATION_CLASS, isAnimationEnabled, provideNzNoAnimation, slideAnimationEnter, slideAnimationLeave, withAnimationCheck }; //# sourceMappingURL=ng-zorro-antd-core-animation.mjs.map