kadou-game-sdk 1.0.3 → 1.0.4

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var SDK_VERSION = '1.0.3';
5
+ var SDK_VERSION = '1.0.4';
6
6
 
7
7
  var _MESSAGE_TYPES;
8
8
  /**
@@ -57,7 +57,7 @@ var MESSAGE_TYPES = (_MESSAGE_TYPES = {
57
57
  QUESTION_SUBMIT: 'QUESTION_SUBMIT',
58
58
  //单题提交
59
59
  ANSWER_COMPLETED: 'ANSWER_COMPLETED'
60
- }, _MESSAGE_TYPES["QUESTION_SUBMIT"] = 'QUESTION_SUBMIT', _MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED = 'QUESTION_ANSWER_COMPLETED', _MESSAGE_TYPES.ANSWER_POPUP_SHOW = 'ANSWER_POPUP_SHOW', _MESSAGE_TYPES.ANSWER_POPUP_COMPLETED = 'ANSWER_POPUP_COMPLETED', _MESSAGE_TYPES.AUDIO_VOLUME_CHANGE = 'AUDIO_VOLUME_CHANGE', _MESSAGE_TYPES.PAGE_START_SHOW = 'PAGE_START_SHOW', _MESSAGE_TYPES.PAGE_END_SHOW = 'PAGE_END_SHOW', _MESSAGE_TYPES.EXTENSION_EVENT = 'EXTENSION_EVENT', _MESSAGE_TYPES.ERROR = 'ERROR', _MESSAGE_TYPES);
60
+ }, _MESSAGE_TYPES["QUESTION_SUBMIT"] = 'QUESTION_SUBMIT', _MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED = 'QUESTION_ANSWER_COMPLETED', _MESSAGE_TYPES.QUESTION_SUBMIT_RESULT = 'QUESTION_SUBMIT_RESULT', _MESSAGE_TYPES.ANSWER_POPUP_SHOW = 'ANSWER_POPUP_SHOW', _MESSAGE_TYPES.ANSWER_POPUP_COMPLETED = 'ANSWER_POPUP_COMPLETED', _MESSAGE_TYPES.AUDIO_VOLUME_CHANGE = 'AUDIO_VOLUME_CHANGE', _MESSAGE_TYPES.PAGE_START_SHOW = 'PAGE_START_SHOW', _MESSAGE_TYPES.PAGE_END_SHOW = 'PAGE_END_SHOW', _MESSAGE_TYPES.EXTENSION_EVENT = 'EXTENSION_EVENT', _MESSAGE_TYPES.ERROR = 'ERROR', _MESSAGE_TYPES);
61
61
 
62
62
  function isFunction(fn) {
63
63
  return typeof fn === 'function';
@@ -1325,7 +1325,7 @@ GameManager.prototype._bindBusEvents = function () {
1325
1325
  * 纯转发事件统一注册
1326
1326
  * 这些事件只是把底层消息转成标准事件名
1327
1327
  */
1328
- this._registerBusEventMap((_this$_registerBusEve = {}, _this$_registerBusEve[MESSAGE_TYPES.GAME_LOAD] = 'game:load', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADED] = 'game:loaded', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADING] = 'game:loading', _this$_registerBusEve[MESSAGE_TYPES.CONFIG_UPDATE] = 'config:update', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_START] = 'answer:start', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT] = 'question:submit', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED] = 'question:answer:completed', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_SHOW] = 'answer:popup:show', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_COMPLETED] = 'answer:popup:completed', _this$_registerBusEve[MESSAGE_TYPES.REPORT_GENERATED] = 'result:report', _this$_registerBusEve[MESSAGE_TYPES.ERROR] = 'error', _this$_registerBusEve[MESSAGE_TYPES.GAME_RANK] = 'game:rank', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_PREV] = 'question:prev', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_NEXT] = 'question:next', _this$_registerBusEve[MESSAGE_TYPES.AUDIO_VOLUME_CHANGE] = 'volume:change', _this$_registerBusEve[MESSAGE_TYPES.EXTENSION_EVENT] = 'extension:event', _this$_registerBusEve[MESSAGE_TYPES.HEARTBEAT_PONG] = 'heartbeat:pong', _this$_registerBusEve));
1328
+ this._registerBusEventMap((_this$_registerBusEve = {}, _this$_registerBusEve[MESSAGE_TYPES.GAME_LOAD] = 'game:load', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADED] = 'game:loaded', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADING] = 'game:loading', _this$_registerBusEve[MESSAGE_TYPES.CONFIG_UPDATE] = 'config:update', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_START] = 'answer:start', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT] = 'question:submit', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED] = 'question:answer:completed', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_SHOW] = 'answer:popup:show', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_COMPLETED] = 'answer:popup:completed', _this$_registerBusEve[MESSAGE_TYPES.REPORT_GENERATED] = 'result:report', _this$_registerBusEve[MESSAGE_TYPES.ERROR] = 'error', _this$_registerBusEve[MESSAGE_TYPES.GAME_RANK] = 'game:rank', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_PREV] = 'question:prev', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_NEXT] = 'question:next', _this$_registerBusEve[MESSAGE_TYPES.AUDIO_VOLUME_CHANGE] = 'volume:change', _this$_registerBusEve[MESSAGE_TYPES.EXTENSION_EVENT] = 'extension:event', _this$_registerBusEve[MESSAGE_TYPES.HEARTBEAT_PONG] = 'heartbeat:pong', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT_RESULT] = 'question:submit:result', _this$_registerBusEve));
1329
1329
 
1330
1330
  /**
1331
1331
  * SDK 已准备完成
@@ -1866,6 +1866,8 @@ GameManager.prototype.buildThemeUrl = function (themeRoot, themeKey) {
1866
1866
  //开始答题
1867
1867
  ['submitQuestion', MESSAGE_TYPES.QUESTION_SUBMIT],
1868
1868
  //提交题目
1869
+ ['questionSubmitResult', MESSAGE_TYPES.QUESTION_SUBMIT_RESULT],
1870
+ // 答题提交结果
1869
1871
  ['completeQuestionAnswer', MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED],
1870
1872
  //答题完成
1871
1873
  ['showAnswerPopup', MESSAGE_TYPES.ANSWER_POPUP_SHOW],
@@ -1,4 +1,4 @@
1
- var SDK_VERSION = '1.0.3';
1
+ var SDK_VERSION = '1.0.4';
2
2
 
3
3
  var _MESSAGE_TYPES;
4
4
  /**
@@ -53,7 +53,7 @@ var MESSAGE_TYPES = (_MESSAGE_TYPES = {
53
53
  QUESTION_SUBMIT: 'QUESTION_SUBMIT',
54
54
  //单题提交
55
55
  ANSWER_COMPLETED: 'ANSWER_COMPLETED'
56
- }, _MESSAGE_TYPES["QUESTION_SUBMIT"] = 'QUESTION_SUBMIT', _MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED = 'QUESTION_ANSWER_COMPLETED', _MESSAGE_TYPES.ANSWER_POPUP_SHOW = 'ANSWER_POPUP_SHOW', _MESSAGE_TYPES.ANSWER_POPUP_COMPLETED = 'ANSWER_POPUP_COMPLETED', _MESSAGE_TYPES.AUDIO_VOLUME_CHANGE = 'AUDIO_VOLUME_CHANGE', _MESSAGE_TYPES.PAGE_START_SHOW = 'PAGE_START_SHOW', _MESSAGE_TYPES.PAGE_END_SHOW = 'PAGE_END_SHOW', _MESSAGE_TYPES.EXTENSION_EVENT = 'EXTENSION_EVENT', _MESSAGE_TYPES.ERROR = 'ERROR', _MESSAGE_TYPES);
56
+ }, _MESSAGE_TYPES["QUESTION_SUBMIT"] = 'QUESTION_SUBMIT', _MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED = 'QUESTION_ANSWER_COMPLETED', _MESSAGE_TYPES.QUESTION_SUBMIT_RESULT = 'QUESTION_SUBMIT_RESULT', _MESSAGE_TYPES.ANSWER_POPUP_SHOW = 'ANSWER_POPUP_SHOW', _MESSAGE_TYPES.ANSWER_POPUP_COMPLETED = 'ANSWER_POPUP_COMPLETED', _MESSAGE_TYPES.AUDIO_VOLUME_CHANGE = 'AUDIO_VOLUME_CHANGE', _MESSAGE_TYPES.PAGE_START_SHOW = 'PAGE_START_SHOW', _MESSAGE_TYPES.PAGE_END_SHOW = 'PAGE_END_SHOW', _MESSAGE_TYPES.EXTENSION_EVENT = 'EXTENSION_EVENT', _MESSAGE_TYPES.ERROR = 'ERROR', _MESSAGE_TYPES);
57
57
 
58
58
  function isFunction(fn) {
59
59
  return typeof fn === 'function';
@@ -1321,7 +1321,7 @@ GameManager.prototype._bindBusEvents = function () {
1321
1321
  * 纯转发事件统一注册
1322
1322
  * 这些事件只是把底层消息转成标准事件名
1323
1323
  */
1324
- this._registerBusEventMap((_this$_registerBusEve = {}, _this$_registerBusEve[MESSAGE_TYPES.GAME_LOAD] = 'game:load', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADED] = 'game:loaded', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADING] = 'game:loading', _this$_registerBusEve[MESSAGE_TYPES.CONFIG_UPDATE] = 'config:update', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_START] = 'answer:start', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT] = 'question:submit', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED] = 'question:answer:completed', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_SHOW] = 'answer:popup:show', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_COMPLETED] = 'answer:popup:completed', _this$_registerBusEve[MESSAGE_TYPES.REPORT_GENERATED] = 'result:report', _this$_registerBusEve[MESSAGE_TYPES.ERROR] = 'error', _this$_registerBusEve[MESSAGE_TYPES.GAME_RANK] = 'game:rank', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_PREV] = 'question:prev', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_NEXT] = 'question:next', _this$_registerBusEve[MESSAGE_TYPES.AUDIO_VOLUME_CHANGE] = 'volume:change', _this$_registerBusEve[MESSAGE_TYPES.EXTENSION_EVENT] = 'extension:event', _this$_registerBusEve[MESSAGE_TYPES.HEARTBEAT_PONG] = 'heartbeat:pong', _this$_registerBusEve));
1324
+ this._registerBusEventMap((_this$_registerBusEve = {}, _this$_registerBusEve[MESSAGE_TYPES.GAME_LOAD] = 'game:load', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADED] = 'game:loaded', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADING] = 'game:loading', _this$_registerBusEve[MESSAGE_TYPES.CONFIG_UPDATE] = 'config:update', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_START] = 'answer:start', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT] = 'question:submit', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED] = 'question:answer:completed', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_SHOW] = 'answer:popup:show', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_COMPLETED] = 'answer:popup:completed', _this$_registerBusEve[MESSAGE_TYPES.REPORT_GENERATED] = 'result:report', _this$_registerBusEve[MESSAGE_TYPES.ERROR] = 'error', _this$_registerBusEve[MESSAGE_TYPES.GAME_RANK] = 'game:rank', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_PREV] = 'question:prev', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_NEXT] = 'question:next', _this$_registerBusEve[MESSAGE_TYPES.AUDIO_VOLUME_CHANGE] = 'volume:change', _this$_registerBusEve[MESSAGE_TYPES.EXTENSION_EVENT] = 'extension:event', _this$_registerBusEve[MESSAGE_TYPES.HEARTBEAT_PONG] = 'heartbeat:pong', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT_RESULT] = 'question:submit:result', _this$_registerBusEve));
1325
1325
 
1326
1326
  /**
1327
1327
  * SDK 已准备完成
@@ -1862,6 +1862,8 @@ GameManager.prototype.buildThemeUrl = function (themeRoot, themeKey) {
1862
1862
  //开始答题
1863
1863
  ['submitQuestion', MESSAGE_TYPES.QUESTION_SUBMIT],
1864
1864
  //提交题目
1865
+ ['questionSubmitResult', MESSAGE_TYPES.QUESTION_SUBMIT_RESULT],
1866
+ // 答题提交结果
1865
1867
  ['completeQuestionAnswer', MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED],
1866
1868
  //答题完成
1867
1869
  ['showAnswerPopup', MESSAGE_TYPES.ANSWER_POPUP_SHOW],
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.KadouGameSDK = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- var SDK_VERSION = '1.0.3';
7
+ var SDK_VERSION = '1.0.4';
8
8
 
9
9
  var _MESSAGE_TYPES;
10
10
  /**
@@ -59,7 +59,7 @@
59
59
  QUESTION_SUBMIT: 'QUESTION_SUBMIT',
60
60
  //单题提交
61
61
  ANSWER_COMPLETED: 'ANSWER_COMPLETED'
62
- }, _MESSAGE_TYPES["QUESTION_SUBMIT"] = 'QUESTION_SUBMIT', _MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED = 'QUESTION_ANSWER_COMPLETED', _MESSAGE_TYPES.ANSWER_POPUP_SHOW = 'ANSWER_POPUP_SHOW', _MESSAGE_TYPES.ANSWER_POPUP_COMPLETED = 'ANSWER_POPUP_COMPLETED', _MESSAGE_TYPES.AUDIO_VOLUME_CHANGE = 'AUDIO_VOLUME_CHANGE', _MESSAGE_TYPES.PAGE_START_SHOW = 'PAGE_START_SHOW', _MESSAGE_TYPES.PAGE_END_SHOW = 'PAGE_END_SHOW', _MESSAGE_TYPES.EXTENSION_EVENT = 'EXTENSION_EVENT', _MESSAGE_TYPES.ERROR = 'ERROR', _MESSAGE_TYPES);
62
+ }, _MESSAGE_TYPES["QUESTION_SUBMIT"] = 'QUESTION_SUBMIT', _MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED = 'QUESTION_ANSWER_COMPLETED', _MESSAGE_TYPES.QUESTION_SUBMIT_RESULT = 'QUESTION_SUBMIT_RESULT', _MESSAGE_TYPES.ANSWER_POPUP_SHOW = 'ANSWER_POPUP_SHOW', _MESSAGE_TYPES.ANSWER_POPUP_COMPLETED = 'ANSWER_POPUP_COMPLETED', _MESSAGE_TYPES.AUDIO_VOLUME_CHANGE = 'AUDIO_VOLUME_CHANGE', _MESSAGE_TYPES.PAGE_START_SHOW = 'PAGE_START_SHOW', _MESSAGE_TYPES.PAGE_END_SHOW = 'PAGE_END_SHOW', _MESSAGE_TYPES.EXTENSION_EVENT = 'EXTENSION_EVENT', _MESSAGE_TYPES.ERROR = 'ERROR', _MESSAGE_TYPES);
63
63
 
64
64
  function isFunction(fn) {
65
65
  return typeof fn === 'function';
@@ -1327,7 +1327,7 @@
1327
1327
  * 纯转发事件统一注册
1328
1328
  * 这些事件只是把底层消息转成标准事件名
1329
1329
  */
1330
- this._registerBusEventMap((_this$_registerBusEve = {}, _this$_registerBusEve[MESSAGE_TYPES.GAME_LOAD] = 'game:load', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADED] = 'game:loaded', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADING] = 'game:loading', _this$_registerBusEve[MESSAGE_TYPES.CONFIG_UPDATE] = 'config:update', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_START] = 'answer:start', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT] = 'question:submit', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED] = 'question:answer:completed', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_SHOW] = 'answer:popup:show', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_COMPLETED] = 'answer:popup:completed', _this$_registerBusEve[MESSAGE_TYPES.REPORT_GENERATED] = 'result:report', _this$_registerBusEve[MESSAGE_TYPES.ERROR] = 'error', _this$_registerBusEve[MESSAGE_TYPES.GAME_RANK] = 'game:rank', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_PREV] = 'question:prev', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_NEXT] = 'question:next', _this$_registerBusEve[MESSAGE_TYPES.AUDIO_VOLUME_CHANGE] = 'volume:change', _this$_registerBusEve[MESSAGE_TYPES.EXTENSION_EVENT] = 'extension:event', _this$_registerBusEve[MESSAGE_TYPES.HEARTBEAT_PONG] = 'heartbeat:pong', _this$_registerBusEve));
1330
+ this._registerBusEventMap((_this$_registerBusEve = {}, _this$_registerBusEve[MESSAGE_TYPES.GAME_LOAD] = 'game:load', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADED] = 'game:loaded', _this$_registerBusEve[MESSAGE_TYPES.GAME_LOADING] = 'game:loading', _this$_registerBusEve[MESSAGE_TYPES.CONFIG_UPDATE] = 'config:update', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_START] = 'answer:start', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT] = 'question:submit', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED] = 'question:answer:completed', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_SHOW] = 'answer:popup:show', _this$_registerBusEve[MESSAGE_TYPES.ANSWER_POPUP_COMPLETED] = 'answer:popup:completed', _this$_registerBusEve[MESSAGE_TYPES.REPORT_GENERATED] = 'result:report', _this$_registerBusEve[MESSAGE_TYPES.ERROR] = 'error', _this$_registerBusEve[MESSAGE_TYPES.GAME_RANK] = 'game:rank', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_PREV] = 'question:prev', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_NEXT] = 'question:next', _this$_registerBusEve[MESSAGE_TYPES.AUDIO_VOLUME_CHANGE] = 'volume:change', _this$_registerBusEve[MESSAGE_TYPES.EXTENSION_EVENT] = 'extension:event', _this$_registerBusEve[MESSAGE_TYPES.HEARTBEAT_PONG] = 'heartbeat:pong', _this$_registerBusEve[MESSAGE_TYPES.QUESTION_SUBMIT_RESULT] = 'question:submit:result', _this$_registerBusEve));
1331
1331
 
1332
1332
  /**
1333
1333
  * SDK 已准备完成
@@ -1868,6 +1868,8 @@
1868
1868
  //开始答题
1869
1869
  ['submitQuestion', MESSAGE_TYPES.QUESTION_SUBMIT],
1870
1870
  //提交题目
1871
+ ['questionSubmitResult', MESSAGE_TYPES.QUESTION_SUBMIT_RESULT],
1872
+ // 答题提交结果
1871
1873
  ['completeQuestionAnswer', MESSAGE_TYPES.QUESTION_ANSWER_COMPLETED],
1872
1874
  //答题完成
1873
1875
  ['showAnswerPopup', MESSAGE_TYPES.ANSWER_POPUP_SHOW],
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).KadouGameSDK={})}(this,function(t){"use strict";var e,n="1.0.3",o=((e={SDK_READY:"SDK_READY",HEARTBEAT_PING:"HEARTBEAT_PING",HEARTBEAT_PONG:"HEARTBEAT_PONG",ERROR_THROWN:"ERROR_THROWN",GAME_LOAD:"GAME_LOAD",GAME_START:"GAME_START",GAME_PAUSE:"GAME_PAUSE",GAME_RESUME:"GAME_RESUME",GAME_RESTART:"GAME_RESTART",GAME_DESTROY:"GAME_DESTROY",GAME_READY:"GAME_READY",GAME_LOADED:"GAME_LOADED",GAME_LOADING:"GAME_LOADING",GAME_FINISH:"GAME_FINISH",GAME_RANK:"GAME_RANK",THEME_UPDATE:"THEME_UPDATE",CONFIG_UPDATE:"CONFIG_UPDATE",QUESTION_PREV:"QUESTION_PREV",QUESTION_NEXT:"QUESTION_NEXT",ANSWER_START:"ANSWER_START",QUESTION_SUBMIT:"QUESTION_SUBMIT",ANSWER_COMPLETED:"ANSWER_COMPLETED"}).QUESTION_SUBMIT="QUESTION_SUBMIT",e.QUESTION_ANSWER_COMPLETED="QUESTION_ANSWER_COMPLETED",e.ANSWER_POPUP_SHOW="ANSWER_POPUP_SHOW",e.ANSWER_POPUP_COMPLETED="ANSWER_POPUP_COMPLETED",e.AUDIO_VOLUME_CHANGE="AUDIO_VOLUME_CHANGE",e.PAGE_START_SHOW="PAGE_START_SHOW",e.PAGE_END_SHOW="PAGE_END_SHOW",e.EXTENSION_EVENT="EXTENSION_EVENT",e.ERROR="ERROR",e);function i(t){return"function"==typeof t}function r(t){return"[object Object]"===Object.prototype.toString.call(t)}function s(){this.events={}}s.prototype.on=function(t,e){return t&&i(e)?(this.events[t]||(this.events[t]=[]),this.events[t].push(e),this):this},s.prototype.once=function(t,e){var n=this;if(!t||!i(e))return this;function o(){n.off(t,o),e.apply(null,arguments)}return o.__original__=e,this.on(t,o),this},s.prototype.off=function(t,e){var n,o,i,r;if(!t)return this.events={},this;if(!(n=this.events[t])||!n.length)return this;if(!e)return delete this.events[t],this;for(o=[],i=0;i<n.length;i++)(r=n[i])!==e&&r.__original__!==e&&o.push(r);return o.length?this.events[t]=o:delete this.events[t],this},s.prototype.emit=function(t){var e,n,o=this.events[t];if(!o||!o.length)return this;for(e=Array.prototype.slice.call(arguments,1),o=o.slice(),n=0;n<o.length;n++)try{o[n].apply(null,e)}catch(e){"undefined"!=typeof console&&console.error&&console.error('[EventEmitter] "'+t+'" handler error:',e)}return this};function a(t){t=t||{},this.selfWindow=t.selfWindow||window,this.targetWindow=t.targetWindow||null,this.targetOrigin=t.targetOrigin||"*",this.source=t.source||"KADOU_GAME_SDK",this.debug=!!t.debug}function d(t){t=t||{},s.call(this),this.channel=new a(t),this.selfWindow=t.selfWindow||window,this.allowedOrigins=t.allowedOrigins||["*"],this.debug=!!t.debug,this._boundOnMessage=this._onMessage.bind(this),this._listening=!1}function h(t){return"[object Object]"===Object.prototype.toString.call(t)}function u(t,e){var n,o={};for(n in t=h(t)?t:{},e=h(e)?e:{},t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n]);for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(o[n]=e[n]);return o}function p(t,e){return null==e?"":"backgroundImage"===t&&e&&"string"==typeof e&&0!==e.indexOf("url(")&&"none"!==e?'url("'+e+'")':String(e)}function l(){this.el=null,this.stageEl=null,this.container=null,this.pageData=null,this.events=[],this._onResize=null}function c(t,e,n,o){var i=document.createElement(t);return e&&(i.className=e),n&&function(t,e){var n;if(t&&e)for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t.style[n]=p(n,e[n]))}(i,n),null!=o&&(i.textContent=String(o)),i}function g(){l.call(this)}function f(){l.call(this)}function E(t){t=t||{},this.container=t.container||document.body,this.startPage=null,this.endPage=null}a.prototype.setTargetWindow=function(t){return this.targetWindow=t,this},a.prototype.setTargetOrigin=function(t){return this.targetOrigin=t||"*",this},a.prototype.createMessage=function(t,e,o){return e=e||{},o=o||{},{source:this.source,version:n,type:t,requestId:(i=i||"msg")+"_"+(new Date).getTime()+"_"+Math.random().toString(16).slice(2,10),timestamp:(new Date).getTime(),payload:r(e)?e:{value:e},meta:r(o)?o:{}};var i},a.prototype.send=function(t,e,n){var o;return this.targetWindow&&this.targetWindow.postMessage?(o=this.createMessage(t,e,n),this.targetWindow.postMessage(o,this.targetOrigin),this.debug&&"undefined"!=typeof console&&console.log&&console.log("[PostMessageChannel] send =>",o),o):(this.debug&&"undefined"!=typeof console&&console.warn&&console.warn("[PostMessageChannel] targetWindow 不存在,消息发送失败:",t),null)},a.prototype.isValidMessage=function(t){return!(!t||"object"!=typeof t||t.source!==this.source||"string"!=typeof t.type)},d.prototype=Object.create(s.prototype),d.prototype.constructor=d,d.prototype.start=function(){return this._listening||(this.selfWindow.addEventListener("message",this._boundOnMessage,!1),this._listening=!0,this.debug&&"undefined"!=typeof console&&console.log&&console.log("[MessageBus] started")),this},d.prototype.stop=function(){return this._listening?(this.selfWindow.removeEventListener("message",this._boundOnMessage,!1),this._listening=!1,this.debug&&"undefined"!=typeof console&&console.log&&console.log("[MessageBus] stopped"),this):this},d.prototype.destroy=function(){return this.stop(),this.off(),this},d.prototype.setTargetWindow=function(t){return this.channel.setTargetWindow(t),this},d.prototype.setTargetOrigin=function(t){return this.channel.setTargetOrigin(t),this},d.prototype.send=function(t,e,n){return this.channel.send(t,e,n)},d.prototype._matchOrigin=function(t){var e;if(!this.allowedOrigins||!this.allowedOrigins.length)return!0;if("*"===this.allowedOrigins[0]||this.allowedOrigins.indexOf("*")>-1)return!0;for(e=0;e<this.allowedOrigins.length;e++)if(this.allowedOrigins[e]===t)return!0;return!1},d.prototype._onMessage=function(t){var e,n=t.data,o=t.origin,i=t.source;this._matchOrigin(o)?this.channel.isValidMessage(n)&&(this.debug&&"undefined"!=typeof console&&console.log&&console.log("[MessageBus] receive <=",n),e={rawEvent:t,origin:o,sourceWindow:i},this.emit("*",n,e),this.emit(n.type,n.payload,n,e)):this.debug&&"undefined"!=typeof console&&console.warn&&console.warn("[MessageBus] origin 不匹配,已忽略:",o)},l.prototype.destroy=function(){var t;if(this.unbindResize(),this.events&&this.events.length)for(t=0;t<this.events.length;t++){var e=this.events[t];e&&e.el&&e.type&&e.handler&&e.el.removeEventListener(e.type,e.handler)}this.events=[],this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null},l.prototype.bindEvent=function(t,e,n){t&&e&&n&&(t.addEventListener(e,n),this.events.push({el:t,type:e,handler:n}))},l.prototype.getDesignSize=function(t){return{designWidth:(t=t||{}).designWidth||1920,designHeight:t.designHeight||1080}},l.prototype.getScaleRatio=function(t){return"number"==typeof(t=t||{}).scaleRatio?t.scaleRatio:1},l.prototype.getWrapperCss=function(t){return u({position:"absolute",width:"100%",height:"100%",overflow:"hidden",top:"0",left:"0",right:"0",bottom:"0",display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",zIndex:"99999",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover"},(t=t||{}).wrapper)},l.prototype.getAutoScaleRatio=function(t,e){if(!t)return 1;var n=this.getDesignSize(e),o=t.clientWidth||0,i=t.clientHeight||0;return o&&i?Math.min(o/n.designWidth,i/n.designHeight):1},l.prototype.getStageCss=function(t,e){e=e||{};var n=this.getDesignSize(e),o=this.getAutoScaleRatio(t,e);return u({flex:"none",position:"relative",width:n.designWidth+"px",height:n.designHeight+"px",transform:"scale("+o+")",transformOrigin:"center center",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",boxSizing:"border-box",padding:"40px",color:"#ffffff",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",textAlign:"center"},e.stage)},l.prototype.setPageContext=function(t,e,n){this.container=t||null,this.pageData=e||{},this.stageEl=n||null},l.prototype.updateScale=function(){if(this.stageEl&&this.container){var t=this.getAutoScaleRatio(this.container,this.pageData);this.stageEl.style.transform="scale("+t+")"}},l.prototype.bindResize=function(){var t=this;this.unbindResize(),this._onResize=function(){t.updateScale()},window.addEventListener("resize",this._onResize)},l.prototype.unbindResize=function(){this._onResize&&(window.removeEventListener("resize",this._onResize),this._onResize=null)},g.prototype=Object.create(l.prototype),g.prototype.constructor=g,g.prototype.getStyles=function(t,e){e=e||{};var n=this.getWrapperCss(e),o=this.getStageCss(t,e);return e.disableScale&&(o.transform="none"),{wrapperCss:n,stageCss:o,overlayCss:u({position:"absolute",top:"0",left:"0",right:"0",bottom:"0"},e.overlay),contentCss:u({position:"relative",zIndex:"1",width:"100%",maxHeight:"100%",overflow:"auto",display:"flex",flexDirection:"column",alignItems:"center"},e.content),titleCss:u({fontSize:"85px",fontWeight:"bold",textShadow:"2px 2px 4px #0b1c32",letterSpacing:"5px",lineHeight:"1.3",maxWidth:"90%",wordBreak:"break-word"},e.title),descCss:u({marginTop:"30px",width:"100%",whiteSpace:"pre-wrap",lineHeight:"1.6",wordBreak:"break-word",fontSize:"40px"},e.desc),btnGroupCss:u({width:"100%",maxWidth:"800px",marginTop:"80px",display:"flex",justifyContent:"center",alignItems:"center"},e.buttonGroup),btnCss:u({display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:"240px",minHeight:"88px",padding:"20px 50px",boxSizing:"border-box",cursor:"pointer",fontSize:"40px",fontWeight:"bold",backgroundColor:"#04b6bb",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",borderRadius:"50px",border:"none",color:"#fff",transition:"all 0.2s linear"},e.button)}},g.prototype.render=function(t,e,n){if(e=e||{},!t)throw new Error("[StartPage] render 失败:container 不存在");this.destroy();var o=this.getStyles(t,e),i=e.titleText||"欢迎进入游戏",r="string"==typeof e.descText?e.descText:"",s=e.buttonText||"开始游戏",a=c("div","kadou-start-page",o.wrapperCss),d=c("div","kadou-start-stage",o.stageCss),h=c("div","kadou-start-overlay",o.overlayCss),u=c("div","kadou-start-content",o.contentCss),p=c("div","kadou-start-title",o.titleCss,i);if(d.appendChild(h),u.appendChild(p),r){var l=c("div","kadou-start-desc",o.descCss,r);u.appendChild(l)}var g=c("div","kadou-start-btn-group",o.btnGroupCss),f=c("div","kadou-start-btn",o.btnCss,s);return this.bindEvent(f,"click",function(){"function"==typeof n&&n()}),g.appendChild(f),u.appendChild(g),d.appendChild(u),a.appendChild(d),t.appendChild(a),this.el=a,e.disableScale||(this.setPageContext(t,e,d),this.bindResize(),this.updateScale()),a},f.prototype=Object.create(l.prototype),f.prototype.constructor=f,f.prototype.getStyles=function(t,e){e=e||{};var n=this.getWrapperCss(e),o=this.getStageCss(t,e);return e.disableScale&&(o.transform="none"),{wrapperCss:n,stageCss:o,overlayCss:u({position:"absolute",top:"0",left:"0",right:"0",bottom:"0"},e.overlay),contentCss:u({position:"relative",zIndex:"1",width:"100%",maxHeight:"100%",overflow:"auto",display:"flex",flexDirection:"column",alignItems:"center"},e.content),titleCss:u({fontSize:"72px",fontWeight:"bold",lineHeight:"1.3",maxWidth:"90%",wordBreak:"break-word",textShadow:"2px 2px 4px #0b1c32"},e.title),timeCss:u({marginTop:"28px",fontSize:"40px",wordBreak:"break-word"},e.time),scoreCss:u({marginTop:"28px",fontSize:"40px",wordBreak:"break-word"},e.score),btnGroupCss:u({width:"100%",maxWidth:"900px",marginTop:"70px",display:"flex",justifyContent:"center",alignItems:"center",gap:"24px",flexWrap:"wrap"},e.buttonGroup),primaryBtnCss:u({display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:"240px",minHeight:"88px",padding:"20px 50px",boxSizing:"border-box",cursor:"pointer",fontSize:"40px",fontWeight:"bold",background:"#04b6bb",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",borderRadius:"50px",border:"none",color:"#fff",transition:"all 0.2s linear"},e.primaryButton||e.button),secondaryBtnCss:u({display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:"240px",minHeight:"88px",padding:"20px 50px",boxSizing:"border-box",cursor:"pointer",fontSize:"40px",fontWeight:"bold",background:"#ff6600",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",borderRadius:"50px",border:"none",color:"#fff",transition:"all 0.2s linear"},e.secondaryButton)}},f.prototype.render=function(t,e,n){if(e=e||{},n=n||{},!t)throw new Error("[EndPage] render 失败:container 不存在");this.destroy();var o=this.getStyles(t,e),i=e.titleText||"游戏结束",r="string"==typeof e.timeText?e.timeText:"",s="string"==typeof e.scoreText?e.scoreText:"",a=e.primaryButtonText||e.buttonText||"再来一次",d=e.secondaryButtonText||"",h=c("div","kadou-end-page",o.wrapperCss),u=c("div","kadou-end-stage",o.stageCss),p=c("div","kadou-end-overlay",o.overlayCss),l=c("div","kadou-end-content",o.contentCss),g=c("div","kadou-end-title",o.titleCss,i);if(u.appendChild(p),l.appendChild(g),s){var f=c("div","kadou-end-score",o.scoreCss,s);l.appendChild(f)}if(r){var E=c("div","kadou-end-time",o.timeCss,r);l.appendChild(E)}var y=c("div","kadou-end-btn-group",o.btnGroupCss);if(d){var _=c("div","kadou-end-secondary-btn",o.secondaryBtnCss,d);this.bindEvent(_,"click",function(){"function"==typeof n.onShowRank?n.onShowRank():"function"==typeof n.onClose&&n.onClose()}),y.appendChild(_)}var S=c("div","kadou-end-primary-btn",o.primaryBtnCss,a);return this.bindEvent(S,"click",function(){"function"==typeof n.onRestart&&n.onRestart()}),y.appendChild(S),y.childNodes.length>0&&l.appendChild(y),u.appendChild(l),h.appendChild(u),t.appendChild(h),this.el=h,e.disableScale||(this.setPageContext(t,e,u),this.bindResize(),this.updateScale()),h},E.prototype.setContainer=function(t){return t&&(this.container=t),this},E.prototype.showStartPage=function(t,e){var n=this,o=e||{};if(!this.container)throw new Error("[OverlayManager] showStartPage 失败:container 不存在");return this.hideStartPage(),this.startPage=new g,this.startPage.render(this.container,t||{},function(){"function"==typeof o.onStart&&o.onStart(),n.hideStartPage()}),n},E.prototype.hideStartPage=function(){return this.startPage&&(this.startPage.destroy(),this.startPage=null),this},E.prototype.showEndPage=function(t,e){var n=this,o=e||{};if(!this.container)throw new Error("[OverlayManager] showEndPage 失败:container 不存在");return this.hideEndPage(),this.endPage=new f,this.endPage.render(this.container,t||{},{onRestart:function(){"function"==typeof o.onRestart&&(o.onRestart(),n.hideEndPage())},onShowRank:function(){"function"==typeof o.onShowRank&&o.onShowRank()}}),n},E.prototype.hideEndPage=function(){return this.endPage&&(this.endPage.destroy(),this.endPage=null),this},E.prototype.hideAll=function(){return this.hideStartPage(),this.hideEndPage(),this},E.prototype.destroy=function(){this.hideAll(),this.container=null};var y={};function _(t){return y[t]||y.default||null}function S(t,e){return e?/^(https?:)?\/\//.test(n=e)||/^file:/.test(n)||/^data:/.test(n)||/^blob:/.test(n)?e:t+e.replace(/^\.\//,""):"";var n}function m(t,e){var n,o;if(!t)return t;for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&"string"==typeof(o=t[n])&&("backgroundImage"!==n&&"src"!==n?"background"===n&&(t[n]=o.replace(/url\((['"]?)(.+?)\1\)/g,function(t,n,o){return'url("'+S(e,o)+'")'})):t[n]=S(e,o));return t}function v(t,e){var n,o,i,r;if(!t)return t;for(n=t.startPage||{},o=t.endPage||{},i=["wrapper","overlay","content","title","desc","buttonGroup","button","primaryButton","secondaryButton","score"],r=0;r<i.length;r++)m(n[i[r]],e),m(o[i[r]],e);return function(t,e){var n,o,i,r;if(!t)return t;for(n=["bg","frame","actionBtn","logo","icon"],o=0;o<n.length;o++)"string"==typeof(r=t[i=n[o]])&&r&&(t[i]=S(e,r))}(t.host,e),t}function T(t,e){window.__KADOU_THEME_PACK__=null,function(t,e){var n=document.createElement("script"),o=!1;n.type="text/javascript",n.async=!0,n.src=t,n.onload=function(){o||(o=!0,e&&e(null,n))},n.onerror=function(){o||(o=!0,e&&e(new Error("Failed to load script: "+t)))},document.head.appendChild(n)}(t,function(n){var o,i,r;n?e&&e(n):(o=window.__KADOU_THEME_PACK__)&&o.key&&o.theme?(i=function(t){return t?t.replace(/\/[^\/]*$/,"/"):""}(t),r=v(o.theme,i),function(t,e){if(!t)throw new Error("Theme key is required");y[t]=e||{}}(o.key,r),e&&e(null,{key:o.key,url:t,from:"remote",theme:r})):e&&e(new Error("Invalid theme pack: "+t))})}function A(t,e){if(!t)throw new Error("themeRoot is required");if(!e)throw new Error("themeKey is required");return t.replace(/\/?$/,"/")+e+"/theme.js"}function b(t,e,n){if(y[t])n&&n(null,{key:t,from:"cache",theme:_(t)});else{var o;try{o=A(e,t)}catch(t){return void(n&&n(t))}T(o,n)}}function O(t){t=t||{},s.call(this),this.options=t,this.root=t.root||document.body,this.debug=!!t.debug,this.role=t.role||"host",this.state={sdkReady:!1,gameReady:!1,started:!1,paused:!1,destroyed:!1},this.currentThemeKey="",this.currentTheme=null,this.bus=new d({selfWindow:t.selfWindow||window,targetWindow:t.targetWindow||null,targetOrigin:t.targetOrigin||"*",allowedOrigins:t.allowedOrigins||["*"],source:t.source||"KADOU_GAME_SDK",debug:this.debug}),this.overlay="game"===this.role?new E({container:this.root}):null,this._bindBusEvents()}O.prototype=Object.create(s.prototype),O.prototype.constructor=O,O.prototype._log=function(){this.debug&&"undefined"!=typeof console&&console.log&&console.log.apply(console,arguments)},O.prototype._callIfFn=function(t){if("function"==typeof t)return t.apply(this,Array.prototype.slice.call(arguments,1))},O.prototype._setState=function(t){var e;for(e in t=t||{})Object.prototype.hasOwnProperty.call(t,e)&&(this.state[e]=t[e])},O.prototype._emitLocal=function(t,e){this.emit(t,e||{},null,{local:!0})},O.prototype._registerBusEvent=function(t,e,n){var o=this;this.bus.on(t,function(t,i,r){n&&n.call(o,t,i,r),e&&o.emit(e,t,i,r)})},O.prototype._registerBusEventMap=function(t){var e=this;Object.keys(t).forEach(function(n){e._registerBusEvent(n,t[n])})},O.prototype._createSendMethod=function(t,e){O.prototype[t]=function(t){return this.send(e,t||{})}},O.prototype._bindBusEvents=function(){var t,e=this;this.bus.on("*",function(t,n){e.emit("message",t,n)}),this._registerBusEventMap(((t={})[o.GAME_LOAD]="game:load",t[o.GAME_LOADED]="game:loaded",t[o.GAME_LOADING]="game:loading",t[o.CONFIG_UPDATE]="config:update",t[o.ANSWER_START]="answer:start",t[o.QUESTION_SUBMIT]="question:submit",t[o.QUESTION_ANSWER_COMPLETED]="question:answer:completed",t[o.ANSWER_POPUP_SHOW]="answer:popup:show",t[o.ANSWER_POPUP_COMPLETED]="answer:popup:completed",t[o.REPORT_GENERATED]="result:report",t[o.ERROR]="error",t[o.GAME_RANK]="game:rank",t[o.QUESTION_PREV]="question:prev",t[o.QUESTION_NEXT]="question:next",t[o.AUDIO_VOLUME_CHANGE]="volume:change",t[o.EXTENSION_EVENT]="extension:event",t[o.HEARTBEAT_PONG]="heartbeat:pong",t)),this._registerBusEvent(o.SDK_READY,"sdk:ready",function(){this._setState({sdkReady:!0})}),this._registerBusEvent(o.GAME_READY,"game:ready",function(){this._setState({gameReady:!0})}),this._registerBusEvent(o.GAME_START,"game:start",function(){this._setState({started:!0,paused:!1}),"game"===this.role&&this.overlay&&this.hideStartPage()}),this._registerBusEvent(o.GAME_RESTART,"game:restart",function(){this._setState({started:!0,paused:!1}),"game"===this.role&&this.overlay&&this.hideEndPage()}),this._registerBusEvent(o.GAME_PAUSE,"game:pause",function(){this._setState({paused:!0})}),this._registerBusEvent(o.GAME_RESUME,"game:resume",function(){this._setState({paused:!1})}),this._registerBusEvent(o.GAME_FINISH,"game:finish",function(){this._setState({started:!1})}),this._registerBusEvent(o.GAME_DESTROY,"game:destroy",function(){this._setState({destroyed:!0})}),this._registerBusEvent(o.THEME_UPDATE,"theme:update",function(t){this.currentThemeKey=t&&t.themeKey?t.themeKey:"",this.currentTheme=t&&t.theme?t.theme:t||null}),this._registerBusEvent(o.PAGE_START_SHOW,"page:start:show",function(t){"game"===this.role&&this.renderStartPage(t)}),this._registerBusEvent(o.PAGE_END_SHOW,"page:end:show",function(t){"game"===this.role&&this.renderEndPage(t)}),this._registerBusEvent(o.HEARTBEAT_PING,"heartbeat:ping",function(t,e){this.send(o.HEARTBEAT_PONG,{replyTo:e&&e.requestId,time:(new Date).getTime()})})},O.prototype.init=function(){return this.bus.start(),this._log("[GameManager] init, role =",this.role),this},O.prototype.destroy=function(){return this._setState({destroyed:!0}),this.bus.destroy(),this.overlay&&(this._callIfFn(this.overlay.hideStartPage),this._callIfFn(this.overlay.hideEndPage)),this.off(),this._log("[GameManager] destroyed"),this},O.prototype.setTargetWindow=function(t){return this.bus.setTargetWindow(t),this},O.prototype.setTargetOrigin=function(t){return this.bus.setTargetOrigin(t),this},O.prototype.setRoot=function(t){return t?(this.root=t,this.overlay&&(this.overlay.container=t),this):this},O.prototype.send=function(t,e,n){return this.bus.send(t,e,n)},O.prototype.notifySdkReady=function(t){return this._setState({sdkReady:!0}),this.send(o.SDK_READY,t||{})},O.prototype.heartbeatPing=function(t){var e=t||{};return e.time=(new Date).getTime(),this.send(o.HEARTBEAT_PING,e)},O.prototype.gameReady=function(t){return this._setState({gameReady:!0}),this.send(o.GAME_READY,t||{})},O.prototype.startGame=function(t){var e=t||{};return this._setState({started:!0,paused:!1}),this._emitLocal("game:start",e),this.send(o.GAME_START,e)},O.prototype.restartGame=function(t){var e=t||{};return this._setState({started:!0,paused:!1}),this._emitLocal("game:restart",e),this.send(o.GAME_RESTART,e)},O.prototype.pauseGame=function(t){return this._setState({paused:!0}),this.send(o.GAME_PAUSE,t||{})},O.prototype.resumeGame=function(t){return this._setState({paused:!1}),this.send(o.GAME_RESUME,t||{})},O.prototype.finishGame=function(t){return this._setState({started:!1}),this.send(o.GAME_FINISH,t||{})},O.prototype.destroyGame=function(t){return this._setState({destroyed:!0}),this.send(o.GAME_DESTROY,t||{})},O.prototype.updateTheme=function(t){return"game"===this.role&&(this.currentTheme=t||null),this.send(o.THEME_UPDATE,t||{})},O.prototype.applyTheme=function(t,e,n){var i=n||{};return i.themeKey=t||"",i.theme=e||{},"game"===this.role&&(this.currentThemeKey=i.themeKey,this.currentTheme=i.theme),this.send(o.THEME_UPDATE,i)},O.prototype.reportError=function(t){var e;return e=t instanceof Error?{message:t.message,stack:t.stack}:t||{},this.send(o.ERROR,e)},O.prototype.getState=function(){return{sdkReady:this.state.sdkReady,gameReady:this.state.gameReady,started:this.state.started,paused:this.state.paused,destroyed:this.state.destroyed}},O.prototype.isReady=function(){return!(!this.state.sdkReady||!this.state.gameReady)},O.prototype._mergePageTheme=function(t,e){var n,o=(this.currentTheme||{})[t]||{},i={};for(n in e=e||{},o)Object.prototype.hasOwnProperty.call(o,n)&&(i[n]=o[n]);for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);return i},O.prototype.renderStartPage=function(t,e){var n=this,o=this._mergePageTheme("startPage",t||{});return this.overlay&&this.overlay.showStartPage?(this.overlay.showStartPage(o,e||{onStart:function(){n.startGame({from:"sdk-start-game"})}}),this):this},O.prototype.hideStartPage=function(){return this.overlay&&this.overlay.hideStartPage&&this.overlay.hideStartPage(),this},O.prototype.renderEndPage=function(t,e){var n=this,o=this._mergePageTheme("endPage",t||{});return this.overlay&&this.overlay.showEndPage?(this.overlay.showEndPage(o,e||{onRestart:function(){n.restartGame({from:"sdk-restart-game"})},onShowRank:function(){n.showGameRank({from:"sdk-game-rank"})}}),this):this},O.prototype.hideEndPage=function(){return this.overlay&&this.overlay.hideEndPage&&this.overlay.hideEndPage(),this},O.prototype.loadThemeByUrl=function(t,e){return T(t,e),this},O.prototype.ensureTheme=function(t,e,n){return b(t,e,n),this},O.prototype.buildThemeUrl=function(t,e){return A(t,e)},[["loadGame",o.GAME_LOAD],["gameLoading",o.GAME_LOADING],["gameLoaded",o.GAME_LOADED],["showGameRank",o.GAME_RANK],["updateConfig",o.CONFIG_UPDATE],["showStartPage",o.PAGE_START_SHOW],["showEndPage",o.PAGE_END_SHOW],["startAnswer",o.ANSWER_START],["submitQuestion",o.QUESTION_SUBMIT],["completeQuestionAnswer",o.QUESTION_ANSWER_COMPLETED],["showAnswerPopup",o.ANSWER_POPUP_SHOW],["completeAnswerPopup",o.ANSWER_POPUP_COMPLETED],["prevQuestion",o.QUESTION_PREV],["nextQuestion",o.QUESTION_NEXT],["changeVolume",o.AUDIO_VOLUME_CHANGE],["extensionEvent",o.EXTENSION_EVENT]].forEach(function(t){O.prototype._createSendMethod(t[0],t[1])});var R={SDK_VERSION:n,MESSAGE_TYPES:o,EventEmitter:s,MessageBus:d,GameRuntime:O};t.EventEmitter=s,t.GameRuntime=O,t.MESSAGE_TYPES=o,t.MessageBus=d,t.SDK_VERSION=n,t.default=R,Object.defineProperty(t,"__esModule",{value:!0})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).KadouGameSDK={})}(this,function(t){"use strict";var e,n="1.0.4",o=((e={SDK_READY:"SDK_READY",HEARTBEAT_PING:"HEARTBEAT_PING",HEARTBEAT_PONG:"HEARTBEAT_PONG",ERROR_THROWN:"ERROR_THROWN",GAME_LOAD:"GAME_LOAD",GAME_START:"GAME_START",GAME_PAUSE:"GAME_PAUSE",GAME_RESUME:"GAME_RESUME",GAME_RESTART:"GAME_RESTART",GAME_DESTROY:"GAME_DESTROY",GAME_READY:"GAME_READY",GAME_LOADED:"GAME_LOADED",GAME_LOADING:"GAME_LOADING",GAME_FINISH:"GAME_FINISH",GAME_RANK:"GAME_RANK",THEME_UPDATE:"THEME_UPDATE",CONFIG_UPDATE:"CONFIG_UPDATE",QUESTION_PREV:"QUESTION_PREV",QUESTION_NEXT:"QUESTION_NEXT",ANSWER_START:"ANSWER_START",QUESTION_SUBMIT:"QUESTION_SUBMIT",ANSWER_COMPLETED:"ANSWER_COMPLETED"}).QUESTION_SUBMIT="QUESTION_SUBMIT",e.QUESTION_ANSWER_COMPLETED="QUESTION_ANSWER_COMPLETED",e.QUESTION_SUBMIT_RESULT="QUESTION_SUBMIT_RESULT",e.ANSWER_POPUP_SHOW="ANSWER_POPUP_SHOW",e.ANSWER_POPUP_COMPLETED="ANSWER_POPUP_COMPLETED",e.AUDIO_VOLUME_CHANGE="AUDIO_VOLUME_CHANGE",e.PAGE_START_SHOW="PAGE_START_SHOW",e.PAGE_END_SHOW="PAGE_END_SHOW",e.EXTENSION_EVENT="EXTENSION_EVENT",e.ERROR="ERROR",e);function i(t){return"function"==typeof t}function r(t){return"[object Object]"===Object.prototype.toString.call(t)}function s(){this.events={}}s.prototype.on=function(t,e){return t&&i(e)?(this.events[t]||(this.events[t]=[]),this.events[t].push(e),this):this},s.prototype.once=function(t,e){var n=this;if(!t||!i(e))return this;function o(){n.off(t,o),e.apply(null,arguments)}return o.__original__=e,this.on(t,o),this},s.prototype.off=function(t,e){var n,o,i,r;if(!t)return this.events={},this;if(!(n=this.events[t])||!n.length)return this;if(!e)return delete this.events[t],this;for(o=[],i=0;i<n.length;i++)(r=n[i])!==e&&r.__original__!==e&&o.push(r);return o.length?this.events[t]=o:delete this.events[t],this},s.prototype.emit=function(t){var e,n,o=this.events[t];if(!o||!o.length)return this;for(e=Array.prototype.slice.call(arguments,1),o=o.slice(),n=0;n<o.length;n++)try{o[n].apply(null,e)}catch(e){"undefined"!=typeof console&&console.error&&console.error('[EventEmitter] "'+t+'" handler error:',e)}return this};function a(t){t=t||{},this.selfWindow=t.selfWindow||window,this.targetWindow=t.targetWindow||null,this.targetOrigin=t.targetOrigin||"*",this.source=t.source||"KADOU_GAME_SDK",this.debug=!!t.debug}function d(t){t=t||{},s.call(this),this.channel=new a(t),this.selfWindow=t.selfWindow||window,this.allowedOrigins=t.allowedOrigins||["*"],this.debug=!!t.debug,this._boundOnMessage=this._onMessage.bind(this),this._listening=!1}function h(t){return"[object Object]"===Object.prototype.toString.call(t)}function u(t,e){var n,o={};for(n in t=h(t)?t:{},e=h(e)?e:{},t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n]);for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(o[n]=e[n]);return o}function p(t,e){return null==e?"":"backgroundImage"===t&&e&&"string"==typeof e&&0!==e.indexOf("url(")&&"none"!==e?'url("'+e+'")':String(e)}function l(){this.el=null,this.stageEl=null,this.container=null,this.pageData=null,this.events=[],this._onResize=null}function c(t,e,n,o){var i=document.createElement(t);return e&&(i.className=e),n&&function(t,e){var n;if(t&&e)for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t.style[n]=p(n,e[n]))}(i,n),null!=o&&(i.textContent=String(o)),i}function g(){l.call(this)}function f(){l.call(this)}function E(t){t=t||{},this.container=t.container||document.body,this.startPage=null,this.endPage=null}a.prototype.setTargetWindow=function(t){return this.targetWindow=t,this},a.prototype.setTargetOrigin=function(t){return this.targetOrigin=t||"*",this},a.prototype.createMessage=function(t,e,o){return e=e||{},o=o||{},{source:this.source,version:n,type:t,requestId:(i=i||"msg")+"_"+(new Date).getTime()+"_"+Math.random().toString(16).slice(2,10),timestamp:(new Date).getTime(),payload:r(e)?e:{value:e},meta:r(o)?o:{}};var i},a.prototype.send=function(t,e,n){var o;return this.targetWindow&&this.targetWindow.postMessage?(o=this.createMessage(t,e,n),this.targetWindow.postMessage(o,this.targetOrigin),this.debug&&"undefined"!=typeof console&&console.log&&console.log("[PostMessageChannel] send =>",o),o):(this.debug&&"undefined"!=typeof console&&console.warn&&console.warn("[PostMessageChannel] targetWindow 不存在,消息发送失败:",t),null)},a.prototype.isValidMessage=function(t){return!(!t||"object"!=typeof t||t.source!==this.source||"string"!=typeof t.type)},d.prototype=Object.create(s.prototype),d.prototype.constructor=d,d.prototype.start=function(){return this._listening||(this.selfWindow.addEventListener("message",this._boundOnMessage,!1),this._listening=!0,this.debug&&"undefined"!=typeof console&&console.log&&console.log("[MessageBus] started")),this},d.prototype.stop=function(){return this._listening?(this.selfWindow.removeEventListener("message",this._boundOnMessage,!1),this._listening=!1,this.debug&&"undefined"!=typeof console&&console.log&&console.log("[MessageBus] stopped"),this):this},d.prototype.destroy=function(){return this.stop(),this.off(),this},d.prototype.setTargetWindow=function(t){return this.channel.setTargetWindow(t),this},d.prototype.setTargetOrigin=function(t){return this.channel.setTargetOrigin(t),this},d.prototype.send=function(t,e,n){return this.channel.send(t,e,n)},d.prototype._matchOrigin=function(t){var e;if(!this.allowedOrigins||!this.allowedOrigins.length)return!0;if("*"===this.allowedOrigins[0]||this.allowedOrigins.indexOf("*")>-1)return!0;for(e=0;e<this.allowedOrigins.length;e++)if(this.allowedOrigins[e]===t)return!0;return!1},d.prototype._onMessage=function(t){var e,n=t.data,o=t.origin,i=t.source;this._matchOrigin(o)?this.channel.isValidMessage(n)&&(this.debug&&"undefined"!=typeof console&&console.log&&console.log("[MessageBus] receive <=",n),e={rawEvent:t,origin:o,sourceWindow:i},this.emit("*",n,e),this.emit(n.type,n.payload,n,e)):this.debug&&"undefined"!=typeof console&&console.warn&&console.warn("[MessageBus] origin 不匹配,已忽略:",o)},l.prototype.destroy=function(){var t;if(this.unbindResize(),this.events&&this.events.length)for(t=0;t<this.events.length;t++){var e=this.events[t];e&&e.el&&e.type&&e.handler&&e.el.removeEventListener(e.type,e.handler)}this.events=[],this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=null},l.prototype.bindEvent=function(t,e,n){t&&e&&n&&(t.addEventListener(e,n),this.events.push({el:t,type:e,handler:n}))},l.prototype.getDesignSize=function(t){return{designWidth:(t=t||{}).designWidth||1920,designHeight:t.designHeight||1080}},l.prototype.getScaleRatio=function(t){return"number"==typeof(t=t||{}).scaleRatio?t.scaleRatio:1},l.prototype.getWrapperCss=function(t){return u({position:"absolute",width:"100%",height:"100%",overflow:"hidden",top:"0",left:"0",right:"0",bottom:"0",display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",zIndex:"99999",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover"},(t=t||{}).wrapper)},l.prototype.getAutoScaleRatio=function(t,e){if(!t)return 1;var n=this.getDesignSize(e),o=t.clientWidth||0,i=t.clientHeight||0;return o&&i?Math.min(o/n.designWidth,i/n.designHeight):1},l.prototype.getStageCss=function(t,e){e=e||{};var n=this.getDesignSize(e),o=this.getAutoScaleRatio(t,e);return u({flex:"none",position:"relative",width:n.designWidth+"px",height:n.designHeight+"px",transform:"scale("+o+")",transformOrigin:"center center",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",boxSizing:"border-box",padding:"40px",color:"#ffffff",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",textAlign:"center"},e.stage)},l.prototype.setPageContext=function(t,e,n){this.container=t||null,this.pageData=e||{},this.stageEl=n||null},l.prototype.updateScale=function(){if(this.stageEl&&this.container){var t=this.getAutoScaleRatio(this.container,this.pageData);this.stageEl.style.transform="scale("+t+")"}},l.prototype.bindResize=function(){var t=this;this.unbindResize(),this._onResize=function(){t.updateScale()},window.addEventListener("resize",this._onResize)},l.prototype.unbindResize=function(){this._onResize&&(window.removeEventListener("resize",this._onResize),this._onResize=null)},g.prototype=Object.create(l.prototype),g.prototype.constructor=g,g.prototype.getStyles=function(t,e){e=e||{};var n=this.getWrapperCss(e),o=this.getStageCss(t,e);return e.disableScale&&(o.transform="none"),{wrapperCss:n,stageCss:o,overlayCss:u({position:"absolute",top:"0",left:"0",right:"0",bottom:"0"},e.overlay),contentCss:u({position:"relative",zIndex:"1",width:"100%",maxHeight:"100%",overflow:"auto",display:"flex",flexDirection:"column",alignItems:"center"},e.content),titleCss:u({fontSize:"85px",fontWeight:"bold",textShadow:"2px 2px 4px #0b1c32",letterSpacing:"5px",lineHeight:"1.3",maxWidth:"90%",wordBreak:"break-word"},e.title),descCss:u({marginTop:"30px",width:"100%",whiteSpace:"pre-wrap",lineHeight:"1.6",wordBreak:"break-word",fontSize:"40px"},e.desc),btnGroupCss:u({width:"100%",maxWidth:"800px",marginTop:"80px",display:"flex",justifyContent:"center",alignItems:"center"},e.buttonGroup),btnCss:u({display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:"240px",minHeight:"88px",padding:"20px 50px",boxSizing:"border-box",cursor:"pointer",fontSize:"40px",fontWeight:"bold",backgroundColor:"#04b6bb",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",borderRadius:"50px",border:"none",color:"#fff",transition:"all 0.2s linear"},e.button)}},g.prototype.render=function(t,e,n){if(e=e||{},!t)throw new Error("[StartPage] render 失败:container 不存在");this.destroy();var o=this.getStyles(t,e),i=e.titleText||"欢迎进入游戏",r="string"==typeof e.descText?e.descText:"",s=e.buttonText||"开始游戏",a=c("div","kadou-start-page",o.wrapperCss),d=c("div","kadou-start-stage",o.stageCss),h=c("div","kadou-start-overlay",o.overlayCss),u=c("div","kadou-start-content",o.contentCss),p=c("div","kadou-start-title",o.titleCss,i);if(d.appendChild(h),u.appendChild(p),r){var l=c("div","kadou-start-desc",o.descCss,r);u.appendChild(l)}var g=c("div","kadou-start-btn-group",o.btnGroupCss),f=c("div","kadou-start-btn",o.btnCss,s);return this.bindEvent(f,"click",function(){"function"==typeof n&&n()}),g.appendChild(f),u.appendChild(g),d.appendChild(u),a.appendChild(d),t.appendChild(a),this.el=a,e.disableScale||(this.setPageContext(t,e,d),this.bindResize(),this.updateScale()),a},f.prototype=Object.create(l.prototype),f.prototype.constructor=f,f.prototype.getStyles=function(t,e){e=e||{};var n=this.getWrapperCss(e),o=this.getStageCss(t,e);return e.disableScale&&(o.transform="none"),{wrapperCss:n,stageCss:o,overlayCss:u({position:"absolute",top:"0",left:"0",right:"0",bottom:"0"},e.overlay),contentCss:u({position:"relative",zIndex:"1",width:"100%",maxHeight:"100%",overflow:"auto",display:"flex",flexDirection:"column",alignItems:"center"},e.content),titleCss:u({fontSize:"72px",fontWeight:"bold",lineHeight:"1.3",maxWidth:"90%",wordBreak:"break-word",textShadow:"2px 2px 4px #0b1c32"},e.title),timeCss:u({marginTop:"28px",fontSize:"40px",wordBreak:"break-word"},e.time),scoreCss:u({marginTop:"28px",fontSize:"40px",wordBreak:"break-word"},e.score),btnGroupCss:u({width:"100%",maxWidth:"900px",marginTop:"70px",display:"flex",justifyContent:"center",alignItems:"center",gap:"24px",flexWrap:"wrap"},e.buttonGroup),primaryBtnCss:u({display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:"240px",minHeight:"88px",padding:"20px 50px",boxSizing:"border-box",cursor:"pointer",fontSize:"40px",fontWeight:"bold",background:"#04b6bb",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",borderRadius:"50px",border:"none",color:"#fff",transition:"all 0.2s linear"},e.primaryButton||e.button),secondaryBtnCss:u({display:"inline-flex",alignItems:"center",justifyContent:"center",minWidth:"240px",minHeight:"88px",padding:"20px 50px",boxSizing:"border-box",cursor:"pointer",fontSize:"40px",fontWeight:"bold",background:"#ff6600",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"cover",borderRadius:"50px",border:"none",color:"#fff",transition:"all 0.2s linear"},e.secondaryButton)}},f.prototype.render=function(t,e,n){if(e=e||{},n=n||{},!t)throw new Error("[EndPage] render 失败:container 不存在");this.destroy();var o=this.getStyles(t,e),i=e.titleText||"游戏结束",r="string"==typeof e.timeText?e.timeText:"",s="string"==typeof e.scoreText?e.scoreText:"",a=e.primaryButtonText||e.buttonText||"再来一次",d=e.secondaryButtonText||"",h=c("div","kadou-end-page",o.wrapperCss),u=c("div","kadou-end-stage",o.stageCss),p=c("div","kadou-end-overlay",o.overlayCss),l=c("div","kadou-end-content",o.contentCss),g=c("div","kadou-end-title",o.titleCss,i);if(u.appendChild(p),l.appendChild(g),s){var f=c("div","kadou-end-score",o.scoreCss,s);l.appendChild(f)}if(r){var E=c("div","kadou-end-time",o.timeCss,r);l.appendChild(E)}var y=c("div","kadou-end-btn-group",o.btnGroupCss);if(d){var _=c("div","kadou-end-secondary-btn",o.secondaryBtnCss,d);this.bindEvent(_,"click",function(){"function"==typeof n.onShowRank?n.onShowRank():"function"==typeof n.onClose&&n.onClose()}),y.appendChild(_)}var S=c("div","kadou-end-primary-btn",o.primaryBtnCss,a);return this.bindEvent(S,"click",function(){"function"==typeof n.onRestart&&n.onRestart()}),y.appendChild(S),y.childNodes.length>0&&l.appendChild(y),u.appendChild(l),h.appendChild(u),t.appendChild(h),this.el=h,e.disableScale||(this.setPageContext(t,e,u),this.bindResize(),this.updateScale()),h},E.prototype.setContainer=function(t){return t&&(this.container=t),this},E.prototype.showStartPage=function(t,e){var n=this,o=e||{};if(!this.container)throw new Error("[OverlayManager] showStartPage 失败:container 不存在");return this.hideStartPage(),this.startPage=new g,this.startPage.render(this.container,t||{},function(){"function"==typeof o.onStart&&o.onStart(),n.hideStartPage()}),n},E.prototype.hideStartPage=function(){return this.startPage&&(this.startPage.destroy(),this.startPage=null),this},E.prototype.showEndPage=function(t,e){var n=this,o=e||{};if(!this.container)throw new Error("[OverlayManager] showEndPage 失败:container 不存在");return this.hideEndPage(),this.endPage=new f,this.endPage.render(this.container,t||{},{onRestart:function(){"function"==typeof o.onRestart&&(o.onRestart(),n.hideEndPage())},onShowRank:function(){"function"==typeof o.onShowRank&&o.onShowRank()}}),n},E.prototype.hideEndPage=function(){return this.endPage&&(this.endPage.destroy(),this.endPage=null),this},E.prototype.hideAll=function(){return this.hideStartPage(),this.hideEndPage(),this},E.prototype.destroy=function(){this.hideAll(),this.container=null};var y={};function _(t){return y[t]||y.default||null}function S(t,e){return e?/^(https?:)?\/\//.test(n=e)||/^file:/.test(n)||/^data:/.test(n)||/^blob:/.test(n)?e:t+e.replace(/^\.\//,""):"";var n}function m(t,e){var n,o;if(!t)return t;for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&"string"==typeof(o=t[n])&&("backgroundImage"!==n&&"src"!==n?"background"===n&&(t[n]=o.replace(/url\((['"]?)(.+?)\1\)/g,function(t,n,o){return'url("'+S(e,o)+'")'})):t[n]=S(e,o));return t}function T(t,e){var n,o,i,r;if(!t)return t;for(n=t.startPage||{},o=t.endPage||{},i=["wrapper","overlay","content","title","desc","buttonGroup","button","primaryButton","secondaryButton","score"],r=0;r<i.length;r++)m(n[i[r]],e),m(o[i[r]],e);return function(t,e){var n,o,i,r;if(!t)return t;for(n=["bg","frame","actionBtn","logo","icon"],o=0;o<n.length;o++)"string"==typeof(r=t[i=n[o]])&&r&&(t[i]=S(e,r))}(t.host,e),t}function v(t,e){window.__KADOU_THEME_PACK__=null,function(t,e){var n=document.createElement("script"),o=!1;n.type="text/javascript",n.async=!0,n.src=t,n.onload=function(){o||(o=!0,e&&e(null,n))},n.onerror=function(){o||(o=!0,e&&e(new Error("Failed to load script: "+t)))},document.head.appendChild(n)}(t,function(n){var o,i,r;n?e&&e(n):(o=window.__KADOU_THEME_PACK__)&&o.key&&o.theme?(i=function(t){return t?t.replace(/\/[^\/]*$/,"/"):""}(t),r=T(o.theme,i),function(t,e){if(!t)throw new Error("Theme key is required");y[t]=e||{}}(o.key,r),e&&e(null,{key:o.key,url:t,from:"remote",theme:r})):e&&e(new Error("Invalid theme pack: "+t))})}function A(t,e){if(!t)throw new Error("themeRoot is required");if(!e)throw new Error("themeKey is required");return t.replace(/\/?$/,"/")+e+"/theme.js"}function b(t,e,n){if(y[t])n&&n(null,{key:t,from:"cache",theme:_(t)});else{var o;try{o=A(e,t)}catch(t){return void(n&&n(t))}v(o,n)}}function R(t){t=t||{},s.call(this),this.options=t,this.root=t.root||document.body,this.debug=!!t.debug,this.role=t.role||"host",this.state={sdkReady:!1,gameReady:!1,started:!1,paused:!1,destroyed:!1},this.currentThemeKey="",this.currentTheme=null,this.bus=new d({selfWindow:t.selfWindow||window,targetWindow:t.targetWindow||null,targetOrigin:t.targetOrigin||"*",allowedOrigins:t.allowedOrigins||["*"],source:t.source||"KADOU_GAME_SDK",debug:this.debug}),this.overlay="game"===this.role?new E({container:this.root}):null,this._bindBusEvents()}R.prototype=Object.create(s.prototype),R.prototype.constructor=R,R.prototype._log=function(){this.debug&&"undefined"!=typeof console&&console.log&&console.log.apply(console,arguments)},R.prototype._callIfFn=function(t){if("function"==typeof t)return t.apply(this,Array.prototype.slice.call(arguments,1))},R.prototype._setState=function(t){var e;for(e in t=t||{})Object.prototype.hasOwnProperty.call(t,e)&&(this.state[e]=t[e])},R.prototype._emitLocal=function(t,e){this.emit(t,e||{},null,{local:!0})},R.prototype._registerBusEvent=function(t,e,n){var o=this;this.bus.on(t,function(t,i,r){n&&n.call(o,t,i,r),e&&o.emit(e,t,i,r)})},R.prototype._registerBusEventMap=function(t){var e=this;Object.keys(t).forEach(function(n){e._registerBusEvent(n,t[n])})},R.prototype._createSendMethod=function(t,e){R.prototype[t]=function(t){return this.send(e,t||{})}},R.prototype._bindBusEvents=function(){var t,e=this;this.bus.on("*",function(t,n){e.emit("message",t,n)}),this._registerBusEventMap(((t={})[o.GAME_LOAD]="game:load",t[o.GAME_LOADED]="game:loaded",t[o.GAME_LOADING]="game:loading",t[o.CONFIG_UPDATE]="config:update",t[o.ANSWER_START]="answer:start",t[o.QUESTION_SUBMIT]="question:submit",t[o.QUESTION_ANSWER_COMPLETED]="question:answer:completed",t[o.ANSWER_POPUP_SHOW]="answer:popup:show",t[o.ANSWER_POPUP_COMPLETED]="answer:popup:completed",t[o.REPORT_GENERATED]="result:report",t[o.ERROR]="error",t[o.GAME_RANK]="game:rank",t[o.QUESTION_PREV]="question:prev",t[o.QUESTION_NEXT]="question:next",t[o.AUDIO_VOLUME_CHANGE]="volume:change",t[o.EXTENSION_EVENT]="extension:event",t[o.HEARTBEAT_PONG]="heartbeat:pong",t[o.QUESTION_SUBMIT_RESULT]="question:submit:result",t)),this._registerBusEvent(o.SDK_READY,"sdk:ready",function(){this._setState({sdkReady:!0})}),this._registerBusEvent(o.GAME_READY,"game:ready",function(){this._setState({gameReady:!0})}),this._registerBusEvent(o.GAME_START,"game:start",function(){this._setState({started:!0,paused:!1}),"game"===this.role&&this.overlay&&this.hideStartPage()}),this._registerBusEvent(o.GAME_RESTART,"game:restart",function(){this._setState({started:!0,paused:!1}),"game"===this.role&&this.overlay&&this.hideEndPage()}),this._registerBusEvent(o.GAME_PAUSE,"game:pause",function(){this._setState({paused:!0})}),this._registerBusEvent(o.GAME_RESUME,"game:resume",function(){this._setState({paused:!1})}),this._registerBusEvent(o.GAME_FINISH,"game:finish",function(){this._setState({started:!1})}),this._registerBusEvent(o.GAME_DESTROY,"game:destroy",function(){this._setState({destroyed:!0})}),this._registerBusEvent(o.THEME_UPDATE,"theme:update",function(t){this.currentThemeKey=t&&t.themeKey?t.themeKey:"",this.currentTheme=t&&t.theme?t.theme:t||null}),this._registerBusEvent(o.PAGE_START_SHOW,"page:start:show",function(t){"game"===this.role&&this.renderStartPage(t)}),this._registerBusEvent(o.PAGE_END_SHOW,"page:end:show",function(t){"game"===this.role&&this.renderEndPage(t)}),this._registerBusEvent(o.HEARTBEAT_PING,"heartbeat:ping",function(t,e){this.send(o.HEARTBEAT_PONG,{replyTo:e&&e.requestId,time:(new Date).getTime()})})},R.prototype.init=function(){return this.bus.start(),this._log("[GameManager] init, role =",this.role),this},R.prototype.destroy=function(){return this._setState({destroyed:!0}),this.bus.destroy(),this.overlay&&(this._callIfFn(this.overlay.hideStartPage),this._callIfFn(this.overlay.hideEndPage)),this.off(),this._log("[GameManager] destroyed"),this},R.prototype.setTargetWindow=function(t){return this.bus.setTargetWindow(t),this},R.prototype.setTargetOrigin=function(t){return this.bus.setTargetOrigin(t),this},R.prototype.setRoot=function(t){return t?(this.root=t,this.overlay&&(this.overlay.container=t),this):this},R.prototype.send=function(t,e,n){return this.bus.send(t,e,n)},R.prototype.notifySdkReady=function(t){return this._setState({sdkReady:!0}),this.send(o.SDK_READY,t||{})},R.prototype.heartbeatPing=function(t){var e=t||{};return e.time=(new Date).getTime(),this.send(o.HEARTBEAT_PING,e)},R.prototype.gameReady=function(t){return this._setState({gameReady:!0}),this.send(o.GAME_READY,t||{})},R.prototype.startGame=function(t){var e=t||{};return this._setState({started:!0,paused:!1}),this._emitLocal("game:start",e),this.send(o.GAME_START,e)},R.prototype.restartGame=function(t){var e=t||{};return this._setState({started:!0,paused:!1}),this._emitLocal("game:restart",e),this.send(o.GAME_RESTART,e)},R.prototype.pauseGame=function(t){return this._setState({paused:!0}),this.send(o.GAME_PAUSE,t||{})},R.prototype.resumeGame=function(t){return this._setState({paused:!1}),this.send(o.GAME_RESUME,t||{})},R.prototype.finishGame=function(t){return this._setState({started:!1}),this.send(o.GAME_FINISH,t||{})},R.prototype.destroyGame=function(t){return this._setState({destroyed:!0}),this.send(o.GAME_DESTROY,t||{})},R.prototype.updateTheme=function(t){return"game"===this.role&&(this.currentTheme=t||null),this.send(o.THEME_UPDATE,t||{})},R.prototype.applyTheme=function(t,e,n){var i=n||{};return i.themeKey=t||"",i.theme=e||{},"game"===this.role&&(this.currentThemeKey=i.themeKey,this.currentTheme=i.theme),this.send(o.THEME_UPDATE,i)},R.prototype.reportError=function(t){var e;return e=t instanceof Error?{message:t.message,stack:t.stack}:t||{},this.send(o.ERROR,e)},R.prototype.getState=function(){return{sdkReady:this.state.sdkReady,gameReady:this.state.gameReady,started:this.state.started,paused:this.state.paused,destroyed:this.state.destroyed}},R.prototype.isReady=function(){return!(!this.state.sdkReady||!this.state.gameReady)},R.prototype._mergePageTheme=function(t,e){var n,o=(this.currentTheme||{})[t]||{},i={};for(n in e=e||{},o)Object.prototype.hasOwnProperty.call(o,n)&&(i[n]=o[n]);for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);return i},R.prototype.renderStartPage=function(t,e){var n=this,o=this._mergePageTheme("startPage",t||{});return this.overlay&&this.overlay.showStartPage?(this.overlay.showStartPage(o,e||{onStart:function(){n.startGame({from:"sdk-start-game"})}}),this):this},R.prototype.hideStartPage=function(){return this.overlay&&this.overlay.hideStartPage&&this.overlay.hideStartPage(),this},R.prototype.renderEndPage=function(t,e){var n=this,o=this._mergePageTheme("endPage",t||{});return this.overlay&&this.overlay.showEndPage?(this.overlay.showEndPage(o,e||{onRestart:function(){n.restartGame({from:"sdk-restart-game"})},onShowRank:function(){n.showGameRank({from:"sdk-game-rank"})}}),this):this},R.prototype.hideEndPage=function(){return this.overlay&&this.overlay.hideEndPage&&this.overlay.hideEndPage(),this},R.prototype.loadThemeByUrl=function(t,e){return v(t,e),this},R.prototype.ensureTheme=function(t,e,n){return b(t,e,n),this},R.prototype.buildThemeUrl=function(t,e){return A(t,e)},[["loadGame",o.GAME_LOAD],["gameLoading",o.GAME_LOADING],["gameLoaded",o.GAME_LOADED],["showGameRank",o.GAME_RANK],["updateConfig",o.CONFIG_UPDATE],["showStartPage",o.PAGE_START_SHOW],["showEndPage",o.PAGE_END_SHOW],["startAnswer",o.ANSWER_START],["submitQuestion",o.QUESTION_SUBMIT],["questionSubmitResult",o.QUESTION_SUBMIT_RESULT],["completeQuestionAnswer",o.QUESTION_ANSWER_COMPLETED],["showAnswerPopup",o.ANSWER_POPUP_SHOW],["completeAnswerPopup",o.ANSWER_POPUP_COMPLETED],["prevQuestion",o.QUESTION_PREV],["nextQuestion",o.QUESTION_NEXT],["changeVolume",o.AUDIO_VOLUME_CHANGE],["extensionEvent",o.EXTENSION_EVENT]].forEach(function(t){R.prototype._createSendMethod(t[0],t[1])});var O={SDK_VERSION:n,MESSAGE_TYPES:o,EventEmitter:s,MessageBus:d,GameRuntime:R};t.EventEmitter=s,t.GameRuntime=R,t.MESSAGE_TYPES=o,t.MessageBus=d,t.SDK_VERSION=n,t.default=O,Object.defineProperty(t,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kadou-game-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "kadou-game-sdk",
5
5
  "main": "dist/kadou-game-sdk.cjs",
6
6
  "module": "dist/kadou-game-sdk.esm.js",