@zag-js/file-utils 1.46.0 → 1.48.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/dist/data-transfer.d.mts +1 -3
- package/dist/data-transfer.d.ts +1 -3
- package/dist/data-transfer.js +47 -80
- package/dist/data-transfer.mjs +43 -55
- package/dist/data-url-to-blob.d.mts +1 -3
- package/dist/data-url-to-blob.d.ts +1 -3
- package/dist/data-url-to-blob.js +11 -36
- package/dist/data-url-to-blob.mjs +7 -11
- package/dist/download-file.d.mts +30 -32
- package/dist/download-file.d.ts +30 -32
- package/dist/download-file.js +43 -72
- package/dist/download-file.mjs +39 -47
- package/dist/get-accept-attr.d.mts +1 -3
- package/dist/get-accept-attr.d.ts +1 -3
- package/dist/get-accept-attr.js +16 -39
- package/dist/get-accept-attr.mjs +12 -14
- package/dist/get-file-data-url.d.mts +1 -3
- package/dist/get-file-data-url.d.ts +1 -3
- package/dist/get-file-data-url.js +19 -45
- package/dist/get-file-data-url.mjs +15 -20
- package/dist/get-file-mime-type.d.mts +2 -5
- package/dist/get-file-mime-type.d.ts +2 -5
- package/dist/get-file-mime-type.js +8 -31
- package/dist/get-file-mime-type.mjs +4 -6
- package/dist/get-total-file-size.d.mts +1 -3
- package/dist/get-total-file-size.d.ts +1 -3
- package/dist/get-total-file-size.js +7 -30
- package/dist/get-total-file-size.mjs +3 -5
- package/dist/index.d.mts +12 -11
- package/dist/index.d.ts +12 -11
- package/dist/index.js +25 -41
- package/dist/index.mjs +11 -11
- package/dist/is-file-equal.d.mts +2 -4
- package/dist/is-file-equal.d.ts +2 -4
- package/dist/is-file-equal.js +10 -34
- package/dist/is-file-equal.mjs +5 -8
- package/dist/is-valid-file-size.d.mts +2 -5
- package/dist/is-valid-file-size.d.ts +2 -5
- package/dist/is-valid-file-size.js +14 -40
- package/dist/is-valid-file-size.mjs +10 -15
- package/dist/is-valid-file-type.d.mts +3 -6
- package/dist/is-valid-file-type.d.ts +3 -6
- package/dist/is-valid-file-type.js +43 -60
- package/dist/is-valid-file-type.mjs +38 -34
- package/dist/mime-types.d.mts +2 -4
- package/dist/mime-types.d.ts +2 -4
- package/dist/mime-types.js +11 -37
- package/dist/mime-types.mjs +6 -11
- package/dist/types.d.mts +10 -11
- package/dist/types.d.ts +10 -11
- package/dist/types.js +4 -18
- package/dist/types.mjs +1 -0
- package/package.json +4 -4
package/dist/data-transfer.d.mts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
declare const getFileEntries: (items: DataTransferItemList, traverseDirectories: boolean | undefined) => Promise<(
|
|
2
|
-
|
|
3
|
-
export { getFileEntries };
|
|
1
|
+
export declare const getFileEntries: (items: DataTransferItemList, traverseDirectories: boolean | undefined) => Promise<((File | null)[] | File | null | undefined)[]>;
|
package/dist/data-transfer.d.ts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
declare const getFileEntries: (items: DataTransferItemList, traverseDirectories: boolean | undefined) => Promise<(
|
|
2
|
-
|
|
3
|
-
export { getFileEntries };
|
|
1
|
+
export declare const getFileEntries: (items: DataTransferItemList, traverseDirectories: boolean | undefined) => Promise<((File | null)[] | File | null | undefined)[]>;
|
package/dist/data-transfer.js
CHANGED
|
@@ -1,83 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/data-transfer.ts
|
|
21
|
-
var data_transfer_exports = {};
|
|
22
|
-
__export(data_transfer_exports, {
|
|
23
|
-
getFileEntries: () => getFileEntries
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
// src/data-transfer.ts
|
|
6
|
+
const getItemEntry = (item) => typeof item.getAsEntry === "function" ? item.getAsEntry() : typeof item.webkitGetAsEntry === "function" ? item.webkitGetAsEntry() : null;
|
|
7
|
+
const isDirectoryEntry = (entry) => entry.isDirectory;
|
|
8
|
+
const isFileEntry = (entry) => entry.isFile;
|
|
9
|
+
const addRelativePath = (file, path) => {
|
|
10
|
+
Object.defineProperty(file, "relativePath", { value: path ? `${path}/${file.name}` : file.name });
|
|
11
|
+
return file;
|
|
32
12
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
resolve2(addRelativePath(file, path));
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}).filter((b) => b);
|
|
74
|
-
entryPromises.push(Promise.all(promises));
|
|
75
|
-
readDirectoryEntries();
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
readDirectoryEntries();
|
|
79
|
-
});
|
|
80
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
-
0 && (module.exports = {
|
|
82
|
-
getFileEntries
|
|
13
|
+
const getFileEntries = (items, traverseDirectories) => Promise.all(Array.from(items).filter((item) => item.kind === "file").map((item) => {
|
|
14
|
+
const entry = getItemEntry(item);
|
|
15
|
+
if (!entry) return null;
|
|
16
|
+
if (isDirectoryEntry(entry) && traverseDirectories) return getDirectoryFiles(entry.createReader(), `${entry.name}`);
|
|
17
|
+
if (isFileEntry(entry) && typeof item.getAsFile === "function") {
|
|
18
|
+
const file = item.getAsFile();
|
|
19
|
+
return Promise.resolve(file ? addRelativePath(file, "") : null);
|
|
20
|
+
}
|
|
21
|
+
if (isFileEntry(entry)) return new Promise((resolve) => {
|
|
22
|
+
entry.file((file) => {
|
|
23
|
+
resolve(addRelativePath(file, ""));
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}).filter((b) => b));
|
|
27
|
+
const getDirectoryFiles = (reader, path = "") => new Promise((resolve) => {
|
|
28
|
+
const entryPromises = [];
|
|
29
|
+
const readDirectoryEntries = () => {
|
|
30
|
+
reader.readEntries((entries) => {
|
|
31
|
+
if (entries.length === 0) {
|
|
32
|
+
resolve(Promise.all(entryPromises).then((entries) => entries.flat()));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const promises = entries.map((entry) => {
|
|
36
|
+
if (!entry) return null;
|
|
37
|
+
if (isDirectoryEntry(entry)) return getDirectoryFiles(entry.createReader(), `${path}${entry.name}`);
|
|
38
|
+
if (isFileEntry(entry)) return new Promise((resolve) => {
|
|
39
|
+
entry.file((file) => {
|
|
40
|
+
resolve(addRelativePath(file, path));
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}).filter((b) => b);
|
|
44
|
+
entryPromises.push(Promise.all(promises));
|
|
45
|
+
readDirectoryEntries();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
readDirectoryEntries();
|
|
83
49
|
});
|
|
50
|
+
exports.getFileEntries = getFileEntries;
|
package/dist/data-transfer.mjs
CHANGED
|
@@ -1,58 +1,46 @@
|
|
|
1
1
|
// src/data-transfer.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
const getItemEntry = (item) => typeof item.getAsEntry === "function" ? item.getAsEntry() : typeof item.webkitGetAsEntry === "function" ? item.webkitGetAsEntry() : null;
|
|
3
|
+
const isDirectoryEntry = (entry) => entry.isDirectory;
|
|
4
|
+
const isFileEntry = (entry) => entry.isFile;
|
|
5
|
+
const addRelativePath = (file, path) => {
|
|
6
|
+
Object.defineProperty(file, "relativePath", { value: path ? `${path}/${file.name}` : file.name });
|
|
7
|
+
return file;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
resolve2(addRelativePath(file, path));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}).filter((b) => b);
|
|
50
|
-
entryPromises.push(Promise.all(promises));
|
|
51
|
-
readDirectoryEntries();
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
readDirectoryEntries();
|
|
9
|
+
const getFileEntries = (items, traverseDirectories) => Promise.all(Array.from(items).filter((item) => item.kind === "file").map((item) => {
|
|
10
|
+
const entry = getItemEntry(item);
|
|
11
|
+
if (!entry) return null;
|
|
12
|
+
if (isDirectoryEntry(entry) && traverseDirectories) return getDirectoryFiles(entry.createReader(), `${entry.name}`);
|
|
13
|
+
if (isFileEntry(entry) && typeof item.getAsFile === "function") {
|
|
14
|
+
const file = item.getAsFile();
|
|
15
|
+
return Promise.resolve(file ? addRelativePath(file, "") : null);
|
|
16
|
+
}
|
|
17
|
+
if (isFileEntry(entry)) return new Promise((resolve) => {
|
|
18
|
+
entry.file((file) => {
|
|
19
|
+
resolve(addRelativePath(file, ""));
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}).filter((b) => b));
|
|
23
|
+
const getDirectoryFiles = (reader, path = "") => new Promise((resolve) => {
|
|
24
|
+
const entryPromises = [];
|
|
25
|
+
const readDirectoryEntries = () => {
|
|
26
|
+
reader.readEntries((entries) => {
|
|
27
|
+
if (entries.length === 0) {
|
|
28
|
+
resolve(Promise.all(entryPromises).then((entries) => entries.flat()));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const promises = entries.map((entry) => {
|
|
32
|
+
if (!entry) return null;
|
|
33
|
+
if (isDirectoryEntry(entry)) return getDirectoryFiles(entry.createReader(), `${path}${entry.name}`);
|
|
34
|
+
if (isFileEntry(entry)) return new Promise((resolve) => {
|
|
35
|
+
entry.file((file) => {
|
|
36
|
+
resolve(addRelativePath(file, path));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}).filter((b) => b);
|
|
40
|
+
entryPromises.push(Promise.all(promises));
|
|
41
|
+
readDirectoryEntries();
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
readDirectoryEntries();
|
|
55
45
|
});
|
|
56
|
-
export {
|
|
57
|
-
getFileEntries
|
|
58
|
-
};
|
|
46
|
+
export { getFileEntries };
|
package/dist/data-url-to-blob.js
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/data-url-to-blob.ts
|
|
21
|
-
var data_url_to_blob_exports = {};
|
|
22
|
-
__export(data_url_to_blob_exports, {
|
|
23
|
-
dataURItoBlob: () => dataURItoBlob
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
5
|
+
// src/data-url-to-blob.ts
|
|
26
6
|
function dataURItoBlob(uri) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return new Blob([buffer], { type: mimeString });
|
|
7
|
+
const binary = atob(uri.split(",")[1]);
|
|
8
|
+
const mimeString = uri.split(",")[0].split(":")[1].split(";")[0];
|
|
9
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
10
|
+
const intArray = new Uint8Array(buffer);
|
|
11
|
+
for (let i = 0; i < binary.length; i++) intArray[i] = binary.charCodeAt(i);
|
|
12
|
+
return new Blob([buffer], { type: mimeString });
|
|
35
13
|
}
|
|
36
|
-
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
dataURItoBlob
|
|
39
|
-
});
|
|
14
|
+
exports.dataURItoBlob = dataURItoBlob;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
// src/data-url-to-blob.ts
|
|
2
2
|
function dataURItoBlob(uri) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return new Blob([buffer], { type: mimeString });
|
|
3
|
+
const binary = atob(uri.split(",")[1]);
|
|
4
|
+
const mimeString = uri.split(",")[0].split(":")[1].split(";")[0];
|
|
5
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
6
|
+
const intArray = new Uint8Array(buffer);
|
|
7
|
+
for (let i = 0; i < binary.length; i++) intArray[i] = binary.charCodeAt(i);
|
|
8
|
+
return new Blob([buffer], { type: mimeString });
|
|
11
9
|
}
|
|
12
|
-
export {
|
|
13
|
-
dataURItoBlob
|
|
14
|
-
};
|
|
10
|
+
export { dataURItoBlob };
|
package/dist/download-file.d.mts
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
interface DownloadFileOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
export interface DownloadFileOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The name of the file
|
|
4
|
+
*/
|
|
5
|
+
name?: string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The MIME type of the file
|
|
8
|
+
*/
|
|
9
|
+
type: string;
|
|
10
|
+
/**
|
|
11
|
+
* The file contents
|
|
12
|
+
*/
|
|
13
|
+
file: File | Blob | string;
|
|
14
|
+
/**
|
|
15
|
+
* The window environment
|
|
16
|
+
*/
|
|
17
|
+
win?: typeof window | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to add a BOM (Byte Order Mark) to the file.
|
|
20
|
+
* Useful for CSV files.
|
|
21
|
+
*/
|
|
22
|
+
appendBOM?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The timeout in milliseconds to revoke the object URL.
|
|
25
|
+
* This is a safeguard for when the browser has not finished reading the
|
|
26
|
+
* file data from memory before the URL is revoked.
|
|
27
|
+
* @default 0
|
|
28
|
+
*/
|
|
29
|
+
revokeTimeout?: number | undefined;
|
|
30
30
|
}
|
|
31
|
-
declare function downloadFile(options: DownloadFileOptions): void;
|
|
32
|
-
|
|
33
|
-
export { type DownloadFileOptions, downloadFile };
|
|
31
|
+
export declare function downloadFile(options: DownloadFileOptions): void;
|
package/dist/download-file.d.ts
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
interface DownloadFileOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
export interface DownloadFileOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The name of the file
|
|
4
|
+
*/
|
|
5
|
+
name?: string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The MIME type of the file
|
|
8
|
+
*/
|
|
9
|
+
type: string;
|
|
10
|
+
/**
|
|
11
|
+
* The file contents
|
|
12
|
+
*/
|
|
13
|
+
file: File | Blob | string;
|
|
14
|
+
/**
|
|
15
|
+
* The window environment
|
|
16
|
+
*/
|
|
17
|
+
win?: typeof window | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to add a BOM (Byte Order Mark) to the file.
|
|
20
|
+
* Useful for CSV files.
|
|
21
|
+
*/
|
|
22
|
+
appendBOM?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The timeout in milliseconds to revoke the object URL.
|
|
25
|
+
* This is a safeguard for when the browser has not finished reading the
|
|
26
|
+
* file data from memory before the URL is revoked.
|
|
27
|
+
* @default 0
|
|
28
|
+
*/
|
|
29
|
+
revokeTimeout?: number | undefined;
|
|
30
30
|
}
|
|
31
|
-
declare function downloadFile(options: DownloadFileOptions): void;
|
|
32
|
-
|
|
33
|
-
export { type DownloadFileOptions, downloadFile };
|
|
31
|
+
export declare function downloadFile(options: DownloadFileOptions): void;
|
package/dist/download-file.js
CHANGED
|
@@ -1,81 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/download-file.ts
|
|
21
|
-
var download_file_exports = {};
|
|
22
|
-
__export(download_file_exports, {
|
|
23
|
-
downloadFile: () => downloadFile
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
5
|
+
// src/download-file.ts
|
|
6
|
+
const BOM_REGEX = /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i;
|
|
7
|
+
const MAC_REGEX = /Macintosh/;
|
|
8
|
+
const APPLE_WEBKIT_REGEX = /AppleWebKit/;
|
|
9
|
+
const SAFARI_REGEX = /Safari/;
|
|
30
10
|
function getBlob(blobOrString, type, appendBOM) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return blob;
|
|
11
|
+
let blob = typeof blobOrString === "string" ? new Blob([blobOrString], { type }) : blobOrString;
|
|
12
|
+
if (appendBOM && BOM_REGEX.test(blob.type)) return new Blob([String.fromCharCode(65279), blob], { type: blob.type });
|
|
13
|
+
return blob;
|
|
36
14
|
}
|
|
37
15
|
function isMSEdge(win) {
|
|
38
|
-
|
|
16
|
+
return Boolean(win.navigator && win.navigator.msSaveOrOpenBlob);
|
|
39
17
|
}
|
|
40
18
|
function isWebView(win) {
|
|
41
|
-
|
|
19
|
+
return win.navigator && MAC_REGEX.test(win.navigator.userAgent) && APPLE_WEBKIT_REGEX.test(win.navigator.userAgent) && !SAFARI_REGEX.test(win.navigator.userAgent);
|
|
42
20
|
}
|
|
43
21
|
function downloadFile(options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
setTimeout(() => {
|
|
75
|
-
win.URL.revokeObjectURL(url);
|
|
76
|
-
}, revokeTimeout);
|
|
22
|
+
const { file, win = window, type, name, appendBOM, revokeTimeout = 0 } = options;
|
|
23
|
+
const doc = win.document;
|
|
24
|
+
const blob = getBlob(file, type, appendBOM);
|
|
25
|
+
const fileName = (file instanceof File ? name || file.name : name) || "file-download";
|
|
26
|
+
if (isMSEdge(win)) {
|
|
27
|
+
win.navigator.msSaveOrOpenBlob(blob, fileName);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const isMacOSWebView = isWebView(win);
|
|
31
|
+
const anchor = doc.createElement("a");
|
|
32
|
+
if ("download" in anchor && !isMacOSWebView) {
|
|
33
|
+
const url = win.URL.createObjectURL(blob);
|
|
34
|
+
anchor.href = url;
|
|
35
|
+
anchor.rel = "noopener";
|
|
36
|
+
anchor.download = fileName;
|
|
37
|
+
anchor.style.display = "none";
|
|
38
|
+
doc.body.appendChild(anchor);
|
|
39
|
+
anchor.dispatchEvent(new win.MouseEvent("click"));
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
win.URL.revokeObjectURL(url);
|
|
42
|
+
anchor.remove();
|
|
43
|
+
}, revokeTimeout);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const url = win.URL.createObjectURL(blob);
|
|
47
|
+
if (!win.open(url, "_blank")) win.location.href = url;
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
win.URL.revokeObjectURL(url);
|
|
50
|
+
}, revokeTimeout);
|
|
77
51
|
}
|
|
78
|
-
|
|
79
|
-
0 && (module.exports = {
|
|
80
|
-
downloadFile
|
|
81
|
-
});
|
|
52
|
+
exports.downloadFile = downloadFile;
|