@alipay/ams-checkout 0.0.1748918972-dev.0 → 0.0.1749206034-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.
@@ -5,10 +5,10 @@ export declare const sdkVersion: string;
5
5
  /**
6
6
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
7
7
  */
8
- export declare const AMSCheckoutAppVersion = "1.36.0";
9
- export declare const AMSAutoDebitAppVersion = "1.36.0";
10
- export declare const AMSEasyPayAppVersion = "1.36.0";
11
- export declare const AMSCashierPaymentAppVersion = "1.36.0";
12
- export declare const AMSVaultingAppVersion = "1.36.0";
13
- export declare const AMSPaymentElementAppVersion = "1.36.0";
14
- export declare const ADDRESSElementAppVersion = "1.36.0";
8
+ export declare const AMSCheckoutAppVersion = "1.37.0";
9
+ export declare const AMSAutoDebitAppVersion = "1.37.0";
10
+ export declare const AMSEasyPayAppVersion = "1.37.0";
11
+ export declare const AMSCashierPaymentAppVersion = "1.37.0";
12
+ export declare const AMSVaultingAppVersion = "1.37.0";
13
+ export declare const AMSPaymentElementAppVersion = "1.37.0";
14
+ export declare const ADDRESSElementAppVersion = "1.37.0";
@@ -35,10 +35,10 @@ export var sdkVersion = json.version;
35
35
  /**
36
36
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
37
37
  */
38
- export var AMSCheckoutAppVersion = '1.36.0'; // 兜底版本号
39
- export var AMSAutoDebitAppVersion = '1.36.0'; // 代扣
40
- export var AMSEasyPayAppVersion = '1.36.0'; // easypay
41
- export var AMSCashierPaymentAppVersion = '1.36.0'; // 收银台(卡、apm)
42
- export var AMSVaultingAppVersion = '1.36.0'; // 绑卡
43
- export var AMSPaymentElementAppVersion = '1.36.0'; // payment element
44
- export var ADDRESSElementAppVersion = '1.36.0'; // address element
38
+ export var AMSCheckoutAppVersion = '1.37.0'; // 兜底版本号
39
+ export var AMSAutoDebitAppVersion = '1.37.0'; // 代扣
40
+ export var AMSEasyPayAppVersion = '1.37.0'; // easypay
41
+ export var AMSCashierPaymentAppVersion = '1.37.0'; // 收银台(卡、apm)
42
+ export var AMSVaultingAppVersion = '1.37.0'; // 绑卡
43
+ export var AMSPaymentElementAppVersion = '1.37.0'; // payment element
44
+ export var ADDRESSElementAppVersion = '1.37.0'; // address element
@@ -222,6 +222,9 @@ export declare const EVENT: {
222
222
  getSdkVersion: {
223
223
  name: string;
224
224
  };
225
+ inputFocus: {
226
+ name: string;
227
+ };
225
228
  };
226
229
  export declare const COMPONENT_CONTAINER_ID = "ams-component-container";
227
230
  export declare const COMPONENT_SECTION_ID = "ams-component-section";
@@ -224,6 +224,9 @@ export var EVENT = {
224
224
  },
225
225
  getSdkVersion: {
226
226
  name: 'getSdkVersion'
227
+ },
228
+ inputFocus: {
229
+ name: 'onInputFocus'
227
230
  }
228
231
  };
229
232
  export var COMPONENT_CONTAINER_ID = 'ams-component-container';
@@ -12,6 +12,8 @@ export declare class ContainerService implements Service {
12
12
  private displayInfo;
13
13
  private webApp;
14
14
  private _webAppHeartBeatTimeoutFn;
15
+ private clientHeight;
16
+ private boundFocusResizeChange;
15
17
  private customizedLoadingListener;
16
18
  destroy(): void;
17
19
  init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
@@ -22,10 +24,13 @@ export declare class ContainerService implements Service {
22
24
  dismissLoading(isKeepMockup?: boolean): void;
23
25
  customizeLoading(listener: (event: 'SDK_START_OF_LOADING' | 'SDK_END_OF_LOADING') => void): void;
24
26
  startHideAnim(): void;
27
+ private handleAccountFocus;
25
28
  private addCapabilityToEventCenter;
26
29
  private addCapabilityToApiBusManager;
27
30
  private updateMaskCloseBtn;
28
31
  private handleSizeChanged;
32
+ private focusResizeChange;
33
+ private focusScrollFixed;
29
34
  private handleAppHeartBeat;
30
35
  private changeCloseBtnVisibility;
31
36
  private handleMaskCloseBtnShow;
@@ -35,6 +35,8 @@ export var ContainerService = /*#__PURE__*/function () {
35
35
  _defineProperty(this, "displayInfo", void 0);
36
36
  _defineProperty(this, "webApp", void 0);
37
37
  _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
38
+ _defineProperty(this, "clientHeight", void 0);
39
+ _defineProperty(this, "boundFocusResizeChange", void 0);
38
40
  // if this variable is true, SDK will invoke listener instead of showing loading
39
41
  _defineProperty(this, "customizedLoadingListener", void 0);
40
42
  }
@@ -46,6 +48,7 @@ export var ContainerService = /*#__PURE__*/function () {
46
48
  value: function init(initOptions, instanceId, sdkMetaData) {
47
49
  this.instanceId = instanceId;
48
50
  this.sdkMetaData = sdkMetaData;
51
+ this.clientHeight = Math.max(window.innerHeight, window.visualViewport.height);
49
52
  this.eventCenter = ServiceProvider.getInstance(instanceId).getService('EventCenter');
50
53
  this.logService = ServiceProvider.getInstance(instanceId).getService('Log');
51
54
  this.popupManager = new PopupManager();
@@ -55,6 +58,8 @@ export var ContainerService = /*#__PURE__*/function () {
55
58
  this.addCapabilityToEventCenter();
56
59
  }
57
60
  this.addCapabilityToApiBusManager();
61
+ // bind会返回一个新的方法,init时记录上这个focus,不然window.addEventListener时this指向会变成window
62
+ this.boundFocusResizeChange = this.focusResizeChange.bind(this);
58
63
  }
59
64
  }, {
60
65
  key: "update",
@@ -156,6 +161,22 @@ export var ContainerService = /*#__PURE__*/function () {
156
161
  container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.displayInfo.platform));
157
162
  }
158
163
  }
164
+ }, {
165
+ key: "handleAccountFocus",
166
+ value: function handleAccountFocus(focus) {
167
+ var _window$visualViewpor, _window;
168
+ // 失焦时v2会走默认的sizeChange还原高度,这里仅移除监听
169
+ (_window$visualViewpor = window.visualViewport) === null || _window$visualViewpor === void 0 || _window$visualViewpor.removeEventListener('resize', this.boundFocusResizeChange);
170
+ (_window = window) === null || _window === void 0 || _window.removeEventListener('resize', this.boundFocusResizeChange);
171
+ // 只有聚焦才监听,失焦后移除,避免影响别的场景
172
+ if (focus) {
173
+ var _window$visualViewpor2;
174
+ // 监听页面visualViewport的高度变化,适用于主流机型更精准获取当前页面高度
175
+ (_window$visualViewpor2 = window.visualViewport) === null || _window$visualViewpor2 === void 0 || _window$visualViewpor2.addEventListener('resize', this.boundFocusResizeChange);
176
+ // 兼容visualViewport处理不到的场景,一般存在于老版本浏览器
177
+ window.addEventListener('resize', this.boundFocusResizeChange);
178
+ }
179
+ }
159
180
  }, {
160
181
  key: "addCapabilityToEventCenter",
161
182
  value: function addCapabilityToEventCenter() {
@@ -207,6 +228,22 @@ export var ContainerService = /*#__PURE__*/function () {
207
228
  this.eventCenter.listen(EVENT.appHeartBeat.name, function () {
208
229
  _this.handleAppHeartBeat();
209
230
  });
231
+ /**
232
+ * 目前仅用于ESP V2的 web sdk
233
+ * 原因: 在账户输入页和OTP页面的h5场景下键盘弹起页面会有问题,iframe有固定高度,键盘弹起时应用层不会触发大小变化
234
+ * account账号输入页需要在sdk监听键盘弹起后高度变化并修改iframe及iframe外层容器,account需要按钮置底的放在键盘上面,必须修改高度而不是让容器定位
235
+ * otp页面需要在聚焦时给iframe及外层容器设置fixed定位,让页面不被弹起
236
+ * 目的: esp页面输入框聚焦/失焦后给sdk发送消息
237
+ */
238
+ this.eventCenter.listen(EVENT.inputFocus.name, function (data) {
239
+ // 账号输入页需要修改iframe高度
240
+ if (data.source === 'ESP_V2' && data.type === 'account') {
241
+ _this.handleAccountFocus(data.focus);
242
+ // otp页面需要定位元素
243
+ } else if (data.source === 'ESP_V2' && data.type === 'otp') {
244
+ _this.focusScrollFixed(data.focus);
245
+ }
246
+ });
210
247
  }
211
248
  }, {
212
249
  key: "addCapabilityToApiBusManager",
@@ -267,6 +304,50 @@ export var ContainerService = /*#__PURE__*/function () {
267
304
  this.webApp.style.height = "".concat(data.height, "px");
268
305
  }
269
306
  }
307
+
308
+ // 目前仅用于esp账号输入页聚焦
309
+ }, {
310
+ key: "focusResizeChange",
311
+ value: function focusResizeChange() {
312
+ var _window2;
313
+ // 计算出当前iframe应有的高度,需要和顶部留有距离
314
+ var webPageHeightRatio = 0.9;
315
+ var browserPageHeightFocusRatio = 0.9;
316
+ // sdk层才能拿到当前键盘弹起后页面的高度
317
+ var height = ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.visualViewport) === null || _window2 === void 0 ? void 0 : _window2.height) || window.innerHeight;
318
+ height = height * webPageHeightRatio;
319
+ height = height * browserPageHeightFocusRatio;
320
+ // 调用handleSizeChanged修改iframe高度
321
+ this.handleSizeChanged({
322
+ width: 0,
323
+ height: height
324
+ });
325
+ }
326
+
327
+ // 目前仅用于esp otp页面账号聚焦
328
+ }, {
329
+ key: "focusScrollFixed",
330
+ value: function focusScrollFixed(focus) {
331
+ // 获取iframe dom元素
332
+ var _this$displayInfo4 = this.displayInfo,
333
+ appendAliasContainerId = _this$displayInfo4.appendAliasContainerId,
334
+ selector = _this$displayInfo4.selector;
335
+ var cashierId = appendAliasContainerId ? "".concat(COMPONENT_CONTAINER_ID, "-").concat((selector === null || selector === void 0 ? void 0 : selector.indexOf('#')) === -1 ? selector : selector.slice(1)) : COMPONENT_CONTAINER_ID;
336
+ if (!this.webApp || !this.displayInfo) {
337
+ return;
338
+ }
339
+ var cashier = document.getElementById(cashierId);
340
+ if (!cashier) return;
341
+ // 输入框聚焦时修改定位信息和top距离
342
+ if (focus) {
343
+ cashier.style.setProperty('position', 'fixed', 'important');
344
+ cashier.style.setProperty('top', "".concat(this.clientHeight - cashier.clientHeight, "px"), 'important');
345
+ } else {
346
+ // 失焦时移除定位信息
347
+ cashier.style.removeProperty('position');
348
+ cashier.style.removeProperty('top');
349
+ }
350
+ }
270
351
  }, {
271
352
  key: "handleAppHeartBeat",
272
353
  value: function handleAppHeartBeat() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1748918972-dev.0",
3
+ "version": "0.0.1749206034-dev.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",