UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

114 lines (110 loc) 3.23 kB
/*! * NENT 2022 */ import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client'; import { a as actionBus } from './index2.js'; import { f as debugIf } from './logging.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 { p as playedTrack } from './tracks.js'; const AudioSoundLoad = /*@__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 = 'load'; /** * The discard strategy the player should use for this file. */ this.discard = 'route'; /** * 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: false, type: AudioType.sound, 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) { const trackPlayed = await playedTrack(this.trackId); if (this.mode == 'play' && trackPlayed) return; actionBus.emit(action.topic, action); } else { this.dispose = onChange('hasAudioComponent', async (loaded) => { if (loaded) { actionBus.emit(action.topic, action); debugIf(state.debug, `n-audio-action-sound-load: load-action sent for ${this.trackId}`); this.sent = true; } }); } } 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-sound-load", { "src": [1], "trackId": [1, "track-id"], "mode": [1], "discard": [1], "deferLoad": [1028, "defer-load"], "sent": [32], "getAction": [64], "sendAction": [64] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["n-audio-action-sound-load"]; components.forEach(tagName => { switch (tagName) { case "n-audio-action-sound-load": if (!customElements.get(tagName)) { customElements.define(tagName, AudioSoundLoad); } break; } }); } const NAudioActionSoundLoad = AudioSoundLoad; const defineCustomElement = defineCustomElement$1; export { NAudioActionSoundLoad, defineCustomElement };