@mintplayer/ng-swiper 20.3.0 → 21.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/mintplayer-ng-swiper-observe-size.mjs +15 -25
- package/fesm2022/mintplayer-ng-swiper-observe-size.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-swiper-swiper.mjs +254 -254
- package/fesm2022/mintplayer-ng-swiper-swiper.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-swiper.mjs.map +1 -1
- package/package.json +9 -9
- package/types/mintplayer-ng-swiper-observe-size.d.ts +25 -0
- package/types/mintplayer-ng-swiper-swiper.d.ts +90 -0
- package/observe-size/index.d.ts +0 -26
- package/swiper/index.d.ts +0 -94
- /package/{index.d.ts → types/mintplayer-ng-swiper.d.ts} +0 -0
|
@@ -1,212 +1,226 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import * as
|
|
2
|
+
import { inject, ElementRef, input, model, output, signal, computed, effect, forwardRef, ContentChildren, HostBinding, Directive, HostListener, NgModule } from '@angular/core';
|
|
3
|
+
import * as i1 from '@mintplayer/ng-swiper/observe-size';
|
|
4
4
|
import { BsObserveSizeDirective } from '@mintplayer/ng-swiper/observe-size';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
8
|
-
import * as i1 from '@angular/animations';
|
|
9
|
-
import { style, animate } from '@angular/animations';
|
|
5
|
+
import { DOCUMENT } from '@angular/common';
|
|
6
|
+
import { AnimationBuilder, style, animate } from '@angular/animations';
|
|
10
7
|
|
|
11
8
|
class BsSwipeContainerDirective {
|
|
12
|
-
animationBuilder;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
animationBuilder = inject(AnimationBuilder);
|
|
10
|
+
observeSize = inject(BsObserveSizeDirective);
|
|
11
|
+
containerElement = inject((ElementRef));
|
|
12
|
+
document = inject(DOCUMENT);
|
|
13
|
+
offsetLeft = null;
|
|
14
|
+
offsetRight = null;
|
|
15
|
+
offsetTopPx = null;
|
|
16
|
+
offsetBottomPx = null;
|
|
17
|
+
set swipes(value) {
|
|
18
|
+
setTimeout(() => this._swipes.set(value));
|
|
19
|
+
}
|
|
20
|
+
minimumOffset = input(50, ...(ngDevMode ? [{ debugName: "minimumOffset" }] : []));
|
|
21
|
+
animation = input('slide', ...(ngDevMode ? [{ debugName: "animation" }] : []));
|
|
22
|
+
orientation = input('horizontal', ...(ngDevMode ? [{ debugName: "orientation" }] : []));
|
|
23
|
+
imageIndex = model(0, ...(ngDevMode ? [{ debugName: "imageIndex" }] : []));
|
|
24
|
+
animationStart = output();
|
|
25
|
+
animationEnd = output();
|
|
26
|
+
isViewInited = signal(false, ...(ngDevMode ? [{ debugName: "isViewInited" }] : []));
|
|
27
|
+
isAnimating = signal(false, ...(ngDevMode ? [{ debugName: "isAnimating" }] : []));
|
|
28
|
+
startTouch = signal(null, ...(ngDevMode ? [{ debugName: "startTouch" }] : []));
|
|
29
|
+
lastTouch = signal(null, ...(ngDevMode ? [{ debugName: "lastTouch" }] : []));
|
|
30
|
+
_swipes = signal(null, ...(ngDevMode ? [{ debugName: "_swipes" }] : []));
|
|
31
|
+
pendingAnimation;
|
|
32
|
+
// Computed signals for derived state
|
|
33
|
+
offset = computed(() => {
|
|
34
|
+
const startTouch = this.startTouch();
|
|
35
|
+
const lastTouch = this.lastTouch();
|
|
36
|
+
const imageIndex = this.imageIndex();
|
|
37
|
+
const isViewInited = this.isViewInited();
|
|
38
|
+
const orientation = this.orientation();
|
|
39
|
+
const containerSize = this.observeSize.size();
|
|
40
|
+
const maxSlideHeight = this.maxSlideHeight();
|
|
41
|
+
if (!isViewInited) {
|
|
42
|
+
return (-imageIndex * 100);
|
|
43
|
+
}
|
|
44
|
+
else if (!!startTouch && !!lastTouch) {
|
|
45
|
+
// For horizontal: use container width
|
|
46
|
+
// For vertical: use maxSlideHeight (single slide height, not total container height)
|
|
47
|
+
const containerLength = orientation === 'horizontal'
|
|
48
|
+
? (containerSize?.width ?? this.containerElement.nativeElement.clientWidth)
|
|
49
|
+
: maxSlideHeight;
|
|
50
|
+
if (containerLength === 0) {
|
|
31
51
|
return (-imageIndex * 100);
|
|
32
52
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
const delta = orientation === 'horizontal'
|
|
54
|
+
? (lastTouch.position.x - startTouch.position.x)
|
|
55
|
+
: (lastTouch.position.y - startTouch.position.y);
|
|
56
|
+
return (-imageIndex * 100 + (delta / containerLength) * 100);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return (-imageIndex * 100);
|
|
60
|
+
}
|
|
61
|
+
}, ...(ngDevMode ? [{ debugName: "offset" }] : []));
|
|
62
|
+
padLeft = computed(() => {
|
|
63
|
+
const swipes = this._swipes();
|
|
64
|
+
if (!swipes)
|
|
65
|
+
return 0;
|
|
66
|
+
let count = 0;
|
|
67
|
+
for (const s of swipes) {
|
|
68
|
+
if (!s.offside()) {
|
|
69
|
+
break;
|
|
44
70
|
}
|
|
45
71
|
else {
|
|
46
|
-
|
|
72
|
+
count++;
|
|
47
73
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
count++;
|
|
60
|
-
}
|
|
74
|
+
}
|
|
75
|
+
return count;
|
|
76
|
+
}, ...(ngDevMode ? [{ debugName: "padLeft" }] : []));
|
|
77
|
+
padRight = computed(() => {
|
|
78
|
+
const swipes = this._swipes();
|
|
79
|
+
if (!swipes)
|
|
80
|
+
return 0;
|
|
81
|
+
let count = 0;
|
|
82
|
+
for (const s of swipes.toArray().reverse()) {
|
|
83
|
+
if (!s.offside()) {
|
|
84
|
+
break;
|
|
61
85
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.padRight$ = this.swipes$.pipe(map(swipes => {
|
|
65
|
-
if (!swipes) {
|
|
66
|
-
return 0;
|
|
86
|
+
else {
|
|
87
|
+
count++;
|
|
67
88
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
}
|
|
90
|
+
return count;
|
|
91
|
+
}, ...(ngDevMode ? [{ debugName: "padRight" }] : []));
|
|
92
|
+
offsetPrimary = computed(() => this.offset() - this.padLeft() * 100, ...(ngDevMode ? [{ debugName: "offsetPrimary" }] : []));
|
|
93
|
+
offsetSecondary = computed(() => -(this.offset() - this.padLeft() * 100) - (this.padRight() - 1) * 100, ...(ngDevMode ? [{ debugName: "offsetSecondary" }] : []));
|
|
94
|
+
actualSwipes = computed(() => {
|
|
95
|
+
const swipes = this._swipes();
|
|
96
|
+
if (swipes) {
|
|
97
|
+
return swipes.filter(swipe => !swipe.offside());
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}, ...(ngDevMode ? [{ debugName: "actualSwipes" }] : []));
|
|
103
|
+
// Computed signal that reactively tracks all swipe sizes
|
|
104
|
+
slideSizes = computed(() => {
|
|
105
|
+
const actualSwipes = this.actualSwipes();
|
|
106
|
+
if (!actualSwipes || actualSwipes.length === 0) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
// Reading each swipe's size() creates reactive dependencies
|
|
110
|
+
return actualSwipes.map(swipe => swipe.observeSize.size());
|
|
111
|
+
}, ...(ngDevMode ? [{ debugName: "slideSizes" }] : []));
|
|
112
|
+
maxSlideHeight = computed(() => {
|
|
113
|
+
const slideSizes = this.slideSizes();
|
|
114
|
+
const heights = slideSizes.map(s => s?.height ?? 1);
|
|
115
|
+
return heights.length ? Math.max(...heights) : 1;
|
|
116
|
+
}, ...(ngDevMode ? [{ debugName: "maxSlideHeight" }] : []));
|
|
117
|
+
currentSlideHeight = computed(() => {
|
|
118
|
+
const slideSizes = this.slideSizes();
|
|
119
|
+
const imageIndex = this.imageIndex();
|
|
120
|
+
const orientation = this.orientation();
|
|
121
|
+
const heights = slideSizes.map(s => s?.height ?? 0);
|
|
122
|
+
const maxHeight = heights.length ? Math.max(...heights) : 0;
|
|
123
|
+
const currHeight = slideSizes[imageIndex]?.height ?? maxHeight;
|
|
124
|
+
const result = (orientation === 'vertical') ? maxHeight : currHeight;
|
|
125
|
+
// Return null if measurements aren't valid yet to avoid collapsing the carousel
|
|
126
|
+
return result > 10 ? result : null;
|
|
127
|
+
}, ...(ngDevMode ? [{ debugName: "currentSlideHeight" }] : []));
|
|
128
|
+
constructor() {
|
|
129
|
+
// Effect to update offsetLeft/offsetTopPx based on offsetPrimary and orientation
|
|
130
|
+
effect(() => {
|
|
131
|
+
const offsetPrimary = this.offsetPrimary();
|
|
132
|
+
const orientation = this.orientation();
|
|
133
|
+
const maxSlideHeight = this.maxSlideHeight();
|
|
134
|
+
const isAnimating = this.isAnimating();
|
|
135
|
+
// Skip updating offsets during animation to avoid interfering with CSS animation
|
|
136
|
+
if (isAnimating) {
|
|
137
|
+
return;
|
|
76
138
|
}
|
|
77
|
-
return count;
|
|
78
|
-
}));
|
|
79
|
-
this.offsetPrimary$ = combineLatest([this.offset$, this.padLeft$])
|
|
80
|
-
.pipe(map(([offset, padLeft]) => offset - padLeft * 100));
|
|
81
|
-
this.offsetSecondary$ = combineLatest([this.offset$, this.padLeft$, this.padRight$])
|
|
82
|
-
.pipe(map(([offset, padLeft, padRight]) => -(offset - padLeft * 100) - (padRight - 1) * 100));
|
|
83
|
-
combineLatest([this.offsetPrimary$, this.orientation$])
|
|
84
|
-
.pipe(takeUntilDestroyed())
|
|
85
|
-
.subscribe(([offsetPrimary, orientation]) => {
|
|
86
139
|
if (orientation === 'horizontal') {
|
|
87
140
|
this.offsetLeft = offsetPrimary;
|
|
88
|
-
this.
|
|
141
|
+
this.offsetTopPx = null;
|
|
89
142
|
}
|
|
90
143
|
else {
|
|
91
|
-
|
|
144
|
+
// For vertical mode, convert percentage to pixels using slide height
|
|
145
|
+
// offsetPrimary is in percentage units (e.g., -100 means -100%)
|
|
146
|
+
// We need to convert to pixels based on actual slide height
|
|
147
|
+
this.offsetTopPx = (offsetPrimary / 100) * maxSlideHeight;
|
|
92
148
|
this.offsetLeft = null;
|
|
93
149
|
}
|
|
94
150
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.
|
|
151
|
+
// Effect to update offsetRight/offsetBottomPx based on offsetSecondary and orientation
|
|
152
|
+
effect(() => {
|
|
153
|
+
const offsetSecondary = this.offsetSecondary();
|
|
154
|
+
const orientation = this.orientation();
|
|
155
|
+
const maxSlideHeight = this.maxSlideHeight();
|
|
156
|
+
const isAnimating = this.isAnimating();
|
|
157
|
+
// Skip updating offsets during animation to avoid interfering with CSS animation
|
|
158
|
+
if (isAnimating) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
98
161
|
if (orientation === 'horizontal') {
|
|
99
162
|
this.offsetRight = offsetSecondary;
|
|
100
|
-
this.
|
|
163
|
+
this.offsetBottomPx = null;
|
|
101
164
|
}
|
|
102
165
|
else {
|
|
103
|
-
|
|
166
|
+
// For vertical mode, convert percentage to pixels using slide height
|
|
167
|
+
this.offsetBottomPx = (offsetSecondary / 100) * maxSlideHeight;
|
|
104
168
|
this.offsetRight = null;
|
|
105
169
|
}
|
|
106
170
|
});
|
|
107
|
-
this.imageIndex$.pipe(takeUntilDestroyed())
|
|
108
|
-
.subscribe(imageIndex => this.imageIndexChange.emit(imageIndex));
|
|
109
|
-
this.actualSwipes$ = this.swipes$
|
|
110
|
-
.pipe(map(swipes => {
|
|
111
|
-
if (swipes) {
|
|
112
|
-
return swipes.filter(swipe => !swipe.offside());
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return [];
|
|
116
|
-
}
|
|
117
|
-
}));
|
|
118
|
-
this.slideSizes$ = this.actualSwipes$
|
|
119
|
-
.pipe(delay(400), filter(swipes => !!swipes))
|
|
120
|
-
.pipe(mergeMap(swipes => combineLatest(swipes.map(swipe => swipe.observeSize.size$))))
|
|
121
|
-
.pipe(shareReplay({ bufferSize: 1, refCount: true }));
|
|
122
|
-
this.maxSlideHeight$ = this.slideSizes$
|
|
123
|
-
.pipe(map(slideSizes => {
|
|
124
|
-
const heights = slideSizes.map(s => s?.height ?? 1);
|
|
125
|
-
return heights.length ? Math.max(...heights) : 1;
|
|
126
|
-
}))
|
|
127
|
-
.pipe(shareReplay({ bufferSize: 1, refCount: true }));
|
|
128
|
-
this.currentSlideHeight$ = combineLatest([this.slideSizes$, this.imageIndex$, this.orientation$])
|
|
129
|
-
.pipe(map(([slideSizes, imageIndex, orientation]) => {
|
|
130
|
-
const heights = slideSizes.map(s => s?.height ?? 1);
|
|
131
|
-
const maxHeight = heights.length ? Math.max(...heights) : 1;
|
|
132
|
-
const currHeight = slideSizes[imageIndex]?.height ?? maxHeight;
|
|
133
|
-
return (orientation === 'vertical') ? maxHeight : currHeight;
|
|
134
|
-
}))
|
|
135
|
-
.pipe(shareReplay({ bufferSize: 1, refCount: true }))
|
|
136
|
-
.pipe(debounceTime(10));
|
|
137
|
-
this.orientation$
|
|
138
|
-
.pipe(distinctUntilChanged(), takeUntilDestroyed())
|
|
139
|
-
.subscribe(() => {
|
|
140
|
-
this.offsetLeft = null;
|
|
141
|
-
this.offsetRight = null;
|
|
142
|
-
this.offsetTop = null;
|
|
143
|
-
this.offsetBottom = null;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
offsetLeft = null;
|
|
147
|
-
offsetRight = null;
|
|
148
|
-
offsetTop = null;
|
|
149
|
-
offsetBottom = null;
|
|
150
|
-
set swipes(value) {
|
|
151
|
-
setTimeout(() => this.swipes$.next(value));
|
|
152
|
-
}
|
|
153
|
-
minimumOffset = 50;
|
|
154
|
-
get orientation() {
|
|
155
|
-
return this.orientation$.value;
|
|
156
|
-
}
|
|
157
|
-
set orientation(value) {
|
|
158
|
-
this.orientation$.next(value ?? 'horizontal');
|
|
159
171
|
}
|
|
160
|
-
//#region ImageIndex
|
|
161
|
-
get imageIndex() {
|
|
162
|
-
return this.imageIndex$.value;
|
|
163
|
-
}
|
|
164
|
-
set imageIndex(value) {
|
|
165
|
-
this.imageIndex$.next(value);
|
|
166
|
-
}
|
|
167
|
-
imageIndexChange = new EventEmitter();
|
|
168
|
-
//#endregion
|
|
169
|
-
actualSwipes$;
|
|
170
|
-
isViewInited$ = new BehaviorSubject(false);
|
|
171
|
-
startTouch$ = new BehaviorSubject(null);
|
|
172
|
-
lastTouch$ = new BehaviorSubject(null);
|
|
173
|
-
swipes$ = new BehaviorSubject(null);
|
|
174
|
-
// TODO: slide sizes instead
|
|
175
|
-
slideSizes$;
|
|
176
|
-
maxSlideHeight$;
|
|
177
|
-
imageIndex$ = new BehaviorSubject(0);
|
|
178
|
-
currentSlideHeight$;
|
|
179
|
-
pendingAnimation;
|
|
180
|
-
containerElement;
|
|
181
|
-
document;
|
|
182
|
-
// TODO: Don't just keep px, but both px and % using currentslidesize$
|
|
183
|
-
offset$;
|
|
184
|
-
offsetPrimary$;
|
|
185
|
-
offsetSecondary$;
|
|
186
|
-
padLeft$;
|
|
187
|
-
padRight$;
|
|
188
|
-
orientation$ = new BehaviorSubject('horizontal');
|
|
189
172
|
ngAfterViewInit() {
|
|
190
|
-
this.isViewInited
|
|
173
|
+
this.isViewInited.set(true);
|
|
191
174
|
}
|
|
192
175
|
animateToIndexByDx(distance) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this.animateToIndex(imageIndex, newIndex, distance, actualSwipes?.length ?? 1);
|
|
204
|
-
});
|
|
176
|
+
const imageIndex = this.imageIndex();
|
|
177
|
+
const actualSwipes = this.actualSwipes();
|
|
178
|
+
let newIndex;
|
|
179
|
+
if (Math.abs(distance) < this.minimumOffset()) {
|
|
180
|
+
newIndex = imageIndex;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
newIndex = imageIndex + (distance < 0 ? 1 : -1);
|
|
184
|
+
}
|
|
185
|
+
this.animateToIndex(imageIndex, newIndex, distance, actualSwipes?.length ?? 1);
|
|
205
186
|
}
|
|
206
187
|
animateToIndex(oldIndex, newIndex, distance, totalSlides) {
|
|
207
|
-
const
|
|
188
|
+
const animation = this.animation();
|
|
189
|
+
const orientation = this.orientation();
|
|
208
190
|
const containerElement = this.containerElement.nativeElement;
|
|
209
|
-
const
|
|
191
|
+
const maxSlideHeight = this.maxSlideHeight();
|
|
192
|
+
// For vertical mode, use maxSlideHeight instead of container height
|
|
193
|
+
const containerLength = orientation === 'horizontal'
|
|
194
|
+
? containerElement.clientWidth
|
|
195
|
+
: maxSlideHeight;
|
|
196
|
+
this.animationStart.emit();
|
|
197
|
+
// Handle 'none' animation mode - instant transition
|
|
198
|
+
if (animation === 'none') {
|
|
199
|
+
// Correct the image index immediately
|
|
200
|
+
if (newIndex === -1) {
|
|
201
|
+
this.imageIndex.set(totalSlides - 1);
|
|
202
|
+
}
|
|
203
|
+
else if (newIndex === totalSlides) {
|
|
204
|
+
this.imageIndex.set(0);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
this.imageIndex.set(newIndex);
|
|
208
|
+
}
|
|
209
|
+
this.startTouch.set(null);
|
|
210
|
+
this.lastTouch.set(null);
|
|
211
|
+
this.animationEnd.emit();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Set animating flag and clear host bindings so animation has full control
|
|
215
|
+
this.isAnimating.set(true);
|
|
216
|
+
if (orientation === 'horizontal') {
|
|
217
|
+
this.offsetLeft = null;
|
|
218
|
+
this.offsetRight = null;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.offsetTopPx = null;
|
|
222
|
+
this.offsetBottomPx = null;
|
|
223
|
+
}
|
|
210
224
|
if (orientation === 'horizontal') {
|
|
211
225
|
this.pendingAnimation = this.animationBuilder.build([
|
|
212
226
|
style({
|
|
@@ -234,18 +248,21 @@ class BsSwipeContainerDirective {
|
|
|
234
248
|
this.pendingAnimation.onDone(() => {
|
|
235
249
|
// Correct the image index
|
|
236
250
|
if (newIndex === -1) {
|
|
237
|
-
this.imageIndex
|
|
251
|
+
this.imageIndex.set(totalSlides - 1);
|
|
238
252
|
}
|
|
239
253
|
else if (newIndex === totalSlides) {
|
|
240
|
-
this.imageIndex
|
|
254
|
+
this.imageIndex.set(0);
|
|
241
255
|
}
|
|
242
256
|
else {
|
|
243
|
-
this.imageIndex
|
|
257
|
+
this.imageIndex.set(newIndex);
|
|
244
258
|
}
|
|
245
|
-
this.startTouch
|
|
246
|
-
this.lastTouch
|
|
259
|
+
this.startTouch.set(null);
|
|
260
|
+
this.lastTouch.set(null);
|
|
247
261
|
this.pendingAnimation?.destroy();
|
|
248
262
|
this.pendingAnimation = undefined;
|
|
263
|
+
// Clear animating flag so effects can update offsets again
|
|
264
|
+
this.isAnimating.set(false);
|
|
265
|
+
this.animationEnd.emit();
|
|
249
266
|
});
|
|
250
267
|
this.pendingAnimation.play();
|
|
251
268
|
}
|
|
@@ -264,76 +281,58 @@ class BsSwipeContainerDirective {
|
|
|
264
281
|
gotoAnimate(index, type) {
|
|
265
282
|
this.pendingAnimation?.finish();
|
|
266
283
|
setTimeout(() => {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
this.animateToIndex(imageIndex, idx, 0, actualSwipes?.length ?? 1);
|
|
273
|
-
});
|
|
284
|
+
this.pendingAnimation?.finish();
|
|
285
|
+
const actualSwipes = this.actualSwipes();
|
|
286
|
+
const imageIndex = this.imageIndex();
|
|
287
|
+
const idx = (type === 'relative') ? imageIndex + index : index;
|
|
288
|
+
this.animateToIndex(imageIndex, idx, 0, actualSwipes?.length ?? 1);
|
|
274
289
|
}, 20);
|
|
275
290
|
}
|
|
276
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
277
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
291
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwipeContainerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
292
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.0.6", type: BsSwipeContainerDirective, isStandalone: true, selector: "[bsSwipeContainer]", inputs: { minimumOffset: { classPropertyName: "minimumOffset", publicName: "minimumOffset", isSignal: true, isRequired: false, transformFunction: null }, animation: { classPropertyName: "animation", publicName: "animation", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, imageIndex: { classPropertyName: "imageIndex", publicName: "imageIndex", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { imageIndex: "imageIndexChange", animationStart: "animationStart", animationEnd: "animationEnd" }, host: { properties: { "style.margin-left.%": "this.offsetLeft", "style.margin-right.%": "this.offsetRight", "style.margin-top.px": "this.offsetTopPx", "style.margin-bottom.px": "this.offsetBottomPx" } }, queries: [{ propertyName: "swipes", predicate: i0.forwardRef(() => BsSwipeDirective) }], exportAs: ["bsSwipeContainer"], hostDirectives: [{ directive: i1.BsObserveSizeDirective }], ngImport: i0 });
|
|
278
293
|
}
|
|
279
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
294
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwipeContainerDirective, decorators: [{
|
|
280
295
|
type: Directive,
|
|
281
296
|
args: [{
|
|
282
297
|
selector: '[bsSwipeContainer]',
|
|
283
298
|
exportAs: 'bsSwipeContainer',
|
|
284
|
-
standalone:
|
|
299
|
+
standalone: true,
|
|
285
300
|
hostDirectives: [BsObserveSizeDirective],
|
|
286
301
|
}]
|
|
287
|
-
}], ctorParameters: () => [
|
|
288
|
-
type: Inject,
|
|
289
|
-
args: [DOCUMENT]
|
|
290
|
-
}] }, { type: i2.BsObserveSizeDirective }], propDecorators: { offsetLeft: [{
|
|
302
|
+
}], ctorParameters: () => [], propDecorators: { offsetLeft: [{
|
|
291
303
|
type: HostBinding,
|
|
292
304
|
args: ['style.margin-left.%']
|
|
293
305
|
}], offsetRight: [{
|
|
294
306
|
type: HostBinding,
|
|
295
307
|
args: ['style.margin-right.%']
|
|
296
|
-
}],
|
|
308
|
+
}], offsetTopPx: [{
|
|
297
309
|
type: HostBinding,
|
|
298
|
-
args: ['style.margin-top
|
|
299
|
-
}],
|
|
310
|
+
args: ['style.margin-top.px']
|
|
311
|
+
}], offsetBottomPx: [{
|
|
300
312
|
type: HostBinding,
|
|
301
|
-
args: ['style.margin-bottom
|
|
313
|
+
args: ['style.margin-bottom.px']
|
|
302
314
|
}], swipes: [{
|
|
303
315
|
type: ContentChildren,
|
|
304
316
|
args: [forwardRef(() => BsSwipeDirective)]
|
|
305
|
-
}], minimumOffset: [{
|
|
306
|
-
type: Input
|
|
307
|
-
}], orientation: [{
|
|
308
|
-
type: Input
|
|
309
|
-
}], imageIndex: [{
|
|
310
|
-
type: Input
|
|
311
|
-
}], imageIndexChange: [{
|
|
312
|
-
type: Output
|
|
313
|
-
}] } });
|
|
317
|
+
}], minimumOffset: [{ type: i0.Input, args: [{ isSignal: true, alias: "minimumOffset", required: false }] }], animation: [{ type: i0.Input, args: [{ isSignal: true, alias: "animation", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], imageIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "imageIndex", required: false }] }, { type: i0.Output, args: ["imageIndexChange"] }], animationStart: [{ type: i0.Output, args: ["animationStart"] }], animationEnd: [{ type: i0.Output, args: ["animationEnd"] }] } });
|
|
314
318
|
|
|
315
319
|
class BsSwipeDirective {
|
|
316
|
-
container;
|
|
317
|
-
|
|
318
|
-
constructor(container, observeSize, destroy) {
|
|
319
|
-
this.container = container;
|
|
320
|
-
this.destroy = destroy;
|
|
321
|
-
this.observeSize = observeSize;
|
|
322
|
-
this.container.orientation$
|
|
323
|
-
.pipe(takeUntilDestroyed())
|
|
324
|
-
.subscribe(orientation => {
|
|
325
|
-
this.inlineBlock = (orientation === 'horizontal');
|
|
326
|
-
this.block = (orientation === 'vertical');
|
|
327
|
-
});
|
|
328
|
-
combineLatest([this.container.maxSlideHeight$, this.container.orientation$])
|
|
329
|
-
.pipe(takeUntilDestroyed())
|
|
330
|
-
.subscribe(([maxHeight, orientation]) => {
|
|
331
|
-
const targetHeight = (orientation === 'vertical') ? maxHeight : null;
|
|
332
|
-
this.slideHeight = (targetHeight && targetHeight > 0) ? targetHeight : null;
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
observeSize;
|
|
320
|
+
container = inject(BsSwipeContainerDirective);
|
|
321
|
+
observeSize = inject(BsObserveSizeDirective);
|
|
336
322
|
offside = input(false, ...(ngDevMode ? [{ debugName: "offside" }] : []));
|
|
323
|
+
orientationEffect = effect(() => {
|
|
324
|
+
const orientation = this.container.orientation();
|
|
325
|
+
this.inlineBlock = (orientation === 'horizontal');
|
|
326
|
+
this.block = (orientation === 'vertical');
|
|
327
|
+
}, ...(ngDevMode ? [{ debugName: "orientationEffect" }] : []));
|
|
328
|
+
heightEffect = effect(() => {
|
|
329
|
+
const maxHeight = this.container.maxSlideHeight();
|
|
330
|
+
const orientation = this.container.orientation();
|
|
331
|
+
// Only set height when we have valid measurements (> 10px threshold)
|
|
332
|
+
// to avoid circular dependency during initial load
|
|
333
|
+
const targetHeight = (orientation === 'vertical' && maxHeight > 10) ? maxHeight : null;
|
|
334
|
+
this.slideHeight = targetHeight;
|
|
335
|
+
}, ...(ngDevMode ? [{ debugName: "heightEffect" }] : []));
|
|
337
336
|
classes = true;
|
|
338
337
|
inlineBlock = true;
|
|
339
338
|
block = false;
|
|
@@ -341,16 +340,17 @@ class BsSwipeDirective {
|
|
|
341
340
|
onTouchStart(ev) {
|
|
342
341
|
if (ev.touches.length === 1) {
|
|
343
342
|
ev.preventDefault();
|
|
343
|
+
ev.stopPropagation();
|
|
344
344
|
this.container.pendingAnimation?.finish();
|
|
345
345
|
setTimeout(() => {
|
|
346
|
-
this.container.startTouch
|
|
346
|
+
this.container.startTouch.set({
|
|
347
347
|
position: {
|
|
348
348
|
x: ev.touches[0].clientX,
|
|
349
349
|
y: ev.touches[0].clientY,
|
|
350
350
|
},
|
|
351
351
|
timestamp: Date.now(),
|
|
352
352
|
});
|
|
353
|
-
this.container.lastTouch
|
|
353
|
+
this.container.lastTouch.set({
|
|
354
354
|
position: {
|
|
355
355
|
x: ev.touches[0].clientX,
|
|
356
356
|
y: ev.touches[0].clientY,
|
|
@@ -361,7 +361,9 @@ class BsSwipeDirective {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
onTouchMove(ev) {
|
|
364
|
-
|
|
364
|
+
ev.preventDefault();
|
|
365
|
+
ev.stopPropagation();
|
|
366
|
+
this.container.lastTouch.set({
|
|
365
367
|
position: {
|
|
366
368
|
x: ev.touches[0].clientX,
|
|
367
369
|
y: ev.touches[0].clientY,
|
|
@@ -370,29 +372,28 @@ class BsSwipeDirective {
|
|
|
370
372
|
});
|
|
371
373
|
}
|
|
372
374
|
onTouchEnd(ev) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
});
|
|
375
|
+
ev.stopPropagation();
|
|
376
|
+
const startTouch = this.container.startTouch();
|
|
377
|
+
const lastTouch = this.container.lastTouch();
|
|
378
|
+
const orientation = this.container.orientation();
|
|
379
|
+
if (!!startTouch && !!lastTouch) {
|
|
380
|
+
const distance = (orientation === 'horizontal')
|
|
381
|
+
? lastTouch.position.x - startTouch.position.x
|
|
382
|
+
: lastTouch.position.y - startTouch.position.y;
|
|
383
|
+
this.container.onSwipe(distance);
|
|
384
|
+
}
|
|
384
385
|
}
|
|
385
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
386
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "
|
|
386
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwipeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
387
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.0.6", type: BsSwipeDirective, isStandalone: true, selector: "[bsSwipe]", inputs: { offside: { classPropertyName: "offside", publicName: "offside", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "touchstart": "onTouchStart($event)", "touchmove": "onTouchMove($event)", "touchend": "onTouchEnd($event)" }, properties: { "class.align-top": "this.classes", "class.float-none": "this.classes", "class.w-100": "this.classes", "class.pe-auto": "this.classes", "class.me-0": "this.classes", "class.d-inline-block": "this.inlineBlock", "class.d-block": "this.block", "style.height.px": "this.slideHeight" } }, hostDirectives: [{ directive: i1.BsObserveSizeDirective }], ngImport: i0 });
|
|
387
388
|
}
|
|
388
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
389
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwipeDirective, decorators: [{
|
|
389
390
|
type: Directive,
|
|
390
391
|
args: [{
|
|
391
392
|
selector: '[bsSwipe]',
|
|
392
393
|
hostDirectives: [BsObserveSizeDirective],
|
|
393
|
-
standalone:
|
|
394
|
+
standalone: true,
|
|
394
395
|
}]
|
|
395
|
-
}],
|
|
396
|
+
}], propDecorators: { offside: [{ type: i0.Input, args: [{ isSignal: true, alias: "offside", required: false }] }], classes: [{
|
|
396
397
|
type: HostBinding,
|
|
397
398
|
args: ['class.align-top']
|
|
398
399
|
}, {
|
|
@@ -428,15 +429,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImpor
|
|
|
428
429
|
}] } });
|
|
429
430
|
|
|
430
431
|
class BsSwiperModule {
|
|
431
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
432
|
-
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
433
|
-
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
432
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwiperModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
433
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.6", ngImport: i0, type: BsSwiperModule, imports: [BsSwipeDirective, BsSwipeContainerDirective], exports: [BsSwipeDirective, BsSwipeContainerDirective] });
|
|
434
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwiperModule });
|
|
434
435
|
}
|
|
435
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
436
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: BsSwiperModule, decorators: [{
|
|
436
437
|
type: NgModule,
|
|
437
438
|
args: [{
|
|
438
|
-
imports: [
|
|
439
|
-
declarations: [BsSwipeDirective, BsSwipeContainerDirective],
|
|
439
|
+
imports: [BsSwipeDirective, BsSwipeContainerDirective],
|
|
440
440
|
exports: [BsSwipeDirective, BsSwipeContainerDirective],
|
|
441
441
|
}]
|
|
442
442
|
}] });
|