UNPKG

@particle-network/authkit

Version:

Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.

12 lines (11 loc) 7.78 kB
"use client"; import{j as Y}from"./chunk-K3VNPFHC.mjs";import"./chunk-UXH6IVHO.mjs";import"./chunk-ZBZCVTZA.mjs";import"./chunk-3RRPQ2DX.mjs";import{Q as B,X as _,h as V,l as j,m as q,ta as K,wa as U}from"./chunk-2KFRLDSI.mjs";import"./chunk-C7OWFSST.mjs";import{particleAuth as we}from"@particle-network/auth-core";import o,{useEffect as N,useMemo as R,useRef as ee,useState as te}from"react";import ge from"react-shadow";import ae,{useEffect as se}from"react";import{useEffect as re,useRef as ne}from"react";var le=9;function I(){let e=ne(null);function n(s){if(!e.current)return;let t=e.current.querySelectorAll(` a[href]:not(:disabled), button:not(:disabled), textarea:not(:disabled), input[type="text"]:not(:disabled), input[type="radio"]:not(:disabled), input[type="checkbox"]:not(:disabled), select:not(:disabled) `),i=t[0],y=t[t.length-1];(s.key==="Tab"||s.keyCode===le)&&(s.shiftKey?document.activeElement===i&&(y.focus(),s.preventDefault()):document.activeElement===y&&(i.focus(),s.preventDefault()))}return re(()=>(e.current&&(e.current.addEventListener("keydown",n),e.current.focus({preventScroll:!0})),()=>{e.current&&e.current.removeEventListener("keydown",n)}),[]),e}function O(e){let n=I();return se(()=>{!n.current||n.current.focus({preventScroll:!0})},[]),ae.createElement("div",{ref:n,tabIndex:0},e.children)}import H,{forwardRef as ce,useEffect as de,useImperativeHandle as me,useState as ue}from"react";var Z="";var ye=ce((e,n)=>{var x,A,F,b,v,P,C,w;let{children:s,title:t,drawerProps:i={},modalProps:{destroyOnClose:y,...c}={}}=e,{authCoreModal:E}=q(),[W,f]=ue(e.visible||!1),a=e.locked==="drawer"||E.viewType!=="desktop"&&e.locked!=="modal",h=()=>{f(!1),e.onClose&&e.onClose()},S=()=>{f(!0),e.onOpen&&e.onOpen()};me(n,()=>({setVisible:f,onOpen:S,onClose:h})),de(()=>{var g;f((g=e.visible)!=null?g:!1)},[e.visible]),(x=c==null?void 0:c.style)!=null&&x.top&&(c.style.top="");let T={...i};delete T.closable;let k=a?{...c.styles,...i.styles,wrapper:{...(A=c.styles)==null?void 0:A.wrapper,...i.contentWrapperStyle,...(F=i.styles)==null?void 0:F.wrapper},body:{...(b=c.styles)==null?void 0:b.body,...i.bodyStyle,...(v=i.styles)==null?void 0:v.body}}:c.styles;return H.createElement(H.Fragment,null,H.createElement("style",null,V(Z)),H.createElement(Y,{title:t,open:W,okText:"",className:`${a?"w-drawer-container":""} ${e.className||""}`.trim(),wrapClassName:`${a?"":"w-model-container"}`.trim(),centered:!a,forceBottom:a,maskClosable:a&&(P=i.maskClosable)!=null?P:!1,getContainer:()=>e.containerSelector?document.querySelector(e.containerSelector):E.rootModalContainer||document.querySelector("body"),onCancel:()=>{h()},closable:(C=e.closable)!=null?C:!0,destroyOnHidden:a&&(w=i.destroyOnClose)!=null?w:y,...c,...a?T:{},styles:k,forceRender:!0},s))}),G=ye;import pe,{useEffect as fe,useRef as he}from"react";var Se=({setAuthCoreModal:e})=>{let n=he(null);return fe(()=>{e({rootModalContainer:n.current})},[e]),pe.createElement("div",{ref:n})},J=Se;var Q=()=>"web_3.0.0-alpha.8";import{getLatestAuthType as be,isSocialAuthType as ve}from"@particle-network/auth-core";import{useEffect as Pe}from"react";var Ce=({web3Modal:e})=>{let{connectionStatus:n}=_(),{provider:s}=K();Pe(()=>{var t;e&&n==="connected"&&ve(be())&&s&&((t=e==null?void 0:e.setEIP6963Provider)==null||t.call(e,s,"Particle Wallet"))},[n,s,e])},X=Ce;var Me=o.lazy(()=>import("./iframeWalletPlugin-CM5SEIMD.mjs")),Ee=o.lazy(()=>import("./accountTipModal-L2XRSPZ7.mjs")),Te=o.lazy(()=>import("./paymentVerifyModal-TXZXWD6Y.mjs")),ke=o.lazy(()=>import("./wrongPasswordModal-QC3AMQRF.mjs")),xe=o.lazy(()=>import("./selectSecurityAccount-22ZK5X54.mjs")),D=[{name:"resetStyle",loadStyle:()=>import("./reset-X6WS37RQ.mjs")},{name:"globalStyle",loadStyle:()=>import("./global-4F6HKCIM.mjs")},{name:"scrollStyle",loadStyle:()=>import("./scroll-DAY6HBTM.mjs")},{name:"themeStyle",loadStyle:()=>import("./theme-LUFYGUGL.mjs")}],Ae=()=>{var b,v,P,C,w,g,$,z;let{modalOptions:e,authCoreModal:n,setAuthCoreModal:s,customRouter:t,authCoreModalClose:i,selectSecurityAccount:y,verifySecurityAccountState:c,wrongPassword:E,paymentVerify:W,accountTipModal:f}=j(),a=ee(null),h=ee(null),[S,T]=te(null),[k,x]=te({styleList:D.map(r=>({name:r.name,styleContent:""}))});N(()=>{Promise.all(D.map(r=>r.loadStyle())).then(r=>{x({styleList:D.map((l,d)=>{var m,p;return{name:l.name,styleContent:(p=(m=r[d])==null?void 0:m.default)!=null?p:""}})})})},[]),N(()=>{var r;((r=h.current)==null?void 0:r.shadowRoot)&&!S&&T(h.current.shadowRoot)},[S]),N(()=>{let r=a.current;if(!r)return;let l=m=>m.stopPropagation(),d=["click","mousedown","mouseup","pointerdown","pointerup","touchstart","touchend"];return d.forEach(m=>r.addEventListener(m,l)),()=>d.forEach(m=>r.removeEventListener(m,l))},[S]),N(()=>{var r,l;if(a.current){let p=Math.max(300,Number((r=e.customStyle)==null?void 0:r.modalWidth)),M=Math.max(500,Number((l=e.customStyle)==null?void 0:l.modalHeight));n.viewType=="mobile"&&(p=document.body.clientWidth,M=document.body.clientHeight*.86);let u=p/100;a.current.style.setProperty("--vw",u+"px"),a.current.style.setProperty("--doc-height",M+"px"),a.current.style.setProperty("--doc-width",p+"px")}},[a.current,n.viewType,(b=e.customStyle)==null?void 0:b.modalWidth,(v=e.customStyle)==null?void 0:v.modalHeight]);let A=R(()=>{var d;if(B())return"";let r=window.getComputedStyle(window.document.body).fontFamily;return`.particle-auth-core-shadow-root { --auth-core-font-family: ${((d=e==null?void 0:e.customStyle)==null?void 0:d.fontFamily)||r||'"PingFang SC", "Helvetica Neue", "Helvetica", "Arial", sans-serif'}; }`},[(P=e==null?void 0:e.customStyle)==null?void 0:P.fontFamily]),F=R(()=>{var M;let r=e.themeType,l=e.customStyle||{},d={...Object.fromEntries(Object.keys(l||{}).filter(u=>u!=="theme").map(u=>[u,(l==null?void 0:l[u])||""])),...((M=l==null?void 0:l.theme)==null?void 0:M[r==="light"?"light":"dark"])||{}},m=Object.keys(d).filter(u=>u!=="fontFamily").map(u=>{let oe=u.replace(/([A-Z])/g,"-$1").toLowerCase(),L=d[u];return isNaN(Number(L))||(L=L+"px"),`--${oe}:${L};`}).join(` `);return`${r==="dark"?".particle-auth-core-shadow-root.dark":".particle-auth-core-shadow-root"}{ ${m} }`},[e.themeType,e.customStyle]);return o.createElement(ge.div,{ref:h,mode:"open"},S&&o.createElement(o.Fragment,null,o.createElement("div",{id:"particle-auth-core-modal",className:`particle-auth-core-shadow-root ${e.themeType}`,"data-path":t==null?void 0:t.path,"data-auth-core-modal-version":Q(),"data-auth-core-version":we.version,ref:a},o.createElement(O,null,o.createElement("style",{"data-name":"fontStyle"},A),!!((C=k.styleList[0])!=null&&C.styleContent)&&k.styleList.map((r,l)=>o.createElement("style",{"data-name":r.name,"data-index":l,key:l},r.styleContent)),o.createElement("style",{"data-name":"customTheme"},F),n.rootModalContainer&&o.createElement(G,{visible:n.particleModalVisible,closable:n.closable,onClose:()=>{i()},className:"root-particle-modal-container",modalProps:{footer:null,width:parseInt((w=e.customStyle)==null?void 0:w.modalWidth),height:parseInt((g=e.customStyle)==null?void 0:g.modalHeight),destroyOnClose:!0,zIndex:(($=e.customStyle)==null?void 0:$.zIndex)||1e3},drawerProps:{destroyOnClose:!0,zIndex:((z=e.customStyle)==null?void 0:z.zIndex)||1e3}},o.createElement(U,{path:t==null?void 0:t.path,state:t==null?void 0:t.state,replace:t==null?void 0:t.replace,children:t==null?void 0:t.children})),o.createElement(o.Suspense,null,o.createElement(Me,null),o.createElement(xe,{visible:y,state:c}),o.createElement(Ee,{modal:f}),o.createElement(Te,{props:W}),o.createElement(ke,{info:E})),o.createElement(J,{"data-ref":"rootModalContainer",setAuthCoreModal:s}),e.web3Modal&&o.createElement(X,{web3Modal:e.web3Modal})))))},at=Ae;export{at as default};