import{Qn as e,d as t,k as n}from"./DLvf9lie.js";var r=2700*1e3,i=600*1e3,a=`reverseDnsCache`,o=200,s=new Map,c=new Map,l=e({});function u(e){if(e.length<1||e.length>3)return!1;for(let t of e)if(t<`0`||t>`9`)return!1;return Number(e)<=255}function d(e){if(e.length<1||e.length>4)return!1;for(let t of e.toLowerCase())if(!(t>=`0`&&t<=`9`)&&!(t>=`a`&&t<=`f`))return!1;return!0}function f(e){let t=e.split(`:`,1)[0];return!!t&&d(t)&&(Number.parseInt(t,16)&65472)==65152}var p=new Set;function m(e,t){l[e]===t||p.has(e)||(p.add(e),queueMicrotask(()=>{p.delete(e),l[e]!==t&&(l[e]=t)}))}function h(e){if(!e)return!1;if(e.includes(`:`)){let t=e.split(`%`)[0].toLowerCase();return!(_(t)===null||t===`::`||t===`::1`||f(t))}let t=e.split(`.`);if(t.length!==4)return!1;for(let e of t)if(!u(e))return!1;let n=Number(t[0]),r=Number(t[1]);return!(n===127||n===0||n===169&&r===254)}function g(e){let t=e.split(`.`);if(t.length!==4)return null;for(let e of t)if(!u(e))return null;return`${t[3]}.${t[2]}.${t[1]}.${t[0]}.in-addr.arpa`}function _(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(!d(e))return null;a+=e.padStart(4,`0`).toLowerCase()}return`${a.split(``).reverse().join(`.`)}.ip6.arpa`}function v(e){return e.includes(`:`)?_(e):g(e)}function y(e,t){let n=e.name===null?i:r;return t-e.ts>n}function b(){try{let e=localStorage.getItem(a);if(!e)return{};let t=JSON.parse(e);return t&&typeof t==`object`?t:{}}catch{return{}}}function x(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 S(e,t){let n=b();delete n[e],n[e]=t,x(n)}var C=!1;function w(){if(C)return;C=!0;let e=Date.now();for(let[t,n]of Object.entries(b()))n&&typeof n.name==`string`&&typeof n.ts==`number`&&!y(n,e)&&!s.has(t)&&s.set(t,n)}w();function T(){let e=t();async function r(e){let t=v(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.endsWith(`.`)?e.slice(0,-1):e:null}catch{return null}}function i(t){if(!e.resolveClientHostname||!t||!h(t))return;let n=Date.now(),i=s.get(t);if(i){if(!y(i,n)){i.name&&m(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,S(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{T as t};