UNPKG

@watergis/maplibre-gl-sky

Version:
771 lines (770 loc) 28.4 kB
var gt = Object.defineProperty; var yt = (_, $, v) => $ in _ ? gt(_, $, { enumerable: !0, configurable: !0, writable: !0, value: v }) : _[$] = v; var st = (_, $, v) => yt(_, typeof $ != "symbol" ? $ + "" : $, v); import "maplibre-gl"; function ft(_) { return _ && _.__esModule && Object.prototype.hasOwnProperty.call(_, "default") ? _.default : _; } var ct = { exports: {} }, lt; function $t() { return lt || (lt = 1, function(_, $) { (function() { var v = Math.PI, a = Math.sin, m = Math.cos, z = Math.tan, k = Math.asin, O = Math.atan2, d = Math.acos, h = v / 180, C = 1e3 * 60 * 60 * 24, D = 2440588, E = 2451545; function A(t) { return t.valueOf() / C - 0.5 + D; } function j(t) { return new Date((t + 0.5 - D) * C); } function u(t) { return A(t) - E; } var Y = h * 23.4397; function q(t, r) { return O(a(t) * m(Y) - z(r) * a(Y), m(t)); } function B(t, r) { return k(a(r) * m(Y) + m(r) * a(Y) * a(t)); } function L(t, r, i) { return O(a(t), m(t) * a(r) - z(i) * m(r)); } function tt(t, r, i) { return k(a(r) * a(i) + m(r) * m(i) * m(t)); } function I(t, r) { return h * (280.16 + 360.9856235 * t) - r; } function J(t) { return t < 0 && (t = 0), 2967e-7 / Math.tan(t + 312536e-8 / (t + 0.08901179)); } function V(t) { return h * (357.5291 + 0.98560028 * t); } function X(t) { var r = h * (1.9148 * a(t) + 0.02 * a(2 * t) + 3e-4 * a(3 * t)), i = h * 102.9372; return t + r + i + v; } function F(t) { var r = V(t), i = X(r); return { dec: B(i, 0), ra: q(i, 0) }; } var M = {}; M.getPosition = function(t, r, i) { var g = h * -i, y = h * r, S = u(t), b = F(S), w = I(S, g) - b.ra; return { azimuth: L(w, y, b.dec), altitude: tt(w, y, b.dec) }; }; var p = M.times = [ [-0.833, "sunrise", "sunset"], [-0.3, "sunriseEnd", "sunsetStart"], [-6, "dawn", "dusk"], [-12, "nauticalDawn", "nauticalDusk"], [-18, "nightEnd", "night"], [6, "goldenHourEnd", "goldenHour"] ]; M.addTime = function(t, r, i) { p.push([t, r, i]); }; var et = 9e-4; function ot(t, r) { return Math.round(t - et - r / (2 * v)); } function c(t, r, i) { return et + (t + r) / (2 * v) + i; } function o(t, r, i) { return E + t + 53e-4 * a(r) - 69e-4 * a(2 * i); } function e(t, r, i) { return d((a(t) - a(r) * a(i)) / (m(r) * m(i))); } function s(t) { return -2.076 * Math.sqrt(t) / 60; } function n(t, r, i, g, y, S, b) { var w = e(t, i, g), x = c(w, r, y); return o(x, S, b); } M.getTimes = function(t, r, i, g) { g = g || 0; var y = h * -i, S = h * r, b = s(g), w = u(t), x = ot(w, y), T = c(0, y, x), H = V(T), U = X(H), P = B(U, 0), Z = o(T, H, U), Q, nt, R, W, G, rt, N = { solarNoon: j(Z), nadir: j(Z - 0.5) }; for (Q = 0, nt = p.length; Q < nt; Q += 1) R = p[Q], W = (R[0] + b) * h, G = n(W, y, S, P, x, H, U), rt = Z - (G - Z), N[R[1]] = j(rt), N[R[2]] = j(G); return N; }; function l(t) { var r = h * (218.316 + 13.176396 * t), i = h * (134.963 + 13.064993 * t), g = h * (93.272 + 13.22935 * t), y = r + h * 6.289 * a(i), S = h * 5.128 * a(g), b = 385001 - 20905 * m(i); return { ra: q(y, S), dec: B(y, S), dist: b }; } M.getMoonPosition = function(t, r, i) { var g = h * -i, y = h * r, S = u(t), b = l(S), w = I(S, g) - b.ra, x = tt(w, y, b.dec), T = O(a(w), z(y) * m(b.dec) - a(b.dec) * m(w)); return x = x + J(x), { azimuth: L(w, y, b.dec), altitude: x, distance: b.dist, parallacticAngle: T }; }, M.getMoonIllumination = function(t) { var r = u(t || /* @__PURE__ */ new Date()), i = F(r), g = l(r), y = 149598e3, S = d(a(i.dec) * a(g.dec) + m(i.dec) * m(g.dec) * m(i.ra - g.ra)), b = O(y * a(S), g.dist - y * m(S)), w = O(m(i.dec) * a(i.ra - g.ra), a(i.dec) * m(g.dec) - m(i.dec) * a(g.dec) * m(i.ra - g.ra)); return { fraction: (1 + m(b)) / 2, phase: 0.5 + 0.5 * b * (w < 0 ? -1 : 1) / Math.PI, angle: w }; }; function f(t, r) { return new Date(t.valueOf() + r * C / 24); } M.getMoonTimes = function(t, r, i, g) { var y = new Date(t); g ? y.setUTCHours(0, 0, 0, 0) : y.setHours(0, 0, 0, 0); for (var S = 0.133 * h, b = M.getMoonPosition(y, r, i).altitude - S, w, x, T, H, U, P, Z, Q, nt, R, W, G, rt, N = 1; N <= 24 && (w = M.getMoonPosition(f(y, N), r, i).altitude - S, x = M.getMoonPosition(f(y, N + 1), r, i).altitude - S, U = (b + x) / 2 - w, P = (x - b) / 2, Z = -P / (2 * U), Q = (U * Z + P) * Z + w, nt = P * P - 4 * U * w, R = 0, nt >= 0 && (rt = Math.sqrt(nt) / (Math.abs(U) * 2), W = Z - rt, G = Z + rt, Math.abs(W) <= 1 && R++, Math.abs(G) <= 1 && R++, W < -1 && (W = G)), R === 1 ? b < 0 ? T = N + W : H = N + W : R === 2 && (T = N + (Q < 0 ? G : W), H = N + (Q < 0 ? W : G)), !(T && H)); N += 2) b = x; var it = {}; return T && (it.rise = f(y, T)), H && (it.set = f(y, H)), !T && !H && (it[Q > 0 ? "alwaysUp" : "alwaysDown"] = !0), it; }, _.exports = M; })(); }(ct)), ct.exports; } var mt = $t(); const vt = /* @__PURE__ */ ft(mt), pt = [ "sunrise", "sunriseEnd", "goldenHourEnd", "solarNoon", "goldenHour", "sunsetStart", "sunset", "dusk", "nauticalDusk", "night", "nadir", "nightEnd", "nauticalDawn", "dawn" ], bt = { skyOptions: { //https://www.color-hex.com/color-palette/51090 sunrise: { "sky-color": "#f7dc6f", "sky-horizon-blend": 0.8, "horizon-color": "#f5b041", "horizon-fog-blend": 0.8, "fog-color": "#f7dc6f", "fog-ground-blend": 0.5 }, sunriseEnd: { "sky-color": "#88C6FC", "sky-horizon-blend": 0.8, "horizon-color": "#ffa700", "horizon-fog-blend": 0.8, "fog-color": "#ffffff", "fog-ground-blend": 0.5 }, //https://www.color-hex.com/color-palette/51090 goldenHourEnd: { "sky-color": "#5b2c6f", "sky-horizon-blend": 0.8, "horizon-color": "#e74c3c", "horizon-fog-blend": 0.8, "fog-color": "#f7dc6f", "fog-ground-blend": 0.5 }, // default (clear blue sky) solarNoon: { "sky-color": "#199EF3", "sky-horizon-blend": 0.7, "horizon-color": "#f0f8ff", "horizon-fog-blend": 0.8, "fog-color": "#2c7fb8", "fog-ground-blend": 0.9, "atmosphere-blend": ["interpolate", ["linear"], ["zoom"], 0, 1, 12, 0] }, // https://www.color-hex.com/color-palette/92854 goldenHour: { "sky-color": "#ffe90e", "sky-horizon-blend": 0.8, "horizon-color": "#ff6700", "horizon-fog-blend": 0.8, "fog-color": "#ffb400", "fog-ground-blend": 0.5 }, sunsetStart: { "sky-color": "#88C6FC", "sky-horizon-blend": 0.8, "horizon-color": "#ffe90e", "horizon-fog-blend": 0.8, "fog-color": "#ffb400", "fog-ground-blend": 0.5 }, sunset: { "sky-color": "#ffe90e", "sky-horizon-blend": 0.8, "horizon-color": "#ff6700", "horizon-fog-blend": 0.8, "fog-color": "#ffb400", "fog-ground-blend": 0.5 }, // https://www.color-hex.com/color-palette/4582 dusk: { "sky-color": "#0d0d3e", "sky-horizon-blend": 0.8, "horizon-color": "#4d2149", "horizon-fog-blend": 0.8, "fog-color": "#30016d", "fog-ground-blend": 0.5 }, // https://www.color-hex.com/color-palette/81746 nauticalDusk: { "sky-color": "#000000", "sky-horizon-blend": 0.8, "horizon-color": "#0426d0", "horizon-fog-blend": 0.8, "fog-color": "#202b7a", "fog-ground-blend": 0.5 }, // https://www.color-hex.com/color-palette/36836 night: { "sky-color": "#1e2b58", "sky-horizon-blend": 0.8, "horizon-color": "#614cbf", "horizon-fog-blend": 0.8, "fog-color": "#D4D6D8", "fog-ground-blend": 0.5 }, //https://www.color-hex.com/color-palette/62573 nadir: { "sky-color": "#3b3768", "sky-horizon-blend": 0.8, "horizon-color": "#100d36", "horizon-fog-blend": 0.8, "fog-color": "#282454", "fog-ground-blend": 0.5 }, // https://www.color-hex.com/color-palette/36836 nightEnd: { "sky-color": "#1e2b58", "sky-horizon-blend": 0.8, "horizon-color": "#614cbf", "horizon-fog-blend": 0.8, "fog-color": "#D4D6D8", "fog-ground-blend": 0.5 }, // https://www.color-hex.com/color-palette/81746 nauticalDawn: { "sky-color": "#2c2b48", "sky-horizon-blend": 0.8, "horizon-color": "#0426d0", "horizon-fog-blend": 0.8, "fog-color": "#202b7a", "fog-ground-blend": 0.5 }, // https://www.color-hex.com/color-palette/14359 dawn: { "sky-color": "#311f62", "sky-horizon-blend": 0.8, "horizon-color": "#e8817f", "horizon-fog-blend": 0.8, "fog-color": "#8d5273", "fog-ground-blend": 0.5 } }, maxPitch: 85 }; var at = { exports: {} }, Dt = at.exports, dt; function Mt() { return dt || (dt = 1, function(_, $) { (function(v, a) { _.exports = a(); })(Dt, function() { var v = 1e3, a = 6e4, m = 36e5, z = "millisecond", k = "second", O = "minute", d = "hour", h = "day", C = "week", D = "month", E = "quarter", A = "year", j = "date", u = "Invalid Date", Y = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, q = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, B = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(c) { var o = ["th", "st", "nd", "rd"], e = c % 100; return "[" + c + (o[(e - 20) % 10] || o[e] || o[0]) + "]"; } }, L = function(c, o, e) { var s = String(c); return !s || s.length >= o ? c : "" + Array(o + 1 - s.length).join(e) + c; }, tt = { s: L, z: function(c) { var o = -c.utcOffset(), e = Math.abs(o), s = Math.floor(e / 60), n = e % 60; return (o <= 0 ? "+" : "-") + L(s, 2, "0") + ":" + L(n, 2, "0"); }, m: function c(o, e) { if (o.date() < e.date()) return -c(e, o); var s = 12 * (e.year() - o.year()) + (e.month() - o.month()), n = o.clone().add(s, D), l = e - n < 0, f = o.clone().add(s + (l ? -1 : 1), D); return +(-(s + (e - n) / (l ? n - f : f - n)) || 0); }, a: function(c) { return c < 0 ? Math.ceil(c) || 0 : Math.floor(c); }, p: function(c) { return { M: D, y: A, w: C, d: h, D: j, h: d, m: O, s: k, ms: z, Q: E }[c] || String(c || "").toLowerCase().replace(/s$/, ""); }, u: function(c) { return c === void 0; } }, I = "en", J = {}; J[I] = B; var V = "$isDayjsObject", X = function(c) { return c instanceof et || !(!c || !c[V]); }, F = function c(o, e, s) { var n; if (!o) return I; if (typeof o == "string") { var l = o.toLowerCase(); J[l] && (n = l), e && (J[l] = e, n = l); var f = o.split("-"); if (!n && f.length > 1) return c(f[0]); } else { var t = o.name; J[t] = o, n = t; } return !s && n && (I = n), n || !s && I; }, M = function(c, o) { if (X(c)) return c.clone(); var e = typeof o == "object" ? o : {}; return e.date = c, e.args = arguments, new et(e); }, p = tt; p.l = F, p.i = X, p.w = function(c, o) { return M(c, { locale: o.$L, utc: o.$u, x: o.$x, $offset: o.$offset }); }; var et = function() { function c(e) { this.$L = F(e.locale, null, !0), this.parse(e), this.$x = this.$x || e.x || {}, this[V] = !0; } var o = c.prototype; return o.parse = function(e) { this.$d = function(s) { var n = s.date, l = s.utc; if (n === null) return /* @__PURE__ */ new Date(NaN); if (p.u(n)) return /* @__PURE__ */ new Date(); if (n instanceof Date) return new Date(n); if (typeof n == "string" && !/Z$/i.test(n)) { var f = n.match(Y); if (f) { var t = f[2] - 1 || 0, r = (f[7] || "0").substring(0, 3); return l ? new Date(Date.UTC(f[1], t, f[3] || 1, f[4] || 0, f[5] || 0, f[6] || 0, r)) : new Date(f[1], t, f[3] || 1, f[4] || 0, f[5] || 0, f[6] || 0, r); } } return new Date(n); }(e), this.init(); }, o.init = function() { var e = this.$d; this.$y = e.getFullYear(), this.$M = e.getMonth(), this.$D = e.getDate(), this.$W = e.getDay(), this.$H = e.getHours(), this.$m = e.getMinutes(), this.$s = e.getSeconds(), this.$ms = e.getMilliseconds(); }, o.$utils = function() { return p; }, o.isValid = function() { return this.$d.toString() !== u; }, o.isSame = function(e, s) { var n = M(e); return this.startOf(s) <= n && n <= this.endOf(s); }, o.isAfter = function(e, s) { return M(e) < this.startOf(s); }, o.isBefore = function(e, s) { return this.endOf(s) < M(e); }, o.$g = function(e, s, n) { return p.u(e) ? this[s] : this.set(n, e); }, o.unix = function() { return Math.floor(this.valueOf() / 1e3); }, o.valueOf = function() { return this.$d.getTime(); }, o.startOf = function(e, s) { var n = this, l = !!p.u(s) || s, f = p.p(e), t = function(x, T) { var H = p.w(n.$u ? Date.UTC(n.$y, T, x) : new Date(n.$y, T, x), n); return l ? H : H.endOf(h); }, r = function(x, T) { return p.w(n.toDate()[x].apply(n.toDate("s"), (l ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(T)), n); }, i = this.$W, g = this.$M, y = this.$D, S = "set" + (this.$u ? "UTC" : ""); switch (f) { case A: return l ? t(1, 0) : t(31, 11); case D: return l ? t(1, g) : t(0, g + 1); case C: var b = this.$locale().weekStart || 0, w = (i < b ? i + 7 : i) - b; return t(l ? y - w : y + (6 - w), g); case h: case j: return r(S + "Hours", 0); case d: return r(S + "Minutes", 1); case O: return r(S + "Seconds", 2); case k: return r(S + "Milliseconds", 3); default: return this.clone(); } }, o.endOf = function(e) { return this.startOf(e, !1); }, o.$set = function(e, s) { var n, l = p.p(e), f = "set" + (this.$u ? "UTC" : ""), t = (n = {}, n[h] = f + "Date", n[j] = f + "Date", n[D] = f + "Month", n[A] = f + "FullYear", n[d] = f + "Hours", n[O] = f + "Minutes", n[k] = f + "Seconds", n[z] = f + "Milliseconds", n)[l], r = l === h ? this.$D + (s - this.$W) : s; if (l === D || l === A) { var i = this.clone().set(j, 1); i.$d[t](r), i.init(), this.$d = i.set(j, Math.min(this.$D, i.daysInMonth())).$d; } else t && this.$d[t](r); return this.init(), this; }, o.set = function(e, s) { return this.clone().$set(e, s); }, o.get = function(e) { return this[p.p(e)](); }, o.add = function(e, s) { var n, l = this; e = Number(e); var f = p.p(s), t = function(g) { var y = M(l); return p.w(y.date(y.date() + Math.round(g * e)), l); }; if (f === D) return this.set(D, this.$M + e); if (f === A) return this.set(A, this.$y + e); if (f === h) return t(1); if (f === C) return t(7); var r = (n = {}, n[O] = a, n[d] = m, n[k] = v, n)[f] || 1, i = this.$d.getTime() + e * r; return p.w(i, this); }, o.subtract = function(e, s) { return this.add(-1 * e, s); }, o.format = function(e) { var s = this, n = this.$locale(); if (!this.isValid()) return n.invalidDate || u; var l = e || "YYYY-MM-DDTHH:mm:ssZ", f = p.z(this), t = this.$H, r = this.$m, i = this.$M, g = n.weekdays, y = n.months, S = n.meridiem, b = function(T, H, U, P) { return T && (T[H] || T(s, l)) || U[H].slice(0, P); }, w = function(T) { return p.s(t % 12 || 12, T, "0"); }, x = S || function(T, H, U) { var P = T < 12 ? "AM" : "PM"; return U ? P.toLowerCase() : P; }; return l.replace(q, function(T, H) { return H || function(U) { switch (U) { case "YY": return String(s.$y).slice(-2); case "YYYY": return p.s(s.$y, 4, "0"); case "M": return i + 1; case "MM": return p.s(i + 1, 2, "0"); case "MMM": return b(n.monthsShort, i, y, 3); case "MMMM": return b(y, i); case "D": return s.$D; case "DD": return p.s(s.$D, 2, "0"); case "d": return String(s.$W); case "dd": return b(n.weekdaysMin, s.$W, g, 2); case "ddd": return b(n.weekdaysShort, s.$W, g, 3); case "dddd": return g[s.$W]; case "H": return String(t); case "HH": return p.s(t, 2, "0"); case "h": return w(1); case "hh": return w(2); case "a": return x(t, r, !0); case "A": return x(t, r, !1); case "m": return String(r); case "mm": return p.s(r, 2, "0"); case "s": return String(s.$s); case "ss": return p.s(s.$s, 2, "0"); case "SSS": return p.s(s.$ms, 3, "0"); case "Z": return f; } return null; }(T) || f.replace(":", ""); }); }, o.utcOffset = function() { return 15 * -Math.round(this.$d.getTimezoneOffset() / 15); }, o.diff = function(e, s, n) { var l, f = this, t = p.p(s), r = M(e), i = (r.utcOffset() - this.utcOffset()) * a, g = this - r, y = function() { return p.m(f, r); }; switch (t) { case A: l = y() / 12; break; case D: l = y(); break; case E: l = y() / 3; break; case C: l = (g - i) / 6048e5; break; case h: l = (g - i) / 864e5; break; case d: l = g / m; break; case O: l = g / a; break; case k: l = g / v; break; default: l = g; } return n ? l : p.a(l); }, o.daysInMonth = function() { return this.endOf(D).$D; }, o.$locale = function() { return J[this.$L]; }, o.locale = function(e, s) { if (!e) return this.$L; var n = this.clone(), l = F(e, s, !0); return l && (n.$L = l), n; }, o.clone = function() { return p.w(this.$d, this); }, o.toDate = function() { return new Date(this.valueOf()); }, o.toJSON = function() { return this.isValid() ? this.toISOString() : null; }, o.toISOString = function() { return this.$d.toISOString(); }, o.toString = function() { return this.$d.toUTCString(); }, c; }(), ot = et.prototype; return M.prototype = ot, [["$ms", z], ["$s", k], ["$m", O], ["$H", d], ["$W", h], ["$M", D], ["$y", A], ["$D", j]].forEach(function(c) { ot[c[1]] = function(o) { return this.$g(o, c[0], c[1]); }; }), M.extend = function(c, o) { return c.$i || (c(o, et, M), c.$i = !0), M; }, M.locale = F, M.isDayjs = X, M.unix = function(c) { return M(1e3 * c); }, M.en = J[I], M.Ls = J, M.p = {}, M; }); }(at)), at.exports; } var kt = Mt(); const K = /* @__PURE__ */ ft(kt); var ut = { exports: {} }, St = ut.exports, ht; function Tt() { return ht || (ht = 1, function(_, $) { (function(v, a) { _.exports = a(); })(St, function() { var v = "minute", a = /[+-]\d\d(?::?\d\d)?/g, m = /([+-]|\d\d)/g; return function(z, k, O) { var d = k.prototype; O.utc = function(u) { var Y = { date: u, utc: !0, args: arguments }; return new k(Y); }, d.utc = function(u) { var Y = O(this.toDate(), { locale: this.$L, utc: !0 }); return u ? Y.add(this.utcOffset(), v) : Y; }, d.local = function() { return O(this.toDate(), { locale: this.$L, utc: !1 }); }; var h = d.parse; d.parse = function(u) { u.utc && (this.$u = !0), this.$utils().u(u.$offset) || (this.$offset = u.$offset), h.call(this, u); }; var C = d.init; d.init = function() { if (this.$u) { var u = this.$d; this.$y = u.getUTCFullYear(), this.$M = u.getUTCMonth(), this.$D = u.getUTCDate(), this.$W = u.getUTCDay(), this.$H = u.getUTCHours(), this.$m = u.getUTCMinutes(), this.$s = u.getUTCSeconds(), this.$ms = u.getUTCMilliseconds(); } else C.call(this); }; var D = d.utcOffset; d.utcOffset = function(u, Y) { var q = this.$utils().u; if (q(u)) return this.$u ? 0 : q(this.$offset) ? D.call(this) : this.$offset; if (typeof u == "string" && (u = function(I) { I === void 0 && (I = ""); var J = I.match(a); if (!J) return null; var V = ("" + J[0]).match(m) || ["-", 0, 0], X = V[0], F = 60 * +V[1] + +V[2]; return F === 0 ? 0 : X === "+" ? F : -F; }(u), u === null)) return this; var B = Math.abs(u) <= 16 ? 60 * u : u, L = this; if (Y) return L.$offset = B, L.$u = u === 0, L; if (u !== 0) { var tt = this.$u ? this.toDate().getTimezoneOffset() : -1 * this.utcOffset(); (L = this.local().add(B + tt, v)).$offset = B, L.$x.$localOffset = tt; } else L = this.utc(); return L; }; var E = d.format; d.format = function(u) { var Y = u || (this.$u ? "YYYY-MM-DDTHH:mm:ss[Z]" : ""); return E.call(this, Y); }, d.valueOf = function() { var u = this.$utils().u(this.$offset) ? 0 : this.$offset + (this.$x.$localOffset || this.$d.getTimezoneOffset()); return this.$d.valueOf() - 6e4 * u; }, d.isUTC = function() { return !!this.$u; }, d.toISOString = function() { return this.toDate().toISOString(); }, d.toString = function() { return this.toDate().toUTCString(); }; var A = d.toDate; d.toDate = function(u) { return u === "s" && this.$offset ? O(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate() : A.call(this); }; var j = d.diff; d.diff = function(u, Y, q) { if (u && this.$u === u.$u) return j.call(this, u, Y, q); var B = this.local(), L = O(u).local(); return j.call(B, L, Y, q); }; }; }); }(ut)), ut.exports; } var zt = Tt(); const Ot = /* @__PURE__ */ ft(zt); K.extend(Ot); class Ct { /** * Constructor * @param options Options object */ constructor($) { st(this, "map"); st(this, "options", bt); st(this, "addToOptions"); $ && (this.options = Object.assign(this.options, $)); } /** * Update options in the control object * @param options Options object */ setOptions($) { this.options = $; } /** * Add sky color to maplibre map object. * If options are not specified, try to find better sky color based on map center and time. * @param map Maplibre map object * @param options AddToOptions object * @returns void */ addTo($, v) { this.map = $, this.addToOptions = v, this.map.setMaxPitch(this.options.maxPitch), this.map.isStyleLoaded() ? this.updateSky() : this.map.once("load", () => { this.updateSky(); }), v != null && v.location || this.map.on("moveend", () => { this.updateSky(); }), this.map.off("styledata", this.updateSky.bind(this)), this.map.on("styledata", this.updateSky.bind(this)); } updateSky() { var v; if (!this.map) return; const $ = this.getSky(this.addToOptions); $ && ((v = this.map) == null || v.setSky($)); } /** * get maplibre SkySpecification object according to parameters * @param options AddToOptions object * @returns SkySpecification object */ getSky($) { if (!this.map) return; const v = this.options.skyOptions; if (!v) return; const a = $ == null ? void 0 : $.timeType; if (a) { const d = v[a]; return d || v.solarNoon; } let m = $ == null ? void 0 : $.location; if (!m) { const d = this.map.getCenter(); m = [d.lng, d.lat]; } let z; $ != null && $.date ? z = K($ == null ? void 0 : $.date).utc() : z = K.utc(); const k = this.getBestTimeNameByLocation( m[0], m[1], z.toDate() ); return v[k]; } /** * get suncalc times by location and date * @param lng Longitude * @param lat Latitude * @param date Date object * @param addBuffer Default is false. If ture, add yesterday and tomorrow's times * @returns */ getTimesByLocation($, v, a, m = !1) { const z = vt.getTimes(a, v, $), k = [], O = [], d = []; pt.forEach((C) => { const D = K(z[C]).utc(); if (O.push({ type: C, date: D.toDate() }), m) { const E = D.add(-1, "day"); k.push({ type: C, date: E.toDate() }); const A = D.add(1, "day"); d.push({ type: C, date: A.toDate() }); } }); let h = [...k, ...O, ...d]; return h = h.sort((C, D) => C.date.getTime() - D.date.getTime()), h; } /** * Get the best time name by using suncalc library based on given location and date * @param lng Longitude * @param lat Latitude * @param date Date * @returns active suncalc time name */ getBestTimeNameByLocation($, v, a) { const m = this.getTimesByLocation($, v, a, !0); let z = {}, k = {}; m.forEach((C) => { const D = K(C.date), E = C.type; K(D).isBefore(a) && (z.type ? K(D).isAfter(z.date) && (z = { type: E, date: D }) : z = { type: E, date: D }), K(D).isAfter(a) && (k.type ? K(D).isBefore(k.date) && (k = { type: E, date: D }) : k = { type: E, date: D }); }); const O = z.date ? a.getTime() - z.date.toDate().getTime() : -1, d = k.date ? k.date.toDate().getTime() - a.getTime() : -1; let h; return O > -1 && d > -1 ? d > O ? h = k.type : h = z.type : z && !k ? h = z.type : k && !z ? h = k.type : h = "solarNoon", h; } } export { pt as AvailableTimeTypes, Ct as SkyControl, bt as defaultSkyOptions }; //# sourceMappingURL=maplibre-gl-sky.es.js.map