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.

89 lines (86 loc) 2.54 kB
/*! * NENT 2022 */ import { r as registerInstance, h, H as Host } from './index-916ca544.js'; import { g as getDataProvider } from './factory-acbf0d3d.js'; import { s as state, o as onChange } from './state-627a24e0.js'; import { a as state$1, o as onChange$1 } from './state-27a8a5bc.js'; import './index-f7016b94.js'; import './interfaces-8c5cd1b8.js'; import './index-4bfabbbd.js'; import './values-ddfac998.js'; import './promises-584c4ece.js'; import './logging-5a93c8af.js'; const AudioSwitch = class { constructor(hostRef) { registerInstance(this, hostRef); this.storage = null; /** * Which state property this switch controls. */ this.setting = 'enabled'; /** * The data provider to store the audio state in. */ this.dataProvider = 'storage'; } get stateKey() { return `audio-${this.setting}`; } setValue(value) { switch (this.setting) { case 'enabled': { state$1.audioEnabled = value; break; } case 'muted': { state.muted = value; break; } } } getValue() { switch (this.setting) { case 'enabled': { return state$1.audioEnabled; } case 'muted': { return state.muted; } } } async componentWillLoad() { var _a; this.storage = (await getDataProvider(this.dataProvider)); if (this.storage) { const value = await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.get(this.stateKey)); if (value != null) { this.setValue(value == 'true'); } } this.subscription = this.setting == 'muted' ? onChange('muted', async (m) => { var _a; await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.set(this.stateKey, m.toString())); }) : onChange$1('audioEnabled', async (m) => { var _a; await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.set(this.stateKey, m.toString())); }); } toggle() { var _a; this.setValue(((_a = this.checkbox) === null || _a === void 0 ? void 0 : _a.checked) || false); } disconnectedCallback() { var _a; (_a = this.subscription) === 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.toggle(), checked: this.getValue() }))); } }; export { AudioSwitch as n_audio_switch };