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 (89 loc) 2.62 kB
/*! * NENT 2022 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-1829aebc.js'); const index$1 = require('./index-637e8c28.js'); const interfaces = require('./interfaces-f9ceab29.js'); const state = require('./state-9c7a0826.js'); const logging = require('./logging-37c154cf.js'); require('./index-96f3ab3f.js'); const AudioMusicLoad = class { constructor(hostRef) { index.registerInstance(this, hostRef); 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: interfaces.AUDIO_TOPIC, command: this.mode || interfaces.LoadStrategy.load, data: { trackId: this.trackId || this.src, src: this.src, discard: this.discard || interfaces.DiscardStrategy.route, loop: this.loop, type: interfaces.AudioType.music, mode: this.mode || interfaces.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.state.hasAudioComponent) { index$1.actionBus.emit(action.topic, action); } else { this.dispose = state.onChange('hasAudioComponent', async (loaded) => { var _a; if (loaded) { index$1.actionBus.emit(action.topic, action); logging.debugIf(state.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 index.h(index.Host, null); } disconnectedCallback() { var _a; (_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this); } get el() { return index.getElement(this); } }; exports.n_audio_action_music_load = AudioMusicLoad;