!(function (t, e) { 'object' == typeof exports && 'object' == typeof module ? (module.exports = e()) : 'function' == typeof define && define.amd ? define('night2', [], e) : 'object' == typeof exports ? (exports.night2 = e()) : (t.night2 = e()); })('undefined' != typeof self ? self : this, function () { return (function (t) { var e = {}; function n(o) { if (e[o]) return e[o].exports; var i = (e[o] = { i: o, l: !1, exports: {} }); return t[o].call(i.exports, i, i.exports, n), (i.l = !0), i.exports; } return ( (n.m = t), (n.c = e), (n.d = function (t, e, o) { n.o(t, e) || Object.defineProperty(t, e, { enumerable: !0, get: o }); }), (n.r = function (t) { 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, { value: 'Module' }), Object.defineProperty(t, '__esModule', { value: !0 }); }), (n.t = function (t, e) { if ((1 & e && (t = n(t)), 8 & e)) return t; if (4 & e && 'object' == typeof t && t && t.__esModule) return t; var o = Object.create(null); if ( (n.r(o), Object.defineProperty(o, 'default', { enumerable: !0, value: t }), 2 & e && 'string' != typeof t) ) for (var i in t) n.d( o, i, function (e) { return t[e]; }.bind(null, i) ); return o; }), (n.n = function (t) { var e = t && t.__esModule ? function () { return t.default; } : function () { return t; }; return n.d(e, 'a', e), e; }), (n.o = function (t, e) { return Object.prototype.hasOwnProperty.call(t, e); }), (n.p = ''), n((n.s = 0)) ); })([ function (t, e, n) { 'use strict'; function o(t) { return (o = 'function' == typeof Symbol && 'symbol' == typeof Symbol.iterator ? function (t) { return typeof t; } : function (t) { return t && 'function' == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? 'symbol' : typeof t; })(t); } Object.defineProperty(e, '__esModule', { value: !0 }), (e.default = void 0); var i = (function (t, e) { if (!e && t && t.__esModule) return t; if (null === t || ('object' !== o(t) && 'function' != typeof t)) return { default: t }; var n = r(e); if (n && n.has(t)) return n.get(t); var i = {}, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var s in t) if ('default' !== s && Object.prototype.hasOwnProperty.call(t, s)) { var u = a ? Object.getOwnPropertyDescriptor(t, s) : null; u && (u.get || u.set) ? Object.defineProperty(i, s, u) : (i[s] = t[s]); } (i.default = t), n && n.set(t, i); return i; })(n(1)); function r(t) { if ('function' != typeof WeakMap) return null; var e = new WeakMap(), n = new WeakMap(); return (r = function (t) { return t ? n : e; })(t); } var a = i.default; (e.default = a), i.IS_BROWSER && (function (t) { t.Night2 = i.default; })(window), (t.exports = e.default); }, function (t, e, n) { 'use strict'; Object.defineProperty(e, '__esModule', { value: !0 }), (e.default = e.IS_BROWSER = void 0); var o, i = (o = n(2)) && o.__esModule ? o : { default: o }; function r(t, e) { if (!(t instanceof e)) throw new TypeError('Cannot call a class as a function'); } function a(t, e) { for (var n = 0; n < e.length; n++) { var o = e[n]; (o.enumerable = o.enumerable || !1), (o.configurable = !0), 'value' in o && (o.writable = !0), Object.defineProperty(t, o.key, o); } } var s = 'undefined' != typeof window; e.IS_BROWSER = s; var u = (function () { function t() { var e = this, n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}; r(this, t), (this.settings = this.extendSettings(n)), (this.today = new Date()), this.time(this.today), setInterval(function () { return e.time(new Date()); }, 1e3 * this.settings.intervalForTime * 60), this.settings.auto && this.auto(!0), this.theme(); } var e, n, o; return ( (e = t), (n = [ { key: 'time', value: function (t) { var e = new Date().setHours(24, 0, 0, 0); localStorage.time ? localStorage.location && t.getTime() > JSON.parse(localStorage.time) && (localStorage.removeItem('time'), this.settings.cacheClear && (localStorage.removeItem('location'), 'function' == typeof this.settings.onCacheClear && this.settings.onCacheClear())) : (localStorage.setItem('time', JSON.stringify(e)), localStorage.location || ('geolocation' in navigator && this.myLocation())); } }, { key: 'theme', value: function () { return 'true' === localStorage.dark ? this.dark() : this.light(); } }, { key: 'auto', value: function (t) { ((t && !localStorage.auto) || !t) && (localStorage.setItem('auto', 'true'), 'function' == typeof this.settings.onAuto && this.settings.onAuto()), 'geolocation' in navigator && this.myLocation(); } }, { key: 'myLocation', value: function () { if (localStorage.location) { var t = JSON.parse(localStorage.location); this.checkSunPosition(t.latitude, t.longitude); } else navigator.geolocation.getCurrentPosition(this.success.bind(this), this.error.bind(this)); } }, { key: 'success', value: function (t) { var e = { latitude: t.coords.latitude, longitude: t.coords.longitude }; this.checkSunPosition(e.latitude, e.longitude), this.settings.cache && localStorage.setItem('location', JSON.stringify(e)); } }, { key: 'error', value: function (t) { 'function' == typeof this.settings.onDenied && this.settings.onDenied(), document.dispatchEvent(new CustomEvent('smartDarkError', { detail: t })); } }, { key: 'checkSunPosition', value: function (t, e) { var n = this, o = new i.default.getTimes(this.today, t, e), r = o.sunriseEnd - (o.sunriseEnd - o.sunrise) / 2 + 60 * this.settings.offset * 1e3, a = o.sunset - (o.sunset - o.sunsetStart) / 2 - 60 * this.settings.offset * 1e3, s = { sunrise: new Date(r), sunset: new Date(a), latitude: t, longitude: e }; if ( (document.dispatchEvent(new CustomEvent('smartDark', { detail: s })), localStorage.auto && JSON.parse(localStorage.auto)) ) { var u = new Date(), l = this.isDark; u.getTime() > r && u.getTime() < a ? this.light() : this.dark(), l !== this.isDark && 'function' == typeof this.settings.onChange && this.settings.onChange(this.isDark); } this.intervalForCheckSunPosition = setInterval(function () { if (localStorage.auto && JSON.parse(localStorage.auto)) { var t = new Date(), e = n.isDark; t.getTime() > r && t.getTime() < a ? n.light() : n.dark(), e !== n.isDark && 'function' == typeof n.settings.onChange && n.settings.onChange(n.isDark); } }, 1e3 * this.settings.intervalForCheckSun * 60); } }, { key: 'reset', value: function () { localStorage.clear(), clearInterval(this.intervalForCheckSunPosition), 'function' == typeof this.settings.onReset && this.settings.onReset(); } }, { key: 'light', value: function () { 'function' == typeof this.settings.onLight && this.settings.onLight(), (this.isDark = !1), this.settings.lightClass && document.body.classList.add(this.settings.lightClass), document.body.classList.remove(this.settings.darkClass), localStorage.setItem('dark', 'false'); } }, { key: 'dark', value: function () { 'function' == typeof this.settings.onDark && this.settings.onDark(), (this.isDark = !0), this.settings.lightClass && document.body.classList.remove(this.settings.lightClass), document.body.classList.add(this.settings.darkClass), localStorage.setItem('dark', 'true'); } }, { key: 'toggle', value: function () { this.isDark ? this.light() : this.dark(), 'function' == typeof this.settings.onToggle && this.settings.onToggle(this.isDark), localStorage.setItem('auto', 'false'); } }, { key: 'extendSettings', value: function (t) { var e = { divId: 'default', lightClass: '', darkClass: 'dark', cache: !0, cacheClear: !0, auto: !0, intervalForCheckSun: 10, intervalForTime: 60, offset: 30, onAuto: null, onLight: null, onDark: null, onToggle: null, onChange: null, onDenied: null, onCacheClear: null, onReset: null }, n = {}; for (var o in e) n[o] = o in t ? t[o] : e[o]; return n; } } ]) && a(e.prototype, n), o && a(e, o), t ); })(); e.default = u; }, function (t, e, n) { !(function () { 'use strict'; var e = Math.PI, n = Math.sin, o = Math.cos, i = Math.tan, r = Math.asin, a = Math.atan2, s = Math.acos, u = e / 180; function l(t) { return new Date(864e5 * (t + 0.5 - 2440588)); } function c(t) { return ( (function (t) { return t.valueOf() / 864e5 - 0.5 + 2440588; })(t) - 2451545 ); } var f = 23.4397 * u; function d(t, e) { return a(n(t) * o(f) - i(e) * n(f), o(t)); } function g(t, e) { return r(n(e) * o(f) + o(e) * n(f) * n(t)); } function h(t, e, r) { return a(n(t), o(t) * n(e) - i(r) * o(e)); } function v(t, e, i) { return r(n(e) * n(i) + o(e) * o(i) * o(t)); } function y(t, e) { return u * (280.16 + 360.9856235 * t) - e; } function p(t) { return u * (357.5291 + 0.98560028 * t); } function m(t) { return t + u * (1.9148 * n(t) + 0.02 * n(2 * t) + 3e-4 * n(3 * t)) + 102.9372 * u + e; } function S(t) { var e = m(p(t)); return { dec: g(e, 0), ra: d(e, 0) }; } var k = { getPosition: function (t, e, n) { var o = u * -n, i = u * e, r = c(t), a = S(r), s = y(r, o) - a.ra; return { azimuth: h(s, i, a.dec), altitude: v(s, i, a.dec) }; } }, b = (k.times = [ [-0.833, 'sunrise', 'sunset'], [-0.3, 'sunriseEnd', 'sunsetStart'], [-6, 'dawn', 'dusk'], [-12, 'nauticalDawn', 'nauticalDusk'], [-18, 'nightEnd', 'night'], [6, 'goldenHourEnd', 'goldenHour'] ]); k.addTime = function (t, e, n) { b.push([t, e, n]); }; function D(t, n, o) { return 9e-4 + (t + n) / (2 * e) + o; } function w(t, e, o) { return 2451545 + t + 0.0053 * n(e) - 0.0069 * n(2 * o); } function M(t, e, i, r, a, u, l) { return w( D( (function (t, e, i) { return s((n(t) - n(e) * n(i)) / (o(e) * o(i))); })(t, i, r), e, a ), u, l ); } function C(t) { var e = u * (134.963 + 13.064993 * t), i = u * (93.272 + 13.22935 * t), r = u * (218.316 + 13.176396 * t) + 6.289 * u * n(e), a = 5.128 * u * n(i), s = 385001 - 20905 * o(e); return { ra: d(r, a), dec: g(r, a), dist: s }; } function O(t, e) { return new Date(t.valueOf() + (864e5 * e) / 24); } (k.getTimes = function (t, n, o) { var i, r, a, s, f, d = u * -o, h = u * n, v = (function (t, n) { return Math.round(t - 9e-4 - n / (2 * e)); })(c(t), d), y = D(0, d, v), S = p(y), k = m(S), C = g(k, 0), O = w(y, S, k), P = { solarNoon: l(O), nadir: l(O - 0.5) }; for (i = 0, r = b.length; i < r; i += 1) (f = O - ((s = M((a = b[i])[0] * u, d, h, C, v, S, k)) - O)), (P[a[1]] = l(f)), (P[a[2]] = l(s)); return P; }), (k.getMoonPosition = function (t, e, r) { var s = u * -r, l = u * e, f = c(t), d = C(f), g = y(f, s) - d.ra, p = v(g, l, d.dec), m = a(n(g), i(l) * o(d.dec) - n(d.dec) * o(g)); return ( (p += (function (t) { return t < 0 && (t = 0), 2967e-7 / Math.tan(t + 0.00312536 / (t + 0.08901179)); })(p)), { azimuth: h(g, l, d.dec), altitude: p, distance: d.dist, parallacticAngle: m } ); }), (k.getMoonIllumination = function (t) { var e = c(t || new Date()), i = S(e), r = C(e), u = s(n(i.dec) * n(r.dec) + o(i.dec) * o(r.dec) * o(i.ra - r.ra)), l = a(149598e3 * n(u), r.dist - 149598e3 * o(u)), f = a(o(i.dec) * n(i.ra - r.ra), n(i.dec) * o(r.dec) - o(i.dec) * n(r.dec) * o(i.ra - r.ra)); return { fraction: (1 + o(l)) / 2, phase: 0.5 + (0.5 * l * (f < 0 ? -1 : 1)) / Math.PI, angle: f }; }), (k.getMoonTimes = function (t, e, n, o) { var i = new Date(t); o ? i.setUTCHours(0, 0, 0, 0) : i.setHours(0, 0, 0, 0); for ( var r, a, s, l, c, f, d, g, h, v, y, p, m, S = 0.133 * u, b = k.getMoonPosition(i, e, n).altitude - S, D = 1; D <= 24 && ((r = k.getMoonPosition(O(i, D), e, n).altitude - S), (g = ((c = (b + (a = k.getMoonPosition(O(i, D + 1), e, n).altitude - S)) / 2 - r) * (d = -(f = (a - b) / 2) / (2 * c)) + f) * d + r), (v = 0), (h = f * f - 4 * c * r) >= 0 && ((y = d - (m = Math.sqrt(h) / (2 * Math.abs(c)))), (p = d + m), Math.abs(y) <= 1 && v++, Math.abs(p) <= 1 && v++, y < -1 && (y = p)), 1 === v ? b < 0 ? (s = D + y) : (l = D + y) : 2 === v && ((s = D + (g < 0 ? p : y)), (l = D + (g < 0 ? y : p))), !s || !l); D += 2 ) b = a; var w = {}; return ( s && (w.rise = O(i, s)), l && (w.set = O(i, l)), s || l || (w[g > 0 ? 'alwaysUp' : 'alwaysDown'] = !0), w ); }), (t.exports = k); })(); } ]); });