@aippy/runtime 0.2.0 → 0.2.1
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/dist/audio/index.js +7 -7
- package/dist/core/index.js +29 -43
- package/dist/device/index.js +208 -270
- package/dist/errors-CDEBaBxB.js +26 -0
- package/dist/index/index.js +38 -38
- package/dist/pwa-DPd78fwK.js +342 -0
- package/dist/tweaks/index.js +3 -3
- package/dist/useAudioContext-DaLkaQ8P.js +223 -0
- package/dist/useTweaks-Bc26i-fJ.js +195 -0
- package/dist/utils/index.js +7 -7
- package/package.json +1 -1
- package/dist/errors-DAz5_jDJ.js +0 -25
- package/dist/pwa-BkviTQoN.js +0 -408
- package/dist/useAudioContext-D9Y4gIw9.js +0 -358
- package/dist/useTweaks-mK5PAWOs.js +0 -258
package/dist/device/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var h = Object.defineProperty;
|
|
2
|
+
var p = (n, e, t) => e in n ? h(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var m = (n, e, t) => p(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { c as a } from "../errors-CDEBaBxB.js";
|
|
5
|
+
class g {
|
|
6
|
+
constructor() {
|
|
7
|
+
m(this, "stream", null);
|
|
8
|
+
}
|
|
4
9
|
/**
|
|
5
10
|
* Check if camera is supported
|
|
6
11
|
*/
|
|
@@ -10,23 +15,21 @@ class CameraAPI {
|
|
|
10
15
|
/**
|
|
11
16
|
* Get camera stream
|
|
12
17
|
*/
|
|
13
|
-
async getStream(
|
|
14
|
-
if (!this.isSupported())
|
|
15
|
-
throw
|
|
16
|
-
}
|
|
18
|
+
async getStream(e = {}) {
|
|
19
|
+
if (!this.isSupported())
|
|
20
|
+
throw a("Camera API is not supported", "NOT_SUPPORTED");
|
|
17
21
|
try {
|
|
18
|
-
const
|
|
22
|
+
const t = {
|
|
19
23
|
video: {
|
|
20
|
-
width:
|
|
21
|
-
height:
|
|
22
|
-
facingMode:
|
|
24
|
+
width: e.width,
|
|
25
|
+
height: e.height,
|
|
26
|
+
facingMode: e.facingMode || "environment"
|
|
23
27
|
}
|
|
24
28
|
};
|
|
25
|
-
this.stream = await navigator.mediaDevices.getUserMedia(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`Failed to access camera: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
29
|
+
return this.stream = await navigator.mediaDevices.getUserMedia(t), this.stream;
|
|
30
|
+
} catch (t) {
|
|
31
|
+
throw a(
|
|
32
|
+
`Failed to access camera: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
30
33
|
"PERMISSION_DENIED"
|
|
31
34
|
);
|
|
32
35
|
}
|
|
@@ -34,43 +37,30 @@ class CameraAPI {
|
|
|
34
37
|
/**
|
|
35
38
|
* Capture photo from stream
|
|
36
39
|
*/
|
|
37
|
-
async capturePhoto(
|
|
38
|
-
if (!this.stream)
|
|
39
|
-
throw
|
|
40
|
-
}
|
|
40
|
+
async capturePhoto(e = {}) {
|
|
41
|
+
if (!this.stream)
|
|
42
|
+
throw a("No camera stream available", "NOT_SUPPORTED");
|
|
41
43
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const format = options.format || "jpeg";
|
|
54
|
-
const quality = options.quality === "high" ? 0.9 : options.quality === "medium" ? 0.7 : 0.5;
|
|
55
|
-
const blob = await new Promise((resolve, reject) => {
|
|
56
|
-
canvas.toBlob((blob2) => {
|
|
57
|
-
if (blob2) {
|
|
58
|
-
resolve(blob2);
|
|
59
|
-
} else {
|
|
60
|
-
reject(new Error("Failed to create blob"));
|
|
61
|
-
}
|
|
62
|
-
}, `image/${format}`, quality);
|
|
63
|
-
});
|
|
64
|
-
const dataUrl = canvas.toDataURL(`image/${format}`, quality);
|
|
44
|
+
const t = document.createElement("video");
|
|
45
|
+
t.srcObject = this.stream, t.play();
|
|
46
|
+
const o = document.createElement("canvas"), i = o.getContext("2d");
|
|
47
|
+
if (!i)
|
|
48
|
+
throw a("Failed to get canvas context", "UNKNOWN_ERROR");
|
|
49
|
+
o.width = e.width || t.videoWidth, o.height = e.height || t.videoHeight, i.drawImage(t, 0, 0, o.width, o.height);
|
|
50
|
+
const r = e.format || "jpeg", c = e.quality === "high" ? 0.9 : e.quality === "medium" ? 0.7 : 0.5, s = await new Promise((u, w) => {
|
|
51
|
+
o.toBlob((l) => {
|
|
52
|
+
l ? u(l) : w(new Error("Failed to create blob"));
|
|
53
|
+
}, `image/${r}`, c);
|
|
54
|
+
}), d = o.toDataURL(`image/${r}`, c);
|
|
65
55
|
return {
|
|
66
|
-
blob,
|
|
67
|
-
dataUrl,
|
|
68
|
-
width:
|
|
69
|
-
height:
|
|
56
|
+
blob: s,
|
|
57
|
+
dataUrl: d,
|
|
58
|
+
width: o.width,
|
|
59
|
+
height: o.height
|
|
70
60
|
};
|
|
71
|
-
} catch (
|
|
72
|
-
throw
|
|
73
|
-
`Failed to capture photo: ${
|
|
61
|
+
} catch (t) {
|
|
62
|
+
throw a(
|
|
63
|
+
`Failed to capture photo: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
74
64
|
"UNKNOWN_ERROR"
|
|
75
65
|
);
|
|
76
66
|
}
|
|
@@ -79,14 +69,11 @@ class CameraAPI {
|
|
|
79
69
|
* Stop camera stream
|
|
80
70
|
*/
|
|
81
71
|
stopStream() {
|
|
82
|
-
|
|
83
|
-
this.stream.getTracks().forEach((track) => track.stop());
|
|
84
|
-
this.stream = null;
|
|
85
|
-
}
|
|
72
|
+
this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null);
|
|
86
73
|
}
|
|
87
74
|
}
|
|
88
|
-
const
|
|
89
|
-
class
|
|
75
|
+
const f = new g();
|
|
76
|
+
class v {
|
|
90
77
|
/**
|
|
91
78
|
* Check if geolocation is supported
|
|
92
79
|
*/
|
|
@@ -96,92 +83,88 @@ class GeolocationAPI {
|
|
|
96
83
|
/**
|
|
97
84
|
* Get current position
|
|
98
85
|
*/
|
|
99
|
-
async getCurrentPosition(
|
|
100
|
-
if (!this.isSupported())
|
|
101
|
-
throw
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
maximumAge: options.maximumAge ?? 6e4
|
|
86
|
+
async getCurrentPosition(e = {}) {
|
|
87
|
+
if (!this.isSupported())
|
|
88
|
+
throw a("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
89
|
+
return new Promise((t, o) => {
|
|
90
|
+
const i = {
|
|
91
|
+
enableHighAccuracy: e.enableHighAccuracy ?? !0,
|
|
92
|
+
timeout: e.timeout ?? 1e4,
|
|
93
|
+
maximumAge: e.maximumAge ?? 6e4
|
|
108
94
|
};
|
|
109
95
|
navigator.geolocation.getCurrentPosition(
|
|
110
|
-
(
|
|
111
|
-
const
|
|
112
|
-
latitude:
|
|
113
|
-
longitude:
|
|
114
|
-
accuracy:
|
|
115
|
-
altitude:
|
|
116
|
-
altitudeAccuracy:
|
|
117
|
-
heading:
|
|
118
|
-
speed:
|
|
119
|
-
timestamp:
|
|
96
|
+
(r) => {
|
|
97
|
+
const c = {
|
|
98
|
+
latitude: r.coords.latitude,
|
|
99
|
+
longitude: r.coords.longitude,
|
|
100
|
+
accuracy: r.coords.accuracy,
|
|
101
|
+
altitude: r.coords.altitude ?? void 0,
|
|
102
|
+
altitudeAccuracy: r.coords.altitudeAccuracy ?? void 0,
|
|
103
|
+
heading: r.coords.heading ?? void 0,
|
|
104
|
+
speed: r.coords.speed ?? void 0,
|
|
105
|
+
timestamp: r.timestamp
|
|
120
106
|
};
|
|
121
|
-
|
|
107
|
+
t(c);
|
|
122
108
|
},
|
|
123
|
-
(
|
|
124
|
-
let
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
errorCode = "PERMISSION_DENIED";
|
|
129
|
-
errorMessage = "Geolocation permission denied";
|
|
109
|
+
(r) => {
|
|
110
|
+
let c = "UNKNOWN_ERROR", s = "Unknown geolocation error";
|
|
111
|
+
switch (r.code) {
|
|
112
|
+
case r.PERMISSION_DENIED:
|
|
113
|
+
c = "PERMISSION_DENIED", s = "Geolocation permission denied";
|
|
130
114
|
break;
|
|
131
|
-
case
|
|
132
|
-
|
|
115
|
+
case r.POSITION_UNAVAILABLE:
|
|
116
|
+
s = "Position unavailable";
|
|
133
117
|
break;
|
|
134
|
-
case
|
|
135
|
-
|
|
118
|
+
case r.TIMEOUT:
|
|
119
|
+
s = "Geolocation timeout";
|
|
136
120
|
break;
|
|
137
121
|
}
|
|
138
|
-
|
|
122
|
+
o(a(s, c));
|
|
139
123
|
},
|
|
140
|
-
|
|
124
|
+
i
|
|
141
125
|
);
|
|
142
126
|
});
|
|
143
127
|
}
|
|
144
128
|
/**
|
|
145
129
|
* Watch position changes
|
|
146
130
|
*/
|
|
147
|
-
watchPosition(
|
|
148
|
-
if (!this.isSupported())
|
|
149
|
-
throw
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
maximumAge: options.maximumAge ?? 6e4
|
|
131
|
+
watchPosition(e, t = {}) {
|
|
132
|
+
if (!this.isSupported())
|
|
133
|
+
throw a("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
134
|
+
const o = {
|
|
135
|
+
enableHighAccuracy: t.enableHighAccuracy ?? !0,
|
|
136
|
+
timeout: t.timeout ?? 1e4,
|
|
137
|
+
maximumAge: t.maximumAge ?? 6e4
|
|
155
138
|
};
|
|
156
139
|
return navigator.geolocation.watchPosition(
|
|
157
|
-
(
|
|
158
|
-
const
|
|
159
|
-
latitude:
|
|
160
|
-
longitude:
|
|
161
|
-
accuracy:
|
|
162
|
-
altitude:
|
|
163
|
-
altitudeAccuracy:
|
|
164
|
-
heading:
|
|
165
|
-
speed:
|
|
166
|
-
timestamp:
|
|
140
|
+
(i) => {
|
|
141
|
+
const r = {
|
|
142
|
+
latitude: i.coords.latitude,
|
|
143
|
+
longitude: i.coords.longitude,
|
|
144
|
+
accuracy: i.coords.accuracy,
|
|
145
|
+
altitude: i.coords.altitude ?? void 0,
|
|
146
|
+
altitudeAccuracy: i.coords.altitudeAccuracy ?? void 0,
|
|
147
|
+
heading: i.coords.heading ?? void 0,
|
|
148
|
+
speed: i.coords.speed ?? void 0,
|
|
149
|
+
timestamp: i.timestamp
|
|
167
150
|
};
|
|
168
|
-
|
|
151
|
+
e(r);
|
|
169
152
|
},
|
|
170
|
-
(
|
|
171
|
-
console.error("Geolocation watch error:",
|
|
153
|
+
(i) => {
|
|
154
|
+
console.error("Geolocation watch error:", i);
|
|
172
155
|
},
|
|
173
|
-
|
|
156
|
+
o
|
|
174
157
|
);
|
|
175
158
|
}
|
|
176
159
|
/**
|
|
177
160
|
* Clear position watch
|
|
178
161
|
*/
|
|
179
|
-
clearWatch(
|
|
180
|
-
navigator.geolocation.clearWatch(
|
|
162
|
+
clearWatch(e) {
|
|
163
|
+
navigator.geolocation.clearWatch(e);
|
|
181
164
|
}
|
|
182
165
|
}
|
|
183
|
-
const
|
|
184
|
-
class
|
|
166
|
+
const N = new v();
|
|
167
|
+
class E {
|
|
185
168
|
/**
|
|
186
169
|
* Check if device orientation is supported
|
|
187
170
|
*/
|
|
@@ -198,107 +181,93 @@ class SensorsAPI {
|
|
|
198
181
|
* Get device orientation data
|
|
199
182
|
*/
|
|
200
183
|
async getOrientation() {
|
|
201
|
-
if (!this.isOrientationSupported())
|
|
202
|
-
throw
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
y: event.beta ?? 0,
|
|
210
|
-
z: event.gamma ?? 0,
|
|
184
|
+
if (!this.isOrientationSupported())
|
|
185
|
+
throw a("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
186
|
+
return new Promise((e, t) => {
|
|
187
|
+
const o = (i) => {
|
|
188
|
+
window.removeEventListener("deviceorientation", o), e({
|
|
189
|
+
x: i.alpha ?? 0,
|
|
190
|
+
y: i.beta ?? 0,
|
|
191
|
+
z: i.gamma ?? 0,
|
|
211
192
|
timestamp: Date.now()
|
|
212
193
|
});
|
|
213
194
|
};
|
|
214
|
-
window.addEventListener("deviceorientation",
|
|
215
|
-
|
|
216
|
-
window.removeEventListener("deviceorientation", handleOrientation);
|
|
217
|
-
reject(createError("Device orientation timeout", "UNKNOWN_ERROR"));
|
|
195
|
+
window.addEventListener("deviceorientation", o), setTimeout(() => {
|
|
196
|
+
window.removeEventListener("deviceorientation", o), t(a("Device orientation timeout", "UNKNOWN_ERROR"));
|
|
218
197
|
}, 5e3);
|
|
219
198
|
});
|
|
220
199
|
}
|
|
221
200
|
/**
|
|
222
201
|
* Watch device orientation changes
|
|
223
202
|
*/
|
|
224
|
-
watchOrientation(
|
|
225
|
-
if (!this.isOrientationSupported())
|
|
226
|
-
throw
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
z: event.gamma ?? 0,
|
|
203
|
+
watchOrientation(e) {
|
|
204
|
+
if (!this.isOrientationSupported())
|
|
205
|
+
throw a("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
206
|
+
const t = (o) => {
|
|
207
|
+
e({
|
|
208
|
+
x: o.alpha ?? 0,
|
|
209
|
+
y: o.beta ?? 0,
|
|
210
|
+
z: o.gamma ?? 0,
|
|
233
211
|
timestamp: Date.now()
|
|
234
212
|
});
|
|
235
213
|
};
|
|
236
|
-
window.addEventListener("deviceorientation",
|
|
237
|
-
|
|
238
|
-
window.removeEventListener("deviceorientation", handleOrientation);
|
|
214
|
+
return window.addEventListener("deviceorientation", t), () => {
|
|
215
|
+
window.removeEventListener("deviceorientation", t);
|
|
239
216
|
};
|
|
240
217
|
}
|
|
241
218
|
/**
|
|
242
219
|
* Get device motion data
|
|
243
220
|
*/
|
|
244
221
|
async getMotion() {
|
|
245
|
-
if (!this.isMotionSupported())
|
|
246
|
-
throw
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
y: event.acceleration?.y ?? 0,
|
|
254
|
-
z: event.acceleration?.z ?? 0,
|
|
222
|
+
if (!this.isMotionSupported())
|
|
223
|
+
throw a("Device motion API is not supported", "NOT_SUPPORTED");
|
|
224
|
+
return new Promise((e, t) => {
|
|
225
|
+
const o = (i) => {
|
|
226
|
+
window.removeEventListener("devicemotion", o), e({
|
|
227
|
+
x: i.acceleration?.x ?? 0,
|
|
228
|
+
y: i.acceleration?.y ?? 0,
|
|
229
|
+
z: i.acceleration?.z ?? 0,
|
|
255
230
|
timestamp: Date.now()
|
|
256
231
|
});
|
|
257
232
|
};
|
|
258
|
-
window.addEventListener("devicemotion",
|
|
259
|
-
|
|
260
|
-
window.removeEventListener("devicemotion", handleMotion);
|
|
261
|
-
reject(createError("Device motion timeout", "UNKNOWN_ERROR"));
|
|
233
|
+
window.addEventListener("devicemotion", o), setTimeout(() => {
|
|
234
|
+
window.removeEventListener("devicemotion", o), t(a("Device motion timeout", "UNKNOWN_ERROR"));
|
|
262
235
|
}, 5e3);
|
|
263
236
|
});
|
|
264
237
|
}
|
|
265
238
|
/**
|
|
266
239
|
* Watch device motion changes
|
|
267
240
|
*/
|
|
268
|
-
watchMotion(
|
|
269
|
-
if (!this.isMotionSupported())
|
|
270
|
-
throw
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
z: event.acceleration?.z ?? 0,
|
|
241
|
+
watchMotion(e) {
|
|
242
|
+
if (!this.isMotionSupported())
|
|
243
|
+
throw a("Device motion API is not supported", "NOT_SUPPORTED");
|
|
244
|
+
const t = (o) => {
|
|
245
|
+
e({
|
|
246
|
+
x: o.acceleration?.x ?? 0,
|
|
247
|
+
y: o.acceleration?.y ?? 0,
|
|
248
|
+
z: o.acceleration?.z ?? 0,
|
|
277
249
|
timestamp: Date.now()
|
|
278
250
|
});
|
|
279
251
|
};
|
|
280
|
-
window.addEventListener("devicemotion",
|
|
281
|
-
|
|
282
|
-
window.removeEventListener("devicemotion", handleMotion);
|
|
252
|
+
return window.addEventListener("devicemotion", t), () => {
|
|
253
|
+
window.removeEventListener("devicemotion", t);
|
|
283
254
|
};
|
|
284
255
|
}
|
|
285
256
|
/**
|
|
286
257
|
* Request permission for motion sensors (iOS 13+)
|
|
287
258
|
*/
|
|
288
259
|
async requestPermission() {
|
|
289
|
-
if (!this.isMotionSupported())
|
|
290
|
-
return
|
|
291
|
-
}
|
|
260
|
+
if (!this.isMotionSupported())
|
|
261
|
+
return !1;
|
|
292
262
|
try {
|
|
293
|
-
|
|
294
|
-
return permission?.state === "granted";
|
|
263
|
+
return (await navigator.permissions?.query({ name: "accelerometer" }))?.state === "granted";
|
|
295
264
|
} catch {
|
|
296
|
-
return
|
|
265
|
+
return !1;
|
|
297
266
|
}
|
|
298
267
|
}
|
|
299
268
|
}
|
|
300
|
-
const
|
|
301
|
-
class
|
|
269
|
+
const R = new E();
|
|
270
|
+
class O {
|
|
302
271
|
/**
|
|
303
272
|
* Check if file system access is supported
|
|
304
273
|
*/
|
|
@@ -309,39 +278,33 @@ class FileSystemAPI {
|
|
|
309
278
|
* Check if legacy file input is supported
|
|
310
279
|
*/
|
|
311
280
|
isLegacySupported() {
|
|
312
|
-
return typeof document
|
|
281
|
+
return typeof document < "u" && "createElement" in document;
|
|
313
282
|
}
|
|
314
283
|
/**
|
|
315
284
|
* Open file picker (modern API)
|
|
316
285
|
*/
|
|
317
|
-
async openFilePicker(
|
|
318
|
-
if (!this.isSupported())
|
|
319
|
-
throw
|
|
320
|
-
}
|
|
286
|
+
async openFilePicker(e = {}) {
|
|
287
|
+
if (!this.isSupported())
|
|
288
|
+
throw a("File System Access API is not supported", "NOT_SUPPORTED");
|
|
321
289
|
try {
|
|
322
|
-
const
|
|
323
|
-
types:
|
|
290
|
+
const t = {
|
|
291
|
+
types: e.accept ? [{
|
|
324
292
|
description: "Files",
|
|
325
293
|
accept: Object.fromEntries(
|
|
326
|
-
|
|
294
|
+
e.accept.map((r) => [r, [r]])
|
|
327
295
|
)
|
|
328
296
|
}] : void 0,
|
|
329
|
-
multiple:
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const files = await Promise.all(
|
|
333
|
-
fileHandles.map(async (handle) => handle.getFile())
|
|
297
|
+
multiple: e.multiple ?? !1
|
|
298
|
+
}, o = await window.showOpenFilePicker(t), i = await Promise.all(
|
|
299
|
+
o.map(async (r) => r.getFile())
|
|
334
300
|
);
|
|
335
301
|
return {
|
|
336
|
-
files,
|
|
337
|
-
paths:
|
|
302
|
+
files: i,
|
|
303
|
+
paths: i.map((r) => r.name)
|
|
338
304
|
};
|
|
339
|
-
} catch (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
throw createError(
|
|
344
|
-
`Failed to open file picker: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
305
|
+
} catch (t) {
|
|
306
|
+
throw t instanceof Error && t.name === "AbortError" ? a("File picker was cancelled", "PERMISSION_DENIED") : a(
|
|
307
|
+
`Failed to open file picker: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
345
308
|
"PERMISSION_DENIED"
|
|
346
309
|
);
|
|
347
310
|
}
|
|
@@ -349,55 +312,38 @@ class FileSystemAPI {
|
|
|
349
312
|
/**
|
|
350
313
|
* Open file picker (legacy fallback)
|
|
351
314
|
*/
|
|
352
|
-
async openFilePickerLegacy(
|
|
353
|
-
if (!this.isLegacySupported())
|
|
354
|
-
throw
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const target = event.target;
|
|
363
|
-
const files = Array.from(target.files || []);
|
|
364
|
-
resolve({
|
|
365
|
-
files,
|
|
366
|
-
paths: files.map((file) => file.name)
|
|
315
|
+
async openFilePickerLegacy(e = {}) {
|
|
316
|
+
if (!this.isLegacySupported())
|
|
317
|
+
throw a("File input is not supported", "NOT_SUPPORTED");
|
|
318
|
+
return new Promise((t, o) => {
|
|
319
|
+
const i = document.createElement("input");
|
|
320
|
+
i.type = "file", i.multiple = e.multiple ?? !1, i.accept = e.accept?.join(",") ?? "", i.onchange = (r) => {
|
|
321
|
+
const c = r.target, s = Array.from(c.files || []);
|
|
322
|
+
t({
|
|
323
|
+
files: s,
|
|
324
|
+
paths: s.map((d) => d.name)
|
|
367
325
|
});
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
};
|
|
372
|
-
input.click();
|
|
326
|
+
}, i.oncancel = () => {
|
|
327
|
+
o(a("File picker was cancelled", "PERMISSION_DENIED"));
|
|
328
|
+
}, i.click();
|
|
373
329
|
});
|
|
374
330
|
}
|
|
375
331
|
/**
|
|
376
332
|
* Open file picker with fallback
|
|
377
333
|
*/
|
|
378
|
-
async openFile(
|
|
379
|
-
|
|
380
|
-
return await this.openFilePicker(options);
|
|
381
|
-
} else {
|
|
382
|
-
return await this.openFilePickerLegacy(options);
|
|
383
|
-
}
|
|
334
|
+
async openFile(e = {}) {
|
|
335
|
+
return this.isSupported() ? await this.openFilePicker(e) : await this.openFilePickerLegacy(e);
|
|
384
336
|
}
|
|
385
337
|
/**
|
|
386
338
|
* Save file
|
|
387
339
|
*/
|
|
388
|
-
async saveFile(
|
|
340
|
+
async saveFile(e, t) {
|
|
389
341
|
try {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
a
|
|
394
|
-
|
|
395
|
-
a.click();
|
|
396
|
-
document.body.removeChild(a);
|
|
397
|
-
URL.revokeObjectURL(url);
|
|
398
|
-
} catch (error) {
|
|
399
|
-
throw createError(
|
|
400
|
-
`Failed to save file: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
342
|
+
const o = URL.createObjectURL(e), i = document.createElement("a");
|
|
343
|
+
i.href = o, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(o);
|
|
344
|
+
} catch (o) {
|
|
345
|
+
throw a(
|
|
346
|
+
`Failed to save file: ${o instanceof Error ? o.message : "Unknown error"}`,
|
|
401
347
|
"UNKNOWN_ERROR"
|
|
402
348
|
);
|
|
403
349
|
}
|
|
@@ -405,53 +351,45 @@ class FileSystemAPI {
|
|
|
405
351
|
/**
|
|
406
352
|
* Read file as text
|
|
407
353
|
*/
|
|
408
|
-
async readAsText(
|
|
409
|
-
return new Promise((
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
reader.onerror = () => reject(createError("Failed to read file", "UNKNOWN_ERROR"));
|
|
413
|
-
reader.readAsText(file);
|
|
354
|
+
async readAsText(e) {
|
|
355
|
+
return new Promise((t, o) => {
|
|
356
|
+
const i = new FileReader();
|
|
357
|
+
i.onload = () => t(i.result), i.onerror = () => o(a("Failed to read file", "UNKNOWN_ERROR")), i.readAsText(e);
|
|
414
358
|
});
|
|
415
359
|
}
|
|
416
360
|
/**
|
|
417
361
|
* Read file as data URL
|
|
418
362
|
*/
|
|
419
|
-
async readAsDataURL(
|
|
420
|
-
return new Promise((
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
reader.onerror = () => reject(createError("Failed to read file", "UNKNOWN_ERROR"));
|
|
424
|
-
reader.readAsDataURL(file);
|
|
363
|
+
async readAsDataURL(e) {
|
|
364
|
+
return new Promise((t, o) => {
|
|
365
|
+
const i = new FileReader();
|
|
366
|
+
i.onload = () => t(i.result), i.onerror = () => o(a("Failed to read file", "UNKNOWN_ERROR")), i.readAsDataURL(e);
|
|
425
367
|
});
|
|
426
368
|
}
|
|
427
369
|
}
|
|
428
|
-
const
|
|
429
|
-
function
|
|
430
|
-
return new Promise((
|
|
431
|
-
if ("vibrate" in navigator)
|
|
432
|
-
navigator.vibrate(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const data = {
|
|
370
|
+
const S = new O();
|
|
371
|
+
function D(n) {
|
|
372
|
+
return new Promise((e) => {
|
|
373
|
+
if ("vibrate" in navigator)
|
|
374
|
+
navigator.vibrate(n), e();
|
|
375
|
+
else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.aippyListener) {
|
|
376
|
+
const t = {
|
|
436
377
|
command: "navigator.vibrate",
|
|
437
|
-
parameters:
|
|
378
|
+
parameters: n
|
|
438
379
|
};
|
|
439
|
-
window.webkit.messageHandlers.aippyListener.postMessage(
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
console.warn("Vibration not supported in this environment");
|
|
443
|
-
resolve();
|
|
444
|
-
}
|
|
380
|
+
window.webkit.messageHandlers.aippyListener.postMessage(t), e();
|
|
381
|
+
} else
|
|
382
|
+
console.warn("Vibration not supported in this environment"), e();
|
|
445
383
|
});
|
|
446
384
|
}
|
|
447
385
|
export {
|
|
448
|
-
CameraAPI,
|
|
449
|
-
FileSystemAPI,
|
|
450
|
-
GeolocationAPI,
|
|
451
|
-
SensorsAPI,
|
|
452
|
-
camera,
|
|
453
|
-
fileSystem,
|
|
454
|
-
geolocation,
|
|
455
|
-
sensors,
|
|
456
|
-
vibrate
|
|
386
|
+
g as CameraAPI,
|
|
387
|
+
O as FileSystemAPI,
|
|
388
|
+
v as GeolocationAPI,
|
|
389
|
+
E as SensorsAPI,
|
|
390
|
+
f as camera,
|
|
391
|
+
S as fileSystem,
|
|
392
|
+
N as geolocation,
|
|
393
|
+
R as sensors,
|
|
394
|
+
D as vibrate
|
|
457
395
|
};
|