@hkdigital/lib-sveltekit 0.1.2 → 0.1.4
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 → svkit}/audio/AudioScene.svelte.js +1 -1
- package/dist/classes/{svelte → svkit}/image/ImageLoader.svelte.js +2 -2
- package/dist/classes/{svelte → svkit}/image/ImageScene.svelte.js +1 -1
- package/dist/classes/{svelte → svkit}/network-loader/NetworkLoader.svelte.js +1 -1
- package/dist/components/image/ImageBox.svelte +8 -6
- package/dist/components/image/ImageBox.svelte.d.ts +2 -2
- package/dist/util/http/index.js +1 -1
- package/package.json +2 -2
- package/dist/components/image/EnhancedImage.svelte__ +0 -162
- package/dist/components/image/ImageBox.svelte__ +0 -242
- package/dist/components/image/ImageBox.svelte___ +0 -241
- package/dist/components/image/ResponsiveImage.svelte +0 -90
- package/dist/components/image/ResponsiveImage.svelte.d.ts +0 -31
- package/dist/components/image/ResponsiveImage.svelte__ +0 -90
- /package/dist/classes/{svelte → svkit}/audio/AudioLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/audio/AudioLoader.svelte.js +0 -0
- /package/dist/classes/{svelte → svkit}/audio/AudioScene.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/audio/mocks.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/audio/mocks.js +0 -0
- /package/dist/classes/{svelte → svkit}/final-state-machine/FiniteStateMachine.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/final-state-machine/FiniteStateMachine.svelte.js +0 -0
- /package/dist/classes/{svelte → svkit}/final-state-machine/index.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/final-state-machine/index.js +0 -0
- /package/dist/classes/{svelte → svkit}/image/ImageLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/image/ImageScene.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/image/ImageVariantsLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/image/ImageVariantsLoader.svelte.js +0 -0
- /package/dist/classes/{svelte → svkit}/image/index.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/image/index.js +0 -0
- /package/dist/classes/{svelte → svkit}/image/mocks.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/image/mocks.js +0 -0
- /package/dist/classes/{svelte → svkit}/image/typedef.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/image/typedef.js +0 -0
- /package/dist/classes/{svelte → svkit}/loading-state-machine/LoadingStateMachine.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/loading-state-machine/LoadingStateMachine.svelte.js +0 -0
- /package/dist/classes/{svelte → svkit}/loading-state-machine/constants.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/loading-state-machine/constants.js +0 -0
- /package/dist/classes/{svelte → svkit}/loading-state-machine/index.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/loading-state-machine/index.js +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/NetworkLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/constants.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/constants.js +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/index.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/index.js +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/mocks.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/mocks.js +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/typedef.d.ts +0 -0
- /package/dist/classes/{svelte → svkit}/network-loader/typedef.js +0 -0
@@ -4,9 +4,9 @@ import { toSingleImageMeta } from '../../../util/image/index.js';
|
|
4
4
|
|
5
5
|
import {
|
6
6
|
NetworkLoader
|
7
|
-
// ERROR_NOT_LOADED
|
7
|
+
// ERROR_NOT_LOADED
|
8
8
|
// ERROR_TRANSFERRED
|
9
|
-
} from '
|
9
|
+
} from '../network-loader/index.js';
|
10
10
|
|
11
11
|
/**
|
12
12
|
* ImageLoader instance
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<script>
|
2
|
-
import { ImageLoader } from '../../classes/
|
3
|
-
import { ImageVariantsLoader } from '../../classes/
|
2
|
+
import { ImageLoader } from '../../classes/svkit/image/index.js';
|
3
|
+
import { ImageVariantsLoader } from '../../classes/svkit/image/index.js';
|
4
4
|
import { toSingleImageMeta } from '../../util/image/index.js';
|
5
5
|
|
6
6
|
/**
|
@@ -15,9 +15,9 @@
|
|
15
15
|
* fit?: 'contain' | 'cover' | 'fill',
|
16
16
|
* position?: string,
|
17
17
|
* imageMeta: import('../../config/typedef.js').ImageMeta | import('../../config/typedef.js').ImageMeta[],
|
18
|
-
* imageLoader?: import('../../classes/
|
18
|
+
* imageLoader?: import('../../classes/svkit/image/index.js').ImageLoader,
|
19
19
|
* alt?: string,
|
20
|
-
* onProgress?: (progress: import('../../classes/
|
20
|
+
* onProgress?: (progress: import('../../classes/svkit/network-loader/typedef.js').LoadingProgress) => void,
|
21
21
|
* [attr: string]: any
|
22
22
|
* }}
|
23
23
|
*/
|
@@ -200,7 +200,9 @@
|
|
200
200
|
height: 100%;
|
201
201
|
max-width: 100%;
|
202
202
|
max-height: 100%;
|
203
|
-
object-fit: var(--fit);
|
204
|
-
|
203
|
+
-o-object-fit: var(--fit);
|
204
|
+
object-fit: var(--fit);
|
205
|
+
-o-object-position: var(--pos);
|
206
|
+
object-position: var(--pos);
|
205
207
|
}
|
206
208
|
</style>
|
@@ -30,7 +30,7 @@ declare const ImageBox: import("svelte").Component<{
|
|
30
30
|
fit?: "contain" | "cover" | "fill";
|
31
31
|
position?: string;
|
32
32
|
imageMeta: import("../../config/typedef.js").ImageMeta | import("../../config/typedef.js").ImageMeta[];
|
33
|
-
imageLoader?: import("../../classes/
|
33
|
+
imageLoader?: import("../../classes/svkit/image/index.js").ImageLoader;
|
34
34
|
alt?: string;
|
35
|
-
onProgress?: (progress: import("../../classes/
|
35
|
+
onProgress?: (progress: import("../../classes/svkit/network-loader/typedef.js").LoadingProgress) => void;
|
36
36
|
}, {}, "">;
|
package/dist/util/http/index.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
// AbortError,
|
6
6
|
// TimeoutError,
|
7
7
|
// TypeOrValueError
|
8
|
-
// } from '
|
8
|
+
// } from '../../constants/errors/index.js';
|
9
9
|
|
10
10
|
// import { setRequestHeaders } from './headers.js';
|
11
11
|
// import { getErrorFromResponse } from './errors.js';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hkdigital/lib-sveltekit",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.4",
|
4
4
|
"author": {
|
5
5
|
"name": "HKdigital",
|
6
6
|
"url": "https://hkdigital.nl"
|
@@ -68,7 +68,7 @@
|
|
68
68
|
"@skeletonlabs/skeleton-svelte": "1.0.0-next.4",
|
69
69
|
"@steeze-ui/heroicons": "^2.4.2",
|
70
70
|
"@sveltejs/adapter-auto": "^4.0.0",
|
71
|
-
"@sveltejs/package": "
|
71
|
+
"@sveltejs/package": "2.3.7",
|
72
72
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
73
73
|
"@tailwindcss/typography": "^0.5.16",
|
74
74
|
"@types/eslint": "^9.6.1",
|
@@ -1,162 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
import { onMount } from 'svelte';
|
3
|
-
|
4
|
-
/**
|
5
|
-
* @example
|
6
|
-
* import { EnhancedImage }
|
7
|
-
* from '$lib/components/EnhancedImage/index.js';
|
8
|
-
*
|
9
|
-
* <EnhancedImage
|
10
|
-
* classes="aspect-video max-h-svh w-full border-8 border-pink-500"
|
11
|
-
* src={NeonLightsOff}
|
12
|
-
* onload={() => {
|
13
|
-
* console.log('loaded');
|
14
|
-
* }}
|
15
|
-
* />
|
16
|
-
*/
|
17
|
-
|
18
|
-
/**
|
19
|
-
* @type {{
|
20
|
-
* base?: string,
|
21
|
-
* bg?: string,
|
22
|
-
* classes?: string,
|
23
|
-
* overflow?: string,
|
24
|
-
* aspect?: string,
|
25
|
-
* fit?: string,
|
26
|
-
* position?: string,
|
27
|
-
* src: string | import('$lib/typedef/image.js').Picture,
|
28
|
-
* alt?: string,
|
29
|
-
* onload?: ( e: (Event|{ type: string, target: HTMLImageElement }) ) => void,
|
30
|
-
* onerror?: ( e: (Event|{ type: string, target: HTMLImageElement }) ) => void,
|
31
|
-
* loading?: string
|
32
|
-
* } & { [attr: string]: any }}
|
33
|
-
*/
|
34
|
-
let {
|
35
|
-
// Style
|
36
|
-
base,
|
37
|
-
bg,
|
38
|
-
classes,
|
39
|
-
|
40
|
-
overflow = 'overflow-clip',
|
41
|
-
aspect,
|
42
|
-
|
43
|
-
fit = 'contain',
|
44
|
-
position = 'left top',
|
45
|
-
|
46
|
-
src,
|
47
|
-
alt = '',
|
48
|
-
onload,
|
49
|
-
onerror,
|
50
|
-
loading,
|
51
|
-
|
52
|
-
// Attributes
|
53
|
-
...attrs
|
54
|
-
} = $props();
|
55
|
-
|
56
|
-
// let show = $state(false);
|
57
|
-
|
58
|
-
/** @type {HTMLDivElement|undefined} */
|
59
|
-
let imgBoxElem = $state();
|
60
|
-
|
61
|
-
/** @type {HTMLImageElement|undefined} */
|
62
|
-
let imgElem = $state();
|
63
|
-
|
64
|
-
/** @type {string | import('$lib/typedef/image.js').Picture} */
|
65
|
-
let src_;
|
66
|
-
|
67
|
-
$effect(() => {
|
68
|
-
if (src_ && src !== src_) {
|
69
|
-
throw new Error('Property [src] change is not supported');
|
70
|
-
}
|
71
|
-
});
|
72
|
-
|
73
|
-
let aspectStyle = $state('');
|
74
|
-
|
75
|
-
// > Event names
|
76
|
-
const LOAD = 'load';
|
77
|
-
const ERROR = 'error';
|
78
|
-
|
79
|
-
// > onMount
|
80
|
-
|
81
|
-
onMount(() => {
|
82
|
-
// show = true;
|
83
|
-
|
84
|
-
imgElem = imgBoxElem?.getElementsByTagName('img')[0];
|
85
|
-
|
86
|
-
if (!imgElem) {
|
87
|
-
throw new Error('Missing IMG element');
|
88
|
-
}
|
89
|
-
|
90
|
-
// > Auto set box aspect to same as image aspect if not set
|
91
|
-
|
92
|
-
if (!aspect) {
|
93
|
-
aspectStyle = `${imgElem.width / imgElem.height}`;
|
94
|
-
} else {
|
95
|
-
aspectStyle = '';
|
96
|
-
}
|
97
|
-
|
98
|
-
// > Register image onload and onerror handlers
|
99
|
-
|
100
|
-
/** @type {( e: Event ) => void} */
|
101
|
-
let onloadFn;
|
102
|
-
|
103
|
-
if (onload) {
|
104
|
-
if (imgElem?.complete) {
|
105
|
-
onload({ type: LOAD, target: imgElem });
|
106
|
-
} else {
|
107
|
-
onloadFn = onload;
|
108
|
-
imgElem?.addEventListener(LOAD, onloadFn);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
/** @type {( e: Event ) => void} */
|
113
|
-
let onerrorFn;
|
114
|
-
|
115
|
-
if (onerror) {
|
116
|
-
onerrorFn = onerror;
|
117
|
-
imgElem?.addEventListener(ERROR, onerrorFn);
|
118
|
-
}
|
119
|
-
|
120
|
-
return () => {
|
121
|
-
if (onloadFn) {
|
122
|
-
imgElem?.removeEventListener(LOAD, onloadFn);
|
123
|
-
}
|
124
|
-
|
125
|
-
if (onerrorFn) {
|
126
|
-
imgElem?.removeEventListener(ERROR, onerrorFn);
|
127
|
-
}
|
128
|
-
};
|
129
|
-
});
|
130
|
-
</script>
|
131
|
-
|
132
|
-
<div
|
133
|
-
data-hk-enhanced-image
|
134
|
-
bind:this={imgBoxElem}
|
135
|
-
class="{base} {bg} {aspect} {overflow} {classes}"
|
136
|
-
style:--fit={fit}
|
137
|
-
style:--pos={position}
|
138
|
-
style:aspect-ratio={aspectStyle}
|
139
|
-
{...attrs}
|
140
|
-
>
|
141
|
-
<enhanced:img {src} {alt} />
|
142
|
-
</div>
|
143
|
-
|
144
|
-
<style>
|
145
|
-
[data-hk-enhanced-image],
|
146
|
-
:global([data-hk-enhanced-image] picture),
|
147
|
-
:global([data-hk-enhanced-image] img) {
|
148
|
-
display: block;
|
149
|
-
width: 100%;
|
150
|
-
height: 100%;
|
151
|
-
}
|
152
|
-
:global([data-hk-enhanced-image] picture),
|
153
|
-
:global([data-hk-enhanced-image] img) {
|
154
|
-
max-width: 100%;
|
155
|
-
max-height: 100%;
|
156
|
-
}
|
157
|
-
|
158
|
-
:global([data-hk-enhanced-image] img) {
|
159
|
-
object-fit: var(--fit);
|
160
|
-
object-position: var(--pos);
|
161
|
-
}
|
162
|
-
</style>
|
@@ -1,242 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
import { onMount } from 'svelte';
|
3
|
-
|
4
|
-
import { ImageLoader } from '$lib/classes/svelte/image/index.js';
|
5
|
-
|
6
|
-
import { toSingleImageMeta } from '$lib/util/image/index.js';
|
7
|
-
|
8
|
-
/**
|
9
|
-
* @example
|
10
|
-
* import { ImageBox } from '/path/to/ImageBox/index.js';
|
11
|
-
*
|
12
|
-
* // @note 'as=metadata' is set by the preset
|
13
|
-
* import NeonLightsOff from '$lib/img/NeonLightsOff.jpg?preset=gradient';
|
14
|
-
*
|
15
|
-
* <!-- Example that fits in an outer-box -->
|
16
|
-
*
|
17
|
-
* <div class="outer-box">
|
18
|
-
* <ImageBox image={ArmyGreen} fit="contain" position="center center" />
|
19
|
-
* </div>
|
20
|
-
*
|
21
|
-
* <!-- Examples that has have width, height or aspect set -->
|
22
|
-
*
|
23
|
-
* <ImageBox
|
24
|
-
* image={ArmyGreen}
|
25
|
-
* fit="contain"
|
26
|
-
* position="center center"
|
27
|
-
* width="w-[200px]"
|
28
|
-
* height="h-[200px]"
|
29
|
-
* classes="border-8 border-green-500"
|
30
|
-
* />
|
31
|
-
*
|
32
|
-
* <ImageBox
|
33
|
-
* image={ArmyGreen}
|
34
|
-
* fit="contain"
|
35
|
-
* position="center center"
|
36
|
-
* width="w-[200px]"
|
37
|
-
* aspect="aspect-square"
|
38
|
-
* classes="border-8 border-green-500"
|
39
|
-
* />
|
40
|
-
*
|
41
|
-
* <ImageBox
|
42
|
-
* image={ArmyGreen}
|
43
|
-
* fit="contain"
|
44
|
-
* position="center center"
|
45
|
-
* height="h-[200px]"
|
46
|
-
* aspect="aspect-square"
|
47
|
-
* classes="border-8 border-green-500"
|
48
|
-
* />
|
49
|
-
*
|
50
|
-
* <!-- Or hack it using !important -->
|
51
|
-
*
|
52
|
-
* <ImageBox
|
53
|
-
* image={ArmyGreen}
|
54
|
-
* fit="contain"
|
55
|
-
* position="center center"
|
56
|
-
* classes="!w-[200px] !h-[200px] border-8 border-green-500"
|
57
|
-
* />
|
58
|
-
*/
|
59
|
-
|
60
|
-
/**
|
61
|
-
* @typedef {import('./typedef.js').ObjectFit} ObjectFit
|
62
|
-
* @typedef {import('./typedef.js').ObjectPosition} ObjectPosition
|
63
|
-
*
|
64
|
-
* @typedef {import('$lib/classes/svelte/network-loader/typedef.js').LoadingProgress} LoadingProgress
|
65
|
-
*
|
66
|
-
* @typedef {import('$lib/config/typedef.js').ImageMeta} ImageMeta
|
67
|
-
*
|
68
|
-
* @typedef {Object} Props
|
69
|
-
* @property {string} [base] - Base styling class
|
70
|
-
* @property {string} [bg] - Background styling class
|
71
|
-
* @property {string} [classes] - Additional CSS classes
|
72
|
-
* @property {string} [width] - Width of the image container
|
73
|
-
* @property {string} [height] - Height of the image container
|
74
|
-
* @property {string} [aspect] - Aspect ratio of the image container
|
75
|
-
* @property {string} [overflow] - Overflow behavior
|
76
|
-
* @property {ObjectFit} [fit] - Object-fit property
|
77
|
-
* @property {ObjectPosition} [position] - Object-position property
|
78
|
-
*
|
79
|
-
* @property {ImageMeta|ImageMeta[]} [imageMeta]
|
80
|
-
* Image metadata, TODO: array of image metadata for responsive image
|
81
|
-
*
|
82
|
-
* @property {ImageLoader} [imageLoader]
|
83
|
-
* Image loader
|
84
|
-
*
|
85
|
-
* @property {string} [alt] - Alternative text for the image
|
86
|
-
* @property {() => LoadingProgress} [onProgress] - Progress callback function
|
87
|
-
* @property {*} [attr] - Additional arbitrary attributes
|
88
|
-
*/
|
89
|
-
|
90
|
-
/** @type {Props} */
|
91
|
-
let {
|
92
|
-
// Style
|
93
|
-
base,
|
94
|
-
bg,
|
95
|
-
classes,
|
96
|
-
width,
|
97
|
-
height,
|
98
|
-
aspect,
|
99
|
-
overflow = 'overflow-clip',
|
100
|
-
|
101
|
-
// Fitting and positioning of image in its container
|
102
|
-
fit = 'contain',
|
103
|
-
position = 'left top',
|
104
|
-
|
105
|
-
// Single image or responsive image meta data
|
106
|
-
imageMeta,
|
107
|
-
|
108
|
-
imageLoader,
|
109
|
-
|
110
|
-
alt = '',
|
111
|
-
|
112
|
-
// Attributes
|
113
|
-
...attrs
|
114
|
-
} = $props();
|
115
|
-
|
116
|
-
if (!imageMeta) {
|
117
|
-
throw new Error('Missing [imageMeta]');
|
118
|
-
}
|
119
|
-
|
120
|
-
// let show = $state(false);
|
121
|
-
|
122
|
-
/** @type {HTMLImageElement|undefined} */
|
123
|
-
let imgElem = $state();
|
124
|
-
|
125
|
-
let aspectStyle = $state('');
|
126
|
-
|
127
|
-
// > Loading
|
128
|
-
|
129
|
-
let metaWidth = $state(0);
|
130
|
-
let metaHeight = $state(0);
|
131
|
-
|
132
|
-
let imageMeta_ = $state();
|
133
|
-
|
134
|
-
$effect(() => {
|
135
|
-
//
|
136
|
-
// Is imageMeta is a list of responsive options: pick one
|
137
|
-
//
|
138
|
-
if (imageMeta) {
|
139
|
-
imageMeta_ = toSingleImageMeta(imageMeta);
|
140
|
-
}
|
141
|
-
});
|
142
|
-
|
143
|
-
$effect(() => {
|
144
|
-
//
|
145
|
-
// Set meta width and height
|
146
|
-
//
|
147
|
-
if (imageMeta_) {
|
148
|
-
if (imageMeta_.width) {
|
149
|
-
metaWidth = imageMeta_.width;
|
150
|
-
}
|
151
|
-
|
152
|
-
if (imageMeta_.height) {
|
153
|
-
metaHeight = imageMeta_.height;
|
154
|
-
}
|
155
|
-
}
|
156
|
-
});
|
157
|
-
|
158
|
-
/** @type {ImageLoader|undefined} */
|
159
|
-
let imageLoader_ = $state();
|
160
|
-
|
161
|
-
$effect(() => {
|
162
|
-
//
|
163
|
-
// User supplied imageLoader instead of imageMeta
|
164
|
-
//
|
165
|
-
if (!imageMeta && imageLoader && !imageLoader_) {
|
166
|
-
imageLoader_ = imageLoader;
|
167
|
-
imageMeta_ = imageLoader.imageMeta;
|
168
|
-
}
|
169
|
-
});
|
170
|
-
|
171
|
-
/** @type {string|null} */
|
172
|
-
let objectUrl = $state(null);
|
173
|
-
|
174
|
-
$effect(() => {
|
175
|
-
//
|
176
|
-
// Create image loader
|
177
|
-
//
|
178
|
-
if (imageMeta_ && !imageLoader_) {
|
179
|
-
imageLoader_ = new ImageLoader({ imageMeta: imageMeta_ });
|
180
|
-
}
|
181
|
-
});
|
182
|
-
|
183
|
-
$effect(() => {
|
184
|
-
//
|
185
|
-
// Start loading if imageLoader_ is in state 'initial'
|
186
|
-
//
|
187
|
-
// TODO: implement lazy flag
|
188
|
-
//
|
189
|
-
if (imageLoader_?.initial) {
|
190
|
-
imageLoader_.load();
|
191
|
-
}
|
192
|
-
});
|
193
|
-
|
194
|
-
$effect(() => {
|
195
|
-
//
|
196
|
-
// Get objectUrl when the image has finished loading
|
197
|
-
//
|
198
|
-
if (imageLoader_.loaded) {
|
199
|
-
// @ts-ignore
|
200
|
-
objectUrl = imageLoader_.getObjectURL();
|
201
|
-
}
|
202
|
-
|
203
|
-
return () => {
|
204
|
-
if (objectUrl) {
|
205
|
-
URL.revokeObjectURL(objectUrl);
|
206
|
-
objectUrl = null;
|
207
|
-
}
|
208
|
-
};
|
209
|
-
});
|
210
|
-
</script>
|
211
|
-
|
212
|
-
<div
|
213
|
-
data-image="box"
|
214
|
-
class="{base} {bg} {aspect} {overflow} {width} {height} {classes}"
|
215
|
-
style:--fit={fit}
|
216
|
-
style:--pos={position}
|
217
|
-
style:aspect-ratio={aspectStyle}
|
218
|
-
style:width={width || (height && aspect) ? undefined : '100%'}
|
219
|
-
style:height={height || (width && aspect) ? undefined : '100%'}
|
220
|
-
{...attrs}
|
221
|
-
>
|
222
|
-
{#if objectUrl && metaWidth && metaHeight}
|
223
|
-
<img src={objectUrl} {alt} width={metaWidth} height={metaHeight} />
|
224
|
-
{/if}
|
225
|
-
</div>
|
226
|
-
|
227
|
-
<style>
|
228
|
-
[data-image='box'] {
|
229
|
-
max-width: 100%;
|
230
|
-
max-height: 100%;
|
231
|
-
}
|
232
|
-
|
233
|
-
img {
|
234
|
-
display: block;
|
235
|
-
width: 100%;
|
236
|
-
height: 100%;
|
237
|
-
max-width: 100%;
|
238
|
-
max-height: 100%;
|
239
|
-
object-fit: var(--fit);
|
240
|
-
object-position: var(--pos);
|
241
|
-
}
|
242
|
-
</style>
|
@@ -1,241 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
import { onMount } from 'svelte';
|
3
|
-
import { ImageLoader } from '$lib/classes/svelte/image/index.js';
|
4
|
-
import { ImageVariantsLoader } from '$lib/classes/svelte/image/index.js';
|
5
|
-
import { toSingleImageMeta } from '$lib/util/image/index.js';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* @type {{
|
9
|
-
* base?: string,
|
10
|
-
* bg?: string,
|
11
|
-
* classes?: string,
|
12
|
-
* width?: string,
|
13
|
-
* height?: string,
|
14
|
-
* aspect?: string,
|
15
|
-
* overflow?: string,
|
16
|
-
* fit?: 'contain' | 'cover' | 'fill',
|
17
|
-
* position?: string,
|
18
|
-
* imageMeta: import('$lib/config/typedef.js').ImageMeta | import('$lib/config/typedef.js').ImageMeta[],
|
19
|
-
* imageLoader?: import('$lib/classes/svelte/image/index.js').ImageLoader,
|
20
|
-
* alt?: string,
|
21
|
-
* onProgress?: () => import('$lib/classes/svelte/network-loader/typedef.js').LoadingProgress,
|
22
|
-
* debug?: boolean,
|
23
|
-
* [attr: string]: any
|
24
|
-
* }}
|
25
|
-
*/
|
26
|
-
let {
|
27
|
-
// Style
|
28
|
-
base,
|
29
|
-
bg,
|
30
|
-
classes,
|
31
|
-
width,
|
32
|
-
height,
|
33
|
-
aspect,
|
34
|
-
overflow = 'overflow-clip',
|
35
|
-
|
36
|
-
// Fitting and positioning of image in its container
|
37
|
-
fit = 'contain',
|
38
|
-
position = 'left top',
|
39
|
-
|
40
|
-
// Single image or responsive image meta data
|
41
|
-
imageMeta,
|
42
|
-
imageLoader,
|
43
|
-
|
44
|
-
// Accessibility
|
45
|
-
alt = '',
|
46
|
-
|
47
|
-
// Development
|
48
|
-
debug = false,
|
49
|
-
|
50
|
-
// Additional attributes
|
51
|
-
...attrs
|
52
|
-
} = $props();
|
53
|
-
|
54
|
-
if (!imageMeta) {
|
55
|
-
throw new Error('Missing [imageMeta]');
|
56
|
-
}
|
57
|
-
|
58
|
-
/** @type {HTMLDivElement|undefined} */
|
59
|
-
let containerElem = $state();
|
60
|
-
|
61
|
-
/** @type {HTMLImageElement|undefined} */
|
62
|
-
let imgElem = $state();
|
63
|
-
|
64
|
-
let aspectStyle = $state('');
|
65
|
-
|
66
|
-
// > Loading
|
67
|
-
let metaWidth = $state(0);
|
68
|
-
let metaHeight = $state(0);
|
69
|
-
|
70
|
-
let imageMeta_ = $state();
|
71
|
-
let variantsLoader = $state();
|
72
|
-
let variantObjectUrl = $state(null);
|
73
|
-
let objectUrl = $state(null);
|
74
|
-
|
75
|
-
$effect(() => {
|
76
|
-
//
|
77
|
-
// Is imageMeta is a list of responsive options:
|
78
|
-
// => setup variants loader
|
79
|
-
//
|
80
|
-
if (Array.isArray(imageMeta) && !imageLoader && !variantsLoader) {
|
81
|
-
// $inspect(imageMeta, 'Creating variantsLoader');
|
82
|
-
|
83
|
-
variantsLoader = new ImageVariantsLoader(imageMeta, {
|
84
|
-
devicePixelRatio: window.devicePixelRatio
|
85
|
-
});
|
86
|
-
}
|
87
|
-
//
|
88
|
-
// Single image meta (only if not using variants)
|
89
|
-
//
|
90
|
-
else if (imageMeta && !variantsLoader) {
|
91
|
-
// Only run if there is no variantsLoader
|
92
|
-
|
93
|
-
//$inspect(imageMeta, 'Using single imageMeta');
|
94
|
-
|
95
|
-
imageMeta_ = toSingleImageMeta(imageMeta);
|
96
|
-
}
|
97
|
-
});
|
98
|
-
|
99
|
-
$effect(() => {
|
100
|
-
//
|
101
|
-
// Set meta width and height for single image
|
102
|
-
//
|
103
|
-
if (imageMeta_) {
|
104
|
-
if (imageMeta_.width) {
|
105
|
-
metaWidth = imageMeta_.width;
|
106
|
-
}
|
107
|
-
|
108
|
-
if (imageMeta_.height) {
|
109
|
-
metaHeight = imageMeta_.height;
|
110
|
-
}
|
111
|
-
}
|
112
|
-
});
|
113
|
-
|
114
|
-
/** @type {ImageLoader|undefined} */
|
115
|
-
let imageLoader_ = $state();
|
116
|
-
|
117
|
-
$effect(() => {
|
118
|
-
//
|
119
|
-
// User supplied imageLoader instead of imageMeta
|
120
|
-
//
|
121
|
-
if (!imageMeta && imageLoader && !imageLoader_) {
|
122
|
-
imageLoader_ = imageLoader;
|
123
|
-
imageMeta_ = imageLoader.imageMeta;
|
124
|
-
}
|
125
|
-
});
|
126
|
-
|
127
|
-
$effect(() => {
|
128
|
-
//
|
129
|
-
// Create image loader for single image
|
130
|
-
//
|
131
|
-
if (imageMeta_ && !imageLoader_) {
|
132
|
-
imageLoader_ = new ImageLoader({ imageMeta: imageMeta_ });
|
133
|
-
}
|
134
|
-
});
|
135
|
-
|
136
|
-
$effect(() => {
|
137
|
-
//
|
138
|
-
// Start loading if imageLoader_ is in state 'initial'
|
139
|
-
//
|
140
|
-
if (imageLoader_?.initial) {
|
141
|
-
imageLoader_.load();
|
142
|
-
}
|
143
|
-
});
|
144
|
-
|
145
|
-
$effect(() => {
|
146
|
-
//
|
147
|
-
// Get objectUrl when the single image has finished loading
|
148
|
-
//
|
149
|
-
if (imageLoader_?.loaded) {
|
150
|
-
objectUrl = imageLoader_.getObjectURL();
|
151
|
-
}
|
152
|
-
|
153
|
-
return () => {
|
154
|
-
if (objectUrl) {
|
155
|
-
URL.revokeObjectURL(objectUrl);
|
156
|
-
objectUrl = null;
|
157
|
-
}
|
158
|
-
};
|
159
|
-
});
|
160
|
-
|
161
|
-
$effect(() => {
|
162
|
-
//
|
163
|
-
// Setup resize observer for variants loading
|
164
|
-
//
|
165
|
-
if (!containerElem || !variantsLoader) return;
|
166
|
-
|
167
|
-
const resizeObserver = new ResizeObserver((entries) => {
|
168
|
-
for (const entry of entries) {
|
169
|
-
const { width, height } = entry.contentRect;
|
170
|
-
|
171
|
-
variantsLoader.updateOptimalImageMeta({
|
172
|
-
containerWidth: width,
|
173
|
-
containerHeight: height,
|
174
|
-
fit
|
175
|
-
});
|
176
|
-
}
|
177
|
-
});
|
178
|
-
|
179
|
-
resizeObserver.observe(containerElem);
|
180
|
-
|
181
|
-
return () => {
|
182
|
-
resizeObserver.disconnect();
|
183
|
-
};
|
184
|
-
});
|
185
|
-
|
186
|
-
$effect(() => {
|
187
|
-
//
|
188
|
-
// Get variantObjectUrl when a variant has finished loading
|
189
|
-
//
|
190
|
-
if (variantsLoader?.loaded) {
|
191
|
-
variantObjectUrl = variantsLoader.getObjectURL();
|
192
|
-
}
|
193
|
-
|
194
|
-
return () => {
|
195
|
-
if (variantObjectUrl) {
|
196
|
-
URL.revokeObjectURL(variantObjectUrl);
|
197
|
-
variantObjectUrl = null;
|
198
|
-
}
|
199
|
-
};
|
200
|
-
});
|
201
|
-
</script>
|
202
|
-
|
203
|
-
<div
|
204
|
-
data-image="box"
|
205
|
-
bind:this={containerElem}
|
206
|
-
class="{base} {bg} {aspect} {overflow} {width} {height} {classes}"
|
207
|
-
style:--fit={fit}
|
208
|
-
style:--pos={position}
|
209
|
-
style:aspect-ratio={aspectStyle}
|
210
|
-
style:width={width || (height && aspect) ? undefined : '100%'}
|
211
|
-
style:height={height || (width && aspect) ? undefined : '100%'}
|
212
|
-
{...attrs}
|
213
|
-
>
|
214
|
-
{#if variantsLoader?.loaded && variantObjectUrl}
|
215
|
-
<img
|
216
|
-
src={variantObjectUrl}
|
217
|
-
{alt}
|
218
|
-
width={variantsLoader.variant.width}
|
219
|
-
height={variantsLoader.variant.height}
|
220
|
-
/>
|
221
|
-
{:else if objectUrl && metaWidth && metaHeight}
|
222
|
-
<img src={objectUrl} {alt} width={metaWidth} height={metaHeight} />
|
223
|
-
{/if}
|
224
|
-
</div>
|
225
|
-
|
226
|
-
<style>
|
227
|
-
[data-image='box'] {
|
228
|
-
max-width: 100%;
|
229
|
-
max-height: 100%;
|
230
|
-
}
|
231
|
-
|
232
|
-
img {
|
233
|
-
display: block;
|
234
|
-
width: 100%;
|
235
|
-
height: 100%;
|
236
|
-
max-width: 100%;
|
237
|
-
max-height: 100%;
|
238
|
-
object-fit: var(--fit);
|
239
|
-
object-position: var(--pos);
|
240
|
-
}
|
241
|
-
</style>
|
@@ -1,90 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
/** @typedef {import('../../config/typedef.js').ImageMeta} ImageMeta */
|
3
|
-
|
4
|
-
import { ImageVariantsLoader } from '../../classes/svelte/image/index.js';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* @type {{
|
8
|
-
* base?: string,
|
9
|
-
* classes?: string
|
10
|
-
* boxBase?: string,
|
11
|
-
* boxClasses?: string
|
12
|
-
* boxAttrs?: { [attr: string]: * },
|
13
|
-
* images: ImageMeta[],
|
14
|
-
* alt?: string
|
15
|
-
* } & { [attr: string]: any }}
|
16
|
-
*/
|
17
|
-
const {
|
18
|
-
base,
|
19
|
-
classes,
|
20
|
-
boxBase,
|
21
|
-
boxClasses,
|
22
|
-
boxAttrs,
|
23
|
-
|
24
|
-
// Functional
|
25
|
-
images,
|
26
|
-
alt = '',
|
27
|
-
|
28
|
-
// Attributes
|
29
|
-
...attrs
|
30
|
-
} = $props();
|
31
|
-
|
32
|
-
let variantsLoader = new ImageVariantsLoader(images);
|
33
|
-
|
34
|
-
let containerWidth = $state(0);
|
35
|
-
|
36
|
-
/** @type {ImageMeta|null} */
|
37
|
-
let imageVariant = $state(null);
|
38
|
-
|
39
|
-
$effect(() => {
|
40
|
-
variantsLoader.updateOptimalImageMeta({ containerWidth });
|
41
|
-
});
|
42
|
-
|
43
|
-
// $effect(() => {
|
44
|
-
// console.log('imageVariant', $state.snapshot(imageVariant));
|
45
|
-
// });
|
46
|
-
|
47
|
-
/** @type {string|null} */
|
48
|
-
let imageUrl = $state(null);
|
49
|
-
|
50
|
-
$effect(() => {
|
51
|
-
let image;
|
52
|
-
|
53
|
-
if (variantsLoader.loaded) {
|
54
|
-
// @ts-ignore
|
55
|
-
imageUrl = variantsLoader.getObjectURL();
|
56
|
-
}
|
57
|
-
|
58
|
-
return () => {
|
59
|
-
if (imageUrl) {
|
60
|
-
URL.revokeObjectURL(imageUrl);
|
61
|
-
imageUrl = null;
|
62
|
-
}
|
63
|
-
};
|
64
|
-
});
|
65
|
-
|
66
|
-
let variant = $derived(variantsLoader.variant);
|
67
|
-
|
68
|
-
// let image = $derived(variantsLoader.image);
|
69
|
-
</script>
|
70
|
-
|
71
|
-
™
|
72
|
-
<div
|
73
|
-
bind:clientWidth={containerWidth}
|
74
|
-
class="{boxBase} {boxClasses}"
|
75
|
-
{...boxAttrs}
|
76
|
-
>
|
77
|
-
<!-- <p class="p text-white">variant: {JSON.stringify(variant)}</p> -->
|
78
|
-
|
79
|
-
{#if variant}
|
80
|
-
<img
|
81
|
-
data-image="responsive"
|
82
|
-
src={imageUrl ? imageUrl : ''}
|
83
|
-
width={variant.width}
|
84
|
-
height={variant.height}
|
85
|
-
{alt}
|
86
|
-
class="{boxBase} {boxClasses}"
|
87
|
-
{...attrs}
|
88
|
-
/>
|
89
|
-
{/if}
|
90
|
-
</div>
|
@@ -1,31 +0,0 @@
|
|
1
|
-
export default ResponsiveImage;
|
2
|
-
export type ImageMeta = import("../../config/typedef.js").ImageMeta;
|
3
|
-
type ResponsiveImage = {
|
4
|
-
$on?(type: string, callback: (e: any) => void): () => void;
|
5
|
-
$set?(props: Partial<{
|
6
|
-
base?: string;
|
7
|
-
classes?: string;
|
8
|
-
boxBase?: string;
|
9
|
-
boxClasses?: string;
|
10
|
-
boxAttrs?: {
|
11
|
-
[attr: string]: any;
|
12
|
-
};
|
13
|
-
images: ImageMeta[];
|
14
|
-
alt?: string;
|
15
|
-
} & {
|
16
|
-
[attr: string]: any;
|
17
|
-
}>): void;
|
18
|
-
};
|
19
|
-
declare const ResponsiveImage: import("svelte").Component<{
|
20
|
-
base?: string;
|
21
|
-
classes?: string;
|
22
|
-
boxBase?: string;
|
23
|
-
boxClasses?: string;
|
24
|
-
boxAttrs?: {
|
25
|
-
[attr: string]: any;
|
26
|
-
};
|
27
|
-
images: ImageMeta[];
|
28
|
-
alt?: string;
|
29
|
-
} & {
|
30
|
-
[attr: string]: any;
|
31
|
-
}, {}, "">;
|
@@ -1,90 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
/** @typedef {import('$lib/config/typedef.js').ImageMeta} ImageMeta */
|
3
|
-
|
4
|
-
import { ImageVariantsLoader } from '$lib/classes/svelte/image/index.js';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* @type {{
|
8
|
-
* base?: string,
|
9
|
-
* classes?: string
|
10
|
-
* boxBase?: string,
|
11
|
-
* boxClasses?: string
|
12
|
-
* boxAttrs?: { [attr: string]: * },
|
13
|
-
* images: ImageMeta[],
|
14
|
-
* alt?: string
|
15
|
-
* } & { [attr: string]: any }}
|
16
|
-
*/
|
17
|
-
const {
|
18
|
-
base,
|
19
|
-
classes,
|
20
|
-
boxBase,
|
21
|
-
boxClasses,
|
22
|
-
boxAttrs,
|
23
|
-
|
24
|
-
// Functional
|
25
|
-
images,
|
26
|
-
alt = '',
|
27
|
-
|
28
|
-
// Attributes
|
29
|
-
...attrs
|
30
|
-
} = $props();
|
31
|
-
|
32
|
-
let variantsLoader = new ImageVariantsLoader(images);
|
33
|
-
|
34
|
-
let containerWidth = $state(0);
|
35
|
-
|
36
|
-
/** @type {ImageMeta|null} */
|
37
|
-
let imageVariant = $state(null);
|
38
|
-
|
39
|
-
$effect(() => {
|
40
|
-
variantsLoader.updateOptimalImageMeta({ containerWidth });
|
41
|
-
});
|
42
|
-
|
43
|
-
// $effect(() => {
|
44
|
-
// console.log('imageVariant', $state.snapshot(imageVariant));
|
45
|
-
// });
|
46
|
-
|
47
|
-
/** @type {string|null} */
|
48
|
-
let imageUrl = $state(null);
|
49
|
-
|
50
|
-
$effect(() => {
|
51
|
-
let image;
|
52
|
-
|
53
|
-
if (variantsLoader.loaded) {
|
54
|
-
// @ts-ignore
|
55
|
-
imageUrl = variantsLoader.getObjectURL();
|
56
|
-
}
|
57
|
-
|
58
|
-
return () => {
|
59
|
-
if (imageUrl) {
|
60
|
-
URL.revokeObjectURL(imageUrl);
|
61
|
-
imageUrl = null;
|
62
|
-
}
|
63
|
-
};
|
64
|
-
});
|
65
|
-
|
66
|
-
let variant = $derived(variantsLoader.variant);
|
67
|
-
|
68
|
-
// let image = $derived(variantsLoader.image);
|
69
|
-
</script>
|
70
|
-
|
71
|
-
™
|
72
|
-
<div
|
73
|
-
bind:clientWidth={containerWidth}
|
74
|
-
class="{boxBase} {boxClasses}"
|
75
|
-
{...boxAttrs}
|
76
|
-
>
|
77
|
-
<!-- <p class="p text-white">variant: {JSON.stringify(variant)}</p> -->
|
78
|
-
|
79
|
-
{#if variant}
|
80
|
-
<img
|
81
|
-
data-image="responsive"
|
82
|
-
src={imageUrl ? imageUrl : ''}
|
83
|
-
width={variant.width}
|
84
|
-
height={variant.height}
|
85
|
-
{alt}
|
86
|
-
class="{boxBase} {boxClasses}"
|
87
|
-
{...attrs}
|
88
|
-
/>
|
89
|
-
{/if}
|
90
|
-
</div>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
/package/dist/classes/{svelte → svkit}/loading-state-machine/LoadingStateMachine.svelte.d.ts
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|