/** * SSR Window 3.0.0 * Better handling for window object in SSR environment * https://github.com/nolimits4web/ssr-window * * Copyright 2020, Vladimir Kharlampidi * * Licensed under MIT * * Released on: November 9, 2020 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory(global.ssrWindow = {})); }(this, (function (exports) { 'use strict'; /* eslint-disable no-param-reassign */ function isObject(obj) { return (obj !== null && typeof obj === 'object' && 'constructor' in obj && obj.constructor === Object); } function extend(target, src) { if (target === void 0) { target = {}; } if (src === void 0) { src = {}; } Object.keys(src).forEach(function (key) { if (typeof target[key] === 'undefined') target[key] = src[key]; else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) { extend(target[key], src[key]); } }); } var ssrDocument = { body: {}, addEventListener: function () { }, removeEventListener: function () { }, activeElement: { blur: function () { }, nodeName: '', }, querySelector: function () { return null; }, querySelectorAll: function () { return []; }, getElementById: function () { return null; }, createEvent: function () { return { initEvent: function () { }, }; }, createElement: function () { return { children: [], childNodes: [], style: {}, setAttribute: function () { }, getElementsByTagName: function () { return []; }, }; }, createElementNS: function () { return {}; }, importNode: function () { return null; }, location: { hash: '', host: '', hostname: '', href: '', origin: '', pathname: '', protocol: '', search: '', }, }; function getDocument() { var doc = typeof document !== 'undefined' ? document : {}; extend(doc, ssrDocument); return doc; } var ssrWindow = { document: ssrDocument, navigator: { userAgent: '', }, location: { hash: '', host: '', hostname: '', href: '', origin: '', pathname: '', protocol: '', search: '', }, history: { replaceState: function () { }, pushState: function () { }, go: function () { }, back: function () { }, }, CustomEvent: function CustomEvent() { return this; }, addEventListener: function () { }, removeEventListener: function () { }, getComputedStyle: function () { return { getPropertyValue: function () { return ''; }, }; }, Image: function () { }, Date: function () { }, screen: {}, setTimeout: function () { }, clearTimeout: function () { }, matchMedia: function () { return {}; }, requestAnimationFrame: function (callback) { if (typeof setTimeout === 'undefined') { callback(); return null; } return setTimeout(callback, 0); }, cancelAnimationFrame: function (id) { if (typeof setTimeout === 'undefined') { return; } clearTimeout(id); }, }; function getWindow() { var win = typeof window !== 'undefined' ? window : {}; extend(win, ssrWindow); return win; } exports.extend = extend; exports.getDocument = getDocument; exports.getWindow = getWindow; exports.ssrDocument = ssrDocument; exports.ssrWindow = ssrWindow; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ssr-window.umd.js.map