@hkdigital/lib-core 0.4.39 → 0.4.41

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,13 +1,4 @@
1
- /**
2
- * @typedef {object} SourceConfig
3
- * // property ...
4
- */
5
- /**
6
- * @typedef {object} MemorySource
7
- * @property {string} label
8
- * @property {AudioLoader} audioLoader
9
- * @property {SourceConfig} [config]
10
- */
1
+ /** @typedef {import('./typedef.js').MemorySource} MemorySource */
11
2
  export default class AudioScene extends SceneBase {
12
3
  muted: boolean;
13
4
  targetGain: number;
@@ -29,16 +20,9 @@ export default class AudioScene extends SceneBase {
29
20
  * Add in-memory audio source
30
21
  * - Uses an AudioLoader instance to load audio data from network
31
22
  *
32
- * @param {object} _
33
- * @param {string} _.label
34
- * @param {string} _.url
35
- * @param {SourceConfig} [_.config]
23
+ * @param {import('./typedef.js').MemorySourceParams} params
36
24
  */
37
- defineMemorySource({ label, url, config }: {
38
- label: string;
39
- url: string;
40
- config?: object | undefined;
41
- }): void;
25
+ defineMemorySource({ label, url, config }: import("./typedef.js").MemorySourceParams): void;
42
26
  /**
43
27
  * Get a source that can be used to play the audio once
44
28
  *
@@ -63,9 +47,9 @@ export default class AudioScene extends SceneBase {
63
47
  */
64
48
  setTargetGain(value: number): void;
65
49
  /**
66
- * Get the current target gain (volume level)
50
+ * Get the current target gain
67
51
  *
68
- * @returns {number} Target gain value (0.0 to 1.0+)
52
+ * @returns {number}
69
53
  */
70
54
  getTargetGain(): number;
71
55
  /**
@@ -84,14 +68,6 @@ export default class AudioScene extends SceneBase {
84
68
  unmute(): void;
85
69
  #private;
86
70
  }
87
- /**
88
- * // property ...
89
- */
90
- export type SourceConfig = object;
91
- export type MemorySource = {
92
- label: string;
93
- audioLoader: AudioLoader;
94
- config?: object | undefined;
95
- };
71
+ export type MemorySource = import("./typedef.js").MemorySource;
96
72
  import SceneBase from '../base/SceneBase.svelte.js';
97
73
  import AudioLoader from './AudioLoader.svelte.js';
@@ -3,17 +3,7 @@ import * as expect from '../../../util/expect.js';
3
3
  import SceneBase from '../base/SceneBase.svelte.js';
4
4
  import AudioLoader from './AudioLoader.svelte.js';
5
5
 
6
- /**
7
- * @typedef {object} SourceConfig
8
- * // property ...
9
- */
10
-
11
- /**
12
- * @typedef {object} MemorySource
13
- * @property {string} label
14
- * @property {AudioLoader} audioLoader
15
- * @property {SourceConfig} [config]
16
- */
6
+ /** @typedef {import('./typedef.js').MemorySource} MemorySource */
17
7
 
18
8
  export default class AudioScene extends SceneBase {
19
9
 
@@ -25,19 +15,16 @@ export default class AudioScene extends SceneBase {
25
15
 
26
16
  targetGain = $derived( this.#targetGain );
27
17
 
28
- /** @type {AudioContext|null} */
29
- #audioContext = null;
18
+ /** @type {AudioContext|undefined} */
19
+ #audioContext;
30
20
 
31
- /** {GainNode} */
32
- #targetGainNode = null;
21
+ /** @type {GainNode|undefined} */
22
+ #targetGainNode;
33
23
 
34
24
  /** @type {MemorySource[]} */
35
25
  #memorySources = $state([]);
36
26
 
37
27
 
38
- /**
39
- * Construct AudioScene
40
- */
41
28
  constructor() {
42
29
  super();
43
30
  }
@@ -71,10 +58,7 @@ export default class AudioScene extends SceneBase {
71
58
  * Add in-memory audio source
72
59
  * - Uses an AudioLoader instance to load audio data from network
73
60
  *
74
- * @param {object} _
75
- * @param {string} _.label
76
- * @param {string} _.url
77
- * @param {SourceConfig} [_.config]
61
+ * @param {import('./typedef.js').MemorySourceParams} params
78
62
  */
79
63
  defineMemorySource({ label, url, config }) {
80
64
  expect.notEmptyString(label);
@@ -95,8 +79,10 @@ export default class AudioScene extends SceneBase {
95
79
  * @returns {Promise<AudioBufferSourceNode>}
96
80
  */
97
81
  async getSourceNode(label) {
82
+
98
83
  // @note Gain setup
99
- // https://stackoverflow.com/questions/46203191/should-i-disconnect-nodes-that-cant-be-used-anymore
84
+ // https://stackoverflow.com/
85
+ // questions/46203191/should-i-disconnect-nodes-that-cant-be-used-anymore
100
86
 
101
87
  const { audioLoader /*, config */ } = this.#getMemorySource(label);
102
88
 
@@ -149,9 +135,9 @@ export default class AudioScene extends SceneBase {
149
135
  }
150
136
 
151
137
  /**
152
- * Get the current target gain (volume level)
138
+ * Get the current target gain
153
139
  *
154
- * @returns {number} Target gain value (0.0 to 1.0+)
140
+ * @returns {number}
155
141
  */
156
142
  getTargetGain()
157
143
  {
@@ -191,6 +177,11 @@ export default class AudioScene extends SceneBase {
191
177
 
192
178
  /* ==== Internals */
193
179
 
180
+ /**
181
+ * Get or create the master gain node
182
+ *
183
+ * @returns {GainNode}
184
+ */
194
185
  #getGainNode()
195
186
  {
196
187
  if( !this.#targetGainNode )
@@ -205,6 +196,11 @@ export default class AudioScene extends SceneBase {
205
196
  return this.#targetGainNode;
206
197
  }
207
198
 
199
+ /**
200
+ * Get or create the audio context
201
+ *
202
+ * @returns {AudioContext}
203
+ */
208
204
  #getAudioContext()
209
205
  {
210
206
  if( !this.#audioContext )
@@ -216,7 +212,7 @@ export default class AudioScene extends SceneBase {
216
212
  }
217
213
 
218
214
  /**
219
- * Get memory source
215
+ * Find memory source by label
220
216
  *
221
217
  * @param {string} label
222
218
  *
@@ -0,0 +1,25 @@
1
+ declare const _default: {};
2
+ export default _default;
3
+ export type MemorySourceParams = {
4
+ /**
5
+ * - Source identifier
6
+ */
7
+ label: string;
8
+ /**
9
+ * - Audio file URL
10
+ */
11
+ url: string;
12
+ /**
13
+ * - Optional source configuration
14
+ */
15
+ config?: object | undefined;
16
+ };
17
+ export type MemorySource = {
18
+ label: string;
19
+ audioLoader: import("./AudioLoader.svelte.js").default;
20
+ config?: object | undefined;
21
+ };
22
+ /**
23
+ * // property ...
24
+ */
25
+ export type SourceConfig = object;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @typedef {object} MemorySourceParams
3
+ * @property {string} label - Source identifier
4
+ * @property {string} url - Audio file URL
5
+ * @property {SourceConfig} [config] - Optional source configuration
6
+ */
7
+
8
+ /**
9
+ * @typedef {object} MemorySource
10
+ * @property {string} label
11
+ * @property {import('./AudioLoader.svelte.js').default} audioLoader
12
+ * @property {SourceConfig} [config]
13
+ */
14
+
15
+ /**
16
+ * @typedef {object} SourceConfig
17
+ * // property ...
18
+ */
19
+
20
+ export default {};
@@ -1,3 +1,4 @@
1
+ /** @typedef {import('./typedef.js').SceneLoadingProgress} SceneLoadingProgress */
1
2
  /**
2
3
  * Base class for scene loaders that manage collections of media sources
3
4
  */
@@ -13,20 +14,15 @@ export default class SceneBase {
13
14
  /**
14
15
  * Extract the loader from a source object
15
16
  *
16
- * @param {*} source
17
+ * @param {object} source - Source object
17
18
  *
18
- * @returns {*} Loader object with progress and state properties
19
+ * @returns {import('../../states/index.js').NetworkLoader} loader
19
20
  */
20
- getLoaderFromSource(source: any): any;
21
+ getLoaderFromSource(source: object): import("../../states/index.js").NetworkLoader;
21
22
  /**
22
23
  * Get scene loading progress
23
24
  */
24
- get progress(): {
25
- totalBytesLoaded: number;
26
- totalSize: number;
27
- sourcesLoaded: number;
28
- numberOfSources: number;
29
- };
25
+ get progress(): import("./typedef.js").SceneLoadingProgress;
30
26
  /**
31
27
  * Get scene abort progress
32
28
  */
@@ -44,22 +40,24 @@ export default class SceneBase {
44
40
  abort(): void;
45
41
  /**
46
42
  * Preload all sources with progress tracking and abort capability
47
- * - Starts loading and waits for completion
48
- * - Supports timeout and progress callbacks
49
- * - Returns object with promise and abort function
50
43
  *
51
44
  * @param {object} [options]
52
- * @param {number} [options.timeoutMs=10000] - Timeout in milliseconds
53
- * @param {Function} [options.onProgress] - Progress callback function
45
+ * @param {number} [options.timeoutMs=10000]
46
+ * Timeout in milliseconds
47
+ * @param {(progress: SceneLoadingProgress) => void} [options.onProgress]
48
+ * Progress callback function
54
49
  *
55
- * @returns {object} Object with promise and abort function
56
- * @returns {Promise<SceneBase>} returns.promise - Promise that resolves when loaded
57
- * @returns {Function} returns.abort - Function to abort preloading
50
+ * @returns {{promise: Promise<SceneBase>, abort: Function}}
51
+ * Object with promise that resolves when loaded and abort function
58
52
  */
59
53
  preload({ timeoutMs, onProgress }?: {
60
54
  timeoutMs?: number | undefined;
61
- onProgress?: Function | undefined;
62
- }): object;
55
+ onProgress?: ((progress: SceneLoadingProgress) => void) | undefined;
56
+ }): {
57
+ promise: Promise<SceneBase>;
58
+ abort: Function;
59
+ };
63
60
  destroy(): void;
64
61
  #private;
65
62
  }
63
+ export type SceneLoadingProgress = import("./typedef.js").SceneLoadingProgress;
@@ -15,6 +15,8 @@ import {
15
15
 
16
16
  import { waitForState } from '../../../util/svelte.js';
17
17
 
18
+ /** @typedef {import('./typedef.js').SceneLoadingProgress} SceneLoadingProgress */
19
+
18
20
  /**
19
21
  * Base class for scene loaders that manage collections of media sources
20
22
  */
@@ -28,6 +30,7 @@ export default class SceneBase {
28
30
  return this.state === STATE_LOADED;
29
31
  });
30
32
 
33
+ /** @type {SceneLoadingProgress} */
31
34
  #progress = $derived.by(() => {
32
35
  let totalSize = 0;
33
36
  let totalBytesLoaded = 0;
@@ -130,9 +133,9 @@ export default class SceneBase {
130
133
  /**
131
134
  * Extract the loader from a source object
132
135
  *
133
- * @param {*} source
136
+ * @param {object} source - Source object
134
137
  *
135
- * @returns {*} Loader object with progress and state properties
138
+ * @returns {import('../../states/index.js').NetworkLoader} loader
136
139
  */
137
140
  // eslint-disable-next-line no-unused-vars
138
141
  getLoaderFromSource(source) {
@@ -171,21 +174,24 @@ export default class SceneBase {
171
174
 
172
175
  /**
173
176
  * Preload all sources with progress tracking and abort capability
174
- * - Starts loading and waits for completion
175
- * - Supports timeout and progress callbacks
176
- * - Returns object with promise and abort function
177
177
  *
178
178
  * @param {object} [options]
179
- * @param {number} [options.timeoutMs=10000] - Timeout in milliseconds
180
- * @param {Function} [options.onProgress] - Progress callback function
179
+ * @param {number} [options.timeoutMs=10000]
180
+ * Timeout in milliseconds
181
+ * @param {(progress: SceneLoadingProgress) => void} [options.onProgress]
182
+ * Progress callback function
181
183
  *
182
- * @returns {object} Object with promise and abort function
183
- * @returns {Promise<SceneBase>} returns.promise - Promise that resolves when loaded
184
- * @returns {Function} returns.abort - Function to abort preloading
184
+ * @returns {{promise: Promise<SceneBase>, abort: Function}}
185
+ * Object with promise that resolves when loaded and abort function
185
186
  */
186
187
  preload({ timeoutMs = 10000, onProgress } = {}) {
188
+
189
+ /** @type {number|NodeJS.Timeout|null} */
187
190
  let timeoutId = null;
191
+
192
+ /** @type {number|NodeJS.Timeout|null} */
188
193
  let progressIntervalId = null;
194
+
189
195
  let isAborted = false;
190
196
 
191
197
  const abort = () => {
@@ -0,0 +1,20 @@
1
+ declare const _default: {};
2
+ export default _default;
3
+ export type SceneLoadingProgress = {
4
+ /**
5
+ * - Total bytes loaded across all sources
6
+ */
7
+ totalBytesLoaded: number;
8
+ /**
9
+ * - Total size across all sources
10
+ */
11
+ totalSize: number;
12
+ /**
13
+ * - Number of sources fully loaded
14
+ */
15
+ sourcesLoaded: number;
16
+ /**
17
+ * - Total number of sources
18
+ */
19
+ numberOfSources: number;
20
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @typedef {Object} SceneLoadingProgress
3
+ * @property {number} totalBytesLoaded - Total bytes loaded across all sources
4
+ * @property {number} totalSize - Total size across all sources
5
+ * @property {number} sourcesLoaded - Number of sources fully loaded
6
+ * @property {number} numberOfSources - Total number of sources
7
+ */
8
+
9
+ export default {};
@@ -8,7 +8,7 @@ export default class ImageLoader extends NetworkLoader {
8
8
  * @param {import('../../../config/typedef.js').ImageSource} imageSource
9
9
  */
10
10
  constructor(imageSource: import("../../../config/typedef.js").ImageSource);
11
- get imageMeta(): import("./typedef.js").ImageMeta;
11
+ get imageMeta(): import("../../../config/typedef.js").ImageMeta;
12
12
  get url(): string | null;
13
13
  #private;
14
14
  }
@@ -1,16 +1,3 @@
1
1
  declare const _default: {};
2
2
  export default _default;
3
- export type ImageMeta = {
4
- /**
5
- * - URL of the image
6
- */
7
- src: string;
8
- /**
9
- * - Width of the image
10
- */
11
- width: number;
12
- /**
13
- * - Height of the image
14
- */
15
- height: number;
16
- };
3
+ export type ImageMeta = import("../../../config/typedef.js").ImageMeta;
@@ -1,8 +1,3 @@
1
- /**
2
- * @typedef {Object} ImageMeta
3
- * @property {string} src - URL of the image
4
- * @property {number} width - Width of the image
5
- * @property {number} height - Height of the image
6
- */
1
+ /** @typedef {import('../../../config/typedef.js').ImageMeta} ImageMeta */
7
2
 
8
3
  export default {};
@@ -422,7 +422,7 @@ export class ServiceManager extends EventEmitter {
422
422
  if (!result.ok) {
423
423
  // Create detailed error with the actual service failure
424
424
  const detailedError = new DetailedError(
425
- `Failed to start service [${name}], stopping`,
425
+ `Failed to start service [${name}]`,
426
426
  null,
427
427
  result.error
428
428
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.39",
3
+ "version": "0.4.41",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"