@betorigami/games 1.1.2 → 1.1.3

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/index.d.ts CHANGED
@@ -3693,8 +3693,6 @@ export declare class GameProviderWrapper extends OrigamiElement {
3693
3693
  private _historyController;
3694
3694
  private _hapticController;
3695
3695
  private _resizeObserver;
3696
- private _lastInnerHeight;
3697
- private _lastInnerWidth;
3698
3696
  protected _gameProvider: ContextProvider<typeof gameContext>;
3699
3697
  connectedCallback(): void;
3700
3698
  firstUpdated(_changed: PropertyValues): Promise<void>;
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ var Et=Object.create;var{getPrototypeOf:Mt,defineProperty:Zn,getOwnPropertyNames
10
10
  \f\r](?:([^\\s"'>=/]+)([
11
11
  \f\r]*=[
12
12
  \f\r]*(?:[^
13
- \f\r"'\`<>=]|("|')|))|$)`,"g"),Qn=/'/g,Pn=/"/g,Gn=/^(?:script|style|textarea|title)$/i,Ee=(a)=>(i,...e)=>({_$litType$:a,strings:i,values:e}),T=Ee(1),ra=Ee(2),Ml=Ee(3),ja=Symbol.for("lit-noChange"),D=Symbol.for("lit-nothing"),_n=new WeakMap,Ii=qi.createTreeWalker(qi,129);function Nn(a,i){if(!Oe(a)||!a.hasOwnProperty("raw"))throw Error("invalid template strings array");return Cn!==void 0?Cn.createHTML(i):i}var On=(a,i)=>{let e=a.length-1,o=[],n,r=i===2?"<svg>":i===3?"<math>":"",t=Pi;for(let s=0;s<e;s++){let l=a[s],u,m,S=-1,p=0;for(;p<l.length&&(t.lastIndex=p,m=t.exec(l),m!==null);)p=t.lastIndex,t===Pi?m[1]==="!--"?t=Yn:m[1]!==void 0?t=Dn:m[2]!==void 0?(Gn.test(m[2])&&(n=RegExp("</"+m[2],"g")),t=ji):m[3]!==void 0&&(t=ji):t===ji?m[0]===">"?(t=n??Pi,S=-1):m[1]===void 0?S=-2:(S=t.lastIndex-m[2].length,u=m[1],t=m[3]===void 0?ji:m[3]==='"'?Pn:Qn):t===Pn||t===Qn?t=ji:t===Yn||t===Dn?t=Pi:(t=ji,n=void 0);let x=t===ji&&a[s+1].startsWith("/>")?" ":"";r+=t===Pi?l+hs:S>=0?(o.push(u),l.slice(0,S)+"$lit$"+l.slice(S)+di+x):l+di+(S===-2?s:x)}return[Nn(a,r+(a[e]||"<?>")+(i===2?"</svg>":i===3?"</math>":"")),o]};class Gi{constructor({strings:a,_$litType$:i},e){let o;this.parts=[];let n=0,r=0,t=a.length-1,s=this.parts,[l,u]=On(a,i);if(this.el=Gi.createElement(l,e),Ii.currentNode=this.el.content,i===2||i===3){let m=this.el.content.firstChild;m.replaceWith(...m.childNodes)}for(;(o=Ii.nextNode())!==null&&s.length<t;){if(o.nodeType===1){if(o.hasAttributes())for(let m of o.getAttributeNames())if(m.endsWith("$lit$")){let S=u[r++],p=o.getAttribute(m).split(di),x=/([.?@])?(.*)/.exec(S);s.push({type:1,index:n,name:x[2],strings:p,ctor:x[1]==="."?ao:x[1]==="?"?io:x[1]==="@"?eo:Ti}),o.removeAttribute(m)}else m.startsWith(di)&&(s.push({type:6,index:n}),o.removeAttribute(m));if(Gn.test(o.tagName)){let m=o.textContent.split(di),S=m.length-1;if(S>0){o.textContent=ke?ke.emptyScript:"";for(let p=0;p<S;p++)o.append(m[p],_i()),Ii.nextNode(),s.push({type:2,index:++n});o.append(m[S],_i())}}}else if(o.nodeType===8)if(o.data===Ne)s.push({type:2,index:n});else{let m=-1;for(;(m=o.data.indexOf(di,m+1))!==-1;)s.push({type:7,index:n}),m+=di.length-1}n++}}static createElement(a,i){let e=qi.createElement("template");return e.innerHTML=a,e}}function Hi(a,i,e=a,o){if(i===ja)return i;let n=o!==void 0?e._$Co?.[o]:e._$Cl,r=Xi(i)?void 0:i._$litDirective$;return n?.constructor!==r&&(n?._$AO?.(!1),r===void 0?n=void 0:(n=new r(a),n._$AT(a,e,o)),o!==void 0?(e._$Co??=[])[o]=n:e._$Cl=n),n!==void 0&&(i=Hi(a,n._$AS(a,i.values),n,o)),i}class Me{constructor(a,i){this._$AV=[],this._$AN=void 0,this._$AD=a,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(a){let{el:{content:i},parts:e}=this._$AD,o=(a?.creationScope??qi).importNode(i,!0);Ii.currentNode=o;let n=Ii.nextNode(),r=0,t=0,s=e[0];for(;s!==void 0;){if(r===s.index){let l;s.type===2?l=new Bi(n,n.nextSibling,this,a):s.type===1?l=new s.ctor(n,s.name,s.strings,this,a):s.type===6&&(l=new oo(n,this,a)),this._$AV.push(l),s=e[++t]}r!==s?.index&&(n=Ii.nextNode(),r++)}return Ii.currentNode=qi,o}p(a){let i=0;for(let e of this._$AV)e!==void 0&&(e.strings!==void 0?(e._$AI(a,e,i),i+=e.strings.length-2):e._$AI(a[i])),i++}}class Bi{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(a,i,e,o){this.type=2,this._$AH=D,this._$AN=void 0,this._$AA=a,this._$AB=i,this._$AM=e,this.options=o,this._$Cv=o?.isConnected??!0}get parentNode(){let a=this._$AA.parentNode,i=this._$AM;return i!==void 0&&a?.nodeType===11&&(a=i.parentNode),a}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(a,i=this){a=Hi(this,a,i),Xi(a)?a===D||a==null||a===""?(this._$AH!==D&&this._$AR(),this._$AH=D):a!==this._$AH&&a!==ja&&this._(a):a._$litType$!==void 0?this.$(a):a.nodeType!==void 0?this.T(a):Xn(a)?this.k(a):this._(a)}O(a){return this._$AA.parentNode.insertBefore(a,this._$AB)}T(a){this._$AH!==a&&(this._$AR(),this._$AH=this.O(a))}_(a){this._$AH!==D&&Xi(this._$AH)?this._$AA.nextSibling.data=a:this.T(qi.createTextNode(a)),this._$AH=a}$(a){let{values:i,_$litType$:e}=a,o=typeof e=="number"?this._$AC(a):(e.el===void 0&&(e.el=Gi.createElement(Nn(e.h,e.h[0]),this.options)),e);if(this._$AH?._$AD===o)this._$AH.p(i);else{let n=new Me(o,this),r=n.u(this.options);n.p(i),this.T(r),this._$AH=n}}_$AC(a){let i=_n.get(a.strings);return i===void 0&&_n.set(a.strings,i=new Gi(a)),i}k(a){Oe(this._$AH)||(this._$AH=[],this._$AR());let i=this._$AH,e,o=0;for(let n of a)o===i.length?i.push(e=new Bi(this.O(_i()),this.O(_i()),this,this.options)):e=i[o],e._$AI(n),o++;o<i.length&&(this._$AR(e&&e._$AB.nextSibling,o),i.length=o)}_$AR(a=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);a&&a!==this._$AB;){let e=a.nextSibling;a.remove(),a=e}}setConnected(a){this._$AM===void 0&&(this._$Cv=a,this._$AP?.(a))}}class Ti{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(a,i,e,o,n){this.type=1,this._$AH=D,this._$AN=void 0,this.element=a,this.name=i,this._$AM=o,this.options=n,e.length>2||e[0]!==""||e[1]!==""?(this._$AH=Array(e.length-1).fill(new String),this.strings=e):this._$AH=D}_$AI(a,i=this,e,o){let n=this.strings,r=!1;if(n===void 0)a=Hi(this,a,i,0),r=!Xi(a)||a!==this._$AH&&a!==ja,r&&(this._$AH=a);else{let t=a,s,l;for(a=n[0],s=0;s<n.length-1;s++)l=Hi(this,t[e+s],i,s),l===ja&&(l=this._$AH[s]),r||=!Xi(l)||l!==this._$AH[s],l===D?a=D:a!==D&&(a+=(l??"")+n[s+1]),this._$AH[s]=l}r&&!o&&this.j(a)}j(a){a===D?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,a??"")}}class ao extends Ti{constructor(){super(...arguments),this.type=3}j(a){this.element[this.name]=a===D?void 0:a}}class io extends Ti{constructor(){super(...arguments),this.type=4}j(a){this.element.toggleAttribute(this.name,!!a&&a!==D)}}class eo extends Ti{constructor(a,i,e,o,n){super(a,i,e,o,n),this.type=5}_$AI(a,i=this){if((a=Hi(this,a,i,0)??D)===ja)return;let e=this._$AH,o=a===D&&e!==D||a.capture!==e.capture||a.once!==e.once||a.passive!==e.passive,n=a!==D&&(e===D||o);o&&this.element.removeEventListener(this.name,this,e),n&&this.element.addEventListener(this.name,this,a),this._$AH=a}handleEvent(a){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,a):this._$AH.handleEvent(a)}}class oo{constructor(a,i,e){this.element=a,this.type=6,this._$AN=void 0,this._$AM=i,this.options=e}get _$AU(){return this._$AM._$AU}_$AI(a){Hi(this,a)}}var En={M:"$lit$",P:di,A:Ne,C:1,L:On,R:Me,D:Xn,V:Hi,I:Bi,H:Ti,N:io,U:eo,B:ao,F:oo},ps=Ge.litHtmlPolyfillSupport;ps?.(Gi,Bi),(Ge.litHtmlVersions??=[]).push("3.3.0");var Mn=(a,i,e)=>{let o=e?.renderBefore??i,n=o._$litPart$;if(n===void 0){let r=e?.renderBefore??null;o._$litPart$=n=new Bi(i.insertBefore(_i(),r),r,void 0,e??{})}return n._$AI(a),n};var no=globalThis;class wa extends bi{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let a=super.createRenderRoot();return this.renderOptions.renderBefore??=a.firstChild,a}update(a){let i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(a),this._$Do=Mn(i,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return ja}}wa._$litElement$=!0,wa.finalized=!0,no.litElementHydrateSupport?.({LitElement:wa});var ms=no.litElementPolyfillSupport;ms?.({LitElement:wa});(no.litElementVersions??=[]).push("4.2.0");var Q=(a)=>(i,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(a,i)}):customElements.define(a,i)};var gs={attribute:!0,type:String,converter:Qi,reflect:!1,hasChanged:be},bs=(a=gs,i,e)=>{let{kind:o,metadata:n}=e,r=globalThis.litPropertyMetadata.get(n);if(r===void 0&&globalThis.litPropertyMetadata.set(n,r=new Map),o==="setter"&&((a=Object.create(a)).wrapped=!0),r.set(e.name,a),o==="accessor"){let{name:t}=e;return{set(s){let l=i.get.call(this);i.set.call(this,s),this.requestUpdate(t,l,a)},init(s){return s!==void 0&&this.C(t,void 0,a,s),s}}}if(o==="setter"){let{name:t}=e;return function(s){let l=this[t];i.call(this,s),this.requestUpdate(t,l,a)}}throw Error("Unsupported decorator location: "+o)};function F(a){return(i,e)=>typeof e=="object"?bs(a,i,e):((o,n,r)=>{let t=n.hasOwnProperty(r);return n.constructor.createProperty(r,o),t?Object.getOwnPropertyDescriptor(n,r):void 0})(a,i,e)}function Y(a){return F({...a,state:!0,attribute:!1})}var Vi=(a,i,e)=>(e.configurable=!0,e.enumerable=!0,Reflect.decorate&&typeof i!="object"&&Object.defineProperty(a,i,e),e);function ca(a,i){return(e,o,n)=>{let r=(t)=>t.renderRoot?.querySelector(a)??null;if(i){let{get:t,set:s}=typeof o=="object"?e:n??(()=>{let l=Symbol();return{get(){return this[l]},set(u){this[l]=u}}})();return Vi(e,o,{get(){let l=t.call(this);return l===void 0&&(l=r(this),(l!==null||this.hasUpdated)&&s.call(this,l)),l}})}return Vi(e,o,{get(){return r(this)}})}}class ro{canVibrate;constructor(a){a.addController(this),this.canVibrate="vibrate"in navigator}trigger(a=10){if(!this.canVibrate)return;try{navigator.vibrate(a)}catch{}}click(){this.trigger(50)}lightClick(){this.trigger(35)}}function ar(a){let i=a.replace(/-/g,"").substring(0,12),e=parseInt(i,16);return new Date(e)}function ir(a){return a.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})}class to extends EventTarget{host;_historyData=[];_hasData=null;_isInitialized=!1;_hasNextPage=!1;_initialLoadSize=20;_hasLoadedMore=!1;_clientSeed=null;_hasLoadedClientSeed=!1;constructor(a){super();this.host=a,a.addController(this),setTimeout(()=>{this.preloadHistory(),this.loadClientSeed()},100)}get historyData(){return this._historyData}get hasData(){return this._hasData}get isInitialized(){return this._isInitialized}get hasNextPage(){return this._hasNextPage}get clientSeed(){return this._clientSeed}get hasLoadedClientSeed(){return this._hasLoadedClientSeed}notifyDataChanged(){this.dispatchEvent(new CustomEvent("history-data-changed",{detail:{historyData:this._historyData,hasNextPage:this._hasNextPage,hasData:this._hasData}}))}notifyClientSeedChanged(){this.dispatchEvent(new CustomEvent("client-seed-changed",{detail:{clientSeed:this._clientSeed}}))}async preloadHistory(){if(!this.host.gameData?.baseUrl||!this.host.gameData?.authToken)return;try{let{historyData:a,hasNextPage:i}=await this.fetchHistory(void 0,this._initialLoadSize);this._historyData=a,this._hasData=a.length>0,this._hasNextPage=i,this._isInitialized=!0,this._hasLoadedMore=!1,this.notifyDataChanged()}catch(a){console.error("Failed to preload history:",a),this._isInitialized=!0,this._hasData=null}}async fetchHistory(a,i=5){if(!this.host.gameData?.baseUrl||!this.host.gameData?.authToken)return{historyData:[],hasNextPage:!1};let e=new URL(`${this.host.gameData.baseUrl}/bet/my-bets`);if(e.searchParams.append("limit",i.toString()),a)e.searchParams.append("beforeId",a);let o=await fetch(e.toString(),{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.host.gameData.authToken}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let n=await o.json();return{historyData:n.results.map((t)=>({id:`${t.id.slice(0,3)}...${t.id.slice(-3)}`,fullId:t.id,timestamp:ir(ar(t.id)),currency:t.currency,bet:Number(t.amount),win:Number(t.payout)})),hasNextPage:!!n.nextCursor}}async refreshHistory(a=!1){try{let i=a&&this._hasLoadedMore?this._historyData.length:this._initialLoadSize,{historyData:e,hasNextPage:o}=await this.fetchHistory(void 0,i);if(this._historyData=e,this._hasData=e.length>0,this._hasNextPage=o,!a)this._hasLoadedMore=!1;this.notifyDataChanged()}catch(i){console.error("Failed to refresh history:",i)}}async loadMore(){if(!this._hasNextPage||this._historyData.length===0)return{historyData:[],hasNextPage:!1};let a=this._historyData[this._historyData.length-1],{historyData:i,hasNextPage:e}=await this.fetchHistory(a.fullId,this._initialLoadSize);return this._historyData=[...this._historyData,...i],this._hasNextPage=e,this._hasLoadedMore=!0,this.notifyDataChanged(),this.dispatchEvent(new CustomEvent("history-loaded-more")),{historyData:i,hasNextPage:e}}addNewBet(a){if(this._historyData.some((e)=>e.fullId===a.id))return;let i={id:`${a.id.slice(0,3)}...${a.id.slice(-3)}`,fullId:a.id,timestamp:ir(ar(a.id)),currency:a.currency,bet:Number(a.amount),win:Number(a.payout)};if(!this._hasLoadedMore&&this._historyData.length>=this._initialLoadSize)this._historyData=[i,...this._historyData.slice(0,this._initialLoadSize-1)],this._hasNextPage=!0;else this._historyData=[i,...this._historyData];this._hasData=!0,this.notifyDataChanged()}async loadClientSeed(){if(!this.host.gameData?.baseUrl||!this.host.gameData?.authToken||this._hasLoadedClientSeed)return;try{let a=await fetch(`${this.host.gameData.baseUrl}/provably-fair/my-info`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.host.gameData.authToken}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);let i=await a.json();this._clientSeed=i.clientSeed,this._hasLoadedClientSeed=!0,this.notifyClientSeedChanged()}catch(a){console.error("Failed to load client seed:",a)}}updateClientSeed(a){this._clientSeed=a,this.notifyClientSeedChanged()}}class so{host;muted=!1;audioCtx;buffer;spriteMap=null;constructor(a){this.host=a,a.addController(this);let i=window.AudioContext||window.webkitAudioContext;this.audioCtx=new i,fetch("https://assets.betorigami.com/sounds/sounds.mp3").then((e)=>{return e.arrayBuffer().then((o)=>{this.audioCtx.decodeAudioData(o,(n)=>{this.buffer=n})}).catch((o)=>{})}).catch(),fetch("https://assets.betorigami.com/sounds/sounds.json").then((e)=>e.json()).catch().then((e)=>{this.spriteMap=e.spritemap}).catch(),window.onclick=()=>{this.play("bet",!0),window.onclick=null}}preload(a){}async play(a,i,e=1,o,n=()=>{}){if(!this.buffer||!this.spriteMap)return;let r=this.audioCtx.createBufferSource();r.buffer=this.buffer;let t=this.spriteMap[a];try{if(this.audioCtx&&r){let s=this.audioCtx.createGain(),l=o??(this.host.gameData?.volume??100)/100,u=i??this.muted;return s.gain.value=u?0:Math.min(l,1),s.connect(this.audioCtx.destination),r.connect(s),r.playbackRate.value=e,r.start(0,t.start),setTimeout(()=>{r?.stop(),n()},1000*(t.end-t.start)),r}}catch(s){}}}var Ni=100;class X extends wa{static componentStyles=[];emit(a,i){let e=new CustomEvent(a,{bubbles:!0,cancelable:!1,composed:!0,detail:{},...i});return this.dispatchEvent(e),e}}var N=si(Symbol("game"));class ve extends X{constructor(){super(...arguments);this.currency="USD";this.showCurrencyAsText=!1;this.balance=0;this.currencyDecimals=2;this.baseUrl="https://betorigami.com";this.authToken="";this.origamiGame="DICE";this.lobbyUrl="https://betorigami.com";this.depositUrl=void 0;this.maxPayout=200;this.minBet=0.01;this.maxBet=20;this.footerPosition="BELOW";this.logoUrl=null;this.betAmount="0.00";this.autobetNumberOfBets=0;this.hotkeysOpenEnabled=!1;this.showMaxBetButton=!1;this.volume=100;this.instantBetEnabled=!1;this.mainWidth=0;this.publicKey="";this.scale=1;this.language="en"}_soundController=new so(this);_historyController=new to(this);_hapticController=new ro(this);_resizeObserver=null;_lastInnerHeight=0;_lastInnerWidth=0;_gameProvider=new Si(this,{context:N,initialValue:{amount:this.betAmount,updateBetAmount:this.updateBetAmount.bind(this),updateBalance:this.updateBalance.bind(this),currency:this.currency,showCurrencyAsText:this.showCurrencyAsText,currencyDecimals:this.currencyDecimals,lobbyUrl:this.lobbyUrl,depositUrl:this.depositUrl,maxPayout:this.maxPayout,minBet:this.minBet,maxBet:this.maxBet,balance:this.balance,baseUrl:this.baseUrl,authToken:this.authToken,publicKey:this.publicKey,autobetNumberOfBets:this.autobetNumberOfBets,hotkeysOpenEnabled:this.hotkeysOpenEnabled,showMaxBetButton:this.showMaxBetButton,volume:this.volume,instantBetEnabled:this.instantBetEnabled,soundController:this._soundController,historyController:this._historyController,hapticController:this._hapticController,updateHotkeysOpenEnabled:this.updateHotkeysOpenEnabled.bind(this),updateShowMaxBetButton:this.updateShowMaxBetButton.bind(this),updateVolume:this.updateVolume.bind(this),updateInstantBetEnabled:this.updateInstantBetEnabled.bind(this),updateAutobetNumberOfBets:this.updateAutobetNumberOfBets.bind(this),mainWidth:this.mainWidth,updateMainWidth:this.updateMainWidth.bind(this),language:this.language,footerPosition:this.footerPosition,logoUrl:this.logoUrl}});connectedCallback(){super.connectedCallback(),this.updateProviderValue(),this.fetchBalance(),this.fetchPublicKey(),this.setupResizeObserver(),this.calculateScale()}async firstUpdated(a){super.firstUpdated(a),await this.updateComplete}disconnectedCallback(){super.disconnectedCallback(),this.cleanupResizeObserver()}updated(a){if(super.updated(a),a.has("currency")||a.has("balance")||a.has("baseUrl")||a.has("showCurrencyAsText")||a.has("authToken")||a.has("hotkeysOpenEnabled")||a.has("volume")||a.has("instantBetEnabled")||a.has("showMaxBetButton")||a.has("mainWidth"))this.updateProviderValue()}get gameData(){return this._gameProvider.value}updateProviderValue(){this._gameProvider.setValue({amount:this.betAmount,currency:this.currency,updateBetAmount:this.updateBetAmount.bind(this),updateBalance:this.updateBalance.bind(this),showCurrencyAsText:this.showCurrencyAsText,currencyDecimals:this.currencyDecimals,lobbyUrl:this.lobbyUrl,depositUrl:this.depositUrl,maxPayout:this.maxPayout,minBet:this.minBet,maxBet:this.maxBet,balance:this.balance,baseUrl:this.baseUrl,publicKey:this.publicKey,authToken:this.authToken,autobetNumberOfBets:this.autobetNumberOfBets,updateAutobetNumberOfBets:this.updateAutobetNumberOfBets.bind(this),hotkeysOpenEnabled:this.hotkeysOpenEnabled,showMaxBetButton:this.showMaxBetButton,volume:this.volume,instantBetEnabled:this.instantBetEnabled,soundController:this._soundController,historyController:this._historyController,hapticController:this._hapticController,updateHotkeysOpenEnabled:this.updateHotkeysOpenEnabled.bind(this),updateShowMaxBetButton:this.updateShowMaxBetButton.bind(this),updateVolume:this.updateVolume.bind(this),updateInstantBetEnabled:this.updateInstantBetEnabled.bind(this),mainWidth:this.mainWidth,updateMainWidth:this.updateMainWidth.bind(this),language:this.language,footerPosition:this.footerPosition,logoUrl:this.logoUrl})}fetchBalance=async()=>{if(!this.authToken||!this.baseUrl){this.balance=1000;return}try{let a=await fetch(`${this.baseUrl}/users/balance?currency=${this.currency}&origamiGame=${this.origamiGame}`,{headers:{Authorization:`Bearer ${this.authToken}`,"Content-Type":"application/json"}});if(!a.ok){console.error("Failed to fetch balance:",a.statusText);return}let i=await a.json();this.balance=new C(i.balance).toNumber()}catch(a){console.error("Error fetching balance:",a)}};fetchPublicKey=async()=>{if(!this.authToken||!this.baseUrl)return;let a=await fetch(`${this.baseUrl}/provably-fair/public-key`);if(!a.ok){console.error("Failed to fetch public key:",a.statusText);return}let i=await a.json();this.publicKey=i.publicKey};updateHotkeysOpenEnabled(a){this.hotkeysOpenEnabled=a,this.updateProviderValue()}updateShowMaxBetButton(a){this.showMaxBetButton=a,this.updateProviderValue()}updateVolume(a){this.volume=a,this.updateProviderValue()}updateInstantBetEnabled(a){this.instantBetEnabled=a,this.updateProviderValue()}updateAutobetNumberOfBets(a){this.autobetNumberOfBets=a,this.updateProviderValue()}updateMainWidth(a){this.mainWidth=a,this.updateProviderValue()}updateBetAmount(a){if(a.isNaN())return;if(a.isLessThan(0)){this.betAmount="0";return}let i=a.toFixed(this.currencyDecimals);this.betAmount=i,this.updateProviderValue()}updateBalance(a){if(a.isNaN())return;if(a.isLessThan(0)){this.balance=0;return}this.balance=a.toNumber(),this.updateProviderValue()}_boundCalculateScale=this.calculateScale.bind(this);setupResizeObserver(){if(typeof ResizeObserver!=="undefined")this._resizeObserver=new ResizeObserver(()=>{this.calculateScale(),this.gameData.updateMainWidth(document.documentElement.clientWidth)}),this._resizeObserver.observe(document.body);else window.addEventListener("resize",this._boundCalculateScale)}cleanupResizeObserver(){if(this._resizeObserver)this._resizeObserver.disconnect(),this._resizeObserver=null;else window.removeEventListener("resize",this._boundCalculateScale)}calculateScale(){let a=window.innerWidth,i=document.documentElement.clientWidth,e=window.innerHeight;if(a===this._lastInnerWidth&&e===this._lastInnerHeight)return;this._lastInnerWidth=a,this._lastInnerHeight=e;let n=i/1200;this.scale=n,this.requestUpdate()}render(){let a=(()=>{switch(this.origamiGame){case"DICE":return T`<origami-dice-game></origami-dice-game>`;case"KENO":return T`<origami-keno-game></origami-keno-game>`;case"MINES":return T`<origami-mines-game></origami-mines-game>`;case"LIMBO":return T`<origami-limbo-game></origami-limbo-game>`;default:this.origamiGame}})(),i=`
13
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),Qn=/'/g,Pn=/"/g,Gn=/^(?:script|style|textarea|title)$/i,Ee=(a)=>(i,...e)=>({_$litType$:a,strings:i,values:e}),T=Ee(1),ra=Ee(2),Ml=Ee(3),ja=Symbol.for("lit-noChange"),D=Symbol.for("lit-nothing"),_n=new WeakMap,Ii=qi.createTreeWalker(qi,129);function Nn(a,i){if(!Oe(a)||!a.hasOwnProperty("raw"))throw Error("invalid template strings array");return Cn!==void 0?Cn.createHTML(i):i}var On=(a,i)=>{let e=a.length-1,o=[],n,r=i===2?"<svg>":i===3?"<math>":"",t=Pi;for(let s=0;s<e;s++){let l=a[s],u,m,S=-1,p=0;for(;p<l.length&&(t.lastIndex=p,m=t.exec(l),m!==null);)p=t.lastIndex,t===Pi?m[1]==="!--"?t=Yn:m[1]!==void 0?t=Dn:m[2]!==void 0?(Gn.test(m[2])&&(n=RegExp("</"+m[2],"g")),t=ji):m[3]!==void 0&&(t=ji):t===ji?m[0]===">"?(t=n??Pi,S=-1):m[1]===void 0?S=-2:(S=t.lastIndex-m[2].length,u=m[1],t=m[3]===void 0?ji:m[3]==='"'?Pn:Qn):t===Pn||t===Qn?t=ji:t===Yn||t===Dn?t=Pi:(t=ji,n=void 0);let x=t===ji&&a[s+1].startsWith("/>")?" ":"";r+=t===Pi?l+hs:S>=0?(o.push(u),l.slice(0,S)+"$lit$"+l.slice(S)+di+x):l+di+(S===-2?s:x)}return[Nn(a,r+(a[e]||"<?>")+(i===2?"</svg>":i===3?"</math>":"")),o]};class Gi{constructor({strings:a,_$litType$:i},e){let o;this.parts=[];let n=0,r=0,t=a.length-1,s=this.parts,[l,u]=On(a,i);if(this.el=Gi.createElement(l,e),Ii.currentNode=this.el.content,i===2||i===3){let m=this.el.content.firstChild;m.replaceWith(...m.childNodes)}for(;(o=Ii.nextNode())!==null&&s.length<t;){if(o.nodeType===1){if(o.hasAttributes())for(let m of o.getAttributeNames())if(m.endsWith("$lit$")){let S=u[r++],p=o.getAttribute(m).split(di),x=/([.?@])?(.*)/.exec(S);s.push({type:1,index:n,name:x[2],strings:p,ctor:x[1]==="."?ao:x[1]==="?"?io:x[1]==="@"?eo:Ti}),o.removeAttribute(m)}else m.startsWith(di)&&(s.push({type:6,index:n}),o.removeAttribute(m));if(Gn.test(o.tagName)){let m=o.textContent.split(di),S=m.length-1;if(S>0){o.textContent=ke?ke.emptyScript:"";for(let p=0;p<S;p++)o.append(m[p],_i()),Ii.nextNode(),s.push({type:2,index:++n});o.append(m[S],_i())}}}else if(o.nodeType===8)if(o.data===Ne)s.push({type:2,index:n});else{let m=-1;for(;(m=o.data.indexOf(di,m+1))!==-1;)s.push({type:7,index:n}),m+=di.length-1}n++}}static createElement(a,i){let e=qi.createElement("template");return e.innerHTML=a,e}}function Hi(a,i,e=a,o){if(i===ja)return i;let n=o!==void 0?e._$Co?.[o]:e._$Cl,r=Xi(i)?void 0:i._$litDirective$;return n?.constructor!==r&&(n?._$AO?.(!1),r===void 0?n=void 0:(n=new r(a),n._$AT(a,e,o)),o!==void 0?(e._$Co??=[])[o]=n:e._$Cl=n),n!==void 0&&(i=Hi(a,n._$AS(a,i.values),n,o)),i}class Me{constructor(a,i){this._$AV=[],this._$AN=void 0,this._$AD=a,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(a){let{el:{content:i},parts:e}=this._$AD,o=(a?.creationScope??qi).importNode(i,!0);Ii.currentNode=o;let n=Ii.nextNode(),r=0,t=0,s=e[0];for(;s!==void 0;){if(r===s.index){let l;s.type===2?l=new Bi(n,n.nextSibling,this,a):s.type===1?l=new s.ctor(n,s.name,s.strings,this,a):s.type===6&&(l=new oo(n,this,a)),this._$AV.push(l),s=e[++t]}r!==s?.index&&(n=Ii.nextNode(),r++)}return Ii.currentNode=qi,o}p(a){let i=0;for(let e of this._$AV)e!==void 0&&(e.strings!==void 0?(e._$AI(a,e,i),i+=e.strings.length-2):e._$AI(a[i])),i++}}class Bi{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(a,i,e,o){this.type=2,this._$AH=D,this._$AN=void 0,this._$AA=a,this._$AB=i,this._$AM=e,this.options=o,this._$Cv=o?.isConnected??!0}get parentNode(){let a=this._$AA.parentNode,i=this._$AM;return i!==void 0&&a?.nodeType===11&&(a=i.parentNode),a}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(a,i=this){a=Hi(this,a,i),Xi(a)?a===D||a==null||a===""?(this._$AH!==D&&this._$AR(),this._$AH=D):a!==this._$AH&&a!==ja&&this._(a):a._$litType$!==void 0?this.$(a):a.nodeType!==void 0?this.T(a):Xn(a)?this.k(a):this._(a)}O(a){return this._$AA.parentNode.insertBefore(a,this._$AB)}T(a){this._$AH!==a&&(this._$AR(),this._$AH=this.O(a))}_(a){this._$AH!==D&&Xi(this._$AH)?this._$AA.nextSibling.data=a:this.T(qi.createTextNode(a)),this._$AH=a}$(a){let{values:i,_$litType$:e}=a,o=typeof e=="number"?this._$AC(a):(e.el===void 0&&(e.el=Gi.createElement(Nn(e.h,e.h[0]),this.options)),e);if(this._$AH?._$AD===o)this._$AH.p(i);else{let n=new Me(o,this),r=n.u(this.options);n.p(i),this.T(r),this._$AH=n}}_$AC(a){let i=_n.get(a.strings);return i===void 0&&_n.set(a.strings,i=new Gi(a)),i}k(a){Oe(this._$AH)||(this._$AH=[],this._$AR());let i=this._$AH,e,o=0;for(let n of a)o===i.length?i.push(e=new Bi(this.O(_i()),this.O(_i()),this,this.options)):e=i[o],e._$AI(n),o++;o<i.length&&(this._$AR(e&&e._$AB.nextSibling,o),i.length=o)}_$AR(a=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);a&&a!==this._$AB;){let e=a.nextSibling;a.remove(),a=e}}setConnected(a){this._$AM===void 0&&(this._$Cv=a,this._$AP?.(a))}}class Ti{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(a,i,e,o,n){this.type=1,this._$AH=D,this._$AN=void 0,this.element=a,this.name=i,this._$AM=o,this.options=n,e.length>2||e[0]!==""||e[1]!==""?(this._$AH=Array(e.length-1).fill(new String),this.strings=e):this._$AH=D}_$AI(a,i=this,e,o){let n=this.strings,r=!1;if(n===void 0)a=Hi(this,a,i,0),r=!Xi(a)||a!==this._$AH&&a!==ja,r&&(this._$AH=a);else{let t=a,s,l;for(a=n[0],s=0;s<n.length-1;s++)l=Hi(this,t[e+s],i,s),l===ja&&(l=this._$AH[s]),r||=!Xi(l)||l!==this._$AH[s],l===D?a=D:a!==D&&(a+=(l??"")+n[s+1]),this._$AH[s]=l}r&&!o&&this.j(a)}j(a){a===D?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,a??"")}}class ao extends Ti{constructor(){super(...arguments),this.type=3}j(a){this.element[this.name]=a===D?void 0:a}}class io extends Ti{constructor(){super(...arguments),this.type=4}j(a){this.element.toggleAttribute(this.name,!!a&&a!==D)}}class eo extends Ti{constructor(a,i,e,o,n){super(a,i,e,o,n),this.type=5}_$AI(a,i=this){if((a=Hi(this,a,i,0)??D)===ja)return;let e=this._$AH,o=a===D&&e!==D||a.capture!==e.capture||a.once!==e.once||a.passive!==e.passive,n=a!==D&&(e===D||o);o&&this.element.removeEventListener(this.name,this,e),n&&this.element.addEventListener(this.name,this,a),this._$AH=a}handleEvent(a){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,a):this._$AH.handleEvent(a)}}class oo{constructor(a,i,e){this.element=a,this.type=6,this._$AN=void 0,this._$AM=i,this.options=e}get _$AU(){return this._$AM._$AU}_$AI(a){Hi(this,a)}}var En={M:"$lit$",P:di,A:Ne,C:1,L:On,R:Me,D:Xn,V:Hi,I:Bi,H:Ti,N:io,U:eo,B:ao,F:oo},ps=Ge.litHtmlPolyfillSupport;ps?.(Gi,Bi),(Ge.litHtmlVersions??=[]).push("3.3.0");var Mn=(a,i,e)=>{let o=e?.renderBefore??i,n=o._$litPart$;if(n===void 0){let r=e?.renderBefore??null;o._$litPart$=n=new Bi(i.insertBefore(_i(),r),r,void 0,e??{})}return n._$AI(a),n};var no=globalThis;class wa extends bi{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let a=super.createRenderRoot();return this.renderOptions.renderBefore??=a.firstChild,a}update(a){let i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(a),this._$Do=Mn(i,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return ja}}wa._$litElement$=!0,wa.finalized=!0,no.litElementHydrateSupport?.({LitElement:wa});var ms=no.litElementPolyfillSupport;ms?.({LitElement:wa});(no.litElementVersions??=[]).push("4.2.0");var Q=(a)=>(i,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(a,i)}):customElements.define(a,i)};var gs={attribute:!0,type:String,converter:Qi,reflect:!1,hasChanged:be},bs=(a=gs,i,e)=>{let{kind:o,metadata:n}=e,r=globalThis.litPropertyMetadata.get(n);if(r===void 0&&globalThis.litPropertyMetadata.set(n,r=new Map),o==="setter"&&((a=Object.create(a)).wrapped=!0),r.set(e.name,a),o==="accessor"){let{name:t}=e;return{set(s){let l=i.get.call(this);i.set.call(this,s),this.requestUpdate(t,l,a)},init(s){return s!==void 0&&this.C(t,void 0,a,s),s}}}if(o==="setter"){let{name:t}=e;return function(s){let l=this[t];i.call(this,s),this.requestUpdate(t,l,a)}}throw Error("Unsupported decorator location: "+o)};function F(a){return(i,e)=>typeof e=="object"?bs(a,i,e):((o,n,r)=>{let t=n.hasOwnProperty(r);return n.constructor.createProperty(r,o),t?Object.getOwnPropertyDescriptor(n,r):void 0})(a,i,e)}function Y(a){return F({...a,state:!0,attribute:!1})}var Vi=(a,i,e)=>(e.configurable=!0,e.enumerable=!0,Reflect.decorate&&typeof i!="object"&&Object.defineProperty(a,i,e),e);function ca(a,i){return(e,o,n)=>{let r=(t)=>t.renderRoot?.querySelector(a)??null;if(i){let{get:t,set:s}=typeof o=="object"?e:n??(()=>{let l=Symbol();return{get(){return this[l]},set(u){this[l]=u}}})();return Vi(e,o,{get(){let l=t.call(this);return l===void 0&&(l=r(this),(l!==null||this.hasUpdated)&&s.call(this,l)),l}})}return Vi(e,o,{get(){return r(this)}})}}class ro{canVibrate;constructor(a){a.addController(this),this.canVibrate="vibrate"in navigator}trigger(a=10){if(!this.canVibrate)return;try{navigator.vibrate(a)}catch{}}click(){this.trigger(50)}lightClick(){this.trigger(35)}}function ar(a){let i=a.replace(/-/g,"").substring(0,12),e=parseInt(i,16);return new Date(e)}function ir(a){return a.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:!0})}class to extends EventTarget{host;_historyData=[];_hasData=null;_isInitialized=!1;_hasNextPage=!1;_initialLoadSize=20;_hasLoadedMore=!1;_clientSeed=null;_hasLoadedClientSeed=!1;constructor(a){super();this.host=a,a.addController(this),setTimeout(()=>{this.preloadHistory(),this.loadClientSeed()},100)}get historyData(){return this._historyData}get hasData(){return this._hasData}get isInitialized(){return this._isInitialized}get hasNextPage(){return this._hasNextPage}get clientSeed(){return this._clientSeed}get hasLoadedClientSeed(){return this._hasLoadedClientSeed}notifyDataChanged(){this.dispatchEvent(new CustomEvent("history-data-changed",{detail:{historyData:this._historyData,hasNextPage:this._hasNextPage,hasData:this._hasData}}))}notifyClientSeedChanged(){this.dispatchEvent(new CustomEvent("client-seed-changed",{detail:{clientSeed:this._clientSeed}}))}async preloadHistory(){if(!this.host.gameData?.baseUrl||!this.host.gameData?.authToken)return;try{let{historyData:a,hasNextPage:i}=await this.fetchHistory(void 0,this._initialLoadSize);this._historyData=a,this._hasData=a.length>0,this._hasNextPage=i,this._isInitialized=!0,this._hasLoadedMore=!1,this.notifyDataChanged()}catch(a){console.error("Failed to preload history:",a),this._isInitialized=!0,this._hasData=null}}async fetchHistory(a,i=5){if(!this.host.gameData?.baseUrl||!this.host.gameData?.authToken)return{historyData:[],hasNextPage:!1};let e=new URL(`${this.host.gameData.baseUrl}/bet/my-bets`);if(e.searchParams.append("limit",i.toString()),a)e.searchParams.append("beforeId",a);let o=await fetch(e.toString(),{headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.host.gameData.authToken}`}});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let n=await o.json();return{historyData:n.results.map((t)=>({id:`${t.id.slice(0,3)}...${t.id.slice(-3)}`,fullId:t.id,timestamp:ir(ar(t.id)),currency:t.currency,bet:Number(t.amount),win:Number(t.payout)})),hasNextPage:!!n.nextCursor}}async refreshHistory(a=!1){try{let i=a&&this._hasLoadedMore?this._historyData.length:this._initialLoadSize,{historyData:e,hasNextPage:o}=await this.fetchHistory(void 0,i);if(this._historyData=e,this._hasData=e.length>0,this._hasNextPage=o,!a)this._hasLoadedMore=!1;this.notifyDataChanged()}catch(i){console.error("Failed to refresh history:",i)}}async loadMore(){if(!this._hasNextPage||this._historyData.length===0)return{historyData:[],hasNextPage:!1};let a=this._historyData[this._historyData.length-1],{historyData:i,hasNextPage:e}=await this.fetchHistory(a.fullId,this._initialLoadSize);return this._historyData=[...this._historyData,...i],this._hasNextPage=e,this._hasLoadedMore=!0,this.notifyDataChanged(),this.dispatchEvent(new CustomEvent("history-loaded-more")),{historyData:i,hasNextPage:e}}addNewBet(a){if(this._historyData.some((e)=>e.fullId===a.id))return;let i={id:`${a.id.slice(0,3)}...${a.id.slice(-3)}`,fullId:a.id,timestamp:ir(ar(a.id)),currency:a.currency,bet:Number(a.amount),win:Number(a.payout)};if(!this._hasLoadedMore&&this._historyData.length>=this._initialLoadSize)this._historyData=[i,...this._historyData.slice(0,this._initialLoadSize-1)],this._hasNextPage=!0;else this._historyData=[i,...this._historyData];this._hasData=!0,this.notifyDataChanged()}async loadClientSeed(){if(!this.host.gameData?.baseUrl||!this.host.gameData?.authToken||this._hasLoadedClientSeed)return;try{let a=await fetch(`${this.host.gameData.baseUrl}/provably-fair/my-info`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.host.gameData.authToken}`}});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);let i=await a.json();this._clientSeed=i.clientSeed,this._hasLoadedClientSeed=!0,this.notifyClientSeedChanged()}catch(a){console.error("Failed to load client seed:",a)}}updateClientSeed(a){this._clientSeed=a,this.notifyClientSeedChanged()}}class so{host;muted=!1;audioCtx;buffer;spriteMap=null;constructor(a){this.host=a,a.addController(this);let i=window.AudioContext||window.webkitAudioContext;this.audioCtx=new i,fetch("https://assets.betorigami.com/sounds/sounds.mp3").then((e)=>{return e.arrayBuffer().then((o)=>{this.audioCtx.decodeAudioData(o,(n)=>{this.buffer=n})}).catch((o)=>{})}).catch(),fetch("https://assets.betorigami.com/sounds/sounds.json").then((e)=>e.json()).catch().then((e)=>{this.spriteMap=e.spritemap}).catch(),window.onclick=()=>{this.play("bet",!0),window.onclick=null}}preload(a){}async play(a,i,e=1,o,n=()=>{}){if(!this.buffer||!this.spriteMap)return;let r=this.audioCtx.createBufferSource();r.buffer=this.buffer;let t=this.spriteMap[a];try{if(this.audioCtx&&r){let s=this.audioCtx.createGain(),l=o??(this.host.gameData?.volume??100)/100,u=i??this.muted;return s.gain.value=u?0:Math.min(l,1),s.connect(this.audioCtx.destination),r.connect(s),r.playbackRate.value=e,r.start(0,t.start),setTimeout(()=>{r?.stop(),n()},1000*(t.end-t.start)),r}}catch(s){}}}var Ni=100;class X extends wa{static componentStyles=[];emit(a,i){let e=new CustomEvent(a,{bubbles:!0,cancelable:!1,composed:!0,detail:{},...i});return this.dispatchEvent(e),e}}var N=si(Symbol("game"));class ve extends X{constructor(){super(...arguments);this.currency="USD";this.showCurrencyAsText=!1;this.balance=0;this.currencyDecimals=2;this.baseUrl="https://betorigami.com";this.authToken="";this.origamiGame="DICE";this.lobbyUrl="https://betorigami.com";this.depositUrl=void 0;this.maxPayout=200;this.minBet=0.01;this.maxBet=20;this.footerPosition="BELOW";this.logoUrl=null;this.betAmount="0.00";this.autobetNumberOfBets=0;this.hotkeysOpenEnabled=!1;this.showMaxBetButton=!1;this.volume=100;this.instantBetEnabled=!1;this.mainWidth=0;this.publicKey="";this.scale=1;this.language="en"}_soundController=new so(this);_historyController=new to(this);_hapticController=new ro(this);_resizeObserver=null;_gameProvider=new Si(this,{context:N,initialValue:{amount:this.betAmount,updateBetAmount:this.updateBetAmount.bind(this),updateBalance:this.updateBalance.bind(this),currency:this.currency,showCurrencyAsText:this.showCurrencyAsText,currencyDecimals:this.currencyDecimals,lobbyUrl:this.lobbyUrl,depositUrl:this.depositUrl,maxPayout:this.maxPayout,minBet:this.minBet,maxBet:this.maxBet,balance:this.balance,baseUrl:this.baseUrl,authToken:this.authToken,publicKey:this.publicKey,autobetNumberOfBets:this.autobetNumberOfBets,hotkeysOpenEnabled:this.hotkeysOpenEnabled,showMaxBetButton:this.showMaxBetButton,volume:this.volume,instantBetEnabled:this.instantBetEnabled,soundController:this._soundController,historyController:this._historyController,hapticController:this._hapticController,updateHotkeysOpenEnabled:this.updateHotkeysOpenEnabled.bind(this),updateShowMaxBetButton:this.updateShowMaxBetButton.bind(this),updateVolume:this.updateVolume.bind(this),updateInstantBetEnabled:this.updateInstantBetEnabled.bind(this),updateAutobetNumberOfBets:this.updateAutobetNumberOfBets.bind(this),mainWidth:this.mainWidth,updateMainWidth:this.updateMainWidth.bind(this),language:this.language,footerPosition:this.footerPosition,logoUrl:this.logoUrl}});connectedCallback(){super.connectedCallback(),this.updateProviderValue(),this.fetchBalance(),this.fetchPublicKey(),this.setupResizeObserver(),this.calculateScale()}async firstUpdated(a){super.firstUpdated(a),await this.updateComplete}disconnectedCallback(){super.disconnectedCallback(),this.cleanupResizeObserver()}updated(a){if(super.updated(a),a.has("currency")||a.has("balance")||a.has("baseUrl")||a.has("showCurrencyAsText")||a.has("authToken")||a.has("hotkeysOpenEnabled")||a.has("volume")||a.has("instantBetEnabled")||a.has("showMaxBetButton")||a.has("mainWidth"))this.updateProviderValue()}get gameData(){return this._gameProvider.value}updateProviderValue(){this._gameProvider.setValue({amount:this.betAmount,currency:this.currency,updateBetAmount:this.updateBetAmount.bind(this),updateBalance:this.updateBalance.bind(this),showCurrencyAsText:this.showCurrencyAsText,currencyDecimals:this.currencyDecimals,lobbyUrl:this.lobbyUrl,depositUrl:this.depositUrl,maxPayout:this.maxPayout,minBet:this.minBet,maxBet:this.maxBet,balance:this.balance,baseUrl:this.baseUrl,publicKey:this.publicKey,authToken:this.authToken,autobetNumberOfBets:this.autobetNumberOfBets,updateAutobetNumberOfBets:this.updateAutobetNumberOfBets.bind(this),hotkeysOpenEnabled:this.hotkeysOpenEnabled,showMaxBetButton:this.showMaxBetButton,volume:this.volume,instantBetEnabled:this.instantBetEnabled,soundController:this._soundController,historyController:this._historyController,hapticController:this._hapticController,updateHotkeysOpenEnabled:this.updateHotkeysOpenEnabled.bind(this),updateShowMaxBetButton:this.updateShowMaxBetButton.bind(this),updateVolume:this.updateVolume.bind(this),updateInstantBetEnabled:this.updateInstantBetEnabled.bind(this),mainWidth:this.mainWidth,updateMainWidth:this.updateMainWidth.bind(this),language:this.language,footerPosition:this.footerPosition,logoUrl:this.logoUrl})}fetchBalance=async()=>{if(!this.authToken||!this.baseUrl){this.balance=1000;return}try{let a=await fetch(`${this.baseUrl}/users/balance?currency=${this.currency}&origamiGame=${this.origamiGame}`,{headers:{Authorization:`Bearer ${this.authToken}`,"Content-Type":"application/json"}});if(!a.ok){console.error("Failed to fetch balance:",a.statusText);return}let i=await a.json();this.balance=new C(i.balance).toNumber()}catch(a){console.error("Error fetching balance:",a)}};fetchPublicKey=async()=>{if(!this.authToken||!this.baseUrl)return;let a=await fetch(`${this.baseUrl}/provably-fair/public-key`);if(!a.ok){console.error("Failed to fetch public key:",a.statusText);return}let i=await a.json();this.publicKey=i.publicKey};updateHotkeysOpenEnabled(a){this.hotkeysOpenEnabled=a,this.updateProviderValue()}updateShowMaxBetButton(a){this.showMaxBetButton=a,this.updateProviderValue()}updateVolume(a){this.volume=a,this.updateProviderValue()}updateInstantBetEnabled(a){this.instantBetEnabled=a,this.updateProviderValue()}updateAutobetNumberOfBets(a){this.autobetNumberOfBets=a,this.updateProviderValue()}updateMainWidth(a){this.mainWidth=a,this.updateProviderValue()}updateBetAmount(a){if(a.isNaN())return;if(a.isLessThan(0)){this.betAmount="0";return}let i=a.toFixed(this.currencyDecimals);this.betAmount=i,this.updateProviderValue()}updateBalance(a){if(a.isNaN())return;if(a.isLessThan(0)){this.balance=0;return}this.balance=a.toNumber(),this.updateProviderValue()}_boundCalculateScale=this.calculateScale.bind(this);setupResizeObserver(){if(typeof ResizeObserver!=="undefined")this._resizeObserver=new ResizeObserver(()=>{this.calculateScale(),this.gameData.updateMainWidth(document.documentElement.clientWidth)}),this._resizeObserver.observe(document.body);else window.addEventListener("resize",this._boundCalculateScale)}cleanupResizeObserver(){if(this._resizeObserver)this._resizeObserver.disconnect(),this._resizeObserver=null;else window.removeEventListener("resize",this._boundCalculateScale)}calculateScale(){let a=document.documentElement.clientWidth,i=1200,e=a/1200;this.scale=e,this.requestUpdate()}render(){let a=(()=>{switch(this.origamiGame){case"DICE":return T`<origami-dice-game></origami-dice-game>`;case"KENO":return T`<origami-keno-game></origami-keno-game>`;case"MINES":return T`<origami-mines-game></origami-mines-game>`;case"LIMBO":return T`<origami-limbo-game></origami-limbo-game>`;default:this.origamiGame}})(),i=`
14
14
  position: absolute;
15
15
  top: 0;
16
16
  left: 0;
@@ -1911,7 +1911,7 @@ var Et=Object.create;var{getPrototypeOf:Mt,defineProperty:Zn,getOwnPropertyNames
1911
1911
  `];get gameData(){return this._gameContext.value}_gameContext=new ga(this,{context:N,subscribe:!0,callback:(a)=>{if(!C(a.amount).isEqualTo(this.value)&&!this.isFocused&&this._isInitialized)requestAnimationFrame(()=>{this.value=C(a.amount).toFixed(this.gameData.currencyDecimals)});this.handleValueOrBalanceChange()}});firstUpdated(){requestAnimationFrame(()=>{if(this.gameData?.amount)this.value=C(this.gameData.amount).toFixed(this.gameData.currencyDecimals);this._isInitialized=!0})}watchValue(){this.handleValueOrBalanceChange()}handleValueOrBalanceChange(){if(!this._isInitialized)return;if(!this.gameData)return;let a=this.value===""?"0":this.value,i=C(a),e=C(this.gameData.balance??0),o=this.invalidReason;if(i.isNaN())this.invalidReason="BET_AMOUNT_BELOW_MIN_BET";else if(i.isEqualTo(0))this.invalidReason=null;else if(i.gt(this.gameData.maxBet))this.invalidReason="BET_AMOUNT_ABOVE_MAX_BET";else if(i.lt(this.gameData.minBet))this.invalidReason="BET_AMOUNT_BELOW_MIN_BET";else if(i.gt(e))this.invalidReason="BET_AMOUNT_ABOVE_BALANCE";else if(this.betMaxMultiplier&&i.multipliedBy(this.betMaxMultiplier).gt(this.gameData.maxPayout))this.invalidReason="BET_AMOUNT_ABOVE_MAX_BET";else this.invalidReason=null;if(o!==this.invalidReason)this.emit("bet-amount-validity-change",{detail:{isValid:!this.invalidReason}})}constructor(){super();this.isFocused=!1;this.invalidReason=null;this.betMaxMultiplier=null;this.value="0";this._isInitialized=!1;this.disabled=!1;this.label="";new Ma(this,[{key:"a",callback:this.handleHalfBet.bind(this),options:{disabled:()=>this.disabled||!this.gameData?.hotkeysOpenEnabled,repeat:!0,repeatInterval:200}},{key:"s",callback:this.handleDoubleBet.bind(this),options:{disabled:()=>this.disabled||!this.gameData?.hotkeysOpenEnabled,repeat:!0,repeatInterval:200}},{key:"d",callback:this.handleZeroBet.bind(this),options:{disabled:()=>this.disabled||!this.gameData?.hotkeysOpenEnabled}}])}updateBalanceState(a){if(a.isNaN())return;let i=a.toFixed(this.gameData.currencyDecimals);this.gameData?.updateBetAmount(C(i))}handleCurrencyInputChange(a){let i=a.detail.value;this.value=i,this.updateBalanceState(C(i))}updateAmount(a){if(this.disabled)return;let e=(a.isLessThan(0)?C(0):a).decimalPlaces(this.gameData.currencyDecimals,C.ROUND_DOWN);if(e.toString()!==this.value)this.value=e.toFixed(this.gameData.currencyDecimals),this.updateBalanceState(C(e))}handleHalfBet(){if(this.disabled||C(this.value).isLessThanOrEqualTo(0))return;this.gameData?.soundController?.play("half-double").catch((i)=>console.error(i)),this.gameData?.hapticController?.lightClick();let a=C.max(this.gameData.minBet,C.min(C(this.value).dividedBy(2),C(this.gameData?.balance??0),C(this.gameData.maxPayout).div(this.betMaxMultiplier||1),C(this.gameData.maxBet)));this.updateAmount(a)}handleDoubleBet(){if(this.disabled)return;if(this.gameData?.soundController?.play("half-double").catch((i)=>console.error(i)),this.gameData?.hapticController?.lightClick(),C(this.value).isZero()){this.updateAmount(C(C("1").div(10**this.gameData.currencyDecimals)));return}let a=C.max(this.gameData.minBet,C.min(C(this.value).multipliedBy(2),C(this.gameData?.balance??0),C(this.gameData.maxBet),C(this.gameData.maxPayout).div(this.betMaxMultiplier||1)));this.updateAmount(a)}handleZeroBet(){if(this.disabled)return;this.gameData?.soundController?.play("half-double").catch((a)=>console.error(a)),this.updateAmount(C(0))}handleMaxBet(){if(this.disabled)return;this.gameData?.soundController?.play("half-double").catch((o)=>console.error(o)),this.gameData?.hapticController?.lightClick();let a=C(this.gameData?.balance??0),i=C(this.gameData?.maxBet??0),e=C.min(a,i,C(this.gameData.maxPayout).div(this.betMaxMultiplier??1));this.updateAmount(e)}formatMonetaryAmount(a,i){let e=Math.abs(a),o=ui(i),n=ii(i),r=ei(i),t="";if(a<0)t+="-";if(r===0)t+=`${n}${e.toFixed(o)}`;if(r===1)t+=`${e.toFixed(o)} ${n}`;return t}render(){let a=this.gameData?.language||"en",i="0.00000000",e=this.invalidReason?V(Qs[this.invalidReason],a):"";if(this.invalidReason==="BET_AMOUNT_BELOW_MIN_BET")e=e.replace("{value}",this.formatMonetaryAmount(this.gameData.minBet,this.gameData.currency));if(this.invalidReason==="BET_AMOUNT_ABOVE_MAX_BET"){let o=C.min(this.gameData.maxBet,this.betMaxMultiplier?C(this.gameData.maxPayout).div(this.betMaxMultiplier).toNumber():this.gameData.maxBet).toNumber();e=e.replace("{value}",this.formatMonetaryAmount(o,this.gameData.currency))}return T`
1912
1912
  <origami-raw-currency-input
1913
1913
  .value=${this.value}
1914
- .label='${this.label||V("common.betAmount",a)}'
1914
+ .label=${this.label||V("common.betAmount",a)}
1915
1915
  .placeholder=${"0.00000000"}
1916
1916
  .currency=${this.gameData?.currency??"USD"}
1917
1917
  ?disabled=${this.disabled}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betorigami/games",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",