vevet 2.0.1-dev.23 → 2.0.1-dev.24

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.
@@ -49,7 +49,8 @@ var ScrollView = /** @class */ (function (_super) {
49
49
  if (init === void 0) { init = true; }
50
50
  var _this = _super.call(this, initialProp, false) || this;
51
51
  _this._scrollEvent = undefined;
52
- _this._intersectionObserver = undefined;
52
+ _this._intersectionObserverIn = undefined;
53
+ _this._intersectionObserverOut = undefined;
53
54
  _this._firstStart = true;
54
55
  _this._elements = __spreadArray([], _this.prop.elements);
55
56
  // initialize the class
@@ -117,17 +118,27 @@ var ScrollView = /** @class */ (function (_super) {
117
118
  ? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
118
119
  var yMargin = this._firstStart
119
120
  ? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
120
- // create intersection observer
121
- this._intersectionObserver = new IntersectionObserver(this._handleIntersectionObserver.bind(this), {
121
+ // create intersection observers
122
+ this._intersectionObserverIn = new IntersectionObserver(this._handleIntersectionObserverIn.bind(this), {
122
123
  root: this.intersectionRoot,
123
124
  threshold: 0,
124
125
  rootMargin: "0px " + xMargin + "px " + yMargin + "px 0px",
125
126
  });
126
- // add elements
127
127
  this.elements.forEach(function (el) {
128
128
  var _a;
129
- (_a = _this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
129
+ (_a = _this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(el);
130
130
  });
131
+ if (this.prop.states === 'inout') {
132
+ this._intersectionObserverOut = new IntersectionObserver(this._handleIntersectionObserverOut.bind(this), {
133
+ root: this.intersectionRoot,
134
+ threshold: 0,
135
+ rootMargin: '0px 0px 0px 0px',
136
+ });
137
+ this.elements.forEach(function (el) {
138
+ var _a;
139
+ (_a = _this._intersectionObserverOut) === null || _a === void 0 ? void 0 : _a.observe(el);
140
+ });
141
+ }
131
142
  }
132
143
  else {
133
144
  // set scroll bounding events
@@ -141,21 +152,22 @@ var ScrollView = /** @class */ (function (_super) {
141
152
  * Remove View events: scroll or intersection
142
153
  */
143
154
  ScrollView.prototype._removeViewEvents = function () {
155
+ var _a, _b;
144
156
  // remove scroll events
145
157
  if (this._scrollEvent) {
146
158
  this._scrollEvent.remove();
147
159
  this._scrollEvent = undefined;
148
160
  }
149
- // destroy intersection observer
150
- if (this._intersectionObserver) {
151
- this._intersectionObserver.disconnect();
152
- this._intersectionObserver = undefined;
153
- }
161
+ // destroy intersection observers
162
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.disconnect();
163
+ this._intersectionObserverIn = undefined;
164
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.disconnect();
165
+ this._intersectionObserverOut = undefined;
154
166
  };
155
167
  /**
156
168
  * Event on IntersectionObserver
157
169
  */
158
- ScrollView.prototype._handleIntersectionObserver = function (data) {
170
+ ScrollView.prototype._handleIntersectionObserverIn = function (data) {
159
171
  var parentBounding = this._firstStart ? this.scrollContainerBounding : false;
160
172
  for (var index = 0; index < data.length; index += 1) {
161
173
  var entry = data[index];
@@ -163,7 +175,9 @@ var ScrollView = /** @class */ (function (_super) {
163
175
  if (this._firstStart && !!parentBounding && entry.isIntersecting) {
164
176
  delay = this._elementInViewportData(entry.target, parentBounding).delay;
165
177
  }
166
- this._handleInOut(entry.target, entry.isIntersecting, delay);
178
+ if (entry.isIntersecting) {
179
+ this._handleInOut(entry.target, entry.isIntersecting, delay);
180
+ }
167
181
  }
168
182
  this._processUnusedElements();
169
183
  // change states
@@ -172,6 +186,17 @@ var ScrollView = /** @class */ (function (_super) {
172
186
  this.resize();
173
187
  }
174
188
  };
189
+ /**
190
+ * Event on IntersectionObserver
191
+ */
192
+ ScrollView.prototype._handleIntersectionObserverOut = function (data) {
193
+ for (var index = 0; index < data.length; index += 1) {
194
+ var entry = data[index];
195
+ if (!entry.isIntersecting) {
196
+ this._handleInOut(entry.target, entry.isIntersecting, 0);
197
+ }
198
+ }
199
+ };
175
200
  /**
176
201
  * Event on Scroll
177
202
  */
@@ -194,7 +219,9 @@ var ScrollView = /** @class */ (function (_super) {
194
219
  var el = this.elements[index];
195
220
  var elData = this._elementInViewportData(el, scrollContainerBounding);
196
221
  var delay = elData.isIntersecting ? elData.delay : 0;
197
- this._handleInOut(el, elData.isIntersecting, delay);
222
+ if (typeof elData.isIntersecting === 'boolean') {
223
+ this._handleInOut(el, elData.isIntersecting, delay);
224
+ }
198
225
  }
199
226
  this._processUnusedElements();
200
227
  // change states
@@ -210,7 +237,7 @@ var ScrollView = /** @class */ (function (_super) {
210
237
  var threshold = this._firstStart ? 1 : propThreshold;
211
238
  var bounding = el.getBoundingClientRect();
212
239
  // check if the element is intersecting
213
- var isIntersecting = false;
240
+ var isIntersecting;
214
241
  if (bounding.top < parentBounding.top + parentBounding.height * threshold
215
242
  && bounding.left < parentBounding.left + parentBounding.width * threshold) {
216
243
  if (states === 'in') {
@@ -224,6 +251,10 @@ var ScrollView = /** @class */ (function (_super) {
224
251
  isIntersecting = true;
225
252
  }
226
253
  }
254
+ else if (bounding.top > parentBounding.top + parentBounding.height
255
+ || bounding.left > parentBounding.left + parentBounding.width) {
256
+ isIntersecting = false;
257
+ }
227
258
  // calculate delay only if it is enabled & calculations
228
259
  // are done for the first time
229
260
  var delay = 0;
@@ -281,9 +312,9 @@ var ScrollView = /** @class */ (function (_super) {
281
312
  // remove unused elements
282
313
  var elementsToRemove = this._elements.filter(function (el) { return el.scrollViewIn; });
283
314
  elementsToRemove.forEach(function (el) {
284
- if (_this._intersectionObserver) {
285
- _this._intersectionObserver.unobserve(el);
286
- }
315
+ var _a, _b;
316
+ (_a = _this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(el);
317
+ (_b = _this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(el);
287
318
  });
288
319
  this._elements = this._elements.filter(function (el) { return !el.scrollViewIn; });
289
320
  };
@@ -292,12 +323,12 @@ var ScrollView = /** @class */ (function (_super) {
292
323
  */
293
324
  ScrollView.prototype.addElement = function (element) {
294
325
  var _this = this;
326
+ var _a, _b;
295
327
  var viewEl = element;
296
328
  viewEl.scrollViewIn = undefined;
297
329
  this._elements.push(element);
298
- if (this._intersectionObserver) {
299
- this._intersectionObserver.observe(element);
300
- }
330
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(element);
331
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.observe(element);
301
332
  if (this.prop.enabled) {
302
333
  this.seekBounding();
303
334
  }
@@ -311,12 +342,12 @@ var ScrollView = /** @class */ (function (_super) {
311
342
  * Remove a view element
312
343
  */
313
344
  ScrollView.prototype.removeElement = function (element) {
345
+ var _a, _b;
314
346
  var viewEl = element;
315
347
  viewEl.scrollViewIn = undefined;
316
348
  this._elements = this._elements.filter(function (el) { return el !== element; });
317
- if (this._intersectionObserver) {
318
- this._intersectionObserver.unobserve(element);
319
- }
349
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(element);
350
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(element);
320
351
  };
321
352
  /**
322
353
  * Remove all view elements
@@ -324,9 +355,7 @@ var ScrollView = /** @class */ (function (_super) {
324
355
  ScrollView.prototype.removeElements = function () {
325
356
  var _this = this;
326
357
  this._elements.forEach(function (el) {
327
- if (_this._intersectionObserver) {
328
- _this._intersectionObserver.unobserve(el);
329
- }
358
+ _this.removeElement(el);
330
359
  });
331
360
  this._elements = [];
332
361
  };
@@ -10,7 +10,8 @@ export class ScrollView extends ScrollEventsBase {
10
10
  constructor(initialProp, init = true) {
11
11
  super(initialProp, false);
12
12
  this._scrollEvent = undefined;
13
- this._intersectionObserver = undefined;
13
+ this._intersectionObserverIn = undefined;
14
+ this._intersectionObserverOut = undefined;
14
15
  this._firstStart = true;
15
16
  this._elements = [...this.prop.elements];
16
17
  // initialize the class
@@ -67,17 +68,27 @@ export class ScrollView extends ScrollEventsBase {
67
68
  ? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
68
69
  const yMargin = this._firstStart
69
70
  ? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
70
- // create intersection observer
71
- this._intersectionObserver = new IntersectionObserver(this._handleIntersectionObserver.bind(this), {
71
+ // create intersection observers
72
+ this._intersectionObserverIn = new IntersectionObserver(this._handleIntersectionObserverIn.bind(this), {
72
73
  root: this.intersectionRoot,
73
74
  threshold: 0,
74
75
  rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
75
76
  });
76
- // add elements
77
77
  this.elements.forEach((el) => {
78
78
  var _a;
79
- (_a = this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
79
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(el);
80
80
  });
81
+ if (this.prop.states === 'inout') {
82
+ this._intersectionObserverOut = new IntersectionObserver(this._handleIntersectionObserverOut.bind(this), {
83
+ root: this.intersectionRoot,
84
+ threshold: 0,
85
+ rootMargin: '0px 0px 0px 0px',
86
+ });
87
+ this.elements.forEach((el) => {
88
+ var _a;
89
+ (_a = this._intersectionObserverOut) === null || _a === void 0 ? void 0 : _a.observe(el);
90
+ });
91
+ }
81
92
  }
82
93
  else {
83
94
  // set scroll bounding events
@@ -91,21 +102,22 @@ export class ScrollView extends ScrollEventsBase {
91
102
  * Remove View events: scroll or intersection
92
103
  */
93
104
  _removeViewEvents() {
105
+ var _a, _b;
94
106
  // remove scroll events
95
107
  if (this._scrollEvent) {
96
108
  this._scrollEvent.remove();
97
109
  this._scrollEvent = undefined;
98
110
  }
99
- // destroy intersection observer
100
- if (this._intersectionObserver) {
101
- this._intersectionObserver.disconnect();
102
- this._intersectionObserver = undefined;
103
- }
111
+ // destroy intersection observers
112
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.disconnect();
113
+ this._intersectionObserverIn = undefined;
114
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.disconnect();
115
+ this._intersectionObserverOut = undefined;
104
116
  }
105
117
  /**
106
118
  * Event on IntersectionObserver
107
119
  */
108
- _handleIntersectionObserver(data) {
120
+ _handleIntersectionObserverIn(data) {
109
121
  const parentBounding = this._firstStart ? this.scrollContainerBounding : false;
110
122
  for (let index = 0; index < data.length; index += 1) {
111
123
  const entry = data[index];
@@ -113,7 +125,9 @@ export class ScrollView extends ScrollEventsBase {
113
125
  if (this._firstStart && !!parentBounding && entry.isIntersecting) {
114
126
  delay = this._elementInViewportData(entry.target, parentBounding).delay;
115
127
  }
116
- this._handleInOut(entry.target, entry.isIntersecting, delay);
128
+ if (entry.isIntersecting) {
129
+ this._handleInOut(entry.target, entry.isIntersecting, delay);
130
+ }
117
131
  }
118
132
  this._processUnusedElements();
119
133
  // change states
@@ -122,6 +136,17 @@ export class ScrollView extends ScrollEventsBase {
122
136
  this.resize();
123
137
  }
124
138
  }
139
+ /**
140
+ * Event on IntersectionObserver
141
+ */
142
+ _handleIntersectionObserverOut(data) {
143
+ for (let index = 0; index < data.length; index += 1) {
144
+ const entry = data[index];
145
+ if (!entry.isIntersecting) {
146
+ this._handleInOut(entry.target, entry.isIntersecting, 0);
147
+ }
148
+ }
149
+ }
125
150
  /**
126
151
  * Event on Scroll
127
152
  */
@@ -144,7 +169,9 @@ export class ScrollView extends ScrollEventsBase {
144
169
  const el = this.elements[index];
145
170
  const elData = this._elementInViewportData(el, scrollContainerBounding);
146
171
  const delay = elData.isIntersecting ? elData.delay : 0;
147
- this._handleInOut(el, elData.isIntersecting, delay);
172
+ if (typeof elData.isIntersecting === 'boolean') {
173
+ this._handleInOut(el, elData.isIntersecting, delay);
174
+ }
148
175
  }
149
176
  this._processUnusedElements();
150
177
  // change states
@@ -160,7 +187,7 @@ export class ScrollView extends ScrollEventsBase {
160
187
  const threshold = this._firstStart ? 1 : propThreshold;
161
188
  const bounding = el.getBoundingClientRect();
162
189
  // check if the element is intersecting
163
- let isIntersecting = false;
190
+ let isIntersecting;
164
191
  if (bounding.top < parentBounding.top + parentBounding.height * threshold
165
192
  && bounding.left < parentBounding.left + parentBounding.width * threshold) {
166
193
  if (states === 'in') {
@@ -174,6 +201,10 @@ export class ScrollView extends ScrollEventsBase {
174
201
  isIntersecting = true;
175
202
  }
176
203
  }
204
+ else if (bounding.top > parentBounding.top + parentBounding.height
205
+ || bounding.left > parentBounding.left + parentBounding.width) {
206
+ isIntersecting = false;
207
+ }
177
208
  // calculate delay only if it is enabled & calculations
178
209
  // are done for the first time
179
210
  let delay = 0;
@@ -228,9 +259,9 @@ export class ScrollView extends ScrollEventsBase {
228
259
  // remove unused elements
229
260
  const elementsToRemove = this._elements.filter((el) => el.scrollViewIn);
230
261
  elementsToRemove.forEach((el) => {
231
- if (this._intersectionObserver) {
232
- this._intersectionObserver.unobserve(el);
233
- }
262
+ var _a, _b;
263
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(el);
264
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(el);
234
265
  });
235
266
  this._elements = this._elements.filter((el) => !el.scrollViewIn);
236
267
  }
@@ -238,12 +269,12 @@ export class ScrollView extends ScrollEventsBase {
238
269
  * Add a view element
239
270
  */
240
271
  addElement(element) {
272
+ var _a, _b;
241
273
  const viewEl = element;
242
274
  viewEl.scrollViewIn = undefined;
243
275
  this._elements.push(element);
244
- if (this._intersectionObserver) {
245
- this._intersectionObserver.observe(element);
246
- }
276
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(element);
277
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.observe(element);
247
278
  if (this.prop.enabled) {
248
279
  this.seekBounding();
249
280
  }
@@ -257,21 +288,19 @@ export class ScrollView extends ScrollEventsBase {
257
288
  * Remove a view element
258
289
  */
259
290
  removeElement(element) {
291
+ var _a, _b;
260
292
  const viewEl = element;
261
293
  viewEl.scrollViewIn = undefined;
262
294
  this._elements = this._elements.filter((el) => el !== element);
263
- if (this._intersectionObserver) {
264
- this._intersectionObserver.unobserve(element);
265
- }
295
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(element);
296
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(element);
266
297
  }
267
298
  /**
268
299
  * Remove all view elements
269
300
  */
270
301
  removeElements() {
271
302
  this._elements.forEach((el) => {
272
- if (this._intersectionObserver) {
273
- this._intersectionObserver.unobserve(el);
274
- }
303
+ this.removeElement(el);
275
304
  });
276
305
  this._elements = [];
277
306
  }
@@ -78,9 +78,13 @@ export declare class ScrollView<StaticProp extends NScrollView.StaticProp = NScr
78
78
  */
79
79
  protected _scrollEvent?: IRemovable;
80
80
  /**
81
- * Intersection observer
81
+ * Intersection observer - type IN
82
82
  */
83
- protected _intersectionObserver?: IntersectionObserver;
83
+ protected _intersectionObserverIn?: IntersectionObserver;
84
+ /**
85
+ * Intersection observer - type OUT
86
+ */
87
+ protected _intersectionObserverOut?: IntersectionObserver;
84
88
  /**
85
89
  * If first start
86
90
  */
@@ -109,7 +113,11 @@ export declare class ScrollView<StaticProp extends NScrollView.StaticProp = NScr
109
113
  /**
110
114
  * Event on IntersectionObserver
111
115
  */
112
- protected _handleIntersectionObserver(data: IntersectionObserverEntry[]): void;
116
+ protected _handleIntersectionObserverIn(data: IntersectionObserverEntry[]): void;
117
+ /**
118
+ * Event on IntersectionObserver
119
+ */
120
+ protected _handleIntersectionObserverOut(data: IntersectionObserverEntry[]): void;
113
121
  /**
114
122
  * Event on Scroll
115
123
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollView.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EA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cAAc,CAAC,KACvD,CAAC;IAgBP;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,EAAE,UAAU,CAAC;IACpC;;OAEG;IACH,SAAS,CAAC,qBAAqB,CAAC,EAAE,oBAAoB,CAAC;IAEvD;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC;IAE/B,SAAS,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC;IACtC;;OAEG;IACH,IAAI,QAAQ,qBAEX;gBAKG,WAAW,CAAC,EAAE,CAAC,UAAU,GAAG,cAAc,CAAC,EAC3C,IAAI,UAAO;IAeR,IAAI;IAKX,SAAS,CAAC,UAAU;IAQpB,SAAS,CAAC,aAAa;IAKvB;;OAEG;IACI,MAAM;IAQb;;OAEG;IACH,SAAS,CAAC,cAAc;IA+BxB;;OAEG;IACH,SAAS,CAAC,iBAAiB;IAa3B;;OAEG;IACH,SAAS,CAAC,2BAA2B,CACjC,IAAI,EAAE,yBAAyB,EAAE;IAuBrC;;OAEG;IACH,SAAS,CAAC,aAAa;IAIvB;;;OAGG;IACI,YAAY;IAwBnB;;OAEG;IACH,SAAS,CAAC,sBAAsB,CAC5B,EAAE,EAAE,OAAO,EACX,cAAc,EAAE,iBAAiB,CAAC,YAAY;;;;IA2ClD;;OAEG;IACH,SAAS,CAAC,YAAY,CAClB,EAAE,EAAE,WAAW,CAAC,EAAE,EAClB,UAAU,EAAE,OAAO,EACnB,KAAK,SAAI;IAgCb;;OAEG;IACH,SAAS,CAAC,sBAAsB;IAehC;;OAEG;IACI,UAAU,CACb,OAAO,EAAE,OAAO,GACjB,UAAU;IAiBb;;OAEG;IACI,aAAa,CAChB,OAAO,EAAE,OAAO;IAUpB;;OAEG;IACI,cAAc;IAWrB;;OAEG;IACH,SAAS,CAAC,QAAQ;CAIrB"}
1
+ {"version":3,"file":"ScrollView.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollView.ts"],"names":[],"mappings":"AAAA,OAA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ACb,OAAO,EAAE,OAAO,GACjB,UAAU;IAgBb;;OAEG;IACI,aAAa,CAChB,OAAO,EAAE,OAAO;IASpB;;OAEG;IACI,cAAc;IASrB;;OAEG;IACH,SAAS,CAAC,QAAQ;CAIrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vevet",
3
- "version": "2.0.1-dev.23",
3
+ "version": "2.0.1-dev.24",
4
4
  "description": "VEVET - A JavaScript library",
5
5
  "browserslist": [
6
6
  "since 2015"
@@ -120,9 +120,13 @@ export class ScrollView <
120
120
  */
121
121
  protected _scrollEvent?: IRemovable;
122
122
  /**
123
- * Intersection observer
123
+ * Intersection observer - type IN
124
124
  */
125
- protected _intersectionObserver?: IntersectionObserver;
125
+ protected _intersectionObserverIn?: IntersectionObserver;
126
+ /**
127
+ * Intersection observer - type OUT
128
+ */
129
+ protected _intersectionObserverOut?: IntersectionObserver;
126
130
 
127
131
  /**
128
132
  * If first start
@@ -146,7 +150,8 @@ export class ScrollView <
146
150
  super(initialProp, false);
147
151
 
148
152
  this._scrollEvent = undefined;
149
- this._intersectionObserver = undefined;
153
+ this._intersectionObserverIn = undefined;
154
+ this._intersectionObserverOut = undefined;
150
155
  this._firstStart = true;
151
156
  this._elements = [...this.prop.elements];
152
157
 
@@ -197,19 +202,31 @@ export class ScrollView <
197
202
  ? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
198
203
  const yMargin = this._firstStart
199
204
  ? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
200
- // create intersection observer
201
- this._intersectionObserver = new IntersectionObserver(
202
- this._handleIntersectionObserver.bind(this),
205
+ // create intersection observers
206
+ this._intersectionObserverIn = new IntersectionObserver(
207
+ this._handleIntersectionObserverIn.bind(this),
203
208
  {
204
209
  root: this.intersectionRoot,
205
210
  threshold: 0,
206
211
  rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
207
212
  },
208
213
  );
209
- // add elements
210
214
  this.elements.forEach((el) => {
211
- this._intersectionObserver?.observe(el);
215
+ this._intersectionObserverIn?.observe(el);
212
216
  });
217
+ if (this.prop.states === 'inout') {
218
+ this._intersectionObserverOut = new IntersectionObserver(
219
+ this._handleIntersectionObserverOut.bind(this),
220
+ {
221
+ root: this.intersectionRoot,
222
+ threshold: 0,
223
+ rootMargin: '0px 0px 0px 0px',
224
+ },
225
+ );
226
+ this.elements.forEach((el) => {
227
+ this._intersectionObserverOut?.observe(el);
228
+ });
229
+ }
213
230
  } else {
214
231
  // set scroll bounding events
215
232
  this._scrollEvent = onScroll({
@@ -228,17 +245,17 @@ export class ScrollView <
228
245
  this._scrollEvent.remove();
229
246
  this._scrollEvent = undefined;
230
247
  }
231
- // destroy intersection observer
232
- if (this._intersectionObserver) {
233
- this._intersectionObserver.disconnect();
234
- this._intersectionObserver = undefined;
235
- }
248
+ // destroy intersection observers
249
+ this._intersectionObserverIn?.disconnect();
250
+ this._intersectionObserverIn = undefined;
251
+ this._intersectionObserverOut?.disconnect();
252
+ this._intersectionObserverOut = undefined;
236
253
  }
237
254
 
238
255
  /**
239
256
  * Event on IntersectionObserver
240
257
  */
241
- protected _handleIntersectionObserver (
258
+ protected _handleIntersectionObserverIn (
242
259
  data: IntersectionObserverEntry[],
243
260
  ) {
244
261
  const parentBounding = this._firstStart ? this.scrollContainerBounding : false;
@@ -248,11 +265,13 @@ export class ScrollView <
248
265
  if (this._firstStart && !!parentBounding && entry.isIntersecting) {
249
266
  delay = this._elementInViewportData(entry.target, parentBounding).delay;
250
267
  }
251
- this._handleInOut(
252
- entry.target,
253
- entry.isIntersecting,
254
- delay,
255
- );
268
+ if (entry.isIntersecting) {
269
+ this._handleInOut(
270
+ entry.target,
271
+ entry.isIntersecting,
272
+ delay,
273
+ );
274
+ }
256
275
  }
257
276
  this._processUnusedElements();
258
277
  // change states
@@ -262,6 +281,24 @@ export class ScrollView <
262
281
  }
263
282
  }
264
283
 
284
+ /**
285
+ * Event on IntersectionObserver
286
+ */
287
+ protected _handleIntersectionObserverOut (
288
+ data: IntersectionObserverEntry[],
289
+ ) {
290
+ for (let index = 0; index < data.length; index += 1) {
291
+ const entry = data[index];
292
+ if (!entry.isIntersecting) {
293
+ this._handleInOut(
294
+ entry.target,
295
+ entry.isIntersecting,
296
+ 0,
297
+ );
298
+ }
299
+ }
300
+ }
301
+
265
302
  /**
266
303
  * Event on Scroll
267
304
  */
@@ -287,7 +324,9 @@ export class ScrollView <
287
324
  const el = this.elements[index];
288
325
  const elData = this._elementInViewportData(el, scrollContainerBounding);
289
326
  const delay = elData.isIntersecting ? elData.delay : 0;
290
- this._handleInOut(el, elData.isIntersecting, delay);
327
+ if (typeof elData.isIntersecting === 'boolean') {
328
+ this._handleInOut(el, elData.isIntersecting, delay);
329
+ }
291
330
  }
292
331
  this._processUnusedElements();
293
332
 
@@ -309,7 +348,7 @@ export class ScrollView <
309
348
  const bounding = el.getBoundingClientRect();
310
349
 
311
350
  // check if the element is intersecting
312
- let isIntersecting = false;
351
+ let isIntersecting: undefined | boolean;
313
352
  if (
314
353
  bounding.top < parentBounding.top + parentBounding.height * threshold
315
354
  && bounding.left < parentBounding.left + parentBounding.width * threshold
@@ -324,6 +363,11 @@ export class ScrollView <
324
363
  } else {
325
364
  isIntersecting = true;
326
365
  }
366
+ } else if (
367
+ bounding.top > parentBounding.top + parentBounding.height
368
+ || bounding.left > parentBounding.left + parentBounding.width
369
+ ) {
370
+ isIntersecting = false;
327
371
  }
328
372
 
329
373
  // calculate delay only if it is enabled & calculations
@@ -393,9 +437,8 @@ export class ScrollView <
393
437
  // remove unused elements
394
438
  const elementsToRemove = this._elements.filter((el) => el.scrollViewIn);
395
439
  elementsToRemove.forEach((el) => {
396
- if (this._intersectionObserver) {
397
- this._intersectionObserver.unobserve(el);
398
- }
440
+ this._intersectionObserverIn?.unobserve(el);
441
+ this._intersectionObserverOut?.unobserve(el);
399
442
  });
400
443
  this._elements = this._elements.filter((el) => !el.scrollViewIn);
401
444
  }
@@ -410,9 +453,8 @@ export class ScrollView <
410
453
  const viewEl = element as NScrollView.El;
411
454
  viewEl.scrollViewIn = undefined;
412
455
  this._elements.push(element);
413
- if (this._intersectionObserver) {
414
- this._intersectionObserver.observe(element);
415
- }
456
+ this._intersectionObserverIn?.observe(element);
457
+ this._intersectionObserverOut?.observe(element);
416
458
  if (this.prop.enabled) {
417
459
  this.seekBounding();
418
460
  }
@@ -432,9 +474,8 @@ export class ScrollView <
432
474
  const viewEl = element as NScrollView.El;
433
475
  viewEl.scrollViewIn = undefined;
434
476
  this._elements = this._elements.filter((el) => el !== element);
435
- if (this._intersectionObserver) {
436
- this._intersectionObserver.unobserve(element);
437
- }
477
+ this._intersectionObserverIn?.unobserve(element);
478
+ this._intersectionObserverOut?.unobserve(element);
438
479
  }
439
480
 
440
481
  /**
@@ -442,9 +483,7 @@ export class ScrollView <
442
483
  */
443
484
  public removeElements () {
444
485
  this._elements.forEach((el) => {
445
- if (this._intersectionObserver) {
446
- this._intersectionObserver.unobserve(el);
447
- }
486
+ this.removeElement(el);
448
487
  });
449
488
  this._elements = [];
450
489
  }