@capgo/capacitor-file-sharer 8.1.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/CapgoCapacitorFileSharer.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +238 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/java/app/capgo/filesharer/FileSharer.java +68 -0
- package/android/src/main/java/app/capgo/filesharer/FileSharerPlugin.java +413 -0
- package/android/src/main/java/app/capgo/filesharer/FileSharerProvider.java +5 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/android/src/main/res/xml/sharing_paths.xml +4 -0
- package/dist/docs.json +237 -0
- package/dist/esm/definitions.d.ts +100 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +10 -0
- package/dist/esm/web.js +93 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +107 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +110 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/FileSharerPlugin/FileSharer.swift +51 -0
- package/ios/Sources/FileSharerPlugin/FileSharerPlugin.swift +140 -0
- package/ios/Tests/FileSharerPluginTests/FileSharerTests.swift +24 -0
- package/package.json +89 -0
package/dist/docs.json
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "FileSharerPlugin",
|
|
4
|
+
"slug": "filesharerplugin",
|
|
5
|
+
"docs": "Capacitor File Sharer plugin.",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "share",
|
|
10
|
+
"signature": "(options: ShareFileOptions) => Promise<void>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "ShareFileOptions"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<void>",
|
|
19
|
+
"tags": [],
|
|
20
|
+
"docs": "Share a file using the native share sheet on Android and iOS.\nOn web, this downloads the file because browsers do not expose a consistent native file share target.",
|
|
21
|
+
"complexTypes": [
|
|
22
|
+
"ShareFileOptions"
|
|
23
|
+
],
|
|
24
|
+
"slug": "share"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "save",
|
|
28
|
+
"signature": "(options: SaveFileOptions) => Promise<SaveFileResult>",
|
|
29
|
+
"parameters": [
|
|
30
|
+
{
|
|
31
|
+
"name": "options",
|
|
32
|
+
"docs": "",
|
|
33
|
+
"type": "ShareFileOptions"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"returns": "Promise<SaveFileResult>",
|
|
37
|
+
"tags": [],
|
|
38
|
+
"docs": "Save a file locally.\nOn Android this writes to MediaStore/Downloads. On web this downloads the file.\nOn iOS this opens the share sheet so the user can choose Save to Files or another target.",
|
|
39
|
+
"complexTypes": [
|
|
40
|
+
"SaveFileResult",
|
|
41
|
+
"SaveFileOptions"
|
|
42
|
+
],
|
|
43
|
+
"slug": "save"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "getPluginVersion",
|
|
47
|
+
"signature": "() => Promise<PluginVersionResult>",
|
|
48
|
+
"parameters": [],
|
|
49
|
+
"returns": "Promise<PluginVersionResult>",
|
|
50
|
+
"tags": [],
|
|
51
|
+
"docs": "Returns the platform implementation version marker.",
|
|
52
|
+
"complexTypes": [
|
|
53
|
+
"PluginVersionResult"
|
|
54
|
+
],
|
|
55
|
+
"slug": "getpluginversion"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"properties": []
|
|
59
|
+
},
|
|
60
|
+
"interfaces": [
|
|
61
|
+
{
|
|
62
|
+
"name": "ShareFileOptions",
|
|
63
|
+
"slug": "sharefileoptions",
|
|
64
|
+
"docs": "Options used to share a file.",
|
|
65
|
+
"tags": [],
|
|
66
|
+
"methods": [],
|
|
67
|
+
"properties": [
|
|
68
|
+
{
|
|
69
|
+
"name": "filename",
|
|
70
|
+
"tags": [],
|
|
71
|
+
"docs": "File name presented to the receiving app. Include the extension.",
|
|
72
|
+
"complexTypes": [],
|
|
73
|
+
"type": "string"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "base64Data",
|
|
77
|
+
"tags": [],
|
|
78
|
+
"docs": "Base64 encoded file data. Data URL prefixes are accepted.",
|
|
79
|
+
"complexTypes": [],
|
|
80
|
+
"type": "string | undefined"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "path",
|
|
84
|
+
"tags": [],
|
|
85
|
+
"docs": "Local file path, file:// URL, content:// URL, or Capacitor _capacitor_file_ URL.",
|
|
86
|
+
"complexTypes": [],
|
|
87
|
+
"type": "string | undefined"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name": "contentType",
|
|
91
|
+
"tags": [],
|
|
92
|
+
"docs": "MIME type of the file. Defaults to application/octet-stream when omitted.",
|
|
93
|
+
"complexTypes": [],
|
|
94
|
+
"type": "string | undefined"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "text",
|
|
98
|
+
"tags": [],
|
|
99
|
+
"docs": "Optional text or caption shared with the file.",
|
|
100
|
+
"complexTypes": [],
|
|
101
|
+
"type": "string | undefined"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"name": "title",
|
|
105
|
+
"tags": [],
|
|
106
|
+
"docs": "Optional title for the share sheet or shared item.",
|
|
107
|
+
"complexTypes": [],
|
|
108
|
+
"type": "string | undefined"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "subject",
|
|
112
|
+
"tags": [],
|
|
113
|
+
"docs": "Optional subject used by mail and compatible share targets.",
|
|
114
|
+
"complexTypes": [],
|
|
115
|
+
"type": "string | undefined"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "android",
|
|
119
|
+
"tags": [],
|
|
120
|
+
"docs": "Android-specific options.",
|
|
121
|
+
"complexTypes": [
|
|
122
|
+
"AndroidFileSharerOptions"
|
|
123
|
+
],
|
|
124
|
+
"type": "AndroidFileSharerOptions"
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "AndroidFileSharerOptions",
|
|
130
|
+
"slug": "androidfileshareroptions",
|
|
131
|
+
"docs": "Android-specific behavior for file sharing and saving.",
|
|
132
|
+
"tags": [],
|
|
133
|
+
"methods": [],
|
|
134
|
+
"properties": [
|
|
135
|
+
{
|
|
136
|
+
"name": "chooserTitle",
|
|
137
|
+
"tags": [],
|
|
138
|
+
"docs": "Title shown at the top of the Android chooser.",
|
|
139
|
+
"complexTypes": [],
|
|
140
|
+
"type": "string | undefined"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "saveDirectory",
|
|
144
|
+
"tags": [],
|
|
145
|
+
"docs": "Public collection used by save(). Defaults from contentType.",
|
|
146
|
+
"complexTypes": [
|
|
147
|
+
"AndroidSaveDirectory"
|
|
148
|
+
],
|
|
149
|
+
"type": "AndroidSaveDirectory"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"name": "relativePath",
|
|
153
|
+
"tags": [],
|
|
154
|
+
"docs": "Optional relative folder inside the selected public collection on Android 10+.",
|
|
155
|
+
"complexTypes": [],
|
|
156
|
+
"type": "string | undefined"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "SaveFileResult",
|
|
162
|
+
"slug": "savefileresult",
|
|
163
|
+
"docs": "Result returned by save().",
|
|
164
|
+
"tags": [],
|
|
165
|
+
"methods": [],
|
|
166
|
+
"properties": [
|
|
167
|
+
{
|
|
168
|
+
"name": "uri",
|
|
169
|
+
"tags": [],
|
|
170
|
+
"docs": "Native URI of the saved file when the platform provides one.",
|
|
171
|
+
"complexTypes": [],
|
|
172
|
+
"type": "string | undefined"
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"name": "PluginVersionResult",
|
|
178
|
+
"slug": "pluginversionresult",
|
|
179
|
+
"docs": "Plugin version payload.",
|
|
180
|
+
"tags": [],
|
|
181
|
+
"methods": [],
|
|
182
|
+
"properties": [
|
|
183
|
+
{
|
|
184
|
+
"name": "version",
|
|
185
|
+
"tags": [],
|
|
186
|
+
"docs": "Version identifier returned by the platform implementation.",
|
|
187
|
+
"complexTypes": [],
|
|
188
|
+
"type": "string"
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"enums": [],
|
|
194
|
+
"typeAliases": [
|
|
195
|
+
{
|
|
196
|
+
"name": "AndroidSaveDirectory",
|
|
197
|
+
"slug": "androidsavedirectory",
|
|
198
|
+
"docs": "Android public collection used by save().",
|
|
199
|
+
"types": [
|
|
200
|
+
{
|
|
201
|
+
"text": "'downloads'",
|
|
202
|
+
"complexTypes": []
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"text": "'pictures'",
|
|
206
|
+
"complexTypes": []
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"text": "'movies'",
|
|
210
|
+
"complexTypes": []
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"text": "'music'",
|
|
214
|
+
"complexTypes": []
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"text": "'documents'",
|
|
218
|
+
"complexTypes": []
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"name": "SaveFileOptions",
|
|
224
|
+
"slug": "savefileoptions",
|
|
225
|
+
"docs": "Options used to save a file locally.",
|
|
226
|
+
"types": [
|
|
227
|
+
{
|
|
228
|
+
"text": "ShareFileOptions",
|
|
229
|
+
"complexTypes": [
|
|
230
|
+
"ShareFileOptions"
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
"pluginConfigs": []
|
|
237
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Android public collection used by save().
|
|
3
|
+
*/
|
|
4
|
+
export type AndroidSaveDirectory = 'downloads' | 'pictures' | 'movies' | 'music' | 'documents';
|
|
5
|
+
/**
|
|
6
|
+
* Android-specific behavior for file sharing and saving.
|
|
7
|
+
*/
|
|
8
|
+
export interface AndroidFileSharerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Title shown at the top of the Android chooser.
|
|
11
|
+
*/
|
|
12
|
+
chooserTitle?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Public collection used by save(). Defaults from contentType.
|
|
15
|
+
*/
|
|
16
|
+
saveDirectory?: AndroidSaveDirectory;
|
|
17
|
+
/**
|
|
18
|
+
* Optional relative folder inside the selected public collection on Android 10+.
|
|
19
|
+
*/
|
|
20
|
+
relativePath?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options used to share a file.
|
|
24
|
+
*/
|
|
25
|
+
export interface ShareFileOptions {
|
|
26
|
+
/**
|
|
27
|
+
* File name presented to the receiving app. Include the extension.
|
|
28
|
+
*/
|
|
29
|
+
filename: string;
|
|
30
|
+
/**
|
|
31
|
+
* Base64 encoded file data. Data URL prefixes are accepted.
|
|
32
|
+
*/
|
|
33
|
+
base64Data?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Local file path, file:// URL, content:// URL, or Capacitor _capacitor_file_ URL.
|
|
36
|
+
*/
|
|
37
|
+
path?: string;
|
|
38
|
+
/**
|
|
39
|
+
* MIME type of the file. Defaults to application/octet-stream when omitted.
|
|
40
|
+
*/
|
|
41
|
+
contentType?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Optional text or caption shared with the file.
|
|
44
|
+
*/
|
|
45
|
+
text?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional title for the share sheet or shared item.
|
|
48
|
+
*/
|
|
49
|
+
title?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional subject used by mail and compatible share targets.
|
|
52
|
+
*/
|
|
53
|
+
subject?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Android-specific options.
|
|
56
|
+
*/
|
|
57
|
+
android?: AndroidFileSharerOptions;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options used to save a file locally.
|
|
61
|
+
*/
|
|
62
|
+
export type SaveFileOptions = ShareFileOptions;
|
|
63
|
+
/**
|
|
64
|
+
* Result returned by save().
|
|
65
|
+
*/
|
|
66
|
+
export interface SaveFileResult {
|
|
67
|
+
/**
|
|
68
|
+
* Native URI of the saved file when the platform provides one.
|
|
69
|
+
*/
|
|
70
|
+
uri?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Plugin version payload.
|
|
74
|
+
*/
|
|
75
|
+
export interface PluginVersionResult {
|
|
76
|
+
/**
|
|
77
|
+
* Version identifier returned by the platform implementation.
|
|
78
|
+
*/
|
|
79
|
+
version: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Capacitor File Sharer plugin.
|
|
83
|
+
*/
|
|
84
|
+
export interface FileSharerPlugin {
|
|
85
|
+
/**
|
|
86
|
+
* Share a file using the native share sheet on Android and iOS.
|
|
87
|
+
* On web, this downloads the file because browsers do not expose a consistent native file share target.
|
|
88
|
+
*/
|
|
89
|
+
share(options: ShareFileOptions): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Save a file locally.
|
|
92
|
+
* On Android this writes to MediaStore/Downloads. On web this downloads the file.
|
|
93
|
+
* On iOS this opens the share sheet so the user can choose Save to Files or another target.
|
|
94
|
+
*/
|
|
95
|
+
save(options: SaveFileOptions): Promise<SaveFileResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the platform implementation version marker.
|
|
98
|
+
*/
|
|
99
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Android public collection used by save().\n */\nexport type AndroidSaveDirectory = 'downloads' | 'pictures' | 'movies' | 'music' | 'documents';\n\n/**\n * Android-specific behavior for file sharing and saving.\n */\nexport interface AndroidFileSharerOptions {\n /**\n * Title shown at the top of the Android chooser.\n */\n chooserTitle?: string;\n\n /**\n * Public collection used by save(). Defaults from contentType.\n */\n saveDirectory?: AndroidSaveDirectory;\n\n /**\n * Optional relative folder inside the selected public collection on Android 10+.\n */\n relativePath?: string;\n}\n\n/**\n * Options used to share a file.\n */\nexport interface ShareFileOptions {\n /**\n * File name presented to the receiving app. Include the extension.\n */\n filename: string;\n\n /**\n * Base64 encoded file data. Data URL prefixes are accepted.\n */\n base64Data?: string;\n\n /**\n * Local file path, file:// URL, content:// URL, or Capacitor _capacitor_file_ URL.\n */\n path?: string;\n\n /**\n * MIME type of the file. Defaults to application/octet-stream when omitted.\n */\n contentType?: string;\n\n /**\n * Optional text or caption shared with the file.\n */\n text?: string;\n\n /**\n * Optional title for the share sheet or shared item.\n */\n title?: string;\n\n /**\n * Optional subject used by mail and compatible share targets.\n */\n subject?: string;\n\n /**\n * Android-specific options.\n */\n android?: AndroidFileSharerOptions;\n}\n\n/**\n * Options used to save a file locally.\n */\nexport type SaveFileOptions = ShareFileOptions;\n\n/**\n * Result returned by save().\n */\nexport interface SaveFileResult {\n /**\n * Native URI of the saved file when the platform provides one.\n */\n uri?: string;\n}\n\n/**\n * Plugin version payload.\n */\nexport interface PluginVersionResult {\n /**\n * Version identifier returned by the platform implementation.\n */\n version: string;\n}\n\n/**\n * Capacitor File Sharer plugin.\n */\nexport interface FileSharerPlugin {\n /**\n * Share a file using the native share sheet on Android and iOS.\n * On web, this downloads the file because browsers do not expose a consistent native file share target.\n */\n share(options: ShareFileOptions): Promise<void>;\n\n /**\n * Save a file locally.\n * On Android this writes to MediaStore/Downloads. On web this downloads the file.\n * On iOS this opens the share sheet so the user can choose Save to Files or another target.\n */\n save(options: SaveFileOptions): Promise<SaveFileResult>;\n\n /**\n * Returns the platform implementation version marker.\n */\n getPluginVersion(): Promise<PluginVersionResult>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,UAAU,GAAG,cAAc,CAAmB,YAAY,EAAE;IAChE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { FileSharerPlugin } from './definitions';\n\nconst FileSharer = registerPlugin<FileSharerPlugin>('FileSharer', {\n web: () => import('./web').then((m) => new m.FileSharerWeb()),\n});\n\nexport * from './definitions';\nexport { FileSharer };\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { FileSharerPlugin, PluginVersionResult, SaveFileOptions, SaveFileResult, ShareFileOptions } from './definitions';
|
|
3
|
+
export declare class FileSharerWeb extends WebPlugin implements FileSharerPlugin {
|
|
4
|
+
share(options: ShareFileOptions): Promise<void>;
|
|
5
|
+
save(options: SaveFileOptions): Promise<SaveFileResult>;
|
|
6
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
7
|
+
private download;
|
|
8
|
+
private validateOptions;
|
|
9
|
+
private createBlob;
|
|
10
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
const DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
|
3
|
+
const ERR_PARAM_NO_FILENAME = 'ERR_PARAM_NO_FILENAME';
|
|
4
|
+
const ERR_PARAM_NO_DATA = 'ERR_PARAM_NO_DATA';
|
|
5
|
+
const ERR_PARAM_DATA_INVALID = 'ERR_PARAM_DATA_INVALID';
|
|
6
|
+
const ERR_LOCAL_FILE_NOT_FOUND = 'ERR_LOCAL_FILE_NOT_FOUND';
|
|
7
|
+
const BASE64_CHUNK_LENGTH = 256 * 1024;
|
|
8
|
+
export class FileSharerWeb extends WebPlugin {
|
|
9
|
+
async share(options) {
|
|
10
|
+
await this.download(options);
|
|
11
|
+
}
|
|
12
|
+
async save(options) {
|
|
13
|
+
await this.download(options);
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
async getPluginVersion() {
|
|
17
|
+
return {
|
|
18
|
+
version: '8.0.0',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async download(options) {
|
|
22
|
+
this.validateOptions(options);
|
|
23
|
+
const blob = await this.createBlob(options);
|
|
24
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
25
|
+
const anchor = document.createElement('a');
|
|
26
|
+
anchor.href = objectUrl;
|
|
27
|
+
anchor.download = options.filename;
|
|
28
|
+
anchor.rel = 'noopener';
|
|
29
|
+
anchor.style.display = 'none';
|
|
30
|
+
document.body.appendChild(anchor);
|
|
31
|
+
anchor.click();
|
|
32
|
+
anchor.remove();
|
|
33
|
+
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
|
|
34
|
+
}
|
|
35
|
+
validateOptions(options) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
if (!((_a = options.filename) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
38
|
+
throw new Error(ERR_PARAM_NO_FILENAME);
|
|
39
|
+
}
|
|
40
|
+
if (!((_b = options.base64Data) === null || _b === void 0 ? void 0 : _b.trim()) && !((_c = options.path) === null || _c === void 0 ? void 0 : _c.trim())) {
|
|
41
|
+
throw new Error(ERR_PARAM_NO_DATA);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async createBlob(options) {
|
|
45
|
+
var _a;
|
|
46
|
+
const contentType = options.contentType || DEFAULT_CONTENT_TYPE;
|
|
47
|
+
if ((_a = options.base64Data) === null || _a === void 0 ? void 0 : _a.trim()) {
|
|
48
|
+
return new Blob(decodeBase64ToBlobParts(options.base64Data), {
|
|
49
|
+
type: contentType,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const response = await fetch(options.path);
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(ERR_LOCAL_FILE_NOT_FOUND);
|
|
56
|
+
}
|
|
57
|
+
const blob = await response.blob();
|
|
58
|
+
return blob.type === contentType ? blob : new Blob([blob], { type: contentType });
|
|
59
|
+
}
|
|
60
|
+
catch (_b) {
|
|
61
|
+
throw new Error(ERR_LOCAL_FILE_NOT_FOUND);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function decodeBase64ToBlobParts(base64Data) {
|
|
66
|
+
const payload = getBase64Payload(base64Data);
|
|
67
|
+
const chunkLength = Math.max(4, Math.floor(BASE64_CHUNK_LENGTH / 4) * 4);
|
|
68
|
+
const parts = [];
|
|
69
|
+
try {
|
|
70
|
+
for (let offset = 0; offset < payload.length; offset += chunkLength) {
|
|
71
|
+
const byteCharacters = atob(payload.slice(offset, offset + chunkLength));
|
|
72
|
+
const buffer = new ArrayBuffer(byteCharacters.length);
|
|
73
|
+
const bytes = new Uint8Array(buffer);
|
|
74
|
+
for (let index = 0; index < byteCharacters.length; index++) {
|
|
75
|
+
bytes[index] = byteCharacters.charCodeAt(index);
|
|
76
|
+
}
|
|
77
|
+
parts.push(buffer);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (_a) {
|
|
81
|
+
throw new Error(ERR_PARAM_DATA_INVALID);
|
|
82
|
+
}
|
|
83
|
+
return parts;
|
|
84
|
+
}
|
|
85
|
+
function getBase64Payload(base64Data) {
|
|
86
|
+
const trimmed = base64Data.trim();
|
|
87
|
+
const commaIndex = trimmed.indexOf(',');
|
|
88
|
+
if (commaIndex > -1 && trimmed.slice(0, commaIndex).toLowerCase().includes('base64')) {
|
|
89
|
+
return trimmed.slice(commaIndex + 1).replace(/\s/g, '');
|
|
90
|
+
}
|
|
91
|
+
return trimmed.replace(/\s/g, '');
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AACxD,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AACtD,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AACxD,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAC5D,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,CAAC;AAEvC,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,KAAK,CAAC,OAAyB;QACnC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAwB;QACjC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO;YACL,OAAO,EAAE,OAAO;SACjB,CAAC;IACJ,CAAC;IAEO,KA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CAAC,CAAC,CAAC;YACzE,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACtD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;YAErC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;gBAC3D,KAAK,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAClD,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAAC,WAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAkB;IAC1C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;IAClC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAExC,IAAI,UAAU,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrF,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n FileSharerPlugin,\n PluginVersionResult,\n SaveFileOptions,\n SaveFileResult,\n ShareFileOptions,\n} from './definitions';\n\nconst DEFAULT_CONTENT_TYPE = 'application/octet-stream';\nconst ERR_PARAM_NO_FILENAME = 'ERR_PARAM_NO_FILENAME';\nconst ERR_PARAM_NO_DATA = 'ERR_PARAM_NO_DATA';\nconst ERR_PARAM_DATA_INVALID = 'ERR_PARAM_DATA_INVALID';\nconst ERR_LOCAL_FILE_NOT_FOUND = 'ERR_LOCAL_FILE_NOT_FOUND';\nconst BASE64_CHUNK_LENGTH = 256 * 1024;\n\nexport class FileSharerWeb extends WebPlugin implements FileSharerPlugin {\n async share(options: ShareFileOptions): Promise<void> {\n await this.download(options);\n }\n\n async save(options: SaveFileOptions): Promise<SaveFileResult> {\n await this.download(options);\n return {};\n }\n\n async getPluginVersion(): Promise<PluginVersionResult> {\n return {\n version: '8.0.0',\n };\n }\n\n private async download(options: ShareFileOptions): Promise<void> {\n this.validateOptions(options);\n\n const blob = await this.createBlob(options);\n const objectUrl = URL.createObjectURL(blob);\n const anchor = document.createElement('a');\n\n anchor.href = objectUrl;\n anchor.download = options.filename;\n anchor.rel = 'noopener';\n anchor.style.display = 'none';\n\n document.body.appendChild(anchor);\n anchor.click();\n anchor.remove();\n\n window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);\n }\n\n private validateOptions(options: ShareFileOptions): void {\n if (!options.filename?.trim()) {\n throw new Error(ERR_PARAM_NO_FILENAME);\n }\n\n if (!options.base64Data?.trim() && !options.path?.trim()) {\n throw new Error(ERR_PARAM_NO_DATA);\n }\n }\n\n private async createBlob(options: ShareFileOptions): Promise<Blob> {\n const contentType = options.contentType || DEFAULT_CONTENT_TYPE;\n\n if (options.base64Data?.trim()) {\n return new Blob(decodeBase64ToBlobParts(options.base64Data), {\n type: contentType,\n });\n }\n\n try {\n const response = await fetch(options.path as string);\n if (!response.ok) {\n throw new Error(ERR_LOCAL_FILE_NOT_FOUND);\n }\n\n const blob = await response.blob();\n return blob.type === contentType ? blob : new Blob([blob], { type: contentType });\n } catch {\n throw new Error(ERR_LOCAL_FILE_NOT_FOUND);\n }\n }\n}\n\nfunction decodeBase64ToBlobParts(base64Data: string): ArrayBuffer[] {\n const payload = getBase64Payload(base64Data);\n const chunkLength = Math.max(4, Math.floor(BASE64_CHUNK_LENGTH / 4) * 4);\n const parts: ArrayBuffer[] = [];\n\n try {\n for (let offset = 0; offset < payload.length; offset += chunkLength) {\n const byteCharacters = atob(payload.slice(offset, offset + chunkLength));\n const buffer = new ArrayBuffer(byteCharacters.length);\n const bytes = new Uint8Array(buffer);\n\n for (let index = 0; index < byteCharacters.length; index++) {\n bytes[index] = byteCharacters.charCodeAt(index);\n }\n\n parts.push(buffer);\n }\n } catch {\n throw new Error(ERR_PARAM_DATA_INVALID);\n }\n\n return parts;\n}\n\nfunction getBase64Payload(base64Data: string): string {\n const trimmed = base64Data.trim();\n const commaIndex = trimmed.indexOf(',');\n\n if (commaIndex > -1 && trimmed.slice(0, commaIndex).toLowerCase().includes('base64')) {\n return trimmed.slice(commaIndex + 1).replace(/\\s/g, '');\n }\n\n return trimmed.replace(/\\s/g, '');\n}\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const FileSharer = core.registerPlugin('FileSharer', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.FileSharerWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
|
10
|
+
const ERR_PARAM_NO_FILENAME = 'ERR_PARAM_NO_FILENAME';
|
|
11
|
+
const ERR_PARAM_NO_DATA = 'ERR_PARAM_NO_DATA';
|
|
12
|
+
const ERR_PARAM_DATA_INVALID = 'ERR_PARAM_DATA_INVALID';
|
|
13
|
+
const ERR_LOCAL_FILE_NOT_FOUND = 'ERR_LOCAL_FILE_NOT_FOUND';
|
|
14
|
+
const BASE64_CHUNK_LENGTH = 256 * 1024;
|
|
15
|
+
class FileSharerWeb extends core.WebPlugin {
|
|
16
|
+
async share(options) {
|
|
17
|
+
await this.download(options);
|
|
18
|
+
}
|
|
19
|
+
async save(options) {
|
|
20
|
+
await this.download(options);
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
async getPluginVersion() {
|
|
24
|
+
return {
|
|
25
|
+
version: '8.0.0',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async download(options) {
|
|
29
|
+
this.validateOptions(options);
|
|
30
|
+
const blob = await this.createBlob(options);
|
|
31
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
32
|
+
const anchor = document.createElement('a');
|
|
33
|
+
anchor.href = objectUrl;
|
|
34
|
+
anchor.download = options.filename;
|
|
35
|
+
anchor.rel = 'noopener';
|
|
36
|
+
anchor.style.display = 'none';
|
|
37
|
+
document.body.appendChild(anchor);
|
|
38
|
+
anchor.click();
|
|
39
|
+
anchor.remove();
|
|
40
|
+
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
|
|
41
|
+
}
|
|
42
|
+
validateOptions(options) {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
if (!((_a = options.filename) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
45
|
+
throw new Error(ERR_PARAM_NO_FILENAME);
|
|
46
|
+
}
|
|
47
|
+
if (!((_b = options.base64Data) === null || _b === void 0 ? void 0 : _b.trim()) && !((_c = options.path) === null || _c === void 0 ? void 0 : _c.trim())) {
|
|
48
|
+
throw new Error(ERR_PARAM_NO_DATA);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async createBlob(options) {
|
|
52
|
+
var _a;
|
|
53
|
+
const contentType = options.contentType || DEFAULT_CONTENT_TYPE;
|
|
54
|
+
if ((_a = options.base64Data) === null || _a === void 0 ? void 0 : _a.trim()) {
|
|
55
|
+
return new Blob(decodeBase64ToBlobParts(options.base64Data), {
|
|
56
|
+
type: contentType,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(options.path);
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(ERR_LOCAL_FILE_NOT_FOUND);
|
|
63
|
+
}
|
|
64
|
+
const blob = await response.blob();
|
|
65
|
+
return blob.type === contentType ? blob : new Blob([blob], { type: contentType });
|
|
66
|
+
}
|
|
67
|
+
catch (_b) {
|
|
68
|
+
throw new Error(ERR_LOCAL_FILE_NOT_FOUND);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function decodeBase64ToBlobParts(base64Data) {
|
|
73
|
+
const payload = getBase64Payload(base64Data);
|
|
74
|
+
const chunkLength = Math.max(4, Math.floor(BASE64_CHUNK_LENGTH / 4) * 4);
|
|
75
|
+
const parts = [];
|
|
76
|
+
try {
|
|
77
|
+
for (let offset = 0; offset < payload.length; offset += chunkLength) {
|
|
78
|
+
const byteCharacters = atob(payload.slice(offset, offset + chunkLength));
|
|
79
|
+
const buffer = new ArrayBuffer(byteCharacters.length);
|
|
80
|
+
const bytes = new Uint8Array(buffer);
|
|
81
|
+
for (let index = 0; index < byteCharacters.length; index++) {
|
|
82
|
+
bytes[index] = byteCharacters.charCodeAt(index);
|
|
83
|
+
}
|
|
84
|
+
parts.push(buffer);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (_a) {
|
|
88
|
+
throw new Error(ERR_PARAM_DATA_INVALID);
|
|
89
|
+
}
|
|
90
|
+
return parts;
|
|
91
|
+
}
|
|
92
|
+
function getBase64Payload(base64Data) {
|
|
93
|
+
const trimmed = base64Data.trim();
|
|
94
|
+
const commaIndex = trimmed.indexOf(',');
|
|
95
|
+
if (commaIndex > -1 && trimmed.slice(0, commaIndex).toLowerCase().includes('base64')) {
|
|
96
|
+
return trimmed.slice(commaIndex + 1).replace(/\s/g, '');
|
|
97
|
+
}
|
|
98
|
+
return trimmed.replace(/\s/g, '');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
102
|
+
__proto__: null,
|
|
103
|
+
FileSharerWeb: FileSharerWeb
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
exports.FileSharer = FileSharer;
|
|
107
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst FileSharer = registerPlugin('FileSharer', {\n web: () => import('./web').then((m) => new m.FileSharerWeb()),\n});\nexport * from './definitions';\nexport { FileSharer };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst DEFAULT_CONTENT_TYPE = 'application/octet-stream';\nconst ERR_PARAM_NO_FILENAME = 'ERR_PARAM_NO_FILENAME';\nconst ERR_PARAM_NO_DATA = 'ERR_PARAM_NO_DATA';\nconst ERR_PARAM_DATA_INVALID = 'ERR_PARAM_DATA_INVALID';\nconst ERR_LOCAL_FILE_NOT_FOUND = 'ERR_LOCAL_FILE_NOT_FOUND';\nconst BASE64_CHUNK_LENGTH = 256 * 1024;\nexport class FileSharerWeb extends WebPlugin {\n async share(options) {\n await this.download(options);\n }\n async save(options) {\n await this.download(options);\n return {};\n }\n async getPluginVersion() {\n return {\n version: '8.0.0',\n };\n }\n async download(options) {\n this.validateOptions(options);\n const blob = await this.createBlob(options);\n const objectUrl = URL.createObjectURL(blob);\n const anchor = document.createElement('a');\n anchor.href = objectUrl;\n anchor.download = options.filename;\n anchor.rel = 'noopener';\n anchor.style.display = 'none';\n document.body.appendChild(anchor);\n anchor.click();\n anchor.remove();\n window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);\n }\n validateOptions(options) {\n var _a, _b, _c;\n if (!((_a = options.filename) === null || _a === void 0 ? void 0 : _a.trim())) {\n throw new Error(ERR_PARAM_NO_FILENAME);\n }\n if (!((_b = options.base64Data) === null || _b === void 0 ? void 0 : _b.trim()) && !((_c = options.path) === null || _c === void 0 ? void 0 : _c.trim())) {\n throw new Error(ERR_PARAM_NO_DATA);\n }\n }\n async createBlob(options) {\n var _a;\n const contentType = options.contentType || DEFAULT_CONTENT_TYPE;\n if ((_a = options.base64Data) === null || _a === void 0 ? void 0 : _a.trim()) {\n return new Blob(decodeBase64ToBlobParts(options.base64Data), {\n type: contentType,\n });\n }\n try {\n const response = await fetch(options.path);\n if (!response.ok) {\n throw new Error(ERR_LOCAL_FILE_NOT_FOUND);\n }\n const blob = await response.blob();\n return blob.type === contentType ? blob : new Blob([blob], { type: contentType });\n }\n catch (_b) {\n throw new Error(ERR_LOCAL_FILE_NOT_FOUND);\n }\n }\n}\nfunction decodeBase64ToBlobParts(base64Data) {\n const payload = getBase64Payload(base64Data);\n const chunkLength = Math.max(4, Math.floor(BASE64_CHUNK_LENGTH / 4) * 4);\n const parts = [];\n try {\n for (let offset = 0; offset < payload.length; offset += chunkLength) {\n const byteCharacters = atob(payload.slice(offset, offset + chunkLength));\n const buffer = new ArrayBuffer(byteCharacters.length);\n const bytes = new Uint8Array(buffer);\n for (let index = 0; index < byteCharacters.length; index++) {\n bytes[index] = byteCharacters.charCodeAt(index);\n }\n parts.push(buffer);\n }\n }\n catch (_a) {\n throw new Error(ERR_PARAM_DATA_INVALID);\n }\n return parts;\n}\nfunction getBase64Payload(base64Data) {\n const trimmed = base64Data.trim();\n const commaIndex = trimmed.indexOf(',');\n if (commaIndex > -1 && trimmed.slice(0, commaIndex).toLowerCase().includes('base64')) {\n return trimmed.slice(commaIndex + 1).replace(/\\s/g, '');\n }\n return trimmed.replace(/\\s/g, '');\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AACjE,CAAC;;ACFD,MAAM,oBAAoB,GAAG,0BAA0B;AACvD,MAAM,qBAAqB,GAAG,uBAAuB;AACrD,MAAM,iBAAiB,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