@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.
@@ -1,212 +1,226 @@
1
1
  import * as i0 from '@angular/core';
2
- import { EventEmitter, Output, Input, forwardRef, ContentChildren, HostBinding, Inject, Directive, input, HostListener, NgModule } from '@angular/core';
3
- import * as i2 from '@mintplayer/ng-swiper/observe-size';
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 { combineLatest, map, delay, filter, mergeMap, shareReplay, debounceTime, distinctUntilChanged, BehaviorSubject, take } from 'rxjs';
6
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
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
- destroy;
14
- observeSize;
15
- constructor(element, animationBuilder, destroy, document, observeSize) {
16
- this.animationBuilder = animationBuilder;
17
- this.destroy = destroy;
18
- this.observeSize = observeSize;
19
- this.containerElement = element;
20
- this.document = document;
21
- this.offset$ = combineLatest([
22
- this.startTouch$,
23
- this.lastTouch$,
24
- this.imageIndex$,
25
- this.isViewInited$,
26
- this.orientation$,
27
- this.observeSize.size$,
28
- ])
29
- .pipe(map(([startTouch, lastTouch, imageIndex, isViewInited, orientation, containerSize]) => {
30
- if (!isViewInited) {
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
- else if (!!startTouch && !!lastTouch) {
34
- const containerLength = orientation === 'horizontal'
35
- ? (containerSize?.width ?? this.containerElement.nativeElement.clientWidth)
36
- : (containerSize?.height ?? this.containerElement.nativeElement.clientHeight);
37
- if (containerLength === 0) {
38
- return (-imageIndex * 100);
39
- }
40
- const delta = orientation === 'horizontal'
41
- ? (lastTouch.position.x - startTouch.position.x)
42
- : (lastTouch.position.y - startTouch.position.y);
43
- return (-imageIndex * 100 + (delta / containerLength) * 100);
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
- return (-imageIndex * 100);
72
+ count++;
47
73
  }
48
- }));
49
- this.padLeft$ = this.swipes$.pipe(map(swipes => {
50
- if (!swipes) {
51
- return 0;
52
- }
53
- let count = 0;
54
- for (const s of swipes) {
55
- if (!s.offside()) {
56
- break;
57
- }
58
- else {
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
- return count;
63
- }));
64
- this.padRight$ = this.swipes$.pipe(map(swipes => {
65
- if (!swipes) {
66
- return 0;
86
+ else {
87
+ count++;
67
88
  }
68
- let count = 0;
69
- for (const s of swipes.toArray().reverse()) {
70
- if (!s.offside()) {
71
- break;
72
- }
73
- else {
74
- count++;
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.offsetTop = null;
141
+ this.offsetTopPx = null;
89
142
  }
90
143
  else {
91
- this.offsetTop = offsetPrimary;
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
- combineLatest([this.offsetSecondary$, this.orientation$])
96
- .pipe(takeUntilDestroyed())
97
- .subscribe(([offsetSecondary, orientation]) => {
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.offsetBottom = null;
163
+ this.offsetBottomPx = null;
101
164
  }
102
165
  else {
103
- this.offsetBottom = offsetSecondary;
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$.next(true);
173
+ this.isViewInited.set(true);
191
174
  }
192
175
  animateToIndexByDx(distance) {
193
- combineLatest([this.imageIndex$, this.actualSwipes$])
194
- .pipe(take(1), takeUntilDestroyed(this.destroy))
195
- .subscribe(([imageIndex, actualSwipes]) => {
196
- let newIndex;
197
- if (Math.abs(distance) < this.minimumOffset) {
198
- newIndex = imageIndex;
199
- }
200
- else {
201
- newIndex = imageIndex + (distance < 0 ? 1 : -1);
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 orientation = this.orientation$.value;
188
+ const animation = this.animation();
189
+ const orientation = this.orientation();
208
190
  const containerElement = this.containerElement.nativeElement;
209
- const containerLength = orientation === 'horizontal' ? containerElement.clientWidth : containerElement.clientHeight;
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$.next(totalSlides - 1);
251
+ this.imageIndex.set(totalSlides - 1);
238
252
  }
239
253
  else if (newIndex === totalSlides) {
240
- this.imageIndex$.next(0);
254
+ this.imageIndex.set(0);
241
255
  }
242
256
  else {
243
- this.imageIndex$.next(newIndex);
257
+ this.imageIndex.set(newIndex);
244
258
  }
245
- this.startTouch$.next(null);
246
- this.lastTouch$.next(null);
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
- combineLatest([this.actualSwipes$, this.imageIndex$])
268
- .pipe(take(1), takeUntilDestroyed(this.destroy))
269
- .subscribe(([actualSwipes, imageIndex]) => {
270
- this.pendingAnimation?.finish();
271
- const idx = (type === 'relative') ? imageIndex + index : index;
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: "20.1.7", ngImport: i0, type: BsSwipeContainerDirective, deps: [{ token: i0.ElementRef }, { token: i1.AnimationBuilder }, { token: i0.DestroyRef }, { token: DOCUMENT }, { token: i2.BsObserveSizeDirective }], target: i0.ɵɵFactoryTarget.Directive });
277
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.1.7", type: BsSwipeContainerDirective, isStandalone: false, selector: "[bsSwipeContainer]", inputs: { minimumOffset: "minimumOffset", orientation: "orientation", imageIndex: "imageIndex" }, outputs: { imageIndexChange: "imageIndexChange" }, host: { properties: { "style.margin-left.%": "this.offsetLeft", "style.margin-right.%": "this.offsetRight", "style.margin-top.%": "this.offsetTop", "style.margin-bottom.%": "this.offsetBottom" } }, queries: [{ propertyName: "swipes", predicate: i0.forwardRef(() => BsSwipeDirective) }], exportAs: ["bsSwipeContainer"], hostDirectives: [{ directive: i2.BsObserveSizeDirective }], ngImport: i0 });
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: "20.1.7", ngImport: i0, type: BsSwipeContainerDirective, decorators: [{
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: false,
299
+ standalone: true,
285
300
  hostDirectives: [BsObserveSizeDirective],
286
301
  }]
287
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.AnimationBuilder }, { type: i0.DestroyRef }, { type: undefined, decorators: [{
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
- }], offsetTop: [{
308
+ }], offsetTopPx: [{
297
309
  type: HostBinding,
298
- args: ['style.margin-top.%']
299
- }], offsetBottom: [{
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
- destroy;
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$.next({
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$.next({
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
- this.container.lastTouch$.next({
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
- combineLatest([this.container.startTouch$, this.container.lastTouch$, this.container.orientation$])
374
- .pipe(filter(([startTouch, lastTouch]) => !!startTouch && !!lastTouch))
375
- .pipe(take(1), takeUntilDestroyed(this.destroy))
376
- .subscribe(([startTouch, lastTouch, orientation]) => {
377
- if (!!startTouch && !!lastTouch) {
378
- const distance = (orientation === 'horizontal')
379
- ? lastTouch.position.x - startTouch.position.x
380
- : lastTouch.position.y - startTouch.position.y;
381
- this.container.onSwipe(distance);
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: "20.1.7", ngImport: i0, type: BsSwipeDirective, deps: [{ token: BsSwipeContainerDirective }, { token: i2.BsObserveSizeDirective }, { token: i0.DestroyRef }], target: i0.ɵɵFactoryTarget.Directive });
386
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.1.7", type: BsSwipeDirective, isStandalone: false, 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: i2.BsObserveSizeDirective }], ngImport: i0 });
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: "20.1.7", ngImport: i0, type: BsSwipeDirective, decorators: [{
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: false,
394
+ standalone: true,
394
395
  }]
395
- }], ctorParameters: () => [{ type: BsSwipeContainerDirective }, { type: i2.BsObserveSizeDirective }, { type: i0.DestroyRef }], propDecorators: { classes: [{
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: "20.1.7", ngImport: i0, type: BsSwiperModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
432
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.7", ngImport: i0, type: BsSwiperModule, declarations: [BsSwipeDirective, BsSwipeContainerDirective], imports: [CommonModule], exports: [BsSwipeDirective, BsSwipeContainerDirective] });
433
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: BsSwiperModule, imports: [CommonModule] });
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: "20.1.7", ngImport: i0, type: BsSwiperModule, decorators: [{
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: [CommonModule],
439
- declarations: [BsSwipeDirective, BsSwipeContainerDirective],
439
+ imports: [BsSwipeDirective, BsSwipeContainerDirective],
440
440
  exports: [BsSwipeDirective, BsSwipeContainerDirective],
441
441
  }]
442
442
  }] });