|
|
|
@ -37,9 +37,7 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
@Output() changedIndex: EventEmitter<number> = new EventEmitter<number>();
|
|
|
|
|
@Input() slides?: any[];
|
|
|
|
|
@ContentChild(TemplateRef) template?: TemplateRef<any>;
|
|
|
|
|
|
|
|
|
|
@ViewChild('carouselWindow') window!: ElementRef;
|
|
|
|
|
|
|
|
|
|
@ViewChildren('slideElement') slideElements!: QueryList<ElementRef>;
|
|
|
|
|
|
|
|
|
|
current: number = 0;
|
|
|
|
@ -50,6 +48,7 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
angularAnimating: boolean = false;
|
|
|
|
|
animation: string = 'vertical';
|
|
|
|
|
directionTime: number = 0;
|
|
|
|
|
@Input() numVisible: number = 1;
|
|
|
|
|
|
|
|
|
|
private debouncedOnchange: Subject<void> = new Subject<void>();
|
|
|
|
|
|
|
|
|
@ -91,6 +90,14 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numExtraNext() {
|
|
|
|
|
return Math.floor((this.numVisible - 1) / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numExtraPrev() {
|
|
|
|
|
return Math.ceil((this.numVisible - 1) / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
|
|
|
|
|
this.slideElements.changes.subscribe((comps: QueryList<ElementRef>) => {
|
|
|
|
@ -104,16 +111,13 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialize() {
|
|
|
|
|
this.visibleSlides?.push({
|
|
|
|
|
index: 0,
|
|
|
|
|
hasBeenVisible: false,
|
|
|
|
|
currentlyIntersecting: false,
|
|
|
|
|
})
|
|
|
|
|
this.visibleSlides?.push({
|
|
|
|
|
index: 1,
|
|
|
|
|
hasBeenVisible: false,
|
|
|
|
|
currentlyIntersecting: false,
|
|
|
|
|
})
|
|
|
|
|
for(let i = 0; i <= this.numExtraNext() && i < this.slides!.length; i++) {
|
|
|
|
|
this.visibleSlides?.push({
|
|
|
|
|
index: i,
|
|
|
|
|
hasBeenVisible: false,
|
|
|
|
|
currentlyIntersecting: false,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleNewDomSlide(ref: ElementRef) {
|
|
|
|
@ -125,11 +129,11 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
if (this.slides && this.current + 1 < this.slides?.length) {
|
|
|
|
|
this.current += 1;
|
|
|
|
|
this.changedIndex.emit(this.current);
|
|
|
|
|
|
|
|
|
|
if (this.current + 1 < this.slides.length) {
|
|
|
|
|
if (!this.visibleSlides?.find(e => e.index == this.current + 1)) {
|
|
|
|
|
console.log("numextra", this.numExtraNext());
|
|
|
|
|
if (this.current + this.numExtraNext() < this.slides.length) {
|
|
|
|
|
if (!this.visibleSlides?.find(e => e.index == this.current + this.numExtraNext() )) {
|
|
|
|
|
this.visibleSlides?.push({
|
|
|
|
|
index: this.current + 1,
|
|
|
|
|
index: this.current + this.numExtraNext(),
|
|
|
|
|
hasBeenVisible: false,
|
|
|
|
|
currentlyIntersecting: false,
|
|
|
|
|
});
|
|
|
|
@ -145,10 +149,10 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
this.current -= 1;
|
|
|
|
|
this.changedIndex.emit(this.current);
|
|
|
|
|
|
|
|
|
|
if (this.current - 1 >= 0) {
|
|
|
|
|
if (!this.visibleSlides?.find(e => e.index == this.current - 1)) {
|
|
|
|
|
if (this.current - this.numExtraPrev() >= 0) {
|
|
|
|
|
if (!this.visibleSlides?.find(e => e.index == this.current - this.numExtraPrev())) {
|
|
|
|
|
this.visibleSlides?.push({
|
|
|
|
|
index: this.current - 1,
|
|
|
|
|
index: this.current - this.numExtraPrev(),
|
|
|
|
|
hasBeenVisible: false,
|
|
|
|
|
currentlyIntersecting: false,
|
|
|
|
|
});
|
|
|
|
@ -163,22 +167,23 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
realOnChange() {
|
|
|
|
|
const safetyFactor = this.numVisible == 1 ? 1 : 2;
|
|
|
|
|
{
|
|
|
|
|
const intersecting = this.visibleSlides?.filter(e => e.currentlyIntersecting).sort((e1, e2) => e1.index - e2.index);
|
|
|
|
|
const lowestIntersecting = intersecting![0];
|
|
|
|
|
this.visibleSlides = this.visibleSlides?.filter(e => e.index + 2 >= lowestIntersecting!.index && e.index >= this.current - 2);
|
|
|
|
|
this.visibleSlides = this.visibleSlides?.filter(e => e.index + safetyFactor >= lowestIntersecting!.index && e.index >= this.current - this.numExtraPrev());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
const intersecting = this.visibleSlides?.filter(e => e.currentlyIntersecting).sort((e1, e2) => e1.index - e2.index).reverse();
|
|
|
|
|
const highestIntersecting = intersecting![0]
|
|
|
|
|
this.visibleSlides = this.visibleSlides?.filter(e => e.index - 2 <= highestIntersecting!.index && e.index <= this.current + 2);
|
|
|
|
|
this.visibleSlides = this.visibleSlides?.filter(e => e.index - safetyFactor <= highestIntersecting!.index && e.index <= this.current + this.numExtraNext());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
translation() {
|
|
|
|
|
let num = (this.current - 1) * (-1 / 3) * 100;
|
|
|
|
|
let num = (this.current - this.numExtraNext() - (this.numVisible % 2 == 0 ? 1 : 0)) * (-1 / this.numVisible) * 100;
|
|
|
|
|
if (this.vertical) {
|
|
|
|
|
return `0 ${num}%`
|
|
|
|
|
} else {
|
|
|
|
@ -189,7 +194,7 @@ export class CarouselComponent implements OnInit, AfterViewInit {
|
|
|
|
|
|
|
|
|
|
templateValue() {
|
|
|
|
|
const len = this.slides?.length;
|
|
|
|
|
return `repeat(${len}, minmax(calc(100% / 3), 1fr))`;
|
|
|
|
|
return `repeat(${len}, minmax(calc(100% / ${this.numVisible}), 1fr))`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
style() {
|
|
|
|
|