@cngx/common 0.1.0-rc.9 → 0.3.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.
- package/a11y/README.md +15 -2
- package/button/README.md +258 -0
- package/command/README.md +19 -8
- package/data/README.md +10 -10
- package/fesm2022/cngx-common-a11y.mjs +701 -263
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +83 -64
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-button.mjs +1084 -0
- package/fesm2022/cngx-common-button.mjs.map +1 -0
- package/fesm2022/cngx-common-card.mjs +135 -76
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +749 -296
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +51 -29
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +695 -405
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +112 -112
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +668 -308
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +7066 -2739
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +2121 -492
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-menu-button.mjs +557 -0
- package/fesm2022/cngx-common-menu-button.mjs.map +1 -0
- package/fesm2022/cngx-common-popover.mjs +1207 -569
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +256 -261
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +202 -262
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +28 -61
- package/fesm2022/cngx-common-timeline.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +10 -10
- package/fesm2022/cngx-common.mjs.map +1 -1
- package/interactive/README.md +30 -19
- package/layout/README.md +1 -1
- package/menu-button/README.md +234 -0
- package/package.json +14 -4
- package/popover/README.md +42 -5
- package/popover/tooltip-indicator.scss +52 -0
- package/schematics/ng-add/index.js +7 -7
- package/schematics/ng-add/schema.json +5 -0
- package/stepper/README.md +0 -1
- package/theming/components/cngx-accordion.css +36 -7
- package/theming/components/cngx-async.css +185 -37
- package/theming/components/cngx-backdrop.css +3 -1
- package/theming/components/cngx-badge.css +20 -5
- package/theming/components/cngx-bottom-sheet.css +2 -0
- package/theming/components/cngx-breadcrumb.css +3 -1
- package/theming/components/cngx-button-group.css +325 -0
- package/theming/components/cngx-button-toggle.css +55 -23
- package/theming/components/cngx-button.css +975 -0
- package/theming/components/cngx-data-grid.css +2 -0
- package/theming/components/cngx-dialog.css +3 -1
- package/theming/components/cngx-divider.css +24 -9
- package/theming/components/cngx-drawer.css +153 -0
- package/theming/components/cngx-icon-glyph.css +76 -0
- package/theming/components/cngx-listbox.css +79 -25
- package/theming/components/cngx-menu.css +112 -52
- package/theming/components/cngx-nav.css +1220 -0
- package/theming/components/cngx-popover-sheet.css +43 -11
- package/theming/components/cngx-popover.css +37 -13
- package/theming/components/cngx-recycler-placeholder.css +2 -0
- package/theming/components/cngx-ripple.css +74 -16
- package/theming/components/cngx-sidebar.css +71 -0
- package/theming/components/cngx-slider.css +3 -1
- package/theming/components/cngx-tooltip.css +2 -0
- package/timeline/README.md +2 -2
- package/types/cngx-common-a11y.d.ts +343 -120
- package/types/cngx-common-audio.d.ts +60 -88
- package/types/cngx-common-button.d.ts +698 -0
- package/types/cngx-common-card.d.ts +104 -78
- package/types/cngx-common-chart.d.ts +671 -384
- package/types/cngx-common-command.d.ts +44 -47
- package/types/cngx-common-data.d.ts +350 -342
- package/types/cngx-common-dialog.d.ts +91 -120
- package/types/cngx-common-display.d.ts +475 -300
- package/types/cngx-common-interactive.d.ts +4350 -1723
- package/types/cngx-common-layout.d.ts +1365 -286
- package/types/cngx-common-menu-button.d.ts +382 -0
- package/types/cngx-common-popover.d.ts +671 -289
- package/types/cngx-common-stepper.d.ts +217 -347
- package/types/cngx-common-tabs.d.ts +173 -386
- package/types/cngx-common-timeline.d.ts +25 -104
|
@@ -7,9 +7,8 @@ import { CNGX_STATEFUL, createTransitionTracker } from '@cngx/core/utils';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Library defaults - English, browser-native.
|
|
10
|
-
* @category common/audio
|
|
11
10
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
12
|
-
* @since 0.
|
|
11
|
+
* @since 0.3.0
|
|
13
12
|
*/
|
|
14
13
|
const CNGX_AUDIO_DEFAULTS = {
|
|
15
14
|
muted: false,
|
|
@@ -23,10 +22,9 @@ const CNGX_AUDIO_DEFAULTS = {
|
|
|
23
22
|
* `provideCngxAudio(...)`. Read the resolved, defaults-merged config with
|
|
24
23
|
* {@link injectAudioConfig}.
|
|
25
24
|
*
|
|
26
|
-
* @category common/audio
|
|
27
25
|
* @relatedTo provideCngxAudio, injectAudioConfig
|
|
28
26
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
29
|
-
* @since 0.
|
|
27
|
+
* @since 0.3.0
|
|
30
28
|
*/
|
|
31
29
|
const CNGX_AUDIO_CONFIG = new InjectionToken('CngxAudioConfig', {
|
|
32
30
|
providedIn: 'root',
|
|
@@ -36,9 +34,8 @@ const CNGX_AUDIO_CONFIG = new InjectionToken('CngxAudioConfig', {
|
|
|
36
34
|
* Resolve the effective audio config: library defaults merged with whatever
|
|
37
35
|
* `provideCngxAudio(...)` contributed. Runs in an injection context.
|
|
38
36
|
*
|
|
39
|
-
* @category common/audio
|
|
40
37
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
41
|
-
* @since 0.
|
|
38
|
+
* @since 0.3.0
|
|
42
39
|
*/
|
|
43
40
|
function injectAudioConfig() {
|
|
44
41
|
return { ...CNGX_AUDIO_DEFAULTS, ...inject(CNGX_AUDIO_CONFIG, { optional: true }) };
|
|
@@ -77,10 +74,9 @@ function foldAudioFeatures(features) {
|
|
|
77
74
|
* configure a subtree, use `provideCngxAudioAt(...)` in `viewProviders` - it
|
|
78
75
|
* layers over this one and re-provides the engine so the scope actually applies.
|
|
79
76
|
*
|
|
80
|
-
* @category common/audio
|
|
81
77
|
* @relatedTo provideCngxAudioAt, injectAudioConfig
|
|
82
78
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
83
|
-
* @since 0.
|
|
79
|
+
* @since 0.3.0
|
|
84
80
|
*/
|
|
85
81
|
function provideCngxAudio(...features) {
|
|
86
82
|
return makeEnvironmentProviders([
|
|
@@ -91,9 +87,8 @@ function provideCngxAudio(...features) {
|
|
|
91
87
|
* Register or override earcons globally. Merged over the six built-ins and over
|
|
92
88
|
* any earlier `withEarcons` in the same `provideCngxAudio` call.
|
|
93
89
|
*
|
|
94
|
-
* @category common/audio
|
|
95
90
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
96
|
-
* @since 0.
|
|
91
|
+
* @since 0.3.0
|
|
97
92
|
*/
|
|
98
93
|
function withEarcons(earcons) {
|
|
99
94
|
return { _apply: (c) => ({ ...c, earcons: { ...c.earcons, ...earcons } }) };
|
|
@@ -101,9 +96,8 @@ function withEarcons(earcons) {
|
|
|
101
96
|
/**
|
|
102
97
|
* Set the master volume in `[0, 1]`.
|
|
103
98
|
*
|
|
104
|
-
* @category common/audio
|
|
105
99
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
106
|
-
* @since 0.
|
|
100
|
+
* @since 0.3.0
|
|
107
101
|
*/
|
|
108
102
|
function withVolume(volume) {
|
|
109
103
|
return { _apply: (c) => ({ ...c, volume }) };
|
|
@@ -111,9 +105,8 @@ function withVolume(volume) {
|
|
|
111
105
|
/**
|
|
112
106
|
* Start muted (or explicitly unmuted with `withMuted(false)`).
|
|
113
107
|
*
|
|
114
|
-
* @category common/audio
|
|
115
108
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
116
|
-
* @since 0.
|
|
109
|
+
* @since 0.3.0
|
|
117
110
|
*/
|
|
118
111
|
function withMuted(muted = true) {
|
|
119
112
|
return { _apply: (c) => ({ ...c, muted }) };
|
|
@@ -122,9 +115,8 @@ function withMuted(muted = true) {
|
|
|
122
115
|
* Toggle the `prefers-reduced-motion` mute gate. `true` by default in the
|
|
123
116
|
* library; pass `false` to keep audio playing under reduced-motion.
|
|
124
117
|
*
|
|
125
|
-
* @category common/audio
|
|
126
118
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
127
|
-
* @since 0.
|
|
119
|
+
* @since 0.3.0
|
|
128
120
|
*/
|
|
129
121
|
function withRespectReducedMotion(respect) {
|
|
130
122
|
return { _apply: (c) => ({ ...c, respectReducedMotion: respect }) };
|
|
@@ -132,9 +124,8 @@ function withRespectReducedMotion(respect) {
|
|
|
132
124
|
/**
|
|
133
125
|
* Set the same-name suppression window in milliseconds.
|
|
134
126
|
*
|
|
135
|
-
* @category common/audio
|
|
136
127
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/config/audio-config.ts
|
|
137
|
-
* @since 0.
|
|
128
|
+
* @since 0.3.0
|
|
138
129
|
*/
|
|
139
130
|
function withDebounceMs(ms) {
|
|
140
131
|
return { _apply: (c) => ({ ...c, debounceMs: ms }) };
|
|
@@ -157,9 +148,8 @@ const GESTURE_EVENTS = ['pointerdown', 'keydown', 'touchstart'];
|
|
|
157
148
|
*
|
|
158
149
|
* @param deps.target The event target to listen on (typically the `Document`).
|
|
159
150
|
* @param deps.destroyRef Cleanup owner - removes any surviving listeners on destroy.
|
|
160
|
-
* @category common/audio
|
|
161
151
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/autoplay-gate/autoplay-gate.ts
|
|
162
|
-
* @since 0.
|
|
152
|
+
* @since 0.3.0
|
|
163
153
|
*/
|
|
164
154
|
function createAutoplayGate(deps) {
|
|
165
155
|
const { target, destroyRef } = deps;
|
|
@@ -209,9 +199,8 @@ const DEFAULT_WINDOW_MS = 100;
|
|
|
209
199
|
*
|
|
210
200
|
* @param options.windowMs Suppression window, or a getter for it. `<= 0` disables debouncing. Default `100`.
|
|
211
201
|
* @param options.now Clock source in ms. Default `Date.now`.
|
|
212
|
-
* @category common/audio
|
|
213
202
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/debouncer/debouncer.ts
|
|
214
|
-
* @since 0.
|
|
203
|
+
* @since 0.3.0
|
|
215
204
|
*/
|
|
216
205
|
function createDebouncer(options) {
|
|
217
206
|
const windowOption = options?.windowMs ?? DEFAULT_WINDOW_MS;
|
|
@@ -241,8 +230,8 @@ function createDebouncer(options) {
|
|
|
241
230
|
|
|
242
231
|
/**
|
|
243
232
|
* The six built-in earcons, synthesised entirely from `OscillatorNode` - zero
|
|
244
|
-
* audio assets. Plain `as const
|
|
245
|
-
*
|
|
233
|
+
* audio assets. Plain `as const`: tree-shakeable, compile-time exhaustive keys,
|
|
234
|
+
* and NOT exported from `public-api.ts`. The
|
|
246
235
|
* consumer override surface is `withEarcons({...})` and the engine's runtime
|
|
247
236
|
* `register()`, never this const.
|
|
248
237
|
*
|
|
@@ -299,9 +288,9 @@ const MIN_DURATION_SEC = ATTACK_SEC + RELEASE_SEC;
|
|
|
299
288
|
* Default peak gain for a single tone (before the engine's master volume).
|
|
300
289
|
* Exported so a per-element volume multiplier can scale against the same
|
|
301
290
|
* baseline the generator uses.
|
|
302
|
-
* @category common/audio
|
|
303
291
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
304
|
-
* @since 0.
|
|
292
|
+
* @since 0.3.0
|
|
293
|
+
* @internal
|
|
305
294
|
*/
|
|
306
295
|
const DEFAULT_TONE_GAIN = 0.2;
|
|
307
296
|
/**
|
|
@@ -313,9 +302,8 @@ const DEFAULT_TONE_GAIN = 0.2;
|
|
|
313
302
|
*
|
|
314
303
|
* `create*` pure factory (no `inject()`), so it composes inside the engine and
|
|
315
304
|
* runs against the shared `createAudioContextMock` in specs.
|
|
316
|
-
* @category common/audio
|
|
317
305
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
318
|
-
* @since 0.
|
|
306
|
+
* @since 0.3.0
|
|
319
307
|
*/
|
|
320
308
|
const createToneGenerator = (deps) => {
|
|
321
309
|
function schedule(freq, durationMs, opts, whenSec) {
|
|
@@ -363,9 +351,8 @@ const createToneGenerator = (deps) => {
|
|
|
363
351
|
* forking the engine - the documented second consumer of this boundary token.
|
|
364
352
|
*
|
|
365
353
|
* @relatedTo createToneGenerator, CNGX_AUDIO_ENGINE_FACTORY
|
|
366
|
-
* @category common/audio
|
|
367
354
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/tone-generator/tone-generator.ts
|
|
368
|
-
* @since 0.
|
|
355
|
+
* @since 0.3.0
|
|
369
356
|
*/
|
|
370
357
|
const CNGX_AUDIO_TONE_GENERATOR_FACTORY = new InjectionToken('CngxAudioToneGeneratorFactory', { providedIn: 'root', factory: () => createToneGenerator });
|
|
371
358
|
|
|
@@ -425,9 +412,8 @@ function scaleSteps(steps, scale) {
|
|
|
425
412
|
* tone-generator factory, and the reduced-motion query). The engine instance is
|
|
426
413
|
* resolved through {@link CNGX_AUDIO_ENGINE_FACTORY}; scope it to a subtree with
|
|
427
414
|
* `provideCngxAudioAt(...)` rather than calling this directly.
|
|
428
|
-
* @category common/audio
|
|
429
415
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
430
|
-
* @since 0.
|
|
416
|
+
* @since 0.3.0
|
|
431
417
|
*/
|
|
432
418
|
const createAudioEngine = (options) => {
|
|
433
419
|
const doc = inject(DOCUMENT);
|
|
@@ -598,9 +584,8 @@ const createAudioEngine = (options) => {
|
|
|
598
584
|
* the library baseline. Both are exported from `@cngx/common/audio`.
|
|
599
585
|
*
|
|
600
586
|
* @relatedTo createAudioEngine, injectCngxAudio, injectAudioConfig
|
|
601
|
-
* @category common/audio
|
|
602
587
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/engine/audio-engine.ts
|
|
603
|
-
* @since 0.
|
|
588
|
+
* @since 0.3.0
|
|
604
589
|
*/
|
|
605
590
|
const CNGX_AUDIO_ENGINE_FACTORY = new InjectionToken('CngxAudioEngineFactory', { providedIn: 'root', factory: () => createAudioEngine });
|
|
606
591
|
|
|
@@ -632,9 +617,8 @@ const CNGX_AUDIO_ENGINE = new InjectionToken('CngxAudioEngineInstance', {
|
|
|
632
617
|
* }
|
|
633
618
|
* ```
|
|
634
619
|
*
|
|
635
|
-
* @category common/audio
|
|
636
620
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/inject-audio.ts
|
|
637
|
-
* @since 0.
|
|
621
|
+
* @since 0.3.0
|
|
638
622
|
*/
|
|
639
623
|
function injectCngxAudio() {
|
|
640
624
|
return inject(CNGX_AUDIO_ENGINE);
|
|
@@ -674,10 +658,9 @@ function injectCngxAudio() {
|
|
|
674
658
|
* independent audio scope - per-element `[audioVolume]` / `[audioDisabled]`
|
|
675
659
|
* cover the common case without a second context.
|
|
676
660
|
*
|
|
677
|
-
* @category common/audio
|
|
678
661
|
* @relatedTo provideCngxAudio, injectCngxAudio
|
|
679
662
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/inject-audio.ts
|
|
680
|
-
* @since 0.
|
|
663
|
+
* @since 0.3.0
|
|
681
664
|
*/
|
|
682
665
|
function provideCngxAudioAt(...features) {
|
|
683
666
|
return [
|
|
@@ -716,7 +699,10 @@ function sameStringMap(a, b) {
|
|
|
716
699
|
return true;
|
|
717
700
|
}
|
|
718
701
|
|
|
719
|
-
/**
|
|
702
|
+
/**
|
|
703
|
+
* DOM events `[cngxAudio]` may bind an earcon to.
|
|
704
|
+
* @internal
|
|
705
|
+
*/
|
|
720
706
|
const CNGX_AUDIO_DOM_EVENTS = [
|
|
721
707
|
'click',
|
|
722
708
|
'focus',
|
|
@@ -745,6 +731,7 @@ const LIFECYCLE_SET = new Set(LIFECYCLE_KEYS);
|
|
|
745
731
|
* DOM-event map. Pure - no DOM, no `inject()`. Keys are categorised so the
|
|
746
732
|
* directive can dev-warn on unknown earcon keys and, separately, on lifecycle
|
|
747
733
|
* keys that should have used `[cngxAudioStatus]`.
|
|
734
|
+
* @internal
|
|
748
735
|
*/
|
|
749
736
|
function parseEventBindings(spec) {
|
|
750
737
|
const bindings = new Map();
|
|
@@ -804,17 +791,16 @@ function parseEventBindings(spec) {
|
|
|
804
791
|
* cost alone. Either way the engine's `lastPlayed` and `status` are signals, so
|
|
805
792
|
* anything a template binds to them stays current.
|
|
806
793
|
*
|
|
807
|
-
* @category common/audio
|
|
808
|
-
* @docsKind primary
|
|
809
794
|
* @wcag AA
|
|
810
795
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/event-mode/audio.directive.ts
|
|
811
|
-
* @since 0.
|
|
796
|
+
* @since 0.3.0
|
|
812
797
|
* @relatedTo injectCngxAudio, provideCngxAudio, CngxAudioStatus
|
|
813
|
-
* <example-url
|
|
814
|
-
* <example-url
|
|
815
|
-
* <example-url
|
|
816
|
-
* <example-url
|
|
817
|
-
* <example-url
|
|
798
|
+
* <example-url>/#/common/audio/event-mode/basic</example-url>
|
|
799
|
+
* <example-url>/#/common/audio/event-mode/custom-earcons</example-url>
|
|
800
|
+
* <example-url>/#/common/audio/event-mode/earcon-palette</example-url>
|
|
801
|
+
* <example-url>/#/common/audio/event-mode/form-feedback</example-url>
|
|
802
|
+
* <example-url>/#/common/audio/event-mode/hover-and-focus</example-url>
|
|
803
|
+
* @axis level atom
|
|
818
804
|
*/
|
|
819
805
|
class CngxAudio {
|
|
820
806
|
audio = injectCngxAudio();
|
|
@@ -940,6 +926,8 @@ const DOM_EVENT_SET = new Set(CNGX_AUDIO_STATUS_DOM_EVENTS);
|
|
|
940
926
|
* Only own keys of the alias table resolve, so `constructor` or `toString` is
|
|
941
927
|
* an unknown key. `succeeded`/`failed` normalise to `success`/`error` so a
|
|
942
928
|
* lookup by the tracker's raw `AsyncStatus` hits.
|
|
929
|
+
*
|
|
930
|
+
* @internal
|
|
943
931
|
*/
|
|
944
932
|
function parseStatusBindings(spec) {
|
|
945
933
|
const bindings = new Map();
|
|
@@ -994,13 +982,12 @@ function parseStatusBindings(spec) {
|
|
|
994
982
|
* keys (`click`, `focus`, …) belong to `[cngxAudio]` and are rejected with a
|
|
995
983
|
* dev-error. `succeeded`/`failed` are accepted as aliases for `success`/`error`.
|
|
996
984
|
*
|
|
997
|
-
* @category common/audio
|
|
998
|
-
* @docsKind primary
|
|
999
985
|
* @wcag AA
|
|
1000
986
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/status-mode/audio-status.directive.ts
|
|
1001
|
-
* @since 0.
|
|
987
|
+
* @since 0.3.0
|
|
1002
988
|
* @relatedTo CngxAudio, injectCngxAudio, CngxAsyncClick
|
|
1003
|
-
* <example-url
|
|
989
|
+
* <example-url>/#/common/audio/status-bridge/async-click</example-url>
|
|
990
|
+
* @axis level atom
|
|
1004
991
|
*/
|
|
1005
992
|
class CngxAudioStatus {
|
|
1006
993
|
audio = injectCngxAudio();
|
|
@@ -1080,13 +1067,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1080
1067
|
* `[audioDisabled]`, muted, reduced-motion-gated, autoplay-not-armed, or still
|
|
1081
1068
|
* within the debounce window. `[audioVolume]` scales just this element's plays.
|
|
1082
1069
|
*
|
|
1083
|
-
* @category common/audio
|
|
1084
|
-
* @docsKind primary
|
|
1085
1070
|
* @wcag AA
|
|
1086
1071
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/zone-mode/audio-zone.directive.ts
|
|
1087
|
-
* @since 0.
|
|
1072
|
+
* @since 0.3.0
|
|
1088
1073
|
* @relatedTo CngxAudio, injectCngxAudio
|
|
1089
|
-
* <example-url
|
|
1074
|
+
* <example-url>/#/common/audio/zone/enter-leave</example-url>
|
|
1075
|
+
* @axis level atom
|
|
1090
1076
|
*/
|
|
1091
1077
|
class CngxAudioZone {
|
|
1092
1078
|
audio = injectCngxAudio();
|
|
@@ -1136,6 +1122,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1136
1122
|
|
|
1137
1123
|
/** Throttle key - the pitch directive plays a single ad-hoc voice. */
|
|
1138
1124
|
const PITCH_VOICE = 'pitch';
|
|
1125
|
+
/** No span to interpolate across: equal ends, or an end that is `NaN` / infinite. */
|
|
1126
|
+
function isDegenerateDomain(lo, hi) {
|
|
1127
|
+
return lo === hi || !Number.isFinite(lo) || !Number.isFinite(hi);
|
|
1128
|
+
}
|
|
1139
1129
|
/**
|
|
1140
1130
|
* Pitch-mode audio binder. Sonifies a continuous numeric value: each change of
|
|
1141
1131
|
* `[cngxAudioPitch]` clamps against a fixed domain, linear-scales into an output
|
|
@@ -1156,13 +1146,12 @@ const PITCH_VOICE = 'pitch';
|
|
|
1156
1146
|
* values, so the directive holds no hidden state. Value-to-frequency is a pure
|
|
1157
1147
|
* derivation; rapid sweeps are throttled through the shared `createDebouncer`.
|
|
1158
1148
|
*
|
|
1159
|
-
* @category common/audio
|
|
1160
|
-
* @docsKind primary
|
|
1161
1149
|
* @wcag AA
|
|
1162
1150
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/audio/pitch-mode/audio-pitch.directive.ts
|
|
1163
|
-
* @since 0.
|
|
1151
|
+
* @since 0.3.0
|
|
1164
1152
|
* @relatedTo CngxAudio, injectCngxAudio
|
|
1165
|
-
* <example-url
|
|
1153
|
+
* <example-url>/#/common/audio/pitch/slider</example-url>
|
|
1154
|
+
* @axis level atom
|
|
1166
1155
|
*/
|
|
1167
1156
|
class CngxAudioPitch {
|
|
1168
1157
|
audio = injectCngxAudio();
|
|
@@ -1170,7 +1159,12 @@ class CngxAudioPitch {
|
|
|
1170
1159
|
value = input.required({ ...(ngDevMode ? { debugName: "value" } : /* istanbul ignore next */ {}), alias: 'cngxAudioPitch' });
|
|
1171
1160
|
/** Output frequency range `[lo, hi]` in Hz. Default `[220, 880]`. */
|
|
1172
1161
|
pitchRange = input([220, 880], ...(ngDevMode ? [{ debugName: "pitchRange" }] : /* istanbul ignore next */ []));
|
|
1173
|
-
/**
|
|
1162
|
+
/**
|
|
1163
|
+
* Fixed input domain `[lo, hi]` the value is clamped against; `lo > hi`
|
|
1164
|
+
* inverts the mapping. An empty domain (`lo === hi`) or one with a `NaN` /
|
|
1165
|
+
* infinite end plays the range low for every value and warns in dev mode
|
|
1166
|
+
* ([`CNGX1069`](/error-codes/cngx1069.md)).
|
|
1167
|
+
*/
|
|
1174
1168
|
pitchDomain = input.required(...(ngDevMode ? [{ debugName: "pitchDomain" }] : /* istanbul ignore next */ []));
|
|
1175
1169
|
/** Tone duration in ms. Default `120`. */
|
|
1176
1170
|
pitchDurationMs = input(120, ...(ngDevMode ? [{ debugName: "pitchDurationMs" }] : /* istanbul ignore next */ []));
|
|
@@ -1207,15 +1201,40 @@ class CngxAudioPitch {
|
|
|
1207
1201
|
this.audio.tone(this.scale(current), this.pitchDurationMs(), undefined, this.audioVolume());
|
|
1208
1202
|
});
|
|
1209
1203
|
});
|
|
1204
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1205
|
+
// [pitchDomain] is a live input, so the check re-runs on every change;
|
|
1206
|
+
// the key keeps a re-bound identical empty tuple silent.
|
|
1207
|
+
let lastWarned = null;
|
|
1208
|
+
effect(() => {
|
|
1209
|
+
const [lo, hi] = this.pitchDomain();
|
|
1210
|
+
if (!isDegenerateDomain(lo, hi)) {
|
|
1211
|
+
lastWarned = null;
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const key = `${lo},${hi}`;
|
|
1215
|
+
if (key === lastWarned) {
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
lastWarned = key;
|
|
1219
|
+
const rangeLo = untracked(() => this.pitchRange()[0]);
|
|
1220
|
+
cngxDevWarn('CNGX1069', `[cngxAudioPitch] [pitchDomain] [${lo}, ${hi}] is empty or not finite; every value plays ${rangeLo} Hz, the low end of [pitchRange].`);
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1210
1223
|
}
|
|
1211
|
-
/**
|
|
1224
|
+
/**
|
|
1225
|
+
* Clamp to the domain, then linear-scale into the frequency range. The
|
|
1226
|
+
* interpolation runs against the declared pair, so an inverted domain maps
|
|
1227
|
+
* `lo` to the range low and `hi` to the range high.
|
|
1228
|
+
*/
|
|
1212
1229
|
scale(value) {
|
|
1213
1230
|
const [domainLo, domainHi] = this.pitchDomain();
|
|
1214
1231
|
const [rangeLo, rangeHi] = this.pitchRange();
|
|
1215
|
-
|
|
1216
|
-
if (domainHi === domainLo) {
|
|
1232
|
+
if (isDegenerateDomain(domainLo, domainHi)) {
|
|
1217
1233
|
return rangeLo;
|
|
1218
1234
|
}
|
|
1235
|
+
const min = Math.min(domainLo, domainHi);
|
|
1236
|
+
const max = Math.max(domainLo, domainHi);
|
|
1237
|
+
const clamped = Math.max(min, Math.min(max, value));
|
|
1219
1238
|
const t = (clamped - domainLo) / (domainHi - domainLo);
|
|
1220
1239
|
return rangeLo + t * (rangeHi - rangeLo);
|
|
1221
1240
|
}
|
|
@@ -1231,7 +1250,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1231
1250
|
}], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxAudioPitch", required: true }] }], pitchRange: [{ type: i0.Input, args: [{ isSignal: true, alias: "pitchRange", required: false }] }], pitchDomain: [{ type: i0.Input, args: [{ isSignal: true, alias: "pitchDomain", required: true }] }], pitchDurationMs: [{ type: i0.Input, args: [{ isSignal: true, alias: "pitchDurationMs", required: false }] }], pitchThrottleMs: [{ type: i0.Input, args: [{ isSignal: true, alias: "pitchThrottleMs", required: false }] }], audioVolume: [{ type: i0.Input, args: [{ isSignal: true, alias: "audioVolume", required: false }] }], audioDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "audioDisabled", required: false }] }] } });
|
|
1232
1251
|
|
|
1233
1252
|
/**
|
|
1234
|
-
* @module
|
|
1253
|
+
* @module `@cngx/common/audio`
|
|
1235
1254
|
*
|
|
1236
1255
|
* Signal-first audio-feedback system. A thin directive layer over a small
|
|
1237
1256
|
* Web Audio adapter: zero asset weight (earcons synthesised from
|