UNPKG

@copoko/maxwell

Version:
57 lines (54 loc) 2.11 kB
/*! * ========================================================================== * "CoPoKo Maxwell" License * GNU General Public License version 3.0 (GPLv3) * ========================================================================== * This file is part of "CoPoKo Maxwell" * * "CoPoKo Maxwell" is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * "CoPoKo Maxwell" is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with "CoPoKo Maxwell". If not, see <http://www.gnu.org/licenses/>. * ========================================================================== */ import './style/style.scss' import { defaultConf } from './default' import Config from './types/config' import MaxwellContext from './context' export default class Maxwell { public conf: Config public $root!: HTMLElement public ctx: any constructor(conf: Partial<Config>) { this.conf = Maxwell.initConf(conf) if (this.conf.el instanceof HTMLElement) this.$root = this.conf.el this.ctx = new MaxwellContext(this.conf) this.initComponents() } private initComponents() { } public static readonly defaultConf: Config = defaultConf private static initConf(conf: Partial<Config>): Config { const config = Object.assign(defaultConf, conf) if (typeof config.id === 'string' && !!config.id) { try { const El = document.querySelector<HTMLElement>(config.id) if (!El) throw Error(`HTMLElement "${config.id}" was not found.`) config.el = El } catch (e) { console.error(e) throw new Error('Please check your `id` config.') } } config.api = config.api.replace(/\/$/, '') return config } }