1 | /*!
|
---|
2 | * Bootstrap config.js v5.3.3 (https://getbootstrap.com/)
|
---|
3 | * Copyright 2011-2024 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | */
|
---|
6 | (function (global, factory) {
|
---|
7 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/manipulator.js'), require('./index.js')) :
|
---|
8 | typeof define === 'function' && define.amd ? define(['../dom/manipulator', './index'], factory) :
|
---|
9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Config = factory(global.Manipulator, global.Index));
|
---|
10 | })(this, (function (Manipulator, index_js) { 'use strict';
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * --------------------------------------------------------------------------
|
---|
14 | * Bootstrap util/config.js
|
---|
15 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
16 | * --------------------------------------------------------------------------
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Class definition
|
---|
22 | */
|
---|
23 |
|
---|
24 | class Config {
|
---|
25 | // Getters
|
---|
26 | static get Default() {
|
---|
27 | return {};
|
---|
28 | }
|
---|
29 | static get DefaultType() {
|
---|
30 | return {};
|
---|
31 | }
|
---|
32 | static get NAME() {
|
---|
33 | throw new Error('You have to implement the static method "NAME", for each component!');
|
---|
34 | }
|
---|
35 | _getConfig(config) {
|
---|
36 | config = this._mergeConfigObj(config);
|
---|
37 | config = this._configAfterMerge(config);
|
---|
38 | this._typeCheckConfig(config);
|
---|
39 | return config;
|
---|
40 | }
|
---|
41 | _configAfterMerge(config) {
|
---|
42 | return config;
|
---|
43 | }
|
---|
44 | _mergeConfigObj(config, element) {
|
---|
45 | const jsonConfig = index_js.isElement(element) ? Manipulator.getDataAttribute(element, 'config') : {}; // try to parse
|
---|
46 |
|
---|
47 | return {
|
---|
48 | ...this.constructor.Default,
|
---|
49 | ...(typeof jsonConfig === 'object' ? jsonConfig : {}),
|
---|
50 | ...(index_js.isElement(element) ? Manipulator.getDataAttributes(element) : {}),
|
---|
51 | ...(typeof config === 'object' ? config : {})
|
---|
52 | };
|
---|
53 | }
|
---|
54 | _typeCheckConfig(config, configTypes = this.constructor.DefaultType) {
|
---|
55 | for (const [property, expectedTypes] of Object.entries(configTypes)) {
|
---|
56 | const value = config[property];
|
---|
57 | const valueType = index_js.isElement(value) ? 'element' : index_js.toType(value);
|
---|
58 | if (!new RegExp(expectedTypes).test(valueType)) {
|
---|
59 | throw new TypeError(`${this.constructor.NAME.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | return Config;
|
---|
66 |
|
---|
67 | }));
|
---|
68 | //# sourceMappingURL=config.js.map
|
---|