@hylid/env 0.0.90011288758-dev.2 → 0.0.90011319730-dev.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.
@@ -38,4 +38,7 @@ export var webChecker = [{
38
38
  }, {
39
39
  name: CLIENT.WORLDFIRST,
40
40
  match: [NO_MINIPROGRAM, NO_GRIVER, /WorldFirst/]
41
+ }, {
42
+ name: CLIENT.CHANGIPAY,
43
+ match: [NO_MINIPROGRAM, NO_GRIVER, /ChangiPay/]
41
44
  }];
@@ -1,6 +1,5 @@
1
1
  import { mpWebChecker } from "../checker";
2
- import { getMatchName, browserAPI } from "../utils";
2
+ import { getMatchName } from "../utils";
3
3
  export function getName4MpWeb() {
4
- var navigator = browserAPI.getNavigator();
5
- return getMatchName(mpWebChecker, (navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) || '');
4
+ return getMatchName(mpWebChecker, window.navigator.userAgent);
6
5
  }
@@ -1,8 +1,6 @@
1
1
  import { webChecker } from "../checker";
2
2
  import { CLIENT } from "../constants";
3
- import { getMatchName, browserAPI } from "../utils";
3
+ import { getMatchName } from "../utils";
4
4
  export function getName4Web() {
5
- var navigator = browserAPI.getNavigator();
6
- if (!navigator) return CLIENT.H5;
7
- return getMatchName(webChecker, navigator.userAgent) || CLIENT.H5;
5
+ return getMatchName(webChecker, window.navigator.userAgent) || CLIENT.H5;
8
6
  }
package/lib/index.d.ts CHANGED
@@ -2,9 +2,9 @@ import { ClientEnv, PlatformEnv } from './types';
2
2
  import version from './version';
3
3
  export declare function getDefaultDiscernEnv(): {
4
4
  client: string | undefined;
5
- platform: string;
5
+ platform: string | undefined;
6
6
  };
7
- declare let client: string | undefined, platform: string;
7
+ declare let client: string | undefined, platform: string | undefined;
8
8
  interface CustomEnv {
9
9
  client?: string;
10
10
  platform?: string;
package/lib/utils.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  import { Checker } from './types';
2
- import { browserAPI } from './browser-api';
3
- export { browserAPI };
4
2
  export declare function isMP(): boolean;
5
3
  export declare function getMatchName(checks: Checker[], pattern: string): string | undefined;
6
4
  export declare function createCommonEnv<T>(source: Record<string, string>, current?: string): T;
7
5
  export declare function notice(text: string): void;
8
- export declare function getSettingName(): {
9
- client?: string;
10
- platform?: string;
11
- };
6
+ export declare function getSettingName(): any;
package/lib/utils.js CHANGED
@@ -8,8 +8,6 @@ var __assign = this && this.__assign || function () {
8
8
  };
9
9
  return __assign.apply(this, arguments);
10
10
  };
11
- import { browserAPI } from "./browser-api";
12
- export { browserAPI };
13
11
  export function isMP() {
14
12
  // 小程序一定有 my
15
13
  if (typeof my === 'undefined') return false;
@@ -45,45 +43,30 @@ export function notice(text) {
45
43
  export function getSettingName() {
46
44
  var _a;
47
45
  var ENV_KEY = '__hy_env__';
48
- var window = browserAPI.getWindow();
49
- if (!window) return {};
50
46
  var clientMatch = ((_a = window.location.search) === null || _a === void 0 ? void 0 : _a.match(/__app__=([^&]*)/)) || [];
51
47
  var client = clientMatch[1];
52
48
  var platformMatch = window.location.search.match(/__platform__=([^&]*)/) || [];
53
49
  var platform = platformMatch[1];
54
- var env = {};
55
- try {
56
- env = JSON.parse(browserAPI.localStorage.getItem(ENV_KEY) || '{}') || {};
57
- } catch (e) {
58
- env = {};
59
- }
50
+ var env = JSON.parse(localStorage.getItem(ENV_KEY) || '{}') || {};
60
51
  if (client) {
61
52
  env.client = client;
62
53
  }
63
54
  if (platform) {
64
55
  env.platform = platform;
65
56
  }
66
- // SSR 兼容:安全的 localStorage 设置
67
- browserAPI.localStorage.setItem(ENV_KEY, JSON.stringify(env));
68
- // SSR 兼容:安全的 history API 访问
69
- if (clientMatch[1]) {
70
- try {
71
- var search = window.location.search.replace(new RegExp("".concat(clientMatch[0], "(&)*")), '');
72
- var hash = window.location.hash || '';
73
- var newUrl = "".concat(window.location.pathname).concat(search).concat(hash);
74
- browserAPI.history.replaceState(null, '', newUrl);
75
- } catch (e) {
76
- // 不处理
77
- }
78
- }
79
- // SSR 兼容:安全的缓存读取
80
- var cached = {};
81
57
  try {
82
- cached = JSON.parse(browserAPI.localStorage.getItem(ENV_KEY) || '{}');
58
+ localStorage.setItem(ENV_KEY, JSON.stringify(env));
83
59
  } catch (e) {
84
- cached = {};
60
+ // 不处理
61
+ }
62
+ if (clientMatch[1]) {
63
+ var search = window.location.search.replace(new RegExp("".concat(clientMatch[0], "(&)*")), '');
64
+ var hash = window.location.hash || '';
65
+ var newUrl = "".concat(window.location.pathname).concat(search).concat(hash);
66
+ history.replaceState(null, '', newUrl);
85
67
  }
86
- var crossBridgeStorage = browserAPI.localStorage.getItem('_CB__app__');
68
+ var cached = JSON.parse(localStorage.getItem(ENV_KEY) || '{}');
69
+ var crossBridgeStorage = localStorage.getItem('_CB__app__');
87
70
  return crossBridgeStorage ? __assign(__assign({}, cached), {
88
71
  client: crossBridgeStorage
89
72
  }) : cached;
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.0.90011288758-dev.2';
1
+ export default '0.0.90011319730-dev.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hylid/env",
3
- "version": "0.0.90011288758-dev.2",
3
+ "version": "0.0.90011319730-dev.1",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib"
@@ -1,15 +0,0 @@
1
- export declare const browserAPI: {
2
- isBrowser: () => boolean;
3
- isMiniProgram: () => boolean;
4
- getWindow: () => (Window & typeof globalThis) | null;
5
- getDocument: () => Document | null;
6
- getNavigator: () => Navigator | null;
7
- localStorage: {
8
- getItem: (key: string) => string | null;
9
- setItem: (key: string, value: string) => boolean;
10
- removeItem: (key: string) => boolean;
11
- };
12
- history: {
13
- replaceState: (state: any, title: string, url?: string) => boolean;
14
- };
15
- };
@@ -1,67 +0,0 @@
1
- // SSR 兼容性工具函数
2
- export var browserAPI = {
3
- // 检测是否在浏览器环境
4
- isBrowser: function isBrowser() {
5
- return typeof window !== 'undefined' && typeof document !== 'undefined';
6
- },
7
- // 检测是否在小程序环境
8
- isMiniProgram: function isMiniProgram() {
9
- return typeof my !== 'undefined';
10
- },
11
- // 安全的 window 访问
12
- getWindow: function getWindow() {
13
- return typeof window !== 'undefined' ? window : null;
14
- },
15
- // 安全的 document 访问
16
- getDocument: function getDocument() {
17
- return typeof document !== 'undefined' ? document : null;
18
- },
19
- // 安全的 navigator 访问
20
- getNavigator: function getNavigator() {
21
- if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
22
- return null;
23
- }
24
- return window.navigator;
25
- },
26
- // 安全的 localStorage 访问
27
- localStorage: {
28
- getItem: function getItem(key) {
29
- if (typeof window === 'undefined') return null;
30
- try {
31
- return localStorage.getItem(key);
32
- } catch (e) {
33
- return null;
34
- }
35
- },
36
- setItem: function setItem(key, value) {
37
- if (typeof window === 'undefined') return false;
38
- try {
39
- localStorage.setItem(key, value);
40
- return true;
41
- } catch (e) {
42
- return false;
43
- }
44
- },
45
- removeItem: function removeItem(key) {
46
- if (typeof window === 'undefined') return false;
47
- try {
48
- localStorage.removeItem(key);
49
- return true;
50
- } catch (e) {
51
- return false;
52
- }
53
- }
54
- },
55
- // 安全的 history 访问
56
- history: {
57
- replaceState: function replaceState(state, title, url) {
58
- if (typeof window === 'undefined' || !window.history) return false;
59
- try {
60
- window.history.replaceState(state, title, url);
61
- return true;
62
- } catch (e) {
63
- return false;
64
- }
65
- }
66
- }
67
- };
@@ -1 +0,0 @@
1
-
@@ -1 +0,0 @@
1
- "use strict";