import{Wr as e,t}from"./D-ctIW6J.js";import{v as n}from"./DFcQv_XM.js";var r=2700*1e3,i=600*1e3,a=`reverseDnsCache`,o=200,s=new Map,c=new Map,l=e({}),u=new Set;function d(e,t){l[e]===t||u.has(e)||(u.add(e),queueMicrotask(()=>{u.delete(e),l[e]!==t&&(l[e]=t)}))}function f(e){if(!e)return!1;if(e.includes(`:`)){let t=e.split(`%`)[0].toLowerCase();return!(t===`::`||t===`::1`||/^fe[89ab]/.test(t))}let t=e.split(`.`);if(t.length!==4)return!1;for(let e of t)if(!/^\d{1,3}$/.test(e)||Number(e)>255)return!1;let n=Number(t[0]),r=Number(t[1]);return!(n===127||n===0||n===169&&r===254)}function p(e){let t=e.split(`.`);if(t.length!==4)return null;for(let e of t)if(!/^\d{1,3}$/.test(e)||Number(e)>255)return null;return`${t[3]}.${t[2]}.${t[1]}.${t[0]}.in-addr.arpa`}function m(e){let t=e.split(`%`)[0].split(`::`);if(t.length>2)return null;let n=t[0]?t[0].split(`:`):[],r=t.length===2&&t[1]?t[1].split(`:`):[],i;if(t.length===2){let e=8-n.length-r.length;if(e<0)return null;let t=[];for(let n=0;n<e;n++)t.push(`0`);i=[...n,...t,...r]}else i=n;if(i.length!==8)return null;let a=``;for(let e of i){if(!/^[0-9a-f]{1,4}$/i.test(e))return null;a+=e.padStart(4,`0`).toLowerCase()}return`${a.split(``).reverse().join(`.`)}.ip6.arpa`}function h(e){return e.includes(`:`)?m(e):p(e)}function g(e,t){let n=e.name===null?i:r;return t-e.ts>n}function _(){try{let e=localStorage.getItem(a);if(!e)return{};let t=JSON.parse(e);return t&&typeof t==`object`?t:{}}catch{return{}}}function v(e){try{let t=Object.keys(e);if(t.length>o){let n={};for(let r of t.slice(t.length-o)){let t=e[r];t&&(n[r]=t)}e=n}localStorage.setItem(a,JSON.stringify(e))}catch{}}function y(e,t){let n=_();delete n[e],n[e]=t,v(n)}var b=!1;function x(){if(b)return;b=!0;let e=Date.now();for(let[t,n]of Object.entries(_()))n&&typeof n.name==`string`&&typeof n.ts==`number`&&!g(n,e)&&!s.has(t)&&s.set(t,n)}x();function S(){let e=t();async function r(e){let t=h(e);if(!t)return null;try{let e=(await n().get(`dns/query`,{searchParams:{name:t,type:`PTR`}}).json()).Answer?.[0]?.data;return e?e.replace(/\.$/,``):null}catch{return null}}function i(t){if(!e.resolveClientHostname||!t||!f(t))return;let n=Date.now(),i=s.get(t);if(i){if(!g(i,n)){i.name&&d(t,i.name);return}s.delete(t),l[t]&&delete l[t]}if(c.has(t))return;let a=r(t);c.set(t,a),a.then(e=>{let n={name:e,ts:Date.now()};s.set(t,n),e&&(l[t]=e,y(t,n))}).finally(()=>c.delete(t))}function a(e){if(e)return i(e),l[e]}function o(t){return t?e.resolveClientHostname&&a(t)||t:``}return{lookup:i,get:a,label:o}}export{S as t};