wx-auth-sdk 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wx-auth.js +1 -1
- package/dist/wx-auth.umd.js +1 -1
- package/package.json +1 -1
package/dist/wx-auth.js
CHANGED
|
@@ -118,7 +118,7 @@ const r = {
|
|
|
118
118
|
// 设置Cookie(30天过期,自动设置根域名实现跨子域共享)
|
|
119
119
|
setCookie(e, t) {
|
|
120
120
|
const o = /* @__PURE__ */ new Date();
|
|
121
|
-
o.setTime(o.getTime() +
|
|
121
|
+
o.setTime(o.getTime() + 365 * 24 * 60 * 60 * 1e3);
|
|
122
122
|
const s = this.getRootDomain(), i = s ? `;domain=${s}` : "", d = window.location.protocol === "https:" ? ";Secure" : "";
|
|
123
123
|
document.cookie = `${e}=${t};expires=${o.toUTCString()};path=/${i}${d};SameSite=Strict`;
|
|
124
124
|
},
|
package/dist/wx-auth.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(h,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(h=typeof globalThis<"u"?globalThis:h||self,p(h.WxAuthSDK={}))})(this,(function(h){"use strict";var p=document.createElement("style");p.textContent=`.wx-auth-modal{position:fixed;inset:0;z-index:9999;display:none;align-items:center;justify-content:center;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif}.wx-auth-overlay{position:absolute;width:100%;height:100%;background:#00000080;animation:wxAuthFadeIn .2s ease}.wx-auth-content{position:relative;width:350px;max-width:90vw;background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 10px 40px #0003;animation:wxAuthSlideUp .3s ease}.wx-auth-header{background:#07c160;color:#fff;padding:16px 20px;display:flex;align-items:center;justify-content:space-between}.wx-auth-title{font-size:16px;font-weight:600;flex:1;text-align:center}.wx-auth-close{background:none;border:none;color:#fff;font-size:24px;cursor:pointer;width:30px;height:30px;line-height:1;padding:0;position:absolute;right:10px;top:50%;transform:translateY(-50%);opacity:.8}.wx-auth-close:hover{opacity:1}.wx-auth-body{padding:20px;text-align:center}.wx-auth-desc{font-size:15px;color:#333;margin-bottom:16px;font-weight:500}.wx-auth-hint{font-size:15px;color:#333;margin-top:12px;margin-bottom:16px;font-weight:500}.wx-auth-qrcode-container{width:180px;height:180px;margin:0 auto 8px;border:2px solid #07C160;border-radius:8px;overflow:hidden;background:#f5f5f5}.wx-auth-qrcode{width:100%;height:100%;display:none;object-fit:contain}.wx-auth-inputs{display:flex;gap:8px;justify-content:center;margin:20px 0}.wx-auth-input{width:42px;height:50px;font-size:20px;font-weight:600;text-align:center;border:2px solid #DCDCDC;border-radius:8px;outline:none;transition:all .2s;color:#333}.wx-auth-input:focus{border-color:#07c160;box-shadow:0 0 0 2px #07c16033}.wx-auth-input:disabled{background:#f5f5f5;color:#999}.wx-auth-success-icon{font-size:48px;margin-bottom:8px}.wx-auth-success-text{font-size:16px;color:#07c160;font-weight:600}.wx-auth-message{font-size:13px;padding:8px 12px;border-radius:6px;margin:8px 0;line-height:1.4}.wx-auth-message-info{background:#e8f4ff;color:#06c;border:1px solid #B3D9FF}.wx-auth-message-success{background:#f0fdf4;color:#07c160;border:1px solid #07C160}.wx-auth-message-error{background:#fef2f2;color:#dc2626;border:1px solid #DC2626}.wx-auth-actions{display:flex;gap:10px;margin-top:16px}.wx-auth-btn{flex:1;padding:12px 16px;border:none;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s;outline:none}.wx-auth-btn:active{transform:scale(.98)}.wx-auth-btn:disabled{opacity:.5;cursor:not-allowed}.wx-auth-btn-primary{background:#07c160;color:#fff}.wx-auth-btn-primary:hover:not(:disabled){background:#06ad56}.wx-auth-btn-secondary{background:#f2f2f2;color:#333}.wx-auth-btn-secondary:hover:not(:disabled){background:#e5e5e5}@keyframes wxAuthFadeIn{0%{opacity:0}to{opacity:1}}@keyframes wxAuthSlideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@media(max-width:480px){.wx-auth-content{width:95vw;margin:20px}.wx-auth-qrcode-container{width:160px;height:160px}.wx-auth-inputs{gap:6px}.wx-auth-input{width:38px;height:46px;font-size:18px}}@media(prefers-color-scheme:dark){.wx-auth-content{background:#1a1a1a}.wx-auth-desc,.wx-auth-hint{color:#e5e5e5}}.wx-auth-required .wx-auth-close{display:none!important}.wx-auth-optional .wx-auth-overlay{cursor:pointer}
|
|
2
|
-
/*$vite$:1*/`,document.head.appendChild(p);const d={observer:null,healthCheckTimer:null,isProtected:!1},x={enable(e){if(d.isProtected||typeof window>"u")return;const{modalId:t,getState:o}=e;d.observer=new MutationObserver(i=>{i.forEach(a=>{if(a.type==="childList")a.removedNodes.forEach(s=>{if(s.nodeType===Node.ELEMENT_NODE){const l=s;(l.id===t||l.querySelector?.(`#${t}`))&&(console.warn("[WxAuth] 检测到弹窗被删除,正在自动恢复..."),this.restore(e))}});else if(a.type==="attributes"){const s=a.target;s.id===t&&a.attributeName==="style"&&s.style.display==="none"&&o().isOpen&&(console.warn("[WxAuth] 检测到弹窗被隐藏,正在自动恢复..."),s.style.display="flex")}})}),d.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}),d.healthCheckTimer=window.setInterval(()=>{this.healthCheck(e)},1e3),d.isProtected=!0,console.log("[WxAuth] 弹窗保护已启用")},disable(){d.observer&&(d.observer.disconnect(),d.observer=null),d.healthCheckTimer&&(clearInterval(d.healthCheckTimer),d.healthCheckTimer=null),d.isProtected=!1,console.log("[WxAuth] 弹窗保护已禁用")},healthCheck(e){const{modalId:t,getState:o}=e;if(!o().isOpen)return;const i=document.getElementById(t);if(!i){console.warn("[WxAuth] 健康检查:弹窗不存在,正在恢复..."),this.restore(e);return}i.style.display==="none"&&(console.warn("[WxAuth] 健康检查:弹窗被隐藏,正在恢复..."),i.style.display="flex")},restore(e){const{modalId:t,getState:o,onRestore:i}=e;if(!o().isOpen)return;const a=document.getElementById(t);if(a){a.style.display="flex";return}i()}},w={apiBase:"https://wx-auth.shenzjd.com",siteId:"",onVerified:null,onError:null,onClose:null,required:!0,wechatName:"神族九帝",qrcodeUrl:""};let n={...w},c={isOpen:!1,resolveAuth:null,currentStep:"qr"};const r={getRootDomain(){try{const e=new URL(n.apiBase||window.location.origin).hostname;if(e==="localhost"||/^\d+\.\d+\.\d+\.\d+$/.test(e))return"";const t=e.split(".");return t.length>=2?"."+t.slice(-2).join("."):""}catch{return""}},getCookie(e){const o=`; ${document.cookie}`.split(`; ${e}=`);return o.length===2&&o.pop()?.split(";").shift()||null},setCookie(e,t){const o=new Date;o.setTime(o.getTime()+
|
|
2
|
+
/*$vite$:1*/`,document.head.appendChild(p);const d={observer:null,healthCheckTimer:null,isProtected:!1},x={enable(e){if(d.isProtected||typeof window>"u")return;const{modalId:t,getState:o}=e;d.observer=new MutationObserver(i=>{i.forEach(a=>{if(a.type==="childList")a.removedNodes.forEach(s=>{if(s.nodeType===Node.ELEMENT_NODE){const l=s;(l.id===t||l.querySelector?.(`#${t}`))&&(console.warn("[WxAuth] 检测到弹窗被删除,正在自动恢复..."),this.restore(e))}});else if(a.type==="attributes"){const s=a.target;s.id===t&&a.attributeName==="style"&&s.style.display==="none"&&o().isOpen&&(console.warn("[WxAuth] 检测到弹窗被隐藏,正在自动恢复..."),s.style.display="flex")}})}),d.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}),d.healthCheckTimer=window.setInterval(()=>{this.healthCheck(e)},1e3),d.isProtected=!0,console.log("[WxAuth] 弹窗保护已启用")},disable(){d.observer&&(d.observer.disconnect(),d.observer=null),d.healthCheckTimer&&(clearInterval(d.healthCheckTimer),d.healthCheckTimer=null),d.isProtected=!1,console.log("[WxAuth] 弹窗保护已禁用")},healthCheck(e){const{modalId:t,getState:o}=e;if(!o().isOpen)return;const i=document.getElementById(t);if(!i){console.warn("[WxAuth] 健康检查:弹窗不存在,正在恢复..."),this.restore(e);return}i.style.display==="none"&&(console.warn("[WxAuth] 健康检查:弹窗被隐藏,正在恢复..."),i.style.display="flex")},restore(e){const{modalId:t,getState:o,onRestore:i}=e;if(!o().isOpen)return;const a=document.getElementById(t);if(a){a.style.display="flex";return}i()}},w={apiBase:"https://wx-auth.shenzjd.com",siteId:"",onVerified:null,onError:null,onClose:null,required:!0,wechatName:"神族九帝",qrcodeUrl:""};let n={...w},c={isOpen:!1,resolveAuth:null,currentStep:"qr"};const r={getRootDomain(){try{const e=new URL(n.apiBase||window.location.origin).hostname;if(e==="localhost"||/^\d+\.\d+\.\d+\.\d+$/.test(e))return"";const t=e.split(".");return t.length>=2?"."+t.slice(-2).join("."):""}catch{return""}},getCookie(e){const o=`; ${document.cookie}`.split(`; ${e}=`);return o.length===2&&o.pop()?.split(";").shift()||null},setCookie(e,t){const o=new Date;o.setTime(o.getTime()+365*24*60*60*1e3);const i=this.getRootDomain(),a=i?`;domain=${i}`:"",l=window.location.protocol==="https:"?";Secure":"";document.cookie=`${e}=${t};expires=${o.toUTCString()};path=/${a}${l};SameSite=Strict`},deleteCookie(e){const t=this.getRootDomain(),o=t?`;domain=${t}`:"";document.cookie=`${e}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/${o};SameSite=Strict`},async request(e,t={}){try{const o=await fetch(e,{method:t.method||"GET",headers:{"Content-Type":"application/json",...t.headers},body:t.body?JSON.stringify(t.body):null,credentials:"include"});if(!o.ok)throw new Error(`HTTP ${o.status}`);return await o.json()}catch(o){throw console.error("[WxAuth] Request error:",o),o}},generateCodeInputs(){let e='<div class="wx-auth-inputs">';for(let t=0;t<6;t++)e+=`<input type="text" inputmode="numeric" pattern="[0-9]*" maxlength="1" class="wx-auth-input" data-index="${t}" autocomplete="off" />`;return e+="</div>",e}},u={createModal(){const e=document.createElement("div");e.id="wx-auth-modal",e.className="wx-auth-modal",n.required?e.classList.add("wx-auth-required"):e.classList.add("wx-auth-optional");const t=n.required?"":'<button class="wx-auth-close" onclick="WxAuth.close()">×</button>';return e.innerHTML=`
|
|
3
3
|
<div class="wx-auth-overlay" ${n.required?'onclick="event.preventDefault()"':""}></div>
|
|
4
4
|
<div class="wx-auth-content">
|
|
5
5
|
<div class="wx-auth-header">
|