{
  "version": 3,
  "sources": ["/cdn/shop/t/66/assets/speech-search.js?cb=16427"],
  "sourcesContent": ["/**\n * Returns a function that as long as it continues to be invoked, won't be triggered.\n * @param {Function} fn - Callback function.\n * @param {number} [wait=300] - Delay (in milliseconds).\n * @returns {Function}\n */\nfunction debounce(fn, wait = 300) {\n  let t;\n  return (...args) => {\n    clearTimeout(t);\n    t = setTimeout(() => fn.apply(this, args), wait);\n  };\n}\n\nif (!customElements.get('speech-search-button')) {\n  class SpeechSearchButton extends HTMLElement {\n    constructor() {\n      super();\n\n      this.recognition = null;\n      this.isListening = false;\n      this.form = null;\n      this.searchInput = null;\n      this.predictiveSearch = this.closest('predictive-search');\n\n      const userAgent = window.navigator.userAgent.toLowerCase();\n      if ('webkitSpeechRecognition' in window\n        && userAgent.indexOf('chrome') > -1 && !!window.chrome\n        && userAgent.indexOf('edg/') === -1) {\n        // Browser webkit speech recognition api, and is chrome\n        this.init();\n        this.bindEvents();\n      } else if (this.predictiveSearch) {\n        this.predictiveSearch.classList.add('speech-search--failed');\n      }\n    }\n\n    bindEvents() {\n      this.recognition.addEventListener(\n        'result',\n        debounce((evt) => {\n          if (evt.results) {\n            const term = evt.results[0][0].transcript;\n            this.searchInput.value = term;\n\n            if (this.searchInput.getAttribute('role') === 'combobox') {\n              this.searchInput.dispatchEvent(new Event('input'));\n            } else {\n              this.form.submit();\n            }\n          }\n        }, 300)\n      );\n\n      this.recognition.addEventListener('audiostart', () => {\n        this.isListening = true;\n        this.classList.add('search__speech-listening');\n      });\n\n      this.recognition.addEventListener('audioend', () => {\n        this.isListening = false;\n        this.classList.remove('search__speech-listening');\n      });\n\n      this.addEventListener('click', this.toggleListen);\n\n      this.addEventListener('keydown', (e) => {\n        if (e.code === 'Space' || e.code === 'Enter') {\n          this.toggleListen(e);\n        }\n      });\n    }\n\n    init() {\n      this.classList.remove('hidden');\n      this.recognition = new window.webkitSpeechRecognition(); // eslint-disable-line new-cap\n      this.recognition.continuous = false;\n      this.recognition.interimResults = false;\n      this.form = this.closest('form');\n      this.searchInput = this.form.querySelector('.js-search-input');\n      if (this.predictiveSearch) this.predictiveSearch.classList.add('speech-search--enabled');\n    }\n\n    /**\n     * Stops/starts the browser from listening\n     * @param {object} evt - Event object\n     */\n    toggleListen(evt) {\n      evt.preventDefault();\n      if (this.isListening) {\n        this.recognition.stop();\n      } else {\n        this.recognition.start();\n      }\n    }\n  }\n\n  customElements.define('speech-search-button', SpeechSearchButton);\n}\n"],
  "mappings": "AAMA,SAAS,SAAS,GAAI,KAAO,IAAK,CAChC,IAAI,EACJ,MAAO,IAAI,OAAS,CAClB,aAAa,CAAC,EACd,EAAI,WAAW,IAAM,GAAG,MAAM,KAAM,IAAI,EAAG,IAAI,CACjD,CACF,CAEA,GAAI,CAAC,eAAe,IAAI,sBAAsB,EAAG,CAC/C,MAAM,2BAA2B,WAAY,CAC3C,aAAc,CACZ,MAAM,EAEN,KAAK,YAAc,KACnB,KAAK,YAAc,GACnB,KAAK,KAAO,KACZ,KAAK,YAAc,KACnB,KAAK,iBAAmB,KAAK,QAAQ,mBAAmB,EAExD,MAAM,UAAY,OAAO,UAAU,UAAU,YAAY,EACrD,4BAA6B,QAC5B,UAAU,QAAQ,QAAQ,EAAI,IAAQ,OAAO,QAC7C,UAAU,QAAQ,MAAM,IAAM,IAEjC,KAAK,KAAK,EACV,KAAK,WAAW,GACP,KAAK,kBACd,KAAK,iBAAiB,UAAU,IAAI,uBAAuB,CAE/D,CAEA,YAAa,CACX,KAAK,YAAY,iBACf,SACA,SAAU,KAAQ,CAChB,GAAI,IAAI,QAAS,CACf,MAAM,KAAO,IAAI,QAAQ,CAAC,EAAE,CAAC,EAAE,WAC/B,KAAK,YAAY,MAAQ,KAErB,KAAK,YAAY,aAAa,MAAM,IAAM,WAC5C,KAAK,YAAY,cAAc,IAAI,MAAM,OAAO,CAAC,EAEjD,KAAK,KAAK,OAAO,CAErB,CACF,EAAG,GAAG,CACR,EAEA,KAAK,YAAY,iBAAiB,aAAc,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