playsout-web-sdk 1.0.6 → 1.0.62
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/README.md +353 -369
- package/chunk-MDSUYVLI.cjs +2 -0
- package/chunk-Z5PDR5PA.js +2 -0
- package/data/games.d.ts.map +1 -1
- package/index.cjs +1 -1
- package/index.global.js +18 -25
- package/index.iife.js +18 -25
- package/index.js +1 -1
- package/package.json +1 -1
- package/react/index.cjs +1 -1
- package/react/index.js +1 -1
- package/vue/index.cjs +1 -1
- package/vue/index.js +1 -1
- package/web-components/PlaysoutWidget.d.ts.map +1 -1
- package/web-components/index.cjs +0 -7
- package/web-components/index.js +0 -7
- package/chunk-NHFWJCNJ.cjs +0 -2
- package/chunk-XDBADNFW.js +0 -2
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as ErrorCode,h as Playsout,e as PlaysoutSDK,b as SDKError,d as STORAGE_KEYS,g as default,f as sdk,c as storage}from'./chunk-
|
|
1
|
+
export{a as ErrorCode,h as Playsout,e as PlaysoutSDK,b as SDKError,d as STORAGE_KEYS,g as default,f as sdk,c as storage}from'./chunk-Z5PDR5PA.js';export{a as SDKEvent,b as eventEmitter}from'./chunk-EZLO3WY6.js';
|
package/package.json
CHANGED
package/react/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkMDSUYVLI_cjs=require('../chunk-MDSUYVLI.cjs');require('../chunk-Z2CIDSTP.cjs');var react=require('react'),jsxRuntime=require('react/jsx-runtime');var S=react.createContext(null);function H({children:a,config:n,locale:m}){let[l,p]=react.useState(false),[L,c]=react.useState(false),[G,i]=react.useState(null),[C,f]=react.useState(null),[x,v]=react.useState(m||"zh"),[k,w]=react.useState([]),[b,E]=react.useState([]),[U,r]=react.useState(false),[R,y]=react.useState(null),I=react.useCallback(async o=>{try{r(!0),y(null),await chunkMDSUYVLI_cjs.f.init(o),p(!0),c(chunkMDSUYVLI_cjs.f.isLoggedIn),i(chunkMDSUYVLI_cjs.f.user),f(chunkMDSUYVLI_cjs.f.token),v(chunkMDSUYVLI_cjs.f.locale);let[t,P]=await Promise.all([chunkMDSUYVLI_cjs.f.getGames(),chunkMDSUYVLI_cjs.f.getCategories()]);w(t),E(P);}catch(t){y(t instanceof Error?t:new Error("Initialization failed")),console.error("[PlaysoutProvider] Init error:",t);}finally{r(false);}},[]),z=react.useCallback(async o=>{try{r(!0),y(null);let t=await chunkMDSUYVLI_cjs.h.Login(o);return c(chunkMDSUYVLI_cjs.f.isLoggedIn),i(chunkMDSUYVLI_cjs.f.user),f(chunkMDSUYVLI_cjs.f.token),t}catch(t){let P=t instanceof Error?t:new Error("Login failed");throw y(P),P}finally{r(false);}},[]),V=react.useCallback(()=>{chunkMDSUYVLI_cjs.f.logout(),c(false),i(null),f(null);},[]),D=react.useCallback(o=>{chunkMDSUYVLI_cjs.h.setLocale(o),v(o);},[]),K=react.useCallback(async o=>{try{return r(!0),await chunkMDSUYVLI_cjs.f.getGames(o)}finally{r(false);}},[]),T=react.useCallback(async()=>{try{return r(!0),await chunkMDSUYVLI_cjs.f.getCategories()}finally{r(false);}},[]),A=react.useCallback(async()=>{try{r(!0);let[o,t]=await Promise.all([chunkMDSUYVLI_cjs.f.getGames(),chunkMDSUYVLI_cjs.f.getCategories()]);w(o),E(t);}catch(o){y(o instanceof Error?o:new Error("Refresh failed"));}finally{r(false);}},[]),F=react.useCallback(async()=>{try{r(!0);let o=await chunkMDSUYVLI_cjs.f.getUserInfo();return i(chunkMDSUYVLI_cjs.f.user),o}finally{r(false);}},[]);react.useEffect(()=>{n&&!l&&I(n);},[n,l,I]),react.useEffect(()=>{if(!l)return;let o=()=>{c(chunkMDSUYVLI_cjs.f.isLoggedIn),i(chunkMDSUYVLI_cjs.f.user),f(chunkMDSUYVLI_cjs.f.token);},t=[chunkMDSUYVLI_cjs.h.on("login",o),chunkMDSUYVLI_cjs.h.on("logout",o),chunkMDSUYVLI_cjs.h.on("authExpired",o)];return ()=>{t.forEach(P=>P());}},[l]);let N={isInitialized:l,isLoggedIn:L,user:G,token:C,locale:x,games:k,categories:b,isLoading:U,error:R,init:I,Login:z,logout:V,setLocale:D,getGames:K,getCategories:T,refreshGames:A,getUserInfo:F};return jsxRuntime.jsx(S.Provider,{value:N,children:a})}function h(){let a=react.useContext(S);if(!a)throw new Error("usePlaysout must be used within PlaysoutProvider");return a}function J(a){let{games:n,getGames:m,isLoading:l,error:p}=h(),[L,c]=react.useState(n),[G,i]=react.useState(l);react.useEffect(()=>{c(n);},[n]),react.useEffect(()=>{i(l);},[l]);let C=react.useCallback(async f=>{i(true);try{let x=await m(f||a);c(x);}finally{i(false);}},[m,a]);return {games:L,isLoading:G,error:p,refresh:C}}function M(){let{categories:a,getCategories:n,isLoading:m}=h();return {categories:a,isLoading:m,refresh:n}}Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.h}});exports.PlaysoutProvider=H;exports.useCategories=M;exports.useGames=J;exports.usePlaysout=h;
|
package/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {f,h as h$1}from'../chunk-
|
|
1
|
+
import {f,h as h$1}from'../chunk-Z5PDR5PA.js';export{h as Playsout}from'../chunk-Z5PDR5PA.js';import'../chunk-EZLO3WY6.js';import {createContext,useState,useCallback,useEffect,useContext}from'react';import {jsx}from'react/jsx-runtime';var S=createContext(null);function H({children:a,config:n,locale:m}){let[l,p]=useState(false),[L,c]=useState(false),[G,i]=useState(null),[C,f$1]=useState(null),[x,v]=useState(m||"zh"),[k,w]=useState([]),[b,E]=useState([]),[U,r]=useState(false),[R,y]=useState(null),I=useCallback(async o=>{try{r(!0),y(null),await f.init(o),p(!0),c(f.isLoggedIn),i(f.user),f$1(f.token),v(f.locale);let[t,P]=await Promise.all([f.getGames(),f.getCategories()]);w(t),E(P);}catch(t){y(t instanceof Error?t:new Error("Initialization failed")),console.error("[PlaysoutProvider] Init error:",t);}finally{r(false);}},[]),z=useCallback(async o=>{try{r(!0),y(null);let t=await h$1.Login(o);return c(f.isLoggedIn),i(f.user),f$1(f.token),t}catch(t){let P=t instanceof Error?t:new Error("Login failed");throw y(P),P}finally{r(false);}},[]),V=useCallback(()=>{f.logout(),c(false),i(null),f$1(null);},[]),D=useCallback(o=>{h$1.setLocale(o),v(o);},[]),K=useCallback(async o=>{try{return r(!0),await f.getGames(o)}finally{r(false);}},[]),T=useCallback(async()=>{try{return r(!0),await f.getCategories()}finally{r(false);}},[]),A=useCallback(async()=>{try{r(!0);let[o,t]=await Promise.all([f.getGames(),f.getCategories()]);w(o),E(t);}catch(o){y(o instanceof Error?o:new Error("Refresh failed"));}finally{r(false);}},[]),F=useCallback(async()=>{try{r(!0);let o=await f.getUserInfo();return i(f.user),o}finally{r(false);}},[]);useEffect(()=>{n&&!l&&I(n);},[n,l,I]),useEffect(()=>{if(!l)return;let o=()=>{c(f.isLoggedIn),i(f.user),f$1(f.token);},t=[h$1.on("login",o),h$1.on("logout",o),h$1.on("authExpired",o)];return ()=>{t.forEach(P=>P());}},[l]);let N={isInitialized:l,isLoggedIn:L,user:G,token:C,locale:x,games:k,categories:b,isLoading:U,error:R,init:I,Login:z,logout:V,setLocale:D,getGames:K,getCategories:T,refreshGames:A,getUserInfo:F};return jsx(S.Provider,{value:N,children:a})}function h(){let a=useContext(S);if(!a)throw new Error("usePlaysout must be used within PlaysoutProvider");return a}function J(a){let{games:n,getGames:m,isLoading:l,error:p}=h(),[L,c]=useState(n),[G,i]=useState(l);useEffect(()=>{c(n);},[n]),useEffect(()=>{i(l);},[l]);let C=useCallback(async f=>{i(true);try{let x=await m(f||a);c(x);}finally{i(false);}},[m,a]);return {games:L,isLoading:G,error:p,refresh:C}}function M(){let{categories:a,getCategories:n,isLoading:m}=h();return {categories:a,isLoading:m,refresh:n}}export{H as PlaysoutProvider,M as useCategories,J as useGames,h as usePlaysout};
|
package/vue/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkMDSUYVLI_cjs=require('../chunk-MDSUYVLI.cjs');require('../chunk-Z2CIDSTP.cjs');var vue=require('vue');var c=Symbol("PlaysoutSDK");function p(){let l=vue.ref(false),f=vue.ref(false),u=vue.ref(null),g=vue.ref(null),m=vue.ref("zh"),y=vue.ref([]),P=vue.ref([]),o=vue.ref(false),s=vue.ref(null),L=false,G=vue.computed(()=>s.value!==null);async function x(e){try{o.value=!0,s.value=null,await chunkMDSUYVLI_cjs.f.init(e),l.value=!0,i(),S(),await v();}catch(a){s.value=a instanceof Error?a:new Error("Initialization failed"),console.error("[usePlaysout] Init error:",a);}finally{o.value=false;}}function i(){f.value=chunkMDSUYVLI_cjs.f.isLoggedIn,u.value=chunkMDSUYVLI_cjs.f.user,g.value=chunkMDSUYVLI_cjs.f.token,m.value=chunkMDSUYVLI_cjs.f.locale;}function S(){L||(L=true,chunkMDSUYVLI_cjs.h.on("login",i),chunkMDSUYVLI_cjs.h.on("logout",i),chunkMDSUYVLI_cjs.h.on("authExpired",i));}async function b(e){try{o.value=!0,s.value=null;let a=await chunkMDSUYVLI_cjs.h.Login(e);return i(),a}catch(a){let d=a instanceof Error?a:new Error("Login failed");throw s.value=d,d}finally{o.value=false;}}function R(){chunkMDSUYVLI_cjs.f.logout(),i();}function E(e){chunkMDSUYVLI_cjs.h.setLocale(e),m.value=e;}async function h(e){try{return o.value=!0,await chunkMDSUYVLI_cjs.f.getGames(e)}finally{o.value=false;}}async function K(){try{return o.value=!0,await chunkMDSUYVLI_cjs.f.getCategories()}finally{o.value=false;}}async function v(){try{o.value=!0;let[e,a]=await Promise.all([chunkMDSUYVLI_cjs.f.getGames(),chunkMDSUYVLI_cjs.f.getCategories()]);y.value=e,P.value=a;}catch(e){s.value=e instanceof Error?e:new Error("Refresh failed");}finally{o.value=false;}}return {isInitialized:l,isLoggedIn:f,user:u,token:g,locale:m,games:y,categories:P,isLoading:o,error:s,hasError:G,init:x,Login:b,logout:R,setLocale:E,getGames:h,getCategories:K,refreshGames:v}}function C(){let l=vue.inject(c);if(!l)throw new Error("usePlaysout must be used after calling createPlaysout()");return l}function k(l={}){return {install(f){let u=p();f.provide(c,u),l.config&&u.init(l.config);}}}Object.defineProperty(exports,"Playsout",{enumerable:true,get:function(){return chunkMDSUYVLI_cjs.h}});exports.createPlaysout=p;exports.createPlaysoutPlugin=k;exports.usePlaysout=C;
|
package/vue/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {f,h}from'../chunk-
|
|
1
|
+
import {f,h}from'../chunk-Z5PDR5PA.js';export{h as Playsout}from'../chunk-Z5PDR5PA.js';import'../chunk-EZLO3WY6.js';import {ref,computed,inject}from'vue';var c=Symbol("PlaysoutSDK");function p(){let l=ref(false),f$1=ref(false),u=ref(null),g=ref(null),m=ref("zh"),y=ref([]),P=ref([]),o=ref(false),s=ref(null),L=false,G=computed(()=>s.value!==null);async function x(e){try{o.value=!0,s.value=null,await f.init(e),l.value=!0,i(),S(),await v();}catch(a){s.value=a instanceof Error?a:new Error("Initialization failed"),console.error("[usePlaysout] Init error:",a);}finally{o.value=false;}}function i(){f$1.value=f.isLoggedIn,u.value=f.user,g.value=f.token,m.value=f.locale;}function S(){L||(L=true,h.on("login",i),h.on("logout",i),h.on("authExpired",i));}async function b(e){try{o.value=!0,s.value=null;let a=await h.Login(e);return i(),a}catch(a){let d=a instanceof Error?a:new Error("Login failed");throw s.value=d,d}finally{o.value=false;}}function R(){f.logout(),i();}function E(e){h.setLocale(e),m.value=e;}async function h$1(e){try{return o.value=!0,await f.getGames(e)}finally{o.value=false;}}async function K(){try{return o.value=!0,await f.getCategories()}finally{o.value=false;}}async function v(){try{o.value=!0;let[e,a]=await Promise.all([f.getGames(),f.getCategories()]);y.value=e,P.value=a;}catch(e){s.value=e instanceof Error?e:new Error("Refresh failed");}finally{o.value=false;}}return {isInitialized:l,isLoggedIn:f$1,user:u,token:g,locale:m,games:y,categories:P,isLoading:o,error:s,hasError:G,init:x,Login:b,logout:R,setLocale:E,getGames:h$1,getCategories:K,refreshGames:v}}function C(){let l=inject(c);if(!l)throw new Error("usePlaysout must be used after calling createPlaysout()");return l}function k(l={}){return {install(f){let u=p();f.provide(c,u),l.config&&u.init(l.config);}}}export{p as createPlaysout,k as createPlaysoutPlugin,C as usePlaysout};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlaysoutWidget.d.ts","sourceRoot":"","sources":["../../src/web-components/PlaysoutWidget.ts"],"names":[],"mappings":"AAg4CA,cAAM,cAAe,SAAQ,WAAW;IACtC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,WAAW,CAAc;IAGjC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,WAAW,CAAc;IAGjC,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,gBAAgB,CAAc;IACtC,OAAO,CAAC,sBAAsB,CAAwD;IAEtF,MAAM,KAAK,kBAAkB,aAE5B;;IAgBD,OAAO,CAAC,CAAC;IAUT,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,aAAa;IAmBrB,iBAAiB;IAMjB,oBAAoB;IASpB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;YA+CzE,SAAS;IA4BvB,OAAO,CAAC,UAAU;YAmBJ,WAAW;IA6BzB,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,SAAS;IAgBjB,OAAO,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"PlaysoutWidget.d.ts","sourceRoot":"","sources":["../../src/web-components/PlaysoutWidget.ts"],"names":[],"mappings":"AAg4CA,cAAM,cAAe,SAAQ,WAAW;IACtC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,WAAW,CAAc;IAGjC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,WAAW,CAAc;IAGjC,OAAO,CAAC,WAAW,CAA+B;IAClD,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,gBAAgB,CAAc;IACtC,OAAO,CAAC,sBAAsB,CAAwD;IAEtF,MAAM,KAAK,kBAAkB,aAE5B;;IAgBD,OAAO,CAAC,CAAC;IAUT,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,aAAa;IAmBrB,iBAAiB;IAMjB,oBAAoB;IASpB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;YA+CzE,SAAS;IA4BvB,OAAO,CAAC,UAAU;YAmBJ,WAAW;IA6BzB,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,SAAS;IAgBjB,OAAO,CAAC,MAAM;IA0Gd,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,QAAQ,CAKd;IAEF,OAAO,CAAC,cAAc;IA6DtB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,gBAAgB;IAgExB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,gBAAgB;IAuFxB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,uBAAuB;IAuE/B,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,YAAY,CAAuB;IAE3C,OAAO,CAAC,SAAS;IAoCjB,OAAO,CAAC,WAAW;IAgEnB,OAAO,CAAC,eAAe;IAqCvB,OAAO,CAAC,cAAc;IA+BtB,OAAO,CAAC,gBAAgB;IAoDxB,OAAO,CAAC,oBAAoB;CAkD7B;AAOD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/web-components/index.cjs
CHANGED
|
@@ -1303,13 +1303,6 @@
|
|
|
1303
1303
|
<img src="${L("./logowhite.png")}" alt="Playsout" />
|
|
1304
1304
|
</div>
|
|
1305
1305
|
<div class="widget-user">
|
|
1306
|
-
<!-- Gems Button -->
|
|
1307
|
-
<button class="widget-gems-btn" id="gems-btn" aria-label="Gem Store">
|
|
1308
|
-
<span class="widget-gems-amount" id="gems-amount">${this.userPoints}</span>
|
|
1309
|
-
<svg class="widget-gems-icon" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
1310
|
-
<use href="#icon-gem"/>
|
|
1311
|
-
</svg>
|
|
1312
|
-
</button>
|
|
1313
1306
|
<!-- Profile Button -->
|
|
1314
1307
|
<button class="widget-profile-btn" id="profile-btn" aria-label="Profile">
|
|
1315
1308
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
package/web-components/index.js
CHANGED
|
@@ -1303,13 +1303,6 @@ import {b as b$1,c}from'../chunk-EZLO3WY6.js';function U(o,n=false){return;}func
|
|
|
1303
1303
|
<img src="${L("./logowhite.png")}" alt="Playsout" />
|
|
1304
1304
|
</div>
|
|
1305
1305
|
<div class="widget-user">
|
|
1306
|
-
<!-- Gems Button -->
|
|
1307
|
-
<button class="widget-gems-btn" id="gems-btn" aria-label="Gem Store">
|
|
1308
|
-
<span class="widget-gems-amount" id="gems-amount">${this.userPoints}</span>
|
|
1309
|
-
<svg class="widget-gems-icon" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
1310
|
-
<use href="#icon-gem"/>
|
|
1311
|
-
</svg>
|
|
1312
|
-
</button>
|
|
1313
1306
|
<!-- Profile Button -->
|
|
1314
1307
|
<button class="widget-profile-btn" id="profile-btn" aria-label="Profile">
|
|
1315
1308
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
package/chunk-NHFWJCNJ.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkZ2CIDSTP_cjs=require('./chunk-Z2CIDSTP.cjs');var N=(m=>(m.NOT_INITIALIZED="NOT_INITIALIZED",m.ALREADY_INITIALIZED="ALREADY_INITIALIZED",m.NOT_LOGGED_IN="NOT_LOGGED_IN",m.TOKEN_EXPIRED="TOKEN_EXPIRED",m.INVALID_TOKEN="INVALID_TOKEN",m.NETWORK_ERROR="NETWORK_ERROR",m.TIMEOUT="TIMEOUT",m.SERVER_ERROR="SERVER_ERROR",m.API_ERROR="API_ERROR",m.INVALID_PARAMS="INVALID_PARAMS",m.MISSING_PARAMS="MISSING_PARAMS",m.FEATURE_NOT_SUPPORTED="FEATURE_NOT_SUPPORTED",m.UNKNOWN="UNKNOWN",m.PAYMENT_FAILED="PAYMENT_FAILED",m.SHARE_FAILED="SHARE_FAILED",m))(N||{}),E=class extends Error{constructor(t,r,i){super(r);this.code=t;this.details=i;this.name="SDKError";}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}},Z={NOT_INITIALIZED:"SDK not initialized. Please call PlaysoutSDK.init() first.",ALREADY_INITIALIZED:"SDK already initialized. Please do not call init() more than once.",NOT_LOGGED_IN:"User not logged in. Please log in first.",TOKEN_EXPIRED:"Login token has expired. Please log in again.",INVALID_TOKEN:"Invalid login token. Please log in again.",NETWORK_ERROR:"Network connection failed. Please check your network.",TIMEOUT:"Request timed out. Please try again later.",SERVER_ERROR:"Server is busy. Please try again later.",API_ERROR:"API request failed.",INVALID_PARAMS:"Invalid parameter(s).",MISSING_PARAMS:"Missing required parameter(s).",FEATURE_NOT_SUPPORTED:"This feature is not supported in the current environment.",UNKNOWN:"An unknown error occurred.",PAYMENT_FAILED:"Payment failed.",SHARE_FAILED:"Share failed."};function s(o,e){return new E(o,Z[o],e)}var P="playsout_",R=class{constructor(e){this.storage=e;}get(e){try{return this.storage.getItem(P+e)}catch{return null}}set(e,t){try{this.storage.setItem(P+e,t);}catch(r){console.warn("[PlaysoutSDK] Storage set failed:",r);}}remove(e){try{this.storage.removeItem(P+e);}catch{}}clear(){try{let e=[];for(let t=0;t<this.storage.length;t++){let r=this.storage.key(t);r&&r.startsWith(P)&&e.push(r);}e.forEach(t=>this.storage.removeItem(t));}catch{}}},_=class{constructor(){this.store=new Map;}get(e){return this.store.get(e)??null}set(e,t){this.store.set(e,t);}remove(e){this.store.delete(e);}clear(){this.store.clear();}};function x(o="localStorage"){return typeof window>"u"||o==="memory"?new _:o==="sessionStorage"?new R(sessionStorage):new R(localStorage)}var T=x(),l={get:o=>T.get(o),set:(o,e)=>{T.set(o,e);},remove:o=>{T.remove(o);},clear:()=>{T.clear();},getJSON:o=>{let e=T.get(o);if(!e)return null;try{return JSON.parse(e)}catch{return null}},setJSON:(o,e)=>{T.set(o,JSON.stringify(e));},configure(o){T=x(o);}},u={TOKEN_DATA:"token_data",USER:"user",LOGIN_PARAMS:"login_params",LOCALE:"locale",CONFIG:"config"};var V=o=>{if(!o)return o;try{let e=new URL(o);if(e.hostname==="games.playsout.com"){let t=e.pathname,r=t.endsWith("/"),i=/\.[a-z0-9]+$/i.test(t);!r&&!i&&(e.pathname=`${t}/`);}return e.toString()}catch{return o}},X=o=>o.map(e=>{if(!e.externalUrl)return e;let t=V(e.externalUrl);return t===e.externalUrl?e:{...e,externalUrl:t}}),Y=[{id:"BlockCrushFun",title:"Block Crush Fun",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/BlockCrushFun.png"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BlockCrushFun"},{id:"DogeSurvivors",title:"Doge Survivors",category:"Doge OS",image:chunkZ2CIDSTP_cjs.c("./games/DogeSurvivors.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeSurvivors/"},{id:"DogeMaze",title:"Doge Maze",category:"Doge OS",image:chunkZ2CIDSTP_cjs.c("./games/DogeMaze.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMaze/"},{id:"DogeMart",title:"Doge Mart",category:"Doge OS",image:chunkZ2CIDSTP_cjs.c("./games/DogeMart.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMart/"},{id:"KittyEscape",title:"Kitty Escape",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/KittyEscape.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/KittyEscape/"},{id:"ProjectGarden",title:"Project: Garden",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/SimulatedAdventures.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/simulated/"},{id:"ProjectIDLE",title:"Project: IDLE",category:"Simulation",image:chunkZ2CIDSTP_cjs.c("./games/ProjectIDLE.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/idle/"},{id:"CulinaryStarWeb",title:"Culinary Star",category:"Casual",image:chunkZ2CIDSTP_cjs.c("./games/CulinaryStar.webp"),description:"Cooking game",isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CulinaryStar/"},{id:"PickaxeQuest",title:"Pickaxe Quest",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/PickaxeQuest.jpg"),description:"Mining and adventure game",isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/PickaxeQuest/",apiGameId:73},{id:"MonsterSurvivors",title:"Monster Survivors",category:"Adventure",image:chunkZ2CIDSTP_cjs.c("./games/MonsterSurvivors.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MonsterSurvivors/"},{id:"IdleTowerDefense",title:"Idle Tower Defense",category:"RPG",image:chunkZ2CIDSTP_cjs.c("./games/IdleTowerDefense.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/IdleTowerDefense/"},{id:"MushroomWarriors",title:"Mushroom Warriors",category:"RPG",image:chunkZ2CIDSTP_cjs.c("./games/MushroomWarriors.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MushroomWarriors/"},{id:"FollowThePath",title:"Follow The Path",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/FollowThePath.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/FollowThePath/"},{id:"ColorRun",title:"Color Run",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ColorRun.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ColorRun/"},{id:"StupidArrow",title:"Stupid Arrow",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/StupidArrow.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/StupidArrow/"},{id:"ZigZag",title:"Zig Zag",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ZigZag.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ZigZag/"},{id:"SpikesEverywhere",title:"Spikes Everywhere",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/SpikesEverywhere.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/SpikesEverywhere/"},{id:"ArrowRacer",title:"Arrow Racer",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ArrowRacer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ArrowRacer/"},{id:"CircleLeap",title:"Circle Leap",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/CircleLeap.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CircleLeap/"},{id:"ColorMatcher",title:"Color Matcher",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ColorMatcher.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ColorMatcher/"},{id:"EndlessMaze",title:"Endless Maze",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/EndlessMaze.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/EndlessMaze/"},{id:"SpinningAround",title:"Spinning Around",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/SpinningAround.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/SpinningAround/"},{id:"BoomBallz",title:"Boom Ballz",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/BoomBallz.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BoomBallz/"},{id:"CubeHead",title:"Cube Head",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/CubeHead.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CubeHead/"},{id:"CapybaraLink",title:"Capybara Link",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/CapybaraLink.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CapybaraLink/"},{id:"Snake2048",title:"Snake 2048",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/Snake2048.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Snake2048/"},{id:"FishTankFury",title:"Fish Tank Fury",category:"Puzzle",image:chunkZ2CIDSTP_cjs.c("./games/FishTankFury.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/FishTankFury/"},{id:"ConnectBalls",title:"Connect Balls",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/ConnectBalls.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ConnectBalls/"},{id:"CircularBreaker",title:"Circular Breaker",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/CircularBreaker.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CircularBreaker/"},{id:"OneDoor",title:"One Door",category:"Arcade",image:chunkZ2CIDSTP_cjs.c("./games/OneDoor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/OneDoor/"},{id:"CatchtheFruits",title:"Catch the Fruits",category:"Casual",image:chunkZ2CIDSTP_cjs.c("./games/CatchtheFruits.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CatchtheFruits/"},{id:"Falling2048",title:"Falling 2048",category:"Casual",image:chunkZ2CIDSTP_cjs.c("./games/Falling2048.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Falling2048/"}],M=X(Y),h=()=>M.filter(o=>o.enable);({Adventure:h().filter(o=>o.category==="Adventure"),Moba:h().filter(o=>o.category==="Moba")});var K=o=>M.find(e=>e.id===o);var z=()=>Array.from(new Set(h().map(o=>o.category)));var C="https://api.playsout.com",G=3e4;function Q(o){let e=String(o?.platform||"").toLowerCase();if(e==="tiktok"){let t=o.authorizationCode;if(typeof t!="string"||!t.trim())throw s("MISSING_PARAMS","authorizationCode is required for TikTok login");return {platform:e,authorizationCode:t}}if(e==="grab"||e==="eros"){let t=o;if(typeof t.platformUserId!="string"||!t.platformUserId.trim())throw s("MISSING_PARAMS","platformUserId is required for Grab/Eros login");if(typeof t.platformToken!="string"||!t.platformToken.trim())throw s("MISSING_PARAMS","platformToken is required for Grab/Eros login");if(typeof t.username!="string"||!t.username.trim())throw s("MISSING_PARAMS","username is required for Grab/Eros login");return {platform:e,platformUserId:t.platformUserId,platformToken:t.platformToken,username:t.username,inviteCode:typeof t.inviteCode=="string"?t.inviteCode:void 0}}throw s("INVALID_PARAMS","Unsupported platform. Expected grab, eros, or tiktok")}var S=null,v=null,O=null,b=null;function B(o){v=o;}function q(o){O=o;}function W(o){b=o;}function H(){if(b)try{b();}catch{}}async function ee(o){if(!O)throw H(),o instanceof E?o:s("TOKEN_EXPIRED",o);try{return await O()}catch(e){throw H(),e instanceof E?e:s("TOKEN_EXPIRED",e)}}async function j(o,e={},t,r=false,i=r){let c=t?.apiBaseUrl||C,p=o.startsWith("http")?o:`${c}${o}`,g=new AbortController,f=setTimeout(()=>g.abort(),G);try{let d=l.getJSON(u.TOKEN_DATA),A={"Content-Type":"application/json",...e.headers};r&&d?.accessToken&&!A.token&&(A.token=d.accessToken);let I=await fetch(p,{...e,signal:g.signal,headers:A});if(clearTimeout(f),!I.ok){if(I.status===401&&r&&i)return await F(o,e,t);throw s(I.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${I.status}: ${I.statusText}`)}let D=await I.json();if(D.code!==1e4){if(r&&i)return await F(o,e,t);throw s("API_ERROR",D.msg||"API request failed")}return D.data}catch(d){throw clearTimeout(f),d instanceof E?d:d instanceof Error?d.name==="AbortError"?s("TIMEOUT"):s("NETWORK_ERROR",d.message):s("UNKNOWN")}}async function F(o,e,t){await J(t);let r=t?.apiBaseUrl||C,i=o.startsWith("http")?o:`${r}${o}`,c=new AbortController,p=setTimeout(()=>c.abort(),G);try{let g=l.getJSON(u.TOKEN_DATA),f={"Content-Type":"application/json",...e.headers};g?.accessToken&&(f.token=g.accessToken);let d=await fetch(i,{...e,signal:c.signal,headers:f});if(clearTimeout(p),!d.ok)throw s(d.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${d.status}: ${d.statusText}`);let A=await d.json();if(A.code!==1e4)throw s("API_ERROR",A.msg||"API request failed");return A.data}catch(g){throw clearTimeout(p),g instanceof E?g:g instanceof Error&&g.name==="AbortError"?s("TIMEOUT"):s("NETWORK_ERROR",g?.message||"Request failed")}}async function J(o){if(S)return S;let e=(async()=>{try{let t=l.getJSON(u.TOKEN_DATA),r=Math.floor(Date.now()/1e3);if(!t?.refreshToken||t.refreshExpiresAt<=r)throw s("TOKEN_EXPIRED","Refresh token has expired");let i=o?.apiBaseUrl||C,c=new AbortController,p=setTimeout(()=>c.abort(),G);try{let g=await fetch(`${i}/platform/refreshToken`,{method:"POST",signal:c.signal,headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t.refreshToken})});if(clearTimeout(p),!g.ok)throw g.status>=500?s("SERVER_ERROR",`HTTP ${g.status}: ${g.statusText}`):s("TOKEN_EXPIRED",`HTTP ${g.status}: ${g.statusText}`);let f=await g.json();if(f.code!==1e4||!f.data)throw s("TOKEN_EXPIRED",f.msg||"Failed to refresh token");let d=f.data;if(l.setJSON(u.TOKEN_DATA,d),v)try{v(d);}catch{}return d}catch(g){throw clearTimeout(p),g instanceof E?g:g instanceof Error&&g.name==="AbortError"?s("TIMEOUT"):s("NETWORK_ERROR",g?.message||"Refresh token failed")}}catch(t){return await ee(t)}})();S=e;try{return await e}finally{S===e&&(S=null);}}var U=class{constructor(){this.config=null;}configure(e){this.config=e;}async refreshToken(){return await J(this.config||void 0)}async getGames(e){let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){let e=h(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],c)=>({id:`category_${c}`,name:r,count:i}))}async getGameById(e){return K(e)}async getCategoryNames(){return z()}async loginOnly(e){let t=Q(e);return await j("/platform/login",{method:"POST",body:JSON.stringify(t)},this.config??void 0)}async Login(e){let t=await this.loginOnly(e);l.setJSON(u.TOKEN_DATA,t);try{let r=await this.getUserInfo(!1);return {tokenData:t,user:r}}catch(r){throw l.remove(u.TOKEN_DATA),l.remove(u.USER),r}}async getUserInfo(e=true){return await j("/platform/user",{method:"GET"},this.config??void 0,true,e)}async getUser(){return l.getJSON(u.USER)}async validateToken(e){return !!e}},L=null;function k(){return L||(L=new U),L}var te="https://api.playsout.com",$="zh",w=class o{constructor(){this.config=null;this._isInitialized=false;this._user=null;this._token=null;this._locale=$;this._widget=null;}clearAuthState(){let e=!!(this._token||l.get(u.TOKEN_DATA)||l.get(u.USER));return this._user=null,this._token=null,l.remove(u.TOKEN_DATA),l.remove(u.USER),l.remove(u.LOGIN_PARAMS),e}updateUser(e){this._user={userId:String(e.id),username:e.username},l.setJSON(u.USER,this._user);}saveLoginParams(e){if(e.platform==="grab"||e.platform==="eros"){l.setJSON(u.LOGIN_PARAMS,{...e});return}l.remove(u.LOGIN_PARAMS);}async performLogin(e,t){let r=k();r.configure(this.config);let i=await r.loginOnly(e);l.setJSON(u.TOKEN_DATA,i);let c=await r.getUserInfo(false);return this._token=i.accessToken,this.updateUser(c),t&&this.saveLoginParams(e),chunkZ2CIDSTP_cjs.b.emit("login",{user:this._user,token:this._token}),{tokenData:i,user:c}}async recoverAuthentication(){let e=l.getJSON(u.LOGIN_PARAMS);if(!e||e.platform!=="grab"&&e.platform!=="eros")throw s("TOKEN_EXPIRED","No reusable login parameters available");return (await this.performLogin(e,false)).tokenData}handleAuthExpired(){this.clearAuthState()&&chunkZ2CIDSTP_cjs.b.emit("authExpired"),this.config?.debug&&console.warn("[PlaysoutSDK] Auth expired, logged out");}static getInstance(){return o.instance||(o.instance=new o),o.instance}async init(e={}){if(this._isInitialized)throw s("ALREADY_INITIALIZED");this.config={apiBaseUrl:e.apiBaseUrl||te,debug:e.debug||false,storage:e.storage||"localStorage",locale:e.locale||$,appId:e.appId||""},l.configure(this.config.storage),B(i=>{this._token=i.accessToken;}),q(()=>this.recoverAuthentication()),W(()=>{this.handleAuthExpired();});let t=l.getJSON(u.TOKEN_DATA);this._user=l.getJSON(u.USER),this._locale=l.get(u.LOCALE)||this.config.locale;let r=Math.floor(Date.now()/1e3);if(t){let i=k();if(i.configure(this.config),t.accessToken&&t.expiresAt>r?this._token=t.accessToken:await i.refreshToken(),this._token&&!this._user){let c=await i.getUserInfo();this.updateUser(c);}}else this._user&&(this._user=null,l.remove(u.USER));this._isInitialized=true,this.config.debug&&(console.log("[PlaysoutSDK] Initialized with config:",this.config),console.log("[PlaysoutSDK] Restored token:",this._token?this._token.substring(0,20)+"...":"(none)")),chunkZ2CIDSTP_cjs.b.emit("initialized");}destroy(){this.config=null,this._isInitialized=false,this._user=null,this._token=null,l.clear(),chunkZ2CIDSTP_cjs.b.clear();}get isInitialized(){return this._isInitialized}get isLoggedIn(){return !!(this._token&&this._user)}get user(){return this._user}get token(){return this._token}get locale(){return this._locale}get sdkConfig(){return this.config}async Login(e){this.ensureInitialized(),this.config?.debug&&console.log("[PlaysoutSDK] Login with params:",e);try{let t=await this.performLogin(e,!0);return this.config?.debug&&console.log("[PlaysoutSDK] Login success, user:",t.user),t}catch(t){throw this.clearAuthState(),t}}async getUserInfo(){if(this.ensureInitialized(),!this.isLoggedIn)throw s("NOT_LOGGED_IN","Please login first");let e=k();e.configure(this.config);let t=await e.getUserInfo();return this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo result:",t),t&&this.updateUser(t),t}logout(){this.clearAuthState(),chunkZ2CIDSTP_cjs.b.emit("logout");}getToken(){return this.ensureInitialized(),this._token}getUser(){return this.ensureInitialized(),this._user}setLocale(e){if(this.ensureInitialized(),!["zh","en","ja","ko","vi","th","id","ms"].includes(e))throw s("INVALID_PARAMS",`Unsupported locale: ${e}`);this._locale=e,l.set(u.LOCALE,e),this.config?.debug&&console.log("[PlaysoutSDK] Locale changed to:",e);let t=this._widget||document.querySelector("playsout-widget");t&&t.getAttribute("locale")!==e&&t.setAttribute("locale",e),chunkZ2CIDSTP_cjs.b.emit("localeChange",e);}getLocale(){return this.ensureInitialized(),this._locale}async getGames(e){this.ensureInitialized();let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){this.ensureInitialized();let e=h(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],c)=>({id:`category_${c}`,name:r,count:i}))}async getGameById(e){return this.ensureInitialized(),h().find(t=>t.id===e)}mount(e,t){if(this.ensureInitialized(),typeof document>"u")throw s("FEATURE_NOT_SUPPORTED","mount requires DOM environment");let r=document.querySelector(e);if(!r)throw s("INVALID_PARAMS",`Container not found: ${e}`);let i=document.createElement("playsout-widget");this.config?.appId&&i.setAttribute("app-id",this.config.appId),i.setAttribute("locale",t?.locale||this._locale),t?.detailMode&&i.setAttribute("detail-mode",t.detailMode),this._widget=i,t?.onGameClick&&i.addEventListener("game-click",c=>{let p=c;t.onGameClick(p.detail);}),t?.onLoginRequired&&i.addEventListener("login-required",t.onLoginRequired),t?.onLocaleChange&&i.addEventListener("locale-change",c=>{let p=c;t.onLocaleChange(p.detail);}),r.appendChild(i),this.config?.debug&&console.log("[PlaysoutSDK] Widget mounted to:",e);}unmount(){let e=document.querySelector("playsout-widget");e&&e.remove(),this._widget=null;}on(e,t){return this.ensureInitialized(),chunkZ2CIDSTP_cjs.b.on(e,t)}off(e,t){this.ensureInitialized(),chunkZ2CIDSTP_cjs.b.off(e,t);}ensureInitialized(){if(!this._isInitialized)throw s("NOT_INITIALIZED")}},a=w.getInstance(),Te=a;typeof window<"u"&&(window.__playsout_sdk_instance=a);var we=Object.freeze({init:a.init.bind(a),mount:a.mount.bind(a),unmount:a.unmount.bind(a),destroy:a.destroy.bind(a),Login:a.Login.bind(a),logout:a.logout.bind(a),getToken:a.getToken.bind(a),getUserInfo:a.getUserInfo.bind(a),getUser:a.getUser.bind(a),setLocale:a.setLocale.bind(a),getLocale:a.getLocale.bind(a),getGames:a.getGames.bind(a),getCategories:a.getCategories.bind(a),on:a.on.bind(a),off:a.off.bind(a),get isInitialized(){return a.isInitialized},get isLoggedIn(){return a.isLoggedIn},instance:a,PlaysoutSDKClass:w});
|
|
2
|
-
exports.a=N;exports.b=E;exports.c=l;exports.d=u;exports.e=w;exports.f=a;exports.g=Te;exports.h=we;
|
package/chunk-XDBADNFW.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {c,b as b$1}from'./chunk-EZLO3WY6.js';var N=(m=>(m.NOT_INITIALIZED="NOT_INITIALIZED",m.ALREADY_INITIALIZED="ALREADY_INITIALIZED",m.NOT_LOGGED_IN="NOT_LOGGED_IN",m.TOKEN_EXPIRED="TOKEN_EXPIRED",m.INVALID_TOKEN="INVALID_TOKEN",m.NETWORK_ERROR="NETWORK_ERROR",m.TIMEOUT="TIMEOUT",m.SERVER_ERROR="SERVER_ERROR",m.API_ERROR="API_ERROR",m.INVALID_PARAMS="INVALID_PARAMS",m.MISSING_PARAMS="MISSING_PARAMS",m.FEATURE_NOT_SUPPORTED="FEATURE_NOT_SUPPORTED",m.UNKNOWN="UNKNOWN",m.PAYMENT_FAILED="PAYMENT_FAILED",m.SHARE_FAILED="SHARE_FAILED",m))(N||{}),E=class extends Error{constructor(t,r,i){super(r);this.code=t;this.details=i;this.name="SDKError";}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}},Z={NOT_INITIALIZED:"SDK not initialized. Please call PlaysoutSDK.init() first.",ALREADY_INITIALIZED:"SDK already initialized. Please do not call init() more than once.",NOT_LOGGED_IN:"User not logged in. Please log in first.",TOKEN_EXPIRED:"Login token has expired. Please log in again.",INVALID_TOKEN:"Invalid login token. Please log in again.",NETWORK_ERROR:"Network connection failed. Please check your network.",TIMEOUT:"Request timed out. Please try again later.",SERVER_ERROR:"Server is busy. Please try again later.",API_ERROR:"API request failed.",INVALID_PARAMS:"Invalid parameter(s).",MISSING_PARAMS:"Missing required parameter(s).",FEATURE_NOT_SUPPORTED:"This feature is not supported in the current environment.",UNKNOWN:"An unknown error occurred.",PAYMENT_FAILED:"Payment failed.",SHARE_FAILED:"Share failed."};function s(o,e){return new E(o,Z[o],e)}var P="playsout_",R=class{constructor(e){this.storage=e;}get(e){try{return this.storage.getItem(P+e)}catch{return null}}set(e,t){try{this.storage.setItem(P+e,t);}catch(r){console.warn("[PlaysoutSDK] Storage set failed:",r);}}remove(e){try{this.storage.removeItem(P+e);}catch{}}clear(){try{let e=[];for(let t=0;t<this.storage.length;t++){let r=this.storage.key(t);r&&r.startsWith(P)&&e.push(r);}e.forEach(t=>this.storage.removeItem(t));}catch{}}},_=class{constructor(){this.store=new Map;}get(e){return this.store.get(e)??null}set(e,t){this.store.set(e,t);}remove(e){this.store.delete(e);}clear(){this.store.clear();}};function x(o="localStorage"){return typeof window>"u"||o==="memory"?new _:o==="sessionStorage"?new R(sessionStorage):new R(localStorage)}var T=x(),l={get:o=>T.get(o),set:(o,e)=>{T.set(o,e);},remove:o=>{T.remove(o);},clear:()=>{T.clear();},getJSON:o=>{let e=T.get(o);if(!e)return null;try{return JSON.parse(e)}catch{return null}},setJSON:(o,e)=>{T.set(o,JSON.stringify(e));},configure(o){T=x(o);}},u={TOKEN_DATA:"token_data",USER:"user",LOGIN_PARAMS:"login_params",LOCALE:"locale",CONFIG:"config"};var V=o=>{if(!o)return o;try{let e=new URL(o);if(e.hostname==="games.playsout.com"){let t=e.pathname,r=t.endsWith("/"),i=/\.[a-z0-9]+$/i.test(t);!r&&!i&&(e.pathname=`${t}/`);}return e.toString()}catch{return o}},X=o=>o.map(e=>{if(!e.externalUrl)return e;let t=V(e.externalUrl);return t===e.externalUrl?e:{...e,externalUrl:t}}),Y=[{id:"BlockCrushFun",title:"Block Crush Fun",category:"Puzzle",image:c("./games/BlockCrushFun.png"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BlockCrushFun"},{id:"DogeSurvivors",title:"Doge Survivors",category:"Doge OS",image:c("./games/DogeSurvivors.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeSurvivors/"},{id:"DogeMaze",title:"Doge Maze",category:"Doge OS",image:c("./games/DogeMaze.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMaze/"},{id:"DogeMart",title:"Doge Mart",category:"Doge OS",image:c("./games/DogeMart.jpg"),isNew:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Doge/DogeMart/"},{id:"KittyEscape",title:"Kitty Escape",category:"Puzzle",image:c("./games/KittyEscape.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/KittyEscape/"},{id:"ProjectGarden",title:"Project: Garden",category:"Adventure",image:c("./games/SimulatedAdventures.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/simulated/"},{id:"ProjectIDLE",title:"Project: IDLE",category:"Simulation",image:c("./games/ProjectIDLE.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/idle/"},{id:"CulinaryStarWeb",title:"Culinary Star",category:"Casual",image:c("./games/CulinaryStar.webp"),description:"Cooking game",isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CulinaryStar/"},{id:"PickaxeQuest",title:"Pickaxe Quest",category:"Adventure",image:c("./games/PickaxeQuest.jpg"),description:"Mining and adventure game",isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/PickaxeQuest/",apiGameId:73},{id:"MonsterSurvivors",title:"Monster Survivors",category:"Adventure",image:c("./games/MonsterSurvivors.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MonsterSurvivors/"},{id:"IdleTowerDefense",title:"Idle Tower Defense",category:"RPG",image:c("./games/IdleTowerDefense.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/IdleTowerDefense/"},{id:"MushroomWarriors",title:"Mushroom Warriors",category:"RPG",image:c("./games/MushroomWarriors.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/MushroomWarriors/"},{id:"FollowThePath",title:"Follow The Path",category:"Arcade",image:c("./games/FollowThePath.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/FollowThePath/"},{id:"ColorRun",title:"Color Run",category:"Arcade",image:c("./games/ColorRun.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ColorRun/"},{id:"StupidArrow",title:"Stupid Arrow",category:"Arcade",image:c("./games/StupidArrow.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/StupidArrow/"},{id:"ZigZag",title:"Zig Zag",category:"Arcade",image:c("./games/ZigZag.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ZigZag/"},{id:"SpikesEverywhere",title:"Spikes Everywhere",category:"Arcade",image:c("./games/SpikesEverywhere.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/SpikesEverywhere/"},{id:"ArrowRacer",title:"Arrow Racer",category:"Arcade",image:c("./games/ArrowRacer.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ArrowRacer/"},{id:"CircleLeap",title:"Circle Leap",category:"Arcade",image:c("./games/CircleLeap.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CircleLeap/"},{id:"ColorMatcher",title:"Color Matcher",category:"Arcade",image:c("./games/ColorMatcher.jpg"),isNew:false,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ColorMatcher/"},{id:"EndlessMaze",title:"Endless Maze",category:"Arcade",image:c("./games/EndlessMaze.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/EndlessMaze/"},{id:"SpinningAround",title:"Spinning Around",category:"Arcade",image:c("./games/SpinningAround.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/SpinningAround/"},{id:"BoomBallz",title:"Boom Ballz",category:"Arcade",image:c("./games/BoomBallz.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/BoomBallz/"},{id:"CubeHead",title:"Cube Head",category:"Arcade",image:c("./games/CubeHead.jpg"),isNew:false,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CubeHead/"},{id:"CapybaraLink",title:"Capybara Link",category:"Puzzle",image:c("./games/CapybaraLink.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CapybaraLink/"},{id:"Snake2048",title:"Snake 2048",category:"Puzzle",image:c("./games/Snake2048.jpg"),isNew:true,isHot:true,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Snake2048/"},{id:"FishTankFury",title:"Fish Tank Fury",category:"Puzzle",image:c("./games/FishTankFury.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/FishTankFury/"},{id:"ConnectBalls",title:"Connect Balls",category:"Arcade",image:c("./games/ConnectBalls.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/ConnectBalls/"},{id:"CircularBreaker",title:"Circular Breaker",category:"Arcade",image:c("./games/CircularBreaker.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CircularBreaker/"},{id:"OneDoor",title:"One Door",category:"Arcade",image:c("./games/OneDoor.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/OneDoor/"},{id:"CatchtheFruits",title:"Catch the Fruits",category:"Casual",image:c("./games/CatchtheFruits.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/CatchtheFruits/"},{id:"Falling2048",title:"Falling 2048",category:"Casual",image:c("./games/Falling2048.jpg"),isNew:true,isHot:false,enable:true,orientation:"portrait",externalUrl:"https://games.playsout.com/Falling2048/"}],M=X(Y),h=()=>M.filter(o=>o.enable);({Adventure:h().filter(o=>o.category==="Adventure"),Moba:h().filter(o=>o.category==="Moba")});var K=o=>M.find(e=>e.id===o);var z=()=>Array.from(new Set(h().map(o=>o.category)));var C="https://api.playsout.com",G=3e4;function Q(o){let e=String(o?.platform||"").toLowerCase();if(e==="tiktok"){let t=o.authorizationCode;if(typeof t!="string"||!t.trim())throw s("MISSING_PARAMS","authorizationCode is required for TikTok login");return {platform:e,authorizationCode:t}}if(e==="grab"||e==="eros"){let t=o;if(typeof t.platformUserId!="string"||!t.platformUserId.trim())throw s("MISSING_PARAMS","platformUserId is required for Grab/Eros login");if(typeof t.platformToken!="string"||!t.platformToken.trim())throw s("MISSING_PARAMS","platformToken is required for Grab/Eros login");if(typeof t.username!="string"||!t.username.trim())throw s("MISSING_PARAMS","username is required for Grab/Eros login");return {platform:e,platformUserId:t.platformUserId,platformToken:t.platformToken,username:t.username,inviteCode:typeof t.inviteCode=="string"?t.inviteCode:void 0}}throw s("INVALID_PARAMS","Unsupported platform. Expected grab, eros, or tiktok")}var S=null,v=null,O=null,b=null;function B(o){v=o;}function q(o){O=o;}function W(o){b=o;}function H(){if(b)try{b();}catch{}}async function ee(o){if(!O)throw H(),o instanceof E?o:s("TOKEN_EXPIRED",o);try{return await O()}catch(e){throw H(),e instanceof E?e:s("TOKEN_EXPIRED",e)}}async function j(o,e={},t,r=false,i=r){let c=t?.apiBaseUrl||C,p=o.startsWith("http")?o:`${c}${o}`,g=new AbortController,f=setTimeout(()=>g.abort(),G);try{let d=l.getJSON(u.TOKEN_DATA),A={"Content-Type":"application/json",...e.headers};r&&d?.accessToken&&!A.token&&(A.token=d.accessToken);let I=await fetch(p,{...e,signal:g.signal,headers:A});if(clearTimeout(f),!I.ok){if(I.status===401&&r&&i)return await F(o,e,t);throw s(I.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${I.status}: ${I.statusText}`)}let D=await I.json();if(D.code!==1e4){if(r&&i)return await F(o,e,t);throw s("API_ERROR",D.msg||"API request failed")}return D.data}catch(d){throw clearTimeout(f),d instanceof E?d:d instanceof Error?d.name==="AbortError"?s("TIMEOUT"):s("NETWORK_ERROR",d.message):s("UNKNOWN")}}async function F(o,e,t){await J(t);let r=t?.apiBaseUrl||C,i=o.startsWith("http")?o:`${r}${o}`,c=new AbortController,p=setTimeout(()=>c.abort(),G);try{let g=l.getJSON(u.TOKEN_DATA),f={"Content-Type":"application/json",...e.headers};g?.accessToken&&(f.token=g.accessToken);let d=await fetch(i,{...e,signal:c.signal,headers:f});if(clearTimeout(p),!d.ok)throw s(d.status>=500?"SERVER_ERROR":"API_ERROR",`HTTP ${d.status}: ${d.statusText}`);let A=await d.json();if(A.code!==1e4)throw s("API_ERROR",A.msg||"API request failed");return A.data}catch(g){throw clearTimeout(p),g instanceof E?g:g instanceof Error&&g.name==="AbortError"?s("TIMEOUT"):s("NETWORK_ERROR",g?.message||"Request failed")}}async function J(o){if(S)return S;let e=(async()=>{try{let t=l.getJSON(u.TOKEN_DATA),r=Math.floor(Date.now()/1e3);if(!t?.refreshToken||t.refreshExpiresAt<=r)throw s("TOKEN_EXPIRED","Refresh token has expired");let i=o?.apiBaseUrl||C,c=new AbortController,p=setTimeout(()=>c.abort(),G);try{let g=await fetch(`${i}/platform/refreshToken`,{method:"POST",signal:c.signal,headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:t.refreshToken})});if(clearTimeout(p),!g.ok)throw g.status>=500?s("SERVER_ERROR",`HTTP ${g.status}: ${g.statusText}`):s("TOKEN_EXPIRED",`HTTP ${g.status}: ${g.statusText}`);let f=await g.json();if(f.code!==1e4||!f.data)throw s("TOKEN_EXPIRED",f.msg||"Failed to refresh token");let d=f.data;if(l.setJSON(u.TOKEN_DATA,d),v)try{v(d);}catch{}return d}catch(g){throw clearTimeout(p),g instanceof E?g:g instanceof Error&&g.name==="AbortError"?s("TIMEOUT"):s("NETWORK_ERROR",g?.message||"Refresh token failed")}}catch(t){return await ee(t)}})();S=e;try{return await e}finally{S===e&&(S=null);}}var U=class{constructor(){this.config=null;}configure(e){this.config=e;}async refreshToken(){return await J(this.config||void 0)}async getGames(e){let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){let e=h(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],c)=>({id:`category_${c}`,name:r,count:i}))}async getGameById(e){return K(e)}async getCategoryNames(){return z()}async loginOnly(e){let t=Q(e);return await j("/platform/login",{method:"POST",body:JSON.stringify(t)},this.config??void 0)}async Login(e){let t=await this.loginOnly(e);l.setJSON(u.TOKEN_DATA,t);try{let r=await this.getUserInfo(!1);return {tokenData:t,user:r}}catch(r){throw l.remove(u.TOKEN_DATA),l.remove(u.USER),r}}async getUserInfo(e=true){return await j("/platform/user",{method:"GET"},this.config??void 0,true,e)}async getUser(){return l.getJSON(u.USER)}async validateToken(e){return !!e}},L=null;function k(){return L||(L=new U),L}var te="https://api.playsout.com",$="zh",w=class o{constructor(){this.config=null;this._isInitialized=false;this._user=null;this._token=null;this._locale=$;this._widget=null;}clearAuthState(){let e=!!(this._token||l.get(u.TOKEN_DATA)||l.get(u.USER));return this._user=null,this._token=null,l.remove(u.TOKEN_DATA),l.remove(u.USER),l.remove(u.LOGIN_PARAMS),e}updateUser(e){this._user={userId:String(e.id),username:e.username},l.setJSON(u.USER,this._user);}saveLoginParams(e){if(e.platform==="grab"||e.platform==="eros"){l.setJSON(u.LOGIN_PARAMS,{...e});return}l.remove(u.LOGIN_PARAMS);}async performLogin(e,t){let r=k();r.configure(this.config);let i=await r.loginOnly(e);l.setJSON(u.TOKEN_DATA,i);let c=await r.getUserInfo(false);return this._token=i.accessToken,this.updateUser(c),t&&this.saveLoginParams(e),b$1.emit("login",{user:this._user,token:this._token}),{tokenData:i,user:c}}async recoverAuthentication(){let e=l.getJSON(u.LOGIN_PARAMS);if(!e||e.platform!=="grab"&&e.platform!=="eros")throw s("TOKEN_EXPIRED","No reusable login parameters available");return (await this.performLogin(e,false)).tokenData}handleAuthExpired(){this.clearAuthState()&&b$1.emit("authExpired"),this.config?.debug&&console.warn("[PlaysoutSDK] Auth expired, logged out");}static getInstance(){return o.instance||(o.instance=new o),o.instance}async init(e={}){if(this._isInitialized)throw s("ALREADY_INITIALIZED");this.config={apiBaseUrl:e.apiBaseUrl||te,debug:e.debug||false,storage:e.storage||"localStorage",locale:e.locale||$,appId:e.appId||""},l.configure(this.config.storage),B(i=>{this._token=i.accessToken;}),q(()=>this.recoverAuthentication()),W(()=>{this.handleAuthExpired();});let t=l.getJSON(u.TOKEN_DATA);this._user=l.getJSON(u.USER),this._locale=l.get(u.LOCALE)||this.config.locale;let r=Math.floor(Date.now()/1e3);if(t){let i=k();if(i.configure(this.config),t.accessToken&&t.expiresAt>r?this._token=t.accessToken:await i.refreshToken(),this._token&&!this._user){let c=await i.getUserInfo();this.updateUser(c);}}else this._user&&(this._user=null,l.remove(u.USER));this._isInitialized=true,this.config.debug&&(console.log("[PlaysoutSDK] Initialized with config:",this.config),console.log("[PlaysoutSDK] Restored token:",this._token?this._token.substring(0,20)+"...":"(none)")),b$1.emit("initialized");}destroy(){this.config=null,this._isInitialized=false,this._user=null,this._token=null,l.clear(),b$1.clear();}get isInitialized(){return this._isInitialized}get isLoggedIn(){return !!(this._token&&this._user)}get user(){return this._user}get token(){return this._token}get locale(){return this._locale}get sdkConfig(){return this.config}async Login(e){this.ensureInitialized(),this.config?.debug&&console.log("[PlaysoutSDK] Login with params:",e);try{let t=await this.performLogin(e,!0);return this.config?.debug&&console.log("[PlaysoutSDK] Login success, user:",t.user),t}catch(t){throw this.clearAuthState(),t}}async getUserInfo(){if(this.ensureInitialized(),!this.isLoggedIn)throw s("NOT_LOGGED_IN","Please login first");let e=k();e.configure(this.config);let t=await e.getUserInfo();return this.config?.debug&&console.log("[PlaysoutSDK] getUserInfo result:",t),t&&this.updateUser(t),t}logout(){this.clearAuthState(),b$1.emit("logout");}getToken(){return this.ensureInitialized(),this._token}getUser(){return this.ensureInitialized(),this._user}setLocale(e){if(this.ensureInitialized(),!["zh","en","ja","ko","vi","th","id","ms"].includes(e))throw s("INVALID_PARAMS",`Unsupported locale: ${e}`);this._locale=e,l.set(u.LOCALE,e),this.config?.debug&&console.log("[PlaysoutSDK] Locale changed to:",e);let t=this._widget||document.querySelector("playsout-widget");t&&t.getAttribute("locale")!==e&&t.setAttribute("locale",e),b$1.emit("localeChange",e);}getLocale(){return this.ensureInitialized(),this._locale}async getGames(e){this.ensureInitialized();let t=h();if(e?.category&&(t=t.filter(r=>r.category===e.category)),e?.search){let r=e.search.toLowerCase();t=t.filter(i=>i.title.toLowerCase().includes(r)||i.category.toLowerCase().includes(r)||i.description&&i.description.toLowerCase().includes(r));}if(e?.sortBy)switch(e.sortBy){case "newest":t=t.filter(r=>r.isNew).concat(t.filter(r=>!r.isNew));break;case "rating":t=t.filter(r=>r.isHot).concat(t.filter(r=>!r.isHot));break}if(e?.page&&e?.pageSize){let r=(e.page-1)*e.pageSize;t=t.slice(r,r+e.pageSize);}return t}async getCategories(){this.ensureInitialized();let e=h(),t=new Map;return e.forEach(r=>{let i=t.get(r.category)||0;t.set(r.category,i+1);}),Array.from(t.entries()).map(([r,i],c)=>({id:`category_${c}`,name:r,count:i}))}async getGameById(e){return this.ensureInitialized(),h().find(t=>t.id===e)}mount(e,t){if(this.ensureInitialized(),typeof document>"u")throw s("FEATURE_NOT_SUPPORTED","mount requires DOM environment");let r=document.querySelector(e);if(!r)throw s("INVALID_PARAMS",`Container not found: ${e}`);let i=document.createElement("playsout-widget");this.config?.appId&&i.setAttribute("app-id",this.config.appId),i.setAttribute("locale",t?.locale||this._locale),t?.detailMode&&i.setAttribute("detail-mode",t.detailMode),this._widget=i,t?.onGameClick&&i.addEventListener("game-click",c=>{let p=c;t.onGameClick(p.detail);}),t?.onLoginRequired&&i.addEventListener("login-required",t.onLoginRequired),t?.onLocaleChange&&i.addEventListener("locale-change",c=>{let p=c;t.onLocaleChange(p.detail);}),r.appendChild(i),this.config?.debug&&console.log("[PlaysoutSDK] Widget mounted to:",e);}unmount(){let e=document.querySelector("playsout-widget");e&&e.remove(),this._widget=null;}on(e,t){return this.ensureInitialized(),b$1.on(e,t)}off(e,t){this.ensureInitialized(),b$1.off(e,t);}ensureInitialized(){if(!this._isInitialized)throw s("NOT_INITIALIZED")}},a=w.getInstance(),Te=a;typeof window<"u"&&(window.__playsout_sdk_instance=a);var we=Object.freeze({init:a.init.bind(a),mount:a.mount.bind(a),unmount:a.unmount.bind(a),destroy:a.destroy.bind(a),Login:a.Login.bind(a),logout:a.logout.bind(a),getToken:a.getToken.bind(a),getUserInfo:a.getUserInfo.bind(a),getUser:a.getUser.bind(a),setLocale:a.setLocale.bind(a),getLocale:a.getLocale.bind(a),getGames:a.getGames.bind(a),getCategories:a.getCategories.bind(a),on:a.on.bind(a),off:a.off.bind(a),get isInitialized(){return a.isInitialized},get isLoggedIn(){return a.isLoggedIn},instance:a,PlaysoutSDKClass:w});
|
|
2
|
-
export{N as a,E as b,l as c,u as d,w as e,a as f,Te as g,we as h};
|