{"version":3,"file":"browser.cjs","sources":["../src/browser.js"],"sourcesContent":["function generateHandler(replaceWith) {\n\tvar selector;\n\tvar remove;\n\tvar add;\n\tvar lastElements = [];\n\n\tif (replaceWith[0] === '.') {\n\t\tselector = replaceWith.slice(1);\n\t\tremove = function remove(el) {\n\t\t\tel.classList.remove(selector);\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.classList.add(selector);\n\t\t};\n\t} else {\n\t\t// A bit naive\n\t\tselector = replaceWith.slice(1, -1);\n\n\t\tremove = function remove(el) {\n\t\t\tel.removeAttribute(selector, '');\n\t\t};\n\n\t\tadd = function add(el) {\n\t\t\tel.setAttribute(selector, '');\n\t\t};\n\t}\n\n\treturn function handleFocusChange() {\n\t\tfor (var i = 0; i < lastElements.length; i++) {\n\t\t\tremove(lastElements[i]);\n\t\t}\n\t\tlastElements.length = 0;\n\n\t\tvar activeElement = document.activeElement;\n\n\t\t// only add focus if it has not been added and is not the document element\n\t\tif (!/^(#document|HTML|BODY)$/.test(Object(activeElement).nodeName)) {\n\t\t\twhile (activeElement && activeElement.nodeType === 1) {\n\t\t\t\tadd(activeElement);\n\t\t\t\tlastElements.push(activeElement);\n\n\t\t\t\tactiveElement = activeElement.parentNode;\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport default function focusWithin(opts) {\n\t// configuration\n\tvar options = {\n\t\tforce: false,\n\t\treplaceWith: '[focus-within]',\n\t};\n\n\tif (typeof opts !== 'undefined' && 'force' in opts) {\n\t\toptions.force = opts.force;\n\t}\n\n\tif (typeof opts !== 'undefined' && 'replaceWith' in opts) {\n\t\toptions.replaceWith = opts.replaceWith;\n\t}\n\n\ttry {\n\t\tdocument.querySelector(':focus-within');\n\n\t\tif (!options.force) {\n\t\t\treturn;\n\t\t}\n\t} catch (_) {}\n\n\tvar handleFocusChange = generateHandler(options.replaceWith);\n\n\tvar initialize = function initializeEventListeners() {\n\t\tif (document.documentElement.className.indexOf('js-focus-within') > -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tdocument.documentElement.className = document.documentElement.className + ' js-focus-within';\n\t\tdocument.addEventListener('focus', handleFocusChange, true);\n\t\tdocument.addEventListener('blur', handleFocusChange, true);\n\t};\n\n\tif (document.readyState === 'complete') {\n\t\tinitialize();\n\t} else {\n\t\tdocument.addEventListener('DOMContentLoaded', initialize);\n\t}\n}\n"],"names":["focusWithin","opts","options","force","replaceWith","document","querySelector","_","selector","remove","add","lastElements","handleFocusChange","slice","el","classList","removeAttribute","setAttribute","i","length","activeElement","test","Object","nodeName","nodeType","push","parentNode","initialize","initializeEventListeners","documentElement","className","indexOf","addEventListener","readyState"],"mappings":"eAgDe,SAASA,YAAYC,GAEnC,IAAIC,EAAU,CACbC,OAAO,EACPC,YAAa,uBAGM,IAATH,GAAwB,UAAWA,IAC7CC,EAAQC,MAAQF,EAAKE,YAGF,IAATF,GAAwB,gBAAiBA,IACnDC,EAAQE,YAAcH,EAAKG,aAG5B,IAGC,GAFAC,SAASC,cAAc,kBAElBJ,EAAQC,MACZ,MAEF,CAAE,MAAOI,GAAI,CAEb,IAvEwBH,EACpBI,EACAC,EACAC,EACAC,EAmEAC,GAvEoBR,EAuEgBF,EAAQE,YAnE5CO,EAAe,GAEI,MAAnBP,EAAY,IACfI,EAAWJ,EAAYS,MAAM,GAC7BJ,EAAS,SAASA,OAAOK,GACxBA,EAAGC,UAAUN,OAAOD,EACrB,EAEAE,EAAM,SAASA,IAAII,GAClBA,EAAGC,UAAUL,IAAIF,EAClB,IAGAA,EAAWJ,EAAYS,MAAM,GAAG,GAEhCJ,EAAS,SAASA,OAAOK,GACxBA,EAAGE,gBAAgBR,EAAU,GAC9B,EAEAE,EAAM,SAASA,IAAII,GAClBA,EAAGG,aAAaT,EAAU,GAC3B,GAGM,SAASI,oBACf,IAAK,IAAIM,EAAI,EAAGA,EAAIP,EAAaQ,OAAQD,IACxCT,EAAOE,EAAaO,IAErBP,EAAaQ,OAAS,EAEtB,IAAIC,EAAgBf,SAASe,cAG7B,IAAK,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