@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,345 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* File System Access API type definitions and utilities for browser compatibility.
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
// Local type definitions for File System Access API
|
|
29
|
+
// Based on https://wicg.github.io/file-system-access/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* File System Access API methods available on Window
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export interface IFsAccessApis {
|
|
36
|
+
showDirectoryPicker(options?: ShowDirectoryPickerOptions): Promise<FileSystemDirectoryHandle>;
|
|
37
|
+
showOpenFilePicker(options?: ShowOpenFilePickerOptions): Promise<FileSystemFileHandle[]>;
|
|
38
|
+
showSaveFilePicker(options?: ShowSaveFilePickerOptions): Promise<FileSystemFileHandle>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Window interface extended with File System Access API
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export type WindowWithFsAccess = Window & IFsAccessApis;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Base interface for file system handles
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export interface FileSystemHandle {
|
|
52
|
+
readonly kind: 'file' | 'directory';
|
|
53
|
+
readonly name: string;
|
|
54
|
+
isSameEntry(other: FileSystemHandle): Promise<boolean>;
|
|
55
|
+
queryPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;
|
|
56
|
+
requestPermission(descriptor?: FileSystemHandlePermissionDescriptor): Promise<PermissionState>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* File handle interface
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export interface FileSystemFileHandle extends FileSystemHandle {
|
|
64
|
+
readonly kind: 'file';
|
|
65
|
+
getFile(): Promise<File>;
|
|
66
|
+
createWritable(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Directory handle interface
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
export interface FileSystemDirectoryHandle extends FileSystemHandle {
|
|
74
|
+
readonly kind: 'directory';
|
|
75
|
+
getDirectoryHandle(
|
|
76
|
+
name: string,
|
|
77
|
+
options?: FileSystemGetDirectoryOptions
|
|
78
|
+
): Promise<FileSystemDirectoryHandle>;
|
|
79
|
+
getFileHandle(name: string, options?: FileSystemGetFileOptions): Promise<FileSystemFileHandle>;
|
|
80
|
+
removeEntry(name: string, options?: FileSystemRemoveOptions): Promise<void>;
|
|
81
|
+
resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;
|
|
82
|
+
keys(): AsyncIterableIterator<string>;
|
|
83
|
+
values(): AsyncIterableIterator<FileSystemHandle>;
|
|
84
|
+
entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
85
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Permission descriptor for file system handles
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export interface FileSystemHandlePermissionDescriptor {
|
|
93
|
+
mode?: 'read' | 'readwrite';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Options for creating writable file streams
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export interface FileSystemCreateWritableOptions {
|
|
101
|
+
keepExistingData?: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Options for getting directory handles
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export interface FileSystemGetDirectoryOptions {
|
|
109
|
+
create?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Options for getting file handles
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
export interface FileSystemGetFileOptions {
|
|
117
|
+
create?: boolean;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Options for removing entries
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
export interface FileSystemRemoveOptions {
|
|
125
|
+
recursive?: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Writable file stream interface
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
export interface FileSystemWritableFileStream extends WritableStream {
|
|
133
|
+
write(data: BufferSource | Blob | string): Promise<void>;
|
|
134
|
+
seek(position: number): Promise<void>;
|
|
135
|
+
truncate(size: number): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Directory picker options
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
export interface ShowDirectoryPickerOptions {
|
|
143
|
+
id?: string;
|
|
144
|
+
mode?: 'read' | 'readwrite';
|
|
145
|
+
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* File picker options
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
export interface ShowOpenFilePickerOptions {
|
|
153
|
+
multiple?: boolean;
|
|
154
|
+
excludeAcceptAllOption?: boolean;
|
|
155
|
+
id?: string;
|
|
156
|
+
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
157
|
+
types?: FilePickerAcceptType[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Save file picker options
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
export interface ShowSaveFilePickerOptions {
|
|
165
|
+
excludeAcceptAllOption?: boolean;
|
|
166
|
+
id?: string;
|
|
167
|
+
startIn?: FileSystemHandle | WellKnownDirectory;
|
|
168
|
+
suggestedName?: string;
|
|
169
|
+
types?: FilePickerAcceptType[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* File picker accept type
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
export interface FilePickerAcceptType {
|
|
177
|
+
description?: string;
|
|
178
|
+
accept: Record<string, string | string[]>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Well-known directory type
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export type WellKnownDirectory = 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos';
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Type guard to check if the browser supports the File System Access API
|
|
189
|
+
* @param window - The window object to check
|
|
190
|
+
* @returns True if the window supports File System Access API
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
export function supportsFileSystemAccess(window: Window): window is WindowWithFsAccess {
|
|
194
|
+
return 'showOpenFilePicker' in window && 'showSaveFilePicker' in window && 'showDirectoryPicker' in window;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Type guard to check if a FileSystemHandle is a file handle
|
|
199
|
+
* @param handle - The handle to check
|
|
200
|
+
* @returns True if the handle is a FileSystemFileHandle
|
|
201
|
+
* @public
|
|
202
|
+
*/
|
|
203
|
+
export function isFileHandle(handle: FileSystemHandle): handle is FileSystemFileHandle {
|
|
204
|
+
return handle.kind === 'file';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Type guard to check if a FileSystemHandle is a directory handle
|
|
209
|
+
* @param handle - The handle to check
|
|
210
|
+
* @returns True if the handle is a FileSystemDirectoryHandle
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
export function isDirectoryHandle(handle: FileSystemHandle): handle is FileSystemDirectoryHandle {
|
|
214
|
+
return handle.kind === 'directory';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Safely access showOpenFilePicker with proper type checking
|
|
219
|
+
* @param window - The window object
|
|
220
|
+
* @param options - Options for the file picker
|
|
221
|
+
* @returns Promise with file handles or null if not supported
|
|
222
|
+
* @public
|
|
223
|
+
*/
|
|
224
|
+
export async function safeShowOpenFilePicker(
|
|
225
|
+
window: Window,
|
|
226
|
+
options?: ShowOpenFilePickerOptions
|
|
227
|
+
): Promise<FileSystemFileHandle[] | null> {
|
|
228
|
+
if (supportsFileSystemAccess(window)) {
|
|
229
|
+
return window.showOpenFilePicker(options);
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Safely access showSaveFilePicker with proper type checking
|
|
236
|
+
* @param window - The window object
|
|
237
|
+
* @param options - Options for the file picker
|
|
238
|
+
* @returns Promise with file handle or null if not supported
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
export async function safeShowSaveFilePicker(
|
|
242
|
+
window: Window,
|
|
243
|
+
options?: ShowSaveFilePickerOptions
|
|
244
|
+
): Promise<FileSystemFileHandle | null> {
|
|
245
|
+
if (supportsFileSystemAccess(window)) {
|
|
246
|
+
return window.showSaveFilePicker(options);
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Safely access showDirectoryPicker with proper type checking
|
|
253
|
+
* @param window - The window object
|
|
254
|
+
* @param options - Options for the directory picker
|
|
255
|
+
* @returns Promise with directory handle or null if not supported
|
|
256
|
+
* @public
|
|
257
|
+
*/
|
|
258
|
+
export async function safeShowDirectoryPicker(
|
|
259
|
+
window: Window,
|
|
260
|
+
options?: ShowDirectoryPickerOptions
|
|
261
|
+
): Promise<FileSystemDirectoryHandle | null> {
|
|
262
|
+
if (supportsFileSystemAccess(window)) {
|
|
263
|
+
return window.showDirectoryPicker(options);
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Export data as JSON file using legacy blob download method.
|
|
270
|
+
* Creates a temporary download link and triggers file download.
|
|
271
|
+
* @param data - Data to export as JSON
|
|
272
|
+
* @param filename - Name for the downloaded file
|
|
273
|
+
* @public
|
|
274
|
+
*/
|
|
275
|
+
export function exportAsJson(data: unknown, filename: string): void {
|
|
276
|
+
const json = JSON.stringify(data, null, 2);
|
|
277
|
+
const blob = new Blob([json], { type: 'application/json' });
|
|
278
|
+
const url = URL.createObjectURL(blob);
|
|
279
|
+
|
|
280
|
+
const a = document.createElement('a');
|
|
281
|
+
a.href = url;
|
|
282
|
+
a.download = filename;
|
|
283
|
+
document.body.appendChild(a);
|
|
284
|
+
a.click();
|
|
285
|
+
document.body.removeChild(a);
|
|
286
|
+
URL.revokeObjectURL(url);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Export data using File System Access API with fallback to blob download.
|
|
291
|
+
* @param data - Data to export as JSON
|
|
292
|
+
* @param suggestedName - Suggested filename for the save dialog
|
|
293
|
+
* @param description - Description for file type filter (default: 'JSON files')
|
|
294
|
+
* @param window - Window object for API access (default: globalThis.window)
|
|
295
|
+
* @returns Promise resolving to true if saved via File System Access API, false if fallback used
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
export async function exportUsingFileSystemAPI(
|
|
299
|
+
data: unknown,
|
|
300
|
+
suggestedName: string,
|
|
301
|
+
description: string = 'JSON files',
|
|
302
|
+
window: Window = globalThis.window
|
|
303
|
+
): Promise<boolean> {
|
|
304
|
+
if (!supportsFileSystemAccess(window)) {
|
|
305
|
+
// Fallback to blob download
|
|
306
|
+
exportAsJson(data, suggestedName);
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
const fileHandle = await safeShowSaveFilePicker(window, {
|
|
312
|
+
suggestedName,
|
|
313
|
+
types: [
|
|
314
|
+
{
|
|
315
|
+
description,
|
|
316
|
+
accept: {
|
|
317
|
+
'application/json': ['.json']
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
if (!fileHandle) {
|
|
324
|
+
// User cancelled - fallback to blob download
|
|
325
|
+
exportAsJson(data, suggestedName);
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const json = JSON.stringify(data, null, 2);
|
|
330
|
+
const writable = await fileHandle.createWritable();
|
|
331
|
+
await writable.write(json);
|
|
332
|
+
await writable.close();
|
|
333
|
+
|
|
334
|
+
return true;
|
|
335
|
+
} catch (error) {
|
|
336
|
+
// Handle errors by falling back to blob download
|
|
337
|
+
if ((error as Error).name === 'AbortError') {
|
|
338
|
+
// User cancelled - fallback
|
|
339
|
+
exportAsJson(data, suggestedName);
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
// Other errors - re-throw as they indicate a real problem
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
}
|