@aippy/runtime 0.2.7-dev.6 → 0.2.7-dev.7
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/ai/config/index.d.ts +1 -1
- package/dist/ai/config/parser.d.ts +5 -12
- package/dist/ai/errors.d.ts +1 -0
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/index.js +15 -16
- package/dist/{app-version-checker-GLONqMxq.js → app-version-checker-B1UXEcy9.js} +75 -65
- package/dist/{bridge-BKcAlLAd.js → bridge-BQQ3PfSO.js} +51 -51
- package/dist/{container-message-WJolNXso.js → container-message-YB3cWpWj.js} +2 -2
- package/dist/core/errors.d.ts +22 -3
- package/dist/core/index.js +14 -12
- package/dist/device/index.js +194 -194
- package/dist/errors-B3bDbQbD.js +40 -0
- package/dist/{helper-yKJ_6uB-.js → helper-BjRhidue.js} +63 -65
- package/dist/{hooks-DgadJdiM.js → hooks-C7VP176R.js} +1 -1
- package/dist/index/index.js +82 -81
- package/dist/pwa-C5nXU0DN.js +250 -0
- package/dist/tweaks/index.js +1 -1
- package/dist/{useTweaks-QxMRmg7i.js → useTweaks-B7Muzo78.js} +10 -9
- package/dist/user/index.js +3 -3
- package/dist/utils/index.js +2 -2
- package/dist/utils/ui.d.ts +3 -1
- package/package.json +1 -1
- package/dist/errors-CDEBaBxB.js +0 -26
- package/dist/pwa-CilSlaik.js +0 -249
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { c as n, a as i } from "./errors-B3bDbQbD.js";
|
|
2
|
+
class d {
|
|
3
|
+
/**
|
|
4
|
+
* Get Core Web Vitals metrics
|
|
5
|
+
*/
|
|
6
|
+
async getCoreWebVitals() {
|
|
7
|
+
const e = {};
|
|
8
|
+
try {
|
|
9
|
+
const t = performance.getEntriesByName("first-contentful-paint")[0];
|
|
10
|
+
t && (e.fcp = t.startTime);
|
|
11
|
+
const r = performance.getEntriesByType("largest-contentful-paint");
|
|
12
|
+
if (r.length > 0) {
|
|
13
|
+
const o = r[r.length - 1];
|
|
14
|
+
e.lcp = o.startTime;
|
|
15
|
+
}
|
|
16
|
+
const a = performance.getEntriesByType("first-input");
|
|
17
|
+
if (a.length > 0) {
|
|
18
|
+
const o = a[0];
|
|
19
|
+
e.fid = o.processingStart - o.startTime;
|
|
20
|
+
}
|
|
21
|
+
const s = performance.getEntriesByType("layout-shift");
|
|
22
|
+
if (s.length > 0) {
|
|
23
|
+
let o = 0;
|
|
24
|
+
for (const p of s) {
|
|
25
|
+
const l = p;
|
|
26
|
+
l.hadRecentInput || (o += l.value);
|
|
27
|
+
}
|
|
28
|
+
e.cls = o;
|
|
29
|
+
}
|
|
30
|
+
const c = this.calculateTTI();
|
|
31
|
+
c && (e.tti = c);
|
|
32
|
+
} catch (t) {
|
|
33
|
+
console.warn("Failed to get Core Web Vitals:", t);
|
|
34
|
+
}
|
|
35
|
+
return e;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get navigation timing metrics
|
|
39
|
+
*/
|
|
40
|
+
getNavigationTiming() {
|
|
41
|
+
const e = performance.getEntriesByType("navigation")[0];
|
|
42
|
+
return e ? {
|
|
43
|
+
// DNS lookup time
|
|
44
|
+
dns: e.domainLookupEnd - e.domainLookupStart,
|
|
45
|
+
// TCP connection time
|
|
46
|
+
tcp: e.connectEnd - e.connectStart,
|
|
47
|
+
// Request time
|
|
48
|
+
request: e.responseStart - e.requestStart,
|
|
49
|
+
// Response time
|
|
50
|
+
response: e.responseEnd - e.responseStart,
|
|
51
|
+
// DOM processing time
|
|
52
|
+
domProcessing: e.domComplete - e.domInteractive,
|
|
53
|
+
// Total page load time
|
|
54
|
+
total: e.loadEventEnd - e.fetchStart
|
|
55
|
+
} : null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get resource timing metrics
|
|
59
|
+
*/
|
|
60
|
+
getResourceTiming() {
|
|
61
|
+
return performance.getEntriesByType("resource").map((t) => ({
|
|
62
|
+
name: t.name,
|
|
63
|
+
duration: t.duration,
|
|
64
|
+
size: t.transferSize,
|
|
65
|
+
type: this.getResourceType(t.name)
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Measure function execution time
|
|
70
|
+
*/
|
|
71
|
+
measureFunction(e, t) {
|
|
72
|
+
const r = e();
|
|
73
|
+
return t && (performance.mark(`${t}-start`), performance.mark(`${t}-end`), performance.measure(t, `${t}-start`, `${t}-end`)), r;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Measure async function execution time
|
|
77
|
+
*/
|
|
78
|
+
async measureAsyncFunction(e, t) {
|
|
79
|
+
const r = await e();
|
|
80
|
+
return t && (performance.mark(`${t}-start`), performance.mark(`${t}-end`), performance.measure(t, `${t}-start`, `${t}-end`)), r;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get memory usage (if available)
|
|
84
|
+
*/
|
|
85
|
+
getMemoryUsage() {
|
|
86
|
+
if ("memory" in performance) {
|
|
87
|
+
const e = performance.memory;
|
|
88
|
+
return {
|
|
89
|
+
used: e.usedJSHeapSize,
|
|
90
|
+
total: e.totalJSHeapSize,
|
|
91
|
+
limit: e.jsHeapSizeLimit
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
calculateTTI() {
|
|
97
|
+
const e = performance.getEntriesByType("navigation")[0];
|
|
98
|
+
return e ? e.domContentLoadedEventEnd - e.fetchStart : null;
|
|
99
|
+
}
|
|
100
|
+
getResourceType(e) {
|
|
101
|
+
return e.includes(".js") ? "script" : e.includes(".css") ? "stylesheet" : e.includes(".png") || e.includes(".jpg") || e.includes(".gif") ? "image" : e.includes(".woff") || e.includes(".ttf") ? "font" : "other";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const m = new d();
|
|
105
|
+
class u {
|
|
106
|
+
/**
|
|
107
|
+
* Get PWA information
|
|
108
|
+
*/
|
|
109
|
+
getPWAInfo() {
|
|
110
|
+
return {
|
|
111
|
+
isInstalled: this.isInstalled(),
|
|
112
|
+
isInstallable: this.isInstallable(),
|
|
113
|
+
canInstall: this.canInstall(),
|
|
114
|
+
isStandalone: this.isStandalone()
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if PWA is installed
|
|
119
|
+
*/
|
|
120
|
+
isInstalled() {
|
|
121
|
+
return this.isStandalone() || this.isInApp();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if PWA is installable
|
|
125
|
+
*/
|
|
126
|
+
isInstallable() {
|
|
127
|
+
return "serviceWorker" in navigator && "PushManager" in window;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if install prompt is available
|
|
131
|
+
*/
|
|
132
|
+
canInstall() {
|
|
133
|
+
return this.isInstallable() && !this.isInstalled();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Check if running in standalone mode
|
|
137
|
+
*/
|
|
138
|
+
isStandalone() {
|
|
139
|
+
return window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === !0;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if running in app (iOS)
|
|
143
|
+
*/
|
|
144
|
+
isInApp() {
|
|
145
|
+
return window.navigator.standalone === !0;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Register service worker
|
|
149
|
+
*/
|
|
150
|
+
async registerServiceWorker(e) {
|
|
151
|
+
if (!("serviceWorker" in navigator))
|
|
152
|
+
return console.warn("Service Worker not supported"), null;
|
|
153
|
+
try {
|
|
154
|
+
return await navigator.serviceWorker.register(e);
|
|
155
|
+
} catch (t) {
|
|
156
|
+
return console.error("Service Worker registration failed:", t), null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Unregister service worker
|
|
161
|
+
*/
|
|
162
|
+
async unregisterServiceWorker() {
|
|
163
|
+
if (!("serviceWorker" in navigator))
|
|
164
|
+
return !1;
|
|
165
|
+
try {
|
|
166
|
+
const e = await navigator.serviceWorker.getRegistrations();
|
|
167
|
+
for (const t of e)
|
|
168
|
+
await t.unregister();
|
|
169
|
+
return !0;
|
|
170
|
+
} catch (e) {
|
|
171
|
+
return console.error("Service Worker unregistration failed:", e), !1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Request notification permission
|
|
176
|
+
*/
|
|
177
|
+
async requestNotificationPermission() {
|
|
178
|
+
if (!("Notification" in window))
|
|
179
|
+
throw n("Notifications not supported", i.NOT_SUPPORTED);
|
|
180
|
+
return Notification.permission === "granted" ? "granted" : Notification.permission === "denied" ? "denied" : await Notification.requestPermission();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Send notification
|
|
184
|
+
*/
|
|
185
|
+
async sendNotification(e, t) {
|
|
186
|
+
if (!("Notification" in window))
|
|
187
|
+
throw n("Notifications not supported", i.NOT_SUPPORTED);
|
|
188
|
+
if (Notification.permission !== "granted")
|
|
189
|
+
throw n("Notification permission not granted", i.PERMISSION_DENIED);
|
|
190
|
+
const r = new Notification(e, t);
|
|
191
|
+
setTimeout(() => {
|
|
192
|
+
r.close();
|
|
193
|
+
}, 5e3);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Share content using Web Share API
|
|
197
|
+
*/
|
|
198
|
+
async share(e) {
|
|
199
|
+
if (!("share" in navigator))
|
|
200
|
+
throw n("Web Share API not supported", i.NOT_SUPPORTED);
|
|
201
|
+
try {
|
|
202
|
+
await navigator.share(e);
|
|
203
|
+
} catch (t) {
|
|
204
|
+
if (t instanceof Error && t.name !== "AbortError")
|
|
205
|
+
throw n(`Share failed: ${t.message}`, i.OPERATION_FAILED);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Copy text to clipboard
|
|
210
|
+
*/
|
|
211
|
+
async copyToClipboard(e) {
|
|
212
|
+
if (!("clipboard" in navigator))
|
|
213
|
+
throw n("Clipboard API not supported", i.NOT_SUPPORTED);
|
|
214
|
+
try {
|
|
215
|
+
await navigator.clipboard.writeText(e);
|
|
216
|
+
} catch (t) {
|
|
217
|
+
throw n(`Copy to clipboard failed: ${t instanceof Error ? t.message : "Unknown error"}`, i.OPERATION_FAILED);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Read text from clipboard
|
|
222
|
+
*/
|
|
223
|
+
async readFromClipboard() {
|
|
224
|
+
if (!("clipboard" in navigator))
|
|
225
|
+
throw n("Clipboard API not supported", i.NOT_SUPPORTED);
|
|
226
|
+
try {
|
|
227
|
+
return await navigator.clipboard.readText();
|
|
228
|
+
} catch (e) {
|
|
229
|
+
throw n(`Read from clipboard failed: ${e instanceof Error ? e.message : "Unknown error"}`, i.OPERATION_FAILED);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get install prompt event
|
|
234
|
+
*/
|
|
235
|
+
getInstallPromptEvent() {
|
|
236
|
+
return new Promise((e) => {
|
|
237
|
+
const t = (r) => {
|
|
238
|
+
r.preventDefault(), e(r), window.removeEventListener("beforeinstallprompt", t);
|
|
239
|
+
};
|
|
240
|
+
window.addEventListener("beforeinstallprompt", t);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const y = new u();
|
|
245
|
+
export {
|
|
246
|
+
d as P,
|
|
247
|
+
u as a,
|
|
248
|
+
y as b,
|
|
249
|
+
m as p
|
|
250
|
+
};
|
package/dist/tweaks/index.js
CHANGED
|
@@ -2,7 +2,8 @@ var b = Object.defineProperty;
|
|
|
2
2
|
var g = (n, e, t) => e in n ? b(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
3
|
var r = (n, e, t) => g(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { useReducer as v, useEffect as m } from "react";
|
|
5
|
-
|
|
5
|
+
import { b as T, a as C } from "./errors-B3bDbQbD.js";
|
|
6
|
+
class I {
|
|
6
7
|
constructor(e) {
|
|
7
8
|
r(this, "cancelled", !1);
|
|
8
9
|
this.cancelFn = e;
|
|
@@ -22,13 +23,13 @@ class k {
|
|
|
22
23
|
this.listeners.forEach((t) => t(e));
|
|
23
24
|
}
|
|
24
25
|
subscribe(e) {
|
|
25
|
-
return this.listeners.push(e), new
|
|
26
|
+
return this.listeners.push(e), new I(() => {
|
|
26
27
|
const t = this.listeners.indexOf(e);
|
|
27
28
|
t > -1 && this.listeners.splice(t, 1);
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
class
|
|
32
|
+
class O {
|
|
32
33
|
constructor(e, t) {
|
|
33
34
|
r(this, "values", {});
|
|
34
35
|
r(this, "subject", new k());
|
|
@@ -51,7 +52,7 @@ class C {
|
|
|
51
52
|
getValue(e) {
|
|
52
53
|
const t = this.values[e];
|
|
53
54
|
if (t === void 0)
|
|
54
|
-
throw
|
|
55
|
+
throw T(`Tweak key not found in values: ${e}`, C.INVALID_CONFIG);
|
|
55
56
|
return t;
|
|
56
57
|
}
|
|
57
58
|
// React Hook integration
|
|
@@ -67,7 +68,7 @@ class C {
|
|
|
67
68
|
}, [e]), t;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
class
|
|
71
|
+
class R {
|
|
71
72
|
constructor() {
|
|
72
73
|
r(this, "tweaksInstance", null);
|
|
73
74
|
r(this, "tweaksDidWarn", !1);
|
|
@@ -80,7 +81,7 @@ class I {
|
|
|
80
81
|
if (this.tweaksInstance)
|
|
81
82
|
return this.tweaksDidWarn || (this.tweaksDidWarn = !0, console.warn("⚠️ [Aippy Tweaks] tweaks() is expected to only be called once, returning previous value")), this.tweaksInstance;
|
|
82
83
|
this.originalConfig = { ...e };
|
|
83
|
-
const t = new k(), i = new
|
|
84
|
+
const t = new k(), i = new O(t, e), a = {};
|
|
84
85
|
for (const s of Object.keys(e))
|
|
85
86
|
a[s] = {
|
|
86
87
|
useState: () => i.useState(s)
|
|
@@ -172,11 +173,11 @@ class I {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
|
-
const w = new
|
|
176
|
+
const w = new R(), y = {
|
|
176
177
|
tweaks: (n) => w.tweaks(n)
|
|
177
|
-
},
|
|
178
|
+
}, S = y.tweaks;
|
|
178
179
|
typeof window < "u" && (window.aippyTweaksRuntime = y, window.processNativeData = w.processNativeData.bind(w));
|
|
179
180
|
export {
|
|
180
|
-
|
|
181
|
+
S as a,
|
|
181
182
|
y as b
|
|
182
183
|
};
|
package/dist/user/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as o, u as s } from "../hooks-
|
|
2
|
-
import { getAuthTokenAsync as f } from "../bridge-
|
|
3
|
-
import { i as t } from "../app-version-checker-
|
|
1
|
+
import { c as o, u as s } from "../hooks-C7VP176R.js";
|
|
2
|
+
import { getAuthTokenAsync as f } from "../bridge-BQQ3PfSO.js";
|
|
3
|
+
import { i as t } from "../app-version-checker-B1UXEcy9.js";
|
|
4
4
|
export {
|
|
5
5
|
o as clearUserInfoCache,
|
|
6
6
|
f as getAuthTokenAsync,
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as a, a as s, c as o, b as t, g as p, i, p as m, r as n, s as f } from "../app-version-checker-
|
|
2
|
-
import { a as c, P as l, p as P, b as F } from "../pwa-
|
|
1
|
+
import { P as a, a as s, c as o, b as t, g as p, i, p as m, r as n, s as f } from "../app-version-checker-B1UXEcy9.js";
|
|
2
|
+
import { a as c, P as l, p as P, b as F } from "../pwa-C5nXU0DN.js";
|
|
3
3
|
import { j as g } from "../url-c26cuIpu.js";
|
|
4
4
|
export {
|
|
5
5
|
c as PWAUtils,
|
package/dist/utils/ui.d.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* UI Utilities
|
|
3
3
|
* Common UI components for SDK modules
|
|
4
4
|
*/
|
|
5
|
+
export type AlertType = 'update' | 'signin';
|
|
5
6
|
/**
|
|
6
7
|
* 自定义弹窗
|
|
7
8
|
* 用于在各 SDK 模块中显示提示信息
|
|
8
9
|
*
|
|
9
10
|
* @param message - 要显示的消息
|
|
11
|
+
* @param type - 弹窗类型:'update' 发送消息给原生 App,'signin' 发送消息给父窗口
|
|
10
12
|
*/
|
|
11
|
-
export declare function showAlert(message: string): Promise<void>;
|
|
13
|
+
export declare function showAlert(message: string, type?: AlertType): Promise<void>;
|
package/package.json
CHANGED
package/dist/errors-CDEBaBxB.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var e = Object.defineProperty;
|
|
2
|
-
var o = (E, R, N) => R in E ? e(E, R, { enumerable: !0, configurable: !0, writable: !0, value: N }) : E[R] = N;
|
|
3
|
-
var O = (E, R, N) => o(E, typeof R != "symbol" ? R + "" : R, N);
|
|
4
|
-
class I extends Error {
|
|
5
|
-
constructor(N, r = "AIPPY_ERROR", t) {
|
|
6
|
-
super(N);
|
|
7
|
-
O(this, "code");
|
|
8
|
-
O(this, "context");
|
|
9
|
-
this.name = "AippyRuntimeError", this.code = r, this.context = t;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
const _ = {
|
|
13
|
-
NOT_SUPPORTED: "NOT_SUPPORTED",
|
|
14
|
-
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
15
|
-
INVALID_CONFIG: "INVALID_CONFIG",
|
|
16
|
-
NETWORK_ERROR: "NETWORK_ERROR",
|
|
17
|
-
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
18
|
-
};
|
|
19
|
-
function s(E, R = "UNKNOWN_ERROR", N) {
|
|
20
|
-
return new I(E, _[R], N);
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
I as A,
|
|
24
|
-
_ as E,
|
|
25
|
-
s as c
|
|
26
|
-
};
|
package/dist/pwa-CilSlaik.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
class f {
|
|
2
|
-
/**
|
|
3
|
-
* Get Core Web Vitals metrics
|
|
4
|
-
*/
|
|
5
|
-
async getCoreWebVitals() {
|
|
6
|
-
const r = {};
|
|
7
|
-
try {
|
|
8
|
-
const e = performance.getEntriesByName("first-contentful-paint")[0];
|
|
9
|
-
e && (r.fcp = e.startTime);
|
|
10
|
-
const t = performance.getEntriesByType("largest-contentful-paint");
|
|
11
|
-
if (t.length > 0) {
|
|
12
|
-
const n = t[t.length - 1];
|
|
13
|
-
r.lcp = n.startTime;
|
|
14
|
-
}
|
|
15
|
-
const i = performance.getEntriesByType("first-input");
|
|
16
|
-
if (i.length > 0) {
|
|
17
|
-
const n = i[0];
|
|
18
|
-
r.fid = n.processingStart - n.startTime;
|
|
19
|
-
}
|
|
20
|
-
const o = performance.getEntriesByType("layout-shift");
|
|
21
|
-
if (o.length > 0) {
|
|
22
|
-
let n = 0;
|
|
23
|
-
for (const l of o) {
|
|
24
|
-
const s = l;
|
|
25
|
-
s.hadRecentInput || (n += s.value);
|
|
26
|
-
}
|
|
27
|
-
r.cls = n;
|
|
28
|
-
}
|
|
29
|
-
const a = this.calculateTTI();
|
|
30
|
-
a && (r.tti = a);
|
|
31
|
-
} catch (e) {
|
|
32
|
-
console.warn("Failed to get Core Web Vitals:", e);
|
|
33
|
-
}
|
|
34
|
-
return r;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Get navigation timing metrics
|
|
38
|
-
*/
|
|
39
|
-
getNavigationTiming() {
|
|
40
|
-
const r = performance.getEntriesByType("navigation")[0];
|
|
41
|
-
return r ? {
|
|
42
|
-
// DNS lookup time
|
|
43
|
-
dns: r.domainLookupEnd - r.domainLookupStart,
|
|
44
|
-
// TCP connection time
|
|
45
|
-
tcp: r.connectEnd - r.connectStart,
|
|
46
|
-
// Request time
|
|
47
|
-
request: r.responseStart - r.requestStart,
|
|
48
|
-
// Response time
|
|
49
|
-
response: r.responseEnd - r.responseStart,
|
|
50
|
-
// DOM processing time
|
|
51
|
-
domProcessing: r.domComplete - r.domInteractive,
|
|
52
|
-
// Total page load time
|
|
53
|
-
total: r.loadEventEnd - r.fetchStart
|
|
54
|
-
} : null;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get resource timing metrics
|
|
58
|
-
*/
|
|
59
|
-
getResourceTiming() {
|
|
60
|
-
return performance.getEntriesByType("resource").map((e) => ({
|
|
61
|
-
name: e.name,
|
|
62
|
-
duration: e.duration,
|
|
63
|
-
size: e.transferSize,
|
|
64
|
-
type: this.getResourceType(e.name)
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Measure function execution time
|
|
69
|
-
*/
|
|
70
|
-
measureFunction(r, e) {
|
|
71
|
-
const t = r();
|
|
72
|
-
return e && (performance.mark(`${e}-start`), performance.mark(`${e}-end`), performance.measure(e, `${e}-start`, `${e}-end`)), t;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Measure async function execution time
|
|
76
|
-
*/
|
|
77
|
-
async measureAsyncFunction(r, e) {
|
|
78
|
-
const t = await r();
|
|
79
|
-
return e && (performance.mark(`${e}-start`), performance.mark(`${e}-end`), performance.measure(e, `${e}-start`, `${e}-end`)), t;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get memory usage (if available)
|
|
83
|
-
*/
|
|
84
|
-
getMemoryUsage() {
|
|
85
|
-
if ("memory" in performance) {
|
|
86
|
-
const r = performance.memory;
|
|
87
|
-
return {
|
|
88
|
-
used: r.usedJSHeapSize,
|
|
89
|
-
total: r.totalJSHeapSize,
|
|
90
|
-
limit: r.jsHeapSizeLimit
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
calculateTTI() {
|
|
96
|
-
const r = performance.getEntriesByType("navigation")[0];
|
|
97
|
-
return r ? r.domContentLoadedEventEnd - r.fetchStart : null;
|
|
98
|
-
}
|
|
99
|
-
getResourceType(r) {
|
|
100
|
-
return r.includes(".js") ? "script" : r.includes(".css") ? "stylesheet" : r.includes(".png") || r.includes(".jpg") || r.includes(".gif") ? "image" : r.includes(".woff") || r.includes(".ttf") ? "font" : "other";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const p = new f();
|
|
104
|
-
class d {
|
|
105
|
-
/**
|
|
106
|
-
* Get PWA information
|
|
107
|
-
*/
|
|
108
|
-
getPWAInfo() {
|
|
109
|
-
return {
|
|
110
|
-
isInstalled: this.isInstalled(),
|
|
111
|
-
isInstallable: this.isInstallable(),
|
|
112
|
-
canInstall: this.canInstall(),
|
|
113
|
-
isStandalone: this.isStandalone()
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Check if PWA is installed
|
|
118
|
-
*/
|
|
119
|
-
isInstalled() {
|
|
120
|
-
return this.isStandalone() || this.isInApp();
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Check if PWA is installable
|
|
124
|
-
*/
|
|
125
|
-
isInstallable() {
|
|
126
|
-
return "serviceWorker" in navigator && "PushManager" in window;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Check if install prompt is available
|
|
130
|
-
*/
|
|
131
|
-
canInstall() {
|
|
132
|
-
return this.isInstallable() && !this.isInstalled();
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Check if running in standalone mode
|
|
136
|
-
*/
|
|
137
|
-
isStandalone() {
|
|
138
|
-
return window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === !0;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Check if running in app (iOS)
|
|
142
|
-
*/
|
|
143
|
-
isInApp() {
|
|
144
|
-
return window.navigator.standalone === !0;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Register service worker
|
|
148
|
-
*/
|
|
149
|
-
async registerServiceWorker(r) {
|
|
150
|
-
if (!("serviceWorker" in navigator))
|
|
151
|
-
return console.warn("Service Worker not supported"), null;
|
|
152
|
-
try {
|
|
153
|
-
return await navigator.serviceWorker.register(r);
|
|
154
|
-
} catch (e) {
|
|
155
|
-
return console.error("Service Worker registration failed:", e), null;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Unregister service worker
|
|
160
|
-
*/
|
|
161
|
-
async unregisterServiceWorker() {
|
|
162
|
-
if (!("serviceWorker" in navigator))
|
|
163
|
-
return !1;
|
|
164
|
-
try {
|
|
165
|
-
const r = await navigator.serviceWorker.getRegistrations();
|
|
166
|
-
for (const e of r)
|
|
167
|
-
await e.unregister();
|
|
168
|
-
return !0;
|
|
169
|
-
} catch (r) {
|
|
170
|
-
return console.error("Service Worker unregistration failed:", r), !1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Request notification permission
|
|
175
|
-
*/
|
|
176
|
-
async requestNotificationPermission() {
|
|
177
|
-
if (!("Notification" in window))
|
|
178
|
-
throw new Error("Notifications not supported");
|
|
179
|
-
return Notification.permission === "granted" ? "granted" : Notification.permission === "denied" ? "denied" : await Notification.requestPermission();
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Send notification
|
|
183
|
-
*/
|
|
184
|
-
async sendNotification(r, e) {
|
|
185
|
-
if (!("Notification" in window))
|
|
186
|
-
throw new Error("Notifications not supported");
|
|
187
|
-
if (Notification.permission !== "granted")
|
|
188
|
-
throw new Error("Notification permission not granted");
|
|
189
|
-
const t = new Notification(r, e);
|
|
190
|
-
setTimeout(() => {
|
|
191
|
-
t.close();
|
|
192
|
-
}, 5e3);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Share content using Web Share API
|
|
196
|
-
*/
|
|
197
|
-
async share(r) {
|
|
198
|
-
if (!("share" in navigator))
|
|
199
|
-
throw new Error("Web Share API not supported");
|
|
200
|
-
try {
|
|
201
|
-
await navigator.share(r);
|
|
202
|
-
} catch (e) {
|
|
203
|
-
if (e instanceof Error && e.name !== "AbortError")
|
|
204
|
-
throw new Error(`Share failed: ${e.message}`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Copy text to clipboard
|
|
209
|
-
*/
|
|
210
|
-
async copyToClipboard(r) {
|
|
211
|
-
if (!("clipboard" in navigator))
|
|
212
|
-
throw new Error("Clipboard API not supported");
|
|
213
|
-
try {
|
|
214
|
-
await navigator.clipboard.writeText(r);
|
|
215
|
-
} catch (e) {
|
|
216
|
-
throw new Error(`Copy to clipboard failed: ${e instanceof Error ? e.message : "Unknown error"}`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Read text from clipboard
|
|
221
|
-
*/
|
|
222
|
-
async readFromClipboard() {
|
|
223
|
-
if (!("clipboard" in navigator))
|
|
224
|
-
throw new Error("Clipboard API not supported");
|
|
225
|
-
try {
|
|
226
|
-
return await navigator.clipboard.readText();
|
|
227
|
-
} catch (r) {
|
|
228
|
-
throw new Error(`Read from clipboard failed: ${r instanceof Error ? r.message : "Unknown error"}`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Get install prompt event
|
|
233
|
-
*/
|
|
234
|
-
getInstallPromptEvent() {
|
|
235
|
-
return new Promise((r) => {
|
|
236
|
-
const e = (t) => {
|
|
237
|
-
t.preventDefault(), r(t), window.removeEventListener("beforeinstallprompt", e);
|
|
238
|
-
};
|
|
239
|
-
window.addEventListener("beforeinstallprompt", e);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const u = new d();
|
|
244
|
-
export {
|
|
245
|
-
f as P,
|
|
246
|
-
d as a,
|
|
247
|
-
u as b,
|
|
248
|
-
p
|
|
249
|
-
};
|