import{k as V,j as B,t as W,h as X,m as _,n as F,p as e,q as Y,v as z,i as G,A as x,w as Z,x as tt,s as et}from"./web.Os7kOAdY.js";import{c as J}from"./clipboard.BNxbz_oK.js";import{g as K,t as nt}from"./i18n-runtime._BAkvU05.js";var lt=x("<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-field><span class=tool-label></span><input class=tool-input autocomplete=off></div><!$><!/>"),it=x("<dl class=tool-kv><dt>CIDR</dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd style=font-family:ui-monospace,monospace></dd><dt></dt><dd></dd><dt></dt><dd></dd><dt></dt><dd></dd><dt></dt><dd style=font-family:ui-monospace,monospace>"),ot=x('<div class=tool-actions><button class="tool-btn is-primary"></button><button class=tool-btn>'),st=x("<div class=tool-error>× <!$><!/>");function Q(n){const i=n.split(".").map(t=>parseInt(t,10));if(i.length!==4||i.some(t=>!Number.isInteger(t)||t<0||t>255))throw new Error("IP 必须为 4 个 0..255 段");return(i[0]<<24|i[1]<<16|i[2]<<8|i[3])>>>0}function f(n){return[n>>>24&255,n>>>16&255,n>>>8&255,n&255].join(".")}function at(n){if(n<0||n>32)throw new Error("掩码位数必须 0..32");return n===0?0:4294967295<<32-n>>>0}function rt(n){let i=0,t=n>>>0;for(;t&2147483648;)i++,t=t<<1>>>0;if((t&4294967295)!==0&&i>0)throw new Error("掩码不连续");return i}function dt(n){return n<128?"A":n<192?"B":n<224?"C":n<240?"D (multicast)":"E (reserved)"}function ct(n){try{const i=n.trim();let t=i,o=32;if(i.includes("/")){const[l,r]=i.split("/");t=l,r.includes(".")?o=rt(Q(r)):o=parseInt(r,10)}const g=Q(t);if(o<0||o>32||!Number.isInteger(o))throw new Error("掩码 0..32");const c=at(o),s=~c>>>0,a=(g&c)>>>0,d=(a|s)>>>0,u=o===32?1:o===31?2:1<<32-o>>>0,S=o>=31?u:Math.max(0,u-2),y=o>=31?a:a+1>>>0,v=o>=31?d:d-1>>>0,$=[24,16,8,0].map(l=>(a>>>l&255).toString(2).padStart(8,"0")).join(".");return{ok:!0,ipStr:t,bits:o,mask:f(c),wildcard:f(s),network:f(a),broadcast:f(d),firstHost:f(y),lastHost:f(v),hosts:S,total:u,cidr:`${f(a)}/${o}`,classOf:dt(g>>>24&255),binary:$}}catch(i){return{ok:!1,err:i.message}}}function ft(){const[n,i]=B(K(),{equals:!1}),t=s=>nt(s,n());W(()=>{const s=a=>{const d=a.detail?.locale;d&&i(d)};window.addEventListener("taitan:locale-change",s),i(K()),et(()=>window.removeEventListener("taitan:locale-change",s))});const[o,g]=B("192.168.1.130/24"),c=X(()=>ct(o()));return(()=>{var s=_(lt),a=s.firstChild,d=a.firstChild,u=d.nextSibling,S=a.nextSibling,[y,v]=F(S.nextSibling);return e(d,()=>t("IP / CIDR / 掩码")),u.$$input=$=>g($.currentTarget.value),e(s,(()=>{var $=Y(()=>!!c().ok);return()=>$()?(()=>{const l=c();return[(()=>{var r=_(it),m=r.firstChild,p=m.nextSibling,b=p.nextSibling,w=b.nextSibling,h=w.nextSibling,k=h.nextSibling,I=k.nextSibling,C=I.nextSibling,E=C.nextSibling,H=E.nextSibling,L=H.nextSibling,M=L.nextSibling,T=M.nextSibling,D=T.nextSibling,N=D.nextSibling,R=N.nextSibling,j=R.nextSibling,A=j.nextSibling,O=A.nextSibling,P=O.nextSibling,q=P.nextSibling,U=q.nextSibling;return e(p,()=>l.cidr),e(b,()=>t("子网掩码")),e(w,()=>l.mask),e(h,()=>t("反掩码")),e(k,()=>l.wildcard),e(I,()=>t("网络号")),e(C,()=>l.network),e(E,()=>t("广播地址")),e(H,()=>l.broadcast),e(L,()=>t("首个主机")),e(M,()=>l.firstHost),e(T,()=>t("末尾主机")),e(D,()=>l.lastHost),e(N,()=>t("可用主机数")),e(R,()=>l.hosts.toLocaleString()),e(j,()=>t("地址总数")),e(A,()=>l.total.toLocaleString()),e(O,()=>t("地址类")),e(P,()=>l.classOf),e(q,()=>t("二进制")),e(U,()=>l.binary),r})(),(()=>{var r=_(ot),m=r.firstChild,p=m.nextSibling;return m.$$click=()=>J(l.cidr),e(m,()=>t("复制 CIDR")),p.$$click=()=>J(`${l.firstHost} - ${l.lastHost}`),e(p,()=>t("复制主机范围")),z(),r})()]})():(()=>{var l=_(st),r=l.firstChild,m=r.nextSibling,[p,b]=F(m.nextSibling);return e(l,()=>c().err,p,b),l})()})(),y,v),G(()=>Z(u,"placeholder",t("如 192.168.1.130/24 或 10.0.0.0/255.255.255.0"))),G(()=>tt(u,"value",o())),z(),s})()}V(["input","click"]);export{ft as default};
