sun-position
Version:
Calculate the position of the sun for a specific date, time and location. Calculate sunrise and sunset
1 lines • 223 kB
Source Map (JSON)
{"version":3,"sources":["../../from-git/browser-geo-tz/node_modules/geobuf/encode.js","../../from-git/browser-geo-tz/node_modules/geobuf/decode.js","../../from-git/browser-geo-tz/node_modules/geobuf/index.js","../../from-git/browser-geo-tz/node_modules/ieee754/index.js","../../from-git/browser-geo-tz/node_modules/pbf/index.js","../../from-git/browser-geo-tz/src/find.ts","../../from-git/browser-geo-tz/src/oceanUtils.ts","../../from-git/browser-geo-tz/node_modules/robust-predicates/esm/util.js","../../from-git/browser-geo-tz/node_modules/robust-predicates/esm/orient2d.js","../../from-git/browser-geo-tz/node_modules/robust-predicates/esm/orient3d.js","../../from-git/browser-geo-tz/node_modules/robust-predicates/esm/incircle.js","../../from-git/browser-geo-tz/node_modules/robust-predicates/esm/insphere.js","../../from-git/browser-geo-tz/node_modules/point-in-polygon-hao/dist/esm/index.js","../../from-git/browser-geo-tz/node_modules/@turf/helpers/index.ts","../../from-git/browser-geo-tz/node_modules/@turf/invariant/index.ts","../../from-git/browser-geo-tz/node_modules/@turf/boolean-point-in-polygon/index.ts","../src/utils.ts","../src/sun-position.ts"],"sourcesContent":["'use strict';\n\nmodule.exports = encode;\n\nvar keys, keysNum, keysArr, dim, e,\n maxPrecision = 1e6;\n\nvar geometryTypes = {\n 'Point': 0,\n 'MultiPoint': 1,\n 'LineString': 2,\n 'MultiLineString': 3,\n 'Polygon': 4,\n 'MultiPolygon': 5,\n 'GeometryCollection': 6\n};\n\nfunction encode(obj, pbf) {\n keys = {};\n keysArr = [];\n keysNum = 0;\n dim = 0;\n e = 1;\n\n analyze(obj);\n\n e = Math.min(e, maxPrecision);\n var precision = Math.ceil(Math.log(e) / Math.LN10);\n\n for (var i = 0; i < keysArr.length; i++) pbf.writeStringField(1, keysArr[i]);\n if (dim !== 2) pbf.writeVarintField(2, dim);\n if (precision !== 6) pbf.writeVarintField(3, precision);\n\n if (obj.type === 'FeatureCollection') pbf.writeMessage(4, writeFeatureCollection, obj);\n else if (obj.type === 'Feature') pbf.writeMessage(5, writeFeature, obj);\n else pbf.writeMessage(6, writeGeometry, obj);\n\n keys = null;\n\n return pbf.finish();\n}\n\nfunction analyze(obj) {\n var i, key;\n\n if (obj.type === 'FeatureCollection') {\n for (i = 0; i < obj.features.length; i++) analyze(obj.features[i]);\n\n } else if (obj.type === 'Feature') {\n if (obj.geometry !== null) analyze(obj.geometry);\n for (key in obj.properties) saveKey(key);\n\n } else if (obj.type === 'Point') analyzePoint(obj.coordinates);\n else if (obj.type === 'MultiPoint') analyzePoints(obj.coordinates);\n else if (obj.type === 'GeometryCollection') {\n for (i = 0; i < obj.geometries.length; i++) analyze(obj.geometries[i]);\n }\n else if (obj.type === 'LineString') analyzePoints(obj.coordinates);\n else if (obj.type === 'Polygon' || obj.type === 'MultiLineString') analyzeMultiLine(obj.coordinates);\n else if (obj.type === 'MultiPolygon') {\n for (i = 0; i < obj.coordinates.length; i++) analyzeMultiLine(obj.coordinates[i]);\n }\n\n for (key in obj) {\n if (!isSpecialKey(key, obj.type)) saveKey(key);\n }\n}\n\nfunction analyzeMultiLine(coords) {\n for (var i = 0; i < coords.length; i++) analyzePoints(coords[i]);\n}\n\nfunction analyzePoints(coords) {\n for (var i = 0; i < coords.length; i++) analyzePoint(coords[i]);\n}\n\nfunction analyzePoint(point) {\n dim = Math.max(dim, point.length);\n\n // find max precision\n for (var i = 0; i < point.length; i++) {\n while (Math.round(point[i] * e) / e !== point[i] && e < maxPrecision) e *= 10;\n }\n}\n\nfunction saveKey(key) {\n if (keys[key] === undefined) {\n keysArr.push(key);\n keys[key] = keysNum++;\n }\n}\n\nfunction writeFeatureCollection(obj, pbf) {\n for (var i = 0; i < obj.features.length; i++) {\n pbf.writeMessage(1, writeFeature, obj.features[i]);\n }\n writeProps(obj, pbf, true);\n}\n\nfunction writeFeature(feature, pbf) {\n if (feature.geometry !== null) pbf.writeMessage(1, writeGeometry, feature.geometry);\n\n if (feature.id !== undefined) {\n if (typeof feature.id === 'number' && feature.id % 1 === 0) pbf.writeSVarintField(12, feature.id);\n else pbf.writeStringField(11, feature.id);\n }\n\n if (feature.properties) writeProps(feature.properties, pbf);\n writeProps(feature, pbf, true);\n}\n\nfunction writeGeometry(geom, pbf) {\n pbf.writeVarintField(1, geometryTypes[geom.type]);\n\n var coords = geom.coordinates;\n\n if (geom.type === 'Point') writePoint(coords, pbf);\n else if (geom.type === 'MultiPoint') writeLine(coords, pbf, true);\n else if (geom.type === 'LineString') writeLine(coords, pbf);\n else if (geom.type === 'MultiLineString') writeMultiLine(coords, pbf);\n else if (geom.type === 'Polygon') writeMultiLine(coords, pbf, true);\n else if (geom.type === 'MultiPolygon') writeMultiPolygon(coords, pbf);\n else if (geom.type === 'GeometryCollection') {\n for (var i = 0; i < geom.geometries.length; i++) pbf.writeMessage(4, writeGeometry, geom.geometries[i]);\n }\n\n writeProps(geom, pbf, true);\n}\n\nfunction writeProps(props, pbf, isCustom) {\n var indexes = [],\n valueIndex = 0;\n\n for (var key in props) {\n if (isCustom && isSpecialKey(key, props.type)) {\n continue;\n }\n pbf.writeMessage(13, writeValue, props[key]);\n indexes.push(keys[key]);\n indexes.push(valueIndex++);\n }\n pbf.writePackedVarint(isCustom ? 15 : 14, indexes);\n}\n\nfunction writeValue(value, pbf) {\n if (value === null) return;\n\n var type = typeof value;\n\n if (type === 'string') pbf.writeStringField(1, value);\n else if (type === 'boolean') pbf.writeBooleanField(5, value);\n else if (type === 'object') pbf.writeStringField(6, JSON.stringify(value));\n else if (type === 'number') {\n if (value % 1 !== 0) pbf.writeDoubleField(2, value);\n else if (value >= 0) pbf.writeVarintField(3, value);\n else pbf.writeVarintField(4, -value);\n }\n}\n\nfunction writePoint(point, pbf) {\n var coords = [];\n for (var i = 0; i < dim; i++) coords.push(Math.round(point[i] * e));\n pbf.writePackedSVarint(3, coords);\n}\n\nfunction writeLine(line, pbf) {\n var coords = [];\n populateLine(coords, line);\n pbf.writePackedSVarint(3, coords);\n}\n\nfunction writeMultiLine(lines, pbf, closed) {\n var len = lines.length,\n i;\n if (len !== 1) {\n var lengths = [];\n for (i = 0; i < len; i++) lengths.push(lines[i].length - (closed ? 1 : 0));\n pbf.writePackedVarint(2, lengths);\n // TODO faster with custom writeMessage?\n }\n var coords = [];\n for (i = 0; i < len; i++) populateLine(coords, lines[i], closed);\n pbf.writePackedSVarint(3, coords);\n}\n\nfunction writeMultiPolygon(polygons, pbf) {\n var len = polygons.length,\n i, j;\n if (len !== 1 || polygons[0].length !== 1) {\n var lengths = [len];\n for (i = 0; i < len; i++) {\n lengths.push(polygons[i].length);\n for (j = 0; j < polygons[i].length; j++) lengths.push(polygons[i][j].length - 1);\n }\n pbf.writePackedVarint(2, lengths);\n }\n\n var coords = [];\n for (i = 0; i < len; i++) {\n for (j = 0; j < polygons[i].length; j++) populateLine(coords, polygons[i][j], true);\n }\n pbf.writePackedSVarint(3, coords);\n}\n\nfunction populateLine(coords, line, closed) {\n var i, j,\n len = line.length - (closed ? 1 : 0),\n sum = new Array(dim);\n for (j = 0; j < dim; j++) sum[j] = 0;\n for (i = 0; i < len; i++) {\n for (j = 0; j < dim; j++) {\n var n = Math.round(line[i][j] * e) - sum[j];\n coords.push(n);\n sum[j] += n;\n }\n }\n}\n\nfunction isSpecialKey(key, type) {\n if (key === 'type') return true;\n else if (type === 'FeatureCollection') {\n if (key === 'features') return true;\n } else if (type === 'Feature') {\n if (key === 'id' || key === 'properties' || key === 'geometry') return true;\n } else if (type === 'GeometryCollection') {\n if (key === 'geometries') return true;\n } else if (key === 'coordinates') return true;\n return false;\n}\n","'use strict';\n\nmodule.exports = decode;\n\nvar keys, values, lengths, dim, e;\n\nvar geometryTypes = [\n 'Point', 'MultiPoint', 'LineString', 'MultiLineString',\n 'Polygon', 'MultiPolygon', 'GeometryCollection'];\n\nfunction decode(pbf) {\n dim = 2;\n e = Math.pow(10, 6);\n lengths = null;\n\n keys = [];\n values = [];\n var obj = pbf.readFields(readDataField, {});\n keys = null;\n\n return obj;\n}\n\nfunction readDataField(tag, obj, pbf) {\n if (tag === 1) keys.push(pbf.readString());\n else if (tag === 2) dim = pbf.readVarint();\n else if (tag === 3) e = Math.pow(10, pbf.readVarint());\n\n else if (tag === 4) readFeatureCollection(pbf, obj);\n else if (tag === 5) readFeature(pbf, obj);\n else if (tag === 6) readGeometry(pbf, obj);\n}\n\nfunction readFeatureCollection(pbf, obj) {\n obj.type = 'FeatureCollection';\n obj.features = [];\n return pbf.readMessage(readFeatureCollectionField, obj);\n}\n\nfunction readFeature(pbf, feature) {\n feature.type = 'Feature';\n var f = pbf.readMessage(readFeatureField, feature);\n if (!('geometry' in f)) f.geometry = null;\n return f;\n}\n\nfunction readGeometry(pbf, geom) {\n geom.type = 'Point';\n return pbf.readMessage(readGeometryField, geom);\n}\n\nfunction readFeatureCollectionField(tag, obj, pbf) {\n if (tag === 1) obj.features.push(readFeature(pbf, {}));\n\n else if (tag === 13) values.push(readValue(pbf));\n else if (tag === 15) readProps(pbf, obj);\n}\n\nfunction readFeatureField(tag, feature, pbf) {\n if (tag === 1) feature.geometry = readGeometry(pbf, {});\n\n else if (tag === 11) feature.id = pbf.readString();\n else if (tag === 12) feature.id = pbf.readSVarint();\n\n else if (tag === 13) values.push(readValue(pbf));\n else if (tag === 14) feature.properties = readProps(pbf, {});\n else if (tag === 15) readProps(pbf, feature);\n}\n\nfunction readGeometryField(tag, geom, pbf) {\n if (tag === 1) geom.type = geometryTypes[pbf.readVarint()];\n\n else if (tag === 2) lengths = pbf.readPackedVarint();\n else if (tag === 3) readCoords(geom, pbf, geom.type);\n else if (tag === 4) {\n geom.geometries = geom.geometries || [];\n geom.geometries.push(readGeometry(pbf, {}));\n }\n else if (tag === 13) values.push(readValue(pbf));\n else if (tag === 15) readProps(pbf, geom);\n}\n\nfunction readCoords(geom, pbf, type) {\n if (type === 'Point') geom.coordinates = readPoint(pbf);\n else if (type === 'MultiPoint') geom.coordinates = readLine(pbf, true);\n else if (type === 'LineString') geom.coordinates = readLine(pbf);\n else if (type === 'MultiLineString') geom.coordinates = readMultiLine(pbf);\n else if (type === 'Polygon') geom.coordinates = readMultiLine(pbf, true);\n else if (type === 'MultiPolygon') geom.coordinates = readMultiPolygon(pbf);\n}\n\nfunction readValue(pbf) {\n var end = pbf.readVarint() + pbf.pos,\n value = null;\n\n while (pbf.pos < end) {\n var val = pbf.readVarint(),\n tag = val >> 3;\n\n if (tag === 1) value = pbf.readString();\n else if (tag === 2) value = pbf.readDouble();\n else if (tag === 3) value = pbf.readVarint();\n else if (tag === 4) value = -pbf.readVarint();\n else if (tag === 5) value = pbf.readBoolean();\n else if (tag === 6) value = JSON.parse(pbf.readString());\n }\n return value;\n}\n\nfunction readProps(pbf, props) {\n var end = pbf.readVarint() + pbf.pos;\n while (pbf.pos < end) props[keys[pbf.readVarint()]] = values[pbf.readVarint()];\n values = [];\n return props;\n}\n\nfunction readPoint(pbf) {\n var end = pbf.readVarint() + pbf.pos,\n coords = [];\n while (pbf.pos < end) coords.push(pbf.readSVarint() / e);\n return coords;\n}\n\nfunction readLinePart(pbf, end, len, closed) {\n var i = 0,\n coords = [],\n p, d;\n\n var prevP = [];\n for (d = 0; d < dim; d++) prevP[d] = 0;\n\n while (len ? i < len : pbf.pos < end) {\n p = [];\n for (d = 0; d < dim; d++) {\n prevP[d] += pbf.readSVarint();\n p[d] = prevP[d] / e;\n }\n coords.push(p);\n i++;\n }\n if (closed) coords.push(coords[0]);\n\n return coords;\n}\n\nfunction readLine(pbf) {\n return readLinePart(pbf, pbf.readVarint() + pbf.pos);\n}\n\nfunction readMultiLine(pbf, closed) {\n var end = pbf.readVarint() + pbf.pos;\n if (!lengths) return [readLinePart(pbf, end, null, closed)];\n\n var coords = [];\n for (var i = 0; i < lengths.length; i++) coords.push(readLinePart(pbf, end, lengths[i], closed));\n lengths = null;\n return coords;\n}\n\nfunction readMultiPolygon(pbf) {\n var end = pbf.readVarint() + pbf.pos;\n if (!lengths) return [[readLinePart(pbf, end, null, true)]];\n\n var coords = [];\n var j = 1;\n for (var i = 0; i < lengths[0]; i++) {\n var rings = [];\n for (var k = 0; k < lengths[j]; k++) rings.push(readLinePart(pbf, end, lengths[j + 1 + k], true));\n j += lengths[j] + 1;\n coords.push(rings);\n }\n lengths = null;\n return coords;\n}\n","'use strict';\n\nexports.encode = require('./encode');\nexports.decode = require('./decode');\n","/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */\nexports.read = function (buffer, offset, isLE, mLen, nBytes) {\n var e, m\n var eLen = (nBytes * 8) - mLen - 1\n var eMax = (1 << eLen) - 1\n var eBias = eMax >> 1\n var nBits = -7\n var i = isLE ? (nBytes - 1) : 0\n var d = isLE ? -1 : 1\n var s = buffer[offset + i]\n\n i += d\n\n e = s & ((1 << (-nBits)) - 1)\n s >>= (-nBits)\n nBits += eLen\n for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}\n\n m = e & ((1 << (-nBits)) - 1)\n e >>= (-nBits)\n nBits += mLen\n for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}\n\n if (e === 0) {\n e = 1 - eBias\n } else if (e === eMax) {\n return m ? NaN : ((s ? -1 : 1) * Infinity)\n } else {\n m = m + Math.pow(2, mLen)\n e = e - eBias\n }\n return (s ? -1 : 1) * m * Math.pow(2, e - mLen)\n}\n\nexports.write = function (buffer, value, offset, isLE, mLen, nBytes) {\n var e, m, c\n var eLen = (nBytes * 8) - mLen - 1\n var eMax = (1 << eLen) - 1\n var eBias = eMax >> 1\n var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)\n var i = isLE ? 0 : (nBytes - 1)\n var d = isLE ? 1 : -1\n var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0\n\n value = Math.abs(value)\n\n if (isNaN(value) || value === Infinity) {\n m = isNaN(value) ? 1 : 0\n e = eMax\n } else {\n e = Math.floor(Math.log(value) / Math.LN2)\n if (value * (c = Math.pow(2, -e)) < 1) {\n e--\n c *= 2\n }\n if (e + eBias >= 1) {\n value += rt / c\n } else {\n value += rt * Math.pow(2, 1 - eBias)\n }\n if (value * c >= 2) {\n e++\n c /= 2\n }\n\n if (e + eBias >= eMax) {\n m = 0\n e = eMax\n } else if (e + eBias >= 1) {\n m = ((value * c) - 1) * Math.pow(2, mLen)\n e = e + eBias\n } else {\n m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)\n e = 0\n }\n }\n\n for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}\n\n e = (e << mLen) | m\n eLen += mLen\n for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}\n\n buffer[offset + i - d] |= s * 128\n}\n","'use strict';\n\nmodule.exports = Pbf;\n\nvar ieee754 = require('ieee754');\n\nfunction Pbf(buf) {\n this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);\n this.pos = 0;\n this.type = 0;\n this.length = this.buf.length;\n}\n\nPbf.Varint = 0; // varint: int32, int64, uint32, uint64, sint32, sint64, bool, enum\nPbf.Fixed64 = 1; // 64-bit: double, fixed64, sfixed64\nPbf.Bytes = 2; // length-delimited: string, bytes, embedded messages, packed repeated fields\nPbf.Fixed32 = 5; // 32-bit: float, fixed32, sfixed32\n\nvar SHIFT_LEFT_32 = (1 << 16) * (1 << 16),\n SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;\n\n// Threshold chosen based on both benchmarking and knowledge about browser string\n// data structures (which currently switch structure types at 12 bytes or more)\nvar TEXT_DECODER_MIN_LENGTH = 12;\nvar utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf8');\n\nPbf.prototype = {\n\n destroy: function() {\n this.buf = null;\n },\n\n // === READING =================================================================\n\n readFields: function(readField, result, end) {\n end = end || this.length;\n\n while (this.pos < end) {\n var val = this.readVarint(),\n tag = val >> 3,\n startPos = this.pos;\n\n this.type = val & 0x7;\n readField(tag, result, this);\n\n if (this.pos === startPos) this.skip(val);\n }\n return result;\n },\n\n readMessage: function(readField, result) {\n return this.readFields(readField, result, this.readVarint() + this.pos);\n },\n\n readFixed32: function() {\n var val = readUInt32(this.buf, this.pos);\n this.pos += 4;\n return val;\n },\n\n readSFixed32: function() {\n var val = readInt32(this.buf, this.pos);\n this.pos += 4;\n return val;\n },\n\n // 64-bit int handling is based on github.com/dpw/node-buffer-more-ints (MIT-licensed)\n\n readFixed64: function() {\n var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;\n this.pos += 8;\n return val;\n },\n\n readSFixed64: function() {\n var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;\n this.pos += 8;\n return val;\n },\n\n readFloat: function() {\n var val = ieee754.read(this.buf, this.pos, true, 23, 4);\n this.pos += 4;\n return val;\n },\n\n readDouble: function() {\n var val = ieee754.read(this.buf, this.pos, true, 52, 8);\n this.pos += 8;\n return val;\n },\n\n readVarint: function(isSigned) {\n var buf = this.buf,\n val, b;\n\n b = buf[this.pos++]; val = b & 0x7f; if (b < 0x80) return val;\n b = buf[this.pos++]; val |= (b & 0x7f) << 7; if (b < 0x80) return val;\n b = buf[this.pos++]; val |= (b & 0x7f) << 14; if (b < 0x80) return val;\n b = buf[this.pos++]; val |= (b & 0x7f) << 21; if (b < 0x80) return val;\n b = buf[this.pos]; val |= (b & 0x0f) << 28;\n\n return readVarintRemainder(val, isSigned, this);\n },\n\n readVarint64: function() { // for compatibility with v2.0.1\n return this.readVarint(true);\n },\n\n readSVarint: function() {\n var num = this.readVarint();\n return num % 2 === 1 ? (num + 1) / -2 : num / 2; // zigzag encoding\n },\n\n readBoolean: function() {\n return Boolean(this.readVarint());\n },\n\n readString: function() {\n var end = this.readVarint() + this.pos;\n var pos = this.pos;\n this.pos = end;\n\n if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {\n // longer strings are fast with the built-in browser TextDecoder API\n return readUtf8TextDecoder(this.buf, pos, end);\n }\n // short strings are fast with our custom implementation\n return readUtf8(this.buf, pos, end);\n },\n\n readBytes: function() {\n var end = this.readVarint() + this.pos,\n buffer = this.buf.subarray(this.pos, end);\n this.pos = end;\n return buffer;\n },\n\n // verbose for performance reasons; doesn't affect gzipped size\n\n readPackedVarint: function(arr, isSigned) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readVarint(isSigned));\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readVarint(isSigned));\n return arr;\n },\n readPackedSVarint: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readSVarint());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readSVarint());\n return arr;\n },\n readPackedBoolean: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readBoolean());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readBoolean());\n return arr;\n },\n readPackedFloat: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readFloat());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readFloat());\n return arr;\n },\n readPackedDouble: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readDouble());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readDouble());\n return arr;\n },\n readPackedFixed32: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readFixed32());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readFixed32());\n return arr;\n },\n readPackedSFixed32: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readSFixed32());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readSFixed32());\n return arr;\n },\n readPackedFixed64: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readFixed64());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readFixed64());\n return arr;\n },\n readPackedSFixed64: function(arr) {\n if (this.type !== Pbf.Bytes) return arr.push(this.readSFixed64());\n var end = readPackedEnd(this);\n arr = arr || [];\n while (this.pos < end) arr.push(this.readSFixed64());\n return arr;\n },\n\n skip: function(val) {\n var type = val & 0x7;\n if (type === Pbf.Varint) while (this.buf[this.pos++] > 0x7f) {}\n else if (type === Pbf.Bytes) this.pos = this.readVarint() + this.pos;\n else if (type === Pbf.Fixed32) this.pos += 4;\n else if (type === Pbf.Fixed64) this.pos += 8;\n else throw new Error('Unimplemented type: ' + type);\n },\n\n // === WRITING =================================================================\n\n writeTag: function(tag, type) {\n this.writeVarint((tag << 3) | type);\n },\n\n realloc: function(min) {\n var length = this.length || 16;\n\n while (length < this.pos + min) length *= 2;\n\n if (length !== this.length) {\n var buf = new Uint8Array(length);\n buf.set(this.buf);\n this.buf = buf;\n this.length = length;\n }\n },\n\n finish: function() {\n this.length = this.pos;\n this.pos = 0;\n return this.buf.subarray(0, this.length);\n },\n\n writeFixed32: function(val) {\n this.realloc(4);\n writeInt32(this.buf, val, this.pos);\n this.pos += 4;\n },\n\n writeSFixed32: function(val) {\n this.realloc(4);\n writeInt32(this.buf, val, this.pos);\n this.pos += 4;\n },\n\n writeFixed64: function(val) {\n this.realloc(8);\n writeInt32(this.buf, val & -1, this.pos);\n writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);\n this.pos += 8;\n },\n\n writeSFixed64: function(val) {\n this.realloc(8);\n writeInt32(this.buf, val & -1, this.pos);\n writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);\n this.pos += 8;\n },\n\n writeVarint: function(val) {\n val = +val || 0;\n\n if (val > 0xfffffff || val < 0) {\n writeBigVarint(val, this);\n return;\n }\n\n this.realloc(4);\n\n this.buf[this.pos++] = val & 0x7f | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;\n this.buf[this.pos++] = ((val >>>= 7) & 0x7f) | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;\n this.buf[this.pos++] = ((val >>>= 7) & 0x7f) | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;\n this.buf[this.pos++] = (val >>> 7) & 0x7f;\n },\n\n writeSVarint: function(val) {\n this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);\n },\n\n writeBoolean: function(val) {\n this.writeVarint(Boolean(val));\n },\n\n writeString: function(str) {\n str = String(str);\n this.realloc(str.length * 4);\n\n this.pos++; // reserve 1 byte for short string length\n\n var startPos = this.pos;\n // write the string directly to the buffer and see how much was written\n this.pos = writeUtf8(this.buf, str, this.pos);\n var len = this.pos - startPos;\n\n if (len >= 0x80) makeRoomForExtraLength(startPos, len, this);\n\n // finally, write the message length in the reserved place and restore the position\n this.pos = startPos - 1;\n this.writeVarint(len);\n this.pos += len;\n },\n\n writeFloat: function(val) {\n this.realloc(4);\n ieee754.write(this.buf, val, this.pos, true, 23, 4);\n this.pos += 4;\n },\n\n writeDouble: function(val) {\n this.realloc(8);\n ieee754.write(this.buf, val, this.pos, true, 52, 8);\n this.pos += 8;\n },\n\n writeBytes: function(buffer) {\n var len = buffer.length;\n this.writeVarint(len);\n this.realloc(len);\n for (var i = 0; i < len; i++) this.buf[this.pos++] = buffer[i];\n },\n\n writeRawMessage: function(fn, obj) {\n this.pos++; // reserve 1 byte for short message length\n\n // write the message directly to the buffer and see how much was written\n var startPos = this.pos;\n fn(obj, this);\n var len = this.pos - startPos;\n\n if (len >= 0x80) makeRoomForExtraLength(startPos, len, this);\n\n // finally, write the message length in the reserved place and restore the position\n this.pos = startPos - 1;\n this.writeVarint(len);\n this.pos += len;\n },\n\n writeMessage: function(tag, fn, obj) {\n this.writeTag(tag, Pbf.Bytes);\n this.writeRawMessage(fn, obj);\n },\n\n writePackedVarint: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedVarint, arr); },\n writePackedSVarint: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSVarint, arr); },\n writePackedBoolean: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedBoolean, arr); },\n writePackedFloat: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFloat, arr); },\n writePackedDouble: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedDouble, arr); },\n writePackedFixed32: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFixed32, arr); },\n writePackedSFixed32: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSFixed32, arr); },\n writePackedFixed64: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFixed64, arr); },\n writePackedSFixed64: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSFixed64, arr); },\n\n writeBytesField: function(tag, buffer) {\n this.writeTag(tag, Pbf.Bytes);\n this.writeBytes(buffer);\n },\n writeFixed32Field: function(tag, val) {\n this.writeTag(tag, Pbf.Fixed32);\n this.writeFixed32(val);\n },\n writeSFixed32Field: function(tag, val) {\n this.writeTag(tag, Pbf.Fixed32);\n this.writeSFixed32(val);\n },\n writeFixed64Field: function(tag, val) {\n this.writeTag(tag, Pbf.Fixed64);\n this.writeFixed64(val);\n },\n writeSFixed64Field: function(tag, val) {\n this.writeTag(tag, Pbf.Fixed64);\n this.writeSFixed64(val);\n },\n writeVarintField: function(tag, val) {\n this.writeTag(tag, Pbf.Varint);\n this.writeVarint(val);\n },\n writeSVarintField: function(tag, val) {\n this.writeTag(tag, Pbf.Varint);\n this.writeSVarint(val);\n },\n writeStringField: function(tag, str) {\n this.writeTag(tag, Pbf.Bytes);\n this.writeString(str);\n },\n writeFloatField: function(tag, val) {\n this.writeTag(tag, Pbf.Fixed32);\n this.writeFloat(val);\n },\n writeDoubleField: function(tag, val) {\n this.writeTag(tag, Pbf.Fixed64);\n this.writeDouble(val);\n },\n writeBooleanField: function(tag, val) {\n this.writeVarintField(tag, Boolean(val));\n }\n};\n\nfunction readVarintRemainder(l, s, p) {\n var buf = p.buf,\n h, b;\n\n b = buf[p.pos++]; h = (b & 0x70) >> 4; if (b < 0x80) return toNum(l, h, s);\n b = buf[p.pos++]; h |= (b & 0x7f) << 3; if (b < 0x80) return toNum(l, h, s);\n b = buf[p.pos++]; h |= (b & 0x7f) << 10; if (b < 0x80) return toNum(l, h, s);\n b = buf[p.pos++]; h |= (b & 0x7f) << 17; if (b < 0x80) return toNum(l, h, s);\n b = buf[p.pos++]; h |= (b & 0x7f) << 24; if (b < 0x80) return toNum(l, h, s);\n b = buf[p.pos++]; h |= (b & 0x01) << 31; if (b < 0x80) return toNum(l, h, s);\n\n throw new Error('Expected varint not more than 10 bytes');\n}\n\nfunction readPackedEnd(pbf) {\n return pbf.type === Pbf.Bytes ?\n pbf.readVarint() + pbf.pos : pbf.pos + 1;\n}\n\nfunction toNum(low, high, isSigned) {\n if (isSigned) {\n return high * 0x100000000 + (low >>> 0);\n }\n\n return ((high >>> 0) * 0x100000000) + (low >>> 0);\n}\n\nfunction writeBigVarint(val, pbf) {\n var low, high;\n\n if (val >= 0) {\n low = (val % 0x100000000) | 0;\n high = (val / 0x100000000) | 0;\n } else {\n low = ~(-val % 0x100000000);\n high = ~(-val / 0x100000000);\n\n if (low ^ 0xffffffff) {\n low = (low + 1) | 0;\n } else {\n low = 0;\n high = (high + 1) | 0;\n }\n }\n\n if (val >= 0x10000000000000000 || val < -0x10000000000000000) {\n throw new Error('Given varint doesn\\'t fit into 10 bytes');\n }\n\n pbf.realloc(10);\n\n writeBigVarintLow(low, high, pbf);\n writeBigVarintHigh(high, pbf);\n}\n\nfunction writeBigVarintLow(low, high, pbf) {\n pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;\n pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;\n pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;\n pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;\n pbf.buf[pbf.pos] = low & 0x7f;\n}\n\nfunction writeBigVarintHigh(high, pbf) {\n var lsb = (high & 0x07) << 4;\n\n pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 0x80 : 0); if (!high) return;\n pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;\n pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;\n pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;\n pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;\n pbf.buf[pbf.pos++] = high & 0x7f;\n}\n\nfunction makeRoomForExtraLength(startPos, len, pbf) {\n var extraLen =\n len <= 0x3fff ? 1 :\n len <= 0x1fffff ? 2 :\n len <= 0xfffffff ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));\n\n // if 1 byte isn't enough for encoding message length, shift the data to the right\n pbf.realloc(extraLen);\n for (var i = pbf.pos - 1; i >= startPos; i--) pbf.buf[i + extraLen] = pbf.buf[i];\n}\n\nfunction writePackedVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeVarint(arr[i]); }\nfunction writePackedSVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSVarint(arr[i]); }\nfunction writePackedFloat(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFloat(arr[i]); }\nfunction writePackedDouble(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeDouble(arr[i]); }\nfunction writePackedBoolean(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeBoolean(arr[i]); }\nfunction writePackedFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed32(arr[i]); }\nfunction writePackedSFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed32(arr[i]); }\nfunction writePackedFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed64(arr[i]); }\nfunction writePackedSFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed64(arr[i]); }\n\n// Buffer code below from https://github.com/feross/buffer, MIT-licensed\n\nfunction readUInt32(buf, pos) {\n return ((buf[pos]) |\n (buf[pos + 1] << 8) |\n (buf[pos + 2] << 16)) +\n (buf[pos + 3] * 0x1000000);\n}\n\nfunction writeInt32(buf, val, pos) {\n buf[pos] = val;\n buf[pos + 1] = (val >>> 8);\n buf[pos + 2] = (val >>> 16);\n buf[pos + 3] = (val >>> 24);\n}\n\nfunction readInt32(buf, pos) {\n return ((buf[pos]) |\n (buf[pos + 1] << 8) |\n (buf[pos + 2] << 16)) +\n (buf[pos + 3] << 24);\n}\n\nfunction readUtf8(buf, pos, end) {\n var str = '';\n var i = pos;\n\n while (i < end) {\n var b0 = buf[i];\n var c = null; // codepoint\n var bytesPerSequence =\n b0 > 0xEF ? 4 :\n b0 > 0xDF ? 3 :\n b0 > 0xBF ? 2 : 1;\n\n if (i + bytesPerSequence > end) break;\n\n var b1, b2, b3;\n\n if (bytesPerSequence === 1) {\n if (b0 < 0x80) {\n c = b0;\n }\n } else if (bytesPerSequence === 2) {\n b1 = buf[i + 1];\n if ((b1 & 0xC0) === 0x80) {\n c = (b0 & 0x1F) << 0x6 | (b1 & 0x3F);\n if (c <= 0x7F) {\n c = null;\n }\n }\n } else if (bytesPerSequence === 3) {\n b1 = buf[i + 1];\n b2 = buf[i + 2];\n if ((b1 & 0xC0) === 0x80 && (b2 & 0xC0) === 0x80) {\n c = (b0 & 0xF) << 0xC | (b1 & 0x3F) << 0x6 | (b2 & 0x3F);\n if (c <= 0x7FF || (c >= 0xD800 && c <= 0xDFFF)) {\n c = null;\n }\n }\n } else if (bytesPerSequence === 4) {\n b1 = buf[i + 1];\n b2 = buf[i + 2];\n b3 = buf[i + 3];\n if ((b1 & 0xC0) === 0x80 && (b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80) {\n c = (b0 & 0xF) << 0x12 | (b1 & 0x3F) << 0xC | (b2 & 0x3F) << 0x6 | (b3 & 0x3F);\n if (c <= 0xFFFF || c >= 0x110000) {\n c = null;\n }\n }\n }\n\n if (c === null) {\n c = 0xFFFD;\n bytesPerSequence = 1;\n\n } else if (c > 0xFFFF) {\n c -= 0x10000;\n str += String.fromCharCode(c >>> 10 & 0x3FF | 0xD800);\n c = 0xDC00 | c & 0x3FF;\n }\n\n str += String.fromCharCode(c);\n i += bytesPerSequence;\n }\n\n return str;\n}\n\nfunction readUtf8TextDecoder(buf, pos, end) {\n return utf8TextDecoder.decode(buf.subarray(pos, end));\n}\n\nfunction writeUtf8(buf, str, pos) {\n for (var i = 0, c, lead; i < str.length; i++) {\n c = str.charCodeAt(i); // code point\n\n if (c > 0xD7FF && c < 0xE000) {\n if (lead) {\n if (c < 0xDC00) {\n buf[pos++] = 0xEF;\n buf[pos++] = 0xBF;\n buf[pos++] = 0xBD;\n lead = c;\n continue;\n } else {\n c = lead - 0xD800 << 10 | c - 0xDC00 | 0x10000;\n lead = null;\n }\n } else {\n if (c > 0xDBFF || (i + 1 === str.length)) {\n buf[pos++] = 0xEF;\n buf[pos++] = 0xBF;\n buf[pos++] = 0xBD;\n } else {\n lead = c;\n }\n continue;\n }\n } else if (lead) {\n buf[pos++] = 0xEF;\n buf[pos++] = 0xBF;\n buf[pos++] = 0xBD;\n lead = null;\n }\n\n if (c < 0x80) {\n buf[pos++] = c;\n } else {\n if (c < 0x800) {\n buf[pos++] = c >> 0x6 | 0xC0;\n } else {\n if (c < 0x10000) {\n buf[pos++] = c >> 0xC | 0xE0;\n } else {\n buf[pos++] = c >> 0x12 | 0xF0;\n buf[pos++] = c >> 0xC & 0x3F | 0x80;\n }\n buf[pos++] = c >> 0x6 & 0x3F | 0x80;\n }\n buf[pos++] = c & 0x3F | 0x80;\n }\n }\n return pos;\n}\n","import { decode } from \"geobuf\";\r\nimport inside from \"@turf/boolean-point-in-polygon\";\r\nimport { point } from \"@turf/helpers\";\r\nimport Pbf from \"pbf\";\r\n\r\nimport { getTimezoneAtSea, oceanZones } from \"./oceanUtils\";\r\n\r\ntype GeoDataSource =\r\n | string\r\n | ((start: number, end: number) => Promise<ArrayBuffer>);\r\ntype TzDataSource = string | (() => Promise<any>);\r\n\r\n/**\r\n * Initialize the GeoTZ module with the given data sources.\r\n *\r\n * @param geoDataSource A string of the URL of the GeoJSON data or a function that returns an ArrayBuffer given a byte range.\r\n * @param tzDataSource A string of the URL of the index.json data or a function that returns an object.\r\n * @returns An object with a find function that can be used to find the timezone ID(s) at the given GPS coordinates.\r\n */\r\nexport function init(\r\n geoDataSource: GeoDataSource = \"https://cdn.jsdelivr.net/npm/geo-tz@latest/data/timezones-1970.geojson.geo.dat\",\r\n tzDataSource: TzDataSource = \"https://cdn.jsdelivr.net/npm/geo-tz@latest/data/timezones-1970.geojson.index.json\",\r\n) {\r\n const geoData =\r\n typeof geoDataSource === \"string\"\r\n ? async (start: number, end: number) => {\r\n const response = await fetch(geoDataSource, {\r\n headers: { Range: `bytes=${start}-${end}` },\r\n });\r\n return await response.arrayBuffer();\r\n }\r\n : geoDataSource;\r\n\r\n let tzDataPromise: Promise<any> | null = null;\r\n\r\n const tzData =\r\n typeof tzDataSource === \"string\"\r\n ? async () => {\r\n if (tzDataPromise) {\r\n return await tzDataPromise;\r\n }\r\n const promise = fetch(tzDataSource).then((response) =>\r\n response.json(),\r\n );\r\n tzDataPromise = promise;\r\n return await promise;\r\n }\r\n : tzDataSource;\r\n\r\n return {\r\n /**\r\n * Find the timezone ID(s) at the given GPS coordinates.\r\n *\r\n * @param lat latitude (must be >= -90 and <=90)\r\n * @param lon longitue (must be >= -180 and <=180)\r\n * @returns An array of string of TZIDs at the given coordinate.\r\n */\r\n find: async (lat: number, lon: number) => {\r\n return await findImpl(geoData, tzData, lat, lon);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Find the timezone ID(s) at the given GPS coordinates. This is identical to calling\r\n * `init()` and then calling `find()`.\r\n *\r\n * @param lat latitude (must be >= -90 and <=90)\r\n * @param lon longitue (must be >= -180 and <=180)\r\n * @returns An array of string of TZIDs at the given coordinate.\r\n */\r\nexport async function find(lat: number, lon: number): Promise<string[]> {\r\n return await init().find(lat, lon);\r\n}\r\n\r\nasync function findImpl(\r\n geoData: (start: number, end: number) => Promise<ArrayBuffer>,\r\n tzData: () => Promise<any>,\r\n lat: number,\r\n lon: number,\r\n): Promise<string[]> {\r\n const originalLon = lon;\r\n\r\n let err;\r\n\r\n // validate latitude\r\n if (isNaN(lat) || lat > 90 || lat < -90) {\r\n err = new Error(\"Invalid latitude: \" + lat);\r\n throw err;\r\n }\r\n\r\n // validate longitude\r\n if (isNaN(lon) || lon > 180 || lon < -180) {\r\n err = new Error(\"Invalid longitude: \" + lon);\r\n throw err;\r\n }\r\n\r\n // North Pole should return all ocean zones\r\n if (lat === 90) {\r\n return oceanZones.map((zone) => zone.tzid);\r\n }\r\n\r\n // fix edges of the world\r\n if (lat >= 89.9999) {\r\n lat = 89.9999;\r\n } else if (lat <= -89.9999) {\r\n lat = -89.9999;\r\n }\r\n\r\n if (lon >= 179.9999) {\r\n lon = 179.9999;\r\n } else if (lon <= -179.9999) {\r\n lon = -179.9999;\r\n }\r\n\r\n const pt = point([lon, lat]);\r\n\r\n // get exact boundaries\r\n const quadData = {\r\n top: 89.9999,\r\n bottom: -89.9999,\r\n left: -179.9999,\r\n right: 179.9999,\r\n midLat: 0,\r\n midLon: 0,\r\n };\r\n let quadPos = \"\";\r\n\r\n const tzDataResponse = await tzData();\r\n\r\n let curTzData = tzDataResponse.lookup;\r\n\r\n while (true) {\r\n // calculate next quadtree position\r\n let nextQuad;\r\n if (lat >= quadData.midLat && lon >= quadData.midLon) {\r\n nextQuad = \"a\";\r\n quadData.bottom = quadData.midLat;\r\n quadData.left = quadData.midLon;\r\n } else if (lat >= quadData.midLat && lon < quadData.midLon) {\r\n nextQuad = \"b\";\r\n quadData.bottom = quadData.midLat;\r\n quadData.right = quadData.midLon;\r\n } else if (lat < quadData.midLat && lon < quadData.midLon) {\r\n nextQuad = \"c\";\r\n quadData.top = quadData.midLat;\r\n quadData.right = quadData.midLon;\r\n } else {\r\n nextQuad = \"d\";\r\n quadData.top = quadData.midLat;\r\n quadData.left = quadData.midLon;\r\n }\r\n\r\n // console.log(nextQuad)\r\n curTzData = curTzData[nextQuad];\r\n // console.log()\r\n quadPos += nextQuad;\r\n\r\n // analyze result of current depth\r\n if (!curTzData) {\r\n // no timezone in this quad, therefore must be timezone at sea\r\n return getTimezoneAtSea(originalLon);\r\n } else if (curTzData.pos >= 0 && curTzData.len) {\r\n // get exact boundaries\r\n const bufSlice = await geoData(\r\n curTzData.pos,\r\n curTzData.pos + curTzData.len - 1,\r\n );\r\n const geoJson = decode(new Pbf(bufSlice));\r\n\r\n const timezonesContainingPoint = [];\r\n\r\n if (geoJson.type === \"FeatureCollection\") {\r\n for (let i = 0; i < geoJson.features.length; i++) {\r\n if (inside(pt, geoJson.features[i] as any)) {\r\n const properties = geoJson.features[i].properties;\r\n if (properties) {\r\n timezonesContainingPoint.push(properties.tzid);\r\n }\r\n }\r\n }\r\n } else if (geoJson.type === \"Feature\") {\r\n if (inside(pt, geoJson as any) && geoJson.properties) {\r\n timezonesContainingPoint.push(geoJson.properties.tzid);\r\n }\r\n }\r\n\r\n // if at least one timezone contained the point, return those timezones,\r\n // otherwise must be timezone at sea\r\n return timezonesContainingPoint.length > 0\r\n ? timezonesContainingPoint\r\n : getTimezoneAtSea(originalLon);\r\n } else if (curTzData.length > 0) {\r\n // exact match found\r\n const timezones = tzDataResponse.timezones;\r\n return curTzData.map((idx: number) => timezones[idx]);\r\n } else if (typeof curTzData !== \"object\") {\r\n // not another nested quad index, throw error\r\n err = new Error(\"Unexpected data type\");\r\n throw err;\r\n }\r\n\r\n // calculate next quadtree depth data\r\n quadData.midLat = (quadData.top + quadData.bottom) / 2;\r\n quadData.midLon = (quadData.left + quadData.right) / 2;\r\n }\r\n}\r\n\r\nexport function toOffset(timeZone: string) {\r\n const date = new Date();\r\n const utcDate = new Date(date.toLocaleString(\"en-US\", { timeZone: \"UTC\" }));\r\n const tzDate = new Date(date.toLocaleString(\"en-US\", { timeZone }));\r\n return (tzDate.getTime() - utcDate.getTime()) / 6e4;\r\n}\r\n","type OceanZone = {\r\n left: number\r\n right: number\r\n tzid: string\r\n}\r\n\r\nexport const oceanZones: OceanZone[] = [\r\n { tzid: 'Etc/GMT-12', left: 172.5, right: 180 },\r\n { tzid: 'Etc/GMT-11', left: 157.5, right: 172.5 },\r\n { tzid: 'Etc/GMT-10', left: 142.5, right: 157.5 },\r\n { tzid: 'Etc/GMT-9', left: 127.5, right: 142.5 },\r\n { tzid: 'Etc/GMT-8', left: 112.5, right: 127.5 },\r\n { tzid: 'Etc/GMT-7', left: 97.5, right: 112.5 },\r\n { tzid: 'Etc/GMT-6', left: 82.5, right: 97.5 },\r\n { tzid: 'Etc/GMT-5', left: 67.5, right: 82.5 },\r\n { tzid: 'Etc/GMT-4', left: 52.5, right: 67.5 },\r\n { tzid: 'Etc/GMT-3', left: 37.5, right: 52.5 },\r\n { tzid: 'Etc/GMT-2', left: 22.5, right: 37.5 },\r\n { tzid: 'Etc/GMT-1', left: 7.5, right: 22.5 },\r\n { tzid: 'Etc/GMT', left: -7.5, right: 7.5 },\r\n { tzid: 'Etc/GMT+1', left: -22.5, right: -7.5 },\r\n { tzid: 'Etc/GMT+2', left: -37.5, right: -22.5 },\r\n { tzid: 'Etc/GMT+3', left: -52.5, right: -37.5 },\r\n { tzid: 'Etc/GMT+4', left: -67.5, right: -52.5 },\r\n { tzid: 'Etc/GMT+5', left: -82.5, right: -67.5 },\r\n { tzid: 'Etc/GMT+6', left: -97.5, right: -82.5 },\r\n { tzid: 'Etc/GMT+7', left: -112.5, right: -97.5 },\r\n { tzid: 'Etc/GMT+8', left: -127.5, right: -112.5 },\r\n { tzid: 'Etc/GMT+9', left: -142.5, right: -127.5 },\r\n { tzid: 'Etc/GMT+10', left: -157.5, right: -142.5 },\r\n { tzid: 'Etc/GMT+11', left: -172.5, right: -157.5 },\r\n { tzid: 'Etc/GMT+12', left: -180, right: -172.5 },\r\n]\r\n\r\n/**\r\n * Find the Etc/GMT* timezone name(s) corresponding to the given longitue.\r\n *\r\n * @param lon The longitude to analyze\r\n * @returns An array of strings of TZIDs\r\n */\r\nexport function getTimezoneAtSea(lon: number): string[] {\r\n // coordinates along the 180 longitude should return two zones\r\n if (lon === -180 || lon === 180) {\r\n return ['Etc/GMT+12', 'Etc/GMT-12']\r\n }\r\n const tzs = []\r\n for (let i = 0; i < oceanZones.length; i++) {\r\n const z = oceanZones[i]\r\n if (z.left <= lon && z.right >= lon) {\r\n tzs.push(z.tzid)\r\n } else if (z.right < lon) {\r\n break\r\n }\r\n }\r\n return tzs\r\n}\r\n","export const epsilon = 1.1102230246251565e-16;\nexport const splitter = 134217729;\nexport const resulterrbound = (3 + 8 * epsilon) * epsilon;\n\n// fast_expansion_sum_zeroelim routine from oritinal code\nexport function sum(elen, e, flen, f, h) {\n let Q, Qnew, hh, bvirt;\n let enow = e[0];\n let fnow = f[0];\n let eindex = 0;\n let findex = 0;\n if ((fnow > enow) === (fnow > -enow)) {\n Q = enow;\n enow = e[++eindex];\n } else {\n Q = fnow;\n fnow = f[++findex];\n }\n let hindex = 0;\n if (eindex < elen && findex < flen) {\n if ((fnow > enow) === (fnow > -enow)) {\n Qnew = enow + Q;\n hh = Q - (Qnew - enow);\n enow = e[++eindex];\n } else {\n Qnew = fnow + Q;\n hh = Q - (Qnew - fnow);\n fnow = f[++findex];\n }\n Q = Qnew;\n if (hh !== 0) {\n h[hindex++] = hh;\n }\n while (eindex < elen && findex < flen) {\n if ((fnow > enow) === (fnow > -enow)) {\n Qnew = Q + enow;\n bvirt = Qnew - Q;\n hh = Q - (Qnew - bvirt) + (enow - bvirt);\n enow = e[++eindex];\n } else {\n Qnew = Q + fnow;\n bvirt = Qnew - Q;\n hh = Q - (Qnew - bvirt) + (fnow - bvirt);\n fnow = f[++findex];\n }\n Q = Qnew;\n if (hh !== 0) {\n h[hindex++] = hh;\n }\n }\n }\n while (eindex < elen) {\n Qnew = Q + enow;\n bvirt = Qnew - Q;\n hh = Q - (Qnew - bvirt) + (enow - bvirt);\n enow = e[++eindex];\n Q = Qnew;\n if (hh !== 0) {\n h[hindex++] = hh;\n }\n }\n while (findex < flen) {\n Qnew = Q + fnow;\n bvirt = Qnew - Q;\n hh = Q - (Qnew - bvirt) + (fnow - bvirt);\n fnow = f[++findex];\n Q = Qnew;\n if (hh !== 0) {\n h[hindex++] = hh;\n }\n }\n if (Q !== 0 || hindex === 0) {\n h[hindex++] = Q;\n }\n return hindex;\n}\n\nexport function sum_three(alen, a, blen, b, clen, c, tmp, out) {\n return sum(sum(alen, a, blen, b, tmp), tmp, clen, c, out);\n}\n\n// scale_expansion_zeroelim routine from oritinal code\nexport function scale(elen, e, b, h) {\n let Q, sum, hh, product1, product0;\n let bvirt, c, ahi, alo, bhi, blo;\n\n c = splitter * b;\n bhi = c - (c - b);\n blo = b - bhi;\n let enow = e[0];\n Q = enow * b;\n c = splitter * enow;\n ahi = c - (c - enow);\n alo = enow - ahi;\n hh = alo * blo - (Q - ahi * bhi - alo * bhi - ahi * blo);\n let hindex = 0;\n if (hh !== 0) {\n h[hindex++] = hh;\n }\n for (let i = 1; i < elen; i++) {\n