@nent/core
Version:
117 lines (113 loc) • 3.28 kB
JavaScript
/*!
* NENT 2022
*/
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { a as actionBus } from './index2.js';
import { a as AUDIO_TOPIC, L as LoadStrategy, D as DiscardStrategy, c as AudioType } from './interfaces2.js';
import { s as state, o as onChange } from './state3.js';
import { f as debugIf } from './logging.js';
const AudioMusicLoad = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.__attachShadow();
this.sent = false;
/**
* This is the loading strategy that determines
* what it should do after the file is retrieved.
*/
this.mode = 'queue';
/**
* The discard strategy the player should use for this file.
*/
this.discard = 'route';
/**
* Set this to true to have the audio file loop.
*/
this.loop = false;
/**
* If set, disables auto-rendering of this instance.
* To fetch the contents change to false or remove
* attribute.
*/
this.deferLoad = false;
}
/**
* Get the underlying actionEvent instance.
*/
async getAction() {
return {
topic: AUDIO_TOPIC,
command: this.mode || LoadStrategy.load,
data: {
trackId: this.trackId || this.src,
src: this.src,
discard: this.discard || DiscardStrategy.route,
loop: this.loop,
type: AudioType.music,
mode: this.mode || LoadStrategy.load,
},
};
}
/**
* Send this action to the the action messaging system.
*/
async sendAction(data) {
const action = await this.getAction();
if (data)
Object.assign(action.data, data);
if (state.hasAudioComponent) {
actionBus.emit(action.topic, action);
}
else {
this.dispose = onChange('hasAudioComponent', async (loaded) => {
var _a;
if (loaded) {
actionBus.emit(action.topic, action);
debugIf(state.debug, `n-audio-action-music-load: load-action sent for ${this.trackId}`);
this.sent = true;
}
(_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this);
});
}
}
async componentWillRender() {
if (this.deferLoad || this.sent)
return;
await this.sendAction();
}
render() {
return h(Host, null);
}
disconnectedCallback() {
var _a;
(_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this);
}
get el() { return this; }
}, [1, "n-audio-action-music-load", {
"src": [1],
"trackId": [1, "track-id"],
"mode": [1],
"discard": [1],
"loop": [4],
"deferLoad": [1028, "defer-load"],
"sent": [32],
"getAction": [64],
"sendAction": [64]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["n-audio-action-music-load"];
components.forEach(tagName => { switch (tagName) {
case "n-audio-action-music-load":
if (!customElements.get(tagName)) {
customElements.define(tagName, AudioMusicLoad);
}
break;
} });
}
const NAudioActionMusicLoad = AudioMusicLoad;
const defineCustomElement = defineCustomElement$1;
export { NAudioActionMusicLoad, defineCustomElement };