import*as t from"fs";import*as e from"path";import{decode as i}from"geobuf";import o from"@turf/boolean-point-in-polygon";import{point as r}from"@turf/helpers";import n from"pbf";const f=[{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 d(t){if(-180===t||180===t)return["Etc/GMT+12","Etc/GMT-12"];const e=[];for(let i=0;i<f.length;i++){const o=f[i];if(o.left<=t&&o.right>=t)e.push(o.tzid);else if(o.right<t)break}return e}const l=require("../data/index.json"),c=e.join(__dirname,"..","data","geo.dat");let a;function h(e){if(a=e&&e.store&&"function"==typeof e.store.get&&"function"==typeof e.store.set?e.store:new Map,e&&e.preload){const e=t.openSync(c,"r");if(e<0)throw new Error("Failed to open geo.dat file");!function(t){!function e(i,o){if(i.pos>=0&&i.len){const e=g(0,i.pos,i.len,t);a.set(o,e)}else"object"==typeof i&&Object.getOwnPropertyNames(i).forEach(function(t){e(i[t],o+t)})}(l.lookup,"")}(e),t.closeSync(e)}}function g(e,o,r,f=-1){let d=f;if(d<0&&(d=t.openSync(c,"r"),d<0))throw new Error("Failed to open geo.dat file");const l=Buffer.alloc(r),a=t.readSync(d,l,0,r,o);if(f<0&&t.closeSync(d),a<r)throw new Error(`tried to read ${r} bytes from geo.dat but only got ${a} bytes`);const h=new n(l);return i(h)}function s(t,e){const i=e;let n;if(isNaN(t)||t>90||t<-90)throw n=new Error("Invalid latitude: "+t),n;if(isNaN(e)||e>180||e<-180)throw n=new Error("Invalid longitude: "+e),n;if(90===t)return f.map(t=>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);const c=r([e,t]),h={top:89.9999,bottom:-89.9999,left:-179.9999,right:179.9999,midLat:0,midLon:0};let s="",p=l.lookup;for(;;){let r;if(t>=h.midLat&&e>=h.midLon?(r="a",h.bottom=h.midLat,h.left=h.midLon):t>=h.midLat&&e<h.midLon?(r="b",h.bottom=h.midLat,h.right=h.midLon):t<h.midLat&&e<h.midLon?(r="c",h.top=h.midLat,h.right=h.midLon):(r="d",h.top=h.midLat,h.left=h.midLon),p=p[r],s+=r,!p)return d(i);if(p.pos>=0&&p.len){let t=a.get(s);t||(t=g(0,p.pos,p.len),a.set(s,t));const e=[];for(let i=0;i<t.features.length;i++)o(c,t.features[i])&&e.push(t.features[i].properties.tzid);return e.length>0?e:d(i)}if(p.length>0)return p.map(t=>l.timezones[t]);if("object"!=typeof p)throw n=new Error("Unexpected data type"),n;h.midLat=(h.top+h.bottom)/2,h.midLon=(h.left+h.right)/2}}function p(){h({preload:!0})}h();export{s as default,p as preCache,h as setCache};
//# sourceMappingURL=geo-tz.modern.js.map
