vevet 2.5.1 → 2.7.1
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/Application.js +23 -0
- package/build/cjs/components/scroll/scrollable/ScrollView.js +2 -2
- package/build/cjs/index.js +2 -0
- package/build/cjs/utils/image/index.js +12 -0
- package/build/cjs/utils/image/load.js +77 -0
- package/build/cjs/utils/image/pathsToProps.js +34 -0
- package/build/cjs/utils/image/sizesToSrcSet.js +17 -0
- package/build/es/app/Application.js +18 -0
- package/build/es/components/scroll/scrollable/ScrollView.js +2 -2
- package/build/es/index.js +2 -0
- package/build/es/utils/image/index.js +4 -0
- package/build/es/utils/image/load.js +60 -0
- package/build/es/utils/image/pathsToProps.js +28 -0
- package/build/es/utils/image/sizesToSrcSet.js +14 -0
- package/build/types/app/Application.d.ts +10 -0
- package/build/types/app/Application.d.ts.map +1 -1
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +6 -0
- package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
- package/build/types/components/scroll/section/ScrollSectionProgress.d.ts +2 -2
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils/image/index.d.ts +5 -0
- package/build/types/utils/image/index.d.ts.map +1 -0
- package/build/types/utils/image/load.d.ts +17 -0
- package/build/types/utils/image/load.d.ts.map +1 -0
- package/build/types/utils/image/pathsToProps.d.ts +9 -0
- package/build/types/utils/image/pathsToProps.d.ts.map +1 -0
- package/build/types/utils/image/sizesToSrcSet.d.ts +5 -0
- package/build/types/utils/image/sizesToSrcSet.d.ts.map +1 -0
- package/build/types/utils/types/general.d.ts +9 -0
- package/build/types/utils/types/general.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ts/app/Application.ts +30 -0
- package/src/ts/components/scroll/scrollable/ScrollView.ts +8 -1
- package/src/ts/components/scroll/section/ScrollSectionProgress.ts +2 -2
- package/src/ts/index.ts +2 -0
- package/src/ts/utils/image/index.ts +9 -0
- package/src/ts/utils/image/load.ts +88 -0
- package/src/ts/utils/image/pathsToProps.ts +34 -0
- package/src/ts/utils/image/sizesToSrcSet.ts +16 -0
- package/src/ts/utils/types/general.ts +13 -0
|
@@ -40,6 +40,11 @@ export namespace NApplication {
|
|
|
40
40
|
* @default [.25, .1, .25, 1]
|
|
41
41
|
*/
|
|
42
42
|
easing: EasingType;
|
|
43
|
+
/**
|
|
44
|
+
* Check if the browser supports WebP
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
webpSupport: boolean;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
}
|
|
@@ -75,6 +80,7 @@ export class Application <
|
|
|
75
80
|
prefix: 'v-',
|
|
76
81
|
easing: [0.25, 0.1, 0.25, 1],
|
|
77
82
|
viewportResizeTimeout: 0,
|
|
83
|
+
webpSupport: false,
|
|
78
84
|
};
|
|
79
85
|
}
|
|
80
86
|
|
|
@@ -138,6 +144,16 @@ export class Application <
|
|
|
138
144
|
|
|
139
145
|
|
|
140
146
|
|
|
147
|
+
/**
|
|
148
|
+
* WebP Support
|
|
149
|
+
*/
|
|
150
|
+
protected _supportsWebp?: boolean;
|
|
151
|
+
get supportsWebp () {
|
|
152
|
+
return this._supportsWebp;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
141
157
|
/**
|
|
142
158
|
* @example
|
|
143
159
|
* const app = Application({
|
|
@@ -200,6 +216,20 @@ export class Application <
|
|
|
200
216
|
// create default helpers
|
|
201
217
|
this._pageLoad = new PageLoad();
|
|
202
218
|
this._viewport = new Viewport();
|
|
219
|
+
|
|
220
|
+
// check webp support
|
|
221
|
+
if (this.prop.webpSupport) {
|
|
222
|
+
const testWebP = new Image();
|
|
223
|
+
testWebP.onload = () => {
|
|
224
|
+
this._supportsWebp = testWebP.width === 1;
|
|
225
|
+
};
|
|
226
|
+
testWebP.onerror = () => {
|
|
227
|
+
this._supportsWebp = false;
|
|
228
|
+
};
|
|
229
|
+
testWebP.src = 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAwA0JaQAA3AA/vuUAAA=';
|
|
230
|
+
} else {
|
|
231
|
+
this._supportsWebp = false;
|
|
232
|
+
}
|
|
203
233
|
}
|
|
204
234
|
|
|
205
235
|
|
|
@@ -5,6 +5,7 @@ import onScroll from '../../../utils/listeners/onScroll';
|
|
|
5
5
|
import { intersectionObserverSupported } from '../../../utils/listeners';
|
|
6
6
|
import clamp from '../../../utils/math/clamp';
|
|
7
7
|
import timeoutCallback from '../../../utils/common/timeoutCallback';
|
|
8
|
+
import { NViewport } from '../../../app/events/Viewport';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -55,6 +56,11 @@ export namespace NScrollView {
|
|
|
55
56
|
* @default true
|
|
56
57
|
*/
|
|
57
58
|
useIntersectionObserver?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Viewport target on resize
|
|
61
|
+
* @default ''
|
|
62
|
+
*/
|
|
63
|
+
viewportTarget?: keyof NViewport.CallbacksTypes;
|
|
58
64
|
/**
|
|
59
65
|
* @default 0
|
|
60
66
|
*/
|
|
@@ -114,6 +120,7 @@ export class ScrollView <
|
|
|
114
120
|
classToToggle: 'viewed',
|
|
115
121
|
useDelay: false,
|
|
116
122
|
useIntersectionObserver: true,
|
|
123
|
+
viewportTarget: '',
|
|
117
124
|
resizeTimeout: 0,
|
|
118
125
|
};
|
|
119
126
|
}
|
|
@@ -174,7 +181,7 @@ export class ScrollView <
|
|
|
174
181
|
protected _setEvents () {
|
|
175
182
|
super._setEvents();
|
|
176
183
|
this.resize();
|
|
177
|
-
this.addViewportCallback(
|
|
184
|
+
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
178
185
|
this.resize();
|
|
179
186
|
}, {
|
|
180
187
|
timeout: this.prop.resizeTimeout,
|
package/src/ts/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as common from './utils/common';
|
|
|
2
2
|
import * as listeners from './utils/listeners';
|
|
3
3
|
import * as math from './utils/math';
|
|
4
4
|
import * as scroll from './utils/scroll';
|
|
5
|
+
import * as image from './utils/image';
|
|
5
6
|
|
|
6
7
|
import * as GeneralTypes from './utils/types/general';
|
|
7
8
|
|
|
@@ -51,6 +52,7 @@ const utils = {
|
|
|
51
52
|
listeners,
|
|
52
53
|
math,
|
|
53
54
|
scroll,
|
|
55
|
+
image,
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import PCancelable from 'p-cancelable';
|
|
2
|
+
|
|
3
|
+
const cachedImages: {
|
|
4
|
+
src: string;
|
|
5
|
+
image: HTMLImageElement
|
|
6
|
+
}[] = [];
|
|
7
|
+
|
|
8
|
+
type LoadImageProps = {
|
|
9
|
+
/**
|
|
10
|
+
* @default null
|
|
11
|
+
*/
|
|
12
|
+
crossOrigin?: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
useCache?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Load an image
|
|
21
|
+
*/
|
|
22
|
+
export default function loadImage (
|
|
23
|
+
source: string | HTMLImageElement,
|
|
24
|
+
props?: LoadImageProps,
|
|
25
|
+
) {
|
|
26
|
+
const defaultLoadProps: Required<LoadImageProps> = {
|
|
27
|
+
crossOrigin: null,
|
|
28
|
+
useCache: false,
|
|
29
|
+
};
|
|
30
|
+
const loadProps = {
|
|
31
|
+
...defaultLoadProps,
|
|
32
|
+
...props,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const imageSrc = typeof source === 'string' ? source : source.src;
|
|
36
|
+
|
|
37
|
+
return new PCancelable((
|
|
38
|
+
resolve: (img: HTMLImageElement) => void,
|
|
39
|
+
reject: () => void,
|
|
40
|
+
) => {
|
|
41
|
+
const cachedImage = loadProps.useCache && cachedImages.find((img) => img.src === imageSrc);
|
|
42
|
+
// get image from cache
|
|
43
|
+
if (cachedImage) {
|
|
44
|
+
resolve(cachedImage.image);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// load the image by src
|
|
49
|
+
if (typeof source === 'string') {
|
|
50
|
+
const img = new Image();
|
|
51
|
+
img.crossOrigin = loadProps.crossOrigin;
|
|
52
|
+
img.onload = () => {
|
|
53
|
+
if (loadProps.useCache) {
|
|
54
|
+
cachedImages.push({
|
|
55
|
+
src: imageSrc,
|
|
56
|
+
image: img,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
resolve(img);
|
|
60
|
+
};
|
|
61
|
+
img.onerror = () => {
|
|
62
|
+
reject();
|
|
63
|
+
};
|
|
64
|
+
img.src = source;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// load the image by image element
|
|
69
|
+
if (source instanceof HTMLImageElement) {
|
|
70
|
+
if (source.complete) {
|
|
71
|
+
resolve(source);
|
|
72
|
+
} else {
|
|
73
|
+
source.addEventListener('load', () => {
|
|
74
|
+
if (loadProps.useCache) {
|
|
75
|
+
cachedImages.push({
|
|
76
|
+
src: imageSrc,
|
|
77
|
+
image: source,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
resolve(source);
|
|
81
|
+
});
|
|
82
|
+
source.addEventListener('error', () => {
|
|
83
|
+
reject();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ImageAdaptivePaths, ImagePaths } from '../types/general';
|
|
2
|
+
import imageSizesToSrcSet from './sizesToSrcSet';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transform image paths to properties
|
|
6
|
+
*/
|
|
7
|
+
export default function imagePathsToProps (
|
|
8
|
+
data: ImagePaths | ImageAdaptivePaths,
|
|
9
|
+
) {
|
|
10
|
+
const app = window.vevetApp;
|
|
11
|
+
|
|
12
|
+
// get src
|
|
13
|
+
let src = data.original;
|
|
14
|
+
if (data.thumb) {
|
|
15
|
+
src = data.thumb;
|
|
16
|
+
}
|
|
17
|
+
if (app && app.supportsWebp && !!data.thumbWebp) {
|
|
18
|
+
src = data.thumbWebp;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// get src set
|
|
22
|
+
let srcSet = '';
|
|
23
|
+
// get webp images
|
|
24
|
+
if (app && app.supportsWebp && 'sizesWebp' in data && !!data.sizesWebp) {
|
|
25
|
+
srcSet = imageSizesToSrcSet(data.sizesWebp);
|
|
26
|
+
} else if ('sizes' in data && !!data.sizes) {
|
|
27
|
+
srcSet = imageSizesToSrcSet(data.sizes);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
src,
|
|
32
|
+
srcSet,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform image sizes to src set
|
|
3
|
+
*/
|
|
4
|
+
export default function imageSizesToSrcSet (
|
|
5
|
+
sizes: Record<string | number, string>,
|
|
6
|
+
) {
|
|
7
|
+
const keys = Object.keys(sizes);
|
|
8
|
+
const srcParts = keys.map((key) => {
|
|
9
|
+
const value = sizes[key];
|
|
10
|
+
if (value) {
|
|
11
|
+
return `${value} ${key}w`;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
});
|
|
15
|
+
return srcParts.filter((item) => !!item).join(', ');
|
|
16
|
+
}
|
|
@@ -12,3 +12,16 @@ export interface ScrollLike {
|
|
|
12
12
|
scrollTo(options: ScrollToOptions): void;
|
|
13
13
|
scrollTo(x: number, y: number): void;
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export interface ImagePaths {
|
|
17
|
+
original: string;
|
|
18
|
+
thumb?: string;
|
|
19
|
+
thumbWebp?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ImageAdaptivePaths<
|
|
23
|
+
S extends Record<string | number, string> = {}
|
|
24
|
+
> extends ImagePaths {
|
|
25
|
+
sizes?: S;
|
|
26
|
+
sizesWebp?: S;
|
|
27
|
+
}
|