template-replacement 3.3.2 → 3.3.3

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