@hkdigital/lib-sveltekit 0.0.85 → 0.0.87
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/dist/classes/svelte/image/ImageVariantsLoader.svelte.d.ts +8 -8
- package/dist/classes/svelte/image/ImageVariantsLoader.svelte.js +9 -9
- package/dist/classes/svelte/image/index.d.ts +1 -1
- package/dist/classes/svelte/image/index.js +1 -1
- package/dist/classes/svelte/image/typedef.d.ts +1 -1
- package/dist/classes/svelte/image/typedef.js +2 -2
- package/dist/components/image/ResponsiveImage.svelte +6 -6
- package/dist/components/image/ResponsiveImage.svelte.d.ts +2 -2
- package/dist/components/image/index.d.ts +1 -1
- package/dist/components/image/index.js +1 -1
- package/dist/config/imagetools-config.js +11 -5
- package/dist/types/imagetools.d.ts +14 -34
- package/package.json +1 -1
@@ -1,8 +1,8 @@
|
|
1
|
-
export default class
|
1
|
+
export default class ImageMetasLoader {
|
2
2
|
/**
|
3
|
-
* @param {
|
3
|
+
* @param {ImageMeta[]} imagesMeta
|
4
4
|
*/
|
5
|
-
constructor(imagesMeta:
|
5
|
+
constructor(imagesMeta: ImageMeta[], { devicePixelRatio }?: {
|
6
6
|
devicePixelRatio?: number;
|
7
7
|
});
|
8
8
|
/**
|
@@ -10,9 +10,9 @@ export default class ImageVariantsLoader {
|
|
10
10
|
*
|
11
11
|
* @param {number} containerWidth
|
12
12
|
*/
|
13
|
-
|
13
|
+
updateOptimalImageMeta(containerWidth: number): void;
|
14
14
|
get loaded(): boolean;
|
15
|
-
get variant(): import("./typedef.js").
|
15
|
+
get variant(): import("./typedef.js").ImageMeta;
|
16
16
|
/**
|
17
17
|
* Get object URL that can be used as src parameter of an HTML image
|
18
18
|
*
|
@@ -31,9 +31,9 @@ export default class ImageVariantsLoader {
|
|
31
31
|
*
|
32
32
|
* @param {number} containerWidth
|
33
33
|
*
|
34
|
-
* @returns {
|
34
|
+
* @returns {ImageMeta|null}
|
35
35
|
*/
|
36
|
-
|
36
|
+
getOptimalImageMeta(containerWidth: number): ImageMeta | null;
|
37
37
|
#private;
|
38
38
|
}
|
39
|
-
export type
|
39
|
+
export type ImageMeta = import("./typedef.js").ImageMeta;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/** @typedef {import('./typedef.js').
|
1
|
+
/** @typedef {import('./typedef.js').ImageMeta} ImageMeta */
|
2
2
|
|
3
3
|
// import * as expect from '@hkdigital/lib-sveltekit/util/expect/index.js';
|
4
4
|
|
@@ -6,14 +6,14 @@ import { untrack } from 'svelte';
|
|
6
6
|
|
7
7
|
import ImageLoader from './ImageLoader.svelte.js';
|
8
8
|
|
9
|
-
export default class
|
9
|
+
export default class ImageMetasLoader {
|
10
10
|
/** @type {number} */
|
11
11
|
#devicePixelRatio;
|
12
12
|
|
13
|
-
/** @type {
|
13
|
+
/** @type {ImageMeta[]} */
|
14
14
|
#imagesMeta;
|
15
15
|
|
16
|
-
/** @type {
|
16
|
+
/** @type {ImageMeta|null} */
|
17
17
|
#imageVariant = $state(null);
|
18
18
|
|
19
19
|
/** @type {ImageLoader|null} */
|
@@ -32,7 +32,7 @@ export default class ImageVariantsLoader {
|
|
32
32
|
#loaded = $derived(this.#progress.loaded);
|
33
33
|
|
34
34
|
/**
|
35
|
-
* @param {
|
35
|
+
* @param {ImageMeta[]} imagesMeta
|
36
36
|
*/
|
37
37
|
constructor(imagesMeta, { devicePixelRatio = 1 } = {}) {
|
38
38
|
// expect.notEmptyArray( imagesMeta );
|
@@ -66,8 +66,8 @@ export default class ImageVariantsLoader {
|
|
66
66
|
*
|
67
67
|
* @param {number} containerWidth
|
68
68
|
*/
|
69
|
-
|
70
|
-
const newVariant = this.
|
69
|
+
updateOptimalImageMeta(containerWidth) {
|
70
|
+
const newVariant = this.getOptimalImageMeta(containerWidth);
|
71
71
|
|
72
72
|
if (
|
73
73
|
!newVariant ||
|
@@ -127,9 +127,9 @@ export default class ImageVariantsLoader {
|
|
127
127
|
*
|
128
128
|
* @param {number} containerWidth
|
129
129
|
*
|
130
|
-
* @returns {
|
130
|
+
* @returns {ImageMeta|null}
|
131
131
|
*/
|
132
|
-
|
132
|
+
getOptimalImageMeta(containerWidth) {
|
133
133
|
if (!containerWidth) {
|
134
134
|
return null;
|
135
135
|
}
|
@@ -1,2 +1,2 @@
|
|
1
1
|
export { default as ImageLoader } from "./ImageLoader.svelte";
|
2
|
-
export { default as
|
2
|
+
export { default as ImageMetasLoader } from "./ImageMetasLoader.svelte";
|
@@ -1,7 +1,7 @@
|
|
1
|
-
// /** @typedef {import('@hkdigital/lib-sveltekit/types/imagetools.js').
|
1
|
+
// /** @typedef {import('@hkdigital/lib-sveltekit/types/imagetools.js').ImageMeta} ImageMeta */
|
2
2
|
|
3
3
|
/**
|
4
|
-
* @typedef {Object}
|
4
|
+
* @typedef {Object} ImageMeta
|
5
5
|
* @property {string} src - URL of the image
|
6
6
|
* @property {number} width - Width of the image
|
7
7
|
* @property {number} height - Height of the image
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<script>
|
2
|
-
/** @typedef {import('../../types/imagetools.js').
|
2
|
+
/** @typedef {import('../../types/imagetools.js').ImageMeta} ImageMeta */
|
3
3
|
|
4
|
-
import {
|
4
|
+
import { ImageMetasLoader } from '../../classes/svelte/image/index.js';
|
5
5
|
|
6
6
|
/**
|
7
7
|
* @type {{
|
@@ -10,7 +10,7 @@
|
|
10
10
|
* boxBase?: string,
|
11
11
|
* boxClasses?: string
|
12
12
|
* boxAttrs?: { [attr: string]: * },
|
13
|
-
* images:
|
13
|
+
* images: ImageMeta[],
|
14
14
|
* alt?: string
|
15
15
|
* } & { [attr: string]: * }}
|
16
16
|
*/
|
@@ -29,15 +29,15 @@
|
|
29
29
|
...attrs
|
30
30
|
} = $props();
|
31
31
|
|
32
|
-
let variantsLoader = new
|
32
|
+
let variantsLoader = new ImageMetasLoader(images);
|
33
33
|
|
34
34
|
let containerWidth = $state(0);
|
35
35
|
|
36
|
-
/** @type {
|
36
|
+
/** @type {ImageMeta|null} */
|
37
37
|
let imageVariant = $state(null);
|
38
38
|
|
39
39
|
$effect(() => {
|
40
|
-
variantsLoader.
|
40
|
+
variantsLoader.updateOptimalImageMeta(containerWidth);
|
41
41
|
});
|
42
42
|
|
43
43
|
// $effect(() => {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export default ResponsiveImage;
|
2
|
-
export type
|
2
|
+
export type ImageMeta = any;
|
3
3
|
declare const ResponsiveImage: import("svelte").Component<{
|
4
4
|
base?: string;
|
5
5
|
classes?: string;
|
@@ -8,7 +8,7 @@ declare const ResponsiveImage: import("svelte").Component<{
|
|
8
8
|
boxAttrs?: {
|
9
9
|
[attr: string]: any;
|
10
10
|
};
|
11
|
-
images:
|
11
|
+
images: ImageMeta[];
|
12
12
|
alt?: string;
|
13
13
|
} & {
|
14
14
|
[attr: string]: any;
|
@@ -7,24 +7,29 @@ const DEFAULT_PRESETS = {
|
|
7
7
|
},
|
8
8
|
gradient: {
|
9
9
|
format: 'jpg',
|
10
|
-
quality: '95'
|
10
|
+
quality: '95',
|
11
|
+
as: 'metadata'
|
11
12
|
},
|
12
13
|
photo: {
|
13
14
|
format: 'jpg',
|
14
|
-
quality: '95'
|
15
|
+
quality: '95',
|
16
|
+
as: 'metadata'
|
15
17
|
},
|
16
18
|
drawing: {
|
17
19
|
format: 'avif',
|
18
|
-
quality: '90'
|
20
|
+
quality: '90',
|
21
|
+
as: 'metadata'
|
19
22
|
},
|
20
23
|
savedata: {
|
21
24
|
format: 'avif',
|
22
|
-
quality: '85'
|
25
|
+
quality: '85',
|
26
|
+
as: 'metadata'
|
23
27
|
},
|
24
28
|
blur: {
|
25
29
|
format: 'avif',
|
26
30
|
quality: '50',
|
27
|
-
blur: '75'
|
31
|
+
blur: '75',
|
32
|
+
as: 'metadata'
|
28
33
|
}
|
29
34
|
};
|
30
35
|
|
@@ -105,6 +110,7 @@ export function generateDefaultDirectives(options) {
|
|
105
110
|
if (params.has('responsive')) {
|
106
111
|
params.set('as', 'metadata');
|
107
112
|
}
|
113
|
+
|
108
114
|
// > Process presets
|
109
115
|
|
110
116
|
if (presetName) {
|
@@ -1,87 +1,67 @@
|
|
1
1
|
|
2
2
|
|
3
|
-
interface
|
3
|
+
interface ImageMeta {
|
4
4
|
src: string;
|
5
5
|
width?: number;
|
6
6
|
height?: number;
|
7
7
|
}
|
8
8
|
|
9
9
|
declare module '*?responsive' {
|
10
|
-
const out:
|
10
|
+
const out: ImageMeta[];
|
11
11
|
export default out;
|
12
12
|
}
|
13
13
|
|
14
14
|
declare module '*&responsive' {
|
15
|
-
const out:
|
15
|
+
const out: ImageMeta[];
|
16
16
|
export default out;
|
17
17
|
}
|
18
18
|
|
19
19
|
declare module '*?preset=gradient' {
|
20
|
-
const out:
|
20
|
+
const out: ImageMeta|ImageMeta[];
|
21
21
|
export default out;
|
22
22
|
}
|
23
23
|
|
24
24
|
declare module '*&preset=gradient' {
|
25
|
-
const out:
|
25
|
+
const out: ImageMeta|ImageMeta[];
|
26
26
|
export default out;
|
27
27
|
}
|
28
28
|
|
29
29
|
declare module '*?preset=photo' {
|
30
|
-
const out:
|
30
|
+
const out: ImageMeta|ImageMeta[];
|
31
31
|
export default out;
|
32
32
|
}
|
33
33
|
|
34
34
|
declare module '*&preset=photo' {
|
35
|
-
const out:
|
35
|
+
const out: ImageMeta|ImageMeta[];
|
36
36
|
export default out;
|
37
37
|
}
|
38
38
|
|
39
39
|
declare module '*?preset=drawing' {
|
40
|
-
const out:
|
40
|
+
const out: ImageMeta|ImageMeta[];
|
41
41
|
export default out;
|
42
42
|
}
|
43
43
|
|
44
44
|
declare module '*&preset=drawing' {
|
45
|
-
const out:
|
45
|
+
const out: ImageMeta|ImageMeta[];
|
46
46
|
export default out;
|
47
47
|
}
|
48
48
|
|
49
49
|
declare module '*?preset=savedata' {
|
50
|
-
const out:
|
50
|
+
const out: ImageMeta|ImageMeta[];
|
51
51
|
export default out;
|
52
52
|
}
|
53
53
|
|
54
54
|
declare module '*&preset=savedata' {
|
55
|
-
const out:
|
55
|
+
const out: ImageMeta|ImageMeta[];
|
56
56
|
export default out;
|
57
57
|
}
|
58
58
|
|
59
59
|
declare module '*?preset=blur' {
|
60
|
-
const out:
|
60
|
+
const out: ImageMeta|ImageMeta[];
|
61
61
|
export default out;
|
62
62
|
}
|
63
63
|
|
64
64
|
declare module '*&preset=blur' {
|
65
|
-
const out:
|
65
|
+
const out: ImageMeta|ImageMeta[];
|
66
66
|
export default out;
|
67
|
-
}
|
68
|
-
|
69
|
-
// declare module '*&w=sm' {
|
70
|
-
// const src: string;
|
71
|
-
// export default src;
|
72
|
-
// }
|
73
|
-
|
74
|
-
// declare module '*&w=md' {
|
75
|
-
// const src: string;
|
76
|
-
// export default src;
|
77
|
-
// }
|
78
|
-
|
79
|
-
// declare module '*&w=lg' {
|
80
|
-
// const src: string;
|
81
|
-
// export default src;
|
82
|
-
// }
|
83
|
-
|
84
|
-
// declare module '*&w=hd' {
|
85
|
-
// const src: string;
|
86
|
-
// export default src;
|
87
|
-
// }
|
67
|
+
}
|