template-replacement 3.0.8 → 3.1.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/core/base.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export interface Interface {
2
2
  await(): Promise<Interface>
3
- add_template(file: Uint8Array): Promise<number>
3
+ add_template(file: Uint8Array, is_decode: boolean): Promise<number>
4
4
  add_media(file: Uint8Array): Promise<string>
5
- extract_one_file_variable_names(data: Uint8Array): Promise<(string)[]>
6
- extract_variable_names(files: (Uint8Array)[]): Promise<(string)[]>
7
- extract_one_file_medias(data: Uint8Array): Promise<any>
8
- extract_medias(files: (Uint8Array)[]): Promise<any>
5
+ extract_one_file_variable_names(data: Uint8Array, is_decode: boolean): Promise<(string)[]>
6
+ extract_variable_names(files: (Uint8Array)[], is_decode: boolean): Promise<(string)[]>
7
+ extract_one_file_medias(data: Uint8Array, is_decode: boolean): Promise<any>
8
+ extract_medias(files: (Uint8Array)[], is_decode: boolean): Promise<any>
9
+ file_encrypt(file: Uint8Array): Promise<Uint8Array>
10
+ files_encrypt(files: (Uint8Array)[]): Promise<(Uint8Array)[]>
9
11
  }
10
12
 
11
13
  export default class implements Interface {
@@ -22,9 +24,9 @@ export default class implements Interface {
22
24
  return this
23
25
  }
24
26
 
25
- async add_template(file: Uint8Array): Promise<number> {
27
+ async add_template(file: Uint8Array, is_decode: boolean): Promise<number> {
26
28
  await this.awaitInit
27
- return this.module.add_template(file)
29
+ return this.module.add_template(file, is_decode)
28
30
  }
29
31
 
30
32
  async add_media(file: Uint8Array): Promise<string> {
@@ -32,23 +34,34 @@ export default class implements Interface {
32
34
  return this.module.add_media(file)
33
35
  }
34
36
 
35
- async extract_one_file_variable_names(data: Uint8Array): Promise<(string)[]> {
37
+ async extract_one_file_variable_names(data: Uint8Array, is_decode: boolean): Promise<(string)[]> {
36
38
  await this.awaitInit
37
- return this.module.extract_one_file_variable_names(data)
39
+ return this.module.extract_one_file_variable_names(data, is_decode)
38
40
  }
39
41
 
40
- async extract_variable_names(files: (Uint8Array)[]): Promise<(string)[]> {
42
+ async extract_variable_names(files: (Uint8Array)[], is_decode: boolean): Promise<(string)[]> {
41
43
  await this.awaitInit
42
- return this.module.extract_variable_names(files)
44
+ return this.module.extract_variable_names(files, is_decode)
43
45
  }
44
46
 
45
- async extract_one_file_medias(data: Uint8Array): Promise<any> {
47
+ async extract_one_file_medias(data: Uint8Array, is_decode: boolean): Promise<any> {
46
48
  await this.awaitInit
47
- return this.module.extract_one_file_medias(data)
49
+ return this.module.extract_one_file_medias(data, is_decode)
48
50
  }
49
51
 
50
- async extract_medias(files: (Uint8Array)[]): Promise<any> {
52
+ async extract_medias(files: (Uint8Array)[], is_decode: boolean): Promise<any> {
51
53
  await this.awaitInit
52
- return this.module.extract_medias(files)
54
+ return this.module.extract_medias(files, is_decode)
55
+ }
56
+
57
+ async file_encrypt(file: Uint8Array): Promise<Uint8Array> {
58
+ await this.awaitInit
59
+ return this.module.file_encrypt(file)
60
+ }
61
+
62
+ async files_encrypt(files: (Uint8Array)[]): Promise<(Uint8Array)[]> {
63
+ await this.awaitInit
64
+ const res = this.module.files_encrypt(files)
65
+ return res
53
66
  }
54
67
  }
package/core/general.ts CHANGED
@@ -8,6 +8,6 @@ export default () => {
8
8
  if (!awaitInit) {
9
9
  awaitInit = init()
10
10
  }
11
- return new base(awaitInit, core)
11
+ return new base(awaitInit as Promise<any>, core)
12
12
  }
13
13
 
package/core/sign.ts CHANGED
@@ -8,6 +8,6 @@ export default () => {
8
8
  if (!awaitInit) {
9
9
  awaitInit = init()
10
10
  }
11
- return new base(awaitInit, core)
11
+ return new base(awaitInit as Promise<any>, core)
12
12
  }
13
13
 
@@ -1,5 +1,6 @@
1
1
  import ReplaceInterface from '../replace/interface'
2
2
  import WorkerReplace from '../worker/main'
3
+ // import replace from '../worker/main/general'
3
4
  import replace from '../dist/main/general'
4
5
 
5
6
  export default (concurrency?: number): ReplaceInterface => {
@@ -1,5 +1,6 @@
1
1
  import ReplaceInterface from '../replace/interface'
2
2
  import WorkerReplace from '../worker/main'
3
+ // import replace from '../worker/main/sign'
3
4
  import replace from '../dist/main/sign'
4
5
 
5
6
  export default (concurrency?: number): ReplaceInterface => {
@@ -0,0 +1,214 @@
1
+ var m = (i) => {
2
+ throw TypeError(i);
3
+ };
4
+ var f = (i, e, t) => e.has(i) || m("Cannot " + t);
5
+ var c = (i, e, t) => (f(i, e, "read from private field"), t ? t.call(i) : e.get(i)), _ = (i, e, t) => e.has(i) ? m("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), y = (i, e, t, s) => (f(i, e, "write to private field"), s ? s.call(i, t) : e.set(i, t), t);
6
+ class p {
7
+ //表配置
8
+ // 构造函数
9
+ constructor() {
10
+ this._initFinishCallBackFuns = [], this._isInitFinish = !1, this._dbName = "template_replacement", this._dbversion = 1, this._cacheTableName = "templates", this._tableMap = {}, this.initDB();
11
+ }
12
+ initDB() {
13
+ return new Promise((e, t) => {
14
+ const s = indexedDB.open(this._dbName, this._dbversion);
15
+ s.onsuccess = (a) => {
16
+ if (this._db = s.result, this._isInitFinish = !0, this._initFinishCallBackFuns) {
17
+ try {
18
+ for (const n of this._initFinishCallBackFuns)
19
+ n();
20
+ } catch {
21
+ }
22
+ this._initFinishCallBackFuns = void 0;
23
+ }
24
+ e(a);
25
+ }, s.onerror = (a) => {
26
+ console.error(a), t(a);
27
+ }, s.onupgradeneeded = (a) => {
28
+ let n = s.result;
29
+ n.objectStoreNames.contains(this._cacheTableName) || n.createObjectStore(this._cacheTableName, {
30
+ keyPath: "url"
31
+ // 设置主键
32
+ }), e(a);
33
+ };
34
+ });
35
+ }
36
+ async awaitInit() {
37
+ this._isInitFinish || !this._initFinishCallBackFuns || await new Promise((e, t) => {
38
+ var s;
39
+ (s = this._initFinishCallBackFuns) == null || s.push(e);
40
+ });
41
+ }
42
+ closeDB() {
43
+ var e;
44
+ (e = this._db) == null || e.close();
45
+ }
46
+ async store(e) {
47
+ return await this.awaitInit(), this._db.transaction(this._cacheTableName, e).objectStore(this._cacheTableName);
48
+ }
49
+ /**
50
+ * @description : 更新数据
51
+ * @param {Object} params 添加到数据库中的数据 { url: 文件地址, data: 文件blob }
52
+ * @return {*}
53
+ */
54
+ putData(e) {
55
+ return new Promise(async (t, s) => {
56
+ const a = (await this.store("readwrite")).put(e);
57
+ a.onsuccess = (n) => {
58
+ t(n);
59
+ }, a.onerror = (n) => {
60
+ s(n);
61
+ };
62
+ });
63
+ }
64
+ // 通过主键读取数据
65
+ getDataByKey(e) {
66
+ return new Promise(async (t, s) => {
67
+ const a = (await this.store()).get(e);
68
+ a.onsuccess = () => {
69
+ t(a.result);
70
+ }, a.onerror = (n) => {
71
+ s(n);
72
+ };
73
+ });
74
+ }
75
+ // 清空数据库数据
76
+ clearDB() {
77
+ return new Promise(async (e, t) => {
78
+ const s = (await this.store("readwrite")).clear();
79
+ s.onsuccess = (a) => {
80
+ e(a);
81
+ }, s.onerror = (a) => {
82
+ t(a);
83
+ };
84
+ });
85
+ }
86
+ }
87
+ new p();
88
+ var w = /* @__PURE__ */ ((i) => (i.word = "word", i.excel = "excel", i.unknown = "unknown", i))(w || {}), h, u;
89
+ class x {
90
+ constructor(e) {
91
+ _(this, h, []);
92
+ _(this, u);
93
+ y(this, u, e);
94
+ }
95
+ addTempFile(e) {
96
+ c(this, h).push(e);
97
+ }
98
+ clear() {
99
+ c(this, h).length = 0;
100
+ }
101
+ async extractVariables(e) {
102
+ e || (e = c(this, h));
103
+ const t = {}, s = [];
104
+ for (const a of e)
105
+ s.push(new Promise(async (n, r) => {
106
+ const o = await a.getBuffer();
107
+ o && (a.isDecode || await a.type() !== w.unknown) && (t[a.name] = await c(this, u).extract_one_file_variable_names(o, a.isDecode)), n();
108
+ }));
109
+ return await Promise.all(s), t;
110
+ }
111
+ async extractMedias(e) {
112
+ e || (e = c(this, h));
113
+ const t = {}, s = [];
114
+ for (const a of e)
115
+ s.push(new Promise(async (n, r) => {
116
+ const o = await a.getBuffer();
117
+ if (o && (a.isDecode || await a.type() !== w.unknown)) {
118
+ let l = await c(this, u).extract_one_file_medias(o, a.isDecode);
119
+ t[a.name] = [], l && Array.isArray(l) && l.forEach((d) => {
120
+ d.id && d.data && t[a.name].push({
121
+ id: d.id,
122
+ data: new Uint8Array(d.data)
123
+ });
124
+ });
125
+ }
126
+ n();
127
+ }));
128
+ return await Promise.all(s), t;
129
+ }
130
+ async handle(e, t, s = !1) {
131
+ return [];
132
+ }
133
+ async sign(e) {
134
+ return "";
135
+ }
136
+ async execute(e, t) {
137
+ t || (t = c(this, h));
138
+ const s = [];
139
+ for (const r of t)
140
+ s.push(r.getBuffer());
141
+ await Promise.all(s);
142
+ const a = {
143
+ //需要解密的文件
144
+ decode: {
145
+ names: [],
146
+ uint8Arrays: []
147
+ },
148
+ //不需要解密的文件
149
+ noDecode: {
150
+ names: [],
151
+ uint8Arrays: []
152
+ }
153
+ };
154
+ for (const r of t)
155
+ r.uint8Array && (r.isDecode ? (a.decode.names.push(r.name), a.decode.uint8Arrays.push(r.uint8Array)) : (a.noDecode.names.push(r.name), a.noDecode.uint8Arrays.push(r.uint8Array)));
156
+ const n = await Promise.all([
157
+ this._execute(e, a.noDecode.names, a.noDecode.uint8Arrays, !1),
158
+ this._execute(e, a.decode.names, a.decode.uint8Arrays, !0)
159
+ ]);
160
+ return {
161
+ ...n[0],
162
+ ...n[1]
163
+ };
164
+ }
165
+ async _execute(e, t, s, a = !1) {
166
+ const n = {};
167
+ return s.length && (await this.handle(e, s, a)).forEach((o, l) => {
168
+ o.length && (n[t[l]] = o);
169
+ }), n;
170
+ }
171
+ async fileEncrypt(e) {
172
+ return await c(this, u).file_encrypt(e);
173
+ }
174
+ async filesEncrypt(e) {
175
+ return await c(this, u).files_encrypt(e);
176
+ }
177
+ }
178
+ h = new WeakMap(), u = new WeakMap();
179
+ class D {
180
+ constructor(e, t) {
181
+ this.awaitInit = e, this.module = t;
182
+ }
183
+ async await() {
184
+ return await this.awaitInit, this;
185
+ }
186
+ async add_template(e, t) {
187
+ return await this.awaitInit, this.module.add_template(e, t);
188
+ }
189
+ async add_media(e) {
190
+ return await this.awaitInit, this.module.add_media(e);
191
+ }
192
+ async extract_one_file_variable_names(e, t) {
193
+ return await this.awaitInit, this.module.extract_one_file_variable_names(e, t);
194
+ }
195
+ async extract_variable_names(e, t) {
196
+ return await this.awaitInit, this.module.extract_variable_names(e, t);
197
+ }
198
+ async extract_one_file_medias(e, t) {
199
+ return await this.awaitInit, this.module.extract_one_file_medias(e, t);
200
+ }
201
+ async extract_medias(e, t) {
202
+ return await this.awaitInit, this.module.extract_medias(e, t);
203
+ }
204
+ async file_encrypt(e) {
205
+ return await this.awaitInit, this.module.file_encrypt(e);
206
+ }
207
+ async files_encrypt(e) {
208
+ return await this.awaitInit, this.module.files_encrypt(e);
209
+ }
210
+ }
211
+ export {
212
+ x as B,
213
+ D as b
214
+ };