template-replacement 3.3.3 → 3.5.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 +1911 -2031
- package/dist/main/sign.js +2141 -2252
- package/dist/replace/general.js +287 -390
- package/dist/replace/sign.js +307 -401
- 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 +100 -92
- package/replace/interface.ts +29 -24
- package/replace/paramsData.ts +107 -95
- package/replace/sign.ts +72 -54
- 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 +192 -67
- 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/dist/base-CJv023nf.js
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
class f {
|
|
2
|
-
// 构造函数
|
|
3
|
-
constructor() {
|
|
4
|
-
this._initFinishCallBackFuns = [], this._isInitFinish = !1, this._dbName = "template_replacement_db", this._dbversion = 1, this._cacheTableName = "template_files", this._tableMap = {}, this.initDB();
|
|
5
|
-
}
|
|
6
|
-
initDB() {
|
|
7
|
-
return this._init ? this._init : (this._init = new Promise((e, a) => {
|
|
8
|
-
const i = indexedDB.open(this._dbName, this._dbversion);
|
|
9
|
-
i.onsuccess = (t) => {
|
|
10
|
-
if (this._db = i.result, this._isInitFinish = !0, this._initFinishCallBackFuns) {
|
|
11
|
-
try {
|
|
12
|
-
for (const s of this._initFinishCallBackFuns)
|
|
13
|
-
s();
|
|
14
|
-
} catch {
|
|
15
|
-
}
|
|
16
|
-
this._initFinishCallBackFuns = void 0;
|
|
17
|
-
}
|
|
18
|
-
e(t);
|
|
19
|
-
}, i.onerror = (t) => {
|
|
20
|
-
console.error(t), a(t);
|
|
21
|
-
}, i.onupgradeneeded = (t) => {
|
|
22
|
-
let s = i.result;
|
|
23
|
-
s.objectStoreNames.contains(this._cacheTableName) || s.createObjectStore(this._cacheTableName, {
|
|
24
|
-
keyPath: "key"
|
|
25
|
-
// 设置主键
|
|
26
|
-
}), e(t);
|
|
27
|
-
};
|
|
28
|
-
}), this._init);
|
|
29
|
-
}
|
|
30
|
-
async awaitInit() {
|
|
31
|
-
this._isInitFinish || !this._initFinishCallBackFuns || await new Promise((e, a) => {
|
|
32
|
-
this._initFinishCallBackFuns?.push(e);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
closeDB() {
|
|
36
|
-
this._db?.close();
|
|
37
|
-
}
|
|
38
|
-
async store(e) {
|
|
39
|
-
return await this.awaitInit(), this._db.transaction(this._cacheTableName, e).objectStore(this._cacheTableName);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @description : 更新数据
|
|
43
|
-
* @param {templateData} params 添加到数据库中的数据 { key: 文件key, data: 文件blob }
|
|
44
|
-
* @return {*}
|
|
45
|
-
*/
|
|
46
|
-
putData(e) {
|
|
47
|
-
return new Promise((a, i) => {
|
|
48
|
-
this.store("readwrite").then((t) => {
|
|
49
|
-
const s = t.put(e);
|
|
50
|
-
s.onsuccess = (n) => {
|
|
51
|
-
a(n);
|
|
52
|
-
}, s.onerror = (n) => {
|
|
53
|
-
i(n);
|
|
54
|
-
};
|
|
55
|
-
}).catch(i);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
// 通过主键读取数据
|
|
59
|
-
getDataByKey(e) {
|
|
60
|
-
return new Promise((a, i) => {
|
|
61
|
-
this.store().then((t) => {
|
|
62
|
-
const s = t.get(e);
|
|
63
|
-
s.onsuccess = () => {
|
|
64
|
-
a(s.result);
|
|
65
|
-
}, s.onerror = (n) => {
|
|
66
|
-
i(n);
|
|
67
|
-
};
|
|
68
|
-
}).catch(i);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
// 通过主键移除数据
|
|
72
|
-
deleteDataByKey(e) {
|
|
73
|
-
return new Promise((a, i) => {
|
|
74
|
-
this.store().then((t) => {
|
|
75
|
-
const s = t.delete(e);
|
|
76
|
-
s.onsuccess = () => {
|
|
77
|
-
a(s.result);
|
|
78
|
-
}, s.onerror = (n) => {
|
|
79
|
-
i(n);
|
|
80
|
-
};
|
|
81
|
-
}).catch(i);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
// 清空数据库数据
|
|
85
|
-
clearDB() {
|
|
86
|
-
return new Promise((e, a) => {
|
|
87
|
-
this.store("readwrite").then((i) => {
|
|
88
|
-
const t = i.clear();
|
|
89
|
-
t.onsuccess = (s) => {
|
|
90
|
-
e(s);
|
|
91
|
-
}, t.onerror = (s) => {
|
|
92
|
-
a(s);
|
|
93
|
-
};
|
|
94
|
-
}).catch(a);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
new f();
|
|
99
|
-
var l = /* @__PURE__ */ ((c) => (c.word = "word", c.excel = "excel", c.unknown = "unknown", c))(l || {});
|
|
100
|
-
class m {
|
|
101
|
-
#e = [];
|
|
102
|
-
#t;
|
|
103
|
-
constructor(e) {
|
|
104
|
-
this.#t = e;
|
|
105
|
-
}
|
|
106
|
-
addTempFile(e) {
|
|
107
|
-
this.#e.push(e);
|
|
108
|
-
}
|
|
109
|
-
clear() {
|
|
110
|
-
this.#e.length = 0;
|
|
111
|
-
}
|
|
112
|
-
async extractVariables(e) {
|
|
113
|
-
e || (e = this.#e);
|
|
114
|
-
const a = {}, i = [];
|
|
115
|
-
for (const t of e)
|
|
116
|
-
i.push(new Promise(async (s) => {
|
|
117
|
-
try {
|
|
118
|
-
const n = await t.getBuffer();
|
|
119
|
-
n && (t.isDecode || await t.type() !== l.unknown) && (a[t.name] = await this.#t.extract_one_file_variable_names(n, t.isDecode)), s();
|
|
120
|
-
} catch (n) {
|
|
121
|
-
console.error(n);
|
|
122
|
-
}
|
|
123
|
-
}));
|
|
124
|
-
return await Promise.all(i), a;
|
|
125
|
-
}
|
|
126
|
-
async extractMedias(e) {
|
|
127
|
-
e || (e = this.#e);
|
|
128
|
-
const a = {}, i = [];
|
|
129
|
-
for (const t of e)
|
|
130
|
-
i.push(new Promise(async (s) => {
|
|
131
|
-
try {
|
|
132
|
-
const n = await t.getBuffer();
|
|
133
|
-
if (n && (t.isDecode || await t.type() !== l.unknown)) {
|
|
134
|
-
let r = await this.#t.extract_one_file_medias(n, t.isDecode);
|
|
135
|
-
if (a[t.name] = [], r && Array.isArray(r))
|
|
136
|
-
for (const o of r)
|
|
137
|
-
o.id && o.data && a[t.name].push({
|
|
138
|
-
id: o.id,
|
|
139
|
-
data: new Uint8Array(o.data)
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
s();
|
|
143
|
-
} catch (n) {
|
|
144
|
-
console.error(n);
|
|
145
|
-
}
|
|
146
|
-
}));
|
|
147
|
-
return await Promise.all(i), a;
|
|
148
|
-
}
|
|
149
|
-
async handle(e, a, i = !1) {
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
async handleMultipleParams(e, a, i = !1) {
|
|
153
|
-
return [];
|
|
154
|
-
}
|
|
155
|
-
async sign(e) {
|
|
156
|
-
return "";
|
|
157
|
-
}
|
|
158
|
-
async execute(e, a) {
|
|
159
|
-
a || (a = this.#e);
|
|
160
|
-
const i = [];
|
|
161
|
-
for (const n of a)
|
|
162
|
-
i.push(n.getBuffer());
|
|
163
|
-
await Promise.all(i);
|
|
164
|
-
const t = {
|
|
165
|
-
//需要解密的文件
|
|
166
|
-
decode: {
|
|
167
|
-
names: [],
|
|
168
|
-
uint8Arrays: []
|
|
169
|
-
},
|
|
170
|
-
//不需要解密的文件
|
|
171
|
-
noDecode: {
|
|
172
|
-
names: [],
|
|
173
|
-
uint8Arrays: []
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
for (const n of a)
|
|
177
|
-
n.uint8Array && (n.isDecode ? (t.decode.names.push(n.name), t.decode.uint8Arrays.push(n.uint8Array)) : (t.noDecode.names.push(n.name), t.noDecode.uint8Arrays.push(n.uint8Array)));
|
|
178
|
-
const s = await Promise.all([
|
|
179
|
-
this._execute(e, t.noDecode.names, t.noDecode.uint8Arrays, !1),
|
|
180
|
-
this._execute(e, t.decode.names, t.decode.uint8Arrays, !0)
|
|
181
|
-
]);
|
|
182
|
-
return {
|
|
183
|
-
...s[0],
|
|
184
|
-
...s[1]
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
async _execute(e, a, i, t = !1) {
|
|
188
|
-
const s = {};
|
|
189
|
-
if (!i.length)
|
|
190
|
-
return s;
|
|
191
|
-
const n = await this.handle(e, i, t);
|
|
192
|
-
for (let r = 0; r < n.length; r++) {
|
|
193
|
-
const o = n[r];
|
|
194
|
-
o.length && (s[a[r]] = o);
|
|
195
|
-
}
|
|
196
|
-
return s;
|
|
197
|
-
}
|
|
198
|
-
async executeMultipleParams(e, a) {
|
|
199
|
-
a || (a = this.#e);
|
|
200
|
-
const i = [];
|
|
201
|
-
for (const r of a)
|
|
202
|
-
i.push(r.getBuffer());
|
|
203
|
-
await Promise.all(i);
|
|
204
|
-
const t = {
|
|
205
|
-
//需要解密的文件
|
|
206
|
-
decode: {
|
|
207
|
-
names: [],
|
|
208
|
-
uint8Arrays: []
|
|
209
|
-
},
|
|
210
|
-
//不需要解密的文件
|
|
211
|
-
noDecode: {
|
|
212
|
-
names: [],
|
|
213
|
-
uint8Arrays: []
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
for (const r of a)
|
|
217
|
-
r.uint8Array && (r.isDecode ? (t.decode.names.push(r.name), t.decode.uint8Arrays.push(r.uint8Array)) : (t.noDecode.names.push(r.name), t.noDecode.uint8Arrays.push(r.uint8Array)));
|
|
218
|
-
const s = await Promise.all([
|
|
219
|
-
this._executeMultipleParams(e, t.noDecode.names, t.noDecode.uint8Arrays, !1),
|
|
220
|
-
this._executeMultipleParams(e, t.decode.names, t.decode.uint8Arrays, !0)
|
|
221
|
-
]), n = [];
|
|
222
|
-
for (let r = 0; r < s[0].length; r++)
|
|
223
|
-
n.push({ ...s[0][r], ...s[1][r] });
|
|
224
|
-
return n;
|
|
225
|
-
}
|
|
226
|
-
async _executeMultipleParams(e, a, i, t = !1) {
|
|
227
|
-
const s = Array(e.length);
|
|
228
|
-
if (!i.length)
|
|
229
|
-
return s;
|
|
230
|
-
const n = await this.handleMultipleParams(e, i, t);
|
|
231
|
-
let r = 0;
|
|
232
|
-
for (let o = 0; o < e.length; o++) {
|
|
233
|
-
const u = {};
|
|
234
|
-
for (const d of a) {
|
|
235
|
-
const h = n[r++];
|
|
236
|
-
h.length && (u[d] = h);
|
|
237
|
-
}
|
|
238
|
-
s[o] = u;
|
|
239
|
-
}
|
|
240
|
-
return s;
|
|
241
|
-
}
|
|
242
|
-
fileEncrypt(e) {
|
|
243
|
-
return this.#t.file_encrypt(e);
|
|
244
|
-
}
|
|
245
|
-
filesEncrypt(e) {
|
|
246
|
-
return this.#t.files_encrypt(e);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
class _ {
|
|
250
|
-
constructor(e, a) {
|
|
251
|
-
this.awaitInit = e, this.module = a;
|
|
252
|
-
}
|
|
253
|
-
async await() {
|
|
254
|
-
return await this.awaitInit, this;
|
|
255
|
-
}
|
|
256
|
-
async add_template(e, a) {
|
|
257
|
-
return await this.awaitInit, this.module.add_template(e, a);
|
|
258
|
-
}
|
|
259
|
-
async add_media(e) {
|
|
260
|
-
return await this.awaitInit, this.module.add_media(e);
|
|
261
|
-
}
|
|
262
|
-
async extract_one_file_variable_names(e, a) {
|
|
263
|
-
return await this.awaitInit, this.module.extract_one_file_variable_names(e, a);
|
|
264
|
-
}
|
|
265
|
-
async extract_variable_names(e, a) {
|
|
266
|
-
return await this.awaitInit, this.module.extract_variable_names(e, a);
|
|
267
|
-
}
|
|
268
|
-
async extract_one_file_medias(e, a) {
|
|
269
|
-
return await this.awaitInit, this.module.extract_one_file_medias(e, a);
|
|
270
|
-
}
|
|
271
|
-
async extract_medias(e, a) {
|
|
272
|
-
return await this.awaitInit, this.module.extract_medias(e, a);
|
|
273
|
-
}
|
|
274
|
-
async file_encrypt(e) {
|
|
275
|
-
return await this.awaitInit, this.module.file_encrypt(e);
|
|
276
|
-
}
|
|
277
|
-
async files_encrypt(e) {
|
|
278
|
-
return await this.awaitInit, this.module.files_encrypt(e);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
export {
|
|
282
|
-
m as B,
|
|
283
|
-
_ as b
|
|
284
|
-
};
|
package/dist/general.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
package/dist/index-tFDVIkZX.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
class h {
|
|
2
|
-
#s;
|
|
3
|
-
#r = 0;
|
|
4
|
-
#e = [];
|
|
5
|
-
#t = [];
|
|
6
|
-
constructor(t, s) {
|
|
7
|
-
if (this.#s = Number(s), !this.#s || this.#s < 1)
|
|
8
|
-
try {
|
|
9
|
-
this.#s = navigator.hardwareConcurrency < 8 ? navigator.hardwareConcurrency : 8;
|
|
10
|
-
} catch {
|
|
11
|
-
}
|
|
12
|
-
(!this.#s || this.#s < 1) && (this.#s = 1);
|
|
13
|
-
for (let r = 0; r < this.#s; r++)
|
|
14
|
-
this.#i(t);
|
|
15
|
-
}
|
|
16
|
-
#i(t) {
|
|
17
|
-
const s = new t();
|
|
18
|
-
s.onmessage = async (r) => {
|
|
19
|
-
const i = [];
|
|
20
|
-
for (const e of this.#t)
|
|
21
|
-
i.push(e(r));
|
|
22
|
-
const o = await Promise.all(i);
|
|
23
|
-
for (const e of o)
|
|
24
|
-
e && s.postMessage(e);
|
|
25
|
-
}, this.#e.push(s);
|
|
26
|
-
}
|
|
27
|
-
concurrency() {
|
|
28
|
-
return this.#s;
|
|
29
|
-
}
|
|
30
|
-
postMessage(t, s) {
|
|
31
|
-
this.#e[++this.#r] || (this.#r = 0), this.#e[this.#r].postMessage(t, s);
|
|
32
|
-
}
|
|
33
|
-
addListener(t) {
|
|
34
|
-
this.#t.push(t);
|
|
35
|
-
}
|
|
36
|
-
removeListener(t) {
|
|
37
|
-
for (const s in this.#t)
|
|
38
|
-
if (this.#t[s] == t) {
|
|
39
|
-
this.#t.splice(s, 1);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
h as w
|
|
46
|
-
};
|
package/dist/sign.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|