module-develop-kit 1.1.0 → 1.2.1

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.
Files changed (45) hide show
  1. package/dist/commonjs-virtual-dir/browser.js +5 -2
  2. package/dist/commonjs-virtual-dir/browser2.js +4 -0
  3. package/dist/commonjs-virtual-dir/index2.js +5 -3
  4. package/dist/commonjs-virtual-dir/index3.js +3 -5
  5. package/dist/commonjs-virtual-dir/index4.js +2 -4
  6. package/dist/commonjs-virtual-dir/index5.js +2 -2
  7. package/dist/commonjs-virtual-dir/index6.js +2 -2
  8. package/dist/commonjs-virtual-dir/index7.js +4 -0
  9. package/dist/commonjs-virtual-dir/index8.js +4 -0
  10. package/dist/main.d.ts +140 -29
  11. package/dist/main.js +34 -22
  12. package/dist/src/outside-call/utils.js +1 -1
  13. package/dist/src/shield/crypto/sm4.js +1 -1
  14. package/dist/src/shield/file-detection.js +143 -0
  15. package/dist/vendor/@borewit/text-codec/lib/index.js +181 -0
  16. package/dist/vendor/@tokenizer/inflate/lib/GzipHandler.js +21 -0
  17. package/dist/vendor/@tokenizer/inflate/lib/ZipHandler.js +156 -0
  18. package/dist/vendor/@tokenizer/inflate/lib/ZipToken.js +71 -0
  19. package/dist/vendor/base64-js/index.js +1 -1
  20. package/dist/vendor/debug/src/browser.js +1 -1
  21. package/dist/vendor/file-type/source/detectors/asf.js +74 -0
  22. package/dist/vendor/file-type/source/detectors/ebml.js +61 -0
  23. package/dist/vendor/file-type/source/detectors/png.js +64 -0
  24. package/dist/vendor/file-type/source/detectors/zip.js +344 -0
  25. package/dist/vendor/file-type/source/index.js +1135 -0
  26. package/dist/vendor/file-type/source/parser.js +49 -0
  27. package/dist/vendor/file-type/source/supported.js +372 -0
  28. package/dist/vendor/file-type/source/tokens.js +40 -0
  29. package/dist/vendor/ieee754/index.js +30 -0
  30. package/dist/vendor/jsbn/index.js +1 -1
  31. package/dist/vendor/sdp-transform/lib/index.js +1 -1
  32. package/dist/vendor/strtok3/lib/AbstractTokenizer.js +92 -0
  33. package/dist/vendor/strtok3/lib/BlobTokenizer.js +48 -0
  34. package/dist/vendor/strtok3/lib/BufferTokenizer.js +47 -0
  35. package/dist/vendor/strtok3/lib/ReadStreamTokenizer.js +91 -0
  36. package/dist/vendor/strtok3/lib/core.js +22 -0
  37. package/dist/vendor/strtok3/lib/stream/AbstractStreamReader.js +51 -0
  38. package/dist/vendor/strtok3/lib/stream/Errors.js +16 -0
  39. package/dist/vendor/strtok3/lib/stream/WebStreamByobReader.js +18 -0
  40. package/dist/vendor/strtok3/lib/stream/WebStreamDefaultReader.js +45 -0
  41. package/dist/vendor/strtok3/lib/stream/WebStreamReader.js +15 -0
  42. package/dist/vendor/strtok3/lib/stream/WebStreamReaderFactory.js +15 -0
  43. package/dist/vendor/token-types/lib/index.js +81 -0
  44. package/dist/vendor/uint8array-extras/index.js +45 -0
  45. package/package.json +2 -1
@@ -0,0 +1,344 @@
1
+ import { UINT32_LE as h } from "../../../token-types/lib/index.js";
2
+ import { EndOfStreamError as T } from "../../../strtok3/lib/stream/Errors.js";
3
+ import { ZipHandler as y } from "../../../@tokenizer/inflate/lib/ZipHandler.js";
4
+ import { hasUnknownFileSize as f, ParserHardLimitError as x, hasExceededUnknownSizeScanBudget as w, maximumUntrustedSkipSizeInBytes as u, safeIgnore as C } from "../parser.js";
5
+ const d = 1024 * 1024, E = 1024, F = 2 ** 31 - 1, D = d, P = /* @__PURE__ */ new Set([
6
+ "Unexpected signature",
7
+ "Encrypted ZIP",
8
+ "Expected Central-File-Header signature"
9
+ ]), M = [
10
+ "ZIP entry count exceeds ",
11
+ "Unsupported ZIP compression method:",
12
+ "ZIP entry compressed data exceeds ",
13
+ "ZIP entry decompressed data exceeds ",
14
+ "Expected data-descriptor-signature at position "
15
+ ], B = /* @__PURE__ */ new Set([
16
+ "Z_BUF_ERROR",
17
+ "Z_DATA_ERROR",
18
+ "ERR_INVALID_STATE"
19
+ ]);
20
+ async function z(e, { maximumLength: t = d } = {}) {
21
+ const i = new ReadableStream({
22
+ start(c) {
23
+ c.enqueue(e), c.close();
24
+ }
25
+ }).pipeThrough(new DecompressionStream("deflate-raw")).getReader(), s = [];
26
+ let o = 0;
27
+ try {
28
+ for (; ; ) {
29
+ const { done: c, value: m } = await i.read();
30
+ if (c)
31
+ break;
32
+ if (o += m.length, o > t)
33
+ throw await i.cancel(), new Error(`ZIP entry decompressed data exceeds ${t} bytes`);
34
+ s.push(m);
35
+ }
36
+ } finally {
37
+ i.releaseLock();
38
+ }
39
+ const a = new Uint8Array(o);
40
+ let p = 0;
41
+ for (const c of s)
42
+ a.set(c, p), p += c.length;
43
+ return a;
44
+ }
45
+ function L(e, t) {
46
+ const r = new Uint8Array(t);
47
+ let n = 0;
48
+ for (const i of e)
49
+ r.set(i, n), n += i.length;
50
+ return r;
51
+ }
52
+ function R(e) {
53
+ const t = e.fileInfo.size, r = Number.isFinite(t) ? Math.max(0, t - e.position) : Number.MAX_SAFE_INTEGER;
54
+ return Math.min(r, F);
55
+ }
56
+ function U(e) {
57
+ if (e instanceof T || e instanceof x)
58
+ return !0;
59
+ if (!(e instanceof Error))
60
+ return !1;
61
+ if (P.has(e.message) || B.has(e.code))
62
+ return !0;
63
+ for (const t of M)
64
+ if (e.message.startsWith(t))
65
+ return !0;
66
+ return !1;
67
+ }
68
+ function v(e, t = d) {
69
+ const r = [e.compressedSize, e.uncompressedSize];
70
+ for (const n of r)
71
+ if (!Number.isFinite(n) || n < 0 || n > t)
72
+ return !1;
73
+ return !0;
74
+ }
75
+ function O() {
76
+ return {
77
+ hasDocumentEntry: !1,
78
+ hasMasterSlideEntry: !1,
79
+ hasTablesEntry: !1,
80
+ hasCalculationEngineEntry: !1
81
+ };
82
+ }
83
+ function A(e, t) {
84
+ t === "Index/Document.iwa" && (e.hasDocumentEntry = !0), t.startsWith("Index/MasterSlide") && (e.hasMasterSlideEntry = !0), t.startsWith("Index/Tables/") && (e.hasTablesEntry = !0), t === "Index/CalculationEngine.iwa" && (e.hasCalculationEngineEntry = !0);
85
+ }
86
+ function b(e) {
87
+ if (e.hasDocumentEntry)
88
+ return e.hasMasterSlideEntry ? { ext: "key", mime: "application/vnd.apple.keynote" } : e.hasTablesEntry ? { ext: "numbers", mime: "application/vnd.apple.numbers" } : { ext: "pages", mime: "application/vnd.apple.pages" };
89
+ }
90
+ function k(e) {
91
+ switch (e = e.toLowerCase(), e) {
92
+ case "application/epub+zip":
93
+ return { ext: "epub", mime: e };
94
+ case "application/vnd.oasis.opendocument.text":
95
+ return { ext: "odt", mime: e };
96
+ case "application/vnd.oasis.opendocument.text-template":
97
+ return { ext: "ott", mime: e };
98
+ case "application/vnd.oasis.opendocument.spreadsheet":
99
+ return { ext: "ods", mime: e };
100
+ case "application/vnd.oasis.opendocument.spreadsheet-template":
101
+ return { ext: "ots", mime: e };
102
+ case "application/vnd.oasis.opendocument.presentation":
103
+ return { ext: "odp", mime: e };
104
+ case "application/vnd.oasis.opendocument.presentation-template":
105
+ return { ext: "otp", mime: e };
106
+ case "application/vnd.oasis.opendocument.graphics":
107
+ return { ext: "odg", mime: e };
108
+ case "application/vnd.oasis.opendocument.graphics-template":
109
+ return { ext: "otg", mime: e };
110
+ case "application/vnd.openxmlformats-officedocument.presentationml.slideshow":
111
+ return { ext: "ppsx", mime: e };
112
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
113
+ return { ext: "xlsx", mime: e };
114
+ case "application/vnd.ms-excel.sheet.macroenabled":
115
+ return { ext: "xlsm", mime: "application/vnd.ms-excel.sheet.macroenabled.12" };
116
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.template":
117
+ return { ext: "xltx", mime: e };
118
+ case "application/vnd.ms-excel.template.macroenabled":
119
+ return { ext: "xltm", mime: "application/vnd.ms-excel.template.macroenabled.12" };
120
+ case "application/vnd.ms-powerpoint.slideshow.macroenabled":
121
+ return { ext: "ppsm", mime: "application/vnd.ms-powerpoint.slideshow.macroenabled.12" };
122
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
123
+ return { ext: "docx", mime: e };
124
+ case "application/vnd.ms-word.document.macroenabled":
125
+ return { ext: "docm", mime: "application/vnd.ms-word.document.macroenabled.12" };
126
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.template":
127
+ return { ext: "dotx", mime: e };
128
+ case "application/vnd.ms-word.template.macroenabledtemplate":
129
+ return { ext: "dotm", mime: "application/vnd.ms-word.template.macroenabled.12" };
130
+ case "application/vnd.openxmlformats-officedocument.presentationml.template":
131
+ return { ext: "potx", mime: e };
132
+ case "application/vnd.ms-powerpoint.template.macroenabled":
133
+ return { ext: "potm", mime: "application/vnd.ms-powerpoint.template.macroenabled.12" };
134
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
135
+ return { ext: "pptx", mime: e };
136
+ case "application/vnd.ms-powerpoint.presentation.macroenabled":
137
+ return { ext: "pptm", mime: "application/vnd.ms-powerpoint.presentation.macroenabled.12" };
138
+ case "application/vnd.ms-visio.drawing":
139
+ return { ext: "vsdx", mime: "application/vnd.visio" };
140
+ case "application/vnd.ms-package.3dmanufacturing-3dmodel+xml":
141
+ return { ext: "3mf", mime: "model/3mf" };
142
+ }
143
+ }
144
+ function _() {
145
+ return {
146
+ hasContentTypesEntry: !1,
147
+ hasParsedContentTypesEntry: !1,
148
+ isParsingContentTypes: !1,
149
+ hasUnparseableContentTypes: !1,
150
+ hasWordDirectory: !1,
151
+ hasPresentationDirectory: !1,
152
+ hasSpreadsheetDirectory: !1,
153
+ hasThreeDimensionalModelEntry: !1
154
+ };
155
+ }
156
+ function W(e, t) {
157
+ t.startsWith("word/") && (e.hasWordDirectory = !0), t.startsWith("ppt/") && (e.hasPresentationDirectory = !0), t.startsWith("xl/") && (e.hasSpreadsheetDirectory = !0), t.startsWith("3D/") && t.endsWith(".model") && (e.hasThreeDimensionalModelEntry = !0);
158
+ }
159
+ function Z(e) {
160
+ if (e.hasWordDirectory)
161
+ return {
162
+ ext: "docx",
163
+ mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
164
+ };
165
+ if (e.hasPresentationDirectory)
166
+ return {
167
+ ext: "pptx",
168
+ mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
169
+ };
170
+ if (e.hasSpreadsheetDirectory)
171
+ return {
172
+ ext: "xlsx",
173
+ mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
174
+ };
175
+ if (e.hasThreeDimensionalModelEntry)
176
+ return {
177
+ ext: "3mf",
178
+ mime: "model/3mf"
179
+ };
180
+ }
181
+ function I(e) {
182
+ if (!(!e.hasContentTypesEntry || e.hasUnparseableContentTypes || e.isParsingContentTypes || e.hasParsedContentTypesEntry))
183
+ return Z(e);
184
+ }
185
+ function N(e) {
186
+ const t = e.indexOf('.main+xml"');
187
+ if (t === -1) {
188
+ const i = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml";
189
+ return e.includes(`ContentType="${i}"`) ? i : void 0;
190
+ }
191
+ const r = e.slice(0, t), n = r.lastIndexOf('"');
192
+ return r.slice(n + 1);
193
+ }
194
+ const S = 134695760, l = 16, $ = l - 1;
195
+ function j(e, t) {
196
+ if (e.length < l)
197
+ return -1;
198
+ const r = e.length - l;
199
+ for (let n = 0; n <= r; n++)
200
+ if (h.get(e, n) === S && h.get(e, n + 8) === t + n)
201
+ return n;
202
+ return -1;
203
+ }
204
+ async function q(e, { shouldBuffer: t, maximumLength: r = d } = {}) {
205
+ const { syncBuffer: n } = e, { length: i } = n, s = [];
206
+ let o = 0;
207
+ for (; ; ) {
208
+ const a = await e.tokenizer.peekBuffer(n, { mayBeLess: !0 }), p = j(n.subarray(0, a), o), c = p >= 0 ? 0 : a === i ? Math.min($, a - 1) : 0, m = p >= 0 ? p : a - c;
209
+ if (m === 0)
210
+ break;
211
+ if (o += m, o > r)
212
+ throw new Error(`ZIP entry compressed data exceeds ${r} bytes`);
213
+ if (t) {
214
+ const g = new Uint8Array(m);
215
+ await e.tokenizer.readBuffer(g), s.push(g);
216
+ } else
217
+ await e.tokenizer.ignore(m);
218
+ if (p >= 0)
219
+ break;
220
+ }
221
+ if (f(e.tokenizer) || (e.knownSizeDescriptorScannedBytes += o), !!t)
222
+ return L(s, o);
223
+ }
224
+ function G(e, t) {
225
+ return f(e.tokenizer) ? Math.max(0, u - (e.tokenizer.position - t)) : Math.max(0, d - e.knownSizeDescriptorScannedBytes);
226
+ }
227
+ async function Q(e, t, { shouldBuffer: r, maximumDescriptorLength: n = d } = {}) {
228
+ if (t.dataDescriptor && t.compressedSize === 0)
229
+ return q(e, {
230
+ shouldBuffer: r,
231
+ maximumLength: n
232
+ });
233
+ if (!r) {
234
+ await C(e.tokenizer, t.compressedSize, {
235
+ maximumLength: f(e.tokenizer) ? d : e.tokenizer.fileInfo.size,
236
+ reason: "ZIP entry compressed data"
237
+ });
238
+ return;
239
+ }
240
+ const i = R(e.tokenizer);
241
+ if (!Number.isFinite(t.compressedSize) || t.compressedSize < 0 || t.compressedSize > i)
242
+ throw new Error(`ZIP entry compressed data exceeds ${i} bytes`);
243
+ const s = new Uint8Array(t.compressedSize);
244
+ return await e.tokenizer.readBuffer(s), s;
245
+ }
246
+ y.prototype.inflate = async function(e, t, r) {
247
+ if (e.compressedMethod === 0)
248
+ return r(t);
249
+ if (e.compressedMethod !== 8)
250
+ throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);
251
+ const n = await z(t, { maximumLength: d });
252
+ return r(n);
253
+ };
254
+ y.prototype.unzip = async function(e) {
255
+ let t = !1, r = 0;
256
+ const n = this.tokenizer.position;
257
+ this.knownSizeDescriptorScannedBytes = 0;
258
+ do {
259
+ if (w(this.tokenizer, n, u))
260
+ throw new x(`ZIP stream probing exceeds ${u} bytes`);
261
+ const i = await this.readLocalFileHeader();
262
+ if (!i)
263
+ break;
264
+ if (r++, r > E)
265
+ throw new Error(`ZIP entry count exceeds ${E}`);
266
+ const s = e(i);
267
+ t = !!s.stop, await this.tokenizer.ignore(i.extraFieldLength);
268
+ const o = await Q(this, i, {
269
+ shouldBuffer: !!s.handler,
270
+ maximumDescriptorLength: Math.min(d, G(this, n))
271
+ });
272
+ if (s.handler && await this.inflate(i, o, s.handler), i.dataDescriptor) {
273
+ const a = new Uint8Array(l);
274
+ if (await this.tokenizer.readBuffer(a), h.get(a, 0) !== S)
275
+ throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position - a.length}`);
276
+ }
277
+ if (w(this.tokenizer, n, u))
278
+ throw new x(`ZIP stream probing exceeds ${u} bytes`);
279
+ } while (!t);
280
+ };
281
+ async function Y(e) {
282
+ let t;
283
+ const r = _(), n = O();
284
+ try {
285
+ await new y(e).unzip((s) => {
286
+ if (W(r, s.filename), A(n, s.filename), n.hasDocumentEntry && (n.hasMasterSlideEntry || n.hasTablesEntry))
287
+ return t = b(n), { stop: !0 };
288
+ const o = s.filename === "[Content_Types].xml", a = I(r);
289
+ if (!o && a)
290
+ return t = a, {
291
+ stop: !0
292
+ };
293
+ switch (s.filename) {
294
+ case "META-INF/mozilla.rsa":
295
+ return t = {
296
+ ext: "xpi",
297
+ mime: "application/x-xpinstall"
298
+ }, {
299
+ stop: !0
300
+ };
301
+ case "META-INF/MANIFEST.MF":
302
+ return t = {
303
+ ext: "jar",
304
+ mime: "application/java-archive"
305
+ }, {
306
+ stop: !0
307
+ };
308
+ case "mimetype":
309
+ return v(s, D) ? {
310
+ async handler(p) {
311
+ const c = new TextDecoder("utf-8").decode(p).trim();
312
+ t = k(c);
313
+ },
314
+ stop: !0
315
+ } : {};
316
+ case "[Content_Types].xml":
317
+ return r.hasContentTypesEntry = !0, v(s, D) ? (r.isParsingContentTypes = !0, {
318
+ async handler(p) {
319
+ const c = new TextDecoder("utf-8").decode(p), m = N(c);
320
+ m && (t = k(m)), r.hasParsedContentTypesEntry = !0, r.isParsingContentTypes = !1;
321
+ },
322
+ stop: !0
323
+ }) : (r.hasUnparseableContentTypes = !0, {});
324
+ default:
325
+ return new RegExp("classes\\d*\\.dex", "v").test(s.filename) ? (t = {
326
+ ext: "apk",
327
+ mime: "application/vnd.android.package-archive"
328
+ }, { stop: !0 }) : {};
329
+ }
330
+ });
331
+ } catch (s) {
332
+ if (!U(s))
333
+ throw s;
334
+ r.isParsingContentTypes && (r.isParsingContentTypes = !1, r.hasUnparseableContentTypes = !0), !t && s instanceof T && !r.hasContentTypesEntry && (t = Z(r));
335
+ }
336
+ const i = f(e) && n.hasDocumentEntry && !n.hasMasterSlideEntry && !n.hasTablesEntry && !n.hasCalculationEngineEntry ? void 0 : b(n);
337
+ return t ?? I(r) ?? i ?? {
338
+ ext: "zip",
339
+ mime: "application/zip"
340
+ };
341
+ }
342
+ export {
343
+ Y as detectZip
344
+ };