assistsx-js 0.1.37 → 0.1.38

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.
@@ -56,11 +56,26 @@ export interface WebFloatingWindowOptions {
56
56
  }
57
57
  export declare const callbacks: Map<string, (data: string) => void>;
58
58
  export declare const accessibilityEventListeners: AccessibilityEventListener[];
59
+ /**
60
+ * 屏幕尺寸类型(width/height 为整型像素值)
61
+ */
62
+ export interface Screen {
63
+ width: number;
64
+ height: number;
65
+ }
66
+ /** 全局屏幕尺寸,在 assistsxCallback 初始化后自动加载 */
67
+ export declare let screen: Screen | null;
59
68
  export declare class AssistsX {
60
69
  /**
61
- * 屏幕尺寸静态变量,在 assistsxCallback 初始化后自动加载
70
+ * 屏幕尺寸(与全局变量 screen 同源)
71
+ * @deprecated 已过时,请使用全局变量 {@link screen}
62
72
  */
63
- static screenSize: any;
73
+ static get screenSize(): {
74
+ width: number;
75
+ height: number;
76
+ screenWidth: number;
77
+ screenHeight: number;
78
+ } | null;
64
79
  /**
65
80
  * 执行同步调用
66
81
  * @param method 方法名
@@ -437,9 +452,9 @@ export declare class AssistsX {
437
452
  static addAccessibilityEventFilter(value: AccessibilityEventFilter): Promise<any>;
438
453
  /**
439
454
  * 获取屏幕尺寸
440
- * @returns 屏幕尺寸对象
455
+ * @returns 屏幕尺寸对象(width, height)
441
456
  */
442
- static getScreenSize(): any;
457
+ static getScreenSize(): Screen | null;
443
458
  /**
444
459
  * 获取应用窗口尺寸
445
460
  * @returns 应用窗口尺寸对象
package/dist/AssistsX.js CHANGED
@@ -13,6 +13,8 @@ import { DeviceInfo } from "./DeviceInfo";
13
13
  export const callbacks = new Map();
14
14
  // 无障碍事件监听器存储
15
15
  export const accessibilityEventListeners = [];
16
+ /** 全局屏幕尺寸,在 assistsxCallback 初始化后自动加载 */
17
+ export let screen = null;
16
18
  // 初始化全局回调函数
17
19
  if (typeof window !== "undefined" && !window.assistsxCallback) {
18
20
  window.assistsxCallback = (data) => {
@@ -57,6 +59,20 @@ if (typeof window !== "undefined" && !window.onAccessibilityEvent) {
57
59
  };
58
60
  }
59
61
  export class AssistsX {
62
+ /**
63
+ * 屏幕尺寸(与全局变量 screen 同源)
64
+ * @deprecated 已过时,请使用全局变量 {@link screen}
65
+ */
66
+ static get screenSize() {
67
+ if (screen == null)
68
+ return null;
69
+ return {
70
+ width: screen.width,
71
+ height: screen.height,
72
+ screenWidth: screen.width,
73
+ screenHeight: screen.height,
74
+ };
75
+ }
60
76
  /**
61
77
  * 执行同步调用
62
78
  * @param method 方法名
@@ -730,11 +746,12 @@ export class AssistsX {
730
746
  }
731
747
  /**
732
748
  * 获取屏幕尺寸
733
- * @returns 屏幕尺寸对象
749
+ * @returns 屏幕尺寸对象(width, height)
734
750
  */
735
751
  static getScreenSize() {
736
752
  const response = this.call(CallMethod.getScreenSize);
737
- return response.getDataOrDefault({});
753
+ const data = response.getDataOrDefault({});
754
+ return normalizeScreen(data);
738
755
  }
739
756
  /**
740
757
  * 获取应用窗口尺寸
@@ -786,20 +803,26 @@ export class AssistsX {
786
803
  return accessibilityEventListeners.length;
787
804
  }
788
805
  }
789
- /**
790
- * 屏幕尺寸静态变量,在 assistsxCallback 初始化后自动加载
791
- */
792
- AssistsX.screenSize = null;
806
+ /** 将原生返回的 screenWidth/screenHeight 规范为 width/height */
807
+ function normalizeScreen(data) {
808
+ if (data == null)
809
+ return null;
810
+ const w = typeof data.width === "number" ? data.width : data.screenWidth;
811
+ const h = typeof data.height === "number" ? data.height : data.screenHeight;
812
+ if (typeof w !== "number" || typeof h !== "number")
813
+ return null;
814
+ return { width: Math.floor(w), height: Math.floor(h) };
815
+ }
793
816
  // 在 assistsxCallback 初始化后,初始化屏幕尺寸
794
817
  if (typeof window !== "undefined") {
795
818
  try {
796
819
  // 检查 assistsx 是否可用,如果可用则初始化屏幕尺寸
797
820
  if (window.assistsx && typeof window.assistsx.call === "function") {
798
- AssistsX.screenSize = AssistsX.getScreenSize();
821
+ screen = AssistsX.getScreenSize();
799
822
  }
800
823
  }
801
824
  catch (e) {
802
- // 如果初始化失败,screenSize 保持为 null
825
+ // 如果初始化失败,screen 保持为 null
803
826
  console.log("Failed to initialize screen size:", e);
804
827
  }
805
828
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/AssistsX.ts CHANGED
@@ -67,6 +67,17 @@ export const callbacks: Map<string, (data: string) => void> = new Map();
67
67
  // 无障碍事件监听器存储
68
68
  export const accessibilityEventListeners: AccessibilityEventListener[] = [];
69
69
 
70
+ /**
71
+ * 屏幕尺寸类型(width/height 为整型像素值)
72
+ */
73
+ export interface Screen {
74
+ width: number;
75
+ height: number;
76
+ }
77
+
78
+ /** 全局屏幕尺寸,在 assistsxCallback 初始化后自动加载 */
79
+ export let screen: Screen | null = null;
80
+
70
81
  // 初始化全局回调函数
71
82
  if (typeof window !== "undefined" && !window.assistsxCallback) {
72
83
  window.assistsxCallback = (data: string) => {
@@ -111,9 +122,18 @@ if (typeof window !== "undefined" && !window.onAccessibilityEvent) {
111
122
 
112
123
  export class AssistsX {
113
124
  /**
114
- * 屏幕尺寸静态变量,在 assistsxCallback 初始化后自动加载
125
+ * 屏幕尺寸(与全局变量 screen 同源)
126
+ * @deprecated 已过时,请使用全局变量 {@link screen}
115
127
  */
116
- public static screenSize: any = null;
128
+ public static get screenSize(): { width: number; height: number; screenWidth: number; screenHeight: number } | null {
129
+ if (screen == null) return null;
130
+ return {
131
+ width: screen.width,
132
+ height: screen.height,
133
+ screenWidth: screen.width,
134
+ screenHeight: screen.height,
135
+ };
136
+ }
117
137
 
118
138
  /**
119
139
  * 执行同步调用
@@ -1026,11 +1046,12 @@ export class AssistsX {
1026
1046
 
1027
1047
  /**
1028
1048
  * 获取屏幕尺寸
1029
- * @returns 屏幕尺寸对象
1049
+ * @returns 屏幕尺寸对象(width, height)
1030
1050
  */
1031
- public static getScreenSize(): any {
1051
+ public static getScreenSize(): Screen | null {
1032
1052
  const response = this.call(CallMethod.getScreenSize);
1033
- return response.getDataOrDefault({});
1053
+ const data = response.getDataOrDefault({});
1054
+ return normalizeScreen(data);
1034
1055
  }
1035
1056
 
1036
1057
  /**
@@ -1095,15 +1116,24 @@ export class AssistsX {
1095
1116
 
1096
1117
  }
1097
1118
 
1119
+ /** 将原生返回的 screenWidth/screenHeight 规范为 width/height */
1120
+ function normalizeScreen(data: any): Screen | null {
1121
+ if (data == null) return null;
1122
+ const w = typeof data.width === "number" ? data.width : data.screenWidth;
1123
+ const h = typeof data.height === "number" ? data.height : data.screenHeight;
1124
+ if (typeof w !== "number" || typeof h !== "number") return null;
1125
+ return { width: Math.floor(w), height: Math.floor(h) };
1126
+ }
1127
+
1098
1128
  // 在 assistsxCallback 初始化后,初始化屏幕尺寸
1099
1129
  if (typeof window !== "undefined") {
1100
1130
  try {
1101
1131
  // 检查 assistsx 是否可用,如果可用则初始化屏幕尺寸
1102
1132
  if ((window as any).assistsx && typeof (window as any).assistsx.call === "function") {
1103
- AssistsX.screenSize = AssistsX.getScreenSize();
1133
+ screen = AssistsX.getScreenSize();
1104
1134
  }
1105
1135
  } catch (e) {
1106
- // 如果初始化失败,screenSize 保持为 null
1136
+ // 如果初始化失败,screen 保持为 null
1107
1137
  console.log("Failed to initialize screen size:", e);
1108
1138
  }
1109
1139
  }