@hkdigital/lib-sveltekit 0.0.92 → 0.0.93
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/components/image/ResponsiveImage.svelte +1 -1
- package/dist/components/image/ResponsiveImage.svelte.d.ts +1 -1
- package/dist/components/image/index.d.ts +2 -1
- package/dist/components/image/index.js +2 -1
- package/dist/config/imagetools.d.ts +0 -6
- package/package.json +1 -1
- package/dist/components/image/EnhancedImage.svelte__ +0 -162
@@ -1,4 +1,5 @@
|
|
1
|
+
export { default as ImageBox } from "./ImageBox.svelte";
|
1
2
|
export { default as ResponsiveImage } from "./ResponsiveImage.svelte";
|
2
3
|
declare const _default: {};
|
3
4
|
export default _default;
|
4
|
-
export type ImageMeta =
|
5
|
+
export type ImageMeta = import("../../config/typedef.js").ImageMeta;
|
@@ -1,5 +1,6 @@
|
|
1
|
-
/** @typedef {import('../../
|
1
|
+
/** @typedef {import('../../config/typedef.js').ImageMeta} ImageMeta */
|
2
2
|
|
3
|
+
export { default as ImageBox } from './ImageBox.svelte';
|
3
4
|
export { default as ResponsiveImage } from './ResponsiveImage.svelte';
|
4
5
|
|
5
6
|
export default {};
|
package/package.json
CHANGED
@@ -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]: * }}
|
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>
|