template-replacement 3.3.3 → 3.4.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/.editorconfig +8 -0
- package/.oxfmtrc.jsonc +7 -0
- package/.oxlintrc.json +3 -0
- package/README.md +39 -9
- package/core/base.ts +54 -55
- package/core/general.ts +37 -9
- package/core/sign.ts +43 -8
- package/dispatcher/general.ts +2 -1
- package/dispatcher/sign.ts +2 -1
- package/dispatcher/workerGeneral.ts +1 -1
- package/dispatcher/workerSign.ts +1 -1
- package/dist/base-DQz39fXI.js +249 -0
- package/dist/index-oILo_kXG.js +46 -0
- package/dist/main/general.js +1334 -1384
- package/dist/main/sign.js +1476 -1514
- package/dist/replace/general.js +283 -313
- package/dist/replace/sign.js +309 -327
- package/download/index.ts +13 -13
- package/download/stream.ts +29 -28
- package/eslint.config.ts +28 -0
- package/fileSystem/db/index.ts +25 -25
- package/fileSystem/db/indexedDBCache.ts +145 -143
- package/fileSystem/index.ts +5 -8
- package/fileSystem/interface.ts +4 -5
- package/fileSystem/opfs/index.ts +40 -36
- package/helper/index.ts +136 -125
- package/index.ts +6 -6
- package/office/zip.ts +106 -97
- package/package.json +14 -8
- package/replace/base.ts +203 -222
- package/replace/general.ts +44 -24
- package/replace/image.ts +88 -90
- package/replace/interface.ts +29 -24
- package/replace/paramsData.ts +107 -95
- package/replace/sign.ts +79 -52
- package/task/urlDownloadTask.ts +53 -55
- package/temp/index.ts +139 -124
- package/temp/interface.ts +8 -8
- package/tsconfig.json +1 -1
- package/vite.config.ts +11 -14
- package/worker/child/agency.ts +49 -41
- package/worker/child/base.ts +125 -89
- package/worker/child/general.ts +2 -3
- package/worker/child/sign.ts +4 -4
- package/worker/index.ts +52 -53
- package/worker/interface.ts +9 -6
- package/worker/main/general.ts +5 -5
- package/worker/main/index.ts +191 -66
- package/worker/main/sign.ts +5 -5
- package/worker/type.ts +16 -15
- package/dist/assets/template_replacement_core_wasm_bg.wasm +0 -0
- package/dist/assets/template_replacement_sign_core_wasm_bg.wasm +0 -0
- package/dist/base-CJv023nf.js +0 -284
- package/dist/general.d.ts +0 -1
- package/dist/index-tFDVIkZX.js +0 -46
- package/dist/sign.d.ts +0 -1
package/.editorconfig
ADDED
package/.oxfmtrc.jsonc
ADDED
package/.oxlintrc.json
ADDED
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
|
|
16
16
|
- ✅ 变量提取
|
|
17
17
|
- ✅ 媒体文件提取
|
|
18
18
|
- ✅ 模板文件加密/替换加密模板(确保文件无法被第三方使用)
|
|
19
|
+
- ✅ 多套变量同时替换
|
|
19
20
|
##### 待实现功能:
|
|
20
21
|
- 支持PPTX文件进行替换
|
|
21
22
|
- 更多媒体类型替换
|
|
@@ -33,7 +34,7 @@ const replaceInstance = tr()
|
|
|
33
34
|
需要同时替换大量文件时使用
|
|
34
35
|
``` javascript
|
|
35
36
|
import tr from 'template-replacement'
|
|
36
|
-
const worker = 4
|
|
37
|
+
const worker = 4 //线程数量,建议<=CPU核心数
|
|
37
38
|
const replaceInstance = tr(worker)
|
|
38
39
|
```
|
|
39
40
|
3、模板替换并校验签名:
|
|
@@ -43,7 +44,11 @@ import tr from 'template-replacement'
|
|
|
43
44
|
|
|
44
45
|
// 获取函数签名
|
|
45
46
|
async function getSignature(data) {
|
|
46
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* 对data数据进行签名处理,
|
|
49
|
+
* 可以请求后端获取签名或者通过其他方式生成签名,
|
|
50
|
+
* 不要前端直接生成,避免暴露签名方法
|
|
51
|
+
*/
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
const replaceInstance = tr(0, getSignature)
|
|
@@ -51,7 +56,7 @@ const replaceInstance = tr(0, getSignature)
|
|
|
51
56
|
4、多线程模板替换并校验签名:
|
|
52
57
|
``` javascript
|
|
53
58
|
import tr from 'template-replacement'
|
|
54
|
-
const worker = 4
|
|
59
|
+
const worker = 4 //线程数量,建议<=CPU核心数
|
|
55
60
|
const replaceInstance = tr(worker, getSignature)
|
|
56
61
|
```
|
|
57
62
|
|
|
@@ -73,7 +78,7 @@ type fileName = string
|
|
|
73
78
|
*/
|
|
74
79
|
const tempFile = new temp(file, url, uint8Array, name)
|
|
75
80
|
|
|
76
|
-
// 2
|
|
81
|
+
// 2、标记出需要解密的模板文件(通过filesEncrypt方法加密后的文件),未加密的文件跳过这一步
|
|
77
82
|
tempFile.isDecode = true
|
|
78
83
|
|
|
79
84
|
// 3、把模板文件加入到替换任务中
|
|
@@ -83,6 +88,7 @@ replaceInstance.addTempFile(tempFile)
|
|
|
83
88
|
// 4、清除所有模板文件
|
|
84
89
|
replaceInstance.clear()
|
|
85
90
|
```
|
|
91
|
+
|
|
86
92
|
##### 三、批量提取模板中的媒体文件数据(不需要提取媒体文件数据时跳过这一步)
|
|
87
93
|
``` typescript
|
|
88
94
|
//媒体文件id,同一个媒体文件在一个模板中多次使用或在不同模板中的id相同
|
|
@@ -109,6 +115,8 @@ const result: extractVariablesResult = await replaceInstance.extractVariables()
|
|
|
109
115
|
```
|
|
110
116
|
|
|
111
117
|
##### 五、执行变量替换
|
|
118
|
+
支持单套变量替换和多套变量替换,执行替换前需确保模板文件已经完成添加。
|
|
119
|
+
1、单套变量替换:一套模板文件根据一套变量的数据生成一套文件数据
|
|
112
120
|
``` typescript
|
|
113
121
|
import paramsData, { textData, mediaData } from 'template-replacement/replace/paramsData'
|
|
114
122
|
import image from 'template-replacement/replace/image'
|
|
@@ -128,6 +136,29 @@ const params = new paramsData(texts, medias)
|
|
|
128
136
|
const result: executeResult = await replaceInstance.execute(params)
|
|
129
137
|
```
|
|
130
138
|
|
|
139
|
+
2、多套变量替换:一套模板文件根据多套变量的数据生成多套文件数据
|
|
140
|
+
``` typescript
|
|
141
|
+
import paramsData, { textData, mediaData } from 'template-replacement/replace/paramsData'
|
|
142
|
+
import image from 'template-replacement/replace/image'
|
|
143
|
+
|
|
144
|
+
//变量值
|
|
145
|
+
type variableValue = string
|
|
146
|
+
type textData = Record<variableName, variableValue|image>
|
|
147
|
+
type mediaData = Record<mediaID, image>
|
|
148
|
+
type executeResult = Record<fileName, Uint8Array>
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 替换的变量数据
|
|
152
|
+
* texts: textData 文本变量数据,将模板中的文本变量替换为指定文本或者媒体数据
|
|
153
|
+
* medias: mediaData 媒体变量数据,将模板中的媒体文件替换为指定媒体数据
|
|
154
|
+
*/
|
|
155
|
+
const paramsList = [
|
|
156
|
+
new paramsData(texts, medias),
|
|
157
|
+
new paramsData(texts1, medias1),
|
|
158
|
+
new paramsData(texts2, medias2),
|
|
159
|
+
]
|
|
160
|
+
const result: executeResult[] = await replaceInstance.executeMultipleParams(paramsList)
|
|
161
|
+
```
|
|
131
162
|
|
|
132
163
|
##### 其他说明
|
|
133
164
|
1、媒体文件替换,目前仅支持图片替换,其他文件类型暂不支持
|
|
@@ -150,9 +181,8 @@ media.setPxExtent(width: number, height: number)
|
|
|
150
181
|
media.setCmExtent(width: number, height: number)
|
|
151
182
|
```
|
|
152
183
|
|
|
153
|
-
2
|
|
184
|
+
2、文件加密,需要防止被第三方获取到模板文件的场景可以使用(配合class Temp中的isDecode属性进行解码使用)
|
|
154
185
|
``` typescript
|
|
155
|
-
|
|
156
186
|
// 加密后的文件数据,按照传入的文件顺序返回
|
|
157
187
|
type filesEncryptResult = Uint8Array[]
|
|
158
188
|
|
|
@@ -165,14 +195,14 @@ const result: filesEncryptResult = await replaceInstance.filesEncrypt(buffers)
|
|
|
165
195
|
|
|
166
196
|
3、模板对象部分属性说明
|
|
167
197
|
``` typescript
|
|
168
|
-
//template-replacement/temp
|
|
169
|
-
class
|
|
198
|
+
//template-replacement/temp/index.ts
|
|
199
|
+
class Temp {
|
|
170
200
|
name: string = '' //文件名
|
|
171
201
|
blob?: File|Blob //文件数据
|
|
172
202
|
uint8Array?: Uint8Array //文件数据
|
|
173
203
|
url?: string //文件下载地址
|
|
174
204
|
status = status.waitLoad // 文件状态 0文件待加载,1文件已加载,2完成替换,3替换失败
|
|
175
|
-
isDecode: boolean = false
|
|
205
|
+
isDecode: boolean = false //文件是否需要解密
|
|
176
206
|
}
|
|
177
207
|
|
|
178
208
|
```
|
package/core/base.ts
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export interface rawCoreInterface {
|
|
2
|
+
add_media(file: Uint8Array): string
|
|
3
|
+
add_template(file_data: Uint8Array, is_decode: boolean): Promise<number>
|
|
4
|
+
extract_medias(files: Uint8Array[], encode_files: Uint8Array[]): Promise<unknown>
|
|
5
|
+
extract_one_file_medias(data: Uint8Array, is_decode: boolean): Promise<unknown>
|
|
6
|
+
extract_one_file_variable_names(
|
|
7
|
+
data: Uint8Array,
|
|
8
|
+
is_decode: boolean,
|
|
9
|
+
): Promise<string[]>
|
|
10
|
+
extract_variable_names(
|
|
11
|
+
files: Uint8Array[],
|
|
12
|
+
encode_files: Uint8Array[],
|
|
13
|
+
): Promise<string[]>
|
|
14
|
+
file_encrypt(file: Uint8Array): Uint8Array
|
|
15
|
+
files_encrypt(files: Uint8Array[]): Uint8Array[]
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
type PromisifyAll<T> = {
|
|
19
|
+
[K in keyof T]: T[K] extends (...args: infer Args) => infer R
|
|
20
|
+
? (...args: Args) => R extends Promise<unknown>
|
|
21
|
+
? R
|
|
22
|
+
: Promise<R>
|
|
23
|
+
: never;
|
|
24
|
+
};
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
this.awaitInit = init
|
|
19
|
-
this.module = module
|
|
20
|
-
}
|
|
26
|
+
export type AsyncCoreInterface = PromisifyAll<rawCoreInterface>;
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return this
|
|
25
|
-
}
|
|
28
|
+
export default class implements AsyncCoreInterface {
|
|
29
|
+
awaitInit: Promise<rawCoreInterface>
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
+
constructor(init: Promise<rawCoreInterface>) {
|
|
32
|
+
this.awaitInit = init
|
|
33
|
+
}
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
35
|
+
async add_template(file: Uint8Array, is_decode: boolean) {
|
|
36
|
+
return (await this.awaitInit).add_template(file, is_decode)
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
39
|
+
async add_media(file: Uint8Array) {
|
|
40
|
+
return (await this.awaitInit).add_media(file)
|
|
41
|
+
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
43
|
+
async extract_one_file_variable_names(data: Uint8Array, is_decode: boolean) {
|
|
44
|
+
return (await this.awaitInit).extract_one_file_variable_names(data, is_decode)
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
47
|
+
async extract_variable_names(files: Uint8Array[], encode_files: Uint8Array[]) {
|
|
48
|
+
return (await this.awaitInit).extract_variable_names(files, encode_files)
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
51
|
+
async extract_one_file_medias(data: Uint8Array, is_decode: boolean) {
|
|
52
|
+
return (await this.awaitInit).extract_one_file_medias(data, is_decode)
|
|
53
|
+
}
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
55
|
+
async extract_medias(files: Uint8Array[], encode_files: Uint8Array[]) {
|
|
56
|
+
return (await this.awaitInit).extract_medias(files, encode_files)
|
|
57
|
+
}
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
async file_encrypt(file: Uint8Array) {
|
|
60
|
+
return (await this.awaitInit).file_encrypt(file)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async files_encrypt(files: Uint8Array[]) {
|
|
64
|
+
return (await this.awaitInit).files_encrypt(files)
|
|
65
|
+
}
|
|
66
|
+
}
|
package/core/general.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
replace_batch_multiple_params,
|
|
3
|
+
replace_batch,
|
|
4
|
+
add_media,
|
|
5
|
+
add_template,
|
|
6
|
+
extract_medias,
|
|
7
|
+
extract_one_file_medias,
|
|
8
|
+
extract_one_file_variable_names,
|
|
9
|
+
extract_variable_names,
|
|
10
|
+
file_encrypt,
|
|
11
|
+
files_encrypt,
|
|
12
|
+
} from 'template-replacement-core-wasm'
|
|
13
|
+
import init from 'template-replacement-core-wasm'
|
|
14
|
+
import base, { rawCoreInterface } from './base'
|
|
4
15
|
|
|
5
|
-
let awaitInit: Promise<
|
|
16
|
+
let awaitInit: Promise<rawCoreInterface> | undefined
|
|
6
17
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return new base(awaitInit as Promise<any>, core)
|
|
18
|
+
export {
|
|
19
|
+
replace_batch_multiple_params,
|
|
20
|
+
replace_batch
|
|
12
21
|
}
|
|
13
22
|
|
|
23
|
+
export default () => {
|
|
24
|
+
if (!awaitInit) {
|
|
25
|
+
awaitInit = new Promise((resolve) => {
|
|
26
|
+
init().then(() => {
|
|
27
|
+
resolve({
|
|
28
|
+
add_media,
|
|
29
|
+
add_template,
|
|
30
|
+
extract_medias,
|
|
31
|
+
extract_one_file_medias,
|
|
32
|
+
extract_one_file_variable_names,
|
|
33
|
+
extract_variable_names,
|
|
34
|
+
file_encrypt,
|
|
35
|
+
files_encrypt,
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
return new base(awaitInit)
|
|
41
|
+
}
|
package/core/sign.ts
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
replace_batch_multiple_params,
|
|
3
|
+
replace_batch,
|
|
4
|
+
add_media,
|
|
5
|
+
add_template,
|
|
6
|
+
extract_medias,
|
|
7
|
+
extract_one_file_medias,
|
|
8
|
+
extract_one_file_variable_names,
|
|
9
|
+
extract_variable_names,
|
|
10
|
+
file_encrypt,
|
|
11
|
+
files_encrypt,
|
|
12
|
+
replace_params_encode,
|
|
13
|
+
replace_params_encode_multiple_params,
|
|
14
|
+
} from 'template-replacement-sign-core-wasm'
|
|
15
|
+
import init from 'template-replacement-sign-core-wasm'
|
|
16
|
+
import base, { rawCoreInterface } from './base'
|
|
4
17
|
|
|
5
|
-
let awaitInit: Promise<
|
|
18
|
+
let awaitInit: Promise<rawCoreInterface> | undefined
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
add_media,
|
|
22
|
+
add_template,
|
|
23
|
+
replace_params_encode,
|
|
24
|
+
replace_params_encode_multiple_params,
|
|
25
|
+
replace_batch_multiple_params,
|
|
26
|
+
replace_batch
|
|
27
|
+
}
|
|
6
28
|
|
|
7
29
|
export default () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
30
|
+
if (!awaitInit) {
|
|
31
|
+
awaitInit = new Promise((resolve) => {
|
|
32
|
+
init().then(() => {
|
|
33
|
+
resolve({
|
|
34
|
+
add_media,
|
|
35
|
+
add_template,
|
|
36
|
+
extract_medias,
|
|
37
|
+
extract_one_file_medias,
|
|
38
|
+
extract_one_file_variable_names,
|
|
39
|
+
extract_variable_names,
|
|
40
|
+
file_encrypt,
|
|
41
|
+
files_encrypt,
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
return new base(awaitInit)
|
|
12
47
|
}
|
|
13
48
|
|
package/dispatcher/general.ts
CHANGED
package/dispatcher/sign.ts
CHANGED
package/dispatcher/workerSign.ts
CHANGED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
class y {
|
|
2
|
+
// 构造函数
|
|
3
|
+
constructor() {
|
|
4
|
+
this._initFinishCallBackFuns = [], this.#t = !1, this.#e = "template_replacement_db", this.#n = 1, this.#a = "template_files", this.#s();
|
|
5
|
+
}
|
|
6
|
+
#t;
|
|
7
|
+
#e;
|
|
8
|
+
#n;
|
|
9
|
+
#a;
|
|
10
|
+
#s() {
|
|
11
|
+
return this._init ? this._init : (this._init = new Promise((t, e) => {
|
|
12
|
+
const a = indexedDB.open(this.#e, this.#n);
|
|
13
|
+
a.onsuccess = (s) => {
|
|
14
|
+
if (this._db = a.result, this.#t = !0, this._initFinishCallBackFuns) {
|
|
15
|
+
try {
|
|
16
|
+
for (const n of this._initFinishCallBackFuns)
|
|
17
|
+
n();
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
this._initFinishCallBackFuns = void 0;
|
|
21
|
+
}
|
|
22
|
+
t(s);
|
|
23
|
+
}, a.onerror = (s) => {
|
|
24
|
+
console.error(s), e(s);
|
|
25
|
+
}, a.onupgradeneeded = (s) => {
|
|
26
|
+
let n = a.result;
|
|
27
|
+
n.objectStoreNames.contains(this.#a) || n.createObjectStore(this.#a, {
|
|
28
|
+
keyPath: "key"
|
|
29
|
+
// 设置主键
|
|
30
|
+
}), t(s);
|
|
31
|
+
};
|
|
32
|
+
}), this._init);
|
|
33
|
+
}
|
|
34
|
+
async awaitInit() {
|
|
35
|
+
this.#t || !this._initFinishCallBackFuns || await new Promise((t, e) => {
|
|
36
|
+
this._initFinishCallBackFuns?.push(t);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
closeDB() {
|
|
40
|
+
this._db?.close();
|
|
41
|
+
}
|
|
42
|
+
async store(t) {
|
|
43
|
+
return await this.awaitInit(), this._db.transaction(this.#a, t).objectStore(this.#a);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @description : 更新数据
|
|
47
|
+
* @param {templateData} params 添加到数据库中的数据 { key: 文件key, data: 文件blob }
|
|
48
|
+
* @return {*}
|
|
49
|
+
*/
|
|
50
|
+
putData(t) {
|
|
51
|
+
return new Promise((e, a) => {
|
|
52
|
+
this.store("readwrite").then((s) => {
|
|
53
|
+
const n = s.put(t);
|
|
54
|
+
n.onsuccess = (i) => {
|
|
55
|
+
e(i);
|
|
56
|
+
}, n.onerror = (i) => {
|
|
57
|
+
a(i);
|
|
58
|
+
};
|
|
59
|
+
}).catch(a);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// 通过主键读取数据
|
|
63
|
+
getDataByKey(t) {
|
|
64
|
+
return new Promise((e, a) => {
|
|
65
|
+
this.store().then((s) => {
|
|
66
|
+
const n = s.get(t);
|
|
67
|
+
n.onsuccess = () => {
|
|
68
|
+
e(n.result);
|
|
69
|
+
}, n.onerror = (i) => {
|
|
70
|
+
a(i);
|
|
71
|
+
};
|
|
72
|
+
}).catch(a);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// 通过主键移除数据
|
|
76
|
+
deleteDataByKey(t) {
|
|
77
|
+
return new Promise((e, a) => {
|
|
78
|
+
this.store().then((s) => {
|
|
79
|
+
const n = s.delete(t);
|
|
80
|
+
n.onsuccess = () => {
|
|
81
|
+
e(n.result);
|
|
82
|
+
}, n.onerror = (i) => {
|
|
83
|
+
a(i);
|
|
84
|
+
};
|
|
85
|
+
}).catch(a);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// 清空数据库数据
|
|
89
|
+
clearDB() {
|
|
90
|
+
return new Promise((t, e) => {
|
|
91
|
+
this.store("readwrite").then((a) => {
|
|
92
|
+
const s = a.clear();
|
|
93
|
+
s.onsuccess = (n) => {
|
|
94
|
+
t(n);
|
|
95
|
+
}, s.onerror = (n) => {
|
|
96
|
+
e(n);
|
|
97
|
+
};
|
|
98
|
+
}).catch(e);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
new y();
|
|
103
|
+
var d = /* @__PURE__ */ ((r) => (r.word = "word", r.excel = "excel", r.unknown = "unknown", r))(d || {});
|
|
104
|
+
async function f(r = []) {
|
|
105
|
+
const t = [];
|
|
106
|
+
for (const a of r)
|
|
107
|
+
t.push(a.getBuffer());
|
|
108
|
+
await Promise.all(t);
|
|
109
|
+
const e = {
|
|
110
|
+
decode: {
|
|
111
|
+
names: [],
|
|
112
|
+
uint8Arrays: []
|
|
113
|
+
},
|
|
114
|
+
noDecode: {
|
|
115
|
+
names: [],
|
|
116
|
+
uint8Arrays: []
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
for (const a of r)
|
|
120
|
+
a.uint8Array && (a.isDecode ? (e.decode.names.push(a.name), e.decode.uint8Arrays.push(a.uint8Array)) : (e.noDecode.names.push(a.name), e.noDecode.uint8Arrays.push(a.uint8Array)));
|
|
121
|
+
return e;
|
|
122
|
+
}
|
|
123
|
+
class _ {
|
|
124
|
+
#t = [];
|
|
125
|
+
#e;
|
|
126
|
+
constructor(t) {
|
|
127
|
+
this.#e = t;
|
|
128
|
+
}
|
|
129
|
+
addTempFile(t) {
|
|
130
|
+
this.#t.push(t);
|
|
131
|
+
}
|
|
132
|
+
clear() {
|
|
133
|
+
this.#t.length = 0;
|
|
134
|
+
}
|
|
135
|
+
//提取单个文件内的所有变量
|
|
136
|
+
async extractOneFileVariables(t, e) {
|
|
137
|
+
const a = await e.getBuffer();
|
|
138
|
+
a && (await e.type() === d.unknown && !e.isDecode || (t[e.name] = await this.#e.extract_one_file_variable_names(
|
|
139
|
+
a,
|
|
140
|
+
e.isDecode
|
|
141
|
+
)));
|
|
142
|
+
}
|
|
143
|
+
//提取多个文件内的所有变量
|
|
144
|
+
async extractVariables(t) {
|
|
145
|
+
t || (t = this.#t);
|
|
146
|
+
const e = {}, a = [];
|
|
147
|
+
for (const s of t)
|
|
148
|
+
a.push(this.extractOneFileVariables(e, s));
|
|
149
|
+
return await Promise.allSettled(a), e;
|
|
150
|
+
}
|
|
151
|
+
//提取单个文件内的所有媒体文件
|
|
152
|
+
async extractOneFileMedias(t, e) {
|
|
153
|
+
const a = await e.getBuffer();
|
|
154
|
+
if (!a || await e.type() === d.unknown && !e.isDecode)
|
|
155
|
+
return;
|
|
156
|
+
const s = await this.#e.extract_one_file_medias(
|
|
157
|
+
a,
|
|
158
|
+
e.isDecode
|
|
159
|
+
);
|
|
160
|
+
if (t[e.name] = [], !!Array.isArray(s))
|
|
161
|
+
for (const { id: n, data: i } of s)
|
|
162
|
+
n && i && t[e.name].push({
|
|
163
|
+
id: n,
|
|
164
|
+
data: new Uint8Array(i)
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//提取多个文件内的所有媒体文件
|
|
168
|
+
async extractMedias(t) {
|
|
169
|
+
t || (t = this.#t);
|
|
170
|
+
const e = {}, a = [];
|
|
171
|
+
for (const s of t)
|
|
172
|
+
a.push(this.extractOneFileMedias(e, s));
|
|
173
|
+
return await Promise.all(a), e;
|
|
174
|
+
}
|
|
175
|
+
async handle(t, e, a) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
async handleMultipleParams(t, e, a) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
async sign(t) {
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
async execute(t, e) {
|
|
185
|
+
const { noDecode: a, decode: s } = await f(e ?? this.#t), n = await this.handle(t, a.uint8Arrays, s.uint8Arrays), i = {};
|
|
186
|
+
let o = 0;
|
|
187
|
+
for (const c of a.names)
|
|
188
|
+
i[c] = n[o++] ?? new Uint8Array();
|
|
189
|
+
for (const c of s.names)
|
|
190
|
+
i[c] = n[o++] ?? new Uint8Array();
|
|
191
|
+
return i;
|
|
192
|
+
}
|
|
193
|
+
async executeMultipleParams(t, e) {
|
|
194
|
+
const { noDecode: a, decode: s } = await f(e ?? this.#t), n = await this.handleMultipleParams(t, a.uint8Arrays, s.uint8Arrays), i = Array(t.length);
|
|
195
|
+
let o = 0;
|
|
196
|
+
for (let c = 0; c < t.length; c++) {
|
|
197
|
+
const h = {};
|
|
198
|
+
for (const l of a.names) {
|
|
199
|
+
const u = n[o++];
|
|
200
|
+
u.length && (h[l] = u);
|
|
201
|
+
}
|
|
202
|
+
for (const l of s.names) {
|
|
203
|
+
const u = n[o++];
|
|
204
|
+
u.length && (h[l] = u);
|
|
205
|
+
}
|
|
206
|
+
i[c] = h;
|
|
207
|
+
}
|
|
208
|
+
return i;
|
|
209
|
+
}
|
|
210
|
+
async fileEncrypt(t) {
|
|
211
|
+
return this.#e.file_encrypt(t);
|
|
212
|
+
}
|
|
213
|
+
async filesEncrypt(t) {
|
|
214
|
+
return this.#e.files_encrypt(t);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
class m {
|
|
218
|
+
constructor(t) {
|
|
219
|
+
this.awaitInit = t;
|
|
220
|
+
}
|
|
221
|
+
async add_template(t, e) {
|
|
222
|
+
return (await this.awaitInit).add_template(t, e);
|
|
223
|
+
}
|
|
224
|
+
async add_media(t) {
|
|
225
|
+
return (await this.awaitInit).add_media(t);
|
|
226
|
+
}
|
|
227
|
+
async extract_one_file_variable_names(t, e) {
|
|
228
|
+
return (await this.awaitInit).extract_one_file_variable_names(t, e);
|
|
229
|
+
}
|
|
230
|
+
async extract_variable_names(t, e) {
|
|
231
|
+
return (await this.awaitInit).extract_variable_names(t, e);
|
|
232
|
+
}
|
|
233
|
+
async extract_one_file_medias(t, e) {
|
|
234
|
+
return (await this.awaitInit).extract_one_file_medias(t, e);
|
|
235
|
+
}
|
|
236
|
+
async extract_medias(t, e) {
|
|
237
|
+
return (await this.awaitInit).extract_medias(t, e);
|
|
238
|
+
}
|
|
239
|
+
async file_encrypt(t) {
|
|
240
|
+
return (await this.awaitInit).file_encrypt(t);
|
|
241
|
+
}
|
|
242
|
+
async files_encrypt(t) {
|
|
243
|
+
return (await this.awaitInit).files_encrypt(t);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export {
|
|
247
|
+
_ as B,
|
|
248
|
+
m as b
|
|
249
|
+
};
|