vevet 2.0.1-dev.20 → 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.
- package/build/cdn/index.js +1 -1
- package/build/cjs/components/scroll/scrollable/ScrollView.js +67 -25
- package/build/cjs/components/text/SplitText.js +1 -1
- package/build/es/components/scroll/scrollable/ScrollView.js +66 -25
- package/build/es/components/text/SplitText.js +1 -1
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +12 -4
- package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ts/components/scroll/scrollable/ScrollView.ts +84 -33
- package/src/ts/components/text/SplitText.ts +1 -1
|
@@ -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
|
|
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.
|
|
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
|
|
201
|
-
this.
|
|
202
|
-
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.
|
|
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
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
397
|
-
|
|
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,11 +449,20 @@ export class ScrollView <
|
|
|
406
449
|
*/
|
|
407
450
|
public addElement (
|
|
408
451
|
element: Element,
|
|
409
|
-
) {
|
|
452
|
+
): IRemovable {
|
|
453
|
+
const viewEl = element as NScrollView.El;
|
|
454
|
+
viewEl.scrollViewIn = undefined;
|
|
410
455
|
this._elements.push(element);
|
|
411
|
-
|
|
412
|
-
|
|
456
|
+
this._intersectionObserverIn?.observe(element);
|
|
457
|
+
this._intersectionObserverOut?.observe(element);
|
|
458
|
+
if (this.prop.enabled) {
|
|
459
|
+
this.seekBounding();
|
|
413
460
|
}
|
|
461
|
+
return {
|
|
462
|
+
remove: () => {
|
|
463
|
+
this.removeElement(element);
|
|
464
|
+
},
|
|
465
|
+
};
|
|
414
466
|
}
|
|
415
467
|
|
|
416
468
|
/**
|
|
@@ -419,10 +471,11 @@ export class ScrollView <
|
|
|
419
471
|
public removeElement (
|
|
420
472
|
element: Element,
|
|
421
473
|
) {
|
|
474
|
+
const viewEl = element as NScrollView.El;
|
|
475
|
+
viewEl.scrollViewIn = undefined;
|
|
422
476
|
this._elements = this._elements.filter((el) => el !== element);
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
477
|
+
this._intersectionObserverIn?.unobserve(element);
|
|
478
|
+
this._intersectionObserverOut?.unobserve(element);
|
|
426
479
|
}
|
|
427
480
|
|
|
428
481
|
/**
|
|
@@ -430,9 +483,7 @@ export class ScrollView <
|
|
|
430
483
|
*/
|
|
431
484
|
public removeElements () {
|
|
432
485
|
this._elements.forEach((el) => {
|
|
433
|
-
|
|
434
|
-
this._intersectionObserver.unobserve(el);
|
|
435
|
-
}
|
|
486
|
+
this.removeElement(el);
|
|
436
487
|
});
|
|
437
488
|
this._elements = [];
|
|
438
489
|
}
|
|
@@ -160,7 +160,7 @@ 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
165
|
|
|
166
166
|
// set default vars
|