UNPKG

@detector-js/feature

Version:
3 lines (2 loc) 9.43 kB
var e=require("@detector-js/core");function t(e,t){return Object.keys(t).forEach(function(s){"default"===s||"__esModule"===s||e.hasOwnProperty(s)||Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[s]}})}),e}function s(e,t,s,i){Object.defineProperty(e,t,{get:s,set:i,enumerable:!0,configurable:!0})}s(module.exports,"Feature",()=>a);var i={};s(i,"AudioFeature",()=>r);class r extends e.CssFlagsClass{#e;constructor(e=null,t={},s="audio"){super(e,t,s),this.#t(),this.context=this.getContext(),this.formats={mp3:this.getMp3(),webm:this.getWebm(),ogg:this.getOgg(),opus:this.getOpus(),wav:this.getWav(),m4a:this.getM4a()}}#t(){this.#e=this.document.createElement("audio")}get supported(){return(0,e.Asserts).all(["Audio"in this.root,"HTMLAudioElement"in this.root,"HTMLMediaElement"in this.root,()=>!!this.#e&&"canPlayType"in this.#e&&this.#e instanceof HTMLAudioElement&&this.#e instanceof HTMLMediaElement],!0)}getContext(){return(0,e.Asserts).one(["AudioContext"in this.root,"webkitAudioContext"in this.root])}getMp3(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#e.canPlayType("audio/mpeg;").replace(/^no$/,"")],!0)}getWebm(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#e.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")],!0)}getOgg(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#e.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,"")],!0)}getOpus(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#e.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,"")],!0)}getWav(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#e.canPlayType('audio/wav; codecs="1"').replace(/^no$/,"")],!0)}getM4a(){return(0,e.Asserts).all([()=>this.supported&&""!==(this.#e.canPlayType("audio/x-m4a;").replace(/^no$/,"")||this.#e.canPlayType("audio/aac;").replace(/^no$/,""))],!0)}}var n={};s(n,"VideoFeature",()=>o);class o extends e.CssFlagsClass{#s;constructor(e=null,t={},s="video"){super(e,t,s),this._createTestElements(),this.formats={mp4:this.getMp4(),ogv:this.getOgv(),webm:this.getWebm()}}_createTestElements(){this.#s=this.document.createElement("video")}get supported(){return(0,e.Asserts).all(["HTMLVideoElement"in this.root,"HTMLMediaElement"in this.root,()=>!!this.#s&&"canPlayType"in this.#s&&this.#s instanceof HTMLVideoElement&&this.#s instanceof HTMLMediaElement],!0)}getMp4(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#s.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/^no$/,"")],!0)}getOgv(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#s.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/^no$/,"")],!0)}getWebm(){return(0,e.Asserts).all([()=>this.supported&&""!==this.#s.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,"")],!0)}}class a extends e.CssFlagsClass{#i;#r;#n;#o;#a;#l;#h;constructor(e=null,t={},s="feature"){super(e,t,s),this.#t(),this.addEventListener=this.getAddEventListener(),this.asyncScript=this.getAsyncScript(),this.battery=this.getBattery(),this.cors=this.getCors(),this.deferScript=this.getDeferScript(),this.file=this.getFile(),this.fileSystem=this.getFileSystem(),this.fullscreen=this.getFullscreen(),this.fullscreenKeyboard=this.getFullscreenKeyboard(),this.geolocation=this.getGeolocation(),this.historyAPI=this.getHistoryAPI(),this.littleEndian=this.getLittleEndian(),this.localStorage=this.getLocalStorage(),this.matchMedia=this.getMatchMedia(),this.querySelector=this.getQuerySelector(),this.querySelectorAll=this.getQuerySelectorAll(),this.serviceWorker=this.getServiceWorker(),this.typedArray=this.getTypedArray(),this.userMedia=this.getUserMedia(),this.vibration=this.getVibration(),this.worker=this.getWorker()}#c(e,t=this.#i){e=e.toCamelCase();let s=t.map(t=>("spec"===t?"":"-"+t+"-")+e),i=s.filter(e=>e in this.#o.style);return i.length>0?i[0]:null}_checkCssPrefixedProp(e,t=this.#i){return!!this.#c(e,t)}_getCssPrefixedPropValue(e,t){let s=this.#c(e);if(s){this.document.body.insertBefore(this.#o,null),this.#o.style[s]=t;let e=this.root.getComputedStyle(this.#o).getPropertyValue(s);if(this.document.body.removeChild(this.#o),e&&"string"==typeof e)return e}return null}_checkCssPrefixedPropValue(e,t){let s=this._getCssPrefixedPropValue(e,t);return!!s&&"none"!==s}#t(){this.#i=["spec","webkit","moz","ms","o"],this.#r=this.document.createElement("script"),this.#n=this.document.createElement("canvas"),this.#o=this.document.createElement("div"),this.#a=this.document.createElement("input"),this.#l=this.document.createElement("img"),this.#h=new this.root.XMLHttpRequest}getAddEventListener(){return"addEventListener"in this.root}getAsyncScript(){return"async"in this.#r}getBattery(){return"battery"in this.navigator}getCors(){return"XMLHttpRequest"in this.root&&"withCredentials"in this.#h}getDeferScript(){return"defer"in this.#r}getFile(){return(0,e.Asserts).all(["File"in this.root,"FileReader"in this.root,"FileList"in this.root,"Blob"in this.root])}getFileSystem(){return"requestFileSystem"in this.root}getFullscreen(){return(0,e.Asserts).one(["requestFullscreen"in this.#n,"webkitRequestFullscreen"in this.#n,"msRequestFullscreen"in this.#n,"mozRequestFullScreen"in this.#n])}getFullscreenKeyboard(){return(0,e.Asserts).all([()=>"Element"in this.root&&"ALLOW_KEYBOARD_INPUT"in this.root.Element],!0)}getGeolocation(){return"geolocation"in this.navigator}getHistoryAPI(){return(0,e.Asserts).all([()=>"history"in this.root&&"pushState"in this.root.history],!0)}getLittleEndian(){return(0,e.Asserts).all([this.getTypedArray.bind(this),()=>new this.root.Int8Array(new this.root.Int16Array([1]).buffer)[0]>0],!0)}getLocalStorage(){return(0,e.Asserts).one([()=>"localStorage"in this.root],!0)&&(0,e.Asserts).one([()=>(this.root.localStorage.setItem("x","x"),this.root.localStorage.removeItem("x"),!0)],!0)}getMatchMedia(){return"matchMedia"in this.root}getQuerySelector(){return"querySelector"in this.document}getQuerySelectorAll(){return"querySelectorAll"in this.document}getServiceWorker(){return"serviceWorker"in this.navigator}getTypedArray(){return(0,e.Asserts).all([()=>"Int8Array"in this.root&&void 0!==this.root.Int8Array],!0)}getUserMedia(){return(0,e.Asserts).one(["getUserMedia"in this.navigator,"webkitGetUserMedia"in this.navigator,"mozGetUserMedia"in this.navigator,"msGetUserMedia"in this.navigator])}getVibration(){return(0,e.Asserts).one(["vibrate"in this.navigator,"webkitVibrate"in this.navigator,"mozVibrate"in this.navigator,"msVibrate"in this.navigator])}getWorker(){return"Worker"in this.root}get pointerEnabled(){return(0,e.Asserts).one(["pointerEnabled"in this.navigator,"msPointerEnabled"in this.navigator])}get pixelRatio(){return this.root.devicePixelRatio||1}get pointerLock(){return(0,e.Asserts).one(["pointerLockElement"in this.document,"webkitPointerLockElement"in this.document,"mozPointerLockElement"in this.document])}get quirksMode(){return"CSS1Compat"!==this.document.compatMode}get css3D(){return(0,e.Asserts).all([this._checkCssPrefixedPropValue.bind(this,"transform","translate3d(1px,1px,1px)"),this._checkCssPrefixedProp.bind(this,"perspective")],!0)}get cssTransform(){return(0,e.Asserts).one([this._checkCssPrefixedProp.bind(this,"transform-origin")],!0)}get cssTransition(){return(0,e.Asserts).one([this._checkCssPrefixedProp.bind(this,"transition")],!0)}get deviceMotion(){return"DeviceMotionEvent"in this.root}get deviceOrientation(){return"DeviceOrientationEvent"in this.root}get contextMenu(){return(0,e.Asserts).all(["contextMenu"in this.document,"HTMLMenuItemElement"in this.root])}get classList(){return"classList"in this.document}get placeholder(){return"placeholder"in this.#a}get viewportUnit(){return(0,e.Asserts).all([()=>(this.#l.style.width="1vw",""!==this.#l.style.width)],!0)}get remUnit(){return(0,e.Asserts).all([()=>(this.#l.style.width="1rem",""!==this.#l.style.width)],!0)}get canvas(){return(0,e.Asserts).all([()=>"getContext"in this.#n&&!!this.#n.getContext("2d")],!0)}get svg(){return(0,e.Asserts).all([()=>"createElementNS"in this.document&&"createSVGRect"in this.document.createElementNS("http://www.w3.org/2000/svg","svg")],!0)}get webp(){return(0,e.Asserts).all([()=>{let e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))&&0===e.toDataURL("image/webp").indexOf("data:image/webp")}],!0)}get webGL(){return(0,e.Asserts).one([()=>this.canvas&&"WebGLRenderingContext"in this.root&&(this.#n.getContext("webgl")||this.#n.getContext("experimental-webgl")),()=>this.canvas&&"WebGL2RenderingContext"in this.root&&this.#n.getContext("webgl2")],!0)}get webVR(){return(0,e.Asserts).all(["getVRDisplays"in this.navigator])}get touch(){return(0,e.Asserts).one([()=>"ontouchstart"in this.root,()=>"ontouchstart"in this.document.documentElement],!0)&&(0,e.Asserts).one([()=>"DocumentTouch"in this.root,()=>this.pointerEnabled&&"MSGesture"in this.root,()=>"maxTouchPoints"in this.navigator&&this.navigator.maxTouchPoints>1],!0)}get forceTouch(){return(0,e.Asserts).all([()=>"MouseEvent"in this.root&&"WEBKIT_FORCE_AT_MOUSE_DOWN"in this.root.MouseEvent&&"WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN"in this.root.MouseEvent],!0)}get pointerEvents(){return(0,e.Asserts).all([!!this.root.PointerEvent],!0)}get srcset(){return"srcset"in this.#l}get sizes(){return"sizes"in this.#l}get pictureElement(){return"HTMLPictureElement"in this.root}get dialogElement(){return"HTMLDialogElement"in this.root}}t(module.exports,i),t(module.exports,n); //# sourceMappingURL=feature.js.map