0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-03 15:24:19 +01:00
Bootstrap/js/dist/dom/polyfill.js.map
2020-09-14 18:12:06 +03:00

1 line
9.4 KiB
Plaintext

{"version":3,"file":"polyfill.js","sources":["../../src/util/index.js","../../src/dom/polyfill.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap (v5.0.0-alpha1): util/index.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst MAX_UID = 1000000\nconst MILLISECONDS_MULTIPLIER = 1000\nconst TRANSITION_END = 'transitionend'\n\n// Shoutout AngusCroll (https://goo.gl/pxwQGp)\nconst toType = obj => {\n if (obj === null || obj === undefined) {\n return `${obj}`\n }\n\n return {}.toString.call(obj).match(/\\s([a-z]+)/i)[1].toLowerCase()\n}\n\n/**\n * --------------------------------------------------------------------------\n * Public Util Api\n * --------------------------------------------------------------------------\n */\n\nconst getUID = prefix => {\n do {\n prefix += Math.floor(Math.random() * MAX_UID)\n } while (document.getElementById(prefix))\n\n return prefix\n}\n\nconst getSelector = element => {\n let selector = element.getAttribute('data-target')\n\n if (!selector || selector === '#') {\n const hrefAttr = element.getAttribute('href')\n\n selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null\n }\n\n return selector\n}\n\nconst getSelectorFromElement = element => {\n const selector = getSelector(element)\n\n if (selector) {\n return document.querySelector(selector) ? selector : null\n }\n\n return null\n}\n\nconst getElementFromSelector = element => {\n const selector = getSelector(element)\n\n return selector ? document.querySelector(selector) : null\n}\n\nconst getTransitionDurationFromElement = element => {\n if (!element) {\n return 0\n }\n\n // Get transition-duration of the element\n let {\n transitionDuration,\n transitionDelay\n } = window.getComputedStyle(element)\n\n const floatTransitionDuration = parseFloat(transitionDuration)\n const floatTransitionDelay = parseFloat(transitionDelay)\n\n // Return 0 if element or transition duration is not found\n if (!floatTransitionDuration && !floatTransitionDelay) {\n return 0\n }\n\n // If multiple durations are defined, take the first\n transitionDuration = transitionDuration.split(',')[0]\n transitionDelay = transitionDelay.split(',')[0]\n\n return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER\n}\n\nconst triggerTransitionEnd = element => {\n element.dispatchEvent(new Event(TRANSITION_END))\n}\n\nconst isElement = obj => (obj[0] || obj).nodeType\n\nconst emulateTransitionEnd = (element, duration) => {\n let called = false\n const durationPadding = 5\n const emulatedDuration = duration + durationPadding\n function listener() {\n called = true\n element.removeEventListener(TRANSITION_END, listener)\n }\n\n element.addEventListener(TRANSITION_END, listener)\n setTimeout(() => {\n if (!called) {\n triggerTransitionEnd(element)\n }\n }, emulatedDuration)\n}\n\nconst typeCheckConfig = (componentName, config, configTypes) => {\n Object.keys(configTypes).forEach(property => {\n const expectedTypes = configTypes[property]\n const value = config[property]\n const valueType = value && isElement(value) ?\n 'element' :\n toType(value)\n\n if (!new RegExp(expectedTypes).test(valueType)) {\n throw new Error(\n `${componentName.toUpperCase()}: ` +\n `Option \"${property}\" provided type \"${valueType}\" ` +\n `but expected type \"${expectedTypes}\".`)\n }\n })\n}\n\nconst isVisible = element => {\n if (!element) {\n return false\n }\n\n if (element.style && element.parentNode && element.parentNode.style) {\n const elementStyle = getComputedStyle(element)\n const parentNodeStyle = getComputedStyle(element.parentNode)\n\n return elementStyle.display !== 'none' &&\n parentNodeStyle.display !== 'none' &&\n elementStyle.visibility !== 'hidden'\n }\n\n return false\n}\n\nconst findShadowRoot = element => {\n if (!document.documentElement.attachShadow) {\n return null\n }\n\n // Can find the shadow root otherwise it'll return the document\n if (typeof element.getRootNode === 'function') {\n const root = element.getRootNode()\n return root instanceof ShadowRoot ? root : null\n }\n\n if (element instanceof ShadowRoot) {\n return element\n }\n\n // when we don't find a shadow root\n if (!element.parentNode) {\n return null\n }\n\n return findShadowRoot(element.parentNode)\n}\n\nconst noop = () => function () {}\n\nconst reflow = element => element.offsetHeight\n\nconst getjQuery = () => {\n const { jQuery } = window\n\n if (jQuery && !document.body.hasAttribute('data-no-jquery')) {\n return jQuery\n }\n\n return null\n}\n\nexport {\n getjQuery,\n TRANSITION_END,\n getUID,\n getSelectorFromElement,\n getElementFromSelector,\n getTransitionDurationFromElement,\n triggerTransitionEnd,\n isElement,\n emulateTransitionEnd,\n typeCheckConfig,\n isVisible,\n findShadowRoot,\n noop,\n reflow\n}\n","/* istanbul ignore file */\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v5.0.0-alpha1): dom/polyfill.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport { getUID } from '../util/index'\n\nlet find = Element.prototype.querySelectorAll\nlet findOne = Element.prototype.querySelector\n\n// MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached\nconst defaultPreventedPreservedOnDispatch = (() => {\n const e = new CustomEvent('Bootstrap', {\n cancelable: true\n })\n\n const element = document.createElement('div')\n element.addEventListener('Bootstrap', () => null)\n\n e.preventDefault()\n element.dispatchEvent(e)\n return e.defaultPrevented\n})()\n\nconst scopeSelectorRegex = /:scope\\b/\nconst supportScopeQuery = (() => {\n const element = document.createElement('div')\n\n try {\n element.querySelectorAll(':scope *')\n } catch (_) {\n return false\n }\n\n return true\n})()\n\nif (!supportScopeQuery) {\n find = function (selector) {\n if (!scopeSelectorRegex.test(selector)) {\n return this.querySelectorAll(selector)\n }\n\n const hasId = Boolean(this.id)\n\n if (!hasId) {\n this.id = getUID('scope')\n }\n\n let nodeList = null\n try {\n selector = selector.replace(scopeSelectorRegex, `#${this.id}`)\n nodeList = this.querySelectorAll(selector)\n } finally {\n if (!hasId) {\n this.removeAttribute('id')\n }\n }\n\n return nodeList\n }\n\n findOne = function (selector) {\n if (!scopeSelectorRegex.test(selector)) {\n return this.querySelector(selector)\n }\n\n const matches = find.call(this, selector)\n\n if (typeof matches[0] !== 'undefined') {\n return matches[0]\n }\n\n return null\n }\n}\n\nexport {\n find,\n findOne,\n defaultPreventedPreservedOnDispatch\n}\n"],"names":["MAX_UID","getUID","prefix","Math","floor","random","document","getElementById","find","Element","prototype","querySelectorAll","findOne","querySelector","defaultPreventedPreservedOnDispatch","e","CustomEvent","cancelable","element","createElement","addEventListener","preventDefault","dispatchEvent","defaultPrevented","scopeSelectorRegex","supportScopeQuery","_","selector","test","hasId","Boolean","id","nodeList","replace","removeAttribute","matches","call"],"mappings":";;;;;;;;;;;EAAA;;;;;;EAOA,IAAMA,OAAO,GAAG,OAAhB;EAaA;;;;;;;EAMA,IAAMC,MAAM,GAAG,SAATA,MAAS,CAAAC,MAAM,EAAI;EACvB,KAAG;EACDA,IAAAA,MAAM,IAAIC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,MAAL,KAAgBL,OAA3B,CAAV;EACD,GAFD,QAESM,QAAQ,CAACC,cAAT,CAAwBL,MAAxB,CAFT;;EAIA,SAAOA,MAAP;EACD,CAND;;EC1BA;AAWIM,cAAI,GAAGC,OAAO,CAACC,SAAR,CAAkBC;AACzBC,iBAAO,GAAGH,OAAO,CAACC,SAAR,CAAkBG;;MAG1BC,mCAAmC,GAAI,YAAM;EACjD,MAAMC,CAAC,GAAG,IAAIC,WAAJ,CAAgB,WAAhB,EAA6B;EACrCC,IAAAA,UAAU,EAAE;EADyB,GAA7B,CAAV;EAIA,MAAMC,OAAO,GAAGZ,QAAQ,CAACa,aAAT,CAAuB,KAAvB,CAAhB;EACAD,EAAAA,OAAO,CAACE,gBAAR,CAAyB,WAAzB,EAAsC;EAAA,WAAM,IAAN;EAAA,GAAtC;EAEAL,EAAAA,CAAC,CAACM,cAAF;EACAH,EAAAA,OAAO,CAACI,aAAR,CAAsBP,CAAtB;EACA,SAAOA,CAAC,CAACQ,gBAAT;EACD,CAX2C;;EAa5C,IAAMC,kBAAkB,GAAG,UAA3B;;EACA,IAAMC,iBAAiB,GAAI,YAAM;EAC/B,MAAMP,OAAO,GAAGZ,QAAQ,CAACa,aAAT,CAAuB,KAAvB,CAAhB;;EAEA,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