@nibgate/sdk 0.2.22 → 0.2.23

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 ${G.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($){var L=document.getElementById("nibgate-lottie");L&&window.lottie&&window.lottie.loadAnimation({container:L,animationData:$,loop:!0,autoplay:!0})}if(window.lottie){window._lottieData?R(window._lottieData):fetch("/nibgate-unlock-key.json?t=1").then(function($){if(!$.ok)throw new Error;return $.json()}).then(function($){window._lottieData=$,R($)}).catch(function(){});return}if(!window._lottieLoading){window._lottieLoading=!0;var U=document.createElement("script");U.src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",U.onload=function(){fetch("/nibgate-unlock-key.json?t=1").then(function($){if(!$.ok)throw new Error;return $.json()}).then(function($){window._lottieData=$,R($)}).catch(function(){})},document.head.appendChild(U)}})();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:S=>hS(s,S),onUnlock:r.premiumContentUrl?async()=>{let S=n.querySelector("[data-nibgate-premium]");if(S){S.innerHTML="Loading content...";try{let R=await fetch(r.premiumContentUrl);if(!R.ok)throw new Error(`HTTP ${R.status}`);let U=await R.text();S.innerHTML=U}catch{S.innerHTML="Could not load premium content. Refresh and try again."}}}:r.onUnlock});function y(S){return S?S.slice(0,6)+"..."+S.slice(-4):""}function g(){let S=h.getWalletAddress();S?(i.innerHTML=y(S)+' <span data-nibgate-disconnect style="cursor:pointer">\xB7 Disconnect</span>',u.disabled=!1,u.style.cursor="pointer"):(i.textContent="Connect wallet",u.disabled=!0,u.style.cursor="default",u.innerHTML=o+"Hold to pay")}function v(S){u.innerHTML=o+S}function A(){l=!1,p=!1,d=null,u.style.transform="scale(1)",u.style.boxShadow="0 4px 12px rgba(0,0,0,0.08)",c.style.width="0%",u.disabled||v("Hold to pay")}function x(S){u.disabled||l||(S.preventDefault(),l=!0,p=!1,u.style.transform="scale(.97)",u.style.boxShadow="0 2px 6px rgba(0,0,0,0.12)",c.style.transition="none",c.style.width="0%",v("Hold\u2026"),requestAnimationFrame(()=>{c.style.transition="width "+f+"ms linear",c.style.width="100%"}),d=setTimeout(()=>{p=!0,l=!1,u.style.transform="scale(1)",u.style.boxShadow="0 4px 12px rgba(0,0,0,0.08)",c.style.transition="width .05s linear",v("Processing\u2026"),u.disabled=!0,setTimeout(()=>h.unlock().then(g).catch(g),300)},f))}function b(){!l||p||(clearTimeout(d),A())}i.addEventListener("click",S=>{S.target.dataset.nibgateDisconnect!==void 0?h.disconnect().then(g):h.getWalletAddress()||h.connect().then(g).catch(()=>g())}),a.addEventListener("mousedown",x),a.addEventListener("touchstart",x,{passive:!1}),document.addEventListener("mouseup",b),document.addEventListener("touchend",b),a.addEventListener("mouseleave",b),setTimeout(g,200);let w=()=>{document.removeEventListener("mouseup",b),document.removeEventListener("touchend",b)};n.addEventListener("remove",w);let E=null,P=null,k=null;function C(){return'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:baseline"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>'}async function I(){if(E)return;E=$r("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 S=$r("div",{style:"background:"+G.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=$r("button",{style:"position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:"+G.muted+";font-family:inherit;line-height:1"},"\xD7");R.addEventListener("click",M),S.appendChild(R),E.appendChild(S),E.addEventListener("click",$=>{$.target===E&&M()}),document.body.appendChild(E),document.addEventListener("keydown",_),(await Promise.resolve().then(()=>(Mb(),wE))).renderDefaultGatewayWalletUI(S,r.gatewayOptions||{})}function M(){E&&(E.remove(),E=null,document.removeEventListener("keydown",_))}function _(S){S.key==="Escape"&&M()}function z(){return k&&k.isConnected||(k=$r("span",{"data-nibgate-bal":"",style:"margin-left:6px;cursor:pointer;white-space:nowrap"},C()+" <span data-nibgate-bal-text></span>"),k.addEventListener("click",I),i.parentNode&&i.parentNode.insertBefore(k,i.nextSibling)),k}async function N(){if(stateRef?.destroyed)return;let S=h.getWalletAddress();if(!S)return;let R=z().querySelector("[data-nibgate-bal-text]");if(r.gatewayBalanceUrl)try{let $=await(await fetch(r.gatewayBalanceUrl+"?address="+encodeURIComponent(S))).json();R&&(R.textContent=$?.balance||$?.availableBalance||"\u2026");return}catch{}R&&(R.textContent="\u2026")}return window.ethereum&&(P=setInterval(N,3e3),setTimeout(N,1e3),window.ethereum.on("accountsChanged",N)),{...h,element:n,destroy:()=>{w(),n.remove(),P&&clearInterval(P),M()}}}function Nb(e,t,r={}){Rb();let n=0,o=!1,s=null,i=null,a=$r("div",{cls:"nui",style:{animation:"nfade .2s ease-out",textAlign:"center",padding:"28px 0"}}),c=$r("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"4px"}}),u=[];for(let A=1;A<=5;A++){let x=$r("button",{type:"button","aria-label":`${A} star${A>1?"s":""}`,"data-star":A,style:{background:"none",border:"none",cursor:"pointer",padding:"4px",fontSize:"31px",lineHeight:"1",color:G.border,transition:"color .12s, transform .12s",borderRadius:"4px",fontFamily:"inherit"}},"\u2606");u.push(x),c.appendChild(x)}let f=$r("span",{style:{fontSize:"17px",color:G.muted,marginLeft:"12px"}});f.textContent="No ratings yet",c.appendChild(f);let d=$r("div",{style:{fontSize:"17px",color:G.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=G.muted}function p(A,x,b){d.textContent=A||"",d.style.color=x||"",b&&(i=setTimeout(l,b))}function h(A){u.forEach((x,b)=>{let w=b<A;x.style.color=w?G.accent:G.border,x.textContent=w?"\u2605":"\u2606",x.style.transform=w?"scale(1.08)":"scale(1)"})}function y(A){p(["","Poor","Below average","Average","Good","Excellent"][A])}async function g(A){if(!(o||!s)){o=!0,u.forEach(x=>{x.disabled=!0,x.style.cursor="default"}),n=A,h(A),p("Submitting\u2026");try{await s.rate({rating:A}),h(A),p("You rated "+A+" \u2605".repeat(A),G.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 A=r.statsUrl||(t.id?`${r.apiBase||"/api"}/rating/${t.id}`:null);A&&fetch(A).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(A=>{let x=parseInt(A.dataset.star);A.addEventListener("mouseenter",()=>{o||(h(x),y(x))}),A.addEventListener("mouseleave",()=>{o||(h(n),l())}),A.addEventListener("click",()=>g(x)),A.addEventListener("keydown",b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),g(x))})}),Promise.resolve().then(()=>(Am(),bE)).then(A=>{s=A.createOnchainRating(t,{autoMount:!1,contentId:r.contentId||"0x"+(t.id||"").replace(/-/g,""),onRated:x=>{p("Rating saved",G.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:A=>{n=A,h(A)}}}function Hb(e,t={}){Rb();let r="deposit",n=$r("div",{cls:"nui",style:{animation:"nfade .2s ease-out",border:"1px solid "+G.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($){var L=document.getElementById("nibgate-lottie");L&&window.lottie&&window.lottie.loadAnimation({container:L,animationData:$,loop:!0,autoplay:!0})}if(window.lottie){window._lottieData?R(window._lottieData):fetch("/nibgate-unlock-key.json?t=1").then(function($){if(!$.ok)throw new Error;return $.json()}).then(function($){window._lottieData=$,R($)}).catch(function(){});return}if(!window._lottieLoading){window._lottieLoading=!0;var U=document.createElement("script");U.src="https://cdnjs.cloudflare.com/ajax/libs/lottie-web/5.12.2/lottie.min.js",U.onload=function(){fetch("/nibgate-unlock-key.json?t=1").then(function($){if(!$.ok)throw new Error;return $.json()}).then(function($){window._lottieData=$,R($)}).catch(function(){})},document.head.appendChild(U)}})();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:S=>hS(s,S),onUnlock:r.premiumContentUrl?async()=>{let S=n.querySelector("[data-nibgate-premium]");if(S){S.innerHTML="Loading content...";try{let R=await fetch(r.premiumContentUrl);if(!R.ok)throw new Error(`HTTP ${R.status}`);let U=await R.text();S.innerHTML=U}catch{S.innerHTML="Could not load premium content. Refresh and try again."}}}:r.onUnlock});function y(S){return S?S.slice(0,6)+"..."+S.slice(-4):""}function g(){let S=h.getWalletAddress();S?(i.innerHTML=y(S)+' <span data-nibgate-disconnect style="cursor:pointer">\xB7 Disconnect</span>',u.disabled=!1,u.style.cursor="pointer"):(i.textContent="Connect wallet",u.disabled=!0,u.style.cursor="default",u.innerHTML=o+"Hold to pay")}function v(S){u.innerHTML=o+S}function A(){l=!1,p=!1,d=null,u.style.transform="scale(1)",u.style.boxShadow="0 4px 12px rgba(0,0,0,0.08)",c.style.width="0%",u.disabled||v("Hold to pay")}function x(S){u.disabled||l||(S.preventDefault(),l=!0,p=!1,u.style.transform="scale(.97)",u.style.boxShadow="0 2px 6px rgba(0,0,0,0.12)",c.style.transition="none",c.style.width="0%",v("Hold\u2026"),requestAnimationFrame(()=>{c.style.transition="width "+f+"ms linear",c.style.width="100%"}),d=setTimeout(()=>{p=!0,l=!1,u.style.transform="scale(1)",u.style.boxShadow="0 4px 12px rgba(0,0,0,0.08)",c.style.transition="width .05s linear",v("Processing\u2026"),u.disabled=!0,setTimeout(()=>h.unlock().then(g).catch(g),300)},f))}function b(){!l||p||(clearTimeout(d),A())}i.addEventListener("click",S=>{S.target.dataset.nibgateDisconnect!==void 0?h.disconnect().then(g):h.getWalletAddress()||h.connect().then(g).catch(()=>g())}),a.addEventListener("mousedown",x),a.addEventListener("touchstart",x,{passive:!1}),document.addEventListener("mouseup",b),document.addEventListener("touchend",b),a.addEventListener("mouseleave",b),setTimeout(g,200);let w=()=>{document.removeEventListener("mouseup",b),document.removeEventListener("touchend",b)};n.addEventListener("remove",w);let E=null,P=null,k=null;function C(){return'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:baseline"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>'}async function I(){if(E)return;E=$r("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 S=$r("div",{style:"background:"+G.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=$r("button",{style:"position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:"+G.muted+";font-family:inherit;line-height:1"},"\xD7");R.addEventListener("click",M),S.appendChild(R),E.appendChild(S),E.addEventListener("click",$=>{$.target===E&&M()}),document.body.appendChild(E),document.addEventListener("keydown",_),(await Promise.resolve().then(()=>(Mb(),wE))).renderDefaultGatewayWalletUI(S,r.gatewayOptions||{})}function M(){E&&(E.remove(),E=null,document.removeEventListener("keydown",_))}function _(S){S.key==="Escape"&&M()}function z(){return k&&k.isConnected||(k=$r("span",{"data-nibgate-bal":"",style:"margin-left:6px;cursor:pointer;white-space:nowrap"},C()+" <span data-nibgate-bal-text></span>"),k.addEventListener("click",I),i.parentNode&&i.parentNode.insertBefore(k,i.nextSibling)),k}async function N(){if(!n.isConnected)return;let S=h.getWalletAddress();if(!S)return;let R=z().querySelector("[data-nibgate-bal-text]");if(r.gatewayBalanceUrl)try{let $=await(await fetch(r.gatewayBalanceUrl+"?address="+encodeURIComponent(S))).json();R&&(R.textContent=$?.balance||$?.availableBalance||"\u2026");return}catch{}R&&(R.textContent="\u2026")}return window.ethereum&&(P=setInterval(N,3e3),setTimeout(N,1e3),window.ethereum.on("accountsChanged",N)),{...h,element:n,destroy:()=>{w(),n.remove(),P&&clearInterval(P),M()}}}function Nb(e,t,r={}){Rb();let n=0,o=!1,s=null,i=null,a=$r("div",{cls:"nui",style:{animation:"nfade .2s ease-out",textAlign:"center",padding:"28px 0"}}),c=$r("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"4px"}}),u=[];for(let A=1;A<=5;A++){let x=$r("button",{type:"button","aria-label":`${A} star${A>1?"s":""}`,"data-star":A,style:{background:"none",border:"none",cursor:"pointer",padding:"4px",fontSize:"31px",lineHeight:"1",color:G.border,transition:"color .12s, transform .12s",borderRadius:"4px",fontFamily:"inherit"}},"\u2606");u.push(x),c.appendChild(x)}let f=$r("span",{style:{fontSize:"17px",color:G.muted,marginLeft:"12px"}});f.textContent="No ratings yet",c.appendChild(f);let d=$r("div",{style:{fontSize:"17px",color:G.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=G.muted}function p(A,x,b){d.textContent=A||"",d.style.color=x||"",b&&(i=setTimeout(l,b))}function h(A){u.forEach((x,b)=>{let w=b<A;x.style.color=w?G.accent:G.border,x.textContent=w?"\u2605":"\u2606",x.style.transform=w?"scale(1.08)":"scale(1)"})}function y(A){p(["","Poor","Below average","Average","Good","Excellent"][A])}async function g(A){if(!(o||!s)){o=!0,u.forEach(x=>{x.disabled=!0,x.style.cursor="default"}),n=A,h(A),p("Submitting\u2026");try{await s.rate({rating:A}),h(A),p("You rated "+A+" \u2605".repeat(A),G.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 A=r.statsUrl||(t.id?`${r.apiBase||"/api"}/rating/${t.id}`:null);A&&fetch(A).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(A=>{let x=parseInt(A.dataset.star);A.addEventListener("mouseenter",()=>{o||(h(x),y(x))}),A.addEventListener("mouseleave",()=>{o||(h(n),l())}),A.addEventListener("click",()=>g(x)),A.addEventListener("keydown",b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),g(x))})}),Promise.resolve().then(()=>(Am(),bE)).then(A=>{s=A.createOnchainRating(t,{autoMount:!1,contentId:r.contentId||"0x"+(t.id||"").replace(/-/g,""),onRated:x=>{p("Rating saved",G.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:A=>{n=A,h(A)}}}function Hb(e,t={}){Rb();let r="deposit",n=$r("div",{cls:"nui",style:{animation:"nfade .2s ease-out",border:"1px solid "+G.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:${G.bg};border:1px solid ${G.border};border-radius:12px;padding:16px">
85
85
  <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">