@hkdigital/lib-sveltekit 0.1.22 → 0.1.24

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 (41) hide show
  1. package/dist/classes/svelte/image/ImageScene.svelte.d.ts +54 -26
  2. package/dist/classes/svelte/image/ImageScene.svelte.js +208 -75
  3. package/dist/classes/svelte/image/ImageVariantsLoader.svelte.d.ts +5 -6
  4. package/dist/classes/svelte/image/ImageVariantsLoader.svelte.js +39 -55
  5. package/dist/components/area/HkArea.svelte.d.ts +0 -14
  6. package/dist/components/area/HkGridArea.svelte.d.ts +0 -22
  7. package/dist/components/buttons/button/Button.svelte.d.ts +0 -21
  8. package/dist/components/buttons/button-icon-steeze/SteezeIconButton.svelte.d.ts +0 -9
  9. package/dist/components/buttons/button-text/TextButton.svelte.d.ts +0 -7
  10. package/dist/components/debug/debug-panel-design-scaling/DebugPanelDesignScaling.svelte.d.ts +0 -4
  11. package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +0 -13
  12. package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +0 -18
  13. package/dist/components/icons/HkIcon.svelte.d.ts +0 -12
  14. package/dist/components/icons/HkTabIcon.svelte.d.ts +0 -21
  15. package/dist/components/icons/SteezeIcon.svelte.d.ts +0 -12
  16. package/dist/components/inputs/text-input/TextInput.svelte.d.ts +0 -28
  17. package/dist/components/layout/grid-layers/GridLayers.svelte.d.ts +0 -23
  18. package/dist/components/panels/panel/Panel.svelte.d.ts +0 -13
  19. package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +0 -14
  20. package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +0 -14
  21. package/dist/components/tab-bar/HkTabBar.svelte.d.ts +0 -18
  22. package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +0 -19
  23. package/dist/design/tailwind-theme-extend.d.ts +4 -4
  24. package/dist/server/logger.d.ts +0 -1
  25. package/dist/widgets/button-group/ButtonGroup.svelte.d.ts +0 -20
  26. package/dist/widgets/compare-left-right/CompareLeftRight.svelte.d.ts +0 -10
  27. package/dist/widgets/game-box/GameBox.svelte.d.ts +0 -41
  28. package/dist/widgets/hk-app-layout/HkAppLayout.svelte.d.ts +0 -11
  29. package/dist/widgets/image-box/ImageBox.svelte +4 -4
  30. package/dist/widgets/image-box/ImageBox.svelte.d.ts +1 -21
  31. package/dist/widgets/presenter/(broken) Presenter.state.svelte.js__ +613 -0
  32. package/dist/widgets/presenter/ImageSlide.svelte.d.ts +1 -5
  33. package/dist/widgets/presenter/Presenter.state.svelte.d.ts +3 -22
  34. package/dist/widgets/presenter/Presenter.state.svelte.js +156 -155
  35. package/dist/widgets/presenter/Presenter.svelte +23 -7
  36. package/dist/widgets/presenter/Presenter.svelte.d.ts +3 -12
  37. package/dist/widgets/presenter/Presenter.svelte__ +125 -0
  38. package/dist/widgets/virtual-viewport/VirtualViewport.svelte.d.ts +0 -22
  39. package/package.json +1 -1
  40. package/dist/classes/svelte/image/ImageScene.svelte.js__ +0 -253
  41. package/dist/classes/svelte/image/ImageVariantsLoader.svelte.js--responsive-loading-fails-fix-tried__ +0 -184
@@ -1,253 +0,0 @@
1
- /** @typedef {import('./typedef.js').ImageMeta} ImageMeta */
2
-
3
- import * as expect from '$lib/util/expect/index.js';
4
-
5
- import {
6
- LoadingStateMachine,
7
- STATE_INITIAL,
8
- STATE_LOADING,
9
- STATE_UNLOADING,
10
- STATE_LOADED,
11
- STATE_CANCELLED,
12
- STATE_ERROR,
13
- LOAD,
14
- // CANCEL,
15
- ERROR,
16
- LOADED,
17
- UNLOAD,
18
- INITIAL
19
- } from '$lib/classes/svelte/loading-state-machine/index.js';
20
-
21
- import ImageLoader from '$lib/classes/svelte/image/ImageLoader.svelte.js';
22
-
23
- /**
24
- * @typedef {object} SourceConfig
25
- * // property ...
26
- */
27
-
28
- /**
29
- * @typedef {object} ImageSource
30
- * @property {string} label
31
- * @property {ImageLoader} imageLoader
32
- * @property {ImageMeta} [imageMeta]
33
- */
34
-
35
- export default class ImageScene {
36
- #state = new LoadingStateMachine();
37
-
38
- // @note this exported state is set by $effect's
39
- state = $state(STATE_INITIAL);
40
-
41
- // @note this exported state is set by $effect's
42
- loaded = $derived.by(() => {
43
- return this.state === STATE_LOADED;
44
- });
45
-
46
- /** @type {ImageSource[]} */
47
- #imageSources = $state([]);
48
-
49
- #progress = $derived.by(() => {
50
- // console.log('update progress');
51
-
52
- let totalSize = 0;
53
- let totalBytesLoaded = 0;
54
- let sourcesLoaded = 0;
55
-
56
- const sources = this.#imageSources;
57
- const numberOfSources = sources.length;
58
-
59
- for (let j = 0; j < numberOfSources; j++) {
60
- const source = sources[j];
61
- const { imageLoader } = source;
62
-
63
- const { bytesLoaded, size, loaded } = imageLoader.progress;
64
-
65
- totalSize += size;
66
- totalBytesLoaded += bytesLoaded;
67
-
68
- if (loaded) {
69
- sourcesLoaded++;
70
- }
71
- } // end for
72
-
73
- return {
74
- totalBytesLoaded,
75
- totalSize,
76
- sourcesLoaded,
77
- numberOfSources
78
- };
79
- });
80
-
81
- /**
82
- * Construct ImageScene
83
- */
84
- constructor() {
85
- const state = this.#state;
86
-
87
- $effect(() => {
88
- if (state.current === STATE_LOADING) {
89
- // console.log(
90
- // 'progress',
91
- // JSON.stringify($state.snapshot(this.#progress))
92
- // );
93
-
94
- const { sourcesLoaded, numberOfSources } = this.#progress;
95
-
96
- if (sourcesLoaded === numberOfSources) {
97
- // console.log(`All [${numberOfSources}] sources loaded`);
98
- this.#state.send(LOADED);
99
- }
100
- }
101
- });
102
-
103
- $effect(() => {
104
- switch (state.current) {
105
- case STATE_LOADING:
106
- {
107
- // console.log('ImageScene:loading');
108
- this.#startLoading();
109
- }
110
- break;
111
-
112
- case STATE_UNLOADING:
113
- {
114
- // console.log('ImageScene:unloading');
115
- // this.#startUnLoading();
116
- }
117
- break;
118
-
119
- case STATE_LOADED:
120
- {
121
- // console.log('ImageScene:loaded');
122
- // TODO
123
- // this.#abortLoading = null;
124
- }
125
- break;
126
-
127
- case STATE_CANCELLED:
128
- {
129
- // console.log('ImageScene:cancelled');
130
- // TODO
131
- }
132
- break;
133
-
134
- case STATE_ERROR:
135
- {
136
- console.log('ImageScene:error', state.error);
137
- }
138
- break;
139
- } // end switch
140
-
141
- this.state = state.current;
142
- });
143
- }
144
-
145
- destroy() {
146
- // TODO: disconnect all image sources?
147
- // TODO: Unload ImageLoaders?
148
- }
149
-
150
- /**
151
- * Add image source
152
- * - Uses an ImageLoader instance to load image data from network
153
- *
154
- * @param {object} _
155
- * @param {string} _.label
156
- * @param {ImageMeta|ImageMeta[]} _.imageMeta
157
- */
158
- defineImage({ label, imageMeta }) {
159
- expect.notEmptyString(label);
160
-
161
- // expect.notEmptyString(url);
162
-
163
- const imageLoader = new ImageLoader({ imageMeta });
164
-
165
- this.#imageSources.push({ label, imageLoader, imageMeta });
166
- }
167
-
168
- /**
169
- * Start loading all image sources
170
- */
171
- load() {
172
- this.#state.send(LOAD);
173
-
174
- // FIXME: in unit test when moved to startloading it hangs!
175
-
176
- for (const { imageLoader } of this.#imageSources) {
177
- imageLoader.load();
178
- }
179
- }
180
-
181
- async #startLoading() {
182
- // console.log('#startLoading');
183
- // FIXME: in unit test when moved to startloading it hangs!
184
- // for (const { audioLoader } of this.#memorySources) {
185
- // audioLoader.load();
186
- // }
187
- }
188
-
189
- /**
190
- * Get Image source
191
- *
192
- * @param {string} label
193
- *
194
- * @returns {ImageSource}
195
- */
196
- #getImageSource(label) {
197
- for (const source of this.#imageSources) {
198
- if (label === source.label) {
199
- return source;
200
- }
201
- }
202
-
203
- throw new Error(`Source [${label}] has not been defined`);
204
- }
205
-
206
- /**
207
- * Get image scene loading progress
208
- */
209
- get progress() {
210
- return this.#progress;
211
- }
212
-
213
- /**
214
- * Get an image loader
215
- *
216
- * @param {string} label
217
- *
218
- * @returns {ImageLoader}
219
- */
220
- getImageLoader(label) {
221
- const source = this.#getImageSource(label);
222
-
223
- return source.imageLoader;
224
- }
225
-
226
- /**
227
- * Get object URL that can be used as src parameter of an HTML image
228
- *
229
- * @param {string} label
230
- *
231
- * @returns {ImageMeta}
232
- */
233
- getImageMeta(label) {
234
- const source = this.#getImageSource(label);
235
-
236
- return source.imageMeta;
237
- }
238
-
239
- /**
240
- * Get object URL that can be used as src parameter of an HTML image
241
- *
242
- * @param {string} label
243
- *
244
- * @note the objectURL should be revoked when no longer used
245
- *
246
- * @returns {string}
247
- */
248
- getObjectURL(label) {
249
- const source = this.#getImageSource(label);
250
-
251
- return source.imageLoader.getObjectURL();
252
- }
253
- }
@@ -1,184 +0,0 @@
1
- /** @typedef {import('./typedef.js').ImageMeta} ImageMeta */
2
-
3
- // import * as expect from '$lib/util/expect/index.js';
4
-
5
- import { calculateEffectiveWidth } from '$lib/util/image/index.js';
6
-
7
- import { untrack } from 'svelte';
8
-
9
- import ImageLoader from './ImageLoader.svelte.js';
10
-
11
- export default class ImageVariantsLoader {
12
- /** @type {number} */
13
- #devicePixelRatio;
14
-
15
- /** @type {ImageMeta[]} */
16
- #imagesMeta;
17
-
18
- /** @type {ImageMeta|null} */
19
- #imageVariant = $state(null);
20
-
21
- /** @type {ImageLoader|null} */
22
- #imageLoader = $state(null);
23
-
24
- /** @type {boolean} */
25
- #manuallyCheckedLoaded = $state(false);
26
-
27
- // Create a custom progress object that we control fully
28
- #customProgress = $state({
29
- bytesLoaded: 0,
30
- size: 0,
31
- loaded: false
32
- });
33
-
34
- #progress = $derived.by(() => {
35
- return this.#customProgress;
36
- });
37
-
38
- // Derive loaded state from our custom progress
39
- #loaded = $derived.by(() => this.#customProgress.loaded);
40
-
41
- /**
42
- * @param {ImageMeta[]} imagesMeta
43
- */
44
- constructor(imagesMeta, { devicePixelRatio = 1 } = {}) {
45
- this.#devicePixelRatio = devicePixelRatio ?? 1;
46
- this.#imagesMeta = [...imagesMeta].sort((a, b) => a.width - b.width);
47
-
48
- // Track when the imageLoader's progress changes
49
- $effect(() => {
50
- if (this.#imageLoader) {
51
- const loaderProgress = this.#imageLoader.progress;
52
-
53
- // Update our custom progress with the loader's values,
54
- // but maintain our own loaded state
55
- this.#customProgress = {
56
- bytesLoaded: loaderProgress.bytesLoaded,
57
- size: loaderProgress.size,
58
- loaded: this.#manuallyCheckedLoaded && loaderProgress.loaded
59
- };
60
- }
61
- });
62
- }
63
-
64
- /**
65
- * Set new optimal image variant or keep current
66
- *
67
- * @param {object} params
68
- * @param {number} [params.containerWidth] Container width
69
- * @param {number} [params.containerHeight] Container height
70
- * @param {'cover'|'contain'|'fill'} [params.fit='contain'] Fit mode
71
- */
72
- updateOptimalImageMeta({ containerWidth, containerHeight, fit = 'contain' }) {
73
- const baseImage = this.#imagesMeta[0];
74
- const imageAspectRatio = baseImage.width / baseImage.height;
75
-
76
- const effectiveWidth = calculateEffectiveWidth({
77
- containerWidth,
78
- containerHeight,
79
- imageAspectRatio,
80
- fit
81
- });
82
-
83
- const newVariant = this.getOptimalImageMeta(effectiveWidth);
84
-
85
- if (
86
- !newVariant ||
87
- !this.#imageVariant ||
88
- newVariant.width > this.#imageVariant.width
89
- ) {
90
- this.#imageVariant = newVariant;
91
-
92
- // Reset loaded state when changing variants
93
- this.#manuallyCheckedLoaded = false;
94
- this.#customProgress = {
95
- bytesLoaded: 0,
96
- size: 0,
97
- loaded: false
98
- };
99
-
100
- // Create and start loader here directly when variant changes
101
- if (this.#imageLoader?.initial) {
102
- this.#imageLoader.unload();
103
- }
104
-
105
- this.#imageLoader = new ImageLoader({
106
- imageMeta: newVariant
107
- });
108
-
109
- this.#imageLoader.load();
110
- }
111
- }
112
-
113
- get loaded() {
114
- return this.#loaded;
115
- }
116
-
117
- get variant() {
118
- return this.#imageVariant;
119
- }
120
-
121
- /**
122
- * Get object URL that can be used as src parameter of an HTML image
123
- *
124
- * @note the objectURL should be revoked when no longer used
125
- *
126
- * @returns {string|null}
127
- */
128
- getObjectURL() {
129
- // First check if the loader is actually loaded
130
- if (!this.#imageLoader?.loaded) {
131
- return null;
132
- }
133
-
134
- const blob = this.#imageLoader.getBlob();
135
-
136
- if (!blob) {
137
- return null;
138
- }
139
-
140
- // Successfully got a blob, so we're definitely loaded
141
- if (!this.#manuallyCheckedLoaded) {
142
- this.#manuallyCheckedLoaded = true;
143
-
144
- // Update our custom progress to indicate we're loaded
145
- this.#customProgress = {
146
- bytesLoaded: this.#customProgress.bytesLoaded,
147
- size: this.#customProgress.size,
148
- loaded: true
149
- };
150
- }
151
-
152
- return URL.createObjectURL(blob);
153
- }
154
-
155
- get progress() {
156
- return this.#progress;
157
- }
158
-
159
- /**
160
- * Get optimal image variant
161
- *
162
- * @param {number} containerWidth
163
- *
164
- * @returns {ImageMeta|null}
165
- */
166
- getOptimalImageMeta(containerWidth) {
167
- if (!containerWidth) {
168
- return null;
169
- }
170
-
171
- // Calculate the required width (container * DPR)
172
- const requiredWidth = containerWidth * this.#devicePixelRatio;
173
-
174
- const imagesMeta = this.#imagesMeta;
175
-
176
- // Find the smallest image that's larger than our required width
177
- const optimal = imagesMeta.find(
178
- (current) => current.width >= requiredWidth
179
- );
180
-
181
- // Fall back to the largest image if nothing is big enough
182
- return optimal || imagesMeta[imagesMeta.length - 1];
183
- }
184
- } // end class