@alipay/ams-checkout 1.3.1 → 1.4.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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/config/index.d.ts +2 -0
- package/esm/config/index.js +17 -0
- package/esm/config/request.d.ts +21 -0
- package/esm/config/request.js +67 -0
- package/esm/constant/index.d.ts +136 -0
- package/esm/constant/index.js +136 -0
- package/esm/core/component/index.d.ts +17 -0
- package/esm/core/component/index.js +100 -0
- package/esm/core/drop-in/index.d.ts +29 -0
- package/esm/core/drop-in/index.js +104 -0
- package/esm/core/instance/index.d.ts +59 -0
- package/esm/core/instance/index.js +254 -0
- package/esm/image/cta.svg +9 -0
- package/esm/index.d.ts +22 -0
- package/esm/plugin/component/cashierApp.d.ts +23 -0
- package/esm/plugin/component/cashierApp.js +122 -0
- package/esm/plugin/component/component.style.d.ts +8 -0
- package/esm/plugin/component/component.style.js +15 -0
- package/esm/plugin/component/index.d.ts +102 -0
- package/esm/plugin/component/index.js +900 -0
- package/esm/plugin/drop-in/index.d.ts +73 -0
- package/esm/plugin/drop-in/index.js +323 -0
- package/esm/request/index.d.ts +15 -0
- package/esm/request/index.js +145 -0
- package/esm/request/utils.d.ts +28 -0
- package/esm/request/utils.js +59 -0
- package/esm/service/index.d.ts +2 -0
- package/esm/service/index.js +40 -0
- package/esm/types/index.d.ts +216 -0
- package/esm/types/index.js +97 -0
- package/esm/util/createIframeNode.d.ts +5 -0
- package/esm/util/createIframeNode.js +35 -0
- package/esm/util/get.d.ts +25 -0
- package/esm/util/get.js +145 -0
- package/esm/util/index.d.ts +53 -0
- package/esm/util/index.js +237 -0
- package/esm/util/intl-callapp/es/browser.d.ts +21 -0
- package/esm/util/intl-callapp/es/browser.js +42 -0
- package/esm/util/intl-callapp/es/evoke.d.ts +13 -0
- package/esm/util/intl-callapp/es/evoke.js +39 -0
- package/esm/util/intl-callapp/es/generate.d.ts +29 -0
- package/esm/util/intl-callapp/es/generate.js +44 -0
- package/esm/util/intl-callapp/es/index.d.ts +43 -0
- package/esm/util/intl-callapp/es/index.js +298 -0
- package/esm/util/intl-callapp/es/main.d.ts +41 -0
- package/esm/util/intl-callapp/es/main.js +305 -0
- package/esm/util/intl-callapp/es/openWallet.d.ts +15 -0
- package/esm/util/intl-callapp/es/openWallet.js +197 -0
- package/esm/util/intl-callapp/es/types.d.ts +46 -0
- package/esm/util/intl-callapp/es/types.js +1 -0
- package/esm/util/intl-callapp/es/utils/config.d.ts +24 -0
- package/esm/util/intl-callapp/es/utils/config.js +57 -0
- package/esm/util/intl-callapp/es/utils/index.d.ts +15 -0
- package/esm/util/intl-callapp/es/utils/index.js +98 -0
- package/esm/util/mock.d.ts +1 -0
- package/esm/util/mock.js +4 -0
- package/package.json +1 -1
@@ -0,0 +1,53 @@
|
|
1
|
+
import { ERROR } from '../types';
|
2
|
+
/**
|
3
|
+
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
6
|
+
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
7
|
+
*/
|
8
|
+
declare const getType: (target: any) => string;
|
9
|
+
declare class EventCenter {
|
10
|
+
private events;
|
11
|
+
private eventsKey;
|
12
|
+
constructor();
|
13
|
+
on(name: string, func: any, key?: string): void;
|
14
|
+
off(name: string, func: any, key?: string): void;
|
15
|
+
emit(name: string, ...rest: any): void;
|
16
|
+
once(name: string, func: any, key?: string): void;
|
17
|
+
}
|
18
|
+
declare const getViewPort: (key: string) => any;
|
19
|
+
declare const getOrigin: () => string;
|
20
|
+
declare const serialize: (obj: Record<string, string>) => string;
|
21
|
+
declare const isJsonString: (str: string) => boolean;
|
22
|
+
declare const isDom: (obj: any) => any;
|
23
|
+
declare const device: {
|
24
|
+
iOS: boolean;
|
25
|
+
Android: boolean;
|
26
|
+
macOS: boolean;
|
27
|
+
WindowsNT: boolean;
|
28
|
+
isMobile: boolean;
|
29
|
+
};
|
30
|
+
declare const safeJson: (data: any, obj: any) => any;
|
31
|
+
declare const fomatGetwayError: (headers: Record<string, any>, traceId: string) => {
|
32
|
+
success: boolean;
|
33
|
+
traceId: string;
|
34
|
+
errorCode: ERROR;
|
35
|
+
resultStatus: any;
|
36
|
+
errorMessage?: undefined;
|
37
|
+
result?: undefined;
|
38
|
+
} | {
|
39
|
+
success: boolean;
|
40
|
+
traceId: string;
|
41
|
+
errorCode: ERROR;
|
42
|
+
errorMessage: string;
|
43
|
+
result: {
|
44
|
+
resultStatus: any;
|
45
|
+
tips: string;
|
46
|
+
memo: string;
|
47
|
+
};
|
48
|
+
resultStatus: any;
|
49
|
+
} | null;
|
50
|
+
declare const isPC: () => boolean;
|
51
|
+
declare const queryParse: (url?: string) => Record<string, any>;
|
52
|
+
declare const getDesignFontSize: () => number;
|
53
|
+
export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, fomatGetwayError, safeJson, isPC, queryParse, getDesignFontSize, };
|
@@ -0,0 +1,237 @@
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
8
|
+
import { ERROR } from "../types";
|
9
|
+
import { get } from "./get";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
14
|
+
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
15
|
+
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
16
|
+
*/
|
17
|
+
var getType = function getType(target) {
|
18
|
+
return Object.prototype.toString.call(target).slice(8, -1).toLowerCase();
|
19
|
+
};
|
20
|
+
var EventCenter = /*#__PURE__*/function () {
|
21
|
+
function EventCenter() {
|
22
|
+
_classCallCheck(this, EventCenter);
|
23
|
+
_defineProperty(this, "events", void 0);
|
24
|
+
_defineProperty(this, "eventsKey", void 0);
|
25
|
+
this.events = new Map();
|
26
|
+
this.eventsKey = new Map();
|
27
|
+
}
|
28
|
+
_createClass(EventCenter, [{
|
29
|
+
key: "on",
|
30
|
+
value: function on(name, func) {
|
31
|
+
var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
32
|
+
if (key) {
|
33
|
+
if (this.eventsKey.has("".concat(name, "-").concat(key))) {
|
34
|
+
// eslint-disable-next-line no-console
|
35
|
+
console.warn("".concat(key, "\uFF1AHas been registered. Please use another key or do not pass the key"));
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
this.eventsKey.set("".concat(name, "-").concat(key), true);
|
39
|
+
}
|
40
|
+
var eventList = this.events.get(name) || [];
|
41
|
+
eventList.push({
|
42
|
+
func: func,
|
43
|
+
key: key || ''
|
44
|
+
});
|
45
|
+
this.events.set(name, eventList);
|
46
|
+
}
|
47
|
+
}, {
|
48
|
+
key: "off",
|
49
|
+
value: function off(name, func) {
|
50
|
+
var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
51
|
+
if (key && this.eventsKey.has("".concat(name, "-").concat(key))) {
|
52
|
+
this.eventsKey.delete("".concat(name, "-").concat(key));
|
53
|
+
}
|
54
|
+
if (this.events.has(name)) {
|
55
|
+
var eventList = this.events.get(name);
|
56
|
+
eventList = eventList.filter(function (item) {
|
57
|
+
if (func === item.func && item.key === key) return false;
|
58
|
+
if (item.key && item.key === key) return false;
|
59
|
+
return true;
|
60
|
+
});
|
61
|
+
this.events.set(name, eventList);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}, {
|
65
|
+
key: "emit",
|
66
|
+
value: function emit(name) {
|
67
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
68
|
+
rest[_key - 1] = arguments[_key];
|
69
|
+
}
|
70
|
+
if (this.events.has(name)) {
|
71
|
+
var eventList = this.events.get(name);
|
72
|
+
eventList.forEach(function (item) {
|
73
|
+
item.func.apply(item, rest);
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}, {
|
78
|
+
key: "once",
|
79
|
+
value: function once(name, func, key) {
|
80
|
+
var _this = this;
|
81
|
+
var onceF = function onceF() {
|
82
|
+
for (var _len2 = arguments.length, rest = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
83
|
+
rest[_key2] = arguments[_key2];
|
84
|
+
}
|
85
|
+
func.call.apply(func, [_this].concat(rest));
|
86
|
+
_this.off(name, onceF, key);
|
87
|
+
};
|
88
|
+
this.on(name, onceF, key);
|
89
|
+
}
|
90
|
+
}]);
|
91
|
+
return EventCenter;
|
92
|
+
}();
|
93
|
+
var getViewPort = function getViewPort(key) {
|
94
|
+
var meta = document.getElementsByTagName('meta');
|
95
|
+
// HTMLMetaElement
|
96
|
+
var viewPort = meta.viewPort;
|
97
|
+
var _meta = {};
|
98
|
+
if (viewPort) {
|
99
|
+
var content = viewPort.content.split(',');
|
100
|
+
for (var j = 0; j < content.length; j++) {
|
101
|
+
var i = content[j].split('=');
|
102
|
+
_meta[i[0]] = i[1];
|
103
|
+
}
|
104
|
+
}
|
105
|
+
return _meta[key];
|
106
|
+
};
|
107
|
+
var getOrigin = function getOrigin() {
|
108
|
+
var _window$location = window.location,
|
109
|
+
origin = _window$location.origin,
|
110
|
+
protocol = _window$location.protocol,
|
111
|
+
hostname = _window$location.hostname,
|
112
|
+
port = _window$location.port;
|
113
|
+
return origin || "".concat(protocol, "//").concat(hostname).concat(port ? ":".concat(port) : '');
|
114
|
+
};
|
115
|
+
var serialize = /* istanbul ignore next */function serialize(obj) {
|
116
|
+
var s = [];
|
117
|
+
for (var item in obj) {
|
118
|
+
// eslint-disable-next-line no-prototype-builtins
|
119
|
+
if (obj.hasOwnProperty(item)) {
|
120
|
+
var k = encodeURIComponent(item);
|
121
|
+
var v = encodeURIComponent(obj[item] === null ? '' : obj[item]);
|
122
|
+
s.push("".concat(k, "=").concat(v));
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return s.join('&');
|
126
|
+
};
|
127
|
+
var isJsonString = function isJsonString(str) {
|
128
|
+
try {
|
129
|
+
JSON.parse(str);
|
130
|
+
} catch (e) {
|
131
|
+
return false;
|
132
|
+
}
|
133
|
+
return true;
|
134
|
+
};
|
135
|
+
var isDom = function isDom(obj) {
|
136
|
+
if ((typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === 'object') {
|
137
|
+
return obj instanceof HTMLElement;
|
138
|
+
} else {
|
139
|
+
return obj && _typeof(obj) === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
|
140
|
+
}
|
141
|
+
};
|
142
|
+
var _window = window,
|
143
|
+
navigator = _window.navigator;
|
144
|
+
var UA = navigator.userAgent;
|
145
|
+
var isIOS = /iPhone|iPad|iPod/i.test(UA) || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
|
146
|
+
var isAndroid = /Android/i.test(UA);
|
147
|
+
var isMacOS = /\bMacintosh\b/.test(UA);
|
148
|
+
var isWindowsNT = /Windows NT/.test(UA);
|
149
|
+
var isMobile = function isMobile() {
|
150
|
+
return /Android|iPhone|iPad|iPod|Mobile/.test(UA);
|
151
|
+
};
|
152
|
+
var device = {
|
153
|
+
iOS: isIOS,
|
154
|
+
Android: isAndroid,
|
155
|
+
macOS: isMacOS,
|
156
|
+
WindowsNT: isWindowsNT,
|
157
|
+
isMobile: !!isMobile()
|
158
|
+
};
|
159
|
+
var safeJson = function safeJson(data, obj) {
|
160
|
+
try {
|
161
|
+
return JSON.parse(data) || obj;
|
162
|
+
} catch (_unused) {
|
163
|
+
return obj;
|
164
|
+
}
|
165
|
+
};
|
166
|
+
|
167
|
+
// 判断header 中的resultStatus
|
168
|
+
var fomatGetwayError = function fomatGetwayError(headers, traceId) {
|
169
|
+
var resultStatus = get(headers, 'Result-Status') || get(headers, 'result-status', '');
|
170
|
+
// 请求静态数据情况
|
171
|
+
if (!resultStatus) return null;
|
172
|
+
// 未登录
|
173
|
+
if (+resultStatus === 2000) {
|
174
|
+
return {
|
175
|
+
success: false,
|
176
|
+
traceId: traceId,
|
177
|
+
errorCode: ERROR.LOGIN,
|
178
|
+
resultStatus: resultStatus
|
179
|
+
};
|
180
|
+
}
|
181
|
+
// 网关超时
|
182
|
+
if (+resultStatus === 4001) {
|
183
|
+
return {
|
184
|
+
success: false,
|
185
|
+
traceId: traceId,
|
186
|
+
errorCode: ERROR.TIMEOUT,
|
187
|
+
resultStatus: resultStatus
|
188
|
+
};
|
189
|
+
}
|
190
|
+
if (+resultStatus !== 1000) {
|
191
|
+
var tips = get(headers, 'Tips') || get(headers, 'tips', '');
|
192
|
+
var memo = get(headers, 'Memo') || get(headers, 'memo', '');
|
193
|
+
return {
|
194
|
+
success: false,
|
195
|
+
traceId: traceId,
|
196
|
+
errorCode: ERROR.GATEWAY,
|
197
|
+
errorMessage: decodeURIComponent(tips || ''),
|
198
|
+
result: {
|
199
|
+
resultStatus: resultStatus || '',
|
200
|
+
tips: decodeURIComponent(tips || ''),
|
201
|
+
memo: decodeURIComponent(memo || '')
|
202
|
+
},
|
203
|
+
resultStatus: resultStatus
|
204
|
+
};
|
205
|
+
}
|
206
|
+
return null;
|
207
|
+
};
|
208
|
+
var isPC = function isPC() {
|
209
|
+
var userAgentInfo = navigator.userAgent;
|
210
|
+
var agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPod'];
|
211
|
+
return !agents.some(function (agent) {
|
212
|
+
return userAgentInfo.includes(agent);
|
213
|
+
});
|
214
|
+
};
|
215
|
+
var queryParse = function queryParse(url) {
|
216
|
+
var qs = {};
|
217
|
+
if (!url) {
|
218
|
+
// eslint-disable-next-line no-param-reassign
|
219
|
+
url = window.location.href;
|
220
|
+
}
|
221
|
+
url.replace(/([^?=&#]+)(=([^&#]*))?/g, function (_$0, $1, _$2, $3) {
|
222
|
+
if ($3 === undefined) {
|
223
|
+
return '';
|
224
|
+
}
|
225
|
+
qs[$1] = decodeURIComponent($3);
|
226
|
+
return qs[$1];
|
227
|
+
});
|
228
|
+
return qs;
|
229
|
+
};
|
230
|
+
var designSize = 390;
|
231
|
+
var maxFontSize = 130;
|
232
|
+
var getDesignFontSize = function getDesignFontSize() {
|
233
|
+
var screenWidth = document.documentElement.clientWidth;
|
234
|
+
var currentFontSize = isPC() ? maxFontSize : screenWidth * 100 / designSize;
|
235
|
+
return Math.min(currentFontSize, maxFontSize);
|
236
|
+
};
|
237
|
+
export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, fomatGetwayError, safeJson, isPC, queryParse, getDesignFontSize };
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* @param versionA
|
3
|
+
* @param versionB
|
4
|
+
* @returns
|
5
|
+
*/
|
6
|
+
export declare const semverCompare: (
|
7
|
+
versionA: string,
|
8
|
+
versionB: string,
|
9
|
+
) => -1 | 0 | 1;
|
10
|
+
|
11
|
+
export declare const getIOSVersion: () => number;
|
12
|
+
export declare const isAndroid: boolean;
|
13
|
+
export declare const isIOS: boolean;
|
14
|
+
export declare const isOriginalChrome: boolean;
|
15
|
+
export declare const isQQBrowser: boolean;
|
16
|
+
export declare const isFirefox: boolean;
|
17
|
+
export declare const isBaidu: boolean;
|
18
|
+
/**
|
19
|
+
* @returns boolean
|
20
|
+
*/
|
21
|
+
export declare const haveSchemeToLinkOrFallback: () => boolean;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
5
|
+
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
6
|
+
*/
|
7
|
+
var ua = window.navigator.userAgent || '';
|
8
|
+
/**
|
9
|
+
* @param versionA
|
10
|
+
* @param versionB
|
11
|
+
* @returns
|
12
|
+
*/
|
13
|
+
export var semverCompare = function semverCompare(versionA, versionB) {
|
14
|
+
var splitA = versionA.split('.');
|
15
|
+
var splitB = versionB.split('.');
|
16
|
+
for (var i = 0; i < 3; i++) {
|
17
|
+
var snippetA = Number(splitA[i]);
|
18
|
+
var snippetB = Number(splitB[i]);
|
19
|
+
if (snippetA > snippetB) return 1;
|
20
|
+
if (snippetB > snippetA) return -1;
|
21
|
+
// e.g. '1.0.0-rc' -- Number('0-rc') = NaN
|
22
|
+
if (!isNaN(snippetA) && isNaN(snippetB)) return 1;
|
23
|
+
if (isNaN(snippetA) && !isNaN(snippetB)) return -1;
|
24
|
+
}
|
25
|
+
return 0;
|
26
|
+
};
|
27
|
+
export var getIOSVersion = function getIOSVersion() {
|
28
|
+
var version = ua.match(/OS (\d+)_(\d+)_?(\d+)?/);
|
29
|
+
return Number.parseInt(version[1], 10);
|
30
|
+
};
|
31
|
+
export var isAndroid = /android/i.test(ua);
|
32
|
+
export var isIOS = /iphone|ipad|ipod/i.test(ua);
|
33
|
+
export var isOriginalChrome = /chrome\/[\d.]+ mobile safari\/[\d.]+/i.test(ua) && isAndroid && ua.indexOf('Version') < 0;
|
34
|
+
export var isQQBrowser = /qqbrowser/i.test(ua);
|
35
|
+
export var isFirefox = /firefox/i.test(ua);
|
36
|
+
export var isBaidu = /baidubrowser/i.test(ua);
|
37
|
+
/**
|
38
|
+
* @returns boolean
|
39
|
+
*/
|
40
|
+
export var haveSchemeToLinkOrFallback = function haveSchemeToLinkOrFallback() {
|
41
|
+
return isAndroid || getIOSVersion() < 9;
|
42
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* @param url
|
3
|
+
*/
|
4
|
+
export declare function evokeByLocation(url: string): void;
|
5
|
+
/**
|
6
|
+
* @param url
|
7
|
+
*/
|
8
|
+
export declare function evokeByTagA(url: string): void;
|
9
|
+
export declare function buildIFrame(): void;
|
10
|
+
/**
|
11
|
+
* @param url
|
12
|
+
*/
|
13
|
+
export declare function evokeByIFrame(url: string): void;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
5
|
+
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* @param url
|
9
|
+
*/
|
10
|
+
export function evokeByLocation(url) {
|
11
|
+
window.location.href = url;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* @param url
|
15
|
+
*/
|
16
|
+
export function evokeByTagA(url) {
|
17
|
+
var a = document.createElement('a');
|
18
|
+
a.setAttribute('href', url);
|
19
|
+
a.style.display = 'none';
|
20
|
+
document.body.appendChild(a);
|
21
|
+
var e = document.createEvent('HTMLEvents');
|
22
|
+
e.initEvent('click', false, false);
|
23
|
+
a.dispatchEvent(e);
|
24
|
+
}
|
25
|
+
var iframe;
|
26
|
+
export function buildIFrame() {
|
27
|
+
if (!iframe) {
|
28
|
+
iframe = document.createElement('iframe');
|
29
|
+
iframe.id = 'callapp_iframe_'.concat(Date.now());
|
30
|
+
iframe.style.cssText = 'display:none;border:0;width:0;height:0;';
|
31
|
+
document.body.appendChild(iframe);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* @param url
|
36
|
+
*/
|
37
|
+
export function evokeByIFrame(url) {
|
38
|
+
iframe.src = url;
|
39
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* @param url
|
3
|
+
* @param params
|
4
|
+
* @returns
|
5
|
+
*/
|
6
|
+
export declare function generateQS(
|
7
|
+
url: string,
|
8
|
+
params?: Record<string, any>,
|
9
|
+
): string;
|
10
|
+
/**
|
11
|
+
* @param url
|
12
|
+
* @param params
|
13
|
+
* @returns
|
14
|
+
*/
|
15
|
+
export declare function generateLink(
|
16
|
+
url: string,
|
17
|
+
params?: Record<string, any>,
|
18
|
+
): string;
|
19
|
+
/**
|
20
|
+
* @param url
|
21
|
+
* @param packageName
|
22
|
+
* @param params
|
23
|
+
* @returns
|
24
|
+
*/
|
25
|
+
export declare function generateIntent(
|
26
|
+
url: string,
|
27
|
+
packageName?: string,
|
28
|
+
fallbackUrl?: string,
|
29
|
+
): string;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
* 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
|
5
|
+
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* @param url
|
9
|
+
* @param params
|
10
|
+
* @returns
|
11
|
+
*/
|
12
|
+
export function generateQS(url, params) {
|
13
|
+
var newUrl = new URL(url);
|
14
|
+
for (var i in params) {
|
15
|
+
if (i) {
|
16
|
+
newUrl.searchParams.set(i, params[i]);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return newUrl.toString();
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* @param url
|
23
|
+
* @param params
|
24
|
+
* @returns
|
25
|
+
*/
|
26
|
+
export function generateLink(url, params) {
|
27
|
+
return generateQS(url, params);
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* @param url
|
31
|
+
* @param packageName
|
32
|
+
* @param params
|
33
|
+
* @returns
|
34
|
+
*/
|
35
|
+
export function generateIntent(url, packageName, fallbackUrl) {
|
36
|
+
var intentTail = '';
|
37
|
+
if (fallbackUrl) {
|
38
|
+
intentTail = 'S.browser_fallback_url='.concat(encodeURIComponent(fallbackUrl), ';');
|
39
|
+
}
|
40
|
+
var protocol = url.substring(0, url.indexOf('://'));
|
41
|
+
var hash = packageName ? '#Intent;scheme='.concat(protocol, ';package=').concat(packageName, ';') : '#Intent;scheme='.concat(protocol, ';');
|
42
|
+
var newUrl = url.replace(/.*?:\/\//, 'intent://');
|
43
|
+
return ''.concat(newUrl + hash + intentTail, 'end');
|
44
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import type { CallappConfig, CallappOptions, EvokeAppBy } from './types';
|
3
|
+
declare class CallApp {
|
4
|
+
config: CallappConfig;
|
5
|
+
timer: NodeJS.Timeout | null;
|
6
|
+
options: CallappOptions;
|
7
|
+
evokeAppBy: EvokeAppBy;
|
8
|
+
constructor(config?: CallappConfig);
|
9
|
+
|
10
|
+
private init;
|
11
|
+
/**
|
12
|
+
* @param options
|
13
|
+
*/
|
14
|
+
open(options: CallappOptions): void;
|
15
|
+
|
16
|
+
private handleLink;
|
17
|
+
|
18
|
+
private handleIntent;
|
19
|
+
|
20
|
+
private handleScheme;
|
21
|
+
|
22
|
+
private handleIOSScheme;
|
23
|
+
|
24
|
+
private handleOriginalChrome;
|
25
|
+
/**
|
26
|
+
* @param evokeFn
|
27
|
+
* @param delay
|
28
|
+
* @param fallback
|
29
|
+
* @param degradationStrategy
|
30
|
+
*/
|
31
|
+
private evokeAppDelay;
|
32
|
+
private evokeByLocationDelay;
|
33
|
+
private evokeByTagADelay;
|
34
|
+
private evokeByIFrameDelay;
|
35
|
+
/**
|
36
|
+
* @param fallback
|
37
|
+
* @returns
|
38
|
+
*/
|
39
|
+
private checkIsOpen;
|
40
|
+
|
41
|
+
private clearTimer;
|
42
|
+
}
|
43
|
+
export default CallApp;
|