@nibgate/sdk 0.2.33 → 0.2.34

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.
@@ -79,7 +79,7 @@ ${cx(p)}`),super(t.shortMessage,{cause:t,docsPath:n,metaMessages:[...t.metaMessa
79
79
  <div class="nui-stat" style="text-align:center;margin-top:16px" data-nibgate-status></div>
80
80
  </div>
81
81
  <div data-nibgate-premium hidden style="margin-top:32px;border-top:1px solid ${V.border};padding-top:32px">${r.premiumContentHTML||""}</div>
82
- `,(typeof e=="string"?document.querySelector(e):e)?.appendChild(n),(function(){if(!document.getElementById("nibgate-lottie"))return;function R(N){var U=document.getElementById("nibgate-lottie");U&&window.lottie&&window.lottie.loadAnimation({container:U,animationData:N,loop:!0,autoplay:!0})}if(window.lottie){window._lottieData?R(window._lottieData):fetch("/nibgate-unlock-key.json?t=1").then(function(N){if(!N.ok)throw new Error;return N.json()}).then(function(N){window._lottieData=N,R(N)}).catch(function(){});return}if(!window._lottieLoading){window._lottieLoading=!0;var B=document.createElement("script");B.src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",B.onload=function(){fetch("/nibgate-unlock-key.json?t=1").then(function(N){if(!N.ok)throw new Error;return N.json()}).then(function(N){window._lottieData=N,R(N)}).catch(function(){})},document.head.appendChild(B)}})();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=1500,d=null,l=!1,p=!1,h=Ci(t,{...r,connectButton:null,unlockButton:null,walletLabel:null,status:"[data-nibgate-status]",unlockedTarget:"[data-nibgate-premium]",onStatus:C=>hS(s,C),onUnlock:r.premiumContentUrl?async()=>{let C=n.querySelector("[data-nibgate-premium]");if(C){C.innerHTML="Loading content...";try{let R=await fetch(r.premiumContentUrl);if(!R.ok)throw new Error(`HTTP ${R.status}`);let B=await R.text();C.innerHTML=B}catch{C.innerHTML="Could not load premium content. Refresh and try again."}}}:r.onUnlock});function y(C){return C?C.slice(0,6)+"..."+C.slice(-4):""}function g(){let C=h.getWalletAddress();C?(i.innerHTML=y(C)+' <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> | '+$()+"</span>",balEl=i.querySelector("[data-nibgate-bal]"),balEl?.addEventListener("click",S),u.disabled=!1,u.style.cursor="pointer"):(i.innerHTML="Connect wallet",u.disabled=!0,u.style.cursor="default",u.innerHTML=o+"Hold to pay")}function v(){let C=i.querySelector("[data-nibgate-bal]");C&&!C._clickAttached&&(C.addEventListener("click",S),C._clickAttached=!0)}function E(C){u.innerHTML=o+C}function x(){l=!1,p=!1,d=null,u.style.transform="",u.style.boxShadow="",c.style.width="0%",u.disabled||E("Hold to pay")}function b(C){u.disabled||l||(C.preventDefault(),l=!0,p=!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%",E("Hold\u2026"),requestAnimationFrame(()=>{c.style.transition="width "+f+"ms linear",c.style.width="100%"}),d=setTimeout(()=>{p=!0,l=!1,u.style.transform="",u.style.boxShadow="",c.style.transition="width .05s linear",E("Processing\u2026"),u.disabled=!0,setTimeout(()=>h.unlock().then(g).catch(g),300)},f))}function w(){!l||p||(clearTimeout(d),x())}i.addEventListener("click",C=>{h.getWalletAddress()||h.connect().then(g).catch(()=>g())}),a.addEventListener("mousedown",b),a.addEventListener("touchstart",b,{passive:!1}),document.addEventListener("mouseup",w),document.addEventListener("touchend",w),a.addEventListener("mouseleave",w),setTimeout(g,200);let A=()=>{document.removeEventListener("mouseup",w),document.removeEventListener("touchend",w)};n.addEventListener("remove",A);let P=null,k=null;function $(){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 S(){if(P)return;P=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 C=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"}),R=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");R.addEventListener("click",()=>{P.remove(),P=null,document.removeEventListener("keydown",M)}),C.appendChild(R),P.appendChild(C),P.addEventListener("click",B=>{B.target===P&&(P.remove(),P=null,document.removeEventListener("keydown",M))}),document.body.appendChild(P),document.addEventListener("keydown",M),Promise.resolve().then(()=>(Mb(),w4)).then(B=>B.renderDefaultGatewayWalletUI(C,r.gatewayOptions||{})).catch(()=>{})}function M(C){C.key==="Escape"&&P&&(P.remove(),P=null,document.removeEventListener("keydown",M))}async function _(){if(!(!n.isConnected||!window.ethereum||!r.gatewayBalanceUrl))try{let C=await window.ethereum.request({method:"eth_accounts"}),R=Array.isArray(C)&&C[0]?C[0]:null;if(!R)return;v();let B=i.querySelector("[data-nibgate-bal-txt]");if(!B)return;let U=await(await fetch(r.gatewayBalanceUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:R})})).json();B.textContent=U?.balance||""}catch{}}return window.ethereum&&(k=setInterval(_,3e3),setTimeout(_,1e3),window.ethereum.on("accountsChanged",_)),{...h,element:n,destroy:()=>{A(),n.remove(),k&&clearInterval(k),P&&(P.remove(),P=null)}}}function Nb(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=`
82
+ `,(typeof e=="string"?document.querySelector(e):e)?.appendChild(n),(function(){if(!document.getElementById("nibgate-lottie"))return;function R(N){var U=document.getElementById("nibgate-lottie");U&&window.lottie&&window.lottie.loadAnimation({container:U,animationData:N,loop:!0,autoplay:!0})}if(window.lottie){window._lottieData?R(window._lottieData):fetch("/nibgate-unlock-key.json?t=1").then(function(N){if(!N.ok)throw new Error;return N.json()}).then(function(N){window._lottieData=N,R(N)}).catch(function(){});return}if(!window._lottieLoading){window._lottieLoading=!0;var B=document.createElement("script");B.src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",B.onload=function(){fetch("/nibgate-unlock-key.json?t=1").then(function(N){if(!N.ok)throw new Error;return N.json()}).then(function(N){window._lottieData=N,R(N)}).catch(function(){})},document.head.appendChild(B)}})();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=1500,d=null,l=!1,p=!1,h=Ci(t,{...r,connectButton:null,unlockButton:null,walletLabel:null,status:"[data-nibgate-status]",unlockedTarget:"[data-nibgate-premium]",onStatus:C=>hS(s,C),onUnlock:r.premiumContentUrl?async()=>{let C=n.querySelector("[data-nibgate-premium]");if(C){C.innerHTML="Loading content...";try{let R=await fetch(r.premiumContentUrl);if(!R.ok)throw new Error(`HTTP ${R.status}`);let B=await R.text();C.innerHTML=B}catch{C.innerHTML="Could not load premium content. Refresh and try again."}}}:r.onUnlock});function y(C){return C?C.slice(0,6)+"..."+C.slice(-4):""}function g(){let C=h.getWalletAddress();C?(i.innerHTML=y(C)+' <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> | '+$()+"</span>",balEl=i.querySelector("[data-nibgate-bal]"),balEl?.addEventListener("click",S),u.disabled=!1,u.style.cursor="pointer"):(i.innerHTML="Connect wallet",u.disabled=!0,u.style.cursor="default",u.innerHTML=o+"Hold to pay")}function v(){let C=i.querySelector("[data-nibgate-bal]");C&&!C._clickAttached&&(C.addEventListener("click",S),C._clickAttached=!0)}function E(C){u.innerHTML=o+C}function x(){l=!1,p=!1,d=null,u.style.transform="",u.style.boxShadow="",c.style.width="0%",u.disabled||E("Hold to pay")}function b(C){u.disabled||l||(C.preventDefault(),l=!0,p=!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%",E("Hold\u2026"),requestAnimationFrame(()=>{c.style.transition="width "+f+"ms linear",c.style.width="100%"}),d=setTimeout(()=>{p=!0,l=!1,u.style.transform="",u.style.boxShadow="",c.style.transition="width .05s linear",E("Processing\u2026"),u.disabled=!0,setTimeout(()=>h.unlock().then(g).catch(g),300)},f))}function w(){!l||p||(clearTimeout(d),x())}i.addEventListener("click",C=>{C.target.dataset.nibgateDisconnect!==void 0?h.disconnect().then(g):h.getWalletAddress()||h.connect().then(g).catch(()=>g())}),a.addEventListener("mousedown",b),a.addEventListener("touchstart",b,{passive:!1}),document.addEventListener("mouseup",w),document.addEventListener("touchend",w),a.addEventListener("mouseleave",w),setTimeout(g,200);let A=()=>{document.removeEventListener("mouseup",w),document.removeEventListener("touchend",w)};n.addEventListener("remove",A);let P=null,k=null;function $(){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 S(){if(P)return;P=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 C=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"}),R=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");R.addEventListener("click",()=>{P.remove(),P=null,document.removeEventListener("keydown",M)}),C.appendChild(R),P.appendChild(C),P.addEventListener("click",B=>{B.target===P&&(P.remove(),P=null,document.removeEventListener("keydown",M))}),document.body.appendChild(P),document.addEventListener("keydown",M),Promise.resolve().then(()=>(Mb(),w4)).then(B=>B.renderDefaultGatewayWalletUI(C,r.gatewayOptions||{})).catch(()=>{})}function M(C){C.key==="Escape"&&P&&(P.remove(),P=null,document.removeEventListener("keydown",M))}async function _(){if(!(!n.isConnected||!window.ethereum||!r.gatewayBalanceUrl))try{let C=await window.ethereum.request({method:"eth_accounts"}),R=Array.isArray(C)&&C[0]?C[0]:null;if(!R)return;v();let B=i.querySelector("[data-nibgate-bal-txt]");if(!B)return;let U=await(await fetch(r.gatewayBalanceUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({address:R})})).json();B.textContent=U?.balance||""}catch{}}return window.ethereum&&(k=setInterval(_,3e3),setTimeout(_,1e3),window.ethereum.on("accountsChanged",_)),{...h,element:n,destroy:()=>{A(),n.remove(),k&&clearInterval(k),P&&(P.remove(),P=null)}}}function Nb(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=`
83
83
  <div style="display:flex;gap:12px;margin-bottom:20px">
84
84
  <div data-gw-wallet-card style="flex:1;background:${V.bg};border:1px solid ${V.border};border-radius:12px;padding:16px">
85
85
  <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">