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.

94 lines (91 loc) 2.74 kB
/*! * NENT 2022 */ import { r as registerInstance, h, a as getElement, H as Host } from './index-916ca544.js'; import { a as actionBus } from './index-f7016b94.js'; import { f as debugIf } from './logging-5a93c8af.js'; import { a as AUDIO_TOPIC, L as LoadStrategy, D as DiscardStrategy, c as AudioType } from './interfaces-13ff7aec.js'; import { s as state, o as onChange } from './state-627a24e0.js'; import { p as playedTrack } from './tracks-667892d6.js'; import './index-4bfabbbd.js'; import './mutex-e5645c85.js'; import './factory-acbf0d3d.js'; import './interfaces-8c5cd1b8.js'; import './values-ddfac998.js'; import './promises-584c4ece.js'; import './memory-0d63dacd.js'; const AudioSoundLoad = class { constructor(hostRef) { registerInstance(this, hostRef); 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 getElement(this); } }; export { AudioSoundLoad as n_audio_action_sound_load };