{"version":3,"file":"bs-stepper.min.js","sources":["../../src/js/polyfill.js","../../src/js/util.js","../../src/js/listeners.js","../../src/js/index.js"],"sourcesContent":["let matches = window.Element.prototype.matches\nlet closest = (element, selector) => element.closest(selector)\nlet WinEvent = (inType, params) => new window.Event(inType, params)\n\n/* istanbul ignore next */\nfunction polyfill () {\n if (!window.Element.prototype.matches) {\n matches = window.Element.prototype.msMatchesSelector ||\n window.Element.prototype.webkitMatchesSelector\n }\n\n if (!window.Element.prototype.closest) {\n closest = (element, selector) => {\n if (!document.documentElement.contains(element)) {\n return null\n }\n\n do {\n if (matches.call(element, selector)) {\n return element\n }\n\n element = element.parentElement || element.parentNode\n } while (element !== null && element.nodeType === 1)\n\n return null\n }\n }\n\n if (!window.Event || typeof window.Event !== 'function') {\n WinEvent = (inType, params) => {\n params = params || {}\n const e = document.createEvent('Event')\n e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable))\n return e\n }\n }\n}\n\npolyfill()\n\nexport {\n closest,\n WinEvent\n}\n","import { WinEvent, closest } from './polyfill'\r\n\r\nconst MILLISECONDS_MULTIPLIER = 1000\r\nconst Selectors = {\r\n STEPS: '.step',\r\n TRIGGER: '.step-trigger, a',\r\n STEPPER: '.bs-stepper'\r\n}\r\n\r\nconst ClassName = {\r\n ACTIVE: 'active',\r\n LINEAR: 'linear',\r\n BLOCK: 'dstepper-block',\r\n NONE: 'dstepper-none',\r\n FADE: 'fade'\r\n}\r\n\r\nconst transitionEndEvent = 'transitionend'\r\nconst customProperty = 'bsStepper'\r\n\r\nconst showStep = (step, stepList) => {\r\n if (step.classList.contains(ClassName.ACTIVE)) {\r\n return\r\n }\r\n\r\n const stepperNode = closest(step, Selectors.STEPPER)\r\n const activeStep = stepList.filter(step => step.classList.contains(ClassName.ACTIVE))\r\n if (activeStep.length) {\r\n activeStep[0].classList.remove(ClassName.ACTIVE)\r\n }\r\n stepList.forEach(step => {\r\n const trigger = step.querySelector(Selectors.TRIGGER)\r\n trigger.setAttribute('aria-selected', 'false')\r\n // if stepper is in linear mode, set disabled attribute on the trigger\r\n if (stepperNode.classList.contains(ClassName.LINEAR)) {\r\n trigger.setAttribute('disabled', 'disabled')\r\n }\r\n })\r\n\r\n step.classList.add(ClassName.ACTIVE)\r\n const currentTrigger = step.querySelector(Selectors.TRIGGER)\r\n currentTrigger.setAttribute('aria-selected', 'true')\r\n // if stepper is in linear mode, remove disabled attribute on current\r\n if (stepperNode.classList.contains(ClassName.LINEAR)) {\r\n currentTrigger.removeAttribute('disabled')\r\n }\r\n}\r\n\r\nconst showContent = (content, contentList) => {\r\n if (content.classList.contains(ClassName.ACTIVE)) {\r\n return\r\n }\r\n\r\n function complete () {\r\n content.classList.add(ClassName.BLOCK)\r\n content.removeEventListener(transitionEndEvent, complete)\r\n }\r\n\r\n const activeContent = contentList.filter(content => content.classList.contains(ClassName.ACTIVE))\r\n if (activeContent.length) {\r\n activeContent[0].classList.remove(ClassName.ACTIVE)\r\n activeContent[0].classList.remove(ClassName.BLOCK)\r\n }\r\n\r\n if (content.classList.contains(ClassName.FADE)) {\r\n content.classList.remove(ClassName.NONE)\r\n const duration = getTransitionDurationFromElement(content)\r\n content.addEventListener(transitionEndEvent, complete)\r\n if (activeContent.length) {\r\n activeContent[0].classList.add(ClassName.NONE)\r\n }\r\n\r\n content.classList.add(ClassName.ACTIVE)\r\n emulateTransitionEnd(content, duration)\r\n } else {\r\n content.classList.add(ClassName.ACTIVE)\r\n }\r\n}\r\n\r\nconst getTransitionDurationFromElement = element => {\r\n if (!element) {\r\n return 0\r\n }\r\n\r\n // Get transition-duration of the element\r\n let transitionDuration = window.getComputedStyle(element).transitionDuration\r\n const floatTransitionDuration = parseFloat(transitionDuration)\r\n\r\n // Return 0 if element or transition duration is not found\r\n if (!floatTransitionDuration) {\r\n return 0\r\n }\r\n\r\n // If multiple durations are defined, take the first\r\n transitionDuration = transitionDuration.split(',')[0]\r\n\r\n return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER\r\n}\r\n\r\nconst emulateTransitionEnd = (element, duration) => {\r\n let called = false\r\n const durationPadding = 5\r\n const emulatedDuration = duration + durationPadding\r\n function listener () {\r\n called = true\r\n element.removeEventListener(transitionEndEvent, listener)\r\n }\r\n\r\n element.addEventListener(transitionEndEvent, listener)\r\n window.setTimeout(() => {\r\n if (!called) {\r\n element.dispatchEvent(WinEvent(transitionEndEvent))\r\n }\r\n\r\n element.removeEventListener(transitionEndEvent, listener)\r\n }, emulatedDuration)\r\n}\r\n\r\nconst detectAnimation = (contentList, animation) => {\r\n if (animation) {\r\n contentList.forEach(content => {\r\n content.classList.add(ClassName.FADE)\r\n content.classList.add(ClassName.NONE)\r\n })\r\n }\r\n}\r\n\r\nexport {\r\n showContent,\r\n showStep,\r\n Selectors,\r\n ClassName,\r\n customProperty,\r\n detectAnimation\r\n}\r\n","import { closest } from './polyfill'\nimport { Selectors, customProperty, showStep, showContent } from './util'\n\nfunction clickStepLinearListener (event) {\n event.preventDefault()\n}\n\nfunction clickStepNonLinearListener (event) {\n event.preventDefault()\n\n const step = closest(event.target, Selectors.STEPS)\n const stepperNode = closest(step, Selectors.STEPPER)\n const stepper = stepperNode[customProperty]\n\n const stepIndex = stepper._steps.indexOf(step)\n stepper._currentIndex = stepIndex\n showStep(step, stepper._steps)\n showContent(stepper._stepsContents[stepIndex], stepper._stepsContents)\n}\n\nexport {\n clickStepLinearListener,\n clickStepNonLinearListener\n}\n","import { showContent, showStep, Selectors, ClassName, customProperty, detectAnimation } from './util'\r\nimport { clickStepLinearListener, clickStepNonLinearListener } from './listeners'\r\n\r\nconst DEFAULT_OPTIONS = {\r\n linear: true,\r\n animation: false\r\n}\r\n\r\nclass Stepper {\r\n constructor (element, _options = {}) {\r\n this._element = element\r\n this._currentIndex = 0\r\n this._stepsContents = []\r\n this._steps = [].slice.call(this._element.querySelectorAll(Selectors.STEPS))\r\n .filter(step => step.hasAttribute('data-target'))\r\n\r\n this._steps.forEach(step => {\r\n this._stepsContents.push(\r\n this._element.querySelector(step.getAttribute('data-target'))\r\n )\r\n })\r\n\r\n this.options = {\r\n ...DEFAULT_OPTIONS,\r\n ..._options\r\n }\r\n\r\n if (this.options.linear) {\r\n this._element.classList.add(ClassName.LINEAR)\r\n }\r\n\r\n detectAnimation(this._stepsContents, this.options.animation)\r\n if (this._steps.length) {\r\n showStep(this._steps[this._currentIndex], this._steps)\r\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\r\n }\r\n\r\n this._setLinkListeners()\r\n Object.defineProperty(this._element, customProperty, {\r\n value: this,\r\n writable: true\r\n })\r\n }\r\n\r\n // Private\r\n\r\n _setLinkListeners () {\r\n this._steps.forEach(step => {\r\n const trigger = step.querySelector(Selectors.TRIGGER)\r\n if (this.options.linear) {\r\n trigger.addEventListener('click', clickStepLinearListener)\r\n } else {\r\n trigger.addEventListener('click', clickStepNonLinearListener)\r\n }\r\n })\r\n }\r\n\r\n // Public\r\n\r\n next () {\r\n this._currentIndex = (this._currentIndex + 1) <= this._steps.length - 1 ? this._currentIndex + 1 : (this._steps.length - 1)\r\n\r\n showStep(this._steps[this._currentIndex], this._steps)\r\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\r\n }\r\n\r\n previous () {\r\n this._currentIndex = (this._currentIndex - 1) >= 0 ? this._currentIndex - 1 : 0\r\n\r\n showStep(this._steps[this._currentIndex], this._steps)\r\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\r\n }\r\n\r\n to (stepNumber) {\r\n const tempIndex = stepNumber - 1\r\n this._currentIndex = tempIndex >= 0 && tempIndex < this._steps.length\r\n ? tempIndex\r\n : 0\r\n\r\n showStep(this._steps[this._currentIndex], this._steps)\r\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\r\n }\r\n\r\n reset () {\r\n this._currentIndex = 0\r\n showStep(this._steps[this._currentIndex], this._steps)\r\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\r\n }\r\n\r\n destroy () {\r\n this._steps.forEach(step => {\r\n const trigger = step.querySelector(Selectors.TRIGGER)\r\n if (this.options.linear) {\r\n trigger.removeEventListener('click', clickStepLinearListener)\r\n } else {\r\n trigger.removeEventListener('click', clickStepNonLinearListener)\r\n }\r\n })\r\n\r\n this._element[customProperty] = undefined\r\n this._element = undefined\r\n this._currentIndex = undefined\r\n this._steps = undefined\r\n this._stepsContents = undefined\r\n }\r\n}\r\n\r\nexport default Stepper\r\n"],"names":["matches","window","Element","prototype","closest","element","selector","WinEvent","inType","params","Event","msMatchesSelector","webkitMatchesSelector","document","documentElement","contains","call","parentElement","parentNode","nodeType","e","createEvent","initEvent","Boolean","bubbles","cancelable","Selectors","ClassName","transitionEndEvent","customProperty","showStep","step","stepList","classList","stepperNode","activeStep","filter","length","remove","forEach","trigger","querySelector","setAttribute","add","currentTrigger","removeAttribute","showContent","content","contentList","activeContent","duration","getTransitionDurationFromElement","addEventListener","complete","removeEventListener","emulateTransitionEnd","transitionDuration","getComputedStyle","parseFloat","split","called","emulatedDuration","listener","setTimeout","dispatchEvent","clickStepLinearListener","event","preventDefault","clickStepNonLinearListener","target","stepper","stepIndex","_steps","indexOf","_currentIndex","_stepsContents","DEFAULT_OPTIONS","linear","animation","_options","_element","slice","this","querySelectorAll","hasAttribute","_this","push","getAttribute","options","_setLinkListeners","Object","defineProperty","value","writable","_this2","next","previous","to","stepNumber","tempIndex","reset","destroy","_this3","undefined"],"mappings":";;;;;4YAAA,IAAIA,EAAUC,OAAOC,QAAQC,UAAUH,QACnCI,EAAU,SAACC,EAASC,UAAaD,EAAQD,QAAQE,IACjDC,EAAW,SAACC,EAAQC,UAAW,IAAIR,OAAOS,MAAMF,EAAQC,IAIrDR,OAAOC,QAAQC,UAAUH,UAC5BA,EAAUC,OAAOC,QAAQC,UAAUQ,mBACjCV,OAAOC,QAAQC,UAAUS,uBAGxBX,OAAOC,QAAQC,UAAUC,UAC5BA,EAAU,SAACC,EAASC,OACbO,SAASC,gBAAgBC,SAASV,UAC9B,OAGN,IACGL,EAAQgB,KAAKX,EAASC,UACjBD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