Files
2026-11-12 06:29:38 +08:00

10 lines
28 KiB
JavaScript

import{r as A,j as r,R}from"./react-vendor-jWT2yUdV.js";import{N as Ue,s as Oe,b as L}from"./index-DiaaLdUu.js";import{i as le}from"./chunk-2QAN2V2R-B2qCPZrG.js";import{d as k}from"./chunk-IHO36JMK-DJPUeGG0.js";import{c as _}from"./chunk-NAV3ZXLI-ChbUTMf0.js";import{a as ce,l as ue}from"./chunk-KVDW62ZT-CGYYmJoP.js";import{z as E}from"./react-hot-toast-cGcFZPSt.js";import{h as re,i as ee,j as de,k as fe,l as he,m as me}from"./index-DE7yoXMZ.js";import{g as Be}from"./qface-BZLvZXJ8.js";import{Q as D}from"./qq_manager-BfRTEAby.js";import{u as Fe}from"./use-dialog-CRIMuzeE.js";var Te=Ue();const xe=Be(Te),ot=({showRestart:h=!0,compact:l=!1})=>{const i=Fe(),[u,C]=A.useState(""),x=u==="win32",j=u==="darwin",w=u!==""&&u!=="win32"&&u!=="darwin",e=u!=="",[s,t]=A.useState(""),[n,a]=A.useState(""),[d,o]=A.useState([]),[f,m]=A.useState(""),[v,N]=A.useState(""),[g,y]=A.useState(""),[P,Y]=A.useState([]),[Z,U]=A.useState(!1),[X,B]=A.useState(!1),[S,J]=A.useState(!1),Q=c=>/^[0-9a-fA-F]{32}$/.test(c),b=c=>/^[0-9a-fA-F]{2}(-[0-9a-fA-F]{2}){5}$/.test(c.trim().toLowerCase()),z=A.useMemo(()=>{if(!w)return"";const c=v.trim().toLowerCase();return!g&&!c?"":xe(g+c).toString()},[w,g,v]),F=A.useMemo(()=>!w||!f?"":xe(g+f).toString(),[w,g,f]),T=A.useCallback(async()=>{try{const c=await D.getPlatformInfo();C(c.platform)}catch{C("win32")}},[]),$=A.useCallback(async()=>{U(!0);try{const c=await D.getDeviceGUID();t(c.guid),a(c.guid)}catch(c){const M=c.message;t(""),a(""),M.includes("not found")||E.error(`获取 GUID 失败: ${M}`)}finally{U(!1)}},[]),O=A.useCallback(async()=>{try{const c=await D.getGUIDBackups();o(c)}catch{}},[]),H=A.useCallback(async()=>{U(!0);try{const[c,M]=await Promise.all([D.getLinuxMAC().catch(()=>({mac:""})),D.getLinuxMachineId().catch(()=>({machineId:""}))]);m(c.mac),N(c.mac),y(M.machineId)}catch(c){const M=c.message;E.error(`获取设备信息失败: ${M}`)}finally{U(!1)}},[]),G=A.useCallback(async()=>{try{const c=await D.getLinuxMachineInfoBackups();Y(c)}catch{}},[]);A.useEffect(()=>{T()},[T]),A.useEffect(()=>{e&&(x?($(),O()):(H(),G()))},[e,x,$,O,H,G]);const q=()=>{const c=w?F:s;c&&(navigator.clipboard.writeText(c),E.success("已复制到剪贴板"))},se=async()=>{if(!Q(n)){E.error("GUID 格式无效,需要 32 位十六进制字符");return}B(!0);try{await D.setDeviceGUID(n),t(n),E.success("GUID 已设置,重启后生效"),await O()}catch(c){const M=c.message;E.error(`设置 GUID 失败: ${M}`)}finally{B(!1)}},ne=()=>{i.confirm({title:"确认删除",content:"删除 Registry20 后,QQ 将在下次启动时生成新的设备标识。确定要删除吗?",confirmText:"删除",cancelText:"取消",onConfirm:async()=>{try{await D.resetDeviceID(),t(""),a(""),E.success("已删除,重启后生效"),await O()}catch(c){const M=c.message;E.error(`删除失败: ${M}`)}}})},Re=async()=>{try{await D.createGUIDBackup(),E.success("备份已创建"),await O()}catch(c){const M=c.message;E.error(`备份失败: ${M}`)}},De=c=>{i.confirm({title:"确认恢复",content:`确定要从备份 "${c}" 恢复吗?当前的 Registry20 将被覆盖。`,confirmText:"恢复",cancelText:"取消",onConfirm:async()=>{try{await D.restoreGUIDBackup(c),E.success("已恢复,重启后生效"),await $(),await O()}catch(M){const K=M.message;E.error(`恢复失败: ${K}`)}}})},Pe=async()=>{const c=v.trim().toLowerCase();if(!b(c)){E.error("MAC 格式无效,需要 xx-xx-xx-xx-xx-xx 格式");return}B(!0);try{await D.setLinuxMAC(c),m(c),E.success("MAC 已设置,重启后生效"),await G()}catch(M){const K=M.message;E.error(`设置 MAC 失败: ${K}`)}finally{B(!1)}},Se=()=>{f&&(navigator.clipboard.writeText(f),E.success("MAC 已复制到剪贴板"))},be=()=>{i.confirm({title:"确认删除",content:"删除 machine-info 后,QQ 将在下次启动时生成新的设备标识。确定要删除吗?",confirmText:"删除",cancelText:"取消",onConfirm:async()=>{try{await D.resetLinuxDeviceID(),m(""),N(""),E.success("已删除,重启后生效"),await G()}catch(c){const M=c.message;E.error(`删除失败: ${M}`)}}})},Le=async()=>{try{await D.createLinuxMachineInfoBackup(),E.success("备份已创建"),await G()}catch(c){const M=c.message;E.error(`备份失败: ${M}`)}},ze=c=>{i.confirm({title:"确认恢复",content:`确定要从备份 "${c}" 恢复吗?当前的 machine-info 将被覆盖。`,confirmText:"恢复",cancelText:"取消",onConfirm:async()=>{try{await D.restoreLinuxMachineInfoBackup(c),E.success("已恢复,重启后生效"),await H(),await G()}catch(M){const K=M.message;E.error(`恢复失败: ${K}`)}}})},oe=()=>{i.confirm({title:"确认重启",content:"确定要重启 SnowCat 吗?这将导致当前连接断开。",confirmText:"重启",cancelText:"取消",onConfirm:async()=>{J(!0);try{await D.restartSnowCat(),E.success("重启指令已发送")}catch(c){const M=c.message;E.error(`重启失败: ${M}`)}finally{J(!1)}}})};return Z||!e?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Oe,{label:"加载中..."})}):j?r.jsx("div",{className:`flex flex-col gap-${l?"3":"4"}`,children:r.jsxs("div",{className:"flex flex-col items-center justify-center py-8 gap-2",children:[r.jsx(_,{variant:"flat",color:"warning",className:"text-xs",children:"macOS 平台暂不支持 GUID 管理"}),r.jsx("div",{className:"text-xs text-default-400",children:"该功能仅适用于 Windows 和 Linux 平台"})]})}):w?r.jsxs("div",{className:`flex flex-col gap-${l?"3":"4"}`,children:[r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"text-sm font-medium text-default-700",children:"当前设备 GUID"}),r.jsxs("div",{className:"flex items-center gap-2",children:[F?r.jsx(_,{variant:"flat",color:"primary",className:"font-mono text-xs max-w-full",children:F}):r.jsx(_,{variant:"flat",color:"warning",className:"text-xs",children:"未设置 / 不存在"}),F&&r.jsx(L,{isIconOnly:!0,size:"sm",variant:"light",onPress:q,"aria-label":"复制GUID",children:r.jsx(re,{size:16})}),r.jsx(L,{isIconOnly:!0,size:"sm",variant:"light",onPress:H,"aria-label":"刷新",children:r.jsx(ee,{size:16})})]}),r.jsx("div",{className:"text-xs text-default-400",children:"GUID = MD5(machine-id + MAC),修改 MAC 即可改变 GUID"})]}),r.jsx(k,{}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("div",{className:"text-sm font-medium text-default-700",children:"Machine ID"}),r.jsx(_,{variant:"flat",color:"default",className:"font-mono text-xs max-w-full",children:g||"未知"}),r.jsx("div",{className:"text-xs text-default-400",children:"来自 /etc/machine-id,不可修改"})]}),r.jsx(k,{}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"text-sm font-medium text-default-700",children:"当前 MAC 地址"}),r.jsxs("div",{className:"flex items-center gap-2",children:[f?r.jsx(_,{variant:"flat",color:"secondary",className:"font-mono text-xs max-w-full",children:f}):r.jsx(_,{variant:"flat",color:"warning",className:"text-xs",children:"未设置 / 不存在"}),f&&r.jsx(L,{isIconOnly:!0,size:"sm",variant:"light",onPress:Se,"aria-label":"复制MAC",children:r.jsx(re,{size:16})})]})]}),r.jsx(k,{}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"text-sm font-medium text-default-700",children:"设置 MAC 地址"}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsx(le,{size:"sm",variant:"bordered",placeholder:"xx-xx-xx-xx-xx-xx",value:v,onValueChange:N,isInvalid:v.length>0&&!b(v),errorMessage:v.length>0&&!b(v)?"格式: xx-xx-xx-xx-xx-xx":void 0,classNames:{input:"font-mono text-sm"},maxLength:17})}),v&&b(v)&&r.jsxs("div",{className:"flex flex-col gap-1 p-2 rounded-lg bg-default-100",children:[r.jsx("div",{className:"text-xs font-medium text-default-500",children:"预览 GUID"}),r.jsx("div",{className:"font-mono text-xs text-primary break-all",children:z}),z!==F&&r.jsx("div",{className:"text-xs text-warning-500",children:"与当前 GUID 不同,保存后重启生效"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(L,{size:"sm",color:"primary",variant:"flat",isLoading:X,isDisabled:!b(v)||v.trim().toLowerCase()===f,onPress:Pe,startContent:r.jsx(de,{size:16}),children:"保存 MAC"}),r.jsx(L,{size:"sm",color:"danger",variant:"flat",isDisabled:!f,onPress:be,startContent:r.jsx(fe,{size:16}),children:"删除"}),r.jsx(L,{size:"sm",color:"secondary",variant:"flat",isDisabled:!f,onPress:Le,startContent:r.jsx(he,{size:16}),children:"手动备份"})]}),r.jsx("div",{className:"text-xs text-default-400",children:"修改 MAC 后 GUID 将变化,需重启 SnowCat 才能生效,操作前会自动备份"})]}),P.length>0&&r.jsxs(r.Fragment,{children:[r.jsx(k,{}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("div",{className:"text-sm font-medium text-default-700",children:["备份列表",r.jsx("span",{className:"text-xs text-default-400 ml-2",children:"(点击恢复)"})]}),r.jsx("div",{className:"max-h-[160px] overflow-y-auto rounded-lg border border-default-200",children:r.jsx(ce,{"aria-label":"备份列表",selectionMode:"none",onAction:c=>ze(c),children:P.map(c=>r.jsx(ue,{startContent:r.jsx(me,{size:16,className:"text-default-400"}),className:"font-mono text-xs",children:c},c))})})]})]}),h&&r.jsxs(r.Fragment,{children:[r.jsx(k,{}),r.jsx(L,{size:"sm",color:"warning",variant:"flat",isLoading:S,onPress:oe,startContent:r.jsx(ee,{size:16}),children:"重启 SnowCat"})]})]}):r.jsxs("div",{className:`flex flex-col gap-${l?"3":"4"}`,children:[r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"text-sm font-medium text-default-700",children:"当前设备 GUID"}),r.jsxs("div",{className:"flex items-center gap-2",children:[s?r.jsx(_,{variant:"flat",color:"primary",className:"font-mono text-xs max-w-full",children:s}):r.jsx(_,{variant:"flat",color:"warning",className:"text-xs",children:"未设置 / 不存在"}),s&&r.jsx(L,{isIconOnly:!0,size:"sm",variant:"light",onPress:q,"aria-label":"复制GUID",children:r.jsx(re,{size:16})}),r.jsx(L,{isIconOnly:!0,size:"sm",variant:"light",onPress:$,"aria-label":"刷新",children:r.jsx(ee,{size:16})})]})]}),r.jsx(k,{}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"text-sm font-medium text-default-700",children:"设置 GUID"}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsx(le,{size:"sm",variant:"bordered",placeholder:"输入32位十六进制 GUID",value:n,onValueChange:a,isInvalid:n.length>0&&!Q(n),errorMessage:n.length>0&&!Q(n)?"需要32位十六进制字符":void 0,classNames:{input:"font-mono text-sm"},maxLength:32})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(L,{size:"sm",color:"primary",variant:"flat",isLoading:X,isDisabled:!Q(n)||n===s,onPress:se,startContent:r.jsx(de,{size:16}),children:"保存 GUID"}),r.jsx(L,{size:"sm",color:"danger",variant:"flat",isDisabled:!s,onPress:ne,startContent:r.jsx(fe,{size:16}),children:"删除 GUID"}),r.jsx(L,{size:"sm",color:"secondary",variant:"flat",isDisabled:!s,onPress:Re,startContent:r.jsx(he,{size:16}),children:"手动备份"})]}),r.jsx("div",{className:"text-xs text-default-400",children:"修改或删除 GUID 后需重启 SnowCat 才能生效,操作前会自动备份"})]}),d.length>0&&r.jsxs(r.Fragment,{children:[r.jsx(k,{}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("div",{className:"text-sm font-medium text-default-700",children:["备份列表",r.jsx("span",{className:"text-xs text-default-400 ml-2",children:"(点击恢复)"})]}),r.jsx("div",{className:"max-h-[160px] overflow-y-auto rounded-lg border border-default-200",children:r.jsx(ce,{"aria-label":"备份列表",selectionMode:"none",onAction:c=>De(c),children:d.map(c=>r.jsx(ue,{startContent:r.jsx(me,{size:16,className:"text-default-400"}),className:"font-mono text-xs",children:c},c))})})]})]}),h&&r.jsxs(r.Fragment,{children:[r.jsx(k,{}),r.jsx(L,{size:"sm",color:"warning",variant:"flat",isLoading:S,onPress:oe,startContent:r.jsx(ee,{size:16}),children:"重启 SnowCat"})]})]})};var Ge=Object.defineProperty,te=Object.getOwnPropertySymbols,Ce=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,ge=(h,l,i)=>l in h?Ge(h,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):h[l]=i,ae=(h,l)=>{for(var i in l||(l={}))Ce.call(l,i)&&ge(h,i,l[i]);if(te)for(var i of te(l))pe.call(l,i)&&ge(h,i,l[i]);return h},ie=(h,l)=>{var i={};for(var u in h)Ce.call(h,u)&&l.indexOf(u)<0&&(i[u]=h[u]);if(h!=null&&te)for(var u of te(h))l.indexOf(u)<0&&pe.call(h,u)&&(i[u]=h[u]);return i};/**
* @license QR Code generator library (TypeScript)
* Copyright (c) Project Nayuki.
* SPDX-License-Identifier: MIT
*/var V;(h=>{const l=class p{constructor(e,s,t,n){if(this.version=e,this.errorCorrectionLevel=s,this.modules=[],this.isFunction=[],e<p.MIN_VERSION||e>p.MAX_VERSION)throw new RangeError("Version value out of range");if(n<-1||n>7)throw new RangeError("Mask value out of range");this.size=e*4+17;let a=[];for(let o=0;o<this.size;o++)a.push(!1);for(let o=0;o<this.size;o++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();const d=this.addEccAndInterleave(t);if(this.drawCodewords(d),n==-1){let o=1e9;for(let f=0;f<8;f++){this.applyMask(f),this.drawFormatBits(f);const m=this.getPenaltyScore();m<o&&(n=f,o=m),this.applyMask(f)}}C(0<=n&&n<=7),this.mask=n,this.applyMask(n),this.drawFormatBits(n),this.isFunction=[]}static encodeText(e,s){const t=h.QrSegment.makeSegments(e);return p.encodeSegments(t,s)}static encodeBinary(e,s){const t=h.QrSegment.makeBytes(e);return p.encodeSegments([t],s)}static encodeSegments(e,s,t=1,n=40,a=-1,d=!0){if(!(p.MIN_VERSION<=t&&t<=n&&n<=p.MAX_VERSION)||a<-1||a>7)throw new RangeError("Invalid value");let o,f;for(o=t;;o++){const g=p.getNumDataCodewords(o,s)*8,y=j.getTotalBits(e,o);if(y<=g){f=y;break}if(o>=n)throw new RangeError("Data too long")}for(const g of[p.Ecc.MEDIUM,p.Ecc.QUARTILE,p.Ecc.HIGH])d&&f<=p.getNumDataCodewords(o,g)*8&&(s=g);let m=[];for(const g of e){i(g.mode.modeBits,4,m),i(g.numChars,g.mode.numCharCountBits(o),m);for(const y of g.getData())m.push(y)}C(m.length==f);const v=p.getNumDataCodewords(o,s)*8;C(m.length<=v),i(0,Math.min(4,v-m.length),m),i(0,(8-m.length%8)%8,m),C(m.length%8==0);for(let g=236;m.length<v;g^=253)i(g,8,m);let N=[];for(;N.length*8<m.length;)N.push(0);return m.forEach((g,y)=>N[y>>>3]|=g<<7-(y&7)),new p(o,s,N,a)}getModule(e,s){return 0<=e&&e<this.size&&0<=s&&s<this.size&&this.modules[s][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let t=0;t<this.size;t++)this.setFunctionModule(6,t,t%2==0),this.setFunctionModule(t,6,t%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const e=this.getAlignmentPatternPositions(),s=e.length;for(let t=0;t<s;t++)for(let n=0;n<s;n++)t==0&&n==0||t==0&&n==s-1||t==s-1&&n==0||this.drawAlignmentPattern(e[t],e[n]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const s=this.errorCorrectionLevel.formatBits<<3|e;let t=s;for(let a=0;a<10;a++)t=t<<1^(t>>>9)*1335;const n=(s<<10|t)^21522;C(n>>>15==0);for(let a=0;a<=5;a++)this.setFunctionModule(8,a,u(n,a));this.setFunctionModule(8,7,u(n,6)),this.setFunctionModule(8,8,u(n,7)),this.setFunctionModule(7,8,u(n,8));for(let a=9;a<15;a++)this.setFunctionModule(14-a,8,u(n,a));for(let a=0;a<8;a++)this.setFunctionModule(this.size-1-a,8,u(n,a));for(let a=8;a<15;a++)this.setFunctionModule(8,this.size-15+a,u(n,a));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;const s=this.version<<12|e;C(s>>>18==0);for(let t=0;t<18;t++){const n=u(s,t),a=this.size-11+t%3,d=Math.floor(t/3);this.setFunctionModule(a,d,n),this.setFunctionModule(d,a,n)}}drawFinderPattern(e,s){for(let t=-4;t<=4;t++)for(let n=-4;n<=4;n++){const a=Math.max(Math.abs(n),Math.abs(t)),d=e+n,o=s+t;0<=d&&d<this.size&&0<=o&&o<this.size&&this.setFunctionModule(d,o,a!=2&&a!=4)}}drawAlignmentPattern(e,s){for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)this.setFunctionModule(e+n,s+t,Math.max(Math.abs(n),Math.abs(t))!=1)}setFunctionModule(e,s,t){this.modules[s][e]=t,this.isFunction[s][e]=!0}addEccAndInterleave(e){const s=this.version,t=this.errorCorrectionLevel;if(e.length!=p.getNumDataCodewords(s,t))throw new RangeError("Invalid argument");const n=p.NUM_ERROR_CORRECTION_BLOCKS[t.ordinal][s],a=p.ECC_CODEWORDS_PER_BLOCK[t.ordinal][s],d=Math.floor(p.getNumRawDataModules(s)/8),o=n-d%n,f=Math.floor(d/n);let m=[];const v=p.reedSolomonComputeDivisor(a);for(let g=0,y=0;g<n;g++){let P=e.slice(y,y+f-a+(g<o?0:1));y+=P.length;const Y=p.reedSolomonComputeRemainder(P,v);g<o&&P.push(0),m.push(P.concat(Y))}let N=[];for(let g=0;g<m[0].length;g++)m.forEach((y,P)=>{(g!=f-a||P>=o)&&N.push(y[g])});return C(N.length==d),N}drawCodewords(e){if(e.length!=Math.floor(p.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let s=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let n=0;n<this.size;n++)for(let a=0;a<2;a++){const d=t-a,f=(t+1&2)==0?this.size-1-n:n;!this.isFunction[f][d]&&s<e.length*8&&(this.modules[f][d]=u(e[s>>>3],7-(s&7)),s++)}}C(s==e.length*8)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let s=0;s<this.size;s++)for(let t=0;t<this.size;t++){let n;switch(e){case 0:n=(t+s)%2==0;break;case 1:n=s%2==0;break;case 2:n=t%3==0;break;case 3:n=(t+s)%3==0;break;case 4:n=(Math.floor(t/3)+Math.floor(s/2))%2==0;break;case 5:n=t*s%2+t*s%3==0;break;case 6:n=(t*s%2+t*s%3)%2==0;break;case 7:n=((t+s)%2+t*s%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[s][t]&&n&&(this.modules[s][t]=!this.modules[s][t])}}getPenaltyScore(){let e=0;for(let a=0;a<this.size;a++){let d=!1,o=0,f=[0,0,0,0,0,0,0];for(let m=0;m<this.size;m++)this.modules[a][m]==d?(o++,o==5?e+=p.PENALTY_N1:o>5&&e++):(this.finderPenaltyAddHistory(o,f),d||(e+=this.finderPenaltyCountPatterns(f)*p.PENALTY_N3),d=this.modules[a][m],o=1);e+=this.finderPenaltyTerminateAndCount(d,o,f)*p.PENALTY_N3}for(let a=0;a<this.size;a++){let d=!1,o=0,f=[0,0,0,0,0,0,0];for(let m=0;m<this.size;m++)this.modules[m][a]==d?(o++,o==5?e+=p.PENALTY_N1:o>5&&e++):(this.finderPenaltyAddHistory(o,f),d||(e+=this.finderPenaltyCountPatterns(f)*p.PENALTY_N3),d=this.modules[m][a],o=1);e+=this.finderPenaltyTerminateAndCount(d,o,f)*p.PENALTY_N3}for(let a=0;a<this.size-1;a++)for(let d=0;d<this.size-1;d++){const o=this.modules[a][d];o==this.modules[a][d+1]&&o==this.modules[a+1][d]&&o==this.modules[a+1][d+1]&&(e+=p.PENALTY_N2)}let s=0;for(const a of this.modules)s=a.reduce((d,o)=>d+(o?1:0),s);const t=this.size*this.size,n=Math.ceil(Math.abs(s*20-t*10)/t)-1;return C(0<=n&&n<=9),e+=n*p.PENALTY_N4,C(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{const e=Math.floor(this.version/7)+2,s=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2;let t=[6];for(let n=this.size-7;t.length<e;n-=s)t.splice(1,0,n);return t}}static getNumRawDataModules(e){if(e<p.MIN_VERSION||e>p.MAX_VERSION)throw new RangeError("Version number out of range");let s=(16*e+128)*e+64;if(e>=2){const t=Math.floor(e/7)+2;s-=(25*t-10)*t-55,e>=7&&(s-=36)}return C(208<=s&&s<=29648),s}static getNumDataCodewords(e,s){return Math.floor(p.getNumRawDataModules(e)/8)-p.ECC_CODEWORDS_PER_BLOCK[s.ordinal][e]*p.NUM_ERROR_CORRECTION_BLOCKS[s.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let s=[];for(let n=0;n<e-1;n++)s.push(0);s.push(1);let t=1;for(let n=0;n<e;n++){for(let a=0;a<s.length;a++)s[a]=p.reedSolomonMultiply(s[a],t),a+1<s.length&&(s[a]^=s[a+1]);t=p.reedSolomonMultiply(t,2)}return s}static reedSolomonComputeRemainder(e,s){let t=s.map(n=>0);for(const n of e){const a=n^t.shift();t.push(0),s.forEach((d,o)=>t[o]^=p.reedSolomonMultiply(d,a))}return t}static reedSolomonMultiply(e,s){if(e>>>8||s>>>8)throw new RangeError("Byte out of range");let t=0;for(let n=7;n>=0;n--)t=t<<1^(t>>>7)*285,t^=(s>>>n&1)*e;return C(t>>>8==0),t}finderPenaltyCountPatterns(e){const s=e[1];C(s<=this.size*3);const t=s>0&&e[2]==s&&e[3]==s*3&&e[4]==s&&e[5]==s;return(t&&e[0]>=s*4&&e[6]>=s?1:0)+(t&&e[6]>=s*4&&e[0]>=s?1:0)}finderPenaltyTerminateAndCount(e,s,t){return e&&(this.finderPenaltyAddHistory(s,t),s=0),s+=this.size,this.finderPenaltyAddHistory(s,t),this.finderPenaltyCountPatterns(t)}finderPenaltyAddHistory(e,s){s[0]==0&&(e+=this.size),s.pop(),s.unshift(e)}};l.MIN_VERSION=1,l.MAX_VERSION=40,l.PENALTY_N1=3,l.PENALTY_N2=3,l.PENALTY_N3=40,l.PENALTY_N4=10,l.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],l.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],h.QrCode=l;function i(w,e,s){if(e<0||e>31||w>>>e)throw new RangeError("Value out of range");for(let t=e-1;t>=0;t--)s.push(w>>>t&1)}function u(w,e){return(w>>>e&1)!=0}function C(w){if(!w)throw new Error("Assertion error")}const x=class I{constructor(e,s,t){if(this.mode=e,this.numChars=s,this.bitData=t,s<0)throw new RangeError("Invalid argument");this.bitData=t.slice()}static makeBytes(e){let s=[];for(const t of e)i(t,8,s);return new I(I.Mode.BYTE,e.length,s)}static makeNumeric(e){if(!I.isNumeric(e))throw new RangeError("String contains non-numeric characters");let s=[];for(let t=0;t<e.length;){const n=Math.min(e.length-t,3);i(parseInt(e.substring(t,t+n),10),n*3+1,s),t+=n}return new I(I.Mode.NUMERIC,e.length,s)}static makeAlphanumeric(e){if(!I.isAlphanumeric(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");let s=[],t;for(t=0;t+2<=e.length;t+=2){let n=I.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t))*45;n+=I.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t+1)),i(n,11,s)}return t<e.length&&i(I.ALPHANUMERIC_CHARSET.indexOf(e.charAt(t)),6,s),new I(I.Mode.ALPHANUMERIC,e.length,s)}static makeSegments(e){return e==""?[]:I.isNumeric(e)?[I.makeNumeric(e)]:I.isAlphanumeric(e)?[I.makeAlphanumeric(e)]:[I.makeBytes(I.toUtf8ByteArray(e))]}static makeEci(e){let s=[];if(e<0)throw new RangeError("ECI assignment value out of range");if(e<128)i(e,8,s);else if(e<16384)i(2,2,s),i(e,14,s);else if(e<1e6)i(6,3,s),i(e,21,s);else throw new RangeError("ECI assignment value out of range");return new I(I.Mode.ECI,0,s)}static isNumeric(e){return I.NUMERIC_REGEX.test(e)}static isAlphanumeric(e){return I.ALPHANUMERIC_REGEX.test(e)}getData(){return this.bitData.slice()}static getTotalBits(e,s){let t=0;for(const n of e){const a=n.mode.numCharCountBits(s);if(n.numChars>=1<<a)return 1/0;t+=4+a+n.bitData.length}return t}static toUtf8ByteArray(e){e=encodeURI(e);let s=[];for(let t=0;t<e.length;t++)e.charAt(t)!="%"?s.push(e.charCodeAt(t)):(s.push(parseInt(e.substring(t+1,t+3),16)),t+=2);return s}};x.NUMERIC_REGEX=/^[0-9]*$/,x.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,x.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let j=x;h.QrSegment=x})(V||(V={}));(h=>{(l=>{const i=class{constructor(C,x){this.ordinal=C,this.formatBits=x}};i.LOW=new i(0,1),i.MEDIUM=new i(1,0),i.QUARTILE=new i(2,3),i.HIGH=new i(3,2),l.Ecc=i})(h.QrCode||(h.QrCode={}))})(V||(V={}));(h=>{(l=>{const i=class{constructor(C,x){this.modeBits=C,this.numBitsCharCount=x}numCharCountBits(C){return this.numBitsCharCount[Math.floor((C+7)/17)]}};i.NUMERIC=new i(1,[10,12,14]),i.ALPHANUMERIC=new i(2,[9,11,13]),i.BYTE=new i(4,[8,16,16]),i.KANJI=new i(8,[8,10,12]),i.ECI=new i(7,[0,0,0]),l.Mode=i})(h.QrSegment||(h.QrSegment={}))})(V||(V={}));var W=V;/**
* @license qrcode.react
* Copyright (c) Paul O'Shannessy
* SPDX-License-Identifier: ISC
*/var ke={L:W.QrCode.Ecc.LOW,M:W.QrCode.Ecc.MEDIUM,Q:W.QrCode.Ecc.QUARTILE,H:W.QrCode.Ecc.HIGH},we=128,ve="L",Me="#FFFFFF",Ee="#000000",Ne=!1,Ie=1,_e=4,Qe=0,$e=.1;function ye(h,l=0){const i=[];return h.forEach(function(u,C){let x=null;u.forEach(function(j,w){if(!j&&x!==null){i.push(`M${x+l} ${C+l}h${w-x}v1H${x+l}z`),x=null;return}if(w===u.length-1){if(!j)return;x===null?i.push(`M${w+l},${C+l} h1v1H${w+l}z`):i.push(`M${x+l},${C+l} h${w+1-x}v1H${x+l}z`);return}j&&x===null&&(x=w)})}),i.join("")}function Ae(h,l){return h.slice().map((i,u)=>u<l.y||u>=l.y+l.h?i:i.map((C,x)=>x<l.x||x>=l.x+l.w?C:!1))}function He(h,l,i,u){if(u==null)return null;const C=h.length+i*2,x=Math.floor(l*$e),j=C/l,w=(u.width||x)*j,e=(u.height||x)*j,s=u.x==null?h.length/2-w/2:u.x*j,t=u.y==null?h.length/2-e/2:u.y*j,n=u.opacity==null?1:u.opacity;let a=null;if(u.excavate){let o=Math.floor(s),f=Math.floor(t),m=Math.ceil(w+s-o),v=Math.ceil(e+t-f);a={x:o,y:f,w:m,h:v}}const d=u.crossOrigin;return{x:s,y:t,h:e,w,excavation:a,opacity:n,crossOrigin:d}}function Ve(h,l){return l!=null?Math.max(Math.floor(l),0):h?_e:Qe}function je({value:h,level:l,minVersion:i,includeMargin:u,marginSize:C,imageSettings:x,size:j,boostLevel:w}){let e=R.useMemo(()=>{const o=(Array.isArray(h)?h:[h]).reduce((f,m)=>(f.push(...W.QrSegment.makeSegments(m)),f),[]);return W.QrCode.encodeSegments(o,ke[l],i,void 0,void 0,w)},[h,l,i,w]);const{cells:s,margin:t,numCells:n,calculatedImageSettings:a}=R.useMemo(()=>{let d=e.getModules();const o=Ve(u,C),f=d.length+o*2,m=He(d,j,o,x);return{cells:d,margin:o,numCells:f,calculatedImageSettings:m}},[e,j,x,u,C]);return{qrcode:e,margin:t,cells:s,numCells:n,calculatedImageSettings:a}}var Ye=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),Xe=R.forwardRef(function(l,i){const u=l,{value:C,size:x=we,level:j=ve,bgColor:w=Me,fgColor:e=Ee,includeMargin:s=Ne,minVersion:t=Ie,boostLevel:n,marginSize:a,imageSettings:d}=u,f=ie(u,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:m}=f,v=ie(f,["style"]),N=d==null?void 0:d.src,g=R.useRef(null),y=R.useRef(null),P=R.useCallback(b=>{g.current=b,typeof i=="function"?i(b):i&&(i.current=b)},[i]),[Y,Z]=R.useState(!1),{margin:U,cells:X,numCells:B,calculatedImageSettings:S}=je({value:C,level:j,minVersion:t,boostLevel:n,includeMargin:s,marginSize:a,imageSettings:d,size:x});R.useEffect(()=>{if(g.current!=null){const b=g.current,z=b.getContext("2d");if(!z)return;let F=X;const T=y.current,$=S!=null&&T!==null&&T.complete&&T.naturalHeight!==0&&T.naturalWidth!==0;$&&S.excavation!=null&&(F=Ae(X,S.excavation));const O=window.devicePixelRatio||1;b.height=b.width=x*O;const H=x/B*O;z.scale(H,H),z.fillStyle=w,z.fillRect(0,0,B,B),z.fillStyle=e,Ye?z.fill(new Path2D(ye(F,U))):X.forEach(function(G,q){G.forEach(function(se,ne){se&&z.fillRect(ne+U,q+U,1,1)})}),S&&(z.globalAlpha=S.opacity),$&&z.drawImage(T,S.x+U,S.y+U,S.w,S.h)}}),R.useEffect(()=>{Z(!1)},[N]);const J=ae({height:x,width:x},m);let Q=null;return N!=null&&(Q=R.createElement("img",{src:N,key:N,style:{display:"none"},onLoad:()=>{Z(!0)},ref:y,crossOrigin:S==null?void 0:S.crossOrigin})),R.createElement(R.Fragment,null,R.createElement("canvas",ae({style:J,height:x,width:x,ref:P,role:"img"},v)),Q)});Xe.displayName="QRCodeCanvas";var We=R.forwardRef(function(l,i){const u=l,{value:C,size:x=we,level:j=ve,bgColor:w=Me,fgColor:e=Ee,includeMargin:s=Ne,minVersion:t=Ie,boostLevel:n,title:a,marginSize:d,imageSettings:o}=u,f=ie(u,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:m,cells:v,numCells:N,calculatedImageSettings:g}=je({value:C,level:j,minVersion:t,boostLevel:n,includeMargin:s,marginSize:d,imageSettings:o,size:x});let y=v,P=null;o!=null&&g!=null&&(g.excavation!=null&&(y=Ae(v,g.excavation)),P=R.createElement("image",{href:o.src,height:g.h,width:g.w,x:g.x+m,y:g.y+m,preserveAspectRatio:"none",opacity:g.opacity,crossOrigin:g.crossOrigin}));const Y=ye(y,m);return R.createElement("svg",ae({height:x,width:x,viewBox:`0 0 ${N} ${N}`,ref:i,role:"img"},f),!!a&&R.createElement("title",null,a),R.createElement("path",{fill:w,d:`M0,0 h${N}v${N}H0z`,shapeRendering:"crispEdges"}),R.createElement("path",{fill:e,d:Y,shapeRendering:"crispEdges"}),P)});We.displayName="QRCodeSVG";export{ot as G,We as Q};