aio-capacitor 2.1.0 → 2.2.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/index.d.ts +1 -23
- package/index.js +4 -276
- package/package.json +3 -13
package/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Directory } from '@capacitor/filesystem';
|
|
2
|
-
|
|
3
1
|
type I_logItem = {
|
|
4
2
|
tags?: string[];
|
|
5
3
|
id?: string;
|
|
@@ -64,13 +62,7 @@ export declare class AIOCapacitor {
|
|
|
64
62
|
success: boolean;
|
|
65
63
|
error: any;
|
|
66
64
|
}>;
|
|
67
|
-
shareFile: (file: Blob | File, fileName?: string) => Promise<
|
|
68
|
-
success: boolean;
|
|
69
|
-
error?: undefined;
|
|
70
|
-
} | {
|
|
71
|
-
success: boolean;
|
|
72
|
-
error: any;
|
|
73
|
-
}>;
|
|
65
|
+
shareFile: (file: Blob | File, fileName?: string) => Promise<any>;
|
|
74
66
|
getLocation: () => Promise<{
|
|
75
67
|
success: boolean;
|
|
76
68
|
latitude?: number;
|
|
@@ -118,18 +110,4 @@ export declare class Tracker {
|
|
|
118
110
|
stop(): Promise<void>;
|
|
119
111
|
isTracking(): boolean;
|
|
120
112
|
}
|
|
121
|
-
export type I_FileRecordType = 'image' | 'file' | 'json' | 'text';
|
|
122
|
-
export type I_FileRecord = {
|
|
123
|
-
id: string;
|
|
124
|
-
name: string;
|
|
125
|
-
path: string;
|
|
126
|
-
type: I_FileRecordType;
|
|
127
|
-
createdAt: number;
|
|
128
|
-
meta?: any;
|
|
129
|
-
};
|
|
130
|
-
type FileResult<T> = {
|
|
131
|
-
success: boolean;
|
|
132
|
-
result: T;
|
|
133
|
-
message?: string;
|
|
134
|
-
};
|
|
135
113
|
export {};
|
package/index.js
CHANGED
|
@@ -7,18 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { Capacitor } from '
|
|
11
|
-
import {
|
|
12
|
-
import { Clipboard } from '@capacitor/clipboard';
|
|
13
|
-
import { Camera } from '@capacitor/camera';
|
|
14
|
-
import { Geolocation } from '@capacitor/geolocation';
|
|
15
|
-
import { PushNotifications } from '@capacitor/push-notifications';
|
|
16
|
-
import { TextToSpeech } from '@capacitor-community/text-to-speech';
|
|
17
|
-
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
|
18
|
-
import { Haptics, ImpactStyle } from '@capacitor/haptics';
|
|
19
|
-
import { Share } from '@capacitor/share';
|
|
20
|
-
import { LocalNotifications } from '@capacitor/local-notifications';
|
|
21
|
-
import { KeepAwake } from '@capacitor-community/keep-awake';
|
|
10
|
+
import { Capacitor, Preferences, Clipboard, Camera, Geolocation, PushNotifications, TextToSpeech, Filesystem, Directory, Encoding, Haptics, ImpactStyle, Share, LocalNotifications, KeepAwake } from 'aio-capacitor-deps';
|
|
11
|
+
import { FileClass } from 'aio-class';
|
|
22
12
|
export class AIOCapacitor {
|
|
23
13
|
constructor(p) {
|
|
24
14
|
this.getPlatform = () => Capacitor.getPlatform();
|
|
@@ -48,7 +38,7 @@ export class AIOCapacitor {
|
|
|
48
38
|
console.error('Haptics pattern error:', err);
|
|
49
39
|
}
|
|
50
40
|
});
|
|
51
|
-
this.vibrateImpact = (
|
|
41
|
+
this.vibrateImpact = (...args_1) => __awaiter(this, [...args_1], void 0, function* (style = 'medium') {
|
|
52
42
|
try {
|
|
53
43
|
const map = {
|
|
54
44
|
light: ImpactStyle.Light,
|
|
@@ -190,7 +180,7 @@ export class AIOCapacitor {
|
|
|
190
180
|
return { success: false, error: (err === null || err === void 0 ? void 0 : err.message) || err };
|
|
191
181
|
}
|
|
192
182
|
});
|
|
193
|
-
this.shareFile = (
|
|
183
|
+
this.shareFile = (file_1, ...args_2) => __awaiter(this, [file_1, ...args_2], void 0, function* (file, fileName = `file_${Date.now()}`) {
|
|
194
184
|
try {
|
|
195
185
|
const res = yield new FileClass().toDataUrl(file);
|
|
196
186
|
if (!res.success) {
|
|
@@ -433,265 +423,3 @@ export class Tracker {
|
|
|
433
423
|
return !!this.watchId;
|
|
434
424
|
}
|
|
435
425
|
}
|
|
436
|
-
class FileClass {
|
|
437
|
-
constructor() {
|
|
438
|
-
this.isNative = false;
|
|
439
|
-
this.isUrl = (input) => input.startsWith("http://") || input.startsWith("https://") || input.startsWith("blob:");
|
|
440
|
-
this.isDataUrl = (input) => input.startsWith("data:");
|
|
441
|
-
this.toDataUrl = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
442
|
-
const blobRes = yield this.toBlob(input);
|
|
443
|
-
if (!blobRes.success) {
|
|
444
|
-
return { success: false, result: "", message: blobRes.message };
|
|
445
|
-
}
|
|
446
|
-
const fr = new FileReader();
|
|
447
|
-
return new Promise((resolve) => {
|
|
448
|
-
fr.onload = () => resolve({ success: true, result: fr.result, message: "" });
|
|
449
|
-
fr.onerror = () => resolve({ success: false, result: "", message: "FileReader error" });
|
|
450
|
-
fr.readAsDataURL(blobRes.result);
|
|
451
|
-
});
|
|
452
|
-
});
|
|
453
|
-
this.fileToText = (file) => __awaiter(this, void 0, void 0, function* () {
|
|
454
|
-
return new Promise((resolve, reject) => {
|
|
455
|
-
const fr = new FileReader();
|
|
456
|
-
fr.onload = () => {
|
|
457
|
-
try {
|
|
458
|
-
const result = fr.result;
|
|
459
|
-
resolve(result);
|
|
460
|
-
}
|
|
461
|
-
catch (error) {
|
|
462
|
-
reject(new Error('Error parsing JSON: ' + error.message));
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
fr.onerror = () => reject(new Error('Error reading file.'));
|
|
466
|
-
fr.readAsText(file);
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
this.readText = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
470
|
-
if (typeof input === 'object' && 'path' in input && 'directory' in input) {
|
|
471
|
-
return yield this.readCapacitorText(input.path, input.directory);
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
try {
|
|
475
|
-
const blobRes = yield this.toBlob(input);
|
|
476
|
-
if (!blobRes.success)
|
|
477
|
-
return blobRes;
|
|
478
|
-
let result = yield blobRes.result.text();
|
|
479
|
-
return { success: true, result, message: "" };
|
|
480
|
-
}
|
|
481
|
-
catch (e) {
|
|
482
|
-
return { success: false, result: "", message: (e === null || e === void 0 ? void 0 : e.message) || `read text failed` };
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
this.readCapacitorText = (path, directory) => __awaiter(this, void 0, void 0, function* () {
|
|
487
|
-
try {
|
|
488
|
-
const res = yield this.pathToBase64(path, directory);
|
|
489
|
-
if (!res.success) {
|
|
490
|
-
return { success: false, result: null, message: 'Empty file' };
|
|
491
|
-
}
|
|
492
|
-
const blobRes = this.base64ToBlob(res.result);
|
|
493
|
-
if (!blobRes.success) {
|
|
494
|
-
return blobRes;
|
|
495
|
-
}
|
|
496
|
-
return this.readText(blobRes.result);
|
|
497
|
-
}
|
|
498
|
-
catch (e) {
|
|
499
|
-
return { success: false, result: null, message: (e === null || e === void 0 ? void 0 : e.message) || 'Storage read failed' };
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
this.pathToBase64 = (path, directory) => __awaiter(this, void 0, void 0, function* () {
|
|
503
|
-
const a = new AIOCapacitor();
|
|
504
|
-
const res = yield a.readFile(path, directory);
|
|
505
|
-
if (!(res === null || res === void 0 ? void 0 : res.data)) {
|
|
506
|
-
return { success: false, result: null, message: 'Empty file' };
|
|
507
|
-
}
|
|
508
|
-
return { success: true, result: res.data, message: '' };
|
|
509
|
-
});
|
|
510
|
-
this.pathToSrc = (path, directory) => __awaiter(this, void 0, void 0, function* () { return yield new AIOCapacitor().pathToSrc(path, directory); });
|
|
511
|
-
this.toSrc = (file) => typeof file === 'string' ? file : window.URL.createObjectURL(file);
|
|
512
|
-
this.toBase64 = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
513
|
-
const dataUrl = yield this.toDataUrl(input);
|
|
514
|
-
if (!dataUrl.success) {
|
|
515
|
-
return { success: false, result: "", message: dataUrl.message };
|
|
516
|
-
}
|
|
517
|
-
return this.dataUrlToBase64(dataUrl.result);
|
|
518
|
-
});
|
|
519
|
-
this.GetDurationByUrl = (url) => __awaiter(this, void 0, void 0, function* () {
|
|
520
|
-
return new Promise((resolve) => {
|
|
521
|
-
const video = document.createElement("video");
|
|
522
|
-
video.preload = "metadata";
|
|
523
|
-
video.src = url;
|
|
524
|
-
video.onloadedmetadata = () => { resolve(isNaN(video.duration) ? null : video.duration); video.remove(); };
|
|
525
|
-
video.onerror = () => { resolve(null); video.remove(); };
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
this.GetSizeByUrl = (url) => __awaiter(this, void 0, void 0, function* () {
|
|
529
|
-
let size = null;
|
|
530
|
-
try {
|
|
531
|
-
const res = yield fetch(url, { method: "HEAD" });
|
|
532
|
-
const contentLength = res.headers.get("content-length");
|
|
533
|
-
if (contentLength)
|
|
534
|
-
size = parseInt(contentLength, 10);
|
|
535
|
-
}
|
|
536
|
-
catch (err) { }
|
|
537
|
-
return size;
|
|
538
|
-
});
|
|
539
|
-
this.GetNameByUrl = (url) => { var _a; return decodeURIComponent(((_a = url.split("/").pop()) === null || _a === void 0 ? void 0 : _a.split("?")[0]) || "unknown"); };
|
|
540
|
-
this.GetFileDetailsByUrl = (url) => __awaiter(this, void 0, void 0, function* () {
|
|
541
|
-
const name = this.GetNameByUrl(url);
|
|
542
|
-
const size = yield this.GetSizeByUrl(url);
|
|
543
|
-
const duration = yield this.GetDurationByUrl(url);
|
|
544
|
-
return { name, size, duration };
|
|
545
|
-
});
|
|
546
|
-
this.fetchBlob = (url) => __awaiter(this, void 0, void 0, function* () {
|
|
547
|
-
try {
|
|
548
|
-
const res = yield fetch(url);
|
|
549
|
-
if (!res.ok) {
|
|
550
|
-
return { success: false, result: null, message: `HTTP Error: ${res.status}` };
|
|
551
|
-
}
|
|
552
|
-
const blob = yield res.blob();
|
|
553
|
-
return { success: true, result: blob, message: "" };
|
|
554
|
-
}
|
|
555
|
-
catch (e) {
|
|
556
|
-
return { success: false, result: null, message: (e === null || e === void 0 ? void 0 : e.message) || "Fetch failed" };
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
this.fetchBlob2 = () => __awaiter(this, void 0, void 0, function* () {
|
|
560
|
-
});
|
|
561
|
-
this.base64ToBlob = (base64) => {
|
|
562
|
-
try {
|
|
563
|
-
const byteCharacters = atob(base64);
|
|
564
|
-
const byteNumbers = new Array(byteCharacters.length);
|
|
565
|
-
for (let i = 0; i < byteCharacters.length; i++) {
|
|
566
|
-
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
567
|
-
}
|
|
568
|
-
const byteArray = new Uint8Array(byteNumbers);
|
|
569
|
-
return { success: true, result: new Blob([byteArray]), message: "" };
|
|
570
|
-
}
|
|
571
|
-
catch (e) {
|
|
572
|
-
return { success: false, result: null, message: (e === null || e === void 0 ? void 0 : e.message) || "Invalid base64" };
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
this.handleFileName = (selectedName) => selectedName || window.prompt('Please Enter File Name') || `file-${Date.now()}.json`;
|
|
576
|
-
this.generateFileName = (mimeType) => {
|
|
577
|
-
const map = {
|
|
578
|
-
'application/json': 'file.json',
|
|
579
|
-
'text/plain': 'file.txt',
|
|
580
|
-
'text/html': 'file.html',
|
|
581
|
-
'text/csv': 'file.csv',
|
|
582
|
-
'application/pdf': 'file.pdf',
|
|
583
|
-
'image/png': 'image.png',
|
|
584
|
-
'image/jpeg': 'image.jpg',
|
|
585
|
-
'image/webp': 'image.webp',
|
|
586
|
-
'application/zip': 'archive.zip',
|
|
587
|
-
'application/octet-stream': 'file.bin'
|
|
588
|
-
};
|
|
589
|
-
const base = map[mimeType || ''] || 'file.bin';
|
|
590
|
-
const timestamp = Date.now();
|
|
591
|
-
const [name, ext] = base.split('.');
|
|
592
|
-
return `${name}-${timestamp}.${ext}`;
|
|
593
|
-
};
|
|
594
|
-
this.saveWeb = (url, fileName) => __awaiter(this, void 0, void 0, function* () {
|
|
595
|
-
const a = document.createElement('a');
|
|
596
|
-
a.href = url;
|
|
597
|
-
a.download = fileName;
|
|
598
|
-
document.body.appendChild(a);
|
|
599
|
-
a.click();
|
|
600
|
-
document.body.removeChild(a);
|
|
601
|
-
URL.revokeObjectURL(url);
|
|
602
|
-
return { success: true, message: '' };
|
|
603
|
-
});
|
|
604
|
-
this.dataUrlToBase64 = (dataUrl) => {
|
|
605
|
-
try {
|
|
606
|
-
const base64 = dataUrl.split(",")[1];
|
|
607
|
-
return { success: true, result: base64, message: "" };
|
|
608
|
-
}
|
|
609
|
-
catch (_a) {
|
|
610
|
-
return { success: false, result: "", message: "Invalid data url" };
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
this.toBlob = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
614
|
-
try {
|
|
615
|
-
if (input instanceof Blob) {
|
|
616
|
-
return { success: true, result: input, message: "" };
|
|
617
|
-
}
|
|
618
|
-
if (input instanceof ArrayBuffer) {
|
|
619
|
-
const result = new Blob([input], { type: 'application/octet-stream' });
|
|
620
|
-
return { success: true, result };
|
|
621
|
-
}
|
|
622
|
-
if (input instanceof Uint8Array) {
|
|
623
|
-
const buffer = input.buffer instanceof ArrayBuffer ? input.buffer : new ArrayBuffer(input.byteLength);
|
|
624
|
-
const result = new Blob([new Uint8Array(buffer)], { type: 'application/octet-stream' });
|
|
625
|
-
return { success: true, result };
|
|
626
|
-
}
|
|
627
|
-
if (typeof input !== "string") {
|
|
628
|
-
const result = new Blob([JSON.stringify(input)], { type: 'application/json' });
|
|
629
|
-
return { success: true, result, message: "" };
|
|
630
|
-
}
|
|
631
|
-
if (this.isDataUrl(input)) {
|
|
632
|
-
const base64 = this.dataUrlToBase64(input);
|
|
633
|
-
if (!base64.success) {
|
|
634
|
-
return { success: false, result: null, message: base64.message };
|
|
635
|
-
}
|
|
636
|
-
return this.base64ToBlob(base64.result);
|
|
637
|
-
}
|
|
638
|
-
if (this.isUrl(input)) {
|
|
639
|
-
return yield this.fetchBlob(input);
|
|
640
|
-
}
|
|
641
|
-
return { success: false, result: null, message: "Unsupported input" };
|
|
642
|
-
}
|
|
643
|
-
catch (e) {
|
|
644
|
-
return { success: false, result: null, message: e === null || e === void 0 ? void 0 : e.message };
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
this.saveText = (text, path) => __awaiter(this, void 0, void 0, function* () {
|
|
648
|
-
try {
|
|
649
|
-
if (this.isNative) {
|
|
650
|
-
return yield new AIOCapacitor().save(text, path);
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
const blob = new Blob([text], { type: "text/plain" });
|
|
654
|
-
const url = URL.createObjectURL(blob);
|
|
655
|
-
try {
|
|
656
|
-
return yield this.saveWeb(url, path);
|
|
657
|
-
}
|
|
658
|
-
finally {
|
|
659
|
-
URL.revokeObjectURL(url);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
catch (e) {
|
|
664
|
-
return { success: false, message: (e === null || e === void 0 ? void 0 : e.message) || "Text download failed" };
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
this.saveFile = (input, path) => __awaiter(this, void 0, void 0, function* () {
|
|
668
|
-
const blobRes = yield new FileClass().toBlob(input);
|
|
669
|
-
if (!blobRes.success) {
|
|
670
|
-
return { success: false, message: blobRes.message };
|
|
671
|
-
}
|
|
672
|
-
if (this.isNative) {
|
|
673
|
-
return yield new AIOCapacitor().save(blobRes.result, path);
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
const url = URL.createObjectURL(blobRes.result);
|
|
677
|
-
yield this.saveWeb(url, path);
|
|
678
|
-
return { success: true, message: '' };
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
this.sizeToString = (size) => {
|
|
682
|
-
if (typeof size !== "number")
|
|
683
|
-
size = 0;
|
|
684
|
-
const gb = size / (Math.pow(1024, 3));
|
|
685
|
-
const mb = size / (Math.pow(1024, 2));
|
|
686
|
-
const kb = size / 1024;
|
|
687
|
-
if (gb >= 1)
|
|
688
|
-
return gb.toFixed(2) + " GB";
|
|
689
|
-
if (mb >= 1)
|
|
690
|
-
return mb.toFixed(2) + " MB";
|
|
691
|
-
if (kb >= 1)
|
|
692
|
-
return kb.toFixed(2) + " KB";
|
|
693
|
-
return size + " byte";
|
|
694
|
-
};
|
|
695
|
-
this.isNative = new AIOCapacitor().isNative();
|
|
696
|
-
}
|
|
697
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aio-capacitor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,18 +8,8 @@
|
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"@capacitor/clipboard": "^8.0.1",
|
|
14
|
-
"@capacitor/camera": "^8.2.0",
|
|
15
|
-
"@capacitor/geolocation": "^8.2.0",
|
|
16
|
-
"@capacitor/push-notifications": "^8.1.1",
|
|
17
|
-
"@capacitor-community/text-to-speech": "^8.0.0",
|
|
18
|
-
"@capacitor/filesystem": "^8.1.2",
|
|
19
|
-
"@capacitor/haptics": "^8.0.2",
|
|
20
|
-
"@capacitor/share": "^8.0.1",
|
|
21
|
-
"@capacitor/local-notifications": "^8.2.0",
|
|
22
|
-
"@capacitor-community/keep-awake": "^8.0.1"
|
|
11
|
+
"aio-capacitor-deps": "latest",
|
|
12
|
+
"aio-class":"latest"
|
|
23
13
|
},
|
|
24
14
|
"repository": {
|
|
25
15
|
"type": "git",
|