var t=require("fs"),e=require("path"),r=require("geobuf"),i=require("@turf/boolean-point-in-polygon"),o=require("@turf/helpers"),n=require("pbf");function f(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function d(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}}),e.default=t,e}var a=/*#__PURE__*/d(t),l=/*#__PURE__*/d(e),c=/*#__PURE__*/f(i),u=/*#__PURE__*/f(n),g=[{tzid:"Etc/GMT-12",left:172.5,right:180},{tzid:"Etc/GMT-11",left:157.5,right:172.5},{tzid:"Etc/GMT-10",left:142.5,right:157.5},{tzid:"Etc/GMT-9",left:127.5,right:142.5},{tzid:"Etc/GMT-8",left:112.5,right:127.5},{tzid:"Etc/GMT-7",left:97.5,right:112.5},{tzid:"Etc/GMT-6",left:82.5,right:97.5},{tzid:"Etc/GMT-5",left:67.5,right:82.5},{tzid:"Etc/GMT-4",left:52.5,right:67.5},{tzid:"Etc/GMT-3",left:37.5,right:52.5},{tzid:"Etc/GMT-2",left:22.5,right:37.5},{tzid:"Etc/GMT-1",left:7.5,right:22.5},{tzid:"Etc/GMT",left:-7.5,right:7.5},{tzid:"Etc/GMT+1",left:-22.5,right:-7.5},{tzid:"Etc/GMT+2",left:-37.5,right:-22.5},{tzid:"Etc/GMT+3",left:-52.5,right:-37.5},{tzid:"Etc/GMT+4",left:-67.5,right:-52.5},{tzid:"Etc/GMT+5",left:-82.5,right:-67.5},{tzid:"Etc/GMT+6",left:-97.5,right:-82.5},{tzid:"Etc/GMT+7",left:-112.5,right:-97.5},{tzid:"Etc/GMT+8",left:-127.5,right:-112.5},{tzid:"Etc/GMT+9",left:-142.5,right:-127.5},{tzid:"Etc/GMT+10",left:-157.5,right:-142.5},{tzid:"Etc/GMT+11",left:-172.5,right:-157.5},{tzid:"Etc/GMT+12",left:-180,right:-172.5}];function h(t){if(-180===t||180===t)return["Etc/GMT+12","Etc/GMT-12"];for(var e=[],r=0;r<g.length;r++){var i=g[r];if(i.left<=t&&i.right>=t)e.push(i.tzid);else if(i.right<t)break}return e}var p,s=require("../data/index.json"),E=l.join(__dirname,"..","data","geo.dat");function m(t){if(p=t&&t.store&&"function"==typeof t.store.get&&"function"==typeof t.store.set?t.store:new Map,t&&t.preload){var e=a.openSync(E,"r");if(e<0)throw new Error("Failed to open geo.dat file");!function(t){!function e(r,i){if(r.pos>=0&&r.len){var o=z(0,r.pos,r.len,t);p.set(i,o)}else"object"==typeof r&&Object.getOwnPropertyNames(r).forEach(function(t){e(r[t],i+t)})}(s.lookup,"")}(e),a.closeSync(e)}}function z(t,e,i,o){void 0===o&&(o=-1);var n=o;if(n<0&&(n=a.openSync(E,"r"))<0)throw new Error("Failed to open geo.dat file");var f=Buffer.alloc(i),d=a.readSync(n,f,0,i,e);if(o<0&&a.closeSync(n),d<i)throw new Error("tried to read "+i+" bytes from geo.dat but only got "+d+" bytes");var l=new u.default(f);return r.decode(l)}m(),exports.default=function(t,e){var r=e;if(isNaN(t)||t>90||t<-90)throw new Error("Invalid latitude: "+t);if(isNaN(e)||e>180||e<-180)throw new Error("Invalid longitude: "+e);if(90===t)return g.map(function(t){return t.tzid});t>=89.9999?t=89.9999:t<=-89.9999&&(t=-89.9999),e>=179.9999?e=179.9999:e<=-179.9999&&(e=-179.9999);for(var i=o.point([e,t]),n={top:89.9999,bottom:-89.9999,left:-179.9999,right:179.9999,midLat:0,midLon:0},f="",d=s.lookup;;){var a=void 0;if(t>=n.midLat&&e>=n.midLon?(a="a",n.bottom=n.midLat,n.left=n.midLon):t>=n.midLat&&e<n.midLon?(a="b",n.bottom=n.midLat,n.right=n.midLon):t<n.midLat&&e<n.midLon?(a="c",n.top=n.midLat,n.right=n.midLon):(a="d",n.top=n.midLat,n.left=n.midLon),f+=a,!(d=d[a]))return h(r);if(d.pos>=0&&d.len){var l=p.get(f);l||(l=z(0,d.pos,d.len),p.set(f,l));for(var u=[],E=0;E<l.features.length;E++)c.default(i,l.features[E])&&u.push(l.features[E].properties.tzid);return u.length>0?u:h(r)}if(d.length>0)return d.map(function(t){return s.timezones[t]});if("object"!=typeof d)throw new Error("Unexpected data type");n.midLat=(n.top+n.bottom)/2,n.midLon=(n.left+n.right)/2}},exports.preCache=function(){m({preload:!0})},exports.setCache=m;
//# sourceMappingURL=geo-tz.js.map
