You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.5 KiB

7 months ago
  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. * Bootstrap util/config.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. /**
  18. * Class definition
  19. */
  20. class Config {
  21. // Getters
  22. static get Default() {
  23. return {};
  24. }
  25. static get DefaultType() {
  26. return {};
  27. }
  28. static get NAME() {
  29. throw new Error('You have to implement the static method "NAME", for each component!');
  30. }
  31. _getConfig(config) {
  32. config = this._mergeConfigObj(config);
  33. config = this._configAfterMerge(config);
  34. this._typeCheckConfig(config);
  35. return config;
  36. }
  37. _configAfterMerge(config) {
  38. return config;
  39. }
  40. _mergeConfigObj(config, element) {
  41. const jsonConfig = index_js.isElement(element) ? Manipulator.getDataAttribute(element, 'config') : {}; // try to parse
  42. return {
  43. ...this.constructor.Default,
  44. ...(typeof jsonConfig === 'object' ? jsonConfig : {}),
  45. ...(index_js.isElement(element) ? Manipulator.getDataAttributes(element) : {}),
  46. ...(typeof config === 'object' ? config : {})
  47. };
  48. }
  49. _typeCheckConfig(config, configTypes = this.constructor.DefaultType) {
  50. for (const [property, expectedTypes] of Object.entries(configTypes)) {
  51. const value = config[property];
  52. const valueType = index_js.isElement(value) ? 'element' : index_js.toType(value);
  53. if (!new RegExp(expectedTypes).test(valueType)) {
  54. throw new TypeError(`${this.constructor.NAME.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
  55. }
  56. }
  57. }
  58. }
  59. return Config;
  60. }));
  61. //# sourceMappingURL=config.js.map