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.

98 lines (93 loc) 2.81 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 logging = require('./logging-37c154cf.js'); const interfaces = require('./interfaces-f9ceab29.js'); const state = require('./state-9c7a0826.js'); const tracks = require('./tracks-10e1ccb7.js'); require('./index-96f3ab3f.js'); require('./mutex-7ae5ebad.js'); require('./factory-0d7ddff9.js'); require('./interfaces-95d0415a.js'); require('./values-b2399e33.js'); require('./promises-463f4e01.js'); require('./memory-33fe6263.js'); const AudioSoundLoad = 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 = '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: 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: false, type: interfaces.AudioType.sound, 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) { const trackPlayed = await tracks.playedTrack(this.trackId); if (this.mode == 'play' && trackPlayed) return; index$1.actionBus.emit(action.topic, action); } else { this.dispose = state.onChange('hasAudioComponent', async (loaded) => { if (loaded) { index$1.actionBus.emit(action.topic, action); logging.debugIf(state.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 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_sound_load = AudioSoundLoad;