@hkdigital/lib-sveltekit 0.1.1 → 0.1.3

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.
Files changed (33) hide show
  1. package/dist/classes/svelte/audio/AudioScene.svelte.js +1 -1
  2. package/dist/classes/svelte/image/ImageLoader.svelte.js +1 -1
  3. package/dist/classes/svelte/image/ImageScene.svelte.js +1 -1
  4. package/dist/classes/svelte/network-loader/NetworkLoader.svelte.js +1 -1
  5. package/dist/components/area/HkArea.svelte.d.ts +14 -0
  6. package/dist/components/area/HkGridArea.svelte.d.ts +22 -0
  7. package/dist/components/boxes/game-box/GameBox.svelte.d.ts +15 -0
  8. package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte.d.ts +22 -0
  9. package/dist/components/buttons/button/Button.svelte.d.ts +21 -0
  10. package/dist/components/buttons/button-text/TextButton.svelte.d.ts +7 -0
  11. package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +13 -0
  12. package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +18 -0
  13. package/dist/components/icon/HkIcon.svelte.d.ts +12 -0
  14. package/dist/components/icon/HkTabIcon.svelte.d.ts +21 -0
  15. package/dist/components/image/ImageBox.svelte.d.ts +19 -0
  16. package/dist/components/inputs/text-input/TextInput.svelte.d.ts +28 -0
  17. package/dist/components/layout/HkAppLayout.svelte.d.ts +11 -0
  18. package/dist/components/layout/HkGridLayers.svelte.d.ts +23 -0
  19. package/dist/components/panels/plain-panel/PlainPanel.svelte.d.ts +12 -0
  20. package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +14 -0
  21. package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +14 -0
  22. package/dist/components/tab-bar/HkTabBar.svelte.d.ts +18 -0
  23. package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +19 -0
  24. package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte.d.ts +10 -0
  25. package/dist/design-system/tailwind-theme-extend.d.ts +4 -4
  26. package/dist/util/http/index.js +1 -1
  27. package/package.json +18 -18
  28. package/dist/components/image/EnhancedImage.svelte__ +0 -162
  29. package/dist/components/image/ImageBox.svelte__ +0 -242
  30. package/dist/components/image/ImageBox.svelte___ +0 -241
  31. package/dist/components/image/ResponsiveImage.svelte +0 -90
  32. package/dist/components/image/ResponsiveImage.svelte.d.ts +0 -15
  33. package/dist/components/image/ResponsiveImage.svelte__ +0 -90
@@ -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>