asai-js-as 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e={659:function(e,t){var o=this&&this.__assign||function(){o=Object.assign||function(e){for(var t,o=1,i=arguments.length;o<i;o++){t=arguments[o];for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n))e[n]=t[n]}return e};return o.apply(this,arguments)};var i=this&&this.__awaiter||function(e,t,o,i){function adopt(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,n){function fulfilled(e){try{step(i.next(e))}catch(e){n(e)}}function rejected(e){try{step(i["throw"](e))}catch(e){n(e)}}function step(e){e.done?o(e.value):adopt(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))};var n=this&&this.__generator||function(e,t){var o={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,n,s,r=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return r.next=verb(0),r["throw"]=verb(1),r["return"]=verb(2),typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function verb(e){return function(t){return step([e,t])}}function step(a){if(i)throw new TypeError("Generator is already executing.");while(r&&(r=0,a[0]&&(o=0)),o)try{if(i=1,n&&(s=a[0]&2?n["return"]:a[0]?n["throw"]||((s=n["return"])&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;if(n=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:o.label++;return{value:a[1],done:false};case 5:o.label++;n=a[1];a=[0];continue;case 7:a=o.ops.pop();o.trys.pop();continue;default:if(!(s=o.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){o.label=a[1];break}if(a[0]===6&&o.label<s[1]){o.label=s[1];s=a;break}if(s&&o.label<s[2]){o.label=s[2];o.ops.push(a);break}if(s[2])o.ops.pop();o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e];n=0}finally{i=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};Object.defineProperty(t,"__esModule",{value:true});var s=function(){function AsaiWorker(e,t){if(t===void 0){t=navigator.hardwareConcurrency||4}this.taskQueue=[];this.workers=new Map;this.taskMap=new Map;this.taskId=0;this.workerScript=e;this.maxWorkers=t}AsaiWorker.prototype.execute=function(e){return i(this,void 0,void 0,(function(){var t=this;return n(this,(function(o){return[2,new Promise((function(o,i){var n=t.taskId++;t.taskQueue.push({taskId:n,taskData:e});t.taskMap.set(n,{resolve:o,reject:i});t._processNext()}))]}))}))};AsaiWorker.prototype._createWorker=function(){var e=this;var t=new Worker(this.workerScript,{type:"module"});t.onmessage=function(o){var i=o.data,n=i.taskId,s=i.result,r=i.error;var a=e.taskMap.get(n);if(a){if(r){a.reject(r)}else{a.resolve(s)}e.taskMap.delete(n)}e.workers.delete(t);t.terminate();e._processNext()};t.onerror=function(o){console.error("Worker error:",o);e.workers.delete(t);e._createWorker()};this.workers.set(t,true);return t};AsaiWorker.prototype._processNext=function(){while(this.taskQueue.length>0&&this.workers.size<this.maxWorkers){var e=this.taskQueue.shift();var t=this._createWorker();t.postMessage({taskId:e.taskId,data:e.taskData})}};AsaiWorker.prototype.terminateAll=function(){this.workers.forEach((function(e,t){return t.terminate()}));this.workers.clear();this.taskQueue=[]};return AsaiWorker}();var r=function(){function AsaiApi(e){if(e===void 0){e={}}this.interceptors={request:[],response:[]};this.defaultConfig={headers:{"Content-Type":"application/json"},cache:"reload",timeout:1e4};this.totalApi=0;this.baseURL=e.baseURL;this.ujt=e.ujt}AsaiApi.prototype.api=function(e){return i(this,arguments,void 0,(function(e,t){var i,s,r,a,l,u,d,v,c,f,p,h,w,g;var m=this;var k,y,b,j,A,W;if(t===void 0){t={}}return n(this,(function(n){switch(n.label){case 0:i=0;s=0;if((b=(y=(k=this.ujt)===null||k===void 0?void 0:k.$global)===null||y===void 0?void 0:y.sys)===null||b===void 0?void 0:b.onconsole){this.totalApi++;this.totalApi>1e4&&(this.totalApi=0);s=this.totalApi;i=Date.now()%1e7}r=new AbortController;a=r.signal;l=setTimeout((function(){return r.abort()}),t.timeout||this.defaultConfig.timeout);n.label=1;case 1:n.trys.push([1,5,,6]);u={url:this.baseURL+e};if(t.body instanceof FormData){u.opt=t}else{u.opt=o(o(o({},this.defaultConfig),t),{signal:a,headers:o(o({},this.defaultConfig.headers),t.headers)})}i&&((W=(A=(j=this.ujt)===null||j===void 0?void 0:j.$fn)===null||A===void 0?void 0:A.lo)===null||W===void 0?void 0:W.call(A,2,"Req"+s,u));d=Promise.resolve(u);this.interceptors.request.forEach((function(e){d=d.then((function(t){return e(t)}))}));return[4,d];case 2:v=n.sent(),c=v.url,f=v.opt;return[4,fetch(c,f)];case 3:p=n.sent();clearTimeout(l);return[4,this._parseResponse(p)];case 4:h=n.sent();w=Promise.resolve(this._getRes(h,t));this.interceptors.response.forEach((function(e){w=w.then((function(t){var o,n,r;i&&((r=(n=(o=m.ujt)===null||o===void 0?void 0:o.$fn)===null||n===void 0?void 0:n.lo)===null||r===void 0?void 0:r.call(n,3,"Res"+s+" "+(Date.now()%1e7-i)+"ms",t));return e(t)}))}));return[2,w];case 5:g=n.sent();clearTimeout(l);throw this._handleError(g);case 6:return[2]}}))}))};AsaiApi.prototype.apiGet=function(e,t,i){if(t===void 0){t={}}if(i===void 0){i={}}var n=new URLSearchParams(t).toString();var s=this._getReq("get",n,i);return this.api("".concat(e).concat(s?"?"+s:""),o(o({},i),{method:"GET"}))};AsaiApi.prototype.apiPost=function(e,t,i){if(i===void 0){i={}}return this.api(e,o(o({},i),{method:"POST",body:t instanceof FormData?t:this._stringifyData(this._getReq("post",t,i),i.headers)}))};AsaiApi.prototype.apiUpload=function(e,t,i){var n=new FormData;n.append("file",t);return this.apiPost(e,n,o({},i))};AsaiApi.prototype.apiDownload=function(e,t){return this.apiGet(e,null,{responseType:"blob"}).then((function(e){var o=document.createElement("a");o.href=URL.createObjectURL(e);o.download=t;o.click()}))};AsaiApi.prototype._getReq=function(e,t,o){var i,n,s,r,a,l;if((o===null||o===void 0?void 0:o.mm)&&((s=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.AsCode)===null||s===void 0?void 0:s.asdecode)&&((l=(a=(r=this.ujt)===null||r===void 0?void 0:r.$global)===null||a===void 0?void 0:a.code)===null||l===void 0?void 0:l.pri)&&t){t=this.ujt.$fn.AsCode.asencode(typeof t==="string"?t:JSON.stringify(t),this.ujt.$global.code.pri);if(t&&e==="get"){t="pm="+encodeURIComponent(t)}}return t};AsaiApi.prototype._getRes=function(e,t){var o,i,n,s,r,a;if((t===null||t===void 0?void 0:t.mm)&&((n=(i=(o=this.ujt)===null||o===void 0?void 0:o.$fn)===null||i===void 0?void 0:i.AsCode)===null||n===void 0?void 0:n.asdecode)&&((a=(r=(s=this.ujt)===null||s===void 0?void 0:s.$global)===null||r===void 0?void 0:r.code)===null||a===void 0?void 0:a.pri)&&(e===null||e===void 0?void 0:e.data)&&typeof e.data==="string"){e.data=this.ujt.$fn.AsCode.asdecode(e.data,this.ujt.$global.code.pri);try{e.data=JSON.parse(e.data)}catch(e){}}return e};AsaiApi.prototype._parseResponse=function(e){var t=e.headers.get("content-type");if(t===null||t===void 0?void 0:t.includes("application/json")){return e.json()}if(t===null||t===void 0?void 0:t.includes("text/")){return e.text()}return e.blob()};AsaiApi.prototype._stringifyData=function(e,t){var o=t===null||t===void 0?void 0:t["Content-Type"];if(e instanceof FormData)return e;if(typeof e==="string")return e;if(o==="application/json"||typeof e==="object")return JSON.stringify(e);return String(e)};AsaiApi.prototype._handleError=function(e){if(e.name==="AbortError"){return{code:504,message:"Request Timeout"}}return{code:500,message:e.message||"Network Error"}};AsaiApi.prototype.ictReq=function(e){this.interceptors.request.push(e)};AsaiApi.prototype.ictRes=function(e){this.interceptors.response.push(e)};return AsaiApi}();var a=function(){function AsaiWs(e){if(e===void 0){e={}}var t=this;var o,i,n,s,r,a,l,u;this.reconnectAttempts=0;this.maxReconnectDelay=0;this.messageQueue=[];this.isSending=false;this.wstaskMap=new Map;this.workerState=false;this.totalWs=0;this.wsname=e.wsname;this.wsworker=e.wsworker;this.wssec=e.wssec;this.wsurl=e.wsurl;this.ujt=e.ujt;this.baseURL=e.baseURL;if((s=(n=(i=(o=this.ujt.$global.link)===null||o===void 0?void 0:o.ws)===null||i===void 0?void 0:i[this.wsname])===null||n===void 0?void 0:n.config)===null||s===void 0?void 0:s.tmdeltask){this.cleanupInterval=setInterval((function(){if(t.wstaskMap.size){var e=Date.now();t.wstaskMap.forEach((function(o,i){var n,s,r,a;if(!o.type&&o.timestamp&&e-o.timestamp>((a=(r=(s=(n=t.ujt.$global.link)===null||n===void 0?void 0:n.ws)===null||s===void 0?void 0:s[t.wsname])===null||r===void 0?void 0:r.config)===null||a===void 0?void 0:a.tmdeltask)/2){t.wstaskMap.delete(i)}}))}}),(u=(l=(a=(r=this.ujt.$global.link)===null||r===void 0?void 0:r.ws)===null||a===void 0?void 0:a[this.wsname])===null||l===void 0?void 0:l.config)===null||u===void 0?void 0:u.tmdeltask)}}AsaiWs.prototype.Uuid=function(e,t,o){if(e===void 0){e=""}if(t===void 0){t=0}if(o===void 0){o=32}var i=[Date.now().toString(36).slice(-9),t.toString(36),e.slice(-3),crypto.getRandomValues(new Uint8Array(6)).reduce((function(e,t){return e+(t&15).toString(o)}),"")];return i.join("").slice(0,16)};AsaiWs.prototype.wsSend=function(e){if(typeof e==="object"){e=JSON.stringify(e)}this.wsSendMsg(e)};AsaiWs.prototype.wsApi=function(e){var t=this;return new Promise((function(i,n){var s,r,a;var l=0;if((a=(r=(s=t.ujt)===null||s===void 0?void 0:s.$global)===null||r===void 0?void 0:r.sys)===null||a===void 0?void 0:a.onconsole){l=Date.now()%1e7}var u;try{if(e==="ping"){u="ping"}else if(!e){u={id:t.Uuid("ws")};e=JSON.stringify(u)}else if(typeof e==="object"){u=o({},e);if(!(u===null||u===void 0?void 0:u.id)){u.id=t.Uuid("ws")}e=JSON.stringify(u)}else{u=JSON.parse(e);if(!(u===null||u===void 0?void 0:u.id)){u.id=t.Uuid("ws");e=JSON.stringify(u)}}}catch(e){}t.wsWatchDo(u,(function(e){var o,n,s,r,a,u;if(l){l=Date.now()%1e7-l;((s=(n=(o=t.ujt)===null||o===void 0?void 0:o.$global)===null||n===void 0?void 0:n.sys)===null||s===void 0?void 0:s.onconsole)&&((u=(a=(r=t.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.lo)===null||u===void 0?void 0:u.call(a,5,"wsGet:"+l+"ms",e))}i(e)}))}))};AsaiWs.prototype.wsWatch=function(e,t){var o,i,n,s,r,a;((n=(i=(o=this.ujt)===null||o===void 0?void 0:o.$global)===null||i===void 0?void 0:i.sys)===null||n===void 0?void 0:n.onconsole)&&((a=(r=(s=this.ujt)===null||s===void 0?void 0:s.$fn)===null||r===void 0?void 0:r.lo)===null||a===void 0?void 0:a.call(r,3,"wsWatch",e));this.wsWatchDo(e,t)};AsaiWs.prototype.wsWatchDo=function(e,t){var i=this.getKeyByData(e);var n={};if(e!=="ping"){if(typeof e=="object"&&(e===null||e===void 0?void 0:e.id)){n={type:0,timestamp:Date.now()}}else{n={type:1}}}this.wstaskMap.set(i,o({callback:t},n));this.wsSend(e)};AsaiWs.prototype.wsWatchOff=function(e){var t,o,i,n,s,r;((i=(o=(t=this.ujt)===null||t===void 0?void 0:t.$global)===null||o===void 0?void 0:o.sys)===null||i===void 0?void 0:i.onconsole)&&((r=(s=(n=this.ujt)===null||n===void 0?void 0:n.$fn)===null||s===void 0?void 0:s.lo)===null||r===void 0?void 0:r.call(s,6,"wsWatchOff:"+this.wstaskMap.size,e));!e.off&&(e.off=1);this.wsSend(e);var a=this.getKeyByData(e);var l=this.wstaskMap.get(a);if(l){this.wstaskMap.delete(a)}};AsaiWs.prototype.wsWatchWork=function(e){var t,o,i,n,s,r;var a=this.getKeyByData(e);var l=this.wstaskMap.get(a);if(l){l.callback(e);if(!l.type){((i=(o=(t=this.ujt)===null||t===void 0?void 0:t.$global)===null||o===void 0?void 0:o.sys)===null||i===void 0?void 0:i.onconsole)&&((r=(s=(n=this.ujt)===null||n===void 0?void 0:n.$fn)===null||s===void 0?void 0:s.lo)===null||r===void 0?void 0:r.call(s,3,"wsDelete:"+this.wstaskMap.size,a));this.wstaskMap.delete(a)}}};AsaiWs.prototype.wsSendMsg=function(e){return i(this,void 0,void 0,(function(){var t;var o,i,s,r,a,l;return n(this,(function(n){switch(n.label){case 0:if(!(e==="ping"))return[3,2];return[4,this.sendSingleMessage(e)];case 1:n.sent();return[3,6];case 2:this.messageQueue.push(e);if(!!this.isSending)return[3,6];this.isSending=true;n.label=3;case 3:if(!(this.messageQueue.length>0))return[3,5];t=this.messageQueue.shift();if((s=(i=(o=this.ujt)===null||o===void 0?void 0:o.$global)===null||i===void 0?void 0:i.sys)===null||s===void 0?void 0:s.onconsole){this.totalWs++;this.totalWs>1e4&&(this.totalWs=0);(l=(a=(r=this.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.lo)===null||l===void 0?void 0:l.call(a,4,"wsSend"+this.totalWs+":"+this.messageQueue.length,t)}return[4,this.sendSingleMessage(t)];case 4:n.sent();return[3,3];case 5:this.isSending=false;n.label=6;case 6:return[2]}}))}))};AsaiWs.prototype.sendSingleMessage=function(e){var t=this;return new Promise((function(o,i){t.init().then((function(){var n,s,r,a,l,u,d,v,c,f,p,h,w,g,m,k,y,b;if(t.wsworker){if(typeof((s=(n=t.ujt.$fn.workers[t.wsname])===null||n===void 0?void 0:n.instance)===null||s===void 0?void 0:s.postMessage)==="function"){(a=(r=t.ujt.$fn.workers[t.wsname])===null||r===void 0?void 0:r.instance)===null||a===void 0?void 0:a.postMessage({type:"send",data:e});o()}else{i()}}else{if(((l=t.ujt.$fn.ws[t.wsname].socket)===null||l===void 0?void 0:l.readyState)===WebSocket.OPEN){t.ujt.$fn.ws[t.wsname].socket.send(e);if((d=(u=t.ujt.$global.link.ws[t.wsname])===null||u===void 0?void 0:u.config)===null||d===void 0?void 0:d.resend){t.ujt.$global.link.ws[t.wsname].config.resend=0}o()}else{if(((c=(v=t.ujt.$global.link.ws[t.wsname])===null||v===void 0?void 0:v.config)===null||c===void 0?void 0:c.resendmax)&&((f=t.ujt.$global.link.ws[t.wsname].config)===null||f===void 0?void 0:f.resend)<=((p=t.ujt.$global.link.ws[t.wsname].config)===null||p===void 0?void 0:p.resendmax)){t.wsSendMsg(e);t.ujt.$global.link.ws[t.wsname].config.resend++;o()}else{((g=(w=(h=t.ujt)===null||h===void 0?void 0:h.$global)===null||w===void 0?void 0:w.sys)===null||g===void 0?void 0:g.onconsole)&&((y=(k=(m=t.ujt)===null||m===void 0?void 0:m.$fn)===null||k===void 0?void 0:k.lo)===null||y===void 0?void 0:y.call(k,5,"Err",t.wsname,t.ujt.$global.link.ws[t.wsname].config.resend,(b=t.ujt.$global.link.ws[t.wsname].config)===null||b===void 0?void 0:b.resendmax));i(new Error("Max send attempts reached"))}}}})).catch(i)}))};AsaiWs.prototype.getKeyByData=function(e){if(e==="ping"||e==="pong")return"pong";return(e===null||e===void 0?void 0:e.id)||(e===null||e===void 0?void 0:e.ty)};AsaiWs.prototype.newWorker=function(e,t){try{if(typeof Worker!=="undefined"&&e.id){if(!e.workers[e.id]){e.workers[e.id]={instance:new Worker(window.URL.createObjectURL(new Blob(["eval(".concat(e.fn.toString(),")(").concat(JSON.stringify(e.params),",this,'')")]))),callbacks:new Set};e.workers[e.id].instance.onmessage=function(t){e.workers[e.id].callbacks.forEach((function(e){e(t.data)}))}}e.workers[e.id].callbacks.add(t)}else{e.fn(e.params,"",t)}}catch(e){console.error("Worker creation error:",e)}};AsaiWs.prototype.initWsWorker=function(e,t){this.newWorker({fn:function(e,t,o){var i,n;var s={};function deonmessage(e,t,o,i){var n,s;if(o===void 0){o={}}try{var r=JSON.parse(e);if(!i||!(r===null||r===void 0?void 0:r.ty)){t(r)}else{var a=r===null||r===void 0?void 0:r.ty;if(!o[a]){o[a]={s:e,v:r,t:1}}else{if(o[a].s===e){if(o[a].t){o[a].t=0}}else{o[a].s=e;o[a].v=r;if(!o[a].t){o[a].t=1}}}if((n=o[a])===null||n===void 0?void 0:n.t){t((s=o[a])===null||s===void 0?void 0:s.v)}}}catch(o){t(e)}}function wsonmessage(t,o){if(t===null||t===void 0?void 0:t.data){if(t.data==="pong"){o(t.data)}else if(typeof t.data==="string"){deonmessage(t.data,o,s,e.de)}}}function wkclose(){a.close();a=null;t.postMessage("onclose");t.terminate()}var r=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.gettoken(0);var a=this.wssec&&r?new WebSocket(e.url,r):new WebSocket(e.url);a.onmessage=function(e){wsonmessage(e,t.postMessage)};a.onclose=function(e){t.postMessage("onclose")};a.onerror=function(e){t.postMessage("onerror")};a.onopen=function(e){a.open=1;t.postMessage("onopen")};t.onmessage=function(e){var t,o,i;try{if(a===null||a===void 0?void 0:a.open){if(((t=e===null||e===void 0?void 0:e.data)===null||t===void 0?void 0:t.type)==="close"){wkclose()}else if(((o=e===null||e===void 0?void 0:e.data)===null||o===void 0?void 0:o.type)==="send"){a.send(((i=e===null||e===void 0?void 0:e.data)===null||i===void 0?void 0:i.data)||"")}}else{wkclose()}}catch(e){wkclose()}}},params:{url:e,de:this.ujt.$global.link.ws[this.wsname].config.de},id:this.wsname,workers:this.ujt.$fn.workers},(function(e){if(e&&e!=="null"){t(e)}}))};AsaiWs.prototype.init=function(){var e=this;var t={};function deonmessage(e,t,o,i){var n,s;if(o===void 0){o={}}try{var r=JSON.parse(e);if(!i||!(r===null||r===void 0?void 0:r.ty)){t(r)}else{var a=r===null||r===void 0?void 0:r.ty;if(!o[a]){o[a]={s:e,v:r,t:1}}else{if(o[a].s===e){if(o[a].t){o[a].t=0}}else{o[a].s=e;o[a].v=r;if(!o[a].t){o[a].t=1}}}if((n=o[a])===null||n===void 0?void 0:n.t){t((s=o[a])===null||s===void 0?void 0:s.v)}}}catch(o){t(e)}}var o=this;return new Promise((function(i,n){var s,r,a;try{if((s=e.ujt.$ws[e.wsname])===null||s===void 0?void 0:s.open){i(e.ujt)}else{if(!e.wsurl.startsWith("ws")){n({error:e.wsurl+" is not a WebSocket (WS) address!"})}else if(!("WebSocket"in window)){n({error:"WebSocket is null!"})}if(e.wsworker){if(e.workerState){setTimeout((function(){i(e.ujt)}),3e3)}else{e.workerState=true;e.initWsWorker(e.wsurl,(function(t){if(t==="onclose"){onclose()}else if(t==="onerror"){onerror()}else if(t==="onopen"){onopen();i(e.ujt)}else{onmessagedo(t)}}))}}else{if(!e.ujt.$fn.ws[e.wsname]){e.ujt.$fn.ws[e.wsname]={}}var l=(a=(r=e.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.gettoken(0);e.ujt.$fn.ws[e.wsname].socket=e.wssec&&l?new WebSocket(e.wsurl,l):new WebSocket(e.wsurl);e.ujt.$fn.ws[e.wsname].socket.onmessage=onmessage;e.ujt.$fn.ws[e.wsname].socket.onclose=onclose;e.ujt.$fn.ws[e.wsname].socket.onerror=onerror;e.ujt.$fn.ws[e.wsname].socket.onopen=function(t){onopen(t);i(e.ujt)}}}}catch(e){onerror(e);n(e)}function onopen(e){if(e===void 0){e=null}if(!o.ujt.$ws[o.wsname]){o.ujt.$ws[o.wsname]={}}o.ujt.$ws[o.wsname].open=true}function onmessage(e){deonmessage(e.data,onmessagedo,t,o.ujt.$global.link.ws[o.wsname].config.de)}function onmessagedo(e){if(o.wstaskMap.size){try{if(typeof e==="object"){o.wsWatchWork(e)}else{o.wsWatchWork(JSON.parse(e))}}catch(t){o.wsWatchWork(e)}}}function onerror(e){var t,i,n,s,r,a,l,u,d;if(e===void 0){e=null}if((i=(t=o===null||o===void 0?void 0:o.ujt)===null||t===void 0?void 0:t.$ws)===null||i===void 0?void 0:i[o===null||o===void 0?void 0:o.wsname]){o.ujt.$ws[o.wsname].open=false;o.ujt.$global.stat[o.wsname]=0}var v=((a=(r=(s=(n=o.ujt.$global.lang)===null||n===void 0?void 0:n.asai)===null||s===void 0?void 0:s.hostmsg)===null||r===void 0?void 0:r.wsname)===null||a===void 0?void 0:a[o.wsname])||o.wsname;(d=(u=(l=o===null||o===void 0?void 0:o.ujt)===null||l===void 0?void 0:l.$global)===null||u===void 0?void 0:u.msg)===null||d===void 0?void 0:d.fn({type:"err",con:o.ujt.$fn.lg("asai.hostmsg.error",v)||v+"is error!"})}function onclose(e){var t,i,n,s,r,a;if(e===void 0){e=null}if(o.ujt.$ws[o.wsname]){o.ujt.$ws[o.wsname].open=false;o.ujt.$global.stat[o.wsname]=0}var l=((s=(n=(i=(t=o.ujt.$global.lang)===null||t===void 0?void 0:t.asai)===null||i===void 0?void 0:i.hostmsg)===null||n===void 0?void 0:n.wsname)===null||s===void 0?void 0:s[o.wsname])||o.wsname;(a=(r=o.ujt.$global)===null||r===void 0?void 0:r.msg)===null||a===void 0?void 0:a.fn({type:"err",con:o.ujt.$fn.lg("asai.hostmsg.closed",l)||l+"is close!"});scheduleReconnect()}function scheduleReconnect(){if(o.maxReconnectDelay){var e=Math.min(1e3*Math.pow(2,o.reconnectAttempts),o.maxReconnectDelay);setTimeout((function(){return o.init()}),e);o.reconnectAttempts++}}}))};return AsaiWs}();function AsaiModel(e){if(e===void 0){e="./webmodel/"}var t=new r({baseURL:e});function fetchPublic(e,o){if(o===void 0){o=""}return new Promise((function(i,n){t===null||t===void 0?void 0:t.apiGet(e).then((function(t){Promise.all(dfsFetch(t,e.substring(0,e.lastIndexOf("/")+1)+o)).then((function(){i(t)})).catch((function(e){n(e)}))})).catch((function(e){n(e)}))}))}function dfsFetch(e,o){var i;var n=[];if((i=e===null||e===void 0?void 0:e.dir)===null||i===void 0?void 0:i.length){e.dir.forEach((function(i){var s=o+i;var r=s.lastIndexOf("/");n.push(t===null||t===void 0?void 0:t.apiGet(s).then((function(t){var o=s.substring(r+1);e[o.substring(0,o.indexOf("."))]=t;n.push(Promise.all(dfsFetch(t,s.substring(0,r+1))))})).catch((function(e){console.error("Error fetching resource:",e)})))}))}return n}return{fetchPublic:fetchPublic}}t["default"]={AsaiWorker:s,AsaiApi:r,AsaiWs:a,AsaiModel:AsaiModel}}};if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};e[659](0,t);module.exports=t})();
1
+ (()=>{"use strict";var e={659:function(e,t){var o=this&&this.__assign||function(){o=Object.assign||function(e){for(var t,o=1,i=arguments.length;o<i;o++){t=arguments[o];for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n))e[n]=t[n]}return e};return o.apply(this,arguments)};var i=this&&this.__awaiter||function(e,t,o,i){function adopt(e){return e instanceof o?e:new o((function(t){t(e)}))}return new(o||(o=Promise))((function(o,n){function fulfilled(e){try{step(i.next(e))}catch(e){n(e)}}function rejected(e){try{step(i["throw"](e))}catch(e){n(e)}}function step(e){e.done?o(e.value):adopt(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))};var n=this&&this.__generator||function(e,t){var o={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,n,s,r=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return r.next=verb(0),r["throw"]=verb(1),r["return"]=verb(2),typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function verb(e){return function(t){return step([e,t])}}function step(a){if(i)throw new TypeError("Generator is already executing.");while(r&&(r=0,a[0]&&(o=0)),o)try{if(i=1,n&&(s=a[0]&2?n["return"]:a[0]?n["throw"]||((s=n["return"])&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;if(n=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:o.label++;return{value:a[1],done:false};case 5:o.label++;n=a[1];a=[0];continue;case 7:a=o.ops.pop();o.trys.pop();continue;default:if(!(s=o.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){o.label=a[1];break}if(a[0]===6&&o.label<s[1]){o.label=s[1];s=a;break}if(s&&o.label<s[2]){o.label=s[2];o.ops.push(a);break}if(s[2])o.ops.pop();o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e];n=0}finally{i=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};Object.defineProperty(t,"__esModule",{value:true});var s=function(){function AsaiWorker(e,t){if(t===void 0){t=navigator.hardwareConcurrency||4}this.taskQueue=[];this.workers=new Map;this.taskMap=new Map;this.taskId=0;this.workerScript=e;this.maxWorkers=t}AsaiWorker.prototype.execute=function(e){return i(this,void 0,void 0,(function(){var t=this;return n(this,(function(o){return[2,new Promise((function(o,i){var n=t.taskId++;t.taskQueue.push({taskId:n,taskData:e});t.taskMap.set(n,{resolve:o,reject:i});t._processNext()}))]}))}))};AsaiWorker.prototype._createWorker=function(){var e=this;var t=new Worker(this.workerScript,{type:"module"});t.onmessage=function(o){var i=o.data,n=i.taskId,s=i.result,r=i.error;var a=e.taskMap.get(n);if(a){if(r){a.reject(r)}else{a.resolve(s)}e.taskMap.delete(n)}e.workers.delete(t);t.terminate();e._processNext()};t.onerror=function(o){console.error("Worker error:",o);e.workers.delete(t);e._createWorker()};this.workers.set(t,true);return t};AsaiWorker.prototype._processNext=function(){while(this.taskQueue.length>0&&this.workers.size<this.maxWorkers){var e=this.taskQueue.shift();var t=this._createWorker();t.postMessage({taskId:e.taskId,data:e.taskData})}};AsaiWorker.prototype.terminateAll=function(){this.workers.forEach((function(e,t){return t.terminate()}));this.workers.clear();this.taskQueue=[]};return AsaiWorker}();var r=function(){function AsaiApi(e){if(e===void 0){e={}}this.interceptors={request:[],response:[]};this.defaultConfig={headers:{"Content-Type":"application/json"},cache:"reload",timeout:1e4};this.totalApi=0;this.baseURL=e.baseURL;this.ujt=e.ujt}AsaiApi.prototype.api=function(e){return i(this,arguments,void 0,(function(e,t){var i,s,r,a,l,u,d,v,c,f,p,h,w,g;var m=this;var k,y,b,j,A,W;if(t===void 0){t={}}return n(this,(function(n){switch(n.label){case 0:i=0;s=0;if((b=(y=(k=this.ujt)===null||k===void 0?void 0:k.$global)===null||y===void 0?void 0:y.sys)===null||b===void 0?void 0:b.onconsole){this.totalApi++;this.totalApi>1e4&&(this.totalApi=0);s=this.totalApi;i=Date.now()%1e7}r=new AbortController;a=r.signal;l=setTimeout((function(){return r.abort()}),t.timeout||this.defaultConfig.timeout);n.label=1;case 1:n.trys.push([1,5,,6]);u={url:this.baseURL+e};if(t.body instanceof FormData){u.opt=t}else{u.opt=o(o(o({},this.defaultConfig),t),{signal:a,headers:o(o({},this.defaultConfig.headers),t.headers)})}i&&((W=(A=(j=this.ujt)===null||j===void 0?void 0:j.$fn)===null||A===void 0?void 0:A.lo)===null||W===void 0?void 0:W.call(A,2,"Req"+s,u));d=Promise.resolve(u);this.interceptors.request.forEach((function(e){d=d.then((function(t){return e(t)}))}));return[4,d];case 2:v=n.sent(),c=v.url,f=v.opt;return[4,fetch(c,f)];case 3:p=n.sent();clearTimeout(l);return[4,this._parseResponse(p)];case 4:h=n.sent();w=Promise.resolve(this._getRes(h,t));this.interceptors.response.forEach((function(e){w=w.then((function(t){var o,n,r;i&&((r=(n=(o=m.ujt)===null||o===void 0?void 0:o.$fn)===null||n===void 0?void 0:n.lo)===null||r===void 0?void 0:r.call(n,3,"Res"+s+" "+(Date.now()%1e7-i)+"ms",t));return e(t)}))}));return[2,w];case 5:g=n.sent();clearTimeout(l);throw this._handleError(g);case 6:return[2]}}))}))};AsaiApi.prototype.apiGet=function(e,t,i){if(t===void 0){t={}}if(i===void 0){i={}}var n=new URLSearchParams(t).toString();var s=this._getReq("get",n,i);return this.api("".concat(e).concat(s?"?"+s:""),o(o({},i),{method:"GET"}))};AsaiApi.prototype.apiPost=function(e,t,i){if(i===void 0){i={}}return this.api(e,o(o({},i),{method:"POST",body:t instanceof FormData?t:this._stringifyData(this._getReq("post",t,i),i.headers)}))};AsaiApi.prototype.apiUpload=function(e,t,i){var n=new FormData;n.append("file",t);return this.apiPost(e,n,o({},i))};AsaiApi.prototype.apiDownload=function(e,t){return this.apiGet(e,null,{responseType:"blob"}).then((function(e){var o=document.createElement("a");o.href=URL.createObjectURL(e);o.download=t;o.click()}))};AsaiApi.prototype._getReq=function(e,t,o){var i,n,s,r,a,l;if((o===null||o===void 0?void 0:o.mm)&&((s=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.AsCode)===null||s===void 0?void 0:s.asdecode)&&((l=(a=(r=this.ujt)===null||r===void 0?void 0:r.$global)===null||a===void 0?void 0:a.code)===null||l===void 0?void 0:l.pri)&&t){t=this.ujt.$fn.AsCode.asencode(typeof t==="string"?t:JSON.stringify(t),this.ujt.$global.code.pri);if(t&&e==="get"){t="pm="+encodeURIComponent(t)}}return t};AsaiApi.prototype._getRes=function(e,t){var o,i,n,s,r,a;if((t===null||t===void 0?void 0:t.mm)&&((n=(i=(o=this.ujt)===null||o===void 0?void 0:o.$fn)===null||i===void 0?void 0:i.AsCode)===null||n===void 0?void 0:n.asdecode)&&((a=(r=(s=this.ujt)===null||s===void 0?void 0:s.$global)===null||r===void 0?void 0:r.code)===null||a===void 0?void 0:a.pri)&&(e===null||e===void 0?void 0:e.data)&&typeof e.data==="string"){e.data=this.ujt.$fn.AsCode.asdecode(e.data,this.ujt.$global.code.pri);try{e.data=JSON.parse(e.data)}catch(e){}}return e};AsaiApi.prototype._parseResponse=function(e){var t=e.headers.get("content-type");if(t===null||t===void 0?void 0:t.includes("application/json")){return e.json()}if(t===null||t===void 0?void 0:t.includes("text/")){return e.text()}return e.blob()};AsaiApi.prototype._stringifyData=function(e,t){var o=t===null||t===void 0?void 0:t["Content-Type"];if(e instanceof FormData)return e;if(typeof e==="string")return e;if(o==="application/json"||typeof e==="object")return JSON.stringify(e);return String(e)};AsaiApi.prototype._handleError=function(e){if(e.name==="AbortError"){return{code:504,message:"Request Timeout"}}return{code:500,message:e.message||"Network Error"}};AsaiApi.prototype.ictReq=function(e){this.interceptors.request.push(e)};AsaiApi.prototype.ictRes=function(e){this.interceptors.response.push(e)};return AsaiApi}();var a=function(){function AsaiWs(e){if(e===void 0){e={}}var t=this;var o,i,n,s,r,a,l,u;this.reconnectAttempts=0;this.maxReconnectDelay=0;this.messageQueue=[];this.isSending=false;this.wstaskMap=new Map;this.workerState=false;this.totalWs=0;this.wsname=e.wsname;this.wsworker=e.wsworker;this.wssec=e.wssec;this.wsurl=e.wsurl;this.ujt=e.ujt;this.baseURL=e.baseURL;if((s=(n=(i=(o=this.ujt.$global.link)===null||o===void 0?void 0:o.ws)===null||i===void 0?void 0:i[this.wsname])===null||n===void 0?void 0:n.config)===null||s===void 0?void 0:s.tmdeltask){this.cleanupInterval=setInterval((function(){if(t.wstaskMap.size){var e=Date.now();t.wstaskMap.forEach((function(o,i){var n,s,r,a;if(!o.type&&o.timestamp&&e-o.timestamp>((a=(r=(s=(n=t.ujt.$global.link)===null||n===void 0?void 0:n.ws)===null||s===void 0?void 0:s[t.wsname])===null||r===void 0?void 0:r.config)===null||a===void 0?void 0:a.tmdeltask)/2){t.wstaskMap.delete(i)}}))}}),(u=(l=(a=(r=this.ujt.$global.link)===null||r===void 0?void 0:r.ws)===null||a===void 0?void 0:a[this.wsname])===null||l===void 0?void 0:l.config)===null||u===void 0?void 0:u.tmdeltask)}}AsaiWs.prototype.Uuid=function(e,t,o){if(e===void 0){e=""}if(t===void 0){t=0}if(o===void 0){o=32}var i=[Date.now().toString(36).slice(-9),t.toString(36),e.slice(-3),crypto.getRandomValues(new Uint8Array(6)).reduce((function(e,t){return e+(t&15).toString(o)}),"")];return i.join("").slice(0,16)};AsaiWs.prototype.wsSend=function(e){if(typeof e==="object"){e=JSON.stringify(e)}this.wsSendMsg(e)};AsaiWs.prototype.wsApi=function(e){var t=this;return new Promise((function(i,n){var s,r,a;var l=0;if((a=(r=(s=t.ujt)===null||s===void 0?void 0:s.$global)===null||r===void 0?void 0:r.sys)===null||a===void 0?void 0:a.onconsole){l=Date.now()%1e7}var u;try{if(e==="ping"){u="ping"}else if(!e){u={id:t.Uuid("ws")};e=JSON.stringify(u)}else if(typeof e==="object"){u=o({},e);if(!(u===null||u===void 0?void 0:u.id)){u.id=t.Uuid("ws")}e=JSON.stringify(u)}else{u=JSON.parse(e);if(!(u===null||u===void 0?void 0:u.id)){u.id=t.Uuid("ws");e=JSON.stringify(u)}}}catch(e){}t.wsWatchDo(u,(function(e){var o,n,s,r,a,u;if(l){l=Date.now()%1e7-l;((s=(n=(o=t.ujt)===null||o===void 0?void 0:o.$global)===null||n===void 0?void 0:n.sys)===null||s===void 0?void 0:s.onconsole)&&((u=(a=(r=t.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.lo)===null||u===void 0?void 0:u.call(a,5,"wsGet:"+l+"ms",e))}i(e)}))}))};AsaiWs.prototype.wsWatch=function(e,t){var o,i,n,s,r,a;((n=(i=(o=this.ujt)===null||o===void 0?void 0:o.$global)===null||i===void 0?void 0:i.sys)===null||n===void 0?void 0:n.onconsole)&&((a=(r=(s=this.ujt)===null||s===void 0?void 0:s.$fn)===null||r===void 0?void 0:r.lo)===null||a===void 0?void 0:a.call(r,3,"wsWatch",e));this.wsWatchDo(e,t)};AsaiWs.prototype.wsWatchDo=function(e,t){var i=this.getKeyByData(e);var n={};if(e!=="ping"){if(typeof e=="object"&&(e===null||e===void 0?void 0:e.id)){n={type:0,timestamp:Date.now()}}else{n={type:1}}}this.wstaskMap.set(i,o({callback:t},n));this.wsSend(e)};AsaiWs.prototype.wsWatchOff=function(e){var t,o,i,n,s,r;((i=(o=(t=this.ujt)===null||t===void 0?void 0:t.$global)===null||o===void 0?void 0:o.sys)===null||i===void 0?void 0:i.onconsole)&&((r=(s=(n=this.ujt)===null||n===void 0?void 0:n.$fn)===null||s===void 0?void 0:s.lo)===null||r===void 0?void 0:r.call(s,6,"wsWatchOff:"+this.wstaskMap.size,e));!e.off&&(e.off=1);this.wsSend(e);var a=this.getKeyByData(e);var l=this.wstaskMap.get(a);if(l){this.wstaskMap.delete(a)}};AsaiWs.prototype.wsWatchWork=function(e){var t,o,i,n,s,r;var a=this.getKeyByData(e);var l=this.wstaskMap.get(a);if(l){l.callback(e);if(!l.type){((i=(o=(t=this.ujt)===null||t===void 0?void 0:t.$global)===null||o===void 0?void 0:o.sys)===null||i===void 0?void 0:i.onconsole)&&((r=(s=(n=this.ujt)===null||n===void 0?void 0:n.$fn)===null||s===void 0?void 0:s.lo)===null||r===void 0?void 0:r.call(s,3,"wsDelete:"+this.wstaskMap.size,a));this.wstaskMap.delete(a)}}};AsaiWs.prototype.wsSendMsg=function(e){return i(this,void 0,void 0,(function(){var t;var o,i,s,r,a,l;return n(this,(function(n){switch(n.label){case 0:if(!(e==="ping"))return[3,2];return[4,this.sendSingleMessage(e)];case 1:n.sent();return[3,6];case 2:this.messageQueue.push(e);if(!!this.isSending)return[3,6];this.isSending=true;n.label=3;case 3:if(!(this.messageQueue.length>0))return[3,5];t=this.messageQueue.shift();if((s=(i=(o=this.ujt)===null||o===void 0?void 0:o.$global)===null||i===void 0?void 0:i.sys)===null||s===void 0?void 0:s.onconsole){this.totalWs++;this.totalWs>1e4&&(this.totalWs=0);(l=(a=(r=this.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.lo)===null||l===void 0?void 0:l.call(a,4,"wsSend"+this.totalWs+":"+this.messageQueue.length,t)}return[4,this.sendSingleMessage(t)];case 4:n.sent();return[3,3];case 5:this.isSending=false;n.label=6;case 6:return[2]}}))}))};AsaiWs.prototype.sendSingleMessage=function(e){var t=this;return new Promise((function(o,i){t.init().then((function(){var n,s,r,a,l,u,d,v,c,f,p,h,w,g,m,k,y,b;if(t.wsworker){if(typeof((s=(n=t.ujt.$fn.workers[t.wsname])===null||n===void 0?void 0:n.instance)===null||s===void 0?void 0:s.postMessage)==="function"){(a=(r=t.ujt.$fn.workers[t.wsname])===null||r===void 0?void 0:r.instance)===null||a===void 0?void 0:a.postMessage({type:"send",data:e});o()}else{i()}}else{if(((l=t.ujt.$fn.ws[t.wsname].socket)===null||l===void 0?void 0:l.readyState)===WebSocket.OPEN){t.ujt.$fn.ws[t.wsname].socket.send(e);if((d=(u=t.ujt.$global.link.ws[t.wsname])===null||u===void 0?void 0:u.config)===null||d===void 0?void 0:d.resend){t.ujt.$global.link.ws[t.wsname].config.resend=0}o()}else{if(((c=(v=t.ujt.$global.link.ws[t.wsname])===null||v===void 0?void 0:v.config)===null||c===void 0?void 0:c.resendmax)&&((f=t.ujt.$global.link.ws[t.wsname].config)===null||f===void 0?void 0:f.resend)<=((p=t.ujt.$global.link.ws[t.wsname].config)===null||p===void 0?void 0:p.resendmax)){t.wsSendMsg(e);t.ujt.$global.link.ws[t.wsname].config.resend++;o()}else{((g=(w=(h=t.ujt)===null||h===void 0?void 0:h.$global)===null||w===void 0?void 0:w.sys)===null||g===void 0?void 0:g.onconsole)&&((y=(k=(m=t.ujt)===null||m===void 0?void 0:m.$fn)===null||k===void 0?void 0:k.lo)===null||y===void 0?void 0:y.call(k,5,"Err",t.wsname,t.ujt.$global.link.ws[t.wsname].config.resend,(b=t.ujt.$global.link.ws[t.wsname].config)===null||b===void 0?void 0:b.resendmax));i(new Error("Max send attempts reached"))}}}})).catch(i)}))};AsaiWs.prototype.getKeyByData=function(e){if(e==="ping"||e==="pong")return"pong";return(e===null||e===void 0?void 0:e.id)||(e===null||e===void 0?void 0:e.ty)};AsaiWs.prototype.newWorker=function(e,t){try{if(typeof Worker!=="undefined"&&e.id){if(!e.workers[e.id]){e.workers[e.id]={instance:new Worker(window.URL.createObjectURL(new Blob(["eval(".concat(e.fn.toString(),")(").concat(JSON.stringify(e.params),",this,'')")]))),callbacks:new Set};e.workers[e.id].instance.onmessage=function(t){e.workers[e.id].callbacks.forEach((function(e){e(t.data)}))}}e.workers[e.id].callbacks.add(t)}else{e.fn(e.params,"",t)}}catch(e){console.error("Worker creation error:",e)}};AsaiWs.prototype.initWsWorker=function(e,t){this.newWorker({fn:function(e,t,o){var i,n;var s={};function deonmessage(e,t,o,i){var n,s;if(o===void 0){o={}}try{var r=JSON.parse(e);if(!i||!(r===null||r===void 0?void 0:r.ty)){t(r)}else{var a=r===null||r===void 0?void 0:r.ty;if(!o[a]){o[a]={s:e,v:r,t:1}}else{if(o[a].s===e){if(o[a].t){o[a].t=0}}else{o[a].s=e;o[a].v=r;if(!o[a].t){o[a].t=1}}}if((n=o[a])===null||n===void 0?void 0:n.t){t((s=o[a])===null||s===void 0?void 0:s.v)}}}catch(o){t(e)}}function wsonmessage(t,o){if(t===null||t===void 0?void 0:t.data){if(t.data==="pong"){o(t.data)}else if(typeof t.data==="string"){deonmessage(t.data,o,s,e.de)}}}function wkclose(){a.close();a=null;t.postMessage("onclose");t.terminate()}var r=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.gettoken(0);var a=this.wssec&&r?new WebSocket(e.url,r):new WebSocket(e.url);a.onmessage=function(e){wsonmessage(e,t.postMessage)};a.onclose=function(e){t.postMessage("onclose")};a.onerror=function(e){t.postMessage("onerror")};a.onopen=function(e){a.open=1;t.postMessage("onopen")};t.onmessage=function(e){var t,o,i;try{if(a===null||a===void 0?void 0:a.open){if(((t=e===null||e===void 0?void 0:e.data)===null||t===void 0?void 0:t.type)==="close"){wkclose()}else if(((o=e===null||e===void 0?void 0:e.data)===null||o===void 0?void 0:o.type)==="send"){a.send(((i=e===null||e===void 0?void 0:e.data)===null||i===void 0?void 0:i.data)||"")}}else{wkclose()}}catch(e){wkclose()}}},params:{url:e,de:this.ujt.$global.link.ws[this.wsname].config.de},id:this.wsname,workers:this.ujt.$fn.workers},(function(e){if(e&&e!=="null"){t(e)}}))};AsaiWs.prototype.init=function(){var e=this;var t={};function deonmessage(e,t,o,i){var n,s;if(o===void 0){o={}}try{var r=JSON.parse(e);if(!i||!(r===null||r===void 0?void 0:r.ty)){t(r)}else{var a=r===null||r===void 0?void 0:r.ty;if(!o[a]){o[a]={s:e,v:r,t:1}}else{if(o[a].s===e){if(o[a].t){o[a].t=0}}else{o[a].s=e;o[a].v=r;if(!o[a].t){o[a].t=1}}}if((n=o[a])===null||n===void 0?void 0:n.t){t((s=o[a])===null||s===void 0?void 0:s.v)}}}catch(o){t(e)}}var o=this;return new Promise((function(i,n){var s,r,a;try{if((s=e.ujt.$ws[e.wsname])===null||s===void 0?void 0:s.open){i(e.ujt)}else{if(!e.wsurl.startsWith("ws")){n({error:e.wsurl+" is not a WebSocket (WS) address!"})}else if(!("WebSocket"in window)){n({error:"WebSocket is null!"})}if(e.wsworker){if(e.workerState){setTimeout((function(){i(e.ujt)}),3e3)}else{e.workerState=true;e.initWsWorker(e.wsurl,(function(t){if(t==="onclose"){onclose()}else if(t==="onerror"){onerror()}else if(t==="onopen"){onopen();i(e.ujt)}else{onmessagedo(t)}}))}}else{if(!e.ujt.$fn.ws[e.wsname]){e.ujt.$fn.ws[e.wsname]={}}var l=(a=(r=e.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.gettoken(0);e.ujt.$fn.ws[e.wsname].socket=e.wssec&&l?new WebSocket(e.wsurl,l):new WebSocket(e.wsurl);e.ujt.$fn.ws[e.wsname].socket.onmessage=onmessage;e.ujt.$fn.ws[e.wsname].socket.onclose=onclose;e.ujt.$fn.ws[e.wsname].socket.onerror=onerror;e.ujt.$fn.ws[e.wsname].socket.onopen=function(t){onopen(t);i(e.ujt)}}}}catch(e){onerror(e);n(e)}function onopen(e){if(e===void 0){e=null}if(!o.ujt.$ws[o.wsname]){o.ujt.$ws[o.wsname]={}}o.ujt.$ws[o.wsname].open=true}function onmessage(e){deonmessage(e.data,onmessagedo,t,o.ujt.$global.link.ws[o.wsname].config.de)}function onmessagedo(e){if(o.wstaskMap.size){try{if(typeof e==="object"){o.wsWatchWork(e)}else{o.wsWatchWork(JSON.parse(e))}}catch(t){o.wsWatchWork(e)}}}function onerror(e){var t,i,n,s,r,a,l,u,d;if(e===void 0){e=null}if((i=(t=o===null||o===void 0?void 0:o.ujt)===null||t===void 0?void 0:t.$ws)===null||i===void 0?void 0:i[o===null||o===void 0?void 0:o.wsname]){o.ujt.$ws[o.wsname].open=false;o.ujt.$global.stat[o.wsname]=0}var v=((a=(r=(s=(n=o.ujt.$global.lang)===null||n===void 0?void 0:n.asai)===null||s===void 0?void 0:s.hostmsg)===null||r===void 0?void 0:r.wsname)===null||a===void 0?void 0:a[o.wsname])||o.wsname;(d=(u=(l=o===null||o===void 0?void 0:o.ujt)===null||l===void 0?void 0:l.$global)===null||u===void 0?void 0:u.msg)===null||d===void 0?void 0:d.fn({type:"err",con:o.ujt.$fn.lg("asai.hostmsg.error",v)||v+" is error!"})}function onclose(e){var t,i,n,s;if(e===void 0){e=null}if(o.ujt.$ws[o.wsname]){o.ujt.$ws[o.wsname].open=false;o.ujt.$global.stat[o.wsname]=0}var r=((s=(n=(i=(t=o.ujt.$global.lang)===null||t===void 0?void 0:t.asai)===null||i===void 0?void 0:i.hostmsg)===null||n===void 0?void 0:n.wsname)===null||s===void 0?void 0:s[o.wsname])||o.wsname;o.ujt.$global.pagebusy={log:o.wsname,close:1,v:o.ujt.$fn.lg("asai.hostmsg.closed",r)||r+" is close!"};scheduleReconnect()}function scheduleReconnect(){if(o.maxReconnectDelay){var e=Math.min(1e3*Math.pow(2,o.reconnectAttempts),o.maxReconnectDelay);setTimeout((function(){return o.init()}),e);o.reconnectAttempts++}}}))};return AsaiWs}();function AsaiModel(e){if(e===void 0){e="./webmodel/"}var t=new r({baseURL:e});function fetchPublic(e,o){if(o===void 0){o=""}return new Promise((function(i,n){t===null||t===void 0?void 0:t.apiGet(e).then((function(t){Promise.all(dfsFetch(t,e.substring(0,e.lastIndexOf("/")+1)+o)).then((function(){i(t)})).catch((function(e){n(e)}))})).catch((function(e){n(e)}))}))}function dfsFetch(e,o){var i;var n=[];if((i=e===null||e===void 0?void 0:e.dir)===null||i===void 0?void 0:i.length){e.dir.forEach((function(i){var s=o+i;var r=s.lastIndexOf("/");n.push(t===null||t===void 0?void 0:t.apiGet(s).then((function(t){var o=s.substring(r+1);e[o.substring(0,o.indexOf("."))]=t;n.push(Promise.all(dfsFetch(t,s.substring(0,r+1))))})).catch((function(e){console.error("Error fetching resource:",e)})))}))}return n}return{fetchPublic:fetchPublic}}t["default"]={AsaiWorker:s,AsaiApi:r,AsaiWs:a,AsaiModel:AsaiModel}}};if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};e[659](0,t);module.exports=t})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asai-js-as",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "asai for you",
5
5
  "author": "Asai",
6
6
  "license": "ISC",