vevet 2.0.1-dev.21 → 2.0.1-dev.25

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.
@@ -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
  }
@@ -406,13 +449,12 @@ export class ScrollView <
406
449
  */
407
450
  public addElement (
408
451
  element: Element,
409
- ) {
452
+ ): IRemovable {
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
  }
@@ -160,8 +160,11 @@ export class SplitText <
160
160
 
161
161
  // get initial text
162
162
  this._initHTML = this._container.innerHTML;
163
- this._initText = (this._container.innerText || 'no rendered text').trim();
163
+ this._initText = (this._container.innerText || this._container.innerHTML || 'no rendered text').trim();
164
164
  this._initText = this._initText.replace(/\s+\n/gm, '\n');
165
+ this._initText = this._initText.replace(/<br>/gm, String.fromCharCode(10));
166
+ this._initText = this._initText.replace(/<br\/>/gm, String.fromCharCode(10));
167
+ this._initText = this._initText.replace(/<br \/>/gm, String.fromCharCode(10));
165
168
 
166
169
  // set default vars
167
170
  this._isPrimarySplit = false;