@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.
Files changed (262) hide show
  1. package/.rush/temp/86c9c1ad46e237e0b957c2442bf0355cf39babba.tar.log +121 -0
  2. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +40 -0
  3. package/.rush/temp/operation/build/all.log +40 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +40 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +624 -0
  7. package/config/api-extractor.json +343 -0
  8. package/config/jest.config.json +16 -0
  9. package/config/rig.json +16 -0
  10. package/dist/ts-web-extras.d.ts +574 -0
  11. package/dist/tsdoc-metadata.json +11 -0
  12. package/docs/index.md +34 -0
  13. package/docs/ts-web-extras.browserhashprovider.hashparts.md +88 -0
  14. package/docs/ts-web-extras.browserhashprovider.hashstring.md +72 -0
  15. package/docs/ts-web-extras.browserhashprovider.md +66 -0
  16. package/docs/ts-web-extras.exportasjson.md +70 -0
  17. package/docs/ts-web-extras.exportusingfilesystemapi.md +104 -0
  18. package/docs/ts-web-extras.extractdirectorypath.md +52 -0
  19. package/docs/ts-web-extras.fileapitreeaccessors.create.md +72 -0
  20. package/docs/ts-web-extras.fileapitreeaccessors.extractfilemetadata.md +54 -0
  21. package/docs/ts-web-extras.fileapitreeaccessors.fromdirectoryupload.md +72 -0
  22. package/docs/ts-web-extras.fileapitreeaccessors.fromfilelist.md +72 -0
  23. package/docs/ts-web-extras.fileapitreeaccessors.getoriginalfile.md +72 -0
  24. package/docs/ts-web-extras.fileapitreeaccessors.md +114 -0
  25. package/docs/ts-web-extras.filepickeraccepttype.accept.md +11 -0
  26. package/docs/ts-web-extras.filepickeraccepttype.description.md +11 -0
  27. package/docs/ts-web-extras.filepickeraccepttype.md +75 -0
  28. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.keepexistingdata.md +11 -0
  29. package/docs/ts-web-extras.filesystemcreatewritableoptions_2.md +58 -0
  30. package/docs/ts-web-extras.filesystemdirectoryhandle_2._symbol.asynciterator_.md +15 -0
  31. package/docs/ts-web-extras.filesystemdirectoryhandle_2.entries.md +15 -0
  32. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getdirectoryhandle.md +66 -0
  33. package/docs/ts-web-extras.filesystemdirectoryhandle_2.getfilehandle.md +66 -0
  34. package/docs/ts-web-extras.filesystemdirectoryhandle_2.keys.md +15 -0
  35. package/docs/ts-web-extras.filesystemdirectoryhandle_2.kind.md +11 -0
  36. package/docs/ts-web-extras.filesystemdirectoryhandle_2.md +146 -0
  37. package/docs/ts-web-extras.filesystemdirectoryhandle_2.removeentry.md +66 -0
  38. package/docs/ts-web-extras.filesystemdirectoryhandle_2.resolve.md +50 -0
  39. package/docs/ts-web-extras.filesystemdirectoryhandle_2.values.md +15 -0
  40. package/docs/ts-web-extras.filesystemfilehandle_2.createwritable.md +52 -0
  41. package/docs/ts-web-extras.filesystemfilehandle_2.getfile.md +15 -0
  42. package/docs/ts-web-extras.filesystemfilehandle_2.kind.md +11 -0
  43. package/docs/ts-web-extras.filesystemfilehandle_2.md +92 -0
  44. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.create.md +11 -0
  45. package/docs/ts-web-extras.filesystemgetdirectoryoptions_2.md +58 -0
  46. package/docs/ts-web-extras.filesystemgetfileoptions_2.create.md +11 -0
  47. package/docs/ts-web-extras.filesystemgetfileoptions_2.md +58 -0
  48. package/docs/ts-web-extras.filesystemhandle_2.issameentry.md +50 -0
  49. package/docs/ts-web-extras.filesystemhandle_2.kind.md +11 -0
  50. package/docs/ts-web-extras.filesystemhandle_2.md +119 -0
  51. package/docs/ts-web-extras.filesystemhandle_2.name.md +11 -0
  52. package/docs/ts-web-extras.filesystemhandle_2.querypermission.md +52 -0
  53. package/docs/ts-web-extras.filesystemhandle_2.requestpermission.md +52 -0
  54. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.md +58 -0
  55. package/docs/ts-web-extras.filesystemhandlepermissiondescriptor.mode.md +11 -0
  56. package/docs/ts-web-extras.filesystemremoveoptions_2.md +58 -0
  57. package/docs/ts-web-extras.filesystemremoveoptions_2.recursive.md +11 -0
  58. package/docs/ts-web-extras.filesystemwritablefilestream_2.md +57 -0
  59. package/docs/ts-web-extras.filesystemwritablefilestream_2.seek.md +50 -0
  60. package/docs/ts-web-extras.filesystemwritablefilestream_2.truncate.md +50 -0
  61. package/docs/ts-web-extras.filesystemwritablefilestream_2.write.md +50 -0
  62. package/docs/ts-web-extras.filetreehelpers.defaultfileapitreeinitparams.md +13 -0
  63. package/docs/ts-web-extras.filetreehelpers.extractfilelistmetadata.md +56 -0
  64. package/docs/ts-web-extras.filetreehelpers.extractfilemetadata.md +56 -0
  65. package/docs/ts-web-extras.filetreehelpers.fromdirectoryupload.md +76 -0
  66. package/docs/ts-web-extras.filetreehelpers.fromfilelist.md +76 -0
  67. package/docs/ts-web-extras.filetreehelpers.getoriginalfile.md +72 -0
  68. package/docs/ts-web-extras.filetreehelpers.md +102 -0
  69. package/docs/ts-web-extras.idirectoryhandletreeinitializer.dirhandles.md +11 -0
  70. package/docs/ts-web-extras.idirectoryhandletreeinitializer.md +100 -0
  71. package/docs/ts-web-extras.idirectoryhandletreeinitializer.nonrecursive.md +11 -0
  72. package/docs/ts-web-extras.idirectoryhandletreeinitializer.prefix.md +11 -0
  73. package/docs/ts-web-extras.ifilehandletreeinitializer.filehandles.md +11 -0
  74. package/docs/ts-web-extras.ifilehandletreeinitializer.md +79 -0
  75. package/docs/ts-web-extras.ifilehandletreeinitializer.prefix.md +11 -0
  76. package/docs/ts-web-extras.ifilelisttreeinitializer.filelist.md +11 -0
  77. package/docs/ts-web-extras.ifilelisttreeinitializer.md +58 -0
  78. package/docs/ts-web-extras.ifilemetadata.lastmodified.md +11 -0
  79. package/docs/ts-web-extras.ifilemetadata.md +124 -0
  80. package/docs/ts-web-extras.ifilemetadata.name.md +11 -0
  81. package/docs/ts-web-extras.ifilemetadata.path.md +11 -0
  82. package/docs/ts-web-extras.ifilemetadata.size.md +11 -0
  83. package/docs/ts-web-extras.ifilemetadata.type.md +11 -0
  84. package/docs/ts-web-extras.ifsaccessapis.md +56 -0
  85. package/docs/ts-web-extras.ifsaccessapis.showdirectorypicker.md +52 -0
  86. package/docs/ts-web-extras.ifsaccessapis.showopenfilepicker.md +52 -0
  87. package/docs/ts-web-extras.ifsaccessapis.showsavefilepicker.md +52 -0
  88. package/docs/ts-web-extras.isdirectoryhandle.md +56 -0
  89. package/docs/ts-web-extras.isfilehandle.md +56 -0
  90. package/docs/ts-web-extras.isfilepath.md +52 -0
  91. package/docs/ts-web-extras.iurlconfigoptions.config.md +13 -0
  92. package/docs/ts-web-extras.iurlconfigoptions.configstartdir.md +13 -0
  93. package/docs/ts-web-extras.iurlconfigoptions.contextfilter.md +13 -0
  94. package/docs/ts-web-extras.iurlconfigoptions.input.md +13 -0
  95. package/docs/ts-web-extras.iurlconfigoptions.inputstartdir.md +13 -0
  96. package/docs/ts-web-extras.iurlconfigoptions.interactive.md +13 -0
  97. package/docs/ts-web-extras.iurlconfigoptions.loadzip.md +13 -0
  98. package/docs/ts-web-extras.iurlconfigoptions.maxdistance.md +13 -0
  99. package/docs/ts-web-extras.iurlconfigoptions.md +286 -0
  100. package/docs/ts-web-extras.iurlconfigoptions.qualifierdefaults.md +13 -0
  101. package/docs/ts-web-extras.iurlconfigoptions.reducequalifiers.md +13 -0
  102. package/docs/ts-web-extras.iurlconfigoptions.resourcetypes.md +13 -0
  103. package/docs/ts-web-extras.iurlconfigoptions.zipfile.md +13 -0
  104. package/docs/ts-web-extras.iurlconfigoptions.zippath.md +13 -0
  105. package/docs/ts-web-extras.md +512 -0
  106. package/docs/ts-web-extras.parsecontextfilter.md +52 -0
  107. package/docs/ts-web-extras.parsequalifierdefaults.md +52 -0
  108. package/docs/ts-web-extras.parseresourcetypes.md +52 -0
  109. package/docs/ts-web-extras.parseurlparameters.md +17 -0
  110. package/docs/ts-web-extras.safeshowdirectorypicker.md +72 -0
  111. package/docs/ts-web-extras.safeshowopenfilepicker.md +72 -0
  112. package/docs/ts-web-extras.safeshowsavefilepicker.md +72 -0
  113. package/docs/ts-web-extras.showdirectorypickeroptions.id.md +11 -0
  114. package/docs/ts-web-extras.showdirectorypickeroptions.md +96 -0
  115. package/docs/ts-web-extras.showdirectorypickeroptions.mode.md +11 -0
  116. package/docs/ts-web-extras.showdirectorypickeroptions.startin.md +11 -0
  117. package/docs/ts-web-extras.showopenfilepickeroptions.excludeacceptalloption.md +11 -0
  118. package/docs/ts-web-extras.showopenfilepickeroptions.id.md +11 -0
  119. package/docs/ts-web-extras.showopenfilepickeroptions.md +134 -0
  120. package/docs/ts-web-extras.showopenfilepickeroptions.multiple.md +11 -0
  121. package/docs/ts-web-extras.showopenfilepickeroptions.startin.md +11 -0
  122. package/docs/ts-web-extras.showopenfilepickeroptions.types.md +11 -0
  123. package/docs/ts-web-extras.showsavefilepickeroptions.excludeacceptalloption.md +11 -0
  124. package/docs/ts-web-extras.showsavefilepickeroptions.id.md +11 -0
  125. package/docs/ts-web-extras.showsavefilepickeroptions.md +134 -0
  126. package/docs/ts-web-extras.showsavefilepickeroptions.startin.md +11 -0
  127. package/docs/ts-web-extras.showsavefilepickeroptions.suggestedname.md +11 -0
  128. package/docs/ts-web-extras.showsavefilepickeroptions.types.md +11 -0
  129. package/docs/ts-web-extras.supportsfilesystemaccess.md +56 -0
  130. package/docs/ts-web-extras.treeinitializer.md +15 -0
  131. package/docs/ts-web-extras.wellknowndirectory.md +13 -0
  132. package/docs/ts-web-extras.windowwithfsaccess.md +15 -0
  133. package/etc/ts-web-extras.api.md +310 -0
  134. package/lib/index.d.ts +16 -0
  135. package/lib/index.d.ts.map +1 -0
  136. package/lib/index.js +58 -0
  137. package/lib/index.js.map +1 -0
  138. package/lib/packlets/crypto/browserHashProvider.d.ts +24 -0
  139. package/lib/packlets/crypto/browserHashProvider.d.ts.map +1 -0
  140. package/lib/packlets/crypto/browserHashProvider.js +70 -0
  141. package/lib/packlets/crypto/browserHashProvider.js.map +1 -0
  142. package/lib/packlets/crypto/index.d.ts +6 -0
  143. package/lib/packlets/crypto/index.d.ts.map +1 -0
  144. package/lib/packlets/crypto/index.js +43 -0
  145. package/lib/packlets/crypto/index.js.map +1 -0
  146. package/lib/packlets/file-api-types/index.d.ts +205 -0
  147. package/lib/packlets/file-api-types/index.d.ts.map +1 -0
  148. package/lib/packlets/file-api-types/index.js +166 -0
  149. package/lib/packlets/file-api-types/index.js.map +1 -0
  150. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +129 -0
  151. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -0
  152. package/lib/packlets/file-tree/fileApiTreeAccessors.js +334 -0
  153. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -0
  154. package/lib/packlets/file-tree/index.d.ts +6 -0
  155. package/lib/packlets/file-tree/index.d.ts.map +1 -0
  156. package/lib/packlets/file-tree/index.js +43 -0
  157. package/lib/packlets/file-tree/index.js.map +1 -0
  158. package/lib/packlets/helpers/fileTreeHelpers.d.ts +60 -0
  159. package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -0
  160. package/lib/packlets/helpers/fileTreeHelpers.js +102 -0
  161. package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -0
  162. package/lib/packlets/helpers/index.d.ts +6 -0
  163. package/lib/packlets/helpers/index.d.ts.map +1 -0
  164. package/lib/packlets/helpers/index.js +63 -0
  165. package/lib/packlets/helpers/index.js.map +1 -0
  166. package/lib/packlets/url-utils/index.d.ts +6 -0
  167. package/lib/packlets/url-utils/index.d.ts.map +1 -0
  168. package/lib/packlets/url-utils/index.js +43 -0
  169. package/lib/packlets/url-utils/index.js.map +1 -0
  170. package/lib/packlets/url-utils/urlParams.d.ts +94 -0
  171. package/lib/packlets/url-utils/urlParams.d.ts.map +1 -0
  172. package/lib/packlets/url-utils/urlParams.js +165 -0
  173. package/lib/packlets/url-utils/urlParams.js.map +1 -0
  174. package/lib/test/setupTests.d.ts +2 -0
  175. package/lib/test/setupTests.d.ts.map +1 -0
  176. package/lib/test/setupTests.js +76 -0
  177. package/lib/test/setupTests.js.map +1 -0
  178. package/lib/test/unit/browserHashProvider.test.d.ts +2 -0
  179. package/lib/test/unit/browserHashProvider.test.d.ts.map +1 -0
  180. package/lib/test/unit/browserHashProvider.test.js +142 -0
  181. package/lib/test/unit/browserHashProvider.test.js.map +1 -0
  182. package/lib/test/unit/fileApiTreeAccessors.test.d.ts +2 -0
  183. package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +1 -0
  184. package/lib/test/unit/fileApiTreeAccessors.test.js +1139 -0
  185. package/lib/test/unit/fileApiTreeAccessors.test.js.map +1 -0
  186. package/lib/test/unit/fileApiTypes.test.d.ts +2 -0
  187. package/lib/test/unit/fileApiTypes.test.d.ts.map +1 -0
  188. package/lib/test/unit/fileApiTypes.test.js +444 -0
  189. package/lib/test/unit/fileApiTypes.test.js.map +1 -0
  190. package/lib/test/unit/fileTreeHelpers.test.d.ts +2 -0
  191. package/lib/test/unit/fileTreeHelpers.test.d.ts.map +1 -0
  192. package/lib/test/unit/fileTreeHelpers.test.js +592 -0
  193. package/lib/test/unit/fileTreeHelpers.test.js.map +1 -0
  194. package/lib/test/unit/urlParams.test.d.ts +2 -0
  195. package/lib/test/unit/urlParams.test.d.ts.map +1 -0
  196. package/lib/test/unit/urlParams.test.js +395 -0
  197. package/lib/test/unit/urlParams.test.js.map +1 -0
  198. package/lib/test/utils/testHelpers.d.ts +51 -0
  199. package/lib/test/utils/testHelpers.d.ts.map +1 -0
  200. package/lib/test/utils/testHelpers.js +133 -0
  201. package/lib/test/utils/testHelpers.js.map +1 -0
  202. package/package.json +68 -0
  203. package/rush-logs/ts-web-extras.build.cache.log +3 -0
  204. package/rush-logs/ts-web-extras.build.log +40 -0
  205. package/src/index.ts +47 -0
  206. package/src/packlets/crypto/browserHashProvider.ts +73 -0
  207. package/src/packlets/crypto/index.ts +28 -0
  208. package/src/packlets/file-api-types/index.ts +345 -0
  209. package/src/packlets/file-tree/fileApiTreeAccessors.ts +420 -0
  210. package/src/packlets/file-tree/index.ts +28 -0
  211. package/src/packlets/helpers/fileTreeHelpers.ts +107 -0
  212. package/src/packlets/helpers/index.ts +28 -0
  213. package/src/packlets/url-utils/index.ts +28 -0
  214. package/src/packlets/url-utils/urlParams.ts +245 -0
  215. package/src/test/setupTests.ts +87 -0
  216. package/src/test/unit/browserHashProvider.test.ts +155 -0
  217. package/src/test/unit/browserHashProvider.test.ts.bak +376 -0
  218. package/src/test/unit/fileApiTreeAccessors.test.ts +1318 -0
  219. package/src/test/unit/fileApiTypes.test.ts +551 -0
  220. package/src/test/unit/fileTreeHelpers.test.ts +694 -0
  221. package/src/test/unit/urlParams.test.ts +464 -0
  222. package/src/test/utils/testHelpers.ts +155 -0
  223. package/temp/build/typescript/ts_l9Fw4VUO.json +1 -0
  224. package/temp/coverage/base.css +224 -0
  225. package/temp/coverage/block-navigation.js +87 -0
  226. package/temp/coverage/crypto/browserHashProvider.ts.html +304 -0
  227. package/temp/coverage/crypto/index.html +116 -0
  228. package/temp/coverage/favicon.png +0 -0
  229. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1345 -0
  230. package/temp/coverage/file-tree/index.html +116 -0
  231. package/temp/coverage/helpers/fileTreeHelpers.ts.html +406 -0
  232. package/temp/coverage/helpers/index.html +116 -0
  233. package/temp/coverage/index.html +161 -0
  234. package/temp/coverage/lcov-report/base.css +224 -0
  235. package/temp/coverage/lcov-report/block-navigation.js +87 -0
  236. package/temp/coverage/lcov-report/crypto/browserHashProvider.ts.html +304 -0
  237. package/temp/coverage/lcov-report/crypto/index.html +116 -0
  238. package/temp/coverage/lcov-report/favicon.png +0 -0
  239. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1345 -0
  240. package/temp/coverage/lcov-report/file-tree/index.html +116 -0
  241. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +406 -0
  242. package/temp/coverage/lcov-report/helpers/index.html +116 -0
  243. package/temp/coverage/lcov-report/index.html +161 -0
  244. package/temp/coverage/lcov-report/prettify.css +1 -0
  245. package/temp/coverage/lcov-report/prettify.js +2 -0
  246. package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  247. package/temp/coverage/lcov-report/sorter.js +210 -0
  248. package/temp/coverage/lcov-report/url-utils/index.html +116 -0
  249. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +820 -0
  250. package/temp/coverage/lcov.info +1096 -0
  251. package/temp/coverage/prettify.css +1 -0
  252. package/temp/coverage/prettify.js +2 -0
  253. package/temp/coverage/sort-arrow-sprite.png +0 -0
  254. package/temp/coverage/sorter.js +210 -0
  255. package/temp/coverage/url-utils/index.html +116 -0
  256. package/temp/coverage/url-utils/urlParams.ts.html +820 -0
  257. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  258. package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/63/package_63a8257b0e4d0e7ff33f927d75f27a75 +53 -0
  259. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -0
  260. package/temp/ts-web-extras.api.json +5040 -0
  261. package/temp/ts-web-extras.api.md +310 -0
  262. 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
+ }