ng-hub-ui-loading 22.0.0

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.
@@ -0,0 +1,252 @@
1
+ import * as _angular_core from '@angular/core';
2
+ import { Signal, InjectionToken, EnvironmentProviders } from '@angular/core';
3
+
4
+ /**
5
+ * Where the indicator is placed relative to the document.
6
+ *
7
+ * `overlay` positions absolutely, so the **parent must establish a containing
8
+ * block** (`position: relative`); `fullscreen` is fixed to the viewport and is
9
+ * what {@link HubLoadingService} mounts on `document.body`.
10
+ */
11
+ type HubLoadingMode = 'inline' | 'overlay' | 'fullscreen';
12
+ /** Built-in pure-CSS activity indicators, so the library ships no image assets. */
13
+ type HubLoadingVariant = 'spinner' | 'dots' | 'bars' | 'pulse' | 'ring';
14
+ /** Size step mapped to `--hub-loading-size`; the token stays overridable on its own. */
15
+ type HubLoadingSize = 'sm' | 'md' | 'lg';
16
+ /** Motion applied to a branding image that replaces the built-in indicator. */
17
+ type HubLoadingImageAnimation = 'none' | 'spin' | 'pulse';
18
+ /**
19
+ * Per-call presentation options accepted by {@link HubLoadingService}.
20
+ *
21
+ * Every field is optional: omitted values fall back to the application-wide
22
+ * {@link HubLoadingConfig}, so a caller only states what it wants to change.
23
+ * `mode` is deliberately absent — the service always renders fullscreen.
24
+ */
25
+ interface HubLoadingOptions {
26
+ /** Text rendered under the indicator; `null` renders no message. */
27
+ message?: string | null;
28
+ /** Which built-in indicator to render when no {@link image} is supplied. */
29
+ variant?: HubLoadingVariant;
30
+ /** URL or data URI replacing the built-in indicator with a brand mark. */
31
+ image?: string | null;
32
+ /** Motion applied to {@link image}; ignored when no image is set. */
33
+ imageAnimation?: HubLoadingImageAnimation;
34
+ /** Size step driving `--hub-loading-size`. */
35
+ size?: HubLoadingSize;
36
+ /** Accent colour: a semantic name, a hex/`oklch()` literal or a `var(...)` reference. */
37
+ color?: string | null;
38
+ /** Paints the translucent scrim; honoured in overlay and fullscreen modes only. */
39
+ backdrop?: boolean;
40
+ /** Accessible label announced through `role="status"`. */
41
+ ariaLabel?: string;
42
+ }
43
+ /**
44
+ * Application-wide defaults for every loading indicator.
45
+ *
46
+ * Fully resolved (no optional members) so the component and the service can read
47
+ * a value without re-implementing the fallback chain at each call site.
48
+ */
49
+ interface HubLoadingConfig {
50
+ /** Default text under the indicator. */
51
+ message: string | null;
52
+ /** Default built-in indicator. */
53
+ variant: HubLoadingVariant;
54
+ /** Default branding image, if the whole application uses one. */
55
+ image: string | null;
56
+ /** Default motion for the branding image. */
57
+ imageAnimation: HubLoadingImageAnimation;
58
+ /** Default size step. */
59
+ size: HubLoadingSize;
60
+ /** Default accent colour, or `null` to keep the stylesheet's own accent. */
61
+ color: string | null;
62
+ /** Default scrim visibility for overlay and fullscreen modes. */
63
+ backdrop: boolean;
64
+ /** Default accessible label. */
65
+ ariaLabel: string;
66
+ }
67
+
68
+ /**
69
+ * Activity indicator rendered inline, over its container or over the viewport.
70
+ *
71
+ * Every input defaults to the injected `HUB_LOADING_CONFIG`, so `provideHubLoading()`
72
+ * re-bases an entire application (brand image, variant, translated label) without
73
+ * touching a single template, while a per-instance binding still wins locally.
74
+ *
75
+ * Styles are unencapsulated on purpose: the host carries the `hub-loading` class and
76
+ * the token block, so consumers can retheme the indicator from a global stylesheet —
77
+ * and so the service-mounted overlay, created outside any component's style scope,
78
+ * is still painted.
79
+ *
80
+ * @example
81
+ * ```html
82
+ * <hub-loading variant="dots" message="Loading orders…" />
83
+ *
84
+ * <div style="position: relative">
85
+ * <hub-loading mode="overlay" color="primary" />
86
+ * </div>
87
+ * ```
88
+ */
89
+ declare class HubLoadingComponent {
90
+ /** Application-wide defaults; also the source of every input's default value. */
91
+ private readonly config;
92
+ /**
93
+ * Placement of the indicator. `overlay` needs a positioned ancestor to cover;
94
+ * `fullscreen` is fixed to the viewport and layered at `--hub-loading-z-index`.
95
+ */
96
+ readonly mode: _angular_core.InputSignal<HubLoadingMode>;
97
+ /** Built-in CSS indicator rendered when no {@link image} is supplied. */
98
+ readonly variant: _angular_core.InputSignal<HubLoadingVariant>;
99
+ /** URL or data URI shown instead of the built-in indicator. */
100
+ readonly image: _angular_core.InputSignal<string | null>;
101
+ /** Motion applied to {@link image}; inert while no image is set. */
102
+ readonly imageAnimation: _angular_core.InputSignal<HubLoadingImageAnimation>;
103
+ /** Text rendered below the indicator. */
104
+ readonly message: _angular_core.InputSignal<string | null>;
105
+ /** Size step feeding `--hub-loading-size`; the token remains overridable on its own. */
106
+ readonly size: _angular_core.InputSignal<HubLoadingSize>;
107
+ /**
108
+ * Accent for the indicator. Accepts a semantic name (`primary`), a CSS colour
109
+ * literal (`#0d6efd`, `oklch(...)`) or a `var(...)` reference — normalised by
110
+ * `resolveHubAccent()` into the single `--hub-loading-accent` slot.
111
+ */
112
+ readonly color: _angular_core.InputSignal<string | null>;
113
+ /** Paints the translucent scrim. Ignored in `inline` mode, which covers nothing. */
114
+ readonly backdrop: _angular_core.InputSignalWithTransform<boolean, unknown>;
115
+ /** Accessible label announced by the host's `role="status"` live region. */
116
+ readonly ariaLabel: _angular_core.InputSignal<string>;
117
+ /** Mode and size modifiers; kept as one binding so a size change cannot drop the mode. */
118
+ protected readonly _modifierClasses: _angular_core.Signal<string>;
119
+ /**
120
+ * The scrim only exists where the indicator actually covers something, so an
121
+ * inline block never paints a background it would have no reason to own.
122
+ */
123
+ protected readonly _showsBackdrop: _angular_core.Signal<boolean>;
124
+ /**
125
+ * Single accent slot consumed by the stylesheet. `null` leaves the binding off
126
+ * entirely, so the token's own cascade default stays in effect.
127
+ */
128
+ protected readonly _accent: _angular_core.Signal<string | null>;
129
+ /** Motion modifier for the branding image; `none` adds no class at all. */
130
+ protected readonly _imageClasses: _angular_core.Signal<string>;
131
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<HubLoadingComponent, never>;
132
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<HubLoadingComponent, "hub-loading", never, { "mode": { "alias": "mode"; "required": false; "isSignal": true; }; "variant": { "alias": "variant"; "required": false; "isSignal": true; }; "image": { "alias": "image"; "required": false; "isSignal": true; }; "imageAnimation": { "alias": "imageAnimation"; "required": false; "isSignal": true; }; "message": { "alias": "message"; "required": false; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; "color": { "alias": "color"; "required": false; "isSignal": true; }; "backdrop": { "alias": "backdrop"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "ariaLabel"; "required": false; "isSignal": true; }; }, {}, never, ["*"], true, never>;
133
+ }
134
+
135
+ /**
136
+ * Drives a single application-wide fullscreen loading overlay.
137
+ *
138
+ * Concurrency is handled with a reference counter rather than a boolean, because
139
+ * independent callers overlap constantly (two parallel requests, a resolver plus a
140
+ * component): the overlay appears on the first `show()` and only disappears once
141
+ * every caller has balanced it with a `hide()`. A caller that forgets to hide would
142
+ * strand the overlay, so {@link hideAll} exists as the explicit escape hatch — use it
143
+ * from an error handler or a route change, never as a substitute for balanced calls.
144
+ *
145
+ * Server-side there is no DOM to mount into, so only the counter runs: `isLoading`
146
+ * stays truthful and hydration finds no orphan overlay markup.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * private readonly loading = inject(HubLoadingService);
151
+ *
152
+ * async save(): Promise<void> {
153
+ * this.loading.show({ message: 'Saving…' });
154
+ * try {
155
+ * await this.api.save();
156
+ * } finally {
157
+ * this.loading.hide();
158
+ * }
159
+ * }
160
+ * ```
161
+ */
162
+ declare class HubLoadingService {
163
+ private readonly appRef;
164
+ private readonly document;
165
+ private readonly platformId;
166
+ private readonly config;
167
+ /** Number of callers currently requesting the overlay. */
168
+ private readonly pending;
169
+ /** Live reference to the mounted overlay; `null` whenever nothing is showing. */
170
+ private overlayRef;
171
+ /**
172
+ * Options accumulated by the active `show()` / `update()` calls, layered over
173
+ * `HUB_LOADING_CONFIG`. Reset once the counter reaches zero so a later overlay
174
+ * never inherits a stale message from a finished operation.
175
+ */
176
+ private options;
177
+ /** True while at least one caller is still waiting. Safe to read during SSR. */
178
+ readonly isLoading: Signal<boolean>;
179
+ /**
180
+ * Registers one caller and mounts the overlay if it is not up yet.
181
+ *
182
+ * @param options - Presentation overrides merged over the application defaults;
183
+ * only the keys supplied are changed, so nested calls compose instead of resetting.
184
+ */
185
+ show(options?: HubLoadingOptions): void;
186
+ /**
187
+ * Retires one caller, tearing the overlay down once none are left.
188
+ * Extra calls are harmless: the counter is clamped at zero rather than going
189
+ * negative, so a stray `hide()` cannot make a later `show()` a no-op.
190
+ */
191
+ hide(): void;
192
+ /** Drops every pending caller and removes the overlay immediately. */
193
+ hideAll(): void;
194
+ /**
195
+ * Re-dresses the overlay while it stays up — a progress message that changes
196
+ * mid-operation, a variant swap — without touching the reference counter.
197
+ *
198
+ * @param options - Presentation overrides merged over the active ones.
199
+ */
200
+ update(options: HubLoadingOptions): void;
201
+ /**
202
+ * Copies only the keys the caller actually supplied.
203
+ *
204
+ * A plain spread would let an `undefined` property erase a configured default,
205
+ * which would make `{ message: undefined }` and `{ message: null }` behave the
206
+ * same; here `undefined` means "leave it alone" and `null` means "clear it".
207
+ */
208
+ private mergeOptions;
209
+ /**
210
+ * Creates the overlay on `document.body` once, outside any component subtree, so
211
+ * it is never clipped by an ancestor's `overflow` or stacking context.
212
+ */
213
+ private mount;
214
+ /** Destroys the overlay and forgets the accumulated options. */
215
+ private unmount;
216
+ /**
217
+ * Pushes the resolved options onto the overlay.
218
+ *
219
+ * Change detection is run by hand: a view attached through `attachView()` sits
220
+ * outside the signal graph's "mark ancestors dirty" traversal, so it would not
221
+ * repaint on its own when an input changes.
222
+ */
223
+ private applyOptions;
224
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<HubLoadingService, never>;
225
+ static ɵprov: _angular_core.ɵɵInjectableDeclaration<HubLoadingService>;
226
+ }
227
+
228
+ /**
229
+ * Neutral defaults applied when an application provides no configuration.
230
+ *
231
+ * These are the values documented as each input's default, so overriding the
232
+ * token silently re-bases the whole application without touching a template.
233
+ */
234
+ declare const HUB_LOADING_DEFAULT_CONFIG: HubLoadingConfig;
235
+ /**
236
+ * Resolved defaults shared by `<hub-loading>` and `HubLoadingService`.
237
+ *
238
+ * Declared with a root factory so the token is always injectable, even when the
239
+ * application never calls {@link provideHubLoading}.
240
+ */
241
+ declare const HUB_LOADING_CONFIG: InjectionToken<HubLoadingConfig>;
242
+ /**
243
+ * Registers application-wide loading defaults — typically the brand image, the
244
+ * preferred variant and a translated label — so individual call sites stay bare.
245
+ *
246
+ * @param config - Values overriding {@link HUB_LOADING_DEFAULT_CONFIG}; omitted keys keep their default.
247
+ * @returns Environment providers for the application bootstrap.
248
+ */
249
+ declare function provideHubLoading(config?: Partial<HubLoadingConfig>): EnvironmentProviders;
250
+
251
+ export { HUB_LOADING_CONFIG, HUB_LOADING_DEFAULT_CONFIG, HubLoadingComponent, HubLoadingService, provideHubLoading };
252
+ export type { HubLoadingConfig, HubLoadingImageAnimation, HubLoadingMode, HubLoadingOptions, HubLoadingSize, HubLoadingVariant };