{"version":3,"file":"doWhileEventing-ef9a7033-DyQ7dKM3.js","sources":["../../../node_modules/@trv-tds/react/node_modules/@trv-tds/webcomponents/dist/esm/doWhileEventing-ef9a7033.js"],"sourcesContent":["/**\n * Runs a callback function while an event is active. This is most useful\n * for efficiently monitoring events such as resizing or scrollng and applying\n * updates to the DOM in without jankiness.\n */\nconst defaultOptions = {\n    runImmediate: true,\n    timeoutDelay: 300\n};\nconst doWhileEventing = (el, events, callback, options = {}) => {\n    if (typeof options === 'boolean') {\n        options = { runImmediate: options };\n    }\n    const { runImmediate, timeoutDelay } = { ...defaultOptions, ...options };\n    const eventList = events.split(' ').filter(e => e);\n    let timeout = 0;\n    const requestAnimationFrame = window.requestAnimationFrame ?\n        window.requestAnimationFrame.bind(window) :\n        (run) => window.setTimeout(run, 60);\n    function onEvent() {\n        if (timeout) {\n            window.clearTimeout(timeout);\n        }\n        else {\n            requestAnimationFrame(run);\n        }\n        timeout = window.setTimeout(() => {\n            timeout = 0;\n        }, timeoutDelay);\n    }\n    function run() {\n        callback();\n        if (timeout) {\n            requestAnimationFrame(run);\n        }\n    }\n    eventList.forEach(event => {\n        el.addEventListener(event, onEvent);\n    });\n    if (runImmediate) {\n        requestAnimationFrame(run);\n    }\n    return () => {\n        eventList.forEach(event => {\n            el.removeEventListener(event, onEvent);\n        });\n    };\n};\n\nexport { doWhileEventing as d };\n\n//# sourceMappingURL=doWhileEventing-ef9a7033.js.map"],"names":["defaultOptions","doWhileEventing","el","events","callback","options","runImmediate","timeoutDelay","eventList","timeout","requestAnimationFrame","run","onEvent","event"],"mappings":"AAKA,MAAMA,EAAiB,CACnB,aAAc,GACd,aAAc,GAClB,EACMC,EAAkB,CAACC,EAAIC,EAAQC,EAAUC,EAAU,CAAA,IAAO,CACxD,OAAOA,GAAY,YACnBA,EAAU,CAAE,aAAcA,CAAS,GAEvC,KAAM,CAAE,aAAAC,EAAc,aAAAC,CAAY,EAAK,CAAE,GAAGP,EAAgB,GAAGK,CAAS,EAClEG,EAAYL,EAAO,MAAM,GAAG,EAAE,OAAO,GAAK,CAAC,EACjD,IAAIM,EAAU,EACd,MAAMC,EAAwB,OAAO,sBACjC,OAAO,sBAAsB,KAAK,MAAM,EACvCC,GAAQ,OAAO,WAAWA,EAAK,EAAE,EACtC,SAASC,GAAU,CACXH,EACA,OAAO,aAAaA,CAAO,EAG3BC,EAAsBC,CAAG,EAE7BF,EAAU,OAAO,WAAW,IAAM,CAC9BA,EAAU,CACb,EAAEF,CAAY,CACvB,CACI,SAASI,GAAM,CACXP,EAAU,EACNK,GACAC,EAAsBC,CAAG,CAErC,CACI,OAAAH,EAAU,QAAQK,GAAS,CACvBX,EAAG,iBAAiBW,EAAOD,CAAO,CAC1C,CAAK,EACGN,GACAI,EAAsBC,CAAG,EAEtB,IAAM,CACTH,EAAU,QAAQK,GAAS,CACvBX,EAAG,oBAAoBW,EAAOD,CAAO,CACjD,CAAS,CACJ,CACL","x_google_ignoreList":[0]}