@fgv/ts-web-extras 5.0.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/.rush/temp/86c9c1ad46e237e0b957c2442bf0355cf39babba.tar.log +121 -0
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +40 -0
- package/.rush/temp/operation/build/all.log +40 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +40 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/shrinkwrap-deps.json +624 -0
- package/config/api-extractor.json +343 -0
- package/config/jest.config.json +16 -0
- package/config/rig.json +16 -0
- package/dist/ts-web-extras.d.ts +574 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/docs/index.md +34 -0
- package/docs/ts-web-extras.browserhashprovider.hashparts.md +88 -0
- package/docs/ts-web-extras.browserhashprovider.hashstring.md +72 -0
- package/docs/ts-web-extras.browserhashprovider.md +66 -0
- package/docs/ts-web-extras.exportasjson.md +70 -0
- package/docs/ts-web-extras.exportusingfilesystemapi.md +104 -0
- package/docs/ts-web-extras.extractdirectorypath.md +52 -0
- package/docs/ts-web-extras.fileapitreeaccessors.create.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +54 -0
- package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +72 -0
- package/docs/ts-web-extras.fileapitreeaccessors.md +114 -0
- package/docs/ts-web-extras.filepickeraccepttype.accept.md +11 -0
- package/docs/ts-web-extras.filepickeraccepttype.description.md +11 -0
- package/docs/ts-web-extras.filepickeraccepttype.md +75 -0
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +11 -0
- package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +15 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +146 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +66 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +50 -0
- package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +15 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +52 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +15 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemfilehandle_2.md +92 -0
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +11 -0
- package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +11 -0
- package/docs/ts-web-extras.filesystemgetfileoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +50 -0
- package/docs/ts-web-extras.filesystemhandle_2.kind.md +11 -0
- package/docs/ts-web-extras.filesystemhandle_2.md +119 -0
- package/docs/ts-web-extras.filesystemhandle_2.name.md +11 -0
- package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +52 -0
- package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +52 -0
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +58 -0
- package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +11 -0
- package/docs/ts-web-extras.filesystemremoveoptions_2.md +58 -0
- package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +11 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.md +57 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +50 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +50 -0
- package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +50 -0
- package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +13 -0
- package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +56 -0
- package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +56 -0
- package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +76 -0
- package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +76 -0
- package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +72 -0
- package/docs/ts-web-extras.filetreehelpers.md +102 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +11 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +100 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +11 -0
- package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +11 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +11 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.md +79 -0
- package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +11 -0
- package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +11 -0
- package/docs/ts-web-extras.ifilelisttreeinitializer.md +58 -0
- package/docs/ts-web-extras.ifilemetadata.lastmodified.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.md +124 -0
- package/docs/ts-web-extras.ifilemetadata.name.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.path.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.size.md +11 -0
- package/docs/ts-web-extras.ifilemetadata.type.md +11 -0
- package/docs/ts-web-extras.ifsaccessapis.md +56 -0
- package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +52 -0
- package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +52 -0
- package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +52 -0
- package/docs/ts-web-extras.isdirectoryhandle.md +56 -0
- package/docs/ts-web-extras.isfilehandle.md +56 -0
- package/docs/ts-web-extras.isfilepath.md +52 -0
- package/docs/ts-web-extras.iurlconfigoptions.config.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.input.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.interactive.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.md +286 -0
- package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +13 -0
- package/docs/ts-web-extras.iurlconfigoptions.zippath.md +13 -0
- package/docs/ts-web-extras.md +512 -0
- package/docs/ts-web-extras.parsecontextfilter.md +52 -0
- package/docs/ts-web-extras.parsequalifierdefaults.md +52 -0
- package/docs/ts-web-extras.parseresourcetypes.md +52 -0
- package/docs/ts-web-extras.parseurlparameters.md +17 -0
- package/docs/ts-web-extras.safeshowdirectorypicker.md +72 -0
- package/docs/ts-web-extras.safeshowopenfilepicker.md +72 -0
- package/docs/ts-web-extras.safeshowsavefilepicker.md +72 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.md +96 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +11 -0
- package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.md +134 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showopenfilepickeroptions.types.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.id.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.md +134 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +11 -0
- package/docs/ts-web-extras.showsavefilepickeroptions.types.md +11 -0
- package/docs/ts-web-extras.supportsfilesystemaccess.md +56 -0
- package/docs/ts-web-extras.treeinitializer.md +15 -0
- package/docs/ts-web-extras.wellknowndirectory.md +13 -0
- package/docs/ts-web-extras.windowwithfsaccess.md +15 -0
- package/etc/ts-web-extras.api.md +310 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +58 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/crypto/browserHashProvider.d.ts +24 -0
- package/lib/packlets/crypto/browserHashProvider.d.ts.map +1 -0
- package/lib/packlets/crypto/browserHashProvider.js +70 -0
- package/lib/packlets/crypto/browserHashProvider.js.map +1 -0
- package/lib/packlets/crypto/index.d.ts +6 -0
- package/lib/packlets/crypto/index.d.ts.map +1 -0
- package/lib/packlets/crypto/index.js +43 -0
- package/lib/packlets/crypto/index.js.map +1 -0
- package/lib/packlets/file-api-types/index.d.ts +205 -0
- package/lib/packlets/file-api-types/index.d.ts.map +1 -0
- package/lib/packlets/file-api-types/index.js +166 -0
- package/lib/packlets/file-api-types/index.js.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +129 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js +334 -0
- package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts +6 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.js +43 -0
- package/lib/packlets/file-tree/index.js.map +1 -0
- package/lib/packlets/helpers/fileTreeHelpers.d.ts +60 -0
- package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -0
- package/lib/packlets/helpers/fileTreeHelpers.js +102 -0
- package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -0
- package/lib/packlets/helpers/index.d.ts +6 -0
- package/lib/packlets/helpers/index.d.ts.map +1 -0
- package/lib/packlets/helpers/index.js +63 -0
- package/lib/packlets/helpers/index.js.map +1 -0
- package/lib/packlets/url-utils/index.d.ts +6 -0
- package/lib/packlets/url-utils/index.d.ts.map +1 -0
- package/lib/packlets/url-utils/index.js +43 -0
- package/lib/packlets/url-utils/index.js.map +1 -0
- package/lib/packlets/url-utils/urlParams.d.ts +94 -0
- package/lib/packlets/url-utils/urlParams.d.ts.map +1 -0
- package/lib/packlets/url-utils/urlParams.js +165 -0
- package/lib/packlets/url-utils/urlParams.js.map +1 -0
- package/lib/test/setupTests.d.ts +2 -0
- package/lib/test/setupTests.d.ts.map +1 -0
- package/lib/test/setupTests.js +76 -0
- package/lib/test/setupTests.js.map +1 -0
- package/lib/test/unit/browserHashProvider.test.d.ts +2 -0
- package/lib/test/unit/browserHashProvider.test.d.ts.map +1 -0
- package/lib/test/unit/browserHashProvider.test.js +142 -0
- package/lib/test/unit/browserHashProvider.test.js.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts +2 -0
- package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +1 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js +1139 -0
- package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -0
- package/lib/test/unit/fileApiTypes.test.d.ts +2 -0
- package/lib/test/unit/fileApiTypes.test.d.ts.map +1 -0
- package/lib/test/unit/fileApiTypes.test.js +444 -0
- package/lib/test/unit/fileApiTypes.test.js.map +1 -0
- package/lib/test/unit/fileTreeHelpers.test.d.ts +2 -0
- package/lib/test/unit/fileTreeHelpers.test.d.ts.map +1 -0
- package/lib/test/unit/fileTreeHelpers.test.js +592 -0
- package/lib/test/unit/fileTreeHelpers.test.js.map +1 -0
- package/lib/test/unit/urlParams.test.d.ts +2 -0
- package/lib/test/unit/urlParams.test.d.ts.map +1 -0
- package/lib/test/unit/urlParams.test.js +395 -0
- package/lib/test/unit/urlParams.test.js.map +1 -0
- package/lib/test/utils/testHelpers.d.ts +51 -0
- package/lib/test/utils/testHelpers.d.ts.map +1 -0
- package/lib/test/utils/testHelpers.js +133 -0
- package/lib/test/utils/testHelpers.js.map +1 -0
- package/package.json +68 -0
- package/rush-logs/ts-web-extras.build.cache.log +3 -0
- package/rush-logs/ts-web-extras.build.log +40 -0
- package/src/index.ts +47 -0
- package/src/packlets/crypto/browserHashProvider.ts +73 -0
- package/src/packlets/crypto/index.ts +28 -0
- package/src/packlets/file-api-types/index.ts +345 -0
- package/src/packlets/file-tree/fileApiTreeAccessors.ts +420 -0
- package/src/packlets/file-tree/index.ts +28 -0
- package/src/packlets/helpers/fileTreeHelpers.ts +107 -0
- package/src/packlets/helpers/index.ts +28 -0
- package/src/packlets/url-utils/index.ts +28 -0
- package/src/packlets/url-utils/urlParams.ts +245 -0
- package/src/test/setupTests.ts +87 -0
- package/src/test/unit/browserHashProvider.test.ts +155 -0
- package/src/test/unit/browserHashProvider.test.ts.bak +376 -0
- package/src/test/unit/fileApiTreeAccessors.test.ts +1318 -0
- package/src/test/unit/fileApiTypes.test.ts +551 -0
- package/src/test/unit/fileTreeHelpers.test.ts +694 -0
- package/src/test/unit/urlParams.test.ts +464 -0
- package/src/test/utils/testHelpers.ts +155 -0
- package/temp/build/typescript/ts_l9Fw4VUO.json +1 -0
- package/temp/coverage/base.css +224 -0
- package/temp/coverage/block-navigation.js +87 -0
- package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
- package/temp/coverage/crypto/index.html +116 -0
- package/temp/coverage/favicon.png +0 -0
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1345 -0
- package/temp/coverage/file-tree/index.html +116 -0
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +406 -0
- package/temp/coverage/helpers/index.html +116 -0
- package/temp/coverage/index.html +161 -0
- package/temp/coverage/lcov-report/base.css +224 -0
- package/temp/coverage/lcov-report/block-navigation.js +87 -0
- package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
- package/temp/coverage/lcov-report/crypto/index.html +116 -0
- package/temp/coverage/lcov-report/favicon.png +0 -0
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1345 -0
- package/temp/coverage/lcov-report/file-tree/index.html +116 -0
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +406 -0
- package/temp/coverage/lcov-report/helpers/index.html +116 -0
- package/temp/coverage/lcov-report/index.html +161 -0
- package/temp/coverage/lcov-report/prettify.css +1 -0
- package/temp/coverage/lcov-report/prettify.js +2 -0
- package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/temp/coverage/lcov-report/sorter.js +210 -0
- package/temp/coverage/lcov-report/url-utils/index.html +116 -0
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +820 -0
- package/temp/coverage/lcov.info +1096 -0
- package/temp/coverage/prettify.css +1 -0
- package/temp/coverage/prettify.js +2 -0
- package/temp/coverage/sort-arrow-sprite.png +0 -0
- package/temp/coverage/sorter.js +210 -0
- package/temp/coverage/url-utils/index.html +116 -0
- package/temp/coverage/url-utils/urlParams.ts.html +820 -0
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/63/package_63a8257b0e4d0e7ff33f927d75f27a75 +53 -0
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
- package/temp/ts-web-extras.api.json +5040 -0
- package/temp/ts-web-extras.api.md +310 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
/**
|
|
39
|
+
* Browser-compatible cryptographic utilities using the Web Crypto API.
|
|
40
|
+
* @packageDocumentation
|
|
41
|
+
*/
|
|
42
|
+
__exportStar(require("./browserHashProvider"), exports);
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/crypto/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH;;;GAGG;AAEH,wDAAsC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Browser-compatible cryptographic utilities using the Web Crypto API.\n * @packageDocumentation\n */\n\nexport * from './browserHashProvider';\n"]}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File System Access API type definitions and utilities for browser compatibility.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* File System Access API methods available on Window
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IFsAccessApis {
|
|
10
|
+
showDirectoryPicker(options?: ShowDirectoryPickerOptions): Promise<FileSystemDirectoryHandle>;
|
|
11
|
+
showOpenFilePicker(options?: ShowOpenFilePickerOptions): Promise<FileSystemFileHandle[]>;
|
|
12
|
+
showSaveFilePicker(options?: ShowSaveFilePickerOptions): Promise<FileSystemFileHandle>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Window interface extended with File System Access API
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export type WindowWithFsAccess = Window & IFsAccessApis;
|
|
19
|
+
/**
|
|
20
|
+
* Base interface for file system handles
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface FileSystemHandle {
|
|
24
|
+
readonly kind: 'file' | 'directory';
|
|
25
|
+
readonly name: string;
|
|
26
|
+
isSameEntry(other: FileSystemHandle): Promise<boolean>;
|
|
27
|
+
queryPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;
|
|
28
|
+
requestPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* File handle interface
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export interface FileSystemFileHandle extends FileSystemHandle {
|
|
35
|
+
readonly kind: 'file';
|
|
36
|
+
getFile(): Promise<File>;
|
|
37
|
+
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Directory handle interface
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export interface FileSystemDirectoryHandle extends FileSystemHandle {
|
|
44
|
+
readonly kind: 'directory';
|
|
45
|
+
getDirectoryHandle(name: string, options?: FileSystemGetDirectoryOptions): Promise<FileSystemDirectoryHandle>;
|
|
46
|
+
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>;
|
|
47
|
+
removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<void>;
|
|
48
|
+
resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
|
|
49
|
+
keys(): AsyncIterableIterator<string>;
|
|
50
|
+
values(): AsyncIterableIterator<FileSystemHandle>;
|
|
51
|
+
entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
52
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Permission descriptor for file system handles
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export interface FileSystemHandlePermissionDescriptor {
|
|
59
|
+
mode?: 'read' | 'readwrite';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for creating writable file streams
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export interface FileSystemCreateWritableOptions {
|
|
66
|
+
keepExistingData?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Options for getting directory handles
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export interface FileSystemGetDirectoryOptions {
|
|
73
|
+
create?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for getting file handles
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export interface FileSystemGetFileOptions {
|
|
80
|
+
create?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Options for removing entries
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface FileSystemRemoveOptions {
|
|
87
|
+
recursive?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Writable file stream interface
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
export interface FileSystemWritableFileStream extends WritableStream {
|
|
94
|
+
write(data: BufferSource | Blob | string): Promise<void>;
|
|
95
|
+
seek(position: number): Promise<void>;
|
|
96
|
+
truncate(size: number): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Directory picker options
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export interface ShowDirectoryPickerOptions {
|
|
103
|
+
id?: string;
|
|
104
|
+
mode?: 'read' | 'readwrite';
|
|
105
|
+
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* File picker options
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export interface ShowOpenFilePickerOptions {
|
|
112
|
+
multiple?: boolean;
|
|
113
|
+
excludeAcceptAllOption?: boolean;
|
|
114
|
+
id?: string;
|
|
115
|
+
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
116
|
+
types?: FilePickerAcceptType[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Save file picker options
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
export interface ShowSaveFilePickerOptions {
|
|
123
|
+
excludeAcceptAllOption?: boolean;
|
|
124
|
+
id?: string;
|
|
125
|
+
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
126
|
+
suggestedName?: string;
|
|
127
|
+
types?: FilePickerAcceptType[];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* File picker accept type
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export interface FilePickerAcceptType {
|
|
134
|
+
description?: string;
|
|
135
|
+
accept: Record<string, string | string[]>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Well-known directory type
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export type WellKnownDirectory = 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos';
|
|
142
|
+
/**
|
|
143
|
+
* Type guard to check if the browser supports the File System Access API
|
|
144
|
+
* @param window - The window object to check
|
|
145
|
+
* @returns True if the window supports File System Access API
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
export declare function supportsFileSystemAccess(window: Window): window is WindowWithFsAccess;
|
|
149
|
+
/**
|
|
150
|
+
* Type guard to check if a FileSystemHandle is a file handle
|
|
151
|
+
* @param handle - The handle to check
|
|
152
|
+
* @returns True if the handle is a FileSystemFileHandle
|
|
153
|
+
* @public
|
|
154
|
+
*/
|
|
155
|
+
export declare function isFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle;
|
|
156
|
+
/**
|
|
157
|
+
* Type guard to check if a FileSystemHandle is a directory handle
|
|
158
|
+
* @param handle - The handle to check
|
|
159
|
+
* @returns True if the handle is a FileSystemDirectoryHandle
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export declare function isDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle;
|
|
163
|
+
/**
|
|
164
|
+
* Safely access showOpenFilePicker with proper type checking
|
|
165
|
+
* @param window - The window object
|
|
166
|
+
* @param options - Options for the file picker
|
|
167
|
+
* @returns Promise with file handles or null if not supported
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
export declare function safeShowOpenFilePicker(window: Window, options?: ShowOpenFilePickerOptions): Promise<FileSystemFileHandle[] | null>;
|
|
171
|
+
/**
|
|
172
|
+
* Safely access showSaveFilePicker with proper type checking
|
|
173
|
+
* @param window - The window object
|
|
174
|
+
* @param options - Options for the file picker
|
|
175
|
+
* @returns Promise with file handle or null if not supported
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
export declare function safeShowSaveFilePicker(window: Window, options?: ShowSaveFilePickerOptions): Promise<FileSystemFileHandle | null>;
|
|
179
|
+
/**
|
|
180
|
+
* Safely access showDirectoryPicker with proper type checking
|
|
181
|
+
* @param window - The window object
|
|
182
|
+
* @param options - Options for the directory picker
|
|
183
|
+
* @returns Promise with directory handle or null if not supported
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
export declare function safeShowDirectoryPicker(window: Window, options?: ShowDirectoryPickerOptions): Promise<FileSystemDirectoryHandle | null>;
|
|
187
|
+
/**
|
|
188
|
+
* Export data as JSON file using legacy blob download method.
|
|
189
|
+
* Creates a temporary download link and triggers file download.
|
|
190
|
+
* @param data - Data to export as JSON
|
|
191
|
+
* @param filename - Name for the downloaded file
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
export declare function exportAsJson(data: unknown, filename: string): void;
|
|
195
|
+
/**
|
|
196
|
+
* Export data using File System Access API with fallback to blob download.
|
|
197
|
+
* @param data - Data to export as JSON
|
|
198
|
+
* @param suggestedName - Suggested filename for the save dialog
|
|
199
|
+
* @param description - Description for file type filter (default: 'JSON files')
|
|
200
|
+
* @param window - Window object for API access (default: globalThis.window)
|
|
201
|
+
* @returns Promise resolving to true if saved via File System Access API, false if fallback used
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
204
|
+
export declare function exportUsingFileSystemAPI(data: unknown, suggestedName: string, description?: string, window?: Window): Promise<boolean>;
|
|
205
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-api-types/index.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAKH;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC9F,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACzF,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACxF;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,aAAa,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,eAAe,CAAC,UAAU,CAAC,EAAE,oCAAoC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7F,iBAAiB,CAAC,UAAU,CAAC,EAAE,oCAAoC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChG;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,cAAc,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAClG;AAED;;;GAGG;AACH,MAAM,WAAW,y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C;AAEzG;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,kBAAkB,CAErF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,IAAI,oBAAoB,CAErF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,IAAI,yBAAyB,CAE/F;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,oBAAoB,EAAE,GAAG,IAAI,CAAC,CAKxC;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAKtC;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAK3C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAYlE;AAED;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,EACrB,WAAW,GAAE,MAAqB,EAClC,MAAM,GAAE,MAA0B,GACjC,OAAO,CAAC,OAAO,CAAC,CA0ClB"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.supportsFileSystemAccess = supportsFileSystemAccess;
|
|
25
|
+
exports.isFileHandle = isFileHandle;
|
|
26
|
+
exports.isDirectoryHandle = isDirectoryHandle;
|
|
27
|
+
exports.safeShowOpenFilePicker = safeShowOpenFilePicker;
|
|
28
|
+
exports.safeShowSaveFilePicker = safeShowSaveFilePicker;
|
|
29
|
+
exports.safeShowDirectoryPicker = safeShowDirectoryPicker;
|
|
30
|
+
exports.exportAsJson = exportAsJson;
|
|
31
|
+
exports.exportUsingFileSystemAPI = exportUsingFileSystemAPI;
|
|
32
|
+
/**
|
|
33
|
+
* Type guard to check if the browser supports the File System Access API
|
|
34
|
+
* @param window - The window object to check
|
|
35
|
+
* @returns True if the window supports File System Access API
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
function supportsFileSystemAccess(window) {
|
|
39
|
+
return 'showOpenFilePicker' in window && 'showSaveFilePicker' in window && 'showDirectoryPicker' in window;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Type guard to check if a FileSystemHandle is a file handle
|
|
43
|
+
* @param handle - The handle to check
|
|
44
|
+
* @returns True if the handle is a FileSystemFileHandle
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
function isFileHandle(handle) {
|
|
48
|
+
return handle.kind === 'file';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Type guard to check if a FileSystemHandle is a directory handle
|
|
52
|
+
* @param handle - The handle to check
|
|
53
|
+
* @returns True if the handle is a FileSystemDirectoryHandle
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
function isDirectoryHandle(handle) {
|
|
57
|
+
return handle.kind === 'directory';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Safely access showOpenFilePicker with proper type checking
|
|
61
|
+
* @param window - The window object
|
|
62
|
+
* @param options - Options for the file picker
|
|
63
|
+
* @returns Promise with file handles or null if not supported
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
async function safeShowOpenFilePicker(window, options) {
|
|
67
|
+
if (supportsFileSystemAccess(window)) {
|
|
68
|
+
return window.showOpenFilePicker(options);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Safely access showSaveFilePicker with proper type checking
|
|
74
|
+
* @param window - The window object
|
|
75
|
+
* @param options - Options for the file picker
|
|
76
|
+
* @returns Promise with file handle or null if not supported
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
async function safeShowSaveFilePicker(window, options) {
|
|
80
|
+
if (supportsFileSystemAccess(window)) {
|
|
81
|
+
return window.showSaveFilePicker(options);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Safely access showDirectoryPicker with proper type checking
|
|
87
|
+
* @param window - The window object
|
|
88
|
+
* @param options - Options for the directory picker
|
|
89
|
+
* @returns Promise with directory handle or null if not supported
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
async function safeShowDirectoryPicker(window, options) {
|
|
93
|
+
if (supportsFileSystemAccess(window)) {
|
|
94
|
+
return window.showDirectoryPicker(options);
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Export data as JSON file using legacy blob download method.
|
|
100
|
+
* Creates a temporary download link and triggers file download.
|
|
101
|
+
* @param data - Data to export as JSON
|
|
102
|
+
* @param filename - Name for the downloaded file
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
function exportAsJson(data, filename) {
|
|
106
|
+
const json = JSON.stringify(data, null, 2);
|
|
107
|
+
const blob = new Blob([json], { type: 'application/json' });
|
|
108
|
+
const url = URL.createObjectURL(blob);
|
|
109
|
+
const a = document.createElement('a');
|
|
110
|
+
a.href = url;
|
|
111
|
+
a.download = filename;
|
|
112
|
+
document.body.appendChild(a);
|
|
113
|
+
a.click();
|
|
114
|
+
document.body.removeChild(a);
|
|
115
|
+
URL.revokeObjectURL(url);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Export data using File System Access API with fallback to blob download.
|
|
119
|
+
* @param data - Data to export as JSON
|
|
120
|
+
* @param suggestedName - Suggested filename for the save dialog
|
|
121
|
+
* @param description - Description for file type filter (default: 'JSON files')
|
|
122
|
+
* @param window - Window object for API access (default: globalThis.window)
|
|
123
|
+
* @returns Promise resolving to true if saved via File System Access API, false if fallback used
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
async function exportUsingFileSystemAPI(data, suggestedName, description = 'JSON files', window = globalThis.window) {
|
|
127
|
+
if (!supportsFileSystemAccess(window)) {
|
|
128
|
+
// Fallback to blob download
|
|
129
|
+
exportAsJson(data, suggestedName);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const fileHandle = await safeShowSaveFilePicker(window, {
|
|
134
|
+
suggestedName,
|
|
135
|
+
types: [
|
|
136
|
+
{
|
|
137
|
+
description,
|
|
138
|
+
accept: {
|
|
139
|
+
'application/json': ['.json']
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
if (!fileHandle) {
|
|
145
|
+
// User cancelled - fallback to blob download
|
|
146
|
+
exportAsJson(data, suggestedName);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const json = JSON.stringify(data, null, 2);
|
|
150
|
+
const writable = await fileHandle.createWritable();
|
|
151
|
+
await writable.write(json);
|
|
152
|
+
await writable.close();
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
// Handle errors by falling back to blob download
|
|
157
|
+
if (error.name === 'AbortError') {
|
|
158
|
+
// User cancelled - fallback
|
|
159
|
+
exportAsJson(data, suggestedName);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
// Other errors - re-throw as they indicate a real problem
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/file-api-types/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AA4KH,4DAEC;AAQD,oCAEC;AAQD,8CAEC;AASD,wDAQC;AASD,wDAQC;AASD,0DAQC;AASD,oCAYC;AAWD,4DA+CC;AA9JD;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,MAAc;IACrD,OAAO,oBAAoB,IAAI,MAAM,IAAI,oBAAoB,IAAI,MAAM,IAAI,qBAAqB,IAAI,MAAM,CAAC;AAC7G,CAAC;AAED;;;;;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AO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iDAAiD;QACjD,IAAK,KAAe,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC3C,4BAA4B;YAC5B,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,0DAA0D;QAC1D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * File System Access API type definitions and utilities for browser compatibility.\n * @packageDocumentation\n */\n\n// Local type definitions for File System Access API\n// Based on https://wicg.github.io/file-system-access/\n\n/**\n * File System Access API methods available on Window\n * @public\n */\nexport interface IFsAccessApis {\n showDirectoryPicker(options?: ShowDirectoryPickerOptions): Promise<FileSystemDirectoryHandle>;\n showOpenFilePicker(options?: ShowOpenFilePickerOptions): Promise<FileSystemFileHandle[]>;\n showSaveFilePicker(options?: ShowSaveFilePickerOptions): Promise<FileSystemFileHandle>;\n}\n\n/**\n * Window interface extended with File System Access API\n * @public\n */\nexport type WindowWithFsAccess = Window & IFsAccessApis;\n\n/**\n * Base interface for file system handles\n * @public\n */\nexport interface FileSystemHandle {\n readonly kind: 'file' | 'directory';\n readonly name: string;\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n queryPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;\n requestPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;\n}\n\n/**\n * File handle interface\n * @public\n */\nexport interface FileSystemFileHandle extends FileSystemHandle {\n readonly kind: 'file';\n getFile(): Promise<File>;\n createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;\n}\n\n/**\n * Directory handle interface\n * @public\n */\nexport interface FileSystemDirectoryHandle extends FileSystemHandle {\n readonly kind: 'directory';\n getDirectoryHandle(\n name: string,\n options?: FileSystemGetDirectoryOptions\n ): Promise<FileSystemDirectoryHandle>;\n getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>;\n removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<void>;\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n keys(): AsyncIterableIterator<string>;\n values(): AsyncIterableIterator<FileSystemHandle>;\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n}\n\n/**\n * Permission descriptor for file system handles\n * @public\n */\nexport interface FileSystemHandlePermissionDescriptor {\n mode?: 'read' | 'readwrite';\n}\n\n/**\n * Options for creating writable file streams\n * @public\n */\nexport interface FileSystemCreateWritableOptions {\n keepExistingData?: boolean;\n}\n\n/**\n * Options for getting directory handles\n * @public\n */\nexport interface FileSystemGetDirectoryOptions {\n create?: boolean;\n}\n\n/**\n * Options for getting file handles\n * @public\n */\nexport interface FileSystemGetFileOptions {\n create?: boolean;\n}\n\n/**\n * Options for removing entries\n * @public\n */\nexport interface FileSystemRemoveOptions {\n recursive?: boolean;\n}\n\n/**\n * Writable file stream interface\n * @public\n */\nexport interface FileSystemWritableFileStream extends WritableStream {\n write(data: BufferSource | Blob | string): Promise<void>;\n seek(position: number): Promise<void>;\n truncate(size: number): Promise<void>;\n}\n\n/**\n * Directory picker options\n * @public\n */\nexport interface ShowDirectoryPickerOptions {\n id?: string;\n mode?: 'read' | 'readwrite';\n startIn?: FileSystemHandle | WellKnownDirectory;\n}\n\n/**\n * File picker options\n * @public\n */\nexport interface ShowOpenFilePickerOptions {\n multiple?: boolean;\n excludeAcceptAllOption?: boolean;\n id?: string;\n startIn?: FileSystemHandle | WellKnownDirectory;\n types?: FilePickerAcceptType[];\n}\n\n/**\n * Save file picker options\n * @public\n */\nexport interface ShowSaveFilePickerOptions {\n excludeAcceptAllOption?: boolean;\n id?: string;\n startIn?: FileSystemHandle | WellKnownDirectory;\n suggestedName?: string;\n types?: FilePickerAcceptType[];\n}\n\n/**\n * File picker accept type\n * @public\n */\nexport interface FilePickerAcceptType {\n description?: string;\n accept: Record<string, string | string[]>;\n}\n\n/**\n * Well-known directory type\n * @public\n */\nexport type WellKnownDirectory = 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos';\n\n/**\n * Type guard to check if the browser supports the File System Access API\n * @param window - The window object to check\n * @returns True if the window supports File System Access API\n * @public\n */\nexport function supportsFileSystemAccess(window: Window): window is WindowWithFsAccess {\n return 'showOpenFilePicker' in window && 'showSaveFilePicker' in window && 'showDirectoryPicker' in window;\n}\n\n/**\n * Type guard to check if a FileSystemHandle is a file handle\n * @param handle - The handle to check\n * @returns True if the handle is a FileSystemFileHandle\n * @public\n */\nexport function isFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle {\n return handle.kind === 'file';\n}\n\n/**\n * Type guard to check if a FileSystemHandle is a directory handle\n * @param handle - The handle to check\n * @returns True if the handle is a FileSystemDirectoryHandle\n * @public\n */\nexport function isDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle {\n return handle.kind === 'directory';\n}\n\n/**\n * Safely access showOpenFilePicker with proper type checking\n * @param window - The window object\n * @param options - Options for the file picker\n * @returns Promise with file handles or null if not supported\n * @public\n */\nexport async function safeShowOpenFilePicker(\n window: Window,\n options?: ShowOpenFilePickerOptions\n): Promise<FileSystemFileHandle[] | null> {\n if (supportsFileSystemAccess(window)) {\n return window.showOpenFilePicker(options);\n }\n return null;\n}\n\n/**\n * Safely access showSaveFilePicker with proper type checking\n * @param window - The window object\n * @param options - Options for the file picker\n * @returns Promise with file handle or null if not supported\n * @public\n */\nexport async function safeShowSaveFilePicker(\n window: Window,\n options?: ShowSaveFilePickerOptions\n): Promise<FileSystemFileHandle | null> {\n if (supportsFileSystemAccess(window)) {\n return window.showSaveFilePicker(options);\n }\n return null;\n}\n\n/**\n * Safely access showDirectoryPicker with proper type checking\n * @param window - The window object\n * @param options - Options for the directory picker\n * @returns Promise with directory handle or null if not supported\n * @public\n */\nexport async function safeShowDirectoryPicker(\n window: Window,\n options?: ShowDirectoryPickerOptions\n): Promise<FileSystemDirectoryHandle | null> {\n if (supportsFileSystemAccess(window)) {\n return window.showDirectoryPicker(options);\n }\n return null;\n}\n\n/**\n * Export data as JSON file using legacy blob download method.\n * Creates a temporary download link and triggers file download.\n * @param data - Data to export as JSON\n * @param filename - Name for the downloaded file\n * @public\n */\nexport function exportAsJson(data: unknown, filename: string): void {\n const json = JSON.stringify(data, null, 2);\n const blob = new Blob([json], { type: 'application/json' });\n const url = URL.createObjectURL(blob);\n\n const a = document.createElement('a');\n a.href = url;\n a.download = filename;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n}\n\n/**\n * Export data using File System Access API with fallback to blob download.\n * @param data - Data to export as JSON\n * @param suggestedName - Suggested filename for the save dialog\n * @param description - Description for file type filter (default: 'JSON files')\n * @param window - Window object for API access (default: globalThis.window)\n * @returns Promise resolving to true if saved via File System Access API, false if fallback used\n * @public\n */\nexport async function exportUsingFileSystemAPI(\n data: unknown,\n suggestedName: string,\n description: string = 'JSON files',\n window: Window = globalThis.window\n): Promise<boolean> {\n if (!supportsFileSystemAccess(window)) {\n // Fallback to blob download\n exportAsJson(data, suggestedName);\n return false;\n }\n\n try {\n const fileHandle = await safeShowSaveFilePicker(window, {\n suggestedName,\n types: [\n {\n description,\n accept: {\n 'application/json': ['.json']\n }\n }\n ]\n });\n\n if (!fileHandle) {\n // User cancelled - fallback to blob download\n exportAsJson(data, suggestedName);\n return false;\n }\n\n const json = JSON.stringify(data, null, 2);\n const writable = await fileHandle.createWritable();\n await writable.write(json);\n await writable.close();\n\n return true;\n } catch (error) {\n // Handle errors by falling back to blob download\n if ((error as Error).name === 'AbortError') {\n // User cancelled - fallback\n exportAsJson(data, suggestedName);\n return false;\n }\n // Other errors - re-throw as they indicate a real problem\n throw error;\n }\n}\n"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { FileTree } from '@fgv/ts-json-base';
|
|
3
|
+
import { FileSystemFileHandle, FileSystemDirectoryHandle } from '../file-api-types';
|
|
4
|
+
/**
|
|
5
|
+
* Tree initializer for FileList objects (from File API).
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface IFileListTreeInitializer {
|
|
9
|
+
readonly fileList: FileList;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Tree initializer for File System Access API file handles.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export interface IFileHandleTreeInitializer {
|
|
16
|
+
readonly prefix?: string;
|
|
17
|
+
readonly fileHandles: FileSystemFileHandle[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tree initializer for File System Access API directory handles.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface IDirectoryHandleTreeInitializer {
|
|
24
|
+
readonly prefix?: string;
|
|
25
|
+
readonly dirHandles: FileSystemDirectoryHandle[];
|
|
26
|
+
readonly nonRecursive?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Union type for all supported tree initializers.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export type TreeInitializer = IFileListTreeInitializer | IFileHandleTreeInitializer | IDirectoryHandleTreeInitializer;
|
|
33
|
+
/**
|
|
34
|
+
* Interface for file metadata.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface IFileMetadata {
|
|
38
|
+
path: string;
|
|
39
|
+
name: string;
|
|
40
|
+
size: number;
|
|
41
|
+
type: string;
|
|
42
|
+
lastModified: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper class to create FileTree instances from various file sources.
|
|
46
|
+
* Supports File API (FileList) and File System Access API handles.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare class FileApiTreeAccessors<TCT extends string = string> {
|
|
50
|
+
/**
|
|
51
|
+
* Create FileTree from various file sources using TreeInitializer array.
|
|
52
|
+
* @param initializers - Array of TreeInitializer objects specifying file sources
|
|
53
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
54
|
+
* @returns Promise resolving to a FileTree with all content pre-loaded
|
|
55
|
+
*/
|
|
56
|
+
static create<TCT extends string = string>(initializers: TreeInitializer[], params?: FileTree.IFileTreeInitParams<TCT>): Promise<Result<FileTree.FileTree<TCT>>>;
|
|
57
|
+
/**
|
|
58
|
+
* Create FileTree from FileList (e.g., from input[type="file"]).
|
|
59
|
+
* @param fileList - FileList from a file input element
|
|
60
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
61
|
+
* @returns Promise resolving to a FileTree with all content pre-loaded
|
|
62
|
+
*/
|
|
63
|
+
static fromFileList<TCT extends string = string>(fileList: FileList, params?: FileTree.IFileTreeInitParams<TCT>): Promise<Result<FileTree.FileTree<TCT>>>;
|
|
64
|
+
/**
|
|
65
|
+
* Create FileTree from directory upload with webkitRelativePath.
|
|
66
|
+
* @param fileList - FileList from a directory upload (input with webkitdirectory)
|
|
67
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
68
|
+
* @returns Promise resolving to a FileTree with all content pre-loaded
|
|
69
|
+
*/
|
|
70
|
+
static fromDirectoryUpload<TCT extends string = string>(fileList: FileList, params?: FileTree.IFileTreeInitParams<TCT>): Promise<Result<FileTree.FileTree<TCT>>>;
|
|
71
|
+
/**
|
|
72
|
+
* Get the File object for a specific path from the original FileList.
|
|
73
|
+
* This is useful for accessing the original File API object for operations
|
|
74
|
+
* like getting file metadata, MIME type, etc.
|
|
75
|
+
* @param fileList - The original FileList
|
|
76
|
+
* @param targetPath - The path to find
|
|
77
|
+
* @returns Result containing the File object if found
|
|
78
|
+
*/
|
|
79
|
+
static getOriginalFile(fileList: FileList, targetPath: string): Result<File>;
|
|
80
|
+
/**
|
|
81
|
+
* Extract file metadata from a File.
|
|
82
|
+
* @param fileList - The File to extract metadata from
|
|
83
|
+
* @returns The {@link IFileMetadata | file metadata}
|
|
84
|
+
*/
|
|
85
|
+
static extractFileMetadata(file: File): IFileMetadata;
|
|
86
|
+
/**
|
|
87
|
+
* Process a single TreeInitializer and return the resulting files.
|
|
88
|
+
* @param initializer - The TreeInitializer to process
|
|
89
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
90
|
+
* @returns Promise resolving to an array of `IInMemoryFile` objects
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
private static _processInitializer;
|
|
94
|
+
/**
|
|
95
|
+
* Process a FileList and return IInMemoryFile array.
|
|
96
|
+
* @param fileList - The FileList to process
|
|
97
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
98
|
+
* @returns Promise resolving to an array of `IInMemoryFile` objects
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
private static _processFileList;
|
|
102
|
+
/**
|
|
103
|
+
* Process FileSystemFileHandles and return IInMemoryFile array.
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
private static _processFileHandles;
|
|
107
|
+
/**
|
|
108
|
+
* Process FileSystemDirectoryHandles and return IInMemoryFile array.
|
|
109
|
+
* @param handles - The FileSystemDirectoryHandle[] to process
|
|
110
|
+
* @param prefix - The prefix to use for the file paths
|
|
111
|
+
* @param recursive - Whether to process the directory recursively
|
|
112
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
113
|
+
* @returns Promise resolving to an array of `IInMemoryFile` objects
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
private static _processDirectoryHandles;
|
|
117
|
+
/**
|
|
118
|
+
* Process a single FileSystemDirectoryHandle recursively.
|
|
119
|
+
* @param handle - The FileSystemDirectoryHandle to process
|
|
120
|
+
* @param basePath - The base path to use for the file paths
|
|
121
|
+
* @param recursive - Whether to process the directory recursively
|
|
122
|
+
* @param params - Optional `IFileTreeInitParams` for the file tree.
|
|
123
|
+
* @returns Promise resolving to an array of `IInMemoryFile` objects
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
private static _processDirectoryHandle;
|
|
127
|
+
private static _normalizePath;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=fileApiTreeAccessors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileApiTreeAccessors.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileApiTreeAccessors.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAGL,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAmB3B;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WA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