hylid-bridge 4.0.27-alpha.0 → 4.0.27-alpha.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.
@@ -21,6 +21,11 @@ interface IQuery {
21
21
  * @default getSystemInfoSync().version
22
22
  */
23
23
  clientVersion?: string;
24
+ /**
25
+ * @description 是否开启 debug 模式,开启 debug 将 toast 提示 canIUse 执行结果与具体错误原因
26
+ * @default false
27
+ */
28
+ debug?: boolean;
24
29
  }
25
- export declare function whichCanIUse(apiName: string, options?: IQuery): Promise<any>;
30
+ export declare function whichCanIUse(apiName: string, options?: IQuery): any;
26
31
  export {};
@@ -1,192 +1,88 @@
1
- var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) {
3
- return value instanceof P ? value : new P(function (resolve) {
4
- resolve(value);
5
- });
6
- }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) {
9
- try {
10
- step(generator.next(value));
11
- } catch (e) {
12
- reject(e);
13
- }
14
- }
15
- function rejected(value) {
16
- try {
17
- step(generator["throw"](value));
18
- } catch (e) {
19
- reject(e);
20
- }
21
- }
22
- function step(result) {
23
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
24
- }
25
- step((generator = generator.apply(thisArg, _arguments || [])).next());
26
- });
27
- };
28
- var __generator = this && this.__generator || function (thisArg, body) {
29
- var _ = {
30
- label: 0,
31
- sent: function sent() {
32
- if (t[0] & 1) throw t[1];
33
- return t[1];
34
- },
35
- trys: [],
36
- ops: []
37
- },
38
- f,
39
- y,
40
- t,
41
- g;
42
- return g = {
43
- next: verb(0),
44
- "throw": verb(1),
45
- "return": verb(2)
46
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
47
- return this;
48
- }), g;
49
- function verb(n) {
50
- return function (v) {
51
- return step([n, v]);
52
- };
53
- }
54
- function step(op) {
55
- if (f) throw new TypeError("Generator is already executing.");
56
- while (_) try {
57
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
- if (y = 0, t) op = [op[0] & 2, t.value];
59
- switch (op[0]) {
60
- case 0:
61
- case 1:
62
- t = op;
63
- break;
64
- case 4:
65
- _.label++;
66
- return {
67
- value: op[1],
68
- done: false
69
- };
70
- case 5:
71
- _.label++;
72
- y = op[1];
73
- op = [0];
74
- continue;
75
- case 7:
76
- op = _.ops.pop();
77
- _.trys.pop();
78
- continue;
79
- default:
80
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
81
- _ = 0;
82
- continue;
83
- }
84
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
- _.label = op[1];
86
- break;
87
- }
88
- if (op[0] === 6 && _.label < t[1]) {
89
- _.label = t[1];
90
- t = op;
91
- break;
92
- }
93
- if (t && _.label < t[2]) {
94
- _.label = t[2];
95
- _.ops.push(op);
96
- break;
97
- }
98
- if (t[2]) _.ops.pop();
99
- _.trys.pop();
100
- continue;
101
- }
102
- op = body.call(thisArg, _);
103
- } catch (e) {
104
- op = [6, e];
105
- y = 0;
106
- } finally {
107
- f = t = 0;
108
- }
109
- if (op[0] & 5) throw op[1];
110
- return {
111
- value: op[0] ? op[1] : void 0,
112
- done: true
113
- };
114
- }
115
- };
116
1
  // @ts-nocheck
117
2
  import { client, platform } from '@hylid/env';
118
3
  import compatibilitiesJson from './compatibilities.json';
119
- import { getSystemInfoAsync } from "../bridges";
4
+ import { getSystemInfoSync, showToast } from "../bridges";
120
5
  export function whichCanIUse(apiName, options) {
121
6
  var _a, _b, _c;
122
7
  if (options === void 0) {
123
8
  options = {};
124
9
  }
125
- return __awaiter(this, void 0, void 0, function () {
126
- var _platform, _client, clientVersion, osType, _d, _e, compatibilities, envMaps, apiCompatibility, envIndex, compatibility, changedVersions, i, _f, version, support, compareResult;
127
- return __generator(this, function (_g) {
128
- switch (_g.label) {
129
- case 0:
130
- _platform = options.platform, _client = options.client, clientVersion = options.clientVersion, osType = options.osType;
131
- _platform = _platform || platform;
132
- _client = _client || client;
133
- _platform = _platform === null || _platform === void 0 ? void 0 : _platform.toUpperCase();
134
- _client = _client === null || _client === void 0 ? void 0 : _client.toUpperCase();
135
- _d = osType;
136
- if (_d) return [3 /*break*/, 2];
137
- return [4 /*yield*/, getSystemInfoAsync()];
138
- case 1:
139
- _d = (_b = (_a = _g.sent()) === null || _a === void 0 ? void 0 : _a.platform) === null || _b === void 0 ? void 0 : _b.toUpperCase();
140
- _g.label = 2;
141
- case 2:
142
- osType = _d;
143
- _e = clientVersion;
144
- if (_e) return [3 /*break*/, 4];
145
- return [4 /*yield*/, getSystemInfoAsync()];
146
- case 3:
147
- _e = (_c = _g.sent()) === null || _c === void 0 ? void 0 : _c.version;
148
- _g.label = 4;
149
- case 4:
150
- clientVersion = _e;
151
- if (!_client || !_platform || !osType) return [2 /*return*/, false];
152
- compatibilities = compatibilitiesJson.data;
153
- envMaps = compatibilitiesJson.envMaps;
154
- apiCompatibility = compatibilities.find(function (item) {
155
- return item.apiName === apiName;
156
- });
157
- // 不存在该 jsapi 或 该 jsapi 兼容度数据不存在
158
- if (!apiCompatibility || !apiCompatibility.compatibilities.length) return [2 /*return*/, false];
159
- envIndex = envMaps.findIndex(function (item) {
160
- return item === "".concat(_client, "_").concat(osType, "_").concat(_platform);
161
- });
162
- // 不存在该环境的兼容度数据 return false
163
- if (envIndex === -1) return [2 /*return*/, false];
164
- compatibility = apiCompatibility.compatibilities.find(function (item) {
165
- return item.env === envIndex;
166
- });
167
- changedVersions = compatibility.changedVersions;
168
- if (changedVersions.length === 1) {
169
- // 全部支持或全部不支持
170
- if (changedVersions[0].version === '*') return [2 /*return*/, changedVersions[0].support];
171
- if (compareRule(clientVersion, changedVersions[0].version) === 1) return [2 /*return*/, changedVersions[0].support];
172
- if (compareRule(clientVersion, changedVersions[0].version) === -1) return [2 /*return*/, !changedVersions[0].support];
173
- return [2 /*return*/, changedVersions[0].support];
174
- }
175
- for (i = 0; i < changedVersions.length; i++) {
176
- _f = changedVersions[i], version = _f.version, support = _f.support;
177
- compareResult = compareRule(clientVersion, version);
178
- // 当前版本大
179
- if (compareResult === 1) {
180
- return [2 /*return*/, support];
181
- }
182
- // 和当前版本一致
183
- if (compareResult === 0) return [2 /*return*/, support];
184
- }
185
- // 版本号比所有的 changedVersions 都小
186
- return [2 /*return*/, !changedVersions[0].support];
187
- }
188
- });
10
+ var _platform = options.platform,
11
+ _client = options.client,
12
+ clientVersion = options.clientVersion,
13
+ osType = options.osType,
14
+ debug = options.debug;
15
+ _platform = _platform || platform;
16
+ _client = _client || client;
17
+ _platform = _platform === null || _platform === void 0 ? void 0 : _platform.toUpperCase();
18
+ _client = _client === null || _client === void 0 ? void 0 : _client.toUpperCase();
19
+ osType = osType || ((_b = (_a = getSystemInfoSync()) === null || _a === void 0 ? void 0 : _a.platform) === null || _b === void 0 ? void 0 : _b.toUpperCase());
20
+ clientVersion = clientVersion || ((_c = getSystemInfoSync()) === null || _c === void 0 ? void 0 : _c.version);
21
+ if (!_client || !_platform || !osType) {
22
+ if (debug) {
23
+ showToast({
24
+ content: '获取客户端/系统类型失败'
25
+ });
26
+ }
27
+ return false;
28
+ }
29
+ // 校验 jsapi 是否存在
30
+ var compatibilities = compatibilitiesJson.data;
31
+ var envMaps = compatibilitiesJson.envMaps;
32
+ var apiCompatibility = compatibilities.find(function (item) {
33
+ return item.apiName === apiName;
189
34
  });
35
+ // 不存在该 jsapi 或 该 jsapi 兼容度数据不存在
36
+ if (!apiCompatibility || !apiCompatibility.compatibilities.length) {
37
+ if (debug) {
38
+ showToast({
39
+ content: apiCompatibility ? '不存在该 jsapi 的兼容度数据' : '该 jsapi 不存在,请检查 jsapi 名称是否正确'
40
+ });
41
+ }
42
+ return false;
43
+ }
44
+ ;
45
+ // 校验 client platform osType 是否支持
46
+ var envIndex = envMaps.findIndex(function (item) {
47
+ return item === "".concat(_client, "_").concat(osType, "_").concat(_platform);
48
+ });
49
+ // 不存在该环境的兼容度数据 return false
50
+ if (envIndex === -1) {
51
+ if (debug) {
52
+ showToast({
53
+ content: '当前环境不存在该 jsapi 的兼容度数据,兜底返回 false'
54
+ });
55
+ }
56
+ return false;
57
+ }
58
+ ;
59
+ var compatibility = apiCompatibility.compatibilities.find(function (item) {
60
+ return item.env === envIndex;
61
+ });
62
+ var changedVersions = compatibility.changedVersions;
63
+ if (changedVersions.length === 1) {
64
+ // 全部支持或全部不支持
65
+ if (changedVersions[0].version === '*') return changedVersions[0].support;
66
+ if (compareRule(clientVersion, changedVersions[0].version) === 1) return changedVersions[0].support;
67
+ if (compareRule(clientVersion, changedVersions[0].version) === -1) return !changedVersions[0].support;
68
+ return changedVersions[0].support;
69
+ }
70
+ for (var i = 0; i < changedVersions.length; i++) {
71
+ // changedVersions 版本号从小到大排序的
72
+ // version 是变化的版本,support 为 true 代表这个版本
73
+ var _d = changedVersions[i],
74
+ version = _d.version,
75
+ support = _d.support;
76
+ var compareResult = compareRule(clientVersion, version);
77
+ // 当前版本大
78
+ if (compareResult === 1) {
79
+ return support;
80
+ }
81
+ // 和当前版本一致
82
+ if (compareResult === 0) return support;
83
+ }
84
+ // 版本号比所有的 changedVersions 都小
85
+ return !changedVersions[0].support;
190
86
  }
191
87
  function compareRule(version1, version2) {
192
88
  var v1Parts = version1.split('.').map(Number);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hylid-bridge",
3
- "version": "4.0.27-alpha.0",
3
+ "version": "4.0.27-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "description": "Unite Api For MiniProgram Project",
6
6
  "files": [
@@ -56,10 +56,10 @@
56
56
  "dependencies": {
57
57
  "@babel/runtime": "7.18.9",
58
58
  "@goldfishjs/utils": "^2.18.0",
59
- "@hylid/call": "^4.0.27-alpha.0",
60
- "@hylid/custom-jsapi": "^4.0.27-alpha.0",
61
- "@hylid/env": "^4.0.27-alpha.0",
62
- "@hylid/types": "^4.0.27-alpha.0",
59
+ "@hylid/call": "^4.0.27-alpha.1",
60
+ "@hylid/custom-jsapi": "^4.0.27-alpha.1",
61
+ "@hylid/env": "^4.0.27-alpha.1",
62
+ "@hylid/types": "^4.0.27-alpha.1",
63
63
  "@types/miniprogram": "^1.0.3",
64
64
  "miniapp-web-jsapi": "^4.0.23",
65
65
  "qs-es5": "^6.8.4",
@@ -1,2 +0,0 @@
1
- import fill from '../../../common/apis/generated/web/getSystemInfo';
2
- export default fill;
@@ -1,3 +0,0 @@
1
- // auto-generated
2
- import fill from '../../../common/apis/generated/web/getSystemInfo';
3
- export default fill;
@@ -1,22 +0,0 @@
1
- import { AsyncCallback } from '@hylid/types';
2
- export interface Payload {
3
- /**
4
- * The path of the file to be opened
5
- */
6
- filePath: string;
7
- /**
8
- * The type of the file to be opened.
9
- * Currently only supports pdf and image
10
- */
11
- fileType: string;
12
- /**
13
- * The name of the file to be opened.
14
- * Used to display on the titlebar.
15
- */
16
- fileName: string;
17
- }
18
- export interface Result {
19
- }
20
- export declare const wfOpenDocument: (args: Payload & AsyncCallback<Result>) => void;
21
- export default wfOpenDocument;
22
- export declare const wfOpenDocumentAsync: (args?: (Payload & AsyncCallback<Result>) | undefined) => Promise<Result>;
@@ -1,8 +0,0 @@
1
- import { webCall as call, promisify } from '@hylid/call';
2
- export var wfOpenDocument = function wfOpenDocument(opt) {
3
- return call('wfOpenDocument', opt, {
4
- type: 'async'
5
- });
6
- };
7
- export default wfOpenDocument;
8
- export var wfOpenDocumentAsync = /*#__PURE__*/promisify(wfOpenDocument);