import { Injectable } from '@angular/core'; import { merge } from 'rxjs'; import { tap, filter } from 'rxjs/operators'; import * as i0 from "@angular/core"; import * as i1 from "./carousel.service"; class NavigationService { carouselService; /** * Subscrioption to merge Observable from CarouselService */ navSubscription; /** * Indicates whether the plugin is initialized or not. */ _initialized = false; /** * The current paging indexes. */ _pages = []; /** * Data for navigation elements of the user interface. */ _navData = { disabled: false, prev: { disabled: false, htmlText: '' }, next: { disabled: false, htmlText: '' }, }; /** * Data for dot elements of the user interface. */ _dotsData = { disabled: false, dots: [] }; constructor(carouselService) { this.carouselService = carouselService; this.spyDataStreams(); } ngOnDestroy() { this.navSubscription.unsubscribe(); } /** * Defines Observables which service must observe */ spyDataStreams() { const initializedCarousel$ = this.carouselService.getInitializedState().pipe(tap(state => { this.initialize(); this._updateNavPages(); this.draw(); this.update(); this.carouselService.sendChanges(); })); // mostly changes in carouselService and carousel at all causes carouselService.to(). It moves stage right-left by its code and calling needed functions // Thus this method by calling carouselService.current(position) notifies about changes const changedSettings$ = this.carouselService.getChangedState().pipe(filter(data => data.property.name === 'position'), tap(data => { this.update(); // should be the call of the function written at the end of comment // but the method carouselServive.to() has setTimeout(f, 0) which contains carouselServive.update() which calls sendChanges() method. // carouselService.navData and carouselService.dotsData update earlier than carouselServive.update() gets called // updates of carouselService.navData and carouselService.dotsData are being happening withing carouselService.current(position) method which calls next() of _changedSettingsCarousel$ // carouselService.current(position) is being calling earlier than carouselServive.update(); // this.carouselService.sendChanges(); })); const refreshedCarousel$ = this.carouselService.getRefreshedState().pipe(tap(() => { this._updateNavPages(); this.draw(); this.update(); this.carouselService.sendChanges(); })); const navMerge$ = merge(initializedCarousel$, changedSettings$, refreshedCarousel$); this.navSubscription = navMerge$.subscribe(() => { }); } /** * Initializes the layout of the plugin and extends the carousel. */ initialize() { this._navData.disabled = true; this._navData.prev.htmlText = this.carouselService.settings.navText[0]; this._navData.next.htmlText = this.carouselService.settings.navText[1]; this._dotsData.disabled = true; this.carouselService.navData = this._navData; this.carouselService.dotsData = this._dotsData; } /** * Calculates internal states and updates prop _pages */ _updateNavPages() { let i, j, k; const lower = this.carouselService.clones().length / 2, upper = lower + this.carouselService.items().length, maximum = this.carouselService.maximum(true), pages = [], settings = this.carouselService.settings; let size = settings.center || settings.autoWidth || settings.dotsData ? 1 : Math.floor(Number(settings.dotsEach)) || Math.floor(settings.items); size = +size; if (settings.slideBy !== 'page') { settings.slideBy = Math.min(+settings.slideBy, settings.items); } if (settings.dots || settings.slideBy === 'page') { for (i = lower, j = 0, k = 0; i < upper; i++) { if (j >= size || j === 0) { pages.push({ start: Math.min(maximum, i - lower), end: i - lower + size - 1 }); if (Math.min(maximum, i - lower) === maximum) { break; } j = 0, ++k; } j += this.carouselService.mergers(this.carouselService.relative(i)); } } this._pages = pages; } /** * Draws the user interface. * @todo The option `dotsData` wont work. */ draw() { let difference; const settings = this.carouselService.settings, items = this.carouselService.items(), disabled = items.length <= settings.items; this._navData.disabled = !settings.nav || disabled; this._dotsData.disabled = !settings.dots || disabled; if (settings.dots) { difference = this._pages.length - this._dotsData.dots.length; if (settings.dotsData && difference !== 0) { this._dotsData.dots = []; items.forEach(item => { this._dotsData.dots.push({ active: false, id: `dot-${item.id}`, innerContent: item.dotContent, showInnerContent: true }); }); } else if (difference > 0) { const startI = this._dotsData.dots.length > 0 ? this._dotsData.dots.length : 0; for (let i = 0; i < difference; i++) { this._dotsData.dots.push({ active: false, id: `dot-${i + startI}`, innerContent: '', showInnerContent: false }); } } else if (difference < 0) { this._dotsData.dots.splice(difference, Math.abs(difference)); } } this.carouselService.navData = this._navData; this.carouselService.dotsData = this._dotsData; } ; /** * Updates navigation buttons's and dots's states */ update() { this._updateNavButtons(); this._updateDots(); } /** * Changes state of nav buttons (disabled, enabled) */ _updateNavButtons() { const settings = this.carouselService.settings, loop = settings.loop || settings.rewind, index = this.carouselService.relative(this.carouselService.current()); if (settings.nav) { this._navData.prev.disabled = !loop && index <= this.carouselService.minimum(true); this._navData.next.disabled = !loop && index >= this.carouselService.maximum(true); } this.carouselService.navData = this._navData; } /** * Changes active dot if page becomes changed */ _updateDots() { let curActiveDotI; if (!this.carouselService.settings.dots) { return; } this._dotsData.dots.forEach(item => { if (item.active === true) { item.active = false; } }); curActiveDotI = this._current(); if (this._dotsData.dots.length) { this._dotsData.dots[curActiveDotI].active = true; } this.carouselService.dotsData = this._dotsData; } /** * Gets the current page position of the carousel. * @returns the current page position of the carousel */ _current() { const current = this.carouselService.relative(this.carouselService.current()); let finalCurrent; const pages = this._pages.filter((page, index) => { return page.start <= current && page.end >= current; }).pop(); finalCurrent = this._pages.findIndex(page => { return page.start === pages.start && page.end === pages.end; }); return finalCurrent; } ; /** * Gets the current succesor/predecessor position. * @param sussessor position of slide * @returns the current succesor/predecessor position */ _getPosition(successor) { let position, length; const settings = this.carouselService.settings; if (settings.slideBy === 'page') { position = this._current(); length = this._pages.length; successor ? ++position : --position; position = this._pages[((position % length) + length) % length].start; } else { position = this.carouselService.relative(this.carouselService.current()); length = this.carouselService.items().length; successor ? position += +settings.slideBy : position -= +settings.slideBy; } return position; } ; /** * Slides to the next item or page. * @param speed The time in milliseconds for the transition. */ next(speed) { this.carouselService.to(this._getPosition(true), speed); } ; /** * Slides to the previous item or page. * @param speed The time in milliseconds for the transition. */ prev(speed) { this.carouselService.to(this._getPosition(false), speed); } ; /** * Slides to the specified item or page. * @param position - The position of the item or page. * @param speed - The time in milliseconds for the transition. * @param standard - Whether to use the standard behaviour or not. Default meaning false */ to(position, speed, standard) { let length; if (!standard && this._pages.length) { length = this._pages.length; this.carouselService.to(this._pages[((position % length) + length) % length].start, speed); } else { this.carouselService.to(position, speed); } } ; /** * Moves carousel after user's clicking on any dots */ moveByDot(dotId) { const index = this._dotsData.dots.findIndex(dot => dotId === dot.id); this.to(index, this.carouselService.settings.dotsSpeed); } /** * rewinds carousel to slide with needed id * @param id id of slide */ toSlideById(id) { const position = this.carouselService.slidesData.findIndex(slide => slide.id === id && slide.isCloned === false); if (position === -1 || position === this.carouselService.current()) { return; } this.carouselService.to(this.carouselService.relative(position), false); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NavigationService, deps: [{ token: i1.CarouselService }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NavigationService }); } export { NavigationService }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NavigationService, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i1.CarouselService }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF2aWdhdGlvbi5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vbGlicy9uZ3gtb3dsLWNhcm91c2VsLW8vc3JjL2xpYi9zZXJ2aWNlcy9uYXZpZ2F0aW9uLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBYSxNQUFNLGVBQWUsQ0FBQztBQUl0RCxPQUFPLEVBQTRCLEtBQUssRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUN2RCxPQUFPLEVBQUUsR0FBRyxFQUFFLE1BQU0sRUFBRSxNQUFNLGdCQUFnQixDQUFDOzs7QUFHN0MsTUFDYSxpQkFBaUI7SUF1Q1I7SUF0Q3BCOztPQUVHO0lBQ0gsZUFBZSxDQUFlO0lBRTlCOztPQUVHO0lBQ08sWUFBWSxHQUFHLEtBQUssQ0FBQztJQUUvQjs7T0FFRztJQUNPLE1BQU0sR0FBVSxFQUFFLENBQUM7SUFFN0I7O09BRUc7SUFDTyxRQUFRLEdBQVk7UUFDNUIsUUFBUSxFQUFFLEtBQUs7UUFDZixJQUFJLEVBQUU7WUFDSixRQUFRLEVBQUUsS0FBSztZQUNmLFFBQVEs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