UNPKG

50.2 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('@angular/common')) :
3 typeof define === 'function' && define.amd ? define('ngx-bootstrap/carousel', ['exports', '@angular/core', 'ngx-bootstrap/utils', '@angular/common'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].carousel = {}), global.ng.core, global.utils, global.ng.common));
5}(this, (function (exports, i0, utils, common) { 'use strict';
6
7 /*! *****************************************************************************
8 Copyright (c) Microsoft Corporation.
9
10 Permission to use, copy, modify, and/or distribute this software for any
11 purpose with or without fee is hereby granted.
12
13 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 PERFORMANCE OF THIS SOFTWARE.
20 ***************************************************************************** */
21 /* global Reflect, Promise */
22 var extendStatics = function (d, b) {
23 extendStatics = Object.setPrototypeOf ||
24 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25 function (d, b) { for (var p in b)
26 if (Object.prototype.hasOwnProperty.call(b, p))
27 d[p] = b[p]; };
28 return extendStatics(d, b);
29 };
30 function __extends(d, b) {
31 if (typeof b !== "function" && b !== null)
32 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33 extendStatics(d, b);
34 function __() { this.constructor = d; }
35 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36 }
37 var __assign = function () {
38 __assign = Object.assign || function __assign(t) {
39 for (var s, i = 1, n = arguments.length; i < n; i++) {
40 s = arguments[i];
41 for (var p in s)
42 if (Object.prototype.hasOwnProperty.call(s, p))
43 t[p] = s[p];
44 }
45 return t;
46 };
47 return __assign.apply(this, arguments);
48 };
49 function __rest(s, e) {
50 var t = {};
51 for (var p in s)
52 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53 t[p] = s[p];
54 if (s != null && typeof Object.getOwnPropertySymbols === "function")
55 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57 t[p[i]] = s[p[i]];
58 }
59 return t;
60 }
61 function __decorate(decorators, target, key, desc) {
62 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63 if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
64 r = Reflect.decorate(decorators, target, key, desc);
65 else
66 for (var i = decorators.length - 1; i >= 0; i--)
67 if (d = decorators[i])
68 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69 return c > 3 && r && Object.defineProperty(target, key, r), r;
70 }
71 function __param(paramIndex, decorator) {
72 return function (target, key) { decorator(target, key, paramIndex); };
73 }
74 function __metadata(metadataKey, metadataValue) {
75 if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
76 return Reflect.metadata(metadataKey, metadataValue);
77 }
78 function __awaiter(thisArg, _arguments, P, generator) {
79 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80 return new (P || (P = Promise))(function (resolve, reject) {
81 function fulfilled(value) { try {
82 step(generator.next(value));
83 }
84 catch (e) {
85 reject(e);
86 } }
87 function rejected(value) { try {
88 step(generator["throw"](value));
89 }
90 catch (e) {
91 reject(e);
92 } }
93 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
94 step((generator = generator.apply(thisArg, _arguments || [])).next());
95 });
96 }
97 function __generator(thisArg, body) {
98 var _ = { label: 0, sent: function () { if (t[0] & 1)
99 throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
100 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
101 function verb(n) { return function (v) { return step([n, v]); }; }
102 function step(op) {
103 if (f)
104 throw new TypeError("Generator is already executing.");
105 while (_)
106 try {
107 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
108 return t;
109 if (y = 0, t)
110 op = [op[0] & 2, t.value];
111 switch (op[0]) {
112 case 0:
113 case 1:
114 t = op;
115 break;
116 case 4:
117 _.label++;
118 return { value: op[1], done: false };
119 case 5:
120 _.label++;
121 y = op[1];
122 op = [0];
123 continue;
124 case 7:
125 op = _.ops.pop();
126 _.trys.pop();
127 continue;
128 default:
129 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
130 _ = 0;
131 continue;
132 }
133 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
134 _.label = op[1];
135 break;
136 }
137 if (op[0] === 6 && _.label < t[1]) {
138 _.label = t[1];
139 t = op;
140 break;
141 }
142 if (t && _.label < t[2]) {
143 _.label = t[2];
144 _.ops.push(op);
145 break;
146 }
147 if (t[2])
148 _.ops.pop();
149 _.trys.pop();
150 continue;
151 }
152 op = body.call(thisArg, _);
153 }
154 catch (e) {
155 op = [6, e];
156 y = 0;
157 }
158 finally {
159 f = t = 0;
160 }
161 if (op[0] & 5)
162 throw op[1];
163 return { value: op[0] ? op[1] : void 0, done: true };
164 }
165 }
166 var __createBinding = Object.create ? (function (o, m, k, k2) {
167 if (k2 === undefined)
168 k2 = k;
169 Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
170 }) : (function (o, m, k, k2) {
171 if (k2 === undefined)
172 k2 = k;
173 o[k2] = m[k];
174 });
175 function __exportStar(m, o) {
176 for (var p in m)
177 if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
178 __createBinding(o, m, p);
179 }
180 function __values(o) {
181 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
182 if (m)
183 return m.call(o);
184 if (o && typeof o.length === "number")
185 return {
186 next: function () {
187 if (o && i >= o.length)
188 o = void 0;
189 return { value: o && o[i++], done: !o };
190 }
191 };
192 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
193 }
194 function __read(o, n) {
195 var m = typeof Symbol === "function" && o[Symbol.iterator];
196 if (!m)
197 return o;
198 var i = m.call(o), r, ar = [], e;
199 try {
200 while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
201 ar.push(r.value);
202 }
203 catch (error) {
204 e = { error: error };
205 }
206 finally {
207 try {
208 if (r && !r.done && (m = i["return"]))
209 m.call(i);
210 }
211 finally {
212 if (e)
213 throw e.error;
214 }
215 }
216 return ar;
217 }
218 /** @deprecated */
219 function __spread() {
220 for (var ar = [], i = 0; i < arguments.length; i++)
221 ar = ar.concat(__read(arguments[i]));
222 return ar;
223 }
224 /** @deprecated */
225 function __spreadArrays() {
226 for (var s = 0, i = 0, il = arguments.length; i < il; i++)
227 s += arguments[i].length;
228 for (var r = Array(s), k = 0, i = 0; i < il; i++)
229 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
230 r[k] = a[j];
231 return r;
232 }
233 function __spreadArray(to, from) {
234 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
235 to[j] = from[i];
236 return to;
237 }
238 function __await(v) {
239 return this instanceof __await ? (this.v = v, this) : new __await(v);
240 }
241 function __asyncGenerator(thisArg, _arguments, generator) {
242 if (!Symbol.asyncIterator)
243 throw new TypeError("Symbol.asyncIterator is not defined.");
244 var g = generator.apply(thisArg, _arguments || []), i, q = [];
245 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
246 function verb(n) { if (g[n])
247 i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
248 function resume(n, v) { try {
249 step(g[n](v));
250 }
251 catch (e) {
252 settle(q[0][3], e);
253 } }
254 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
255 function fulfill(value) { resume("next", value); }
256 function reject(value) { resume("throw", value); }
257 function settle(f, v) { if (f(v), q.shift(), q.length)
258 resume(q[0][0], q[0][1]); }
259 }
260 function __asyncDelegator(o) {
261 var i, p;
262 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
263 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
264 }
265 function __asyncValues(o) {
266 if (!Symbol.asyncIterator)
267 throw new TypeError("Symbol.asyncIterator is not defined.");
268 var m = o[Symbol.asyncIterator], i;
269 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
270 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
271 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
272 }
273 function __makeTemplateObject(cooked, raw) {
274 if (Object.defineProperty) {
275 Object.defineProperty(cooked, "raw", { value: raw });
276 }
277 else {
278 cooked.raw = raw;
279 }
280 return cooked;
281 }
282 ;
283 var __setModuleDefault = Object.create ? (function (o, v) {
284 Object.defineProperty(o, "default", { enumerable: true, value: v });
285 }) : function (o, v) {
286 o["default"] = v;
287 };
288 function __importStar(mod) {
289 if (mod && mod.__esModule)
290 return mod;
291 var result = {};
292 if (mod != null)
293 for (var k in mod)
294 if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
295 __createBinding(result, mod, k);
296 __setModuleDefault(result, mod);
297 return result;
298 }
299 function __importDefault(mod) {
300 return (mod && mod.__esModule) ? mod : { default: mod };
301 }
302 function __classPrivateFieldGet(receiver, privateMap) {
303 if (!privateMap.has(receiver)) {
304 throw new TypeError("attempted to get private field on non-instance");
305 }
306 return privateMap.get(receiver);
307 }
308 function __classPrivateFieldSet(receiver, privateMap, value) {
309 if (!privateMap.has(receiver)) {
310 throw new TypeError("attempted to set private field on non-instance");
311 }
312 privateMap.set(receiver, value);
313 return value;
314 }
315
316 var CarouselConfig = /** @class */ (function () {
317 function CarouselConfig() {
318 /* Default interval of auto changing of slides */
319 this.interval = 5000;
320 /* Is loop of auto changing of slides can be paused */
321 this.noPause = false;
322 /* Is slides can wrap from the last to the first slide */
323 this.noWrap = false;
324 /* Show carousel-indicators */
325 this.showIndicators = true;
326 /* Slides can be paused on focus */
327 this.pauseOnFocus = false;
328 /* If `true` - carousel indicators indicate slides chunks works ONLY if singleSlideOffset = FALSE */
329 this.indicatorsByChunk = false;
330 /* If value more then 1 — carousel works in multilist mode */
331 this.itemsPerSlide = 1;
332 /* If `true` — carousel shifts by one element. By default carousel shifts by number
333 of visible elements (itemsPerSlide field) */
334 this.singleSlideOffset = false;
335 }
336 return CarouselConfig;
337 }());
338 CarouselConfig.ɵprov = i0.ɵɵdefineInjectable({ factory: function CarouselConfig_Factory() { return new CarouselConfig(); }, token: CarouselConfig, providedIn: "root" });
339 CarouselConfig.decorators = [
340 { type: i0.Injectable, args: [{
341 providedIn: 'root'
342 },] }
343 ];
344
345 /**
346 * Returns the index of the last element in the array where predicate is true, and -1
347 * otherwise.
348 * @param array The source array to search in
349 * @param predicate find calls predicate once for each element of the array, in descending
350 * order, until it finds one where predicate returns true. If such an element is found,
351 * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
352 */
353 function findLastIndex(array, predicate) {
354 var l = array.length;
355 while (l--) {
356 if (predicate(array[l], l, array)) {
357 return l;
358 }
359 }
360 return -1;
361 }
362 function chunkByNumber(array, size) {
363 var out = [];
364 var n = Math.ceil((array.length) / size);
365 var i = 0;
366 while (i < n) {
367 var chunk = array.splice(0, (i === n - 1) && size < array.length ? array.length : size);
368 out.push(chunk);
369 i++;
370 }
371 return out;
372 }
373
374 var Direction;
375 (function (Direction) {
376 Direction[Direction["UNKNOWN"] = 0] = "UNKNOWN";
377 Direction[Direction["NEXT"] = 1] = "NEXT";
378 Direction[Direction["PREV"] = 2] = "PREV";
379 })(Direction || (Direction = {}));
380 var _currentId = 1;
381 /**
382 * Base element to create carousel
383 */
384 var CarouselComponent = /** @class */ (function () {
385 function CarouselComponent(config, ngZone) {
386 this.ngZone = ngZone;
387 /* If `true` — carousel will not cycle continuously and will have hard stops (prevent looping) */
388 this.noWrap = false;
389 /* If `true` — will disable pausing on carousel mouse hover */
390 this.noPause = false;
391 /* If `true` — carousel-indicators are visible */
392 this.showIndicators = true;
393 /* If `true` - autoplay will be stopped on focus */
394 this.pauseOnFocus = false;
395 /* If `true` - carousel indicators indicate slides chunks
396 works ONLY if singleSlideOffset = FALSE */
397 this.indicatorsByChunk = false;
398 /* If value more then 1 — carousel works in multilist mode */
399 this.itemsPerSlide = 1;
400 /* If `true` — carousel shifts by one element. By default carousel shifts by number
401 of visible elements (itemsPerSlide field) */
402 this.singleSlideOffset = false;
403 /** Turn on/off animation. Animation doesn't work for multilist carousel */
404 this.isAnimated = false;
405 /** Will be emitted when active slide has been changed. Part of two-way-bindable [(activeSlide)] property */
406 this.activeSlideChange = new i0.EventEmitter(false);
407 /** Will be emitted when active slides has been changed in multilist mode */
408 this.slideRangeChange = new i0.EventEmitter();
409 /* Index to start display slides from it */
410 this.startFromIndex = 0;
411 this._interval = 5000;
412 this._slides = new utils.LinkedList();
413 this._currentVisibleSlidesIndex = 0;
414 this.isPlaying = false;
415 this.destroyed = false;
416 this.currentId = 0;
417 this.getActive = function (slide) { return slide.active; };
418 this.makeSlidesConsistent = function (slides) {
419 slides.forEach(function (slide, index) { return slide.item.order = index; });
420 };
421 Object.assign(this, config);
422 this.currentId = _currentId++;
423 }
424 Object.defineProperty(CarouselComponent.prototype, "activeSlide", {
425 get: function () {
426 return this._currentActiveSlide || 0;
427 },
428 /** Index of currently displayed slide(started for 0) */
429 set: function (index) {
430 if (this.multilist) {
431 return;
432 }
433 if (this._slides.length && index !== this._currentActiveSlide) {
434 this._select(index);
435 }
436 },
437 enumerable: false,
438 configurable: true
439 });
440 Object.defineProperty(CarouselComponent.prototype, "interval", {
441 /**
442 * Delay of item cycling in milliseconds. If false, carousel won't cycle
443 * automatically.
444 */
445 get: function () {
446 return this._interval;
447 },
448 set: function (value) {
449 this._interval = value;
450 this.restartTimer();
451 },
452 enumerable: false,
453 configurable: true
454 });
455 Object.defineProperty(CarouselComponent.prototype, "slides", {
456 get: function () {
457 return this._slides.toArray();
458 },
459 enumerable: false,
460 configurable: true
461 });
462 Object.defineProperty(CarouselComponent.prototype, "isBs4", {
463 get: function () {
464 return !utils.isBs3();
465 },
466 enumerable: false,
467 configurable: true
468 });
469 Object.defineProperty(CarouselComponent.prototype, "_bsVer", {
470 get: function () {
471 return utils.getBsVer();
472 },
473 enumerable: false,
474 configurable: true
475 });
476 CarouselComponent.prototype.ngAfterViewInit = function () {
477 var _this = this;
478 setTimeout(function () {
479 if (_this.singleSlideOffset) {
480 _this.indicatorsByChunk = false;
481 }
482 if (_this.multilist) {
483 _this._chunkedSlides = chunkByNumber(_this.mapSlidesAndIndexes(), _this.itemsPerSlide);
484 _this.selectInitialSlides();
485 }
486 }, 0);
487 };
488 CarouselComponent.prototype.ngOnDestroy = function () {
489 this.destroyed = true;
490 };
491 /**
492 * Adds new slide. If this slide is first in collection - set it as active
493 * and starts auto changing
494 * @param slide
495 */
496 CarouselComponent.prototype.addSlide = function (slide) {
497 this._slides.add(slide);
498 if (this.multilist && this._slides.length <= this.itemsPerSlide) {
499 slide.active = true;
500 }
501 if (!this.multilist && this.isAnimated) {
502 slide.isAnimated = true;
503 }
504 if (!this.multilist && this._slides.length === 1) {
505 this._currentActiveSlide = undefined;
506 this.activeSlide = 0;
507 this.play();
508 }
509 if (this.multilist && this._slides.length > this.itemsPerSlide) {
510 this.play();
511 }
512 };
513 /**
514 * Removes specified slide. If this slide is active - will roll to another
515 * slide
516 * @param slide
517 */
518 CarouselComponent.prototype.removeSlide = function (slide) {
519 var _this = this;
520 var remIndex = this._slides.indexOf(slide);
521 if (this._currentActiveSlide === remIndex) {
522 // removing of active slide
523 var nextSlideIndex_1;
524 if (this._slides.length > 1) {
525 // if this slide last - will roll to first slide, if noWrap flag is
526 // FALSE or to previous, if noWrap is TRUE in case, if this slide in
527 // middle of collection, index of next slide is same to removed
528 nextSlideIndex_1 = !this.isLast(remIndex)
529 ? remIndex
530 : this.noWrap ? remIndex - 1 : 0;
531 }
532 this._slides.remove(remIndex);
533 // prevents exception with changing some value after checking
534 setTimeout(function () {
535 _this._select(nextSlideIndex_1);
536 }, 0);
537 }
538 else {
539 this._slides.remove(remIndex);
540 var currentSlideIndex_1 = this.getCurrentSlideIndex();
541 setTimeout(function () {
542 // after removing, need to actualize index of current active slide
543 _this._currentActiveSlide = currentSlideIndex_1;
544 _this.activeSlideChange.emit(_this._currentActiveSlide);
545 }, 0);
546 }
547 };
548 CarouselComponent.prototype.nextSlideFromInterval = function (force) {
549 if (force === void 0) { force = false; }
550 this.move(Direction.NEXT, force);
551 };
552 /**
553 * Rolling to next slide
554 * @param force: {boolean} if true - will ignore noWrap flag
555 */
556 CarouselComponent.prototype.nextSlide = function (force) {
557 if (force === void 0) { force = false; }
558 if (this.isPlaying) {
559 this.restartTimer();
560 }
561 this.move(Direction.NEXT, force);
562 };
563 /**
564 * Rolling to previous slide
565 * @param force: {boolean} if true - will ignore noWrap flag
566 */
567 CarouselComponent.prototype.previousSlide = function (force) {
568 if (force === void 0) { force = false; }
569 if (this.isPlaying) {
570 this.restartTimer();
571 }
572 this.move(Direction.PREV, force);
573 };
574 CarouselComponent.prototype.getFirstVisibleIndex = function () {
575 return this.slides.findIndex(this.getActive);
576 };
577 CarouselComponent.prototype.getLastVisibleIndex = function () {
578 return findLastIndex(this.slides, this.getActive);
579 };
580 CarouselComponent.prototype.move = function (direction, force) {
581 if (force === void 0) { force = false; }
582 var firstVisibleIndex = this.getFirstVisibleIndex();
583 var lastVisibleIndex = this.getLastVisibleIndex();
584 if (this.noWrap) {
585 if (direction === Direction.NEXT &&
586 this.isLast(lastVisibleIndex) ||
587 direction === Direction.PREV &&
588 firstVisibleIndex === 0) {
589 return;
590 }
591 }
592 if (!this.multilist) {
593 this.activeSlide = this.findNextSlideIndex(direction, force) || 0;
594 }
595 else {
596 this.moveMultilist(direction);
597 }
598 };
599 /**
600 * Swith slides by enter, space and arrows keys
601 * @internal
602 */
603 CarouselComponent.prototype.keydownPress = function (event) {
604 if (event.keyCode === 13 || event.key === 'Enter' || event.keyCode === 32 || event.key === 'Space') {
605 this.nextSlide();
606 event.preventDefault();
607 return;
608 }
609 if (event.keyCode === 37 || event.key === 'LeftArrow') {
610 this.previousSlide();
611 return;
612 }
613 if (event.keyCode === 39 || event.key === 'RightArrow') {
614 this.nextSlide();
615 return;
616 }
617 };
618 /**
619 * Play on mouse leave
620 * @internal
621 */
622 CarouselComponent.prototype.onMouseLeave = function () {
623 if (!this.pauseOnFocus) {
624 this.play();
625 }
626 };
627 /**
628 * Play on mouse up
629 * @internal
630 */
631 CarouselComponent.prototype.onMouseUp = function () {
632 if (!this.pauseOnFocus) {
633 this.play();
634 }
635 };
636 /**
637 * When slides on focus autoplay is stopped(optional)
638 * @internal
639 */
640 CarouselComponent.prototype.pauseFocusIn = function () {
641 if (this.pauseOnFocus) {
642 this.isPlaying = false;
643 this.resetTimer();
644 }
645 };
646 /**
647 * When slides out of focus autoplay is started
648 * @internal
649 */
650 CarouselComponent.prototype.pauseFocusOut = function () {
651 this.play();
652 };
653 /**
654 * Rolling to specified slide
655 * @param index: {number} index of slide, which must be shown
656 */
657 CarouselComponent.prototype.selectSlide = function (index) {
658 if (this.isPlaying) {
659 this.restartTimer();
660 }
661 if (!this.multilist) {
662 this.activeSlide = this.indicatorsByChunk ? index * this.itemsPerSlide : index;
663 }
664 else {
665 this.selectSlideRange(this.indicatorsByChunk ? index * this.itemsPerSlide : index);
666 }
667 };
668 /**
669 * Starts a auto changing of slides
670 */
671 CarouselComponent.prototype.play = function () {
672 if (!this.isPlaying) {
673 this.isPlaying = true;
674 this.restartTimer();
675 }
676 };
677 /**
678 * Stops a auto changing of slides
679 */
680 CarouselComponent.prototype.pause = function () {
681 if (!this.noPause) {
682 this.isPlaying = false;
683 this.resetTimer();
684 }
685 };
686 /**
687 * Finds and returns index of currently displayed slide
688 */
689 CarouselComponent.prototype.getCurrentSlideIndex = function () {
690 return this._slides.findIndex(this.getActive);
691 };
692 /**
693 * Defines, whether the specified index is last in collection
694 * @param index
695 */
696 CarouselComponent.prototype.isLast = function (index) {
697 return index + 1 >= this._slides.length;
698 };
699 /**
700 * Defines, whether the specified index is first in collection
701 * @param index
702 */
703 CarouselComponent.prototype.isFirst = function (index) {
704 return index === 0;
705 };
706 CarouselComponent.prototype.indicatorsSlides = function () {
707 var _this = this;
708 return this.slides.filter(function (slide, index) { return !_this.indicatorsByChunk || index % _this.itemsPerSlide === 0; });
709 };
710 CarouselComponent.prototype.selectInitialSlides = function () {
711 var startIndex = this.startFromIndex <= this._slides.length
712 ? this.startFromIndex
713 : 0;
714 this.hideSlides();
715 if (this.singleSlideOffset) {
716 this._slidesWithIndexes = this.mapSlidesAndIndexes();
717 if (this._slides.length - startIndex < this.itemsPerSlide) {
718 var slidesToAppend = this._slidesWithIndexes.slice(0, startIndex);
719 this._slidesWithIndexes = __spread(this._slidesWithIndexes, slidesToAppend).slice(slidesToAppend.length)
720 .slice(0, this.itemsPerSlide);
721 }
722 else {
723 this._slidesWithIndexes = this._slidesWithIndexes.slice(startIndex, startIndex + this.itemsPerSlide);
724 }
725 this._slidesWithIndexes.forEach(function (slide) { return slide.item.active = true; });
726 this.makeSlidesConsistent(this._slidesWithIndexes);
727 }
728 else {
729 this.selectRangeByNestedIndex(startIndex);
730 }
731 this.slideRangeChange.emit(this.getVisibleIndexes());
732 };
733 /**
734 * Defines next slide index, depending of direction
735 * @param direction: Direction(UNKNOWN|PREV|NEXT)
736 * @param force: {boolean} if TRUE - will ignore noWrap flag, else will
737 * return undefined if next slide require wrapping
738 */
739 CarouselComponent.prototype.findNextSlideIndex = function (direction, force) {
740 var nextSlideIndex = 0;
741 if (!force &&
742 (this.isLast(this.activeSlide) &&
743 direction !== Direction.PREV &&
744 this.noWrap)) {
745 return;
746 }
747 switch (direction) {
748 case Direction.NEXT:
749 // if this is last slide, not force, looping is disabled
750 // and need to going forward - select current slide, as a next
751 if (typeof this._currentActiveSlide === 'undefined') {
752 nextSlideIndex = 0;
753 break;
754 }
755 if (!this.isLast(this._currentActiveSlide)) {
756 nextSlideIndex = this._currentActiveSlide + 1;
757 break;
758 }
759 nextSlideIndex = !force && this.noWrap ? this._currentActiveSlide : 0;
760 break;
761 case Direction.PREV:
762 // if this is first slide, not force, looping is disabled
763 // and need to going backward - select current slide, as a next
764 if (typeof this._currentActiveSlide === 'undefined') {
765 nextSlideIndex = 0;
766 break;
767 }
768 if (this._currentActiveSlide > 0) {
769 nextSlideIndex = this._currentActiveSlide - 1;
770 break;
771 }
772 if (!force && this.noWrap) {
773 nextSlideIndex = this._currentActiveSlide;
774 break;
775 }
776 nextSlideIndex = this._slides.length - 1;
777 break;
778 default:
779 throw new Error('Unknown direction');
780 }
781 return nextSlideIndex;
782 };
783 CarouselComponent.prototype.mapSlidesAndIndexes = function () {
784 return this.slides
785 .slice()
786 .map(function (slide, index) {
787 return {
788 index: index,
789 item: slide
790 };
791 });
792 };
793 CarouselComponent.prototype.selectSlideRange = function (index) {
794 if (this.isIndexInRange(index)) {
795 return;
796 }
797 this.hideSlides();
798 if (!this.singleSlideOffset) {
799 this.selectRangeByNestedIndex(index);
800 }
801 else {
802 var startIndex = this.isIndexOnTheEdges(index)
803 ? index
804 : index - this.itemsPerSlide + 1;
805 var endIndex = this.isIndexOnTheEdges(index)
806 ? index + this.itemsPerSlide
807 : index + 1;
808 this._slidesWithIndexes = this.mapSlidesAndIndexes().slice(startIndex, endIndex);
809 this.makeSlidesConsistent(this._slidesWithIndexes);
810 this._slidesWithIndexes.forEach(function (slide) { return slide.item.active = true; });
811 }
812 this.slideRangeChange.emit(this.getVisibleIndexes());
813 };
814 CarouselComponent.prototype.selectRangeByNestedIndex = function (index) {
815 if (!this._chunkedSlides) {
816 return;
817 }
818 var selectedRange = this._chunkedSlides
819 .map(function (slidesList, i) {
820 return {
821 index: i,
822 list: slidesList
823 };
824 })
825 .find(function (slidesList) {
826 return slidesList.list.find(function (slide) { return slide.index === index; }) !== undefined;
827 });
828 if (!selectedRange) {
829 return;
830 }
831 this._currentVisibleSlidesIndex = selectedRange.index;
832 this._chunkedSlides[selectedRange.index].forEach(function (slide) {
833 slide.item.active = true;
834 });
835 };
836 CarouselComponent.prototype.isIndexOnTheEdges = function (index) {
837 return (index + 1 - this.itemsPerSlide <= 0 ||
838 index + this.itemsPerSlide <= this._slides.length);
839 };
840 CarouselComponent.prototype.isIndexInRange = function (index) {
841 if (this.singleSlideOffset && this._slidesWithIndexes) {
842 var visibleIndexes = this._slidesWithIndexes.map(function (slide) { return slide.index; });
843 return visibleIndexes.indexOf(index) >= 0;
844 }
845 return (index <= this.getLastVisibleIndex() &&
846 index >= this.getFirstVisibleIndex());
847 };
848 CarouselComponent.prototype.hideSlides = function () {
849 this.slides.forEach(function (slide) { return slide.active = false; });
850 };
851 CarouselComponent.prototype.isVisibleSlideListLast = function () {
852 if (!this._chunkedSlides) {
853 return false;
854 }
855 return this._currentVisibleSlidesIndex === this._chunkedSlides.length - 1;
856 };
857 CarouselComponent.prototype.isVisibleSlideListFirst = function () {
858 return this._currentVisibleSlidesIndex === 0;
859 };
860 CarouselComponent.prototype.moveSliderByOneItem = function (direction) {
861 var firstVisibleIndex;
862 var lastVisibleIndex;
863 var indexToHide;
864 var indexToShow;
865 if (this.noWrap) {
866 firstVisibleIndex = this.getFirstVisibleIndex();
867 lastVisibleIndex = this.getLastVisibleIndex();
868 indexToHide = direction === Direction.NEXT
869 ? firstVisibleIndex
870 : lastVisibleIndex;
871 indexToShow = direction !== Direction.NEXT
872 ? firstVisibleIndex - 1
873 : !this.isLast(lastVisibleIndex)
874 ? lastVisibleIndex + 1 : 0;
875 var slideToHide = this._slides.get(indexToHide);
876 if (slideToHide) {
877 slideToHide.active = false;
878 }
879 var slideToShow = this._slides.get(indexToShow);
880 if (slideToShow) {
881 slideToShow.active = true;
882 }
883 var slidesToReorder = this.mapSlidesAndIndexes().filter(function (slide) { return slide.item.active; });
884 this.makeSlidesConsistent(slidesToReorder);
885 this.slideRangeChange.emit(this.getVisibleIndexes());
886 return;
887 }
888 if (!this._slidesWithIndexes || !this._slidesWithIndexes[0]) {
889 return;
890 }
891 var index;
892 firstVisibleIndex = this._slidesWithIndexes[0].index;
893 lastVisibleIndex = this._slidesWithIndexes[this._slidesWithIndexes.length - 1].index;
894 if (direction === Direction.NEXT) {
895 this._slidesWithIndexes.shift();
896 index = this.isLast(lastVisibleIndex)
897 ? 0
898 : lastVisibleIndex + 1;
899 var item = this._slides.get(index);
900 if (item) {
901 this._slidesWithIndexes.push({ index: index, item: item });
902 }
903 }
904 else {
905 this._slidesWithIndexes.pop();
906 index = this.isFirst(firstVisibleIndex)
907 ? this._slides.length - 1
908 : firstVisibleIndex - 1;
909 var item = this._slides.get(index);
910 if (item) {
911 this._slidesWithIndexes = __spread([{ index: index, item: item }], this._slidesWithIndexes);
912 }
913 }
914 this.hideSlides();
915 this._slidesWithIndexes.forEach(function (slide) { return slide.item.active = true; });
916 this.makeSlidesConsistent(this._slidesWithIndexes);
917 this.slideRangeChange.emit(this._slidesWithIndexes.map(function (slide) { return slide.index; }));
918 };
919 CarouselComponent.prototype.moveMultilist = function (direction) {
920 if (this.singleSlideOffset) {
921 this.moveSliderByOneItem(direction);
922 }
923 else {
924 this.hideSlides();
925 if (this.noWrap) {
926 this._currentVisibleSlidesIndex = direction === Direction.NEXT
927 ? this._currentVisibleSlidesIndex + 1
928 : this._currentVisibleSlidesIndex - 1;
929 }
930 else if (direction === Direction.NEXT) {
931 this._currentVisibleSlidesIndex = this.isVisibleSlideListLast()
932 ? 0
933 : this._currentVisibleSlidesIndex + 1;
934 }
935 else {
936 if (this.isVisibleSlideListFirst()) {
937 this._currentVisibleSlidesIndex = this._chunkedSlides
938 ? this._chunkedSlides.length - 1
939 : 0;
940 }
941 else {
942 this._currentVisibleSlidesIndex = this._currentVisibleSlidesIndex - 1;
943 }
944 }
945 if (this._chunkedSlides) {
946 this._chunkedSlides[this._currentVisibleSlidesIndex].forEach(function (slide) { return slide.item.active = true; });
947 }
948 this.slideRangeChange.emit(this.getVisibleIndexes());
949 }
950 };
951 CarouselComponent.prototype.getVisibleIndexes = function () {
952 if (!this.singleSlideOffset && this._chunkedSlides) {
953 return this._chunkedSlides[this._currentVisibleSlidesIndex]
954 .map(function (slide) { return slide.index; });
955 }
956 if (this._slidesWithIndexes) {
957 return this._slidesWithIndexes.map(function (slide) { return slide.index; });
958 }
959 };
960 /**
961 * Sets a slide, which specified through index, as active
962 * @param index
963 */
964 CarouselComponent.prototype._select = function (index) {
965 if (isNaN(index)) {
966 this.pause();
967 return;
968 }
969 if (!this.multilist && typeof this._currentActiveSlide !== 'undefined') {
970 var currentSlide = this._slides.get(this._currentActiveSlide);
971 if (typeof currentSlide !== 'undefined') {
972 currentSlide.active = false;
973 }
974 }
975 var nextSlide = this._slides.get(index);
976 if (typeof nextSlide !== 'undefined') {
977 this._currentActiveSlide = index;
978 nextSlide.active = true;
979 this.activeSlide = index;
980 this.activeSlideChange.emit(index);
981 }
982 };
983 /**
984 * Starts loop of auto changing of slides
985 */
986 CarouselComponent.prototype.restartTimer = function () {
987 var _this = this;
988 this.resetTimer();
989 var interval = +this.interval;
990 if (!isNaN(interval) && interval > 0) {
991 this.currentInterval = this.ngZone.runOutsideAngular(function () {
992 return setInterval(function () {
993 var nInterval = +_this.interval;
994 _this.ngZone.run(function () {
995 if (_this.isPlaying &&
996 !isNaN(_this.interval) &&
997 nInterval > 0 &&
998 _this.slides.length) {
999 _this.nextSlideFromInterval();
1000 }
1001 else {
1002 _this.pause();
1003 }
1004 });
1005 }, interval);
1006 });
1007 }
1008 };
1009 Object.defineProperty(CarouselComponent.prototype, "multilist", {
1010 get: function () {
1011 return this.itemsPerSlide > 1;
1012 },
1013 enumerable: false,
1014 configurable: true
1015 });
1016 /**
1017 * Stops loop of auto changing of slides
1018 */
1019 CarouselComponent.prototype.resetTimer = function () {
1020 if (this.currentInterval) {
1021 clearInterval(this.currentInterval);
1022 this.currentInterval = void 0;
1023 }
1024 };
1025 return CarouselComponent;
1026 }());
1027 CarouselComponent.decorators = [
1028 { type: i0.Component, args: [{
1029 selector: 'carousel',
1030 template: "<div (mouseenter)=\"pause()\"\n (mouseleave)=\"onMouseLeave()\"\n (mouseup)=\"onMouseUp()\"\n (keydown)=\"keydownPress($event)\"\n (focusin)=\"pauseFocusIn()\"\n (focusout)=\"pauseFocusOut()\"\n [id]=\"currentId\"\n class=\"carousel slide\" tabindex=\"0\">\n <ng-container *ngIf=\"!_bsVer.isBs5 && showIndicators && slides.length > 1\">\n <ol class=\"carousel-indicators\">\n <li *ngFor=\"let slide of indicatorsSlides(); let i = index;\"\n [class.active]=\"slide.active === true\"\n (click)=\"selectSlide(i)\">\n </li>\n </ol>\n </ng-container>\n <ng-container *ngIf=\"_bsVer.isBs5 && showIndicators && slides.length > 1\">\n <div class=\"carousel-indicators\">\n <button\n *ngFor=\"let slide of indicatorsSlides(); let i = index;\"\n [class.active]=\"slide.active === true\"\n (click)=\"selectSlide(i)\"\n type=\"button\"\n [attr.data-bs-target]=\"'#'+currentId\"\n [attr.data-bs-slide-to]=\"i\" aria-current=\"true\"\n >\n </button>\n </div>\n </ng-container>\n <div class=\"carousel-inner\" [ngStyle]=\"{'display': multilist ? 'flex' : 'block'}\">\n <ng-content></ng-content>\n </div>\n <a class=\"left carousel-control carousel-control-prev\"\n *ngIf=\"slides.length > 1\"\n [class.disabled]=\"activeSlide === 0 && noWrap\"\n [attr.data-bs-target]=\"'#'+currentId\"\n (click)=\"previousSlide()\"\n tabindex=\"0\" role=\"button\">\n <span class=\"icon-prev carousel-control-prev-icon\" aria-hidden=\"true\"></span>\n <span *ngIf=\"isBs4\" class=\"sr-only visually-hidden\">Previous</span>\n </a>\n <a class=\"right carousel-control carousel-control-next\"\n *ngIf=\"slides.length > 1\"\n [class.disabled]=\"isLast(activeSlide) && noWrap\"\n [attr.data-bs-target]=\"'#'+currentId\"\n (click)=\"nextSlide()\"\n tabindex=\"0\" role=\"button\">\n <span class=\"icon-next carousel-control-next-icon\" aria-hidden=\"true\"></span>\n <span class=\"sr-only visually-hidden\">Next</span>\n </a>\n</div>\n"
1031 },] }
1032 ];
1033 CarouselComponent.ctorParameters = function () { return [
1034 { type: CarouselConfig },
1035 { type: i0.NgZone }
1036 ]; };
1037 CarouselComponent.propDecorators = {
1038 noWrap: [{ type: i0.Input }],
1039 noPause: [{ type: i0.Input }],
1040 showIndicators: [{ type: i0.Input }],
1041 pauseOnFocus: [{ type: i0.Input }],
1042 indicatorsByChunk: [{ type: i0.Input }],
1043 itemsPerSlide: [{ type: i0.Input }],
1044 singleSlideOffset: [{ type: i0.Input }],
1045 isAnimated: [{ type: i0.Input }],
1046 activeSlideChange: [{ type: i0.Output }],
1047 slideRangeChange: [{ type: i0.Output }],
1048 activeSlide: [{ type: i0.Input }],
1049 startFromIndex: [{ type: i0.Input }],
1050 interval: [{ type: i0.Input }]
1051 };
1052
1053 var SlideComponent = /** @class */ (function () {
1054 function SlideComponent(carousel) {
1055 /** Is current slide active */
1056 this.active = false;
1057 this.itemWidth = '100%';
1058 this.order = 0;
1059 this.isAnimated = false;
1060 /** Wraps element by appropriate CSS classes */
1061 this.addClass = true;
1062 this.carousel = carousel;
1063 }
1064 /** Fires changes in container collection after adding a new slide instance */
1065 SlideComponent.prototype.ngOnInit = function () {
1066 this.carousel.addSlide(this);
1067 this.itemWidth = 100 / this.carousel.itemsPerSlide + "%";
1068 };
1069 /** Fires changes in container collection after removing of this slide instance */
1070 SlideComponent.prototype.ngOnDestroy = function () {
1071 this.carousel.removeSlide(this);
1072 };
1073 return SlideComponent;
1074 }());
1075 SlideComponent.decorators = [
1076 { type: i0.Component, args: [{
1077 selector: 'slide',
1078 template: "\n <div [class.active]=\"active\" class=\"item\">\n <ng-content></ng-content>\n </div>\n ",
1079 // eslint-disable-next-line @angular-eslint/no-host-metadata-property
1080 host: {
1081 '[attr.aria-hidden]': '!active'
1082 },
1083 styles: ["\n :host.carousel-animation {\n transition: opacity 0.6s ease, visibility 0.6s ease;\n float: left;\n }\n :host.carousel-animation.active {\n opacity: 1;\n visibility: visible;\n }\n :host.carousel-animation:not(.active) {\n display: block;\n position: absolute;\n opacity: 0;\n visibility: hidden;\n }\n :host.carousel-item {\n margin-right: auto;\n }\n "]
1084 },] }
1085 ];
1086 SlideComponent.ctorParameters = function () { return [
1087 { type: CarouselComponent }
1088 ]; };
1089 SlideComponent.propDecorators = {
1090 active: [{ type: i0.HostBinding, args: ['class.active',] }, { type: i0.Input }],
1091 itemWidth: [{ type: i0.HostBinding, args: ['style.width',] }],
1092 order: [{ type: i0.HostBinding, args: ['style.order',] }],
1093 isAnimated: [{ type: i0.HostBinding, args: ['class.carousel-animation',] }],
1094 addClass: [{ type: i0.HostBinding, args: ['class.item',] }, { type: i0.HostBinding, args: ['class.carousel-item',] }]
1095 };
1096
1097 var CarouselModule = /** @class */ (function () {
1098 function CarouselModule() {
1099 }
1100 CarouselModule.forRoot = function () {
1101 return { ngModule: CarouselModule, providers: [] };
1102 };
1103 return CarouselModule;
1104 }());
1105 CarouselModule.decorators = [
1106 { type: i0.NgModule, args: [{
1107 imports: [common.CommonModule],
1108 declarations: [SlideComponent, CarouselComponent],
1109 exports: [SlideComponent, CarouselComponent]
1110 },] }
1111 ];
1112
1113 /**
1114 * Generated bundle index. Do not edit.
1115 */
1116
1117 exports.CarouselComponent = CarouselComponent;
1118 exports.CarouselConfig = CarouselConfig;
1119 exports.CarouselModule = CarouselModule;
1120 exports.SlideComponent = SlideComponent;
1121
1122 Object.defineProperty(exports, '__esModule', { value: true });
1123
1124})));
1125//# sourceMappingURL=ngx-bootstrap-carousel.umd.js.map