/*!
* Bootstrap config.js v5.3.1 (https://getbootstrap.com/)
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/manipulator.js'), require('./index.js')) :
typeof define === 'function' && define.amd ? define(['../dom/manipulator', './index'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Config = factory(global.Manipulator, global.Index));
})(this, (function (Manipulator, index_js) { 'use strict';
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
/**
* Class definition
*/
var Config = /*#__PURE__*/function () {
function Config() {}
var _proto = Config.prototype;
_proto._getConfig = function _getConfig(config) {
config = this._mergeConfigObj(config);
config = this._configAfterMerge(config);
this._typeCheckConfig(config);
return config;
};
_proto._configAfterMerge = function _configAfterMerge(config) {
return config;
};
_proto._mergeConfigObj = function _mergeConfigObj(config, element) {
var jsonConfig = index_js.isElement(element) ? Manipulator.getDataAttribute(element, 'config') : {}; // try to parse
return _extends({}, this.constructor.Default, typeof jsonConfig === 'object' ? jsonConfig : {}, index_js.isElement(element) ? Manipulator.getDataAttributes(element) : {}, typeof config === 'object' ? config : {});
};
_proto._typeCheckConfig = function _typeCheckConfig(config, configTypes) {
if (configTypes === void 0) {
configTypes = this.constructor.DefaultType;
}
for (var _i = 0, _Object$entries = Object.entries(configTypes); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _Object$entries[_i],
property = _Object$entries$_i[0],
expectedTypes = _Object$entries$_i[1];
var value = config[property];
var valueType = index_js.isElement(value) ? 'element' : index_js.toType(value);
if (!new RegExp(expectedTypes).test(valueType)) {
throw new TypeError(this.constructor.NAME.toUpperCase() + ": Option \"" + property + "\" provided type \"" + valueType + "\" but expected type \"" + expectedTypes + "\".");
}
}
};
_createClass(Config, null, [{
key: "Default",
get:
// Getters
function get() {
return {};
}
}, {
key: "DefaultType",
get: function get() {
return {};
}
}, {
key: "NAME",
get: function get() {
throw new Error('You have to implement the static method "NAME", for each component!');
}
}]);
return Config;
}();
return Config;
}));
//# sourceMappingURL=config.js.map
|