xxf_react 0.4.9 → 0.5.1

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,26 @@
1
+ export type BrowserPlatform = 'mobile' | 'tablet' | 'desktop';
2
+ export type BrowserName = 'Chrome' | 'Safari' | 'Firefox' | 'Edge' | 'IE' | 'Opera' | 'Samsung Internet' | 'Unknown';
3
+ export type BrowserInfo = {
4
+ /** 浏览器名称(标准化) */
5
+ name: BrowserName;
6
+ /** 操作系统 */
7
+ os: string;
8
+ /** 平台类型 */
9
+ platform: BrowserPlatform;
10
+ };
11
+ export declare const parseBrowser: (ua: string) => BrowserInfo;
12
+ export declare const useBrowser: () => BrowserInfo;
13
+ export declare const useBrowserType: () => {
14
+ readonly isMobile: boolean;
15
+ readonly isTablet: boolean;
16
+ readonly isDesktop: boolean;
17
+ readonly isChrome: boolean;
18
+ readonly isSafari: boolean;
19
+ readonly isFirefox: boolean;
20
+ readonly isEdge: boolean;
21
+ readonly isIE: boolean;
22
+ readonly name: BrowserName;
23
+ readonly os: string;
24
+ readonly platform: BrowserPlatform;
25
+ };
26
+ //# sourceMappingURL=BrowserAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserAdapter.d.ts","sourceRoot":"","sources":["../../src/responsive/BrowserAdapter.tsx"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE7D,MAAM,MAAM,WAAW,GACjB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,IAAI,GACJ,OAAO,GACP,kBAAkB,GAClB,SAAS,CAAA;AAEf,MAAM,MAAM,WAAW,GAAG;IACtB,iBAAiB;IACjB,IAAI,EAAE,WAAW,CAAA;IACjB,WAAW;IACX,EAAE,EAAE,MAAM,CAAA;IACV,WAAW;IACX,QAAQ,EAAE,eAAe,CAAA;CAC5B,CAAA;AAgDD,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,WAczC,CAAA;AAGD,eAAO,MAAM,UAAU,mBAEtB,CAAA;AAGD,eAAO,MAAM,cAAc;;;;;;;;;mBA3EjB,WAAW;iBAEb,MAAM;uBAEA,eAAe;CAmG5B,CAAA"}
@@ -0,0 +1,79 @@
1
+ import Bowser from 'bowser';
2
+ /**
3
+ * UA -> BrowserInfo 缓存
4
+ * module scope,天然单例
5
+ */
6
+ const browserCache = new Map();
7
+ /* ===================== 新增 1:BrowserName 规范化 ===================== */
8
+ const normalizeBrowserName = (name) => {
9
+ switch (name) {
10
+ case 'Chrome':
11
+ case 'Chromium':
12
+ return 'Chrome';
13
+ case 'Safari':
14
+ case 'Mobile Safari':
15
+ return 'Safari';
16
+ case 'Firefox':
17
+ return 'Firefox';
18
+ case 'Microsoft Edge':
19
+ case 'Edge':
20
+ return 'Edge';
21
+ case 'Internet Explorer':
22
+ return 'IE';
23
+ case 'Samsung Internet':
24
+ return 'Samsung Internet';
25
+ case 'Opera':
26
+ return 'Opera';
27
+ default:
28
+ return 'Unknown';
29
+ }
30
+ };
31
+ /* ===================== 新增 2:platform 兜底 ===================== */
32
+ const normalizePlatform = (platform) => {
33
+ if (platform === 'mobile' || platform === 'tablet') {
34
+ return platform;
35
+ }
36
+ return 'desktop';
37
+ };
38
+ export const parseBrowser = (ua) => {
39
+ const cached = browserCache.get(ua);
40
+ if (cached)
41
+ return cached;
42
+ const parser = Bowser.getParser(ua);
43
+ const info = {
44
+ name: normalizeBrowserName(parser.getBrowserName()),
45
+ os: parser.getOSName() || 'Unknown',
46
+ platform: normalizePlatform(parser.getPlatformType(true)),
47
+ };
48
+ browserCache.set(ua, info);
49
+ return info;
50
+ };
51
+ /// 判断浏览器信息
52
+ export const useBrowser = () => {
53
+ return parseBrowser(navigator.userAgent);
54
+ };
55
+ /// 判断浏览器类型(语义层)
56
+ export const useBrowserType = () => {
57
+ const browser = useBrowser();
58
+ const isMobile = browser.platform === 'mobile';
59
+ const isTablet = browser.platform === 'tablet';
60
+ const isDesktop = browser.platform === 'desktop';
61
+ const isChrome = browser.name === 'Chrome';
62
+ const isSafari = browser.name === 'Safari';
63
+ const isFirefox = browser.name === 'Firefox';
64
+ const isEdge = browser.name === 'Edge';
65
+ const isIE = browser.name === 'IE';
66
+ return {
67
+ ...browser,
68
+ // platform
69
+ isMobile,
70
+ isTablet,
71
+ isDesktop,
72
+ // browser
73
+ isChrome,
74
+ isSafari,
75
+ isFirefox,
76
+ isEdge,
77
+ isIE,
78
+ };
79
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './ScreenAdapter';
2
+ export * from './BrowserAdapter';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/responsive/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/responsive/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  'use client';
2
2
  export * from './ScreenAdapter';
3
+ export * from './BrowserAdapter';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxf_react",
3
- "version": "0.4.9",
3
+ "version": "0.5.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -63,6 +63,7 @@
63
63
  "dependencies": {
64
64
  "@microsoft/fetch-event-source": "^2.0.1",
65
65
  "@use-gesture/react": "^10.3.1",
66
+ "bowser": "^2.14.1",
66
67
  "dayjs": "^1.11.19",
67
68
  "mitt": "^3.0.1",
68
69
  "react-async-hook": "^4.0.0",