| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /**
- * 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
|