@hkdigital/lib-core 0.4.48 → 0.4.50

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.
@@ -165,6 +165,7 @@ export async function jsonPost(options) {
165
165
  // Apply JSON-specific defaults and validation
166
166
  expect.defined(body);
167
167
 
168
+ /** @type {Record<string, string>} */
168
169
  const jsonHeaders = headers || {};
169
170
  jsonHeaders[ACCEPT] = APPLICATION_JSON;
170
171
  jsonHeaders[CONTENT_TYPE] = APPLICATION_JSON;
@@ -18,7 +18,7 @@ export type HttpRequestOptions = {
18
18
  /**
19
19
  * HTTP headers as name-value pairs
20
20
  */
21
- headers?: Object | undefined;
21
+ headers?: Record<string, string> | undefined;
22
22
  /**
23
23
  * Whether to include credentials
24
24
  */
@@ -79,7 +79,7 @@ export type JsonGetOptions = {
79
79
  /**
80
80
  * HTTP headers as name-value pairs
81
81
  */
82
- headers?: Object | undefined;
82
+ headers?: Record<string, string> | undefined;
83
83
  /**
84
84
  * Whether to include credentials
85
85
  */
@@ -129,7 +129,7 @@ export type JsonPostOptions = {
129
129
  /**
130
130
  * HTTP headers as name-value pairs
131
131
  */
132
- headers?: Object | undefined;
132
+ headers?: Record<string, string> | undefined;
133
133
  /**
134
134
  * Whether to include credentials
135
135
  */
@@ -7,7 +7,7 @@
7
7
  * Parameters to add to the URL
8
8
  *
9
9
  * @property {*} [body] Request body (for POST, PUT, etc.)
10
- * @property {Object} [headers] HTTP headers as name-value pairs
10
+ * @property {Record<string, string>} [headers] HTTP headers as name-value pairs
11
11
  * @property {boolean} [withCredentials] Whether to include credentials
12
12
  * @property {number} [timeoutMs] Request timeout in milliseconds
13
13
  * @property {Function} [requestHandler] Handler for abort/timeout control
@@ -41,7 +41,7 @@
41
41
  * @property {Object|URLSearchParams} [urlSearchParams]
42
42
  * Parameters to add to the URL
43
43
  *
44
- * @property {Object} [headers] HTTP headers as name-value pairs
44
+ * @property {Record<string, string>} [headers] HTTP headers as name-value pairs
45
45
  * @property {boolean} [withCredentials] Whether to include credentials
46
46
  * @property {number} [timeoutMs] Request timeout in milliseconds
47
47
  * @property {RequestHandler} [requestHandler] Handler for abort/timeout control
@@ -60,7 +60,7 @@
60
60
  * @property {Object|URLSearchParams} [urlSearchParams]
61
61
  * Parameters to add to the URL
62
62
  *
63
- * @property {Object} [headers] HTTP headers as name-value pairs
63
+ * @property {Record<string, string>} [headers] HTTP headers as name-value pairs
64
64
  * @property {boolean} [withCredentials] Whether to include credentials
65
65
  * @property {number} [timeoutMs] Request timeout in milliseconds
66
66
  * @property {RequestHandler} [requestHandler] Handler for abort/timeout control
@@ -42,7 +42,6 @@ export default class ImageScene extends SceneBase {
42
42
  *
43
43
  * @returns {ImageLoader}
44
44
  */
45
- // eslint-disable-next-line no-unused-vars
46
45
  getLoaderFromSource(source) {
47
46
  return source.imageLoader;
48
47
  }
@@ -65,4 +65,4 @@ export default class ConfigPlugin {
65
65
  detach(): void;
66
66
  #private;
67
67
  }
68
- export type ServiceEntry = import("../service-manager/typedef.js").ServiceEntry;
68
+ export type ServiceEntry = any;
@@ -14,7 +14,7 @@ export class ServiceBase extends EventEmitter {
14
14
  * Create a new service instance
15
15
  *
16
16
  * @param {string} name - Service name
17
- * @param {import('./typedef.js').ServiceOptions} [options={}] - Service options
17
+ * @param {import('./typedef.js').ServiceOptions} [options]
18
18
  */
19
19
  constructor(name: string, options?: import("./typedef.js").ServiceOptions);
20
20
  /** @type {string} */
@@ -29,8 +29,6 @@ export class ServiceBase extends EventEmitter {
29
29
  error: Error | null;
30
30
  /** @type {Logger} */
31
31
  logger: Logger;
32
- /** @private @type {number} */
33
- private _shutdownTimeout;
34
32
  /**
35
33
  * Configure the service with configuration
36
34
  *
@@ -93,9 +93,10 @@ export class ServiceBase extends EventEmitter {
93
93
  * Create a new service instance
94
94
  *
95
95
  * @param {string} name - Service name
96
- * @param {import('./typedef.js').ServiceOptions} [options={}] - Service options
96
+ * @param {import('./typedef.js').ServiceOptions} [options]
97
97
  */
98
- constructor(name, options = {}) {
98
+ // eslint-disable-next-line no-unused-vars
99
+ constructor(name, options) {
99
100
  super();
100
101
 
101
102
  if( typeof name !== 'string' )
@@ -119,10 +120,13 @@ export class ServiceBase extends EventEmitter {
119
120
  this.error = null;
120
121
 
121
122
  /** @type {Logger} */
122
- this.logger = new Logger(name, options.logLevel || INFO);
123
+ this.logger = new Logger(name, INFO);
124
+ // this.logger = new Logger(name, options.logLevel || INFO);
123
125
 
124
126
  /** @private @type {number} */
125
- this._shutdownTimeout = options.shutdownTimeout || 5000;
127
+ // this._shutdownTimeout = options.shutdownTimeout || 5000;
128
+
129
+ // this.manager = options.manager;
126
130
  }
127
131
 
128
132
  /**
@@ -19,14 +19,7 @@ export type ServiceState = "not-created" | "created" | "configuring" | "configur
19
19
  * Options for creating a service instance
20
20
  */
21
21
  export type ServiceOptions = {
22
- /**
23
- * - Initial log level for the service
24
- */
25
- logLevel?: string | undefined;
26
- /**
27
- * - Timeout for graceful shutdown
28
- */
29
- shutdownTimeout?: number | undefined;
22
+ manager: import("../service-manager/ServiceManager.js").default;
30
23
  };
31
24
  /**
32
25
  * Options for stopping a service
@@ -53,8 +53,7 @@
53
53
  * Options for creating a service instance
54
54
  *
55
55
  * @typedef {Object} ServiceOptions
56
- * @property {string} [logLevel] - Initial log level for the service
57
- * @property {number} [shutdownTimeout=5000] - Timeout for graceful shutdown
56
+ * @property {import('../service-manager/ServiceManager.js').default} manager
58
57
  */
59
58
 
60
59
  /**
@@ -78,12 +78,12 @@ export class ServiceManager extends EventEmitter {
78
78
  /**
79
79
  * Get or create a service instance
80
80
  *
81
+ * @template {import('../service-base/typedef.js').ServiceInstance} T
81
82
  * @param {string} name - Service name
82
83
  *
83
- * @returns {import('../service-base/typedef.js').ServiceInstance|null}
84
- * Service instance or null if not found
84
+ * @returns {T|null} Service instance or null if not found
85
85
  */
86
- get(name: string): import("../service-base/typedef.js").ServiceInstance | null;
86
+ get<T extends import("../service-base/typedef.js").ServiceInstance>(name: string): T | null;
87
87
  /**
88
88
  * Configure a service
89
89
  *
@@ -217,7 +217,7 @@ export type LogLevel = import("../../logging/typedef.js").LogLevel;
217
217
  export type ServiceConstructor = import("./typedef.js").ServiceConstructor;
218
218
  export type ServiceRegistrationOptions = import("./typedef.js").ServiceRegistrationOptions;
219
219
  export type ServiceManagerConfig = import("./typedef.js").ServiceManagerConfig;
220
- export type ServiceEntry = import("./typedef.js").ServiceEntry;
220
+ export type ServiceEntry = any;
221
221
  export type ServiceConfigOrLabel = import("./typedef.js").ServiceConfigOrLabel;
222
222
  export type HealthCheckResult = import("./typedef.js").HealthCheckResult;
223
223
  export type StopOptions = import("../service-base/typedef.js").StopOptions;
@@ -258,10 +258,10 @@ export class ServiceManager extends EventEmitter {
258
258
  /**
259
259
  * Get or create a service instance
260
260
  *
261
+ * @template {import('../service-base/typedef.js').ServiceInstance} T
261
262
  * @param {string} name - Service name
262
263
  *
263
- * @returns {import('../service-base/typedef.js').ServiceInstance|null}
264
- * Service instance or null if not found
264
+ * @returns {T|null} Service instance or null if not found
265
265
  */
266
266
  get(name) {
267
267
  // @throws service not found
@@ -269,7 +269,9 @@ export class ServiceManager extends EventEmitter {
269
269
 
270
270
  if (!entry.instance) {
271
271
  try {
272
- entry.instance = new entry.ServiceClass(name);
272
+ const options = { manager: this };
273
+
274
+ entry.instance = new entry.ServiceClass(name, options);
273
275
 
274
276
  // Apply log level
275
277
  const logLevel = this.#getServiceLogLevel(name);
@@ -84,23 +84,23 @@ export type ServiceManagerPlugin = {
84
84
  */
85
85
  detach: () => void;
86
86
  /**
87
- * - Optional config resolution method
87
+ * - Optional config resolution
88
88
  */
89
- resolveServiceConfig?: ((arg0: string, arg1: ServiceEntry, arg2: any) => Promise<any | undefined>) | undefined;
89
+ resolveServiceConfig?: ((arg0: string, arg1: ServiceEntry<import("../service-base/typedef.js").ServiceInstance>, arg2: any) => Promise<any | undefined>) | undefined;
90
90
  };
91
91
  /**
92
92
  * Internal service registry entry, an internal registry entry that the
93
93
  * ServiceManager uses to track each registered service.
94
94
  */
95
- export type ServiceEntry = {
95
+ export type ServiceEntry<T extends import("../service-base/typedef.js").ServiceInstance> = {
96
96
  /**
97
97
  * - Service class constructor
98
98
  */
99
- ServiceClass: ServiceConstructor;
99
+ ServiceClass: new (name: string, options?: any) => T;
100
100
  /**
101
101
  * - Service instance (lazy-created)
102
102
  */
103
- instance: import("../service-base/typedef.js").ServiceInstance | null;
103
+ instance: T | null;
104
104
  serviceConfigOrLabel: ServiceConfigOrLabel;
105
105
  dependencies: string[];
106
106
  /**
@@ -64,13 +64,15 @@
64
64
 
65
65
  /**
66
66
  * Result of health check for all services
67
- * @typedef {Object<string, import('../service-base/typedef.js').HealthStatus>} HealthCheckResult
67
+ * @typedef {Object<string,
68
+ * import('../service-base/typedef.js').HealthStatus>} HealthCheckResult
68
69
  */
69
70
 
70
71
  /**
71
72
  * Service class constructor type
72
73
  *
73
- * @typedef {new (name: string, options?: import('../service-base/typedef.js').ServiceOptions) => import('../service-base/typedef.js').ServiceInstance} ServiceConstructor
74
+ * @typedef {new (name: string, options?: import('../service-base/typedef.js').ServiceOptions)
75
+ * => import('../service-base/typedef.js').ServiceInstance} ServiceConstructor
74
76
  */
75
77
 
76
78
  /**
@@ -81,7 +83,9 @@
81
83
  * @property {import('./ServiceManager.js').ServiceManager|null} manager - ServiceManager reference
82
84
  * @property {function(import('./ServiceManager.js').ServiceManager): void} attach - Attach to ServiceManager
83
85
  * @property {function(): void} detach - Detach from ServiceManager
84
- * @property {function(string, ServiceEntry, *): Promise<*|undefined>} [resolveServiceConfig] - Optional config resolution method
86
+ * @property {function(string,
87
+ * ServiceEntry<import('../service-base/typedef.js').ServiceInstance>, *
88
+ * ): Promise<*|undefined>} [resolveServiceConfig] - Optional config resolution
85
89
  */
86
90
 
87
91
  // ============================================================================
@@ -92,9 +96,10 @@
92
96
  * Internal service registry entry, an internal registry entry that the
93
97
  * ServiceManager uses to track each registered service.
94
98
  *
99
+ * @template {import('../service-base/typedef.js').ServiceInstance} T
95
100
  * @typedef {Object} ServiceEntry
96
- * @property {ServiceConstructor} ServiceClass - Service class constructor
97
- * @property {import('../service-base/typedef.js').ServiceInstance|null} instance - Service instance (lazy-created)
101
+ * @property {new (name: string, options?: *) => T} ServiceClass - Service class constructor
102
+ * @property {T|null} instance - Service instance (lazy-created)
98
103
  * @property {ServiceConfigOrLabel} serviceConfigOrLabel
99
104
  * @property {string[]} dependencies
100
105
  * @property {Set<string>} dependents - Services that depend on this service
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Hide element when it has no visible content (empty text, no images/icons)
3
+ *
4
+ * @param {HTMLElement} element - Element to monitor and hide when empty
5
+ *
6
+ * @returns {Object} Action object with destroy method for cleanup
7
+ *
8
+ * @example
9
+ * When dynamicContent is empty, the div is hidden (display: none) to
10
+ * prevent it from taking up space due to its padding.
11
+ *
12
+ * <div use:hideIfEmpty style="padding: 10px">{dynamicContent}</div>
13
+ */
14
+ export function hideIfEmpty(element: HTMLElement): Object;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Hide element when it has no visible content (empty text, no images/icons)
3
+ *
4
+ * @param {HTMLElement} element - Element to monitor and hide when empty
5
+ *
6
+ * @returns {Object} Action object with destroy method for cleanup
7
+ *
8
+ * @example
9
+ * When dynamicContent is empty, the div is hidden (display: none) to
10
+ * prevent it from taking up space due to its padding.
11
+ *
12
+ * <div use:hideIfEmpty style="padding: 10px">{dynamicContent}</div>
13
+ */
14
+ export function hideIfEmpty(element) {
15
+ function hasVisibleContent() {
16
+ // Get all text content and trim whitespace
17
+ const textContent = element.textContent?.trim() || '';
18
+
19
+ // Check for images, icons, or other non-text content
20
+ const hasImages = element.querySelector('img, svg, [class*="icon"]');
21
+
22
+ return textContent.length > 0 || hasImages;
23
+ }
24
+
25
+ function updateVisibility() {
26
+ const shouldHide = !hasVisibleContent();
27
+ element.style.display = shouldHide ? 'none' : '';
28
+ }
29
+
30
+ // Initial check
31
+ updateVisibility();
32
+
33
+ // Watch for DOM changes
34
+ const observer = new MutationObserver(updateVisibility);
35
+ observer.observe(element, {
36
+ childList: true, // Watch for added/removed child elements
37
+ subtree: true, // Watch all descendants
38
+ characterData: true // Watch for text content changes
39
+ });
40
+
41
+ return {
42
+ destroy() {
43
+ observer.disconnect();
44
+ }
45
+ };
46
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { default as hideIfEmpty } from './actions/hideIfEmpty.js';
@@ -23,11 +23,12 @@
23
23
  * theme - name of the icon theme (e.g. 'solid' or 'outline')
24
24
  *
25
25
  * @type {{
26
- * src: import('./typedef.js').IconSource,
27
- * size?: string,
28
- * theme?: string,
29
26
  * base?: string,
30
27
  * classes?: string
28
+ * size?: string,
29
+ * variant?: string,
30
+ * src: import('./typedef.js').IconSource,
31
+ * theme?: string,
31
32
  * } & { [attr: string]: any }}
32
33
  */
33
34
  let {
@@ -71,6 +72,7 @@
71
72
  data-component="icon"
72
73
  data-type="steeze"
73
74
  data-size={size}
75
+ data-variant={variant}
74
76
  {...icon?.a}
75
77
  xmlns="http://www.w3.org/2000/svg"
76
78
  class="{base} {classes}"
@@ -2,21 +2,23 @@ export default SteezeIcon;
2
2
  type SteezeIcon = {
3
3
  $on?(type: string, callback: (e: any) => void): () => void;
4
4
  $set?(props: Partial<{
5
- src: IconSource;
6
- size?: string | undefined;
7
- theme?: string | undefined;
8
5
  base?: string | undefined;
9
6
  classes?: string | undefined;
7
+ size?: string | undefined;
8
+ variant?: string | undefined;
9
+ src: IconSource;
10
+ theme?: string | undefined;
10
11
  } & {
11
12
  [attr: string]: any;
12
13
  }>): void;
13
14
  };
14
15
  declare const SteezeIcon: import("svelte").Component<{
15
- src: import("./typedef.js").IconSource;
16
- size?: string;
17
- theme?: string;
18
16
  base?: string;
19
17
  classes?: string;
18
+ size?: string;
19
+ variant?: string;
20
+ src: import("./typedef.js").IconSource;
21
+ theme?: string;
20
22
  } & {
21
23
  [attr: string]: any;
22
24
  }, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.48",
3
+ "version": "0.4.50",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"