vevet 2.0.11 → 2.3.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/build/cdn/index.js +1 -1
- package/build/cjs/app/events/Viewport.js +17 -6
- package/build/cjs/components/loading/ProgressPreloader.js +59 -14
- package/build/cjs/components/text/SplitText.js +2 -2
- package/build/es/app/events/Viewport.js +16 -6
- package/build/es/components/loading/ProgressPreloader.js +59 -14
- package/build/es/components/text/SplitText.js +2 -2
- package/build/types/app/events/Viewport.d.ts +9 -1
- package/build/types/app/events/Viewport.d.ts.map +1 -1
- package/build/types/components/loading/ProgressPreloader.d.ts +13 -7
- package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
- package/build/types/components/text/SplitText.d.ts +5 -0
- package/build/types/components/text/SplitText.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/ts/app/events/Viewport.ts +18 -6
- package/src/ts/components/loading/ProgressPreloader.ts +73 -21
- package/src/ts/components/text/SplitText.ts +7 -1
|
@@ -2,6 +2,7 @@ import { selectAll } from 'vevet-dom';
|
|
|
2
2
|
import PCancelable from 'p-cancelable';
|
|
3
3
|
import { AnimationFrame } from '../animation-frame/AnimationFrame';
|
|
4
4
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
5
|
+
import clamp from '../../utils/math/clamp';
|
|
5
6
|
import lerp from '../../utils/math/lerp';
|
|
6
7
|
import { Preloader, NPreloader } from './Preloader';
|
|
7
8
|
import { Timeline } from '../timeline/Timeline';
|
|
@@ -35,8 +36,10 @@ export namespace NProgressPreloader {
|
|
|
35
36
|
video?: boolean;
|
|
36
37
|
/**
|
|
37
38
|
* Selector for elements to be preloaded.
|
|
38
|
-
* These elements may have such properties
|
|
39
|
-
*
|
|
39
|
+
* These elements may have such properties
|
|
40
|
+
* as 'isLoaded' or 'isComplete' (numeral or boolean)
|
|
41
|
+
* or an attribute like 'data-is-loaded'
|
|
42
|
+
* (string with float or non-empty string for true).
|
|
40
43
|
* @default '.js-preload'
|
|
41
44
|
*/
|
|
42
45
|
custom?: string | false;
|
|
@@ -84,8 +87,13 @@ export namespace NProgressPreloader {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
export interface CustomResource extends Element {
|
|
87
|
-
isLoaded?: boolean;
|
|
88
|
-
isComplete?: boolean;
|
|
90
|
+
isLoaded?: boolean | number;
|
|
91
|
+
isComplete?: boolean | number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface CustomResourceData {
|
|
95
|
+
el: NProgressPreloader.CustomResource,
|
|
96
|
+
targetProgress: number;
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
}
|
|
@@ -147,7 +155,7 @@ export class ProgressPreloader <
|
|
|
147
155
|
get customResources () {
|
|
148
156
|
return this._customResources;
|
|
149
157
|
}
|
|
150
|
-
protected _customResources: NProgressPreloader.
|
|
158
|
+
protected _customResources: NProgressPreloader.CustomResourceData[];
|
|
151
159
|
|
|
152
160
|
|
|
153
161
|
|
|
@@ -305,11 +313,19 @@ export class ProgressPreloader <
|
|
|
305
313
|
|
|
306
314
|
// get custom resources
|
|
307
315
|
if (loaders.custom) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
316
|
+
Array.from(selectAll(loaders.custom)).forEach((el) => {
|
|
317
|
+
// note that each custom resource may have the attribute "data-load-count"
|
|
318
|
+
// which defines how many resources should be added to the loading queue.
|
|
319
|
+
// here we check this quantity and duplicate elements
|
|
320
|
+
let loadCount = parseInt(el.getAttribute('data-load-count') || '1', 10);
|
|
321
|
+
loadCount = Number.isNaN(loadCount) ? 1 : clamp(loadCount, [1, Infinity]);
|
|
322
|
+
for (let index = 1; index <= loadCount; index += 1) {
|
|
323
|
+
const targetProgress = index / loadCount;
|
|
324
|
+
this._customResources.push({
|
|
325
|
+
el,
|
|
326
|
+
targetProgress,
|
|
327
|
+
});
|
|
311
328
|
}
|
|
312
|
-
return true;
|
|
313
329
|
});
|
|
314
330
|
this._resourcesTotal += this._customResources.length;
|
|
315
331
|
}
|
|
@@ -360,8 +376,8 @@ export class ProgressPreloader <
|
|
|
360
376
|
});
|
|
361
377
|
|
|
362
378
|
// preload custom resources
|
|
363
|
-
this._customResources.forEach((
|
|
364
|
-
this._seekCustomResourceLoaded(
|
|
379
|
+
this._customResources.forEach((data) => {
|
|
380
|
+
this._seekCustomResourceLoaded(data).then(() => {
|
|
365
381
|
this._handleLoadedResource();
|
|
366
382
|
});
|
|
367
383
|
});
|
|
@@ -371,29 +387,65 @@ export class ProgressPreloader <
|
|
|
371
387
|
* Seek the moment when a custom resource is loaded
|
|
372
388
|
*/
|
|
373
389
|
protected _seekCustomResourceLoaded (
|
|
374
|
-
|
|
390
|
+
data: NProgressPreloader.CustomResourceData,
|
|
375
391
|
) {
|
|
376
392
|
return new Promise((
|
|
377
393
|
resolve: (...arg: any) => void,
|
|
378
394
|
) => {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
395
|
+
const { el, targetProgress } = data;
|
|
396
|
+
|
|
397
|
+
// get loaded value
|
|
398
|
+
let loadProgress = 0;
|
|
399
|
+
|
|
400
|
+
// from "isComplete" property
|
|
401
|
+
if (typeof el.isComplete !== 'undefined') {
|
|
402
|
+
if (typeof el.isComplete === 'boolean') {
|
|
403
|
+
if (el.isComplete) {
|
|
404
|
+
loadProgress = targetProgress;
|
|
405
|
+
}
|
|
406
|
+
} else if (typeof el.isComplete === 'number') {
|
|
407
|
+
loadProgress = el.isComplete;
|
|
408
|
+
}
|
|
409
|
+
} else if (typeof el.isLoaded !== 'undefined') {
|
|
410
|
+
// from "isLoaded" property
|
|
411
|
+
if (typeof el.isLoaded === 'boolean') {
|
|
412
|
+
if (el.isLoaded) {
|
|
413
|
+
loadProgress = targetProgress;
|
|
414
|
+
}
|
|
415
|
+
} else if (typeof el.isLoaded === 'number') {
|
|
416
|
+
loadProgress = el.isLoaded;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// if loadProgress is still incomplete,
|
|
421
|
+
// we check the "data-is-loaded" attribute
|
|
422
|
+
if (loadProgress === 0) {
|
|
423
|
+
const isLoadedAttr = el.getAttribute('data-is-loaded');
|
|
424
|
+
if (isLoadedAttr !== null && isLoadedAttr !== '') {
|
|
425
|
+
const isLoadedAttrNum = parseFloat(isLoadedAttr);
|
|
426
|
+
// if the value is non-numeric, we define the the resource is loaded
|
|
427
|
+
if (Number.isNaN(isLoadedAttrNum)) {
|
|
428
|
+
loadProgress = targetProgress;
|
|
429
|
+
} else {
|
|
430
|
+
loadProgress = isLoadedAttrNum;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
383
433
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
434
|
+
|
|
435
|
+
// console.log(loadProgress, targetLoadProgress);
|
|
436
|
+
|
|
437
|
+
// and we finally check if the target progress was reached
|
|
438
|
+
if (loadProgress >= targetProgress) {
|
|
388
439
|
resolve();
|
|
389
440
|
return;
|
|
390
441
|
}
|
|
442
|
+
|
|
391
443
|
// otherwise, seek the moment when it will be loaded
|
|
392
444
|
setTimeout(() => {
|
|
393
445
|
if (this.destroyed) {
|
|
394
446
|
return;
|
|
395
447
|
}
|
|
396
|
-
this._seekCustomResourceLoaded(
|
|
448
|
+
this._seekCustomResourceLoaded(data).then(() => {
|
|
397
449
|
resolve();
|
|
398
450
|
});
|
|
399
451
|
}, 50);
|
|
@@ -16,6 +16,11 @@ export namespace NSplitText {
|
|
|
16
16
|
* @default '#v-split-text'
|
|
17
17
|
*/
|
|
18
18
|
container?: string | Element;
|
|
19
|
+
/**
|
|
20
|
+
* Text content
|
|
21
|
+
* @default 'innerText'
|
|
22
|
+
*/
|
|
23
|
+
textSource?: 'textContent' | 'innerText' | 'innerHTML';
|
|
19
24
|
/**
|
|
20
25
|
* If need to split text into letters.
|
|
21
26
|
* @default true
|
|
@@ -92,6 +97,7 @@ export class SplitText <
|
|
|
92
97
|
return {
|
|
93
98
|
...super._getDefaultProp(),
|
|
94
99
|
container: `#${this.prefix}`,
|
|
100
|
+
textSource: 'innerText',
|
|
95
101
|
appendLetters: true,
|
|
96
102
|
appendLines: false,
|
|
97
103
|
viewportTarget: '',
|
|
@@ -168,7 +174,7 @@ export class SplitText <
|
|
|
168
174
|
|
|
169
175
|
// get initial text
|
|
170
176
|
this._initHTML = this._container.innerHTML;
|
|
171
|
-
const innerText = this._container
|
|
177
|
+
const innerText = this._container[this.prop.textSource]!.trim();
|
|
172
178
|
this._initText = innerText || 'no rendered text';
|
|
173
179
|
this._initText = this._initText.replace(/\s+\n/gm, '\n');
|
|
174
180
|
this._initText = this._initText.replace(/<br>/gm, String.fromCharCode(10));
|