template-replacement 3.1.0 → 3.2.0
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 +178 -0
- package/dist/base-dj-SYiQI.js +193 -0
- package/dist/index-BlAsmv2Q.js +62 -0
- package/dist/main/general.js +15 -4600
- package/dist/main/sign.js +15 -4623
- package/dist/replace/general.js +337 -384
- package/dist/replace/sign.js +339 -384
- package/fileSystem/db/index.ts +37 -0
- package/{db → fileSystem/db}/indexedDBCache.ts +16 -0
- package/fileSystem/index.ts +13 -0
- package/fileSystem/interface.ts +8 -0
- package/fileSystem/opfs/index.ts +46 -0
- package/helper/index.ts +1 -3
- package/index.ts +10 -0
- package/package.json +3 -4
- package/pnpm-workspace.yaml +2 -0
- package/task/urlDownloadTask.ts +18 -8
- package/vite.config.ts +13 -1
- package/db/index.ts +0 -5
- package/dist/base-DCmHytJQ.js +0 -214
- package/dist/index-BkwrGCka.js +0 -61
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
### 文件变量替换
|
|
2
|
+
[demo地址](https://gitee.com/zvc/template-replacement-demo)
|
|
3
|
+
|
|
4
|
+
目前支持替换DOCX和XLSX类型的文件,对应的文件MIME信息为:
|
|
5
|
+
application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
|
6
|
+
application/vnd.openxmlformats-officedocument.wordprocessingml.template
|
|
7
|
+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
|
8
|
+
|
|
9
|
+
##### 已实现功能:
|
|
10
|
+
- ✅ 支持DOCX和XLSX文件进行替换
|
|
11
|
+
- ✅ 支持使用文件数据/文件下载地址替换
|
|
12
|
+
- ✅ 文本=>文本替换
|
|
13
|
+
- ✅ 文本=>图片替换
|
|
14
|
+
- ✅ 媒体文件=>媒体文件替换(同类型)
|
|
15
|
+
- ✅ 支持多线程处理
|
|
16
|
+
- ✅ 变量提取
|
|
17
|
+
- ✅ 媒体文件提取
|
|
18
|
+
- ✅ 模板文件加密/替换加密模板(确保文件无法被第三方使用)
|
|
19
|
+
##### 待实现功能:
|
|
20
|
+
- 支持PPTX文件进行替换
|
|
21
|
+
- 更多媒体类型替换
|
|
22
|
+
- 支持更多媒体属性配置
|
|
23
|
+
<br>
|
|
24
|
+
|
|
25
|
+
#### 功能演示
|
|
26
|
+
##### 一、实例化替换对象
|
|
27
|
+
1、模板替换:
|
|
28
|
+
``` javascript
|
|
29
|
+
import tr from 'template-replacement'
|
|
30
|
+
const replaceInstance = tr()
|
|
31
|
+
```
|
|
32
|
+
2、多线程模板替换:
|
|
33
|
+
需要同时替换大量文件时使用
|
|
34
|
+
``` javascript
|
|
35
|
+
import tr from 'template-replacement'
|
|
36
|
+
const worker = 4 //线程数量
|
|
37
|
+
const replaceInstance = tr(worker)
|
|
38
|
+
```
|
|
39
|
+
3、模板替换并校验签名:
|
|
40
|
+
需结合后端做签名校验,前端替换之前需要请求后端获取签名,不想让前端直接使用模板替换功能的场景可以用这个方式,可以确保每次模板替换都是经过后端授权验证的。
|
|
41
|
+
``` javascript
|
|
42
|
+
import tr from 'template-replacement'
|
|
43
|
+
|
|
44
|
+
// 获取函数签名
|
|
45
|
+
async function getSignature(data) {
|
|
46
|
+
/** 对data数据进行签名处理,可以请求后端获取签名或者通过其他方式生成签名,不要前端直接生成 */
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const replaceInstance = tr(0, getSignature)
|
|
50
|
+
```
|
|
51
|
+
4、多线程模板替换并校验签名:
|
|
52
|
+
``` javascript
|
|
53
|
+
import tr from 'template-replacement'
|
|
54
|
+
const worker = 4 //线程数量
|
|
55
|
+
const replaceInstance = tr(worker, getSignature)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
##### 二、添加模板
|
|
59
|
+
支持对docx、xlsx格式的文件进行替换,支持传递File、Blob、Uint8Array类型的文件数据或者文件下载地址
|
|
60
|
+
``` typescript
|
|
61
|
+
import temp from 'template-replacement/temp'
|
|
62
|
+
|
|
63
|
+
//文件名类型
|
|
64
|
+
type fileName = string
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 1、实例化一个模板文件数据,file、url、uint8Array必须传一个
|
|
68
|
+
* file?: File|Blob 文件数据
|
|
69
|
+
* url?: string 文件下载地址
|
|
70
|
+
* uint8Array?: Uint8Array 文件数据
|
|
71
|
+
* name?: fileName 文件名,必须设置文件名且同一批次替换的文件中文件名不能重复,
|
|
72
|
+
* 如果file传递了File数据默认按照File中的name属性作为文件名
|
|
73
|
+
*/
|
|
74
|
+
const tempFile = new temp(file, url, uint8Array, name)
|
|
75
|
+
|
|
76
|
+
// 2、标记出加密的模板文件,未加密的文件跳过这一步
|
|
77
|
+
tempFile.isDecode = true
|
|
78
|
+
|
|
79
|
+
// 3、把模板文件加入到替换任务中
|
|
80
|
+
//每次加一个,可多次添加
|
|
81
|
+
replaceInstance.addTempFile(tempFile)
|
|
82
|
+
|
|
83
|
+
// 4、清除所有模板文件
|
|
84
|
+
replaceInstance.clear()
|
|
85
|
+
```
|
|
86
|
+
##### 三、批量提取模板中的媒体文件数据(不需要提取媒体文件数据时跳过这一步)
|
|
87
|
+
``` typescript
|
|
88
|
+
//媒体文件id,同一个媒体文件在一个模板中多次使用或在不同模板中的id相同
|
|
89
|
+
type mediaID = string
|
|
90
|
+
//媒体数据
|
|
91
|
+
type Media = {
|
|
92
|
+
id: mediaID, // 媒体文件id
|
|
93
|
+
data: Uint8Array, // 媒体文件数据
|
|
94
|
+
}
|
|
95
|
+
type extractMediasResult = Record<fileName, Media[]>
|
|
96
|
+
|
|
97
|
+
//tempFiles: temp[] 为模板文件数组
|
|
98
|
+
const result: extractMediasResult = await replaceInstance.extractMedias(tempFiles)
|
|
99
|
+
```
|
|
100
|
+
##### 四、提取模板变量(不需要提取变量时跳过这一步)
|
|
101
|
+
``` typescript
|
|
102
|
+
/**
|
|
103
|
+
* 变量名,建议使用 ${name} 格式
|
|
104
|
+
* 理论上支持任意文本格式,为避免出现未知问题变量名最好使用中文或者英文字符
|
|
105
|
+
*/
|
|
106
|
+
type variableName = string
|
|
107
|
+
type extractVariablesResult = Record<fileName, variableName[]>
|
|
108
|
+
const result: extractVariablesResult = await replaceInstance.extractVariables()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
##### 五、执行变量替换
|
|
112
|
+
``` typescript
|
|
113
|
+
import paramsData, { textData, mediaData } from 'template-replacement/replace/paramsData'
|
|
114
|
+
import image from 'template-replacement/replace/image'
|
|
115
|
+
|
|
116
|
+
//变量值
|
|
117
|
+
type variableValue = string
|
|
118
|
+
type textData = Record<variableName, variableValue|image>
|
|
119
|
+
type mediaData = Record<mediaID, image>
|
|
120
|
+
type executeResult = Record<fileName, Uint8Array>
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 替换的变量数据
|
|
124
|
+
* texts: textData 文本变量数据,将模板中的文本变量替换为指定文本或者媒体数据
|
|
125
|
+
* medias: mediaData 媒体变量数据,将模板中的媒体文件替换为指定媒体数据
|
|
126
|
+
*/
|
|
127
|
+
const params = new paramsData(texts, medias)
|
|
128
|
+
const result: executeResult = await replaceInstance.execute(params)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
##### 其他说明
|
|
133
|
+
1、媒体文件替换,目前仅支持图片替换,其他文件类型暂不支持
|
|
134
|
+
``` typescript
|
|
135
|
+
import image from 'template-replacement/replace/image'
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* file: Blob 媒体文件
|
|
139
|
+
*/
|
|
140
|
+
const media = new image(file)
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 设置图片的宽高(像素)
|
|
144
|
+
*/
|
|
145
|
+
media.setPxExtent(width: number, height: number)
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 设置图片的宽高(厘米)
|
|
149
|
+
*/
|
|
150
|
+
media.setCmExtent(width: number, height: number)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
2、文件加密,需要防止被第三方获取到模板文件的场景可以使用。
|
|
154
|
+
``` typescript
|
|
155
|
+
|
|
156
|
+
// 加密后的文件数据,按照传入的文件顺序返回
|
|
157
|
+
type filesEncryptResult = Uint8Array[]
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 批量加密文件
|
|
161
|
+
* buffers: Uint8Array[] 待加密的文件数据
|
|
162
|
+
*/
|
|
163
|
+
const result: filesEncryptResult = await replaceInstance.filesEncrypt(buffers)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
3、模板对象部分属性说明
|
|
167
|
+
``` typescript
|
|
168
|
+
//template-replacement/temp
|
|
169
|
+
class temp {
|
|
170
|
+
name: string = '' //文件名
|
|
171
|
+
blob?: File|Blob //文件数据
|
|
172
|
+
uint8Array?: Uint8Array //文件数据
|
|
173
|
+
url?: string //文件下载地址
|
|
174
|
+
status = status.waitLoad // 文件状态 0文件待加载,1文件已加载,2完成替换,3替换失败
|
|
175
|
+
isDecode: boolean = false //文件是否被加密
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
```
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _e, _t;
|
|
9
|
+
new class {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._initFinishCallBackFuns = [], this._isInitFinish = false, this._dbName = "template_replacement", this._dbversion = 1, this._cacheTableName = "templates", this._tableMap = {}, this.initDB();
|
|
12
|
+
}
|
|
13
|
+
initDB() {
|
|
14
|
+
return new Promise((e2, t2) => {
|
|
15
|
+
const a2 = indexedDB.open(this._dbName, this._dbversion);
|
|
16
|
+
a2.onsuccess = (t3) => {
|
|
17
|
+
if (this._db = a2.result, this._isInitFinish = true, this._initFinishCallBackFuns) {
|
|
18
|
+
try {
|
|
19
|
+
for (const e3 of this._initFinishCallBackFuns) e3();
|
|
20
|
+
} catch (e3) {
|
|
21
|
+
}
|
|
22
|
+
this._initFinishCallBackFuns = void 0;
|
|
23
|
+
}
|
|
24
|
+
e2(t3);
|
|
25
|
+
}, a2.onerror = (e3) => {
|
|
26
|
+
console.error(e3), t2(e3);
|
|
27
|
+
}, a2.onupgradeneeded = (t3) => {
|
|
28
|
+
let i = a2.result;
|
|
29
|
+
i.objectStoreNames.contains(this._cacheTableName) || i.createObjectStore(this._cacheTableName, { keyPath: "url" }), e2(t3);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async awaitInit() {
|
|
34
|
+
!this._isInitFinish && this._initFinishCallBackFuns && await new Promise((e2, t2) => {
|
|
35
|
+
var _a;
|
|
36
|
+
(_a = this._initFinishCallBackFuns) == null ? void 0 : _a.push(e2);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
closeDB() {
|
|
40
|
+
var _a;
|
|
41
|
+
(_a = this._db) == null ? void 0 : _a.close();
|
|
42
|
+
}
|
|
43
|
+
async store(e2) {
|
|
44
|
+
await this.awaitInit();
|
|
45
|
+
return this._db.transaction(this._cacheTableName, e2).objectStore(this._cacheTableName);
|
|
46
|
+
}
|
|
47
|
+
putData(e2) {
|
|
48
|
+
return new Promise(async (t2, a2) => {
|
|
49
|
+
const i = (await this.store("readwrite")).put(e2);
|
|
50
|
+
i.onsuccess = (e3) => {
|
|
51
|
+
t2(e3);
|
|
52
|
+
}, i.onerror = (e3) => {
|
|
53
|
+
a2(e3);
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getDataByKey(e2) {
|
|
58
|
+
return new Promise(async (t2, a2) => {
|
|
59
|
+
const i = (await this.store()).get(e2);
|
|
60
|
+
i.onsuccess = () => {
|
|
61
|
+
t2(i.result);
|
|
62
|
+
}, i.onerror = (e3) => {
|
|
63
|
+
a2(e3);
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
deleteDataByKey(e2) {
|
|
68
|
+
return new Promise(async (t2, a2) => {
|
|
69
|
+
const i = (await this.store()).delete(e2);
|
|
70
|
+
i.onsuccess = () => {
|
|
71
|
+
t2();
|
|
72
|
+
}, i.onerror = (e3) => {
|
|
73
|
+
a2(e3);
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
clearDB() {
|
|
78
|
+
return new Promise(async (e2, t2) => {
|
|
79
|
+
const a2 = (await this.store("readwrite")).clear();
|
|
80
|
+
a2.onsuccess = (t3) => {
|
|
81
|
+
e2(t3);
|
|
82
|
+
}, a2.onerror = (e3) => {
|
|
83
|
+
t2(e3);
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}();
|
|
88
|
+
var e = ((e2) => (e2.word = "word", e2.excel = "excel", e2.unknown = "unknown", e2))(e || {});
|
|
89
|
+
class t {
|
|
90
|
+
constructor(e2) {
|
|
91
|
+
__privateAdd(this, _e, []);
|
|
92
|
+
__privateAdd(this, _t);
|
|
93
|
+
__privateSet(this, _t, e2);
|
|
94
|
+
}
|
|
95
|
+
addTempFile(e2) {
|
|
96
|
+
__privateGet(this, _e).push(e2);
|
|
97
|
+
}
|
|
98
|
+
clear() {
|
|
99
|
+
__privateGet(this, _e).length = 0;
|
|
100
|
+
}
|
|
101
|
+
async extractVariables(t2) {
|
|
102
|
+
t2 || (t2 = __privateGet(this, _e));
|
|
103
|
+
const a2 = {}, i = [];
|
|
104
|
+
for (const s of t2) i.push(new Promise(async (t3, i2) => {
|
|
105
|
+
const n = await s.getBuffer();
|
|
106
|
+
n && (s.isDecode || await s.type() !== e.unknown) && (a2[s.name] = await __privateGet(this, _t).extract_one_file_variable_names(n, s.isDecode)), t3();
|
|
107
|
+
}));
|
|
108
|
+
return await Promise.all(i), a2;
|
|
109
|
+
}
|
|
110
|
+
async extractMedias(t2) {
|
|
111
|
+
t2 || (t2 = __privateGet(this, _e));
|
|
112
|
+
const a2 = {}, i = [];
|
|
113
|
+
for (const s of t2) i.push(new Promise(async (t3, i2) => {
|
|
114
|
+
const n = await s.getBuffer();
|
|
115
|
+
if (n && (s.isDecode || await s.type() !== e.unknown)) {
|
|
116
|
+
let e2 = await __privateGet(this, _t).extract_one_file_medias(n, s.isDecode);
|
|
117
|
+
a2[s.name] = [], e2 && Array.isArray(e2) && e2.forEach((e3) => {
|
|
118
|
+
e3.id && e3.data && a2[s.name].push({ id: e3.id, data: new Uint8Array(e3.data) });
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
t3();
|
|
122
|
+
}));
|
|
123
|
+
return await Promise.all(i), a2;
|
|
124
|
+
}
|
|
125
|
+
async handle(e2, t2, a2 = false) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
async sign(e2) {
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
async execute(e2, t2) {
|
|
132
|
+
t2 || (t2 = __privateGet(this, _e));
|
|
133
|
+
const a2 = [];
|
|
134
|
+
for (const e3 of t2) a2.push(e3.getBuffer());
|
|
135
|
+
await Promise.all(a2);
|
|
136
|
+
const i = { decode: { names: [], uint8Arrays: [] }, noDecode: { names: [], uint8Arrays: [] } };
|
|
137
|
+
for (const e3 of t2) e3.uint8Array && (e3.isDecode ? (i.decode.names.push(e3.name), i.decode.uint8Arrays.push(e3.uint8Array)) : (i.noDecode.names.push(e3.name), i.noDecode.uint8Arrays.push(e3.uint8Array)));
|
|
138
|
+
const s = await Promise.all([this._execute(e2, i.noDecode.names, i.noDecode.uint8Arrays, false), this._execute(e2, i.decode.names, i.decode.uint8Arrays, true)]);
|
|
139
|
+
return { ...s[0], ...s[1] };
|
|
140
|
+
}
|
|
141
|
+
async _execute(e2, t2, a2, i = false) {
|
|
142
|
+
const s = {};
|
|
143
|
+
if (!a2.length) return s;
|
|
144
|
+
return (await this.handle(e2, a2, i)).forEach((e3, a3) => {
|
|
145
|
+
e3.length && (s[t2[a3]] = e3);
|
|
146
|
+
}), s;
|
|
147
|
+
}
|
|
148
|
+
async fileEncrypt(e2) {
|
|
149
|
+
return await __privateGet(this, _t).file_encrypt(e2);
|
|
150
|
+
}
|
|
151
|
+
async filesEncrypt(e2) {
|
|
152
|
+
return await __privateGet(this, _t).files_encrypt(e2);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
_e = new WeakMap();
|
|
156
|
+
_t = new WeakMap();
|
|
157
|
+
class a {
|
|
158
|
+
constructor(e2, t2) {
|
|
159
|
+
this.awaitInit = e2, this.module = t2;
|
|
160
|
+
}
|
|
161
|
+
async await() {
|
|
162
|
+
return await this.awaitInit, this;
|
|
163
|
+
}
|
|
164
|
+
async add_template(e2, t2) {
|
|
165
|
+
return await this.awaitInit, this.module.add_template(e2, t2);
|
|
166
|
+
}
|
|
167
|
+
async add_media(e2) {
|
|
168
|
+
return await this.awaitInit, this.module.add_media(e2);
|
|
169
|
+
}
|
|
170
|
+
async extract_one_file_variable_names(e2, t2) {
|
|
171
|
+
return await this.awaitInit, this.module.extract_one_file_variable_names(e2, t2);
|
|
172
|
+
}
|
|
173
|
+
async extract_variable_names(e2, t2) {
|
|
174
|
+
return await this.awaitInit, this.module.extract_variable_names(e2, t2);
|
|
175
|
+
}
|
|
176
|
+
async extract_one_file_medias(e2, t2) {
|
|
177
|
+
return await this.awaitInit, this.module.extract_one_file_medias(e2, t2);
|
|
178
|
+
}
|
|
179
|
+
async extract_medias(e2, t2) {
|
|
180
|
+
return await this.awaitInit, this.module.extract_medias(e2, t2);
|
|
181
|
+
}
|
|
182
|
+
async file_encrypt(e2) {
|
|
183
|
+
return await this.awaitInit, this.module.file_encrypt(e2);
|
|
184
|
+
}
|
|
185
|
+
async files_encrypt(e2) {
|
|
186
|
+
await this.awaitInit;
|
|
187
|
+
return this.module.files_encrypt(e2);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
t as B,
|
|
192
|
+
a as b
|
|
193
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
10
|
+
set _(value) {
|
|
11
|
+
__privateSet(obj, member, value, setter);
|
|
12
|
+
},
|
|
13
|
+
get _() {
|
|
14
|
+
return __privateGet(obj, member, getter);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
var _r, _s, _e, _t, _r_instances, c_fn;
|
|
18
|
+
class r {
|
|
19
|
+
constructor(r2, s) {
|
|
20
|
+
__privateAdd(this, _r_instances);
|
|
21
|
+
__privateAdd(this, _r);
|
|
22
|
+
__privateAdd(this, _s, 0);
|
|
23
|
+
__privateAdd(this, _e, []);
|
|
24
|
+
__privateAdd(this, _t, []);
|
|
25
|
+
if (__privateSet(this, _r, Number(s)), !__privateGet(this, _r) || __privateGet(this, _r) < 1) try {
|
|
26
|
+
__privateSet(this, _r, navigator.hardwareConcurrency < 8 ? navigator.hardwareConcurrency : 8);
|
|
27
|
+
} catch (r3) {
|
|
28
|
+
}
|
|
29
|
+
(!__privateGet(this, _r) || __privateGet(this, _r) < 1) && __privateSet(this, _r, 1);
|
|
30
|
+
for (let s2 = 0; s2 < __privateGet(this, _r); s2++) __privateMethod(this, _r_instances, c_fn).call(this, r2);
|
|
31
|
+
}
|
|
32
|
+
concurrency() {
|
|
33
|
+
return __privateGet(this, _r);
|
|
34
|
+
}
|
|
35
|
+
postMessage(r2, s) {
|
|
36
|
+
__privateGet(this, _e)[++__privateWrapper(this, _s)._] || __privateSet(this, _s, 0), __privateGet(this, _e)[__privateGet(this, _s)].postMessage(r2, s);
|
|
37
|
+
}
|
|
38
|
+
addListener(r2) {
|
|
39
|
+
__privateGet(this, _t).push(r2);
|
|
40
|
+
}
|
|
41
|
+
removeListener(r2) {
|
|
42
|
+
for (const s in __privateGet(this, _t)) if (__privateGet(this, _t)[s] == r2) return void __privateGet(this, _t).splice(s, 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
_r = new WeakMap();
|
|
46
|
+
_s = new WeakMap();
|
|
47
|
+
_e = new WeakMap();
|
|
48
|
+
_t = new WeakMap();
|
|
49
|
+
_r_instances = new WeakSet();
|
|
50
|
+
c_fn = function(r2) {
|
|
51
|
+
const s = new r2();
|
|
52
|
+
s.onmessage = async (r3) => {
|
|
53
|
+
const e = [];
|
|
54
|
+
for (const s2 of __privateGet(this, _t)) e.push(s2(r3));
|
|
55
|
+
(await Promise.all(e)).forEach((r4) => {
|
|
56
|
+
r4 && s.postMessage(r4);
|
|
57
|
+
});
|
|
58
|
+
}, __privateGet(this, _e).push(s);
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
r as w
|
|
62
|
+
};
|