You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
3.9 KiB
145 lines
3.9 KiB
/**
|
|
* SSR Window 2.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: May 12, 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 doc = typeof document !== 'undefined' ? document : {};
|
|
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: '',
|
|
},
|
|
};
|
|
extend(doc, ssrDocument);
|
|
|
|
var win = typeof window !== 'undefined' ? window : {};
|
|
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 {};
|
|
},
|
|
};
|
|
extend(win, ssrWindow);
|
|
|
|
exports.document = doc;
|
|
exports.extend = extend;
|
|
exports.window = win;
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
})));
|
|
//# sourceMappingURL=ssr-window.js.map
|