@hkdigital/lib-sveltekit 0.0.53 → 0.0.55
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/EnhancedImage.svelte +162 -0
- package/dist/components/image/EnhancedImage.svelte.d.ts +23 -0
- package/dist/components/image/index.d.ts +1 -0
- package/dist/components/image/index.js +1 -0
- package/dist/components/layout/HkGridLayers.svelte +9 -1
- package/dist/util/object/index.js +1 -1
- package/package.json +9 -5
@@ -0,0 +1,162 @@
|
|
1
|
+
<script>
|
2
|
+
import { onMount } from 'svelte';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @example
|
6
|
+
* import { EnhancedImage }
|
7
|
+
* from '../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('../../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('../../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>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export default EnhancedImage;
|
2
|
+
declare const EnhancedImage: import("svelte").Component<{
|
3
|
+
base?: string;
|
4
|
+
bg?: string;
|
5
|
+
classes?: string;
|
6
|
+
overflow?: string;
|
7
|
+
aspect?: string;
|
8
|
+
fit?: string;
|
9
|
+
position?: string;
|
10
|
+
src: string | any;
|
11
|
+
alt?: string;
|
12
|
+
onload?: (e: (Event | {
|
13
|
+
type: string;
|
14
|
+
target: HTMLImageElement;
|
15
|
+
})) => void;
|
16
|
+
onerror?: (e: (Event | {
|
17
|
+
type: string;
|
18
|
+
target: HTMLImageElement;
|
19
|
+
})) => void;
|
20
|
+
loading?: string;
|
21
|
+
} & {
|
22
|
+
[attr: string]: any;
|
23
|
+
}, {}, "">;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default as EnhancedImage } from "./EnhancedImage.svelte";
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default as EnhancedImage } from './EnhancedImage.svelte';
|
@@ -68,7 +68,15 @@
|
|
68
68
|
</div>
|
69
69
|
|
70
70
|
<style>
|
71
|
-
[data-hk-grid-layers] > :global(
|
71
|
+
[data-hk-grid-layers] > :global(.area-above) {
|
72
72
|
grid-area: 1/1/2/2;
|
73
73
|
}
|
74
|
+
|
75
|
+
& [data-hk-grid-layers] > :global(*) {
|
76
|
+
grid-area: 2/1/3/2;
|
77
|
+
}
|
78
|
+
|
79
|
+
& [data-hk-grid-layers] > :global(.area-below) {
|
80
|
+
grid-area: 3/1/4/2;
|
81
|
+
}
|
74
82
|
</style>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hkdigital/lib-sveltekit",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.55",
|
4
4
|
"author": "Jens Kleinhout, HKdigital (https://hkdigital.nl)",
|
5
5
|
"license": "ISC",
|
6
6
|
"repository": {
|
@@ -76,18 +76,22 @@
|
|
76
76
|
"types": "./dist/components/area/index.d.ts",
|
77
77
|
"svelte": "./dist/components/area/index.js"
|
78
78
|
},
|
79
|
-
"./components/layout": {
|
80
|
-
"types": "./dist/components/layout/index.d.ts",
|
81
|
-
"svelte": "./dist/components/layout/index.js"
|
82
|
-
},
|
83
79
|
"./components/icon": {
|
84
80
|
"types": "./dist/components/icon/index.d.ts",
|
85
81
|
"svelte": "./dist/components/icon/index.js"
|
86
82
|
},
|
83
|
+
"./components/image": {
|
84
|
+
"types": "./dist/components/image/index.d.ts",
|
85
|
+
"svelte": "./dist/components/image/index.js"
|
86
|
+
},
|
87
87
|
"./components/input": {
|
88
88
|
"types": "./dist/components/input/index.d.ts",
|
89
89
|
"svelte": "./dist/components/input/index.js"
|
90
90
|
},
|
91
|
+
"./components/layout": {
|
92
|
+
"types": "./dist/components/layout/index.d.ts",
|
93
|
+
"svelte": "./dist/components/layout/index.js"
|
94
|
+
},
|
91
95
|
"./components/tab-bar": {
|
92
96
|
"types": "./dist/components/tab-bar/index.d.ts",
|
93
97
|
"svelte": "./dist/components/tab-bar/index.js"
|