@cngx/common 0.1.0-rc.4 → 0.1.0-rc.5
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.
- package/audio/README.md +180 -0
- package/fesm2022/cngx-common-audio.mjs +1205 -0
- package/fesm2022/cngx-common-audio.mjs.map +1 -0
- package/fesm2022/cngx-common-chart.mjs +2 -2
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +307 -5
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +31 -6
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +1 -1
- package/package.json +5 -1
- package/types/cngx-common-audio.d.ts +736 -0
- package/types/cngx-common-data.d.ts +191 -3
- package/types/cngx-common-interactive.d.ts +14 -0
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import { InjectionToken, EnvironmentProviders, Signal, Provider, DestroyRef } from '@angular/core';
|
|
3
|
+
import { CngxAsyncState } from '@cngx/core/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Per-tone synthesis options.
|
|
7
|
+
* @category common/audio
|
|
8
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
interface ToneOptions {
|
|
12
|
+
/** Oscillator waveform. Default `'sine'`. */
|
|
13
|
+
readonly type?: OscillatorType;
|
|
14
|
+
/** Peak gain in `[0, 1]` before the master volume. Default `0.2`. */
|
|
15
|
+
readonly gain?: number;
|
|
16
|
+
/** Schedule offset in seconds from `currentTime`. Default `0`. */
|
|
17
|
+
readonly when?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One step of an earcon sequence.
|
|
21
|
+
* @category common/audio
|
|
22
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
*/
|
|
25
|
+
interface ToneStep {
|
|
26
|
+
/** Frequency in Hz. */
|
|
27
|
+
readonly freq: number;
|
|
28
|
+
/** Duration in milliseconds. */
|
|
29
|
+
readonly duration: number;
|
|
30
|
+
/** Oscillator waveform for this step. Default `'sine'`. */
|
|
31
|
+
readonly type?: OscillatorType;
|
|
32
|
+
/** Peak gain for this step in `[0, 1]`. Default `0.2`. */
|
|
33
|
+
readonly gain?: number;
|
|
34
|
+
/** Silent gap in milliseconds before this step starts. Default `0`. */
|
|
35
|
+
readonly delay?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Public handle returned by {@link createToneGenerator}.
|
|
39
|
+
* @category common/audio
|
|
40
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
41
|
+
* @since 0.1.0
|
|
42
|
+
*/
|
|
43
|
+
interface CngxToneGenerator {
|
|
44
|
+
/** Play a single tone of `durationMs` at `freq`. */
|
|
45
|
+
tone(freq: number, durationMs: number, opts?: ToneOptions): void;
|
|
46
|
+
/** Play a sequence of steps back-to-back, each scheduled after the previous. */
|
|
47
|
+
sequence(steps: readonly ToneStep[]): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Dependencies handed to the tone-generator factory by the engine.
|
|
51
|
+
* @category common/audio
|
|
52
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
*/
|
|
55
|
+
interface ToneGeneratorDeps {
|
|
56
|
+
/** Lazy getter for the shared context — called per tone so the engine controls resume. */
|
|
57
|
+
readonly context: () => BaseAudioContext;
|
|
58
|
+
/** Node to connect each tone into (typically the engine's master-volume gain). */
|
|
59
|
+
readonly destination: () => AudioNode;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Signature of the tone-generator factory — the shape an override must match.
|
|
63
|
+
* @category common/audio
|
|
64
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
*/
|
|
67
|
+
type CngxAudioToneGeneratorFactory = (deps: ToneGeneratorDeps) => CngxToneGenerator;
|
|
68
|
+
/**
|
|
69
|
+
* Pure `OscillatorNode` synthesis — no audio assets. Each tone is an
|
|
70
|
+
* oscillator through a per-note gain envelope (5 ms attack, 30 ms release)
|
|
71
|
+
* into the engine's master-volume node. The envelope is not decoration: a
|
|
72
|
+
* bare `start()`/`stop()` on a full-amplitude oscillator produces an audible
|
|
73
|
+
* click at both ends; ramping in and out removes it.
|
|
74
|
+
*
|
|
75
|
+
* `create*` pure factory (no `inject()`), so it composes inside the engine and
|
|
76
|
+
* runs against the shared `createAudioContextMock` in specs.
|
|
77
|
+
* @category common/audio
|
|
78
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
79
|
+
* @since 0.1.0
|
|
80
|
+
*/
|
|
81
|
+
declare const createToneGenerator: CngxAudioToneGeneratorFactory;
|
|
82
|
+
/**
|
|
83
|
+
* Swappable tone-generator factory. Defaults to {@link createToneGenerator}
|
|
84
|
+
* (oscillator synthesis). Override to swap in sample-based playback without
|
|
85
|
+
* forking the engine — the documented second consumer of this boundary token.
|
|
86
|
+
*
|
|
87
|
+
* @relatedTo createToneGenerator, CNGX_AUDIO_ENGINE_FACTORY
|
|
88
|
+
* @category common/audio
|
|
89
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
90
|
+
* @since 0.1.0
|
|
91
|
+
*/
|
|
92
|
+
declare const CNGX_AUDIO_TONE_GENERATOR_FACTORY: InjectionToken<CngxAudioToneGeneratorFactory>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A named earcon — an ordered sequence of tone steps.
|
|
96
|
+
* @category common/audio
|
|
97
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/earcons/default-earcons.ts
|
|
98
|
+
* @since 0.1.0
|
|
99
|
+
*/
|
|
100
|
+
interface EarconConfig {
|
|
101
|
+
/** The tones that make up the earcon, played back-to-back. */
|
|
102
|
+
readonly sequence: readonly ToneStep[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Global configuration for the audio system. Provided via `provideCngxAudio()`
|
|
107
|
+
* with `with*` features (see the provider section below). Consumers never
|
|
108
|
+
* construct this object directly.
|
|
109
|
+
*
|
|
110
|
+
* @category common/audio
|
|
111
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
112
|
+
* @since 0.1.0
|
|
113
|
+
*/
|
|
114
|
+
interface CngxAudioConfig {
|
|
115
|
+
/** Start muted. Default `false`. */
|
|
116
|
+
readonly muted: boolean;
|
|
117
|
+
/** Master volume in `[0, 1]`. Default `1`. */
|
|
118
|
+
readonly volume: number;
|
|
119
|
+
/** Mute audio when `prefers-reduced-motion: reduce` is set. Default `true`. */
|
|
120
|
+
readonly respectReducedMotion: boolean;
|
|
121
|
+
/** Same-name suppression window in ms. Default `100`. */
|
|
122
|
+
readonly debounceMs: number;
|
|
123
|
+
/** Extra or overriding earcons, merged over the six built-ins. Default `{}`. */
|
|
124
|
+
readonly earcons: Readonly<Record<string, EarconConfig>>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Library defaults — English, browser-native.
|
|
128
|
+
* @category common/audio
|
|
129
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
130
|
+
* @since 0.1.0
|
|
131
|
+
*/
|
|
132
|
+
declare const CNGX_AUDIO_DEFAULTS: CngxAudioConfig;
|
|
133
|
+
/**
|
|
134
|
+
* Injection token carrying the partial audio config contributed by
|
|
135
|
+
* `provideCngxAudio(...)`. Read the resolved, defaults-merged config with
|
|
136
|
+
* {@link injectAudioConfig}.
|
|
137
|
+
*
|
|
138
|
+
* @category common/audio
|
|
139
|
+
* @relatedTo provideCngxAudio, injectAudioConfig
|
|
140
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
141
|
+
* @since 0.1.0
|
|
142
|
+
*/
|
|
143
|
+
declare const CNGX_AUDIO_CONFIG: InjectionToken<Partial<CngxAudioConfig>>;
|
|
144
|
+
/**
|
|
145
|
+
* Resolve the effective audio config: library defaults merged with whatever
|
|
146
|
+
* `provideCngxAudio(...)` contributed. Runs in an injection context.
|
|
147
|
+
*
|
|
148
|
+
* @category common/audio
|
|
149
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
150
|
+
* @since 0.1.0
|
|
151
|
+
*/
|
|
152
|
+
declare function injectAudioConfig(): CngxAudioConfig;
|
|
153
|
+
/**
|
|
154
|
+
* A feature returned by a `with*` helper, folded into the config by {@link provideCngxAudio}.
|
|
155
|
+
* @category common/audio
|
|
156
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
157
|
+
* @since 0.1.0
|
|
158
|
+
*/
|
|
159
|
+
interface CngxAudioFeature {
|
|
160
|
+
/** @internal */
|
|
161
|
+
readonly _apply: (config: Partial<CngxAudioConfig>) => Partial<CngxAudioConfig>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Register global audio defaults. Mirrors `provideFeedback` — a single small
|
|
165
|
+
* config object folded through `with*` features.
|
|
166
|
+
*
|
|
167
|
+
* ```ts
|
|
168
|
+
* bootstrapApplication(AppComponent, {
|
|
169
|
+
* providers: [
|
|
170
|
+
* provideCngxAudio(
|
|
171
|
+
* withVolume(0.6),
|
|
172
|
+
* withEarcons({ send: { sequence: [{ freq: 880, duration: 60 }] } }),
|
|
173
|
+
* ),
|
|
174
|
+
* ],
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* Register this at **application bootstrap**. The shared engine is
|
|
179
|
+
* `providedIn: 'root'` and reads its configuration once, when it is first built,
|
|
180
|
+
* so config registered in a lazy route's `providers` never reaches it. To
|
|
181
|
+
* configure a subtree, use `provideCngxAudioAt(...)` in `viewProviders` — it
|
|
182
|
+
* layers over this one and re-provides the engine so the scope actually applies.
|
|
183
|
+
*
|
|
184
|
+
* @category common/audio
|
|
185
|
+
* @relatedTo provideCngxAudioAt, injectAudioConfig
|
|
186
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
187
|
+
* @since 0.1.0
|
|
188
|
+
*/
|
|
189
|
+
declare function provideCngxAudio(...features: CngxAudioFeature[]): EnvironmentProviders;
|
|
190
|
+
/**
|
|
191
|
+
* Register or override earcons globally. Merged over the six built-ins and over
|
|
192
|
+
* any earlier `withEarcons` in the same `provideCngxAudio` call.
|
|
193
|
+
*
|
|
194
|
+
* @category common/audio
|
|
195
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
196
|
+
* @since 0.1.0
|
|
197
|
+
*/
|
|
198
|
+
declare function withEarcons(earcons: Record<string, EarconConfig>): CngxAudioFeature;
|
|
199
|
+
/**
|
|
200
|
+
* Set the master volume in `[0, 1]`.
|
|
201
|
+
*
|
|
202
|
+
* @category common/audio
|
|
203
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
204
|
+
* @since 0.1.0
|
|
205
|
+
*/
|
|
206
|
+
declare function withVolume(volume: number): CngxAudioFeature;
|
|
207
|
+
/**
|
|
208
|
+
* Start muted (or explicitly unmuted with `withMuted(false)`).
|
|
209
|
+
*
|
|
210
|
+
* @category common/audio
|
|
211
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
212
|
+
* @since 0.1.0
|
|
213
|
+
*/
|
|
214
|
+
declare function withMuted(muted?: boolean): CngxAudioFeature;
|
|
215
|
+
/**
|
|
216
|
+
* Toggle the `prefers-reduced-motion` mute gate. `true` by default in the
|
|
217
|
+
* library; pass `false` to keep audio playing under reduced-motion.
|
|
218
|
+
*
|
|
219
|
+
* @category common/audio
|
|
220
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
221
|
+
* @since 0.1.0
|
|
222
|
+
*/
|
|
223
|
+
declare function withRespectReducedMotion(respect: boolean): CngxAudioFeature;
|
|
224
|
+
/**
|
|
225
|
+
* Set the same-name suppression window in milliseconds.
|
|
226
|
+
*
|
|
227
|
+
* @category common/audio
|
|
228
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
229
|
+
* @since 0.1.0
|
|
230
|
+
*/
|
|
231
|
+
declare function withDebounceMs(ms: number): CngxAudioFeature;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Lifecycle state of the shared `AudioContext`, surfaced for debug panels and
|
|
235
|
+
* headless e2e. Mute is a separate `muted` signal — this tracks the context,
|
|
236
|
+
* not the play gate.
|
|
237
|
+
* @category common/audio
|
|
238
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
239
|
+
* @since 0.1.0
|
|
240
|
+
*/
|
|
241
|
+
type AudioStatus = 'idle' | 'suspended' | 'running' | 'closed' | 'unsupported';
|
|
242
|
+
/**
|
|
243
|
+
* Advanced/testing seam for {@link createAudioEngine}.
|
|
244
|
+
* @category common/audio
|
|
245
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
246
|
+
* @since 0.1.0
|
|
247
|
+
*/
|
|
248
|
+
interface AudioEngineOptions {
|
|
249
|
+
/**
|
|
250
|
+
* Override `AudioContext` construction. Defaults to the host window's
|
|
251
|
+
* `AudioContext` / `webkitAudioContext`, or `null` when neither exists (SSR,
|
|
252
|
+
* unsupported browser). Specs pass `createAudioContextMock`.
|
|
253
|
+
*/
|
|
254
|
+
readonly contextFactory?: () => BaseAudioContext | null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The audio engine surface. A single write path for `muted` / `volume`
|
|
258
|
+
* (no `mute()`/`unmute()` pair); every state change is a reactive `Signal`.
|
|
259
|
+
* @category common/audio
|
|
260
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
261
|
+
* @since 0.1.0
|
|
262
|
+
*/
|
|
263
|
+
interface CngxAudioEngine {
|
|
264
|
+
/**
|
|
265
|
+
* Play a registered earcon by name. Gated + debounced centrally here.
|
|
266
|
+
* `scale` (a `[0, 1]` multiplier over the per-tone default) scales just this
|
|
267
|
+
* play — used by the directives' per-element `audioVolume` without touching
|
|
268
|
+
* the shared master volume.
|
|
269
|
+
*/
|
|
270
|
+
play(name: string, scale?: number): void;
|
|
271
|
+
/**
|
|
272
|
+
* Play a single ad-hoc tone. Gated, not debounced, no `lastPlayed` update.
|
|
273
|
+
* `scale` is the same `[0, 1]` multiplier `play()` takes and is applied over
|
|
274
|
+
* `opts.gain` (or the per-tone default) by the engine.
|
|
275
|
+
*/
|
|
276
|
+
tone(freq: number, durationMs: number, opts?: ToneOptions, scale?: number): void;
|
|
277
|
+
/** Play an ad-hoc tone sequence. Gated, not debounced. `scale` as in {@link tone}. */
|
|
278
|
+
sequence(steps: readonly ToneStep[], scale?: number): void;
|
|
279
|
+
/** Register or override an earcon at runtime. */
|
|
280
|
+
register(name: string, config: EarconConfig): void;
|
|
281
|
+
/** Arm the autoplay gate programmatically and resume the context if possible. */
|
|
282
|
+
armAutoplay(): void;
|
|
283
|
+
/** Set the global mute state. */
|
|
284
|
+
setMuted(muted: boolean): void;
|
|
285
|
+
/** Set master volume, clamped to `[0, 1]`. */
|
|
286
|
+
setVolume(volume: number): void;
|
|
287
|
+
/** `true` when globally muted. */
|
|
288
|
+
readonly muted: Signal<boolean>;
|
|
289
|
+
/** Master volume in `[0, 1]`. */
|
|
290
|
+
readonly volume: Signal<number>;
|
|
291
|
+
/** Shared-context lifecycle state. */
|
|
292
|
+
readonly status: Signal<AudioStatus>;
|
|
293
|
+
/** Name of the last earcon actually played, or `null`. Powers e2e + debug. */
|
|
294
|
+
readonly lastPlayed: Signal<string | null>;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Signature of the engine factory — the shape a telemetry/audit override matches.
|
|
298
|
+
* @category common/audio
|
|
299
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
300
|
+
* @since 0.1.0
|
|
301
|
+
*/
|
|
302
|
+
type CngxAudioEngineFactory = (options?: AudioEngineOptions) => CngxAudioEngine;
|
|
303
|
+
/**
|
|
304
|
+
* Create the audio engine: composes the autoplay gate, tone generator, and
|
|
305
|
+
* debouncer over one lazily-created shared `AudioContext`. Reduced-motion muting
|
|
306
|
+
* reuses the existing `injectMediaQuery('(prefers-reduced-motion: reduce)')`
|
|
307
|
+
* primitive rather than adding another `matchMedia` reader.
|
|
308
|
+
*
|
|
309
|
+
* The four mute conditions are enforced centrally in `play()`/`tone()`/
|
|
310
|
+
* `sequence()`: global mute, reduced-motion, and autoplay-not-armed here;
|
|
311
|
+
* per-element `[audioDisabled]` in the directives.
|
|
312
|
+
*
|
|
313
|
+
* Runs in an injection context (calls `inject()` for DOCUMENT, DestroyRef, the
|
|
314
|
+
* tone-generator factory, and the reduced-motion query). The engine instance is
|
|
315
|
+
* resolved through {@link CNGX_AUDIO_ENGINE_FACTORY}; scope it to a subtree with
|
|
316
|
+
* `provideCngxAudioAt(...)` rather than calling this directly.
|
|
317
|
+
* @category common/audio
|
|
318
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
319
|
+
* @since 0.1.0
|
|
320
|
+
*/
|
|
321
|
+
declare const createAudioEngine: CngxAudioEngineFactory;
|
|
322
|
+
/**
|
|
323
|
+
* Swappable engine factory. Defaults to {@link createAudioEngine}. Override to
|
|
324
|
+
* wrap the engine with telemetry/audit logging — the documented second consumer
|
|
325
|
+
* of this boundary token.
|
|
326
|
+
*
|
|
327
|
+
* Register the override at **application bootstrap**. The shared engine instance
|
|
328
|
+
* is itself `providedIn: 'root'` and is built on first use, so a factory override
|
|
329
|
+
* registered in a lazy route's `providers` is never consulted. For a subtree that
|
|
330
|
+
* needs its own engine, use `provideCngxAudioAt(...)` in `viewProviders`.
|
|
331
|
+
*
|
|
332
|
+
* An override that needs the resolved configuration reads it with
|
|
333
|
+
* {@link injectAudioConfig} (defaults merged); {@link CNGX_AUDIO_DEFAULTS} holds
|
|
334
|
+
* the library baseline. Both are exported from `@cngx/common/audio`.
|
|
335
|
+
*
|
|
336
|
+
* @relatedTo createAudioEngine, injectCngxAudio, injectAudioConfig
|
|
337
|
+
* @category common/audio
|
|
338
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
339
|
+
* @since 0.1.0
|
|
340
|
+
*/
|
|
341
|
+
declare const CNGX_AUDIO_ENGINE_FACTORY: InjectionToken<CngxAudioEngineFactory>;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The public audio handle — what {@link injectCngxAudio} returns.
|
|
345
|
+
*
|
|
346
|
+
* An alias for {@link CngxAudioEngine} rather than a second interface: the two
|
|
347
|
+
* contracts were member-for-member identical, so a separate declaration was
|
|
348
|
+
* duplication, not indirection. The name is kept because it reads better at
|
|
349
|
+
* call sites (`const audio: CngxAudioHandle = injectCngxAudio()`), and because
|
|
350
|
+
* the engine contract is the one an override implements.
|
|
351
|
+
*
|
|
352
|
+
* @category common/audio
|
|
353
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/inject-audio.ts
|
|
354
|
+
* @since 0.1.0
|
|
355
|
+
*/
|
|
356
|
+
type CngxAudioHandle = CngxAudioEngine;
|
|
357
|
+
/**
|
|
358
|
+
* Resolve the shared audio handle. Must run in an injection context (field
|
|
359
|
+
* initialiser or constructor).
|
|
360
|
+
*
|
|
361
|
+
* ```typescript
|
|
362
|
+
* export class MyToggle {
|
|
363
|
+
* private readonly audio = injectCngxAudio();
|
|
364
|
+
* protected readonly muted = this.audio.muted;
|
|
365
|
+
* protected toggle(): void {
|
|
366
|
+
* this.audio.setMuted(!this.muted());
|
|
367
|
+
* }
|
|
368
|
+
* }
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @category common/audio
|
|
372
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/inject-audio.ts
|
|
373
|
+
* @since 0.1.0
|
|
374
|
+
*/
|
|
375
|
+
declare function injectCngxAudio(): CngxAudioHandle;
|
|
376
|
+
/**
|
|
377
|
+
* Component-scope audio config — place in a component's `viewProviders` so a
|
|
378
|
+
* subtree runs its own muted / volume / earcon set, independent of the app-wide
|
|
379
|
+
* `provideCngxAudio(...)`.
|
|
380
|
+
*
|
|
381
|
+
* ```typescript
|
|
382
|
+
* @Component({
|
|
383
|
+
* selector: 'app-mixer',
|
|
384
|
+
* viewProviders: [provideCngxAudioAt(withVolume(0.3), withEarcons({ ... }))],
|
|
385
|
+
* })
|
|
386
|
+
* export class Mixer {}
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* Returns `Provider[]` (not `EnvironmentProviders`) so it can sit in
|
|
390
|
+
* `viewProviders`. The root `provideCngxAudio` must be registered at
|
|
391
|
+
* **application bootstrap**: {@link CNGX_AUDIO_ENGINE} is `providedIn: 'root'`,
|
|
392
|
+
* so its factory resolves the config from the root injector and a provider
|
|
393
|
+
* registered on a lazy route never reaches it.
|
|
394
|
+
*
|
|
395
|
+
* Features **layer over** the ancestor config (root, or an enclosing scope)
|
|
396
|
+
* rather than replacing it — the `provideMenuConfigAt` pattern. Scalar fields
|
|
397
|
+
* (`muted`, `volume`, `debounceMs`, `respectReducedMotion`) override; `earcons`
|
|
398
|
+
* merge, so a subtree adds or overrides individual earcons without dropping the
|
|
399
|
+
* app-wide registry.
|
|
400
|
+
*
|
|
401
|
+
* The default shared engine is a single, process-global `AudioContext`; this
|
|
402
|
+
* deliberately re-provides {@link CNGX_AUDIO_ENGINE} so the subtree gets an
|
|
403
|
+
* **isolated engine** reading the scoped {@link CNGX_AUDIO_CONFIG} — a
|
|
404
|
+
* config-only override would be inert against the already-built root engine.
|
|
405
|
+
* That engine owns a **second `AudioContext`**, created lazily on its first play
|
|
406
|
+
* and closed with the component's `DestroyRef`. Browsers cap the number of live
|
|
407
|
+
* `AudioContext`s, so reach for this only when a subtree genuinely needs an
|
|
408
|
+
* independent audio scope — per-element `[audioVolume]` / `[audioDisabled]`
|
|
409
|
+
* cover the common case without a second context.
|
|
410
|
+
*
|
|
411
|
+
* @category common/audio
|
|
412
|
+
* @relatedTo provideCngxAudio, injectCngxAudio
|
|
413
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/inject-audio.ts
|
|
414
|
+
* @since 0.1.0
|
|
415
|
+
*/
|
|
416
|
+
declare function provideCngxAudioAt(...features: CngxAudioFeature[]): Provider[];
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* A minimal `EventTarget` surface — only what the gate installs. Accepting
|
|
420
|
+
* this narrow shape (rather than a concrete `Document`) keeps the factory
|
|
421
|
+
* inject-free and trivially fakeable in a spec.
|
|
422
|
+
* @category common/audio
|
|
423
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/autoplay-gate/autoplay-gate.ts
|
|
424
|
+
* @since 0.1.0
|
|
425
|
+
*/
|
|
426
|
+
type GestureEventTarget = Pick<EventTarget, 'addEventListener' | 'removeEventListener'>;
|
|
427
|
+
/**
|
|
428
|
+
* Public handle returned by {@link createAutoplayGate}.
|
|
429
|
+
* @category common/audio
|
|
430
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/autoplay-gate/autoplay-gate.ts
|
|
431
|
+
* @since 0.1.0
|
|
432
|
+
*/
|
|
433
|
+
interface CngxAutoplayGate {
|
|
434
|
+
/**
|
|
435
|
+
* `true` once a user gesture (or an explicit {@link arm}) has satisfied the
|
|
436
|
+
* browser autoplay policy. Derived from a single gesture event — never
|
|
437
|
+
* synced from multiple handlers.
|
|
438
|
+
*/
|
|
439
|
+
readonly armed: Signal<boolean>;
|
|
440
|
+
/** Arm the gate programmatically (e.g. after an existing trusted gesture). */
|
|
441
|
+
arm(): void;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Create the autoplay gate: a one-shot latch that flips `armed` to `true` on
|
|
445
|
+
* the first `pointerdown` / `keydown` / `touchstart` and then removes its own
|
|
446
|
+
* listeners. The engine consults `armed()` before resuming the shared
|
|
447
|
+
* `AudioContext`, honouring the browser autoplay policy without a permission
|
|
448
|
+
* prompt.
|
|
449
|
+
*
|
|
450
|
+
* Pure factory — takes its `target` and `destroyRef` as arguments rather than
|
|
451
|
+
* calling `inject()`, so it composes inside the engine's injection context yet
|
|
452
|
+
* stays testable with a fake target. No DI token: the gate has no independent
|
|
453
|
+
* swap consumer (severity ladder `concern: over-abstraction`), so it ships
|
|
454
|
+
* token-less and the engine owns it.
|
|
455
|
+
*
|
|
456
|
+
* @param deps.target The event target to listen on (typically the `Document`).
|
|
457
|
+
* @param deps.destroyRef Cleanup owner — removes any surviving listeners on destroy.
|
|
458
|
+
* @category common/audio
|
|
459
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/autoplay-gate/autoplay-gate.ts
|
|
460
|
+
* @since 0.1.0
|
|
461
|
+
*/
|
|
462
|
+
declare function createAutoplayGate(deps: {
|
|
463
|
+
readonly target: GestureEventTarget;
|
|
464
|
+
readonly destroyRef: Pick<DestroyRef, 'onDestroy'>;
|
|
465
|
+
}): CngxAutoplayGate;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Public handle returned by {@link createDebouncer}.
|
|
469
|
+
* @category common/audio
|
|
470
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/debouncer/debouncer.ts
|
|
471
|
+
* @since 0.1.0
|
|
472
|
+
*/
|
|
473
|
+
interface CngxDebouncer {
|
|
474
|
+
/**
|
|
475
|
+
* Returns `true` if `name` may fire now, `false` if an identical name fired
|
|
476
|
+
* within the window. A `true` result records the fire time; a `false` result
|
|
477
|
+
* leaves it untouched (so a burst is suppressed against its first fire).
|
|
478
|
+
*/
|
|
479
|
+
shouldFire(name: string): boolean;
|
|
480
|
+
/** Clear the recorded fire time for `name`, or all names when omitted. */
|
|
481
|
+
reset(name?: string): void;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Per-name time-window debouncer: suppresses repeated fires of the same earcon
|
|
485
|
+
* within `windowMs`. A separate composed factory rather than logic buried in
|
|
486
|
+
* the engine (Pillar 3). Plain factory, no DI token — `withDebounceMs` covers
|
|
487
|
+
* configuration and there is no independent swap consumer.
|
|
488
|
+
*
|
|
489
|
+
* `windowMs` accepts a getter so a caller whose window is a reactive input can
|
|
490
|
+
* hold ONE debouncer instance for its lifetime and still track changes: the
|
|
491
|
+
* window is resolved per `shouldFire` call, not captured at construction. That
|
|
492
|
+
* keeps the (stateful) debouncer out of the signal graph — minting one inside a
|
|
493
|
+
* `computed` would return a fresh object per evaluation and break the equality
|
|
494
|
+
* rule. `CngxAudioPitch` is the getter consumer; the engine passes a number.
|
|
495
|
+
*
|
|
496
|
+
* The clock is injectable (`now`) purely so specs are deterministic; production
|
|
497
|
+
* defaults to `Date.now`.
|
|
498
|
+
*
|
|
499
|
+
* @param options.windowMs Suppression window, or a getter for it. `<= 0` disables debouncing. Default `100`.
|
|
500
|
+
* @param options.now Clock source in ms. Default `Date.now`.
|
|
501
|
+
* @category common/audio
|
|
502
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/debouncer/debouncer.ts
|
|
503
|
+
* @since 0.1.0
|
|
504
|
+
*/
|
|
505
|
+
declare function createDebouncer(options?: {
|
|
506
|
+
readonly windowMs?: number | (() => number);
|
|
507
|
+
readonly now?: () => number;
|
|
508
|
+
}): CngxDebouncer;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Event-mode audio binder. Maps DOM events on the host to earcons via the
|
|
512
|
+
* `event:earcon` grammar — a pure DOM-event-to-sound directive with no state
|
|
513
|
+
* coupling (that is `[cngxAudioStatus]`'s job).
|
|
514
|
+
*
|
|
515
|
+
* ```html
|
|
516
|
+
* <button [cngxAudio]="'click:tap'">Save</button>
|
|
517
|
+
* <a [cngxAudio]="'pointerenter:notification, click:complete'">Open</a>
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* Playback is skipped when the element is disabled (`[audioDisabled]`), when
|
|
521
|
+
* the engine is muted / reduced-motion-gated / autoplay-not-armed, or when the
|
|
522
|
+
* same earcon is still within the debounce window. `[audioVolume]` scales just
|
|
523
|
+
* this element's plays.
|
|
524
|
+
*
|
|
525
|
+
* The listener set is derived from the grammar, not fixed: `'click:tap'`
|
|
526
|
+
* registers one DOM listener, and rebinding `[cngxAudio]` at runtime adds the
|
|
527
|
+
* newly named events and removes the dropped ones. Binding happens on the first
|
|
528
|
+
* change detection after the input settles rather than at construction, so an
|
|
529
|
+
* event dispatched programmatically before the host's first tick is missed.
|
|
530
|
+
*
|
|
531
|
+
* Listeners are registered outside Angular's event dispatch. In a zoneless app
|
|
532
|
+
* that means they schedule no change detection; under zone.js the patched
|
|
533
|
+
* `addEventListener` still triggers a tick, so there the saving is registration
|
|
534
|
+
* cost alone. Either way the engine's `lastPlayed` and `status` are signals, so
|
|
535
|
+
* anything a template binds to them stays current.
|
|
536
|
+
*
|
|
537
|
+
* @category common/audio
|
|
538
|
+
* @docsKind primary
|
|
539
|
+
* @wcag AA
|
|
540
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/event-mode/audio.directive.ts
|
|
541
|
+
* @since 0.1.0
|
|
542
|
+
* @relatedTo injectCngxAudio, provideCngxAudio, CngxAudioStatus
|
|
543
|
+
* <example-url>http://localhost:4200/#/common/audio/event-mode/basic</example-url>
|
|
544
|
+
* <example-url>http://localhost:4200/#/common/audio/event-mode/custom-earcons</example-url>
|
|
545
|
+
* <example-url>http://localhost:4200/#/common/audio/event-mode/earcon-palette</example-url>
|
|
546
|
+
* <example-url>http://localhost:4200/#/common/audio/event-mode/form-feedback</example-url>
|
|
547
|
+
* <example-url>http://localhost:4200/#/common/audio/event-mode/hover-and-focus</example-url>
|
|
548
|
+
*/
|
|
549
|
+
declare class CngxAudio {
|
|
550
|
+
private readonly audio;
|
|
551
|
+
private readonly host;
|
|
552
|
+
private readonly destroyRef;
|
|
553
|
+
/** The listeners currently registered on the host, keyed by event type. */
|
|
554
|
+
private readonly bound;
|
|
555
|
+
/** The `event:earcon` grammar, e.g. `'click:tap, focus:notification'`. */
|
|
556
|
+
readonly spec: _angular_core.InputSignal<string>;
|
|
557
|
+
/** Per-element volume multiplier in `[0, 1]`; unset uses the engine volume. */
|
|
558
|
+
readonly audioVolume: _angular_core.InputSignal<number | undefined>;
|
|
559
|
+
/** Suppress this element's audio without unbinding. */
|
|
560
|
+
readonly audioDisabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
|
|
561
|
+
private readonly bindings;
|
|
562
|
+
constructor();
|
|
563
|
+
/**
|
|
564
|
+
* Diff the bound listener set against the parsed spec: drop event types the
|
|
565
|
+
* grammar no longer names, add the ones it newly names, leave the rest alone.
|
|
566
|
+
* A rebuild would churn a listener that is still wanted.
|
|
567
|
+
*/
|
|
568
|
+
private syncListeners;
|
|
569
|
+
private unbindAll;
|
|
570
|
+
private handleEvent;
|
|
571
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<CngxAudio, never>;
|
|
572
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<CngxAudio, "[cngxAudio]", ["cngxAudio"], { "spec": { "alias": "cngxAudio"; "required": false; "isSignal": true; }; "audioVolume": { "alias": "audioVolume"; "required": false; "isSignal": true; }; "audioDisabled": { "alias": "audioDisabled"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Status-mode audio bridge. Maps `CngxAsyncState` lifecycle transitions to
|
|
577
|
+
* earcons via the `status:earcon` grammar — the audition counterpart of
|
|
578
|
+
* `CngxToastOn`. Fires only on a real status transition, never on the initial
|
|
579
|
+
* `idle`, and at most once per transition.
|
|
580
|
+
*
|
|
581
|
+
* ```html
|
|
582
|
+
* <button [cngxAsyncClick]="upload"
|
|
583
|
+
* #upload="cngxAsyncClick"
|
|
584
|
+
* [state]="upload.state"
|
|
585
|
+
* [cngxAudioStatus]="'pending:tap, succeeded:success, failed:error'">
|
|
586
|
+
* Upload
|
|
587
|
+
* </button>
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* The state source resolves the same way the feedback bridges do: an explicit
|
|
591
|
+
* `[state]` input wins, otherwise it falls back to an ancestor's
|
|
592
|
+
* `CNGX_STATEFUL`. The grammar keys are lifecycle statuses only — DOM-event
|
|
593
|
+
* keys (`click`, `focus`, …) belong to `[cngxAudio]` and are rejected with a
|
|
594
|
+
* dev-error. `succeeded`/`failed` are accepted as aliases for `success`/`error`.
|
|
595
|
+
*
|
|
596
|
+
* @category common/audio
|
|
597
|
+
* @docsKind primary
|
|
598
|
+
* @wcag AA
|
|
599
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/status-mode/audio-status.directive.ts
|
|
600
|
+
* @since 0.1.0
|
|
601
|
+
* @relatedTo CngxAudio, injectCngxAudio, CngxAsyncClick
|
|
602
|
+
* <example-url>http://localhost:4200/#/common/audio/status-bridge/async-click</example-url>
|
|
603
|
+
*/
|
|
604
|
+
declare class CngxAudioStatus {
|
|
605
|
+
private readonly audio;
|
|
606
|
+
private readonly statefulFallback;
|
|
607
|
+
/** The `status:earcon` grammar, e.g. `'pending:tap, succeeded:success'`. */
|
|
608
|
+
readonly spec: _angular_core.InputSignal<string>;
|
|
609
|
+
/**
|
|
610
|
+
* The async state to watch. Optional — when omitted, the bridge falls back to
|
|
611
|
+
* an ancestor `CNGX_STATEFUL`. A bare `[state]` attribute (empty string) is
|
|
612
|
+
* treated as "no input bound" so the fallback kicks in.
|
|
613
|
+
*/
|
|
614
|
+
readonly state: _angular_core.InputSignalWithTransform<CngxAsyncState<unknown> | undefined, "" | CngxAsyncState<unknown> | undefined>;
|
|
615
|
+
/** Per-element volume multiplier in `[0, 1]`; unset uses the engine volume. */
|
|
616
|
+
readonly audioVolume: _angular_core.InputSignal<number | undefined>;
|
|
617
|
+
/** Suppress this element's audio without unbinding. */
|
|
618
|
+
readonly audioDisabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
|
|
619
|
+
/** Effective state — explicit input wins over ancestor `CNGX_STATEFUL`. */
|
|
620
|
+
private readonly effectiveState;
|
|
621
|
+
private readonly bindings;
|
|
622
|
+
constructor();
|
|
623
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<CngxAudioStatus, never>;
|
|
624
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<CngxAudioStatus, "[cngxAudioStatus]", ["cngxAudioStatus"], { "spec": { "alias": "cngxAudioStatus"; "required": false; "isSignal": true; }; "state": { "alias": "state"; "required": false; "isSignal": true; }; "audioVolume": { "alias": "audioVolume"; "required": false; "isSignal": true; }; "audioDisabled": { "alias": "audioDisabled"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/** Earcon names played as the pointer or focus enters and leaves a zone. */
|
|
628
|
+
interface CngxAudioZoneBinding {
|
|
629
|
+
/** Played on `pointerenter`. */
|
|
630
|
+
readonly enter?: string | null;
|
|
631
|
+
/** Played on `pointerleave`. */
|
|
632
|
+
readonly leave?: string | null;
|
|
633
|
+
/** Played on `focusin`. */
|
|
634
|
+
readonly focus?: string | null;
|
|
635
|
+
/** Played on `focusout`. */
|
|
636
|
+
readonly blur?: string | null;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Zone-mode audio binder. Plays earcons as the pointer or keyboard focus enters
|
|
640
|
+
* and leaves the host — a spatial complement to `[cngxAudio]`. The record input
|
|
641
|
+
* makes the four zone transitions explicit rather than encoding them in the
|
|
642
|
+
* `event:earcon` string grammar, because the listener set (pointer/focus zone)
|
|
643
|
+
* and the shape (record vs string) are semantically distinct from event-mode.
|
|
644
|
+
*
|
|
645
|
+
* ```html
|
|
646
|
+
* <div [cngxAudioZone]="{ enter: 'notification', leave: 'tap' }">Hover me</div>
|
|
647
|
+
* <button [cngxAudioZone]="{ focus: 'tap', blur: 'tap' }">Focus me</button>
|
|
648
|
+
* ```
|
|
649
|
+
*
|
|
650
|
+
* Playback obeys the same gates as the rest of the family: skipped when
|
|
651
|
+
* `[audioDisabled]`, muted, reduced-motion-gated, autoplay-not-armed, or still
|
|
652
|
+
* within the debounce window. `[audioVolume]` scales just this element's plays.
|
|
653
|
+
*
|
|
654
|
+
* @category common/audio
|
|
655
|
+
* @docsKind primary
|
|
656
|
+
* @wcag AA
|
|
657
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/zone-mode/audio-zone.directive.ts
|
|
658
|
+
* @since 0.1.0
|
|
659
|
+
* @relatedTo CngxAudio, injectCngxAudio
|
|
660
|
+
* <example-url>http://localhost:4200/#/common/audio/zone/enter-leave</example-url>
|
|
661
|
+
*/
|
|
662
|
+
declare class CngxAudioZone {
|
|
663
|
+
private readonly audio;
|
|
664
|
+
private readonly host;
|
|
665
|
+
/** Earcon per zone transition. Any omitted key plays nothing. */
|
|
666
|
+
readonly zone: _angular_core.InputSignal<CngxAudioZoneBinding>;
|
|
667
|
+
/** Per-element volume multiplier in `[0, 1]`; unset uses the engine volume. */
|
|
668
|
+
readonly audioVolume: _angular_core.InputSignal<number | undefined>;
|
|
669
|
+
/** Suppress this element's audio without unbinding. */
|
|
670
|
+
readonly audioDisabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
|
|
671
|
+
/**
|
|
672
|
+
* `focusin`/`focusout` bubble, so a zone wrapping focusable children would
|
|
673
|
+
* otherwise fire on every internal tab move. Only a crossing of the zone
|
|
674
|
+
* boundary counts — the focus counterpart of pointerenter/pointerleave.
|
|
675
|
+
*/
|
|
676
|
+
protected handleFocusCross(kind: 'focus' | 'blur', event: FocusEvent): void;
|
|
677
|
+
protected handleZone(kind: keyof CngxAudioZoneBinding): void;
|
|
678
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<CngxAudioZone, never>;
|
|
679
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<CngxAudioZone, "[cngxAudioZone]", ["cngxAudioZone"], { "zone": { "alias": "cngxAudioZone"; "required": false; "isSignal": true; }; "audioVolume": { "alias": "audioVolume"; "required": false; "isSignal": true; }; "audioDisabled": { "alias": "audioDisabled"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Pitch-mode audio binder. Sonifies a continuous numeric value: each change of
|
|
684
|
+
* `[cngxAudioPitch]` clamps against a fixed domain, linear-scales into an output
|
|
685
|
+
* frequency range, and plays a short tone. Useful for sliders, gauges, and live
|
|
686
|
+
* metrics — the ear tracks a value without looking.
|
|
687
|
+
*
|
|
688
|
+
* ```html
|
|
689
|
+
* <input type="range" min="0" max="100"
|
|
690
|
+
* [cngxAudioPitch]="volume()"
|
|
691
|
+
* [pitchDomain]="[0, 100]"
|
|
692
|
+
* [pitchRange]="[220, 880]" />
|
|
693
|
+
* ```
|
|
694
|
+
*
|
|
695
|
+
* The inputs are discrete rather than an options record so `[cngxAudioPitch]`
|
|
696
|
+
* stays a native reactive input — passing `[cngxAudioPitch]="volume()"` binds a
|
|
697
|
+
* signal value directly, never a `Signal` smuggled inside a config object. The
|
|
698
|
+
* domain is caller-supplied and fixed; it is never accumulated from observed
|
|
699
|
+
* values, so the directive holds no hidden state. Value-to-frequency is a pure
|
|
700
|
+
* derivation; rapid sweeps are throttled through the shared `createDebouncer`.
|
|
701
|
+
*
|
|
702
|
+
* @category common/audio
|
|
703
|
+
* @docsKind primary
|
|
704
|
+
* @wcag AA
|
|
705
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/pitch-mode/audio-pitch.directive.ts
|
|
706
|
+
* @since 0.1.0
|
|
707
|
+
* @relatedTo CngxAudio, injectCngxAudio
|
|
708
|
+
* <example-url>http://localhost:4200/#/common/audio/pitch/slider</example-url>
|
|
709
|
+
*/
|
|
710
|
+
declare class CngxAudioPitch {
|
|
711
|
+
private readonly audio;
|
|
712
|
+
/** The tracked value to sonify. */
|
|
713
|
+
readonly value: _angular_core.InputSignal<number>;
|
|
714
|
+
/** Output frequency range `[lo, hi]` in Hz. Default `[220, 880]`. */
|
|
715
|
+
readonly pitchRange: _angular_core.InputSignal<[number, number]>;
|
|
716
|
+
/** Fixed input domain `[min, max]` the value is clamped against. */
|
|
717
|
+
readonly pitchDomain: _angular_core.InputSignal<[number, number]>;
|
|
718
|
+
/** Tone duration in ms. Default `120`. */
|
|
719
|
+
readonly pitchDurationMs: _angular_core.InputSignal<number>;
|
|
720
|
+
/** Minimum ms between tones during a sweep. Default `50`. */
|
|
721
|
+
readonly pitchThrottleMs: _angular_core.InputSignal<number>;
|
|
722
|
+
/** Per-element volume multiplier in `[0, 1]`; unset uses the tone default. */
|
|
723
|
+
readonly audioVolume: _angular_core.InputSignal<number | undefined>;
|
|
724
|
+
/** Suppress this element's audio without unbinding. */
|
|
725
|
+
readonly audioDisabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
|
|
726
|
+
private readonly debouncer;
|
|
727
|
+
private readonly transition;
|
|
728
|
+
constructor();
|
|
729
|
+
/** Clamp to the domain, then linear-scale into the frequency range. */
|
|
730
|
+
private scale;
|
|
731
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<CngxAudioPitch, never>;
|
|
732
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<CngxAudioPitch, "[cngxAudioPitch]", ["cngxAudioPitch"], { "value": { "alias": "cngxAudioPitch"; "required": true; "isSignal": true; }; "pitchRange": { "alias": "pitchRange"; "required": false; "isSignal": true; }; "pitchDomain": { "alias": "pitchDomain"; "required": true; "isSignal": true; }; "pitchDurationMs": { "alias": "pitchDurationMs"; "required": false; "isSignal": true; }; "pitchThrottleMs": { "alias": "pitchThrottleMs"; "required": false; "isSignal": true; }; "audioVolume": { "alias": "audioVolume"; "required": false; "isSignal": true; }; "audioDisabled": { "alias": "audioDisabled"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export { CNGX_AUDIO_CONFIG, CNGX_AUDIO_DEFAULTS, CNGX_AUDIO_ENGINE_FACTORY, CNGX_AUDIO_TONE_GENERATOR_FACTORY, CngxAudio, CngxAudioPitch, CngxAudioStatus, CngxAudioZone, createAudioEngine, createAutoplayGate, createDebouncer, createToneGenerator, injectAudioConfig, injectCngxAudio, provideCngxAudio, provideCngxAudioAt, withDebounceMs, withEarcons, withMuted, withRespectReducedMotion, withVolume };
|
|
736
|
+
export type { AudioEngineOptions, AudioStatus, CngxAudioConfig, CngxAudioEngine, CngxAudioEngineFactory, CngxAudioFeature, CngxAudioHandle, CngxAudioToneGeneratorFactory, CngxAudioZoneBinding, CngxAutoplayGate, CngxDebouncer, CngxToneGenerator, EarconConfig, GestureEventTarget, ToneGeneratorDeps, ToneOptions, ToneStep };
|