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.

61 lines (57 loc) 2.03 kB
/*! * NENT 2022 */ import { r as registerInstance, h, H as Host } from './index-916ca544.js'; import { e as eventBus } from './index-f7016b94.js'; import { g as getDataProvider } from './factory-acbf0d3d.js'; import { c as createStore } from './index-4bfabbbd.js'; import { b as VIDEO_EVENTS } from './interfaces-32699e3c.js'; import './interfaces-8c5cd1b8.js'; import './values-ddfac998.js'; import './promises-584c4ece.js'; import './logging-5a93c8af.js'; /* istanbul ignore file */ const store = createStore({ autoplay: true, }); const { state, onChange, reset, dispose } = store; const VideoSwitch = class { constructor(hostRef) { registerInstance(this, hostRef); this.enabledKey = 'autoplay'; this.storage = null; this.autoPlay = true; /** * The data provider to store the audio-enabled state in. */ this.dataProvider = 'storage'; } async componentWillLoad() { this.autoPlay = state.autoplay; this.storage = (await getDataProvider(this.dataProvider)); if (this.storage) { const autoplay = await this.storage.get(this.enabledKey); state.autoplay = autoplay !== 'false'; } this.videoSubscription = onChange('autoplay', async (a) => { var _a; this.autoPlay = a; await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.set(this.enabledKey, a.toString())); eventBus === null || eventBus === void 0 ? void 0 : eventBus.emit(VIDEO_EVENTS.AutoPlayChanged, a); }); } toggleAutoPlay() { var _a; state.autoplay = ((_a = this.checkbox) === null || _a === void 0 ? void 0 : _a.checked) || false; } disconnectedCallback() { var _a; (_a = this.videoSubscription) === null || _a === void 0 ? void 0 : _a.call(this); } render() { return (h(Host, null, h("input", { type: "checkbox", class: this.inputClass, id: this.inputId, ref: e => { this.checkbox = e; }, onChange: () => this.toggleAutoPlay(), checked: this.autoPlay }))); } }; export { VideoSwitch as n_video_switch };