@capgo/capacitor-device-info 8.0.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.
@@ -0,0 +1,182 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ const DEFAULT_INTERVAL_MS = 1000;
3
+ const MIN_INTERVAL_MS = 250;
4
+ export class DeviceInfoWeb extends WebPlugin {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.timer = null;
8
+ this.samplesEmitted = 0;
9
+ this.isEmitting = false;
10
+ }
11
+ async getInfo() {
12
+ return {
13
+ timestamp: Date.now(),
14
+ platform: 'web',
15
+ cpu: {
16
+ cores: navigator.hardwareConcurrency || 1,
17
+ usagePercent: null,
18
+ },
19
+ memory: this.getMemoryInfo(),
20
+ storage: await this.getStorageInfo(),
21
+ gpu: this.getGpuInfo(),
22
+ sensors: this.getOnboardSensorsInfo(),
23
+ };
24
+ }
25
+ async startMonitoring(options = {}) {
26
+ await this.stopMonitoring();
27
+ const intervalMs = this.normalizeInterval(options.intervalMs);
28
+ const now = Date.now();
29
+ this.intervalMs = intervalMs;
30
+ this.startedAt = now;
31
+ this.samplesEmitted = 0;
32
+ this.sampleLimit = this.normalizePositiveInteger(options.sampleCount);
33
+ this.stopAt = this.normalizePositiveNumber(options.durationMs) ? now + Number(options.durationMs) : undefined;
34
+ if (options.emitImmediately !== false) {
35
+ await this.emitSample();
36
+ }
37
+ this.timer = setInterval(() => {
38
+ void this.emitSample();
39
+ }, intervalMs);
40
+ return {
41
+ monitoring: true,
42
+ intervalMs,
43
+ startedAt: now,
44
+ };
45
+ }
46
+ async stopMonitoring() {
47
+ if (this.timer) {
48
+ clearInterval(this.timer);
49
+ }
50
+ this.timer = null;
51
+ this.startedAt = undefined;
52
+ this.intervalMs = undefined;
53
+ this.sampleLimit = undefined;
54
+ this.stopAt = undefined;
55
+ this.samplesEmitted = 0;
56
+ return { monitoring: false };
57
+ }
58
+ async isMonitoring() {
59
+ return {
60
+ monitoring: this.timer !== null,
61
+ intervalMs: this.intervalMs,
62
+ startedAt: this.startedAt,
63
+ samplesEmitted: this.samplesEmitted,
64
+ };
65
+ }
66
+ async addListener(eventName, listenerFunc) {
67
+ return super.addListener(eventName, listenerFunc);
68
+ }
69
+ async removeAllListeners() {
70
+ await super.removeAllListeners();
71
+ }
72
+ async getPluginVersion() {
73
+ return { version: 'web' };
74
+ }
75
+ async emitSample() {
76
+ if (this.isEmitting || !this.startedAt) {
77
+ return;
78
+ }
79
+ this.isEmitting = true;
80
+ try {
81
+ const snapshot = await this.getInfo();
82
+ this.samplesEmitted += 1;
83
+ const event = Object.assign(Object.assign({}, snapshot), { sequence: this.samplesEmitted, startedAt: this.startedAt, elapsedMs: snapshot.timestamp - this.startedAt });
84
+ this.notifyListeners('deviceInfoUpdate', event);
85
+ if (this.shouldStop()) {
86
+ await this.stopMonitoring();
87
+ }
88
+ }
89
+ finally {
90
+ this.isEmitting = false;
91
+ }
92
+ }
93
+ getMemoryInfo() {
94
+ var _a, _b;
95
+ const nav = navigator;
96
+ const perf = performance;
97
+ const totalBytes = nav.deviceMemory ? nav.deviceMemory * 1024 * 1024 * 1024 : undefined;
98
+ const appUsedBytes = (_a = perf.memory) === null || _a === void 0 ? void 0 : _a.usedJSHeapSize;
99
+ const appLimitBytes = (_b = perf.memory) === null || _b === void 0 ? void 0 : _b.jsHeapSizeLimit;
100
+ return {
101
+ totalBytes,
102
+ appUsedBytes,
103
+ appLimitBytes,
104
+ usedPercent: totalBytes && appUsedBytes ? this.toPercent(appUsedBytes, totalBytes) : undefined,
105
+ pressure: 'unknown',
106
+ };
107
+ }
108
+ async getStorageInfo() {
109
+ var _a;
110
+ if (!((_a = navigator.storage) === null || _a === void 0 ? void 0 : _a.estimate)) {
111
+ return {};
112
+ }
113
+ const estimate = await navigator.storage.estimate();
114
+ const totalBytes = estimate.quota;
115
+ const usedBytes = estimate.usage;
116
+ return {
117
+ totalBytes,
118
+ usedBytes,
119
+ freeBytes: totalBytes !== undefined && usedBytes !== undefined ? Math.max(totalBytes - usedBytes, 0) : undefined,
120
+ usedPercent: totalBytes && usedBytes !== undefined ? this.toPercent(usedBytes, totalBytes) : undefined,
121
+ };
122
+ }
123
+ getGpuInfo() {
124
+ var _a, _b;
125
+ const canvas = document.createElement('canvas');
126
+ const gl = (_a = canvas.getContext('webgl2')) !== null && _a !== void 0 ? _a : canvas.getContext('webgl');
127
+ if (!gl) {
128
+ return undefined;
129
+ }
130
+ const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
131
+ const gpu = {
132
+ api: 'webgl',
133
+ version: gl.getParameter(gl.VERSION),
134
+ maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
135
+ };
136
+ if (debugInfo) {
137
+ gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
138
+ gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
139
+ }
140
+ else {
141
+ gpu.vendor = gl.getParameter(gl.VENDOR);
142
+ gpu.renderer = gl.getParameter(gl.RENDERER);
143
+ }
144
+ (_b = gl.getExtension('WEBGL_lose_context')) === null || _b === void 0 ? void 0 : _b.loseContext();
145
+ return gpu;
146
+ }
147
+ getOnboardSensorsInfo() {
148
+ return {
149
+ availableSensors: [],
150
+ readings: [],
151
+ };
152
+ }
153
+ shouldStop() {
154
+ const reachedSampleLimit = this.sampleLimit !== undefined && this.samplesEmitted >= this.sampleLimit;
155
+ const reachedDuration = this.stopAt !== undefined && Date.now() >= this.stopAt;
156
+ return reachedSampleLimit || reachedDuration;
157
+ }
158
+ normalizeInterval(intervalMs) {
159
+ if (!Number.isFinite(intervalMs)) {
160
+ return DEFAULT_INTERVAL_MS;
161
+ }
162
+ return Math.max(Math.round(Number(intervalMs)), MIN_INTERVAL_MS);
163
+ }
164
+ normalizePositiveInteger(value) {
165
+ if (!Number.isFinite(value)) {
166
+ return undefined;
167
+ }
168
+ const normalized = Math.floor(Number(value));
169
+ return normalized > 0 ? normalized : undefined;
170
+ }
171
+ normalizePositiveNumber(value) {
172
+ if (!Number.isFinite(value)) {
173
+ return undefined;
174
+ }
175
+ const normalized = Number(value);
176
+ return normalized > 0 ? normalized : undefined;
177
+ }
178
+ toPercent(value, total) {
179
+ return total > 0 ? Math.min(Math.max((value / total) * 100, 0), 100) : 0;
180
+ }
181
+ }
182
+ //# 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;AAgC5C,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACjC,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,OAAO,aAAc,SAAQ,SAAS;IAA5C;;QACU,UAAK,GAAuB,IAAI,CAAC;QAGjC,mBAAc,GAAG,CAAC,CAAC;QAGnB,eAAU,GAAG,KAAK,CAAC;IA2M7B,CAAC;IAzMC,KAAK,CAAC,OAAO;QACX,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,QAAQ,EAAE,KAAK;YACf,GAAG,EAAE;gBACH,KAAK,EAAE,SAAS,CAAC,mBAAmB,IAAI,CAAC;gBACzC,YAAY,EAAE,IAAI;aACnB;YACD,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE;YAC5B,OAAO,EAAE,MAAM,IAAI,CAAC,cAAc,EAAE;YACpC,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE;YACtB,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE;SACtC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,UAA6B,EAAE;QACnD,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5B,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IA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AAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nimport type {\n DeviceInfoPlugin,\n DeviceInfoSnapshot,\n DeviceInfoUpdate,\n GpuInfo,\n MemoryInfo,\n MonitoringOptions,\n MonitoringState,\n OnboardSensorsInfo,\n PluginVersionResult,\n StartMonitoringResult,\n StopMonitoringResult,\n StorageInfo,\n} from './definitions';\n\ntype TimerHandle = ReturnType<typeof setInterval>;\n\ninterface NavigatorWithDeviceMemory extends Navigator {\n deviceMemory?: number;\n}\n\ninterface PerformanceWithMemory extends Performance {\n memory?: {\n jsHeapSizeLimit?: number;\n totalJSHeapSize?: number;\n usedJSHeapSize?: number;\n };\n}\n\nconst DEFAULT_INTERVAL_MS = 1000;\nconst MIN_INTERVAL_MS = 250;\n\nexport class DeviceInfoWeb extends WebPlugin implements DeviceInfoPlugin {\n private timer: TimerHandle | null = null;\n private startedAt: number | undefined;\n private intervalMs: number | undefined;\n private samplesEmitted = 0;\n private sampleLimit: number | undefined;\n private stopAt: number | undefined;\n private isEmitting = false;\n\n async getInfo(): Promise<DeviceInfoSnapshot> {\n return {\n timestamp: Date.now(),\n platform: 'web',\n cpu: {\n cores: navigator.hardwareConcurrency || 1,\n usagePercent: null,\n },\n memory: this.getMemoryInfo(),\n storage: await this.getStorageInfo(),\n gpu: this.getGpuInfo(),\n sensors: this.getOnboardSensorsInfo(),\n };\n }\n\n async startMonitoring(options: MonitoringOptions = {}): Promise<StartMonitoringResult> {\n await this.stopMonitoring();\n\n const intervalMs = this.normalizeInterval(options.intervalMs);\n const now = Date.now();\n this.intervalMs = intervalMs;\n this.startedAt = now;\n this.samplesEmitted = 0;\n this.sampleLimit = this.normalizePositiveInteger(options.sampleCount);\n this.stopAt = this.normalizePositiveNumber(options.durationMs) ? now + Number(options.durationMs) : undefined;\n\n if (options.emitImmediately !== false) {\n await this.emitSample();\n }\n\n this.timer = setInterval(() => {\n void this.emitSample();\n }, intervalMs);\n\n return {\n monitoring: true,\n intervalMs,\n startedAt: now,\n };\n }\n\n async stopMonitoring(): Promise<StopMonitoringResult> {\n if (this.timer) {\n clearInterval(this.timer);\n }\n this.timer = null;\n this.startedAt = undefined;\n this.intervalMs = undefined;\n this.sampleLimit = undefined;\n this.stopAt = undefined;\n this.samplesEmitted = 0;\n return { monitoring: false };\n }\n\n async isMonitoring(): Promise<MonitoringState> {\n return {\n monitoring: this.timer !== null,\n intervalMs: this.intervalMs,\n startedAt: this.startedAt,\n samplesEmitted: this.samplesEmitted,\n };\n }\n\n async addListener(\n eventName: 'deviceInfoUpdate',\n listenerFunc: (event: DeviceInfoUpdate) => void,\n ): Promise<PluginListenerHandle> {\n return super.addListener(eventName, listenerFunc);\n }\n\n async removeAllListeners(): Promise<void> {\n await super.removeAllListeners();\n }\n\n async getPluginVersion(): Promise<PluginVersionResult> {\n return { version: 'web' };\n }\n\n private async emitSample(): Promise<void> {\n if (this.isEmitting || !this.startedAt) {\n return;\n }\n\n this.isEmitting = true;\n try {\n const snapshot = await this.getInfo();\n this.samplesEmitted += 1;\n const event: DeviceInfoUpdate = {\n ...snapshot,\n sequence: this.samplesEmitted,\n startedAt: this.startedAt,\n elapsedMs: snapshot.timestamp - this.startedAt,\n };\n this.notifyListeners('deviceInfoUpdate', event);\n\n if (this.shouldStop()) {\n await this.stopMonitoring();\n }\n } finally {\n this.isEmitting = false;\n }\n }\n\n private getMemoryInfo(): MemoryInfo {\n const nav = navigator as NavigatorWithDeviceMemory;\n const perf = performance as PerformanceWithMemory;\n const totalBytes = nav.deviceMemory ? nav.deviceMemory * 1024 * 1024 * 1024 : undefined;\n const appUsedBytes = perf.memory?.usedJSHeapSize;\n const appLimitBytes = perf.memory?.jsHeapSizeLimit;\n\n return {\n totalBytes,\n appUsedBytes,\n appLimitBytes,\n usedPercent: totalBytes && appUsedBytes ? this.toPercent(appUsedBytes, totalBytes) : undefined,\n pressure: 'unknown',\n };\n }\n\n private async getStorageInfo(): Promise<StorageInfo> {\n if (!navigator.storage?.estimate) {\n return {};\n }\n\n const estimate = await navigator.storage.estimate();\n const totalBytes = estimate.quota;\n const usedBytes = estimate.usage;\n\n return {\n totalBytes,\n usedBytes,\n freeBytes: totalBytes !== undefined && usedBytes !== undefined ? Math.max(totalBytes - usedBytes, 0) : undefined,\n usedPercent: totalBytes && usedBytes !== undefined ? this.toPercent(usedBytes, totalBytes) : undefined,\n };\n }\n\n private getGpuInfo(): GpuInfo | undefined {\n const canvas = document.createElement('canvas');\n const gl = canvas.getContext('webgl2') ?? canvas.getContext('webgl');\n if (!gl) {\n return undefined;\n }\n\n const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');\n const gpu: GpuInfo = {\n api: 'webgl',\n version: gl.getParameter(gl.VERSION) as string,\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE) as number,\n };\n\n if (debugInfo) {\n gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) as string;\n gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) as string;\n } else {\n gpu.vendor = gl.getParameter(gl.VENDOR) as string;\n gpu.renderer = gl.getParameter(gl.RENDERER) as string;\n }\n\n gl.getExtension('WEBGL_lose_context')?.loseContext();\n return gpu;\n }\n\n private getOnboardSensorsInfo(): OnboardSensorsInfo {\n return {\n availableSensors: [],\n readings: [],\n };\n }\n\n private shouldStop(): boolean {\n const reachedSampleLimit = this.sampleLimit !== undefined && this.samplesEmitted >= this.sampleLimit;\n const reachedDuration = this.stopAt !== undefined && Date.now() >= this.stopAt;\n return reachedSampleLimit || reachedDuration;\n }\n\n private normalizeInterval(intervalMs: number | undefined): number {\n if (!Number.isFinite(intervalMs)) {\n return DEFAULT_INTERVAL_MS;\n }\n return Math.max(Math.round(Number(intervalMs)), MIN_INTERVAL_MS);\n }\n\n private normalizePositiveInteger(value: number | undefined): number | undefined {\n if (!Number.isFinite(value)) {\n return undefined;\n }\n const normalized = Math.floor(Number(value));\n return normalized > 0 ? normalized : undefined;\n }\n\n private normalizePositiveNumber(value: number | undefined): number | undefined {\n if (!Number.isFinite(value)) {\n return undefined;\n }\n const normalized = Number(value);\n return normalized > 0 ? normalized : undefined;\n }\n\n private toPercent(value: number, total: number): number {\n return total > 0 ? Math.min(Math.max((value / total) * 100, 0), 100) : 0;\n }\n}\n"]}
@@ -0,0 +1,196 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const DeviceInfo = core.registerPlugin('DeviceInfo', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.DeviceInfoWeb()),
7
+ });
8
+
9
+ const DEFAULT_INTERVAL_MS = 1000;
10
+ const MIN_INTERVAL_MS = 250;
11
+ class DeviceInfoWeb extends core.WebPlugin {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.timer = null;
15
+ this.samplesEmitted = 0;
16
+ this.isEmitting = false;
17
+ }
18
+ async getInfo() {
19
+ return {
20
+ timestamp: Date.now(),
21
+ platform: 'web',
22
+ cpu: {
23
+ cores: navigator.hardwareConcurrency || 1,
24
+ usagePercent: null,
25
+ },
26
+ memory: this.getMemoryInfo(),
27
+ storage: await this.getStorageInfo(),
28
+ gpu: this.getGpuInfo(),
29
+ sensors: this.getOnboardSensorsInfo(),
30
+ };
31
+ }
32
+ async startMonitoring(options = {}) {
33
+ await this.stopMonitoring();
34
+ const intervalMs = this.normalizeInterval(options.intervalMs);
35
+ const now = Date.now();
36
+ this.intervalMs = intervalMs;
37
+ this.startedAt = now;
38
+ this.samplesEmitted = 0;
39
+ this.sampleLimit = this.normalizePositiveInteger(options.sampleCount);
40
+ this.stopAt = this.normalizePositiveNumber(options.durationMs) ? now + Number(options.durationMs) : undefined;
41
+ if (options.emitImmediately !== false) {
42
+ await this.emitSample();
43
+ }
44
+ this.timer = setInterval(() => {
45
+ void this.emitSample();
46
+ }, intervalMs);
47
+ return {
48
+ monitoring: true,
49
+ intervalMs,
50
+ startedAt: now,
51
+ };
52
+ }
53
+ async stopMonitoring() {
54
+ if (this.timer) {
55
+ clearInterval(this.timer);
56
+ }
57
+ this.timer = null;
58
+ this.startedAt = undefined;
59
+ this.intervalMs = undefined;
60
+ this.sampleLimit = undefined;
61
+ this.stopAt = undefined;
62
+ this.samplesEmitted = 0;
63
+ return { monitoring: false };
64
+ }
65
+ async isMonitoring() {
66
+ return {
67
+ monitoring: this.timer !== null,
68
+ intervalMs: this.intervalMs,
69
+ startedAt: this.startedAt,
70
+ samplesEmitted: this.samplesEmitted,
71
+ };
72
+ }
73
+ async addListener(eventName, listenerFunc) {
74
+ return super.addListener(eventName, listenerFunc);
75
+ }
76
+ async removeAllListeners() {
77
+ await super.removeAllListeners();
78
+ }
79
+ async getPluginVersion() {
80
+ return { version: 'web' };
81
+ }
82
+ async emitSample() {
83
+ if (this.isEmitting || !this.startedAt) {
84
+ return;
85
+ }
86
+ this.isEmitting = true;
87
+ try {
88
+ const snapshot = await this.getInfo();
89
+ this.samplesEmitted += 1;
90
+ const event = Object.assign(Object.assign({}, snapshot), { sequence: this.samplesEmitted, startedAt: this.startedAt, elapsedMs: snapshot.timestamp - this.startedAt });
91
+ this.notifyListeners('deviceInfoUpdate', event);
92
+ if (this.shouldStop()) {
93
+ await this.stopMonitoring();
94
+ }
95
+ }
96
+ finally {
97
+ this.isEmitting = false;
98
+ }
99
+ }
100
+ getMemoryInfo() {
101
+ var _a, _b;
102
+ const nav = navigator;
103
+ const perf = performance;
104
+ const totalBytes = nav.deviceMemory ? nav.deviceMemory * 1024 * 1024 * 1024 : undefined;
105
+ const appUsedBytes = (_a = perf.memory) === null || _a === void 0 ? void 0 : _a.usedJSHeapSize;
106
+ const appLimitBytes = (_b = perf.memory) === null || _b === void 0 ? void 0 : _b.jsHeapSizeLimit;
107
+ return {
108
+ totalBytes,
109
+ appUsedBytes,
110
+ appLimitBytes,
111
+ usedPercent: totalBytes && appUsedBytes ? this.toPercent(appUsedBytes, totalBytes) : undefined,
112
+ pressure: 'unknown',
113
+ };
114
+ }
115
+ async getStorageInfo() {
116
+ var _a;
117
+ if (!((_a = navigator.storage) === null || _a === void 0 ? void 0 : _a.estimate)) {
118
+ return {};
119
+ }
120
+ const estimate = await navigator.storage.estimate();
121
+ const totalBytes = estimate.quota;
122
+ const usedBytes = estimate.usage;
123
+ return {
124
+ totalBytes,
125
+ usedBytes,
126
+ freeBytes: totalBytes !== undefined && usedBytes !== undefined ? Math.max(totalBytes - usedBytes, 0) : undefined,
127
+ usedPercent: totalBytes && usedBytes !== undefined ? this.toPercent(usedBytes, totalBytes) : undefined,
128
+ };
129
+ }
130
+ getGpuInfo() {
131
+ var _a, _b;
132
+ const canvas = document.createElement('canvas');
133
+ const gl = (_a = canvas.getContext('webgl2')) !== null && _a !== void 0 ? _a : canvas.getContext('webgl');
134
+ if (!gl) {
135
+ return undefined;
136
+ }
137
+ const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
138
+ const gpu = {
139
+ api: 'webgl',
140
+ version: gl.getParameter(gl.VERSION),
141
+ maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
142
+ };
143
+ if (debugInfo) {
144
+ gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
145
+ gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
146
+ }
147
+ else {
148
+ gpu.vendor = gl.getParameter(gl.VENDOR);
149
+ gpu.renderer = gl.getParameter(gl.RENDERER);
150
+ }
151
+ (_b = gl.getExtension('WEBGL_lose_context')) === null || _b === void 0 ? void 0 : _b.loseContext();
152
+ return gpu;
153
+ }
154
+ getOnboardSensorsInfo() {
155
+ return {
156
+ availableSensors: [],
157
+ readings: [],
158
+ };
159
+ }
160
+ shouldStop() {
161
+ const reachedSampleLimit = this.sampleLimit !== undefined && this.samplesEmitted >= this.sampleLimit;
162
+ const reachedDuration = this.stopAt !== undefined && Date.now() >= this.stopAt;
163
+ return reachedSampleLimit || reachedDuration;
164
+ }
165
+ normalizeInterval(intervalMs) {
166
+ if (!Number.isFinite(intervalMs)) {
167
+ return DEFAULT_INTERVAL_MS;
168
+ }
169
+ return Math.max(Math.round(Number(intervalMs)), MIN_INTERVAL_MS);
170
+ }
171
+ normalizePositiveInteger(value) {
172
+ if (!Number.isFinite(value)) {
173
+ return undefined;
174
+ }
175
+ const normalized = Math.floor(Number(value));
176
+ return normalized > 0 ? normalized : undefined;
177
+ }
178
+ normalizePositiveNumber(value) {
179
+ if (!Number.isFinite(value)) {
180
+ return undefined;
181
+ }
182
+ const normalized = Number(value);
183
+ return normalized > 0 ? normalized : undefined;
184
+ }
185
+ toPercent(value, total) {
186
+ return total > 0 ? Math.min(Math.max((value / total) * 100, 0), 100) : 0;
187
+ }
188
+ }
189
+
190
+ var web = /*#__PURE__*/Object.freeze({
191
+ __proto__: null,
192
+ DeviceInfoWeb: DeviceInfoWeb
193
+ });
194
+
195
+ exports.DeviceInfo = DeviceInfo;
196
+ //# 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 DeviceInfo = registerPlugin('DeviceInfo', {\n web: () => import('./web').then((m) => new m.DeviceInfoWeb()),\n});\nexport * from './definitions';\nexport { DeviceInfo };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst DEFAULT_INTERVAL_MS = 1000;\nconst MIN_INTERVAL_MS = 250;\nexport class DeviceInfoWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.timer = null;\n this.samplesEmitted = 0;\n this.isEmitting = false;\n }\n async getInfo() {\n return {\n timestamp: Date.now(),\n platform: 'web',\n cpu: {\n cores: navigator.hardwareConcurrency || 1,\n usagePercent: null,\n },\n memory: this.getMemoryInfo(),\n storage: await this.getStorageInfo(),\n gpu: this.getGpuInfo(),\n sensors: this.getOnboardSensorsInfo(),\n };\n }\n async startMonitoring(options = {}) {\n await this.stopMonitoring();\n const intervalMs = this.normalizeInterval(options.intervalMs);\n const now = Date.now();\n this.intervalMs = intervalMs;\n this.startedAt = now;\n this.samplesEmitted = 0;\n this.sampleLimit = this.normalizePositiveInteger(options.sampleCount);\n this.stopAt = this.normalizePositiveNumber(options.durationMs) ? now + Number(options.durationMs) : undefined;\n if (options.emitImmediately !== false) {\n await this.emitSample();\n }\n this.timer = setInterval(() => {\n void this.emitSample();\n }, intervalMs);\n return {\n monitoring: true,\n intervalMs,\n startedAt: now,\n };\n }\n async stopMonitoring() {\n if (this.timer) {\n clearInterval(this.timer);\n }\n this.timer = null;\n this.startedAt = undefined;\n this.intervalMs = undefined;\n this.sampleLimit = undefined;\n this.stopAt = undefined;\n this.samplesEmitted = 0;\n return { monitoring: false };\n }\n async isMonitoring() {\n return {\n monitoring: this.timer !== null,\n intervalMs: this.intervalMs,\n startedAt: this.startedAt,\n samplesEmitted: this.samplesEmitted,\n };\n }\n async addListener(eventName, listenerFunc) {\n return super.addListener(eventName, listenerFunc);\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n async emitSample() {\n if (this.isEmitting || !this.startedAt) {\n return;\n }\n this.isEmitting = true;\n try {\n const snapshot = await this.getInfo();\n this.samplesEmitted += 1;\n const event = Object.assign(Object.assign({}, snapshot), { sequence: this.samplesEmitted, startedAt: this.startedAt, elapsedMs: snapshot.timestamp - this.startedAt });\n this.notifyListeners('deviceInfoUpdate', event);\n if (this.shouldStop()) {\n await this.stopMonitoring();\n }\n }\n finally {\n this.isEmitting = false;\n }\n }\n getMemoryInfo() {\n var _a, _b;\n const nav = navigator;\n const perf = performance;\n const totalBytes = nav.deviceMemory ? nav.deviceMemory * 1024 * 1024 * 1024 : undefined;\n const appUsedBytes = (_a = perf.memory) === null || _a === void 0 ? void 0 : _a.usedJSHeapSize;\n const appLimitBytes = (_b = perf.memory) === null || _b === void 0 ? void 0 : _b.jsHeapSizeLimit;\n return {\n totalBytes,\n appUsedBytes,\n appLimitBytes,\n usedPercent: totalBytes && appUsedBytes ? this.toPercent(appUsedBytes, totalBytes) : undefined,\n pressure: 'unknown',\n };\n }\n async getStorageInfo() {\n var _a;\n if (!((_a = navigator.storage) === null || _a === void 0 ? void 0 : _a.estimate)) {\n return {};\n }\n const estimate = await navigator.storage.estimate();\n const totalBytes = estimate.quota;\n const usedBytes = estimate.usage;\n return {\n totalBytes,\n usedBytes,\n freeBytes: totalBytes !== undefined && usedBytes !== undefined ? Math.max(totalBytes - usedBytes, 0) : undefined,\n usedPercent: totalBytes && usedBytes !== undefined ? this.toPercent(usedBytes, totalBytes) : undefined,\n };\n }\n getGpuInfo() {\n var _a, _b;\n const canvas = document.createElement('canvas');\n const gl = (_a = canvas.getContext('webgl2')) !== null && _a !== void 0 ? _a : canvas.getContext('webgl');\n if (!gl) {\n return undefined;\n }\n const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');\n const gpu = {\n api: 'webgl',\n version: gl.getParameter(gl.VERSION),\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),\n };\n if (debugInfo) {\n gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);\n gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);\n }\n else {\n gpu.vendor = gl.getParameter(gl.VENDOR);\n gpu.renderer = gl.getParameter(gl.RENDERER);\n }\n (_b = gl.getExtension('WEBGL_lose_context')) === null || _b === void 0 ? void 0 : _b.loseContext();\n return gpu;\n }\n getOnboardSensorsInfo() {\n return {\n availableSensors: [],\n readings: [],\n };\n }\n shouldStop() {\n const reachedSampleLimit = this.sampleLimit !== undefined && this.samplesEmitted >= this.sampleLimit;\n const reachedDuration = this.stopAt !== undefined && Date.now() >= this.stopAt;\n return reachedSampleLimit || reachedDuration;\n }\n normalizeInterval(intervalMs) {\n if (!Number.isFinite(intervalMs)) {\n return DEFAULT_INTERVAL_MS;\n }\n return Math.max(Math.round(Number(intervalMs)), MIN_INTERVAL_MS);\n }\n normalizePositiveInteger(value) {\n if (!Number.isFinite(value)) {\n return undefined;\n }\n const normalized = Math.floor(Number(value));\n return normalized > 0 ? normalized : undefined;\n }\n normalizePositiveNumber(value) {\n if (!Number.isFinite(value)) {\n return undefined;\n }\n const normalized = Number(value);\n return normalized > 0 ? normalized : undefined;\n }\n toPercent(value, total) {\n return total > 0 ? Math.min(Math.max((value / total) * 100, 0), 100) : 0;\n }\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,mBAAmB,GAAG,IAAI;AAChC,MAAM,eAAe,GAAG,GAAG;AACpB,MAAM,aAAa,SAASC,cAAS,CAAC;AAC7C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI;AACzB,QAAQ,IAAI,CAAC,cAAc,GAAG,CAAC;AAC/B,QAAQ,IAAI,CAAC,UAAU,GAAG,KAAK;AAC/B,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;AACjC,YAAY,QAAQ,EAAE,KAAK;AAC3B,YAAY,GAAG,EAAE;AACjB,gBAAgB,KAAK,EAAE,SAAS,CAAC,mBAAmB,IAAI,CAAC;AACzD,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa;AACb,YAAY,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE;AACxC,YAAY,OAAO,EAAE,MAAM,IAAI,CAAC,cAAc,EAAE;AAChD,YAAY,GAAG,EAAE,IAAI,CAAC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 web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.DeviceInfoWeb()),
6
+ });
7
+
8
+ const DEFAULT_INTERVAL_MS = 1000;
9
+ const MIN_INTERVAL_MS = 250;
10
+ class DeviceInfoWeb extends core.WebPlugin {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.timer = null;
14
+ this.samplesEmitted = 0;
15
+ this.isEmitting = false;
16
+ }
17
+ async getInfo() {
18
+ return {
19
+ timestamp: Date.now(),
20
+ platform: 'web',
21
+ cpu: {
22
+ cores: navigator.hardwareConcurrency || 1,
23
+ usagePercent: null,
24
+ },
25
+ memory: this.getMemoryInfo(),
26
+ storage: await this.getStorageInfo(),
27
+ gpu: this.getGpuInfo(),
28
+ sensors: this.getOnboardSensorsInfo(),
29
+ };
30
+ }
31
+ async startMonitoring(options = {}) {
32
+ await this.stopMonitoring();
33
+ const intervalMs = this.normalizeInterval(options.intervalMs);
34
+ const now = Date.now();
35
+ this.intervalMs = intervalMs;
36
+ this.startedAt = now;
37
+ this.samplesEmitted = 0;
38
+ this.sampleLimit = this.normalizePositiveInteger(options.sampleCount);
39
+ this.stopAt = this.normalizePositiveNumber(options.durationMs) ? now + Number(options.durationMs) : undefined;
40
+ if (options.emitImmediately !== false) {
41
+ await this.emitSample();
42
+ }
43
+ this.timer = setInterval(() => {
44
+ void this.emitSample();
45
+ }, intervalMs);
46
+ return {
47
+ monitoring: true,
48
+ intervalMs,
49
+ startedAt: now,
50
+ };
51
+ }
52
+ async stopMonitoring() {
53
+ if (this.timer) {
54
+ clearInterval(this.timer);
55
+ }
56
+ this.timer = null;
57
+ this.startedAt = undefined;
58
+ this.intervalMs = undefined;
59
+ this.sampleLimit = undefined;
60
+ this.stopAt = undefined;
61
+ this.samplesEmitted = 0;
62
+ return { monitoring: false };
63
+ }
64
+ async isMonitoring() {
65
+ return {
66
+ monitoring: this.timer !== null,
67
+ intervalMs: this.intervalMs,
68
+ startedAt: this.startedAt,
69
+ samplesEmitted: this.samplesEmitted,
70
+ };
71
+ }
72
+ async addListener(eventName, listenerFunc) {
73
+ return super.addListener(eventName, listenerFunc);
74
+ }
75
+ async removeAllListeners() {
76
+ await super.removeAllListeners();
77
+ }
78
+ async getPluginVersion() {
79
+ return { version: 'web' };
80
+ }
81
+ async emitSample() {
82
+ if (this.isEmitting || !this.startedAt) {
83
+ return;
84
+ }
85
+ this.isEmitting = true;
86
+ try {
87
+ const snapshot = await this.getInfo();
88
+ this.samplesEmitted += 1;
89
+ const event = Object.assign(Object.assign({}, snapshot), { sequence: this.samplesEmitted, startedAt: this.startedAt, elapsedMs: snapshot.timestamp - this.startedAt });
90
+ this.notifyListeners('deviceInfoUpdate', event);
91
+ if (this.shouldStop()) {
92
+ await this.stopMonitoring();
93
+ }
94
+ }
95
+ finally {
96
+ this.isEmitting = false;
97
+ }
98
+ }
99
+ getMemoryInfo() {
100
+ var _a, _b;
101
+ const nav = navigator;
102
+ const perf = performance;
103
+ const totalBytes = nav.deviceMemory ? nav.deviceMemory * 1024 * 1024 * 1024 : undefined;
104
+ const appUsedBytes = (_a = perf.memory) === null || _a === void 0 ? void 0 : _a.usedJSHeapSize;
105
+ const appLimitBytes = (_b = perf.memory) === null || _b === void 0 ? void 0 : _b.jsHeapSizeLimit;
106
+ return {
107
+ totalBytes,
108
+ appUsedBytes,
109
+ appLimitBytes,
110
+ usedPercent: totalBytes && appUsedBytes ? this.toPercent(appUsedBytes, totalBytes) : undefined,
111
+ pressure: 'unknown',
112
+ };
113
+ }
114
+ async getStorageInfo() {
115
+ var _a;
116
+ if (!((_a = navigator.storage) === null || _a === void 0 ? void 0 : _a.estimate)) {
117
+ return {};
118
+ }
119
+ const estimate = await navigator.storage.estimate();
120
+ const totalBytes = estimate.quota;
121
+ const usedBytes = estimate.usage;
122
+ return {
123
+ totalBytes,
124
+ usedBytes,
125
+ freeBytes: totalBytes !== undefined && usedBytes !== undefined ? Math.max(totalBytes - usedBytes, 0) : undefined,
126
+ usedPercent: totalBytes && usedBytes !== undefined ? this.toPercent(usedBytes, totalBytes) : undefined,
127
+ };
128
+ }
129
+ getGpuInfo() {
130
+ var _a, _b;
131
+ const canvas = document.createElement('canvas');
132
+ const gl = (_a = canvas.getContext('webgl2')) !== null && _a !== void 0 ? _a : canvas.getContext('webgl');
133
+ if (!gl) {
134
+ return undefined;
135
+ }
136
+ const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
137
+ const gpu = {
138
+ api: 'webgl',
139
+ version: gl.getParameter(gl.VERSION),
140
+ maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
141
+ };
142
+ if (debugInfo) {
143
+ gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
144
+ gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
145
+ }
146
+ else {
147
+ gpu.vendor = gl.getParameter(gl.VENDOR);
148
+ gpu.renderer = gl.getParameter(gl.RENDERER);
149
+ }
150
+ (_b = gl.getExtension('WEBGL_lose_context')) === null || _b === void 0 ? void 0 : _b.loseContext();
151
+ return gpu;
152
+ }
153
+ getOnboardSensorsInfo() {
154
+ return {
155
+ availableSensors: [],
156
+ readings: [],
157
+ };
158
+ }
159
+ shouldStop() {
160
+ const reachedSampleLimit = this.sampleLimit !== undefined && this.samplesEmitted >= this.sampleLimit;
161
+ const reachedDuration = this.stopAt !== undefined && Date.now() >= this.stopAt;
162
+ return reachedSampleLimit || reachedDuration;
163
+ }
164
+ normalizeInterval(intervalMs) {
165
+ if (!Number.isFinite(intervalMs)) {
166
+ return DEFAULT_INTERVAL_MS;
167
+ }
168
+ return Math.max(Math.round(Number(intervalMs)), MIN_INTERVAL_MS);
169
+ }
170
+ normalizePositiveInteger(value) {
171
+ if (!Number.isFinite(value)) {
172
+ return undefined;
173
+ }
174
+ const normalized = Math.floor(Number(value));
175
+ return normalized > 0 ? normalized : undefined;
176
+ }
177
+ normalizePositiveNumber(value) {
178
+ if (!Number.isFinite(value)) {
179
+ return undefined;
180
+ }
181
+ const normalized = Number(value);
182
+ return normalized > 0 ? normalized : undefined;
183
+ }
184
+ toPercent(value, total) {
185
+ return total > 0 ? Math.min(Math.max((value / total) * 100, 0), 100) : 0;
186
+ }
187
+ }
188
+
189
+ var web = /*#__PURE__*/Object.freeze({
190
+ __proto__: null,
191
+ DeviceInfoWeb: DeviceInfoWeb
192
+ });
193
+
194
+ exports.DeviceInfo = DeviceInfo;
195
+
196
+ return exports;
197
+
198
+ })({}, capacitorExports);
199
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst DeviceInfo = registerPlugin('DeviceInfo', {\n web: () => import('./web').then((m) => new m.DeviceInfoWeb()),\n});\nexport * from './definitions';\nexport { DeviceInfo };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst DEFAULT_INTERVAL_MS = 1000;\nconst MIN_INTERVAL_MS = 250;\nexport class DeviceInfoWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.timer = null;\n this.samplesEmitted = 0;\n this.isEmitting = false;\n }\n async getInfo() {\n return {\n timestamp: Date.now(),\n platform: 'web',\n cpu: {\n cores: navigator.hardwareConcurrency || 1,\n usagePercent: null,\n },\n memory: this.getMemoryInfo(),\n storage: await this.getStorageInfo(),\n gpu: this.getGpuInfo(),\n sensors: this.getOnboardSensorsInfo(),\n };\n }\n async startMonitoring(options = {}) {\n await this.stopMonitoring();\n const intervalMs = this.normalizeInterval(options.intervalMs);\n const now = Date.now();\n this.intervalMs = intervalMs;\n this.startedAt = now;\n this.samplesEmitted = 0;\n this.sampleLimit = this.normalizePositiveInteger(options.sampleCount);\n this.stopAt = this.normalizePositiveNumber(options.durationMs) ? now + Number(options.durationMs) : undefined;\n if (options.emitImmediately !== false) {\n await this.emitSample();\n }\n this.timer = setInterval(() => {\n void this.emitSample();\n }, intervalMs);\n return {\n monitoring: true,\n intervalMs,\n startedAt: now,\n };\n }\n async stopMonitoring() {\n if (this.timer) {\n clearInterval(this.timer);\n }\n this.timer = null;\n this.startedAt = undefined;\n this.intervalMs = undefined;\n this.sampleLimit = undefined;\n this.stopAt = undefined;\n this.samplesEmitted = 0;\n return { monitoring: false };\n }\n async isMonitoring() {\n return {\n monitoring: this.timer !== null,\n intervalMs: this.intervalMs,\n startedAt: this.startedAt,\n samplesEmitted: this.samplesEmitted,\n };\n }\n async addListener(eventName, listenerFunc) {\n return super.addListener(eventName, listenerFunc);\n }\n async removeAllListeners() {\n await super.removeAllListeners();\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n async emitSample() {\n if (this.isEmitting || !this.startedAt) {\n return;\n }\n this.isEmitting = true;\n try {\n const snapshot = await this.getInfo();\n this.samplesEmitted += 1;\n const event = Object.assign(Object.assign({}, snapshot), { sequence: this.samplesEmitted, startedAt: this.startedAt, elapsedMs: snapshot.timestamp - this.startedAt });\n this.notifyListeners('deviceInfoUpdate', event);\n if (this.shouldStop()) {\n await this.stopMonitoring();\n }\n }\n finally {\n this.isEmitting = false;\n }\n }\n getMemoryInfo() {\n var _a, _b;\n const nav = navigator;\n const perf = performance;\n const totalBytes = nav.deviceMemory ? nav.deviceMemory * 1024 * 1024 * 1024 : undefined;\n const appUsedBytes = (_a = perf.memory) === null || _a === void 0 ? void 0 : _a.usedJSHeapSize;\n const appLimitBytes = (_b = perf.memory) === null || _b === void 0 ? void 0 : _b.jsHeapSizeLimit;\n return {\n totalBytes,\n appUsedBytes,\n appLimitBytes,\n usedPercent: totalBytes && appUsedBytes ? this.toPercent(appUsedBytes, totalBytes) : undefined,\n pressure: 'unknown',\n };\n }\n async getStorageInfo() {\n var _a;\n if (!((_a = navigator.storage) === null || _a === void 0 ? void 0 : _a.estimate)) {\n return {};\n }\n const estimate = await navigator.storage.estimate();\n const totalBytes = estimate.quota;\n const usedBytes = estimate.usage;\n return {\n totalBytes,\n usedBytes,\n freeBytes: totalBytes !== undefined && usedBytes !== undefined ? Math.max(totalBytes - usedBytes, 0) : undefined,\n usedPercent: totalBytes && usedBytes !== undefined ? this.toPercent(usedBytes, totalBytes) : undefined,\n };\n }\n getGpuInfo() {\n var _a, _b;\n const canvas = document.createElement('canvas');\n const gl = (_a = canvas.getContext('webgl2')) !== null && _a !== void 0 ? _a : canvas.getContext('webgl');\n if (!gl) {\n return undefined;\n }\n const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');\n const gpu = {\n api: 'webgl',\n version: gl.getParameter(gl.VERSION),\n maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),\n };\n if (debugInfo) {\n gpu.vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);\n gpu.renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);\n }\n else {\n gpu.vendor = gl.getParameter(gl.VENDOR);\n gpu.renderer = gl.getParameter(gl.RENDERER);\n }\n (_b = gl.getExtension('WEBGL_lose_context')) === null || _b === void 0 ? void 0 : _b.loseContext();\n return gpu;\n }\n getOnboardSensorsInfo() {\n return {\n availableSensors: [],\n readings: [],\n };\n }\n shouldStop() {\n const reachedSampleLimit = this.sampleLimit !== undefined && this.samplesEmitted >= this.sampleLimit;\n const reachedDuration = this.stopAt !== undefined && Date.now() >= this.stopAt;\n return reachedSampleLimit || reachedDuration;\n }\n normalizeInterval(intervalMs) {\n if (!Number.isFinite(intervalMs)) {\n return DEFAULT_INTERVAL_MS;\n }\n return Math.max(Math.round(Number(intervalMs)), MIN_INTERVAL_MS);\n }\n normalizePositiveInteger(value) {\n if (!Number.isFinite(value)) {\n return undefined;\n }\n const normalized = Math.floor(Number(value));\n return normalized > 0 ? normalized : undefined;\n }\n normalizePositiveNumber(value) {\n if (!Number.isFinite(value)) {\n return undefined;\n }\n const normalized = Number(value);\n return normalized > 0 ? normalized : undefined;\n }\n toPercent(value, total) {\n return total > 0 ? Math.min(Math.max((value / total) * 100, 0), 100) : 0;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["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