@microbt/environment 1.2.6 → 1.2.8

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.
package/README.md CHANGED
@@ -160,6 +160,39 @@ console.log(versionInfo);
160
160
  // 在非 SuperAcme 应用中输出:{ version: "unknown" }
161
161
  ```
162
162
 
163
+ ### `getStatusBarHeight()`
164
+
165
+ > 2.6.0 新增
166
+
167
+ 获取 SuperAcme 应用的状态栏高度信息。
168
+
169
+ **返回值**: 返回一个包含状态栏高度信息的对象:
170
+
171
+ ```json
172
+ {
173
+ top: number; // 顶部状态栏高度,单位为像素
174
+ bottom: number; // 底部状态栏高度,单位为像素
175
+ }
176
+ ```
177
+
178
+ 如果不在 SuperAcme 应用中或无法解析高度信息,将返回默认值:
179
+
180
+ ```json
181
+ {
182
+ "top": 0,
183
+ "bottom": 0
184
+ }
185
+ ```
186
+
187
+ **示例** :
188
+
189
+ ```typescript
190
+ const statusBarHeight = getStatusBarHeight();
191
+ console.log(statusBarHeight);
192
+ // 可能输出:{ top: 20, bottom: 0 }
193
+ // 在非 SuperAcme 应用中输出:{ top: 0, bottom: 0 }
194
+ ```
195
+
163
196
  ## 平台相关函数
164
197
 
165
198
  ### `iOSWebview`
@@ -1,5 +1,5 @@
1
1
  // src/cookie.ts
2
- var COOKIE_REGEX = (name) => new RegExp("(^| )" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^;]+)");
2
+ var COOKIE_REGEX = (name) => new RegExp("(^| )" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^;]*)");
3
3
  function getCookie(name) {
4
4
  try {
5
5
  const match = document.cookie.match(COOKIE_REGEX(name));
@@ -1,5 +1,6 @@
1
1
  // src/environment/factory.ts
2
2
  import { CinmooreEnvironmentStrategy } from "./strategies/cinmoore";
3
+ import { CinvueEnvironmentStrategy } from "./strategies/cinvue";
3
4
  import { FronAIEnvironmentStrategy } from "./strategies/fronai";
4
5
  import { LocalEnvironmentStrategy } from "./strategies/local";
5
6
  import { Safio365EnvironmentStrategy } from "./strategies/safio365";
@@ -22,12 +23,13 @@ var EnvironmentStrategyFactory = _EnvironmentStrategyFactory;
22
23
  EnvironmentStrategyFactory.strategies = /* @__PURE__ */ new Map();
23
24
  EnvironmentStrategyFactory.localStrategy = new LocalEnvironmentStrategy();
24
25
  (() => {
25
- _EnvironmentStrategyFactory.strategies.set("superacme.com", new SuperAcmeEnvironmentStrategy());
26
- _EnvironmentStrategyFactory.strategies.set("safio365.com", new Safio365EnvironmentStrategy());
27
- _EnvironmentStrategyFactory.strategies.set("sensforge.com", new SensforgeEnvironmentStrategy());
28
26
  _EnvironmentStrategyFactory.strategies.set("cinmoore.com", new CinmooreEnvironmentStrategy());
29
27
  _EnvironmentStrategyFactory.strategies.set("cinmoore.cn", new CinmooreEnvironmentStrategy());
28
+ _EnvironmentStrategyFactory.strategies.set("cinvue.com", new CinvueEnvironmentStrategy());
30
29
  _EnvironmentStrategyFactory.strategies.set("fronai.cn", new FronAIEnvironmentStrategy());
30
+ _EnvironmentStrategyFactory.strategies.set("safio365.com", new Safio365EnvironmentStrategy());
31
+ _EnvironmentStrategyFactory.strategies.set("sensforge.com", new SensforgeEnvironmentStrategy());
32
+ _EnvironmentStrategyFactory.strategies.set("superacme.com", new SuperAcmeEnvironmentStrategy());
31
33
  _EnvironmentStrategyFactory.strategies.set("superacmeglobal.com", new SuperacmeGlobalEnvironmentStrategy());
32
34
  })();
33
35
  export {
@@ -8,6 +8,7 @@ var SUPPORTED_DOMAINS = [
8
8
  "sensforge.com",
9
9
  "fronai.cn",
10
10
  "superacmeglobal.com",
11
+ "cinvue.com",
11
12
  "0.0.0.0",
12
13
  "127.0.0.1",
13
14
  "localhost"
@@ -0,0 +1,7 @@
1
+ export declare class CinvueEnvironmentStrategy implements EnvironmentStrategy {
2
+ features: EnvironmentFeatures;
3
+ private readonly ENV_PATTERNS;
4
+ getEnvironment(host: string): string;
5
+ getRegion(): string;
6
+ isAWS(): boolean;
7
+ }
@@ -0,0 +1,42 @@
1
+ // src/environment/strategies/cinvue.ts
2
+ var CinvueEnvironmentStrategy = class {
3
+ constructor() {
4
+ this.features = {
5
+ supportEnv: true,
6
+ supportRegion: false,
7
+ supportAWS: false
8
+ };
9
+ this.ENV_PATTERNS = {
10
+ // 匹配 -dev、-dev1、-dev-1、-dev. 等
11
+ dev: /-dev(?:\d*)?(?:-|\.|\b|$)/,
12
+ // 匹配 -test、-test1、-test-1、-test. 等
13
+ test: /-test(?:\d*)?(?:-|\.|\b|$)/,
14
+ // 匹配 -pre、-pre1、-pre-1、-pre. 等
15
+ pre: /-pre(?:\d*)?(?:-|\.|\b|$)/,
16
+ // 匹配 -gray、-gray1、-gray-1、-gray. 等
17
+ gray: /-gray(?:\d*)?(?:-|\.|\b|$)/,
18
+ // 本地环境
19
+ local: /^(localhost|127\.0\.0\.1|0\.0\.0\.0)(?::\d+)?$/
20
+ };
21
+ }
22
+ getEnvironment(host) {
23
+ if (this.ENV_PATTERNS.local.test(host)) {
24
+ return "local";
25
+ }
26
+ for (const [env, pattern] of Object.entries(this.ENV_PATTERNS)) {
27
+ if (pattern.test(host)) {
28
+ return env;
29
+ }
30
+ }
31
+ return "prod";
32
+ }
33
+ getRegion() {
34
+ return "unknown";
35
+ }
36
+ isAWS() {
37
+ return false;
38
+ }
39
+ };
40
+ export {
41
+ CinvueEnvironmentStrategy
42
+ };
@@ -2,6 +2,7 @@
2
2
  import {
3
3
  CinmooreCnURLStrategy,
4
4
  CinmooreComURLStrategy,
5
+ CinvueURLStrategy,
5
6
  FronAiURLStrategy,
6
7
  Safio365URLStrategy,
7
8
  SensforgeURLStrategy,
@@ -20,12 +21,13 @@ var _URLStrategyFactory = class {
20
21
  var URLStrategyFactory = _URLStrategyFactory;
21
22
  URLStrategyFactory.strategies = /* @__PURE__ */ new Map();
22
23
  (() => {
23
- _URLStrategyFactory.strategies.set("superacme.com", new SuperAcmeURLStrategy());
24
- _URLStrategyFactory.strategies.set("sensforge.com", new SensforgeURLStrategy());
25
- _URLStrategyFactory.strategies.set("safio365.com", new Safio365URLStrategy());
26
24
  _URLStrategyFactory.strategies.set("cinmoore.cn", new CinmooreCnURLStrategy());
27
25
  _URLStrategyFactory.strategies.set("cinmoore.com", new CinmooreComURLStrategy());
26
+ _URLStrategyFactory.strategies.set("cinvue.com", new CinvueURLStrategy());
28
27
  _URLStrategyFactory.strategies.set("fronai.cn", new FronAiURLStrategy());
28
+ _URLStrategyFactory.strategies.set("safio365.com", new Safio365URLStrategy());
29
+ _URLStrategyFactory.strategies.set("sensforge.com", new SensforgeURLStrategy());
30
+ _URLStrategyFactory.strategies.set("superacme.com", new SuperAcmeURLStrategy());
29
31
  _URLStrategyFactory.strategies.set("superacmeglobal.com", new SuperAcmeGlobalURLStrategy());
30
32
  })();
31
33
  export {
@@ -0,0 +1,4 @@
1
+ export declare class CinvueURLStrategy implements URLStrategy {
2
+ features: DomainFeatures;
3
+ generateURL({ name, env, path }: URLStrategyConfig): string;
4
+ }
@@ -0,0 +1,19 @@
1
+ // src/gateway/strategies/cinvue.ts
2
+ var CinvueURLStrategy = class {
3
+ constructor() {
4
+ this.features = {
5
+ supportEnv: true,
6
+ supportRegion: false,
7
+ supportAWS: false
8
+ };
9
+ }
10
+ generateURL({ name, env = "prod", path = "" }) {
11
+ if (env === "prod" || !env) {
12
+ return `//${name}.cinvue.com${path}`;
13
+ }
14
+ return `//${name}-${env}.cinvue.com${path}`;
15
+ }
16
+ };
17
+ export {
18
+ CinvueURLStrategy
19
+ };
@@ -1,5 +1,6 @@
1
1
  export * from './cinmoore.cn';
2
2
  export * from './cinmoore.com';
3
+ export * from './cinvue';
3
4
  export * from './fronai.cn';
4
5
  export * from './safio365';
5
6
  export * from './sensforge';
@@ -1,6 +1,7 @@
1
1
  // src/gateway/strategies/index.ts
2
2
  export * from "./cinmoore.cn";
3
3
  export * from "./cinmoore.com";
4
+ export * from "./cinvue";
4
5
  export * from "./fronai.cn";
5
6
  export * from "./safio365";
6
7
  export * from "./sensforge";
@@ -9,3 +9,7 @@ export declare function superAcmeVersion(): {
9
9
  minor: number;
10
10
  patch: number;
11
11
  };
12
+ export declare function getStatusBarHeight(): {
13
+ top: number;
14
+ bottom: number;
15
+ };
@@ -75,6 +75,8 @@ function inSuperAcme() {
75
75
  return navigator.userAgent.toLowerCase().includes("superacme");
76
76
  }
77
77
  var VERSION_REGEX = /AppVersion\s([\d.]+)/;
78
+ var STATUSBAR_TOP_REGEX = /statusBarTop:([\d.]+)/;
79
+ var STATUSBAR_BOTTOM_REGEX = /statusBarBottom:([\d.]+)/;
78
80
  function superAcmeVersion() {
79
81
  const ua = navigator.userAgent;
80
82
  const UNKNOWN = {
@@ -96,9 +98,26 @@ function superAcmeVersion() {
96
98
  }
97
99
  return UNKNOWN;
98
100
  }
101
+ function getStatusBarHeight() {
102
+ const ua = navigator.userAgent;
103
+ const DEFAULT_HEIGHT = {
104
+ top: 0,
105
+ bottom: 0
106
+ };
107
+ if (!inSuperAcme()) {
108
+ return DEFAULT_HEIGHT;
109
+ }
110
+ const topMatch = ua.match(STATUSBAR_TOP_REGEX);
111
+ const bottomMatch = ua.match(STATUSBAR_BOTTOM_REGEX);
112
+ return {
113
+ top: topMatch ? parseFloat(topMatch[1]) : DEFAULT_HEIGHT.top,
114
+ bottom: bottomMatch ? parseFloat(bottomMatch[1]) : DEFAULT_HEIGHT.bottom
115
+ };
116
+ }
99
117
  export {
100
118
  bridgeBootstrap,
101
119
  bridgeCall,
120
+ getStatusBarHeight,
102
121
  inSuperAcme,
103
122
  superAcmeVersion
104
123
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microbt/environment",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "microbt app library for environment",
5
5
  "keywords": [],
6
6
  "license": "MIT",