@alipay/ams-checkout 0.0.1779094014-dev.2 → 0.0.1779094014-dev.21

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 (47) hide show
  1. package/ams-checkout.js +3 -3
  2. package/dist/ams-checkout.min.js +1 -1
  3. package/dist/ams-checkout.min.js.map +1 -1
  4. package/esm/component/popupWindow.style.js +2 -1
  5. package/esm/config/index.d.ts +7 -0
  6. package/esm/config/index.js +2 -2
  7. package/esm/constant/index.d.ts +1 -0
  8. package/esm/constant/index.js +1 -0
  9. package/esm/core/component/element/elementContainerService/containerService.js +3 -2
  10. package/esm/core/component/element/elementProcessor/paymentProcessor.js +42 -4
  11. package/esm/core/component/element/index.d.ts +3 -0
  12. package/esm/core/component/element/index.js +13 -8
  13. package/esm/core/component/element/modernElementController/adapter.d.ts +5 -5
  14. package/esm/core/component/element/modernElementController/adapter.js +23 -19
  15. package/esm/core/component/element/modernElementController/index.d.ts +43 -13
  16. package/esm/core/component/element/modernElementController/index.js +585 -263
  17. package/esm/core/component/element/type.d.ts +6 -18
  18. package/esm/foundation/service/container/utils.js +3 -1
  19. package/esm/modern/global.d.ts +3 -0
  20. package/esm/modern/index.d.ts +5 -1
  21. package/esm/modern/index.js +1 -51
  22. package/esm/modern/tools.js +1 -0
  23. package/esm/plugin/component/channel.d.ts +4 -1
  24. package/esm/plugin/component/channel.js +6 -2
  25. package/esm/plugin/component/index.js +7 -6
  26. package/esm/tsdoc-metadata.json +1 -1
  27. package/esm/types/index.d.ts +1 -0
  28. package/esm/util/logger.js +1 -2
  29. package/package.json +23 -10
  30. package/types.d.ts +896 -71
  31. package/types.untrimmed.d.ts +1203 -113
  32. package/esm/modern/oneapi/iexpfront/PaymentSessionService.d.ts +0 -23
  33. package/esm/modern/oneapi/iexpfront/PaymentSessionService.js +0 -55
  34. package/esm/modern/oneapi/iexpfront/definitions.d.ts +0 -3656
  35. package/esm/modern/oneapi/iexpfront/definitions.js +0 -1
  36. package/esm/modern/tools/AntomSDKError.d.ts +0 -47
  37. package/esm/modern/tools/AntomSDKError.js +0 -47
  38. package/esm/modern/tools/buildPageUrl.d.ts +0 -4
  39. package/esm/modern/tools/buildPageUrl.js +0 -19
  40. package/esm/modern/tools/getDevReqConfig.d.ts +0 -2
  41. package/esm/modern/tools/getDevReqConfig.js +0 -16
  42. package/esm/modern/tools/getLocaleFromRenderData.d.ts +0 -6
  43. package/esm/modern/tools/getLocaleFromRenderData.js +0 -20
  44. package/esm/modern/tools/getMetaData.d.ts +0 -102
  45. package/esm/modern/tools/getMetaData.js +0 -7
  46. package/esm/modern/tools/openModal.d.ts +0 -20
  47. package/esm/modern/tools/openModal.js +0 -221
@@ -2,6 +2,12 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
13
  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; }
@@ -19,22 +25,16 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
19
25
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
20
26
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
21
27
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
- import { MessageType } from '@antintl/opensdk-core';
23
- import { SDKBridge } from '@antintl/opensdk-bridge';
24
- import { request, parseHostSign } from '@antintl/antom-toolset';
28
+ import { openModal, sdkQuery, getLocaleFromRenderData, getDevReqConfig, getMetaData, buildPageUrl, debugError, debug, MessageType, request, parseHostSign, SDKBridge, parseTrackerId, oneAccountQuery, OpenSDKError, awaitWrap, themeColorMap } from "../../../../modern/tools";
25
29
  import { device } from "../../../../util";
26
- import { openModal } from "../../../../modern/tools/openModal";
27
- import { sdkQuery } from "../../../../modern/oneapi/iexpfront/PaymentSessionService";
28
- import { getLocaleFromRenderData } from "../../../../modern/tools/getLocaleFromRenderData";
29
- import { getDevReqConfig } from "../../../../modern/tools/getDevReqConfig";
30
30
  import { EventCallbackCode } from "../type";
31
- import { adaptSubmitResult, adaptErrorToEventCallback, adaptAppearance } from "./adapter";
32
- import { getMetaData } from "../../../../modern/tools/getMetaData";
33
- import { debugError, debug } from '@antintl/opensdk-core';
34
- import { buildPageUrl } from "../../../../modern/tools/buildPageUrl";
35
- import { AntomSDKError } from "../../../../modern/tools/AntomSDKError";
31
+ import { adaptSubmitResult, adaptAppearance } from "./adapter";
32
+ import CallApp from "../../../../util/intl-callapp/es/main";
33
+ import { ApplePayHostService } from "../../../../modern/sdk/applepay-core/ApplePayHostService";
34
+ import { getApplePayPaymentSession } from "../../../../service";
35
+ import { BusManager, BusMessage } from "../../../bus";
36
+ import { ApplePayActionEnum } from "../../../bus/interface";
36
37
  var MOUNT_TIMEOUT = 16000;
37
-
38
38
  /**
39
39
  * HostSDKBridge 扩展 SDKBridge,暴露 setTarget 方法供 HOST 模式使用
40
40
  */
@@ -45,12 +45,12 @@ var HostSDKBridge = /*#__PURE__*/function (_SDKBridge) {
45
45
  _classCallCheck(this, HostSDKBridge);
46
46
  return _super.call(this, mode, scope);
47
47
  }
48
-
49
- // 暴露 protected 的 setTarget 方法
50
48
  _createClass(HostSDKBridge, [{
51
- key: "setTargetWindow",
52
- value: function setTargetWindow(window) {
53
- this.setTarget(window);
49
+ key: "setTarget",
50
+ value:
51
+ // 暴露 protected 的 setTarget 方法
52
+ function setTarget(window) {
53
+ _get(_getPrototypeOf(HostSDKBridge.prototype), "setTarget", this).call(this, window);
54
54
  }
55
55
  }, {
56
56
  key: "setDebugCallback",
@@ -61,28 +61,46 @@ var HostSDKBridge = /*#__PURE__*/function (_SDKBridge) {
61
61
  }
62
62
  (_get2 = _get(_getPrototypeOf(HostSDKBridge.prototype), "setDebugCallback", this)).call.apply(_get2, [this].concat(args));
63
63
  }
64
+ }], [{
65
+ key: "getGlobalBridge",
66
+ value: function getGlobalBridge(mode) {
67
+ return _get(_getPrototypeOf(HostSDKBridge), "getGlobalBridge", this).call(this, mode);
68
+ }
64
69
  }]);
65
70
  return HostSDKBridge;
66
71
  }(SDKBridge);
67
72
  /**
68
73
  * AMSElement 特有的消息类型(非标准 MessageType,webapp 需配合实现)
69
74
  * 使用索引签名兼容,避免 as any
75
+ *
76
+ * GET_APPLE_PAY_TOKEN / REPLY:PC 非 Safari Apple Pay 委托给 SDK 域处理的桥协议。
77
+ * webapp 发 REQUEST → SDK 跑 ApplePaySdk.startPay 弹 Apple modal → REPLY 回传结果。
70
78
  */
71
79
  var AMSMessageType = {
72
80
  VALIDATE: 'OPENSDK@VALIDATE',
73
- VALIDATE_REPLY: 'OPENSDK@VALIDATE_REPLY'
81
+ VALIDATE_REPLY: 'OPENSDK@VALIDATE_REPLY',
82
+ GET_APPLE_PAY_TOKEN: 'OPENSDK@GET_APPLE_PAY_TOKEN',
83
+ GET_APPLE_PAY_TOKEN_REPLY: 'OPENSDK@GET_APPLE_PAY_TOKEN_REPLY',
84
+ // skipRenderPaymentMethod 场景:webapp 委托 SDK 全权拉起 ApplePay,fire-and-forget
85
+ // SDK 收到后走 BusManager.publish(ApplePayActionEnum.createComponent) → plugin/applepay 标准链路
86
+ // (含 onEventCallback 商户通知,不需要 reply 给 webapp)
87
+ HANDLE_PAYMENT: 'OPENSDK@HANDLE_PAYMENT',
88
+ // webapp 查询 native plugin 是否注册(Android webview GooglePay 探测用)
89
+ // webapp 发 REQUEST + requestId → SDK 调 BusManager.isSubscribed → REPLY 回 { requestId, isSubscribed }
90
+ CHECK_BUS_SUBSCRIBED: 'OPENSDK@CHECK_BUS_SUBSCRIBED',
91
+ CHECK_BUS_SUBSCRIBED_REPLY: 'OPENSDK@CHECK_BUS_SUBSCRIBED_REPLY'
74
92
  };
75
-
76
93
  /**
77
94
  * ModernElementController 使用 opensdk-core 的 HostBridge 实现新架构通信。
78
95
  *
79
96
  * Mount 流程(正确):
80
97
  * 1. setup() — 解析 sessionData 获取 metaData,准备 HANDSHAKE 配置
81
- * 2. 创建 iframe,设置 src
82
- * 3. iframe 添加到容器
83
- * 4. 监听 READY_HANDSHAKE → setTarget(iframe.contentWindow) send(HANDSHAKE, mergedConfig)
84
- * 5. 等待 HANDSHAKE_ACK 设置 status = 'ready'
85
- * 6. ready 后发送缓存的消息
98
+ * 2. 创建 iframe(先不设置 src,避免提前触发加载)
99
+ * 3. 先注册所有事件监听,再设置 iframe.src 和 appendChild 触发加载
100
+ * 4. setup() waitForReadyHandshake() 并行执行
101
+ * 5. 两者都完成后,sendHandshake() 发送 HANDSHAKE 配置
102
+ * 6. 等待 HANDSHAKE_ACK → 设置 status = 'ready'
103
+ * 7. ready 后发送缓存的消息
86
104
  */
87
105
  export var ModernElementController = /*#__PURE__*/function () {
88
106
  function ModernElementController(options) {
@@ -91,13 +109,12 @@ export var ModernElementController = /*#__PURE__*/function () {
91
109
  _defineProperty(this, "bridge", void 0);
92
110
  _defineProperty(this, "iframe", null);
93
111
  _defineProperty(this, "status", 'initialized');
94
- _defineProperty(this, "eventListeners", new Map());
95
112
  _defineProperty(this, "cachedSend", []);
96
113
  // Modal 相关资源
97
- _defineProperty(this, "modalIframe", null);
98
114
  _defineProperty(this, "modalBridge", null);
99
115
  _defineProperty(this, "modalDestroy", null);
100
116
  _defineProperty(this, "_closeConfirmResolve", null);
117
+ _defineProperty(this, "notRedirectAfterComplete", false);
101
118
  this.options = options;
102
119
  this.bridge = new HostSDKBridge('HOST', 'payment');
103
120
  this.bridge.setDebugCallback(function (msg, direction) {
@@ -119,7 +136,7 @@ export var ModernElementController = /*#__PURE__*/function () {
119
136
  value: function () {
120
137
  var _mount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(renderOptions, sdkSelector) {
121
138
  var _this$options$loading, _this$options$loading2;
122
- var container, _this$options, _this$options$onEvent, _this$options$loading3, _this$options$loading4, setupConfig, iframeUrl, _this$options$loading5, _this$options$loading6, _this$options2, _this$options2$onEven, errorResult;
139
+ var container, _this$options, _this$options$onEvent, _this$options$loading3, _this$options$loading4, iframeUrl, readyHandshakePromise, _yield$Promise$all, _yield$Promise$all2, setupConfig, dataStructError, _this$options$loading5, _this$options$loading6, _this$options2, _this$options2$onEven, errorResult;
123
140
  return _regeneratorRuntime().wrap(function _callee$(_context) {
124
141
  while (1) switch (_context.prev = _context.next) {
125
142
  case 0:
@@ -142,40 +159,53 @@ export var ModernElementController = /*#__PURE__*/function () {
142
159
  (_this$options$loading = this.options.loading) === null || _this$options$loading === void 0 || (_this$options$loading2 = _this$options$loading.onStartLoading) === null || _this$options$loading2 === void 0 || _this$options$loading2.call(_this$options$loading);
143
160
  this.status = 'mounting';
144
161
  _context.prev = 6;
145
- _context.next = 9;
146
- return this.setup(renderOptions);
147
- case 9:
148
- setupConfig = _context.sent;
149
- console.log('step1: setupConfig', setupConfig);
150
-
151
- // 2. 创建 iframe,设置 src
162
+ // 1. 创建 iframe(先不设置 src,避免提前触发加载)
152
163
  iframeUrl = this.buildIframeUrl();
153
- console.log('step2: iframeUrl', iframeUrl, this.options.environment);
154
164
  this.iframe = document.createElement('iframe');
155
- this.iframe.src = iframeUrl;
156
165
  this.iframe.style.width = '100%';
157
166
  this.iframe.style.border = 'none';
158
167
  this.iframe.style.height = '0';
159
168
  this.iframe.style.transition = 'height 0.3s ease';
160
169
 
161
- // 3. iframe 添加到容器
162
- console.log('step3: iframe added to container');
170
+ // 2. 先注册所有事件监听(包括 READY_HANDSHAKE),再设置 src 和 appendChild 触发加载,
171
+ // 避免 iframe 快速加载时丢失早期消息
172
+ this.bindBridgeEvents();
173
+ readyHandshakePromise = this.waitForReadyHandshake();
174
+ this.iframe.src = iframeUrl;
163
175
  container.appendChild(this.iframe);
164
176
 
165
- // 4-5. 执行握手流程
166
- console.log('step4-5: handshake completed');
167
- _context.next = 24;
168
- return this.performHandshake(setupConfig);
169
- case 24:
170
- console.log('step6: events bound');
171
- // 6. 绑定持续监听的事件
172
- this.bindBridgeEvents();
177
+ // 3. setup()(网络请求)与 waitForReadyHandshake()(等待 iframe 加载)并行执行
178
+ _context.next = 19;
179
+ return Promise.all([this.setup(renderOptions), readyHandshakePromise]);
180
+ case 19:
181
+ _yield$Promise$all = _context.sent;
182
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 1);
183
+ setupConfig = _yield$Promise$all2[0];
184
+ this.status = 'mounted';
185
+
186
+ // 4. 两者都完成后,发送 HANDSHAKE 配置
187
+ this.sendHandshake(setupConfig);
188
+
189
+ // 5. 等待 HANDSHAKE_ACK
190
+ _context.next = 26;
191
+ return this.waitForHandshakeAck();
192
+ case 26:
173
193
  this.status = 'ready';
174
194
  this.flushCachedMessages();
175
195
  (_this$options$loading3 = this.options.loading) === null || _this$options$loading3 === void 0 || (_this$options$loading4 = _this$options$loading3.onEndLoading) === null || _this$options$loading4 === void 0 || _this$options$loading4.call(_this$options$loading3);
176
- return _context.abrupt("return", {});
196
+ // 参照老逻辑 isLoadErrorPage,对 renderData 做数据格式校验
197
+ dataStructError = this.validateRenderData(setupConfig.renderData);
198
+ if (!dataStructError) {
199
+ _context.next = 32;
200
+ break;
201
+ }
202
+ return _context.abrupt("return", {
203
+ error: dataStructError
204
+ });
177
205
  case 32:
178
- _context.prev = 32;
206
+ return _context.abrupt("return", {});
207
+ case 35:
208
+ _context.prev = 35;
179
209
  _context.t0 = _context["catch"](6);
180
210
  (_this$options$loading5 = this.options.loading) === null || _this$options$loading5 === void 0 || (_this$options$loading6 = _this$options$loading5.onEndLoading) === null || _this$options$loading6 === void 0 || _this$options$loading6.call(_this$options$loading5);
181
211
  this.cleanup();
@@ -187,11 +217,11 @@ export var ModernElementController = /*#__PURE__*/function () {
187
217
  return _context.abrupt("return", {
188
218
  error: errorResult
189
219
  });
190
- case 39:
220
+ case 42:
191
221
  case "end":
192
222
  return _context.stop();
193
223
  }
194
- }, _callee, this, [[6, 32]]);
224
+ }, _callee, this, [[6, 35]]);
195
225
  }));
196
226
  function mount(_x, _x2) {
197
227
  return _mount.apply(this, arguments);
@@ -212,61 +242,91 @@ export var ModernElementController = /*#__PURE__*/function () {
212
242
  key: "setup",
213
243
  value: (function () {
214
244
  var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderOptions) {
215
- var _result$data;
216
- var sessionData, parseData, result, preferredLocale, locale;
245
+ var _parseData$connectFac, _parseData$paymentMet, _sdkQueryResult$data;
246
+ var sessionData, parseData, isConnect, paymentSessionConfig, genSdkQueryPromise, genOneAccountQueryPromise, promises, _ref, _ref2, sdkQueryResult, oneAccountQueryResult, preferredLocale, locale, renderDataError;
217
247
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
218
248
  while (1) switch (_context2.prev = _context2.next) {
219
249
  case 0:
250
+ // 缓存起来,submit时使用
251
+ this.notRedirectAfterComplete = renderOptions.notRedirectAfterComplete || false;
220
252
  sessionData = this.options.sessionData;
221
253
  parseData = getMetaData(sessionData); // 初始化 request 全局配置,使 sdkQuery 能正确发起请求
222
254
  request.setGlobalOptions({
223
255
  hostSign: parseHostSign(sessionData),
224
256
  env: this.options.environment,
225
- sdkVersion: "0.0.1779094014-dev.2" || ''
226
- });
227
-
228
- // 调用 sdkQuery 获取渲染数据,参照 VaultingElement.setup()
229
- _context2.next = 5;
230
- return sdkQuery({
231
- extParams: {
232
- isUserPreferredLocale: true
233
- },
234
- paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
235
- paymentSessionData: sessionData
236
- }).then(function (res) {
237
- return {
238
- data: res,
239
- error: undefined
240
- };
241
- }).catch(function (e) {
242
- var _AntomSDKError$unific;
243
- return {
244
- error: (_AntomSDKError$unific = AntomSDKError.unificationError(e)) === null || _AntomSDKError$unific === void 0 ? void 0 : _AntomSDKError$unific.toJSON(),
245
- data: undefined
246
- };
257
+ sdkVersion: "0.0.1779094014-dev.21" || ''
247
258
  });
248
- case 5:
249
- result = _context2.sent;
259
+ isConnect = !!(parseData !== null && parseData !== void 0 && (_parseData$connectFac = parseData.connectFactor) !== null && _parseData$connectFac !== void 0 && _parseData$connectFac.enableConnect);
260
+ paymentSessionConfig = parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig;
261
+ genSdkQueryPromise = function genSdkQueryPromise() {
262
+ return awaitWrap(sdkQuery({
263
+ extParams: {
264
+ isUserPreferredLocale: true
265
+ },
266
+ paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
267
+ paymentSessionData: sessionData
268
+ }));
269
+ };
270
+ genOneAccountQueryPromise = function genOneAccountQueryPromise() {
271
+ return awaitWrap(oneAccountQuery({
272
+ paymentSessionConfig: paymentSessionConfig,
273
+ paymentSessionData: sessionData,
274
+ accountInfo: {
275
+ email: ''
276
+ }
277
+ }));
278
+ };
279
+ promises = isConnect ? [genSdkQueryPromise(), genOneAccountQueryPromise()] : [genSdkQueryPromise(), undefined];
280
+ _context2.next = 11;
281
+ return Promise.all(promises);
282
+ case 11:
283
+ _ref = _context2.sent;
284
+ _ref2 = _slicedToArray(_ref, 2);
285
+ sdkQueryResult = _ref2[0];
286
+ oneAccountQueryResult = _ref2[1];
250
287
  // 从 renderData 中提取 preferredLocale
251
- preferredLocale = getLocaleFromRenderData(result.data);
252
- locale = preferredLocale || this.options.locale;
288
+ preferredLocale = getLocaleFromRenderData(sdkQueryResult.data);
289
+ locale = preferredLocale || this.options.locale; // 优先使用请求错误,其次使用数据结构校验错误
290
+ renderDataError = sdkQueryResult.error || (oneAccountQueryResult === null || oneAccountQueryResult === void 0 ? void 0 : oneAccountQueryResult.error);
253
291
  return _context2.abrupt("return", {
292
+ // 更新字段,对应老的paymentSessionData
254
293
  sessionData: sessionData,
255
- environment: this.options.environment,
294
+ // 新增字段,对应老的queryResult成功时
295
+ renderData: sdkQueryResult.data,
296
+ // 新增字段,对应老的queryResult失败时及 oneAccountQueryResult 失败时
297
+ renderDataError: renderDataError,
298
+ // 更新字段,对应老的oneAccountQueryResult成功时
299
+ connectAccount: oneAccountQueryResult === null || oneAccountQueryResult === void 0 ? void 0 : oneAccountQueryResult.data,
300
+ // 更新字段,对应老的sessionResult
301
+ sessionMetaData: parseData,
302
+ // 更新字段,对应老的doMain
303
+ merchantDomain: window.location.hostname,
304
+ // 更新字段,对应老的appearance,结构按新的来
305
+ appearance: adaptAppearance((renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.appearance) || this.options.appearance, renderOptions.merchantAppointParam),
306
+ // 原老字段
307
+ logMetaData: {
308
+ paymentMethodCategoryType: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.paymentMethodCategoryType,
309
+ productSceneVersion: paymentSessionConfig === null || paymentSessionConfig === void 0 ? void 0 : paymentSessionConfig.productSceneVersion,
310
+ trackId: parseTrackerId(sessionData),
311
+ merchantId: parseData === null || parseData === void 0 ? void 0 : parseData.clientId,
312
+ paymentMethodType: parseData === null || parseData === void 0 || (_parseData$paymentMet = parseData.paymentMethodInfoView) === null || _parseData$paymentMet === void 0 ? void 0 : _parseData$paymentMet.paymentMethodType
313
+ },
314
+ // 原老字段
315
+ heightOfVisible: Math.max(window.changingPageHeight, window.innerHeight),
316
+ // 新sdk字段
256
317
  locale: locale,
257
- paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
258
- appearance: adaptAppearance((renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.appearance) || this.options.appearance),
259
- // 新增字段
260
- renderData: result.data,
261
- renderDataError: result.error,
262
- sdkVersion: "0.0.1779094014-dev.2" || '',
263
- merchantId: ((_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.merchantId) || '',
264
- env: this.options.environment || 'prod',
318
+ // 新sdk字段
319
+ sdkVersion: "0.0.1779094014-dev.21" || '',
320
+ // 新sdk字段
321
+ merchantId: (sdkQueryResult === null || sdkQueryResult === void 0 || (_sdkQueryResult$data = sdkQueryResult.data) === null || _sdkQueryResult$data === void 0 ? void 0 : _sdkQueryResult$data.merchantId) || '',
322
+ // 新sdk字段
323
+ env: this.options.environment === 'sandbox' ? 'sandbox' : 'prod',
324
+ // 新sdk字段,开发环境调试使用
265
325
  _requestConfig: _objectSpread({
266
- env: this.options.environment || 'prod'
326
+ env: this.options.environment === 'sandbox' ? 'sandbox' : 'prod'
267
327
  }, getDevReqConfig())
268
328
  });
269
- case 9:
329
+ case 19:
270
330
  case "end":
271
331
  return _context2.stop();
272
332
  }
@@ -278,122 +338,384 @@ export var ModernElementController = /*#__PURE__*/function () {
278
338
  return setup;
279
339
  }()
280
340
  /**
281
- * 执行握手流程:
282
- * - 监听 READY_HANDSHAKE setTarget → send(HANDSHAKE, mergedConfig)
283
- * - 等待 HANDSHAKE_ACK resolve
341
+ * 校验 renderData 数据格式,参照老逻辑 isLoadErrorPage 的三个校验维度:
342
+ * 1. success 字段 接口是否返回业务成功
343
+ * 2. 支付方式 paymentMethods 或 savedPaymentMethods 必须存在且为非空数组
344
+ * 3. 金额视图 — orderAmountView 和 paymentAmountView 必须同时存在
345
+ *
346
+ * 当数据结构异常时,构造 ERR_DATA_STRUCT_UNRECOGNIZED 错误
284
347
  */
285
348
  )
286
349
  }, {
287
- key: "performHandshake",
288
- value: (function () {
289
- var _performHandshake = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(setupConfig) {
290
- var _this = this;
291
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
292
- while (1) switch (_context3.prev = _context3.next) {
293
- case 0:
294
- return _context3.abrupt("return", new Promise(function (resolve, reject) {
295
- var timer = setTimeout(function () {
296
- reject({
297
- code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
298
- message: 'Mount timeout'
299
- });
300
- }, MOUNT_TIMEOUT);
301
-
302
- // 监听 HEIGHT_UPDATE(只需要注册一次,放在握手前避免丢失早期消息)
303
- _this.bridge.on(MessageType.HEIGHT_UPDATE, function (height) {
304
- console.log(height, 'HEIGHT_UPDATE');
305
- if (_this.iframe) _this.iframe.style.height = "".concat(height, "px");
306
- });
307
-
308
- // 4. 监听 READY_HANDSHAKE → setTarget → send(HANDSHAKE, mergedConfig)
309
- _this.bridge.once(MessageType.READY_HANDSHAKE, function () {
310
- var _this$iframe;
311
- console.log('READY_HANDSHAKE');
312
- if (!((_this$iframe = _this.iframe) !== null && _this$iframe !== void 0 && _this$iframe.contentWindow)) {
313
- clearTimeout(timer);
314
- reject({
315
- code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
316
- message: 'Iframe contentWindow not available'
317
- });
318
- return;
319
- }
320
- _this.bridge.setTargetWindow(_this.iframe.contentWindow);
350
+ key: "validateRenderData",
351
+ value: function validateRenderData(renderData) {
352
+ if (!renderData) {
353
+ return {
354
+ source: 'SDK_INTERNAL',
355
+ code: 'ERR_DATA_STRUCT_UNRECOGNIZED',
356
+ message: 'An error occurred. The transaction cannot be initiated.',
357
+ reason: 'renderData is empty',
358
+ traceId: ''
359
+ };
360
+ }
361
+ var success = renderData.success,
362
+ paymentMethods = renderData.paymentMethods,
363
+ savedPaymentMethods = renderData.savedPaymentMethods,
364
+ orderAmountView = renderData.orderAmountView,
365
+ paymentAmountView = renderData.paymentAmountView;
321
366
 
322
- // 设置安全源
323
- try {
324
- var iframeOrigin = new URL(_this.iframe.src).origin;
325
- if (iframeOrigin && iframeOrigin !== 'null') {
326
- _this.bridge.setOrigin(iframeOrigin);
327
- }
328
- } catch (_unused) {
329
- // URL 解析失败时保持默认 origin
330
- }
367
+ // 校验是否存在有效支付方式
368
+ var hasValidPaymentMethods = paymentMethods && Array.isArray(paymentMethods) && paymentMethods.length > 0 || savedPaymentMethods && Array.isArray(savedPaymentMethods) && savedPaymentMethods.length > 0;
331
369
 
332
- // HANDSHAKE payload 包含 setup() 返回的完整配置
333
- _this.bridge.send(MessageType.HANDSHAKE, setupConfig);
334
- });
370
+ // 金额存在性校验
371
+ var hasAmountViews = !!orderAmountView && !!paymentAmountView;
335
372
 
336
- // 5. 等待 HANDSHAKE_ACK
337
- _this.bridge.once(MessageType.HANDSHAKE_ACK, function () {
338
- clearTimeout(timer);
339
- resolve();
340
- });
341
- }));
342
- case 1:
343
- case "end":
344
- return _context3.stop();
345
- }
346
- }, _callee3);
347
- }));
348
- function performHandshake(_x4) {
349
- return _performHandshake.apply(this, arguments);
373
+ // 满足任一异常条件即判定数据结构不可识别
374
+ if (!success || !hasValidPaymentMethods || !hasAmountViews) {
375
+ return {
376
+ source: 'SDK_INTERNAL',
377
+ code: 'ERR_DATA_STRUCT_UNRECOGNIZED',
378
+ message: 'An error occurred. The transaction cannot be initiated.',
379
+ reason: "Data structure validation failed: success=".concat(success, ", hasValidPaymentMethods=").concat(hasValidPaymentMethods, ", hasAmountViews=").concat(hasAmountViews),
380
+ traceId: ''
381
+ };
350
382
  }
351
- return performHandshake;
352
- }()
383
+ return undefined;
384
+ }
385
+
353
386
  /**
354
- * 绑定持续监听的 bridge 事件
387
+ * 注册所有 bridge 事件监听(必须在 iframe 加载前调用,避免丢失早期消息)
355
388
  */
356
- )
357
389
  }, {
358
390
  key: "bindBridgeEvents",
359
391
  value: function bindBridgeEvents() {
360
- var _this2 = this;
361
- this.bridge.on(MessageType.ERROR, function (payload) {
362
- var _this2$options, _this2$options$onEven;
363
- (_this2$options = _this2.options) === null || _this2$options === void 0 || (_this2$options$onEven = _this2$options.onEventCallback) === null || _this2$options$onEven === void 0 || _this2$options$onEven.call(_this2$options, adaptErrorToEventCallback(payload));
392
+ var _this = this;
393
+ this.bridge.on(MessageType.HEIGHT_UPDATE, function (height) {
394
+ if (_this.iframe) _this.iframe.style.height = "".concat(height, "px");
364
395
  });
365
396
  this.bridge.on(MessageType.REDIRECT, function (payload) {
366
397
  var url = payload.url,
367
- mode = payload.mode;
368
- if (mode === 'replace') {
369
- window.location.replace(url);
370
- } else {
371
- window.location.href = url;
398
+ mode = payload.mode,
399
+ appLinkUrl = payload.appLinkUrl,
400
+ schemaUrl = payload.schemaUrl,
401
+ destory = payload.destory;
402
+ if (destory) {
403
+ _this.destroy();
404
+ }
405
+ function fallbackJump() {
406
+ if (mode === 'replace') {
407
+ window.location.replace(url);
408
+ } else {
409
+ window.location.href = url;
410
+ }
411
+ }
412
+ try {
413
+ if (appLinkUrl || schemaUrl) {
414
+ var app = new CallApp({
415
+ resultJudgmentTime: 2000,
416
+ fallback: function fallback() {
417
+ fallbackJump();
418
+ }
419
+ });
420
+ app.open({
421
+ scheme: schemaUrl,
422
+ link: appLinkUrl
423
+ });
424
+ } else {
425
+ fallbackJump();
426
+ }
427
+ } catch (error) {
428
+ fallbackJump();
372
429
  }
373
430
  });
374
431
  this.bridge.on(MessageType.OPEN_MODAL, function (payload) {
375
- _this2.handleOpenModal(payload);
432
+ _this.handleOpenModal(payload);
376
433
  });
377
434
  this.bridge.on(MessageType.CLOSE_MODAL, function () {
378
- _this2.handleCloseModal();
435
+ _this.handleCloseModal();
436
+ });
437
+
438
+ // PC 非 Safari Apple Pay:webapp 委托 SDK 域调起 Apple modal 拿 token
439
+ this.bridge.on(AMSMessageType.GET_APPLE_PAY_TOKEN, function (payload) {
440
+ _this.handleGetApplePayToken(payload);
441
+ });
442
+
443
+ // skipRenderPaymentMethod 场景:webapp 委托 SDK 全权拉起 ApplePay,fire-and-forget
444
+ // 走 plugin/applepay 标准链路(onEventCallback 自动通知商户)
445
+ this.bridge.on(AMSMessageType.HANDLE_PAYMENT, function (payload) {
446
+ _this.handleHandlePayment(payload);
447
+ });
448
+
449
+ // webapp 查询 native plugin 是否注册(Android webview GooglePay 探测用)
450
+ this.bridge.on(AMSMessageType.CHECK_BUS_SUBSCRIBED, function (payload) {
451
+ _this.bridge.send(AMSMessageType.CHECK_BUS_SUBSCRIBED_REPLY, {
452
+ requestId: payload.requestId,
453
+ isSubscribed: BusManager.isSubscribed(payload.actionName)
454
+ });
455
+ });
456
+ }
457
+
458
+ /**
459
+ * 处理 webapp 委托的 Apple Pay token 请求。
460
+ * Chrome 等非 Safari 浏览器内 iframe 无法拉起 Apple 二维码 modal(jsapi 注入需父域),
461
+ * 改由 SDK 域 new ApplePaySdk().startPay() 拉起 Apple modal,结果通过 bridge 回传。
462
+ */
463
+ }, {
464
+ key: "handleGetApplePayToken",
465
+ value: (function () {
466
+ var _handleGetApplePayToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(payload) {
467
+ var _paymentMethod,
468
+ _this2 = this;
469
+ var sessionData, applePayProps, paymentRequest, merchantCapabilities, merchantInfo, paymentAmount, supportedNetworks, version, requiredBillingContactFields, requiredShippingContactFields, finalAmount, finalCurrency, capturedResult, service;
470
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
471
+ while (1) switch (_context5.prev = _context5.next) {
472
+ case 0:
473
+ sessionData = this.options.sessionData;
474
+ applePayProps = payload === null || payload === void 0 || (_paymentMethod = payload.paymentMethod) === null || _paymentMethod === void 0 || (_paymentMethod = _paymentMethod.paymentMethodDetail) === null || _paymentMethod === void 0 ? void 0 : _paymentMethod.applePayProps;
475
+ paymentRequest = applePayProps === null || applePayProps === void 0 ? void 0 : applePayProps.paymentRequest;
476
+ if (paymentRequest) {
477
+ _context5.next = 6;
478
+ break;
479
+ }
480
+ this.bridge.send(AMSMessageType.GET_APPLE_PAY_TOKEN_REPLY, {
481
+ success: false,
482
+ result: {
483
+ errorCode: 'APPLE_PAY_MISSING_DATA',
484
+ errorMessage: 'paymentRequest not found in payload'
485
+ }
486
+ });
487
+ return _context5.abrupt("return");
488
+ case 6:
489
+ merchantCapabilities = paymentRequest.merchantCapabilities, merchantInfo = paymentRequest.merchantInfo, paymentAmount = paymentRequest.paymentAmount, supportedNetworks = paymentRequest.supportedNetworks, version = paymentRequest.version, requiredBillingContactFields = paymentRequest.requiredBillingContactFields, requiredShippingContactFields = paymentRequest.requiredShippingContactFields;
490
+ finalAmount = (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.formattedValue) || (paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value);
491
+ finalCurrency = paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency;
492
+ service = new ApplePayHostService({
493
+ paymentRequest: {
494
+ countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.countryCode,
495
+ currencyCode: finalCurrency,
496
+ merchantCapabilities: merchantCapabilities,
497
+ supportedNetworks: supportedNetworks,
498
+ requiredBillingContactFields: requiredBillingContactFields,
499
+ requiredShippingContactFields: requiredShippingContactFields,
500
+ total: {
501
+ type: 'final',
502
+ label: (merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName) || 'Payment',
503
+ amount: finalAmount
504
+ },
505
+ version: version
506
+ },
507
+ enableModalCloseListener: true,
508
+ callbacks: {
509
+ validateMerchant: function () {
510
+ var _validateMerchant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(validationURL) {
511
+ var res;
512
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
513
+ while (1) switch (_context3.prev = _context3.next) {
514
+ case 0:
515
+ _context3.next = 2;
516
+ return getApplePayPaymentSession(sessionData, {
517
+ validateUrl: validationURL,
518
+ paymentSessionData: sessionData,
519
+ merchantDomain: window.location.hostname
520
+ }, {
521
+ env: _this2.options.environment,
522
+ envInfo: {
523
+ deviceId: ''
524
+ }
525
+ }, undefined);
526
+ case 2:
527
+ res = _context3.sent;
528
+ if (!(res !== null && res !== void 0 && res.success && res.merchantSessionObject)) {
529
+ _context3.next = 5;
530
+ break;
531
+ }
532
+ return _context3.abrupt("return", typeof res.merchantSessionObject === 'string' ? JSON.parse(res.merchantSessionObject) : res.merchantSessionObject);
533
+ case 5:
534
+ throw {
535
+ errorCode: 'APPLE_PAY_VALIDATION_FAILED',
536
+ errorMessage: (res === null || res === void 0 ? void 0 : res.errorMessage) || 'Merchant validation failed'
537
+ };
538
+ case 6:
539
+ case "end":
540
+ return _context3.stop();
541
+ }
542
+ }, _callee3);
543
+ }));
544
+ function validateMerchant(_x5) {
545
+ return _validateMerchant.apply(this, arguments);
546
+ }
547
+ return validateMerchant;
548
+ }(),
549
+ onAuthorized: function () {
550
+ var _onAuthorized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref3) {
551
+ var token, billingContact, shippingContact;
552
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
553
+ while (1) switch (_context4.prev = _context4.next) {
554
+ case 0:
555
+ token = _ref3.token, billingContact = _ref3.billingContact, shippingContact = _ref3.shippingContact;
556
+ capturedResult = {
557
+ token: token,
558
+ billingContact: billingContact,
559
+ shippingContact: shippingContact
560
+ };
561
+ return _context4.abrupt("return", {
562
+ success: true,
563
+ result: capturedResult
564
+ });
565
+ case 3:
566
+ case "end":
567
+ return _context4.stop();
568
+ }
569
+ }, _callee4);
570
+ }));
571
+ function onAuthorized(_x6) {
572
+ return _onAuthorized.apply(this, arguments);
573
+ }
574
+ return onAuthorized;
575
+ }()
576
+ }
577
+ });
578
+ _context5.prev = 10;
579
+ _context5.next = 13;
580
+ return service.startPay();
581
+ case 13:
582
+ this.bridge.send(AMSMessageType.GET_APPLE_PAY_TOKEN_REPLY, {
583
+ success: true,
584
+ result: capturedResult
585
+ });
586
+ _context5.next = 19;
587
+ break;
588
+ case 16:
589
+ _context5.prev = 16;
590
+ _context5.t0 = _context5["catch"](10);
591
+ this.bridge.send(AMSMessageType.GET_APPLE_PAY_TOKEN_REPLY, {
592
+ success: false,
593
+ result: {
594
+ errorCode: (_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.errorCode) || 'APPLE_PAY_NOT_SUPPORTED',
595
+ errorMessage: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.errorMessage
596
+ }
597
+ });
598
+ case 19:
599
+ case "end":
600
+ return _context5.stop();
601
+ }
602
+ }, _callee5, this, [[10, 16]]);
603
+ }));
604
+ function handleGetApplePayToken(_x4) {
605
+ return _handleGetApplePayToken.apply(this, arguments);
606
+ }
607
+ return handleGetApplePayToken;
608
+ }()
609
+ /**
610
+ * 处理 webapp 委托的 skipRenderPaymentMethod 拉起请求(fire-and-forget)。
611
+ * 走 plugin/applepay 标准链路:ApplePayBusSubscriber.onCreateComponent 自动注入
612
+ * onEventCallback,通过 BusManager.publish(SDKCallbackActionEnum.onEventCallback)
613
+ * 通知商户。SDK 端不需要 reply 给 webapp。
614
+ */
615
+ )
616
+ }, {
617
+ key: "handleHandlePayment",
618
+ value: function handleHandlePayment(_payload) {
619
+ var sessionData = this.options.sessionData;
620
+ var parseData = getMetaData(sessionData);
621
+ BusManager.publish(new BusMessage(ApplePayActionEnum.createComponent, JSON.stringify({
622
+ appendParams: {
623
+ iframeNodesParams: {
624
+ sessionData: sessionData,
625
+ paymentSessionMetaData: parseData
626
+ }
627
+ },
628
+ options: {
629
+ environment: this.options.environment,
630
+ locale: this.options.locale
631
+ }
632
+ })));
633
+ }
634
+
635
+ /**
636
+ * 等待 webapp 发送 READY_HANDSHAKE(表示 iframe 已加载并准备好握手),
637
+ * 收到后设置 bridge target 和安全源
638
+ */
639
+ }, {
640
+ key: "waitForReadyHandshake",
641
+ value: function waitForReadyHandshake() {
642
+ var _this3 = this;
643
+ return new Promise(function (resolve, reject) {
644
+ var timer = setTimeout(function () {
645
+ reject({
646
+ code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
647
+ message: 'Mount timeout'
648
+ });
649
+ }, MOUNT_TIMEOUT);
650
+ _this3.bridge.once(MessageType.READY_HANDSHAKE, function () {
651
+ var _this3$iframe;
652
+ clearTimeout(timer);
653
+ if (!((_this3$iframe = _this3.iframe) !== null && _this3$iframe !== void 0 && _this3$iframe.contentWindow)) {
654
+ reject({
655
+ code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
656
+ message: 'Iframe contentWindow not available'
657
+ });
658
+ return;
659
+ }
660
+ _this3.bridge.setTarget(_this3.iframe.contentWindow);
661
+ try {
662
+ var iframeOrigin = new URL(_this3.iframe.src).origin;
663
+ if (iframeOrigin && iframeOrigin !== 'null') {
664
+ _this3.bridge.setOrigin(iframeOrigin);
665
+ }
666
+ } catch (_unused) {
667
+ // URL 解析失败时保持默认 origin
668
+ }
669
+ resolve();
670
+ });
671
+ });
672
+ }
673
+
674
+ /**
675
+ * 发送 HANDSHAKE 配置给 webapp(setup 和 READY_HANDSHAKE 都完成后调用)
676
+ */
677
+ }, {
678
+ key: "sendHandshake",
679
+ value: function sendHandshake(setupConfig) {
680
+ this.bridge.send(MessageType.HANDSHAKE, setupConfig);
681
+ }
682
+
683
+ /**
684
+ * 等待 webapp 返回 HANDSHAKE_ACK(确认握手完成)
685
+ */
686
+ }, {
687
+ key: "waitForHandshakeAck",
688
+ value: function waitForHandshakeAck() {
689
+ var _this4 = this;
690
+ return new Promise(function (resolve, reject) {
691
+ var timer = setTimeout(function () {
692
+ reject({
693
+ code: 'SDK_LAUNCH_PAYMENT_APP_ERROR',
694
+ message: 'Mount timeout'
695
+ });
696
+ }, MOUNT_TIMEOUT);
697
+ _this4.bridge.once(MessageType.HANDSHAKE_ACK, function () {
698
+ clearTimeout(timer);
699
+ resolve();
700
+ });
379
701
  });
380
702
  }
381
703
  }, {
382
704
  key: "submitPayment",
383
705
  value: function () {
384
- var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
706
+ var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
385
707
  var _this$options$loading7,
386
708
  _this$options$loading8,
387
- _this3 = this;
709
+ _this5 = this;
388
710
  var result, _this$options$loading9, _this$options$loading10;
389
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
390
- while (1) switch (_context4.prev = _context4.next) {
711
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
712
+ while (1) switch (_context6.prev = _context6.next) {
391
713
  case 0:
392
714
  if (!(this.status !== 'ready')) {
393
- _context4.next = 2;
715
+ _context6.next = 2;
394
716
  break;
395
717
  }
396
- return _context4.abrupt("return", {
718
+ return _context6.abrupt("return", {
397
719
  status: 'FAIL',
398
720
  error: {
399
721
  code: 'UI_STATE_ERROR',
@@ -402,26 +724,28 @@ export var ModernElementController = /*#__PURE__*/function () {
402
724
  });
403
725
  case 2:
404
726
  (_this$options$loading7 = this.options.loading) === null || _this$options$loading7 === void 0 || (_this$options$loading8 = _this$options$loading7.onStartLoading) === null || _this$options$loading8 === void 0 || _this$options$loading8.call(_this$options$loading7);
405
- _context4.prev = 3;
406
- this.send(MessageType.SUBMIT, params);
407
- _context4.next = 7;
727
+ _context6.prev = 3;
728
+ this.send(MessageType.SUBMIT, _objectSpread(_objectSpread({}, params), {}, {
729
+ redirect: this.notRedirectAfterComplete ? 'if_required' : 'always'
730
+ }));
731
+ _context6.next = 7;
408
732
  return new Promise(function (resolve) {
409
- _this3.bridge.once(MessageType.SUBMIT_REPLY, resolve);
733
+ _this5.bridge.once(MessageType.SUBMIT_REPLY, resolve);
410
734
  });
411
735
  case 7:
412
- result = _context4.sent;
413
- return _context4.abrupt("return", adaptSubmitResult(result));
736
+ result = _context6.sent;
737
+ return _context6.abrupt("return", adaptSubmitResult(result));
414
738
  case 9:
415
- _context4.prev = 9;
739
+ _context6.prev = 9;
416
740
  (_this$options$loading9 = this.options.loading) === null || _this$options$loading9 === void 0 || (_this$options$loading10 = _this$options$loading9.onEndLoading) === null || _this$options$loading10 === void 0 || _this$options$loading10.call(_this$options$loading9);
417
- return _context4.finish(9);
741
+ return _context6.finish(9);
418
742
  case 12:
419
743
  case "end":
420
- return _context4.stop();
744
+ return _context6.stop();
421
745
  }
422
- }, _callee4, this, [[3,, 9, 12]]);
746
+ }, _callee6, this, [[3,, 9, 12]]);
423
747
  }));
424
- function submitPayment(_x5) {
748
+ function submitPayment(_x7) {
425
749
  return _submitPayment.apply(this, arguments);
426
750
  }
427
751
  return submitPayment;
@@ -429,27 +753,27 @@ export var ModernElementController = /*#__PURE__*/function () {
429
753
  }, {
430
754
  key: "validateFields",
431
755
  value: function () {
432
- var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
433
- var _this4 = this;
434
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
435
- while (1) switch (_context5.prev = _context5.next) {
756
+ var _validateFields = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
757
+ var _this6 = this;
758
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
759
+ while (1) switch (_context7.prev = _context7.next) {
436
760
  case 0:
437
761
  if (!(this.status !== 'ready')) {
438
- _context5.next = 2;
762
+ _context7.next = 2;
439
763
  break;
440
764
  }
441
- return _context5.abrupt("return", {
765
+ return _context7.abrupt("return", {
442
766
  isValid: false
443
767
  });
444
768
  case 2:
445
769
  this.send(AMSMessageType.VALIDATE);
446
- return _context5.abrupt("return", new Promise(function (resolve) {
770
+ return _context7.abrupt("return", new Promise(function (resolve) {
447
771
  var timer = setTimeout(function () {
448
772
  return resolve({
449
773
  isValid: false
450
774
  });
451
775
  }, 15000);
452
- _this4.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
776
+ _this6.bridge.once(AMSMessageType.VALIDATE_REPLY, function (payload) {
453
777
  clearTimeout(timer);
454
778
  resolve(payload || {
455
779
  isValid: false
@@ -458,53 +782,30 @@ export var ModernElementController = /*#__PURE__*/function () {
458
782
  }));
459
783
  case 4:
460
784
  case "end":
461
- return _context5.stop();
785
+ return _context7.stop();
462
786
  }
463
- }, _callee5, this);
787
+ }, _callee7, this);
464
788
  }));
465
789
  function validateFields() {
466
790
  return _validateFields.apply(this, arguments);
467
791
  }
468
792
  return validateFields;
469
- }()
793
+ }() // eslint-disable-next-line @typescript-eslint/no-unused-vars
470
794
  }, {
471
795
  key: "updatePayment",
472
796
  value: function () {
473
- var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(paymentSessionData) {
474
- var parseData, merged;
475
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
476
- while (1) switch (_context6.prev = _context6.next) {
797
+ var _updatePayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(paymentSessionData) {
798
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
799
+ while (1) switch (_context8.prev = _context8.next) {
477
800
  case 0:
478
- if (!(this.status !== 'ready')) {
479
- _context6.next = 2;
480
- break;
481
- }
482
- return _context6.abrupt("return", false);
483
- case 2:
484
- // 更新内部 sessionData
485
- this.options.sessionData = paymentSessionData;
486
- parseData = getMetaData(paymentSessionData);
487
- merged = {
488
- sessionData: paymentSessionData,
489
- paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
490
- environment: this.options.environment,
491
- locale: this.options.locale
492
- };
493
- this.bridge.send(MessageType.UPDATE_CONFIG, {
494
- merged: merged,
495
- updated: {
496
- sessionData: paymentSessionData,
497
- paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig
498
- }
499
- });
500
- return _context6.abrupt("return", true);
501
- case 7:
801
+ return _context8.abrupt("return", false);
802
+ case 1:
502
803
  case "end":
503
- return _context6.stop();
804
+ return _context8.stop();
504
805
  }
505
- }, _callee6, this);
806
+ }, _callee8);
506
807
  }));
507
- function updatePayment(_x6) {
808
+ function updatePayment(_x8) {
508
809
  return _updatePayment.apply(this, arguments);
509
810
  }
510
811
  return updatePayment;
@@ -512,27 +813,24 @@ export var ModernElementController = /*#__PURE__*/function () {
512
813
  }, {
513
814
  key: "on",
514
815
  value: function on(event, callback) {
515
- if (!this.eventListeners.has(event)) this.eventListeners.set(event, new Set());
516
- this.eventListeners.get(event).add(callback);
517
816
  this.bridge.on(event, callback);
518
817
  }
519
818
  }, {
520
819
  key: "destroy",
521
820
  value: function destroy() {
522
- var _this$iframe2;
821
+ var _this$iframe;
523
822
  this.handleCloseModal();
524
823
  this.bridge.destroy();
525
- if ((_this$iframe2 = this.iframe) !== null && _this$iframe2 !== void 0 && _this$iframe2.parentNode) this.iframe.parentNode.removeChild(this.iframe);
824
+ if ((_this$iframe = this.iframe) !== null && _this$iframe !== void 0 && _this$iframe.parentNode) this.iframe.parentNode.removeChild(this.iframe);
526
825
  this.iframe = null;
527
826
  this.status = 'destroyed';
528
- this.eventListeners.clear();
529
827
  this.cachedSend = [];
530
828
  }
531
829
  }, {
532
830
  key: "cleanup",
533
831
  value: function cleanup() {
534
- var _this$iframe3;
535
- if ((_this$iframe3 = this.iframe) !== null && _this$iframe3 !== void 0 && _this$iframe3.parentNode) this.iframe.parentNode.removeChild(this.iframe);
832
+ var _this$iframe2;
833
+ if ((_this$iframe2 = this.iframe) !== null && _this$iframe2 !== void 0 && _this$iframe2.parentNode) this.iframe.parentNode.removeChild(this.iframe);
536
834
  this.iframe = null;
537
835
  this.status = 'initialized';
538
836
  this.cachedSend = [];
@@ -563,12 +861,12 @@ export var ModernElementController = /*#__PURE__*/function () {
563
861
  }, {
564
862
  key: "flushCachedMessages",
565
863
  value: function flushCachedMessages() {
566
- var _this5 = this;
864
+ var _this7 = this;
567
865
  if (this.cachedSend.length > 0) {
568
- this.cachedSend.forEach(function (_ref) {
569
- var type = _ref.type,
570
- payload = _ref.payload;
571
- _this5.bridge.send(type, payload);
866
+ this.cachedSend.forEach(function (_ref4) {
867
+ var type = _ref4.type,
868
+ payload = _ref4.payload;
869
+ _this7.bridge.send(type, payload);
572
870
  });
573
871
  this.cachedSend = [];
574
872
  }
@@ -588,16 +886,39 @@ export var ModernElementController = /*#__PURE__*/function () {
588
886
  }, {
589
887
  key: "handleOpenModal",
590
888
  value: function handleOpenModal(payload) {
591
- var _this6 = this;
889
+ var _payload$appearance,
890
+ _themeColorMap$appear,
891
+ _payload$appearance2,
892
+ _this8 = this;
592
893
  // 清理已存在的 modal
593
894
  this.handleCloseModal();
594
895
  var mode = device.isMobile ? 'mobile' : 'desktop';
595
896
 
596
897
  // 为 modal 创建独立的 HostBridge 用于通信(scope 使用 payload 的 scope 或 'modal')
597
- var modalBridge = this.modalBridge = new HostSDKBridge('HOST', payload.scope || 'modal');
898
+ var modalBridge = this.modalBridge = HostSDKBridge.getGlobalBridge('HOST');
899
+
900
+ // MessageChannel
901
+ var messageChannel = new MessageChannel();
902
+ this.bridge.send(MessageType.TRANSFER_APP_PORT, payload.modalId, [messageChannel.port1]);
903
+ try {
904
+ var url = new URL(payload.url);
905
+ if (payload.closeConfirm) {
906
+ url.searchParams.append('confirm', 'true');
907
+ }
908
+ payload.url = url.toString();
909
+ } catch (e) {
910
+ var error = new OpenSDKError('Invalid URL', 'INVALID_MODAL_URL', 'APP_RUNTIME');
911
+ this.bridge.send(MessageType.OPEN_MODAL_ERROR, error);
912
+ return;
913
+ }
598
914
 
599
- // 处理 closeConfirm MessageChannel
600
- var messageChannel = payload.closeConfirm ? new MessageChannel() : null;
915
+ // appearance 提取主题信息,组装 loadingConfig(对齐 antom.ts openModal 的处理逻辑)
916
+ var appearanceTheme = (payload === null || payload === void 0 || (_payload$appearance = payload.appearance) === null || _payload$appearance === void 0 ? void 0 : _payload$appearance.theme) || 'default';
917
+ var themeConfig = (_themeColorMap$appear = themeColorMap[appearanceTheme]) !== null && _themeColorMap$appear !== void 0 ? _themeColorMap$appear : themeColorMap.default;
918
+ var loadingConfig = {
919
+ theme: themeConfig.theme,
920
+ backgroundColor: (payload === null || payload === void 0 || (_payload$appearance2 = payload.appearance) === null || _payload$appearance2 === void 0 || (_payload$appearance2 = _payload$appearance2.variables) === null || _payload$appearance2 === void 0 ? void 0 : _payload$appearance2['background-primary']) || themeConfig.backgroundColor
921
+ };
601
922
 
602
923
  // 调用 openModal 工具函数创建 DOM(overlay + modal + iframe + 动画 + close icon + loading)
603
924
  var _openModal = openModal({
@@ -606,23 +927,21 @@ export var ModernElementController = /*#__PURE__*/function () {
606
927
  showClose: payload.showClose,
607
928
  hideCloseWhenLoaded: payload.hideCloseWhenLoaded,
608
929
  showLoading: payload.showLoading,
930
+ loadingConfig: loadingConfig,
609
931
  onClose: payload.closeConfirm ? function () {
610
932
  return new Promise(function (resolve) {
611
933
  // closeConfirm 时等待确认关闭(由 CLOSE_MODAL 消息触发 resolve)
612
- _this6._closeConfirmResolve = resolve;
934
+ _this8._closeConfirmResolve = resolve;
613
935
  });
614
936
  } : undefined
615
937
  }),
616
938
  iframe = _openModal.iframe,
617
939
  destroy = _openModal.destroy;
618
- this.modalIframe = iframe;
619
- this.modalDestroy = destroy;
620
-
621
- // 监听 modal 的 iframe load 事件
622
- iframe.addEventListener('load', function () {
940
+ var handler = function handler() {
941
+ iframe.removeEventListener('load', handler);
623
942
  // 确保 target 已设置(如果 load 事件尚未触发,在此设置)
624
943
  if (iframe.contentWindow) {
625
- modalBridge.setTargetWindow(iframe.contentWindow);
944
+ modalBridge.setTarget(iframe.contentWindow);
626
945
  try {
627
946
  var iframeOrigin = new URL(iframe.src).origin;
628
947
  if (iframeOrigin && iframeOrigin !== 'null') {
@@ -631,21 +950,25 @@ export var ModernElementController = /*#__PURE__*/function () {
631
950
  } catch (_unused2) {
632
951
  // URL 解析失败时保持默认 origin
633
952
  }
634
- }
635
-
636
- // 如果 payloadappearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送给 modal
637
- if (payload.appearance) {
638
- modalBridge.send(MessageType.TRANSFER_MODAL_APPEARANCE, payload.appearance);
639
- }
953
+ // 如果 payload 有 appearance,通过 TRANSFER_MODAL_APPEARANCE 消息发送给 modal
954
+ if (payload.appearance) {
955
+ modalBridge.send(MessageType.TRANSFER_MODAL_APPEARANCE, payload.appearance);
956
+ }
957
+ if (payload.initialData) {
958
+ modalBridge.send(MessageType.TRANSFER_MODAL_INITIALDATA, payload.initialData);
959
+ }
640
960
 
641
- // 如果 payload 有 closeConfirm,创建 MessageChannel port 用于确认关闭
642
- if (payload.closeConfirm && messageChannel) {
643
- // 发送 port1 给 webapp(主 iframe)
644
- _this6.bridge.send(MessageType.TRANSFER_APP_PORT, undefined, [messageChannel.port1]);
645
961
  // 发送 port2 给 modal
646
- modalBridge.send(MessageType.TRANSFER_MODAL_PORT, undefined, [messageChannel.port2]);
962
+ modalBridge.send(MessageType.TRANSFER_MODAL_PORT, payload.modalId, [messageChannel.port2]);
647
963
  }
648
- });
964
+ };
965
+ this.modalDestroy = function () {
966
+ destroy();
967
+ iframe.removeEventListener('load', handler);
968
+ };
969
+
970
+ // 监听 modal 的 iframe load 事件
971
+ iframe.addEventListener('load', handler);
649
972
  }
650
973
 
651
974
  /**
@@ -667,7 +990,6 @@ export var ModernElementController = /*#__PURE__*/function () {
667
990
  this.modalDestroy();
668
991
  this.modalDestroy = null;
669
992
  }
670
- this.modalIframe = null;
671
993
  }
672
994
  }, {
673
995
  key: "buildIframeUrl",