@hkdigital/lib-sveltekit 0.0.86 → 0.0.88

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
- NetworkLoader,
3
- ERROR_NOT_LOADED,
4
- ERROR_TRANSFERRED
2
+ NetworkLoader
3
+ // ERROR_NOT_LOADED,
4
+ // ERROR_TRANSFERRED
5
5
  } from '../network-loader/index.js';
6
6
 
7
7
  /**
@@ -9,4 +9,14 @@ import {
9
9
  * - Loads image data from network
10
10
  * - The loading process can be monitored
11
11
  */
12
- export default class ImageLoader extends NetworkLoader {} // end class
12
+ export default class ImageLoader extends NetworkLoader {
13
+ // > Inherited methods
14
+ //
15
+ // /**
16
+ // * Get object URL that can be used as src parameter of an HTML image
17
+ // *
18
+ // * @note the objectURL should be revoked when no longer used
19
+ // */
20
+ // getObjectUrl() {}
21
+ //
22
+ } // end class
@@ -1,8 +1,8 @@
1
- export default class ImageVariantsLoader {
1
+ export default class ImageMetasLoader {
2
2
  /**
3
- * @param {ImageVariant[]} imagesMeta
3
+ * @param {ImageMeta[]} imagesMeta
4
4
  */
5
- constructor(imagesMeta: ImageVariant[], { devicePixelRatio }?: {
5
+ constructor(imagesMeta: ImageMeta[], { devicePixelRatio }?: {
6
6
  devicePixelRatio?: number;
7
7
  });
8
8
  /**
@@ -10,9 +10,9 @@ export default class ImageVariantsLoader {
10
10
  *
11
11
  * @param {number} containerWidth
12
12
  */
13
- updateOptimalImageVariant(containerWidth: number): void;
13
+ updateOptimalImageMeta(containerWidth: number): void;
14
14
  get loaded(): boolean;
15
- get variant(): import("./typedef.js").ImageVariant;
15
+ get variant(): import("./typedef.js").ImageMeta;
16
16
  /**
17
17
  * Get object URL that can be used as src parameter of an HTML image
18
18
  *
@@ -31,9 +31,9 @@ export default class ImageVariantsLoader {
31
31
  *
32
32
  * @param {number} containerWidth
33
33
  *
34
- * @returns {ImageVariant|null}
34
+ * @returns {ImageMeta|null}
35
35
  */
36
- getOptimalImageVariant(containerWidth: number): ImageVariant | null;
36
+ getOptimalImageMeta(containerWidth: number): ImageMeta | null;
37
37
  #private;
38
38
  }
39
- export type ImageVariant = import("./typedef.js").ImageVariant;
39
+ export type ImageMeta = import("./typedef.js").ImageMeta;
@@ -1,4 +1,4 @@
1
- /** @typedef {import('./typedef.js').ImageVariant} ImageVariant */
1
+ /** @typedef {import('./typedef.js').ImageMeta} ImageMeta */
2
2
 
3
3
  // import * as expect from '@hkdigital/lib-sveltekit/util/expect/index.js';
4
4
 
@@ -6,14 +6,14 @@ import { untrack } from 'svelte';
6
6
 
7
7
  import ImageLoader from './ImageLoader.svelte.js';
8
8
 
9
- export default class ImageVariantsLoader {
9
+ export default class ImageMetasLoader {
10
10
  /** @type {number} */
11
11
  #devicePixelRatio;
12
12
 
13
- /** @type {ImageVariant[]} */
13
+ /** @type {ImageMeta[]} */
14
14
  #imagesMeta;
15
15
 
16
- /** @type {ImageVariant|null} */
16
+ /** @type {ImageMeta|null} */
17
17
  #imageVariant = $state(null);
18
18
 
19
19
  /** @type {ImageLoader|null} */
@@ -32,7 +32,7 @@ export default class ImageVariantsLoader {
32
32
  #loaded = $derived(this.#progress.loaded);
33
33
 
34
34
  /**
35
- * @param {ImageVariant[]} imagesMeta
35
+ * @param {ImageMeta[]} imagesMeta
36
36
  */
37
37
  constructor(imagesMeta, { devicePixelRatio = 1 } = {}) {
38
38
  // expect.notEmptyArray( imagesMeta );
@@ -66,8 +66,8 @@ export default class ImageVariantsLoader {
66
66
  *
67
67
  * @param {number} containerWidth
68
68
  */
69
- updateOptimalImageVariant(containerWidth) {
70
- const newVariant = this.getOptimalImageVariant(containerWidth);
69
+ updateOptimalImageMeta(containerWidth) {
70
+ const newVariant = this.getOptimalImageMeta(containerWidth);
71
71
 
72
72
  if (
73
73
  !newVariant ||
@@ -127,9 +127,9 @@ export default class ImageVariantsLoader {
127
127
  *
128
128
  * @param {number} containerWidth
129
129
  *
130
- * @returns {ImageVariant|null}
130
+ * @returns {ImageMeta|null}
131
131
  */
132
- getOptimalImageVariant(containerWidth) {
132
+ getOptimalImageMeta(containerWidth) {
133
133
  if (!containerWidth) {
134
134
  return null;
135
135
  }
@@ -1,2 +1,2 @@
1
1
  export { default as ImageLoader } from "./ImageLoader.svelte";
2
- export { default as ImageVariantsLoader } from "./ImageVariantsLoader.svelte";
2
+ export { default as ImageMetasLoader } from "./ImageMetasLoader.svelte";
@@ -1,4 +1,4 @@
1
1
  export { default as ImageLoader } from './ImageLoader.svelte';
2
- export { default as ImageVariantsLoader } from './ImageVariantsLoader.svelte';
2
+ export { default as ImageMetasLoader } from './ImageMetasLoader.svelte';
3
3
 
4
4
  // export * from './constants.js';
@@ -1,6 +1,6 @@
1
1
  declare const _default: {};
2
2
  export default _default;
3
- export type ImageVariant = {
3
+ export type ImageMeta = {
4
4
  /**
5
5
  * - URL of the image
6
6
  */
@@ -1,7 +1,7 @@
1
- // /** @typedef {import('@hkdigital/lib-sveltekit/types/imagetools.js').ImageVariant} ImageVariant */
1
+ // /** @typedef {import('@hkdigital/lib-sveltekit/types/imagetools.js').ImageMeta} ImageMeta */
2
2
 
3
3
  /**
4
- * @typedef {Object} ImageVariant
4
+ * @typedef {Object} ImageMeta
5
5
  * @property {string} src - URL of the image
6
6
  * @property {number} width - Width of the image
7
7
  * @property {number} height - Height of the image
@@ -80,6 +80,14 @@ export default class NetworkLoader {
80
80
  * @returns {Blob}
81
81
  */
82
82
  getBlob(): Blob;
83
+ /**
84
+ * Get object URL
85
+ *
86
+ * @note the objectURL should be revoked when no longer used
87
+ *
88
+ * @returns {string|null}
89
+ */
90
+ getObjectUrl(): string | null;
83
91
  #private;
84
92
  }
85
93
  import { LoadingStateMachine } from '../loading-state-machine/index.js';
@@ -18,10 +18,7 @@ import {
18
18
 
19
19
  import * as expect from '@hkdigital/lib-sveltekit/util/expect/index.js';
20
20
 
21
- import {
22
- httpGet,
23
- loadResponseBuffer
24
- } from '@hkdigital/lib-sveltekit/util/http/index.js';
21
+ import { httpGet, loadResponseBuffer } from '@hkdigital/lib-sveltekit/util/http/index.js';
25
22
 
26
23
  import { ERROR_NOT_LOADED, ERROR_TRANSFERRED } from './constants.js';
27
24
 
@@ -214,6 +211,36 @@ export default class NetworkLoader {
214
211
  return new Blob([this.getArrayBuffer()], options);
215
212
  }
216
213
 
214
+ /**
215
+ * Get object URL
216
+ *
217
+ * @note the objectURL should be revoked when no longer used
218
+ *
219
+ * @returns {string|null}
220
+ */
221
+ getObjectUrl() {
222
+ //
223
+ // Example usage:
224
+ //
225
+ // $effect(() => {
226
+ // if (loader.loaded) {
227
+ // // @ts-ignore
228
+ // objectUrl = loader.getObjectUrl();
229
+ // }
230
+ //
231
+ // return () => {
232
+ // if (objectUrl) {
233
+ // URL.revokeObjectURL(objectUrl);
234
+ // objectUrl = null;
235
+ // }
236
+ // };
237
+ // });
238
+
239
+ const blob = this.getBlob();
240
+
241
+ return blob ? URL.createObjectURL(blob) : null;
242
+ }
243
+
217
244
  /**
218
245
  * Internal method that initializes the loading process
219
246
  * and transitions to state LOADED when done
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Create a response value that can be used by a mocked
3
+ * fetch function
4
+ *
5
+ * @returns {Response}
6
+ */
7
+ export function createDataResponse(): Response;
@@ -0,0 +1,30 @@
1
+ import { CONTENT_TYPE, CONTENT_LENGTH } from '@hkdigital/lib-sveltekit/constants/http/index.js';
2
+
3
+ import { OCTET_STREAM } from '@hkdigital/lib-sveltekit/constants/mime/application.js';
4
+
5
+ const BASE64_DATA =
6
+ 'UklGRnwAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YVgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
7
+
8
+ /**
9
+ * Create a response value that can be used by a mocked
10
+ * fetch function
11
+ *
12
+ * @returns {Response}
13
+ */
14
+ export function createDataResponse(/* data , options */) {
15
+ const binaryString = atob(BASE64_DATA);
16
+ const bytes = new Uint8Array(binaryString.length);
17
+
18
+ for (let i = 0; i < binaryString.length; i++) {
19
+ bytes[i] = binaryString.charCodeAt(i);
20
+ }
21
+
22
+ const response = new Response(bytes, {
23
+ headers: new Headers({
24
+ [CONTENT_TYPE]: OCTET_STREAM,
25
+ [CONTENT_LENGTH]: String(bytes.length)
26
+ })
27
+ });
28
+
29
+ return response;
30
+ }
@@ -1,7 +1,7 @@
1
1
  <script>
2
- /** @typedef {import('../../types/imagetools.js').ImageVariant} ImageVariant */
2
+ /** @typedef {import('../../types/imagetools.js').ImageMeta} ImageMeta */
3
3
 
4
- import { ImageVariantsLoader } from '../../classes/svelte/image/index.js';
4
+ import { ImageMetasLoader } from '../../classes/svelte/image/index.js';
5
5
 
6
6
  /**
7
7
  * @type {{
@@ -10,7 +10,7 @@
10
10
  * boxBase?: string,
11
11
  * boxClasses?: string
12
12
  * boxAttrs?: { [attr: string]: * },
13
- * images: ImageVariant[],
13
+ * images: ImageMeta[],
14
14
  * alt?: string
15
15
  * } & { [attr: string]: * }}
16
16
  */
@@ -29,15 +29,15 @@
29
29
  ...attrs
30
30
  } = $props();
31
31
 
32
- let variantsLoader = new ImageVariantsLoader(images);
32
+ let variantsLoader = new ImageMetasLoader(images);
33
33
 
34
34
  let containerWidth = $state(0);
35
35
 
36
- /** @type {ImageVariant|null} */
36
+ /** @type {ImageMeta|null} */
37
37
  let imageVariant = $state(null);
38
38
 
39
39
  $effect(() => {
40
- variantsLoader.updateOptimalImageVariant(containerWidth);
40
+ variantsLoader.updateOptimalImageMeta(containerWidth);
41
41
  });
42
42
 
43
43
  // $effect(() => {
@@ -1,5 +1,5 @@
1
1
  export default ResponsiveImage;
2
- export type ImageVariant = any;
2
+ export type ImageMeta = any;
3
3
  declare const ResponsiveImage: import("svelte").Component<{
4
4
  base?: string;
5
5
  classes?: string;
@@ -8,7 +8,7 @@ declare const ResponsiveImage: import("svelte").Component<{
8
8
  boxAttrs?: {
9
9
  [attr: string]: any;
10
10
  };
11
- images: ImageVariant[];
11
+ images: ImageMeta[];
12
12
  alt?: string;
13
13
  } & {
14
14
  [attr: string]: any;
@@ -1,4 +1,4 @@
1
1
  export { default as ResponsiveImage } from "./ResponsiveImage.svelte";
2
2
  declare const _default: {};
3
3
  export default _default;
4
- export type ImageVariant = any;
4
+ export type ImageMeta = any;
@@ -1,4 +1,4 @@
1
- /** @typedef {import('../../types/imagetools.js').ImageVariant} ImageVariant */
1
+ /** @typedef {import('../../types/imagetools.js').ImageMeta} ImageMeta */
2
2
 
3
3
  export { default as ResponsiveImage } from './ResponsiveImage.svelte';
4
4
 
@@ -1,87 +1,67 @@
1
1
 
2
2
 
3
- interface ImageVariant {
3
+ interface ImageMeta {
4
4
  src: string;
5
5
  width?: number;
6
6
  height?: number;
7
7
  }
8
8
 
9
9
  declare module '*?responsive' {
10
- const out: ImageVariant[];
10
+ const out: ImageMeta[];
11
11
  export default out;
12
12
  }
13
13
 
14
14
  declare module '*&responsive' {
15
- const out: ImageVariant[];
15
+ const out: ImageMeta[];
16
16
  export default out;
17
17
  }
18
18
 
19
19
  declare module '*?preset=gradient' {
20
- const out: ImageVariant[]|string[]|string;
20
+ const out: ImageMeta|ImageMeta[];
21
21
  export default out;
22
22
  }
23
23
 
24
24
  declare module '*&preset=gradient' {
25
- const out: ImageVariant[]|string[]|string;
25
+ const out: ImageMeta|ImageMeta[];
26
26
  export default out;
27
27
  }
28
28
 
29
29
  declare module '*?preset=photo' {
30
- const out: ImageVariant[]|string[]|string;
30
+ const out: ImageMeta|ImageMeta[];
31
31
  export default out;
32
32
  }
33
33
 
34
34
  declare module '*&preset=photo' {
35
- const out: ImageVariant[]|string[]|string;
35
+ const out: ImageMeta|ImageMeta[];
36
36
  export default out;
37
37
  }
38
38
 
39
39
  declare module '*?preset=drawing' {
40
- const out: ImageVariant[]|string[]|string;
40
+ const out: ImageMeta|ImageMeta[];
41
41
  export default out;
42
42
  }
43
43
 
44
44
  declare module '*&preset=drawing' {
45
- const out: ImageVariant[]|string[]|string;
45
+ const out: ImageMeta|ImageMeta[];
46
46
  export default out;
47
47
  }
48
48
 
49
49
  declare module '*?preset=savedata' {
50
- const out: ImageVariant[]|string[]|string;
50
+ const out: ImageMeta|ImageMeta[];
51
51
  export default out;
52
52
  }
53
53
 
54
54
  declare module '*&preset=savedata' {
55
- const out: ImageVariant[]|string[]|string;
55
+ const out: ImageMeta|ImageMeta[];
56
56
  export default out;
57
57
  }
58
58
 
59
59
  declare module '*?preset=blur' {
60
- const out: ImageVariant[]|string[]|string;
60
+ const out: ImageMeta|ImageMeta[];
61
61
  export default out;
62
62
  }
63
63
 
64
64
  declare module '*&preset=blur' {
65
- const out: ImageVariant[]|string[]|string;
65
+ const out: ImageMeta|ImageMeta[];
66
66
  export default out;
67
- }
68
-
69
- // declare module '*&w=sm' {
70
- // const src: string;
71
- // export default src;
72
- // }
73
-
74
- // declare module '*&w=md' {
75
- // const src: string;
76
- // export default src;
77
- // }
78
-
79
- // declare module '*&w=lg' {
80
- // const src: string;
81
- // export default src;
82
- // }
83
-
84
- // declare module '*&w=hd' {
85
- // const src: string;
86
- // export default src;
87
- // }
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "author": "Jens Kleinhout, HKdigital (https://hkdigital.nl)",
5
5
  "license": "ISC",
6
6
  "repository": {