@zcomponent/core 1.29.0 → 2.0.0-alpha.2

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.
Files changed (168) hide show
  1. package/README.md +1 -0
  2. package/css/zcomponent.css +121 -122
  3. package/index.js +0 -3
  4. package/lib/actionbehavior.d.ts +3 -3
  5. package/lib/actionbehavior.js +20 -19
  6. package/lib/animation/animation.d.ts +13 -6
  7. package/lib/animation/animation.js +56 -43
  8. package/lib/animation/bezier.d.ts +6 -0
  9. package/lib/animation/bezier.js +8 -2
  10. package/lib/animation/clips/clip.d.ts +13 -1
  11. package/lib/animation/clips/clip.js +34 -14
  12. package/lib/animation/index.d.ts +4 -4
  13. package/lib/animation/index.js +4 -4
  14. package/lib/animation/layer.d.ts +9 -0
  15. package/lib/animation/layer.js +28 -12
  16. package/lib/animation/layerclip.d.ts +21 -0
  17. package/lib/animation/layerclip.js +82 -45
  18. package/lib/animation/tracks/cliptrack.d.ts +18 -0
  19. package/lib/animation/tracks/cliptrack.js +27 -6
  20. package/lib/animation/tracks/functiontrack.d.ts +9 -0
  21. package/lib/animation/tracks/functiontrack.js +16 -3
  22. package/lib/animation/tracks/propertytrack.d.ts +20 -1
  23. package/lib/animation/tracks/propertytrack.js +48 -11
  24. package/lib/animation/tracks/streamtrack.d.ts +18 -0
  25. package/lib/animation/tracks/streamtrack.js +32 -6
  26. package/lib/animation/tracks/track.d.ts +8 -2
  27. package/lib/animation/tracks/track.js +3 -2
  28. package/lib/behavior.js +13 -10
  29. package/lib/behaviors/ActivateState.d.ts +22 -24
  30. package/lib/behaviors/ActivateState.js +145 -35
  31. package/lib/behaviors/CallFunction.d.ts +2 -4
  32. package/lib/behaviors/CallFunction.js +69 -11
  33. package/lib/behaviors/ChangeRootScene.d.ts +35 -0
  34. package/lib/behaviors/ChangeRootScene.js +123 -0
  35. package/lib/behaviors/ConsoleLog.d.ts +6 -5
  36. package/lib/behaviors/ConsoleLog.js +95 -12
  37. package/lib/behaviors/DownloadSnapshot.d.ts +7 -12
  38. package/lib/behaviors/DownloadSnapshot.js +70 -19
  39. package/lib/behaviors/EmitComponentPropEvent.d.ts +1 -3
  40. package/lib/behaviors/EmitComponentPropEvent.js +80 -12
  41. package/lib/behaviors/LaunchURL.d.ts +5 -5
  42. package/lib/behaviors/LaunchURL.js +92 -10
  43. package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -4
  44. package/lib/behaviors/LogAnalyticsEvent.js +88 -7
  45. package/lib/behaviors/PauseLayerClip.d.ts +7 -9
  46. package/lib/behaviors/PauseLayerClip.js +89 -21
  47. package/lib/behaviors/PlayLayerClip.d.ts +35 -32
  48. package/lib/behaviors/PlayLayerClip.js +202 -48
  49. package/lib/behaviors/PlaySound.d.ts +19 -25
  50. package/lib/behaviors/PlaySound.js +122 -28
  51. package/lib/behaviors/SetLayerOff.d.ts +7 -9
  52. package/lib/behaviors/SetLayerOff.js +88 -21
  53. package/lib/behaviors/ShareSnapshot.d.ts +5 -9
  54. package/lib/behaviors/ShareSnapshot.js +70 -17
  55. package/lib/behaviors/ShowTextAlert.d.ts +16 -29
  56. package/lib/behaviors/ShowTextAlert.js +116 -48
  57. package/lib/behaviors/TakeSnapshot.d.ts +22 -26
  58. package/lib/behaviors/TakeSnapshot.js +131 -56
  59. package/lib/behaviors/ToggleLayerClips.d.ts +45 -62
  60. package/lib/behaviors/ToggleLayerClips.js +233 -64
  61. package/lib/behaviors/stream/PauseStream.d.ts +5 -16
  62. package/lib/behaviors/stream/PauseStream.js +94 -34
  63. package/lib/behaviors/stream/PlayStream.d.ts +14 -27
  64. package/lib/behaviors/stream/PlayStream.js +123 -34
  65. package/lib/behaviors/stream/SeekStream.d.ts +8 -18
  66. package/lib/behaviors/stream/SeekStream.js +97 -31
  67. package/lib/behaviors/stream/StopStream.d.ts +6 -15
  68. package/lib/behaviors/stream/StopStream.js +89 -27
  69. package/lib/component.d.ts +36 -13
  70. package/lib/component.js +237 -151
  71. package/lib/components/AnimatedLoader.d.ts +51 -0
  72. package/lib/components/AnimatedLoader.js +159 -0
  73. package/lib/components/Audio.d.ts +35 -37
  74. package/lib/components/Audio.js +264 -151
  75. package/lib/components/AudioLayerSettings.d.ts +13 -11
  76. package/lib/components/AudioLayerSettings.js +76 -18
  77. package/lib/components/Children.d.ts +2 -1
  78. package/lib/components/Children.js +66 -13
  79. package/lib/components/ConditionalConstruct.d.ts +44 -0
  80. package/lib/components/ConditionalConstruct.js +142 -0
  81. package/lib/components/DefaultCookieConsent.d.ts +53 -73
  82. package/lib/components/DefaultCookieConsent.js +382 -264
  83. package/lib/components/DefaultLoader.d.ts +40 -28
  84. package/lib/components/DefaultLoader.js +198 -46
  85. package/lib/components/Gamepad.d.ts +5 -26
  86. package/lib/components/Gamepad.js +201 -65
  87. package/lib/components/LoaderScope.d.ts +15 -0
  88. package/lib/components/LoaderScope.js +71 -0
  89. package/lib/components/LongLoad.d.ts +11 -15
  90. package/lib/components/LongLoad.js +89 -34
  91. package/lib/components/SnapshotUI.d.ts +19 -24
  92. package/lib/components/SnapshotUI.js +202 -105
  93. package/lib/context.d.ts +23 -5
  94. package/lib/context.js +12 -6
  95. package/lib/contexts/analyticscontext.d.ts +12 -2
  96. package/lib/contexts/analyticscontext.js +68 -10
  97. package/lib/contexts/audiocontextcontext.d.ts +1 -1
  98. package/lib/contexts/audiocontextcontext.js +9 -8
  99. package/lib/contexts/canvascontext.d.ts +32 -18
  100. package/lib/contexts/canvascontext.js +195 -120
  101. package/lib/contexts/cookieconsentcontext.d.ts +38 -28
  102. package/lib/contexts/cookieconsentcontext.js +35 -32
  103. package/lib/contexts/documentflagmanager.js +15 -11
  104. package/lib/contexts/environmentcontext.d.ts +22 -6
  105. package/lib/contexts/environmentcontext.js +135 -21
  106. package/lib/contexts/gamepadcontext.d.ts +29 -26
  107. package/lib/contexts/gamepadcontext.js +46 -46
  108. package/lib/contexts/gesturecontext.d.ts +31 -6
  109. package/lib/contexts/gesturecontext.js +110 -85
  110. package/lib/contexts/globaltagcontext.d.ts +1 -1
  111. package/lib/contexts/globaltagcontext.js +8 -11
  112. package/lib/contexts/loadcontext.d.ts +45 -8
  113. package/lib/contexts/loadcontext.js +232 -82
  114. package/lib/contexts/orientationcontext.d.ts +13 -15
  115. package/lib/contexts/orientationcontext.js +150 -67
  116. package/lib/contexts/rootcomponentscontext.d.ts +16 -0
  117. package/lib/contexts/rootcomponentscontext.js +65 -0
  118. package/lib/contexts/snapshotContext.d.ts +0 -3
  119. package/lib/contexts/snapshotContext.js +78 -23
  120. package/lib/contexts/tagcontext.d.ts +5 -5
  121. package/lib/contexts/tagcontext.js +16 -16
  122. package/lib/contexts/textalertcontext.d.ts +1 -5
  123. package/lib/contexts/textalertcontext.js +1 -5
  124. package/lib/contexts/usereventcontext.d.ts +1 -1
  125. package/lib/contexts/usereventcontext.js +12 -12
  126. package/lib/data/animation.d.ts +10 -2
  127. package/lib/data/change.d.ts +1 -1
  128. package/lib/data/change.js +7 -0
  129. package/lib/data/core.d.ts +9 -1
  130. package/lib/data/index.d.ts +1 -1
  131. package/lib/data/index.js +1 -1
  132. package/lib/decorators.d.ts +348 -0
  133. package/lib/decorators.js +239 -0
  134. package/lib/decoratorutils.d.ts +3 -0
  135. package/lib/decoratorutils.js +8 -0
  136. package/lib/emitter.d.ts +15 -2
  137. package/lib/emitter.js +15 -6
  138. package/lib/entity.d.ts +43 -25
  139. package/lib/entity.js +104 -71
  140. package/lib/event.d.ts +2 -1
  141. package/lib/event.js +1 -4
  142. package/lib/groups.d.ts +18 -0
  143. package/lib/groups.js +19 -0
  144. package/lib/icons.d.ts +3372 -0
  145. package/lib/icons.js +1 -0
  146. package/lib/index.d.ts +18 -13
  147. package/lib/index.js +17 -13
  148. package/lib/inflate.d.ts +7 -7
  149. package/lib/inflate.js +5 -5
  150. package/lib/observable.d.ts +9 -2
  151. package/lib/observable.js +5 -4
  152. package/lib/observe.d.ts +18 -0
  153. package/lib/observe.js +177 -0
  154. package/lib/profile.d.ts +9 -5
  155. package/lib/profile.js +27 -17
  156. package/lib/selectors.d.ts +1 -1
  157. package/lib/selectors.js +5 -4
  158. package/lib/types.d.ts +161 -19
  159. package/lib/types.js +22 -1
  160. package/lib/values/values.d.ts +7 -8
  161. package/lib/values/values.js +1 -2
  162. package/lib/values/valuesmutator.d.ts +4 -1
  163. package/lib/values/valuesmutator.js +10 -8
  164. package/lib/zcomponent.d.ts +21 -10
  165. package/lib/zcomponent.js +717 -540
  166. package/package.json +22 -5
  167. package/lib/behaviors/ChangeCursor.d.ts +0 -39
  168. package/lib/behaviors/ChangeCursor.js +0 -44
@@ -2,19 +2,16 @@ import { PlayOptions, Stream } from '../animation';
2
2
  import { Component } from '../component';
3
3
  import { ContextManager } from '../context';
4
4
  import { Event } from '../event';
5
- import { Observable } from '../observable';
5
+ import { ProjectFile } from '../types';
6
6
  export interface AudioConstructorProps {
7
- /** @zprop
8
- * @zvalues files *.+(mp3|wav)
9
- */
10
- source: string;
7
+ source: ProjectFile<'*.+(mp3|wav)'>;
11
8
  /**
12
- * @zprop
13
- * @zdefault default
9
+ *
10
+ * @default default
14
11
  */
15
12
  audioLayer?: string;
16
- /** @zprop
17
- * @zdefault false
13
+ /**
14
+ * @default false
18
15
  */
19
16
  autoplay?: boolean;
20
17
  }
@@ -23,25 +20,31 @@ export interface AudioConstructorProps {
23
20
  * It provides methods to play, pause, stop, and seek the audio.
24
21
  * It also provides observables for volume and mute state, and events for when the audio ends, stops, pauses, and plays.
25
22
  *
23
+ * @zstream
26
24
  * @zcomponent
27
- * @ztag core/audio
28
- * @zgroup Media
29
25
  * @zicon music_note
30
- * @zstream
26
+ * @zgroup Media
27
+ * @ztag core/audio
31
28
  */
32
29
  export declare class Audio extends Component<undefined, AudioConstructorProps> implements Stream {
33
- /** @zui */ readonly onEnded: Event<[Audio]>;
34
- /** @zui */ readonly onStop: Event<[Audio]>;
35
- /** @zui */ readonly onPause: Event<[Audio]>;
36
- /** @zui */ readonly onPlay: Event<[Audio]>;
37
- readonly audioContext: AudioContext;
38
- readonly destination: AudioNode;
39
- audioBuffer?: AudioBuffer;
40
30
  private _gain;
41
31
  private _reversed?;
32
+ /**
33
+ * @default 0
34
+ */
42
35
  private _playhead;
36
+ /**
37
+ * @default 1
38
+ */
43
39
  private _rate;
44
40
  private _session?;
41
+ readonly onEnded: Event<[Audio]>;
42
+ readonly onStop: Event<[Audio]>;
43
+ readonly onPause: Event<[Audio]>;
44
+ readonly onPlay: Event<[Audio]>;
45
+ readonly audioContext: AudioContext;
46
+ readonly destination: AudioNode;
47
+ audioBuffer?: AudioBuffer;
45
48
  /**
46
49
  * Creates a new Audio component.
47
50
  * @param mgr - The current ContextManager
@@ -50,48 +53,43 @@ export declare class Audio extends Component<undefined, AudioConstructorProps> i
50
53
  constructor(mgr: ContextManager, props: AudioConstructorProps);
51
54
  private _load;
52
55
  private _updateVolume;
53
- /** @zprop
54
- * @zdefault false
56
+ /**
57
+ * @default false
58
+ * @zui
55
59
  * @zgroup Audio
56
- * @zgrouppriority 20
57
60
  */
58
- readonly muted: Observable<boolean, never>;
61
+ muted: boolean;
59
62
  private _getReversed;
60
63
  /**
61
- * @zprop
62
- * @ztype proportion
64
+ * @default 1
65
+ * @zui
63
66
  * @zgroup Audio
64
- * @zgrouppriority 20
65
- * @zdefault 1
67
+ * @ztype proportion
66
68
  */
67
- readonly volume: Observable<number, never>;
68
- /** @zprop
69
- * @zdefault false
69
+ volume: number;
70
+ /**
71
+ * @default false
72
+ * @zui
70
73
  * @zgroup Audio
71
- * @zgrouppriority 20
72
74
  */
73
- readonly loop: Observable<boolean, never>;
75
+ loop: boolean;
74
76
  /**
75
- * @zprop
76
77
  * @zui
77
78
  */
78
79
  play(opts?: PlayOptions): void;
79
80
  private _pause;
80
81
  /**
81
- * @zprop
82
82
  * @zui
83
83
  */
84
84
  pause(): void;
85
85
  /**
86
- * @zprop
87
86
  * @zui
88
87
  */
89
88
  stop(): void;
90
89
  /**
91
- * @zprop
92
90
  * @zui
93
91
  */
94
- seek(/** @ztype time-milliseconds */ t: number): void;
92
+ seek(t: number): void;
95
93
  length(): number | undefined;
96
94
  dispose(): never;
97
95
  }
@@ -1,177 +1,290 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
1
35
  import { Component } from '../component';
2
36
  import { AudioContextContext, useAudioContext } from '../contexts/audiocontextcontext';
3
37
  import { isDesignTime } from '../contexts/environmentcontext';
4
- import { registerLoadable, started } from '../contexts/loadcontext';
38
+ import { started, zLoad } from '../contexts/loadcontext';
39
+ import { zComponent, zObserve, zUI } from '../decorators';
5
40
  import { Event } from '../event';
6
- import { Observable } from '../observable';
7
41
  /**
8
42
  * The Audio class represents an audio component that can be controlled.
9
43
  * It provides methods to play, pause, stop, and seek the audio.
10
44
  * It also provides observables for volume and mute state, and events for when the audio ends, stops, pauses, and plays.
11
45
  *
46
+ * @zstream
12
47
  * @zcomponent
13
- * @ztag core/audio
14
- * @zgroup Media
15
48
  * @zicon music_note
16
- * @zstream
49
+ * @zgroup Media
50
+ * @ztag core/audio
17
51
  */
18
- export class Audio extends Component {
19
- /**
20
- * Creates a new Audio component.
21
- * @param mgr - The current ContextManager
22
- * @param props - The constructor properties.
23
- */
24
- constructor(mgr, props) {
25
- super(mgr, props);
26
- /** @zui */ this.onEnded = new Event();
27
- /** @zui */ this.onStop = new Event();
28
- /** @zui */ this.onPause = new Event();
29
- /** @zui */ this.onPlay = new Event();
30
- this._playhead = 0;
31
- this._rate = 1;
32
- this._updateVolume = () => {
33
- this._gain.gain.value = this.muted.value === true ? 0 : this.volume.value;
52
+ let Audio = (() => {
53
+ let _classDecorators = [zComponent({ icon: 'music_note', group: 'Media', tags: ['core/audio'] })];
54
+ let _classDescriptor;
55
+ let _classExtraInitializers = [];
56
+ let _classThis;
57
+ let _classSuper = Component;
58
+ let _instanceExtraInitializers = [];
59
+ let _onEnded_decorators;
60
+ let _onEnded_initializers = [];
61
+ let _onEnded_extraInitializers = [];
62
+ let _onStop_decorators;
63
+ let _onStop_initializers = [];
64
+ let _onStop_extraInitializers = [];
65
+ let _onPause_decorators;
66
+ let _onPause_initializers = [];
67
+ let _onPause_extraInitializers = [];
68
+ let _onPlay_decorators;
69
+ let _onPlay_initializers = [];
70
+ let _onPlay_extraInitializers = [];
71
+ let __load_decorators;
72
+ let _muted_decorators;
73
+ let _muted_initializers = [];
74
+ let _muted_extraInitializers = [];
75
+ let _volume_decorators;
76
+ let _volume_initializers = [];
77
+ let _volume_extraInitializers = [];
78
+ let _loop_decorators;
79
+ let _loop_initializers = [];
80
+ let _loop_extraInitializers = [];
81
+ let _play_decorators;
82
+ let _pause_decorators;
83
+ let _stop_decorators;
84
+ let _seek_decorators;
85
+ var Audio = class extends _classSuper {
86
+ static { _classThis = this; }
87
+ static {
88
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
89
+ _onEnded_decorators = [zUI()];
90
+ _onStop_decorators = [zUI()];
91
+ _onPause_decorators = [zUI()];
92
+ _onPlay_decorators = [zUI()];
93
+ __load_decorators = [zLoad()];
94
+ _muted_decorators = [zUI({ group: 'Audio', priority: 20 }), zObserve((v, instance) => {
95
+ instance._updateVolume();
96
+ })];
97
+ _volume_decorators = [zUI({ group: 'Audio', priority: 20, type: 'proportion' }), zObserve((v, instance) => {
98
+ instance._updateVolume();
99
+ })];
100
+ _loop_decorators = [zUI({ group: 'Audio', priority: 20 }), zObserve((v, instance) => {
101
+ if (instance._session)
102
+ instance._session.source.loop = v;
103
+ })];
104
+ _play_decorators = [zUI()];
105
+ _pause_decorators = [zUI()];
106
+ _stop_decorators = [zUI()];
107
+ _seek_decorators = [zUI({ type: 'time-milliseconds' })];
108
+ __esDecorate(this, null, __load_decorators, { kind: "method", name: "_load", static: false, private: false, access: { has: obj => "_load" in obj, get: obj => obj._load }, metadata: _metadata }, null, _instanceExtraInitializers);
109
+ __esDecorate(this, null, _play_decorators, { kind: "method", name: "play", static: false, private: false, access: { has: obj => "play" in obj, get: obj => obj.play }, metadata: _metadata }, null, _instanceExtraInitializers);
110
+ __esDecorate(this, null, _pause_decorators, { kind: "method", name: "pause", static: false, private: false, access: { has: obj => "pause" in obj, get: obj => obj.pause }, metadata: _metadata }, null, _instanceExtraInitializers);
111
+ __esDecorate(this, null, _stop_decorators, { kind: "method", name: "stop", static: false, private: false, access: { has: obj => "stop" in obj, get: obj => obj.stop }, metadata: _metadata }, null, _instanceExtraInitializers);
112
+ __esDecorate(this, null, _seek_decorators, { kind: "method", name: "seek", static: false, private: false, access: { has: obj => "seek" in obj, get: obj => obj.seek }, metadata: _metadata }, null, _instanceExtraInitializers);
113
+ __esDecorate(null, null, _onEnded_decorators, { kind: "field", name: "onEnded", static: false, private: false, access: { has: obj => "onEnded" in obj, get: obj => obj.onEnded, set: (obj, value) => { obj.onEnded = value; } }, metadata: _metadata }, _onEnded_initializers, _onEnded_extraInitializers);
114
+ __esDecorate(null, null, _onStop_decorators, { kind: "field", name: "onStop", static: false, private: false, access: { has: obj => "onStop" in obj, get: obj => obj.onStop, set: (obj, value) => { obj.onStop = value; } }, metadata: _metadata }, _onStop_initializers, _onStop_extraInitializers);
115
+ __esDecorate(null, null, _onPause_decorators, { kind: "field", name: "onPause", static: false, private: false, access: { has: obj => "onPause" in obj, get: obj => obj.onPause, set: (obj, value) => { obj.onPause = value; } }, metadata: _metadata }, _onPause_initializers, _onPause_extraInitializers);
116
+ __esDecorate(null, null, _onPlay_decorators, { kind: "field", name: "onPlay", static: false, private: false, access: { has: obj => "onPlay" in obj, get: obj => obj.onPlay, set: (obj, value) => { obj.onPlay = value; } }, metadata: _metadata }, _onPlay_initializers, _onPlay_extraInitializers);
117
+ __esDecorate(null, null, _muted_decorators, { kind: "field", name: "muted", static: false, private: false, access: { has: obj => "muted" in obj, get: obj => obj.muted, set: (obj, value) => { obj.muted = value; } }, metadata: _metadata }, _muted_initializers, _muted_extraInitializers);
118
+ __esDecorate(null, null, _volume_decorators, { kind: "field", name: "volume", static: false, private: false, access: { has: obj => "volume" in obj, get: obj => obj.volume, set: (obj, value) => { obj.volume = value; } }, metadata: _metadata }, _volume_initializers, _volume_extraInitializers);
119
+ __esDecorate(null, null, _loop_decorators, { kind: "field", name: "loop", static: false, private: false, access: { has: obj => "loop" in obj, get: obj => obj.loop, set: (obj, value) => { obj.loop = value; } }, metadata: _metadata }, _loop_initializers, _loop_extraInitializers);
120
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
121
+ Audio = _classThis = _classDescriptor.value;
122
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
123
+ __runInitializers(_classThis, _classExtraInitializers);
124
+ }
125
+ _gain = __runInitializers(this, _instanceExtraInitializers);
126
+ _reversed;
127
+ /**
128
+ * @default 0
129
+ */
130
+ _playhead = 0;
131
+ /**
132
+ * @default 1
133
+ */
134
+ _rate = 1;
135
+ _session;
136
+ onEnded = __runInitializers(this, _onEnded_initializers, new Event());
137
+ onStop = (__runInitializers(this, _onEnded_extraInitializers), __runInitializers(this, _onStop_initializers, new Event()));
138
+ onPause = (__runInitializers(this, _onStop_extraInitializers), __runInitializers(this, _onPause_initializers, new Event()));
139
+ onPlay = (__runInitializers(this, _onPause_extraInitializers), __runInitializers(this, _onPlay_initializers, new Event()));
140
+ audioContext = __runInitializers(this, _onPlay_extraInitializers);
141
+ destination;
142
+ audioBuffer;
143
+ /**
144
+ * Creates a new Audio component.
145
+ * @param mgr - The current ContextManager
146
+ * @param props - The constructor properties.
147
+ */
148
+ constructor(mgr, props) {
149
+ super(mgr, props);
150
+ __runInitializers(this, _loop_extraInitializers);
151
+ const audioContextContext = mgr.get(AudioContextContext);
152
+ this.audioContext = useAudioContext(mgr);
153
+ this._gain = this.audioContext.createGain();
154
+ this._gain.connect(audioContextContext.getLayer(props.audioLayer));
155
+ this.destination = this._gain;
156
+ if (!isDesignTime(this.contextManager) && props.autoplay)
157
+ started(mgr).then(() => this.play());
158
+ }
159
+ async _load() {
160
+ const source = this.constructorProps?.source;
161
+ if (!source)
162
+ return;
163
+ const data = await (await fetch(source)).arrayBuffer();
164
+ const audioContext = useAudioContext(this.contextManager);
165
+ this.audioBuffer = await audioContext.decodeAudioData(data);
166
+ }
167
+ _updateVolume = () => {
168
+ this._gain.gain.value = this.muted === true ? 0 : this.volume;
34
169
  };
35
- /** @zprop
36
- * @zdefault false
170
+ /**
171
+ * @default false
172
+ * @zui
37
173
  * @zgroup Audio
38
- * @zgrouppriority 20
39
174
  */
40
- this.muted = new Observable(false, this._updateVolume);
175
+ muted = __runInitializers(this, _muted_initializers, false);
176
+ _getReversed(inp) {
177
+ if (!this._reversed) {
178
+ const audioContext = useAudioContext(this.contextManager);
179
+ this._reversed = audioContext.createBuffer(inp.numberOfChannels, inp.length, inp.sampleRate);
180
+ for (let i = 0; i < inp.numberOfChannels; i++) {
181
+ const source = inp.getChannelData(i);
182
+ const destination = this._reversed.getChannelData(i);
183
+ for (let j = 0; j < inp.length; j++) {
184
+ destination[j] = source[inp.length - j];
185
+ }
186
+ }
187
+ }
188
+ return this._reversed;
189
+ }
41
190
  /**
42
- * @zprop
43
- * @ztype proportion
191
+ * @default 1
192
+ * @zui
44
193
  * @zgroup Audio
45
- * @zgrouppriority 20
46
- * @zdefault 1
194
+ * @ztype proportion
47
195
  */
48
- this.volume = new Observable(1, this._updateVolume);
49
- /** @zprop
50
- * @zdefault false
196
+ volume = (__runInitializers(this, _muted_extraInitializers), __runInitializers(this, _volume_initializers, 1));
197
+ /**
198
+ * @default false
199
+ * @zui
51
200
  * @zgroup Audio
52
- * @zgrouppriority 20
53
201
  */
54
- this.loop = new Observable(false, v => {
202
+ loop = (__runInitializers(this, _volume_extraInitializers), __runInitializers(this, _loop_initializers, false));
203
+ /**
204
+ * @zui
205
+ */
206
+ play(opts) {
207
+ if (!this.audioBuffer)
208
+ return;
55
209
  if (this._session)
56
- this._session.source.loop = v;
57
- });
58
- const audioContextContext = mgr.get(AudioContextContext);
59
- this.audioContext = useAudioContext(mgr);
60
- this._gain = this.audioContext.createGain();
61
- this._gain.connect(audioContextContext.getLayer(props.audioLayer));
62
- this.destination = this._gain;
63
- registerLoadable(mgr, this._load());
64
- if (!isDesignTime(this.contextManager) && props.autoplay)
65
- started(mgr).then(() => this.play());
66
- }
67
- async _load() {
68
- const source = this.constructorProps?.source;
69
- if (!source)
70
- return;
71
- const data = await (await fetch(source)).arrayBuffer();
72
- const audioContext = useAudioContext(this.contextManager);
73
- this.audioBuffer = await audioContext.decodeAudioData(data);
74
- }
75
- _getReversed(inp) {
76
- if (!this._reversed) {
77
- const audioContext = useAudioContext(this.contextManager);
78
- this._reversed = audioContext.createBuffer(inp.numberOfChannels, inp.length, inp.sampleRate);
79
- for (let i = 0; i < inp.numberOfChannels; i++) {
80
- const source = inp.getChannelData(i);
81
- const destination = this._reversed.getChannelData(i);
82
- for (let j = 0; j < inp.length; j++) {
83
- destination[j] = source[inp.length - j];
84
- }
210
+ this._pause();
211
+ this._rate = opts?.speed ?? 1;
212
+ let resolvedPlayhead = this._playhead;
213
+ if (this._rate >= +0) {
214
+ if (this._playhead >= this.audioBuffer.duration)
215
+ this._playhead = 0;
216
+ }
217
+ else {
218
+ if (this._playhead <= 0)
219
+ this._playhead = this.audioBuffer.duration;
220
+ resolvedPlayhead = Math.max(this.audioBuffer.duration - this._playhead, 0);
85
221
  }
222
+ const source = this.audioContext.createBufferSource();
223
+ source.playbackRate.value = Math.abs(this._rate);
224
+ source.buffer = this._rate < 0 ? this._getReversed(this.audioBuffer) : this.audioBuffer;
225
+ source.connect(this.destination);
226
+ source.loop = this.loop;
227
+ const startedAt = this.audioContext.currentTime - resolvedPlayhead / source.playbackRate.value;
228
+ source.start(0, resolvedPlayhead);
229
+ const onEnded = () => {
230
+ if (this.loop) {
231
+ this.onEnded.emit(this);
232
+ this._playhead = 0;
233
+ }
234
+ else {
235
+ this.onEnded.emit(this);
236
+ delete this._session;
237
+ }
238
+ };
239
+ source.addEventListener('ended', onEnded);
240
+ this._session = { source, startedAt };
241
+ this.onPlay.emit(this);
86
242
  }
87
- return this._reversed;
88
- }
89
- /**
90
- * @zprop
91
- * @zui
92
- */
93
- play(opts) {
94
- if (!this.audioBuffer)
95
- return;
96
- if (this._session)
97
- this._pause();
98
- this._rate = opts?.speed ?? 1;
99
- let resolvedPlayhead = this._playhead;
100
- if (this._rate >= +0) {
101
- if (this._playhead >= this.audioBuffer.duration)
102
- this._playhead = 0;
243
+ _pause() {
244
+ if (!this._session)
245
+ return;
246
+ this._playhead = this._session.source.playbackRate.value * (this.audioContext.currentTime - this._session.startedAt);
247
+ if (this._rate < 0)
248
+ this._playhead = (this.audioBuffer?.length ?? 0) - this._playhead;
249
+ this._session.source.stop();
250
+ this._session.source.disconnect();
251
+ delete this._session;
103
252
  }
104
- else {
105
- if (this._playhead <= 0)
106
- this._playhead = this.audioBuffer.duration;
107
- resolvedPlayhead = Math.max(this.audioBuffer.duration - this._playhead, 0);
253
+ /**
254
+ * @zui
255
+ */
256
+ pause() {
257
+ this._pause();
258
+ this.onPause.emit(this);
108
259
  }
109
- const source = this.audioContext.createBufferSource();
110
- source.playbackRate.value = Math.abs(this._rate);
111
- source.buffer = this._rate < 0 ? this._getReversed(this.audioBuffer) : this.audioBuffer;
112
- source.connect(this.destination);
113
- source.loop = this.loop.value;
114
- const startedAt = this.audioContext.currentTime - resolvedPlayhead / source.playbackRate.value;
115
- source.start(0, resolvedPlayhead);
116
- const onEnded = () => {
117
- if (this.loop.value) {
118
- this.onEnded.emit(this);
119
- this._playhead = 0;
120
- }
121
- else {
122
- this.onEnded.emit(this);
123
- delete this._session;
124
- }
125
- };
126
- source.addEventListener('ended', onEnded);
127
- this._session = { source, startedAt };
128
- this.onPlay.emit(this);
129
- }
130
- _pause() {
131
- if (!this._session)
132
- return;
133
- this._playhead = this._session.source.playbackRate.value * (this.audioContext.currentTime - this._session.startedAt);
134
- if (this._rate < 0)
135
- this._playhead = (this.audioBuffer?.length ?? 0) - this._playhead;
136
- this._session.source.stop();
137
- this._session.source.disconnect();
138
- delete this._session;
139
- }
140
- /**
141
- * @zprop
142
- * @zui
143
- */
144
- pause() {
145
- this._pause();
146
- this.onPause.emit(this);
147
- }
148
- /**
149
- * @zprop
150
- * @zui
151
- */
152
- stop() {
153
- this._pause();
154
- this._playhead = 0;
155
- this.onStop.emit(this);
156
- }
157
- /**
158
- * @zprop
159
- * @zui
160
- */
161
- seek(/** @ztype time-milliseconds */ t) {
162
- const previousSession = this._session;
163
- if (previousSession)
260
+ /**
261
+ * @zui
262
+ */
263
+ stop() {
164
264
  this._pause();
165
- this._playhead = t / 1000;
166
- if (previousSession)
167
- this.play({ speed: this._rate });
168
- }
169
- length() {
170
- return this.audioBuffer ? this.audioBuffer.duration * 1000 : undefined;
171
- }
172
- dispose() {
173
- this.stop();
174
- this._gain.disconnect();
175
- return super.dispose();
176
- }
177
- }
265
+ this._playhead = 0;
266
+ this.onStop.emit(this);
267
+ }
268
+ /**
269
+ * @zui
270
+ */
271
+ seek(t) {
272
+ const previousSession = this._session;
273
+ if (previousSession)
274
+ this._pause();
275
+ this._playhead = t / 1000;
276
+ if (previousSession)
277
+ this.play({ speed: this._rate });
278
+ }
279
+ length() {
280
+ return this.audioBuffer ? this.audioBuffer.duration * 1000 : undefined;
281
+ }
282
+ dispose() {
283
+ this.stop();
284
+ this._gain.disconnect();
285
+ return super.dispose();
286
+ }
287
+ };
288
+ return Audio = _classThis;
289
+ })();
290
+ export { Audio };
@@ -1,32 +1,34 @@
1
1
  import { Component } from '../component';
2
2
  import { ContextManager } from '../context';
3
- import { Observable } from '../observable';
4
3
  interface AudioLayerSettingsConstuctorProps {
5
4
  /**
6
- * @zprop
7
- * @zdefault default
5
+ *
6
+ * @default default
8
7
  */
9
8
  layer?: string;
10
9
  }
11
10
  /**
12
11
  * Audio layer settings.
13
12
  * @zcomponent
14
- * @ztag core/audiolayersettings
15
- * @zgroup Media
16
13
  * @zicon volume_up
14
+ * @zgroup Media
15
+ * @ztag core/audiolayersettings
17
16
  */
18
17
  export declare class AudioLayerSettings extends Component<undefined, AudioLayerSettingsConstuctorProps> {
18
+ /**
19
+ * The volume of the layer.
20
+ *
21
+ * Default is 1.
22
+ * @default 1
23
+ * @zui
24
+ * @ztype proportion
25
+ */
26
+ volume: number;
19
27
  /**
20
28
  * Creates a new AudioLayerSettings component.
21
29
  * @param contextManager - The current ContextManager
22
30
  * @param props - The constructor properties.
23
31
  */
24
32
  constructor(contextManager: ContextManager, props: AudioLayerSettingsConstuctorProps);
25
- /**
26
- * @zprop
27
- * @ztype proportion
28
- * @zdefault 1
29
- */
30
- readonly volume: Observable<number, never>;
31
33
  }
32
34
  export {};