sm-click-library-ui 0.0.382 → 0.0.384

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.
@@ -0,0 +1,437 @@
1
+ import { W as P, b as x, E } from "./index-1dgik5G_.js";
2
+ function m(w) {
3
+ const e = w.split("/").filter((t) => t !== "."), r = [];
4
+ return e.forEach((t) => {
5
+ t === ".." && r.length > 0 && r[r.length - 1] !== ".." ? r.pop() : r.push(t);
6
+ }), r.join("/");
7
+ }
8
+ function R(w, e) {
9
+ w = m(w), e = m(e);
10
+ const r = w.split("/"), t = e.split("/");
11
+ return w !== e && r.every((i, n) => i === t[n]);
12
+ }
13
+ class g extends P {
14
+ constructor() {
15
+ super(...arguments), this.DB_VERSION = 1, this.DB_NAME = "Disc", this._writeCmds = ["add", "put", "delete"], this.downloadFile = async (e) => {
16
+ var r, t;
17
+ const i = x(e, e.webFetchExtra), n = await fetch(e.url, i);
18
+ let s;
19
+ if (!e.progress)
20
+ s = await n.blob();
21
+ else if (!(n != null && n.body))
22
+ s = new Blob();
23
+ else {
24
+ const c = n.body.getReader();
25
+ let o = 0;
26
+ const d = [], h = n.headers.get("content-type"), y = parseInt(n.headers.get("content-length") || "0", 10);
27
+ for (; ; ) {
28
+ const { done: f, value: p } = await c.read();
29
+ if (f)
30
+ break;
31
+ d.push(p), o += (p == null ? void 0 : p.length) || 0;
32
+ const b = {
33
+ url: e.url,
34
+ bytes: o,
35
+ contentLength: y
36
+ };
37
+ this.notifyListeners("progress", b);
38
+ }
39
+ const u = new Uint8Array(o);
40
+ let l = 0;
41
+ for (const f of d)
42
+ typeof f > "u" || (u.set(f, l), l += f.length);
43
+ s = new Blob([u.buffer], { type: h || void 0 });
44
+ }
45
+ return { path: (await this.writeFile({
46
+ path: e.path,
47
+ directory: (r = e.directory) !== null && r !== void 0 ? r : void 0,
48
+ recursive: (t = e.recursive) !== null && t !== void 0 ? t : !1,
49
+ data: s
50
+ })).uri, blob: s };
51
+ };
52
+ }
53
+ readFileInChunks(e, r) {
54
+ throw this.unavailable("Method not implemented.");
55
+ }
56
+ async initDb() {
57
+ if (this._db !== void 0)
58
+ return this._db;
59
+ if (!("indexedDB" in window))
60
+ throw this.unavailable("This browser doesn't support IndexedDB");
61
+ return new Promise((e, r) => {
62
+ const t = indexedDB.open(this.DB_NAME, this.DB_VERSION);
63
+ t.onupgradeneeded = g.doUpgrade, t.onsuccess = () => {
64
+ this._db = t.result, e(t.result);
65
+ }, t.onerror = () => r(t.error), t.onblocked = () => {
66
+ console.warn("db blocked");
67
+ };
68
+ });
69
+ }
70
+ static doUpgrade(e) {
71
+ const t = e.target.result;
72
+ switch (e.oldVersion) {
73
+ case 0:
74
+ case 1:
75
+ default:
76
+ t.objectStoreNames.contains("FileStorage") && t.deleteObjectStore("FileStorage"), t.createObjectStore("FileStorage", { keyPath: "path" }).createIndex("by_folder", "folder");
77
+ }
78
+ }
79
+ async dbRequest(e, r) {
80
+ const t = this._writeCmds.indexOf(e) !== -1 ? "readwrite" : "readonly";
81
+ return this.initDb().then((i) => new Promise((n, s) => {
82
+ const o = i.transaction(["FileStorage"], t).objectStore("FileStorage")[e](...r);
83
+ o.onsuccess = () => n(o.result), o.onerror = () => s(o.error);
84
+ }));
85
+ }
86
+ async dbIndexRequest(e, r, t) {
87
+ const i = this._writeCmds.indexOf(r) !== -1 ? "readwrite" : "readonly";
88
+ return this.initDb().then((n) => new Promise((s, a) => {
89
+ const h = n.transaction(["FileStorage"], i).objectStore("FileStorage").index(e)[r](...t);
90
+ h.onsuccess = () => s(h.result), h.onerror = () => a(h.error);
91
+ }));
92
+ }
93
+ getPath(e, r) {
94
+ const t = r !== void 0 ? r.replace(/^[/]+|[/]+$/g, "") : "";
95
+ let i = "";
96
+ return e !== void 0 && (i += "/" + e), r !== "" && (i += "/" + t), i;
97
+ }
98
+ async clear() {
99
+ (await this.initDb()).transaction(["FileStorage"], "readwrite").objectStore("FileStorage").clear();
100
+ }
101
+ /**
102
+ * Read a file from disk
103
+ * @param options options for the file read
104
+ * @return a promise that resolves with the read file data result
105
+ */
106
+ async readFile(e) {
107
+ const r = this.getPath(e.directory, e.path), t = await this.dbRequest("get", [r]);
108
+ if (t === void 0)
109
+ throw Error("File does not exist.");
110
+ return { data: t.content ? t.content : "" };
111
+ }
112
+ /**
113
+ * Write a file to disk in the specified location on device
114
+ * @param options options for the file write
115
+ * @return a promise that resolves with the file write result
116
+ */
117
+ async writeFile(e) {
118
+ const r = this.getPath(e.directory, e.path);
119
+ let t = e.data;
120
+ const i = e.encoding, n = e.recursive, s = await this.dbRequest("get", [r]);
121
+ if (s && s.type === "directory")
122
+ throw Error("The supplied path is a directory.");
123
+ const a = r.substr(0, r.lastIndexOf("/"));
124
+ if (await this.dbRequest("get", [a]) === void 0) {
125
+ const h = a.indexOf("/", 1);
126
+ if (h !== -1) {
127
+ const y = a.substr(h);
128
+ await this.mkdir({
129
+ path: y,
130
+ directory: e.directory,
131
+ recursive: n
132
+ });
133
+ }
134
+ }
135
+ if (!i && !(t instanceof Blob) && (t = t.indexOf(",") >= 0 ? t.split(",")[1] : t, !this.isBase64String(t)))
136
+ throw Error("The supplied data is not valid base64 content.");
137
+ const o = Date.now(), d = {
138
+ path: r,
139
+ folder: a,
140
+ type: "file",
141
+ size: t instanceof Blob ? t.size : t.length,
142
+ ctime: o,
143
+ mtime: o,
144
+ content: t
145
+ };
146
+ return await this.dbRequest("put", [d]), {
147
+ uri: d.path
148
+ };
149
+ }
150
+ /**
151
+ * Append to a file on disk in the specified location on device
152
+ * @param options options for the file append
153
+ * @return a promise that resolves with the file write result
154
+ */
155
+ async appendFile(e) {
156
+ const r = this.getPath(e.directory, e.path);
157
+ let t = e.data;
158
+ const i = e.encoding, n = r.substr(0, r.lastIndexOf("/")), s = Date.now();
159
+ let a = s;
160
+ const c = await this.dbRequest("get", [r]);
161
+ if (c && c.type === "directory")
162
+ throw Error("The supplied path is a directory.");
163
+ if (await this.dbRequest("get", [n]) === void 0) {
164
+ const h = n.indexOf("/", 1);
165
+ if (h !== -1) {
166
+ const y = n.substr(h);
167
+ await this.mkdir({
168
+ path: y,
169
+ directory: e.directory,
170
+ recursive: !0
171
+ });
172
+ }
173
+ }
174
+ if (!i && !this.isBase64String(t))
175
+ throw Error("The supplied data is not valid base64 content.");
176
+ if (c !== void 0) {
177
+ if (c.content instanceof Blob)
178
+ throw Error("The occupied entry contains a Blob object which cannot be appended to.");
179
+ c.content !== void 0 && !i ? t = btoa(atob(c.content) + atob(t)) : t = c.content + t, a = c.ctime;
180
+ }
181
+ const d = {
182
+ path: r,
183
+ folder: n,
184
+ type: "file",
185
+ size: t.length,
186
+ ctime: a,
187
+ mtime: s,
188
+ content: t
189
+ };
190
+ await this.dbRequest("put", [d]);
191
+ }
192
+ /**
193
+ * Delete a file from disk
194
+ * @param options options for the file delete
195
+ * @return a promise that resolves with the deleted file data result
196
+ */
197
+ async deleteFile(e) {
198
+ const r = this.getPath(e.directory, e.path);
199
+ if (await this.dbRequest("get", [r]) === void 0)
200
+ throw Error("File does not exist.");
201
+ if ((await this.dbIndexRequest("by_folder", "getAllKeys", [IDBKeyRange.only(r)])).length !== 0)
202
+ throw Error("Folder is not empty.");
203
+ await this.dbRequest("delete", [r]);
204
+ }
205
+ /**
206
+ * Create a directory.
207
+ * @param options options for the mkdir
208
+ * @return a promise that resolves with the mkdir result
209
+ */
210
+ async mkdir(e) {
211
+ const r = this.getPath(e.directory, e.path), t = e.recursive, i = r.substr(0, r.lastIndexOf("/")), n = (r.match(/\//g) || []).length, s = await this.dbRequest("get", [i]), a = await this.dbRequest("get", [r]);
212
+ if (n === 1)
213
+ throw Error("Cannot create Root directory");
214
+ if (a !== void 0)
215
+ throw Error("Current directory does already exist.");
216
+ if (!t && n !== 2 && s === void 0)
217
+ throw Error("Parent directory must exist");
218
+ if (t && n !== 2 && s === void 0) {
219
+ const d = i.substr(i.indexOf("/", 1));
220
+ await this.mkdir({
221
+ path: d,
222
+ directory: e.directory,
223
+ recursive: t
224
+ });
225
+ }
226
+ const c = Date.now(), o = {
227
+ path: r,
228
+ folder: i,
229
+ type: "directory",
230
+ size: 0,
231
+ ctime: c,
232
+ mtime: c
233
+ };
234
+ await this.dbRequest("put", [o]);
235
+ }
236
+ /**
237
+ * Remove a directory
238
+ * @param options the options for the directory remove
239
+ */
240
+ async rmdir(e) {
241
+ const { path: r, directory: t, recursive: i } = e, n = this.getPath(t, r), s = await this.dbRequest("get", [n]);
242
+ if (s === void 0)
243
+ throw Error("Folder does not exist.");
244
+ if (s.type !== "directory")
245
+ throw Error("Requested path is not a directory");
246
+ const a = await this.readdir({ path: r, directory: t });
247
+ if (a.files.length !== 0 && !i)
248
+ throw Error("Folder is not empty");
249
+ for (const c of a.files) {
250
+ const o = `${r}/${c.name}`;
251
+ (await this.stat({ path: o, directory: t })).type === "file" ? await this.deleteFile({ path: o, directory: t }) : await this.rmdir({ path: o, directory: t, recursive: i });
252
+ }
253
+ await this.dbRequest("delete", [n]);
254
+ }
255
+ /**
256
+ * Return a list of files from the directory (not recursive)
257
+ * @param options the options for the readdir operation
258
+ * @return a promise that resolves with the readdir directory listing result
259
+ */
260
+ async readdir(e) {
261
+ const r = this.getPath(e.directory, e.path), t = await this.dbRequest("get", [r]);
262
+ if (e.path !== "" && t === void 0)
263
+ throw Error("Folder does not exist.");
264
+ const i = await this.dbIndexRequest("by_folder", "getAllKeys", [IDBKeyRange.only(r)]);
265
+ return { files: await Promise.all(i.map(async (s) => {
266
+ let a = await this.dbRequest("get", [s]);
267
+ return a === void 0 && (a = await this.dbRequest("get", [s + "/"])), {
268
+ name: s.substring(r.length + 1),
269
+ type: a.type,
270
+ size: a.size,
271
+ ctime: a.ctime,
272
+ mtime: a.mtime,
273
+ uri: a.path
274
+ };
275
+ })) };
276
+ }
277
+ /**
278
+ * Return full File URI for a path and directory
279
+ * @param options the options for the stat operation
280
+ * @return a promise that resolves with the file stat result
281
+ */
282
+ async getUri(e) {
283
+ const r = this.getPath(e.directory, e.path);
284
+ let t = await this.dbRequest("get", [r]);
285
+ return t === void 0 && (t = await this.dbRequest("get", [r + "/"])), {
286
+ uri: (t == null ? void 0 : t.path) || r
287
+ };
288
+ }
289
+ /**
290
+ * Return data about a file
291
+ * @param options the options for the stat operation
292
+ * @return a promise that resolves with the file stat result
293
+ */
294
+ async stat(e) {
295
+ const r = this.getPath(e.directory, e.path);
296
+ let t = await this.dbRequest("get", [r]);
297
+ if (t === void 0 && (t = await this.dbRequest("get", [r + "/"])), t === void 0)
298
+ throw Error("Entry does not exist.");
299
+ return {
300
+ name: t.path.substring(r.length + 1),
301
+ type: t.type,
302
+ size: t.size,
303
+ ctime: t.ctime,
304
+ mtime: t.mtime,
305
+ uri: t.path
306
+ };
307
+ }
308
+ /**
309
+ * Rename a file or directory
310
+ * @param options the options for the rename operation
311
+ * @return a promise that resolves with the rename result
312
+ */
313
+ async rename(e) {
314
+ await this._copy(e, !0);
315
+ }
316
+ /**
317
+ * Copy a file or directory
318
+ * @param options the options for the copy operation
319
+ * @return a promise that resolves with the copy result
320
+ */
321
+ async copy(e) {
322
+ return this._copy(e, !1);
323
+ }
324
+ async requestPermissions() {
325
+ return { publicStorage: "granted" };
326
+ }
327
+ async checkPermissions() {
328
+ return { publicStorage: "granted" };
329
+ }
330
+ /**
331
+ * Function that can perform a copy or a rename
332
+ * @param options the options for the rename operation
333
+ * @param doRename whether to perform a rename or copy operation
334
+ * @return a promise that resolves with the result
335
+ */
336
+ async _copy(e, r = !1) {
337
+ let { toDirectory: t } = e;
338
+ const { to: i, from: n, directory: s } = e;
339
+ if (!i || !n)
340
+ throw Error("Both to and from must be provided");
341
+ t || (t = s);
342
+ const a = this.getPath(s, n), c = this.getPath(t, i);
343
+ if (a === c)
344
+ return {
345
+ uri: c
346
+ };
347
+ if (R(a, c))
348
+ throw Error("To path cannot contain the from path");
349
+ let o;
350
+ try {
351
+ o = await this.stat({
352
+ path: i,
353
+ directory: t
354
+ });
355
+ } catch {
356
+ const l = i.split("/");
357
+ l.pop();
358
+ const f = l.join("/");
359
+ if (l.length > 0 && (await this.stat({
360
+ path: f,
361
+ directory: t
362
+ })).type !== "directory")
363
+ throw new Error("Parent directory of the to path is a file");
364
+ }
365
+ if (o && o.type === "directory")
366
+ throw new Error("Cannot overwrite a directory with a file");
367
+ const d = await this.stat({
368
+ path: n,
369
+ directory: s
370
+ }), h = async (u, l, f) => {
371
+ const p = this.getPath(t, u), b = await this.dbRequest("get", [p]);
372
+ b.ctime = l, b.mtime = f, await this.dbRequest("put", [b]);
373
+ }, y = d.ctime ? d.ctime : Date.now();
374
+ switch (d.type) {
375
+ case "file": {
376
+ const u = await this.readFile({
377
+ path: n,
378
+ directory: s
379
+ });
380
+ r && await this.deleteFile({
381
+ path: n,
382
+ directory: s
383
+ });
384
+ let l;
385
+ !(u.data instanceof Blob) && !this.isBase64String(u.data) && (l = E.UTF8);
386
+ const f = await this.writeFile({
387
+ path: i,
388
+ directory: t,
389
+ data: u.data,
390
+ encoding: l
391
+ });
392
+ return r && await h(i, y, d.mtime), f;
393
+ }
394
+ case "directory": {
395
+ if (o)
396
+ throw Error("Cannot move a directory over an existing object");
397
+ try {
398
+ await this.mkdir({
399
+ path: i,
400
+ directory: t,
401
+ recursive: !1
402
+ }), r && await h(i, y, d.mtime);
403
+ } catch {
404
+ }
405
+ const u = (await this.readdir({
406
+ path: n,
407
+ directory: s
408
+ })).files;
409
+ for (const l of u)
410
+ await this._copy({
411
+ from: `${n}/${l.name}`,
412
+ to: `${i}/${l.name}`,
413
+ directory: s,
414
+ toDirectory: t
415
+ }, r);
416
+ r && await this.rmdir({
417
+ path: n,
418
+ directory: s
419
+ });
420
+ }
421
+ }
422
+ return {
423
+ uri: c
424
+ };
425
+ }
426
+ isBase64String(e) {
427
+ try {
428
+ return btoa(atob(e)) == e;
429
+ } catch {
430
+ return !1;
431
+ }
432
+ }
433
+ }
434
+ g._debug = !0;
435
+ export {
436
+ g as FilesystemWeb
437
+ };
@@ -0,0 +1,27 @@
1
+ import { W as t } from "./index-1dgik5G_.js";
2
+ class m extends t {
3
+ getMedias(e) {
4
+ throw console.log("getMedias", e), this.unimplemented("Not implemented on web.");
5
+ }
6
+ getMediaByIdentifier(e) {
7
+ throw console.log("getMediaByIdentifier", e), this.unimplemented("Not implemented on web.");
8
+ }
9
+ getAlbums() {
10
+ throw this.unimplemented("Not implemented on web.");
11
+ }
12
+ savePhoto(e) {
13
+ throw console.log("savePhoto", e), this.unimplemented("Not implemented on web.");
14
+ }
15
+ saveVideo(e) {
16
+ throw console.log("saveVideo", e), this.unimplemented("Not implemented on web.");
17
+ }
18
+ createAlbum(e) {
19
+ throw console.log("createAlbum", e), this.unimplemented("Not implemented on web.");
20
+ }
21
+ getAlbumsPath() {
22
+ throw console.log("getAlbumsPath"), this.unimplemented("Not implemented on web.");
23
+ }
24
+ }
25
+ export {
26
+ m as MediaWeb
27
+ };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "dist",
6
6
  "src/test-utils"
7
7
  ],
8
- "version": "0.0.382",
8
+ "version": "0.0.384",
9
9
  "main": "dist/sm-click-library-ui.es.js",
10
10
  "module": "dist/sm-click-library-ui.umd.js",
11
11
  "private": false,
@@ -15,6 +15,10 @@
15
15
  "./test-utils/setup": "./dist/test-utils/setup.js"
16
16
  },
17
17
  "dependencies": {
18
+ "@capacitor-community/media": "^8.0.1",
19
+ "@capacitor/core": "^7.4.2",
20
+ "@capacitor/filesystem": "^7.1.3",
21
+ "@capacitor/share": "^7.0.1",
18
22
  "@fancyapps/ui": "^6.0.16",
19
23
  "@pinia/testing": "^1.0.0",
20
24
  "@tailwindcss/typography": "^0.5.13",