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.

8059 lines
279KB

  1. /*!
  2. * Tabler v1.0.0-beta3 (https://tabler.io)
  3. * @version 1.0.0-beta3
  4. * @link https://tabler.io
  5. * Copyright 2018-2021 The Tabler Authors
  6. * Copyright 2018-2021 codecalm.net Paweł Kuna
  7. * Licensed under MIT (https://github.com/tabler/tabler/blob/master/LICENSE)
  8. */
  9. (function (factory) {
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. factory();
  12. }((function () { 'use strict';
  13. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  14. var autosize$1 = {exports: {}};
  15. /*!
  16. autosize 4.0.2
  17. license: MIT
  18. http://www.jacklmoore.com/autosize
  19. */
  20. (function (module, exports) {
  21. (function (global, factory) {
  22. {
  23. factory(module, exports);
  24. }
  25. })(commonjsGlobal, function (module, exports) {
  26. var map = typeof Map === "function" ? new Map() : function () {
  27. var keys = [];
  28. var values = [];
  29. return {
  30. has: function has(key) {
  31. return keys.indexOf(key) > -1;
  32. },
  33. get: function get(key) {
  34. return values[keys.indexOf(key)];
  35. },
  36. set: function set(key, value) {
  37. if (keys.indexOf(key) === -1) {
  38. keys.push(key);
  39. values.push(value);
  40. }
  41. },
  42. delete: function _delete(key) {
  43. var index = keys.indexOf(key);
  44. if (index > -1) {
  45. keys.splice(index, 1);
  46. values.splice(index, 1);
  47. }
  48. }
  49. };
  50. }();
  51. var createEvent = function createEvent(name) {
  52. return new Event(name, { bubbles: true });
  53. };
  54. try {
  55. new Event('test');
  56. } catch (e) {
  57. createEvent = function createEvent(name) {
  58. var evt = document.createEvent('Event');
  59. evt.initEvent(name, true, false);
  60. return evt;
  61. };
  62. }
  63. function assign(ta) {
  64. if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return;
  65. var heightOffset = null;
  66. var clientWidth = null;
  67. var cachedHeight = null;
  68. function init() {
  69. var style = window.getComputedStyle(ta, null);
  70. if (style.resize === 'vertical') {
  71. ta.style.resize = 'none';
  72. } else if (style.resize === 'both') {
  73. ta.style.resize = 'horizontal';
  74. }
  75. if (style.boxSizing === 'content-box') {
  76. heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom));
  77. } else {
  78. heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
  79. }
  80. if (isNaN(heightOffset)) {
  81. heightOffset = 0;
  82. }
  83. update();
  84. }
  85. function changeOverflow(value) {
  86. {
  87. var width = ta.style.width;
  88. ta.style.width = '0px';
  89. ta.offsetWidth;
  90. ta.style.width = width;
  91. }
  92. ta.style.overflowY = value;
  93. }
  94. function getParentOverflows(el) {
  95. var arr = [];
  96. while (el && el.parentNode && el.parentNode instanceof Element) {
  97. if (el.parentNode.scrollTop) {
  98. arr.push({
  99. node: el.parentNode,
  100. scrollTop: el.parentNode.scrollTop
  101. });
  102. }
  103. el = el.parentNode;
  104. }
  105. return arr;
  106. }
  107. function resize() {
  108. if (ta.scrollHeight === 0) {
  109. return;
  110. }
  111. var overflows = getParentOverflows(ta);
  112. var docTop = document.documentElement && document.documentElement.scrollTop;
  113. ta.style.height = '';
  114. ta.style.height = ta.scrollHeight + heightOffset + 'px';
  115. clientWidth = ta.clientWidth;
  116. overflows.forEach(function (el) {
  117. el.node.scrollTop = el.scrollTop;
  118. });
  119. if (docTop) {
  120. document.documentElement.scrollTop = docTop;
  121. }
  122. }
  123. function update() {
  124. resize();
  125. var styleHeight = Math.round(parseFloat(ta.style.height));
  126. var computed = window.getComputedStyle(ta, null);
  127. var actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(computed.height)) : ta.offsetHeight;
  128. if (actualHeight < styleHeight) {
  129. if (computed.overflowY === 'hidden') {
  130. changeOverflow('scroll');
  131. resize();
  132. actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight;
  133. }
  134. } else {
  135. if (computed.overflowY !== 'hidden') {
  136. changeOverflow('hidden');
  137. resize();
  138. actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight;
  139. }
  140. }
  141. if (cachedHeight !== actualHeight) {
  142. cachedHeight = actualHeight;
  143. var evt = createEvent('autosize:resized');
  144. try {
  145. ta.dispatchEvent(evt);
  146. } catch (err) {
  147. }
  148. }
  149. }
  150. var pageResize = function pageResize() {
  151. if (ta.clientWidth !== clientWidth) {
  152. update();
  153. }
  154. };
  155. var destroy = function (style) {
  156. window.removeEventListener('resize', pageResize, false);
  157. ta.removeEventListener('input', update, false);
  158. ta.removeEventListener('keyup', update, false);
  159. ta.removeEventListener('autosize:destroy', destroy, false);
  160. ta.removeEventListener('autosize:update', update, false);
  161. Object.keys(style).forEach(function (key) {
  162. ta.style[key] = style[key];
  163. });
  164. map.delete(ta);
  165. }.bind(ta, {
  166. height: ta.style.height,
  167. resize: ta.style.resize,
  168. overflowY: ta.style.overflowY,
  169. overflowX: ta.style.overflowX,
  170. wordWrap: ta.style.wordWrap
  171. });
  172. ta.addEventListener('autosize:destroy', destroy, false);
  173. if ('onpropertychange' in ta && 'oninput' in ta) {
  174. ta.addEventListener('keyup', update, false);
  175. }
  176. window.addEventListener('resize', pageResize, false);
  177. ta.addEventListener('input', update, false);
  178. ta.addEventListener('autosize:update', update, false);
  179. ta.style.overflowX = 'hidden';
  180. ta.style.wordWrap = 'break-word';
  181. map.set(ta, {
  182. destroy: destroy,
  183. update: update
  184. });
  185. init();
  186. }
  187. function destroy(ta) {
  188. var methods = map.get(ta);
  189. if (methods) {
  190. methods.destroy();
  191. }
  192. }
  193. function update(ta) {
  194. var methods = map.get(ta);
  195. if (methods) {
  196. methods.update();
  197. }
  198. }
  199. var autosize = null;
  200. if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'function') {
  201. autosize = function autosize(el) {
  202. return el;
  203. };
  204. autosize.destroy = function (el) {
  205. return el;
  206. };
  207. autosize.update = function (el) {
  208. return el;
  209. };
  210. } else {
  211. autosize = function autosize(el, options) {
  212. if (el) {
  213. Array.prototype.forEach.call(el.length ? el : [el], function (x) {
  214. return assign(x);
  215. });
  216. }
  217. return el;
  218. };
  219. autosize.destroy = function (el) {
  220. if (el) {
  221. Array.prototype.forEach.call(el.length ? el : [el], destroy);
  222. }
  223. return el;
  224. };
  225. autosize.update = function (el) {
  226. if (el) {
  227. Array.prototype.forEach.call(el.length ? el : [el], update);
  228. }
  229. return el;
  230. };
  231. }
  232. exports.default = autosize;
  233. module.exports = exports['default'];
  234. });
  235. }(autosize$1, autosize$1.exports));
  236. var autosize = autosize$1.exports;
  237. var elements = document.querySelectorAll('[data-bs-toggle="autosize"]');
  238. if (elements.length) {
  239. elements.forEach(function (element) {
  240. autosize(element);
  241. });
  242. }
  243. function _typeof(obj) {
  244. "@babel/helpers - typeof";
  245. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  246. _typeof = function (obj) {
  247. return typeof obj;
  248. };
  249. } else {
  250. _typeof = function (obj) {
  251. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  252. };
  253. }
  254. return _typeof(obj);
  255. }
  256. function _classCallCheck(instance, Constructor) {
  257. if (!(instance instanceof Constructor)) {
  258. throw new TypeError("Cannot call a class as a function");
  259. }
  260. }
  261. function _defineProperties(target, props) {
  262. for (var i = 0; i < props.length; i++) {
  263. var descriptor = props[i];
  264. descriptor.enumerable = descriptor.enumerable || false;
  265. descriptor.configurable = true;
  266. if ("value" in descriptor) descriptor.writable = true;
  267. Object.defineProperty(target, descriptor.key, descriptor);
  268. }
  269. }
  270. function _createClass(Constructor, protoProps, staticProps) {
  271. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  272. if (staticProps) _defineProperties(Constructor, staticProps);
  273. return Constructor;
  274. }
  275. function _defineProperty(obj, key, value) {
  276. if (key in obj) {
  277. Object.defineProperty(obj, key, {
  278. value: value,
  279. enumerable: true,
  280. configurable: true,
  281. writable: true
  282. });
  283. } else {
  284. obj[key] = value;
  285. }
  286. return obj;
  287. }
  288. function _inherits(subClass, superClass) {
  289. if (typeof superClass !== "function" && superClass !== null) {
  290. throw new TypeError("Super expression must either be null or a function");
  291. }
  292. subClass.prototype = Object.create(superClass && superClass.prototype, {
  293. constructor: {
  294. value: subClass,
  295. writable: true,
  296. configurable: true
  297. }
  298. });
  299. if (superClass) _setPrototypeOf(subClass, superClass);
  300. }
  301. function _getPrototypeOf(o) {
  302. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  303. return o.__proto__ || Object.getPrototypeOf(o);
  304. };
  305. return _getPrototypeOf(o);
  306. }
  307. function _setPrototypeOf(o, p) {
  308. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  309. o.__proto__ = p;
  310. return o;
  311. };
  312. return _setPrototypeOf(o, p);
  313. }
  314. function _isNativeReflectConstruct() {
  315. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  316. if (Reflect.construct.sham) return false;
  317. if (typeof Proxy === "function") return true;
  318. try {
  319. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  320. return true;
  321. } catch (e) {
  322. return false;
  323. }
  324. }
  325. function _objectWithoutPropertiesLoose(source, excluded) {
  326. if (source == null) return {};
  327. var target = {};
  328. var sourceKeys = Object.keys(source);
  329. var key, i;
  330. for (i = 0; i < sourceKeys.length; i++) {
  331. key = sourceKeys[i];
  332. if (excluded.indexOf(key) >= 0) continue;
  333. target[key] = source[key];
  334. }
  335. return target;
  336. }
  337. function _objectWithoutProperties(source, excluded) {
  338. if (source == null) return {};
  339. var target = _objectWithoutPropertiesLoose(source, excluded);
  340. var key, i;
  341. if (Object.getOwnPropertySymbols) {
  342. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  343. for (i = 0; i < sourceSymbolKeys.length; i++) {
  344. key = sourceSymbolKeys[i];
  345. if (excluded.indexOf(key) >= 0) continue;
  346. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  347. target[key] = source[key];
  348. }
  349. }
  350. return target;
  351. }
  352. function _assertThisInitialized(self) {
  353. if (self === void 0) {
  354. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  355. }
  356. return self;
  357. }
  358. function _possibleConstructorReturn(self, call) {
  359. if (call && (typeof call === "object" || typeof call === "function")) {
  360. return call;
  361. }
  362. return _assertThisInitialized(self);
  363. }
  364. function _createSuper(Derived) {
  365. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  366. return function _createSuperInternal() {
  367. var Super = _getPrototypeOf(Derived),
  368. result;
  369. if (hasNativeReflectConstruct) {
  370. var NewTarget = _getPrototypeOf(this).constructor;
  371. result = Reflect.construct(Super, arguments, NewTarget);
  372. } else {
  373. result = Super.apply(this, arguments);
  374. }
  375. return _possibleConstructorReturn(this, result);
  376. };
  377. }
  378. function _superPropBase(object, property) {
  379. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  380. object = _getPrototypeOf(object);
  381. if (object === null) break;
  382. }
  383. return object;
  384. }
  385. function _get(target, property, receiver) {
  386. if (typeof Reflect !== "undefined" && Reflect.get) {
  387. _get = Reflect.get;
  388. } else {
  389. _get = function _get(target, property, receiver) {
  390. var base = _superPropBase(target, property);
  391. if (!base) return;
  392. var desc = Object.getOwnPropertyDescriptor(base, property);
  393. if (desc.get) {
  394. return desc.get.call(receiver);
  395. }
  396. return desc.value;
  397. };
  398. }
  399. return _get(target, property, receiver || target);
  400. }
  401. function set(target, property, value, receiver) {
  402. if (typeof Reflect !== "undefined" && Reflect.set) {
  403. set = Reflect.set;
  404. } else {
  405. set = function set(target, property, value, receiver) {
  406. var base = _superPropBase(target, property);
  407. var desc;
  408. if (base) {
  409. desc = Object.getOwnPropertyDescriptor(base, property);
  410. if (desc.set) {
  411. desc.set.call(receiver, value);
  412. return true;
  413. } else if (!desc.writable) {
  414. return false;
  415. }
  416. }
  417. desc = Object.getOwnPropertyDescriptor(receiver, property);
  418. if (desc) {
  419. if (!desc.writable) {
  420. return false;
  421. }
  422. desc.value = value;
  423. Object.defineProperty(receiver, property, desc);
  424. } else {
  425. _defineProperty(receiver, property, value);
  426. }
  427. return true;
  428. };
  429. }
  430. return set(target, property, value, receiver);
  431. }
  432. function _set(target, property, value, receiver, isStrict) {
  433. var s = set(target, property, value, receiver || target);
  434. if (!s && isStrict) {
  435. throw new Error('failed to set property');
  436. }
  437. return value;
  438. }
  439. function _slicedToArray(arr, i) {
  440. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  441. }
  442. function _arrayWithHoles(arr) {
  443. if (Array.isArray(arr)) return arr;
  444. }
  445. function _iterableToArrayLimit(arr, i) {
  446. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  447. var _arr = [];
  448. var _n = true;
  449. var _d = false;
  450. var _e = undefined;
  451. try {
  452. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  453. _arr.push(_s.value);
  454. if (i && _arr.length === i) break;
  455. }
  456. } catch (err) {
  457. _d = true;
  458. _e = err;
  459. } finally {
  460. try {
  461. if (!_n && _i["return"] != null) _i["return"]();
  462. } finally {
  463. if (_d) throw _e;
  464. }
  465. }
  466. return _arr;
  467. }
  468. function _unsupportedIterableToArray(o, minLen) {
  469. if (!o) return;
  470. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  471. var n = Object.prototype.toString.call(o).slice(8, -1);
  472. if (n === "Object" && o.constructor) n = o.constructor.name;
  473. if (n === "Map" || n === "Set") return Array.from(o);
  474. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  475. }
  476. function _arrayLikeToArray(arr, len) {
  477. if (len == null || len > arr.length) len = arr.length;
  478. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  479. return arr2;
  480. }
  481. function _nonIterableRest() {
  482. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  483. }
  484. function isString(str) {
  485. return typeof str === 'string' || str instanceof String;
  486. }
  487. var DIRECTION = {
  488. NONE: 'NONE',
  489. LEFT: 'LEFT',
  490. FORCE_LEFT: 'FORCE_LEFT',
  491. RIGHT: 'RIGHT',
  492. FORCE_RIGHT: 'FORCE_RIGHT'
  493. };
  494. function forceDirection(direction) {
  495. switch (direction) {
  496. case DIRECTION.LEFT:
  497. return DIRECTION.FORCE_LEFT;
  498. case DIRECTION.RIGHT:
  499. return DIRECTION.FORCE_RIGHT;
  500. default:
  501. return direction;
  502. }
  503. }
  504. function escapeRegExp(str) {
  505. return str.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  506. }
  507. function objectIncludes(b, a) {
  508. if (a === b) return true;
  509. var arrA = Array.isArray(a),
  510. arrB = Array.isArray(b),
  511. i;
  512. if (arrA && arrB) {
  513. if (a.length != b.length) return false;
  514. for (i = 0; i < a.length; i++) {
  515. if (!objectIncludes(a[i], b[i])) return false;
  516. }
  517. return true;
  518. }
  519. if (arrA != arrB) return false;
  520. if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') {
  521. var dateA = a instanceof Date,
  522. dateB = b instanceof Date;
  523. if (dateA && dateB) return a.getTime() == b.getTime();
  524. if (dateA != dateB) return false;
  525. var regexpA = a instanceof RegExp,
  526. regexpB = b instanceof RegExp;
  527. if (regexpA && regexpB) return a.toString() == b.toString();
  528. if (regexpA != regexpB) return false;
  529. var keys = Object.keys(a);
  530. for (i = 0; i < keys.length; i++) {
  531. if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
  532. }
  533. for (i = 0; i < keys.length; i++) {
  534. if (!objectIncludes(b[keys[i]], a[keys[i]])) return false;
  535. }
  536. return true;
  537. } else if (a && b && typeof a === 'function' && typeof b === 'function') {
  538. return a.toString() === b.toString();
  539. }
  540. return false;
  541. }
  542. var ActionDetails = function () {
  543. function ActionDetails(value, cursorPos, oldValue, oldSelection) {
  544. _classCallCheck(this, ActionDetails);
  545. this.value = value;
  546. this.cursorPos = cursorPos;
  547. this.oldValue = oldValue;
  548. this.oldSelection = oldSelection;
  549. while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) {
  550. --this.oldSelection.start;
  551. }
  552. }
  553. _createClass(ActionDetails, [{
  554. key: "startChangePos",
  555. get: function get() {
  556. return Math.min(this.cursorPos, this.oldSelection.start);
  557. }
  558. }, {
  559. key: "insertedCount",
  560. get: function get() {
  561. return this.cursorPos - this.startChangePos;
  562. }
  563. }, {
  564. key: "inserted",
  565. get: function get() {
  566. return this.value.substr(this.startChangePos, this.insertedCount);
  567. }
  568. }, {
  569. key: "removedCount",
  570. get: function get() {
  571. return Math.max(this.oldSelection.end - this.startChangePos ||
  572. this.oldValue.length - this.value.length, 0);
  573. }
  574. }, {
  575. key: "removed",
  576. get: function get() {
  577. return this.oldValue.substr(this.startChangePos, this.removedCount);
  578. }
  579. }, {
  580. key: "head",
  581. get: function get() {
  582. return this.value.substring(0, this.startChangePos);
  583. }
  584. }, {
  585. key: "tail",
  586. get: function get() {
  587. return this.value.substring(this.startChangePos + this.insertedCount);
  588. }
  589. }, {
  590. key: "removeDirection",
  591. get: function get() {
  592. if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
  593. return this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos ? DIRECTION.RIGHT : DIRECTION.LEFT;
  594. }
  595. }]);
  596. return ActionDetails;
  597. }();
  598. var ChangeDetails = function () {
  599. function ChangeDetails(details) {
  600. _classCallCheck(this, ChangeDetails);
  601. Object.assign(this, {
  602. inserted: '',
  603. rawInserted: '',
  604. skip: false,
  605. tailShift: 0
  606. }, details);
  607. }
  608. _createClass(ChangeDetails, [{
  609. key: "aggregate",
  610. value: function aggregate(details) {
  611. this.rawInserted += details.rawInserted;
  612. this.skip = this.skip || details.skip;
  613. this.inserted += details.inserted;
  614. this.tailShift += details.tailShift;
  615. return this;
  616. }
  617. }, {
  618. key: "offset",
  619. get: function get() {
  620. return this.tailShift + this.inserted.length;
  621. }
  622. }]);
  623. return ChangeDetails;
  624. }();
  625. var ContinuousTailDetails = function () {
  626. function ContinuousTailDetails() {
  627. var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  628. var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  629. var stop = arguments.length > 2 ? arguments[2] : undefined;
  630. _classCallCheck(this, ContinuousTailDetails);
  631. this.value = value;
  632. this.from = from;
  633. this.stop = stop;
  634. }
  635. _createClass(ContinuousTailDetails, [{
  636. key: "toString",
  637. value: function toString() {
  638. return this.value;
  639. }
  640. }, {
  641. key: "extend",
  642. value: function extend(tail) {
  643. this.value += String(tail);
  644. }
  645. }, {
  646. key: "appendTo",
  647. value: function appendTo(masked) {
  648. return masked.append(this.toString(), {
  649. tail: true
  650. }).aggregate(masked._appendPlaceholder());
  651. }
  652. }, {
  653. key: "state",
  654. get: function get() {
  655. return {
  656. value: this.value,
  657. from: this.from,
  658. stop: this.stop
  659. };
  660. },
  661. set: function set(state) {
  662. Object.assign(this, state);
  663. }
  664. }, {
  665. key: "shiftBefore",
  666. value: function shiftBefore(pos) {
  667. if (this.from >= pos || !this.value.length) return '';
  668. var shiftChar = this.value[0];
  669. this.value = this.value.slice(1);
  670. return shiftChar;
  671. }
  672. }]);
  673. return ContinuousTailDetails;
  674. }();
  675. function IMask(el) {
  676. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  677. return new IMask.InputMask(el, opts);
  678. }
  679. var Masked = function () {
  680. function Masked(opts) {
  681. _classCallCheck(this, Masked);
  682. this._value = '';
  683. this._update(Object.assign({}, Masked.DEFAULTS, opts));
  684. this.isInitialized = true;
  685. }
  686. _createClass(Masked, [{
  687. key: "updateOptions",
  688. value: function updateOptions(opts) {
  689. if (!Object.keys(opts).length) return;
  690. this.withValueRefresh(this._update.bind(this, opts));
  691. }
  692. }, {
  693. key: "_update",
  694. value: function _update(opts) {
  695. Object.assign(this, opts);
  696. }
  697. }, {
  698. key: "state",
  699. get: function get() {
  700. return {
  701. _value: this.value
  702. };
  703. },
  704. set: function set(state) {
  705. this._value = state._value;
  706. }
  707. }, {
  708. key: "reset",
  709. value: function reset() {
  710. this._value = '';
  711. }
  712. }, {
  713. key: "value",
  714. get: function get() {
  715. return this._value;
  716. },
  717. set: function set(value) {
  718. this.resolve(value);
  719. }
  720. }, {
  721. key: "resolve",
  722. value: function resolve(value) {
  723. this.reset();
  724. this.append(value, {
  725. input: true
  726. }, '');
  727. this.doCommit();
  728. return this.value;
  729. }
  730. }, {
  731. key: "unmaskedValue",
  732. get: function get() {
  733. return this.value;
  734. },
  735. set: function set(value) {
  736. this.reset();
  737. this.append(value, {}, '');
  738. this.doCommit();
  739. }
  740. }, {
  741. key: "typedValue",
  742. get: function get() {
  743. return this.doParse(this.value);
  744. },
  745. set: function set(value) {
  746. this.value = this.doFormat(value);
  747. }
  748. }, {
  749. key: "rawInputValue",
  750. get: function get() {
  751. return this.extractInput(0, this.value.length, {
  752. raw: true
  753. });
  754. },
  755. set: function set(value) {
  756. this.reset();
  757. this.append(value, {
  758. raw: true
  759. }, '');
  760. this.doCommit();
  761. }
  762. }, {
  763. key: "isComplete",
  764. get: function get() {
  765. return true;
  766. }
  767. }, {
  768. key: "nearestInputPos",
  769. value: function nearestInputPos(cursorPos, direction) {
  770. return cursorPos;
  771. }
  772. }, {
  773. key: "extractInput",
  774. value: function extractInput() {
  775. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  776. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  777. return this.value.slice(fromPos, toPos);
  778. }
  779. }, {
  780. key: "extractTail",
  781. value: function extractTail() {
  782. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  783. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  784. return new ContinuousTailDetails(this.extractInput(fromPos, toPos), fromPos);
  785. }
  786. }, {
  787. key: "appendTail",
  788. value: function appendTail(tail) {
  789. if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
  790. return tail.appendTo(this);
  791. }
  792. }, {
  793. key: "_appendCharRaw",
  794. value: function _appendCharRaw(ch) {
  795. if (!ch) return new ChangeDetails();
  796. this._value += ch;
  797. return new ChangeDetails({
  798. inserted: ch,
  799. rawInserted: ch
  800. });
  801. }
  802. }, {
  803. key: "_appendChar",
  804. value: function _appendChar(ch) {
  805. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  806. var checkTail = arguments.length > 2 ? arguments[2] : undefined;
  807. var consistentState = this.state;
  808. var details = this._appendCharRaw(this.doPrepare(ch, flags), flags);
  809. if (details.inserted) {
  810. var consistentTail;
  811. var appended = this.doValidate(flags) !== false;
  812. if (appended && checkTail != null) {
  813. var beforeTailState = this.state;
  814. if (this.overwrite) {
  815. consistentTail = checkTail.state;
  816. checkTail.shiftBefore(this.value.length);
  817. }
  818. var tailDetails = this.appendTail(checkTail);
  819. appended = tailDetails.rawInserted === checkTail.toString();
  820. if (appended && tailDetails.inserted) this.state = beforeTailState;
  821. }
  822. if (!appended) {
  823. details = new ChangeDetails();
  824. this.state = consistentState;
  825. if (checkTail && consistentTail) checkTail.state = consistentTail;
  826. }
  827. }
  828. return details;
  829. }
  830. }, {
  831. key: "_appendPlaceholder",
  832. value: function _appendPlaceholder() {
  833. return new ChangeDetails();
  834. }
  835. }, {
  836. key: "append",
  837. value: function append(str, flags, tail) {
  838. if (!isString(str)) throw new Error('value should be string');
  839. var details = new ChangeDetails();
  840. var checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
  841. if (flags && flags.tail) flags._beforeTailState = this.state;
  842. for (var ci = 0; ci < str.length; ++ci) {
  843. details.aggregate(this._appendChar(str[ci], flags, checkTail));
  844. }
  845. if (checkTail != null) {
  846. details.tailShift += this.appendTail(checkTail).tailShift;
  847. }
  848. return details;
  849. }
  850. }, {
  851. key: "remove",
  852. value: function remove() {
  853. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  854. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  855. this._value = this.value.slice(0, fromPos) + this.value.slice(toPos);
  856. return new ChangeDetails();
  857. }
  858. }, {
  859. key: "withValueRefresh",
  860. value: function withValueRefresh(fn) {
  861. if (this._refreshing || !this.isInitialized) return fn();
  862. this._refreshing = true;
  863. var rawInput = this.rawInputValue;
  864. var value = this.value;
  865. var ret = fn();
  866. this.rawInputValue = rawInput;
  867. if (this.value && this.value !== value && value.indexOf(this.value) === 0) {
  868. this.append(value.slice(this.value.length), {}, '');
  869. }
  870. delete this._refreshing;
  871. return ret;
  872. }
  873. }, {
  874. key: "runIsolated",
  875. value: function runIsolated(fn) {
  876. if (this._isolated || !this.isInitialized) return fn(this);
  877. this._isolated = true;
  878. var state = this.state;
  879. var ret = fn(this);
  880. this.state = state;
  881. delete this._isolated;
  882. return ret;
  883. }
  884. }, {
  885. key: "doPrepare",
  886. value: function doPrepare(str) {
  887. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  888. return this.prepare ? this.prepare(str, this, flags) : str;
  889. }
  890. }, {
  891. key: "doValidate",
  892. value: function doValidate(flags) {
  893. return (!this.validate || this.validate(this.value, this, flags)) && (!this.parent || this.parent.doValidate(flags));
  894. }
  895. }, {
  896. key: "doCommit",
  897. value: function doCommit() {
  898. if (this.commit) this.commit(this.value, this);
  899. }
  900. }, {
  901. key: "doFormat",
  902. value: function doFormat(value) {
  903. return this.format ? this.format(value, this) : value;
  904. }
  905. }, {
  906. key: "doParse",
  907. value: function doParse(str) {
  908. return this.parse ? this.parse(str, this) : str;
  909. }
  910. }, {
  911. key: "splice",
  912. value: function splice(start, deleteCount, inserted, removeDirection) {
  913. var tailPos = start + deleteCount;
  914. var tail = this.extractTail(tailPos);
  915. var startChangePos = this.nearestInputPos(start, removeDirection);
  916. var changeDetails = new ChangeDetails({
  917. tailShift: startChangePos - start
  918. }).aggregate(this.remove(startChangePos)).aggregate(this.append(inserted, {
  919. input: true
  920. }, tail));
  921. return changeDetails;
  922. }
  923. }]);
  924. return Masked;
  925. }();
  926. Masked.DEFAULTS = {
  927. format: function format(v) {
  928. return v;
  929. },
  930. parse: function parse(v) {
  931. return v;
  932. }
  933. };
  934. IMask.Masked = Masked;
  935. function maskedClass(mask) {
  936. if (mask == null) {
  937. throw new Error('mask property should be defined');
  938. }
  939. if (mask instanceof RegExp) return IMask.MaskedRegExp;
  940. if (isString(mask)) return IMask.MaskedPattern;
  941. if (mask instanceof Date || mask === Date) return IMask.MaskedDate;
  942. if (mask instanceof Number || typeof mask === 'number' || mask === Number) return IMask.MaskedNumber;
  943. if (Array.isArray(mask) || mask === Array) return IMask.MaskedDynamic;
  944. if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask;
  945. if (mask instanceof Function) return IMask.MaskedFunction;
  946. if (mask instanceof IMask.Masked) return mask.constructor;
  947. console.warn('Mask not found for mask', mask);
  948. return IMask.Masked;
  949. }
  950. function createMask(opts) {
  951. if (IMask.Masked && opts instanceof IMask.Masked) return opts;
  952. opts = Object.assign({}, opts);
  953. var mask = opts.mask;
  954. if (IMask.Masked && mask instanceof IMask.Masked) return mask;
  955. var MaskedClass = maskedClass(mask);
  956. if (!MaskedClass) throw new Error('Masked class is not found for provided mask, appropriate module needs to be import manually before creating mask.');
  957. return new MaskedClass(opts);
  958. }
  959. IMask.createMask = createMask;
  960. var DEFAULT_INPUT_DEFINITIONS = {
  961. '0': /\d/,
  962. 'a': /[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,
  963. '*': /./
  964. };
  965. var PatternInputDefinition = function () {
  966. function PatternInputDefinition(opts) {
  967. _classCallCheck(this, PatternInputDefinition);
  968. var mask = opts.mask,
  969. blockOpts = _objectWithoutProperties(opts, ["mask"]);
  970. this.masked = createMask({
  971. mask: mask
  972. });
  973. Object.assign(this, blockOpts);
  974. }
  975. _createClass(PatternInputDefinition, [{
  976. key: "reset",
  977. value: function reset() {
  978. this._isFilled = false;
  979. this.masked.reset();
  980. }
  981. }, {
  982. key: "remove",
  983. value: function remove() {
  984. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  985. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  986. if (fromPos === 0 && toPos >= 1) {
  987. this._isFilled = false;
  988. return this.masked.remove(fromPos, toPos);
  989. }
  990. return new ChangeDetails();
  991. }
  992. }, {
  993. key: "value",
  994. get: function get() {
  995. return this.masked.value || (this._isFilled && !this.isOptional ? this.placeholderChar : '');
  996. }
  997. }, {
  998. key: "unmaskedValue",
  999. get: function get() {
  1000. return this.masked.unmaskedValue;
  1001. }
  1002. }, {
  1003. key: "isComplete",
  1004. get: function get() {
  1005. return Boolean(this.masked.value) || this.isOptional;
  1006. }
  1007. }, {
  1008. key: "_appendChar",
  1009. value: function _appendChar(str) {
  1010. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1011. if (this._isFilled) return new ChangeDetails();
  1012. var state = this.masked.state;
  1013. var details = this.masked._appendChar(str, flags);
  1014. if (details.inserted && this.doValidate(flags) === false) {
  1015. details.inserted = details.rawInserted = '';
  1016. this.masked.state = state;
  1017. }
  1018. if (!details.inserted && !this.isOptional && !this.lazy && !flags.input) {
  1019. details.inserted = this.placeholderChar;
  1020. }
  1021. details.skip = !details.inserted && !this.isOptional;
  1022. this._isFilled = Boolean(details.inserted);
  1023. return details;
  1024. }
  1025. }, {
  1026. key: "append",
  1027. value: function append() {
  1028. var _this$masked;
  1029. return (_this$masked = this.masked).append.apply(_this$masked, arguments);
  1030. }
  1031. }, {
  1032. key: "_appendPlaceholder",
  1033. value: function _appendPlaceholder() {
  1034. var details = new ChangeDetails();
  1035. if (this._isFilled || this.isOptional) return details;
  1036. this._isFilled = true;
  1037. details.inserted = this.placeholderChar;
  1038. return details;
  1039. }
  1040. }, {
  1041. key: "extractTail",
  1042. value: function extractTail() {
  1043. var _this$masked2;
  1044. return (_this$masked2 = this.masked).extractTail.apply(_this$masked2, arguments);
  1045. }
  1046. }, {
  1047. key: "appendTail",
  1048. value: function appendTail() {
  1049. var _this$masked3;
  1050. return (_this$masked3 = this.masked).appendTail.apply(_this$masked3, arguments);
  1051. }
  1052. }, {
  1053. key: "extractInput",
  1054. value: function extractInput() {
  1055. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1056. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  1057. var flags = arguments.length > 2 ? arguments[2] : undefined;
  1058. return this.masked.extractInput(fromPos, toPos, flags);
  1059. }
  1060. }, {
  1061. key: "nearestInputPos",
  1062. value: function nearestInputPos(cursorPos) {
  1063. var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
  1064. var minPos = 0;
  1065. var maxPos = this.value.length;
  1066. var boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
  1067. switch (direction) {
  1068. case DIRECTION.LEFT:
  1069. case DIRECTION.FORCE_LEFT:
  1070. return this.isComplete ? boundPos : minPos;
  1071. case DIRECTION.RIGHT:
  1072. case DIRECTION.FORCE_RIGHT:
  1073. return this.isComplete ? boundPos : maxPos;
  1074. case DIRECTION.NONE:
  1075. default:
  1076. return boundPos;
  1077. }
  1078. }
  1079. }, {
  1080. key: "doValidate",
  1081. value: function doValidate() {
  1082. var _this$masked4, _this$parent;
  1083. return (_this$masked4 = this.masked).doValidate.apply(_this$masked4, arguments) && (!this.parent || (_this$parent = this.parent).doValidate.apply(_this$parent, arguments));
  1084. }
  1085. }, {
  1086. key: "doCommit",
  1087. value: function doCommit() {
  1088. this.masked.doCommit();
  1089. }
  1090. }, {
  1091. key: "state",
  1092. get: function get() {
  1093. return {
  1094. masked: this.masked.state,
  1095. _isFilled: this._isFilled
  1096. };
  1097. },
  1098. set: function set(state) {
  1099. this.masked.state = state.masked;
  1100. this._isFilled = state._isFilled;
  1101. }
  1102. }]);
  1103. return PatternInputDefinition;
  1104. }();
  1105. var PatternFixedDefinition = function () {
  1106. function PatternFixedDefinition(opts) {
  1107. _classCallCheck(this, PatternFixedDefinition);
  1108. Object.assign(this, opts);
  1109. this._value = '';
  1110. }
  1111. _createClass(PatternFixedDefinition, [{
  1112. key: "value",
  1113. get: function get() {
  1114. return this._value;
  1115. }
  1116. }, {
  1117. key: "unmaskedValue",
  1118. get: function get() {
  1119. return this.isUnmasking ? this.value : '';
  1120. }
  1121. }, {
  1122. key: "reset",
  1123. value: function reset() {
  1124. this._isRawInput = false;
  1125. this._value = '';
  1126. }
  1127. }, {
  1128. key: "remove",
  1129. value: function remove() {
  1130. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1131. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._value.length;
  1132. this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
  1133. if (!this._value) this._isRawInput = false;
  1134. return new ChangeDetails();
  1135. }
  1136. }, {
  1137. key: "nearestInputPos",
  1138. value: function nearestInputPos(cursorPos) {
  1139. var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
  1140. var minPos = 0;
  1141. var maxPos = this._value.length;
  1142. switch (direction) {
  1143. case DIRECTION.LEFT:
  1144. case DIRECTION.FORCE_LEFT:
  1145. return minPos;
  1146. case DIRECTION.NONE:
  1147. case DIRECTION.RIGHT:
  1148. case DIRECTION.FORCE_RIGHT:
  1149. default:
  1150. return maxPos;
  1151. }
  1152. }
  1153. }, {
  1154. key: "extractInput",
  1155. value: function extractInput() {
  1156. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1157. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._value.length;
  1158. var flags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1159. return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
  1160. }
  1161. }, {
  1162. key: "isComplete",
  1163. get: function get() {
  1164. return true;
  1165. }
  1166. }, {
  1167. key: "_appendChar",
  1168. value: function _appendChar(str) {
  1169. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1170. var details = new ChangeDetails();
  1171. if (this._value) return details;
  1172. var appended = this.char === str[0];
  1173. var isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && !flags.tail;
  1174. if (isResolved) details.rawInserted = this.char;
  1175. this._value = details.inserted = this.char;
  1176. this._isRawInput = isResolved && (flags.raw || flags.input);
  1177. return details;
  1178. }
  1179. }, {
  1180. key: "_appendPlaceholder",
  1181. value: function _appendPlaceholder() {
  1182. var details = new ChangeDetails();
  1183. if (this._value) return details;
  1184. this._value = details.inserted = this.char;
  1185. return details;
  1186. }
  1187. }, {
  1188. key: "extractTail",
  1189. value: function extractTail() {
  1190. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  1191. return new ContinuousTailDetails('');
  1192. }
  1193. }, {
  1194. key: "appendTail",
  1195. value: function appendTail(tail) {
  1196. if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
  1197. return tail.appendTo(this);
  1198. }
  1199. }, {
  1200. key: "append",
  1201. value: function append(str, flags, tail) {
  1202. var details = this._appendChar(str, flags);
  1203. if (tail != null) {
  1204. details.tailShift += this.appendTail(tail).tailShift;
  1205. }
  1206. return details;
  1207. }
  1208. }, {
  1209. key: "doCommit",
  1210. value: function doCommit() {}
  1211. }, {
  1212. key: "state",
  1213. get: function get() {
  1214. return {
  1215. _value: this._value,
  1216. _isRawInput: this._isRawInput
  1217. };
  1218. },
  1219. set: function set(state) {
  1220. Object.assign(this, state);
  1221. }
  1222. }]);
  1223. return PatternFixedDefinition;
  1224. }();
  1225. var ChunksTailDetails = function () {
  1226. function ChunksTailDetails() {
  1227. var chunks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  1228. var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  1229. _classCallCheck(this, ChunksTailDetails);
  1230. this.chunks = chunks;
  1231. this.from = from;
  1232. }
  1233. _createClass(ChunksTailDetails, [{
  1234. key: "toString",
  1235. value: function toString() {
  1236. return this.chunks.map(String).join('');
  1237. }
  1238. }, {
  1239. key: "extend",
  1240. value: function extend(tailChunk) {
  1241. if (!String(tailChunk)) return;
  1242. if (isString(tailChunk)) tailChunk = new ContinuousTailDetails(String(tailChunk));
  1243. var lastChunk = this.chunks[this.chunks.length - 1];
  1244. var extendLast = lastChunk && (
  1245. lastChunk.stop === tailChunk.stop || tailChunk.stop == null) &&
  1246. tailChunk.from === lastChunk.from + lastChunk.toString().length;
  1247. if (tailChunk instanceof ContinuousTailDetails) {
  1248. if (extendLast) {
  1249. lastChunk.extend(tailChunk.toString());
  1250. } else {
  1251. this.chunks.push(tailChunk);
  1252. }
  1253. } else if (tailChunk instanceof ChunksTailDetails) {
  1254. if (tailChunk.stop == null) {
  1255. var firstTailChunk;
  1256. while (tailChunk.chunks.length && tailChunk.chunks[0].stop == null) {
  1257. firstTailChunk = tailChunk.chunks.shift();
  1258. firstTailChunk.from += tailChunk.from;
  1259. this.extend(firstTailChunk);
  1260. }
  1261. }
  1262. if (tailChunk.toString()) {
  1263. tailChunk.stop = tailChunk.blockIndex;
  1264. this.chunks.push(tailChunk);
  1265. }
  1266. }
  1267. }
  1268. }, {
  1269. key: "appendTo",
  1270. value: function appendTo(masked) {
  1271. if (!(masked instanceof IMask.MaskedPattern)) {
  1272. var tail = new ContinuousTailDetails(this.toString());
  1273. return tail.appendTo(masked);
  1274. }
  1275. var details = new ChangeDetails();
  1276. for (var ci = 0; ci < this.chunks.length && !details.skip; ++ci) {
  1277. var chunk = this.chunks[ci];
  1278. var lastBlockIter = masked._mapPosToBlock(masked.value.length);
  1279. var stop = chunk.stop;
  1280. var chunkBlock = void 0;
  1281. if (stop != null && (
  1282. !lastBlockIter || lastBlockIter.index <= stop)) {
  1283. if (chunk instanceof ChunksTailDetails ||
  1284. masked._stops.indexOf(stop) >= 0) {
  1285. details.aggregate(masked._appendPlaceholder(stop));
  1286. }
  1287. chunkBlock = chunk instanceof ChunksTailDetails && masked._blocks[stop];
  1288. }
  1289. if (chunkBlock) {
  1290. var tailDetails = chunkBlock.appendTail(chunk);
  1291. tailDetails.skip = false;
  1292. details.aggregate(tailDetails);
  1293. masked._value += tailDetails.inserted;
  1294. var remainChars = chunk.toString().slice(tailDetails.rawInserted.length);
  1295. if (remainChars) details.aggregate(masked.append(remainChars, {
  1296. tail: true
  1297. }));
  1298. } else {
  1299. details.aggregate(masked.append(chunk.toString(), {
  1300. tail: true
  1301. }));
  1302. }
  1303. }
  1304. return details;
  1305. }
  1306. }, {
  1307. key: "state",
  1308. get: function get() {
  1309. return {
  1310. chunks: this.chunks.map(function (c) {
  1311. return c.state;
  1312. }),
  1313. from: this.from,
  1314. stop: this.stop,
  1315. blockIndex: this.blockIndex
  1316. };
  1317. },
  1318. set: function set(state) {
  1319. var chunks = state.chunks,
  1320. props = _objectWithoutProperties(state, ["chunks"]);
  1321. Object.assign(this, props);
  1322. this.chunks = chunks.map(function (cstate) {
  1323. var chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails();
  1324. chunk.state = cstate;
  1325. return chunk;
  1326. });
  1327. }
  1328. }, {
  1329. key: "shiftBefore",
  1330. value: function shiftBefore(pos) {
  1331. if (this.from >= pos || !this.chunks.length) return '';
  1332. var chunkShiftPos = pos - this.from;
  1333. var ci = 0;
  1334. while (ci < this.chunks.length) {
  1335. var chunk = this.chunks[ci];
  1336. var shiftChar = chunk.shiftBefore(chunkShiftPos);
  1337. if (chunk.toString()) {
  1338. if (!shiftChar) break;
  1339. ++ci;
  1340. } else {
  1341. this.chunks.splice(ci, 1);
  1342. }
  1343. if (shiftChar) return shiftChar;
  1344. }
  1345. return '';
  1346. }
  1347. }]);
  1348. return ChunksTailDetails;
  1349. }();
  1350. var MaskedRegExp = function (_Masked) {
  1351. _inherits(MaskedRegExp, _Masked);
  1352. var _super = _createSuper(MaskedRegExp);
  1353. function MaskedRegExp() {
  1354. _classCallCheck(this, MaskedRegExp);
  1355. return _super.apply(this, arguments);
  1356. }
  1357. _createClass(MaskedRegExp, [{
  1358. key: "_update",
  1359. value:
  1360. function _update(opts) {
  1361. if (opts.mask) opts.validate = function (value) {
  1362. return value.search(opts.mask) >= 0;
  1363. };
  1364. _get(_getPrototypeOf(MaskedRegExp.prototype), "_update", this).call(this, opts);
  1365. }
  1366. }]);
  1367. return MaskedRegExp;
  1368. }(Masked);
  1369. IMask.MaskedRegExp = MaskedRegExp;
  1370. var MaskedPattern = function (_Masked) {
  1371. _inherits(MaskedPattern, _Masked);
  1372. var _super = _createSuper(MaskedPattern);
  1373. function MaskedPattern() {
  1374. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1375. _classCallCheck(this, MaskedPattern);
  1376. opts.definitions = Object.assign({}, DEFAULT_INPUT_DEFINITIONS, opts.definitions);
  1377. return _super.call(this, Object.assign({}, MaskedPattern.DEFAULTS, opts));
  1378. }
  1379. _createClass(MaskedPattern, [{
  1380. key: "_update",
  1381. value: function _update() {
  1382. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1383. opts.definitions = Object.assign({}, this.definitions, opts.definitions);
  1384. _get(_getPrototypeOf(MaskedPattern.prototype), "_update", this).call(this, opts);
  1385. this._rebuildMask();
  1386. }
  1387. }, {
  1388. key: "_rebuildMask",
  1389. value: function _rebuildMask() {
  1390. var _this = this;
  1391. var defs = this.definitions;
  1392. this._blocks = [];
  1393. this._stops = [];
  1394. this._maskedBlocks = {};
  1395. var pattern = this.mask;
  1396. if (!pattern || !defs) return;
  1397. var unmaskingBlock = false;
  1398. var optionalBlock = false;
  1399. for (var i = 0; i < pattern.length; ++i) {
  1400. if (this.blocks) {
  1401. var _ret = function () {
  1402. var p = pattern.slice(i);
  1403. var bNames = Object.keys(_this.blocks).filter(function (bName) {
  1404. return p.indexOf(bName) === 0;
  1405. });
  1406. bNames.sort(function (a, b) {
  1407. return b.length - a.length;
  1408. });
  1409. var bName = bNames[0];
  1410. if (bName) {
  1411. var maskedBlock = createMask(Object.assign({
  1412. parent: _this,
  1413. lazy: _this.lazy,
  1414. placeholderChar: _this.placeholderChar,
  1415. overwrite: _this.overwrite
  1416. }, _this.blocks[bName]));
  1417. if (maskedBlock) {
  1418. _this._blocks.push(maskedBlock);
  1419. if (!_this._maskedBlocks[bName]) _this._maskedBlocks[bName] = [];
  1420. _this._maskedBlocks[bName].push(_this._blocks.length - 1);
  1421. }
  1422. i += bName.length - 1;
  1423. return "continue";
  1424. }
  1425. }();
  1426. if (_ret === "continue") continue;
  1427. }
  1428. var char = pattern[i];
  1429. var _isInput = (char in defs);
  1430. if (char === MaskedPattern.STOP_CHAR) {
  1431. this._stops.push(this._blocks.length);
  1432. continue;
  1433. }
  1434. if (char === '{' || char === '}') {
  1435. unmaskingBlock = !unmaskingBlock;
  1436. continue;
  1437. }
  1438. if (char === '[' || char === ']') {
  1439. optionalBlock = !optionalBlock;
  1440. continue;
  1441. }
  1442. if (char === MaskedPattern.ESCAPE_CHAR) {
  1443. ++i;
  1444. char = pattern[i];
  1445. if (!char) break;
  1446. _isInput = false;
  1447. }
  1448. var def = _isInput ? new PatternInputDefinition({
  1449. parent: this,
  1450. lazy: this.lazy,
  1451. placeholderChar: this.placeholderChar,
  1452. mask: defs[char],
  1453. isOptional: optionalBlock
  1454. }) : new PatternFixedDefinition({
  1455. char: char,
  1456. isUnmasking: unmaskingBlock
  1457. });
  1458. this._blocks.push(def);
  1459. }
  1460. }
  1461. }, {
  1462. key: "state",
  1463. get: function get() {
  1464. return Object.assign({}, _get(_getPrototypeOf(MaskedPattern.prototype), "state", this), {
  1465. _blocks: this._blocks.map(function (b) {
  1466. return b.state;
  1467. })
  1468. });
  1469. },
  1470. set: function set(state) {
  1471. var _blocks = state._blocks,
  1472. maskedState = _objectWithoutProperties(state, ["_blocks"]);
  1473. this._blocks.forEach(function (b, bi) {
  1474. return b.state = _blocks[bi];
  1475. });
  1476. _set(_getPrototypeOf(MaskedPattern.prototype), "state", maskedState, this, true);
  1477. }
  1478. }, {
  1479. key: "reset",
  1480. value: function reset() {
  1481. _get(_getPrototypeOf(MaskedPattern.prototype), "reset", this).call(this);
  1482. this._blocks.forEach(function (b) {
  1483. return b.reset();
  1484. });
  1485. }
  1486. }, {
  1487. key: "isComplete",
  1488. get: function get() {
  1489. return this._blocks.every(function (b) {
  1490. return b.isComplete;
  1491. });
  1492. }
  1493. }, {
  1494. key: "doCommit",
  1495. value: function doCommit() {
  1496. this._blocks.forEach(function (b) {
  1497. return b.doCommit();
  1498. });
  1499. _get(_getPrototypeOf(MaskedPattern.prototype), "doCommit", this).call(this);
  1500. }
  1501. }, {
  1502. key: "unmaskedValue",
  1503. get: function get() {
  1504. return this._blocks.reduce(function (str, b) {
  1505. return str += b.unmaskedValue;
  1506. }, '');
  1507. },
  1508. set: function set(unmaskedValue) {
  1509. _set(_getPrototypeOf(MaskedPattern.prototype), "unmaskedValue", unmaskedValue, this, true);
  1510. }
  1511. }, {
  1512. key: "value",
  1513. get: function get() {
  1514. return this._blocks.reduce(function (str, b) {
  1515. return str += b.value;
  1516. }, '');
  1517. },
  1518. set: function set(value) {
  1519. _set(_getPrototypeOf(MaskedPattern.prototype), "value", value, this, true);
  1520. }
  1521. }, {
  1522. key: "appendTail",
  1523. value: function appendTail(tail) {
  1524. return _get(_getPrototypeOf(MaskedPattern.prototype), "appendTail", this).call(this, tail).aggregate(this._appendPlaceholder());
  1525. }
  1526. }, {
  1527. key: "_appendCharRaw",
  1528. value: function _appendCharRaw(ch) {
  1529. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1530. var blockIter = this._mapPosToBlock(this.value.length);
  1531. var details = new ChangeDetails();
  1532. if (!blockIter) return details;
  1533. for (var bi = blockIter.index;; ++bi) {
  1534. var _block = this._blocks[bi];
  1535. if (!_block) break;
  1536. var blockDetails = _block._appendChar(ch, flags);
  1537. var skip = blockDetails.skip;
  1538. details.aggregate(blockDetails);
  1539. if (skip || blockDetails.rawInserted) break;
  1540. }
  1541. return details;
  1542. }
  1543. }, {
  1544. key: "extractTail",
  1545. value: function extractTail() {
  1546. var _this2 = this;
  1547. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1548. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  1549. var chunkTail = new ChunksTailDetails();
  1550. if (fromPos === toPos) return chunkTail;
  1551. this._forEachBlocksInRange(fromPos, toPos, function (b, bi, bFromPos, bToPos) {
  1552. var blockChunk = b.extractTail(bFromPos, bToPos);
  1553. blockChunk.stop = _this2._findStopBefore(bi);
  1554. blockChunk.from = _this2._blockStartPos(bi);
  1555. if (blockChunk instanceof ChunksTailDetails) blockChunk.blockIndex = bi;
  1556. chunkTail.extend(blockChunk);
  1557. });
  1558. return chunkTail;
  1559. }
  1560. }, {
  1561. key: "extractInput",
  1562. value: function extractInput() {
  1563. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1564. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  1565. var flags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1566. if (fromPos === toPos) return '';
  1567. var input = '';
  1568. this._forEachBlocksInRange(fromPos, toPos, function (b, _, fromPos, toPos) {
  1569. input += b.extractInput(fromPos, toPos, flags);
  1570. });
  1571. return input;
  1572. }
  1573. }, {
  1574. key: "_findStopBefore",
  1575. value: function _findStopBefore(blockIndex) {
  1576. var stopBefore;
  1577. for (var si = 0; si < this._stops.length; ++si) {
  1578. var stop = this._stops[si];
  1579. if (stop <= blockIndex) stopBefore = stop;else break;
  1580. }
  1581. return stopBefore;
  1582. }
  1583. }, {
  1584. key: "_appendPlaceholder",
  1585. value: function _appendPlaceholder(toBlockIndex) {
  1586. var _this3 = this;
  1587. var details = new ChangeDetails();
  1588. if (this.lazy && toBlockIndex == null) return details;
  1589. var startBlockIter = this._mapPosToBlock(this.value.length);
  1590. if (!startBlockIter) return details;
  1591. var startBlockIndex = startBlockIter.index;
  1592. var endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length;
  1593. this._blocks.slice(startBlockIndex, endBlockIndex).forEach(function (b) {
  1594. if (!b.lazy || toBlockIndex != null) {
  1595. var args = b._blocks != null ? [b._blocks.length] : [];
  1596. var bDetails = b._appendPlaceholder.apply(b, args);
  1597. _this3._value += bDetails.inserted;
  1598. details.aggregate(bDetails);
  1599. }
  1600. });
  1601. return details;
  1602. }
  1603. }, {
  1604. key: "_mapPosToBlock",
  1605. value: function _mapPosToBlock(pos) {
  1606. var accVal = '';
  1607. for (var bi = 0; bi < this._blocks.length; ++bi) {
  1608. var _block2 = this._blocks[bi];
  1609. var blockStartPos = accVal.length;
  1610. accVal += _block2.value;
  1611. if (pos <= accVal.length) {
  1612. return {
  1613. index: bi,
  1614. offset: pos - blockStartPos
  1615. };
  1616. }
  1617. }
  1618. }
  1619. }, {
  1620. key: "_blockStartPos",
  1621. value: function _blockStartPos(blockIndex) {
  1622. return this._blocks.slice(0, blockIndex).reduce(function (pos, b) {
  1623. return pos += b.value.length;
  1624. }, 0);
  1625. }
  1626. }, {
  1627. key: "_forEachBlocksInRange",
  1628. value: function _forEachBlocksInRange(fromPos) {
  1629. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  1630. var fn = arguments.length > 2 ? arguments[2] : undefined;
  1631. var fromBlockIter = this._mapPosToBlock(fromPos);
  1632. if (fromBlockIter) {
  1633. var toBlockIter = this._mapPosToBlock(toPos);
  1634. var isSameBlock = toBlockIter && fromBlockIter.index === toBlockIter.index;
  1635. var fromBlockStartPos = fromBlockIter.offset;
  1636. var fromBlockEndPos = toBlockIter && isSameBlock ? toBlockIter.offset : this._blocks[fromBlockIter.index].value.length;
  1637. fn(this._blocks[fromBlockIter.index], fromBlockIter.index, fromBlockStartPos, fromBlockEndPos);
  1638. if (toBlockIter && !isSameBlock) {
  1639. for (var bi = fromBlockIter.index + 1; bi < toBlockIter.index; ++bi) {
  1640. fn(this._blocks[bi], bi, 0, this._blocks[bi].value.length);
  1641. }
  1642. fn(this._blocks[toBlockIter.index], toBlockIter.index, 0, toBlockIter.offset);
  1643. }
  1644. }
  1645. }
  1646. }, {
  1647. key: "remove",
  1648. value: function remove() {
  1649. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1650. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  1651. var removeDetails = _get(_getPrototypeOf(MaskedPattern.prototype), "remove", this).call(this, fromPos, toPos);
  1652. this._forEachBlocksInRange(fromPos, toPos, function (b, _, bFromPos, bToPos) {
  1653. removeDetails.aggregate(b.remove(bFromPos, bToPos));
  1654. });
  1655. return removeDetails;
  1656. }
  1657. }, {
  1658. key: "nearestInputPos",
  1659. value: function nearestInputPos(cursorPos) {
  1660. var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE;
  1661. var beginBlockData = this._mapPosToBlock(cursorPos) || {
  1662. index: 0,
  1663. offset: 0
  1664. };
  1665. var beginBlockOffset = beginBlockData.offset,
  1666. beginBlockIndex = beginBlockData.index;
  1667. var beginBlock = this._blocks[beginBlockIndex];
  1668. if (!beginBlock) return cursorPos;
  1669. var beginBlockCursorPos = beginBlockOffset;
  1670. if (beginBlockCursorPos !== 0 && beginBlockCursorPos < beginBlock.value.length) {
  1671. beginBlockCursorPos = beginBlock.nearestInputPos(beginBlockOffset, forceDirection(direction));
  1672. }
  1673. var cursorAtRight = beginBlockCursorPos === beginBlock.value.length;
  1674. var cursorAtLeft = beginBlockCursorPos === 0;
  1675. if (!cursorAtLeft && !cursorAtRight) return this._blockStartPos(beginBlockIndex) + beginBlockCursorPos;
  1676. var searchBlockIndex = cursorAtRight ? beginBlockIndex + 1 : beginBlockIndex;
  1677. if (direction === DIRECTION.NONE) {
  1678. if (searchBlockIndex > 0) {
  1679. var blockIndexAtLeft = searchBlockIndex - 1;
  1680. var blockAtLeft = this._blocks[blockIndexAtLeft];
  1681. var blockInputPos = blockAtLeft.nearestInputPos(0, DIRECTION.NONE);
  1682. if (!blockAtLeft.value.length || blockInputPos !== blockAtLeft.value.length) {
  1683. return this._blockStartPos(searchBlockIndex);
  1684. }
  1685. }
  1686. var firstInputAtRight = searchBlockIndex;
  1687. for (var bi = firstInputAtRight; bi < this._blocks.length; ++bi) {
  1688. var blockAtRight = this._blocks[bi];
  1689. var _blockInputPos = blockAtRight.nearestInputPos(0, DIRECTION.NONE);
  1690. if (!blockAtRight.value.length || _blockInputPos !== blockAtRight.value.length) {
  1691. return this._blockStartPos(bi) + _blockInputPos;
  1692. }
  1693. }
  1694. for (var _bi = searchBlockIndex - 1; _bi >= 0; --_bi) {
  1695. var _block3 = this._blocks[_bi];
  1696. var _blockInputPos2 = _block3.nearestInputPos(0, DIRECTION.NONE);
  1697. if (!_block3.value.length || _blockInputPos2 !== _block3.value.length) {
  1698. return this._blockStartPos(_bi) + _block3.value.length;
  1699. }
  1700. }
  1701. return cursorPos;
  1702. }
  1703. if (direction === DIRECTION.LEFT || direction === DIRECTION.FORCE_LEFT) {
  1704. var firstFilledBlockIndexAtRight;
  1705. for (var _bi2 = searchBlockIndex; _bi2 < this._blocks.length; ++_bi2) {
  1706. if (this._blocks[_bi2].value) {
  1707. firstFilledBlockIndexAtRight = _bi2;
  1708. break;
  1709. }
  1710. }
  1711. if (firstFilledBlockIndexAtRight != null) {
  1712. var filledBlock = this._blocks[firstFilledBlockIndexAtRight];
  1713. var _blockInputPos3 = filledBlock.nearestInputPos(0, DIRECTION.RIGHT);
  1714. if (_blockInputPos3 === 0 && filledBlock.unmaskedValue.length) {
  1715. return this._blockStartPos(firstFilledBlockIndexAtRight) + _blockInputPos3;
  1716. }
  1717. }
  1718. var firstFilledInputBlockIndex = -1;
  1719. var firstEmptyInputBlockIndex;
  1720. for (var _bi3 = searchBlockIndex - 1; _bi3 >= 0; --_bi3) {
  1721. var _block4 = this._blocks[_bi3];
  1722. var _blockInputPos4 = _block4.nearestInputPos(_block4.value.length, DIRECTION.FORCE_LEFT);
  1723. if (!_block4.value || _blockInputPos4 !== 0) firstEmptyInputBlockIndex = _bi3;
  1724. if (_blockInputPos4 !== 0) {
  1725. if (_blockInputPos4 !== _block4.value.length) {
  1726. return this._blockStartPos(_bi3) + _blockInputPos4;
  1727. } else {
  1728. firstFilledInputBlockIndex = _bi3;
  1729. break;
  1730. }
  1731. }
  1732. }
  1733. if (direction === DIRECTION.LEFT) {
  1734. for (var _bi4 = firstFilledInputBlockIndex + 1; _bi4 <= Math.min(searchBlockIndex, this._blocks.length - 1); ++_bi4) {
  1735. var _block5 = this._blocks[_bi4];
  1736. var _blockInputPos5 = _block5.nearestInputPos(0, DIRECTION.NONE);
  1737. var blockAlignedPos = this._blockStartPos(_bi4) + _blockInputPos5;
  1738. if (blockAlignedPos > cursorPos) break;
  1739. if (_blockInputPos5 !== _block5.value.length) return blockAlignedPos;
  1740. }
  1741. }
  1742. if (firstFilledInputBlockIndex >= 0) {
  1743. return this._blockStartPos(firstFilledInputBlockIndex) + this._blocks[firstFilledInputBlockIndex].value.length;
  1744. }
  1745. if (direction === DIRECTION.FORCE_LEFT || this.lazy && !this.extractInput() && !isInput(this._blocks[searchBlockIndex])) {
  1746. return 0;
  1747. }
  1748. if (firstEmptyInputBlockIndex != null) {
  1749. return this._blockStartPos(firstEmptyInputBlockIndex);
  1750. }
  1751. for (var _bi5 = searchBlockIndex; _bi5 < this._blocks.length; ++_bi5) {
  1752. var _block6 = this._blocks[_bi5];
  1753. var _blockInputPos6 = _block6.nearestInputPos(0, DIRECTION.NONE);
  1754. if (!_block6.value.length || _blockInputPos6 !== _block6.value.length) {
  1755. return this._blockStartPos(_bi5) + _blockInputPos6;
  1756. }
  1757. }
  1758. return 0;
  1759. }
  1760. if (direction === DIRECTION.RIGHT || direction === DIRECTION.FORCE_RIGHT) {
  1761. var firstInputBlockAlignedIndex;
  1762. var firstInputBlockAlignedPos;
  1763. for (var _bi6 = searchBlockIndex; _bi6 < this._blocks.length; ++_bi6) {
  1764. var _block7 = this._blocks[_bi6];
  1765. var _blockInputPos7 = _block7.nearestInputPos(0, DIRECTION.NONE);
  1766. if (_blockInputPos7 !== _block7.value.length) {
  1767. firstInputBlockAlignedPos = this._blockStartPos(_bi6) + _blockInputPos7;
  1768. firstInputBlockAlignedIndex = _bi6;
  1769. break;
  1770. }
  1771. }
  1772. if (firstInputBlockAlignedIndex != null && firstInputBlockAlignedPos != null) {
  1773. for (var _bi7 = firstInputBlockAlignedIndex; _bi7 < this._blocks.length; ++_bi7) {
  1774. var _block8 = this._blocks[_bi7];
  1775. var _blockInputPos8 = _block8.nearestInputPos(0, DIRECTION.FORCE_RIGHT);
  1776. if (_blockInputPos8 !== _block8.value.length) {
  1777. return this._blockStartPos(_bi7) + _blockInputPos8;
  1778. }
  1779. }
  1780. return direction === DIRECTION.FORCE_RIGHT ? this.value.length : firstInputBlockAlignedPos;
  1781. }
  1782. for (var _bi8 = Math.min(searchBlockIndex, this._blocks.length - 1); _bi8 >= 0; --_bi8) {
  1783. var _block9 = this._blocks[_bi8];
  1784. var _blockInputPos9 = _block9.nearestInputPos(_block9.value.length, DIRECTION.LEFT);
  1785. if (_blockInputPos9 !== 0) {
  1786. var alignedPos = this._blockStartPos(_bi8) + _blockInputPos9;
  1787. if (alignedPos >= cursorPos) return alignedPos;
  1788. break;
  1789. }
  1790. }
  1791. }
  1792. return cursorPos;
  1793. }
  1794. }, {
  1795. key: "maskedBlock",
  1796. value: function maskedBlock(name) {
  1797. return this.maskedBlocks(name)[0];
  1798. }
  1799. }, {
  1800. key: "maskedBlocks",
  1801. value: function maskedBlocks(name) {
  1802. var _this4 = this;
  1803. var indices = this._maskedBlocks[name];
  1804. if (!indices) return [];
  1805. return indices.map(function (gi) {
  1806. return _this4._blocks[gi];
  1807. });
  1808. }
  1809. }]);
  1810. return MaskedPattern;
  1811. }(Masked);
  1812. MaskedPattern.DEFAULTS = {
  1813. lazy: true,
  1814. placeholderChar: '_'
  1815. };
  1816. MaskedPattern.STOP_CHAR = '`';
  1817. MaskedPattern.ESCAPE_CHAR = '\\';
  1818. MaskedPattern.InputDefinition = PatternInputDefinition;
  1819. MaskedPattern.FixedDefinition = PatternFixedDefinition;
  1820. function isInput(block) {
  1821. if (!block) return false;
  1822. var value = block.value;
  1823. return !value || block.nearestInputPos(0, DIRECTION.NONE) !== value.length;
  1824. }
  1825. IMask.MaskedPattern = MaskedPattern;
  1826. var MaskedRange = function (_MaskedPattern) {
  1827. _inherits(MaskedRange, _MaskedPattern);
  1828. var _super = _createSuper(MaskedRange);
  1829. function MaskedRange() {
  1830. _classCallCheck(this, MaskedRange);
  1831. return _super.apply(this, arguments);
  1832. }
  1833. _createClass(MaskedRange, [{
  1834. key: "_matchFrom",
  1835. get:
  1836. function get() {
  1837. return this.maxLength - String(this.from).length;
  1838. }
  1839. }, {
  1840. key: "_update",
  1841. value: function _update(opts) {
  1842. opts = Object.assign({
  1843. to: this.to || 0,
  1844. from: this.from || 0
  1845. }, opts);
  1846. var maxLength = String(opts.to).length;
  1847. if (opts.maxLength != null) maxLength = Math.max(maxLength, opts.maxLength);
  1848. opts.maxLength = maxLength;
  1849. var fromStr = String(opts.from).padStart(maxLength, '0');
  1850. var toStr = String(opts.to).padStart(maxLength, '0');
  1851. var sameCharsCount = 0;
  1852. while (sameCharsCount < toStr.length && toStr[sameCharsCount] === fromStr[sameCharsCount]) {
  1853. ++sameCharsCount;
  1854. }
  1855. opts.mask = toStr.slice(0, sameCharsCount).replace(/0/g, '\\0') + '0'.repeat(maxLength - sameCharsCount);
  1856. _get(_getPrototypeOf(MaskedRange.prototype), "_update", this).call(this, opts);
  1857. }
  1858. }, {
  1859. key: "isComplete",
  1860. get: function get() {
  1861. return _get(_getPrototypeOf(MaskedRange.prototype), "isComplete", this) && Boolean(this.value);
  1862. }
  1863. }, {
  1864. key: "boundaries",
  1865. value: function boundaries(str) {
  1866. var minstr = '';
  1867. var maxstr = '';
  1868. var _ref = str.match(/^(\D*)(\d*)(\D*)/) || [],
  1869. _ref2 = _slicedToArray(_ref, 3),
  1870. placeholder = _ref2[1],
  1871. num = _ref2[2];
  1872. if (num) {
  1873. minstr = '0'.repeat(placeholder.length) + num;
  1874. maxstr = '9'.repeat(placeholder.length) + num;
  1875. }
  1876. minstr = minstr.padEnd(this.maxLength, '0');
  1877. maxstr = maxstr.padEnd(this.maxLength, '9');
  1878. return [minstr, maxstr];
  1879. }
  1880. }, {
  1881. key: "doPrepare",
  1882. value: function doPrepare(str) {
  1883. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1884. str = _get(_getPrototypeOf(MaskedRange.prototype), "doPrepare", this).call(this, str, flags).replace(/\D/g, '');
  1885. if (!this.autofix) return str;
  1886. var fromStr = String(this.from).padStart(this.maxLength, '0');
  1887. var toStr = String(this.to).padStart(this.maxLength, '0');
  1888. var val = this.value;
  1889. var prepStr = '';
  1890. for (var ci = 0; ci < str.length; ++ci) {
  1891. var nextVal = val + prepStr + str[ci];
  1892. var _this$boundaries = this.boundaries(nextVal),
  1893. _this$boundaries2 = _slicedToArray(_this$boundaries, 2),
  1894. minstr = _this$boundaries2[0],
  1895. maxstr = _this$boundaries2[1];
  1896. if (Number(maxstr) < this.from) prepStr += fromStr[nextVal.length - 1];else if (Number(minstr) > this.to) prepStr += toStr[nextVal.length - 1];else prepStr += str[ci];
  1897. }
  1898. return prepStr;
  1899. }
  1900. }, {
  1901. key: "doValidate",
  1902. value: function doValidate() {
  1903. var _get2;
  1904. var str = this.value;
  1905. var firstNonZero = str.search(/[^0]/);
  1906. if (firstNonZero === -1 && str.length <= this._matchFrom) return true;
  1907. var _this$boundaries3 = this.boundaries(str),
  1908. _this$boundaries4 = _slicedToArray(_this$boundaries3, 2),
  1909. minstr = _this$boundaries4[0],
  1910. maxstr = _this$boundaries4[1];
  1911. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1912. args[_key] = arguments[_key];
  1913. }
  1914. return this.from <= Number(maxstr) && Number(minstr) <= this.to && (_get2 = _get(_getPrototypeOf(MaskedRange.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args));
  1915. }
  1916. }]);
  1917. return MaskedRange;
  1918. }(MaskedPattern);
  1919. IMask.MaskedRange = MaskedRange;
  1920. var MaskedDate = function (_MaskedPattern) {
  1921. _inherits(MaskedDate, _MaskedPattern);
  1922. var _super = _createSuper(MaskedDate);
  1923. function MaskedDate(opts) {
  1924. _classCallCheck(this, MaskedDate);
  1925. return _super.call(this, Object.assign({}, MaskedDate.DEFAULTS, opts));
  1926. }
  1927. _createClass(MaskedDate, [{
  1928. key: "_update",
  1929. value: function _update(opts) {
  1930. if (opts.mask === Date) delete opts.mask;
  1931. if (opts.pattern) opts.mask = opts.pattern;
  1932. var blocks = opts.blocks;
  1933. opts.blocks = Object.assign({}, MaskedDate.GET_DEFAULT_BLOCKS());
  1934. if (opts.min) opts.blocks.Y.from = opts.min.getFullYear();
  1935. if (opts.max) opts.blocks.Y.to = opts.max.getFullYear();
  1936. if (opts.min && opts.max && opts.blocks.Y.from === opts.blocks.Y.to) {
  1937. opts.blocks.m.from = opts.min.getMonth() + 1;
  1938. opts.blocks.m.to = opts.max.getMonth() + 1;
  1939. if (opts.blocks.m.from === opts.blocks.m.to) {
  1940. opts.blocks.d.from = opts.min.getDate();
  1941. opts.blocks.d.to = opts.max.getDate();
  1942. }
  1943. }
  1944. Object.assign(opts.blocks, blocks);
  1945. Object.keys(opts.blocks).forEach(function (bk) {
  1946. var b = opts.blocks[bk];
  1947. if (!('autofix' in b)) b.autofix = opts.autofix;
  1948. });
  1949. _get(_getPrototypeOf(MaskedDate.prototype), "_update", this).call(this, opts);
  1950. }
  1951. }, {
  1952. key: "doValidate",
  1953. value: function doValidate() {
  1954. var _get2;
  1955. var date = this.date;
  1956. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1957. args[_key] = arguments[_key];
  1958. }
  1959. return (_get2 = _get(_getPrototypeOf(MaskedDate.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args)) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max));
  1960. }
  1961. }, {
  1962. key: "isDateExist",
  1963. value: function isDateExist(str) {
  1964. return this.format(this.parse(str, this), this).indexOf(str) >= 0;
  1965. }
  1966. }, {
  1967. key: "date",
  1968. get: function get() {
  1969. return this.typedValue;
  1970. },
  1971. set: function set(date) {
  1972. this.typedValue = date;
  1973. }
  1974. }, {
  1975. key: "typedValue",
  1976. get: function get() {
  1977. return this.isComplete ? _get(_getPrototypeOf(MaskedDate.prototype), "typedValue", this) : null;
  1978. },
  1979. set: function set(value) {
  1980. _set(_getPrototypeOf(MaskedDate.prototype), "typedValue", value, this, true);
  1981. }
  1982. }]);
  1983. return MaskedDate;
  1984. }(MaskedPattern);
  1985. MaskedDate.DEFAULTS = {
  1986. pattern: 'd{.}`m{.}`Y',
  1987. format: function format(date) {
  1988. var day = String(date.getDate()).padStart(2, '0');
  1989. var month = String(date.getMonth() + 1).padStart(2, '0');
  1990. var year = date.getFullYear();
  1991. return [day, month, year].join('.');
  1992. },
  1993. parse: function parse(str) {
  1994. var _str$split = str.split('.'),
  1995. _str$split2 = _slicedToArray(_str$split, 3),
  1996. day = _str$split2[0],
  1997. month = _str$split2[1],
  1998. year = _str$split2[2];
  1999. return new Date(year, month - 1, day);
  2000. }
  2001. };
  2002. MaskedDate.GET_DEFAULT_BLOCKS = function () {
  2003. return {
  2004. d: {
  2005. mask: MaskedRange,
  2006. from: 1,
  2007. to: 31,
  2008. maxLength: 2
  2009. },
  2010. m: {
  2011. mask: MaskedRange,
  2012. from: 1,
  2013. to: 12,
  2014. maxLength: 2
  2015. },
  2016. Y: {
  2017. mask: MaskedRange,
  2018. from: 1900,
  2019. to: 9999
  2020. }
  2021. };
  2022. };
  2023. IMask.MaskedDate = MaskedDate;
  2024. var MaskElement = function () {
  2025. function MaskElement() {
  2026. _classCallCheck(this, MaskElement);
  2027. }
  2028. _createClass(MaskElement, [{
  2029. key: "selectionStart",
  2030. get:
  2031. function get() {
  2032. var start;
  2033. try {
  2034. start = this._unsafeSelectionStart;
  2035. } catch (e) {}
  2036. return start != null ? start : this.value.length;
  2037. }
  2038. }, {
  2039. key: "selectionEnd",
  2040. get: function get() {
  2041. var end;
  2042. try {
  2043. end = this._unsafeSelectionEnd;
  2044. } catch (e) {}
  2045. return end != null ? end : this.value.length;
  2046. }
  2047. }, {
  2048. key: "select",
  2049. value: function select(start, end) {
  2050. if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return;
  2051. try {
  2052. this._unsafeSelect(start, end);
  2053. } catch (e) {}
  2054. }
  2055. }, {
  2056. key: "_unsafeSelect",
  2057. value: function _unsafeSelect(start, end) {}
  2058. }, {
  2059. key: "isActive",
  2060. get: function get() {
  2061. return false;
  2062. }
  2063. }, {
  2064. key: "bindEvents",
  2065. value: function bindEvents(handlers) {}
  2066. }, {
  2067. key: "unbindEvents",
  2068. value: function unbindEvents() {}
  2069. }]);
  2070. return MaskElement;
  2071. }();
  2072. IMask.MaskElement = MaskElement;
  2073. var HTMLMaskElement = function (_MaskElement) {
  2074. _inherits(HTMLMaskElement, _MaskElement);
  2075. var _super = _createSuper(HTMLMaskElement);
  2076. function HTMLMaskElement(input) {
  2077. var _this;
  2078. _classCallCheck(this, HTMLMaskElement);
  2079. _this = _super.call(this);
  2080. _this.input = input;
  2081. _this._handlers = {};
  2082. return _this;
  2083. }
  2084. _createClass(HTMLMaskElement, [{
  2085. key: "rootElement",
  2086. get: function get() {
  2087. return this.input.getRootNode ? this.input.getRootNode() : document;
  2088. }
  2089. }, {
  2090. key: "isActive",
  2091. get: function get() {
  2092. return this.input === this.rootElement.activeElement;
  2093. }
  2094. }, {
  2095. key: "_unsafeSelectionStart",
  2096. get: function get() {
  2097. return this.input.selectionStart;
  2098. }
  2099. }, {
  2100. key: "_unsafeSelectionEnd",
  2101. get: function get() {
  2102. return this.input.selectionEnd;
  2103. }
  2104. }, {
  2105. key: "_unsafeSelect",
  2106. value: function _unsafeSelect(start, end) {
  2107. this.input.setSelectionRange(start, end);
  2108. }
  2109. }, {
  2110. key: "value",
  2111. get: function get() {
  2112. return this.input.value;
  2113. },
  2114. set: function set(value) {
  2115. this.input.value = value;
  2116. }
  2117. }, {
  2118. key: "bindEvents",
  2119. value: function bindEvents(handlers) {
  2120. var _this2 = this;
  2121. Object.keys(handlers).forEach(function (event) {
  2122. return _this2._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]);
  2123. });
  2124. }
  2125. }, {
  2126. key: "unbindEvents",
  2127. value: function unbindEvents() {
  2128. var _this3 = this;
  2129. Object.keys(this._handlers).forEach(function (event) {
  2130. return _this3._toggleEventHandler(event);
  2131. });
  2132. }
  2133. }, {
  2134. key: "_toggleEventHandler",
  2135. value: function _toggleEventHandler(event, handler) {
  2136. if (this._handlers[event]) {
  2137. this.input.removeEventListener(event, this._handlers[event]);
  2138. delete this._handlers[event];
  2139. }
  2140. if (handler) {
  2141. this.input.addEventListener(event, handler);
  2142. this._handlers[event] = handler;
  2143. }
  2144. }
  2145. }]);
  2146. return HTMLMaskElement;
  2147. }(MaskElement);
  2148. HTMLMaskElement.EVENTS_MAP = {
  2149. selectionChange: 'keydown',
  2150. input: 'input',
  2151. drop: 'drop',
  2152. click: 'click',
  2153. focus: 'focus',
  2154. commit: 'blur'
  2155. };
  2156. IMask.HTMLMaskElement = HTMLMaskElement;
  2157. var HTMLContenteditableMaskElement = function (_HTMLMaskElement) {
  2158. _inherits(HTMLContenteditableMaskElement, _HTMLMaskElement);
  2159. var _super = _createSuper(HTMLContenteditableMaskElement);
  2160. function HTMLContenteditableMaskElement() {
  2161. _classCallCheck(this, HTMLContenteditableMaskElement);
  2162. return _super.apply(this, arguments);
  2163. }
  2164. _createClass(HTMLContenteditableMaskElement, [{
  2165. key: "_unsafeSelectionStart",
  2166. get:
  2167. function get() {
  2168. var root = this.rootElement;
  2169. var selection = root.getSelection && root.getSelection();
  2170. return selection && selection.anchorOffset;
  2171. }
  2172. }, {
  2173. key: "_unsafeSelectionEnd",
  2174. get: function get() {
  2175. var root = this.rootElement;
  2176. var selection = root.getSelection && root.getSelection();
  2177. return selection && this._unsafeSelectionStart + String(selection).length;
  2178. }
  2179. }, {
  2180. key: "_unsafeSelect",
  2181. value: function _unsafeSelect(start, end) {
  2182. if (!this.rootElement.createRange) return;
  2183. var range = this.rootElement.createRange();
  2184. range.setStart(this.input.firstChild || this.input, start);
  2185. range.setEnd(this.input.lastChild || this.input, end);
  2186. var root = this.rootElement;
  2187. var selection = root.getSelection && root.getSelection();
  2188. if (selection) {
  2189. selection.removeAllRanges();
  2190. selection.addRange(range);
  2191. }
  2192. }
  2193. }, {
  2194. key: "value",
  2195. get: function get() {
  2196. return this.input.textContent;
  2197. },
  2198. set: function set(value) {
  2199. this.input.textContent = value;
  2200. }
  2201. }]);
  2202. return HTMLContenteditableMaskElement;
  2203. }(HTMLMaskElement);
  2204. IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
  2205. var InputMask = function () {
  2206. function InputMask(el, opts) {
  2207. _classCallCheck(this, InputMask);
  2208. this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLMaskElement(el);
  2209. this.masked = createMask(opts);
  2210. this._listeners = {};
  2211. this._value = '';
  2212. this._unmaskedValue = '';
  2213. this._saveSelection = this._saveSelection.bind(this);
  2214. this._onInput = this._onInput.bind(this);
  2215. this._onChange = this._onChange.bind(this);
  2216. this._onDrop = this._onDrop.bind(this);
  2217. this._onFocus = this._onFocus.bind(this);
  2218. this._onClick = this._onClick.bind(this);
  2219. this.alignCursor = this.alignCursor.bind(this);
  2220. this.alignCursorFriendly = this.alignCursorFriendly.bind(this);
  2221. this._bindEvents();
  2222. this.updateValue();
  2223. this._onChange();
  2224. }
  2225. _createClass(InputMask, [{
  2226. key: "mask",
  2227. get: function get() {
  2228. return this.masked.mask;
  2229. },
  2230. set: function set(mask) {
  2231. if (this.maskEquals(mask)) return;
  2232. if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
  2233. this.masked.updateOptions({
  2234. mask: mask
  2235. });
  2236. return;
  2237. }
  2238. var masked = createMask({
  2239. mask: mask
  2240. });
  2241. masked.unmaskedValue = this.masked.unmaskedValue;
  2242. this.masked = masked;
  2243. }
  2244. }, {
  2245. key: "maskEquals",
  2246. value: function maskEquals(mask) {
  2247. return mask == null || mask === this.masked.mask || mask === Date && this.masked instanceof MaskedDate;
  2248. }
  2249. }, {
  2250. key: "value",
  2251. get: function get() {
  2252. return this._value;
  2253. },
  2254. set: function set(str) {
  2255. this.masked.value = str;
  2256. this.updateControl();
  2257. this.alignCursor();
  2258. }
  2259. }, {
  2260. key: "unmaskedValue",
  2261. get: function get() {
  2262. return this._unmaskedValue;
  2263. },
  2264. set: function set(str) {
  2265. this.masked.unmaskedValue = str;
  2266. this.updateControl();
  2267. this.alignCursor();
  2268. }
  2269. }, {
  2270. key: "typedValue",
  2271. get: function get() {
  2272. return this.masked.typedValue;
  2273. },
  2274. set: function set(val) {
  2275. this.masked.typedValue = val;
  2276. this.updateControl();
  2277. this.alignCursor();
  2278. }
  2279. }, {
  2280. key: "_bindEvents",
  2281. value: function _bindEvents() {
  2282. this.el.bindEvents({
  2283. selectionChange: this._saveSelection,
  2284. input: this._onInput,
  2285. drop: this._onDrop,
  2286. click: this._onClick,
  2287. focus: this._onFocus,
  2288. commit: this._onChange
  2289. });
  2290. }
  2291. }, {
  2292. key: "_unbindEvents",
  2293. value: function _unbindEvents() {
  2294. if (this.el) this.el.unbindEvents();
  2295. }
  2296. }, {
  2297. key: "_fireEvent",
  2298. value: function _fireEvent(ev) {
  2299. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  2300. args[_key - 1] = arguments[_key];
  2301. }
  2302. var listeners = this._listeners[ev];
  2303. if (!listeners) return;
  2304. listeners.forEach(function (l) {
  2305. return l.apply(void 0, args);
  2306. });
  2307. }
  2308. }, {
  2309. key: "selectionStart",
  2310. get: function get() {
  2311. return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
  2312. }
  2313. }, {
  2314. key: "cursorPos",
  2315. get: function get() {
  2316. return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
  2317. },
  2318. set: function set(pos) {
  2319. if (!this.el || !this.el.isActive) return;
  2320. this.el.select(pos, pos);
  2321. this._saveSelection();
  2322. }
  2323. }, {
  2324. key: "_saveSelection",
  2325. value: function _saveSelection()
  2326. {
  2327. if (this.value !== this.el.value) {
  2328. console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.');
  2329. }
  2330. this._selection = {
  2331. start: this.selectionStart,
  2332. end: this.cursorPos
  2333. };
  2334. }
  2335. }, {
  2336. key: "updateValue",
  2337. value: function updateValue() {
  2338. this.masked.value = this.el.value;
  2339. this._value = this.masked.value;
  2340. }
  2341. }, {
  2342. key: "updateControl",
  2343. value: function updateControl() {
  2344. var newUnmaskedValue = this.masked.unmaskedValue;
  2345. var newValue = this.masked.value;
  2346. var isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue;
  2347. this._unmaskedValue = newUnmaskedValue;
  2348. this._value = newValue;
  2349. if (this.el.value !== newValue) this.el.value = newValue;
  2350. if (isChanged) this._fireChangeEvents();
  2351. }
  2352. }, {
  2353. key: "updateOptions",
  2354. value: function updateOptions(opts) {
  2355. var mask = opts.mask,
  2356. restOpts = _objectWithoutProperties(opts, ["mask"]);
  2357. var updateMask = !this.maskEquals(mask);
  2358. var updateOpts = !objectIncludes(this.masked, restOpts);
  2359. if (updateMask) this.mask = mask;
  2360. if (updateOpts) this.masked.updateOptions(restOpts);
  2361. if (updateMask || updateOpts) this.updateControl();
  2362. }
  2363. }, {
  2364. key: "updateCursor",
  2365. value: function updateCursor(cursorPos) {
  2366. if (cursorPos == null) return;
  2367. this.cursorPos = cursorPos;
  2368. this._delayUpdateCursor(cursorPos);
  2369. }
  2370. }, {
  2371. key: "_delayUpdateCursor",
  2372. value: function _delayUpdateCursor(cursorPos) {
  2373. var _this = this;
  2374. this._abortUpdateCursor();
  2375. this._changingCursorPos = cursorPos;
  2376. this._cursorChanging = setTimeout(function () {
  2377. if (!_this.el) return;
  2378. _this.cursorPos = _this._changingCursorPos;
  2379. _this._abortUpdateCursor();
  2380. }, 10);
  2381. }
  2382. }, {
  2383. key: "_fireChangeEvents",
  2384. value: function _fireChangeEvents() {
  2385. this._fireEvent('accept', this._inputEvent);
  2386. if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);
  2387. }
  2388. }, {
  2389. key: "_abortUpdateCursor",
  2390. value: function _abortUpdateCursor() {
  2391. if (this._cursorChanging) {
  2392. clearTimeout(this._cursorChanging);
  2393. delete this._cursorChanging;
  2394. }
  2395. }
  2396. }, {
  2397. key: "alignCursor",
  2398. value: function alignCursor() {
  2399. this.cursorPos = this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT);
  2400. }
  2401. }, {
  2402. key: "alignCursorFriendly",
  2403. value: function alignCursorFriendly() {
  2404. if (this.selectionStart !== this.cursorPos) return;
  2405. this.alignCursor();
  2406. }
  2407. }, {
  2408. key: "on",
  2409. value: function on(ev, handler) {
  2410. if (!this._listeners[ev]) this._listeners[ev] = [];
  2411. this._listeners[ev].push(handler);
  2412. return this;
  2413. }
  2414. }, {
  2415. key: "off",
  2416. value: function off(ev, handler) {
  2417. if (!this._listeners[ev]) return this;
  2418. if (!handler) {
  2419. delete this._listeners[ev];
  2420. return this;
  2421. }
  2422. var hIndex = this._listeners[ev].indexOf(handler);
  2423. if (hIndex >= 0) this._listeners[ev].splice(hIndex, 1);
  2424. return this;
  2425. }
  2426. }, {
  2427. key: "_onInput",
  2428. value: function _onInput(e) {
  2429. this._inputEvent = e;
  2430. this._abortUpdateCursor();
  2431. if (!this._selection) return this.updateValue();
  2432. var details = new ActionDetails(
  2433. this.el.value, this.cursorPos,
  2434. this.value, this._selection);
  2435. var oldRawValue = this.masked.rawInputValue;
  2436. var offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection).offset;
  2437. var removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
  2438. var cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
  2439. this.updateControl();
  2440. this.updateCursor(cursorPos);
  2441. delete this._inputEvent;
  2442. }
  2443. }, {
  2444. key: "_onChange",
  2445. value: function _onChange() {
  2446. if (this.value !== this.el.value) {
  2447. this.updateValue();
  2448. }
  2449. this.masked.doCommit();
  2450. this.updateControl();
  2451. this._saveSelection();
  2452. }
  2453. }, {
  2454. key: "_onDrop",
  2455. value: function _onDrop(ev) {
  2456. ev.preventDefault();
  2457. ev.stopPropagation();
  2458. }
  2459. }, {
  2460. key: "_onFocus",
  2461. value: function _onFocus(ev) {
  2462. this.alignCursorFriendly();
  2463. }
  2464. }, {
  2465. key: "_onClick",
  2466. value: function _onClick(ev) {
  2467. this.alignCursorFriendly();
  2468. }
  2469. }, {
  2470. key: "destroy",
  2471. value: function destroy() {
  2472. this._unbindEvents();
  2473. this._listeners.length = 0;
  2474. delete this.el;
  2475. }
  2476. }]);
  2477. return InputMask;
  2478. }();
  2479. IMask.InputMask = InputMask;
  2480. var MaskedEnum = function (_MaskedPattern) {
  2481. _inherits(MaskedEnum, _MaskedPattern);
  2482. var _super = _createSuper(MaskedEnum);
  2483. function MaskedEnum() {
  2484. _classCallCheck(this, MaskedEnum);
  2485. return _super.apply(this, arguments);
  2486. }
  2487. _createClass(MaskedEnum, [{
  2488. key: "_update",
  2489. value:
  2490. function _update(opts) {
  2491. if (opts.enum) opts.mask = '*'.repeat(opts.enum[0].length);
  2492. _get(_getPrototypeOf(MaskedEnum.prototype), "_update", this).call(this, opts);
  2493. }
  2494. }, {
  2495. key: "doValidate",
  2496. value: function doValidate() {
  2497. var _this = this,
  2498. _get2;
  2499. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2500. args[_key] = arguments[_key];
  2501. }
  2502. return this.enum.some(function (e) {
  2503. return e.indexOf(_this.unmaskedValue) >= 0;
  2504. }) && (_get2 = _get(_getPrototypeOf(MaskedEnum.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args));
  2505. }
  2506. }]);
  2507. return MaskedEnum;
  2508. }(MaskedPattern);
  2509. IMask.MaskedEnum = MaskedEnum;
  2510. var MaskedNumber = function (_Masked) {
  2511. _inherits(MaskedNumber, _Masked);
  2512. var _super = _createSuper(MaskedNumber);
  2513. function MaskedNumber(opts) {
  2514. _classCallCheck(this, MaskedNumber);
  2515. return _super.call(this, Object.assign({}, MaskedNumber.DEFAULTS, opts));
  2516. }
  2517. _createClass(MaskedNumber, [{
  2518. key: "_update",
  2519. value: function _update(opts) {
  2520. _get(_getPrototypeOf(MaskedNumber.prototype), "_update", this).call(this, opts);
  2521. this._updateRegExps();
  2522. }
  2523. }, {
  2524. key: "_updateRegExps",
  2525. value: function _updateRegExps() {
  2526. var start = '^' + (this.allowNegative ? '[+|\\-]?' : '');
  2527. var midInput = '(0|([1-9]+\\d*))?';
  2528. var mid = '\\d*';
  2529. var end = (this.scale ? '(' + escapeRegExp(this.radix) + '\\d{0,' + this.scale + '})?' : '') + '$';
  2530. this._numberRegExpInput = new RegExp(start + midInput + end);
  2531. this._numberRegExp = new RegExp(start + mid + end);
  2532. this._mapToRadixRegExp = new RegExp('[' + this.mapToRadix.map(escapeRegExp).join('') + ']', 'g');
  2533. this._thousandsSeparatorRegExp = new RegExp(escapeRegExp(this.thousandsSeparator), 'g');
  2534. }
  2535. }, {
  2536. key: "_removeThousandsSeparators",
  2537. value: function _removeThousandsSeparators(value) {
  2538. return value.replace(this._thousandsSeparatorRegExp, '');
  2539. }
  2540. }, {
  2541. key: "_insertThousandsSeparators",
  2542. value: function _insertThousandsSeparators(value) {
  2543. var parts = value.split(this.radix);
  2544. parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator);
  2545. return parts.join(this.radix);
  2546. }
  2547. }, {
  2548. key: "doPrepare",
  2549. value: function doPrepare(str) {
  2550. var _get2;
  2551. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  2552. args[_key - 1] = arguments[_key];
  2553. }
  2554. return (_get2 = _get(_getPrototypeOf(MaskedNumber.prototype), "doPrepare", this)).call.apply(_get2, [this, this._removeThousandsSeparators(str.replace(this._mapToRadixRegExp, this.radix))].concat(args));
  2555. }
  2556. }, {
  2557. key: "_separatorsCount",
  2558. value: function _separatorsCount(to) {
  2559. var extendOnSeparators = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2560. var count = 0;
  2561. for (var pos = 0; pos < to; ++pos) {
  2562. if (this._value.indexOf(this.thousandsSeparator, pos) === pos) {
  2563. ++count;
  2564. if (extendOnSeparators) to += this.thousandsSeparator.length;
  2565. }
  2566. }
  2567. return count;
  2568. }
  2569. }, {
  2570. key: "_separatorsCountFromSlice",
  2571. value: function _separatorsCountFromSlice() {
  2572. var slice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._value;
  2573. return this._separatorsCount(this._removeThousandsSeparators(slice).length, true);
  2574. }
  2575. }, {
  2576. key: "extractInput",
  2577. value: function extractInput() {
  2578. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  2579. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  2580. var flags = arguments.length > 2 ? arguments[2] : undefined;
  2581. var _this$_adjustRangeWit = this._adjustRangeWithSeparators(fromPos, toPos);
  2582. var _this$_adjustRangeWit2 = _slicedToArray(_this$_adjustRangeWit, 2);
  2583. fromPos = _this$_adjustRangeWit2[0];
  2584. toPos = _this$_adjustRangeWit2[1];
  2585. return this._removeThousandsSeparators(_get(_getPrototypeOf(MaskedNumber.prototype), "extractInput", this).call(this, fromPos, toPos, flags));
  2586. }
  2587. }, {
  2588. key: "_appendCharRaw",
  2589. value: function _appendCharRaw(ch) {
  2590. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2591. if (!this.thousandsSeparator) return _get(_getPrototypeOf(MaskedNumber.prototype), "_appendCharRaw", this).call(this, ch, flags);
  2592. var prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
  2593. var prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue);
  2594. this._value = this._removeThousandsSeparators(this.value);
  2595. var appendDetails = _get(_getPrototypeOf(MaskedNumber.prototype), "_appendCharRaw", this).call(this, ch, flags);
  2596. this._value = this._insertThousandsSeparators(this._value);
  2597. var beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
  2598. var beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue);
  2599. appendDetails.tailShift += (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length;
  2600. appendDetails.skip = !appendDetails.rawInserted && ch === this.thousandsSeparator;
  2601. return appendDetails;
  2602. }
  2603. }, {
  2604. key: "_findSeparatorAround",
  2605. value: function _findSeparatorAround(pos) {
  2606. if (this.thousandsSeparator) {
  2607. var searchFrom = pos - this.thousandsSeparator.length + 1;
  2608. var separatorPos = this.value.indexOf(this.thousandsSeparator, searchFrom);
  2609. if (separatorPos <= pos) return separatorPos;
  2610. }
  2611. return -1;
  2612. }
  2613. }, {
  2614. key: "_adjustRangeWithSeparators",
  2615. value: function _adjustRangeWithSeparators(from, to) {
  2616. var separatorAroundFromPos = this._findSeparatorAround(from);
  2617. if (separatorAroundFromPos >= 0) from = separatorAroundFromPos;
  2618. var separatorAroundToPos = this._findSeparatorAround(to);
  2619. if (separatorAroundToPos >= 0) to = separatorAroundToPos + this.thousandsSeparator.length;
  2620. return [from, to];
  2621. }
  2622. }, {
  2623. key: "remove",
  2624. value: function remove() {
  2625. var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  2626. var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length;
  2627. var _this$_adjustRangeWit3 = this._adjustRangeWithSeparators(fromPos, toPos);
  2628. var _this$_adjustRangeWit4 = _slicedToArray(_this$_adjustRangeWit3, 2);
  2629. fromPos = _this$_adjustRangeWit4[0];
  2630. toPos = _this$_adjustRangeWit4[1];
  2631. var valueBeforePos = this.value.slice(0, fromPos);
  2632. var valueAfterPos = this.value.slice(toPos);
  2633. var prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length);
  2634. this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(valueBeforePos + valueAfterPos));
  2635. var beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos);
  2636. return new ChangeDetails({
  2637. tailShift: (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length
  2638. });
  2639. }
  2640. }, {
  2641. key: "nearestInputPos",
  2642. value: function nearestInputPos(cursorPos, direction) {
  2643. if (!this.thousandsSeparator) return cursorPos;
  2644. switch (direction) {
  2645. case DIRECTION.NONE:
  2646. case DIRECTION.LEFT:
  2647. case DIRECTION.FORCE_LEFT:
  2648. {
  2649. var separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1);
  2650. if (separatorAtLeftPos >= 0) {
  2651. var separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length;
  2652. if (cursorPos < separatorAtLeftEndPos || this.value.length <= separatorAtLeftEndPos || direction === DIRECTION.FORCE_LEFT) {
  2653. return separatorAtLeftPos;
  2654. }
  2655. }
  2656. break;
  2657. }
  2658. case DIRECTION.RIGHT:
  2659. case DIRECTION.FORCE_RIGHT:
  2660. {
  2661. var separatorAtRightPos = this._findSeparatorAround(cursorPos);
  2662. if (separatorAtRightPos >= 0) {
  2663. return separatorAtRightPos + this.thousandsSeparator.length;
  2664. }
  2665. }
  2666. }
  2667. return cursorPos;
  2668. }
  2669. }, {
  2670. key: "doValidate",
  2671. value: function doValidate(flags) {
  2672. var regexp = flags.input ? this._numberRegExpInput : this._numberRegExp;
  2673. var valid = regexp.test(this._removeThousandsSeparators(this.value));
  2674. if (valid) {
  2675. var number = this.number;
  2676. valid = valid && !isNaN(number) && (
  2677. this.min == null || this.min >= 0 || this.min <= this.number) && (
  2678. this.max == null || this.max <= 0 || this.number <= this.max);
  2679. }
  2680. return valid && _get(_getPrototypeOf(MaskedNumber.prototype), "doValidate", this).call(this, flags);
  2681. }
  2682. }, {
  2683. key: "doCommit",
  2684. value: function doCommit() {
  2685. if (this.value) {
  2686. var number = this.number;
  2687. var validnum = number;
  2688. if (this.min != null) validnum = Math.max(validnum, this.min);
  2689. if (this.max != null) validnum = Math.min(validnum, this.max);
  2690. if (validnum !== number) this.unmaskedValue = String(validnum);
  2691. var formatted = this.value;
  2692. if (this.normalizeZeros) formatted = this._normalizeZeros(formatted);
  2693. if (this.padFractionalZeros) formatted = this._padFractionalZeros(formatted);
  2694. this._value = formatted;
  2695. }
  2696. _get(_getPrototypeOf(MaskedNumber.prototype), "doCommit", this).call(this);
  2697. }
  2698. }, {
  2699. key: "_normalizeZeros",
  2700. value: function _normalizeZeros(value) {
  2701. var parts = this._removeThousandsSeparators(value).split(this.radix);
  2702. parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, function (match, sign, zeros, num) {
  2703. return sign + num;
  2704. });
  2705. if (value.length && !/\d$/.test(parts[0])) parts[0] = parts[0] + '0';
  2706. if (parts.length > 1) {
  2707. parts[1] = parts[1].replace(/0*$/, '');
  2708. if (!parts[1].length) parts.length = 1;
  2709. }
  2710. return this._insertThousandsSeparators(parts.join(this.radix));
  2711. }
  2712. }, {
  2713. key: "_padFractionalZeros",
  2714. value: function _padFractionalZeros(value) {
  2715. if (!value) return value;
  2716. var parts = value.split(this.radix);
  2717. if (parts.length < 2) parts.push('');
  2718. parts[1] = parts[1].padEnd(this.scale, '0');
  2719. return parts.join(this.radix);
  2720. }
  2721. }, {
  2722. key: "unmaskedValue",
  2723. get: function get() {
  2724. return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, '.');
  2725. },
  2726. set: function set(unmaskedValue) {
  2727. _set(_getPrototypeOf(MaskedNumber.prototype), "unmaskedValue", unmaskedValue.replace('.', this.radix), this, true);
  2728. }
  2729. }, {
  2730. key: "typedValue",
  2731. get: function get() {
  2732. return Number(this.unmaskedValue);
  2733. },
  2734. set: function set(n) {
  2735. _set(_getPrototypeOf(MaskedNumber.prototype), "unmaskedValue", String(n), this, true);
  2736. }
  2737. }, {
  2738. key: "number",
  2739. get: function get() {
  2740. return this.typedValue;
  2741. },
  2742. set: function set(number) {
  2743. this.typedValue = number;
  2744. }
  2745. }, {
  2746. key: "allowNegative",
  2747. get: function get() {
  2748. return this.signed || this.min != null && this.min < 0 || this.max != null && this.max < 0;
  2749. }
  2750. }]);
  2751. return MaskedNumber;
  2752. }(Masked);
  2753. MaskedNumber.DEFAULTS = {
  2754. radix: ',',
  2755. thousandsSeparator: '',
  2756. mapToRadix: ['.'],
  2757. scale: 2,
  2758. signed: false,
  2759. normalizeZeros: true,
  2760. padFractionalZeros: false
  2761. };
  2762. IMask.MaskedNumber = MaskedNumber;
  2763. var MaskedFunction = function (_Masked) {
  2764. _inherits(MaskedFunction, _Masked);
  2765. var _super = _createSuper(MaskedFunction);
  2766. function MaskedFunction() {
  2767. _classCallCheck(this, MaskedFunction);
  2768. return _super.apply(this, arguments);
  2769. }
  2770. _createClass(MaskedFunction, [{
  2771. key: "_update",
  2772. value:
  2773. function _update(opts) {
  2774. if (opts.mask) opts.validate = opts.mask;
  2775. _get(_getPrototypeOf(MaskedFunction.prototype), "_update", this).call(this, opts);
  2776. }
  2777. }]);
  2778. return MaskedFunction;
  2779. }(Masked);
  2780. IMask.MaskedFunction = MaskedFunction;
  2781. var MaskedDynamic = function (_Masked) {
  2782. _inherits(MaskedDynamic, _Masked);
  2783. var _super = _createSuper(MaskedDynamic);
  2784. function MaskedDynamic(opts) {
  2785. var _this;
  2786. _classCallCheck(this, MaskedDynamic);
  2787. _this = _super.call(this, Object.assign({}, MaskedDynamic.DEFAULTS, opts));
  2788. _this.currentMask = null;
  2789. return _this;
  2790. }
  2791. _createClass(MaskedDynamic, [{
  2792. key: "_update",
  2793. value: function _update(opts) {
  2794. _get(_getPrototypeOf(MaskedDynamic.prototype), "_update", this).call(this, opts);
  2795. if ('mask' in opts) {
  2796. this.compiledMasks = Array.isArray(opts.mask) ? opts.mask.map(function (m) {
  2797. return createMask(m);
  2798. }) : [];
  2799. }
  2800. }
  2801. }, {
  2802. key: "_appendCharRaw",
  2803. value: function _appendCharRaw(ch) {
  2804. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2805. var details = this._applyDispatch(ch, flags);
  2806. if (this.currentMask) {
  2807. details.aggregate(this.currentMask._appendChar(ch, flags));
  2808. }
  2809. return details;
  2810. }
  2811. }, {
  2812. key: "_applyDispatch",
  2813. value: function _applyDispatch() {
  2814. var appended = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  2815. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2816. var prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value;
  2817. var inputValue = this.rawInputValue;
  2818. var insertValue = flags.tail && flags._beforeTailState != null ?
  2819. flags._beforeTailState._rawInputValue : inputValue;
  2820. var tailValue = inputValue.slice(insertValue.length);
  2821. var prevMask = this.currentMask;
  2822. var details = new ChangeDetails();
  2823. var prevMaskState = prevMask && prevMask.state;
  2824. this.currentMask = this.doDispatch(appended, Object.assign({}, flags));
  2825. if (this.currentMask) {
  2826. if (this.currentMask !== prevMask) {
  2827. this.currentMask.reset();
  2828. if (insertValue) {
  2829. var d = this.currentMask.append(insertValue, {
  2830. raw: true
  2831. });
  2832. details.tailShift = d.inserted.length - prevValueBeforeTail.length;
  2833. }
  2834. if (tailValue) {
  2835. details.tailShift += this.currentMask.append(tailValue, {
  2836. raw: true,
  2837. tail: true
  2838. }).tailShift;
  2839. }
  2840. } else {
  2841. this.currentMask.state = prevMaskState;
  2842. }
  2843. }
  2844. return details;
  2845. }
  2846. }, {
  2847. key: "_appendPlaceholder",
  2848. value: function _appendPlaceholder() {
  2849. var details = this._applyDispatch.apply(this, arguments);
  2850. if (this.currentMask) {
  2851. details.aggregate(this.currentMask._appendPlaceholder());
  2852. }
  2853. return details;
  2854. }
  2855. }, {
  2856. key: "doDispatch",
  2857. value: function doDispatch(appended) {
  2858. var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2859. return this.dispatch(appended, this, flags);
  2860. }
  2861. }, {
  2862. key: "doValidate",
  2863. value: function doValidate() {
  2864. var _get2, _this$currentMask;
  2865. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2866. args[_key] = arguments[_key];
  2867. }
  2868. return (_get2 = _get(_getPrototypeOf(MaskedDynamic.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args)) && (!this.currentMask || (_this$currentMask = this.currentMask).doValidate.apply(_this$currentMask, args));
  2869. }
  2870. }, {
  2871. key: "reset",
  2872. value: function reset() {
  2873. if (this.currentMask) this.currentMask.reset();
  2874. this.compiledMasks.forEach(function (m) {
  2875. return m.reset();
  2876. });
  2877. }
  2878. }, {
  2879. key: "value",
  2880. get: function get() {
  2881. return this.currentMask ? this.currentMask.value : '';
  2882. },
  2883. set: function set(value) {
  2884. _set(_getPrototypeOf(MaskedDynamic.prototype), "value", value, this, true);
  2885. }
  2886. }, {
  2887. key: "unmaskedValue",
  2888. get: function get() {
  2889. return this.currentMask ? this.currentMask.unmaskedValue : '';
  2890. },
  2891. set: function set(unmaskedValue) {
  2892. _set(_getPrototypeOf(MaskedDynamic.prototype), "unmaskedValue", unmaskedValue, this, true);
  2893. }
  2894. }, {
  2895. key: "typedValue",
  2896. get: function get() {
  2897. return this.currentMask ? this.currentMask.typedValue : '';
  2898. }
  2899. ,
  2900. set: function set(value) {
  2901. var unmaskedValue = String(value);
  2902. if (this.currentMask) {
  2903. this.currentMask.typedValue = value;
  2904. unmaskedValue = this.currentMask.unmaskedValue;
  2905. }
  2906. this.unmaskedValue = unmaskedValue;
  2907. }
  2908. }, {
  2909. key: "isComplete",
  2910. get: function get() {
  2911. return !!this.currentMask && this.currentMask.isComplete;
  2912. }
  2913. }, {
  2914. key: "remove",
  2915. value: function remove() {
  2916. var details = new ChangeDetails();
  2917. if (this.currentMask) {
  2918. var _this$currentMask2;
  2919. details.aggregate((_this$currentMask2 = this.currentMask).remove.apply(_this$currentMask2, arguments))
  2920. .aggregate(this._applyDispatch());
  2921. }
  2922. return details;
  2923. }
  2924. }, {
  2925. key: "state",
  2926. get: function get() {
  2927. return Object.assign({}, _get(_getPrototypeOf(MaskedDynamic.prototype), "state", this), {
  2928. _rawInputValue: this.rawInputValue,
  2929. compiledMasks: this.compiledMasks.map(function (m) {
  2930. return m.state;
  2931. }),
  2932. currentMaskRef: this.currentMask,
  2933. currentMask: this.currentMask && this.currentMask.state
  2934. });
  2935. },
  2936. set: function set(state) {
  2937. var compiledMasks = state.compiledMasks,
  2938. currentMaskRef = state.currentMaskRef,
  2939. currentMask = state.currentMask,
  2940. maskedState = _objectWithoutProperties(state, ["compiledMasks", "currentMaskRef", "currentMask"]);
  2941. this.compiledMasks.forEach(function (m, mi) {
  2942. return m.state = compiledMasks[mi];
  2943. });
  2944. if (currentMaskRef != null) {
  2945. this.currentMask = currentMaskRef;
  2946. this.currentMask.state = currentMask;
  2947. }
  2948. _set(_getPrototypeOf(MaskedDynamic.prototype), "state", maskedState, this, true);
  2949. }
  2950. }, {
  2951. key: "extractInput",
  2952. value: function extractInput() {
  2953. var _this$currentMask3;
  2954. return this.currentMask ? (_this$currentMask3 = this.currentMask).extractInput.apply(_this$currentMask3, arguments) : '';
  2955. }
  2956. }, {
  2957. key: "extractTail",
  2958. value: function extractTail() {
  2959. var _this$currentMask4, _get3;
  2960. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2961. args[_key2] = arguments[_key2];
  2962. }
  2963. return this.currentMask ? (_this$currentMask4 = this.currentMask).extractTail.apply(_this$currentMask4, args) : (_get3 = _get(_getPrototypeOf(MaskedDynamic.prototype), "extractTail", this)).call.apply(_get3, [this].concat(args));
  2964. }
  2965. }, {
  2966. key: "doCommit",
  2967. value: function doCommit() {
  2968. if (this.currentMask) this.currentMask.doCommit();
  2969. _get(_getPrototypeOf(MaskedDynamic.prototype), "doCommit", this).call(this);
  2970. }
  2971. }, {
  2972. key: "nearestInputPos",
  2973. value: function nearestInputPos() {
  2974. var _this$currentMask5, _get4;
  2975. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  2976. args[_key3] = arguments[_key3];
  2977. }
  2978. return this.currentMask ? (_this$currentMask5 = this.currentMask).nearestInputPos.apply(_this$currentMask5, args) : (_get4 = _get(_getPrototypeOf(MaskedDynamic.prototype), "nearestInputPos", this)).call.apply(_get4, [this].concat(args));
  2979. }
  2980. }, {
  2981. key: "overwrite",
  2982. get: function get() {
  2983. return this.currentMask ? this.currentMask.overwrite : _get(_getPrototypeOf(MaskedDynamic.prototype), "overwrite", this);
  2984. },
  2985. set: function set(overwrite) {
  2986. console.warn('"overwrite" option is not available in dynamic mask, use this option in siblings');
  2987. }
  2988. }]);
  2989. return MaskedDynamic;
  2990. }(Masked);
  2991. MaskedDynamic.DEFAULTS = {
  2992. dispatch: function dispatch(appended, masked, flags) {
  2993. if (!masked.compiledMasks.length) return;
  2994. var inputValue = masked.rawInputValue;
  2995. var inputs = masked.compiledMasks.map(function (m, index) {
  2996. m.reset();
  2997. m.append(inputValue, {
  2998. raw: true
  2999. });
  3000. m.append(appended, flags);
  3001. var weight = m.rawInputValue.length;
  3002. return {
  3003. weight: weight,
  3004. index: index
  3005. };
  3006. });
  3007. inputs.sort(function (i1, i2) {
  3008. return i2.weight - i1.weight;
  3009. });
  3010. return masked.compiledMasks[inputs[0].index];
  3011. }
  3012. };
  3013. IMask.MaskedDynamic = MaskedDynamic;
  3014. var PIPE_TYPE = {
  3015. MASKED: 'value',
  3016. UNMASKED: 'unmaskedValue',
  3017. TYPED: 'typedValue'
  3018. };
  3019. function createPipe(mask) {
  3020. var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PIPE_TYPE.MASKED;
  3021. var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : PIPE_TYPE.MASKED;
  3022. var masked = createMask(mask);
  3023. return function (value) {
  3024. return masked.runIsolated(function (m) {
  3025. m[from] = value;
  3026. return m[to];
  3027. });
  3028. };
  3029. }
  3030. function pipe(value) {
  3031. for (var _len = arguments.length, pipeArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  3032. pipeArgs[_key - 1] = arguments[_key];
  3033. }
  3034. return createPipe.apply(void 0, pipeArgs)(value);
  3035. }
  3036. IMask.PIPE_TYPE = PIPE_TYPE;
  3037. IMask.createPipe = createPipe;
  3038. IMask.pipe = pipe;
  3039. try {
  3040. globalThis.IMask = IMask;
  3041. } catch (e) {}
  3042. var maskElementList = [].slice.call(document.querySelectorAll('[data-mask]'));
  3043. maskElementList.map(function (maskEl) {
  3044. return new IMask(maskEl, {
  3045. mask: maskEl.dataset.mask,
  3046. lazy: maskEl.dataset['mask-visible'] === 'true'
  3047. });
  3048. });
  3049. var top = 'top';
  3050. var bottom = 'bottom';
  3051. var right = 'right';
  3052. var left = 'left';
  3053. var auto = 'auto';
  3054. var basePlacements = [top, bottom, right, left];
  3055. var start = 'start';
  3056. var end = 'end';
  3057. var clippingParents = 'clippingParents';
  3058. var viewport = 'viewport';
  3059. var popper = 'popper';
  3060. var reference = 'reference';
  3061. var variationPlacements = basePlacements.reduce(function (acc, placement) {
  3062. return acc.concat([placement + "-" + start, placement + "-" + end]);
  3063. }, []);
  3064. var placements = [].concat(basePlacements, [auto]).reduce(function (acc, placement) {
  3065. return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
  3066. }, []);
  3067. var beforeRead = 'beforeRead';
  3068. var read = 'read';
  3069. var afterRead = 'afterRead';
  3070. var beforeMain = 'beforeMain';
  3071. var main = 'main';
  3072. var afterMain = 'afterMain';
  3073. var beforeWrite = 'beforeWrite';
  3074. var write = 'write';
  3075. var afterWrite = 'afterWrite';
  3076. var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
  3077. function getNodeName(element) {
  3078. return element ? (element.nodeName || '').toLowerCase() : null;
  3079. }
  3080. function getWindow(node) {
  3081. if (node == null) {
  3082. return window;
  3083. }
  3084. if (node.toString() !== '[object Window]') {
  3085. var ownerDocument = node.ownerDocument;
  3086. return ownerDocument ? ownerDocument.defaultView || window : window;
  3087. }
  3088. return node;
  3089. }
  3090. function isElement$1(node) {
  3091. var OwnElement = getWindow(node).Element;
  3092. return node instanceof OwnElement || node instanceof Element;
  3093. }
  3094. function isHTMLElement(node) {
  3095. var OwnElement = getWindow(node).HTMLElement;
  3096. return node instanceof OwnElement || node instanceof HTMLElement;
  3097. }
  3098. function isShadowRoot(node) {
  3099. if (typeof ShadowRoot === 'undefined') {
  3100. return false;
  3101. }
  3102. var OwnElement = getWindow(node).ShadowRoot;
  3103. return node instanceof OwnElement || node instanceof ShadowRoot;
  3104. }
  3105. function applyStyles(_ref) {
  3106. var state = _ref.state;
  3107. Object.keys(state.elements).forEach(function (name) {
  3108. var style = state.styles[name] || {};
  3109. var attributes = state.attributes[name] || {};
  3110. var element = state.elements[name];
  3111. if (!isHTMLElement(element) || !getNodeName(element)) {
  3112. return;
  3113. }
  3114. Object.assign(element.style, style);
  3115. Object.keys(attributes).forEach(function (name) {
  3116. var value = attributes[name];
  3117. if (value === false) {
  3118. element.removeAttribute(name);
  3119. } else {
  3120. element.setAttribute(name, value === true ? '' : value);
  3121. }
  3122. });
  3123. });
  3124. }
  3125. function effect$2(_ref2) {
  3126. var state = _ref2.state;
  3127. var initialStyles = {
  3128. popper: {
  3129. position: state.options.strategy,
  3130. left: '0',
  3131. top: '0',
  3132. margin: '0'
  3133. },
  3134. arrow: {
  3135. position: 'absolute'
  3136. },
  3137. reference: {}
  3138. };
  3139. Object.assign(state.elements.popper.style, initialStyles.popper);
  3140. state.styles = initialStyles;
  3141. if (state.elements.arrow) {
  3142. Object.assign(state.elements.arrow.style, initialStyles.arrow);
  3143. }
  3144. return function () {
  3145. Object.keys(state.elements).forEach(function (name) {
  3146. var element = state.elements[name];
  3147. var attributes = state.attributes[name] || {};
  3148. var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]);
  3149. var style = styleProperties.reduce(function (style, property) {
  3150. style[property] = '';
  3151. return style;
  3152. }, {});
  3153. if (!isHTMLElement(element) || !getNodeName(element)) {
  3154. return;
  3155. }
  3156. Object.assign(element.style, style);
  3157. Object.keys(attributes).forEach(function (attribute) {
  3158. element.removeAttribute(attribute);
  3159. });
  3160. });
  3161. };
  3162. }
  3163. var applyStyles$1 = {
  3164. name: 'applyStyles',
  3165. enabled: true,
  3166. phase: 'write',
  3167. fn: applyStyles,
  3168. effect: effect$2,
  3169. requires: ['computeStyles']
  3170. };
  3171. function getBasePlacement(placement) {
  3172. return placement.split('-')[0];
  3173. }
  3174. function getBoundingClientRect(element) {
  3175. var rect = element.getBoundingClientRect();
  3176. return {
  3177. width: rect.width,
  3178. height: rect.height,
  3179. top: rect.top,
  3180. right: rect.right,
  3181. bottom: rect.bottom,
  3182. left: rect.left,
  3183. x: rect.left,
  3184. y: rect.top
  3185. };
  3186. }
  3187. function getLayoutRect(element) {
  3188. var clientRect = getBoundingClientRect(element);
  3189. var width = element.offsetWidth;
  3190. var height = element.offsetHeight;
  3191. if (Math.abs(clientRect.width - width) <= 1) {
  3192. width = clientRect.width;
  3193. }
  3194. if (Math.abs(clientRect.height - height) <= 1) {
  3195. height = clientRect.height;
  3196. }
  3197. return {
  3198. x: element.offsetLeft,
  3199. y: element.offsetTop,
  3200. width: width,
  3201. height: height
  3202. };
  3203. }
  3204. function contains(parent, child) {
  3205. var rootNode = child.getRootNode && child.getRootNode();
  3206. if (parent.contains(child)) {
  3207. return true;
  3208. }
  3209. else if (rootNode && isShadowRoot(rootNode)) {
  3210. var next = child;
  3211. do {
  3212. if (next && parent.isSameNode(next)) {
  3213. return true;
  3214. }
  3215. next = next.parentNode || next.host;
  3216. } while (next);
  3217. }
  3218. return false;
  3219. }
  3220. function getComputedStyle$1(element) {
  3221. return getWindow(element).getComputedStyle(element);
  3222. }
  3223. function isTableElement(element) {
  3224. return ['table', 'td', 'th'].indexOf(getNodeName(element)) >= 0;
  3225. }
  3226. function getDocumentElement(element) {
  3227. return ((isElement$1(element) ? element.ownerDocument :
  3228. element.document) || window.document).documentElement;
  3229. }
  3230. function getParentNode(element) {
  3231. if (getNodeName(element) === 'html') {
  3232. return element;
  3233. }
  3234. return (
  3235. element.assignedSlot ||
  3236. element.parentNode || (
  3237. isShadowRoot(element) ? element.host : null) ||
  3238. getDocumentElement(element)
  3239. );
  3240. }
  3241. function getTrueOffsetParent(element) {
  3242. if (!isHTMLElement(element) ||
  3243. getComputedStyle$1(element).position === 'fixed') {
  3244. return null;
  3245. }
  3246. return element.offsetParent;
  3247. }
  3248. function getContainingBlock(element) {
  3249. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
  3250. var isIE = navigator.userAgent.indexOf('Trident') !== -1;
  3251. if (isIE && isHTMLElement(element)) {
  3252. var elementCss = getComputedStyle$1(element);
  3253. if (elementCss.position === 'fixed') {
  3254. return null;
  3255. }
  3256. }
  3257. var currentNode = getParentNode(element);
  3258. while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
  3259. var css = getComputedStyle$1(currentNode);
  3260. if (css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || ['transform', 'perspective'].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === 'filter' || isFirefox && css.filter && css.filter !== 'none') {
  3261. return currentNode;
  3262. } else {
  3263. currentNode = currentNode.parentNode;
  3264. }
  3265. }
  3266. return null;
  3267. }
  3268. function getOffsetParent(element) {
  3269. var window = getWindow(element);
  3270. var offsetParent = getTrueOffsetParent(element);
  3271. while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === 'static') {
  3272. offsetParent = getTrueOffsetParent(offsetParent);
  3273. }
  3274. if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle$1(offsetParent).position === 'static')) {
  3275. return window;
  3276. }
  3277. return offsetParent || getContainingBlock(element) || window;
  3278. }
  3279. function getMainAxisFromPlacement(placement) {
  3280. return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
  3281. }
  3282. var max = Math.max;
  3283. var min = Math.min;
  3284. var round = Math.round;
  3285. function within(min$1, value, max$1) {
  3286. return max(min$1, min(value, max$1));
  3287. }
  3288. function getFreshSideObject() {
  3289. return {
  3290. top: 0,
  3291. right: 0,
  3292. bottom: 0,
  3293. left: 0
  3294. };
  3295. }
  3296. function mergePaddingObject(paddingObject) {
  3297. return Object.assign({}, getFreshSideObject(), paddingObject);
  3298. }
  3299. function expandToHashMap(value, keys) {
  3300. return keys.reduce(function (hashMap, key) {
  3301. hashMap[key] = value;
  3302. return hashMap;
  3303. }, {});
  3304. }
  3305. var toPaddingObject = function toPaddingObject(padding, state) {
  3306. padding = typeof padding === 'function' ? padding(Object.assign({}, state.rects, {
  3307. placement: state.placement
  3308. })) : padding;
  3309. return mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  3310. };
  3311. function arrow(_ref) {
  3312. var _state$modifiersData$;
  3313. var state = _ref.state,
  3314. name = _ref.name,
  3315. options = _ref.options;
  3316. var arrowElement = state.elements.arrow;
  3317. var popperOffsets = state.modifiersData.popperOffsets;
  3318. var basePlacement = getBasePlacement(state.placement);
  3319. var axis = getMainAxisFromPlacement(basePlacement);
  3320. var isVertical = [left, right].indexOf(basePlacement) >= 0;
  3321. var len = isVertical ? 'height' : 'width';
  3322. if (!arrowElement || !popperOffsets) {
  3323. return;
  3324. }
  3325. var paddingObject = toPaddingObject(options.padding, state);
  3326. var arrowRect = getLayoutRect(arrowElement);
  3327. var minProp = axis === 'y' ? top : left;
  3328. var maxProp = axis === 'y' ? bottom : right;
  3329. var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets[axis] - state.rects.popper[len];
  3330. var startDiff = popperOffsets[axis] - state.rects.reference[axis];
  3331. var arrowOffsetParent = getOffsetParent(arrowElement);
  3332. var clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
  3333. var centerToReference = endDiff / 2 - startDiff / 2;
  3334. var min = paddingObject[minProp];
  3335. var max = clientSize - arrowRect[len] - paddingObject[maxProp];
  3336. var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
  3337. var offset = within(min, center, max);
  3338. var axisProp = axis;
  3339. state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset, _state$modifiersData$.centerOffset = offset - center, _state$modifiersData$);
  3340. }
  3341. function effect$1(_ref2) {
  3342. var state = _ref2.state,
  3343. options = _ref2.options;
  3344. var _options$element = options.element,
  3345. arrowElement = _options$element === void 0 ? '[data-popper-arrow]' : _options$element;
  3346. if (arrowElement == null) {
  3347. return;
  3348. }
  3349. if (typeof arrowElement === 'string') {
  3350. arrowElement = state.elements.popper.querySelector(arrowElement);
  3351. if (!arrowElement) {
  3352. return;
  3353. }
  3354. }
  3355. if (!contains(state.elements.popper, arrowElement)) {
  3356. return;
  3357. }
  3358. state.elements.arrow = arrowElement;
  3359. }
  3360. var arrow$1 = {
  3361. name: 'arrow',
  3362. enabled: true,
  3363. phase: 'main',
  3364. fn: arrow,
  3365. effect: effect$1,
  3366. requires: ['popperOffsets'],
  3367. requiresIfExists: ['preventOverflow']
  3368. };
  3369. var unsetSides = {
  3370. top: 'auto',
  3371. right: 'auto',
  3372. bottom: 'auto',
  3373. left: 'auto'
  3374. };
  3375. function roundOffsetsByDPR(_ref) {
  3376. var x = _ref.x,
  3377. y = _ref.y;
  3378. var win = window;
  3379. var dpr = win.devicePixelRatio || 1;
  3380. return {
  3381. x: round(round(x * dpr) / dpr) || 0,
  3382. y: round(round(y * dpr) / dpr) || 0
  3383. };
  3384. }
  3385. function mapToStyles(_ref2) {
  3386. var _Object$assign2;
  3387. var popper = _ref2.popper,
  3388. popperRect = _ref2.popperRect,
  3389. placement = _ref2.placement,
  3390. offsets = _ref2.offsets,
  3391. position = _ref2.position,
  3392. gpuAcceleration = _ref2.gpuAcceleration,
  3393. adaptive = _ref2.adaptive,
  3394. roundOffsets = _ref2.roundOffsets;
  3395. var _ref3 = roundOffsets === true ? roundOffsetsByDPR(offsets) : typeof roundOffsets === 'function' ? roundOffsets(offsets) : offsets,
  3396. _ref3$x = _ref3.x,
  3397. x = _ref3$x === void 0 ? 0 : _ref3$x,
  3398. _ref3$y = _ref3.y,
  3399. y = _ref3$y === void 0 ? 0 : _ref3$y;
  3400. var hasX = offsets.hasOwnProperty('x');
  3401. var hasY = offsets.hasOwnProperty('y');
  3402. var sideX = left;
  3403. var sideY = top;
  3404. var win = window;
  3405. if (adaptive) {
  3406. var offsetParent = getOffsetParent(popper);
  3407. var heightProp = 'clientHeight';
  3408. var widthProp = 'clientWidth';
  3409. if (offsetParent === getWindow(popper)) {
  3410. offsetParent = getDocumentElement(popper);
  3411. if (getComputedStyle$1(offsetParent).position !== 'static') {
  3412. heightProp = 'scrollHeight';
  3413. widthProp = 'scrollWidth';
  3414. }
  3415. }
  3416. offsetParent = offsetParent;
  3417. if (placement === top) {
  3418. sideY = bottom;
  3419. y -= offsetParent[heightProp] - popperRect.height;
  3420. y *= gpuAcceleration ? 1 : -1;
  3421. }
  3422. if (placement === left) {
  3423. sideX = right;
  3424. x -= offsetParent[widthProp] - popperRect.width;
  3425. x *= gpuAcceleration ? 1 : -1;
  3426. }
  3427. }
  3428. var commonStyles = Object.assign({
  3429. position: position
  3430. }, adaptive && unsetSides);
  3431. if (gpuAcceleration) {
  3432. var _Object$assign;
  3433. return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? '0' : '', _Object$assign[sideX] = hasX ? '0' : '', _Object$assign.transform = (win.devicePixelRatio || 1) < 2 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
  3434. }
  3435. return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
  3436. }
  3437. function computeStyles(_ref4) {
  3438. var state = _ref4.state,
  3439. options = _ref4.options;
  3440. var _options$gpuAccelerat = options.gpuAcceleration,
  3441. gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
  3442. _options$adaptive = options.adaptive,
  3443. adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
  3444. _options$roundOffsets = options.roundOffsets,
  3445. roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
  3446. var commonStyles = {
  3447. placement: getBasePlacement(state.placement),
  3448. popper: state.elements.popper,
  3449. popperRect: state.rects.popper,
  3450. gpuAcceleration: gpuAcceleration
  3451. };
  3452. if (state.modifiersData.popperOffsets != null) {
  3453. state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
  3454. offsets: state.modifiersData.popperOffsets,
  3455. position: state.options.strategy,
  3456. adaptive: adaptive,
  3457. roundOffsets: roundOffsets
  3458. })));
  3459. }
  3460. if (state.modifiersData.arrow != null) {
  3461. state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
  3462. offsets: state.modifiersData.arrow,
  3463. position: 'absolute',
  3464. adaptive: false,
  3465. roundOffsets: roundOffsets
  3466. })));
  3467. }
  3468. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  3469. 'data-popper-placement': state.placement
  3470. });
  3471. }
  3472. var computeStyles$1 = {
  3473. name: 'computeStyles',
  3474. enabled: true,
  3475. phase: 'beforeWrite',
  3476. fn: computeStyles,
  3477. data: {}
  3478. };
  3479. var passive = {
  3480. passive: true
  3481. };
  3482. function effect(_ref) {
  3483. var state = _ref.state,
  3484. instance = _ref.instance,
  3485. options = _ref.options;
  3486. var _options$scroll = options.scroll,
  3487. scroll = _options$scroll === void 0 ? true : _options$scroll,
  3488. _options$resize = options.resize,
  3489. resize = _options$resize === void 0 ? true : _options$resize;
  3490. var window = getWindow(state.elements.popper);
  3491. var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
  3492. if (scroll) {
  3493. scrollParents.forEach(function (scrollParent) {
  3494. scrollParent.addEventListener('scroll', instance.update, passive);
  3495. });
  3496. }
  3497. if (resize) {
  3498. window.addEventListener('resize', instance.update, passive);
  3499. }
  3500. return function () {
  3501. if (scroll) {
  3502. scrollParents.forEach(function (scrollParent) {
  3503. scrollParent.removeEventListener('scroll', instance.update, passive);
  3504. });
  3505. }
  3506. if (resize) {
  3507. window.removeEventListener('resize', instance.update, passive);
  3508. }
  3509. };
  3510. }
  3511. var eventListeners = {
  3512. name: 'eventListeners',
  3513. enabled: true,
  3514. phase: 'write',
  3515. fn: function fn() {},
  3516. effect: effect,
  3517. data: {}
  3518. };
  3519. var hash$1 = {
  3520. left: 'right',
  3521. right: 'left',
  3522. bottom: 'top',
  3523. top: 'bottom'
  3524. };
  3525. function getOppositePlacement(placement) {
  3526. return placement.replace(/left|right|bottom|top/g, function (matched) {
  3527. return hash$1[matched];
  3528. });
  3529. }
  3530. var hash = {
  3531. start: 'end',
  3532. end: 'start'
  3533. };
  3534. function getOppositeVariationPlacement(placement) {
  3535. return placement.replace(/start|end/g, function (matched) {
  3536. return hash[matched];
  3537. });
  3538. }
  3539. function getWindowScroll(node) {
  3540. var win = getWindow(node);
  3541. var scrollLeft = win.pageXOffset;
  3542. var scrollTop = win.pageYOffset;
  3543. return {
  3544. scrollLeft: scrollLeft,
  3545. scrollTop: scrollTop
  3546. };
  3547. }
  3548. function getWindowScrollBarX(element) {
  3549. return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
  3550. }
  3551. function getViewportRect(element) {
  3552. var win = getWindow(element);
  3553. var html = getDocumentElement(element);
  3554. var visualViewport = win.visualViewport;
  3555. var width = html.clientWidth;
  3556. var height = html.clientHeight;
  3557. var x = 0;
  3558. var y = 0;
  3559. if (visualViewport) {
  3560. width = visualViewport.width;
  3561. height = visualViewport.height;
  3562. if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
  3563. x = visualViewport.offsetLeft;
  3564. y = visualViewport.offsetTop;
  3565. }
  3566. }
  3567. return {
  3568. width: width,
  3569. height: height,
  3570. x: x + getWindowScrollBarX(element),
  3571. y: y
  3572. };
  3573. }
  3574. function getDocumentRect(element) {
  3575. var _element$ownerDocumen;
  3576. var html = getDocumentElement(element);
  3577. var winScroll = getWindowScroll(element);
  3578. var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  3579. var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  3580. var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  3581. var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
  3582. var y = -winScroll.scrollTop;
  3583. if (getComputedStyle$1(body || html).direction === 'rtl') {
  3584. x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
  3585. }
  3586. return {
  3587. width: width,
  3588. height: height,
  3589. x: x,
  3590. y: y
  3591. };
  3592. }
  3593. function isScrollParent(element) {
  3594. var _getComputedStyle = getComputedStyle$1(element),
  3595. overflow = _getComputedStyle.overflow,
  3596. overflowX = _getComputedStyle.overflowX,
  3597. overflowY = _getComputedStyle.overflowY;
  3598. return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
  3599. }
  3600. function getScrollParent(node) {
  3601. if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
  3602. return node.ownerDocument.body;
  3603. }
  3604. if (isHTMLElement(node) && isScrollParent(node)) {
  3605. return node;
  3606. }
  3607. return getScrollParent(getParentNode(node));
  3608. }
  3609. function listScrollParents(element, list) {
  3610. var _element$ownerDocumen;
  3611. if (list === void 0) {
  3612. list = [];
  3613. }
  3614. var scrollParent = getScrollParent(element);
  3615. var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
  3616. var win = getWindow(scrollParent);
  3617. var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
  3618. var updatedList = list.concat(target);
  3619. return isBody ? updatedList :
  3620. updatedList.concat(listScrollParents(getParentNode(target)));
  3621. }
  3622. function rectToClientRect(rect) {
  3623. return Object.assign({}, rect, {
  3624. left: rect.x,
  3625. top: rect.y,
  3626. right: rect.x + rect.width,
  3627. bottom: rect.y + rect.height
  3628. });
  3629. }
  3630. function getInnerBoundingClientRect(element) {
  3631. var rect = getBoundingClientRect(element);
  3632. rect.top = rect.top + element.clientTop;
  3633. rect.left = rect.left + element.clientLeft;
  3634. rect.bottom = rect.top + element.clientHeight;
  3635. rect.right = rect.left + element.clientWidth;
  3636. rect.width = element.clientWidth;
  3637. rect.height = element.clientHeight;
  3638. rect.x = rect.left;
  3639. rect.y = rect.top;
  3640. return rect;
  3641. }
  3642. function getClientRectFromMixedType(element, clippingParent) {
  3643. return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isHTMLElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
  3644. }
  3645. function getClippingParents(element) {
  3646. var clippingParents = listScrollParents(getParentNode(element));
  3647. var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle$1(element).position) >= 0;
  3648. var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
  3649. if (!isElement$1(clipperElement)) {
  3650. return [];
  3651. }
  3652. return clippingParents.filter(function (clippingParent) {
  3653. return isElement$1(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
  3654. });
  3655. }
  3656. function getClippingRect(element, boundary, rootBoundary) {
  3657. var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
  3658. var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
  3659. var firstClippingParent = clippingParents[0];
  3660. var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
  3661. var rect = getClientRectFromMixedType(element, clippingParent);
  3662. accRect.top = max(rect.top, accRect.top);
  3663. accRect.right = min(rect.right, accRect.right);
  3664. accRect.bottom = min(rect.bottom, accRect.bottom);
  3665. accRect.left = max(rect.left, accRect.left);
  3666. return accRect;
  3667. }, getClientRectFromMixedType(element, firstClippingParent));
  3668. clippingRect.width = clippingRect.right - clippingRect.left;
  3669. clippingRect.height = clippingRect.bottom - clippingRect.top;
  3670. clippingRect.x = clippingRect.left;
  3671. clippingRect.y = clippingRect.top;
  3672. return clippingRect;
  3673. }
  3674. function getVariation(placement) {
  3675. return placement.split('-')[1];
  3676. }
  3677. function computeOffsets(_ref) {
  3678. var reference = _ref.reference,
  3679. element = _ref.element,
  3680. placement = _ref.placement;
  3681. var basePlacement = placement ? getBasePlacement(placement) : null;
  3682. var variation = placement ? getVariation(placement) : null;
  3683. var commonX = reference.x + reference.width / 2 - element.width / 2;
  3684. var commonY = reference.y + reference.height / 2 - element.height / 2;
  3685. var offsets;
  3686. switch (basePlacement) {
  3687. case top:
  3688. offsets = {
  3689. x: commonX,
  3690. y: reference.y - element.height
  3691. };
  3692. break;
  3693. case bottom:
  3694. offsets = {
  3695. x: commonX,
  3696. y: reference.y + reference.height
  3697. };
  3698. break;
  3699. case right:
  3700. offsets = {
  3701. x: reference.x + reference.width,
  3702. y: commonY
  3703. };
  3704. break;
  3705. case left:
  3706. offsets = {
  3707. x: reference.x - element.width,
  3708. y: commonY
  3709. };
  3710. break;
  3711. default:
  3712. offsets = {
  3713. x: reference.x,
  3714. y: reference.y
  3715. };
  3716. }
  3717. var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
  3718. if (mainAxis != null) {
  3719. var len = mainAxis === 'y' ? 'height' : 'width';
  3720. switch (variation) {
  3721. case start:
  3722. offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
  3723. break;
  3724. case end:
  3725. offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
  3726. break;
  3727. }
  3728. }
  3729. return offsets;
  3730. }
  3731. function detectOverflow(state, options) {
  3732. if (options === void 0) {
  3733. options = {};
  3734. }
  3735. var _options = options,
  3736. _options$placement = _options.placement,
  3737. placement = _options$placement === void 0 ? state.placement : _options$placement,
  3738. _options$boundary = _options.boundary,
  3739. boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
  3740. _options$rootBoundary = _options.rootBoundary,
  3741. rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
  3742. _options$elementConte = _options.elementContext,
  3743. elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
  3744. _options$altBoundary = _options.altBoundary,
  3745. altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
  3746. _options$padding = _options.padding,
  3747. padding = _options$padding === void 0 ? 0 : _options$padding;
  3748. var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  3749. var altContext = elementContext === popper ? reference : popper;
  3750. var referenceElement = state.elements.reference;
  3751. var popperRect = state.rects.popper;
  3752. var element = state.elements[altBoundary ? altContext : elementContext];
  3753. var clippingClientRect = getClippingRect(isElement$1(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
  3754. var referenceClientRect = getBoundingClientRect(referenceElement);
  3755. var popperOffsets = computeOffsets({
  3756. reference: referenceClientRect,
  3757. element: popperRect,
  3758. strategy: 'absolute',
  3759. placement: placement
  3760. });
  3761. var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
  3762. var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect;
  3763. var overflowOffsets = {
  3764. top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
  3765. bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
  3766. left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
  3767. right: elementClientRect.right - clippingClientRect.right + paddingObject.right
  3768. };
  3769. var offsetData = state.modifiersData.offset;
  3770. if (elementContext === popper && offsetData) {
  3771. var offset = offsetData[placement];
  3772. Object.keys(overflowOffsets).forEach(function (key) {
  3773. var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
  3774. var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
  3775. overflowOffsets[key] += offset[axis] * multiply;
  3776. });
  3777. }
  3778. return overflowOffsets;
  3779. }
  3780. function computeAutoPlacement(state, options) {
  3781. if (options === void 0) {
  3782. options = {};
  3783. }
  3784. var _options = options,
  3785. placement = _options.placement,
  3786. boundary = _options.boundary,
  3787. rootBoundary = _options.rootBoundary,
  3788. padding = _options.padding,
  3789. flipVariations = _options.flipVariations,
  3790. _options$allowedAutoP = _options.allowedAutoPlacements,
  3791. allowedAutoPlacements = _options$allowedAutoP === void 0 ? placements : _options$allowedAutoP;
  3792. var variation = getVariation(placement);
  3793. var placements$1 = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) {
  3794. return getVariation(placement) === variation;
  3795. }) : basePlacements;
  3796. var allowedPlacements = placements$1.filter(function (placement) {
  3797. return allowedAutoPlacements.indexOf(placement) >= 0;
  3798. });
  3799. if (allowedPlacements.length === 0) {
  3800. allowedPlacements = placements$1;
  3801. }
  3802. var overflows = allowedPlacements.reduce(function (acc, placement) {
  3803. acc[placement] = detectOverflow(state, {
  3804. placement: placement,
  3805. boundary: boundary,
  3806. rootBoundary: rootBoundary,
  3807. padding: padding
  3808. })[getBasePlacement(placement)];
  3809. return acc;
  3810. }, {});
  3811. return Object.keys(overflows).sort(function (a, b) {
  3812. return overflows[a] - overflows[b];
  3813. });
  3814. }
  3815. function getExpandedFallbackPlacements(placement) {
  3816. if (getBasePlacement(placement) === auto) {
  3817. return [];
  3818. }
  3819. var oppositePlacement = getOppositePlacement(placement);
  3820. return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
  3821. }
  3822. function flip(_ref) {
  3823. var state = _ref.state,
  3824. options = _ref.options,
  3825. name = _ref.name;
  3826. if (state.modifiersData[name]._skip) {
  3827. return;
  3828. }
  3829. var _options$mainAxis = options.mainAxis,
  3830. checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
  3831. _options$altAxis = options.altAxis,
  3832. checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis,
  3833. specifiedFallbackPlacements = options.fallbackPlacements,
  3834. padding = options.padding,
  3835. boundary = options.boundary,
  3836. rootBoundary = options.rootBoundary,
  3837. altBoundary = options.altBoundary,
  3838. _options$flipVariatio = options.flipVariations,
  3839. flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio,
  3840. allowedAutoPlacements = options.allowedAutoPlacements;
  3841. var preferredPlacement = state.options.placement;
  3842. var basePlacement = getBasePlacement(preferredPlacement);
  3843. var isBasePlacement = basePlacement === preferredPlacement;
  3844. var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
  3845. var placements = [preferredPlacement].concat(fallbackPlacements).reduce(function (acc, placement) {
  3846. return acc.concat(getBasePlacement(placement) === auto ? computeAutoPlacement(state, {
  3847. placement: placement,
  3848. boundary: boundary,
  3849. rootBoundary: rootBoundary,
  3850. padding: padding,
  3851. flipVariations: flipVariations,
  3852. allowedAutoPlacements: allowedAutoPlacements
  3853. }) : placement);
  3854. }, []);
  3855. var referenceRect = state.rects.reference;
  3856. var popperRect = state.rects.popper;
  3857. var checksMap = new Map();
  3858. var makeFallbackChecks = true;
  3859. var firstFittingPlacement = placements[0];
  3860. for (var i = 0; i < placements.length; i++) {
  3861. var placement = placements[i];
  3862. var _basePlacement = getBasePlacement(placement);
  3863. var isStartVariation = getVariation(placement) === start;
  3864. var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
  3865. var len = isVertical ? 'width' : 'height';
  3866. var overflow = detectOverflow(state, {
  3867. placement: placement,
  3868. boundary: boundary,
  3869. rootBoundary: rootBoundary,
  3870. altBoundary: altBoundary,
  3871. padding: padding
  3872. });
  3873. var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
  3874. if (referenceRect[len] > popperRect[len]) {
  3875. mainVariationSide = getOppositePlacement(mainVariationSide);
  3876. }
  3877. var altVariationSide = getOppositePlacement(mainVariationSide);
  3878. var checks = [];
  3879. if (checkMainAxis) {
  3880. checks.push(overflow[_basePlacement] <= 0);
  3881. }
  3882. if (checkAltAxis) {
  3883. checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
  3884. }
  3885. if (checks.every(function (check) {
  3886. return check;
  3887. })) {
  3888. firstFittingPlacement = placement;
  3889. makeFallbackChecks = false;
  3890. break;
  3891. }
  3892. checksMap.set(placement, checks);
  3893. }
  3894. if (makeFallbackChecks) {
  3895. var numberOfChecks = flipVariations ? 3 : 1;
  3896. var _loop = function _loop(_i) {
  3897. var fittingPlacement = placements.find(function (placement) {
  3898. var checks = checksMap.get(placement);
  3899. if (checks) {
  3900. return checks.slice(0, _i).every(function (check) {
  3901. return check;
  3902. });
  3903. }
  3904. });
  3905. if (fittingPlacement) {
  3906. firstFittingPlacement = fittingPlacement;
  3907. return "break";
  3908. }
  3909. };
  3910. for (var _i = numberOfChecks; _i > 0; _i--) {
  3911. var _ret = _loop(_i);
  3912. if (_ret === "break") break;
  3913. }
  3914. }
  3915. if (state.placement !== firstFittingPlacement) {
  3916. state.modifiersData[name]._skip = true;
  3917. state.placement = firstFittingPlacement;
  3918. state.reset = true;
  3919. }
  3920. }
  3921. var flip$1 = {
  3922. name: 'flip',
  3923. enabled: true,
  3924. phase: 'main',
  3925. fn: flip,
  3926. requiresIfExists: ['offset'],
  3927. data: {
  3928. _skip: false
  3929. }
  3930. };
  3931. function getSideOffsets(overflow, rect, preventedOffsets) {
  3932. if (preventedOffsets === void 0) {
  3933. preventedOffsets = {
  3934. x: 0,
  3935. y: 0
  3936. };
  3937. }
  3938. return {
  3939. top: overflow.top - rect.height - preventedOffsets.y,
  3940. right: overflow.right - rect.width + preventedOffsets.x,
  3941. bottom: overflow.bottom - rect.height + preventedOffsets.y,
  3942. left: overflow.left - rect.width - preventedOffsets.x
  3943. };
  3944. }
  3945. function isAnySideFullyClipped(overflow) {
  3946. return [top, right, bottom, left].some(function (side) {
  3947. return overflow[side] >= 0;
  3948. });
  3949. }
  3950. function hide$1(_ref) {
  3951. var state = _ref.state,
  3952. name = _ref.name;
  3953. var referenceRect = state.rects.reference;
  3954. var popperRect = state.rects.popper;
  3955. var preventedOffsets = state.modifiersData.preventOverflow;
  3956. var referenceOverflow = detectOverflow(state, {
  3957. elementContext: 'reference'
  3958. });
  3959. var popperAltOverflow = detectOverflow(state, {
  3960. altBoundary: true
  3961. });
  3962. var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
  3963. var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
  3964. var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
  3965. var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
  3966. state.modifiersData[name] = {
  3967. referenceClippingOffsets: referenceClippingOffsets,
  3968. popperEscapeOffsets: popperEscapeOffsets,
  3969. isReferenceHidden: isReferenceHidden,
  3970. hasPopperEscaped: hasPopperEscaped
  3971. };
  3972. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  3973. 'data-popper-reference-hidden': isReferenceHidden,
  3974. 'data-popper-escaped': hasPopperEscaped
  3975. });
  3976. }
  3977. var hide$2 = {
  3978. name: 'hide',
  3979. enabled: true,
  3980. phase: 'main',
  3981. requiresIfExists: ['preventOverflow'],
  3982. fn: hide$1
  3983. };
  3984. function distanceAndSkiddingToXY(placement, rects, offset) {
  3985. var basePlacement = getBasePlacement(placement);
  3986. var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
  3987. var _ref = typeof offset === 'function' ? offset(Object.assign({}, rects, {
  3988. placement: placement
  3989. })) : offset,
  3990. skidding = _ref[0],
  3991. distance = _ref[1];
  3992. skidding = skidding || 0;
  3993. distance = (distance || 0) * invertDistance;
  3994. return [left, right].indexOf(basePlacement) >= 0 ? {
  3995. x: distance,
  3996. y: skidding
  3997. } : {
  3998. x: skidding,
  3999. y: distance
  4000. };
  4001. }
  4002. function offset(_ref2) {
  4003. var state = _ref2.state,
  4004. options = _ref2.options,
  4005. name = _ref2.name;
  4006. var _options$offset = options.offset,
  4007. offset = _options$offset === void 0 ? [0, 0] : _options$offset;
  4008. var data = placements.reduce(function (acc, placement) {
  4009. acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset);
  4010. return acc;
  4011. }, {});
  4012. var _data$state$placement = data[state.placement],
  4013. x = _data$state$placement.x,
  4014. y = _data$state$placement.y;
  4015. if (state.modifiersData.popperOffsets != null) {
  4016. state.modifiersData.popperOffsets.x += x;
  4017. state.modifiersData.popperOffsets.y += y;
  4018. }
  4019. state.modifiersData[name] = data;
  4020. }
  4021. var offset$1 = {
  4022. name: 'offset',
  4023. enabled: true,
  4024. phase: 'main',
  4025. requires: ['popperOffsets'],
  4026. fn: offset
  4027. };
  4028. function popperOffsets(_ref) {
  4029. var state = _ref.state,
  4030. name = _ref.name;
  4031. state.modifiersData[name] = computeOffsets({
  4032. reference: state.rects.reference,
  4033. element: state.rects.popper,
  4034. strategy: 'absolute',
  4035. placement: state.placement
  4036. });
  4037. }
  4038. var popperOffsets$1 = {
  4039. name: 'popperOffsets',
  4040. enabled: true,
  4041. phase: 'read',
  4042. fn: popperOffsets,
  4043. data: {}
  4044. };
  4045. function getAltAxis(axis) {
  4046. return axis === 'x' ? 'y' : 'x';
  4047. }
  4048. function preventOverflow(_ref) {
  4049. var state = _ref.state,
  4050. options = _ref.options,
  4051. name = _ref.name;
  4052. var _options$mainAxis = options.mainAxis,
  4053. checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
  4054. _options$altAxis = options.altAxis,
  4055. checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis,
  4056. boundary = options.boundary,
  4057. rootBoundary = options.rootBoundary,
  4058. altBoundary = options.altBoundary,
  4059. padding = options.padding,
  4060. _options$tether = options.tether,
  4061. tether = _options$tether === void 0 ? true : _options$tether,
  4062. _options$tetherOffset = options.tetherOffset,
  4063. tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
  4064. var overflow = detectOverflow(state, {
  4065. boundary: boundary,
  4066. rootBoundary: rootBoundary,
  4067. padding: padding,
  4068. altBoundary: altBoundary
  4069. });
  4070. var basePlacement = getBasePlacement(state.placement);
  4071. var variation = getVariation(state.placement);
  4072. var isBasePlacement = !variation;
  4073. var mainAxis = getMainAxisFromPlacement(basePlacement);
  4074. var altAxis = getAltAxis(mainAxis);
  4075. var popperOffsets = state.modifiersData.popperOffsets;
  4076. var referenceRect = state.rects.reference;
  4077. var popperRect = state.rects.popper;
  4078. var tetherOffsetValue = typeof tetherOffset === 'function' ? tetherOffset(Object.assign({}, state.rects, {
  4079. placement: state.placement
  4080. })) : tetherOffset;
  4081. var data = {
  4082. x: 0,
  4083. y: 0
  4084. };
  4085. if (!popperOffsets) {
  4086. return;
  4087. }
  4088. if (checkMainAxis || checkAltAxis) {
  4089. var mainSide = mainAxis === 'y' ? top : left;
  4090. var altSide = mainAxis === 'y' ? bottom : right;
  4091. var len = mainAxis === 'y' ? 'height' : 'width';
  4092. var offset = popperOffsets[mainAxis];
  4093. var min$1 = popperOffsets[mainAxis] + overflow[mainSide];
  4094. var max$1 = popperOffsets[mainAxis] - overflow[altSide];
  4095. var additive = tether ? -popperRect[len] / 2 : 0;
  4096. var minLen = variation === start ? referenceRect[len] : popperRect[len];
  4097. var maxLen = variation === start ? -popperRect[len] : -referenceRect[len];
  4098. var arrowElement = state.elements.arrow;
  4099. var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
  4100. width: 0,
  4101. height: 0
  4102. };
  4103. var arrowPaddingObject = state.modifiersData['arrow#persistent'] ? state.modifiersData['arrow#persistent'].padding : getFreshSideObject();
  4104. var arrowPaddingMin = arrowPaddingObject[mainSide];
  4105. var arrowPaddingMax = arrowPaddingObject[altSide];
  4106. var arrowLen = within(0, referenceRect[len], arrowRect[len]);
  4107. var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - tetherOffsetValue : minLen - arrowLen - arrowPaddingMin - tetherOffsetValue;
  4108. var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + tetherOffsetValue : maxLen + arrowLen + arrowPaddingMax + tetherOffsetValue;
  4109. var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
  4110. var clientOffset = arrowOffsetParent ? mainAxis === 'y' ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
  4111. var offsetModifierValue = state.modifiersData.offset ? state.modifiersData.offset[state.placement][mainAxis] : 0;
  4112. var tetherMin = popperOffsets[mainAxis] + minOffset - offsetModifierValue - clientOffset;
  4113. var tetherMax = popperOffsets[mainAxis] + maxOffset - offsetModifierValue;
  4114. if (checkMainAxis) {
  4115. var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
  4116. popperOffsets[mainAxis] = preventedOffset;
  4117. data[mainAxis] = preventedOffset - offset;
  4118. }
  4119. if (checkAltAxis) {
  4120. var _mainSide = mainAxis === 'x' ? top : left;
  4121. var _altSide = mainAxis === 'x' ? bottom : right;
  4122. var _offset = popperOffsets[altAxis];
  4123. var _min = _offset + overflow[_mainSide];
  4124. var _max = _offset - overflow[_altSide];
  4125. var _preventedOffset = within(tether ? min(_min, tetherMin) : _min, _offset, tether ? max(_max, tetherMax) : _max);
  4126. popperOffsets[altAxis] = _preventedOffset;
  4127. data[altAxis] = _preventedOffset - _offset;
  4128. }
  4129. }
  4130. state.modifiersData[name] = data;
  4131. }
  4132. var preventOverflow$1 = {
  4133. name: 'preventOverflow',
  4134. enabled: true,
  4135. phase: 'main',
  4136. fn: preventOverflow,
  4137. requiresIfExists: ['offset']
  4138. };
  4139. function getHTMLElementScroll(element) {
  4140. return {
  4141. scrollLeft: element.scrollLeft,
  4142. scrollTop: element.scrollTop
  4143. };
  4144. }
  4145. function getNodeScroll(node) {
  4146. if (node === getWindow(node) || !isHTMLElement(node)) {
  4147. return getWindowScroll(node);
  4148. } else {
  4149. return getHTMLElementScroll(node);
  4150. }
  4151. }
  4152. function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
  4153. if (isFixed === void 0) {
  4154. isFixed = false;
  4155. }
  4156. var documentElement = getDocumentElement(offsetParent);
  4157. var rect = getBoundingClientRect(elementOrVirtualElement);
  4158. var isOffsetParentAnElement = isHTMLElement(offsetParent);
  4159. var scroll = {
  4160. scrollLeft: 0,
  4161. scrollTop: 0
  4162. };
  4163. var offsets = {
  4164. x: 0,
  4165. y: 0
  4166. };
  4167. if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
  4168. if (getNodeName(offsetParent) !== 'body' ||
  4169. isScrollParent(documentElement)) {
  4170. scroll = getNodeScroll(offsetParent);
  4171. }
  4172. if (isHTMLElement(offsetParent)) {
  4173. offsets = getBoundingClientRect(offsetParent);
  4174. offsets.x += offsetParent.clientLeft;
  4175. offsets.y += offsetParent.clientTop;
  4176. } else if (documentElement) {
  4177. offsets.x = getWindowScrollBarX(documentElement);
  4178. }
  4179. }
  4180. return {
  4181. x: rect.left + scroll.scrollLeft - offsets.x,
  4182. y: rect.top + scroll.scrollTop - offsets.y,
  4183. width: rect.width,
  4184. height: rect.height
  4185. };
  4186. }
  4187. function order(modifiers) {
  4188. var map = new Map();
  4189. var visited = new Set();
  4190. var result = [];
  4191. modifiers.forEach(function (modifier) {
  4192. map.set(modifier.name, modifier);
  4193. });
  4194. function sort(modifier) {
  4195. visited.add(modifier.name);
  4196. var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
  4197. requires.forEach(function (dep) {
  4198. if (!visited.has(dep)) {
  4199. var depModifier = map.get(dep);
  4200. if (depModifier) {
  4201. sort(depModifier);
  4202. }
  4203. }
  4204. });
  4205. result.push(modifier);
  4206. }
  4207. modifiers.forEach(function (modifier) {
  4208. if (!visited.has(modifier.name)) {
  4209. sort(modifier);
  4210. }
  4211. });
  4212. return result;
  4213. }
  4214. function orderModifiers(modifiers) {
  4215. var orderedModifiers = order(modifiers);
  4216. return modifierPhases.reduce(function (acc, phase) {
  4217. return acc.concat(orderedModifiers.filter(function (modifier) {
  4218. return modifier.phase === phase;
  4219. }));
  4220. }, []);
  4221. }
  4222. function debounce(fn) {
  4223. var pending;
  4224. return function () {
  4225. if (!pending) {
  4226. pending = new Promise(function (resolve) {
  4227. Promise.resolve().then(function () {
  4228. pending = undefined;
  4229. resolve(fn());
  4230. });
  4231. });
  4232. }
  4233. return pending;
  4234. };
  4235. }
  4236. function mergeByName(modifiers) {
  4237. var merged = modifiers.reduce(function (merged, current) {
  4238. var existing = merged[current.name];
  4239. merged[current.name] = existing ? Object.assign({}, existing, current, {
  4240. options: Object.assign({}, existing.options, current.options),
  4241. data: Object.assign({}, existing.data, current.data)
  4242. }) : current;
  4243. return merged;
  4244. }, {});
  4245. return Object.keys(merged).map(function (key) {
  4246. return merged[key];
  4247. });
  4248. }
  4249. var DEFAULT_OPTIONS = {
  4250. placement: 'bottom',
  4251. modifiers: [],
  4252. strategy: 'absolute'
  4253. };
  4254. function areValidElements() {
  4255. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4256. args[_key] = arguments[_key];
  4257. }
  4258. return !args.some(function (element) {
  4259. return !(element && typeof element.getBoundingClientRect === 'function');
  4260. });
  4261. }
  4262. function popperGenerator(generatorOptions) {
  4263. if (generatorOptions === void 0) {
  4264. generatorOptions = {};
  4265. }
  4266. var _generatorOptions = generatorOptions,
  4267. _generatorOptions$def = _generatorOptions.defaultModifiers,
  4268. defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
  4269. _generatorOptions$def2 = _generatorOptions.defaultOptions,
  4270. defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
  4271. return function createPopper(reference, popper, options) {
  4272. if (options === void 0) {
  4273. options = defaultOptions;
  4274. }
  4275. var state = {
  4276. placement: 'bottom',
  4277. orderedModifiers: [],
  4278. options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
  4279. modifiersData: {},
  4280. elements: {
  4281. reference: reference,
  4282. popper: popper
  4283. },
  4284. attributes: {},
  4285. styles: {}
  4286. };
  4287. var effectCleanupFns = [];
  4288. var isDestroyed = false;
  4289. var instance = {
  4290. state: state,
  4291. setOptions: function setOptions(options) {
  4292. cleanupModifierEffects();
  4293. state.options = Object.assign({}, defaultOptions, state.options, options);
  4294. state.scrollParents = {
  4295. reference: isElement$1(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
  4296. popper: listScrollParents(popper)
  4297. };
  4298. var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers)));
  4299. state.orderedModifiers = orderedModifiers.filter(function (m) {
  4300. return m.enabled;
  4301. });
  4302. runModifierEffects();
  4303. return instance.update();
  4304. },
  4305. forceUpdate: function forceUpdate() {
  4306. if (isDestroyed) {
  4307. return;
  4308. }
  4309. var _state$elements = state.elements,
  4310. reference = _state$elements.reference,
  4311. popper = _state$elements.popper;
  4312. if (!areValidElements(reference, popper)) {
  4313. return;
  4314. }
  4315. state.rects = {
  4316. reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
  4317. popper: getLayoutRect(popper)
  4318. };
  4319. state.reset = false;
  4320. state.placement = state.options.placement;
  4321. state.orderedModifiers.forEach(function (modifier) {
  4322. return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
  4323. });
  4324. for (var index = 0; index < state.orderedModifiers.length; index++) {
  4325. if (state.reset === true) {
  4326. state.reset = false;
  4327. index = -1;
  4328. continue;
  4329. }
  4330. var _state$orderedModifie = state.orderedModifiers[index],
  4331. fn = _state$orderedModifie.fn,
  4332. _state$orderedModifie2 = _state$orderedModifie.options,
  4333. _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
  4334. name = _state$orderedModifie.name;
  4335. if (typeof fn === 'function') {
  4336. state = fn({
  4337. state: state,
  4338. options: _options,
  4339. name: name,
  4340. instance: instance
  4341. }) || state;
  4342. }
  4343. }
  4344. },
  4345. update: debounce(function () {
  4346. return new Promise(function (resolve) {
  4347. instance.forceUpdate();
  4348. resolve(state);
  4349. });
  4350. }),
  4351. destroy: function destroy() {
  4352. cleanupModifierEffects();
  4353. isDestroyed = true;
  4354. }
  4355. };
  4356. if (!areValidElements(reference, popper)) {
  4357. return instance;
  4358. }
  4359. instance.setOptions(options).then(function (state) {
  4360. if (!isDestroyed && options.onFirstUpdate) {
  4361. options.onFirstUpdate(state);
  4362. }
  4363. });
  4364. function runModifierEffects() {
  4365. state.orderedModifiers.forEach(function (_ref3) {
  4366. var name = _ref3.name,
  4367. _ref3$options = _ref3.options,
  4368. options = _ref3$options === void 0 ? {} : _ref3$options,
  4369. effect = _ref3.effect;
  4370. if (typeof effect === 'function') {
  4371. var cleanupFn = effect({
  4372. state: state,
  4373. name: name,
  4374. instance: instance,
  4375. options: options
  4376. });
  4377. var noopFn = function noopFn() {};
  4378. effectCleanupFns.push(cleanupFn || noopFn);
  4379. }
  4380. });
  4381. }
  4382. function cleanupModifierEffects() {
  4383. effectCleanupFns.forEach(function (fn) {
  4384. return fn();
  4385. });
  4386. effectCleanupFns = [];
  4387. }
  4388. return instance;
  4389. };
  4390. }
  4391. var createPopper$2 = popperGenerator();
  4392. var defaultModifiers$1 = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1];
  4393. var createPopper$1 = popperGenerator({
  4394. defaultModifiers: defaultModifiers$1
  4395. });
  4396. var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$2];
  4397. var createPopper = popperGenerator({
  4398. defaultModifiers: defaultModifiers
  4399. });
  4400. var Popper = /*#__PURE__*/Object.freeze({
  4401. __proto__: null,
  4402. popperGenerator: popperGenerator,
  4403. detectOverflow: detectOverflow,
  4404. createPopperBase: createPopper$2,
  4405. createPopper: createPopper,
  4406. createPopperLite: createPopper$1,
  4407. top: top,
  4408. bottom: bottom,
  4409. right: right,
  4410. left: left,
  4411. auto: auto,
  4412. basePlacements: basePlacements,
  4413. start: start,
  4414. end: end,
  4415. clippingParents: clippingParents,
  4416. viewport: viewport,
  4417. popper: popper,
  4418. reference: reference,
  4419. variationPlacements: variationPlacements,
  4420. placements: placements,
  4421. beforeRead: beforeRead,
  4422. read: read,
  4423. afterRead: afterRead,
  4424. beforeMain: beforeMain,
  4425. main: main,
  4426. afterMain: afterMain,
  4427. beforeWrite: beforeWrite,
  4428. write: write,
  4429. afterWrite: afterWrite,
  4430. modifierPhases: modifierPhases,
  4431. applyStyles: applyStyles$1,
  4432. arrow: arrow$1,
  4433. computeStyles: computeStyles$1,
  4434. eventListeners: eventListeners,
  4435. flip: flip$1,
  4436. hide: hide$2,
  4437. offset: offset$1,
  4438. popperOffsets: popperOffsets$1,
  4439. preventOverflow: preventOverflow$1
  4440. });
  4441. /*!
  4442. * Bootstrap v5.0.0-beta3 (https://getbootstrap.com/)
  4443. * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4444. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  4445. */
  4446. const MAX_UID = 1000000;
  4447. const MILLISECONDS_MULTIPLIER = 1000;
  4448. const TRANSITION_END = 'transitionend';
  4449. const toType = obj => {
  4450. if (obj === null || obj === undefined) {
  4451. return `${obj}`;
  4452. }
  4453. return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  4454. };
  4455. const getUID = prefix => {
  4456. do {
  4457. prefix += Math.floor(Math.random() * MAX_UID);
  4458. } while (document.getElementById(prefix));
  4459. return prefix;
  4460. };
  4461. const getSelector = element => {
  4462. let selector = element.getAttribute('data-bs-target');
  4463. if (!selector || selector === '#') {
  4464. let hrefAttr = element.getAttribute('href');
  4465. if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
  4466. return null;
  4467. }
  4468. if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
  4469. hrefAttr = '#' + hrefAttr.split('#')[1];
  4470. }
  4471. selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
  4472. }
  4473. return selector;
  4474. };
  4475. const getSelectorFromElement = element => {
  4476. const selector = getSelector(element);
  4477. if (selector) {
  4478. return document.querySelector(selector) ? selector : null;
  4479. }
  4480. return null;
  4481. };
  4482. const getElementFromSelector = element => {
  4483. const selector = getSelector(element);
  4484. return selector ? document.querySelector(selector) : null;
  4485. };
  4486. const getTransitionDurationFromElement = element => {
  4487. if (!element) {
  4488. return 0;
  4489. }
  4490. let {
  4491. transitionDuration,
  4492. transitionDelay
  4493. } = window.getComputedStyle(element);
  4494. const floatTransitionDuration = Number.parseFloat(transitionDuration);
  4495. const floatTransitionDelay = Number.parseFloat(transitionDelay);
  4496. if (!floatTransitionDuration && !floatTransitionDelay) {
  4497. return 0;
  4498. }
  4499. transitionDuration = transitionDuration.split(',')[0];
  4500. transitionDelay = transitionDelay.split(',')[0];
  4501. return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  4502. };
  4503. const triggerTransitionEnd = element => {
  4504. element.dispatchEvent(new Event(TRANSITION_END));
  4505. };
  4506. const isElement = obj => (obj[0] || obj).nodeType;
  4507. const emulateTransitionEnd = (element, duration) => {
  4508. let called = false;
  4509. const durationPadding = 5;
  4510. const emulatedDuration = duration + durationPadding;
  4511. function listener() {
  4512. called = true;
  4513. element.removeEventListener(TRANSITION_END, listener);
  4514. }
  4515. element.addEventListener(TRANSITION_END, listener);
  4516. setTimeout(() => {
  4517. if (!called) {
  4518. triggerTransitionEnd(element);
  4519. }
  4520. }, emulatedDuration);
  4521. };
  4522. const typeCheckConfig = (componentName, config, configTypes) => {
  4523. Object.keys(configTypes).forEach(property => {
  4524. const expectedTypes = configTypes[property];
  4525. const value = config[property];
  4526. const valueType = value && isElement(value) ? 'element' : toType(value);
  4527. if (!new RegExp(expectedTypes).test(valueType)) {
  4528. throw new TypeError(`${componentName.toUpperCase()}: ` + `Option "${property}" provided type "${valueType}" ` + `but expected type "${expectedTypes}".`);
  4529. }
  4530. });
  4531. };
  4532. const isVisible = element => {
  4533. if (!element) {
  4534. return false;
  4535. }
  4536. if (element.style && element.parentNode && element.parentNode.style) {
  4537. const elementStyle = getComputedStyle(element);
  4538. const parentNodeStyle = getComputedStyle(element.parentNode);
  4539. return elementStyle.display !== 'none' && parentNodeStyle.display !== 'none' && elementStyle.visibility !== 'hidden';
  4540. }
  4541. return false;
  4542. };
  4543. const isDisabled = element => {
  4544. if (!element || element.nodeType !== Node.ELEMENT_NODE) {
  4545. return true;
  4546. }
  4547. if (element.classList.contains('disabled')) {
  4548. return true;
  4549. }
  4550. if (typeof element.disabled !== 'undefined') {
  4551. return element.disabled;
  4552. }
  4553. return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
  4554. };
  4555. const findShadowRoot = element => {
  4556. if (!document.documentElement.attachShadow) {
  4557. return null;
  4558. }
  4559. if (typeof element.getRootNode === 'function') {
  4560. const root = element.getRootNode();
  4561. return root instanceof ShadowRoot ? root : null;
  4562. }
  4563. if (element instanceof ShadowRoot) {
  4564. return element;
  4565. }
  4566. if (!element.parentNode) {
  4567. return null;
  4568. }
  4569. return findShadowRoot(element.parentNode);
  4570. };
  4571. const noop = () => function () {};
  4572. const reflow = element => element.offsetHeight;
  4573. const getjQuery = () => {
  4574. const {
  4575. jQuery
  4576. } = window;
  4577. if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
  4578. return jQuery;
  4579. }
  4580. return null;
  4581. };
  4582. const onDOMContentLoaded = callback => {
  4583. if (document.readyState === 'loading') {
  4584. document.addEventListener('DOMContentLoaded', callback);
  4585. } else {
  4586. callback();
  4587. }
  4588. };
  4589. const isRTL = () => document.documentElement.dir === 'rtl';
  4590. const defineJQueryPlugin = (name, plugin) => {
  4591. onDOMContentLoaded(() => {
  4592. const $ = getjQuery();
  4593. if ($) {
  4594. const JQUERY_NO_CONFLICT = $.fn[name];
  4595. $.fn[name] = plugin.jQueryInterface;
  4596. $.fn[name].Constructor = plugin;
  4597. $.fn[name].noConflict = () => {
  4598. $.fn[name] = JQUERY_NO_CONFLICT;
  4599. return plugin.jQueryInterface;
  4600. };
  4601. }
  4602. });
  4603. };
  4604. const elementMap = new Map();
  4605. var Data = {
  4606. set(element, key, instance) {
  4607. if (!elementMap.has(element)) {
  4608. elementMap.set(element, new Map());
  4609. }
  4610. const instanceMap = elementMap.get(element);
  4611. if (!instanceMap.has(key) && instanceMap.size !== 0) {
  4612. console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`);
  4613. return;
  4614. }
  4615. instanceMap.set(key, instance);
  4616. },
  4617. get(element, key) {
  4618. if (elementMap.has(element)) {
  4619. return elementMap.get(element).get(key) || null;
  4620. }
  4621. return null;
  4622. },
  4623. remove(element, key) {
  4624. if (!elementMap.has(element)) {
  4625. return;
  4626. }
  4627. const instanceMap = elementMap.get(element);
  4628. instanceMap.delete(key);
  4629. if (instanceMap.size === 0) {
  4630. elementMap.delete(element);
  4631. }
  4632. }
  4633. };
  4634. const namespaceRegex = /[^.]*(?=\..*)\.|.*/;
  4635. const stripNameRegex = /\..*/;
  4636. const stripUidRegex = /::\d+$/;
  4637. const eventRegistry = {};
  4638. let uidEvent = 1;
  4639. const customEvents = {
  4640. mouseenter: 'mouseover',
  4641. mouseleave: 'mouseout'
  4642. };
  4643. const nativeEvents = new Set(['click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu', 'mousewheel', 'DOMMouseScroll', 'mouseover', 'mouseout', 'mousemove', 'selectstart', 'selectend', 'keydown', 'keypress', 'keyup', 'orientationchange', 'touchstart', 'touchmove', 'touchend', 'touchcancel', 'pointerdown', 'pointermove', 'pointerup', 'pointerleave', 'pointercancel', 'gesturestart', 'gesturechange', 'gestureend', 'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout', 'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange', 'error', 'abort', 'scroll']);
  4644. function getUidEvent(element, uid) {
  4645. return uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++;
  4646. }
  4647. function getEvent(element) {
  4648. const uid = getUidEvent(element);
  4649. element.uidEvent = uid;
  4650. eventRegistry[uid] = eventRegistry[uid] || {};
  4651. return eventRegistry[uid];
  4652. }
  4653. function bootstrapHandler(element, fn) {
  4654. return function handler(event) {
  4655. event.delegateTarget = element;
  4656. if (handler.oneOff) {
  4657. EventHandler.off(element, event.type, fn);
  4658. }
  4659. return fn.apply(element, [event]);
  4660. };
  4661. }
  4662. function bootstrapDelegationHandler(element, selector, fn) {
  4663. return function handler(event) {
  4664. const domElements = element.querySelectorAll(selector);
  4665. for (let {
  4666. target
  4667. } = event; target && target !== this; target = target.parentNode) {
  4668. for (let i = domElements.length; i--;) {
  4669. if (domElements[i] === target) {
  4670. event.delegateTarget = target;
  4671. if (handler.oneOff) {
  4672. EventHandler.off(element, event.type, fn);
  4673. }
  4674. return fn.apply(target, [event]);
  4675. }
  4676. }
  4677. }
  4678. return null;
  4679. };
  4680. }
  4681. function findHandler(events, handler, delegationSelector = null) {
  4682. const uidEventList = Object.keys(events);
  4683. for (let i = 0, len = uidEventList.length; i < len; i++) {
  4684. const event = events[uidEventList[i]];
  4685. if (event.originalHandler === handler && event.delegationSelector === delegationSelector) {
  4686. return event;
  4687. }
  4688. }
  4689. return null;
  4690. }
  4691. function normalizeParams(originalTypeEvent, handler, delegationFn) {
  4692. const delegation = typeof handler === 'string';
  4693. const originalHandler = delegation ? delegationFn : handler;
  4694. let typeEvent = originalTypeEvent.replace(stripNameRegex, '');
  4695. const custom = customEvents[typeEvent];
  4696. if (custom) {
  4697. typeEvent = custom;
  4698. }
  4699. const isNative = nativeEvents.has(typeEvent);
  4700. if (!isNative) {
  4701. typeEvent = originalTypeEvent;
  4702. }
  4703. return [delegation, originalHandler, typeEvent];
  4704. }
  4705. function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
  4706. if (typeof originalTypeEvent !== 'string' || !element) {
  4707. return;
  4708. }
  4709. if (!handler) {
  4710. handler = delegationFn;
  4711. delegationFn = null;
  4712. }
  4713. const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn);
  4714. const events = getEvent(element);
  4715. const handlers = events[typeEvent] || (events[typeEvent] = {});
  4716. const previousFn = findHandler(handlers, originalHandler, delegation ? handler : null);
  4717. if (previousFn) {
  4718. previousFn.oneOff = previousFn.oneOff && oneOff;
  4719. return;
  4720. }
  4721. const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, ''));
  4722. const fn = delegation ? bootstrapDelegationHandler(element, handler, delegationFn) : bootstrapHandler(element, handler);
  4723. fn.delegationSelector = delegation ? handler : null;
  4724. fn.originalHandler = originalHandler;
  4725. fn.oneOff = oneOff;
  4726. fn.uidEvent = uid;
  4727. handlers[uid] = fn;
  4728. element.addEventListener(typeEvent, fn, delegation);
  4729. }
  4730. function removeHandler(element, events, typeEvent, handler, delegationSelector) {
  4731. const fn = findHandler(events[typeEvent], handler, delegationSelector);
  4732. if (!fn) {
  4733. return;
  4734. }
  4735. element.removeEventListener(typeEvent, fn, Boolean(delegationSelector));
  4736. delete events[typeEvent][fn.uidEvent];
  4737. }
  4738. function removeNamespacedHandlers(element, events, typeEvent, namespace) {
  4739. const storeElementEvent = events[typeEvent] || {};
  4740. Object.keys(storeElementEvent).forEach(handlerKey => {
  4741. if (handlerKey.includes(namespace)) {
  4742. const event = storeElementEvent[handlerKey];
  4743. removeHandler(element, events, typeEvent, event.originalHandler, event.delegationSelector);
  4744. }
  4745. });
  4746. }
  4747. const EventHandler = {
  4748. on(element, event, handler, delegationFn) {
  4749. addHandler(element, event, handler, delegationFn, false);
  4750. },
  4751. one(element, event, handler, delegationFn) {
  4752. addHandler(element, event, handler, delegationFn, true);
  4753. },
  4754. off(element, originalTypeEvent, handler, delegationFn) {
  4755. if (typeof originalTypeEvent !== 'string' || !element) {
  4756. return;
  4757. }
  4758. const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn);
  4759. const inNamespace = typeEvent !== originalTypeEvent;
  4760. const events = getEvent(element);
  4761. const isNamespace = originalTypeEvent.startsWith('.');
  4762. if (typeof originalHandler !== 'undefined') {
  4763. if (!events || !events[typeEvent]) {
  4764. return;
  4765. }
  4766. removeHandler(element, events, typeEvent, originalHandler, delegation ? handler : null);
  4767. return;
  4768. }
  4769. if (isNamespace) {
  4770. Object.keys(events).forEach(elementEvent => {
  4771. removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.slice(1));
  4772. });
  4773. }
  4774. const storeElementEvent = events[typeEvent] || {};
  4775. Object.keys(storeElementEvent).forEach(keyHandlers => {
  4776. const handlerKey = keyHandlers.replace(stripUidRegex, '');
  4777. if (!inNamespace || originalTypeEvent.includes(handlerKey)) {
  4778. const event = storeElementEvent[keyHandlers];
  4779. removeHandler(element, events, typeEvent, event.originalHandler, event.delegationSelector);
  4780. }
  4781. });
  4782. },
  4783. trigger(element, event, args) {
  4784. if (typeof event !== 'string' || !element) {
  4785. return null;
  4786. }
  4787. const $ = getjQuery();
  4788. const typeEvent = event.replace(stripNameRegex, '');
  4789. const inNamespace = event !== typeEvent;
  4790. const isNative = nativeEvents.has(typeEvent);
  4791. let jQueryEvent;
  4792. let bubbles = true;
  4793. let nativeDispatch = true;
  4794. let defaultPrevented = false;
  4795. let evt = null;
  4796. if (inNamespace && $) {
  4797. jQueryEvent = $.Event(event, args);
  4798. $(element).trigger(jQueryEvent);
  4799. bubbles = !jQueryEvent.isPropagationStopped();
  4800. nativeDispatch = !jQueryEvent.isImmediatePropagationStopped();
  4801. defaultPrevented = jQueryEvent.isDefaultPrevented();
  4802. }
  4803. if (isNative) {
  4804. evt = document.createEvent('HTMLEvents');
  4805. evt.initEvent(typeEvent, bubbles, true);
  4806. } else {
  4807. evt = new CustomEvent(event, {
  4808. bubbles,
  4809. cancelable: true
  4810. });
  4811. }
  4812. if (typeof args !== 'undefined') {
  4813. Object.keys(args).forEach(key => {
  4814. Object.defineProperty(evt, key, {
  4815. get() {
  4816. return args[key];
  4817. }
  4818. });
  4819. });
  4820. }
  4821. if (defaultPrevented) {
  4822. evt.preventDefault();
  4823. }
  4824. if (nativeDispatch) {
  4825. element.dispatchEvent(evt);
  4826. }
  4827. if (evt.defaultPrevented && typeof jQueryEvent !== 'undefined') {
  4828. jQueryEvent.preventDefault();
  4829. }
  4830. return evt;
  4831. }
  4832. };
  4833. const VERSION = '5.0.0-beta3';
  4834. class BaseComponent {
  4835. constructor(element) {
  4836. element = typeof element === 'string' ? document.querySelector(element) : element;
  4837. if (!element) {
  4838. return;
  4839. }
  4840. this._element = element;
  4841. Data.set(this._element, this.constructor.DATA_KEY, this);
  4842. }
  4843. dispose() {
  4844. Data.remove(this._element, this.constructor.DATA_KEY);
  4845. this._element = null;
  4846. }
  4847. static getInstance(element) {
  4848. return Data.get(element, this.DATA_KEY);
  4849. }
  4850. static get VERSION() {
  4851. return VERSION;
  4852. }
  4853. }
  4854. const NAME$b = 'alert';
  4855. const DATA_KEY$b = 'bs.alert';
  4856. const EVENT_KEY$b = `.${DATA_KEY$b}`;
  4857. const DATA_API_KEY$8 = '.data-api';
  4858. const SELECTOR_DISMISS = '[data-bs-dismiss="alert"]';
  4859. const EVENT_CLOSE = `close${EVENT_KEY$b}`;
  4860. const EVENT_CLOSED = `closed${EVENT_KEY$b}`;
  4861. const EVENT_CLICK_DATA_API$7 = `click${EVENT_KEY$b}${DATA_API_KEY$8}`;
  4862. const CLASS_NAME_ALERT = 'alert';
  4863. const CLASS_NAME_FADE$5 = 'fade';
  4864. const CLASS_NAME_SHOW$8 = 'show';
  4865. class Alert extends BaseComponent {
  4866. static get DATA_KEY() {
  4867. return DATA_KEY$b;
  4868. }
  4869. close(element) {
  4870. const rootElement = element ? this._getRootElement(element) : this._element;
  4871. const customEvent = this._triggerCloseEvent(rootElement);
  4872. if (customEvent === null || customEvent.defaultPrevented) {
  4873. return;
  4874. }
  4875. this._removeElement(rootElement);
  4876. }
  4877. _getRootElement(element) {
  4878. return getElementFromSelector(element) || element.closest(`.${CLASS_NAME_ALERT}`);
  4879. }
  4880. _triggerCloseEvent(element) {
  4881. return EventHandler.trigger(element, EVENT_CLOSE);
  4882. }
  4883. _removeElement(element) {
  4884. element.classList.remove(CLASS_NAME_SHOW$8);
  4885. if (!element.classList.contains(CLASS_NAME_FADE$5)) {
  4886. this._destroyElement(element);
  4887. return;
  4888. }
  4889. const transitionDuration = getTransitionDurationFromElement(element);
  4890. EventHandler.one(element, 'transitionend', () => this._destroyElement(element));
  4891. emulateTransitionEnd(element, transitionDuration);
  4892. }
  4893. _destroyElement(element) {
  4894. if (element.parentNode) {
  4895. element.parentNode.removeChild(element);
  4896. }
  4897. EventHandler.trigger(element, EVENT_CLOSED);
  4898. }
  4899. static jQueryInterface(config) {
  4900. return this.each(function () {
  4901. let data = Data.get(this, DATA_KEY$b);
  4902. if (!data) {
  4903. data = new Alert(this);
  4904. }
  4905. if (config === 'close') {
  4906. data[config](this);
  4907. }
  4908. });
  4909. }
  4910. static handleDismiss(alertInstance) {
  4911. return function (event) {
  4912. if (event) {
  4913. event.preventDefault();
  4914. }
  4915. alertInstance.close(this);
  4916. };
  4917. }
  4918. }
  4919. EventHandler.on(document, EVENT_CLICK_DATA_API$7, SELECTOR_DISMISS, Alert.handleDismiss(new Alert()));
  4920. defineJQueryPlugin(NAME$b, Alert);
  4921. const NAME$a = 'button';
  4922. const DATA_KEY$a = 'bs.button';
  4923. const EVENT_KEY$a = `.${DATA_KEY$a}`;
  4924. const DATA_API_KEY$7 = '.data-api';
  4925. const CLASS_NAME_ACTIVE$3 = 'active';
  4926. const SELECTOR_DATA_TOGGLE$5 = '[data-bs-toggle="button"]';
  4927. const EVENT_CLICK_DATA_API$6 = `click${EVENT_KEY$a}${DATA_API_KEY$7}`;
  4928. class Button extends BaseComponent {
  4929. static get DATA_KEY() {
  4930. return DATA_KEY$a;
  4931. }
  4932. toggle() {
  4933. this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE$3));
  4934. }
  4935. static jQueryInterface(config) {
  4936. return this.each(function () {
  4937. let data = Data.get(this, DATA_KEY$a);
  4938. if (!data) {
  4939. data = new Button(this);
  4940. }
  4941. if (config === 'toggle') {
  4942. data[config]();
  4943. }
  4944. });
  4945. }
  4946. }
  4947. EventHandler.on(document, EVENT_CLICK_DATA_API$6, SELECTOR_DATA_TOGGLE$5, event => {
  4948. event.preventDefault();
  4949. const button = event.target.closest(SELECTOR_DATA_TOGGLE$5);
  4950. let data = Data.get(button, DATA_KEY$a);
  4951. if (!data) {
  4952. data = new Button(button);
  4953. }
  4954. data.toggle();
  4955. });
  4956. defineJQueryPlugin(NAME$a, Button);
  4957. function normalizeData(val) {
  4958. if (val === 'true') {
  4959. return true;
  4960. }
  4961. if (val === 'false') {
  4962. return false;
  4963. }
  4964. if (val === Number(val).toString()) {
  4965. return Number(val);
  4966. }
  4967. if (val === '' || val === 'null') {
  4968. return null;
  4969. }
  4970. return val;
  4971. }
  4972. function normalizeDataKey(key) {
  4973. return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`);
  4974. }
  4975. const Manipulator = {
  4976. setDataAttribute(element, key, value) {
  4977. element.setAttribute(`data-bs-${normalizeDataKey(key)}`, value);
  4978. },
  4979. removeDataAttribute(element, key) {
  4980. element.removeAttribute(`data-bs-${normalizeDataKey(key)}`);
  4981. },
  4982. getDataAttributes(element) {
  4983. if (!element) {
  4984. return {};
  4985. }
  4986. const attributes = {};
  4987. Object.keys(element.dataset).filter(key => key.startsWith('bs')).forEach(key => {
  4988. let pureKey = key.replace(/^bs/, '');
  4989. pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length);
  4990. attributes[pureKey] = normalizeData(element.dataset[key]);
  4991. });
  4992. return attributes;
  4993. },
  4994. getDataAttribute(element, key) {
  4995. return normalizeData(element.getAttribute(`data-bs-${normalizeDataKey(key)}`));
  4996. },
  4997. offset(element) {
  4998. const rect = element.getBoundingClientRect();
  4999. return {
  5000. top: rect.top + document.body.scrollTop,
  5001. left: rect.left + document.body.scrollLeft
  5002. };
  5003. },
  5004. position(element) {
  5005. return {
  5006. top: element.offsetTop,
  5007. left: element.offsetLeft
  5008. };
  5009. }
  5010. };
  5011. const NODE_TEXT = 3;
  5012. const SelectorEngine = {
  5013. find(selector, element = document.documentElement) {
  5014. return [].concat(...Element.prototype.querySelectorAll.call(element, selector));
  5015. },
  5016. findOne(selector, element = document.documentElement) {
  5017. return Element.prototype.querySelector.call(element, selector);
  5018. },
  5019. children(element, selector) {
  5020. return [].concat(...element.children).filter(child => child.matches(selector));
  5021. },
  5022. parents(element, selector) {
  5023. const parents = [];
  5024. let ancestor = element.parentNode;
  5025. while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
  5026. if (ancestor.matches(selector)) {
  5027. parents.push(ancestor);
  5028. }
  5029. ancestor = ancestor.parentNode;
  5030. }
  5031. return parents;
  5032. },
  5033. prev(element, selector) {
  5034. let previous = element.previousElementSibling;
  5035. while (previous) {
  5036. if (previous.matches(selector)) {
  5037. return [previous];
  5038. }
  5039. previous = previous.previousElementSibling;
  5040. }
  5041. return [];
  5042. },
  5043. next(element, selector) {
  5044. let next = element.nextElementSibling;
  5045. while (next) {
  5046. if (next.matches(selector)) {
  5047. return [next];
  5048. }
  5049. next = next.nextElementSibling;
  5050. }
  5051. return [];
  5052. }
  5053. };
  5054. const NAME$9 = 'carousel';
  5055. const DATA_KEY$9 = 'bs.carousel';
  5056. const EVENT_KEY$9 = `.${DATA_KEY$9}`;
  5057. const DATA_API_KEY$6 = '.data-api';
  5058. const ARROW_LEFT_KEY = 'ArrowLeft';
  5059. const ARROW_RIGHT_KEY = 'ArrowRight';
  5060. const TOUCHEVENT_COMPAT_WAIT = 500;
  5061. const SWIPE_THRESHOLD = 40;
  5062. const Default$8 = {
  5063. interval: 5000,
  5064. keyboard: true,
  5065. slide: false,
  5066. pause: 'hover',
  5067. wrap: true,
  5068. touch: true
  5069. };
  5070. const DefaultType$8 = {
  5071. interval: '(number|boolean)',
  5072. keyboard: 'boolean',
  5073. slide: '(boolean|string)',
  5074. pause: '(string|boolean)',
  5075. wrap: 'boolean',
  5076. touch: 'boolean'
  5077. };
  5078. const ORDER_NEXT = 'next';
  5079. const ORDER_PREV = 'prev';
  5080. const DIRECTION_LEFT = 'left';
  5081. const DIRECTION_RIGHT = 'right';
  5082. const EVENT_SLIDE = `slide${EVENT_KEY$9}`;
  5083. const EVENT_SLID = `slid${EVENT_KEY$9}`;
  5084. const EVENT_KEYDOWN = `keydown${EVENT_KEY$9}`;
  5085. const EVENT_MOUSEENTER = `mouseenter${EVENT_KEY$9}`;
  5086. const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY$9}`;
  5087. const EVENT_TOUCHSTART = `touchstart${EVENT_KEY$9}`;
  5088. const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY$9}`;
  5089. const EVENT_TOUCHEND = `touchend${EVENT_KEY$9}`;
  5090. const EVENT_POINTERDOWN = `pointerdown${EVENT_KEY$9}`;
  5091. const EVENT_POINTERUP = `pointerup${EVENT_KEY$9}`;
  5092. const EVENT_DRAG_START = `dragstart${EVENT_KEY$9}`;
  5093. const EVENT_LOAD_DATA_API$2 = `load${EVENT_KEY$9}${DATA_API_KEY$6}`;
  5094. const EVENT_CLICK_DATA_API$5 = `click${EVENT_KEY$9}${DATA_API_KEY$6}`;
  5095. const CLASS_NAME_CAROUSEL = 'carousel';
  5096. const CLASS_NAME_ACTIVE$2 = 'active';
  5097. const CLASS_NAME_SLIDE = 'slide';
  5098. const CLASS_NAME_END = 'carousel-item-end';
  5099. const CLASS_NAME_START = 'carousel-item-start';
  5100. const CLASS_NAME_NEXT = 'carousel-item-next';
  5101. const CLASS_NAME_PREV = 'carousel-item-prev';
  5102. const CLASS_NAME_POINTER_EVENT = 'pointer-event';
  5103. const SELECTOR_ACTIVE$1 = '.active';
  5104. const SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
  5105. const SELECTOR_ITEM = '.carousel-item';
  5106. const SELECTOR_ITEM_IMG = '.carousel-item img';
  5107. const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
  5108. const SELECTOR_INDICATORS = '.carousel-indicators';
  5109. const SELECTOR_INDICATOR = '[data-bs-target]';
  5110. const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]';
  5111. const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]';
  5112. const POINTER_TYPE_TOUCH = 'touch';
  5113. const POINTER_TYPE_PEN = 'pen';
  5114. class Carousel extends BaseComponent {
  5115. constructor(element, config) {
  5116. super(element);
  5117. this._items = null;
  5118. this._interval = null;
  5119. this._activeElement = null;
  5120. this._isPaused = false;
  5121. this._isSliding = false;
  5122. this.touchTimeout = null;
  5123. this.touchStartX = 0;
  5124. this.touchDeltaX = 0;
  5125. this._config = this._getConfig(config);
  5126. this._indicatorsElement = SelectorEngine.findOne(SELECTOR_INDICATORS, this._element);
  5127. this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
  5128. this._pointerEvent = Boolean(window.PointerEvent);
  5129. this._addEventListeners();
  5130. }
  5131. static get Default() {
  5132. return Default$8;
  5133. }
  5134. static get DATA_KEY() {
  5135. return DATA_KEY$9;
  5136. }
  5137. next() {
  5138. if (!this._isSliding) {
  5139. this._slide(ORDER_NEXT);
  5140. }
  5141. }
  5142. nextWhenVisible() {
  5143. if (!document.hidden && isVisible(this._element)) {
  5144. this.next();
  5145. }
  5146. }
  5147. prev() {
  5148. if (!this._isSliding) {
  5149. this._slide(ORDER_PREV);
  5150. }
  5151. }
  5152. pause(event) {
  5153. if (!event) {
  5154. this._isPaused = true;
  5155. }
  5156. if (SelectorEngine.findOne(SELECTOR_NEXT_PREV, this._element)) {
  5157. triggerTransitionEnd(this._element);
  5158. this.cycle(true);
  5159. }
  5160. clearInterval(this._interval);
  5161. this._interval = null;
  5162. }
  5163. cycle(event) {
  5164. if (!event) {
  5165. this._isPaused = false;
  5166. }
  5167. if (this._interval) {
  5168. clearInterval(this._interval);
  5169. this._interval = null;
  5170. }
  5171. if (this._config && this._config.interval && !this._isPaused) {
  5172. this._updateInterval();
  5173. this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
  5174. }
  5175. }
  5176. to(index) {
  5177. this._activeElement = SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element);
  5178. const activeIndex = this._getItemIndex(this._activeElement);
  5179. if (index > this._items.length - 1 || index < 0) {
  5180. return;
  5181. }
  5182. if (this._isSliding) {
  5183. EventHandler.one(this._element, EVENT_SLID, () => this.to(index));
  5184. return;
  5185. }
  5186. if (activeIndex === index) {
  5187. this.pause();
  5188. this.cycle();
  5189. return;
  5190. }
  5191. const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV;
  5192. this._slide(order, this._items[index]);
  5193. }
  5194. dispose() {
  5195. EventHandler.off(this._element, EVENT_KEY$9);
  5196. this._items = null;
  5197. this._config = null;
  5198. this._interval = null;
  5199. this._isPaused = null;
  5200. this._isSliding = null;
  5201. this._activeElement = null;
  5202. this._indicatorsElement = null;
  5203. super.dispose();
  5204. }
  5205. _getConfig(config) {
  5206. config = { ...Default$8,
  5207. ...config
  5208. };
  5209. typeCheckConfig(NAME$9, config, DefaultType$8);
  5210. return config;
  5211. }
  5212. _handleSwipe() {
  5213. const absDeltax = Math.abs(this.touchDeltaX);
  5214. if (absDeltax <= SWIPE_THRESHOLD) {
  5215. return;
  5216. }
  5217. const direction = absDeltax / this.touchDeltaX;
  5218. this.touchDeltaX = 0;
  5219. if (!direction) {
  5220. return;
  5221. }
  5222. this._slide(direction > 0 ? DIRECTION_RIGHT : DIRECTION_LEFT);
  5223. }
  5224. _addEventListeners() {
  5225. if (this._config.keyboard) {
  5226. EventHandler.on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
  5227. }
  5228. if (this._config.pause === 'hover') {
  5229. EventHandler.on(this._element, EVENT_MOUSEENTER, event => this.pause(event));
  5230. EventHandler.on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event));
  5231. }
  5232. if (this._config.touch && this._touchSupported) {
  5233. this._addTouchEventListeners();
  5234. }
  5235. }
  5236. _addTouchEventListeners() {
  5237. const start = event => {
  5238. if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
  5239. this.touchStartX = event.clientX;
  5240. } else if (!this._pointerEvent) {
  5241. this.touchStartX = event.touches[0].clientX;
  5242. }
  5243. };
  5244. const move = event => {
  5245. this.touchDeltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this.touchStartX;
  5246. };
  5247. const end = event => {
  5248. if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
  5249. this.touchDeltaX = event.clientX - this.touchStartX;
  5250. }
  5251. this._handleSwipe();
  5252. if (this._config.pause === 'hover') {
  5253. this.pause();
  5254. if (this.touchTimeout) {
  5255. clearTimeout(this.touchTimeout);
  5256. }
  5257. this.touchTimeout = setTimeout(event => this.cycle(event), TOUCHEVENT_COMPAT_WAIT + this._config.interval);
  5258. }
  5259. };
  5260. SelectorEngine.find(SELECTOR_ITEM_IMG, this._element).forEach(itemImg => {
  5261. EventHandler.on(itemImg, EVENT_DRAG_START, e => e.preventDefault());
  5262. });
  5263. if (this._pointerEvent) {
  5264. EventHandler.on(this._element, EVENT_POINTERDOWN, event => start(event));
  5265. EventHandler.on(this._element, EVENT_POINTERUP, event => end(event));
  5266. this._element.classList.add(CLASS_NAME_POINTER_EVENT);
  5267. } else {
  5268. EventHandler.on(this._element, EVENT_TOUCHSTART, event => start(event));
  5269. EventHandler.on(this._element, EVENT_TOUCHMOVE, event => move(event));
  5270. EventHandler.on(this._element, EVENT_TOUCHEND, event => end(event));
  5271. }
  5272. }
  5273. _keydown(event) {
  5274. if (/input|textarea/i.test(event.target.tagName)) {
  5275. return;
  5276. }
  5277. if (event.key === ARROW_LEFT_KEY) {
  5278. event.preventDefault();
  5279. this._slide(DIRECTION_LEFT);
  5280. } else if (event.key === ARROW_RIGHT_KEY) {
  5281. event.preventDefault();
  5282. this._slide(DIRECTION_RIGHT);
  5283. }
  5284. }
  5285. _getItemIndex(element) {
  5286. this._items = element && element.parentNode ? SelectorEngine.find(SELECTOR_ITEM, element.parentNode) : [];
  5287. return this._items.indexOf(element);
  5288. }
  5289. _getItemByOrder(order, activeElement) {
  5290. const isNext = order === ORDER_NEXT;
  5291. const isPrev = order === ORDER_PREV;
  5292. const activeIndex = this._getItemIndex(activeElement);
  5293. const lastItemIndex = this._items.length - 1;
  5294. const isGoingToWrap = isPrev && activeIndex === 0 || isNext && activeIndex === lastItemIndex;
  5295. if (isGoingToWrap && !this._config.wrap) {
  5296. return activeElement;
  5297. }
  5298. const delta = isPrev ? -1 : 1;
  5299. const itemIndex = (activeIndex + delta) % this._items.length;
  5300. return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
  5301. }
  5302. _triggerSlideEvent(relatedTarget, eventDirectionName) {
  5303. const targetIndex = this._getItemIndex(relatedTarget);
  5304. const fromIndex = this._getItemIndex(SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element));
  5305. return EventHandler.trigger(this._element, EVENT_SLIDE, {
  5306. relatedTarget,
  5307. direction: eventDirectionName,
  5308. from: fromIndex,
  5309. to: targetIndex
  5310. });
  5311. }
  5312. _setActiveIndicatorElement(element) {
  5313. if (this._indicatorsElement) {
  5314. const activeIndicator = SelectorEngine.findOne(SELECTOR_ACTIVE$1, this._indicatorsElement);
  5315. activeIndicator.classList.remove(CLASS_NAME_ACTIVE$2);
  5316. activeIndicator.removeAttribute('aria-current');
  5317. const indicators = SelectorEngine.find(SELECTOR_INDICATOR, this._indicatorsElement);
  5318. for (let i = 0; i < indicators.length; i++) {
  5319. if (Number.parseInt(indicators[i].getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) {
  5320. indicators[i].classList.add(CLASS_NAME_ACTIVE$2);
  5321. indicators[i].setAttribute('aria-current', 'true');
  5322. break;
  5323. }
  5324. }
  5325. }
  5326. }
  5327. _updateInterval() {
  5328. const element = this._activeElement || SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element);
  5329. if (!element) {
  5330. return;
  5331. }
  5332. const elementInterval = Number.parseInt(element.getAttribute('data-bs-interval'), 10);
  5333. if (elementInterval) {
  5334. this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
  5335. this._config.interval = elementInterval;
  5336. } else {
  5337. this._config.interval = this._config.defaultInterval || this._config.interval;
  5338. }
  5339. }
  5340. _slide(directionOrOrder, element) {
  5341. const order = this._directionToOrder(directionOrOrder);
  5342. const activeElement = SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element);
  5343. const activeElementIndex = this._getItemIndex(activeElement);
  5344. const nextElement = element || this._getItemByOrder(order, activeElement);
  5345. const nextElementIndex = this._getItemIndex(nextElement);
  5346. const isCycling = Boolean(this._interval);
  5347. const isNext = order === ORDER_NEXT;
  5348. const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END;
  5349. const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV;
  5350. const eventDirectionName = this._orderToDirection(order);
  5351. if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE$2)) {
  5352. this._isSliding = false;
  5353. return;
  5354. }
  5355. const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
  5356. if (slideEvent.defaultPrevented) {
  5357. return;
  5358. }
  5359. if (!activeElement || !nextElement) {
  5360. return;
  5361. }
  5362. this._isSliding = true;
  5363. if (isCycling) {
  5364. this.pause();
  5365. }
  5366. this._setActiveIndicatorElement(nextElement);
  5367. this._activeElement = nextElement;
  5368. if (this._element.classList.contains(CLASS_NAME_SLIDE)) {
  5369. nextElement.classList.add(orderClassName);
  5370. reflow(nextElement);
  5371. activeElement.classList.add(directionalClassName);
  5372. nextElement.classList.add(directionalClassName);
  5373. const transitionDuration = getTransitionDurationFromElement(activeElement);
  5374. EventHandler.one(activeElement, 'transitionend', () => {
  5375. nextElement.classList.remove(directionalClassName, orderClassName);
  5376. nextElement.classList.add(CLASS_NAME_ACTIVE$2);
  5377. activeElement.classList.remove(CLASS_NAME_ACTIVE$2, orderClassName, directionalClassName);
  5378. this._isSliding = false;
  5379. setTimeout(() => {
  5380. EventHandler.trigger(this._element, EVENT_SLID, {
  5381. relatedTarget: nextElement,
  5382. direction: eventDirectionName,
  5383. from: activeElementIndex,
  5384. to: nextElementIndex
  5385. });
  5386. }, 0);
  5387. });
  5388. emulateTransitionEnd(activeElement, transitionDuration);
  5389. } else {
  5390. activeElement.classList.remove(CLASS_NAME_ACTIVE$2);
  5391. nextElement.classList.add(CLASS_NAME_ACTIVE$2);
  5392. this._isSliding = false;
  5393. EventHandler.trigger(this._element, EVENT_SLID, {
  5394. relatedTarget: nextElement,
  5395. direction: eventDirectionName,
  5396. from: activeElementIndex,
  5397. to: nextElementIndex
  5398. });
  5399. }
  5400. if (isCycling) {
  5401. this.cycle();
  5402. }
  5403. }
  5404. _directionToOrder(direction) {
  5405. if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
  5406. return direction;
  5407. }
  5408. if (isRTL()) {
  5409. return direction === DIRECTION_RIGHT ? ORDER_PREV : ORDER_NEXT;
  5410. }
  5411. return direction === DIRECTION_RIGHT ? ORDER_NEXT : ORDER_PREV;
  5412. }
  5413. _orderToDirection(order) {
  5414. if (![ORDER_NEXT, ORDER_PREV].includes(order)) {
  5415. return order;
  5416. }
  5417. if (isRTL()) {
  5418. return order === ORDER_NEXT ? DIRECTION_LEFT : DIRECTION_RIGHT;
  5419. }
  5420. return order === ORDER_NEXT ? DIRECTION_RIGHT : DIRECTION_LEFT;
  5421. }
  5422. static carouselInterface(element, config) {
  5423. let data = Data.get(element, DATA_KEY$9);
  5424. let _config = { ...Default$8,
  5425. ...Manipulator.getDataAttributes(element)
  5426. };
  5427. if (typeof config === 'object') {
  5428. _config = { ..._config,
  5429. ...config
  5430. };
  5431. }
  5432. const action = typeof config === 'string' ? config : _config.slide;
  5433. if (!data) {
  5434. data = new Carousel(element, _config);
  5435. }
  5436. if (typeof config === 'number') {
  5437. data.to(config);
  5438. } else if (typeof action === 'string') {
  5439. if (typeof data[action] === 'undefined') {
  5440. throw new TypeError(`No method named "${action}"`);
  5441. }
  5442. data[action]();
  5443. } else if (_config.interval && _config.ride) {
  5444. data.pause();
  5445. data.cycle();
  5446. }
  5447. }
  5448. static jQueryInterface(config) {
  5449. return this.each(function () {
  5450. Carousel.carouselInterface(this, config);
  5451. });
  5452. }
  5453. static dataApiClickHandler(event) {
  5454. const target = getElementFromSelector(this);
  5455. if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
  5456. return;
  5457. }
  5458. const config = { ...Manipulator.getDataAttributes(target),
  5459. ...Manipulator.getDataAttributes(this)
  5460. };
  5461. const slideIndex = this.getAttribute('data-bs-slide-to');
  5462. if (slideIndex) {
  5463. config.interval = false;
  5464. }
  5465. Carousel.carouselInterface(target, config);
  5466. if (slideIndex) {
  5467. Data.get(target, DATA_KEY$9).to(slideIndex);
  5468. }
  5469. event.preventDefault();
  5470. }
  5471. }
  5472. EventHandler.on(document, EVENT_CLICK_DATA_API$5, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler);
  5473. EventHandler.on(window, EVENT_LOAD_DATA_API$2, () => {
  5474. const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE);
  5475. for (let i = 0, len = carousels.length; i < len; i++) {
  5476. Carousel.carouselInterface(carousels[i], Data.get(carousels[i], DATA_KEY$9));
  5477. }
  5478. });
  5479. defineJQueryPlugin(NAME$9, Carousel);
  5480. const NAME$8 = 'collapse';
  5481. const DATA_KEY$8 = 'bs.collapse';
  5482. const EVENT_KEY$8 = `.${DATA_KEY$8}`;
  5483. const DATA_API_KEY$5 = '.data-api';
  5484. const Default$7 = {
  5485. toggle: true,
  5486. parent: ''
  5487. };
  5488. const DefaultType$7 = {
  5489. toggle: 'boolean',
  5490. parent: '(string|element)'
  5491. };
  5492. const EVENT_SHOW$5 = `show${EVENT_KEY$8}`;
  5493. const EVENT_SHOWN$5 = `shown${EVENT_KEY$8}`;
  5494. const EVENT_HIDE$5 = `hide${EVENT_KEY$8}`;
  5495. const EVENT_HIDDEN$5 = `hidden${EVENT_KEY$8}`;
  5496. const EVENT_CLICK_DATA_API$4 = `click${EVENT_KEY$8}${DATA_API_KEY$5}`;
  5497. const CLASS_NAME_SHOW$7 = 'show';
  5498. const CLASS_NAME_COLLAPSE = 'collapse';
  5499. const CLASS_NAME_COLLAPSING = 'collapsing';
  5500. const CLASS_NAME_COLLAPSED = 'collapsed';
  5501. const WIDTH = 'width';
  5502. const HEIGHT = 'height';
  5503. const SELECTOR_ACTIVES = '.show, .collapsing';
  5504. const SELECTOR_DATA_TOGGLE$4 = '[data-bs-toggle="collapse"]';
  5505. class Collapse extends BaseComponent {
  5506. constructor(element, config) {
  5507. super(element);
  5508. this._isTransitioning = false;
  5509. this._config = this._getConfig(config);
  5510. this._triggerArray = SelectorEngine.find(`${SELECTOR_DATA_TOGGLE$4}[href="#${this._element.id}"],` + `${SELECTOR_DATA_TOGGLE$4}[data-bs-target="#${this._element.id}"]`);
  5511. const toggleList = SelectorEngine.find(SELECTOR_DATA_TOGGLE$4);
  5512. for (let i = 0, len = toggleList.length; i < len; i++) {
  5513. const elem = toggleList[i];
  5514. const selector = getSelectorFromElement(elem);
  5515. const filterElement = SelectorEngine.find(selector).filter(foundElem => foundElem === this._element);
  5516. if (selector !== null && filterElement.length) {
  5517. this._selector = selector;
  5518. this._triggerArray.push(elem);
  5519. }
  5520. }
  5521. this._parent = this._config.parent ? this._getParent() : null;
  5522. if (!this._config.parent) {
  5523. this._addAriaAndCollapsedClass(this._element, this._triggerArray);
  5524. }
  5525. if (this._config.toggle) {
  5526. this.toggle();
  5527. }
  5528. }
  5529. static get Default() {
  5530. return Default$7;
  5531. }
  5532. static get DATA_KEY() {
  5533. return DATA_KEY$8;
  5534. }
  5535. toggle() {
  5536. if (this._element.classList.contains(CLASS_NAME_SHOW$7)) {
  5537. this.hide();
  5538. } else {
  5539. this.show();
  5540. }
  5541. }
  5542. show() {
  5543. if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW$7)) {
  5544. return;
  5545. }
  5546. let actives;
  5547. let activesData;
  5548. if (this._parent) {
  5549. actives = SelectorEngine.find(SELECTOR_ACTIVES, this._parent).filter(elem => {
  5550. if (typeof this._config.parent === 'string') {
  5551. return elem.getAttribute('data-bs-parent') === this._config.parent;
  5552. }
  5553. return elem.classList.contains(CLASS_NAME_COLLAPSE);
  5554. });
  5555. if (actives.length === 0) {
  5556. actives = null;
  5557. }
  5558. }
  5559. const container = SelectorEngine.findOne(this._selector);
  5560. if (actives) {
  5561. const tempActiveData = actives.find(elem => container !== elem);
  5562. activesData = tempActiveData ? Data.get(tempActiveData, DATA_KEY$8) : null;
  5563. if (activesData && activesData._isTransitioning) {
  5564. return;
  5565. }
  5566. }
  5567. const startEvent = EventHandler.trigger(this._element, EVENT_SHOW$5);
  5568. if (startEvent.defaultPrevented) {
  5569. return;
  5570. }
  5571. if (actives) {
  5572. actives.forEach(elemActive => {
  5573. if (container !== elemActive) {
  5574. Collapse.collapseInterface(elemActive, 'hide');
  5575. }
  5576. if (!activesData) {
  5577. Data.set(elemActive, DATA_KEY$8, null);
  5578. }
  5579. });
  5580. }
  5581. const dimension = this._getDimension();
  5582. this._element.classList.remove(CLASS_NAME_COLLAPSE);
  5583. this._element.classList.add(CLASS_NAME_COLLAPSING);
  5584. this._element.style[dimension] = 0;
  5585. if (this._triggerArray.length) {
  5586. this._triggerArray.forEach(element => {
  5587. element.classList.remove(CLASS_NAME_COLLAPSED);
  5588. element.setAttribute('aria-expanded', true);
  5589. });
  5590. }
  5591. this.setTransitioning(true);
  5592. const complete = () => {
  5593. this._element.classList.remove(CLASS_NAME_COLLAPSING);
  5594. this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW$7);
  5595. this._element.style[dimension] = '';
  5596. this.setTransitioning(false);
  5597. EventHandler.trigger(this._element, EVENT_SHOWN$5);
  5598. };
  5599. const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
  5600. const scrollSize = `scroll${capitalizedDimension}`;
  5601. const transitionDuration = getTransitionDurationFromElement(this._element);
  5602. EventHandler.one(this._element, 'transitionend', complete);
  5603. emulateTransitionEnd(this._element, transitionDuration);
  5604. this._element.style[dimension] = `${this._element[scrollSize]}px`;
  5605. }
  5606. hide() {
  5607. if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW$7)) {
  5608. return;
  5609. }
  5610. const startEvent = EventHandler.trigger(this._element, EVENT_HIDE$5);
  5611. if (startEvent.defaultPrevented) {
  5612. return;
  5613. }
  5614. const dimension = this._getDimension();
  5615. this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`;
  5616. reflow(this._element);
  5617. this._element.classList.add(CLASS_NAME_COLLAPSING);
  5618. this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW$7);
  5619. const triggerArrayLength = this._triggerArray.length;
  5620. if (triggerArrayLength > 0) {
  5621. for (let i = 0; i < triggerArrayLength; i++) {
  5622. const trigger = this._triggerArray[i];
  5623. const elem = getElementFromSelector(trigger);
  5624. if (elem && !elem.classList.contains(CLASS_NAME_SHOW$7)) {
  5625. trigger.classList.add(CLASS_NAME_COLLAPSED);
  5626. trigger.setAttribute('aria-expanded', false);
  5627. }
  5628. }
  5629. }
  5630. this.setTransitioning(true);
  5631. const complete = () => {
  5632. this.setTransitioning(false);
  5633. this._element.classList.remove(CLASS_NAME_COLLAPSING);
  5634. this._element.classList.add(CLASS_NAME_COLLAPSE);
  5635. EventHandler.trigger(this._element, EVENT_HIDDEN$5);
  5636. };
  5637. this._element.style[dimension] = '';
  5638. const transitionDuration = getTransitionDurationFromElement(this._element);
  5639. EventHandler.one(this._element, 'transitionend', complete);
  5640. emulateTransitionEnd(this._element, transitionDuration);
  5641. }
  5642. setTransitioning(isTransitioning) {
  5643. this._isTransitioning = isTransitioning;
  5644. }
  5645. dispose() {
  5646. super.dispose();
  5647. this._config = null;
  5648. this._parent = null;
  5649. this._triggerArray = null;
  5650. this._isTransitioning = null;
  5651. }
  5652. _getConfig(config) {
  5653. config = { ...Default$7,
  5654. ...config
  5655. };
  5656. config.toggle = Boolean(config.toggle);
  5657. typeCheckConfig(NAME$8, config, DefaultType$7);
  5658. return config;
  5659. }
  5660. _getDimension() {
  5661. return this._element.classList.contains(WIDTH) ? WIDTH : HEIGHT;
  5662. }
  5663. _getParent() {
  5664. let {
  5665. parent
  5666. } = this._config;
  5667. if (isElement(parent)) {
  5668. if (typeof parent.jquery !== 'undefined' || typeof parent[0] !== 'undefined') {
  5669. parent = parent[0];
  5670. }
  5671. } else {
  5672. parent = SelectorEngine.findOne(parent);
  5673. }
  5674. const selector = `${SELECTOR_DATA_TOGGLE$4}[data-bs-parent="${parent}"]`;
  5675. SelectorEngine.find(selector, parent).forEach(element => {
  5676. const selected = getElementFromSelector(element);
  5677. this._addAriaAndCollapsedClass(selected, [element]);
  5678. });
  5679. return parent;
  5680. }
  5681. _addAriaAndCollapsedClass(element, triggerArray) {
  5682. if (!element || !triggerArray.length) {
  5683. return;
  5684. }
  5685. const isOpen = element.classList.contains(CLASS_NAME_SHOW$7);
  5686. triggerArray.forEach(elem => {
  5687. if (isOpen) {
  5688. elem.classList.remove(CLASS_NAME_COLLAPSED);
  5689. } else {
  5690. elem.classList.add(CLASS_NAME_COLLAPSED);
  5691. }
  5692. elem.setAttribute('aria-expanded', isOpen);
  5693. });
  5694. }
  5695. static collapseInterface(element, config) {
  5696. let data = Data.get(element, DATA_KEY$8);
  5697. const _config = { ...Default$7,
  5698. ...Manipulator.getDataAttributes(element),
  5699. ...(typeof config === 'object' && config ? config : {})
  5700. };
  5701. if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {
  5702. _config.toggle = false;
  5703. }
  5704. if (!data) {
  5705. data = new Collapse(element, _config);
  5706. }
  5707. if (typeof config === 'string') {
  5708. if (typeof data[config] === 'undefined') {
  5709. throw new TypeError(`No method named "${config}"`);
  5710. }
  5711. data[config]();
  5712. }
  5713. }
  5714. static jQueryInterface(config) {
  5715. return this.each(function () {
  5716. Collapse.collapseInterface(this, config);
  5717. });
  5718. }
  5719. }
  5720. EventHandler.on(document, EVENT_CLICK_DATA_API$4, SELECTOR_DATA_TOGGLE$4, function (event) {
  5721. if (event.target.tagName === 'A' || event.delegateTarget && event.delegateTarget.tagName === 'A') {
  5722. event.preventDefault();
  5723. }
  5724. const triggerData = Manipulator.getDataAttributes(this);
  5725. const selector = getSelectorFromElement(this);
  5726. const selectorElements = SelectorEngine.find(selector);
  5727. selectorElements.forEach(element => {
  5728. const data = Data.get(element, DATA_KEY$8);
  5729. let config;
  5730. if (data) {
  5731. if (data._parent === null && typeof triggerData.parent === 'string') {
  5732. data._config.parent = triggerData.parent;
  5733. data._parent = data._getParent();
  5734. }
  5735. config = 'toggle';
  5736. } else {
  5737. config = triggerData;
  5738. }
  5739. Collapse.collapseInterface(element, config);
  5740. });
  5741. });
  5742. defineJQueryPlugin(NAME$8, Collapse);
  5743. const NAME$7 = 'dropdown';
  5744. const DATA_KEY$7 = 'bs.dropdown';
  5745. const EVENT_KEY$7 = `.${DATA_KEY$7}`;
  5746. const DATA_API_KEY$4 = '.data-api';
  5747. const ESCAPE_KEY$2 = 'Escape';
  5748. const SPACE_KEY = 'Space';
  5749. const TAB_KEY = 'Tab';
  5750. const ARROW_UP_KEY = 'ArrowUp';
  5751. const ARROW_DOWN_KEY = 'ArrowDown';
  5752. const RIGHT_MOUSE_BUTTON = 2;
  5753. const REGEXP_KEYDOWN = new RegExp(`${ARROW_UP_KEY}|${ARROW_DOWN_KEY}|${ESCAPE_KEY$2}`);
  5754. const EVENT_HIDE$4 = `hide${EVENT_KEY$7}`;
  5755. const EVENT_HIDDEN$4 = `hidden${EVENT_KEY$7}`;
  5756. const EVENT_SHOW$4 = `show${EVENT_KEY$7}`;
  5757. const EVENT_SHOWN$4 = `shown${EVENT_KEY$7}`;
  5758. const EVENT_CLICK = `click${EVENT_KEY$7}`;
  5759. const EVENT_CLICK_DATA_API$3 = `click${EVENT_KEY$7}${DATA_API_KEY$4}`;
  5760. const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY$7}${DATA_API_KEY$4}`;
  5761. const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY$7}${DATA_API_KEY$4}`;
  5762. const CLASS_NAME_DISABLED = 'disabled';
  5763. const CLASS_NAME_SHOW$6 = 'show';
  5764. const CLASS_NAME_DROPUP = 'dropup';
  5765. const CLASS_NAME_DROPEND = 'dropend';
  5766. const CLASS_NAME_DROPSTART = 'dropstart';
  5767. const CLASS_NAME_NAVBAR = 'navbar';
  5768. const SELECTOR_DATA_TOGGLE$3 = '[data-bs-toggle="dropdown"]';
  5769. const SELECTOR_MENU = '.dropdown-menu';
  5770. const SELECTOR_NAVBAR_NAV = '.navbar-nav';
  5771. const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)';
  5772. const PLACEMENT_TOP = isRTL() ? 'top-end' : 'top-start';
  5773. const PLACEMENT_TOPEND = isRTL() ? 'top-start' : 'top-end';
  5774. const PLACEMENT_BOTTOM = isRTL() ? 'bottom-end' : 'bottom-start';
  5775. const PLACEMENT_BOTTOMEND = isRTL() ? 'bottom-start' : 'bottom-end';
  5776. const PLACEMENT_RIGHT = isRTL() ? 'left-start' : 'right-start';
  5777. const PLACEMENT_LEFT = isRTL() ? 'right-start' : 'left-start';
  5778. const Default$6 = {
  5779. offset: [0, 2],
  5780. boundary: 'clippingParents',
  5781. reference: 'toggle',
  5782. display: 'dynamic',
  5783. popperConfig: null
  5784. };
  5785. const DefaultType$6 = {
  5786. offset: '(array|string|function)',
  5787. boundary: '(string|element)',
  5788. reference: '(string|element|object)',
  5789. display: 'string',
  5790. popperConfig: '(null|object|function)'
  5791. };
  5792. class Dropdown extends BaseComponent {
  5793. constructor(element, config) {
  5794. super(element);
  5795. this._popper = null;
  5796. this._config = this._getConfig(config);
  5797. this._menu = this._getMenuElement();
  5798. this._inNavbar = this._detectNavbar();
  5799. this._addEventListeners();
  5800. }
  5801. static get Default() {
  5802. return Default$6;
  5803. }
  5804. static get DefaultType() {
  5805. return DefaultType$6;
  5806. }
  5807. static get DATA_KEY() {
  5808. return DATA_KEY$7;
  5809. }
  5810. toggle() {
  5811. if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED)) {
  5812. return;
  5813. }
  5814. const isActive = this._element.classList.contains(CLASS_NAME_SHOW$6);
  5815. Dropdown.clearMenus();
  5816. if (isActive) {
  5817. return;
  5818. }
  5819. this.show();
  5820. }
  5821. show() {
  5822. if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED) || this._menu.classList.contains(CLASS_NAME_SHOW$6)) {
  5823. return;
  5824. }
  5825. const parent = Dropdown.getParentFromElement(this._element);
  5826. const relatedTarget = {
  5827. relatedTarget: this._element
  5828. };
  5829. const showEvent = EventHandler.trigger(this._element, EVENT_SHOW$4, relatedTarget);
  5830. if (showEvent.defaultPrevented) {
  5831. return;
  5832. }
  5833. if (this._inNavbar) {
  5834. Manipulator.setDataAttribute(this._menu, 'popper', 'none');
  5835. } else {
  5836. if (typeof Popper === 'undefined') {
  5837. throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)');
  5838. }
  5839. let referenceElement = this._element;
  5840. if (this._config.reference === 'parent') {
  5841. referenceElement = parent;
  5842. } else if (isElement(this._config.reference)) {
  5843. referenceElement = this._config.reference;
  5844. if (typeof this._config.reference.jquery !== 'undefined') {
  5845. referenceElement = this._config.reference[0];
  5846. }
  5847. } else if (typeof this._config.reference === 'object') {
  5848. referenceElement = this._config.reference;
  5849. }
  5850. const popperConfig = this._getPopperConfig();
  5851. const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false);
  5852. this._popper = createPopper(referenceElement, this._menu, popperConfig);
  5853. if (isDisplayStatic) {
  5854. Manipulator.setDataAttribute(this._menu, 'popper', 'static');
  5855. }
  5856. }
  5857. if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
  5858. [].concat(...document.body.children).forEach(elem => EventHandler.on(elem, 'mouseover', null, noop()));
  5859. }
  5860. this._element.focus();
  5861. this._element.setAttribute('aria-expanded', true);
  5862. this._menu.classList.toggle(CLASS_NAME_SHOW$6);
  5863. this._element.classList.toggle(CLASS_NAME_SHOW$6);
  5864. EventHandler.trigger(this._element, EVENT_SHOWN$4, relatedTarget);
  5865. }
  5866. hide() {
  5867. if (this._element.disabled || this._element.classList.contains(CLASS_NAME_DISABLED) || !this._menu.classList.contains(CLASS_NAME_SHOW$6)) {
  5868. return;
  5869. }
  5870. const relatedTarget = {
  5871. relatedTarget: this._element
  5872. };
  5873. const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE$4, relatedTarget);
  5874. if (hideEvent.defaultPrevented) {
  5875. return;
  5876. }
  5877. if (this._popper) {
  5878. this._popper.destroy();
  5879. }
  5880. this._menu.classList.toggle(CLASS_NAME_SHOW$6);
  5881. this._element.classList.toggle(CLASS_NAME_SHOW$6);
  5882. Manipulator.removeDataAttribute(this._menu, 'popper');
  5883. EventHandler.trigger(this._element, EVENT_HIDDEN$4, relatedTarget);
  5884. }
  5885. dispose() {
  5886. EventHandler.off(this._element, EVENT_KEY$7);
  5887. this._menu = null;
  5888. if (this._popper) {
  5889. this._popper.destroy();
  5890. this._popper = null;
  5891. }
  5892. super.dispose();
  5893. }
  5894. update() {
  5895. this._inNavbar = this._detectNavbar();
  5896. if (this._popper) {
  5897. this._popper.update();
  5898. }
  5899. }
  5900. _addEventListeners() {
  5901. EventHandler.on(this._element, EVENT_CLICK, event => {
  5902. event.preventDefault();
  5903. this.toggle();
  5904. });
  5905. }
  5906. _getConfig(config) {
  5907. config = { ...this.constructor.Default,
  5908. ...Manipulator.getDataAttributes(this._element),
  5909. ...config
  5910. };
  5911. typeCheckConfig(NAME$7, config, this.constructor.DefaultType);
  5912. if (typeof config.reference === 'object' && !isElement(config.reference) && typeof config.reference.getBoundingClientRect !== 'function') {
  5913. throw new TypeError(`${NAME$7.toUpperCase()}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`);
  5914. }
  5915. return config;
  5916. }
  5917. _getMenuElement() {
  5918. return SelectorEngine.next(this._element, SELECTOR_MENU)[0];
  5919. }
  5920. _getPlacement() {
  5921. const parentDropdown = this._element.parentNode;
  5922. if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) {
  5923. return PLACEMENT_RIGHT;
  5924. }
  5925. if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) {
  5926. return PLACEMENT_LEFT;
  5927. }
  5928. const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end';
  5929. if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
  5930. return isEnd ? PLACEMENT_TOPEND : PLACEMENT_TOP;
  5931. }
  5932. return isEnd ? PLACEMENT_BOTTOMEND : PLACEMENT_BOTTOM;
  5933. }
  5934. _detectNavbar() {
  5935. return this._element.closest(`.${CLASS_NAME_NAVBAR}`) !== null;
  5936. }
  5937. _getOffset() {
  5938. const {
  5939. offset
  5940. } = this._config;
  5941. if (typeof offset === 'string') {
  5942. return offset.split(',').map(val => Number.parseInt(val, 10));
  5943. }
  5944. if (typeof offset === 'function') {
  5945. return popperData => offset(popperData, this._element);
  5946. }
  5947. return offset;
  5948. }
  5949. _getPopperConfig() {
  5950. const defaultBsPopperConfig = {
  5951. placement: this._getPlacement(),
  5952. modifiers: [{
  5953. name: 'preventOverflow',
  5954. options: {
  5955. boundary: this._config.boundary
  5956. }
  5957. }, {
  5958. name: 'offset',
  5959. options: {
  5960. offset: this._getOffset()
  5961. }
  5962. }]
  5963. };
  5964. if (this._config.display === 'static') {
  5965. defaultBsPopperConfig.modifiers = [{
  5966. name: 'applyStyles',
  5967. enabled: false
  5968. }];
  5969. }
  5970. return { ...defaultBsPopperConfig,
  5971. ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
  5972. };
  5973. }
  5974. static dropdownInterface(element, config) {
  5975. let data = Data.get(element, DATA_KEY$7);
  5976. const _config = typeof config === 'object' ? config : null;
  5977. if (!data) {
  5978. data = new Dropdown(element, _config);
  5979. }
  5980. if (typeof config === 'string') {
  5981. if (typeof data[config] === 'undefined') {
  5982. throw new TypeError(`No method named "${config}"`);
  5983. }
  5984. data[config]();
  5985. }
  5986. }
  5987. static jQueryInterface(config) {
  5988. return this.each(function () {
  5989. Dropdown.dropdownInterface(this, config);
  5990. });
  5991. }
  5992. static clearMenus(event) {
  5993. if (event) {
  5994. if (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY) {
  5995. return;
  5996. }
  5997. if (/input|select|textarea|form/i.test(event.target.tagName)) {
  5998. return;
  5999. }
  6000. }
  6001. const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE$3);
  6002. for (let i = 0, len = toggles.length; i < len; i++) {
  6003. const context = Data.get(toggles[i], DATA_KEY$7);
  6004. const relatedTarget = {
  6005. relatedTarget: toggles[i]
  6006. };
  6007. if (event && event.type === 'click') {
  6008. relatedTarget.clickEvent = event;
  6009. }
  6010. if (!context) {
  6011. continue;
  6012. }
  6013. const dropdownMenu = context._menu;
  6014. if (!toggles[i].classList.contains(CLASS_NAME_SHOW$6)) {
  6015. continue;
  6016. }
  6017. if (event) {
  6018. if ([context._element].some(element => event.composedPath().includes(element))) {
  6019. continue;
  6020. }
  6021. if (event.type === 'keyup' && event.key === TAB_KEY && dropdownMenu.contains(event.target)) {
  6022. continue;
  6023. }
  6024. }
  6025. const hideEvent = EventHandler.trigger(toggles[i], EVENT_HIDE$4, relatedTarget);
  6026. if (hideEvent.defaultPrevented) {
  6027. continue;
  6028. }
  6029. if ('ontouchstart' in document.documentElement) {
  6030. [].concat(...document.body.children).forEach(elem => EventHandler.off(elem, 'mouseover', null, noop()));
  6031. }
  6032. toggles[i].setAttribute('aria-expanded', 'false');
  6033. if (context._popper) {
  6034. context._popper.destroy();
  6035. }
  6036. dropdownMenu.classList.remove(CLASS_NAME_SHOW$6);
  6037. toggles[i].classList.remove(CLASS_NAME_SHOW$6);
  6038. Manipulator.removeDataAttribute(dropdownMenu, 'popper');
  6039. EventHandler.trigger(toggles[i], EVENT_HIDDEN$4, relatedTarget);
  6040. }
  6041. }
  6042. static getParentFromElement(element) {
  6043. return getElementFromSelector(element) || element.parentNode;
  6044. }
  6045. static dataApiKeydownHandler(event) {
  6046. if (/input|textarea/i.test(event.target.tagName) ? event.key === SPACE_KEY || event.key !== ESCAPE_KEY$2 && (event.key !== ARROW_DOWN_KEY && event.key !== ARROW_UP_KEY || event.target.closest(SELECTOR_MENU)) : !REGEXP_KEYDOWN.test(event.key)) {
  6047. return;
  6048. }
  6049. event.preventDefault();
  6050. event.stopPropagation();
  6051. if (this.disabled || this.classList.contains(CLASS_NAME_DISABLED)) {
  6052. return;
  6053. }
  6054. const parent = Dropdown.getParentFromElement(this);
  6055. const isActive = this.classList.contains(CLASS_NAME_SHOW$6);
  6056. if (event.key === ESCAPE_KEY$2) {
  6057. const button = this.matches(SELECTOR_DATA_TOGGLE$3) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE$3)[0];
  6058. button.focus();
  6059. Dropdown.clearMenus();
  6060. return;
  6061. }
  6062. if (!isActive && (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY)) {
  6063. const button = this.matches(SELECTOR_DATA_TOGGLE$3) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE$3)[0];
  6064. button.click();
  6065. return;
  6066. }
  6067. if (!isActive || event.key === SPACE_KEY) {
  6068. Dropdown.clearMenus();
  6069. return;
  6070. }
  6071. const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, parent).filter(isVisible);
  6072. if (!items.length) {
  6073. return;
  6074. }
  6075. let index = items.indexOf(event.target);
  6076. if (event.key === ARROW_UP_KEY && index > 0) {
  6077. index--;
  6078. }
  6079. if (event.key === ARROW_DOWN_KEY && index < items.length - 1) {
  6080. index++;
  6081. }
  6082. index = index === -1 ? 0 : index;
  6083. items[index].focus();
  6084. }
  6085. }
  6086. EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE$3, Dropdown.dataApiKeydownHandler);
  6087. EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
  6088. EventHandler.on(document, EVENT_CLICK_DATA_API$3, Dropdown.clearMenus);
  6089. EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
  6090. EventHandler.on(document, EVENT_CLICK_DATA_API$3, SELECTOR_DATA_TOGGLE$3, function (event) {
  6091. event.preventDefault();
  6092. Dropdown.dropdownInterface(this);
  6093. });
  6094. defineJQueryPlugin(NAME$7, Dropdown);
  6095. const NAME$6 = 'modal';
  6096. const DATA_KEY$6 = 'bs.modal';
  6097. const EVENT_KEY$6 = `.${DATA_KEY$6}`;
  6098. const DATA_API_KEY$3 = '.data-api';
  6099. const ESCAPE_KEY$1 = 'Escape';
  6100. const Default$5 = {
  6101. backdrop: true,
  6102. keyboard: true,
  6103. focus: true
  6104. };
  6105. const DefaultType$5 = {
  6106. backdrop: '(boolean|string)',
  6107. keyboard: 'boolean',
  6108. focus: 'boolean'
  6109. };
  6110. const EVENT_HIDE$3 = `hide${EVENT_KEY$6}`;
  6111. const EVENT_HIDE_PREVENTED = `hidePrevented${EVENT_KEY$6}`;
  6112. const EVENT_HIDDEN$3 = `hidden${EVENT_KEY$6}`;
  6113. const EVENT_SHOW$3 = `show${EVENT_KEY$6}`;
  6114. const EVENT_SHOWN$3 = `shown${EVENT_KEY$6}`;
  6115. const EVENT_FOCUSIN$1 = `focusin${EVENT_KEY$6}`;
  6116. const EVENT_RESIZE = `resize${EVENT_KEY$6}`;
  6117. const EVENT_CLICK_DISMISS$2 = `click.dismiss${EVENT_KEY$6}`;
  6118. const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY$6}`;
  6119. const EVENT_MOUSEUP_DISMISS = `mouseup.dismiss${EVENT_KEY$6}`;
  6120. const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY$6}`;
  6121. const EVENT_CLICK_DATA_API$2 = `click${EVENT_KEY$6}${DATA_API_KEY$3}`;
  6122. const CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure';
  6123. const CLASS_NAME_BACKDROP = 'modal-backdrop';
  6124. const CLASS_NAME_OPEN = 'modal-open';
  6125. const CLASS_NAME_FADE$4 = 'fade';
  6126. const CLASS_NAME_SHOW$5 = 'show';
  6127. const CLASS_NAME_STATIC = 'modal-static';
  6128. const SELECTOR_DIALOG = '.modal-dialog';
  6129. const SELECTOR_MODAL_BODY = '.modal-body';
  6130. const SELECTOR_DATA_TOGGLE$2 = '[data-bs-toggle="modal"]';
  6131. const SELECTOR_DATA_DISMISS$2 = '[data-bs-dismiss="modal"]';
  6132. const SELECTOR_FIXED_CONTENT$1 = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
  6133. const SELECTOR_STICKY_CONTENT$1 = '.sticky-top';
  6134. class Modal extends BaseComponent {
  6135. constructor(element, config) {
  6136. super(element);
  6137. this._config = this._getConfig(config);
  6138. this._dialog = SelectorEngine.findOne(SELECTOR_DIALOG, this._element);
  6139. this._backdrop = null;
  6140. this._isShown = false;
  6141. this._isBodyOverflowing = false;
  6142. this._ignoreBackdropClick = false;
  6143. this._isTransitioning = false;
  6144. this._scrollbarWidth = 0;
  6145. }
  6146. static get Default() {
  6147. return Default$5;
  6148. }
  6149. static get DATA_KEY() {
  6150. return DATA_KEY$6;
  6151. }
  6152. toggle(relatedTarget) {
  6153. return this._isShown ? this.hide() : this.show(relatedTarget);
  6154. }
  6155. show(relatedTarget) {
  6156. if (this._isShown || this._isTransitioning) {
  6157. return;
  6158. }
  6159. if (this._isAnimated()) {
  6160. this._isTransitioning = true;
  6161. }
  6162. const showEvent = EventHandler.trigger(this._element, EVENT_SHOW$3, {
  6163. relatedTarget
  6164. });
  6165. if (this._isShown || showEvent.defaultPrevented) {
  6166. return;
  6167. }
  6168. this._isShown = true;
  6169. this._checkScrollbar();
  6170. this._setScrollbar();
  6171. this._adjustDialog();
  6172. this._setEscapeEvent();
  6173. this._setResizeEvent();
  6174. EventHandler.on(this._element, EVENT_CLICK_DISMISS$2, SELECTOR_DATA_DISMISS$2, event => this.hide(event));
  6175. EventHandler.on(this._dialog, EVENT_MOUSEDOWN_DISMISS, () => {
  6176. EventHandler.one(this._element, EVENT_MOUSEUP_DISMISS, event => {
  6177. if (event.target === this._element) {
  6178. this._ignoreBackdropClick = true;
  6179. }
  6180. });
  6181. });
  6182. this._showBackdrop(() => this._showElement(relatedTarget));
  6183. }
  6184. hide(event) {
  6185. if (event) {
  6186. event.preventDefault();
  6187. }
  6188. if (!this._isShown || this._isTransitioning) {
  6189. return;
  6190. }
  6191. const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE$3);
  6192. if (hideEvent.defaultPrevented) {
  6193. return;
  6194. }
  6195. this._isShown = false;
  6196. const isAnimated = this._isAnimated();
  6197. if (isAnimated) {
  6198. this._isTransitioning = true;
  6199. }
  6200. this._setEscapeEvent();
  6201. this._setResizeEvent();
  6202. EventHandler.off(document, EVENT_FOCUSIN$1);
  6203. this._element.classList.remove(CLASS_NAME_SHOW$5);
  6204. EventHandler.off(this._element, EVENT_CLICK_DISMISS$2);
  6205. EventHandler.off(this._dialog, EVENT_MOUSEDOWN_DISMISS);
  6206. if (isAnimated) {
  6207. const transitionDuration = getTransitionDurationFromElement(this._element);
  6208. EventHandler.one(this._element, 'transitionend', event => this._hideModal(event));
  6209. emulateTransitionEnd(this._element, transitionDuration);
  6210. } else {
  6211. this._hideModal();
  6212. }
  6213. }
  6214. dispose() {
  6215. [window, this._element, this._dialog].forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY$6));
  6216. super.dispose();
  6217. EventHandler.off(document, EVENT_FOCUSIN$1);
  6218. this._config = null;
  6219. this._dialog = null;
  6220. this._backdrop = null;
  6221. this._isShown = null;
  6222. this._isBodyOverflowing = null;
  6223. this._ignoreBackdropClick = null;
  6224. this._isTransitioning = null;
  6225. this._scrollbarWidth = null;
  6226. }
  6227. handleUpdate() {
  6228. this._adjustDialog();
  6229. }
  6230. _getConfig(config) {
  6231. config = { ...Default$5,
  6232. ...config
  6233. };
  6234. typeCheckConfig(NAME$6, config, DefaultType$5);
  6235. return config;
  6236. }
  6237. _showElement(relatedTarget) {
  6238. const isAnimated = this._isAnimated();
  6239. const modalBody = SelectorEngine.findOne(SELECTOR_MODAL_BODY, this._dialog);
  6240. if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
  6241. document.body.appendChild(this._element);
  6242. }
  6243. this._element.style.display = 'block';
  6244. this._element.removeAttribute('aria-hidden');
  6245. this._element.setAttribute('aria-modal', true);
  6246. this._element.setAttribute('role', 'dialog');
  6247. this._element.scrollTop = 0;
  6248. if (modalBody) {
  6249. modalBody.scrollTop = 0;
  6250. }
  6251. if (isAnimated) {
  6252. reflow(this._element);
  6253. }
  6254. this._element.classList.add(CLASS_NAME_SHOW$5);
  6255. if (this._config.focus) {
  6256. this._enforceFocus();
  6257. }
  6258. const transitionComplete = () => {
  6259. if (this._config.focus) {
  6260. this._element.focus();
  6261. }
  6262. this._isTransitioning = false;
  6263. EventHandler.trigger(this._element, EVENT_SHOWN$3, {
  6264. relatedTarget
  6265. });
  6266. };
  6267. if (isAnimated) {
  6268. const transitionDuration = getTransitionDurationFromElement(this._dialog);
  6269. EventHandler.one(this._dialog, 'transitionend', transitionComplete);
  6270. emulateTransitionEnd(this._dialog, transitionDuration);
  6271. } else {
  6272. transitionComplete();
  6273. }
  6274. }
  6275. _enforceFocus() {
  6276. EventHandler.off(document, EVENT_FOCUSIN$1);
  6277. EventHandler.on(document, EVENT_FOCUSIN$1, event => {
  6278. if (document !== event.target && this._element !== event.target && !this._element.contains(event.target)) {
  6279. this._element.focus();
  6280. }
  6281. });
  6282. }
  6283. _setEscapeEvent() {
  6284. if (this._isShown) {
  6285. EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, event => {
  6286. if (this._config.keyboard && event.key === ESCAPE_KEY$1) {
  6287. event.preventDefault();
  6288. this.hide();
  6289. } else if (!this._config.keyboard && event.key === ESCAPE_KEY$1) {
  6290. this._triggerBackdropTransition();
  6291. }
  6292. });
  6293. } else {
  6294. EventHandler.off(this._element, EVENT_KEYDOWN_DISMISS);
  6295. }
  6296. }
  6297. _setResizeEvent() {
  6298. if (this._isShown) {
  6299. EventHandler.on(window, EVENT_RESIZE, () => this._adjustDialog());
  6300. } else {
  6301. EventHandler.off(window, EVENT_RESIZE);
  6302. }
  6303. }
  6304. _hideModal() {
  6305. this._element.style.display = 'none';
  6306. this._element.setAttribute('aria-hidden', true);
  6307. this._element.removeAttribute('aria-modal');
  6308. this._element.removeAttribute('role');
  6309. this._isTransitioning = false;
  6310. this._showBackdrop(() => {
  6311. document.body.classList.remove(CLASS_NAME_OPEN);
  6312. this._resetAdjustments();
  6313. this._resetScrollbar();
  6314. EventHandler.trigger(this._element, EVENT_HIDDEN$3);
  6315. });
  6316. }
  6317. _removeBackdrop() {
  6318. this._backdrop.parentNode.removeChild(this._backdrop);
  6319. this._backdrop = null;
  6320. }
  6321. _showBackdrop(callback) {
  6322. const isAnimated = this._isAnimated();
  6323. if (this._isShown && this._config.backdrop) {
  6324. this._backdrop = document.createElement('div');
  6325. this._backdrop.className = CLASS_NAME_BACKDROP;
  6326. if (isAnimated) {
  6327. this._backdrop.classList.add(CLASS_NAME_FADE$4);
  6328. }
  6329. document.body.appendChild(this._backdrop);
  6330. EventHandler.on(this._element, EVENT_CLICK_DISMISS$2, event => {
  6331. if (this._ignoreBackdropClick) {
  6332. this._ignoreBackdropClick = false;
  6333. return;
  6334. }
  6335. if (event.target !== event.currentTarget) {
  6336. return;
  6337. }
  6338. if (this._config.backdrop === 'static') {
  6339. this._triggerBackdropTransition();
  6340. } else {
  6341. this.hide();
  6342. }
  6343. });
  6344. if (isAnimated) {
  6345. reflow(this._backdrop);
  6346. }
  6347. this._backdrop.classList.add(CLASS_NAME_SHOW$5);
  6348. if (!isAnimated) {
  6349. callback();
  6350. return;
  6351. }
  6352. const backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
  6353. EventHandler.one(this._backdrop, 'transitionend', callback);
  6354. emulateTransitionEnd(this._backdrop, backdropTransitionDuration);
  6355. } else if (!this._isShown && this._backdrop) {
  6356. this._backdrop.classList.remove(CLASS_NAME_SHOW$5);
  6357. const callbackRemove = () => {
  6358. this._removeBackdrop();
  6359. callback();
  6360. };
  6361. if (isAnimated) {
  6362. const backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
  6363. EventHandler.one(this._backdrop, 'transitionend', callbackRemove);
  6364. emulateTransitionEnd(this._backdrop, backdropTransitionDuration);
  6365. } else {
  6366. callbackRemove();
  6367. }
  6368. } else {
  6369. callback();
  6370. }
  6371. }
  6372. _isAnimated() {
  6373. return this._element.classList.contains(CLASS_NAME_FADE$4);
  6374. }
  6375. _triggerBackdropTransition() {
  6376. const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED);
  6377. if (hideEvent.defaultPrevented) {
  6378. return;
  6379. }
  6380. const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
  6381. if (!isModalOverflowing) {
  6382. this._element.style.overflowY = 'hidden';
  6383. }
  6384. this._element.classList.add(CLASS_NAME_STATIC);
  6385. const modalTransitionDuration = getTransitionDurationFromElement(this._dialog);
  6386. EventHandler.off(this._element, 'transitionend');
  6387. EventHandler.one(this._element, 'transitionend', () => {
  6388. this._element.classList.remove(CLASS_NAME_STATIC);
  6389. if (!isModalOverflowing) {
  6390. EventHandler.one(this._element, 'transitionend', () => {
  6391. this._element.style.overflowY = '';
  6392. });
  6393. emulateTransitionEnd(this._element, modalTransitionDuration);
  6394. }
  6395. });
  6396. emulateTransitionEnd(this._element, modalTransitionDuration);
  6397. this._element.focus();
  6398. }
  6399. _adjustDialog() {
  6400. const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
  6401. if (!this._isBodyOverflowing && isModalOverflowing && !isRTL() || this._isBodyOverflowing && !isModalOverflowing && isRTL()) {
  6402. this._element.style.paddingLeft = `${this._scrollbarWidth}px`;
  6403. }
  6404. if (this._isBodyOverflowing && !isModalOverflowing && !isRTL() || !this._isBodyOverflowing && isModalOverflowing && isRTL()) {
  6405. this._element.style.paddingRight = `${this._scrollbarWidth}px`;
  6406. }
  6407. }
  6408. _resetAdjustments() {
  6409. this._element.style.paddingLeft = '';
  6410. this._element.style.paddingRight = '';
  6411. }
  6412. _checkScrollbar() {
  6413. const rect = document.body.getBoundingClientRect();
  6414. this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth;
  6415. this._scrollbarWidth = this._getScrollbarWidth();
  6416. }
  6417. _setScrollbar() {
  6418. if (this._isBodyOverflowing) {
  6419. this._setElementAttributes(SELECTOR_FIXED_CONTENT$1, 'paddingRight', calculatedValue => calculatedValue + this._scrollbarWidth);
  6420. this._setElementAttributes(SELECTOR_STICKY_CONTENT$1, 'marginRight', calculatedValue => calculatedValue - this._scrollbarWidth);
  6421. this._setElementAttributes('body', 'paddingRight', calculatedValue => calculatedValue + this._scrollbarWidth);
  6422. }
  6423. document.body.classList.add(CLASS_NAME_OPEN);
  6424. }
  6425. _setElementAttributes(selector, styleProp, callback) {
  6426. SelectorEngine.find(selector).forEach(element => {
  6427. if (element !== document.body && window.innerWidth > element.clientWidth + this._scrollbarWidth) {
  6428. return;
  6429. }
  6430. const actualValue = element.style[styleProp];
  6431. const calculatedValue = window.getComputedStyle(element)[styleProp];
  6432. Manipulator.setDataAttribute(element, styleProp, actualValue);
  6433. element.style[styleProp] = callback(Number.parseFloat(calculatedValue)) + 'px';
  6434. });
  6435. }
  6436. _resetScrollbar() {
  6437. this._resetElementAttributes(SELECTOR_FIXED_CONTENT$1, 'paddingRight');
  6438. this._resetElementAttributes(SELECTOR_STICKY_CONTENT$1, 'marginRight');
  6439. this._resetElementAttributes('body', 'paddingRight');
  6440. }
  6441. _resetElementAttributes(selector, styleProp) {
  6442. SelectorEngine.find(selector).forEach(element => {
  6443. const value = Manipulator.getDataAttribute(element, styleProp);
  6444. if (typeof value === 'undefined' && element === document.body) {
  6445. element.style[styleProp] = '';
  6446. } else {
  6447. Manipulator.removeDataAttribute(element, styleProp);
  6448. element.style[styleProp] = value;
  6449. }
  6450. });
  6451. }
  6452. _getScrollbarWidth() {
  6453. const scrollDiv = document.createElement('div');
  6454. scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER;
  6455. document.body.appendChild(scrollDiv);
  6456. const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
  6457. document.body.removeChild(scrollDiv);
  6458. return scrollbarWidth;
  6459. }
  6460. static jQueryInterface(config, relatedTarget) {
  6461. return this.each(function () {
  6462. let data = Data.get(this, DATA_KEY$6);
  6463. const _config = { ...Default$5,
  6464. ...Manipulator.getDataAttributes(this),
  6465. ...(typeof config === 'object' && config ? config : {})
  6466. };
  6467. if (!data) {
  6468. data = new Modal(this, _config);
  6469. }
  6470. if (typeof config === 'string') {
  6471. if (typeof data[config] === 'undefined') {
  6472. throw new TypeError(`No method named "${config}"`);
  6473. }
  6474. data[config](relatedTarget);
  6475. }
  6476. });
  6477. }
  6478. }
  6479. EventHandler.on(document, EVENT_CLICK_DATA_API$2, SELECTOR_DATA_TOGGLE$2, function (event) {
  6480. const target = getElementFromSelector(this);
  6481. if (this.tagName === 'A' || this.tagName === 'AREA') {
  6482. event.preventDefault();
  6483. }
  6484. EventHandler.one(target, EVENT_SHOW$3, showEvent => {
  6485. if (showEvent.defaultPrevented) {
  6486. return;
  6487. }
  6488. EventHandler.one(target, EVENT_HIDDEN$3, () => {
  6489. if (isVisible(this)) {
  6490. this.focus();
  6491. }
  6492. });
  6493. });
  6494. let data = Data.get(target, DATA_KEY$6);
  6495. if (!data) {
  6496. const config = { ...Manipulator.getDataAttributes(target),
  6497. ...Manipulator.getDataAttributes(this)
  6498. };
  6499. data = new Modal(target, config);
  6500. }
  6501. data.toggle(this);
  6502. });
  6503. defineJQueryPlugin(NAME$6, Modal);
  6504. const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed';
  6505. const SELECTOR_STICKY_CONTENT = '.sticky-top';
  6506. const getWidth = () => {
  6507. const documentWidth = document.documentElement.clientWidth;
  6508. return Math.abs(window.innerWidth - documentWidth);
  6509. };
  6510. const hide = (width = getWidth()) => {
  6511. document.body.style.overflow = 'hidden';
  6512. _setElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight', calculatedValue => calculatedValue + width);
  6513. _setElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight', calculatedValue => calculatedValue - width);
  6514. _setElementAttributes('body', 'paddingRight', calculatedValue => calculatedValue + width);
  6515. };
  6516. const _setElementAttributes = (selector, styleProp, callback) => {
  6517. const scrollbarWidth = getWidth();
  6518. SelectorEngine.find(selector).forEach(element => {
  6519. if (element !== document.body && window.innerWidth > element.clientWidth + scrollbarWidth) {
  6520. return;
  6521. }
  6522. const actualValue = element.style[styleProp];
  6523. const calculatedValue = window.getComputedStyle(element)[styleProp];
  6524. Manipulator.setDataAttribute(element, styleProp, actualValue);
  6525. element.style[styleProp] = callback(Number.parseFloat(calculatedValue)) + 'px';
  6526. });
  6527. };
  6528. const reset = () => {
  6529. document.body.style.overflow = 'auto';
  6530. _resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight');
  6531. _resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight');
  6532. _resetElementAttributes('body', 'paddingRight');
  6533. };
  6534. const _resetElementAttributes = (selector, styleProp) => {
  6535. SelectorEngine.find(selector).forEach(element => {
  6536. const value = Manipulator.getDataAttribute(element, styleProp);
  6537. if (typeof value === 'undefined' && element === document.body) {
  6538. element.style.removeProperty(styleProp);
  6539. } else {
  6540. Manipulator.removeDataAttribute(element, styleProp);
  6541. element.style[styleProp] = value;
  6542. }
  6543. });
  6544. };
  6545. const NAME$5 = 'offcanvas';
  6546. const DATA_KEY$5 = 'bs.offcanvas';
  6547. const EVENT_KEY$5 = `.${DATA_KEY$5}`;
  6548. const DATA_API_KEY$2 = '.data-api';
  6549. const EVENT_LOAD_DATA_API$1 = `load${EVENT_KEY$5}${DATA_API_KEY$2}`;
  6550. const ESCAPE_KEY = 'Escape';
  6551. const Default$4 = {
  6552. backdrop: true,
  6553. keyboard: true,
  6554. scroll: false
  6555. };
  6556. const DefaultType$4 = {
  6557. backdrop: 'boolean',
  6558. keyboard: 'boolean',
  6559. scroll: 'boolean'
  6560. };
  6561. const CLASS_NAME_BACKDROP_BODY = 'offcanvas-backdrop';
  6562. const CLASS_NAME_SHOW$4 = 'show';
  6563. const CLASS_NAME_TOGGLING = 'offcanvas-toggling';
  6564. const OPEN_SELECTOR = '.offcanvas.show';
  6565. const ACTIVE_SELECTOR = `${OPEN_SELECTOR}, .${CLASS_NAME_TOGGLING}`;
  6566. const EVENT_SHOW$2 = `show${EVENT_KEY$5}`;
  6567. const EVENT_SHOWN$2 = `shown${EVENT_KEY$5}`;
  6568. const EVENT_HIDE$2 = `hide${EVENT_KEY$5}`;
  6569. const EVENT_HIDDEN$2 = `hidden${EVENT_KEY$5}`;
  6570. const EVENT_FOCUSIN = `focusin${EVENT_KEY$5}`;
  6571. const EVENT_CLICK_DATA_API$1 = `click${EVENT_KEY$5}${DATA_API_KEY$2}`;
  6572. const EVENT_CLICK_DISMISS$1 = `click.dismiss${EVENT_KEY$5}`;
  6573. const SELECTOR_DATA_DISMISS$1 = '[data-bs-dismiss="offcanvas"]';
  6574. const SELECTOR_DATA_TOGGLE$1 = '[data-bs-toggle="offcanvas"]';
  6575. class Offcanvas extends BaseComponent {
  6576. constructor(element, config) {
  6577. super(element);
  6578. this._config = this._getConfig(config);
  6579. this._isShown = false;
  6580. this._addEventListeners();
  6581. }
  6582. static get Default() {
  6583. return Default$4;
  6584. }
  6585. static get DATA_KEY() {
  6586. return DATA_KEY$5;
  6587. }
  6588. toggle(relatedTarget) {
  6589. return this._isShown ? this.hide() : this.show(relatedTarget);
  6590. }
  6591. show(relatedTarget) {
  6592. if (this._isShown) {
  6593. return;
  6594. }
  6595. const showEvent = EventHandler.trigger(this._element, EVENT_SHOW$2, {
  6596. relatedTarget
  6597. });
  6598. if (showEvent.defaultPrevented) {
  6599. return;
  6600. }
  6601. this._isShown = true;
  6602. this._element.style.visibility = 'visible';
  6603. if (this._config.backdrop) {
  6604. document.body.classList.add(CLASS_NAME_BACKDROP_BODY);
  6605. }
  6606. if (!this._config.scroll) {
  6607. hide();
  6608. }
  6609. this._element.classList.add(CLASS_NAME_TOGGLING);
  6610. this._element.removeAttribute('aria-hidden');
  6611. this._element.setAttribute('aria-modal', true);
  6612. this._element.setAttribute('role', 'dialog');
  6613. this._element.classList.add(CLASS_NAME_SHOW$4);
  6614. const completeCallBack = () => {
  6615. this._element.classList.remove(CLASS_NAME_TOGGLING);
  6616. EventHandler.trigger(this._element, EVENT_SHOWN$2, {
  6617. relatedTarget
  6618. });
  6619. this._enforceFocusOnElement(this._element);
  6620. };
  6621. setTimeout(completeCallBack, getTransitionDurationFromElement(this._element));
  6622. }
  6623. hide() {
  6624. if (!this._isShown) {
  6625. return;
  6626. }
  6627. const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE$2);
  6628. if (hideEvent.defaultPrevented) {
  6629. return;
  6630. }
  6631. this._element.classList.add(CLASS_NAME_TOGGLING);
  6632. EventHandler.off(document, EVENT_FOCUSIN);
  6633. this._element.blur();
  6634. this._isShown = false;
  6635. this._element.classList.remove(CLASS_NAME_SHOW$4);
  6636. const completeCallback = () => {
  6637. this._element.setAttribute('aria-hidden', true);
  6638. this._element.removeAttribute('aria-modal');
  6639. this._element.removeAttribute('role');
  6640. this._element.style.visibility = 'hidden';
  6641. if (this._config.backdrop) {
  6642. document.body.classList.remove(CLASS_NAME_BACKDROP_BODY);
  6643. }
  6644. if (!this._config.scroll) {
  6645. reset();
  6646. }
  6647. EventHandler.trigger(this._element, EVENT_HIDDEN$2);
  6648. this._element.classList.remove(CLASS_NAME_TOGGLING);
  6649. };
  6650. setTimeout(completeCallback, getTransitionDurationFromElement(this._element));
  6651. }
  6652. _getConfig(config) {
  6653. config = { ...Default$4,
  6654. ...Manipulator.getDataAttributes(this._element),
  6655. ...(typeof config === 'object' ? config : {})
  6656. };
  6657. typeCheckConfig(NAME$5, config, DefaultType$4);
  6658. return config;
  6659. }
  6660. _enforceFocusOnElement(element) {
  6661. EventHandler.off(document, EVENT_FOCUSIN);
  6662. EventHandler.on(document, EVENT_FOCUSIN, event => {
  6663. if (document !== event.target && element !== event.target && !element.contains(event.target)) {
  6664. element.focus();
  6665. }
  6666. });
  6667. element.focus();
  6668. }
  6669. _addEventListeners() {
  6670. EventHandler.on(this._element, EVENT_CLICK_DISMISS$1, SELECTOR_DATA_DISMISS$1, () => this.hide());
  6671. EventHandler.on(document, 'keydown', event => {
  6672. if (this._config.keyboard && event.key === ESCAPE_KEY) {
  6673. this.hide();
  6674. }
  6675. });
  6676. EventHandler.on(document, EVENT_CLICK_DATA_API$1, event => {
  6677. const target = SelectorEngine.findOne(getSelectorFromElement(event.target));
  6678. if (!this._element.contains(event.target) && target !== this._element) {
  6679. this.hide();
  6680. }
  6681. });
  6682. }
  6683. static jQueryInterface(config) {
  6684. return this.each(function () {
  6685. const data = Data.get(this, DATA_KEY$5) || new Offcanvas(this, typeof config === 'object' ? config : {});
  6686. if (typeof config !== 'string') {
  6687. return;
  6688. }
  6689. if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
  6690. throw new TypeError(`No method named "${config}"`);
  6691. }
  6692. data[config](this);
  6693. });
  6694. }
  6695. }
  6696. EventHandler.on(document, EVENT_CLICK_DATA_API$1, SELECTOR_DATA_TOGGLE$1, function (event) {
  6697. const target = getElementFromSelector(this);
  6698. if (['A', 'AREA'].includes(this.tagName)) {
  6699. event.preventDefault();
  6700. }
  6701. if (isDisabled(this)) {
  6702. return;
  6703. }
  6704. EventHandler.one(target, EVENT_HIDDEN$2, () => {
  6705. if (isVisible(this)) {
  6706. this.focus();
  6707. }
  6708. });
  6709. const allReadyOpen = SelectorEngine.findOne(ACTIVE_SELECTOR);
  6710. if (allReadyOpen && allReadyOpen !== target) {
  6711. return;
  6712. }
  6713. const data = Data.get(target, DATA_KEY$5) || new Offcanvas(target);
  6714. data.toggle(this);
  6715. });
  6716. EventHandler.on(window, EVENT_LOAD_DATA_API$1, () => {
  6717. SelectorEngine.find(OPEN_SELECTOR).forEach(el => (Data.get(el, DATA_KEY$5) || new Offcanvas(el)).show());
  6718. });
  6719. defineJQueryPlugin(NAME$5, Offcanvas);
  6720. const uriAttrs = new Set(['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href']);
  6721. const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i;
  6722. const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/i;
  6723. const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i;
  6724. const allowedAttribute = (attr, allowedAttributeList) => {
  6725. const attrName = attr.nodeName.toLowerCase();
  6726. if (allowedAttributeList.includes(attrName)) {
  6727. if (uriAttrs.has(attrName)) {
  6728. return Boolean(SAFE_URL_PATTERN.test(attr.nodeValue) || DATA_URL_PATTERN.test(attr.nodeValue));
  6729. }
  6730. return true;
  6731. }
  6732. const regExp = allowedAttributeList.filter(attrRegex => attrRegex instanceof RegExp);
  6733. for (let i = 0, len = regExp.length; i < len; i++) {
  6734. if (regExp[i].test(attrName)) {
  6735. return true;
  6736. }
  6737. }
  6738. return false;
  6739. };
  6740. const DefaultAllowlist = {
  6741. '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
  6742. a: ['target', 'href', 'title', 'rel'],
  6743. area: [],
  6744. b: [],
  6745. br: [],
  6746. col: [],
  6747. code: [],
  6748. div: [],
  6749. em: [],
  6750. hr: [],
  6751. h1: [],
  6752. h2: [],
  6753. h3: [],
  6754. h4: [],
  6755. h5: [],
  6756. h6: [],
  6757. i: [],
  6758. img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
  6759. li: [],
  6760. ol: [],
  6761. p: [],
  6762. pre: [],
  6763. s: [],
  6764. small: [],
  6765. span: [],
  6766. sub: [],
  6767. sup: [],
  6768. strong: [],
  6769. u: [],
  6770. ul: []
  6771. };
  6772. function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) {
  6773. if (!unsafeHtml.length) {
  6774. return unsafeHtml;
  6775. }
  6776. if (sanitizeFn && typeof sanitizeFn === 'function') {
  6777. return sanitizeFn(unsafeHtml);
  6778. }
  6779. const domParser = new window.DOMParser();
  6780. const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html');
  6781. const allowlistKeys = Object.keys(allowList);
  6782. const elements = [].concat(...createdDocument.body.querySelectorAll('*'));
  6783. for (let i = 0, len = elements.length; i < len; i++) {
  6784. const el = elements[i];
  6785. const elName = el.nodeName.toLowerCase();
  6786. if (!allowlistKeys.includes(elName)) {
  6787. el.parentNode.removeChild(el);
  6788. continue;
  6789. }
  6790. const attributeList = [].concat(...el.attributes);
  6791. const allowedAttributes = [].concat(allowList['*'] || [], allowList[elName] || []);
  6792. attributeList.forEach(attr => {
  6793. if (!allowedAttribute(attr, allowedAttributes)) {
  6794. el.removeAttribute(attr.nodeName);
  6795. }
  6796. });
  6797. }
  6798. return createdDocument.body.innerHTML;
  6799. }
  6800. const NAME$4 = 'tooltip';
  6801. const DATA_KEY$4 = 'bs.tooltip';
  6802. const EVENT_KEY$4 = `.${DATA_KEY$4}`;
  6803. const CLASS_PREFIX$1 = 'bs-tooltip';
  6804. const BSCLS_PREFIX_REGEX$1 = new RegExp(`(^|\\s)${CLASS_PREFIX$1}\\S+`, 'g');
  6805. const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']);
  6806. const DefaultType$3 = {
  6807. animation: 'boolean',
  6808. template: 'string',
  6809. title: '(string|element|function)',
  6810. trigger: 'string',
  6811. delay: '(number|object)',
  6812. html: 'boolean',
  6813. selector: '(string|boolean)',
  6814. placement: '(string|function)',
  6815. offset: '(array|string|function)',
  6816. container: '(string|element|boolean)',
  6817. fallbackPlacements: 'array',
  6818. boundary: '(string|element)',
  6819. customClass: '(string|function)',
  6820. sanitize: 'boolean',
  6821. sanitizeFn: '(null|function)',
  6822. allowList: 'object',
  6823. popperConfig: '(null|object|function)'
  6824. };
  6825. const AttachmentMap = {
  6826. AUTO: 'auto',
  6827. TOP: 'top',
  6828. RIGHT: isRTL() ? 'left' : 'right',
  6829. BOTTOM: 'bottom',
  6830. LEFT: isRTL() ? 'right' : 'left'
  6831. };
  6832. const Default$3 = {
  6833. animation: true,
  6834. template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div>' + '</div>',
  6835. trigger: 'hover focus',
  6836. title: '',
  6837. delay: 0,
  6838. html: false,
  6839. selector: false,
  6840. placement: 'top',
  6841. offset: [0, 0],
  6842. container: false,
  6843. fallbackPlacements: ['top', 'right', 'bottom', 'left'],
  6844. boundary: 'clippingParents',
  6845. customClass: '',
  6846. sanitize: true,
  6847. sanitizeFn: null,
  6848. allowList: DefaultAllowlist,
  6849. popperConfig: null
  6850. };
  6851. const Event$2 = {
  6852. HIDE: `hide${EVENT_KEY$4}`,
  6853. HIDDEN: `hidden${EVENT_KEY$4}`,
  6854. SHOW: `show${EVENT_KEY$4}`,
  6855. SHOWN: `shown${EVENT_KEY$4}`,
  6856. INSERTED: `inserted${EVENT_KEY$4}`,
  6857. CLICK: `click${EVENT_KEY$4}`,
  6858. FOCUSIN: `focusin${EVENT_KEY$4}`,
  6859. FOCUSOUT: `focusout${EVENT_KEY$4}`,
  6860. MOUSEENTER: `mouseenter${EVENT_KEY$4}`,
  6861. MOUSELEAVE: `mouseleave${EVENT_KEY$4}`
  6862. };
  6863. const CLASS_NAME_FADE$3 = 'fade';
  6864. const CLASS_NAME_MODAL = 'modal';
  6865. const CLASS_NAME_SHOW$3 = 'show';
  6866. const HOVER_STATE_SHOW = 'show';
  6867. const HOVER_STATE_OUT = 'out';
  6868. const SELECTOR_TOOLTIP_INNER = '.tooltip-inner';
  6869. const TRIGGER_HOVER = 'hover';
  6870. const TRIGGER_FOCUS = 'focus';
  6871. const TRIGGER_CLICK = 'click';
  6872. const TRIGGER_MANUAL = 'manual';
  6873. class Tooltip extends BaseComponent {
  6874. constructor(element, config) {
  6875. if (typeof Popper === 'undefined') {
  6876. throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)');
  6877. }
  6878. super(element);
  6879. this._isEnabled = true;
  6880. this._timeout = 0;
  6881. this._hoverState = '';
  6882. this._activeTrigger = {};
  6883. this._popper = null;
  6884. this.config = this._getConfig(config);
  6885. this.tip = null;
  6886. this._setListeners();
  6887. }
  6888. static get Default() {
  6889. return Default$3;
  6890. }
  6891. static get NAME() {
  6892. return NAME$4;
  6893. }
  6894. static get DATA_KEY() {
  6895. return DATA_KEY$4;
  6896. }
  6897. static get Event() {
  6898. return Event$2;
  6899. }
  6900. static get EVENT_KEY() {
  6901. return EVENT_KEY$4;
  6902. }
  6903. static get DefaultType() {
  6904. return DefaultType$3;
  6905. }
  6906. enable() {
  6907. this._isEnabled = true;
  6908. }
  6909. disable() {
  6910. this._isEnabled = false;
  6911. }
  6912. toggleEnabled() {
  6913. this._isEnabled = !this._isEnabled;
  6914. }
  6915. toggle(event) {
  6916. if (!this._isEnabled) {
  6917. return;
  6918. }
  6919. if (event) {
  6920. const context = this._initializeOnDelegatedTarget(event);
  6921. context._activeTrigger.click = !context._activeTrigger.click;
  6922. if (context._isWithActiveTrigger()) {
  6923. context._enter(null, context);
  6924. } else {
  6925. context._leave(null, context);
  6926. }
  6927. } else {
  6928. if (this.getTipElement().classList.contains(CLASS_NAME_SHOW$3)) {
  6929. this._leave(null, this);
  6930. return;
  6931. }
  6932. this._enter(null, this);
  6933. }
  6934. }
  6935. dispose() {
  6936. clearTimeout(this._timeout);
  6937. EventHandler.off(this._element, this.constructor.EVENT_KEY);
  6938. EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler);
  6939. if (this.tip && this.tip.parentNode) {
  6940. this.tip.parentNode.removeChild(this.tip);
  6941. }
  6942. this._isEnabled = null;
  6943. this._timeout = null;
  6944. this._hoverState = null;
  6945. this._activeTrigger = null;
  6946. if (this._popper) {
  6947. this._popper.destroy();
  6948. }
  6949. this._popper = null;
  6950. this.config = null;
  6951. this.tip = null;
  6952. super.dispose();
  6953. }
  6954. show() {
  6955. if (this._element.style.display === 'none') {
  6956. throw new Error('Please use show on visible elements');
  6957. }
  6958. if (!(this.isWithContent() && this._isEnabled)) {
  6959. return;
  6960. }
  6961. const showEvent = EventHandler.trigger(this._element, this.constructor.Event.SHOW);
  6962. const shadowRoot = findShadowRoot(this._element);
  6963. const isInTheDom = shadowRoot === null ? this._element.ownerDocument.documentElement.contains(this._element) : shadowRoot.contains(this._element);
  6964. if (showEvent.defaultPrevented || !isInTheDom) {
  6965. return;
  6966. }
  6967. const tip = this.getTipElement();
  6968. const tipId = getUID(this.constructor.NAME);
  6969. tip.setAttribute('id', tipId);
  6970. this._element.setAttribute('aria-describedby', tipId);
  6971. this.setContent();
  6972. if (this.config.animation) {
  6973. tip.classList.add(CLASS_NAME_FADE$3);
  6974. }
  6975. const placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this._element) : this.config.placement;
  6976. const attachment = this._getAttachment(placement);
  6977. this._addAttachmentClass(attachment);
  6978. const container = this._getContainer();
  6979. Data.set(tip, this.constructor.DATA_KEY, this);
  6980. if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
  6981. container.appendChild(tip);
  6982. EventHandler.trigger(this._element, this.constructor.Event.INSERTED);
  6983. }
  6984. if (this._popper) {
  6985. this._popper.update();
  6986. } else {
  6987. this._popper = createPopper(this._element, tip, this._getPopperConfig(attachment));
  6988. }
  6989. tip.classList.add(CLASS_NAME_SHOW$3);
  6990. const customClass = typeof this.config.customClass === 'function' ? this.config.customClass() : this.config.customClass;
  6991. if (customClass) {
  6992. tip.classList.add(...customClass.split(' '));
  6993. }
  6994. if ('ontouchstart' in document.documentElement) {
  6995. [].concat(...document.body.children).forEach(element => {
  6996. EventHandler.on(element, 'mouseover', noop());
  6997. });
  6998. }
  6999. const complete = () => {
  7000. const prevHoverState = this._hoverState;
  7001. this._hoverState = null;
  7002. EventHandler.trigger(this._element, this.constructor.Event.SHOWN);
  7003. if (prevHoverState === HOVER_STATE_OUT) {
  7004. this._leave(null, this);
  7005. }
  7006. };
  7007. if (this.tip.classList.contains(CLASS_NAME_FADE$3)) {
  7008. const transitionDuration = getTransitionDurationFromElement(this.tip);
  7009. EventHandler.one(this.tip, 'transitionend', complete);
  7010. emulateTransitionEnd(this.tip, transitionDuration);
  7011. } else {
  7012. complete();
  7013. }
  7014. }
  7015. hide() {
  7016. if (!this._popper) {
  7017. return;
  7018. }
  7019. const tip = this.getTipElement();
  7020. const complete = () => {
  7021. if (this._isWithActiveTrigger()) {
  7022. return;
  7023. }
  7024. if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
  7025. tip.parentNode.removeChild(tip);
  7026. }
  7027. this._cleanTipClass();
  7028. this._element.removeAttribute('aria-describedby');
  7029. EventHandler.trigger(this._element, this.constructor.Event.HIDDEN);
  7030. if (this._popper) {
  7031. this._popper.destroy();
  7032. this._popper = null;
  7033. }
  7034. };
  7035. const hideEvent = EventHandler.trigger(this._element, this.constructor.Event.HIDE);
  7036. if (hideEvent.defaultPrevented) {
  7037. return;
  7038. }
  7039. tip.classList.remove(CLASS_NAME_SHOW$3);
  7040. if ('ontouchstart' in document.documentElement) {
  7041. [].concat(...document.body.children).forEach(element => EventHandler.off(element, 'mouseover', noop));
  7042. }
  7043. this._activeTrigger[TRIGGER_CLICK] = false;
  7044. this._activeTrigger[TRIGGER_FOCUS] = false;
  7045. this._activeTrigger[TRIGGER_HOVER] = false;
  7046. if (this.tip.classList.contains(CLASS_NAME_FADE$3)) {
  7047. const transitionDuration = getTransitionDurationFromElement(tip);
  7048. EventHandler.one(tip, 'transitionend', complete);
  7049. emulateTransitionEnd(tip, transitionDuration);
  7050. } else {
  7051. complete();
  7052. }
  7053. this._hoverState = '';
  7054. }
  7055. update() {
  7056. if (this._popper !== null) {
  7057. this._popper.update();
  7058. }
  7059. }
  7060. isWithContent() {
  7061. return Boolean(this.getTitle());
  7062. }
  7063. getTipElement() {
  7064. if (this.tip) {
  7065. return this.tip;
  7066. }
  7067. const element = document.createElement('div');
  7068. element.innerHTML = this.config.template;
  7069. this.tip = element.children[0];
  7070. return this.tip;
  7071. }
  7072. setContent() {
  7073. const tip = this.getTipElement();
  7074. this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle());
  7075. tip.classList.remove(CLASS_NAME_FADE$3, CLASS_NAME_SHOW$3);
  7076. }
  7077. setElementContent(element, content) {
  7078. if (element === null) {
  7079. return;
  7080. }
  7081. if (typeof content === 'object' && isElement(content)) {
  7082. if (content.jquery) {
  7083. content = content[0];
  7084. }
  7085. if (this.config.html) {
  7086. if (content.parentNode !== element) {
  7087. element.innerHTML = '';
  7088. element.appendChild(content);
  7089. }
  7090. } else {
  7091. element.textContent = content.textContent;
  7092. }
  7093. return;
  7094. }
  7095. if (this.config.html) {
  7096. if (this.config.sanitize) {
  7097. content = sanitizeHtml(content, this.config.allowList, this.config.sanitizeFn);
  7098. }
  7099. element.innerHTML = content;
  7100. } else {
  7101. element.textContent = content;
  7102. }
  7103. }
  7104. getTitle() {
  7105. let title = this._element.getAttribute('data-bs-original-title');
  7106. if (!title) {
  7107. title = typeof this.config.title === 'function' ? this.config.title.call(this._element) : this.config.title;
  7108. }
  7109. return title;
  7110. }
  7111. updateAttachment(attachment) {
  7112. if (attachment === 'right') {
  7113. return 'end';
  7114. }
  7115. if (attachment === 'left') {
  7116. return 'start';
  7117. }
  7118. return attachment;
  7119. }
  7120. _initializeOnDelegatedTarget(event, context) {
  7121. const dataKey = this.constructor.DATA_KEY;
  7122. context = context || Data.get(event.delegateTarget, dataKey);
  7123. if (!context) {
  7124. context = new this.constructor(event.delegateTarget, this._getDelegateConfig());
  7125. Data.set(event.delegateTarget, dataKey, context);
  7126. }
  7127. return context;
  7128. }
  7129. _getOffset() {
  7130. const {
  7131. offset
  7132. } = this.config;
  7133. if (typeof offset === 'string') {
  7134. return offset.split(',').map(val => Number.parseInt(val, 10));
  7135. }
  7136. if (typeof offset === 'function') {
  7137. return popperData => offset(popperData, this._element);
  7138. }
  7139. return offset;
  7140. }
  7141. _getPopperConfig(attachment) {
  7142. const defaultBsPopperConfig = {
  7143. placement: attachment,
  7144. modifiers: [{
  7145. name: 'flip',
  7146. options: {
  7147. altBoundary: true,
  7148. fallbackPlacements: this.config.fallbackPlacements
  7149. }
  7150. }, {
  7151. name: 'offset',
  7152. options: {
  7153. offset: this._getOffset()
  7154. }
  7155. }, {
  7156. name: 'preventOverflow',
  7157. options: {
  7158. boundary: this.config.boundary
  7159. }
  7160. }, {
  7161. name: 'arrow',
  7162. options: {
  7163. element: `.${this.constructor.NAME}-arrow`
  7164. }
  7165. }, {
  7166. name: 'onChange',
  7167. enabled: true,
  7168. phase: 'afterWrite',
  7169. fn: data => this._handlePopperPlacementChange(data)
  7170. }],
  7171. onFirstUpdate: data => {
  7172. if (data.options.placement !== data.placement) {
  7173. this._handlePopperPlacementChange(data);
  7174. }
  7175. }
  7176. };
  7177. return { ...defaultBsPopperConfig,
  7178. ...(typeof this.config.popperConfig === 'function' ? this.config.popperConfig(defaultBsPopperConfig) : this.config.popperConfig)
  7179. };
  7180. }
  7181. _addAttachmentClass(attachment) {
  7182. this.getTipElement().classList.add(`${CLASS_PREFIX$1}-${this.updateAttachment(attachment)}`);
  7183. }
  7184. _getContainer() {
  7185. if (this.config.container === false) {
  7186. return document.body;
  7187. }
  7188. if (isElement(this.config.container)) {
  7189. return this.config.container;
  7190. }
  7191. return SelectorEngine.findOne(this.config.container);
  7192. }
  7193. _getAttachment(placement) {
  7194. return AttachmentMap[placement.toUpperCase()];
  7195. }
  7196. _setListeners() {
  7197. const triggers = this.config.trigger.split(' ');
  7198. triggers.forEach(trigger => {
  7199. if (trigger === 'click') {
  7200. EventHandler.on(this._element, this.constructor.Event.CLICK, this.config.selector, event => this.toggle(event));
  7201. } else if (trigger !== TRIGGER_MANUAL) {
  7202. const eventIn = trigger === TRIGGER_HOVER ? this.constructor.Event.MOUSEENTER : this.constructor.Event.FOCUSIN;
  7203. const eventOut = trigger === TRIGGER_HOVER ? this.constructor.Event.MOUSELEAVE : this.constructor.Event.FOCUSOUT;
  7204. EventHandler.on(this._element, eventIn, this.config.selector, event => this._enter(event));
  7205. EventHandler.on(this._element, eventOut, this.config.selector, event => this._leave(event));
  7206. }
  7207. });
  7208. this._hideModalHandler = () => {
  7209. if (this._element) {
  7210. this.hide();
  7211. }
  7212. };
  7213. EventHandler.on(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler);
  7214. if (this.config.selector) {
  7215. this.config = { ...this.config,
  7216. trigger: 'manual',
  7217. selector: ''
  7218. };
  7219. } else {
  7220. this._fixTitle();
  7221. }
  7222. }
  7223. _fixTitle() {
  7224. const title = this._element.getAttribute('title');
  7225. const originalTitleType = typeof this._element.getAttribute('data-bs-original-title');
  7226. if (title || originalTitleType !== 'string') {
  7227. this._element.setAttribute('data-bs-original-title', title || '');
  7228. if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
  7229. this._element.setAttribute('aria-label', title);
  7230. }
  7231. this._element.setAttribute('title', '');
  7232. }
  7233. }
  7234. _enter(event, context) {
  7235. context = this._initializeOnDelegatedTarget(event, context);
  7236. if (event) {
  7237. context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true;
  7238. }
  7239. if (context.getTipElement().classList.contains(CLASS_NAME_SHOW$3) || context._hoverState === HOVER_STATE_SHOW) {
  7240. context._hoverState = HOVER_STATE_SHOW;
  7241. return;
  7242. }
  7243. clearTimeout(context._timeout);
  7244. context._hoverState = HOVER_STATE_SHOW;
  7245. if (!context.config.delay || !context.config.delay.show) {
  7246. context.show();
  7247. return;
  7248. }
  7249. context._timeout = setTimeout(() => {
  7250. if (context._hoverState === HOVER_STATE_SHOW) {
  7251. context.show();
  7252. }
  7253. }, context.config.delay.show);
  7254. }
  7255. _leave(event, context) {
  7256. context = this._initializeOnDelegatedTarget(event, context);
  7257. if (event) {
  7258. context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = context._element.contains(event.relatedTarget);
  7259. }
  7260. if (context._isWithActiveTrigger()) {
  7261. return;
  7262. }
  7263. clearTimeout(context._timeout);
  7264. context._hoverState = HOVER_STATE_OUT;
  7265. if (!context.config.delay || !context.config.delay.hide) {
  7266. context.hide();
  7267. return;
  7268. }
  7269. context._timeout = setTimeout(() => {
  7270. if (context._hoverState === HOVER_STATE_OUT) {
  7271. context.hide();
  7272. }
  7273. }, context.config.delay.hide);
  7274. }
  7275. _isWithActiveTrigger() {
  7276. for (const trigger in this._activeTrigger) {
  7277. if (this._activeTrigger[trigger]) {
  7278. return true;
  7279. }
  7280. }
  7281. return false;
  7282. }
  7283. _getConfig(config) {
  7284. const dataAttributes = Manipulator.getDataAttributes(this._element);
  7285. Object.keys(dataAttributes).forEach(dataAttr => {
  7286. if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
  7287. delete dataAttributes[dataAttr];
  7288. }
  7289. });
  7290. if (config && typeof config.container === 'object' && config.container.jquery) {
  7291. config.container = config.container[0];
  7292. }
  7293. config = { ...this.constructor.Default,
  7294. ...dataAttributes,
  7295. ...(typeof config === 'object' && config ? config : {})
  7296. };
  7297. if (typeof config.delay === 'number') {
  7298. config.delay = {
  7299. show: config.delay,
  7300. hide: config.delay
  7301. };
  7302. }
  7303. if (typeof config.title === 'number') {
  7304. config.title = config.title.toString();
  7305. }
  7306. if (typeof config.content === 'number') {
  7307. config.content = config.content.toString();
  7308. }
  7309. typeCheckConfig(NAME$4, config, this.constructor.DefaultType);
  7310. if (config.sanitize) {
  7311. config.template = sanitizeHtml(config.template, config.allowList, config.sanitizeFn);
  7312. }
  7313. return config;
  7314. }
  7315. _getDelegateConfig() {
  7316. const config = {};
  7317. if (this.config) {
  7318. for (const key in this.config) {
  7319. if (this.constructor.Default[key] !== this.config[key]) {
  7320. config[key] = this.config[key];
  7321. }
  7322. }
  7323. }
  7324. return config;
  7325. }
  7326. _cleanTipClass() {
  7327. const tip = this.getTipElement();
  7328. const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX$1);
  7329. if (tabClass !== null && tabClass.length > 0) {
  7330. tabClass.map(token => token.trim()).forEach(tClass => tip.classList.remove(tClass));
  7331. }
  7332. }
  7333. _handlePopperPlacementChange(popperData) {
  7334. const {
  7335. state
  7336. } = popperData;
  7337. if (!state) {
  7338. return;
  7339. }
  7340. this.tip = state.elements.popper;
  7341. this._cleanTipClass();
  7342. this._addAttachmentClass(this._getAttachment(state.placement));
  7343. }
  7344. static jQueryInterface(config) {
  7345. return this.each(function () {
  7346. let data = Data.get(this, DATA_KEY$4);
  7347. const _config = typeof config === 'object' && config;
  7348. if (!data && /dispose|hide/.test(config)) {
  7349. return;
  7350. }
  7351. if (!data) {
  7352. data = new Tooltip(this, _config);
  7353. }
  7354. if (typeof config === 'string') {
  7355. if (typeof data[config] === 'undefined') {
  7356. throw new TypeError(`No method named "${config}"`);
  7357. }
  7358. data[config]();
  7359. }
  7360. });
  7361. }
  7362. }
  7363. defineJQueryPlugin(NAME$4, Tooltip);
  7364. const NAME$3 = 'popover';
  7365. const DATA_KEY$3 = 'bs.popover';
  7366. const EVENT_KEY$3 = `.${DATA_KEY$3}`;
  7367. const CLASS_PREFIX = 'bs-popover';
  7368. const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g');
  7369. const Default$2 = { ...Tooltip.Default,
  7370. placement: 'right',
  7371. offset: [0, 8],
  7372. trigger: 'click',
  7373. content: '',
  7374. template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div>' + '</div>'
  7375. };
  7376. const DefaultType$2 = { ...Tooltip.DefaultType,
  7377. content: '(string|element|function)'
  7378. };
  7379. const Event$1 = {
  7380. HIDE: `hide${EVENT_KEY$3}`,
  7381. HIDDEN: `hidden${EVENT_KEY$3}`,
  7382. SHOW: `show${EVENT_KEY$3}`,
  7383. SHOWN: `shown${EVENT_KEY$3}`,
  7384. INSERTED: `inserted${EVENT_KEY$3}`,
  7385. CLICK: `click${EVENT_KEY$3}`,
  7386. FOCUSIN: `focusin${EVENT_KEY$3}`,
  7387. FOCUSOUT: `focusout${EVENT_KEY$3}`,
  7388. MOUSEENTER: `mouseenter${EVENT_KEY$3}`,
  7389. MOUSELEAVE: `mouseleave${EVENT_KEY$3}`
  7390. };
  7391. const CLASS_NAME_FADE$2 = 'fade';
  7392. const CLASS_NAME_SHOW$2 = 'show';
  7393. const SELECTOR_TITLE = '.popover-header';
  7394. const SELECTOR_CONTENT = '.popover-body';
  7395. class Popover extends Tooltip {
  7396. static get Default() {
  7397. return Default$2;
  7398. }
  7399. static get NAME() {
  7400. return NAME$3;
  7401. }
  7402. static get DATA_KEY() {
  7403. return DATA_KEY$3;
  7404. }
  7405. static get Event() {
  7406. return Event$1;
  7407. }
  7408. static get EVENT_KEY() {
  7409. return EVENT_KEY$3;
  7410. }
  7411. static get DefaultType() {
  7412. return DefaultType$2;
  7413. }
  7414. isWithContent() {
  7415. return this.getTitle() || this._getContent();
  7416. }
  7417. setContent() {
  7418. const tip = this.getTipElement();
  7419. this.setElementContent(SelectorEngine.findOne(SELECTOR_TITLE, tip), this.getTitle());
  7420. let content = this._getContent();
  7421. if (typeof content === 'function') {
  7422. content = content.call(this._element);
  7423. }
  7424. this.setElementContent(SelectorEngine.findOne(SELECTOR_CONTENT, tip), content);
  7425. tip.classList.remove(CLASS_NAME_FADE$2, CLASS_NAME_SHOW$2);
  7426. }
  7427. _addAttachmentClass(attachment) {
  7428. this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`);
  7429. }
  7430. _getContent() {
  7431. return this._element.getAttribute('data-bs-content') || this.config.content;
  7432. }
  7433. _cleanTipClass() {
  7434. const tip = this.getTipElement();
  7435. const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX);
  7436. if (tabClass !== null && tabClass.length > 0) {
  7437. tabClass.map(token => token.trim()).forEach(tClass => tip.classList.remove(tClass));
  7438. }
  7439. }
  7440. static jQueryInterface(config) {
  7441. return this.each(function () {
  7442. let data = Data.get(this, DATA_KEY$3);
  7443. const _config = typeof config === 'object' ? config : null;
  7444. if (!data && /dispose|hide/.test(config)) {
  7445. return;
  7446. }
  7447. if (!data) {
  7448. data = new Popover(this, _config);
  7449. Data.set(this, DATA_KEY$3, data);
  7450. }
  7451. if (typeof config === 'string') {
  7452. if (typeof data[config] === 'undefined') {
  7453. throw new TypeError(`No method named "${config}"`);
  7454. }
  7455. data[config]();
  7456. }
  7457. });
  7458. }
  7459. }
  7460. defineJQueryPlugin(NAME$3, Popover);
  7461. const NAME$2 = 'scrollspy';
  7462. const DATA_KEY$2 = 'bs.scrollspy';
  7463. const EVENT_KEY$2 = `.${DATA_KEY$2}`;
  7464. const DATA_API_KEY$1 = '.data-api';
  7465. const Default$1 = {
  7466. offset: 10,
  7467. method: 'auto',
  7468. target: ''
  7469. };
  7470. const DefaultType$1 = {
  7471. offset: 'number',
  7472. method: 'string',
  7473. target: '(string|element)'
  7474. };
  7475. const EVENT_ACTIVATE = `activate${EVENT_KEY$2}`;
  7476. const EVENT_SCROLL = `scroll${EVENT_KEY$2}`;
  7477. const EVENT_LOAD_DATA_API = `load${EVENT_KEY$2}${DATA_API_KEY$1}`;
  7478. const CLASS_NAME_DROPDOWN_ITEM = 'dropdown-item';
  7479. const CLASS_NAME_ACTIVE$1 = 'active';
  7480. const SELECTOR_DATA_SPY = '[data-bs-spy="scroll"]';
  7481. const SELECTOR_NAV_LIST_GROUP$1 = '.nav, .list-group';
  7482. const SELECTOR_NAV_LINKS = '.nav-link';
  7483. const SELECTOR_NAV_ITEMS = '.nav-item';
  7484. const SELECTOR_LIST_ITEMS = '.list-group-item';
  7485. const SELECTOR_DROPDOWN$1 = '.dropdown';
  7486. const SELECTOR_DROPDOWN_TOGGLE$1 = '.dropdown-toggle';
  7487. const METHOD_OFFSET = 'offset';
  7488. const METHOD_POSITION = 'position';
  7489. class ScrollSpy extends BaseComponent {
  7490. constructor(element, config) {
  7491. super(element);
  7492. this._scrollElement = this._element.tagName === 'BODY' ? window : this._element;
  7493. this._config = this._getConfig(config);
  7494. this._selector = `${this._config.target} ${SELECTOR_NAV_LINKS}, ${this._config.target} ${SELECTOR_LIST_ITEMS}, ${this._config.target} .${CLASS_NAME_DROPDOWN_ITEM}`;
  7495. this._offsets = [];
  7496. this._targets = [];
  7497. this._activeTarget = null;
  7498. this._scrollHeight = 0;
  7499. EventHandler.on(this._scrollElement, EVENT_SCROLL, () => this._process());
  7500. this.refresh();
  7501. this._process();
  7502. }
  7503. static get Default() {
  7504. return Default$1;
  7505. }
  7506. static get DATA_KEY() {
  7507. return DATA_KEY$2;
  7508. }
  7509. refresh() {
  7510. const autoMethod = this._scrollElement === this._scrollElement.window ? METHOD_OFFSET : METHOD_POSITION;
  7511. const offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method;
  7512. const offsetBase = offsetMethod === METHOD_POSITION ? this._getScrollTop() : 0;
  7513. this._offsets = [];
  7514. this._targets = [];
  7515. this._scrollHeight = this._getScrollHeight();
  7516. const targets = SelectorEngine.find(this._selector);
  7517. targets.map(element => {
  7518. const targetSelector = getSelectorFromElement(element);
  7519. const target = targetSelector ? SelectorEngine.findOne(targetSelector) : null;
  7520. if (target) {
  7521. const targetBCR = target.getBoundingClientRect();
  7522. if (targetBCR.width || targetBCR.height) {
  7523. return [Manipulator[offsetMethod](target).top + offsetBase, targetSelector];
  7524. }
  7525. }
  7526. return null;
  7527. }).filter(item => item).sort((a, b) => a[0] - b[0]).forEach(item => {
  7528. this._offsets.push(item[0]);
  7529. this._targets.push(item[1]);
  7530. });
  7531. }
  7532. dispose() {
  7533. super.dispose();
  7534. EventHandler.off(this._scrollElement, EVENT_KEY$2);
  7535. this._scrollElement = null;
  7536. this._config = null;
  7537. this._selector = null;
  7538. this._offsets = null;
  7539. this._targets = null;
  7540. this._activeTarget = null;
  7541. this._scrollHeight = null;
  7542. }
  7543. _getConfig(config) {
  7544. config = { ...Default$1,
  7545. ...(typeof config === 'object' && config ? config : {})
  7546. };
  7547. if (typeof config.target !== 'string' && isElement(config.target)) {
  7548. let {
  7549. id
  7550. } = config.target;
  7551. if (!id) {
  7552. id = getUID(NAME$2);
  7553. config.target.id = id;
  7554. }
  7555. config.target = `#${id}`;
  7556. }
  7557. typeCheckConfig(NAME$2, config, DefaultType$1);
  7558. return config;
  7559. }
  7560. _getScrollTop() {
  7561. return this._scrollElement === window ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop;
  7562. }
  7563. _getScrollHeight() {
  7564. return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  7565. }
  7566. _getOffsetHeight() {
  7567. return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height;
  7568. }
  7569. _process() {
  7570. const scrollTop = this._getScrollTop() + this._config.offset;
  7571. const scrollHeight = this._getScrollHeight();
  7572. const maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight();
  7573. if (this._scrollHeight !== scrollHeight) {
  7574. this.refresh();
  7575. }
  7576. if (scrollTop >= maxScroll) {
  7577. const target = this._targets[this._targets.length - 1];
  7578. if (this._activeTarget !== target) {
  7579. this._activate(target);
  7580. }
  7581. return;
  7582. }
  7583. if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) {
  7584. this._activeTarget = null;
  7585. this._clear();
  7586. return;
  7587. }
  7588. for (let i = this._offsets.length; i--;) {
  7589. const isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]);
  7590. if (isActiveTarget) {
  7591. this._activate(this._targets[i]);
  7592. }
  7593. }
  7594. }
  7595. _activate(target) {
  7596. this._activeTarget = target;
  7597. this._clear();
  7598. const queries = this._selector.split(',').map(selector => `${selector}[data-bs-target="${target}"],${selector}[href="${target}"]`);
  7599. const link = SelectorEngine.findOne(queries.join(','));
  7600. if (link.classList.contains(CLASS_NAME_DROPDOWN_ITEM)) {
  7601. SelectorEngine.findOne(SELECTOR_DROPDOWN_TOGGLE$1, link.closest(SELECTOR_DROPDOWN$1)).classList.add(CLASS_NAME_ACTIVE$1);
  7602. link.classList.add(CLASS_NAME_ACTIVE$1);
  7603. } else {
  7604. link.classList.add(CLASS_NAME_ACTIVE$1);
  7605. SelectorEngine.parents(link, SELECTOR_NAV_LIST_GROUP$1).forEach(listGroup => {
  7606. SelectorEngine.prev(listGroup, `${SELECTOR_NAV_LINKS}, ${SELECTOR_LIST_ITEMS}`).forEach(item => item.classList.add(CLASS_NAME_ACTIVE$1));
  7607. SelectorEngine.prev(listGroup, SELECTOR_NAV_ITEMS).forEach(navItem => {
  7608. SelectorEngine.children(navItem, SELECTOR_NAV_LINKS).forEach(item => item.classList.add(CLASS_NAME_ACTIVE$1));
  7609. });
  7610. });
  7611. }
  7612. EventHandler.trigger(this._scrollElement, EVENT_ACTIVATE, {
  7613. relatedTarget: target
  7614. });
  7615. }
  7616. _clear() {
  7617. SelectorEngine.find(this._selector).filter(node => node.classList.contains(CLASS_NAME_ACTIVE$1)).forEach(node => node.classList.remove(CLASS_NAME_ACTIVE$1));
  7618. }
  7619. static jQueryInterface(config) {
  7620. return this.each(function () {
  7621. let data = Data.get(this, DATA_KEY$2);
  7622. const _config = typeof config === 'object' && config;
  7623. if (!data) {
  7624. data = new ScrollSpy(this, _config);
  7625. }
  7626. if (typeof config === 'string') {
  7627. if (typeof data[config] === 'undefined') {
  7628. throw new TypeError(`No method named "${config}"`);
  7629. }
  7630. data[config]();
  7631. }
  7632. });
  7633. }
  7634. }
  7635. EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
  7636. SelectorEngine.find(SELECTOR_DATA_SPY).forEach(spy => new ScrollSpy(spy, Manipulator.getDataAttributes(spy)));
  7637. });
  7638. defineJQueryPlugin(NAME$2, ScrollSpy);
  7639. const NAME$1 = 'tab';
  7640. const DATA_KEY$1 = 'bs.tab';
  7641. const EVENT_KEY$1 = `.${DATA_KEY$1}`;
  7642. const DATA_API_KEY = '.data-api';
  7643. const EVENT_HIDE$1 = `hide${EVENT_KEY$1}`;
  7644. const EVENT_HIDDEN$1 = `hidden${EVENT_KEY$1}`;
  7645. const EVENT_SHOW$1 = `show${EVENT_KEY$1}`;
  7646. const EVENT_SHOWN$1 = `shown${EVENT_KEY$1}`;
  7647. const EVENT_CLICK_DATA_API = `click${EVENT_KEY$1}${DATA_API_KEY}`;
  7648. const CLASS_NAME_DROPDOWN_MENU = 'dropdown-menu';
  7649. const CLASS_NAME_ACTIVE = 'active';
  7650. const CLASS_NAME_FADE$1 = 'fade';
  7651. const CLASS_NAME_SHOW$1 = 'show';
  7652. const SELECTOR_DROPDOWN = '.dropdown';
  7653. const SELECTOR_NAV_LIST_GROUP = '.nav, .list-group';
  7654. const SELECTOR_ACTIVE = '.active';
  7655. const SELECTOR_ACTIVE_UL = ':scope > li > .active';
  7656. const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="tab"], [data-bs-toggle="pill"], [data-bs-toggle="list"]';
  7657. const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle';
  7658. const SELECTOR_DROPDOWN_ACTIVE_CHILD = ':scope > .dropdown-menu .active';
  7659. class Tab extends BaseComponent {
  7660. static get DATA_KEY() {
  7661. return DATA_KEY$1;
  7662. }
  7663. show() {
  7664. if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && this._element.classList.contains(CLASS_NAME_ACTIVE) || isDisabled(this._element)) {
  7665. return;
  7666. }
  7667. let previous;
  7668. const target = getElementFromSelector(this._element);
  7669. const listElement = this._element.closest(SELECTOR_NAV_LIST_GROUP);
  7670. if (listElement) {
  7671. const itemSelector = listElement.nodeName === 'UL' || listElement.nodeName === 'OL' ? SELECTOR_ACTIVE_UL : SELECTOR_ACTIVE;
  7672. previous = SelectorEngine.find(itemSelector, listElement);
  7673. previous = previous[previous.length - 1];
  7674. }
  7675. const hideEvent = previous ? EventHandler.trigger(previous, EVENT_HIDE$1, {
  7676. relatedTarget: this._element
  7677. }) : null;
  7678. const showEvent = EventHandler.trigger(this._element, EVENT_SHOW$1, {
  7679. relatedTarget: previous
  7680. });
  7681. if (showEvent.defaultPrevented || hideEvent !== null && hideEvent.defaultPrevented) {
  7682. return;
  7683. }
  7684. this._activate(this._element, listElement);
  7685. const complete = () => {
  7686. EventHandler.trigger(previous, EVENT_HIDDEN$1, {
  7687. relatedTarget: this._element
  7688. });
  7689. EventHandler.trigger(this._element, EVENT_SHOWN$1, {
  7690. relatedTarget: previous
  7691. });
  7692. };
  7693. if (target) {
  7694. this._activate(target, target.parentNode, complete);
  7695. } else {
  7696. complete();
  7697. }
  7698. }
  7699. _activate(element, container, callback) {
  7700. const activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ? SelectorEngine.find(SELECTOR_ACTIVE_UL, container) : SelectorEngine.children(container, SELECTOR_ACTIVE);
  7701. const active = activeElements[0];
  7702. const isTransitioning = callback && active && active.classList.contains(CLASS_NAME_FADE$1);
  7703. const complete = () => this._transitionComplete(element, active, callback);
  7704. if (active && isTransitioning) {
  7705. const transitionDuration = getTransitionDurationFromElement(active);
  7706. active.classList.remove(CLASS_NAME_SHOW$1);
  7707. EventHandler.one(active, 'transitionend', complete);
  7708. emulateTransitionEnd(active, transitionDuration);
  7709. } else {
  7710. complete();
  7711. }
  7712. }
  7713. _transitionComplete(element, active, callback) {
  7714. if (active) {
  7715. active.classList.remove(CLASS_NAME_ACTIVE);
  7716. const dropdownChild = SelectorEngine.findOne(SELECTOR_DROPDOWN_ACTIVE_CHILD, active.parentNode);
  7717. if (dropdownChild) {
  7718. dropdownChild.classList.remove(CLASS_NAME_ACTIVE);
  7719. }
  7720. if (active.getAttribute('role') === 'tab') {
  7721. active.setAttribute('aria-selected', false);
  7722. }
  7723. }
  7724. element.classList.add(CLASS_NAME_ACTIVE);
  7725. if (element.getAttribute('role') === 'tab') {
  7726. element.setAttribute('aria-selected', true);
  7727. }
  7728. reflow(element);
  7729. if (element.classList.contains(CLASS_NAME_FADE$1)) {
  7730. element.classList.add(CLASS_NAME_SHOW$1);
  7731. }
  7732. if (element.parentNode && element.parentNode.classList.contains(CLASS_NAME_DROPDOWN_MENU)) {
  7733. const dropdownElement = element.closest(SELECTOR_DROPDOWN);
  7734. if (dropdownElement) {
  7735. SelectorEngine.find(SELECTOR_DROPDOWN_TOGGLE).forEach(dropdown => dropdown.classList.add(CLASS_NAME_ACTIVE));
  7736. }
  7737. element.setAttribute('aria-expanded', true);
  7738. }
  7739. if (callback) {
  7740. callback();
  7741. }
  7742. }
  7743. static jQueryInterface(config) {
  7744. return this.each(function () {
  7745. const data = Data.get(this, DATA_KEY$1) || new Tab(this);
  7746. if (typeof config === 'string') {
  7747. if (typeof data[config] === 'undefined') {
  7748. throw new TypeError(`No method named "${config}"`);
  7749. }
  7750. data[config]();
  7751. }
  7752. });
  7753. }
  7754. }
  7755. EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
  7756. event.preventDefault();
  7757. const data = Data.get(this, DATA_KEY$1) || new Tab(this);
  7758. data.show();
  7759. });
  7760. defineJQueryPlugin(NAME$1, Tab);
  7761. const NAME = 'toast';
  7762. const DATA_KEY = 'bs.toast';
  7763. const EVENT_KEY = `.${DATA_KEY}`;
  7764. const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`;
  7765. const EVENT_HIDE = `hide${EVENT_KEY}`;
  7766. const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
  7767. const EVENT_SHOW = `show${EVENT_KEY}`;
  7768. const EVENT_SHOWN = `shown${EVENT_KEY}`;
  7769. const CLASS_NAME_FADE = 'fade';
  7770. const CLASS_NAME_HIDE = 'hide';
  7771. const CLASS_NAME_SHOW = 'show';
  7772. const CLASS_NAME_SHOWING = 'showing';
  7773. const DefaultType = {
  7774. animation: 'boolean',
  7775. autohide: 'boolean',
  7776. delay: 'number'
  7777. };
  7778. const Default = {
  7779. animation: true,
  7780. autohide: true,
  7781. delay: 5000
  7782. };
  7783. const SELECTOR_DATA_DISMISS = '[data-bs-dismiss="toast"]';
  7784. class Toast extends BaseComponent {
  7785. constructor(element, config) {
  7786. super(element);
  7787. this._config = this._getConfig(config);
  7788. this._timeout = null;
  7789. this._setListeners();
  7790. }
  7791. static get DefaultType() {
  7792. return DefaultType;
  7793. }
  7794. static get Default() {
  7795. return Default;
  7796. }
  7797. static get DATA_KEY() {
  7798. return DATA_KEY;
  7799. }
  7800. show() {
  7801. const showEvent = EventHandler.trigger(this._element, EVENT_SHOW);
  7802. if (showEvent.defaultPrevented) {
  7803. return;
  7804. }
  7805. this._clearTimeout();
  7806. if (this._config.animation) {
  7807. this._element.classList.add(CLASS_NAME_FADE);
  7808. }
  7809. const complete = () => {
  7810. this._element.classList.remove(CLASS_NAME_SHOWING);
  7811. this._element.classList.add(CLASS_NAME_SHOW);
  7812. EventHandler.trigger(this._element, EVENT_SHOWN);
  7813. if (this._config.autohide) {
  7814. this._timeout = setTimeout(() => {
  7815. this.hide();
  7816. }, this._config.delay);
  7817. }
  7818. };
  7819. this._element.classList.remove(CLASS_NAME_HIDE);
  7820. reflow(this._element);
  7821. this._element.classList.add(CLASS_NAME_SHOWING);
  7822. if (this._config.animation) {
  7823. const transitionDuration = getTransitionDurationFromElement(this._element);
  7824. EventHandler.one(this._element, 'transitionend', complete);
  7825. emulateTransitionEnd(this._element, transitionDuration);
  7826. } else {
  7827. complete();
  7828. }
  7829. }
  7830. hide() {
  7831. if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
  7832. return;
  7833. }
  7834. const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE);
  7835. if (hideEvent.defaultPrevented) {
  7836. return;
  7837. }
  7838. const complete = () => {
  7839. this._element.classList.add(CLASS_NAME_HIDE);
  7840. EventHandler.trigger(this._element, EVENT_HIDDEN);
  7841. };
  7842. this._element.classList.remove(CLASS_NAME_SHOW);
  7843. if (this._config.animation) {
  7844. const transitionDuration = getTransitionDurationFromElement(this._element);
  7845. EventHandler.one(this._element, 'transitionend', complete);
  7846. emulateTransitionEnd(this._element, transitionDuration);
  7847. } else {
  7848. complete();
  7849. }
  7850. }
  7851. dispose() {
  7852. this._clearTimeout();
  7853. if (this._element.classList.contains(CLASS_NAME_SHOW)) {
  7854. this._element.classList.remove(CLASS_NAME_SHOW);
  7855. }
  7856. EventHandler.off(this._element, EVENT_CLICK_DISMISS);
  7857. super.dispose();
  7858. this._config = null;
  7859. }
  7860. _getConfig(config) {
  7861. config = { ...Default,
  7862. ...Manipulator.getDataAttributes(this._element),
  7863. ...(typeof config === 'object' && config ? config : {})
  7864. };
  7865. typeCheckConfig(NAME, config, this.constructor.DefaultType);
  7866. return config;
  7867. }
  7868. _setListeners() {
  7869. EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, () => this.hide());
  7870. }
  7871. _clearTimeout() {
  7872. clearTimeout(this._timeout);
  7873. this._timeout = null;
  7874. }
  7875. static jQueryInterface(config) {
  7876. return this.each(function () {
  7877. let data = Data.get(this, DATA_KEY);
  7878. const _config = typeof config === 'object' && config;
  7879. if (!data) {
  7880. data = new Toast(this, _config);
  7881. }
  7882. if (typeof config === 'string') {
  7883. if (typeof data[config] === 'undefined') {
  7884. throw new TypeError(`No method named "${config}"`);
  7885. }
  7886. data[config](this);
  7887. }
  7888. });
  7889. }
  7890. }
  7891. defineJQueryPlugin(NAME, Toast);
  7892. var dropdownTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="dropdown"]'));
  7893. dropdownTriggerList.map(function (dropdownTriggerEl) {
  7894. return new Dropdown(dropdownTriggerEl);
  7895. });
  7896. var selectors = '.dropdown, .dropup, .dropend, .dropstart',
  7897. dropdowns = document.querySelectorAll(selectors);
  7898. var currentTarget = undefined;
  7899. dropdowns.forEach(function (dropdown) {
  7900. dropdown.addEventListener('mousedown', function (e) {
  7901. e.stopPropagation();
  7902. if (e.target.dataset.bsToggle && e.target.dataset.bsToggle === 'dropdown') {
  7903. currentTarget = e.currentTarget;
  7904. }
  7905. });
  7906. dropdown.addEventListener('hide.bs.dropdown', function (e) {
  7907. e.stopPropagation();
  7908. var parent = currentTarget ? currentTarget.parentElement.closest(selectors) : undefined;
  7909. if (parent && parent === dropdown) {
  7910. e.preventDefault();
  7911. }
  7912. currentTarget = undefined;
  7913. });
  7914. });
  7915. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
  7916. tooltipTriggerList.map(function (tooltipTriggerEl) {
  7917. var _ref, _tooltipTriggerEl$get;
  7918. var options = {
  7919. delay: {
  7920. show: 50,
  7921. hide: 50
  7922. },
  7923. html: (_ref = tooltipTriggerEl.getAttribute("data-bs-html") === "true") !== null && _ref !== void 0 ? _ref : false,
  7924. placement: (_tooltipTriggerEl$get = tooltipTriggerEl.getAttribute('data-bs-placement')) !== null && _tooltipTriggerEl$get !== void 0 ? _tooltipTriggerEl$get : 'auto'
  7925. };
  7926. return new Tooltip(tooltipTriggerEl, options);
  7927. });
  7928. var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
  7929. popoverTriggerList.map(function (popoverTriggerEl) {
  7930. var _ref, _popoverTriggerEl$get;
  7931. var options = {
  7932. delay: {
  7933. show: 50,
  7934. hide: 50
  7935. },
  7936. html: (_ref = popoverTriggerEl.getAttribute('data-bs-html') === "true") !== null && _ref !== void 0 ? _ref : false,
  7937. placement: (_popoverTriggerEl$get = popoverTriggerEl.getAttribute('data-bs-placement')) !== null && _popoverTriggerEl$get !== void 0 ? _popoverTriggerEl$get : 'auto'
  7938. };
  7939. return new Popover(popoverTriggerEl, options);
  7940. });
  7941. var switchesTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="switch-icon"]'));
  7942. switchesTriggerList.map(function (switchTriggerEl) {
  7943. switchTriggerEl.addEventListener('click', function (e) {
  7944. e.stopPropagation();
  7945. switchTriggerEl.classList.toggle('active');
  7946. });
  7947. });
  7948. var EnableActivationTabsFromLocationHash = function EnableActivationTabsFromLocationHash() {
  7949. var locationHash = window.location.hash;
  7950. if (locationHash) {
  7951. var tabsList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tab"]'));
  7952. var matchedTabs = tabsList.filter(function (tab) {
  7953. return tab.hash === locationHash;
  7954. });
  7955. matchedTabs.map(function (tab) {
  7956. new Tab(tab).show();
  7957. });
  7958. }
  7959. };
  7960. var toastsTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="toast"]'));
  7961. toastsTriggerList.map(function (toastTriggerEl) {
  7962. return new Toast(toastTriggerEl);
  7963. });
  7964. EnableActivationTabsFromLocationHash();
  7965. })));