hylid-bridge 2.3.0 → 2.4.0-alpha.0

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.
Files changed (141) hide show
  1. package/lib/appEnv/getEnv.d.ts +20 -0
  2. package/lib/appEnv/getEnv.js +183 -0
  3. package/lib/appEnv/index.d.ts +3 -19
  4. package/lib/appEnv/index.js +4 -42
  5. package/lib/bridges.js +149 -147
  6. package/lib/clients/mp/alipay_plus/generated.d.ts +0 -1
  7. package/lib/clients/mp/alipay_plus/index.d.ts +0 -1
  8. package/lib/clients/mp/lazada/custom.d.ts +0 -1
  9. package/lib/clients/mp/lazada/generated.d.ts +0 -1
  10. package/lib/clients/mp/lazada/index.d.ts +0 -1
  11. package/lib/clients/mp/taobao/custom.d.ts +0 -1
  12. package/lib/clients/mp/taobao/generated.d.ts +0 -1
  13. package/lib/clients/mp/taobao/index.d.ts +0 -1
  14. package/lib/clients/mp_web/alipay/generated.d.ts +0 -1
  15. package/lib/clients/mp_web/alipay/index.d.ts +0 -1
  16. package/lib/clients/mp_web/alipay_plus/generated.d.ts +0 -1
  17. package/lib/clients/mp_web/alipay_plus/index.d.ts +0 -1
  18. package/lib/clients/web/alipay/chooseImage.d.ts +0 -1
  19. package/lib/clients/web/alipay/custom.d.ts +0 -1
  20. package/lib/clients/web/alipay/generated.d.ts +0 -1
  21. package/lib/clients/web/alipay/index.d.ts +0 -1
  22. package/lib/clients/web/alipay_plus/chooseImage.d.ts +0 -1
  23. package/lib/clients/web/alipay_plus/custom.d.ts +0 -1
  24. package/lib/clients/web/alipay_plus/generated.d.ts +0 -1
  25. package/lib/clients/web/alipay_plus/index.d.ts +0 -1
  26. package/lib/clients/web/h5/hideToast.d.ts +2 -1
  27. package/lib/clients/web/h5/hideToast.js +4 -1
  28. package/lib/clients/web/h5/index.d.ts +1 -1
  29. package/lib/common/apis/custom/web/alert.d.ts +0 -1
  30. package/lib/common/apis/generated/addPhoneContact.d.ts +0 -1
  31. package/lib/common/apis/generated/alert.d.ts +0 -1
  32. package/lib/common/apis/generated/chooseImage.d.ts +0 -1
  33. package/lib/common/apis/generated/choosePhoneContact.d.ts +0 -1
  34. package/lib/common/apis/generated/clearStorage.d.ts +0 -1
  35. package/lib/common/apis/generated/closeBluetoothAdapter.d.ts +0 -1
  36. package/lib/common/apis/generated/closeSocket.d.ts +0 -1
  37. package/lib/common/apis/generated/confirm.d.ts +0 -1
  38. package/lib/common/apis/generated/connectBLEDevice.d.ts +0 -1
  39. package/lib/common/apis/generated/connectSocket.d.ts +0 -1
  40. package/lib/common/apis/generated/createAnimation.d.ts +0 -1
  41. package/lib/common/apis/generated/createWebViewContext.d.ts +0 -1
  42. package/lib/common/apis/generated/crossPay.d.ts +0 -1
  43. package/lib/common/apis/generated/datePicker.d.ts +0 -1
  44. package/lib/common/apis/generated/disconnectBLEDevice.d.ts +0 -1
  45. package/lib/common/apis/generated/downloadFile.d.ts +0 -1
  46. package/lib/common/apis/generated/getAuthCode.d.ts +0 -1
  47. package/lib/common/apis/generated/getBLEDeviceCharacteristics.d.ts +0 -1
  48. package/lib/common/apis/generated/getBLEDeviceServices.d.ts +0 -1
  49. package/lib/common/apis/generated/getBatteryInfo.d.ts +0 -1
  50. package/lib/common/apis/generated/getBluetoothAdapterState.d.ts +0 -1
  51. package/lib/common/apis/generated/getBluetoothDevices.d.ts +0 -1
  52. package/lib/common/apis/generated/getClipboard.d.ts +0 -1
  53. package/lib/common/apis/generated/getConnectedBluetoothDevices.d.ts +0 -1
  54. package/lib/common/apis/generated/getFileInfo.d.ts +0 -1
  55. package/lib/common/apis/generated/getImageInfo.d.ts +0 -1
  56. package/lib/common/apis/generated/getLocation.d.ts +0 -1
  57. package/lib/common/apis/generated/getNetworkType.d.ts +0 -1
  58. package/lib/common/apis/generated/getOpenUserInfo.d.ts +0 -1
  59. package/lib/common/apis/generated/getSavedFileInfo.d.ts +0 -1
  60. package/lib/common/apis/generated/getSavedFileList.d.ts +0 -1
  61. package/lib/common/apis/generated/getScreenBrightness.d.ts +0 -1
  62. package/lib/common/apis/generated/getServerTime.d.ts +0 -1
  63. package/lib/common/apis/generated/getSetting.d.ts +0 -1
  64. package/lib/common/apis/generated/getSiteInfo.d.ts +0 -1
  65. package/lib/common/apis/generated/getStorage.d.ts +0 -1
  66. package/lib/common/apis/generated/getSystemInfo.d.ts +0 -1
  67. package/lib/common/apis/generated/hideLoading.d.ts +0 -1
  68. package/lib/common/apis/generated/hideTabBar.d.ts +0 -1
  69. package/lib/common/apis/generated/hideToast.d.ts +0 -1
  70. package/lib/common/apis/generated/multiLevelSelect.d.ts +0 -1
  71. package/lib/common/apis/generated/navigateBack.d.ts +0 -1
  72. package/lib/common/apis/generated/navigateBackMiniProgram.d.ts +0 -1
  73. package/lib/common/apis/generated/navigateTo.d.ts +0 -1
  74. package/lib/common/apis/generated/navigateToMiniProgram.d.ts +0 -1
  75. package/lib/common/apis/generated/notifyBLECharacteristicValueChange.d.ts +0 -1
  76. package/lib/common/apis/generated/onBluetoothAdapterStateChange.d.ts +0 -1
  77. package/lib/common/apis/generated/onBluetoothDeviceFound.d.ts +0 -1
  78. package/lib/common/apis/generated/openBluetoothAdapter.d.ts +0 -1
  79. package/lib/common/apis/generated/openDocument.d.ts +0 -1
  80. package/lib/common/apis/generated/openSetting.d.ts +0 -1
  81. package/lib/common/apis/generated/pageScrollTo.d.ts +0 -1
  82. package/lib/common/apis/generated/previewImage.d.ts +0 -1
  83. package/lib/common/apis/generated/prompt.d.ts +0 -1
  84. package/lib/common/apis/generated/reLaunch.d.ts +0 -1
  85. package/lib/common/apis/generated/readBLECharacteristicValue.d.ts +0 -1
  86. package/lib/common/apis/generated/redirectTo.d.ts +0 -1
  87. package/lib/common/apis/generated/removeSavedFile.d.ts +0 -1
  88. package/lib/common/apis/generated/removeStorage.d.ts +0 -1
  89. package/lib/common/apis/generated/request.d.ts +0 -1
  90. package/lib/common/apis/generated/saveFile.d.ts +0 -1
  91. package/lib/common/apis/generated/saveImage.d.ts +0 -1
  92. package/lib/common/apis/generated/scan.d.ts +0 -1
  93. package/lib/common/apis/generated/sendSocketMessage.d.ts +0 -1
  94. package/lib/common/apis/generated/setBackgroundColor.d.ts +0 -1
  95. package/lib/common/apis/generated/setClipboard.d.ts +0 -1
  96. package/lib/common/apis/generated/setKeepScreenOn.d.ts +0 -1
  97. package/lib/common/apis/generated/setNavigationBar.d.ts +0 -1
  98. package/lib/common/apis/generated/setOptionMenu.d.ts +0 -1
  99. package/lib/common/apis/generated/setScreenBrightness.d.ts +0 -1
  100. package/lib/common/apis/generated/setStorage.d.ts +0 -1
  101. package/lib/common/apis/generated/setTabBarStyle.d.ts +0 -1
  102. package/lib/common/apis/generated/showActionSheet.d.ts +0 -1
  103. package/lib/common/apis/generated/showAuthGuide.d.ts +0 -1
  104. package/lib/common/apis/generated/showLoading.d.ts +0 -1
  105. package/lib/common/apis/generated/showToast.d.ts +0 -1
  106. package/lib/common/apis/generated/signContract.d.ts +0 -1
  107. package/lib/common/apis/generated/startBluetoothDevicesDiscovery.d.ts +0 -1
  108. package/lib/common/apis/generated/startPullDownRefresh.d.ts +0 -1
  109. package/lib/common/apis/generated/stopBluetoothDevicesDiscovery.d.ts +0 -1
  110. package/lib/common/apis/generated/stopPullDownRefresh.d.ts +0 -1
  111. package/lib/common/apis/generated/switchTab.d.ts +0 -1
  112. package/lib/common/apis/generated/tradePay.d.ts +0 -1
  113. package/lib/common/apis/generated/uploadFile.d.ts +0 -1
  114. package/lib/common/apis/generated/vibrate.d.ts +0 -1
  115. package/lib/common/apis/generated/watchShake.d.ts +0 -1
  116. package/lib/common/apis/generated/writeBLECharacteristicValue.d.ts +0 -1
  117. package/lib/common/call/index.js +3 -1
  118. package/lib/common/call/mpWeb.d.ts +2 -2
  119. package/lib/common/notFound.js +1 -1
  120. package/lib/common/utils.d.ts +1 -2
  121. package/lib/common/utils.js +1 -1
  122. package/lib/index.js +3 -1
  123. package/lib/objectSpread.d.ts +1 -0
  124. package/lib/objectSpread.js +3 -0
  125. package/lib/umd/index.js +1 -1
  126. package/lib/umd/mp_alipay_plus.js +2 -1
  127. package/lib/umd/mp_alipay_plus.js.LICENSE.txt +1 -0
  128. package/lib/umd/mp_lazada.js +2 -1
  129. package/lib/umd/mp_lazada.js.LICENSE.txt +1 -0
  130. package/lib/umd/mp_taobao.js +2 -1
  131. package/lib/umd/mp_taobao.js.LICENSE.txt +1 -0
  132. package/lib/umd/mp_web_alipay.js +2 -1
  133. package/lib/umd/mp_web_alipay.js.LICENSE.txt +1 -0
  134. package/lib/umd/mp_web_alipay_plus.js +2 -1
  135. package/lib/umd/mp_web_alipay_plus.js.LICENSE.txt +1 -0
  136. package/lib/umd/web_alipay.js +2 -1
  137. package/lib/umd/web_alipay.js.LICENSE.txt +1 -0
  138. package/lib/umd/web_alipay_plus.js +2 -1
  139. package/lib/umd/web_alipay_plus.js.LICENSE.txt +1 -0
  140. package/lib/umd/web_h5.js +1 -1
  141. package/package.json +14 -9
@@ -0,0 +1,20 @@
1
+ import { clientName, platformType } from '../common/constants';
2
+ export interface AppEnv {
3
+ isMpAlipayPlus: boolean;
4
+ isMpLazada: boolean;
5
+ isMpTaobao: boolean;
6
+ isWebAlipayPlus: boolean;
7
+ isWebAlipay: boolean;
8
+ isMpWebAlipayPlus: boolean;
9
+ isMpWebAlipay: boolean;
10
+ isMpAlipay: boolean;
11
+ isWebH5: boolean;
12
+ isWebAlipayHk: boolean;
13
+ }
14
+ interface Env {
15
+ appEnv: AppEnv;
16
+ platform?: platformType;
17
+ client?: clientName;
18
+ }
19
+ export default function getEnv(): Env | undefined;
20
+ export {};
@@ -0,0 +1,183 @@
1
+ import _silent from "@goldfishjs/utils/lib/silent";
2
+ import _find from "@goldfishjs/utils/lib/find";
3
+ import { upFirst } from "../common/utils";
4
+ import { clients } from "./clients";
5
+ import { clientName, detectType, platformType } from "../common/constants";
6
+
7
+ function setDefaultWebH5(env) {
8
+ if (!env.client) {
9
+ env.client = clientName.webH5;
10
+ }
11
+
12
+ if (!env.platform) {
13
+ env.platform = platformType.web;
14
+ }
15
+
16
+ var hasTrue = false;
17
+
18
+ for (var key in env.appEnv) {
19
+ if (env.appEnv[key]) {
20
+ hasTrue = true;
21
+ break;
22
+ }
23
+ }
24
+
25
+ if (!hasTrue) {
26
+ env.appEnv.isWebH5 = true;
27
+ }
28
+ }
29
+
30
+ function parseAppAndUA(clientsParam, info) {
31
+ var targetClient = _find(clientsParam, function (client) {
32
+ return client.regs.every(function (reg) {
33
+ return reg.test(info);
34
+ });
35
+ });
36
+
37
+ var env = {};
38
+ var appEnv = Object.keys(clientName).reduce(function (result, clientNameKey) {
39
+ var name = clientName[clientNameKey];
40
+ var key = "is".concat(name.split('_').map(upFirst).join(''));
41
+ result[key] = name === (targetClient === null || targetClient === void 0 ? void 0 : targetClient.name);
42
+
43
+ if (result[key]) {
44
+ env.client = name;
45
+ }
46
+
47
+ return result;
48
+ }, {});
49
+ env.appEnv = appEnv;
50
+ env.platform = targetClient === null || targetClient === void 0 ? void 0 : targetClient.type;
51
+ return env;
52
+ }
53
+
54
+ function getEnvFromSystemInfo() {
55
+ var info = _silent(function () {
56
+ return my.getSystemInfoSync();
57
+ })();
58
+
59
+ if (!info || !info.app) {
60
+ return;
61
+ }
62
+
63
+ var localClients = clients.filter(function (client) {
64
+ return client.detectType === detectType.app;
65
+ });
66
+ return parseAppAndUA(localClients, info.app);
67
+ }
68
+
69
+ function getEnvFromUA() {
70
+ var info = _silent(function () {
71
+ var env = window;
72
+ return env.navigator.userAgent;
73
+ })();
74
+
75
+ if (!info) {
76
+ return;
77
+ }
78
+
79
+ var localClients = clients.filter(function (client) {
80
+ return client.detectType === detectType.ua;
81
+ });
82
+ var env = parseAppAndUA(localClients, info); // Since we can visit the `window`, we can also return the pure H5 environment
83
+
84
+ setDefaultWebH5(env);
85
+ return env;
86
+ }
87
+
88
+ function parseApp(app) {
89
+ var normalizeClientName = function normalizeClientName(str) {
90
+ return str.replace(/_/g, '').toLocaleLowerCase();
91
+ };
92
+
93
+ var normalizedApp = normalizeClientName(app);
94
+ var client = undefined;
95
+ var platform = undefined;
96
+ var appEnv = Object.keys(clientName).reduce(function (result, clientNameKey) {
97
+ var name = clientName[clientNameKey];
98
+ var key = "is".concat(name.split('_').map(upFirst).join(''));
99
+ result[key] = normalizeClientName(name) === normalizedApp;
100
+
101
+ if (result[key]) {
102
+ client = name;
103
+ platform = name.match(/mp_web|mp|web/)[0];
104
+ }
105
+
106
+ return result;
107
+ }, {});
108
+ return {
109
+ appEnv: appEnv,
110
+ client: client,
111
+ platform: platform
112
+ };
113
+ }
114
+
115
+ function getEnvFromUrl() {
116
+ // The value of `__app__` is MpAlipayHK, WebAlipay and so on.
117
+ var app = _silent(function () {
118
+ return (window.location.search.match(/[?&]__app__=([^?&=]+)/) || [])[1];
119
+ })();
120
+
121
+ var env = app ? parseApp(app) : undefined;
122
+
123
+ if (env) {
124
+ // Since we can visit the `window`, we can also return the pure H5 environment
125
+ setDefaultWebH5(env);
126
+ }
127
+
128
+ return env;
129
+ }
130
+
131
+ function getEnvFromLocalStorage() {
132
+ // The value of `__app__` is MpAlipayHK, WebAlipay and so on.
133
+ var app = _silent(function () {
134
+ return localStorage.getItem('__app__');
135
+ })();
136
+
137
+ var env = app ? parseApp(app) : undefined;
138
+
139
+ if (env) {
140
+ // Since we can visit the `window`, we can also return the pure H5 environment
141
+ setDefaultWebH5(env);
142
+ }
143
+
144
+ return env;
145
+ }
146
+
147
+ export default function getEnv() {
148
+ var env = getEnvFromSystemInfo();
149
+
150
+ if (env) {
151
+ return env;
152
+ }
153
+
154
+ env = getEnvFromUrl();
155
+
156
+ if (env) {
157
+ return env;
158
+ }
159
+
160
+ env = getEnvFromLocalStorage();
161
+
162
+ if (env) {
163
+ return env;
164
+ }
165
+
166
+ env = getEnvFromUA();
167
+
168
+ if (env) {
169
+ return env;
170
+ } // It is H5 environment, and use the pure H5.
171
+
172
+
173
+ if (typeof window !== 'undefined') {
174
+ var app = 'WebH5';
175
+ env = parseApp(app);
176
+
177
+ if (env) {
178
+ return env;
179
+ }
180
+ }
181
+
182
+ return;
183
+ }
@@ -1,20 +1,4 @@
1
- import { clientName, platformType } from '../common/constants';
2
- interface AppEnv {
3
- isMpAlipayPlus: boolean;
4
- isMpLazada: boolean;
5
- isMpTaobao: boolean;
6
- isWebAlipayPlus: boolean;
7
- isWebAlipay: boolean;
8
- isMpWebAlipayPlus: boolean;
9
- isMpWebAlipay: boolean;
10
- isMpAlipay: boolean;
11
- isWebH5: boolean;
12
- }
13
- interface Env {
14
- appEnv: AppEnv;
15
- platform: platformType;
16
- client: clientName;
17
- }
18
- export declare const getEnv: () => Env;
19
- export declare const appEnv: AppEnv;
1
+ import { AppEnv } from './getEnv';
2
+ export { default as getEnv } from './getEnv';
3
+ export declare const appEnv: Partial<AppEnv>;
20
4
  export default appEnv;
@@ -1,44 +1,6 @@
1
- import { upFirst } from "../common/utils";
2
- import { clients } from "./clients";
3
- import { detectClientInfo, getDefaultClient } from "./utils";
4
- export var getEnv = function () {
5
- var env = {};
6
- var inited = false;
7
- return function () {
8
- if (inited) return env;
1
+ var _a;
9
2
 
10
- var _a = detectClientInfo(),
11
- info = _a.info,
12
- detectType = _a.detectType;
13
-
14
- var _clients = clients.filter(function (client) {
15
- return client.detectType === detectType;
16
- });
17
-
18
- var _b = _clients.find(function (client) {
19
- return client.regs.every(function (reg) {
20
- return reg.test(info);
21
- });
22
- }) || getDefaultClient(),
23
- client = _b.name,
24
- platform = _b.type;
25
-
26
- var appEnv = clients.reduce(function (result, _a) {
27
- var name = _a.name;
28
- var key = 'is' + name.split('_').map(upFirst).join('');
29
-
30
- if (name === client) {
31
- env.client = client;
32
- }
33
-
34
- result[key] = name === client;
35
- return result;
36
- }, {});
37
- env.appEnv = appEnv;
38
- env.platform = platform;
39
- inited = true;
40
- return env;
41
- };
42
- }();
43
- export var appEnv = getEnv().appEnv;
3
+ import getEnv from "./getEnv";
4
+ export { default as getEnv } from "./getEnv";
5
+ export var appEnv = ((_a = getEnv()) === null || _a === void 0 ? void 0 : _a.appEnv) || {};
44
6
  export default appEnv;