UNPKG

ssr-window

Version:

Better handling for window object in SSR environment

13 lines 2.1 kB
/** * SSR Window 5.0.0 * Better handling for window object in SSR environment * https://github.com/nolimits4web/ssr-window * * Copyright 2025, Vladimir Kharlampidi * * Licensed under MIT * * Released on: February 12, 2025 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ssrWindow={})}(this,(function(e){"use strict";function t(e){return null!==e&&"object"==typeof e&&"constructor"in e&&e.constructor===Object}function n(e={},o={}){const r=["__proto__","constructor","prototype"];Object.keys(o).filter((e=>r.indexOf(e)<0)).forEach((r=>{void 0===e[r]?e[r]=o[r]:t(o[r])&&t(e[r])&&Object.keys(o[r]).length>0&&n(e[r],o[r])}))}const o={body:{},addEventListener(){},removeEventListener(){},activeElement:{blur(){},nodeName:""},querySelector:()=>null,querySelectorAll:()=>[],getElementById:()=>null,createEvent:()=>({initEvent(){}}),createElement:()=>({children:[],childNodes:[],style:{},setAttribute(){},getElementsByTagName:()=>[]}),createElementNS:()=>({}),importNode:()=>null,location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""}};const r={document:o,navigator:{userAgent:""},location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""},history:{replaceState(){},pushState(){},go(){},back(){}},CustomEvent:function(){return this},addEventListener(){},removeEventListener(){},getComputedStyle:()=>({getPropertyValue:()=>""}),Image(){},Date(){},screen:{},setTimeout(){},clearTimeout(){},matchMedia:()=>({}),requestAnimationFrame:e=>"undefined"==typeof setTimeout?(e(),null):setTimeout(e,0),cancelAnimationFrame(e){"undefined"!=typeof setTimeout&&clearTimeout(e)}};e.extend=n,e.getDocument=function(){const e="undefined"!=typeof document?document:{};return n(e,o),e},e.getWindow=function(){const e="undefined"!=typeof window?window:{};return n(e,r),e},e.ssrDocument=o,e.ssrWindow=r,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ssr-window.umd.min.js.map