import { ɵAnimationEngine as AnimationEngine } from '@angular/animations/browser'; import { Injectable, NgZone, RendererFactory2 } from '@angular/core'; import * as i0 from "@angular/core"; import * as i1 from "@angular/animations/browser"; const ANIMATION_PREFIX = '@'; const DISABLE_ANIMATIONS_FLAG = '@.disabled'; export class AnimationRendererFactory { constructor(delegate, engine, _zone) { this.delegate = delegate; this.engine = engine; this._zone = _zone; this._currentId = 0; this._microtaskId = 1; this._animationCallbacksBuffer = []; this._rendererCache = new Map(); this._cdRecurDepth = 0; engine.onRemovalComplete = (element, delegate) => { // Note: if a component element has a leave animation, and a host leave animation, // the view engine will call `removeChild` for the parent // component renderer as well as for the child component renderer. // Therefore, we need to check if we already removed the element. const parentNode = delegate?.parentNode(element); if (parentNode) { delegate.removeChild(parentNode, element); } }; } createRenderer(hostElement, type) { const EMPTY_NAMESPACE_ID = ''; // cache the delegates to find out which cached delegate can // be used by which cached renderer const delegate = this.delegate.createRenderer(hostElement, type); if (!hostElement || !type || !type.data || !type.data['animation']) { let renderer = this._rendererCache.get(delegate); if (!renderer) { // Ensure that the renderer is removed from the cache on destroy // since it may contain references to detached DOM nodes. const onRendererDestroy = () => this._rendererCache.delete(delegate); renderer = new BaseAnimationRenderer(EMPTY_NAMESPACE_ID, delegate, this.engine, onRendererDestroy); // only cache this result when the base renderer is used this._rendererCache.set(delegate, renderer); } return renderer; } const componentId = type.id; const namespaceId = type.id + '-' + this._currentId; this._currentId++; this.engine.register(namespaceId, hostElement); const registerTrigger = (trigger) => { if (Array.isArray(trigger)) { trigger.forEach(registerTrigger); } else { this.engine.registerTrigger(componentId, namespaceId, hostElement, trigger.name, trigger); } }; const animationTriggers = type.data['animation']; animationTriggers.forEach(registerTrigger); return new AnimationRenderer(this, namespaceId, delegate, this.engine); } begin() { this._cdRecurDepth++; if (this.delegate.begin) { this.delegate.begin(); } } _scheduleCountTask() { queueMicrotask(() => { this._microtaskId++; }); } /** @internal */ scheduleListenerCallback(count, fn, data) { if (count >= 0 && count < this._microtaskId) { this._zone.run(() => fn(data)); return; } if (this._animationCallbacksBuffer.length == 0) { queueMicrotask(() => { this._zone.run(() => { this._animationCallbacksBuffer.forEach(tuple => { const [fn, data] = tuple; fn(data); }); this._animationCallbacksBuffer = []; }); }); } this._animationCallbacksBuffer.push([fn, data]); } end() { this._cdRecurDepth--; // this is to prevent animations from running twice when an inner // component does CD when a parent component instead has inserted it if (this._cdRecurDepth == 0) { this._zone.runOutsideAngular(() => { this._scheduleCountTask(); this.engine.flush(this._microtaskId); }); } if (this.delegate.end) { this.delegate.end(); } } whenRenderingDone() { return this.engine.whenRenderingDone(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AnimationRendererFactory, deps: [{ token: i0.RendererFactory2 }, { token: i1.ɵAnimationEngine }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AnimationRendererFactory }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AnimationRendererFactory, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i0.RendererFactory2 }, { type: i1.ɵAnimationEngine }, { type: i0.NgZone }]; } }); export class BaseAnimationRenderer { constructor(namespaceId, delegate, engine, _onDestroy) { this.namespaceId = namespaceId; this.delegate = delegate; this.engine = engine; this._onDestroy = _onDestroy; } get data() { return this.delegate.data; } destroyNode(node) { this.delegate.destroyNode?.(node); } destroy() { this.engine.destroy(this.namespaceId, this.delegate); this.engine.afterFlushAnimationsDone(() => { // Call the renderer destroy method after the animations has finished as otherwise // styles will be removed too early which will cause an unstyled animation. queueMicrotask(() => { this.delegate.destroy(); }); }); this._onDestroy?.(); } createElement(name, namespace) { return this.delegate.createElement(name, namespace); } createComment(value) { return this.delegate.createComment(value); } createText(value) { return this.delegate.createText(value); } appendChild(parent, newChild) { this.delegate.appendChild(parent, newChild); this.engine.onInsert(this.namespaceId, newChild, parent, false); } insertBefore(parent, newChild, refChild, isMove = true) { this.delegate.insertBefore(parent, newChild, refChild); // If `isMove` true than we should animate this insert. this.engine.onInsert(this.namespaceId, newChild, parent, isMove); } removeChild(parent, oldChild, isHostElement) { this.engine.onRemove(this.namespaceId, oldChild, this.delegate); } selectRootElement(selectorOrNode, preserveContent) { return this.delegate.selectRootElement(selectorOrNode, preserveContent); } parentNode(node) { return this.delegate.parentNode(node); } nextSibling(node) { return this.delegate.nextSibling(node); } setAttribute(el, name, value, namespace) { this.delegate.setAttribute(el, name, value, namespace); } removeAttribute(el, name, namespace) { this.delegate.removeAttribute(el, name, namespace); } addClass(el, name) { this.delegate.addClass(el, name); } removeClass(el, name) { this.delegate.removeClass(el, name); } setStyle(el, style, value, flags) { this.delegate.setStyle(el, style, value, flags); } removeStyle(el, style, flags) { this.delegate.removeStyle(el, style, flags); } setProperty(el, name, value) { if (name.charAt(0) == ANIMATION_PREFIX && name == DISABLE_ANIMATIONS_FLAG) { this.disableAnimations(el, !!value); } else { this.delegate.setProperty(el, name, value); } } setValue(node, value) { this.delegate.setValue(node, value); } listen(target, eventName, callback) { return this.delegate.listen(target, eventName, callback); } disableAnimations(element, value) { this.engine.disableAnimations(element, value); } } export class AnimationRenderer extends BaseAnimationRenderer { constructor(factory, namespaceId, delegate, engine, onDestroy) { super(namespaceId, delegate, engine, onDestroy); this.factory = factory; this.namespaceId = namespaceId; } setProperty(el, name, value) { if (name.charAt(0) == ANIMATION_PREFIX) { if (name.charAt(1) == '.' && name == DISABLE_ANIMATIONS_FLAG) { value = value === undefined ? true : !!value; this.disableAnimations(el, value); } else { this.engine.process(this.namespaceId, el, name.slice(1), value); } } else { this.delegate.setProperty(el, name, value); } } listen(target, eventName, callback) { if (eventName.charAt(0) == ANIMATION_PREFIX) { const element = resolveElementFromTarget(target); let name = eventName.slice(1); let phase = ''; // @listener.phase is for trigger animation callbacks // @@listener is for animation builder callbacks if (name.charAt(0) != ANIMATION_PREFIX) { [name, phase] = parseTriggerCallbackName(name); } return this.engine.listen(this.namespaceId, element, name, phase, event => { const countId = event['_data'] || -1; this.factory.scheduleListenerCallback(countId, callback, event); }); } return this.delegate.listen(target, eventName, callback); } } function resolveElementFromTarget(target) { switch (target) { case 'body': return document.body; case 'document': return document; case 'window': return window; default: return target; } } function parseTriggerCallbackName(triggerName) { const dotIndex = triggerName.indexOf('.'); const trigger = triggerName.substring(0, dotIndex); const phase = triggerName.slice(dotIndex + 1); return [trigger, phase]; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5pbWF0aW9uX3JlbmRlcmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvcGxhdGZvcm0tYnJvd3Nlci9hbmltYXRpb25zL3NyYy9hbmltYXRpb25fcmVuZGVyZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBUUEsT0FBTyxFQUFDLGdCQUFnQixJQUFJLGVBQWUsRUFBQyxNQUFNLDZCQUE2QixDQUFDO0FBQ2hGLE9BQU8sRUFBQyxVQUFVLEVBQUUsTUFBTSxFQUFhLGdCQUFnQixFQUFxQyxNQUFNLGVBQWUsQ0FBQzs7O0FBRWxILE1BQU0sZ0JBQWdCLEdBQUcsR0FBRyxDQUFDO0FBQzdCLE1BQU0sdUJBQXVCLEdBQUcsWUFBWSxDQUFDO0FBUzdDLE1BQU0sT0FBTyx3QkFBd0I7SUFPbkMsWUFDWSxRQUEwQixFQUFVLE1BQXVCLEVBQVUsS0FBYTtRQUFsRixhQUFRLEdBQVIsUUFBUSxDQUFrQjtRQUFVLFdBQU0sR0FBTixNQUFNLENBQWlCO1FBQVUsVUFBSyxHQUFMLEtBQUssQ0FBUTtRQVB0RixlQUFVLEdBQVcsQ0FBQyxDQUFDO1FBQ3ZCLGlCQUFZLEdBQVcsQ0FBQyxDQU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