{"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'\n\nconst MILLISECONDS_MULTIPLIER = 1000\nconst Selectors = {\n STEPS: '.step',\n TRIGGER: '.step-trigger, a',\n STEPPER: '.bs-stepper'\n}\n\nconst ClassName = {\n ACTIVE: 'active',\n LINEAR: 'linear',\n BLOCK: 'dstepper-block',\n NONE: 'dstepper-none',\n FADE: 'fade'\n}\n\nconst transitionEndEvent = 'transitionend'\nconst customProperty = 'bsStepper'\n\nconst showStep = (step, stepList) => {\n if (step.classList.contains(ClassName.ACTIVE)) {\n return\n }\n\n const stepperNode = closest(step, Selectors.STEPPER)\n const activeStep = stepList.filter(step => step.classList.contains(ClassName.ACTIVE))\n if (activeStep.length) {\n activeStep[0].classList.remove(ClassName.ACTIVE)\n }\n stepList.forEach(step => {\n const trigger = step.querySelector(Selectors.TRIGGER)\n trigger.setAttribute('aria-selected', 'false')\n // if stepper is in linear mode, set disabled attribute on the trigger\n if (stepperNode.classList.contains(ClassName.LINEAR)) {\n trigger.setAttribute('disabled', 'disabled')\n }\n })\n\n step.classList.add(ClassName.ACTIVE)\n const currentTrigger = step.querySelector(Selectors.TRIGGER)\n currentTrigger.setAttribute('aria-selected', 'true')\n // if stepper is in linear mode, remove disabled attribute on current\n if (stepperNode.classList.contains(ClassName.LINEAR)) {\n currentTrigger.removeAttribute('disabled')\n }\n}\n\nconst showContent = (content, contentList) => {\n if (content.classList.contains(ClassName.ACTIVE)) {\n return\n }\n\n function complete () {\n content.classList.add(ClassName.BLOCK)\n content.removeEventListener(transitionEndEvent, complete)\n }\n\n const activeContent = contentList.filter(content => content.classList.contains(ClassName.ACTIVE))\n if (activeContent.length) {\n activeContent[0].classList.remove(ClassName.ACTIVE)\n activeContent[0].classList.remove(ClassName.BLOCK)\n }\n\n if (content.classList.contains(ClassName.FADE)) {\n content.classList.remove(ClassName.NONE)\n const duration = getTransitionDurationFromElement(content)\n content.addEventListener(transitionEndEvent, complete)\n if (activeContent.length) {\n activeContent[0].classList.add(ClassName.NONE)\n }\n\n content.classList.add(ClassName.ACTIVE)\n emulateTransitionEnd(content, duration)\n } else {\n content.classList.add(ClassName.ACTIVE)\n }\n}\n\nconst getTransitionDurationFromElement = element => {\n if (!element) {\n return 0\n }\n\n // Get transition-duration of the element\n let transitionDuration = window.getComputedStyle(element).transitionDuration\n const floatTransitionDuration = parseFloat(transitionDuration)\n\n // Return 0 if element or transition duration is not found\n if (!floatTransitionDuration) {\n return 0\n }\n\n // If multiple durations are defined, take the first\n transitionDuration = transitionDuration.split(',')[0]\n\n return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER\n}\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(transitionEndEvent, listener)\n }\n\n element.addEventListener(transitionEndEvent, listener)\n window.setTimeout(() => {\n if (!called) {\n element.dispatchEvent(WinEvent(transitionEndEvent))\n }\n\n element.removeEventListener(transitionEndEvent, listener)\n }, emulatedDuration)\n}\n\nconst detectAnimation = (contentList, animation) => {\n if (animation) {\n contentList.forEach(content => {\n content.classList.add(ClassName.FADE)\n content.classList.add(ClassName.NONE)\n })\n }\n}\n\nexport {\n showContent,\n showStep,\n Selectors,\n ClassName,\n customProperty,\n detectAnimation\n}\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'\nimport { clickStepLinearListener, clickStepNonLinearListener } from './listeners'\n\nconst DEFAULT_OPTIONS = {\n linear: true,\n animation: false\n}\n\nclass Stepper {\n constructor (element, _options = {}) {\n this._element = element\n this._currentIndex = 0\n this._stepsContents = []\n this._steps = [].slice.call(this._element.querySelectorAll(Selectors.STEPS))\n .filter(step => step.hasAttribute('data-target'))\n\n this._steps.forEach(step => {\n this._stepsContents.push(\n this._element.querySelector(step.getAttribute('data-target'))\n )\n })\n\n this.options = {\n ...DEFAULT_OPTIONS,\n ..._options\n }\n\n if (this.options.linear) {\n this._element.classList.add(ClassName.LINEAR)\n }\n\n detectAnimation(this._stepsContents, this.options.animation)\n if (this._steps.length) {\n showStep(this._steps[this._currentIndex], this._steps)\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\n }\n\n this._setLinkListeners()\n Object.defineProperty(this._element, customProperty, {\n value: this,\n writable: true\n })\n }\n\n // Private\n\n _setLinkListeners () {\n this._steps.forEach(step => {\n const trigger = step.querySelector(Selectors.TRIGGER)\n if (this.options.linear) {\n trigger.addEventListener('click', clickStepLinearListener)\n } else {\n trigger.addEventListener('click', clickStepNonLinearListener)\n }\n })\n }\n\n // Public\n\n next () {\n this._currentIndex = (this._currentIndex + 1) <= this._steps.length - 1 ? this._currentIndex + 1 : (this._steps.length - 1)\n\n showStep(this._steps[this._currentIndex], this._steps)\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\n }\n\n previous () {\n this._currentIndex = (this._currentIndex - 1) >= 0 ? this._currentIndex - 1 : 0\n\n showStep(this._steps[this._currentIndex], this._steps)\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\n }\n\n to (stepNumber) {\n const tempIndex = stepNumber - 1\n this._currentIndex = tempIndex >= 0 && tempIndex < this._steps.length\n ? tempIndex\n : 0\n\n showStep(this._steps[this._currentIndex], this._steps)\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\n }\n\n reset () {\n this._currentIndex = 0\n showStep(this._steps[this._currentIndex], this._steps)\n showContent(this._stepsContents[this._currentIndex], this._stepsContents)\n }\n\n destroy () {\n this._steps.forEach(step => {\n const trigger = step.querySelector(Selectors.TRIGGER)\n if (this.options.linear) {\n trigger.removeEventListener('click', clickStepLinearListener)\n } else {\n trigger.removeEventListener('click', clickStepNonLinearListener)\n }\n })\n\n this._element[customProperty] = undefined\n this._element = undefined\n this._currentIndex = undefined\n this._steps = undefined\n this._stepsContents = undefined\n }\n}\n\nexport default Stepper\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,EAGTA,EAAUA,EAAQY,eAAiBZ,EAAQa,iBACxB,OAAZb,GAAyC,IAArBA,EAAQc,iBAE9B,OAINlB,OAAOS,OAAiC,mBAAjBT,OAAOS,QACjCH,EAAW,SAACC,EAAQC,GAClBA,EAASA,GAAU,OACbW,EAAIP,SAASQ,YAAY,gBAC/BD,EAAEE,UAAUd,EAAQe,QAAQd,EAAOe,SAAUD,QAAQd,EAAOgB,aACrDL,IChCb,IACMM,EACG,QADHA,EAEK,mBAFLA,EAGK,cAGLC,EACI,SADJA,EAEI,SAFJA,EAGG,iBAHHA,EAIE,gBAJFA,EAKE,OAGFC,EAAqB,gBACrBC,EAAiB,YAEjBC,EAAW,SAACC,EAAMC,OAClBD,EAAKE,UAAUlB,SAASY,QAItBO,EAAc9B,EAAQ2B,EAAML,GAC5BS,EAAaH,EAASI,OAAO,SAAAL,UAAQA,EAAKE,UAAUlB,SAASY,KAC/DQ,EAAWE,QACbF,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