UNPKG

@kelvininc/ui-components

Version:
50 lines (46 loc) 2.12 kB
'use strict'; var index = require('./index-DpuMIXDY.js'); require('./components-D2lyDQ_a.js'); var libConfig = require('./lib-config-QLtHwxiM.js'); require('./action-button.types-BYOe6st0.js'); require('./absolute-time-picker-dropdown.types-mPwO9zQk.js'); require('./icon.types-B8lvUrX_.js'); require('./summary-card.types-W26sTdH1.js'); require('./toaster.types-DlSCye8T.js'); require('./tree-item.types-C2yRoORC.js'); require('./tag-alarm.types-BeZw-7PT.js'); require('./wizard.types-DTbE-B6d.js'); var config = require('./config-TIjltaxO.js'); var get = require('./get-DhNVP9X1.js'); const initialize = (userConfig = {}) => { var _a, _b; const defaultStyleMode = get.get(userConfig, 'styleMode', libConfig.StyleMode.Night); const { document: doc, window: win } = window; doc.body.setAttribute('mode', defaultStyleMode); const isKvElement = (elm) => elm.tagName && elm.tagName.startsWith('KV-'); const isAllowedStyleModeValue = (elmMode) => Object.values(libConfig.StyleMode).includes(elmMode); index.setMode((elm) => { while (elm) { const elmMode = elm.mode || elm.getAttribute('mode'); if (elmMode) { if (isAllowedStyleModeValue(elmMode)) { return elmMode; } else if (isKvElement(elm)) { console.warn(`Invalid kv-component mode: ${elmMode}, expected: ${Object.values(libConfig.StyleMode).join(',')}`); } } // TODO: check with more time why cant obtain the parentElement // elm = elm.parentElement; elm = doc.body; } return defaultStyleMode; }); if (typeof win === 'undefined') { return; } const instance = (win.KvUiComponents = (_a = win.KvUiComponents) !== null && _a !== void 0 ? _a : {}); const actualConfig = (instance.config = (_b = instance.config) !== null && _b !== void 0 ? _b : {}); win.KvUiComponents.config = Object.assign(Object.assign(Object.assign({}, config.DEFAULT_CONFIG), actualConfig), userConfig); }; exports.initialize = initialize;