@nibgate/sdk 0.2.39 → 0.2.41
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/nibgate.js +9 -2
- package/dist/nibgate.js.map +2 -2
- package/dist/nibgate.min.js +2 -3
- package/dist/nibgate.min.js.map +2 -2
- package/package.json +1 -1
- package/src/browser/default-ui.js +9 -2
package/dist/nibgate.min.js
CHANGED
|
@@ -81,14 +81,13 @@ ${cx(p)}`),super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessa
|
|
|
81
81
|
<div class="nui-stat" style="text-align:center;margin-top:16px" data-nibgate-status></div>
|
|
82
82
|
</div>
|
|
83
83
|
<div data-nibgate-premium hidden style="margin-top:32px;border-top:1px solid ${V.border};padding-top:32px">${r.premiumContentHTML||""}</div>
|
|
84
|
-
`,(typeof e=="string"?document.querySelector(e):e)?.appendChild(n),(function(){if(!document.getElementById("nibgate-lottie"))return;function _(O){var Y=document.getElementById("nibgate-lottie");Y&&window.lottie&&window.lottie.loadAnimation({container:Y,animationData:O,loop:!0,autoplay:!0})}if(window.lottie){window._lottieData?_(window._lottieData):fetch("/nibgate-unlock-key.json?t=1").then(function(O){if(!O.ok)throw new Error;return O.json()}).then(function(O){window._lottieData=O,_(O)}).catch(function(){});return}if(!window._lottieLoading){window._lottieLoading=!0;var L=document.createElement("script");L.src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",L.onload=function(){fetch("/nibgate-unlock-key.json?t=1").then(function(O){if(!O.ok)throw new Error;return O.json()}).then(function(O){window._lottieData=O,_(O)}).catch(function(){})},document.head.appendChild(L)}})();let s=n.querySelector("[data-nibgate-status]"),i=n.querySelector("[data-nibgate-wallet-label]"),a=n.querySelector("[data-nibgate-unlock-wrap]"),c=n.querySelector("[data-nibgate-unlock-progress]"),u=n.querySelector("[data-nibgate-unlock]"),f=n.querySelector("[data-nibgate-unlock-text]"),d=1500,l=null,p=!1,h=!1,y=Ci(t,{...r,connectButton:null,unlockButton:null,walletLabel:null,status:"[data-nibgate-status]",unlockedTarget:"[data-nibgate-premium]",onStatus:M=>hS(s,M),onUnlock:r.premiumContentUrl?async()=>{let M=n.querySelector("[data-nibgate-premium]");if(M){M.innerHTML="Loading content...";try{let _=await fetch(r.premiumContentUrl);if(!_.ok)throw new Error(`HTTP ${_.status}`);let L=await _.text();M.innerHTML=L}catch{M.innerHTML="Could not load premium content. Refresh and try again."}}}:r.onUnlock});function g(M){return M?M.slice(0,6)+"..."+M.slice(-4):""}function v(){let M=y.getWalletAddress();M?(i.innerHTML=g(M)+' <span data-nibgate-disconnect style="cursor:pointer">\xB7 Disconnect</span> <span data-nibgate-bal style="margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)">\xB7 <span data-nibgate-bal-txt></span> | '+U()+"</span>",P=i.querySelector("[data-nibgate-bal]"),P?.addEventListener("click",$),u.disabled=!1,u.style.cursor="pointer"):(i.innerHTML="Connect wallet",u.disabled=!0,u.style.cursor="default",f.innerHTML=o+"Hold to pay")}function E(){let M=i.querySelector("[data-nibgate-bal]");M&&!M._clickAttached&&(M.addEventListener("click",$),M._clickAttached=!0)}function x(M){f.innerHTML=o+M}function b(){p=!1,h=!1,l=null,u.style.transform="",u.style.boxShadow="",c.style.width="0%",u.disabled||x("Hold to pay")}function w(M){u.disabled||p||(M.preventDefault(),p=!0,h=!1,u.style.transform="scale(0.96)",u.style.boxShadow="0 2px 8px rgba(0,0,0,0.2)",c.style.transition="none",c.style.width="0%",x("Hold\u2026"),requestAnimationFrame(()=>{c.style.transition="width "+d+"ms linear",c.style.width="100%"}),l=setTimeout(()=>{h=!0,p=!1,u.style.transform="",u.style.boxShadow="",c.style.transition="width .05s linear",x("Processing\u2026"),u.disabled=!0,setTimeout(()=>y.unlock().then(v).catch(v),300)},d))}function A(){!p||h||(clearTimeout(l),b())}i.addEventListener("click",M=>{y.getWalletAddress()||y.connect().then(v).catch(()=>v())}),a.addEventListener("mousedown",w),a.addEventListener("touchstart",w,{passive:!1}),document.addEventListener("mouseup",A),document.addEventListener("touchend",A),a.addEventListener("mouseleave",A);function S(){(!u.style.transform||u.style.transform==="none"||u.style.transform==="")&&(u.style.transform="scale(0.97)")}function B(){p||(u.style.transform="")}u.addEventListener("mousedown",S),u.addEventListener("touchstart",S,{passive:!0}),u.addEventListener("mouseup",B),u.addEventListener("touchend",B),u.addEventListener("mouseleave",B),setTimeout(v,200);let R=()=>{document.removeEventListener("mouseup",A),document.removeEventListener("touchend",A)};n.addEventListener("remove",R);let P=null,k=null,N=null;function U(){return'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>'}function $(){if(k)return;k=an("div",{style:"position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;padding:20px;animation:nfade .15s ease-out"});let M=an("div",{style:"background:"+V.bg+";border-radius:16px;max-width:540px;width:100%;max-height:90vh;overflow:auto;position:relative;box-shadow:0 8px 32px rgba(0,0,0,0.12);animation:nscale .15s ease-out"}),_=an("button",{style:"position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:"+V.muted+";font-family:inherit;line-height:1"},"\xD7");_.addEventListener("click",()=>{k.remove(),k=null,document.removeEventListener("keydown",C)}),M.appendChild(_),k.appendChild(M),k.addEventListener("click",L=>{L.target===k&&(k.remove(),k=null,document.removeEventListener("keydown",C))}),document.body.appendChild(k),document.addEventListener("keydown",C),Promise.resolve().then(()=>(Mb(),w4)).then(L=>L.renderDefaultGatewayWalletUI(M,{address:y.getWalletAddress(),gatewayBalanceUrl:r.gatewayBalanceUrl,...r.gatewayOptions||{}})).catch(()=>{})}function C(M){M.key==="Escape"&&k&&(k.remove(),k=null,document.removeEventListener("keydown",C))}async function z(){if(!(!n.isConnected||!window.ethereum||!r.gatewayBalanceUrl))try{let M=await window.ethereum.request({method:"eth_accounts"}),_=Array.isArray(M)&&M[0]?M[0]:null;if(!_)return;E();let L=i.querySelector("[data-nibgate-bal-txt]");if(!L)return;let Y=await(await fetch(r.gatewayBalanceUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:_})})).json();L.textContent=Y?.balance||""}catch{}}return window.ethereum&&(N=setInterval(z,3e3),setTimeout(z,1e3),window.ethereum.on("accountsChanged",z)),{...y,element:n,destroy:()=>{R(),n.remove(),N&&clearInterval(N),k&&(k.remove(),k=null)}}}function $b(e,t,r={}){Rb();let n=0,o=!1,s=null,i=null,a=an("div",{cls:"nui",style:{animation:"nfade .2s ease-out",textAlign:"center",padding:"28px 0"}}),c=an("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"4px"}}),u=[];for(let E=1;E<=5;E++){let x=an("button",{type:"button","aria-label":`${E} star${E>1?"s":""}`,"data-star":E,style:{background:"none",border:"none",cursor:"pointer",padding:"4px",fontSize:"31px",lineHeight:"1",color:V.border,transition:"color .12s, transform .12s",borderRadius:"4px",fontFamily:"inherit"}},"\u2606");u.push(x),c.appendChild(x)}let f=an("span",{style:{fontSize:"17px",color:V.muted,marginLeft:"12px"}});f.textContent="No ratings yet",c.appendChild(f);let d=an("div",{style:{fontSize:"17px",color:V.muted,marginTop:"8px",minHeight:"1.4em"}});d.textContent="Tap stars to rate",a.append(c,d),(typeof e=="string"?document.querySelector(e):e)?.appendChild(a);function l(){i&&(clearTimeout(i),i=null),d.textContent=n>0?"":"Tap stars to rate",d.style.color=V.muted}function p(E,x,b){d.textContent=E||"",d.style.color=x||"",b&&(i=setTimeout(l,b))}function h(E){u.forEach((x,b)=>{let w=b<E;x.style.color=w?V.accent:V.border,x.textContent=w?"\u2605":"\u2606",x.style.transform=w?"scale(1.08)":"scale(1)"})}function y(E){p(["","Poor","Below average","Average","Good","Excellent"][E])}async function g(E){if(!(o||!s)){o=!0,u.forEach(x=>{x.disabled=!0,x.style.cursor="default"}),n=E,h(E),p("Submitting\u2026");try{await s.rate({rating:E}),h(E),p("You rated "+E+" \u2605".repeat(E),V.accent,3e3),v()}catch(x){p(x?.message||"Could not save rating. Try again.","#dc2626"),h(n)}finally{o=!1,u.forEach(x=>{x.disabled=!1,x.style.cursor="pointer"})}}}function v(){let E=r.statsUrl||(t.id?`${r.apiBase||"/api"}/rating/${t.id}`:null);E&&fetch(E).then(x=>x.json()).then(x=>{x.count>0?f.textContent=`${x.average.toFixed(1)} \u2014 ${x.count} rating${x.count!==1?"s":""}`:f.textContent="No ratings yet"}).catch(()=>{})}return u.forEach(E=>{let x=parseInt(E.dataset.star);E.addEventListener("mouseenter",()=>{o||(h(x),y(x))}),E.addEventListener("mouseleave",()=>{o||(h(n),l())}),E.addEventListener("click",()=>g(x)),E.addEventListener("keydown",b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),g(x))})}),Promise.resolve().then(()=>(Am(),b4)).then(E=>{s=E.createOnchainRating(t,{autoMount:!1,contentId:r.contentId||"0x"+(t.id||"").replace(/-/g,""),onRated:x=>{p("Rating saved",V.accent,3e3),v(),typeof r.onRated=="function"&&r.onRated(x)},onError:x=>{p(x?.message||"Could not save rating. Try again.","#dc2626"),typeof r.onError=="function"&&r.onError(x)}}),v()}).catch(()=>{p("Could not load rating","#dc2626")}),{element:a,destroy:()=>a.remove(),refresh:v,setRating:E=>{n=E,h(E)}}}function Hb(e,t={}){Rb();let r="deposit",n=an("div",{cls:"nui",style:{animation:"nfade .2s ease-out",border:"1px solid "+V.border,borderRadius:"16px",padding:"28px"}});n.innerHTML=`
|
|
84
|
+
`,(typeof e=="string"?document.querySelector(e):e)?.appendChild(n),(function(){if(!document.getElementById("nibgate-lottie"))return;function _(O){var Y=document.getElementById("nibgate-lottie");Y&&window.lottie&&window.lottie.loadAnimation({container:Y,animationData:O,loop:!0,autoplay:!0})}if(window.lottie){window._lottieData?_(window._lottieData):fetch("/nibgate-unlock-key.json?t=1").then(function(O){if(!O.ok)throw new Error;return O.json()}).then(function(O){window._lottieData=O,_(O)}).catch(function(){});return}if(!window._lottieLoading){window._lottieLoading=!0;var L=document.createElement("script");L.src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",L.onload=function(){fetch("/nibgate-unlock-key.json?t=1").then(function(O){if(!O.ok)throw new Error;return O.json()}).then(function(O){window._lottieData=O,_(O)}).catch(function(){})},document.head.appendChild(L)}})();let s=n.querySelector("[data-nibgate-status]"),i=n.querySelector("[data-nibgate-wallet-label]"),a=n.querySelector("[data-nibgate-unlock-wrap]"),c=n.querySelector("[data-nibgate-unlock-progress]"),u=n.querySelector("[data-nibgate-unlock]"),f=n.querySelector("[data-nibgate-unlock-text]"),d=1500,l=null,p=!1,h=!1,y=Ci(t,{...r,connectButton:null,unlockButton:null,walletLabel:null,status:"[data-nibgate-status]",unlockedTarget:"[data-nibgate-premium]",onStatus:M=>hS(s,M),onUnlock:r.premiumContentUrl?async()=>{let M=n.querySelector("[data-nibgate-premium]");if(M){M.innerHTML="Loading content...";try{let _=await fetch(r.premiumContentUrl);if(!_.ok)throw new Error(`HTTP ${_.status}`);let L=await _.text();M.innerHTML=L}catch{M.innerHTML="Could not load premium content. Refresh and try again."}}}:r.onUnlock});function g(M){return M?M.slice(0,6)+"..."+M.slice(-4):""}function v(){let M=y.getWalletAddress();M?(i.innerHTML=g(M)+' <span data-nibgate-disconnect style="cursor:pointer">\xB7 Disconnect</span> <span data-nibgate-bal style="margin-left:4px;cursor:pointer;white-space:nowrap;color:var(--accent,#7c9a6d)">\xB7 <span data-nibgate-bal-txt></span> | '+U()+"</span>",P=i.querySelector("[data-nibgate-bal]"),P?.addEventListener("click",$),u.disabled=!1,u.style.cursor="pointer"):(i.innerHTML="Connect wallet",u.disabled=!0,u.style.cursor="default",f.innerHTML=o+"Hold to pay")}function E(){let M=i.querySelector("[data-nibgate-bal]");M&&!M._clickAttached&&(M.addEventListener("click",$),M._clickAttached=!0)}function x(M){f.innerHTML=o+M}function b(){p=!1,h=!1,l=null,u.style.transform="",u.style.boxShadow="",c.style.width="0%",u.disabled||x("Hold to pay")}function w(M){u.disabled||p||(M.preventDefault(),p=!0,h=!1,u.style.transform="scale(0.96)",u.style.boxShadow="0 2px 8px rgba(0,0,0,0.2)",c.style.transition="none",c.style.width="0%",x("Hold\u2026"),requestAnimationFrame(()=>{c.style.transition="width "+d+"ms linear",c.style.width="100%"}),l=setTimeout(()=>{h=!0,p=!1,u.style.transform="",u.style.boxShadow="",c.style.transition="width .05s linear",x("Processing\u2026"),u.disabled=!0,setTimeout(()=>y.unlock().then(v).catch(v),300)},d))}function A(){!p||h||(clearTimeout(l),b())}i.addEventListener("click",M=>{y.getWalletAddress()||y.connect().then(v).catch(()=>v())}),a.addEventListener("mousedown",w),a.addEventListener("touchstart",w,{passive:!1}),document.addEventListener("mouseup",A),document.addEventListener("touchend",A),a.addEventListener("mouseleave",A);function S(){(!u.style.transform||u.style.transform==="none"||u.style.transform==="")&&(u.style.transform="scale(0.97)")}function B(){p||(u.style.transform="")}u.addEventListener("mousedown",S),u.addEventListener("touchstart",S,{passive:!0}),u.addEventListener("mouseup",B),u.addEventListener("touchend",B),u.addEventListener("mouseleave",B),setTimeout(v,200);let R=()=>{document.removeEventListener("mouseup",A),document.removeEventListener("touchend",A)};n.addEventListener("remove",R);let P=null,k=null,N=null;function U(){return'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>'}function $(){if(k)return;k=an("div",{style:"position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;padding:20px;animation:nfade .15s ease-out"});let M=an("div",{style:"background:"+V.bg+";border-radius:16px;max-width:540px;width:100%;max-height:90vh;overflow:auto;position:relative;box-shadow:0 8px 32px rgba(0,0,0,0.12);animation:nscale .15s ease-out"}),_=an("button",{style:"position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:"+V.muted+";font-family:inherit;line-height:1"},"\xD7");_.addEventListener("click",()=>{k.remove(),k=null,document.removeEventListener("keydown",C)}),M.appendChild(_),k.appendChild(M),k.addEventListener("click",L=>{L.target===k&&(k.remove(),k=null,document.removeEventListener("keydown",C))}),document.body.appendChild(k),document.addEventListener("keydown",C),Promise.resolve().then(()=>(Mb(),w4)).then(L=>L.renderDefaultGatewayWalletUI(M,{address:y.getWalletAddress(),gatewayBalanceUrl:r.gatewayBalanceUrl,...r.gatewayOptions||{}})).catch(()=>{})}function C(M){M.key==="Escape"&&k&&(k.remove(),k=null,document.removeEventListener("keydown",C))}async function z(){if(!(!n.isConnected||!window.ethereum||!r.gatewayBalanceUrl))try{let M=await window.ethereum.request({method:"eth_accounts"}),_=Array.isArray(M)&&M[0]?M[0]:null;if(!_)return;E();let L=i.querySelector("[data-nibgate-bal-txt]");if(!L)return;let Y=await(await fetch(r.gatewayBalanceUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:_})})).json();L.textContent=Y?.balance||""}catch{}}return window.ethereum&&(N=setInterval(z,3e3),setTimeout(z,1e3),window.ethereum.on("accountsChanged",z)),{...y,element:n,destroy:()=>{R(),n.remove(),N&&clearInterval(N),k&&(k.remove(),k=null)}}}function $b(e,t,r={}){Rb();let n=0,o=!1,s=null,i=null,a=an("div",{cls:"nui",style:{animation:"nfade .2s ease-out",textAlign:"center",padding:"28px 0"}}),c=an("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"4px"}}),u=[];for(let E=1;E<=5;E++){let x=an("button",{type:"button","aria-label":`${E} star${E>1?"s":""}`,"data-star":E,style:{background:"none",border:"none",cursor:"pointer",padding:"4px",fontSize:"31px",lineHeight:"1",color:V.border,transition:"color .12s, transform .12s",borderRadius:"4px",fontFamily:"inherit"}},"\u2606");u.push(x),c.appendChild(x)}let f=an("span",{style:{fontSize:"17px",color:V.muted,marginLeft:"12px"}});f.textContent="No ratings yet",c.appendChild(f);let d=an("div",{style:{fontSize:"17px",color:V.muted,marginTop:"8px",minHeight:"1.4em"}});d.textContent="Tap stars to rate",a.append(c,d),(typeof e=="string"?document.querySelector(e):e)?.appendChild(a);function l(){i&&(clearTimeout(i),i=null),d.textContent=n>0?"":"Tap stars to rate",d.style.color=V.muted}function p(E,x,b){d.textContent=E||"",d.style.color=x||"",b&&(i=setTimeout(l,b))}function h(E){u.forEach((x,b)=>{let w=b<E;x.style.color=w?V.accent:V.border,x.textContent=w?"\u2605":"\u2606",x.style.transform=w?"scale(1.08)":"scale(1)"})}function y(E){p(["","Poor","Below average","Average","Good","Excellent"][E])}async function g(E){if(!(o||!s)){o=!0,u.forEach(x=>{x.disabled=!0,x.style.cursor="default"}),n=E,h(E),p("Submitting\u2026");try{await s.rate({rating:E}),h(E),p("You rated "+E+" \u2605".repeat(E),V.accent,3e3),v()}catch(x){p(x?.message||"Could not save rating. Try again.","#dc2626"),h(n)}finally{o=!1,u.forEach(x=>{x.disabled=!1,x.style.cursor="pointer"})}}}function v(){let E=r.statsUrl||(t.id?`${r.apiBase||"/api"}/rating/${t.id}`:null);E&&fetch(E).then(x=>x.json()).then(x=>{x.count>0?f.textContent=`${x.average.toFixed(1)} \u2014 ${x.count} rating${x.count!==1?"s":""}`:f.textContent="No ratings yet"}).catch(()=>{})}return u.forEach(E=>{let x=parseInt(E.dataset.star);E.addEventListener("mouseenter",()=>{o||(h(x),y(x))}),E.addEventListener("mouseleave",()=>{o||(h(n),l())}),E.addEventListener("click",()=>g(x)),E.addEventListener("keydown",b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),g(x))})}),Promise.resolve().then(()=>(Am(),b4)).then(E=>{s=E.createOnchainRating(t,{autoMount:!1,contentId:r.contentId||"0x"+(t.id||"").replace(/-/g,""),indexUrl:r.indexUrl,siteId:r.siteId,token:r.token,indexHeaders:r.indexHeaders,actor:r.actor,paymentId:r.paymentId,getPaymentId:r.getPaymentId,getUnlockRef:r.getUnlockRef,onRated:x=>{p("Rating saved",V.accent,3e3),v(),typeof r.onRated=="function"&&r.onRated(x)},onError:x=>{p(x?.message||"Could not save rating. Try again.","#dc2626"),typeof r.onError=="function"&&r.onError(x)}}),v()}).catch(()=>{p("Could not load rating","#dc2626")}),{element:a,destroy:()=>a.remove(),refresh:v,setRating:E=>{n=E,h(E)}}}function Hb(e,t={}){Rb();let r="deposit",n=an("div",{cls:"nui",style:{animation:"nfade .2s ease-out",border:"1px solid "+V.border,borderRadius:"16px",padding:"28px"}});n.innerHTML=`
|
|
85
85
|
<div style="display:flex;gap:12px;margin-bottom:20px">
|
|
86
86
|
<div data-gw-wallet-card style="flex:1;background:${V.bg};border:1px solid ${V.border};border-radius:12px;padding:16px">
|
|
87
87
|
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">
|
|
88
|
-
<div></div>
|
|
88
|
+
<div data-gw-wallet-addr class="nui-mono" style="font-size:13px;color:${V.muted}"></div>
|
|
89
89
|
<span data-gw-connect-label style="font-size:12px;font-weight:600;color:${V.accent}">Connected</span>
|
|
90
90
|
</div>
|
|
91
|
-
<div data-gw-wallet-addr class="nui-mono" style="font-size:13px;color:${V.muted};margin-bottom:4px"></div>
|
|
92
91
|
<div data-gw-wallet-balance class="nui-mono" style="font-size:24px;font-weight:700;color:${V.fg}">\u2014</div>
|
|
93
92
|
</div>
|
|
94
93
|
<div style="flex:1;background:${V.bg};border:1px solid ${V.border};border-radius:12px;padding:16px">
|