asai-js-as 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -0
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# asai-js-as — 通信与模型加载核心
|
|
2
|
+
|
|
3
|
+
## 包信息
|
|
4
|
+
|
|
5
|
+
| 建议 npm 名 | 入口文件 | $fn / 注入键 | 类型 |
|
|
6
|
+
|------------|---------|-------------|------|
|
|
7
|
+
| `@estun/asai-js-as` | `AsaiJsAs.ts` / `src/index.ts` | `AsaiWorker` `AsaiApi` `AsaiWs` `AsaiModel`(展开 4 键) | Feature |
|
|
8
|
+
|
|
9
|
+
## 概述
|
|
10
|
+
|
|
11
|
+
`asai-js-as` 是前端引擎的**通信与数据层**插件,聚合 Worker 任务池、HTTP API、WebSocket 与 webmodel 静态模型加载。通过 `App.vue` 展开注入 `$fn`,供 Host 与各业务模块使用。
|
|
12
|
+
|
|
13
|
+
## 集成方式
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// monorepo — webclient/src/App.vue
|
|
17
|
+
import AsaiJsAs from './plugs/asai-js-as/AsaiJsAs.ts';
|
|
18
|
+
// npm
|
|
19
|
+
// import AsaiJsAs from '@estun/asai-js-as';
|
|
20
|
+
|
|
21
|
+
useProvide({
|
|
22
|
+
plugs: { ...AsaiJsAs },
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 独立性约束
|
|
27
|
+
|
|
28
|
+
- **禁止** `import` 其它 `plugs/*` 插件。
|
|
29
|
+
- `AsaiApi` / `AsaiWs` 依赖 Host 初始化后的 `ujt` 上下文,通过运行时注入使用,不在本包内引用 host 源码。
|
|
30
|
+
|
|
31
|
+
## 主要 API / 导出
|
|
32
|
+
|
|
33
|
+
| 导出 | 说明 |
|
|
34
|
+
|------|------|
|
|
35
|
+
| `AsaiWorker` | Web Worker 任务队列,按 CPU 核心数限并发 |
|
|
36
|
+
| `AsaiApi` | HTTP fetch 封装(需 ujt) |
|
|
37
|
+
| `AsaiWs` | WebSocket 连接与 wsApi(需 ujt) |
|
|
38
|
+
| `AsaiModel` | webmodel 目录递归加载到 `$model` |
|
|
39
|
+
| `deonmessage` | `src/ws-message-filter.ts`,WS 消息过滤(按需 import) |
|
|
40
|
+
|
|
41
|
+
## 性能说明
|
|
42
|
+
|
|
43
|
+
- **首屏同步**注册,体积相对可控(无大型 UI chunk)。
|
|
44
|
+
- `AsaiWorker`:每任务独立 Worker,完成后 `terminate`,适合短任务 burst;长驻计算请自建 Worker 池。
|
|
45
|
+
- 大数据 `postMessage` 注意结构化克隆开销,可考虑 Transferable。
|
|
46
|
+
|
|
47
|
+
## peerDependencies 建议
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"vue": "^3.4.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 模块说明
|
|
60
|
+
|
|
61
|
+
| 模块 | 文件 | 职责 |
|
|
62
|
+
|------|------|------|
|
|
63
|
+
| **AsaiWorker** | `src/AsaiWorker.ts` | Web Worker 任务队列 |
|
|
64
|
+
| **AsaiApi** | `src/AsaiApi.ts` | HTTP 封装 |
|
|
65
|
+
| **AsaiWs** | `src/AsaiWs.ts` | WebSocket |
|
|
66
|
+
| **AsaiModel** | `src/AsaiModel.ts` | 静态模型加载 |
|
|
67
|
+
|
|
68
|
+
## 文件结构
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
asai-js-as/
|
|
72
|
+
├── AsaiJsAs.ts # App.vue 聚合导出
|
|
73
|
+
├── src/
|
|
74
|
+
│ ├── index.ts
|
|
75
|
+
│ ├── AsaiWorker.ts / AsaiApi.ts / AsaiWs.ts / AsaiModel.ts
|
|
76
|
+
│ └── ws-message-filter.ts
|
|
77
|
+
└── README.md
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## AsaiWorker
|
|
81
|
+
|
|
82
|
+
### 构造函数
|
|
83
|
+
|
|
84
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
85
|
+
|------|------|--------|------|
|
|
86
|
+
| `workerScript` | `string` | — | Worker 脚本 URL |
|
|
87
|
+
| `maxWorkers` | `number` | `navigator.hardwareConcurrency \|\| 4` | 最大并发 |
|
|
88
|
+
|
|
89
|
+
### 方法
|
|
90
|
+
|
|
91
|
+
| 方法 | 说明 |
|
|
92
|
+
|------|------|
|
|
93
|
+
| `execute(taskData)` | 提交任务,返回 `Promise<any>` |
|
|
94
|
+
| `terminateAll()` | 终止所有 Worker |
|
|
95
|
+
|
|
96
|
+
### 使用示例
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
const pool = new $fn.AsaiWorker('/workers/compute.js');
|
|
100
|
+
const result = await pool.execute({ op: 'hash', data: buffer });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## AsaiModel
|
|
104
|
+
|
|
105
|
+
递归加载 `webmodel` 配置目录,填充 `$ujtasai.$model`,与 `useProvide` 中 `$model.webmodels` 路由索引配合。
|
|
106
|
+
|
|
107
|
+
## 注意事项
|
|
108
|
+
|
|
109
|
+
1. Worker 脚本需同源或通过 blob URL 加载。
|
|
110
|
+
2. `AsaiApi` / `AsaiWs` 勿在 `useProvide` 之前调用。
|
|
111
|
+
3. 更多 Host 生命周期见 [plugs/README.md](../README.md)。
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={659:function(e,t){var i=this&&this.__assign||function(){i=Object.assign||function(e){for(var t,i=1,o=arguments.length;i<o;i++){t=arguments[i];for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n))e[n]=t[n]}return e};return i.apply(this,arguments)};var o=this&&this.__awaiter||function(e,t,i,o){function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,n){function fulfilled(e){try{step(o.next(e))}catch(e){n(e)}}function rejected(e){try{step(o["throw"](e))}catch(e){n(e)}}function step(e){e.done?i(e.value):adopt(e.value).then(fulfilled,rejected)}step((o=o.apply(e,t||[])).next())}))};var n=this&&this.__generator||function(e,t){var i={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},o,n,s,l=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return l.next=verb(0),l["throw"]=verb(1),l["return"]=verb(2),typeof Symbol==="function"&&(l[Symbol.iterator]=function(){return this}),l;function verb(e){return function(t){return step([e,t])}}function step(r){if(o)throw new TypeError("Generator is already executing.");while(l&&(l=0,r[0]&&(i=0)),i)try{if(o=1,n&&(s=r[0]&2?n["return"]:r[0]?n["throw"]||((s=n["return"])&&s.call(n),0):n.next)&&!(s=s.call(n,r[1])).done)return s;if(n=0,s)r=[r[0]&2,s.value];switch(r[0]){case 0:case 1:s=r;break;case 4:i.label++;return{value:r[1],done:false};case 5:i.label++;n=r[1];r=[0];continue;case 7:r=i.ops.pop();i.trys.pop();continue;default:if(!(s=i.trys,s=s.length>0&&s[s.length-1])&&(r[0]===6||r[0]===2)){i=0;continue}if(r[0]===3&&(!s||r[1]>s[0]&&r[1]<s[3])){i.label=r[1];break}if(r[0]===6&&i.label<s[1]){i.label=s[1];s=r;break}if(s&&i.label<s[2]){i.label=s[2];i.ops.push(r);break}if(s[2])i.ops.pop();i.trys.pop();continue}r=t.call(e,i)}catch(e){r=[6,e];n=0}finally{o=s=0}if(r[0]&5)throw r[1];return{value:r[0]?r[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 o(this,void 0,void 0,(function(){var t=this;return n(this,(function(i){return[2,new Promise((function(i,o){var n=t.taskId++;t.taskQueue.push({taskId:n,taskData:e});t.taskMap.set(n,{resolve:i,reject:o});t._processNext()}))]}))}))};AsaiWorker.prototype._createWorker=function(){var e=this;var t=new Worker(this.workerScript,{type:"module"});t.onmessage=function(i){var o=i.data,n=o.taskId,s=o.result,l=o.error;var r=e.taskMap.get(n);if(r){if(l){r.reject(l)}else{r.resolve(s)}e.taskMap.delete(n)}e.workers.delete(t);t.terminate();e._processNext()};t.onerror=function(i){console.error("Worker error:",i);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 l=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 o(this,arguments,void 0,(function(e,t){var o,s,l,r,a,u,d,v,c,f,p,h,w,g,m;var y=this;var b,k,j,A,$,W;if(t===void 0){t={}}return n(this,(function(n){switch(n.label){case 0:o=0;s=0;if((j=(k=(b=this.ujt)===null||b===void 0?void 0:b.$global)===null||k===void 0?void 0:k.sys)===null||j===void 0?void 0:j.onconsole){this.totalApi++;this.totalApi>1e4&&(this.totalApi=0);s=this.totalApi;o=Date.now()%1e7}l=new AbortController;r=l.signal;a=setTimeout((function(){return l.abort()}),t.timeout||this.defaultConfig.timeout);n.label=1;case 1:n.trys.push([1,6,,7]);u={url:this.baseURL+e};if(t.body instanceof FormData){u.opt=t}else{u.opt=i(i(i({},this.defaultConfig),t),{signal:r,headers:i(i({},this.defaultConfig.headers),t.headers)})}o&&((W=($=(A=this.ujt)===null||A===void 0?void 0:A.$fn)===null||$===void 0?void 0:$.lo)===null||W===void 0?void 0:W.call($,2,(t.method||"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(a);return[4,this._parseResponse(p)];case 4:h=n.sent();return[4,this._getRes(h,t)];case 5:w=n.sent();g=Promise.resolve(w);this.interceptors.response.forEach((function(e){g=g.then((function(i){var n,l,r;o&&((r=(l=(n=y.ujt)===null||n===void 0?void 0:n.$fn)===null||l===void 0?void 0:l.lo)===null||r===void 0?void 0:r.call(l,3,(t.method||"Res")+s+" "+(Date.now()%1e7-o)+"ms",i));return e(i)}))}));return[2,g];case 6:m=n.sent();clearTimeout(a);throw this._handleError(m);case 7:return[2]}}))}))};AsaiApi.prototype.apiGet=function(e){return o(this,arguments,void 0,(function(e,t,o){var s,l,r;if(t===void 0){t={}}if(o===void 0){o={}}return n(this,(function(n){switch(n.label){case 0:s=e;if(!!(o===null||o===void 0?void 0:o.client))return[3,2];s=s.split("?")[0];return[4,this._getReqQuery(e,t,o)];case 1:l=n.sent();if(l){s+="?"+l}n.label=2;case 2:return[4,this.api(s,i(i({},o),{method:"GET"}))];case 3:r=n.sent();return[2,r]}}))}))};AsaiApi.prototype.apiPost=function(e,t){return o(this,arguments,void 0,(function(e,t,o){var s,l,r,a;if(o===void 0){o={}}return n(this,(function(n){switch(n.label){case 0:s=e.split("?")[0];return[4,this._getReqQuery(e,null,o)];case 1:l=n.sent();if(l){s+="?"+l}return[4,this._getReqPost(t,o)];case 2:r=n.sent();return[4,this.api(s,i(i({},o),{method:"POST",body:t instanceof FormData?t:this._stringifyData(r,o.headers)}))];case 3:a=n.sent();return[2,a]}}))}))};AsaiApi.prototype.apiUpload=function(e,t,o){var n=new FormData;n.append("file",t);return this.apiPost(e,n,i({},o))};AsaiApi.prototype.apiDownload=function(e,t){return this.apiGet(e,null,{responseType:"blob"}).then((function(e){var i=document.createElement("a");i.href=URL.createObjectURL(e);i.download=t;i.click()}))};AsaiApi.prototype._getReqQuery=function(e){return o(this,arguments,void 0,(function(e,t,i){var o,s,l;var r,a,u,d,v,c,f,p,h,w,g,m,y,b,k,j,A;if(t===void 0){t=null}if(i===void 0){i=null}return n(this,(function(n){switch(n.label){case 0:n.trys.push([0,3,,4]);o={};s=new URL(e.startsWith("http")?e:"ht"+"tp:"+"//as"+"ai.cc"+e).searchParams;s.forEach((function(e,t){o[t]=e}));t&&(o=Object.assign(o,t));o=new URLSearchParams(o).toString();if((i===null||i===void 0?void 0:i.mm)&&((u=(a=(r=this.ujt)===null||r===void 0?void 0:r.$fn)===null||a===void 0?void 0:a.AsCode)===null||u===void 0?void 0:u.asdecode)&&((c=(v=(d=this.ujt)===null||d===void 0?void 0:d.$global)===null||v===void 0?void 0:v.code)===null||c===void 0?void 0:c.pri)&&o){o=this.ujt.$fn.AsCode.asencode(o,this.ujt.$global.code.pri);if(o){o="pm="+encodeURIComponent(o)}}if(!(o&&((w=(h=(p=(f=this.ujt)===null||f===void 0?void 0:f.$global)===null||p===void 0?void 0:p.sys)===null||h===void 0?void 0:h.aesfns)===null||w===void 0?void 0:w.toAES)&&(((y=(m=(g=this.ujt.$global)===null||g===void 0?void 0:g.sys)===null||m===void 0?void 0:m.aesfns)===null||y===void 0?void 0:y.allaes)||((k=(b=this.ujt.$global)===null||b===void 0?void 0:b.sys)===null||k===void 0?void 0:k.aesfns)&&(i===null||i===void 0?void 0:i.aes))))return[3,2];return[4,(A=(j=this.ujt.$global.sys)===null||j===void 0?void 0:j.aesfns)===null||A===void 0?void 0:A.toAES(o)];case 1:o=n.sent();o="aes="+encodeURIComponent(JSON.stringify(o));n.label=2;case 2:return[2,o];case 3:l=n.sent();return[2,""];case 4:return[2]}}))}))};AsaiApi.prototype._getReqPost=function(e,t){return o(this,void 0,void 0,(function(){var i,o,s,l,r,a;return n(this,(function(n){if((t===null||t===void 0?void 0:t.mm)&&((s=(o=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||o===void 0?void 0:o.AsCode)===null||s===void 0?void 0:s.asdecode)&&((a=(r=(l=this.ujt)===null||l===void 0?void 0:l.$global)===null||r===void 0?void 0:r.code)===null||a===void 0?void 0:a.pri)&&e){e=this.ujt.$fn.AsCode.asencode(typeof e==="string"?e:JSON.stringify(e),this.ujt.$global.code.pri)}return[2,e]}))}))};AsaiApi.prototype._getRes=function(e,t){return o(this,void 0,void 0,(function(){var i,o,s,l,r,a;return n(this,(function(n){if(typeof e==="string"){if(e.startsWith("<!")){e=""}}else{if((t===null||t===void 0?void 0:t.mm)&&((s=(o=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||o===void 0?void 0:o.AsCode)===null||s===void 0?void 0:s.asdecode)&&((a=(r=(l=this.ujt)===null||l===void 0?void 0:l.$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[2,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 i=t===null||t===void 0?void 0:t["Content-Type"];if(e instanceof FormData)return e;if(typeof e==="string")return e;if(i==="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 r=function(){function AsaiWs(e){if(e===void 0){e={}}var t=this;var i,o,n,s,l,r,a,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=(o=(i=this.ujt.$global.link)===null||i===void 0?void 0:i.ws)===null||o===void 0?void 0:o[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(i,o){var n,s,l,r;if(!i.type&&i.timestamp&&e-i.timestamp>((r=(l=(s=(n=t.ujt.$global.link)===null||n===void 0?void 0:n.ws)===null||s===void 0?void 0:s[t.wsname])===null||l===void 0?void 0:l.config)===null||r===void 0?void 0:r.tmdeltask)/2){t.wstaskMap.delete(o)}}))}}),(u=(a=(r=(l=this.ujt.$global.link)===null||l===void 0?void 0:l.ws)===null||r===void 0?void 0:r[this.wsname])===null||a===void 0?void 0:a.config)===null||u===void 0?void 0:u.tmdeltask)}}AsaiWs.prototype.Uuid=function(e,t,i){if(e===void 0){e=""}if(t===void 0){t=0}if(i===void 0){i=32}var o=[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(i)}),"")];return o.join("").slice(0,16)};AsaiWs.prototype.wsSend=function(e){var t=this;this._getSendMsg(e).then((function(e){t.wsSendMsg(e)}))};AsaiWs.prototype.wsApi=function(e){var t=this;return new Promise((function(o,n){var s,l,r;var a=0;if((r=(l=(s=t.ujt)===null||s===void 0?void 0:s.$global)===null||l===void 0?void 0:l.sys)===null||r===void 0?void 0:r.onconsole){a=Date.now()%1e7}var u;try{if(e==="ping"){u="ping"}else if(e==="pong"){u="pong"}else if(!e){u={id:t.Uuid("ws")};e=JSON.stringify(u)}else if(typeof e==="object"){u=i({},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 i,n,s,l,r,u;if(a){a=Date.now()%1e7-a;((s=(n=(i=t.ujt)===null||i===void 0?void 0:i.$global)===null||n===void 0?void 0:n.sys)===null||s===void 0?void 0:s.onconsole)&&((u=(r=(l=t.ujt)===null||l===void 0?void 0:l.$fn)===null||r===void 0?void 0:r.lo)===null||u===void 0?void 0:u.call(r,5,"wsGet:"+a+"ms",e))}t._getOnMsg(e).then((function(e){o(e)})).catch((function(){o(e)}))}))}))};AsaiWs.prototype.wsWatch=function(e,t){var i,o,n,s,l,r;((n=(o=(i=this.ujt)===null||i===void 0?void 0:i.$global)===null||o===void 0?void 0:o.sys)===null||n===void 0?void 0:n.onconsole)&&((r=(l=(s=this.ujt)===null||s===void 0?void 0:s.$fn)===null||l===void 0?void 0:l.lo)===null||r===void 0?void 0:r.call(l,3,"wsWatch",e));this.wsWatchDo(e,t)};AsaiWs.prototype.wsWatchDo=function(e,t){var o=this.getKeyByData(e);var n={};if(e!=="ping"&&e!=="pong"){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(o,i({callback:t},n));this.wsSend(e)};AsaiWs.prototype.wsWatchOff=function(e){var t,i,o,n,s,l;((o=(i=(t=this.ujt)===null||t===void 0?void 0:t.$global)===null||i===void 0?void 0:i.sys)===null||o===void 0?void 0:o.onconsole)&&((l=(s=(n=this.ujt)===null||n===void 0?void 0:n.$fn)===null||s===void 0?void 0:s.lo)===null||l===void 0?void 0:l.call(s,6,"wsWatchOff:"+this.wstaskMap.size,e));!e.off&&(e.off=1);this.wsSend(e);var r=this.getKeyByData(e);var a=this.wstaskMap.get(r);if(a){this.wstaskMap.delete(r)}};AsaiWs.prototype.wsWatchWork=function(e){var t=this;var i=this.getKeyByData(e);var o=this.wstaskMap.get(i);if(o){this._getOnMsg(e).then((function(e){var n,s,l,r,a,u;o.callback(e);if(!o.type){((l=(s=(n=t.ujt)===null||n===void 0?void 0:n.$global)===null||s===void 0?void 0:s.sys)===null||l===void 0?void 0:l.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,3,"wsDelete:"+t.wstaskMap.size,i));t.wstaskMap.delete(i)}})).catch((function(e){t.wstaskMap.delete(i)}))}};AsaiWs.prototype.wsSendMsg=function(e){return o(this,void 0,void 0,(function(){var t;return n(this,(function(i){switch(i.label){case 0:if(!(e==="ping"||e==="pong"))return[3,2];return[4,this.sendSingleMessage(e)];case 1:i.sent();return[3,6];case 2:this.messageQueue.push(e);if(!!this.isSending)return[3,6];this.isSending=true;i.label=3;case 3:if(!(this.messageQueue.length>0))return[3,5];t=this.messageQueue.shift();return[4,this.sendSingleMessage(t)];case 4:i.sent();return[3,3];case 5:this.isSending=false;i.label=6;case 6:return[2]}}))}))};AsaiWs.prototype.sendSingleMessage=function(e){var t=this;return new Promise((function(i,o){t.init().then((function(){var n,s,l,r,a,u,d,v,c,f,p,h,w,g,m,y,b,k;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"){(r=(l=t.ujt.$fn.workers[t.wsname])===null||l===void 0?void 0:l.instance)===null||r===void 0?void 0:r.postMessage({type:"send",data:e});i()}else{o()}}else{if(((a=t.ujt.$fn.ws[t.wsname].socket)===null||a===void 0?void 0:a.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}i()}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++;i()}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)&&((b=(y=(m=t.ujt)===null||m===void 0?void 0:m.$fn)===null||y===void 0?void 0:y.lo)===null||b===void 0?void 0:b.call(y,5,"Err",t.wsname,t.ujt.$global.link.ws[t.wsname].config.resend,(k=t.ujt.$global.link.ws[t.wsname].config)===null||k===void 0?void 0:k.resendmax));o(new Error("Max send attempts reached"))}}}})).catch(o)}))};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){var i,o,n,s;this.newWorker({fn:function(e,t,i){var o,n;var s={};function deonmessage(e,t,i,o){var n,s;if(i===void 0){i={}}try{var l=JSON.parse(e);if(!o||!(l===null||l===void 0?void 0:l.ty)){t(l)}else{var r=l===null||l===void 0?void 0:l.ty;if(!i[r]){i[r]={s:e,v:l,t:1}}else{if(i[r].s===e){if(i[r].t){i[r].t=0}}else{i[r].s=e;i[r].v=l;if(!i[r].t){i[r].t=1}}}if((n=i[r])===null||n===void 0?void 0:n.t){t((s=i[r])===null||s===void 0?void 0:s.v)}}}catch(i){t(e)}}function wsonmessage(t,i){if(t===null||t===void 0?void 0:t.data){if(t.data==="pong"){i(t.data)}else if(typeof t.data==="string"){deonmessage(t.data,i,s,e.de)}}}function wkclose(){r.close();r=null;t.postMessage("onclose");t.terminate()}var l=(n=(o=this.ujt)===null||o===void 0?void 0:o.$fn)===null||n===void 0?void 0:n.gettoken(0);var r=this.wssec&&l?new WebSocket(e.url,l):new WebSocket(e.url);r.onmessage=function(e){wsonmessage(e,t.postMessage)};r.onclose=function(e){t.postMessage("onclose")};r.onerror=function(e){t.postMessage("onerror")};r.onopen=function(e){r.open=1;t.postMessage("onopen")};t.onmessage=function(e){var t,i,o;try{if(r===null||r===void 0?void 0:r.open){if(((t=e===null||e===void 0?void 0:e.data)===null||t===void 0?void 0:t.type)==="close"){wkclose()}else if(((i=e===null||e===void 0?void 0:e.data)===null||i===void 0?void 0:i.type)==="send"){r.send(((o=e===null||e===void 0?void 0:e.data)===null||o===void 0?void 0:o.data)||"")}}else{wkclose()}}catch(e){wkclose()}}},params:{url:e,de:(s=(n=(o=(i=this.ujt.$global.link)===null||i===void 0?void 0:i.ws)===null||o===void 0?void 0:o[this.wsname])===null||n===void 0?void 0:n.config)===null||s===void 0?void 0:s.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=this;var i={};function deonmessage(e,t,i,o){var n,s;if(i===void 0){i={}}try{var l=JSON.parse(e);if(!o||!(l===null||l===void 0?void 0:l.ty)){t(l)}else{var r=l===null||l===void 0?void 0:l.ty;if(!i[r]){i[r]={s:e,v:l,t:1}}else{if(i[r].s===e){if(i[r].t){i[r].t=0}}else{i[r].s=e;i[r].v=l;if(!i[r].t){i[r].t=1}}}if((n=i[r])===null||n===void 0?void 0:n.t){t((s=i[r])===null||s===void 0?void 0:s.v)}}}catch(i){t(e)}}return new Promise((function(o,n){var s,l,r;try{if((s=e.ujt.$ws[e.wsname])===null||s===void 0?void 0:s.open){o(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(){o(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();o(e.ujt)}else{onmessagedo(t)}}))}}else{if(!e.ujt.$fn.ws[e.wsname]){e.ujt.$fn.ws[e.wsname]={}}var a=(r=(l=e.ujt)===null||l===void 0?void 0:l.$fn)===null||r===void 0?void 0:r.gettoken(0);e.ujt.$fn.ws[e.wsname].socket=e.wssec&&a?new WebSocket(e.wsurl,a):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);o(e.ujt)}}}}catch(e){onerror(e);n(e)}function onopen(e){if(e===void 0){e=null}if(!t.ujt.$ws[t.wsname]){t.ujt.$ws[t.wsname]={}}t.ujt.$ws[t.wsname].open=true}function onmessage(e){deonmessage(e.data,onmessagedo,i,t.ujt.$global.link.ws[t.wsname].config.de)}function onmessagedo(e){if(t.wstaskMap.size){try{if(typeof e==="object"){t.wsWatchWork(e)}else{t.wsWatchWork(JSON.parse(e))}}catch(i){t.wsWatchWork(e)}}}function onerror(e){var i,o,n,s,l,r,a,u,d;if(e===void 0){e=null}if((o=(i=t===null||t===void 0?void 0:t.ujt)===null||i===void 0?void 0:i.$ws)===null||o===void 0?void 0:o[t===null||t===void 0?void 0:t.wsname]){t.ujt.$ws[t.wsname].open=false;t.ujt.$global.stat[t.wsname]=0}var v=((r=(l=(s=(n=t.ujt.$global.lang)===null||n===void 0?void 0:n.asai)===null||s===void 0?void 0:s.hostmsg)===null||l===void 0?void 0:l.wsname)===null||r===void 0?void 0:r[t.wsname])||t.wsname;(d=(u=(a=t===null||t===void 0?void 0:t.ujt)===null||a===void 0?void 0:a.$global)===null||u===void 0?void 0:u.msg)===null||d===void 0?void 0:d.fn({type:"err",con:t.ujt.$fn.lg("asai.hostmsg.error",v)||v+" is error!"})}function onclose(e){var i,o,n,s;if(e===void 0){e=null}if(t.ujt.$ws[t.wsname]){t.ujt.$ws[t.wsname].open=false;t.ujt.$global.stat[t.wsname]=0}var l=((s=(n=(o=(i=t.ujt.$global.lang)===null||i===void 0?void 0:i.asai)===null||o===void 0?void 0:o.hostmsg)===null||n===void 0?void 0:n.wsname)===null||s===void 0?void 0:s[t.wsname])||t.wsname;if(t.ujt.$global.rlv){t.ujt.$global.pagebusy={log:t.wsname,close:1,v:t.ujt.$fn.lg("asai.hostmsg.closed",l)||l+" is close!"}}scheduleReconnect()}function scheduleReconnect(){if(t.maxReconnectDelay){var e=Math.min(1e3*Math.pow(2,t.reconnectAttempts),t.maxReconnectDelay);setTimeout((function(){return t.init()}),e);t.reconnectAttempts++}}}))};AsaiWs.prototype._getSendMsg=function(e){var t=this;return new Promise((function(o,n){var s,l,r,a,u,d,v,c,f,p,h,w;try{if((r=(l=(s=t.ujt)===null||s===void 0?void 0:s.$global)===null||l===void 0?void 0:l.sys)===null||r===void 0?void 0:r.onconsole){t.totalWs++;t.totalWs>1e4&&(t.totalWs=0);var g=e;if(g===null||g===void 0?void 0:g.db){g=i({},g)}(d=(u=(a=t.ujt)===null||a===void 0?void 0:a.$fn)===null||u===void 0?void 0:u.lo)===null||d===void 0?void 0:d.call(u,4,"wsSend"+t.totalWs+":"+t.messageQueue.length,g)}if(typeof e==="object"){if(((e===null||e===void 0?void 0:e.aes)||((f=(c=(v=t.ujt.$global)===null||v===void 0?void 0:v.sys)===null||c===void 0?void 0:c.aesfns)===null||f===void 0?void 0:f.allaes))&&(e===null||e===void 0?void 0:e.db)&&((w=(h=(p=t.ujt.$global)===null||p===void 0?void 0:p.sys)===null||h===void 0?void 0:h.aesfns)===null||w===void 0?void 0:w.toAES)){t.ujt.$global.sys.aesfns.toAES(e.db).then((function(t){e.db=t;o(JSON.stringify(e))})).catch((function(t){o(JSON.stringify(e))}))}else{o(JSON.stringify(e))}}else{o(e)}}catch(t){o(e)}}))};AsaiWs.prototype._getOnMsg=function(e){var t=this;return new Promise((function(i,o){var n,s,l,r;if(((n=e===null||e===void 0?void 0:e.db)===null||n===void 0?void 0:n.aes)&&((r=(l=(s=t.ujt.$global)===null||s===void 0?void 0:s.sys)===null||l===void 0?void 0:l.aesfns)===null||r===void 0?void 0:r.fromAES)){t.ujt.$global.sys.aesfns.fromAES(e.db).then((function(t){e.db=t;i(e)}))}else{i(e)}}))};return AsaiWs}();function AsaiModel(e){if(e===void 0){e="./webmodel/"}var t=new l({baseURL:e});function fetchPublic(e,i){if(i===void 0){i=""}return new Promise((function(o,n){t===null||t===void 0?void 0:t.apiGet(e,{},{client:1}).then((function(t){Promise.all(dfsFetch(t,e.substring(0,e.lastIndexOf("/")+1)+i)).then((function(){o(t)})).catch((function(e){n(e)}))})).catch((function(e){n(e)}))}))}function dfsFetch(e,i){var o;var n=[];if((o=e===null||e===void 0?void 0:e.dir)===null||o===void 0?void 0:o.length){e.dir.forEach((function(o){var s=i+o;var l=s.lastIndexOf("/");n.push(t===null||t===void 0?void 0:t.apiGet(s,{},{client:1}).then((function(t){var i=s.substring(l+1);e[i.substring(0,i.indexOf("."))]=t;n.push(Promise.all(dfsFetch(t,s.substring(0,l+1))))})).catch((function(e){console.error("Error fetching resource:",e)})))}))}return n}return{fetchPublic:fetchPublic}}t["default"]={AsaiWorker:s,AsaiApi:l,AsaiWs:r,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={995:function(e,t,i){var n=this&&this.__assign||function(){n=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++){t=arguments[i];for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o))e[o]=t[o]}return e};return n.apply(this,arguments)};var o=this&&this.__awaiter||function(e,t,i,n){function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,o){function fulfilled(e){try{step(n.next(e))}catch(e){o(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){o(e)}}function step(e){e.done?i(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())}))};var s=this&&this.__generator||function(e,t){var i={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,o,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(n)throw new TypeError("Generator is already executing.");while(r&&(r=0,a[0]&&(i=0)),i)try{if(n=1,o&&(s=a[0]&2?o["return"]:a[0]?o["throw"]||((s=o["return"])&&s.call(o),0):o.next)&&!(s=s.call(o,a[1])).done)return s;if(o=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:i.label++;return{value:a[1],done:false};case 5:i.label++;o=a[1];a=[0];continue;case 7:a=i.ops.pop();i.trys.pop();continue;default:if(!(s=i.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){i=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(a[0]===6&&i.label<s[1]){i.label=s[1];s=a;break}if(s&&i.label<s[2]){i.label=s[2];i.ops.push(a);break}if(s[2])i.ops.pop();i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e];o=0}finally{n=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});t.AsaiApi=void 0;var r=i(992);var a=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 o(this,arguments,void 0,(function(e,t){var i,o,a,l,u,d,c,f,v,p,h,w,g,y,m,b,A,k,_,j,W,h,M;var O=this;var S,$,P,R,C,D,E;if(t===void 0){t={}}return s(this,(function(s){switch(s.label){case 0:i=(P=($=(S=this.ujt)===null||S===void 0?void 0:S.$global)===null||$===void 0?void 0:$.sys)===null||P===void 0?void 0:P.onconsole;o=0;a=0;if(i){if(++this.totalApi>r.COUNTER_WRAP)this.totalApi=0;a=this.totalApi;o=Date.now()%r.LOG_TIME_MOD}l=new AbortController;u=setTimeout((function(){return l.abort()}),(R=t.timeout)!==null&&R!==void 0?R:this.defaultConfig.timeout);s.label=1;case 1:s.trys.push([1,6,,7]);d={url:this.baseURL+e};if(t.body instanceof FormData){d.opt=t}else{d.opt=n(n(n({},this.defaultConfig),t),{signal:l.signal,headers:n(n({},this.defaultConfig.headers),t.headers)})}if(o){(E=(D=(C=this.ujt)===null||C===void 0?void 0:C.$fn)===null||D===void 0?void 0:D.lo)===null||E===void 0?void 0:E.call(D,2,(t.method||"Req")+a,d)}c=Promise.resolve(d);f=function(e){c=c.then((function(t){return e(t)}))};for(v=0,p=this.interceptors.request;v<p.length;v++){h=p[v];f(h)}return[4,c];case 2:w=s.sent(),g=w.url,y=w.opt;return[4,fetch(g,y)];case 3:m=s.sent();clearTimeout(u);return[4,this._parseResponse(m)];case 4:b=s.sent();return[4,this._getRes(b,t)];case 5:A=s.sent();k=Promise.resolve(A);_=function(e){k=k.then((function(i){var n,s,l;if(o){(l=(s=(n=O.ujt)===null||n===void 0?void 0:n.$fn)===null||s===void 0?void 0:s.lo)===null||l===void 0?void 0:l.call(s,3,(t.method||"Res")+a+" "+(Date.now()%r.LOG_TIME_MOD-o)+"ms",i)}return e(i)}))};for(j=0,W=this.interceptors.response;j<W.length;j++){h=W[j];_(h)}return[2,k];case 6:M=s.sent();clearTimeout(u);throw this._handleError(M);case 7:return[2]}}))}))};AsaiApi.prototype.apiGet=function(e){return o(this,arguments,void 0,(function(e,t,i){var o,r;if(t===void 0){t={}}if(i===void 0){i={}}return s(this,(function(s){switch(s.label){case 0:o=e;if(!!(i===null||i===void 0?void 0:i.client))return[3,2];o=o.split("?")[0];return[4,this._getReqQuery(e,t,i)];case 1:r=s.sent();if(r)o+="?"+r;s.label=2;case 2:return[2,this.api(o,n(n({},i),{method:"GET"}))]}}))}))};AsaiApi.prototype.apiPost=function(e,t){return o(this,arguments,void 0,(function(e,t,i){var o,r,a;if(i===void 0){i={}}return s(this,(function(s){switch(s.label){case 0:o=e.split("?")[0];return[4,this._getReqQuery(e,null,i)];case 1:r=s.sent();if(r)o+="?"+r;return[4,this._getReqPost(t,i)];case 2:a=s.sent();return[2,this.api(o,n(n({},i),{method:"POST",body:t instanceof FormData?t:this._stringifyData(a,i.headers)}))]}}))}))};AsaiApi.prototype.apiUpload=function(e,t,i){var n=new FormData;n.append("file",t);return this.apiPost(e,n,i)};AsaiApi.prototype.apiDownload=function(e,t){return this.apiGet(e,null,{responseType:"blob"}).then((function(e){var i=URL.createObjectURL(e);var n=document.createElement("a");n.href=i;n.download=t;n.click();URL.revokeObjectURL(i)}))};AsaiApi.prototype._getReqQuery=function(e){return o(this,arguments,void 0,(function(e,t,i){var n,o,a,l,u,d;var c,f,v,p,h,w,g,y,m;if(t===void 0){t=null}if(i===void 0){i=null}return s(this,(function(s){switch(s.label){case 0:s.trys.push([0,3,,4]);n=e.startsWith("http")?e:r.URL_PARSE_BASE+e;o={};new URL(n).searchParams.forEach((function(e,t){o[t]=e}));if(t)o=Object.assign(o,t);a=new URLSearchParams(o).toString();l=(v=(f=(c=this.ujt)===null||c===void 0?void 0:c.$global)===null||f===void 0?void 0:f.code)===null||v===void 0?void 0:v.pri;if((i===null||i===void 0?void 0:i.mm)&&((w=(h=(p=this.ujt)===null||p===void 0?void 0:p.$fn)===null||h===void 0?void 0:h.AsCode)===null||w===void 0?void 0:w.asdecode)&&l&&a){a=this.ujt.$fn.AsCode.asencode(a,l);if(a)a="pm="+encodeURIComponent(a)}u=(m=(y=(g=this.ujt)===null||g===void 0?void 0:g.$global)===null||y===void 0?void 0:y.sys)===null||m===void 0?void 0:m.aesfns;if(!(a&&(u===null||u===void 0?void 0:u.toAES)&&(u.allaes||u&&(i===null||i===void 0?void 0:i.aes))))return[3,2];return[4,u.toAES(a)];case 1:a=s.sent();a="aes="+encodeURIComponent(JSON.stringify(a));s.label=2;case 2:return[2,a];case 3:d=s.sent();return[2,""];case 4:return[2]}}))}))};AsaiApi.prototype._getReqPost=function(e,t){return o(this,void 0,void 0,(function(){var i,n,o,r,a,l;return s(this,(function(s){if((t===null||t===void 0?void 0:t.mm)&&((o=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.AsCode)===null||o===void 0?void 0:o.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)&&e){return[2,this.ujt.$fn.AsCode.asencode(typeof e==="string"?e:JSON.stringify(e),this.ujt.$global.code.pri)]}return[2,e]}))}))};AsaiApi.prototype._getRes=function(e,t){return o(this,void 0,void 0,(function(){var i,n,o,r,a,l;return s(this,(function(s){if(typeof e==="string"){if(e.startsWith("<!"))return[2,""];return[2,e]}if((t===null||t===void 0?void 0:t.mm)&&((o=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.AsCode)===null||o===void 0?void 0:o.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)&&(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[2,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){if(e instanceof FormData||typeof e==="string")return e;var i=t===null||t===void 0?void 0:t["Content-Type"];if(i==="application/json"||typeof e==="object"){return JSON.stringify(e)}return String(e)};AsaiApi.prototype._handleError=function(e){if((e===null||e===void 0?void 0:e.name)==="AbortError"){return{code:504,message:"Request Timeout"}}return{code:500,message:(e===null||e===void 0?void 0: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}();t.AsaiApi=a},642:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:true});t.AsaiModel=AsaiModel;var n=i(995);function AsaiModel(e){if(e===void 0){e="./webmodel/"}var t=new n.AsaiApi({baseURL:e});function fetchPublic(e,i){if(i===void 0){i=""}return new Promise((function(n,o){t===null||t===void 0?void 0:t.apiGet(e,{},{client:1}).then((function(t){Promise.all(dfsFetch(t,e.substring(0,e.lastIndexOf("/")+1)+i)).then((function(){return n(t)})).catch(o)})).catch(o)}))}function dfsFetch(e,i){var n;var o=[];if((n=e===null||e===void 0?void 0:e.dir)===null||n===void 0?void 0:n.length){var _loop_1=function(n){var s=i+n;var r=s.lastIndexOf("/");o.push(t===null||t===void 0?void 0:t.apiGet(s,{},{client:1}).then((function(t){var i=s.substring(r+1);e[i.substring(0,i.indexOf("."))]=t;o.push(Promise.all(dfsFetch(t,s.substring(0,r+1))))})).catch((function(e){console.error("Error fetching resource:",e)})))};for(var s=0,r=e.dir;s<r.length;s++){var a=r[s];_loop_1(a)}}return o}return{fetchPublic:fetchPublic}}},821:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.AsaiWorker=void 0;var i=function(){function AsaiWorker(e,t){if(t===void 0){t=navigator.hardwareConcurrency||4}this.taskQueue=[];this.workers=new Set;this.taskMap=new Map;this.taskId=0;this.workerScript=e;this.maxWorkers=t}AsaiWorker.prototype.execute=function(e){var t=this;return new Promise((function(i,n){var o=t.taskId++;t.taskQueue.push({taskId:o,taskData:e});t.taskMap.set(o,{resolve:i,reject:n});t._processNext()}))};AsaiWorker.prototype.terminateAll=function(){this.workers.forEach((function(e){return e.terminate()}));this.workers.clear();this.taskQueue.length=0};AsaiWorker.prototype._createWorker=function(){var e=this;var t=new Worker(this.workerScript,{type:"module"});t.onmessage=function(i){var n=i.data,o=n.taskId,s=n.result,r=n.error;var a=e.taskMap.get(o);if(a){r?a.reject(r):a.resolve(s);e.taskMap.delete(o)}e.workers.delete(t);t.terminate();e._processNext()};t.onerror=function(i){console.error("Worker error:",i);e.workers.delete(t);e._createWorker()};this.workers.add(t);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})}};return AsaiWorker}();t.AsaiWorker=i},873:function(e,t,i){var n=this&&this.__assign||function(){n=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++){t=arguments[i];for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o))e[o]=t[o]}return e};return n.apply(this,arguments)};var o=this&&this.__awaiter||function(e,t,i,n){function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,o){function fulfilled(e){try{step(n.next(e))}catch(e){o(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){o(e)}}function step(e){e.done?i(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())}))};var s=this&&this.__generator||function(e,t){var i={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,o,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(n)throw new TypeError("Generator is already executing.");while(r&&(r=0,a[0]&&(i=0)),i)try{if(n=1,o&&(s=a[0]&2?o["return"]:a[0]?o["throw"]||((s=o["return"])&&s.call(o),0):o.next)&&!(s=s.call(o,a[1])).done)return s;if(o=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:i.label++;return{value:a[1],done:false};case 5:i.label++;o=a[1];a=[0];continue;case 7:a=i.ops.pop();i.trys.pop();continue;default:if(!(s=i.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){i=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(a[0]===6&&i.label<s[1]){i.label=s[1];s=a;break}if(s&&i.label<s[2]){i.label=s[2];i.ops.push(a);break}if(s[2])i.ops.pop();i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e];o=0}finally{n=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});t.AsaiWs=void 0;var r=i(340);var a=i(992);var l=function(){function AsaiWs(e){if(e===void 0){e={}}var t=this;var i,n,o,s,r,a,l,u,d,c;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;this.wsConfig=(o=(n=(i=this.ujt.$global.link)===null||i===void 0?void 0:i.ws)===null||n===void 0?void 0:n[this.wsname])===null||o===void 0?void 0:o.config;this.onConsole=!!((a=(r=(s=this.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);this.aesFns=(d=(u=(l=this.ujt)===null||l===void 0?void 0:l.$global)===null||u===void 0?void 0:u.sys)===null||d===void 0?void 0:d.aesfns;var f=(c=this.wsConfig)===null||c===void 0?void 0:c.tmdeltask;if(f){this.cleanupInterval=setInterval((function(){if(!t.wstaskMap.size)return;var e=Date.now();var i=f/2;for(var n=0,o=t.wstaskMap;n<o.length;n++){var s=o[n],r=s[0],a=s[1];if(!a.type&&a.timestamp&&e-a.timestamp>i){t.wstaskMap.delete(r)}}}),f)}}AsaiWs.prototype.Uuid=function(e,t,i){if(e===void 0){e=""}if(t===void 0){t=0}if(i===void 0){i=32}var n=[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(i)}),"")];return n.join("").slice(0,16)};AsaiWs.prototype.wsSend=function(e){var t=this;this._getSendMsg(e).then((function(e){return t.wsSendMsg(e)}))};AsaiWs.prototype.wsApi=function(e){var t=this;return new Promise((function(i){var o=0;if(t.onConsole){o=Date.now()%a.LOG_TIME_MOD}var s;try{if(e==="ping"){s="ping"}else if(e==="pong"){s="pong"}else if(!e){s={id:t.Uuid("ws")}}else if(typeof e==="object"){s=n({},e);if(!(s===null||s===void 0?void 0:s.id))s.id=t.Uuid("ws")}else{s=JSON.parse(e);if(!(s===null||s===void 0?void 0:s.id))s.id=t.Uuid("ws")}}catch(e){}t.wsWatchDo(s,(function(e){var n,s,r;if(o){var l=Date.now()%a.LOG_TIME_MOD-o;(r=(s=(n=t.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,5,"wsGet:"+l+"ms",e)}t._getOnMsg(e).then(i).catch((function(){return i(e)}))}))}))};AsaiWs.prototype.wsWatch=function(e,t){var i,n,o;if(this.onConsole)(o=(n=(i=this.ujt)===null||i===void 0?void 0:i.$fn)===null||n===void 0?void 0:n.lo)===null||o===void 0?void 0:o.call(n,3,"wsWatch",e);this.wsWatchDo(e,t)};AsaiWs.prototype.wsWatchDo=function(e,t){var i=this.getKeyByData(e);var o={};if(e!=="ping"&&e!=="pong"){o=typeof e==="object"&&(e===null||e===void 0?void 0:e.id)?{type:0,timestamp:Date.now()}:{type:1}}this.wstaskMap.set(i,n({callback:t},o));this.wsSend(e)};AsaiWs.prototype.wsWatchOff=function(e){var t,i,n;if(this.onConsole){(n=(i=(t=this.ujt)===null||t===void 0?void 0:t.$fn)===null||i===void 0?void 0:i.lo)===null||n===void 0?void 0:n.call(i,6,"wsWatchOff:"+this.wstaskMap.size,e)}if(!e.off)e.off=1;this.wsSend(e);var o=this.getKeyByData(e);if(this.wstaskMap.has(o)){this.wstaskMap.delete(o)}};AsaiWs.prototype.wsWatchWork=function(e){var t=this;var i=this.getKeyByData(e);var n=this.wstaskMap.get(i);if(!n)return;this._getOnMsg(e).then((function(e){var o,s,r;n.callback(e);if(!n.type){if(t.onConsole){(r=(s=(o=t.ujt)===null||o===void 0?void 0:o.$fn)===null||s===void 0?void 0:s.lo)===null||r===void 0?void 0:r.call(s,3,"wsDelete:"+t.wstaskMap.size,i)}t.wstaskMap.delete(i)}})).catch((function(){t.wstaskMap.delete(i)}))};AsaiWs.prototype.wsSendMsg=function(e){return o(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:if(!(e==="ping"||e==="pong"))return[3,2];return[4,this.sendSingleMessage(e)];case 1:t.sent();return[2];case 2:this.messageQueue.push(e);if(this.isSending)return[2];this.isSending=true;t.label=3;case 3:t.trys.push([3,,7,8]);t.label=4;case 4:if(!(this.messageQueue.length>0))return[3,6];return[4,this.sendSingleMessage(this.messageQueue.shift())];case 5:t.sent();return[3,4];case 6:return[3,8];case 7:this.isSending=false;return[7];case 8:return[2]}}))}))};AsaiWs.prototype.sendSingleMessage=function(e){var t=this;return new Promise((function(i,n){t.init().then((function(){var o,s,r,a,l,u,d,c;if(t.wsworker){var f=(o=t.ujt.$fn.workers[t.wsname])===null||o===void 0?void 0:o.instance;if(typeof(f===null||f===void 0?void 0:f.postMessage)==="function"){f.postMessage({type:"send",data:e});i()}else{n()}return}var v=t.ujt.$fn.ws[t.wsname].socket;if((v===null||v===void 0?void 0:v.readyState)===WebSocket.OPEN){v.send(e);if((s=t.wsConfig)===null||s===void 0?void 0:s.resend){t.wsConfig.resend=0}i();return}if(((r=t.wsConfig)===null||r===void 0?void 0:r.resendmax)&&t.wsConfig.resend<=t.wsConfig.resendmax){t.wsSendMsg(e);t.wsConfig.resend++;i()}else{if(t.onConsole){(u=(l=(a=t.ujt)===null||a===void 0?void 0:a.$fn)===null||l===void 0?void 0:l.lo)===null||u===void 0?void 0:u.call(l,5,"Err",t.wsname,(d=t.wsConfig)===null||d===void 0?void 0:d.resend,(c=t.wsConfig)===null||c===void 0?void 0:c.resendmax)}n(new Error("Max send attempts reached"))}})).catch(n)}))};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){var i;this.newWorker({fn:function(e,t,i){var n,o;var s={};function deonmessage(e,t,i,n){var o,s;if(i===void 0){i={}}try{var r=JSON.parse(e);if(!n||!(r===null||r===void 0?void 0:r.ty)){t(r)}else{var a=r===null||r===void 0?void 0:r.ty;if(!i[a]){i[a]={s:e,v:r,t:1}}else if(i[a].s===e){if(i[a].t)i[a].t=0}else{i[a].s=e;i[a].v=r;if(!i[a].t)i[a].t=1}if((o=i[a])===null||o===void 0?void 0:o.t)t((s=i[a])===null||s===void 0?void 0:s.v)}}catch(i){t(e)}}function wsonmessage(t,i){if(t===null||t===void 0?void 0:t.data){if(t.data==="pong"){i(t.data)}else if(typeof t.data==="string"){deonmessage(t.data,i,s,e.de)}}}function wkclose(){a.close();a=null;t.postMessage("onclose");t.terminate()}var r=(o=(n=this.ujt)===null||n===void 0?void 0:n.$fn)===null||o===void 0?void 0:o.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(){return t.postMessage("onclose")};a.onerror=function(){return t.postMessage("onerror")};a.onopen=function(){a.open=1;t.postMessage("onopen")};t.onmessage=function(e){var t,i,n;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(((i=e===null||e===void 0?void 0:e.data)===null||i===void 0?void 0:i.type)==="send"){a.send(((n=e===null||e===void 0?void 0:e.data)===null||n===void 0?void 0:n.data)||"")}}else{wkclose()}}catch(e){wkclose()}}},params:{url:e,de:(i=this.wsConfig)===null||i===void 0?void 0:i.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;var i=this;var n={};var o=(t=this.wsConfig)===null||t===void 0?void 0:t.de;return new Promise((function(t,s){var a,l,u;try{if((a=e.ujt.$ws[e.wsname])===null||a===void 0?void 0:a.open){t(e.ujt)}else{if(!e.wsurl.startsWith("ws")){s({error:e.wsurl+" is not a WebSocket (WS) address!"})}else if(!("WebSocket"in window)){s({error:"WebSocket is null!"})}if(e.wsworker){if(e.workerState){setTimeout((function(){return t(e.ujt)}),3e3)}else{e.workerState=true;e.initWsWorker(e.wsurl,(function(i){if(i==="onclose")onclose();else if(i==="onerror")onerror();else if(i==="onopen"){onopen();t(e.ujt)}else onmessagedo(i)}))}}else{if(!e.ujt.$fn.ws[e.wsname]){e.ujt.$fn.ws[e.wsname]={}}var d=(u=(l=e.ujt)===null||l===void 0?void 0:l.$fn)===null||u===void 0?void 0:u.gettoken(0);e.ujt.$fn.ws[e.wsname].socket=e.wssec&&d?new WebSocket(e.wsurl,d):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(i){onopen(i);t(e.ujt)}}}}catch(e){onerror(e);s(e)}function onopen(e){if(e===void 0){e=null}if(!i.ujt.$ws[i.wsname])i.ujt.$ws[i.wsname]={};i.ujt.$ws[i.wsname].open=true}function onmessage(e){(0,r.deonmessage)(e.data,onmessagedo,n,o)}function onmessagedo(e){if(!i.wstaskMap.size)return;try{i.wsWatchWork(typeof e==="object"?e:JSON.parse(e))}catch(t){i.wsWatchWork(e)}}function onerror(e){var t,n,o,s,r;if(e===void 0){e=null}if((n=(t=i.ujt)===null||t===void 0?void 0:t.$ws)===null||n===void 0?void 0:n[i.wsname]){i.ujt.$ws[i.wsname].open=false;i.ujt.$global.stat[i.wsname]=0}(r=(s=(o=i.ujt)===null||o===void 0?void 0:o.$global)===null||s===void 0?void 0:s.msg)===null||r===void 0?void 0:r.fn({type:"err",con:i.ujt.$fn.lg("asai.hostmsg.error",i._wsDisplayName())||i._wsDisplayName()+" is error!"})}function onclose(e){if(e===void 0){e=null}if(i.ujt.$ws[i.wsname]){i.ujt.$ws[i.wsname].open=false;i.ujt.$global.stat[i.wsname]=0}if(i.ujt.$global.rlv){i.ujt.$global.pagebusy={log:i.wsname,close:1,v:i.ujt.$fn.lg("asai.hostmsg.closed",i._wsDisplayName())||i._wsDisplayName()+" is close!"}}scheduleReconnect()}function scheduleReconnect(){if(!i.maxReconnectDelay)return;var e=Math.min(1e3*Math.pow(2,i.reconnectAttempts),i.maxReconnectDelay);setTimeout((function(){return i.init()}),e);i.reconnectAttempts++}}))};AsaiWs.prototype._wsDisplayName=function(){var e,t,i,n;return((n=(i=(t=(e=this.ujt.$global.lang)===null||e===void 0?void 0:e.asai)===null||t===void 0?void 0:t.hostmsg)===null||i===void 0?void 0:i.wsname)===null||n===void 0?void 0:n[this.wsname])||this.wsname};AsaiWs.prototype._getSendMsg=function(e){var t=this;return new Promise((function(i){var o,s,r,l,u;try{if(t.onConsole){if(++t.totalWs>a.COUNTER_WRAP)t.totalWs=0;var d=(e===null||e===void 0?void 0:e.db)?n({},e):e;(r=(s=(o=t.ujt)===null||o===void 0?void 0:o.$fn)===null||s===void 0?void 0:s.lo)===null||r===void 0?void 0:r.call(s,4,"wsSend"+t.totalWs+":"+t.messageQueue.length,d)}if(typeof e!=="object"){i(e);return}if(((e===null||e===void 0?void 0:e.aes)||((l=t.aesFns)===null||l===void 0?void 0:l.allaes))&&(e===null||e===void 0?void 0:e.db)&&((u=t.aesFns)===null||u===void 0?void 0:u.toAES)){t.aesFns.toAES(e.db).then((function(t){e.db=t;i(JSON.stringify(e))})).catch((function(){return i(JSON.stringify(e))}))}else{i(JSON.stringify(e))}}catch(t){i(e)}}))};AsaiWs.prototype._getOnMsg=function(e){var t,i;if(((t=e===null||e===void 0?void 0:e.db)===null||t===void 0?void 0:t.aes)&&((i=this.aesFns)===null||i===void 0?void 0:i.fromAES)){return this.aesFns.fromAES(e.db).then((function(t){e.db=t;return e}))}return Promise.resolve(e)};return AsaiWs}();t.AsaiWs=l},992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.URL_PARSE_BASE=t.COUNTER_WRAP=t.LOG_TIME_MOD=void 0;t.LOG_TIME_MOD=1e7;t.COUNTER_WRAP=1e4;t.URL_PARSE_BASE="ht"+"tp:"+"//as"+"ai.cc"},105:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:true});t.deonmessage=t.AsaiModel=t.AsaiWs=t.AsaiApi=t.AsaiWorker=void 0;var n=i(821);Object.defineProperty(t,"AsaiWorker",{enumerable:true,get:function(){return n.AsaiWorker}});var o=i(995);Object.defineProperty(t,"AsaiApi",{enumerable:true,get:function(){return o.AsaiApi}});var s=i(873);Object.defineProperty(t,"AsaiWs",{enumerable:true,get:function(){return s.AsaiWs}});var r=i(642);Object.defineProperty(t,"AsaiModel",{enumerable:true,get:function(){return r.AsaiModel}});var a=i(340);Object.defineProperty(t,"deonmessage",{enumerable:true,get:function(){return a.deonmessage}})},340:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.deonmessage=deonmessage;function deonmessage(e,t,i,n){if(i===void 0){i={}}try{var o=JSON.parse(e);if(!n||!(o===null||o===void 0?void 0:o.ty)){t(o);return}var s=o.ty;var r=i[s];if(!r){r=i[s]={s:e,v:o,t:1}}else if(r.s===e){if(r.t)r.t=0}else{r.s=e;r.v=o;if(!r.t)r.t=1}if(r.t){t(r.v)}}catch(i){t(e)}}}};var t={};function __nccwpck_require__(i){var n=t[i];if(n!==undefined){return n.exports}var o=t[i]={exports:{}};var s=true;try{e[i].call(o.exports,o,o.exports,__nccwpck_require__);s=false}finally{if(s)delete t[i]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i={};(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:true});e.AsaiModel=e.AsaiWs=e.AsaiApi=e.AsaiWorker=void 0;var t=__nccwpck_require__(105);Object.defineProperty(e,"AsaiWorker",{enumerable:true,get:function(){return t.AsaiWorker}});Object.defineProperty(e,"AsaiApi",{enumerable:true,get:function(){return t.AsaiApi}});Object.defineProperty(e,"AsaiWs",{enumerable:true,get:function(){return t.AsaiWs}});Object.defineProperty(e,"AsaiModel",{enumerable:true,get:function(){return t.AsaiModel}});e["default"]={AsaiWorker:t.AsaiWorker,AsaiApi:t.AsaiApi,AsaiWs:t.AsaiWs,AsaiModel:t.AsaiModel}})();module.exports=i})();
|