ssr-window.esm.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * SSR Window 1.0.1
  3. * Better handling for window object in SSR environment
  4. * https://github.com/nolimits4web/ssr-window
  5. *
  6. * Copyright 2018, Vladimir Kharlampidi
  7. *
  8. * Licensed under MIT
  9. *
  10. * Released on: July 18, 2018
  11. */
  12. var doc = (typeof document === 'undefined') ? {
  13. body: {},
  14. addEventListener: function addEventListener() {},
  15. removeEventListener: function removeEventListener() {},
  16. activeElement: {
  17. blur: function blur() {},
  18. nodeName: '',
  19. },
  20. querySelector: function querySelector() {
  21. return null;
  22. },
  23. querySelectorAll: function querySelectorAll() {
  24. return [];
  25. },
  26. getElementById: function getElementById() {
  27. return null;
  28. },
  29. createEvent: function createEvent() {
  30. return {
  31. initEvent: function initEvent() {},
  32. };
  33. },
  34. createElement: function createElement() {
  35. return {
  36. children: [],
  37. childNodes: [],
  38. style: {},
  39. setAttribute: function setAttribute() {},
  40. getElementsByTagName: function getElementsByTagName() {
  41. return [];
  42. },
  43. };
  44. },
  45. location: { hash: '' },
  46. } : document; // eslint-disable-line
  47. var win = (typeof window === 'undefined') ? {
  48. document: doc,
  49. navigator: {
  50. userAgent: '',
  51. },
  52. location: {},
  53. history: {},
  54. CustomEvent: function CustomEvent() {
  55. return this;
  56. },
  57. addEventListener: function addEventListener() {},
  58. removeEventListener: function removeEventListener() {},
  59. getComputedStyle: function getComputedStyle() {
  60. return {
  61. getPropertyValue: function getPropertyValue() {
  62. return '';
  63. },
  64. };
  65. },
  66. Image: function Image() {},
  67. Date: function Date() {},
  68. screen: {},
  69. setTimeout: function setTimeout() {},
  70. clearTimeout: function clearTimeout() {},
  71. } : window; // eslint-disable-line
  72. export { win as window, doc as document };