minigame-tuanjie-transform-sdk/Runtime/playable-default/unity-playable-plugin/index.js
2025-07-02 12:36:39 +08:00

1 line
68 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(()=>{var e={7:(e,t,n)=>{"use strict";function s(){}function i(e=20,t){const n=(t?"":"!#%()*+,-./:;=?@[]^_`{|}~")+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",s=n.length,i=[];for(let t=0;t<e;t++)i[t]=n.charAt(Math.random()*s);return i.join("")}function o(e="0.0.0",t){if("string"!=typeof e||"string"!=typeof t)return"string"!=typeof e&&"string"!=typeof t?0:"string"!=typeof e?1:-1;const n=e.split("."),s=t.split("."),i=Math.max(n.length,s.length);for(;n.length<i;)n.push("0");for(;s.length<i;)s.push("0");for(let e=0;e<i;e++){const t=parseInt(n[e],10),i=parseInt(s[e],10);if(t>i)return 1;if(t<i)return-1}return 0}function r(e){return"number"==typeof e&&isFinite(e)}function a(e,t=0,n=0,...s){return new Promise(((i,o)=>{const r=(t=0)=>{e.apply(null,[...s,t]).then(i).catch((e=>{t>0?setTimeout((()=>{r(t-1)}),n):o(e)}))};r(t)}))}function c(e){return e.then((e=>[null,e])).catch((e=>[e,null]))}function l(e,t="yyyy-MM-dd"){if(!e)return"";let n=t;const s=10===String(e).toString().length?new Date(1e3*e):new Date(e),i={"y+":s.getFullYear(),"M+":s.getMonth()+1,"d+":s.getDate(),"h+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),"S+":s.getMilliseconds()};for(const[e,t]of Object.entries(i)){const s=new RegExp(`(${e})`);if(s.test(n)){const[e]=n.match(s);n=n.replace(s,(()=>`00${t}`.slice(-`${e}`.length)))}}return n}function u(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return!e;if(e instanceof Error)return""===e.message;switch(Object.prototype.toString.call(e)){case"[object String]":case"[object Array]":return!e.length;case"[object File]":case"[object Map]":case"[object Set]":return!e.size;case"[object Object]":return!Object.keys(e).length}return!1}function h(e){return"[object String]"===Object.prototype.toString.call(e)}function d(e){return"[object Object]"===Object.prototype.toString.call(e)}function p(e){return e&&"[object Function]"===Object.prototype.toString.call(e)}function g(e){let t=e;try{"object"==typeof e&&(t="string"==typeof e.errMsg?e.errMsg:"string"==typeof e.errmsg?e.errmsg:"string"==typeof e.message?e.message:JSON.stringify(e))}catch(e){console.error(e)}return t}function m(e,t,n){if(!n)return e;let s=e;const i=new RegExp(`([?&])${t}=.*?(&|$)`,"i");if(s.match(i))return s.replace(i,`$1${t}=${n}$2`);const o=-1!==s.indexOf("?")?"&":"?",r=s.split("#");return s=`${r[0]+o+t}=${n}`,r[1]&&(s+=`#${r[1]}`),s}n.d(t,{Et:()=>r,Gm:()=>o,Gv:()=>d,Im:()=>u,Kg:()=>h,L8:()=>g,Ld:()=>i,Mx:()=>a,NW:()=>c,Q$:()=>m,Tn:()=>p,Yq:()=>l,dv:()=>s})},72:(e,t,n)=>{"use strict";var s,i,o,r,a;n.d(t,{OD:()=>s,aM:()=>o,jt:()=>r,rC:()=>a}),function(e){e.devtools="devtools",e.android="android",e.ios="ios",e.windows="windows",e.mac="mac"}(s||(s={})),function(e){e.portrait="portrait",e.landscape="landscape",e.landscapeLeft="landscapeLeft",e.landscapeRight="landscapeRight"}(i||(i={})),function(e){e.DEVELOP="develop",e.TRIAL="trial",e.RELEASE="release"}(o||(o={})),function(e){e[e.release=1]="release",e[e.develop=2]="develop",e[e.trial=3]="trial"}(r||(r={})),function(e){e[e.Android=0]="Android",e[e.IOSJscore=1]="IOSJscore",e[e.IOSWK=2]="IOSWK",e[e.UnKnow=3]="UnKnow",e[e.PC=4]="PC",e[e.Devtools=5]="Devtools",e[e.IPadJscore=6]="IPadJscore",e[e.IPadWK=7]="IPadWK",e[e.IOSWKPlus=8]="IOSWKPlus",e[e.IPadWKPlus=9]="IPadWKPlus"}(a||(a={}))},347:(e,t,n)=>{"use strict";n.d(t,{A:()=>Ie});var s={};n.r(s),n.d(s,{navigateToMiniProgram:()=>I});var i=n(7),o=n(72);function r(e){var t,s,i,r,a;const c=null===(t=e.platform)||void 0===t?void 0:t.toLocaleLowerCase();return c===o.OD.devtools?o.rC.Devtools:c===o.OD.ios?e.model&&e.model.indexOf("iPad")>-1?(null===(s=n.g)||void 0===s?void 0:s.isIOSHighPerformanceModePlus)?o.rC.IPadWKPlus:(null===(i=n.g)||void 0===i?void 0:i.isIOSHighPerformanceMode)?o.rC.IPadWK:o.rC.IPadJscore:(null===(r=n.g)||void 0===r?void 0:r.isIOSHighPerformanceModePlus)?o.rC.IOSWKPlus:(null===(a=n.g)||void 0===a?void 0:a.isIOSHighPerformanceMode)?o.rC.IOSWK:o.rC.IOSJscore:c===o.OD.android?o.rC.Android:c===o.OD.windows||c===o.OD.mac?o.rC.PC:o.rC.UnKnow}var a,c,l,u,h;const d="undefined"!=typeof mb&&void 0!==mb.env,p=!("undefined"==typeof pluginEnv),g=!d&&"undefined"!=typeof wx&&"undefined"!=typeof Page,m=!(d||"undefined"==typeof wx||g)||p,f={isMagicBrush:d,isMiniGamePlugin:p,isMiniGame:m,isMiniProgram:g,isIOS:!1,isAndroid:!1,isDevtools:!1,isWindows:!1,isMac:!1,isPC:!1,isWK:!1,isWKPlus:!1,isIPad:!1,systemInfo:{},accountInfo:{},wx:{},runtimeType:o.rC.UnKnow,pluginWx:{},pluginAppId:"",pluginVersion:""};function y(e){var t;if(f.systemInfo=e,f.systemInfo.screenWidth||f.systemInfo.screenWidth||(f.systemInfo.screenWidth=0,f.systemInfo.screenHeight=0),f.runtimeType=r(f.systemInfo),v(f.systemInfo),(0,i.Gm)(f.systemInfo.SDKVersion,"2.24.4")>=0&&(null===(t=f.pluginWx)||void 0===t?void 0:t.getAccountInfoSync))try{const e=f.pluginWx.getAccountInfoSync()||{},{plugin:t={}}=e;f.pluginAppId=t.appId,f.pluginVersion=t.version}catch(e){console.error(e)}}function v(e){var t;const s=null===(t=e.platform)||void 0===t?void 0:t.toLocaleLowerCase();s===o.OD.devtools?f.isDevtools=!0:s===o.OD.ios?(f.isIOS=!0,f.isWK=!!(null===n.g||void 0===n.g?void 0:n.g.isIOSHighPerformanceMode),f.isWKPlus=!!(null===n.g||void 0===n.g?void 0:n.g.isIOSHighPerformanceModePlus)):s===o.OD.android?f.isAndroid=!0:s===o.OD.windows?f.isWindows=!0:s===o.OD.mac?f.isMac=!0:void 0===s&&(f.isIOS=!0),(f.isWindows||f.isMac)&&(f.isPC=!0),e.model&&e.model.indexOf("iPad")>-1&&(f.isIPad=!0)}if(m||g){if(p){const{customEnv:e}=pluginEnv;e&&e.customEnv&&(pluginEnv.customEnv=e.customEnv),"undefined"!=typeof wx&&(f.pluginWx=wx),pluginEnv.customEnv?f.wx=pluginEnv.customEnv.wx?pluginEnv.customEnv.wx:f.pluginWx:f.wx=f.pluginWx}else f.wx=wx;if(f.wx){try{y(f.wx.getSystemInfoSync()),f.wx.getSystemInfo({success:e=>{y(e)}})}catch(e){console.error(e)}try{f.accountInfo=null!==(l=null===(c=(a=f.wx).getAccountInfoSync)||void 0===c?void 0:c.call(a))&&void 0!==l?l:{}}catch(e){console.error(e)}}}else d&&mb.JSBridge.invoke("getSystemInfoSync",{},(e=>{f.systemInfo=e,f.runtimeType=r(f.systemInfo),v(f.systemInfo)}));null===(h=(u=f.wx).onDeviceOrientationChange)||void 0===h||h.call(u,(()=>{f.wx.getSystemInfo({success:e=>{f.systemInfo=e||{}}})})),p&&(f.pluginEnv=pluginEnv);const S=f;function I(e){S.wx.navigateToMiniProgram&&(S.pluginEnv&&S.pluginEnv.navigateToMiniProgramDirectly?S.pluginEnv.navigateToMiniProgramDirectly({appId:e}):S.wx.navigateToMiniProgram({appId:e}))}const{parse:T,stringify:w}=JSON,{keys:b}=Object,E=String,M="string",P="object",R=(e,t)=>t,A=(e,t,n)=>{const s=E(t.push(n)-1);return e.set(n,s),s},L=(e,t,n)=>{const s=t&&typeof t===P?(e,n)=>""===e||-1<t.indexOf(e)?n:void 0:t||R,i=new Map,o=[],r=[];let a=+A(i,o,s.call({"":e},"",e)),c=!a;for(;a<o.length;)c=!0,r[a]=w(o[a++],l,n);return"["+r.join(",")+"]";function l(e,t){if(c)return c=!c,t;const n=s.call(this,e,t);switch(typeof n){case P:if(null===n)return n;case M:return i.get(n)||A(i,o,n)}return n}};var C,O,D,x,N;!function(e){e.log="log",e.info="info",e.warn="warn",e.error="error"}(C||(C={}));class _{constructor({reportFunc:e,base:t,debug:n,delimiter:s,namespace:i}){this.reportFunc=null,this.debug=!1,this.base={},this.delimiter=" ",this.namespace="",e?(this.reportFunc=e,t&&this.setBase(t),this.debug=!!n,s&&(this.delimiter=s),this.namespace=i?` ${i} `:" "):console.error("[minigamefe XLog]: 未传入上报函数。")}setBase(e){this.base=Object.assign(Object.assign({},this.base),e)}log(...e){this.report(C.log,e)}info(...e){this.report(C.info,e)}warn(...e){this.report(C.warn,e)}error(...e){this.report(C.error,e)}getLogStr(e,t){var n;if(!this.reportFunc)return console.error(`[minigamefe${this.namespace}XLog]: 未传入上报函数。`),"";if(!t)return"";let s="";t.forEach((e=>{s.length>0&&(s+=this.delimiter);let t=e;"object"==typeof t&&(t=t instanceof TypeError?t.message:L(t)),s+=`${String(t).trim()}`}));const i=`[minigamefe${this.namespace}XLog]: ${JSON.stringify(Object.assign(Object.assign({},this.base),{type:e,content:s}))}`;return this.debug&&(null===(n=console[e])||void 0===n||n.call(console,i)),i}report(e,t){const{reportFunc:n}=this;if(!n)return void console.error(`[minigamefe${this.namespace}XLog]: 未传入上报函数。`);if(!n[e]||"function"!=typeof n[e])return void console.error(`[minigamefe${this.namespace}XLog]: 传入的上报函数格式不对。`);const s=this.getLogStr(e,t);s&&n[e](s)}}!function(e){e[e.Front=1]="Front",e[e.Background=2]="Background"}(O||(O={})),function(e){e[e.Default=0]="Default",e[e.GameTransfer=1]="GameTransfer",e[e.Request=2]="Request",e[e.DownloadFile=3]="DownloadFile",e[e.CgiSpeedMeasure=4]="CgiSpeedMeasure",e[e.BadJs=5]="BadJs",e[e.Init=6]="Init",e[e.CostTime=7]="CostTime",e[e.Error=8]="Error",e[e.UploadFile=9]="UploadFile",e[e.Login=10]="Login",e[e.WebTransfer=11]="WebTransfer"}(D||(D={})),function(e){e[e.Info=101]="Info",e[e.Warn=102]="Warn",e[e.Error=103]="Error"}(x||(x={})),function(e){e.GameTransferReport="GameTransferReport",e.KeyValueReport="KeyValueReport",e.WxRequestReport="WxRequestReport"}(N||(N={}));const G=Object.values(D).filter((e=>(0,i.Et)(e)));const F=new class{constructor(){this.options={debug:!1,logReport:!1,qualityReportType:N.KeyValueReport,pluginAppId:"",pluginVersion:"",xlogName:"minigamefe"}}set(e){Object.assign(this.options,e)}get(e){return this.options[e]}};class k{constructor(e){this.identifier=`${F.get("pluginAppId")||S.pluginAppId}/plugin.js`,this.quality=e,this.init()}init(){var e,t;null===(t=null===(e=S.wx)||void 0===e?void 0:e.onError)||void 0===t||t.call(e,(e=>{this.processError(e.message)}))}processError(e){var t;if(e.indexOf(this.identifier)>-1){const n=e.split("\n"),s=n[0],i=null===(t=n[2])||void 0===t?void 0:t.split(":")[0];this.quality.innerReport({Type:D.BadJs,Target:s,CostTime:0,Result:e,CustomKey1:i})}}}var W,U,$=n(504);!function(e){e.GAMETRANSFER_IS_NOT_EXIST="gameTransfer is not exist",e.REQUEST_IS_NOT_EXIST="request is not exist",e.UPLOADFILE_IS_NOT_EXIST="uploadFile is not exist",e.LOGIN_IS_NOT_EXIST="login is not exist",e.URL_IS_EMPTY="request url is empty.",e.HEADER_INVALID="request header is invalid",e.METHOD_IS_NOT_EXIST="method is not exist"}(W||(W={}));class j extends $.TinyEmitter{}!function(e){e.login="login",e.gameTransfer="gameTransfer",e.request="request",e.uploadFile="uploadFile",e.downloadFile="downloadFile",e.webTransfer="webTransfer"}(U||(U={}));const V={QualityReportType:N,RequestRejectType:W,ReportType:D,PluginReportType:x},q=8192;var B,K;!function(e){e.STRING="STRING",e.LONGLONG="LONGLONG",e.UINT="UINT",e.INT="INT"}(B||(B={})),function(e){e.SvrReport="SvrReport",e.KvStat="KvStat"}(K||(K={}));const H={[B.STRING]:e=>"string"==typeof e&&e.length<=q,[B.LONGLONG]:e=>"number"==typeof e&&Math.floor(e)===e,[B.UINT]:e=>"number"==typeof e&&Math.floor(e)===e&&e>=0,[B.INT]:e=>"number"==typeof e&&Math.floor(e)===e};class z{constructor({logid:e,schemas:t={},base:n,debug:s=!1,namespace:i="",skipValidateInProdEnv:o=!0}){this.debug=!1,this.base={},this.namespace="",this.skipValidateInProdEnv=!0,this.asyncGetBase=()=>Promise.resolve({}),this.logid=e,this.schemas=t,n&&this.setBase(n),this.debug=s,this.skipValidateInProdEnv=o,this.namespace=i?` ${i} `:" "}setBase(e){this.validate(e),this.base=Object.assign(Object.assign({},this.base),e)}validate(e){if((this.debug||!this.skipValidateInProdEnv)&&Object.keys(this.schemas).length)for(const[t,n]of Object.entries(e)){if(void 0===n)continue;const e=this.schemas[t];e?this.validateColumn(e,n)||console.error(`[minigamefe${this.namespace}SchemaValidator]: logid ${this.logid}: ${t} should be ${e}, but now ${n}`):console.warn(`[minigamefe${this.namespace}SchemaValidator]: logid${this.logid}: ${t} 缺少类型定义`)}}validateColumn(e,t){return H[e](t)}}let X="";class J extends z{constructor({reportFunc:e,logid:t,schemas:n={},base:s,reportType:i,asyncGetBase:o=()=>Promise.resolve({}),debug:r,namespace:a="",skipValidateInProdEnv:c=!0}){super({logid:t,schemas:n,base:s,debug:r,namespace:a,skipValidateInProdEnv:c}),this.reportType=K.SvrReport,this.asyncGetBase=o,e||console.error(`[minigamefe${this.namespace}GameTransferReport]: 未传入上报函数。`),this.reportFunc=e,void 0!==i&&(this.reportType=i)}setKvStatBase(e,t){if(this.reportType===K.KvStat){const n=(e.system||"").split(" ");Object.assign(this.schemas,{DeviceModel:B.STRING,DeviceBrand:B.STRING,OsName:B.STRING,OsVersion:B.STRING,LanguageVersion:B.STRING,Count:B.UINT,AppId:B.STRING,AppVersion:B.UINT,AppState:B.UINT}),this.setBase({DeviceModel:e.model||"",DeviceBrand:e.brand||"",OsName:n[0]||"",OsVersion:n[1]||"",LanguageVersion:e.language||"",Count:1}),(null==t?void 0:t.miniProgram)&&this.setBase({AppState:o.jt[t.miniProgram.envVersion]||o.jt.release,AppId:t.miniProgram.appId,AppVersion:0})}}send(e,t){if(!this.reportFunc||"function"!=typeof this.reportFunc)return void console.error("[minigamefe GameTransferReport]: 未传入上报函数!!!");const n=[],s=this.logid;let o;o=Array.isArray(e)?e:[e],this.asyncGetBase().then((e=>{this.setBase(e),o.forEach((e=>{const t=Object.assign(Object.assign({},this.base),e);if(t.ExternInfo&&"object"==typeof t.ExternInfo&&this.schemas.ExternInfo===B.STRING&&(t.ExternInfo=encodeURIComponent(JSON.stringify(t.ExternInfo))),this.validate(t),this.reportType===K.KvStat){const e=Math.floor(Date.now()/1e3);Object.assign(t,{StartTime:e,EndTime:e})}const i={log_id:this.logid,custom_data:t};n.push(i),this.debug&&console.log(`[minigamefe${this.namespace}GameTransferReport]: ${s},`,t)}));const r={report_list:n};this.reportFunc({req_path:"comm_datareport",json_data:JSON.stringify(r),success(){t&&t(s,JSON.stringify(r))},fail(e){console.error(e),t&&t(s,(0,i.L8)(e))}})}))}}const Y={19283:"GameComponent",19335:"GameWhatsNew",20285:"MidasFriendPayment",21494:"WXGameWASMLaunchClose",21493:"WXGameWASMLaunchException",21492:"WXGameWASMLaunchTime",21898:"GameLifeMiniGameCardAction",20267:"GameAdsSkipCard"};class Q extends z{constructor({reportFunc:e,logid:t,protocolParams:n,schemas:s,base:i,asyncGetBase:o=()=>Promise.resolve({}),debug:r,namespace:a="",skipValidateInProdEnv:c=!0}){let l=t;"number"==typeof t&&Y[t]&&(l=Y[t],r&&console.warn(`[minigamefe${a?` ${a} `:" "}KeyValueReporter]: logid ${t} auto map to ${l}!`)),super({logid:l,schemas:s,base:i,debug:r,namespace:a,skipValidateInProdEnv:c}),this.asyncGetBase=o,e||console.error(`[minigamefe${this.namespace}KeyValueReporter]: 未传入上报函数。`),this.reportFunc=e||function(){},this.protocolParams=n,this.sendCbk=null}setAppInfoBase(e){Object.assign(this.schemas,{AppId:B.STRING,AppVersion:B.UINT,AppState:B.UINT}),this.protocolParams.unshift("AppId","AppVersion","AppState"),this.setBase(e)}send(e,t){let n;n=Array.isArray(e)?e:[e],this.asyncGetBase().then((e=>{this.setBase(e),n.forEach((e=>{const n=Object.assign(Object.assign({},this.base),e);this.validate(n);const s=[];this.protocolParams.forEach((e=>{const t=void 0!==n[e]?n[e]:"";s.push(t)})),this.reportFunc({key:this.logid,value:s.map(encodeURIComponent).join(","),immediately:!0});const i=t||this.sendCbk;if(i&&i(this.logid,s.map(encodeURIComponent).join(",")),this.debug){(n.IsError?console.error:console.log)(`[minigamefe${this.namespace}keyValueReport]: ${this.logid}`,n)}}))}))}}const Z="https://game.weixin.qq.com",ee="minigamefe_session_id";class te extends z{constructor({reportFunc:e,logid:t,schemas:n={},base:s,debug:i,namespace:o,asyncGetBase:r=()=>Promise.resolve({}),reportType:a,skipValidateInProdEnv:c=!0}){super({logid:t,schemas:n,base:s,debug:i,namespace:o,skipValidateInProdEnv:c}),this.reportType=K.SvrReport,this.reportFunc=e,e||console.error(`[minigamefe${this.namespace}RequestReport]: 未传入上报函数。`),this.asyncGetBase=r,void 0!==a&&(this.reportType=a)}setKvStatBase(e,t){if(this.reportType===K.KvStat){const n=(e.system||"").split(" ");Object.assign(this.schemas,{DeviceModel:B.STRING,DeviceBrand:B.STRING,OsName:B.STRING,OsVersion:B.STRING,LanguageVersion:B.STRING,Count:B.UINT,AppId:B.STRING,AppVersion:B.UINT,AppState:B.UINT}),this.setBase({DeviceModel:e.model||"",DeviceBrand:e.brand||"",OsName:n[0]||"",OsVersion:n[1]||"",LanguageVersion:e.language||"",Count:1}),(null==t?void 0:t.miniProgram)&&this.setBase({AppState:o.jt[t.miniProgram.envVersion]||o.jt.release,AppId:t.miniProgram.appId,AppVersion:0})}}send(e,t){if(!this.reportFunc||"function"!=typeof this.reportFunc)return void console.error("[minigamefe RequestReport]: 未传入上报函数!!!");const n=[],s=this.logid;let o;o=Array.isArray(e)?e:[e],this.asyncGetBase().then((e=>{this.setBase(e),o.forEach((e=>{const t=Object.assign(Object.assign({},this.base),e);this.validate(t);const i={log_id:s,custom_data:t};n.push(i)}));const r=JSON.stringify({report_list:n});this.debug&&console.log(`[minigamefe${this.namespace}RequestReport]: ${s}`,...n),this.reportFunc({url:`${Z}/cgi-bin/comm/datareport`,method:"POST",header:{"content-type":"application/x-www-form-urlencoded"},data:r,success(){t&&t(s,JSON.stringify(r))},fail(e){console.error(e),t&&t(s,(0,i.L8)(e))}})}))}}const ne=["BenchmarkLevel","NetworkType","RuntimeType","PluginAppId","PluginVersion","Scene","SDKVersion","IsVisible","Type","Target","Params","Result","CostTime","ExternInfo","CustomKey1","CustomKey2","CustomKey3","IsError","FELibVersion","Query"],se={BenchmarkLevel:B.UINT,NetworkType:B.STRING,RuntimeType:B.UINT,PluginAppId:B.STRING,PluginVersion:B.STRING,Scene:B.UINT,SDKVersion:B.STRING,IsVisible:B.UINT,Type:B.UINT,Target:B.STRING,Params:B.STRING,Result:B.STRING,CostTime:B.UINT,ExternInfo:B.STRING,CustomKey1:B.STRING,CustomKey2:B.STRING,CustomKey3:B.STRING,IsError:B.UINT,FELibVersion:B.STRING,Query:B.STRING};function ie(e){const{type:t=N.KeyValueReport,reportKeyValue:n,debug:s,gameTransfer:i,systemInfo:o,accountInfo:r,getNetworkType:a,onNetworkStatusChange:c,request:l,namespace:u}=e;let h,d="";function p(){return new Promise((e=>{d?e({NetworkType:d}):a({success:t=>{d=t.networkType,e({NetworkType:d})},fail:()=>{d="unknown",e({NetworkType:d})}})}))}return t===N.KeyValueReport?h=new Q({reportFunc:n,logid:26340,schemas:se,protocolParams:ne,debug:s,namespace:u,asyncGetBase:p}):t===N.GameTransferReport?(h=new J({reportFunc:i,logid:26340,schemas:se,reportType:K.KvStat,debug:s,namespace:u,asyncGetBase:p}),h.setKvStatBase(o,r)):(console.warn("[minigamefe]: 当前选择 reqeust 进行质量上报, 请自行确保兼容性"),h=new te({reportFunc:l,logid:26340,schemas:se,debug:s,namespace:u,asyncGetBase:p,reportType:K.KvStat}),h.setKvStatBase(o,r)),t!==N.GameTransferReport&&t!==N.WxRequestReport||function(e,t,n){X?e&&e(X):(t({success:t=>{X=t.networkType,e&&e(X)}}),n((t=>{X=t.networkType,t.isConnected||(X="none"),e&&e(X)})))}((e=>{d=e,h.setBase({NetworkType:e})}),a,c),h}const oe="1.1.79";function re(e,t){let n=e||"";if((0,i.Gv)(n))try{n=JSON.stringify(n)}catch(e){console.error(`[minigamefe stringify error]: ${e}`),n=""}else n=String(n);return n.length&&n.length>=q&&(n=n.substr(0,q),console.warn(`[minigamefe stringify warning]: ${t} 上报长度超过8192, 已裁剪`)),n}class ae{constructor(e){var t,n,s;this.benchmarkLevel=0,this.network="",this.runtimeType=o.rC.UnKnow,this.sdkVersion="0.0.0",this.isVisible=O.Front,this.scene=0,this.query="",this.pluginAppId="",this.pluginVersion="",this.inited=!1;const{systemInfo:a,launchInfo:c,onShow:l,onHide:u,pluginAppId:h="",pluginVersion:d=""}=e;if(!l||!u)return console.error("[minigamefe stringify warning]: please inject QualityConfig correctly"),void(this.inited=!1);this.inited=!0,this.onShow=l,this.onHide=u,this.benchmarkLevel=(a.benchmarkLevel||1)+100,this.sdkVersion=a.SDKVersion||"0.0.0",this.launchInfo=c,this.scene=(null===(t=this.launchInfo)||void 0===t?void 0:t.scene)||0,(0,i.Im)(null===(n=this.launchInfo)||void 0===n?void 0:n.query)||(this.query=encodeURIComponent(JSON.stringify(null===(s=this.launchInfo)||void 0===s?void 0:s.query))),this.runtimeType=r(a),this.pluginAppId=h,this.pluginVersion=d,this.bindNativeEvent(),this.reporter=ie(e),this.reporter.setBase({BenchmarkLevel:this.benchmarkLevel,RuntimeType:this.runtimeType,Scene:+this.scene,SDKVersion:this.sdkVersion,IsVisible:this.isVisible,PluginAppId:h,PluginVersion:d,FELibVersion:oe,Query:this.query})}bindNativeEvent(){this.onHide((()=>{this.isVisible=O.Background,this.reporter.setBase({IsVisible:this.isVisible})})),this.onShow((e=>{(0,i.Im)(null==e?void 0:e.query)||(this.query=encodeURIComponent(JSON.stringify(e.query))),this.isVisible=O.Front,this.reporter.setBase({IsVisible:this.isVisible,Query:this.query})}))}innerReport(e){this.reporter.send(Object.assign(e,{CostTime:(0,i.Et)(e.CostTime)?e.CostTime:0,Params:re(e.Params,"Params"),Result:re(e.Result,"Result"),ExternInfo:re(e.ExternInfo,"ExternInfo")}))}report(e){G.indexOf(e.Type)>-1&&console.error(`[minigamefe quality report]: 若为自定义上报, Type 请不要使用内置枚举值 ${e.Type}, 内置枚举可见 mgp.consts.ReportType`),this.inited&&this.innerReport(e)}setCustomKey(e){this.inited&&this.reporter.setBase({CustomKey1:e.CustomKey1&&re(e.CustomKey1,"CustomKey1")||"",CustomKey2:e.CustomKey2&&re(e.CustomKey2,"CustomKey2")||"",CustomKey3:e.CustomKey3&&re(e.CustomKey3,"CustomKey3")||""})}clearCustomKey(){this.inited&&this.reporter.setBase({CustomKey1:"",CustomKey2:"",CustomKey3:""})}}class ce{constructor({debug:e=!1,quality:t,namespace:n}){this.namespace="",this.errCodeIgnoreList=[],this.debug=e,this.quality=t,this.namespace=n?` ${n} `:" "}innerRequest(e,t){return new Promise(((n,s)=>{const{Constructor:o,funcName:r,reportType:a}=t;if(r!==U.login&&!e.url)return void s(W.URL_IS_EMPTY);const c=new o(e);c.optionsFilter(e),c.on("success",(()=>{var t;this.debug&&!0!==e.silent&&console.log(`[minigamefe${this.namespace}Network]: ${r} end with success`,c.response);const{response:s,sourceResponse:o,costTime:l}=c;let{errcode:u}=s;const{errmsg:h}=s;let d=h;e.reduceErrmsgBeforeReport&&(0,i.Tn)(e.reduceErrmsgBeforeReport)&&(d=e.reduceErrmsgBeforeReport(s)),r!==U.login||s.code||(d=s.errMsg,u=9999),(0,i.Et)(u)&&0!==Number(u)&&!0!==e.silent&&-1===this.errCodeIgnoreList.indexOf(Number(u))&&(null===(t=this.quality)||void 0===t||t.innerReport({Type:a,Target:e.url||"",Params:e.data,CostTime:l,Result:{errcode:u,errmsg:d},IsError:1})),n([s,o])})),c.on("error",(t=>{var n;!0!==e.silent&&(this.debug&&console.error(`[minigamefe${this.namespace}Network]: ${r} end with error`,e,t),null===(n=this.quality)||void 0===n||n.innerReport({Type:a,Target:e.url||"",CostTime:c.costTime,Params:e.data,Result:(0,i.L8)(t),IsError:1})),s(t)})),c.on("complete",((t=0)=>{var n;!0!==e.silent&&Math.random()<.1&&(null===(n=this.quality)||void 0===n||n.innerReport({Type:D.CgiSpeedMeasure,Target:e.url||"",Params:e.data,CostTime:c.costTime,IsError:t}))})),this.debug&&!0!==e.silent&&console.log(`[minigamefe${this.namespace}Network]: ${r} start`,e),c.send()}))}addIgnoreErrCode(e){(Array.isArray(e)?e:[e]).forEach((e=>{-1===this.errCodeIgnoreList.indexOf(e)&&this.errCodeIgnoreList.push(e)}))}removeIgnoreErrCode(e){(Array.isArray(e)?e:[e]).forEach((e=>{this.errCodeIgnoreList.indexOf(e)>-1&&this.errCodeIgnoreList.splice(this.errCodeIgnoreList.indexOf(e),1)}))}setRequestQualityReporter(e){this.quality=e}}class le{constructor(e){this.sessionId="",this.login=e.login,this.request=e.request}getSessionId(e){return this.checkSession().catch((()=>this.loginWxGame(e)))}clearSessionId(){var e,t;this.sessionId="",null===(t=(e=S.wx).removeStorageSync)||void 0===t||t.call(e,ee)}checkSession(){return new Promise(((e,t)=>{var n,s,i,o;const r=this.sessionId||(null===(s=(n=S.wx).getStorageSync)||void 0===s?void 0:s.call(n,ee));r?null===(o=(i=S.wx).checkSession)||void 0===o||o.call(i,{success:()=>{e({sessionId:r})},fail:e=>{this.clearSessionId(),t(e)}}):t({errMsg:"尚未保存sessionId"})}))}loginWxGame(e){return this.isLoginPromise||(this.isLoginPromise=new Promise(((t,n)=>{this.login({}).then((([t])=>{const n={code:t.code};return e&&(n.appid=e),this.request({url:`${Z}/cgi-bin/gameweappauthwap/login`,data:n,method:"POST"})})).then((([e])=>{var s,i;e&&e.data?(S.isMiniGamePlugin||null===(i=(s=S.wx).setStorageSync)||void 0===i||i.call(s,ee,e.data.session_id),this.sessionId=e.data.session_id||"",t({sessionId:e.data.session_id})):n({errMsg:"登录出错"})})).catch((()=>{n({errMsg:"登录出错"})}))}))),this.isLoginPromise.finally((()=>{this.isLoginPromise=void 0}))}}function ue(e,t){var n,s;if(!e)return"";let o=e,r=t;return r||(r=null===(s=(n=S.wx).getStorageSync)||void 0===s?void 0:s.call(n,ee)),r&&(o=(0,i.Q$)(o,"session_id",r)),o}class he extends j{constructor(e,t){super(),this.startTime=0,this.costTime=0,this.resAsResponse=!1,this.options=e,this.requestFunc=t}optionsFilter(e){return e.sessionId&&(e.url=ue(e.url,e.sessionId)),e}send(){this.startTime=Date.now();const{options:e}=this,t=Object.assign(e,{success:e=>{this.sourceResponse=e,this.costTime=Date.now()-this.startTime;let t=(this.resAsResponse?e:e.data)||{};if((0,i.Kg)(t))try{t=JSON.parse(t)}catch(e){t={}}this.response=t,this.emit("success"),this.emit("complete",0)},fail:e=>{this.costTime=Date.now()-this.startTime,this.emit("error",e),this.emit("complete",1)}});this.requestFunc(t)}}class de extends he{constructor(e){super(e,S.isMiniGamePlugin?S.pluginWx.request:S.wx.request)}optionsFilter(e){return e.timeout=e.timeout||3e4,e.header&&(e.header=Object.assign({"content-type":"application/json; charset=utf-8"},e.header||{})),e.method=e.method?e.method.toUpperCase():"GET",e.sessionId&&(e.url=ue(e.url,e.sessionId)),e}}class pe extends he{constructor(e){super(e,S.isMiniGamePlugin?S.pluginWx.uploadFile:S.wx.uploadFile)}}class ge extends he{constructor(){super({},S.isMiniGamePlugin?S.pluginWx.login:S.wx.login),this.resAsResponse=!0}}class me extends he{constructor(e){super(e,S.isMiniGamePlugin?S.pluginWx.downloadFile:S.wx.downloadFile),this.resAsResponse=!0}}class fe extends ce{constructor(e){super(e),this.login=this.initWxMethod({funcName:U.login,Constructor:ge,reportType:D.Login}),this.request=this.initWxMethod({funcName:U.request,Constructor:de,reportType:D.Request}),this.uploadFile=this.initWxMethod({funcName:U.uploadFile,Constructor:pe,reportType:D.UploadFile}),this.downloadFile=this.initWxMethod({funcName:U.downloadFile,Constructor:me,reportType:D.DownloadFile}),this.session=new le({login:this.login,request:this.request});const{pluginAppId:t=""}=e;this.pluginAppId=t}initWxMethod({funcName:e,Constructor:t,reportType:n}){const s=S.isMiniGamePlugin?S.pluginWx:S.wx;if(void 0!==s&&s[e]){const s={Constructor:t,funcName:e,reportType:n},i=e=>this.innerRequest(e||{},s);return e===U.request||e===U.uploadFile?this.initMethodNeedSession(i):i}console.warn(`[minigamfe${this.namespace}]: 当前环境不支持 ${e}`);return()=>new Promise(((e,t)=>{t(W.METHOD_IS_NOT_EXIST)}))}initMethodNeedSession(e){return t=>t.needSession?this.session.getSessionId(this.pluginAppId).then((n=>e(Object.assign(t,n)))).then((([n,s])=>{return 401===(null==s?void 0:s.statusCode)||("-1702220400"==`${i=n.errcode}`||"-1702220401"==`${i}`||"-1702220407"==`${i}`||"-1702220402"==`${i}`||"40001"==`${i}`)?(this.session.clearSessionId(),this.session.getSessionId(this.pluginAppId).then((n=>e(Object.assign(t,n))))):[n,s];var i})):e(t)}}class ye extends j{constructor(e){super(),this.startTime=0,this.costTime=0,this.isSupportNoStringifyReqData=!1,this.options=e,this.isSupportNoStringifyReqData=!!((0,i.Gm)(S.systemInfo.SDKVersion,"2.29.1")>=0)}optionsFilter(e){return e.sessionId&&e.data&&!e.data.session_id&&(e.data.session_id=e.sessionId),e.timeout=e.timeout||3e4,e}send(){this.startTime=Date.now();const{options:e}=this,{url:t,data:n,flat:s=!1,timeout:o}=e,r=n||{},a=r&&(0,i.Gv)(r);a&&(r[`requestTime_${(0,i.Ld)(10,!0)}`]=Date.now());let c={req_path:t,timeout:o,success:e=>{this.costTime=Date.now()-this.startTime,this.sourceResponse=e,this.response=function(e){const{rawData:t="",respData:n={}}=e,s=t||n.data||"";if(!s)return{};try{return JSON.parse(s)}catch(e){return{}}}(e),this.emit("success"),this.emit("complete",0)},fail:e=>{this.costTime=Date.now()-this.startTime,this.emit("error",e),this.emit("complete",1)}};if(!s){const e=a?JSON.stringify(r):r;this.isSupportNoStringifyReqData?(c.reqData={req_path:t,json_data:e},delete c.req_path):c.json_data=e}s&&a&&(this.isSupportNoStringifyReqData?(c.reqData=Object.assign({req_path:t},r),delete c.req_path):c=Object.assign(Object.assign({},r),c)),S.pluginEnv.gameTransfer(c)}}class ve extends fe{constructor(e){super(e),this.gameTransfer=this.initGameTransfer()}initGameTransfer(){if(S.pluginEnv.gameTransfer){const e={Constructor:ye,funcName:U.gameTransfer,reportType:D.GameTransfer},t=t=>this.innerRequest(t,e);return this.initMethodNeedSession(t)}console.warn(`[minigamfe${this.namespace}]: 当前插件不支持 gameTransfer。`);return()=>new Promise(((e,t)=>{t(W.GAMETRANSFER_IS_NOT_EXIST)}))}}const Se=Date.now();const Ie=new class{constructor(){this.version=oe,this.consts=V,this.env=S,this.util=s,this.config=F,this.reporter={GameTransferReport:J,KeyValueReporter:Q}}init(e){var t;if(console.log("[minigamefe mgp]: inited"),n.g.mgp=this,this.config.set(e),this.network=new ve({pluginAppId:this.config.get("pluginAppId")||S.pluginAppId||"",debug:this.config.get("debug")||!1,namespace:"mgp"}),!S.isMiniGamePlugin)return void console.warn("[minigamefe mgp]: please use mgp in minigame plugin");const{pluginEnv:s}=S;s.gameTransfer||s.reportKeyValue?(this.quality=new ae({debug:this.config.get("debug")&&this.config.get("logReport"),type:this.config.get("qualityReportType"),pluginAppId:this.config.get("pluginAppId")||S.pluginAppId||"",pluginVersion:this.config.get("pluginVersion")||S.pluginVersion||"",launchInfo:S.wx.getLaunchOptionsSync(),accountInfo:S.accountInfo,systemInfo:S.systemInfo,onShow:S.wx.onShow,onHide:S.wx.onHide,getNetworkType:S.wx.getNetworkType,onNetworkStatusChange:S.wx.onNetworkStatusChange,gameTransfer:null==S?void 0:S.pluginEnv.gameTransfer,reportKeyValue:null===(t=null==S?void 0:S.pluginEnv)||void 0===t?void 0:t.reportKeyValue,request:S.pluginWx.request,namespace:"mgp"}),this.network.setRequestQualityReporter(this.quality),this.quality.innerReport({Type:D.Default,Target:"init",CostTime:Date.now()-Se}),new k(this.quality)):(console.warn("[minigamefe mgp]: 当前环境不支持质量上报。"),this.quality={report:i.dv});const o=this.config.get("debug");s.getXLogManager?(this.xlog=new _({reportFunc:s.getXLogManager(),namespace:"mgp",base:{name:this.config.get("xlogName")},debug:o}),o&&console.info("[minigamefe mgp]: 当前插件已支持 xlog, 建议在关键操作打客户端日志。")):(this.xlog=console,o&&console.info("[minigamefe MGP]: 当前客户端不支持 xlog, 降级为 console。"))}}},228:e=>{"use strict";var t=Object.prototype.hasOwnProperty,n="~";function s(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,s,o,r){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new i(s,o||e,r),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function r(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,s,i=[];if(0===this._eventsCount)return i;for(s in e=this._events)t.call(e,s)&&i.push(n?s.slice(1):s);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=n?n+e:e,s=this._events[t];if(!s)return[];if(s.fn)return[s.fn];for(var i=0,o=s.length,r=new Array(o);i<o;i++)r[i]=s[i].fn;return r},a.prototype.listenerCount=function(e){var t=n?n+e:e,s=this._events[t];return s?s.fn?1:s.length:0},a.prototype.emit=function(e,t,s,i,o,r){var a=n?n+e:e;if(!this._events[a])return!1;var c,l,u=this._events[a],h=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),h){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,s),!0;case 4:return u.fn.call(u.context,t,s,i),!0;case 5:return u.fn.call(u.context,t,s,i,o),!0;case 6:return u.fn.call(u.context,t,s,i,o,r),!0}for(l=1,c=new Array(h-1);l<h;l++)c[l-1]=arguments[l];u.fn.apply(u.context,c)}else{var d,p=u.length;for(l=0;l<p;l++)switch(u[l].once&&this.removeListener(e,u[l].fn,void 0,!0),h){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,t);break;case 3:u[l].fn.call(u[l].context,t,s);break;case 4:u[l].fn.call(u[l].context,t,s,i);break;default:if(!c)for(d=1,c=new Array(h-1);d<h;d++)c[d-1]=arguments[d];u[l].fn.apply(u[l].context,c)}}return!0},a.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,s,i){var o=n?n+e:e;if(!this._events[o])return this;if(!t)return r(this,o),this;var a=this._events[o];if(a.fn)a.fn!==t||i&&!a.once||s&&a.context!==s||r(this,o);else{for(var c=0,l=[],u=a.length;c<u;c++)(a[c].fn!==t||i&&!a[c].once||s&&a[c].context!==s)&&l.push(a[c]);l.length?this._events[o]=1===l.length?l[0]:l:r(this,o)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&r(this,t)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a},504:e=>{function t(){}t.prototype={on:function(e,t,n){var s=this.e||(this.e={});return(s[e]||(s[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var s=this;function i(){s.off(e,i),t.apply(n,arguments)}return i._=t,this.on(e,i,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),s=0,i=n.length;s<i;s++)n[s].fn.apply(n[s].ctx,t);return this},off:function(e,t){var n=this.e||(this.e={}),s=n[e],i=[];if(s&&t)for(var o=0,r=s.length;o<r;o++)s[o].fn!==t&&s[o].fn._!==t&&i.push(s[o]);return i.length?n[e]=i:delete n[e],this}},e.exports=t,e.exports.TinyEmitter=t}},t={};function n(s){var i=t[s];if(void 0!==i)return i.exports;var o=t[s]={exports:{}};return e[s](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};(()=>{"use strict";n.r(s),n.d(s,{default:()=>rt});var e=n(347).A;const{env:t}=e;let i,o,r,a,c,l,u,h,d,p,g,m,f,y,v,S,I,T,w,b,E,M,P,R;if(t.isMiniGamePlugin){const{pluginEnv:e}=t,{customEnv:n}=e;i=t.wx,o=t.pluginWx,r=n.unityNamespace,a=n.canvas,c=n.document,b=n.events,E=n.WXWASMSDK,l=e.reportKeyValue||function(){console.warn("当前环境没有reportKeyValue函数!!")},u=e.gameTransfer||function(){console.warn("当前环境没有gameTransfer函数")},I=e.instanceId||"",S=e.setFileSpaceStatistics,T=e.getPrivateFileSystemManager,h=e.coverview,w=e.getWxCommonFont,M=e.createScreenCanvas,P=e.PIXI,R=e.TWEEN,h?({Component:d,getPrivateThis:p,removePrivateThis:g,create:m,init:f,webviewLayout:y,xmlParser:v}=h):d=class{}}else i=wx,r=GameGlobal.unityNamespace,a=GameGlobal.canvas,c=GameGlobal.document,l=function(){},u=function(){},d=function(){},p=function(e){return e},I="";r.isCacheableFile=r.isCacheableFile||function(e){return e.includes("StreamingAssets")};var A=n(7),L=n(72);const{systemInfo:C,accountInfo:O}=t,{pixelRatio:D,platform:x,benchmarkLevel:N,screenHeight:_,screenWidth:G,enableDebug:F,SDKVersion:k,version:W}=C,{miniProgram:U}=O||{},{envVersion:$=L.aM.DEVELOP}=(i.getFileSystemManager(),U||{}),j=$===L.aM.RELEASE,V=(L.aM.DEVELOP,F),q=!!r.enableDebugLog,B=!!V||!!t.isDevtools,K=((0,A.Gm)(k,"2.21.2"),!!h),H=t.isAndroid&&0===(0,A.Gm)(W,"8.0.25"),z=!!i.reportScene&&(0,A.Gm)(W,"8.0.27")>-1;r.instantiateWasm,t.isAndroid&&(0,A.Gm)(W,"8.0.34")>-1||t.isIOS&&(0,A.Gm)(W,"8.0.39");var X,J;a.id="",a.style.width=G,a.style.height=_,a.width=G*D,a.height=_*D,a.widthNative=0,a.heightNative=0,r.eventLog=function(...e){B&&console.log("[PLUGIN LOG]",...e)},r.timeLog=function(...e){console.log("[PLUGIN TIME LOG] ",...e)},function(e){e[e.GAME_LAUNCH=0]="GAME_LAUNCH",e[e.LOAD_SUBPACKAGE=1]="LOAD_SUBPACKAGE",e[e.COMPILE_WASM=2]="COMPILE_WASM",e[e.LOAD_ASSETS=3]="LOAD_ASSETS",e[e.UNZIP_ASSETS=4]="UNZIP_ASSETS",e[e.READ_ASSETS=5]="READ_ASSETS",e[e.PREPARE_GAME=6]="PREPARE_GAME",e[e.GAME_START=7]="GAME_START",e[e.LOAD_ASSET_BUNDLE=8]="LOAD_ASSET_BUNDLE",e[e.FILE_SYSTEM_INIT=9]="FILE_SYSTEM_INIT",e[e.GET_CONTEXT=10]="GET_CONTEXT",e[e.LOAD_BACKGROUND_IMAGE=11]="LOAD_BACKGROUND_IMAGE",e[e.COVER_VIEW_INIT=12]="COVER_VIEW_INIT",e[e.LAUNCH_OPERA_FRAME_START=13]="LAUNCH_OPERA_FRAME_START",e[e.LAUNCH_OPERA_FRAME_END=14]="LAUNCH_OPERA_FRAME_END",e[e.LAUNCH_OPERA_FRAME_CHECKPOINT=15]="LAUNCH_OPERA_FRAME_CHECKPOINT",e[e.LAUNCH_OPERA_FRAME_CHECKPOINT_COUNT=16]="LAUNCH_OPERA_FRAME_CHECKPOINT_COUNT"}(X||(X={})),function(e){e[e.normal=0]="normal",e[e.codeSplit=1]="codeSplit"}(J||(J={}));const Y={1:"webgl",2:"webgl2"};var Q;!function(e){e[e.ON_ABORT=100]="ON_ABORT",e[e.WaitingRemoveDependencies=101]="WaitingRemoveDependencies",e[e.WxABReadEmptyContent=102]="WxABReadEmptyContent"}(Q||(Q={}));class Z{static getInstance(){return this.instance||(this.instance=new this),this.instance}}const ee=class extends Z{constructor(){super(...arguments),this.data={},this.launchData=new Map}setData(e){this.data=Object.assign(Object.assign({},this.data),e)}addLaunchData(e){this.launchData.set(e.type,e)}getLaunchData(e){return this.launchData.get(e)}getAllLaunchData(){return Array.from(this.launchData.values())}}.getInstance();var te=function(e,t,n,s){return new(n||(n=Promise))((function(i,o){function r(e){try{c(s.next(e))}catch(e){o(e)}}function a(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};const ne=class extends Z{init(e){this.unityManager=e,this.initConfig()}initConfig(){return te(this,void 0,void 0,(function*(){}))}}.getInstance();var se,ie;!function(e){e.Mismatch="mismatch data size"}(se||(se={})),function(e){e.launchPlugin="launchPlugin",e.loadWasm="loadWasm",e.compileWasm="compileWasm",e.loadAssets="loadAssets",e.readAssets="readAssets",e.prepareGame="prepareGame",e.launchOperaInit="launchOperaInit",e.launchOperaMsgBridgeFromWasm="launchOperaMsgBridgeFromWasm",e.launchOperaPushMsgToWasm="launchOperaPushMsgToWasm",e.CreateWorker="createWorker"}(ie||(ie={}));var oe=n(228),re=n.n(oe);const ae=new class{constructor(){this.namespaces=new Map}getEventManager(e){return this.namespaces.has(e)||this.namespaces.set(e,new(re())),this.namespaces.get(e)}};const ce=(le="lifecycle",ae.getEventManager(le));var le,ue;!function(e){e.PluginLaunch="onPluginLaunch",e.LoadingPageReady="onLoadingPageReady",e.ParallelLoading="onParallelLoading",e.ParallelLoaded="onParallelLoaded",e.WasmLoading="onWasmLoading",e.WasmLoaded="onWasmLoaded",e.AssetLoading="onAssetLoading",e.AssetLoaded="onAssetLoaded",e.AssetProcessed="onAssetProcessed",e.WasmInstantiated="onWasmInstantiated",e.CalledMain="onCalledMain",e.FileSystemReady="onFileSystemReady",e.FeatureFlagReady="onFeatureFlagReady",e.ReporterReady="onReporterReady",e.InstanceReady="onInstanceReady",e.ModulePrepared="onModulePrepared",e.LaunchProgress="onLaunchProgress"}(ue||(ue={}));const he={[X.GAME_LAUNCH]:ie.launchPlugin,[X.LOAD_SUBPACKAGE]:ie.loadWasm,[X.COMPILE_WASM]:ie.compileWasm,[X.LOAD_ASSETS]:ie.loadAssets,[X.READ_ASSETS]:ie.readAssets,[X.PREPARE_GAME]:ie.prepareGame};class de{static getInstance(){return de.instance||(de.instance=new de),de.instance}init(e){const t=e;this.unityManager=t,this.bindFunction()}triggerEvent(e,t){ce.emit(e,t),e===ue.LaunchProgress&&(null==t?void 0:t.type)&&he[t.type]&&(null==b||b.emit(he[t.type],t))}bindFunction(){Object.values(ue).forEach((e=>{e===ue.LaunchProgress?this.unityManager[e]=t=>{"function"==typeof t&&ce.on(e,t);const n=ee.getAllLaunchData();(null==n?void 0:n.length)&&n.forEach((t=>this.triggerEvent(e,t)))}:this.unityManager[e]=t=>{"function"==typeof t&&ce.on(e,t)}}))}}const pe=de.getInstance();class ge{constructor(e,...t){this.type=e,this.content=t}}class me extends oe.EventEmitter{constructor(e="default"){super(),this.tag=e,this.maxLogs=300,this.logItems=[],this.isSupport=!1,wx.getGameLogManager?this.isSupport=!0:(this.isSupport=!1,console.warn("wx.getGameLogManager is not support")),this.generateLogFunc()}getInstance(e){return this.instance||(this.instance=new me(e)),this.instance}init(e){return!this.logger&&this.isSupport&&(this.logger=wx.getGameLogManager({commonInfo:e}),this.logger=this.logger.tag(this.tag),this.logItems.length>0&&(this.logItems.forEach((e=>{this.logger[e.type](...e.content)})),this.logItems=[])),this.logger}generateLogFunc(){["info","warn","error","debug"].forEach((e=>{this[e]=(...t)=>{this.isSupport&&(this.logger?this.logger[e](...t):(this.logItems.push(new ge(e,...t)),this.logItems.length>this.maxLogs&&this.logItems.shift()))}}))}}const fe=new me("time"),ye=new me("trace"),ve=new me("error");const{pixelRatio:Se}=C;const Ie=function(){const e=[];return t=>"string"==typeof t&&(!!(t.includes("end of list")||t.includes("still waiting on run dependencies")||t.includes("dependency"))&&(!!e.includes(t)||(e.push(t),!1)))}();function Te(e){if(e instanceof Error)return`${e.message}\n${e.stack}`;if(e&&"string"==typeof e.stack&&"string"==typeof e.message)return`${e.message}\n${e.stack}`;switch(typeof e){case"bigint":case"boolean":case"function":case"number":case"symbol":return e.toString();case"string":return e;case"undefined":return"undefined";case"object":{let t;try{t=JSON.stringify(e)}catch(e){t="[对象含有循环引用]"}return t}default:return}}class we{static timeStart(e){if(!we.timeMap.has(e)){const t=Date.now();return we.timeMap.set(e,t),t}return 0}static printTime(e){const t=e.indexOf("callMain耗时")>-1&&r.DO_RUN_START,n=e.indexOf("wasm编译耗时")>-1&&r.WASM_BEGIN_TIME;if(we.timeMap.has(e)||n||t){const t=we.timeEnd(e,!1),n=`[PLUGIN TIME LOG ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] ${e}: ${t}ms`;fe.info(n),console.log(n),we.timeStrList.push(n)}}static timeEnd(e,t=!0){const n=e.indexOf("callMain耗时")>-1&&r.DO_RUN_START,s=e.indexOf("wasm编译耗时")>-1&&r.WASM_BEGIN_TIME;if(we.timeMap.has(e)||n||s){const i=Date.now();let o=we.timeMap.get(e);return n&&(o=r.DO_RUN_START),s&&(o=r.WASM_BEGIN_TIME),t&&we.timeMap.delete(e),i-o}return 0}static getRuntime(e=!1){const t=Date.now()-we.logStartTime;return e?+(t/1e3).toFixed(2):t}static printRuntime(e){const t=`[PLUGIN TIME LOG ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] ${e}: ${we.getRuntime()}ms`;console.log(t),t.indexOf("游戏启动耗时")>-1&&(we.timeStrList.push(t),r.hideTimeLogModal||!r.showTimeLogInAllVersion&&$!==L.aM.DEVELOP||(i.showModal({title:"timelog",content:we.timeStrList.join("\r\n")}),we.timeStrList=[]))}static storeTime(e){we.storeTimeMap.has(e)||we.storeTimeMap.set(e,{CostTimeMs:we.timeEnd(e),RunTimeMs:we.getRuntime()})}static popTime(e){if(we.storeTimeMap.has(e)){const t=we.storeTimeMap.get(e);return we.storeTimeMap.delete(e),t}return null}}we.logStartTime=Date.now(),we.timeMap=new Map,we.storeTimeMap=new Map,we.timeStrList=[];class be{static eventLog(...e){ye.info(Array.from(e).map(Te).join(" ")),B&&console.log(`[PLUGIN LOG ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static debugLog(...e){B&&q&&console.log(`[DEBUG LOG ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static debugWarn(...e){B&&q&&console.warn(`[DEBUG WARN ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static debugError(...e){B&&q&&console.error(`[DEBUG ERROR ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static pluginLog(...e){B&&q&&console.log(`[PLUGIN LOG ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static pluginWarn(...e){B&&console.warn(`[PLUGIN WARN ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static pluginError(...e){ve.error(Array.from(e).map(Te).join(" ")),B&&console.error(`[PLUGIN ERROR ${(0,A.Yq)(Date.now(),"hh:mm.ss.SSS")}] `,...e)}static monitorLog(...e){B&&console.log("[PLUGIN MONITOR] ",...e)}static monitorWarn(...e){B&&console.warn("[PLUGIN MONITOR] ",...e)}}function Ee(e,t,...n){return new e(t,...n)}class Me{constructor(e){this.isVisible=!0,this.useCodeSplit=!!e.codeType}}class Pe extends Me{constructor(e,t,n){super(e),this.type=t,this.data={costTimeMs:n,runTimeMs:we.getRuntime(),isVisible:this.isVisible,useCodeSplit:this.useCodeSplit},delete this.isVisible,delete this.useCodeSplit}}const Re=[Math.pow(216,3),Math.pow(216,2),216,1];const Ae=wx.getFileSystemManager();class Le{static readCompressedFile(e){return new Promise(((t,n)=>{Ae.readCompressedFile({filePath:e,compressionAlgorithm:"br",success:e=>t(e.data),fail:n})}))}static readCompressedFileSyncCatch(e){return new Promise(((t,n)=>{try{t(Ae.readCompressedFileSync({filePath:e,compressionAlgorithm:"br"}))}catch(e){n(e)}}))}static readFile(e,n=void 0,s=!1){return new Promise(((s,i)=>{Ae.readFile({filePath:e,encoding:n,success:e=>{if(t.isIOS&&!t.isWK){const[t]=function(e){const t=e.byteLength;if(e.slice(-8).every(((e,t)=>11+t===e))){let n=1;const s=12,i=e.slice(-12,-8).reduce(((e,t,n)=>e+t*Re[n]),0),o=6;for(;n<=i;){const i=t-s-n*o,r=e[i],a=e[i+1]+200,c=e[i+2],l=e[i+3],u=e[i+4],h=e[i+5],d=c*Re[0]+l*Re[1]+u*Re[2]+h;e[d]=r,e[d+1]=a,n+=1}const r=(e[t-s-(n-1)*o-1]<<8)+e[t-s-(n-1)*o-2];for(let i=1;i<=r;i++)if(0!==e[t-s-(n-1)*o-2-i])return[e.buffer,!1];return[e.slice(0,t-s-(n-1)*o-r-2).buffer,!0]}if(e.slice(-8).every(((e,t)=>21+t===e))){const n=(e[t-9]<<8)+e[t-10];for(let s=1;s<=n;s++)if(0!==e[t-10-s])return[e.buffer,!1];return[e.slice(0,t-8-n-2).buffer,!0]}return[e.buffer,!1]}(new Uint8Array(e.data));e.data=t}s(e.data)},fail:i})}))}}const Ce=/[^:]\/{2,}/gi,Oe=/\.[./]+/gi,De=/[<>]+/gi;function xe(...e){return(null==e?void 0:e.length)?function(e){if(!(null==e?void 0:e.trim()))return"";return e.replace(Oe,"").replace(De,"").replace(Ce,(e=>e.replace(/\/+/g,"/")))}(e.filter((e=>{var t;return!!(null===(t=null==e?void 0:e.trim)||void 0===t?void 0:t.call(e))})).join("/")):""}function Ne(e){const t=r.STREAMING_CDN||r.DATA_CDN,n=r.streamingUrlPrefixPath||"",s=e.match(/(http|https|ftp|file):\/\//);let i=e;return s||(i=xe(t,n,e)),i}const _e={send(e){console.log("report21492 send:",e)},setBase(e){console.log("report21492 setBase:",e)}},Ge={send(e){console.log("report21493 send:",e)},setBase(e){console.log("report21493 setBase:",e)}};var Fe;!function(e){e.False="0",e.True="1"}(Fe||(Fe={}));class ke{constructor(e){Object.keys(e).forEach((t=>{this[t]=e[t]}))}}const We=class extends Z{constructor(){super(...arguments),this.subWasmModuleName="wasmcode1",this.retryCount=1,this.retryDuration=1500,this.pendingDuration=6e4,this.unityModuleInited=!1,this.invokeLoadWasmCode=e=>new Promise(((e,t)=>{const{unityManager:n}=this;pe.triggerEvent(ue.WasmLoading,Ee(Me,n)),we.timeStart("下载wasm代码包"),be.eventLog("开始下载wasm代码包"),pe.triggerEvent(ue.WasmLoaded,Ee(Me,n)),we.printTime("下载wasm代码包");const s=we.timeEnd("下载wasm代码包");n.triggerLaunchProgress(X.LOAD_SUBPACKAGE,s),n.loadingCount-=1,setTimeout((()=>{e()}),0)})).then((()=>{const{unityManager:e}=this;be.eventLog("start invoke UnityModule"),r.useDotnetRuntime?(be.eventLog("invoke UnityModule for dotnet"),e.gameInstance.Module.preInit=[()=>{be.eventLog("UnityModule preInit"),this.unityModuleInited=!0,pe.triggerEvent(ue.ModulePrepared),$e.processRawData()}],r.UnityModule(e.gameInstance.Module)):(be.eventLog("invoke UnityModule for il2cpp"),r.UnityModule(e.gameInstance.Module),this.unityModuleInited=!0,pe.triggerEvent(ue.ModulePrepared),$e.processRawData())}))}init(e){this.unityManager=e,this.initConfig()}loadWasmCode(){return(0,A.Mx)(this.invokeLoadWasmCode,this.retryCount,this.retryDuration)}parallelFetchSubWasm(){return be.eventLog("loadSubPackage1"),new Promise(((e,t)=>{we.timeStart("subWasmLoad"),r._subWasmLoading=!0,r._subWasmLoading=!1,r._subWasmLoaded=!0,console.log("[PLUGIN TIME LOG]下载小游戏分包1: ",we.timeEnd("subWasmLoad",!1),"ms"),be.eventLog("下载代码分包1完毕"),e()}))}initConfig(){const{CODE_FILE_MD5:e,GAME_NAME:t}=r;this.moduleName="wasmcode",this.md5=e,this.filename=`${this.md5}.${t}.wasm.code.unityweb.wasm.br`,this.wasmPath=`${this.moduleName}/${this.filename}`,this.unityManager.gameInstance.Module.wasmPath=this.wasmPath,ee.setData({useCodeSplit:this.unityManager.codeType===J.codeSplit})}}.getInstance();var Ue=function(e,t,n,s){return new(n||(n=Promise))((function(i,o){function r(e){try{c(s.next(e))}catch(e){o(e)}}function a(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};const $e=class extends Z{constructor(){super(...arguments),this.loadDataPackageFromSubpackage=!1,this.compressDataPackage=!1,this.packageName="data-package",this.retryCount=1,this.retryDuration=1500,this.pendingDuration=6e4,this.dataPackageLoaded=!1,this.preloadDataProcessed=!1,this.releaseAblePaths=[],this.processRawData=()=>{var e;const{unityManager:t}=this;if(this.preloadDataProcessed||!this.dataPackageLoaded||!We.unityModuleInited)return;const n=t.gameInstance.Module.rawData,s=new Uint8Array(n),i=new DataView(n);let o=0,a="";if(n&&this.checkPackageSize(n.byteLength)||(a=se.Mismatch),r.customProcessRawData&&"function"==typeof r.customProcessRawData)r.customProcessRawData(t.gameInstance.Module);else{const t=["UnityWebData1.0\0","TuanjieWebData1.0\0"];let c="",l="";for(const e of t)if(l=String.fromCharCode.apply(null,s.subarray(o,o+e.length)),l===e){c=l;break}if(be.pluginLog("prefix",l),c||a||(a="unknown data format"),a.length)throw this.handleDataError({errMsg:a,byteLength:null==n?void 0:n.byteLength,defaultSize:this.defaultSize,prefix:l}),a;o+=c.length;const u=i.getUint32(o,!0);for(o+=4,we.timeStart("解析资源");o<u;){const t=i.getUint32(o,!0);o+=4;const n=i.getUint32(o,!0);o+=4;const a=i.getUint32(o,!0);o+=4;const c=String.fromCharCode.apply(null,s.subarray(o,o+a));o+=a;for(let e=0,t=c.indexOf("/",e)+1;t>0;e=t,t=c.indexOf("/",e)+1)r.FS.createPath(c.substring(0,e),c.substring(e,t-1),!0,!0);(null===(e=null==c?void 0:c.includes)||void 0===e?void 0:e.call(c,"metadata.dat"))&&this.releaseAblePaths.push(c),r.FS.createDataFile(c,null,s.slice(t,t+n),!0,!0,!0)}}this.preloadDataProcessed=!0,t.gameInstance.Module.rawData=null,we.printTime("解析资源"),we.timeEnd("解析资源"),pe.triggerEvent(ue.AssetProcessed,Ee(Me,t)),t.gameInstance.Module.removeRunDependency("wasm-preloadAssets")},this.releaseDataPackage=()=>{this.releaseAblePaths.forEach((e=>{var t,n;try{null===(n=null==r?void 0:(t=r.FS).unlink)||void 0===n||n.call(t,e)}catch(e){be.pluginError(`删除首资源包meta段错误: ${e.message}`)}}))}}init(e,t){this.unityManager=e,this.initConfig(t)}loadDataPackage(){return Ue(this,void 0,void 0,(function*(){const{unityManager:e,downloadFilename:t}=this;try{pe.triggerEvent(ue.AssetLoading,Ee(Me,e)),this.loadDataPackageFromSubpackage?be.eventLog("通过小游戏分包加载资源",t,", 是否压缩=",this.compressDataPackage):be.eventLog("通过CDN加载资源",t);const n=`${this.packageName}/${t}`;return be.eventLog("从缓存加载首包资源"),be.pluginLog("加载路径: ",n),ee.setData({loadFromCache:!0}),e.loadingCount-=1,this.compressDataPackage?yield this.decompressPackage(n):yield this.readDataPackage(n),this.dataPackageLoaded=!0,ee.setData({assetContentLength:e.gameInstance.Module.rawData.byteLength}),pe.triggerEvent(ue.AssetLoaded,Ee(Me,e)),this.processRawData(),Promise.resolve()}catch(e){return be.pluginError("加载资源异常 ",e.errMsg||e.message,e),Promise.reject(e)}}))}readDataPackage(e){return Ue(this,void 0,void 0,(function*(){const{unityManager:t}=this;if(e){we.timeStart("读取资源文件");try{t.gameInstance.Module.rawData=yield Le.readFile(e,void 0,this.loadDataPackageFromSubpackage),we.printTime("读取资源文件"),this.printBufferContent(t.gameInstance.Module.rawData),t.triggerLaunchProgress(X.READ_ASSETS,we.timeEnd("读取资源文件",!1)),be.eventLog(`data content size=${t.gameInstance.Module.rawData.byteLength}`),_e.send(new ke({ReportType:X.READ_ASSETS,CostTimeMs:we.timeEnd("读取资源文件"),RunTimeMs:we.getRuntime(),ExternInfo:JSON.stringify({fileSize:t.gameInstance.Module.rawData.byteLength,defaultSize:this.defaultSize,optimalSize:this.optimalSize,compressDataPackage:this.compressDataPackage})}))}catch(e){let t=e;"number"==typeof e||"string"==typeof e||(t=e.errMsg||e.message),this.handleDataError({errMsg:t})}return Promise.resolve()}return Promise.reject("need asset path")}))}decompressPackage(e){return Ue(this,void 0,void 0,(function*(){const{unityManager:t}=this;we.timeStart("解压资源包耗时");const[n,s]=yield(0,A.NW)(Le.readCompressedFileSyncCatch(e));if(we.printTime("解压资源包耗时"),n||!(null==s?void 0:s.byteLength)){const e=(null==n?void 0:n.errMsg)||"empty content";return Ge.send({ReportType:X.UNZIP_ASSETS,ErrorMsg:e,RunTimeMs:we.getRuntime()}),be.pluginError(`解压资源失败, 加载方式: ${this.loadDataPackageFromSubpackage?"分包":"CDN"}, errMsg: `,e),Promise.reject(n||e)}return be.eventLog(`data decompressed size=${s.byteLength}`),t.triggerLaunchProgress(X.UNZIP_ASSETS,we.timeEnd("解压资源包耗时",!1)),_e.send(new ke({ReportType:X.UNZIP_ASSETS,CostTimeMs:we.timeEnd("解压资源包耗时"),RunTimeMs:we.getRuntime(),ExternInfo:JSON.stringify({fileSize:s.byteLength,defaultSize:this.defaultSize,optimalSize:this.optimalSize,compressDataPackage:this.compressDataPackage})})),t.gameInstance.Module.rawData=s,this.printBufferContent(s),Promise.resolve(s)}))}checkPackageSize(e){const t=!Number.isNaN(this.defaultSize)&&e===this.defaultSize,n=!Number.isNaN(this.optimalSize)&&e===this.optimalSize;return be.eventLog(`[datapackage] fileSize=${e}, defaultSize=${this.defaultSize}, optimalSize=${this.optimalSize}`),t||n}initConfig(e){const{loadDataPackageFromSubpackage:t,compressDataPackage:n}=e||{};this.loadDataPackageFromSubpackage=!!t,this.compressDataPackage=!!n;const{DATA_FILE_MD5:s,GAME_NAME:i,DATA_FILE_SIZE:o,OPT_DATA_FILE_SIZE:a}=r;this.md5=s,this.cacheFilename=`${this.md5}.${i}.data.unityweb.bin`;const c=r.dataFileSubPrefix||"";this.compressDataPackage?this.downloadFilename=`${this.cacheFilename}.br`:this.downloadFilename=`${this.cacheFilename}.txt`,this.unityManager.gameInstance.Module.preLoaDataPath=this.downloadFilename,this.cachePath=xe(c,this.cacheFilename),this.downloadPath=xe(c,this.downloadFilename),this.defaultSize=Number(o),this.optimalSize=Number(a)}handleDataError({errMsg:e,byteLength:t,defaultSize:n,optimalSize:s,prefix:i}){var o;null===(o=null==r?void 0:r.onCrash)||void 0===o||o.call(r),Ge.send(new ke({ReportType:X.READ_ASSETS,ErrorMsg:e,ExternInfo:JSON.stringify({byteLength:t,defaultSize:n,optimalSize:s,prefix:i,compressDataPackage:this.compressDataPackage})}))}printBufferContent(e){e&&be.eventLog("[datapackage] content=",new Uint8Array(e,0,64).toString())}}.getInstance();let je=0;function Ve(){return je}const qe=class extends Z{constructor(){super(...arguments),this.unityFsInited=!1,this.runDependencies=0,this.denpendencyIds=[],this.onAbort=e=>{var t;const{Module:n}=this.gameInstance,s=`abort(${e}) at ${(null===(t=null==e?void 0:e.stack)||void 0===t?void 0:t.toString)?e.stack.toString():n.stackTrace()}`;Ge.send(new ke({ReportType:Ve()||Q.ON_ABORT,ErrorMsg:`${s}`.slice(0,1024),RunTimeMs:we.getRuntime(),ExternInfo:JSON.stringify({isAbort:!0})})),ve.error(s)},this.wasmInstantiated=()=>{var e,t;const{unityManager:n}=this;pe.triggerEvent(ue.WasmInstantiated,Ee(Me,n)),we.printTime("wasm编译耗时"),n.triggerLaunchProgress(X.COMPILE_WASM,we.timeEnd("wasm编译耗时",!1)),_e.send(new ke({ReportType:X.COMPILE_WASM,CostTimeMs:we.timeEnd("wasm编译耗时"),RunTimeMs:we.getRuntime()}));const s=ot.getInstance();s&&s.wasmInited&&"function"==typeof s.wasmInited&&s.wasmInited(),n.codeType===J.codeSplit&&H&&(this.gameInstance.Module.addRunDependency("subWasmInstantiated"),null===(t=null===(e=null==r?void 0:r.compileSubWasm)||void 0===e?void 0:e.call(r))||void 0===t||t.then((()=>{this.gameInstance.Module.removeRunDependency("subWasmInstantiated")})))},this.calledMainCb=()=>{const{unityManager:e}=this;e.mainCalled=!0,pe.triggerEvent(ue.CalledMain,Ee(Me,e)),we.printTime("callMain耗时"),we.printRuntime("游戏启动耗时"),we.timeStart("游戏主场景耗时");const n=we.timeEnd("callMain耗时"),s=we.getRuntime();e.triggerLaunchProgress(X.PREPARE_GAME,n),ee.setData({callmainCost:n,launchTime:s}),_e.send(new ke({ReportType:X.PREPARE_GAME,CostTimeMs:n,RunTimeMs:s})),r.Browser&&(be.pluginLog("是默认启动页callMain完成开始游戏主循环"),r.Browser.mainLoop.resume()),$e.releaseDataPackage(),t.isWK||setTimeout((()=>{var e;null===(e=null==r?void 0:r.compileSubWasm)||void 0===e||e.call(r)}),3e4),j||setTimeout((()=>{e.gameStarted||be.pluginError("[开发阶段提示 不影响线上版本]请使用自定义上报能力 WX.ReportGameStart, 便于分析数据做启动优化, 文档: \nhttps://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/ReportStartupStat.md")}),6e4)},this.unityFileSystemInit=()=>{const{Module:e}=this.gameInstance;e.indexedDB||be.pluginWarn("IndexedDB is not available. Data will not persist in cache and PlayerPrefs will not be saved."),r.FS.mkdir("/idbfs"),r.FS.mount(r.IDBFS,{},"/idbfs"),this.unityFsInited=!0,e.rawData&&e.processRawData()},this.printErr=e=>{const{unityManager:t}=this,n="string"==typeof e?e:e.message;!t.gameStarted&&we.getRuntime()<6e4&&(Ie(e)||Ge.send(new ke({ReportType:Ve(),ErrorMsg:`${n}`.slice(0,1024),RunTimeMs:we.getRuntime(),ExternInfo:JSON.stringify({mainCalled:t.mainCalled})}))),(null==t?void 0:t.onLogError)&&t.onLogError(n),console.error(e)},this.monitorRunDependencies=(e,t)=>{t&&(e<this.runDependencies?this.denpendencyIds=this.denpendencyIds.filter((e=>e!==t)):this.denpendencyIds.push(t)),this.runDependencies=e,0===this.runDependencies&&be.eventLog("no dependencies, invoke run")}}init(e){this.unityManager=e,this.initInstance(),this.checkDependenciesRemoved(),e.printErr=this.printErr.bind(this)}checkDependenciesRemoved(){setTimeout((()=>{0!==this.runDependencies&&(be.pluginError("still waiting runDependencies, ids=",this.denpendencyIds),Ge.send(new ke({ReportType:Q.WaitingRemoveDependencies,ExternInfo:JSON.stringify({runDependencies:this.runDependencies,denpendencyIds:this.denpendencyIds})})))}),3e4)}initInstance(){this.gameInstance={gameInstance:this.gameInstance,onProgress:void 0,compatibilityCheck:void 0,Module:{IsWxGame:!0,preLoadDataPath:$e.downloadFilename,wasmPath:We.wasmPath,graphicsAPI:["WebGL 2.0","WebGL 1.0"],instantiateWasm:r.instantiateWasm,onAbort:this.onAbort.bind(this),monitorRunDependencies:this.monitorRunDependencies.bind(this),wasmInstantiated:this.wasmInstantiated.bind(this),onRuntimeInitialized(){},calledMainCb:this.calledMainCb.bind(this),unityFileSystemInit:this.unityFileSystemInit.bind(this),tuanjieFileSystemInit:this.unityFileSystemInit.bind(this),processRawData:$e.processRawData,preRun:[],postRun:[],print(e){console.log(e)},printErr:this.printErr.bind(this),Jobs:{},canvas:a,buildDownloadProgress:{},resolveBuildUrl:Ne,streamingAssetsUrl:()=>Ne("StreamingAssets"),pthreadMainPrefixURL:"Build/",webglContextAttributes:{premultipliedAlpha:1,preserveDrawingBuffer:1}},SetFullscreen:(...e)=>{if(this.gameInstance.Module.SetFullscreen)return this.gameInstance.Module.SetFullscreen.apply(this.gameInstance.Module,...e)},SendMessage:(...e)=>{if(this.gameInstance.Module.SendMessage)return this.gameInstance.Module.SendMessage.apply(this.gameInstance.Module,...e)},popup:(e,t)=>r.UnityLoader.Error.popup(this.gameInstance,e,t)},this.unityManager.gameInstance=this.gameInstance,r.Module=this.gameInstance.Module}}.getInstance();class Be{constructor(e){const t=e.getAllResponseHeaders(),n=new Map;t.trim().split(/[\r\n]+/).forEach((e=>{const t=e.split(": "),s=t.shift(),i=t.join(": ");n.set(s,i)})),this.headers=n,this.url=e.paramsCache.url,this.ok=!!(e.status>=200&&e.status<300),this.status=e.status,this.statusText=e.statusText,this.parsedBody=new Uint8Array(e.response),this.originXHR=e}}var Ke,He=n(347).A,ze=function(e,t,n,s){return new(n||(n=Promise))((function(i,o){function r(e){try{c(s.next(e))}catch(e){o(e)}}function a(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))};!function(e){e[e.Fail=0]="Fail",e[e.Ok=1]="Ok"}(Ke||(Ke={}));class Xe{constructor(e){this.status=e.status,this.errMsg=e.errMsg,this.cachePath=e.xhrObj.cachePath,this.response=e.xhrObj.response,this.cacheable=e.xhrObj.cacheable,this.isReadFromCache=e.xhrObj.isReadFromCache}}class Je{constructor(){this.status=void 0,this.statusText=void 0,this.reqId="",this.cacheable=!1,this.isReadFromCache=!1,this.isFetchApi=!1,this.ignoreCallback=!1,this.skipOldCacheClean=!1,this.signal={aborted:!1},this.openAndSend=(e,t)=>(this.isFetchApi=!0,this.open(t.method,e,!0),this.responseType="arraybuffer",Object.keys(t.headers).forEach((e=>{this.setRequestHeader(e,t.headers[e])})),this.timeout=t.timeout,this.onprogress=t.onProgress,new Promise(((e,n)=>{this.onFetchResolve=()=>{e(new Be(this))},this.onFetchReject=e=>{const t=new Be(this);t.message=(null==e?void 0:e.errMsg)||(null==e?void 0:e.message)||"",n(t)},this.send(t.body)}))),this.send=(...e)=>ze(this,void 0,void 0,(function*(){console.warn("UnityWebRequest not supported")})),this.open=(e,t,n,...s)=>{this.paramsCache={method:e,url:t,async:n},this.originXhr.open(e,t,n,...s),this.onload=()=>{},this.onerror=()=>{},this.ontimeout=()=>{},this.onabort=()=>{},He.env.isPC&&this.setRequestHeader("Cache-Control","no-cache")},this.bindEvent=()=>{const e=["readyState","response","responseText","responseURL","responseXML","status","statusText"];["readyState","response","responseText","responseType","responseURL","responseXML","status","statusText","timeout","upload","withCredentials","onloadstart","onprogress","onabort","onerror","onload","ontimeout","onloadend","onreadystatechange"].forEach((t=>{Object.defineProperty(this,t,{get:()=>e.includes(t)&&this[`_${t}`]||this.originXhr[t],set:n=>{"onload"===t?this.originXhr[t]=e=>{this.isFetchApi?this.triggerEvent("FetchResolve"):n(e),this.triggerEvent("complete",new Xe({xhrObj:this,status:Ke.Ok}))}:"onerror"===t||"ontimeout"===t||"onabort"===t?this.originXhr[t]=e=>{this.isFetchApi?this.triggerEvent("FetchReject",e):n(e),this.triggerEvent("complete",new Xe({xhrObj:this,status:Ke.Fail,errMsg:`${t}_${this.statusText}`}))}:e.includes(t)?this[`_${t}`]=n:this.originXhr[t]=n}})})),["abort","getAllResponseHeaders","getResponseHeader","overrideMimeType","addEventListener","setRequestHeader"].forEach((e=>{Object.defineProperty(this,e,{value:(...t)=>{if("abort"===e&&(this.signal.aborted=!0),"setRequestHeader"===e){if("wechatminigame-preload"===t[0])return void(this.ignoreCallback="1"===t[1]);if("wechatminigame-skipclean"===t[0])return void(this.skipOldCacheClean="0"===t[1])}return this.originXhr[e](...t)}})}))},this.createResponse=({data:e,statusCode:t=200})=>{void 0!==t&&(this.status=t),e&&(this.response=e)},this.triggerEvent=(e,...t)=>{const n=this[`on${e}`];n&&n.apply(this,t||[])},this.originXhr=new r.XMLHttpRequest,this.paramsCache={},this.bindEvent(),this.reqId=function(e){const t=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];let n="";for(let s=0;s<e;s++)n+=t[Math.floor(36*Math.random())];return n}(10)}}Je.hasUnityAnalysisLoged=!1;const Ye=Je;var Qe;!function(e){e.zhCn="zh-cn",e.enUs="en-us"}(Qe||(Qe={}));const Ze=Qe.zhCn;let et=Qe.zhCn;const tt=new Map([["程序遇到错误",new Map([[Qe.enUs,"Fatal Error"]])],['可尝试重启游戏\n或通过"右上角菜单-反馈与投诉"提交功能异常反馈',new Map([[Qe.enUs,"Try restarting the game"]])],["重启游戏",new Map([[Qe.enUs,"Restart the game"]])],["确定",new Map([[Qe.enUs,"Confirm"]])],["提示",new Map([[Qe.enUs,"Tips"]])],["当前微信为32位版本\n请升级最新版本",new Map([[Qe.enUs,"The current App is a 32-bit version \n please upgrade to the latest version"]])],["确认升级",new Map([[Qe.enUs,"Confirm upgrade"]])],["不支持",new Map([[Qe.enUs,"Not supported"]])],["请升级",new Map([[Qe.enUs,"Please upgrade"]])],["系统",new Map([[Qe.enUs,"System"]])],["微信",new Map([[Qe.enUs,"Application"]])],["资源下载失败",new Map([[Qe.enUs,"Resource download failed"]])],["\n请从 微信-小程序-最近使用 重新打开",new Map([[Qe.enUs,"\nRestart the game"]])],["下载wasm代码包失败",new Map([[Qe.enUs,"Failed to download the wasm code package"]])]]);function nt(e){if(et===Ze)return e;if(tt.has(e)){const t=tt.get(e);if(null==t?void 0:t.has(et))return t.get(et)}return e}var st=function(e,t,n,s){return new(n||(n=Promise))((function(i,o){function r(e){try{c(s.next(e))}catch(e){o(e)}}function a(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))},it=function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(s=Object.getOwnPropertySymbols(e);i<s.length;i++)t.indexOf(s[i])<0&&Object.prototype.propertyIsEnumerable.call(e,s[i])&&(n[s[i]]=e[s[i]])}return n};class ot{static getInstance(){return ot.instance}set loadingCount(e){this.localLoadingCount=e}get loadingCount(){return this.localLoadingCount}constructor(e={}){if(this.codeType=0,this.mainCalled=!1,this.gameStarted=!1,this.useCoverView=!1,this.hideAfterCallmain=!0,this.contextType=1,this.isVisible=!0,this.TimeLogger=we,this.Logger=be,this.localLoadingCount=2,this.reportPluginLaunchScene=(e,t)=>{const n={sceneId:e,costTime:t,dimension:{useCodeSplit:this.codeType?Fe.True:Fe.False,needDownloadDataPackage:Fe.True}};this.baseReportScene(n)},this.baseReportScene=e=>{z&&wx.reportScene(e)},this.showAbort=()=>{console.warn("An error occurred")},ot.instance)return this;var t;t=e.language,et=t,pe.init(this),this.init(e),ne.init(this)}init(e){const{videoManager:n,finalPageVideoUrl:s,pageManager:i,loadingPageConfig:o,useCoverView:a,hideAfterCallmain:c,preloadDataList:l,loadDataPackageFromSubpackage:u=!1,compressDataPackage:h=!1,contextConfig:d={}}=e,p=it(e,["videoManager","finalPageVideoUrl","pageManager","loadingPageConfig","useCoverView","hideAfterCallmain","preloadDataList","loadDataPackageFromSubpackage","compressDataPackage","contextConfig"]);this.gameInstance=null,this.mainCalled=!1,this.gameStarted=!1,this.useCoverView=K,this.hideAfterCallmain=!!c,this.contextType=d.contextType||1,this.codeType=r.useWasmCodeSplit?J.codeSplit:J.normal,we.timeStart("getContext");if(r.globalGL=canvas.getContext(Y[this.contextType],{alpha:!0,stencil:!0,antialias:!1,powerPreference:"high-performance"}),we.storeTime("getContext"),!r.globalGL){const e=`${nt("不支持")}${Y[this.contextType]}, ${nt("请升级")}${t.isIOS?nt("系统"):nt("微信")}`;be.pluginError(e),wx.showModal({title:nt("提示"),content:e,showCancel:!1,success(){}}),setTimeout((()=>{throw new Error(e)}),0)}this.initGameGlobal(p),qe.init(this),$e.init(this,{loadDataPackageFromSubpackage:u,compressDataPackage:h}),We.init(this),ne.init(this),ot.instance=this}initGameGlobal(e={}){Object.entries(e).forEach((([e,t])=>{if(["STREAMING_CDN","DATA_CDN"].includes(e)&&t.includes("http")){const n=t.endsWith("/")?t:`${t}/`;r[e]=n}else r[e]=t})),r.UnityLoader={SystemInfo:{width:G,height:_,gpu:(()=>{const e=canvas.getContext(Y[this.contextType]);if(e){const t=e.getExtension("WEBGL_debug_renderer_info");if(t)return e.getParameter(t.UNMASKED_RENDERER_WEBGL)}return"unknown"})(),browser:"wx",browserVersion:"0.0",language:r.navigator.userLanguage||r.navigator.language,hasWebGL:this.contextType},UnityCache:{XMLHttpRequest:Ye}}}triggerLaunchProgress(e,t){const n=Ee(Pe,this,e,t);this.reportPluginLaunchScene(e,t),ee.addLaunchData(n),pe.triggerEvent(ue.LaunchProgress,n)}startGame(){return st(this,void 0,void 0,(function*(){if(this.mainCalled)return;pe.triggerEvent(ue.LoadingPageReady,Ee(Me,this)),this.startCheckIs32Wechat();const e=[We.loadWasmCode(),$e.loadDataPackage()];return pe.triggerEvent(ue.ParallelLoading,Ee(Me,this)),Promise.all(e).then((()=>{pe.triggerEvent(ue.ParallelLoaded,Ee(Me,this)),this.start()}))}))}start(){return st(this,void 0,void 0,(function*(){}))}startCheckIs32Wechat(){C.abi&&!C.abi.includes("64")&&setTimeout((()=>{this.mainCalled||(be.pluginError("当前是32位微信请升级最新版本"),wx.showModal({title:nt("提示"),content:nt("当前微信为32位版本\n请升级最新版本"),showCancel:!1,confirmText:nt("确认升级"),success(){wx.updateWeChatApp()}}))}),3e4)}}const rt=ot})(),module.exports=s})();