@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.
- package/README.md +1 -0
- package/css/zcomponent.css +121 -122
- package/index.js +0 -3
- package/lib/actionbehavior.d.ts +3 -3
- package/lib/actionbehavior.js +20 -19
- package/lib/animation/animation.d.ts +13 -6
- package/lib/animation/animation.js +56 -43
- package/lib/animation/bezier.d.ts +6 -0
- package/lib/animation/bezier.js +8 -2
- package/lib/animation/clips/clip.d.ts +13 -1
- package/lib/animation/clips/clip.js +34 -14
- package/lib/animation/index.d.ts +4 -4
- package/lib/animation/index.js +4 -4
- package/lib/animation/layer.d.ts +9 -0
- package/lib/animation/layer.js +28 -12
- package/lib/animation/layerclip.d.ts +21 -0
- package/lib/animation/layerclip.js +82 -45
- package/lib/animation/tracks/cliptrack.d.ts +18 -0
- package/lib/animation/tracks/cliptrack.js +27 -6
- package/lib/animation/tracks/functiontrack.d.ts +9 -0
- package/lib/animation/tracks/functiontrack.js +16 -3
- package/lib/animation/tracks/propertytrack.d.ts +20 -1
- package/lib/animation/tracks/propertytrack.js +48 -11
- package/lib/animation/tracks/streamtrack.d.ts +18 -0
- package/lib/animation/tracks/streamtrack.js +32 -6
- package/lib/animation/tracks/track.d.ts +8 -2
- package/lib/animation/tracks/track.js +3 -2
- package/lib/behavior.js +13 -10
- package/lib/behaviors/ActivateState.d.ts +22 -24
- package/lib/behaviors/ActivateState.js +145 -35
- package/lib/behaviors/CallFunction.d.ts +2 -4
- package/lib/behaviors/CallFunction.js +69 -11
- package/lib/behaviors/ChangeRootScene.d.ts +35 -0
- package/lib/behaviors/ChangeRootScene.js +123 -0
- package/lib/behaviors/ConsoleLog.d.ts +6 -5
- package/lib/behaviors/ConsoleLog.js +95 -12
- package/lib/behaviors/DownloadSnapshot.d.ts +7 -12
- package/lib/behaviors/DownloadSnapshot.js +70 -19
- package/lib/behaviors/EmitComponentPropEvent.d.ts +1 -3
- package/lib/behaviors/EmitComponentPropEvent.js +80 -12
- package/lib/behaviors/LaunchURL.d.ts +5 -5
- package/lib/behaviors/LaunchURL.js +92 -10
- package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -4
- package/lib/behaviors/LogAnalyticsEvent.js +88 -7
- package/lib/behaviors/PauseLayerClip.d.ts +7 -9
- package/lib/behaviors/PauseLayerClip.js +89 -21
- package/lib/behaviors/PlayLayerClip.d.ts +35 -32
- package/lib/behaviors/PlayLayerClip.js +202 -48
- package/lib/behaviors/PlaySound.d.ts +19 -25
- package/lib/behaviors/PlaySound.js +122 -28
- package/lib/behaviors/SetLayerOff.d.ts +7 -9
- package/lib/behaviors/SetLayerOff.js +88 -21
- package/lib/behaviors/ShareSnapshot.d.ts +5 -9
- package/lib/behaviors/ShareSnapshot.js +70 -17
- package/lib/behaviors/ShowTextAlert.d.ts +16 -29
- package/lib/behaviors/ShowTextAlert.js +116 -48
- package/lib/behaviors/TakeSnapshot.d.ts +22 -26
- package/lib/behaviors/TakeSnapshot.js +131 -56
- package/lib/behaviors/ToggleLayerClips.d.ts +45 -62
- package/lib/behaviors/ToggleLayerClips.js +233 -64
- package/lib/behaviors/stream/PauseStream.d.ts +5 -16
- package/lib/behaviors/stream/PauseStream.js +94 -34
- package/lib/behaviors/stream/PlayStream.d.ts +14 -27
- package/lib/behaviors/stream/PlayStream.js +123 -34
- package/lib/behaviors/stream/SeekStream.d.ts +8 -18
- package/lib/behaviors/stream/SeekStream.js +97 -31
- package/lib/behaviors/stream/StopStream.d.ts +6 -15
- package/lib/behaviors/stream/StopStream.js +89 -27
- package/lib/component.d.ts +36 -13
- package/lib/component.js +237 -151
- package/lib/components/AnimatedLoader.d.ts +51 -0
- package/lib/components/AnimatedLoader.js +159 -0
- package/lib/components/Audio.d.ts +35 -37
- package/lib/components/Audio.js +264 -151
- package/lib/components/AudioLayerSettings.d.ts +13 -11
- package/lib/components/AudioLayerSettings.js +76 -18
- package/lib/components/Children.d.ts +2 -1
- package/lib/components/Children.js +66 -13
- package/lib/components/ConditionalConstruct.d.ts +44 -0
- package/lib/components/ConditionalConstruct.js +142 -0
- package/lib/components/DefaultCookieConsent.d.ts +53 -73
- package/lib/components/DefaultCookieConsent.js +382 -264
- package/lib/components/DefaultLoader.d.ts +40 -28
- package/lib/components/DefaultLoader.js +198 -46
- package/lib/components/Gamepad.d.ts +5 -26
- package/lib/components/Gamepad.js +201 -65
- package/lib/components/LoaderScope.d.ts +15 -0
- package/lib/components/LoaderScope.js +71 -0
- package/lib/components/LongLoad.d.ts +11 -15
- package/lib/components/LongLoad.js +89 -34
- package/lib/components/SnapshotUI.d.ts +19 -24
- package/lib/components/SnapshotUI.js +202 -105
- package/lib/context.d.ts +23 -5
- package/lib/context.js +12 -6
- package/lib/contexts/analyticscontext.d.ts +12 -2
- package/lib/contexts/analyticscontext.js +68 -10
- package/lib/contexts/audiocontextcontext.d.ts +1 -1
- package/lib/contexts/audiocontextcontext.js +9 -8
- package/lib/contexts/canvascontext.d.ts +32 -18
- package/lib/contexts/canvascontext.js +195 -120
- package/lib/contexts/cookieconsentcontext.d.ts +38 -28
- package/lib/contexts/cookieconsentcontext.js +35 -32
- package/lib/contexts/documentflagmanager.js +15 -11
- package/lib/contexts/environmentcontext.d.ts +22 -6
- package/lib/contexts/environmentcontext.js +135 -21
- package/lib/contexts/gamepadcontext.d.ts +29 -26
- package/lib/contexts/gamepadcontext.js +46 -46
- package/lib/contexts/gesturecontext.d.ts +31 -6
- package/lib/contexts/gesturecontext.js +110 -85
- package/lib/contexts/globaltagcontext.d.ts +1 -1
- package/lib/contexts/globaltagcontext.js +8 -11
- package/lib/contexts/loadcontext.d.ts +45 -8
- package/lib/contexts/loadcontext.js +232 -82
- package/lib/contexts/orientationcontext.d.ts +13 -15
- package/lib/contexts/orientationcontext.js +150 -67
- package/lib/contexts/rootcomponentscontext.d.ts +16 -0
- package/lib/contexts/rootcomponentscontext.js +65 -0
- package/lib/contexts/snapshotContext.d.ts +0 -3
- package/lib/contexts/snapshotContext.js +78 -23
- package/lib/contexts/tagcontext.d.ts +5 -5
- package/lib/contexts/tagcontext.js +16 -16
- package/lib/contexts/textalertcontext.d.ts +1 -5
- package/lib/contexts/textalertcontext.js +1 -5
- package/lib/contexts/usereventcontext.d.ts +1 -1
- package/lib/contexts/usereventcontext.js +12 -12
- package/lib/data/animation.d.ts +10 -2
- package/lib/data/change.d.ts +1 -1
- package/lib/data/change.js +7 -0
- package/lib/data/core.d.ts +9 -1
- package/lib/data/index.d.ts +1 -1
- package/lib/data/index.js +1 -1
- package/lib/decorators.d.ts +348 -0
- package/lib/decorators.js +239 -0
- package/lib/decoratorutils.d.ts +3 -0
- package/lib/decoratorutils.js +8 -0
- package/lib/emitter.d.ts +15 -2
- package/lib/emitter.js +15 -6
- package/lib/entity.d.ts +43 -25
- package/lib/entity.js +104 -71
- package/lib/event.d.ts +2 -1
- package/lib/event.js +1 -4
- package/lib/groups.d.ts +18 -0
- package/lib/groups.js +19 -0
- package/lib/icons.d.ts +3372 -0
- package/lib/icons.js +1 -0
- package/lib/index.d.ts +18 -13
- package/lib/index.js +17 -13
- package/lib/inflate.d.ts +7 -7
- package/lib/inflate.js +5 -5
- package/lib/observable.d.ts +9 -2
- package/lib/observable.js +5 -4
- package/lib/observe.d.ts +18 -0
- package/lib/observe.js +177 -0
- package/lib/profile.d.ts +9 -5
- package/lib/profile.js +27 -17
- package/lib/selectors.d.ts +1 -1
- package/lib/selectors.js +5 -4
- package/lib/types.d.ts +161 -19
- package/lib/types.js +22 -1
- package/lib/values/values.d.ts +7 -8
- package/lib/values/values.js +1 -2
- package/lib/values/valuesmutator.d.ts +4 -1
- package/lib/values/valuesmutator.js +10 -8
- package/lib/zcomponent.d.ts +21 -10
- package/lib/zcomponent.js +717 -540
- package/package.json +22 -5
- package/lib/behaviors/ChangeCursor.d.ts +0 -39
- 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 {
|
|
5
|
+
import { ProjectFile } from '../types';
|
|
6
6
|
export interface AudioConstructorProps {
|
|
7
|
-
|
|
8
|
-
* @zvalues files *.+(mp3|wav)
|
|
9
|
-
*/
|
|
10
|
-
source: string;
|
|
7
|
+
source: ProjectFile<'*.+(mp3|wav)'>;
|
|
11
8
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
9
|
+
*
|
|
10
|
+
* @default default
|
|
14
11
|
*/
|
|
15
12
|
audioLayer?: string;
|
|
16
|
-
/**
|
|
17
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
/**
|
|
54
|
-
* @
|
|
56
|
+
/**
|
|
57
|
+
* @default false
|
|
58
|
+
* @zui
|
|
55
59
|
* @zgroup Audio
|
|
56
|
-
* @zgrouppriority 20
|
|
57
60
|
*/
|
|
58
|
-
|
|
61
|
+
muted: boolean;
|
|
59
62
|
private _getReversed;
|
|
60
63
|
/**
|
|
61
|
-
* @
|
|
62
|
-
* @
|
|
64
|
+
* @default 1
|
|
65
|
+
* @zui
|
|
63
66
|
* @zgroup Audio
|
|
64
|
-
* @
|
|
65
|
-
* @zdefault 1
|
|
67
|
+
* @ztype proportion
|
|
66
68
|
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @
|
|
69
|
+
volume: number;
|
|
70
|
+
/**
|
|
71
|
+
* @default false
|
|
72
|
+
* @zui
|
|
70
73
|
* @zgroup Audio
|
|
71
|
-
* @zgrouppriority 20
|
|
72
74
|
*/
|
|
73
|
-
|
|
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(
|
|
92
|
+
seek(t: number): void;
|
|
95
93
|
length(): number | undefined;
|
|
96
94
|
dispose(): never;
|
|
97
95
|
}
|
package/lib/components/Audio.js
CHANGED
|
@@ -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 {
|
|
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
|
-
* @
|
|
49
|
+
* @zgroup Media
|
|
50
|
+
* @ztag core/audio
|
|
17
51
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
/**
|
|
36
|
-
* @
|
|
170
|
+
/**
|
|
171
|
+
* @default false
|
|
172
|
+
* @zui
|
|
37
173
|
* @zgroup Audio
|
|
38
|
-
* @zgrouppriority 20
|
|
39
174
|
*/
|
|
40
|
-
|
|
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
|
-
* @
|
|
43
|
-
* @
|
|
191
|
+
* @default 1
|
|
192
|
+
* @zui
|
|
44
193
|
* @zgroup Audio
|
|
45
|
-
* @
|
|
46
|
-
* @zdefault 1
|
|
194
|
+
* @ztype proportion
|
|
47
195
|
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @
|
|
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
|
-
|
|
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.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
253
|
+
/**
|
|
254
|
+
* @zui
|
|
255
|
+
*/
|
|
256
|
+
pause() {
|
|
257
|
+
this._pause();
|
|
258
|
+
this.onPause.emit(this);
|
|
108
259
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
*
|
|
7
|
-
* @
|
|
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 {};
|