xxf_react 0.2.5 → 0.2.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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 类似 Kotlin 的 measureTimeMillis
3
+ * @param block 要测量的代码块
4
+ * @returns 执行时间(毫秒)
5
+ */
6
+ export declare function measureTimeMillis(block: () => void): number;
7
+ //# sourceMappingURL=Debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Debug.d.ts","sourceRoot":"","sources":["../../src/foundation/Debug.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,IAAI,GAAG,MAAM,CAK3D"}
@@ -0,0 +1,12 @@
1
+ import { PerformanceMonitor } from "./PerformanceMonitor";
2
+ /**
3
+ * 类似 Kotlin 的 measureTimeMillis
4
+ * @param block 要测量的代码块
5
+ * @returns 执行时间(毫秒)
6
+ */
7
+ export function measureTimeMillis(block) {
8
+ const monitor = new PerformanceMonitor();
9
+ monitor.start();
10
+ block();
11
+ return monitor.end();
12
+ }
@@ -0,0 +1,13 @@
1
+ export declare class PerformanceMonitor {
2
+ private startTime;
3
+ private label;
4
+ /**
5
+ * 开始计时
6
+ */
7
+ start(label?: string): PerformanceMonitor;
8
+ /**
9
+ * 结束计时并返回时间(毫秒)
10
+ */
11
+ end(): number;
12
+ }
13
+ //# sourceMappingURL=PerformanceMonitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceMonitor.d.ts","sourceRoot":"","sources":["../../src/foundation/PerformanceMonitor.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,KAAK,CAAa;IAE1B;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB;IAOzC;;OAEG;IACH,GAAG,IAAI,MAAM;CAKhB"}
@@ -0,0 +1,26 @@
1
+ export class PerformanceMonitor {
2
+ constructor() {
3
+ this.startTime = 0;
4
+ this.label = '';
5
+ }
6
+ /**
7
+ * 开始计时
8
+ */
9
+ start(label) {
10
+ this.startTime = performance.now();
11
+ if (label)
12
+ this.label = label;
13
+ if (this.label)
14
+ console.time(this.label);
15
+ return this;
16
+ }
17
+ /**
18
+ * 结束计时并返回时间(毫秒)
19
+ */
20
+ end() {
21
+ const elapsed = performance.now() - this.startTime;
22
+ if (this.label)
23
+ console.timeEnd(this.label);
24
+ return elapsed;
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Debug';
2
+ export * from './PerformanceMonitor';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/foundation/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Debug';
2
+ export * from './PerformanceMonitor';
package/dist/index.d.ts CHANGED
@@ -6,5 +6,6 @@ export * from './models';
6
6
  export * from './media';
7
7
  export * from './flow';
8
8
  export * from './responsive';
9
+ export * from './foundation';
9
10
  export declare function initXXF(): void;
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAG7B,wBAAgB,OAAO,SAEtB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAG7B,wBAAgB,OAAO,SAEtB"}
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './models';
7
7
  export * from './media';
8
8
  export * from './flow';
9
9
  export * from './responsive';
10
+ export * from './foundation';
10
11
  ///框架初始化函数,调用后会初始化一些全局功能
11
12
  export function initXXF() {
12
13
  initPromiseErrorExtension();
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 统一 API 响应格式
3
+ */
4
+ export interface ApiResponse<T> {
5
+ code: number;
6
+ message: string;
7
+ data: T;
8
+ }
9
+ /**
10
+ * 检查 API 响应是否成功
11
+ */
12
+ export declare function isApiSuccess(code: number): boolean;
13
+ /**
14
+ * API 错误类
15
+ */
16
+ export declare class ApiError extends Error {
17
+ code: number;
18
+ constructor(code: number, message: string);
19
+ }
20
+ /**
21
+ * 从 API 响应中json提取data字段数据,失败时抛出错误
22
+ * @deprecated 请使用 {@link getDataFieldOrThrow} 代替
23
+ */
24
+ export declare function getDataOrThrow<T>(response: ApiResponse<T>): T;
25
+ /**
26
+ * 从 API 响应中json提取data字段数据,失败时抛出错误
27
+ */
28
+ export declare function getDataFieldOrThrow<T>(response: ApiResponse<T>): T;
29
+ //# sourceMappingURL=ApiResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiResponse.d.ts","sourceRoot":"","sources":["../../src/models/ApiResponse.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,CAAC,CAAA;CACV;AAGD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAC/B,IAAI,EAAE,MAAM,CAAA;gBAEA,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK5C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAE7D;AAGD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAKlE"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 检查 API 响应是否成功
3
+ */
4
+ export function isApiSuccess(code) {
5
+ return code === 0 || code === 200;
6
+ }
7
+ /**
8
+ * API 错误类
9
+ */
10
+ export class ApiError extends Error {
11
+ constructor(code, message) {
12
+ super(`API Error: (${code}) ${message}`);
13
+ this.name = 'ApiError';
14
+ this.code = code;
15
+ }
16
+ }
17
+ /**
18
+ * 从 API 响应中json提取data字段数据,失败时抛出错误
19
+ * @deprecated 请使用 {@link getDataFieldOrThrow} 代替
20
+ */
21
+ export function getDataOrThrow(response) {
22
+ return getDataFieldOrThrow(response);
23
+ }
24
+ /**
25
+ * 从 API 响应中json提取data字段数据,失败时抛出错误
26
+ */
27
+ export function getDataFieldOrThrow(response) {
28
+ if (!isApiSuccess(response.code)) {
29
+ throw new ApiError(response.code, response.message);
30
+ }
31
+ return response.data;
32
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './ApiPageDataFieldDTO';
2
2
  export * from './PaginationDTO';
3
+ export * from './ApiResponse';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from './ApiPageDataFieldDTO';
2
2
  export * from './PaginationDTO';
3
+ export * from './ApiResponse';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxf_react",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "private": false,
5
5
 
6
6
  "type": "module",
@@ -44,6 +44,10 @@
44
44
  "./responsive": {
45
45
  "types": "./dist/responsive/index.d.ts",
46
46
  "import": "./dist/responsive/index.js"
47
+ },
48
+ "./foundation": {
49
+ "types": "./dist/foundation/index.d.ts",
50
+ "import": "./dist/foundation/index.js"
47
51
  }
48
52
  },
49
53