import textEncoding from"./common/textencoding.js";import browser from"./browser.js";let supportsCaptureOption=!1;try{let opts=Object.defineProperty({},"capture",{get:function(){supportsCaptureOption=!0}});window.addEventListener("test",null,opts)}catch(e){}function addEventListenerWithOptions(target,type,handler,options){options=supportsCaptureOption?options:options.capture;target.addEventListener(type,handler,options)}function removeEventListenerWithOptions(target,type,handler,options){options=supportsCaptureOption?options:options.capture;target.removeEventListener(type,handler,options)}let windowSize,windowSizeEventsBound;function clearWindowSize(){windowSize=null}function getWindowSize(){var win;return windowSize||(win=window,windowSize={innerHeight:win.innerHeight,innerWidth:win.innerWidth},console.log("dom getWindowSize"),windowSizeEventsBound)||(windowSizeEventsBound=!0,addEventListenerWithOptions(window,"orientationchange",clearWindowSize,{passive:!0}),addEventListenerWithOptions(window,"resize",clearWindowSize,{passive:!0})),windowSize}let _animationEvent;function whichAnimationEvent(){if(!_animationEvent){var t,el=document.createElement("div"),animations={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"animationend",WebkitAnimation:"webkitAnimationEnd"};for(t in animations)if(void 0!==el.style[t])return _animationEvent=animations[t],animations[t];_animationEvent="animationend"}return _animationEvent}function whichAnimationCancelEvent(){return whichAnimationEvent().replace("animationend","animationcancel").replace("AnimationEnd","AnimationCancel")}let _transitionEvent;function whichTransitionEvent(){if(!_transitionEvent){var t,el=document.createElement("div"),transitions={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in transitions)if(void 0!==el.style[t])return _transitionEvent=transitions[t],transitions[t];_transitionEvent="transitionend"}return _transitionEvent}function supportsEventListenerOnce(){return supportsCaptureOption}function removeAttributes(elem){var whitelist=[],attributes=elem.attributes;let i=attributes.length;for(;i--;){var attr=attributes[i];-1===whitelist.indexOf(attr.name)&&elem.removeAttributeNode(attr)}}function stripScriptsWithDom(s){var div=document.createElement("div"),scripts=(div.innerHTML=s,div.getElementsByTagName("script"));let i=scripts.length;for(;i--;)scripts[i].remove();var length,elems=div.getElementsByTagName("*");for(i=0,length=elems.length;i{var testBtn=document.createElement("button");testBtn.addEventListener("click",function(e){_supportsPointerTypeInClickEvent="pointerType"in e}),testBtn.click()})(),"android"===globalThis.appMode),allowBackdropFilter=(()=>{var deviceMemory,platform,cores=navigator.hardwareConcurrency||4;return!(cores<4||(deviceMemory=navigator.deviceMemory||2)<2||browser.edge||browser.android||browser.chrome||"undefined"!=typeof AndroidAppHost&&!AndroidAppHost.allowBackdropFilter()||!supportsEventListenerOnce()||(platform=(navigator.platform||"").toLowerCase(),isNativeAndroid&&(cores<4||deviceMemory<2||platform.includes("armv7"))))})(),allowFocusScaling=(()=>{var cores=navigator.hardwareConcurrency||6;return!(cores<6||(2400<=(screen.width||screen.availWidth||0)||1400<=(screen.height||screen.availHeight||0))&&cores<6||(navigator.deviceMemory||4)<4||!document.documentElement.animate||!CSS.supports("display","flow-root")||isNativeAndroid)})();export default{addEventListener:addEventListenerWithOptions,removeEventListener:removeEventListenerWithOptions,getWindowSize:getWindowSize,whichTransitionEvent:whichTransitionEvent,whichAnimationEvent:whichAnimationEvent,whichAnimationCancelEvent:whichAnimationCancelEvent,htmlEncode:textEncoding.htmlEncode,supportsEventListenerOnce:supportsEventListenerOnce,stripScripts:stripScripts,supportsPointerTypeInClickEvent:function(){return _supportsPointerTypeInClickEvent},allowBackdropFilter:function(){return allowBackdropFilter},allowFocusScaling:function(){return allowFocusScaling},supportsAsyncDecodedImages:function(){return!browser.iOS&&!browser.osx}};