@xh/hoist 73.0.0-SNAPSHOT.1744065661676 → 73.0.0-SNAPSHOT.1744112888481

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.
@@ -4,25 +4,31 @@
4
4
  *
5
5
  * Copyright © 2025 Extremely Heavy Industries Inc.
6
6
  */
7
- import {pick} from 'lodash';
7
+ import {XH} from '@xh/hoist/core';
8
+ import {pick, round} from 'lodash';
8
9
 
9
10
  /**
10
11
  * Extract information (if available) about the client browser's window, screen, and network speed.
11
12
  */
12
- export function getClientDeviceInfo() {
13
- const data: any = pick(window, [
14
- 'screen',
15
- 'devicePixelRatio',
16
- 'screenX',
17
- 'screenY',
18
- 'innerWidth',
19
- 'innerHeight',
20
- 'outerWidth',
21
- 'outerHeight'
22
- ]);
13
+ export function getClientDeviceInfo(): ClientDeviceInfo {
14
+ const ret: ClientDeviceInfo = {
15
+ window: pick(window, [
16
+ 'devicePixelRatio',
17
+ 'screenX',
18
+ 'screenY',
19
+ 'innerWidth',
20
+ 'innerHeight',
21
+ 'outerWidth',
22
+ 'outerHeight'
23
+ ]),
24
+ memory: {
25
+ modelCount: XH.getModels().length
26
+ }
27
+ };
23
28
 
24
- if (data.screen) {
25
- data.screen = pick(data.screen, [
29
+ const screen = window.screen as any;
30
+ if (screen) {
31
+ ret.screen = pick(screen, [
26
32
  'availWidth',
27
33
  'availHeight',
28
34
  'width',
@@ -30,23 +36,68 @@ export function getClientDeviceInfo() {
30
36
  'colorDepth',
31
37
  'pixelDepth',
32
38
  'availLeft',
33
- 'availTop',
34
- 'orientation'
39
+ 'availTop'
35
40
  ]);
36
- if (data.screen.orientation) {
37
- data.screen.orientation = pick(data.screen.orientation, ['angle', 'type']);
41
+ if (screen.orientation) {
42
+ ret.screen.orientation = pick(screen.orientation, ['angle', 'type']);
38
43
  }
39
44
  }
40
45
 
41
46
  const nav = window.navigator as any;
42
47
  if (nav.connection) {
43
- data.connection = pick(nav.connection, ['downlink', 'effectiveType', 'rtt']);
48
+ ret.connection = pick(nav.connection, ['downlink', 'effectiveType', 'rtt']);
44
49
  }
45
50
 
46
51
  const perf = window.performance as any;
47
52
  if (perf?.memory) {
48
- data.memory = pick(perf.memory, ['jsHeapSizeLimit', 'totalJSHeapSize', 'usedJSHeapSize']);
53
+ ['jsHeapSizeLimit', 'totalJSHeapSize', 'usedJSHeapSize'].forEach(key => {
54
+ const raw = perf.memory[key];
55
+ if (raw) ret.memory[key] = round(raw / 1024 / 1024); // convert to MB
56
+ });
57
+
58
+ const {jsHeapSizeLimit: limit, usedJSHeapSize: used} = ret.memory;
59
+ if (limit && used) {
60
+ ret.memory.usedPctLimit = round((used / limit) * 100, 1);
61
+ }
49
62
  }
50
63
 
51
- return data;
64
+ return ret;
65
+ }
66
+
67
+ export interface ClientDeviceInfo {
68
+ window: {
69
+ devicePixelRatio: number;
70
+ screenX: number;
71
+ screenY: number;
72
+ innerWidth: number;
73
+ innerHeight: number;
74
+ outerWidth: number;
75
+ outerHeight: number;
76
+ };
77
+ screen?: {
78
+ availWidth: number;
79
+ availHeight: number;
80
+ width: number;
81
+ height: number;
82
+ colorDepth: number;
83
+ pixelDepth: number;
84
+ availLeft: number;
85
+ availTop: number;
86
+ orientation?: {
87
+ angle: number;
88
+ type: string;
89
+ };
90
+ };
91
+ connection?: {
92
+ downlink: number;
93
+ effectiveType: string;
94
+ rtt: number;
95
+ };
96
+ memory: {
97
+ modelCount: number;
98
+ usedPctLimit?: number;
99
+ jsHeapSizeLimit?: number;
100
+ totalJSHeapSize?: number;
101
+ usedJSHeapSize?: number;
102
+ };
52
103
  }