@zcomponent/html 1.2.0 → 1.3.0-beta
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/lib/audio.d.ts +40 -0
- package/lib/audio.js +67 -0
- package/package.json +2 -2
package/lib/audio.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ContextManager, Observable, PlayOptions, Stream } from '@zcomponent/core';
|
|
2
|
+
import { HTMLElementProps, ZHTMLElement } from './HTMLElement';
|
|
3
|
+
export interface AudioConstructorProps extends HTMLElementProps {
|
|
4
|
+
/** @zprop
|
|
5
|
+
* @zvalues files *.+(mp3|wav)
|
|
6
|
+
*/
|
|
7
|
+
source: string;
|
|
8
|
+
/** @zprop
|
|
9
|
+
* @zdefault false
|
|
10
|
+
*/
|
|
11
|
+
autoplay: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @zcomponent
|
|
15
|
+
* @ztag html/element/audio
|
|
16
|
+
* @zgroup Media
|
|
17
|
+
* @zicon music_note
|
|
18
|
+
* @zstream
|
|
19
|
+
*/
|
|
20
|
+
export declare class Audio extends ZHTMLElement<HTMLAudioElement> implements Stream {
|
|
21
|
+
private _hadUserEvent;
|
|
22
|
+
/** @zprop
|
|
23
|
+
* @zdefault false
|
|
24
|
+
* @zgroup Audio
|
|
25
|
+
* @zgrouppriority 20
|
|
26
|
+
*/
|
|
27
|
+
muted: Observable<boolean, never>;
|
|
28
|
+
constructor(mgr: ContextManager, props: AudioConstructorProps);
|
|
29
|
+
private _updateMute;
|
|
30
|
+
/** @zprop */
|
|
31
|
+
play(opts?: PlayOptions): void;
|
|
32
|
+
/** @zprop */
|
|
33
|
+
pause(): void;
|
|
34
|
+
/** @zprop */
|
|
35
|
+
stop(): void;
|
|
36
|
+
/** @zprop */
|
|
37
|
+
seek(t: number): void;
|
|
38
|
+
length(): number | undefined;
|
|
39
|
+
dispose(): never;
|
|
40
|
+
}
|
package/lib/audio.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isDesignTime, nextUserEvent, Observable, registerLoadable, started } from '@zcomponent/core';
|
|
2
|
+
import { ZHTMLElement } from './HTMLElement';
|
|
3
|
+
/**
|
|
4
|
+
* @zcomponent
|
|
5
|
+
* @ztag html/element/audio
|
|
6
|
+
* @zgroup Media
|
|
7
|
+
* @zicon music_note
|
|
8
|
+
* @zstream
|
|
9
|
+
*/
|
|
10
|
+
export class Audio extends ZHTMLElement {
|
|
11
|
+
constructor(mgr, props) {
|
|
12
|
+
const elm = document.createElement('audio');
|
|
13
|
+
elm.muted = true;
|
|
14
|
+
registerLoadable(mgr, new Promise((resolve, reject) => {
|
|
15
|
+
elm.src = props.source;
|
|
16
|
+
elm.addEventListener('canplaythrough', () => resolve());
|
|
17
|
+
elm.addEventListener('error', () => reject());
|
|
18
|
+
}));
|
|
19
|
+
super(mgr, props, elm);
|
|
20
|
+
this._hadUserEvent = false;
|
|
21
|
+
/** @zprop
|
|
22
|
+
* @zdefault false
|
|
23
|
+
* @zgroup Audio
|
|
24
|
+
* @zgrouppriority 20
|
|
25
|
+
*/
|
|
26
|
+
this.muted = new Observable(false);
|
|
27
|
+
this._updateMute = () => {
|
|
28
|
+
if (!this.element || !this._hadUserEvent)
|
|
29
|
+
return;
|
|
30
|
+
this.element.muted = this.muted.value;
|
|
31
|
+
};
|
|
32
|
+
this.register(this.muted, this._updateMute);
|
|
33
|
+
nextUserEvent(mgr).then(() => {
|
|
34
|
+
this._hadUserEvent = true;
|
|
35
|
+
this._updateMute();
|
|
36
|
+
});
|
|
37
|
+
if (!isDesignTime(this.contextManager) && props.autoplay)
|
|
38
|
+
started(mgr).then(() => this.play());
|
|
39
|
+
elm.load();
|
|
40
|
+
}
|
|
41
|
+
/** @zprop */
|
|
42
|
+
play(opts) {
|
|
43
|
+
this.element.playbackRate = opts?.speed ?? 1;
|
|
44
|
+
this.element.play();
|
|
45
|
+
}
|
|
46
|
+
/** @zprop */
|
|
47
|
+
pause() {
|
|
48
|
+
this.element.pause();
|
|
49
|
+
}
|
|
50
|
+
/** @zprop */
|
|
51
|
+
stop() {
|
|
52
|
+
this.element.pause();
|
|
53
|
+
this.element.currentTime = 0;
|
|
54
|
+
}
|
|
55
|
+
/** @zprop */
|
|
56
|
+
seek(t) {
|
|
57
|
+
this.element.currentTime = t / 1000;
|
|
58
|
+
}
|
|
59
|
+
length() {
|
|
60
|
+
return isNaN(this.element.duration) ? undefined : this.element.duration * 1000;
|
|
61
|
+
}
|
|
62
|
+
dispose() {
|
|
63
|
+
this.element.pause();
|
|
64
|
+
this.element.src = '';
|
|
65
|
+
return super.dispose();
|
|
66
|
+
}
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zcomponent/html",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"author": "Zappar Limited",
|
|
19
19
|
"license": "Proprietary",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@zcomponent/core": "1.
|
|
21
|
+
"@zcomponent/core": "^1.2.0-beta"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^4.9.4"
|