@alipay/ams-checkout 1.3.1 → 1.3.2

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 (56) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/index.d.ts +16 -0
  3. package/esm/config/index.js +70 -0
  4. package/esm/constant/index.d.ts +135 -0
  5. package/esm/constant/index.js +135 -0
  6. package/esm/core/component/index.d.ts +17 -0
  7. package/esm/core/component/index.js +139 -0
  8. package/esm/core/drop-in/index.d.ts +29 -0
  9. package/esm/core/drop-in/index.js +104 -0
  10. package/esm/core/instance/index.d.ts +67 -0
  11. package/esm/core/instance/index.js +276 -0
  12. package/esm/image/cta.svg +9 -0
  13. package/esm/index.d.ts +22 -0
  14. package/esm/plugin/component/cashierApp.d.ts +24 -0
  15. package/esm/plugin/component/cashierApp.js +139 -0
  16. package/esm/plugin/component/component.style.d.ts +8 -0
  17. package/esm/plugin/component/component.style.js +15 -0
  18. package/esm/plugin/component/index.d.ts +102 -0
  19. package/esm/plugin/component/index.js +893 -0
  20. package/esm/plugin/drop-in/index.d.ts +73 -0
  21. package/esm/plugin/drop-in/index.js +323 -0
  22. package/esm/request/index.d.ts +15 -0
  23. package/esm/request/index.js +144 -0
  24. package/esm/request/utils.d.ts +28 -0
  25. package/esm/request/utils.js +59 -0
  26. package/esm/service/index.d.ts +2 -0
  27. package/esm/service/index.js +40 -0
  28. package/esm/types/index.d.ts +194 -0
  29. package/esm/types/index.js +94 -0
  30. package/esm/util/createIframeNode.d.ts +5 -0
  31. package/esm/util/createIframeNode.js +35 -0
  32. package/esm/util/get.d.ts +25 -0
  33. package/esm/util/get.js +145 -0
  34. package/esm/util/index.d.ts +53 -0
  35. package/esm/util/index.js +237 -0
  36. package/esm/util/intl-callapp/es/browser.d.ts +21 -0
  37. package/esm/util/intl-callapp/es/browser.js +42 -0
  38. package/esm/util/intl-callapp/es/evoke.d.ts +13 -0
  39. package/esm/util/intl-callapp/es/evoke.js +39 -0
  40. package/esm/util/intl-callapp/es/generate.d.ts +29 -0
  41. package/esm/util/intl-callapp/es/generate.js +44 -0
  42. package/esm/util/intl-callapp/es/index.d.ts +43 -0
  43. package/esm/util/intl-callapp/es/index.js +298 -0
  44. package/esm/util/intl-callapp/es/main.d.ts +41 -0
  45. package/esm/util/intl-callapp/es/main.js +305 -0
  46. package/esm/util/intl-callapp/es/openWallet.d.ts +15 -0
  47. package/esm/util/intl-callapp/es/openWallet.js +197 -0
  48. package/esm/util/intl-callapp/es/types.d.ts +46 -0
  49. package/esm/util/intl-callapp/es/types.js +1 -0
  50. package/esm/util/intl-callapp/es/utils/config.d.ts +24 -0
  51. package/esm/util/intl-callapp/es/utils/config.js +57 -0
  52. package/esm/util/intl-callapp/es/utils/index.d.ts +15 -0
  53. package/esm/util/intl-callapp/es/utils/index.js +98 -0
  54. package/esm/util/mock.d.ts +1 -0
  55. package/esm/util/mock.js +4 -0
  56. package/package.json +1 -1
@@ -0,0 +1,893 @@
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 _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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
3
+ 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); } }
4
+ 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); }); }; }
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ 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; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ 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); }
13
+ /**
14
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
15
+ * 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:
16
+ * 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
17
+ * 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.
18
+ */
19
+ /* eslint-disable no-console */
20
+ import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
21
+ import { queryPaymentInfo } from "../../service";
22
+ import { componentNameEnum, messageName, Target } from "../../types";
23
+ import { getDesignFontSize, getType, isJsonString, isPC } from "../../util";
24
+ import { isLocalMock } from "../../util/mock";
25
+ import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
26
+ import { componentAddCSS } from "./component.style";
27
+ var _window = window,
28
+ innerHeight = _window.innerHeight;
29
+ var amsSetSize = function amsSetSize(event, dom) {
30
+ try {
31
+ var _dom = dom || document.getElementById('ams-component-container');
32
+ _dom.style.fontSize = "".concat(getDesignFontSize(), "px");
33
+ innerHeight = window.innerHeight;
34
+ // eslint-disable-next-line no-empty
35
+ } catch (error) {}
36
+ };
37
+ var addEvent = function addEvent() {
38
+ window.removeEventListener('resize', amsSetSize);
39
+ window.removeEventListener('pageShow', amsSetSize);
40
+ window.removeEventListener('DOMContentLoaded', amsSetSize);
41
+ window.addEventListener('resize', amsSetSize);
42
+ window.addEventListener('pageShow', amsSetSize);
43
+ window.addEventListener('DOMContentLoaded', amsSetSize);
44
+ };
45
+ var mockupId = 'ams-component-mockup';
46
+ var loadingId = 'ams-component-loading';
47
+ var listenerPrefix = '_ams_sdk_component_listener';
48
+ var ComponentApp = /*#__PURE__*/function () {
49
+ function ComponentApp() {
50
+ _classCallCheck(this, ComponentApp);
51
+ _defineProperty(this, "app", void 0);
52
+ _defineProperty(this, "appDomain", void 0);
53
+ _defineProperty(this, "AMSSDK", void 0);
54
+ _defineProperty(this, "platform", void 0);
55
+ _defineProperty(this, "createIframeNode", void 0);
56
+ _defineProperty(this, "_selector", void 0);
57
+ _defineProperty(this, "_appVersion", void 0);
58
+ _defineProperty(this, "_isRetention", void 0);
59
+ _defineProperty(this, "_actionQueryPromise", null);
60
+ _defineProperty(this, "_renderParams", null);
61
+ _defineProperty(this, "_componentName", '');
62
+ _defineProperty(this, "_performanceData", []);
63
+ _defineProperty(this, "_isInitComponent", void 0);
64
+ _defineProperty(this, "_clickEventName", void 0);
65
+ this._appVersion = '1.3.1';
66
+ this._isInitComponent = false;
67
+ this._selector = '#ams-component-section';
68
+ this.createIframeNode = function () {
69
+ return Promise.resolve();
70
+ };
71
+ this.platform = isPC() ? 'desktop' : 'mobile';
72
+ this._clickEventName = this.platform === 'mobile' ? 'touchend' : 'click';
73
+ this._isRetention = true;
74
+ addEvent();
75
+ this.createMountElement();
76
+ this._performanceData.push({
77
+ key: 'sdk_init',
78
+ value: Date.now()
79
+ });
80
+ }
81
+
82
+ /**
83
+ * @description Cancel listening and destroy the dom
84
+ */
85
+ _createClass(ComponentApp, [{
86
+ key: "logoutPlugin",
87
+ value: function logoutPlugin() {
88
+ this.closeCashier();
89
+ }
90
+
91
+ /**
92
+ * @description When SDK registers plug-ins, it is a required function to receive SDK instances
93
+ */
94
+ }, {
95
+ key: "applyPlugin",
96
+ value: function applyPlugin(AMSSDK) {
97
+ this.AMSSDK = AMSSDK;
98
+ this.subscribeFromSDK();
99
+ }
100
+
101
+ /**
102
+ * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
103
+ */
104
+ }, {
105
+ key: "setRender",
106
+ value: function setRender(createIframeNode) {
107
+ this.createIframeNode = createIframeNode;
108
+ }
109
+
110
+ /**
111
+ * @description render iframe content
112
+ */
113
+ }, {
114
+ key: "appendIframeNodes",
115
+ value: function appendIframeNodes(componentName, renderParams) {
116
+ var _renderParams$appeara,
117
+ _this = this;
118
+ if (this._isInitComponent) return Promise.reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
119
+ this._isInitComponent = true;
120
+ this._renderParams = renderParams;
121
+ this._componentName = componentName;
122
+ this._performanceData.push({
123
+ key: 'sdk_create_component',
124
+ value: Date.now()
125
+ });
126
+ this.createRetentionPopup();
127
+ this.createMockup();
128
+ if ((renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$appeara = renderParams.appearance) === null || _renderParams$appeara === void 0 ? void 0 : _renderParams$appeara.showLoading) !== false) {
129
+ var mockup = document.getElementById(mockupId);
130
+ if (mockup) {
131
+ mockup.style.display = 'block';
132
+ }
133
+ this.showLoading();
134
+ }
135
+ this.showCashier();
136
+ this.createApp(renderParams);
137
+ this.createActionQueryPromise();
138
+ return Promise.all([this.createIframeNode(this, _objectSpread(_objectSpread({}, renderParams), {}, {
139
+ selector: this._selector
140
+ })), this._actionQueryPromise]).catch(function () {
141
+ _this._isInitComponent = false;
142
+ });
143
+ }
144
+ /**
145
+ * @description Interface request
146
+ */
147
+ }, {
148
+ key: "createActionQueryPromise",
149
+ value: function createActionQueryPromise() {
150
+ var _this2 = this;
151
+ this._performanceData.push({
152
+ key: 'sdk_action_query_start',
153
+ value: Date.now()
154
+ });
155
+ this._actionQueryPromise = new Promise(function (resolve, reject) {
156
+ var _this2$_renderParams, _this2$_renderParams2, _this2$_renderParams3;
157
+ var params = {
158
+ paymentSessionData: _this2._renderParams && ((_this2$_renderParams = _this2._renderParams) === null || _this2$_renderParams === void 0 ? void 0 : _this2$_renderParams.paymentSessionData) || '',
159
+ paymentSessionConfig: (_this2$_renderParams2 = _this2._renderParams) === null || _this2$_renderParams2 === void 0 ? void 0 : (_this2$_renderParams3 = _this2$_renderParams2.paymentSessionMetaData) === null || _this2$_renderParams3 === void 0 ? void 0 : _this2$_renderParams3.paymentSessionConfig
160
+ };
161
+ if (componentNameEnum.card === _this2._componentName) {
162
+ params.paymentMethodType = 'CARD';
163
+ }
164
+ if (componentNameEnum.easyPay === _this2._componentName) {
165
+ var _this2$_renderParams4;
166
+ // if EASY_PAY 2.0 , no need to query payment request
167
+ var _ref = params.paymentSessionConfig || {},
168
+ _ref$productSceneVers = _ref.productSceneVersion,
169
+ productSceneVersion = _ref$productSceneVers === void 0 ? '' : _ref$productSceneVers,
170
+ _ref$productScene = _ref.productScene,
171
+ productScene = _ref$productScene === void 0 ? '' : _ref$productScene;
172
+ var _ref2 = ((_this2$_renderParams4 = _this2._renderParams) === null || _this2$_renderParams4 === void 0 ? void 0 : _this2$_renderParams4.paymentSessionMetaData) || {},
173
+ _ref2$action = _ref2.action,
174
+ _ref2$action2 = _ref2$action === void 0 ? {} : _ref2$action,
175
+ _ref2$action2$autoDeb = _ref2$action2.autoDebitWithToken,
176
+ autoDebitWithToken = _ref2$action2$autoDeb === void 0 ? false : _ref2$action2$autoDeb;
177
+ if (productScene === 'EASY_PAY' && productSceneVersion === '2.0' && !autoDebitWithToken) {
178
+ // make queryResult no data we setAppStateData in antom-web-checkout app,
179
+ // eslint-disable-next-line no-promise-executor-return
180
+ return resolve({
181
+ message: 'sdk no need to make query request'
182
+ });
183
+ }
184
+ }
185
+ /**
186
+ * @author tianqiang
187
+ * @description 代扣逻辑处理
188
+ */
189
+ if (componentNameEnum.autoDebit === _this2._componentName) {
190
+ var _this2$_renderParams5, _this2$_renderParams6, _action$web, _action$wap;
191
+ var action = ((_this2$_renderParams5 = _this2._renderParams) === null || _this2$_renderParams5 === void 0 ? void 0 : (_this2$_renderParams6 = _this2$_renderParams5.paymentSessionMetaData) === null || _this2$_renderParams6 === void 0 ? void 0 : _this2$_renderParams6.action) || {};
192
+ var signType = (isPC() ? action === null || action === void 0 ? void 0 : (_action$web = action.web) === null || _action$web === void 0 ? void 0 : _action$web.signType : action === null || action === void 0 ? void 0 : (_action$wap = action.wap) === null || _action$wap === void 0 ? void 0 : _action$wap.signType) || '';
193
+ if (signType === 'SMS') {
194
+ return resolve({
195
+ message: 'sdk no need to make query request'
196
+ });
197
+ } else if (!signType || signType !== 'REDIRECT') {
198
+ return resolve({
199
+ success: false
200
+ });
201
+ }
202
+ }
203
+
204
+ // mock
205
+ if (isLocalMock()) {
206
+ return resolve({
207
+ message: 'sdk no need to make query request'
208
+ });
209
+ }
210
+ queryPaymentInfo(params, {
211
+ env: _this2.AMSSDK.options.env.environment,
212
+ locale: _this2.AMSSDK.options.locale
213
+ }).then(function (res) {
214
+ _this2._performanceData.push({
215
+ key: 'sdk_action_query_end',
216
+ value: Date.now()
217
+ });
218
+ if (res !== null && res !== void 0 && res.success) {
219
+ resolve(res);
220
+ } else {
221
+ resolve(res);
222
+ _this2.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR);
223
+ }
224
+ }).catch(function (err) {
225
+ reject(err);
226
+ _this2.closeCashier();
227
+ });
228
+ });
229
+ }
230
+ }, {
231
+ key: "cleanApp",
232
+ value: function cleanApp() {
233
+ try {
234
+ this.app = null;
235
+ this._removeEventListener();
236
+ if (getType(this._selector) === 'string') {
237
+ var dorpinDom = document.querySelector(this._selector);
238
+ if (dorpinDom) dorpinDom.innerHTML = '';
239
+ }
240
+ // eslint-disable-next-line no-empty
241
+ } catch (error) {}
242
+ }
243
+
244
+ /**
245
+ * @description Create app
246
+ */
247
+ }, {
248
+ key: "createApp",
249
+ value: function createApp(renderParams) {
250
+ if (!!window.postMessage !== true) {
251
+ this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE);
252
+ return;
253
+ }
254
+ this._performanceData.push({
255
+ key: 'sdk_popup_start',
256
+ value: Date.now()
257
+ });
258
+ try {
259
+ var _renderParams$payment, _renderParams$payment2, _renderParams$payment3;
260
+ var productSceneVersion = (renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$payment = renderParams.paymentSessionMetaData) === null || _renderParams$payment === void 0 ? void 0 : (_renderParams$payment2 = _renderParams$payment.paymentSessionConfig) === null || _renderParams$payment2 === void 0 ? void 0 : _renderParams$payment2.productSceneVersion) || '';
261
+ var extendInfo = (renderParams === null || renderParams === void 0 ? void 0 : (_renderParams$payment3 = renderParams.paymentSessionMetaData) === null || _renderParams$payment3 === void 0 ? void 0 : _renderParams$payment3.extendInfo) || '';
262
+ var environment = this.AMSSDK.options.env.environment;
263
+ this.appDomain = getAppDomain({
264
+ environment: environment,
265
+ appVersion: this._appVersion,
266
+ componentName: this._componentName,
267
+ productSceneVersion: productSceneVersion,
268
+ extendInfo: extendInfo
269
+ });
270
+ this.app = createIframe(this.AMSSDK.options.mode);
271
+ this.app.src = getIframeUrl({
272
+ componentName: this._componentName,
273
+ appearance: (renderParams === null || renderParams === void 0 ? void 0 : renderParams.appearance) || {},
274
+ analytics: this.AMSSDK.options.analytics,
275
+ productSceneVersion: productSceneVersion,
276
+ environment: environment,
277
+ appVersion: this._appVersion,
278
+ extendInfo: extendInfo,
279
+ locale: this.AMSSDK.options.locale,
280
+ instanceId: this.AMSSDK._instanceId
281
+ });
282
+
283
+ // Subscribe to messages from iframe
284
+ this._addEventListener();
285
+ } catch (error) {
286
+ this.dispatchToSDK(EVENT.error.name, Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
287
+ stack: error
288
+ }));
289
+ }
290
+ }
291
+ }, {
292
+ key: "listener",
293
+ value: function listener(e) {
294
+ if (e.origin !== this.appDomain) {
295
+ return;
296
+ }
297
+ var isJson = isJsonString(e.data);
298
+ if (isJson) {
299
+ var data = JSON.parse(e.data);
300
+ if (data.name !== messageName.APP_TO_SDK && data.name !== messageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) {
301
+ return;
302
+ }
303
+ this._handleAppMessage(data);
304
+ } else {
305
+ console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
306
+ this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.NOT_JSON_FORMAT);
307
+ }
308
+ }
309
+ }, {
310
+ key: "resizeListener",
311
+ value: function resizeListener() {
312
+ var cashier = document.getElementById('ams-component-container');
313
+ cashier.style.transition = 'none';
314
+ this.dispatchToApp({
315
+ context: {
316
+ event: 'renderResize',
317
+ data: {
318
+ heightOfVisible: window.innerHeight,
319
+ widthOfVisible: window.innerWidth
320
+ }
321
+ }
322
+ });
323
+ }
324
+
325
+ /**
326
+ * @description Initialize subscription iframe message
327
+ */
328
+ }, {
329
+ key: "_addEventListener",
330
+ value: function _addEventListener() {
331
+ window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
332
+ window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId, "_resize")] = this.resizeListener.bind(this);
333
+ this._removeEventListener();
334
+ window.addEventListener('message', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId)]);
335
+ window.addEventListener('resize', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId, "_resize")]);
336
+ }
337
+ }, {
338
+ key: "_removeEventListener",
339
+ value: function _removeEventListener() {
340
+ window.removeEventListener('message', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId)]);
341
+ window.removeEventListener('resize', window["".concat(listenerPrefix, "_").concat(this.AMSSDK._instanceId, "_resize")]);
342
+ }
343
+
344
+ /**
345
+ * @description Processing messages from iframe
346
+ */
347
+ }, {
348
+ key: "_handleAppMessage",
349
+ value: function _handleAppMessage(data) {
350
+ var eventKeyMap = [EVENT.launch.name, EVENT.redirect.name, EVENT.sizeChanged.name, EVENT.log.name, EVENT.onClose.name, EVENT.eventCallback.name, EVENT.submitForm.name, EVENT.showCloseButton.name, EVENT.hideCloseButton.name, EVENT.setAllowRetention.name, EVENT.declareCheckoutInfo.name, EVENT.showPopup.name, EVENT.dismissLoading.name];
351
+ if (data.context.event === EVENT.dismissLoading.name) {
352
+ var _data$context$data;
353
+ this.dispatchToSDK(EVENT.eventCallback.name, {
354
+ code: 'SDK_END_OF_LOADING',
355
+ message: ((_data$context$data = data.context.data) === null || _data$context$data === void 0 ? void 0 : _data$context$data.message) || ''
356
+ });
357
+ return;
358
+ }
359
+ if (!eventKeyMap.includes(data.context.event)) {
360
+ return;
361
+ }
362
+ if (data.context.event === EVENT.launch.name) {
363
+ this._performanceData.push({
364
+ key: 'sdk_onLaunch',
365
+ value: Date.now()
366
+ });
367
+ this.sendRenderEvent();
368
+ return;
369
+ }
370
+ if (data.context.event === EVENT.sizeChanged.name) {
371
+ this.handleSizeChanged(data);
372
+ }
373
+ if (data.context.event === EVENT.onClose.name) {
374
+ return this.closeBtnFunc();
375
+ }
376
+ if (data.context.event === EVENT.redirect.name) {
377
+ return this.handleRedirect(data.context.data);
378
+ }
379
+ if (data.context.event === EVENT.submitForm.name) {
380
+ this.submitForm(data.context.data);
381
+ return;
382
+ }
383
+ if (data.context.event === EVENT.hideCloseButton.name) {
384
+ this.handleCloseBtnShow(false);
385
+ return;
386
+ }
387
+ if (data.context.event === EVENT.showCloseButton.name) {
388
+ this.handleCloseBtnShow(true);
389
+ return;
390
+ }
391
+ if (data.context.event === EVENT.setAllowRetention.name) {
392
+ if (data.context.data === true) this._isRetention = true;
393
+ if (data.context.data === false) this._isRetention = false;
394
+ return;
395
+ }
396
+ if (data.context.event === EVENT.declareCheckoutInfo.name) {
397
+ this.handleDeclareInfo(data.context.data);
398
+ return;
399
+ }
400
+
401
+ // The plug-in communicates with the sdk after processing
402
+ this.dispatchToSDK(data.context.event, data.context.data);
403
+ }
404
+ }, {
405
+ key: "handleSizeChanged",
406
+ value: function handleSizeChanged(data) {
407
+ var _data$context$data2;
408
+ if (((_data$context$data2 = data.context.data) === null || _data$context$data2 === void 0 ? void 0 : _data$context$data2.height) > 1) {
409
+ var _document$getElementB;
410
+ var mockup = document.getElementById(mockupId);
411
+ if (mockup) {
412
+ mockup.style.background = '#000000';
413
+ mockup.style.opacity = '0.6';
414
+ mockup.style.display = 'block';
415
+ }
416
+ (_document$getElementB = document.getElementById(loadingId)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
417
+ var cashier = document.getElementById('ams-component-container');
418
+ cashier.style.height = "".concat(data.context.data.height, "px");
419
+ if (this.platform === 'desktop') {
420
+ cashier.classList.add('ams-component-container-desktop-animation');
421
+ if (data.context.data.width) cashier.style.width = "".concat(data.context.data.width, "px");
422
+ }
423
+ if (this.platform === 'mobile') {
424
+ cashier.classList.add('ams-component-container-mobile-animation');
425
+ var animationStyleId = 'ams-component-container-mobile-animation-style';
426
+ var animationStyle = document.getElementById(animationStyleId);
427
+ if (animationStyle) animationStyle === null || animationStyle === void 0 ? void 0 : animationStyle.remove();
428
+
429
+ // 弹出和弹入动画
430
+ var runkeyframes = " @keyframes ams-component-container-slide-in {\n 0% {\n height: 1px;\n }\n 100% {\n height: ".concat(data.context.data.height, "px;\n }\n }\n @keyframes ams-component-container-slide-out {\n 0% {\n height: ").concat(data.context.data.height, "px;\n opacity: 1;\n }\n 50% {\n opacity: 1;\n }\n 100% {\n height: 1px;\n opacity: 0;\n }\n }");
431
+ // 创建style标签
432
+ var style = document.createElement('style');
433
+ style.id = animationStyleId;
434
+ // 设置style属性
435
+ style.type = 'text/css';
436
+ // 将 keyframes样式写入style内
437
+ style.innerHTML = runkeyframes;
438
+ // 将style样式存放到head标签
439
+ document.getElementsByTagName('head')[0].appendChild(style);
440
+
441
+ // size变动时动画
442
+ setTimeout(function () {
443
+ cashier.style.transition = 'height 0.28s ease-in-out';
444
+ }, 500);
445
+ }
446
+ this.app.style.height = "".concat(data.context.data.height, "px");
447
+ this.app.style.width = '100%';
448
+ this.app.style.border = '0';
449
+ this.app.style.overflow = 'hidden';
450
+ }
451
+ }
452
+ }, {
453
+ key: "handleRedirect",
454
+ value: function handleRedirect(data) {
455
+ var _this3 = this;
456
+ this.closeCashier();
457
+ var _data = typeof data === 'string' ? {
458
+ normalUrl: data
459
+ } : {
460
+ applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
461
+ schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
462
+ normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
463
+ target: data === null || data === void 0 ? void 0 : data.target
464
+ };
465
+ var successCallback = function successCallback(type, url) {
466
+ _this3.dispatchToSDK(EVENT.eventCallback.name, {
467
+ code: 'SDK_CALL_URL_SUCCESS',
468
+ message: "Successfully opened the app,".concat(type, ": ").concat(url)
469
+ });
470
+ };
471
+ var failCallback = function failCallback() {
472
+ _this3.dispatchToSDK(EVENT.eventCallback.name, {
473
+ code: 'SDK_CALL_URL_ERROR',
474
+ message: "Failed to open app,applinkUrl: ".concat(_data === null || _data === void 0 ? void 0 : _data.applinkUrl, " schemeUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.schemeUrl, " normalUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.normalUrl)
475
+ });
476
+ };
477
+
478
+ // 支持 target: _blank,新开tab页打开
479
+ if (_data.target === Target.BLANK) {
480
+ if (!_data.normalUrl) return failCallback();
481
+ successCallback('normalUrl', _data.normalUrl);
482
+ window.open(_data.normalUrl);
483
+ return;
484
+ }
485
+ this.AMSSDK._redirect({
486
+ applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
487
+ }).then(function () {
488
+ successCallback('applinkUrl', _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
489
+ }).catch(function () {
490
+ return _this3.AMSSDK._redirect({
491
+ schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
492
+ });
493
+ }).then(function () {
494
+ successCallback('schemeUrl', _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
495
+ }).catch(function () {
496
+ return _this3.AMSSDK._redirect({
497
+ normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
498
+ });
499
+ }).then(function () {
500
+ successCallback('normalUrl', _data === null || _data === void 0 ? void 0 : _data.normalUrl);
501
+ }).catch(function () {
502
+ failCallback();
503
+ });
504
+ }
505
+ }, {
506
+ key: "handleDeclareInfo",
507
+ value: function handleDeclareInfo(_ref3) {
508
+ var _ref3$closeDialogData = _ref3.closeDialogData,
509
+ closeDialogData = _ref3$closeDialogData === void 0 ? {} : _ref3$closeDialogData;
510
+ try {
511
+ if (closeDialogData) {
512
+ var retentionTitle = document.getElementById('ams-component-retention-title');
513
+ if (retentionTitle) {
514
+ var _closeDialogData$titl, _closeDialogData$titl2, _closeDialogData$titl3;
515
+ retentionTitle.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl = closeDialogData.title) === null || _closeDialogData$titl === void 0 ? void 0 : _closeDialogData$titl.fontSize, "px");
516
+ retentionTitle.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl2 = closeDialogData.title) === null || _closeDialogData$titl2 === void 0 ? void 0 : _closeDialogData$titl2.fontColor;
517
+ retentionTitle.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$titl3 = closeDialogData.title) === null || _closeDialogData$titl3 === void 0 ? void 0 : _closeDialogData$titl3.text;
518
+ }
519
+ var retentionMessage = document.getElementById('ams-component-retention-sub-title');
520
+ if (retentionMessage) {
521
+ var _closeDialogData$mess, _closeDialogData$mess2, _closeDialogData$mess3;
522
+ retentionMessage.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess = closeDialogData.message) === null || _closeDialogData$mess === void 0 ? void 0 : _closeDialogData$mess.fontSize, "px");
523
+ retentionMessage.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess2 = closeDialogData.message) === null || _closeDialogData$mess2 === void 0 ? void 0 : _closeDialogData$mess2.fontColor;
524
+ retentionMessage.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$mess3 = closeDialogData.message) === null || _closeDialogData$mess3 === void 0 ? void 0 : _closeDialogData$mess3.text;
525
+ }
526
+ var remainBtn = document.getElementById('ams-component-retention-remain');
527
+ if (remainBtn) {
528
+ var _closeDialogData$btnO, _closeDialogData$btnO2, _closeDialogData$btnO3, _closeDialogData$btnO4, _closeDialogData$btnO5, _closeDialogData$btnO7;
529
+ remainBtn.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO = closeDialogData.btnOK) === null || _closeDialogData$btnO === void 0 ? void 0 : _closeDialogData$btnO.text;
530
+ remainBtn.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO2 = closeDialogData.btnOK) === null || _closeDialogData$btnO2 === void 0 ? void 0 : _closeDialogData$btnO2.fontSize, "px");
531
+ remainBtn.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO3 = closeDialogData.btnOK) === null || _closeDialogData$btnO3 === void 0 ? void 0 : _closeDialogData$btnO3.fontColor;
532
+ remainBtn.style.borderRadius = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO4 = closeDialogData.btnOK) === null || _closeDialogData$btnO4 === void 0 ? void 0 : _closeDialogData$btnO4.corner, "px");
533
+ if ((closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO5 = closeDialogData.btnOK) === null || _closeDialogData$btnO5 === void 0 ? void 0 : _closeDialogData$btnO5.type) === 'stroke') {
534
+ var _closeDialogData$btnO6;
535
+ remainBtn.style.border = "1px solid ".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO6 = closeDialogData.btnOK) === null || _closeDialogData$btnO6 === void 0 ? void 0 : _closeDialogData$btnO6.bg);
536
+ } else remainBtn.style.backgroundColor = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnO7 = closeDialogData.btnOK) === null || _closeDialogData$btnO7 === void 0 ? void 0 : _closeDialogData$btnO7.bg;
537
+ }
538
+ var leaveBrn = document.getElementById('ams-component-retention-leave');
539
+ if (leaveBrn) {
540
+ var _closeDialogData$btnC, _closeDialogData$btnC2, _closeDialogData$btnC3, _closeDialogData$btnC4, _closeDialogData$btnC5, _closeDialogData$btnC7;
541
+ leaveBrn.innerHTML = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC = closeDialogData.btnCancel) === null || _closeDialogData$btnC === void 0 ? void 0 : _closeDialogData$btnC.text;
542
+ leaveBrn.style.fontSize = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC2 = closeDialogData.btnCancel) === null || _closeDialogData$btnC2 === void 0 ? void 0 : _closeDialogData$btnC2.fontSize, "px");
543
+ leaveBrn.style.color = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC3 = closeDialogData.btnCancel) === null || _closeDialogData$btnC3 === void 0 ? void 0 : _closeDialogData$btnC3.fontColor;
544
+ leaveBrn.style.borderRadius = "".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC4 = closeDialogData.btnCancel) === null || _closeDialogData$btnC4 === void 0 ? void 0 : _closeDialogData$btnC4.corner, "px");
545
+ if ((closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC5 = closeDialogData.btnCancel) === null || _closeDialogData$btnC5 === void 0 ? void 0 : _closeDialogData$btnC5.type) === 'stroke') {
546
+ var _closeDialogData$btnC6;
547
+ leaveBrn.style.border = "1px solid ".concat(closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC6 = closeDialogData.btnCancel) === null || _closeDialogData$btnC6 === void 0 ? void 0 : _closeDialogData$btnC6.bg);
548
+ } else leaveBrn.style.backgroundColor = closeDialogData === null || closeDialogData === void 0 ? void 0 : (_closeDialogData$btnC7 = closeDialogData.btnCancel) === null || _closeDialogData$btnC7 === void 0 ? void 0 : _closeDialogData$btnC7.bg;
549
+ }
550
+ }
551
+ } catch (error) {
552
+ console.error(error);
553
+ }
554
+ }
555
+ }, {
556
+ key: "handleCloseBtnShow",
557
+ value: function handleCloseBtnShow(showClose) {
558
+ var closeBlock = document.getElementById('asm-component-section-close-block');
559
+ if (showClose) {
560
+ closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.remove('asm-component-close-block-hidden');
561
+ } else if (showClose === false) {
562
+ closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.classList.add('asm-component-close-block-hidden');
563
+ }
564
+ }
565
+
566
+ /**
567
+ * @description Send message to SDK
568
+ */
569
+ }, {
570
+ key: "dispatchToSDK",
571
+ value: function dispatchToSDK(event, data) {
572
+ this.AMSSDK.eventCenter.emit(event, data);
573
+ }
574
+
575
+ /**
576
+ * @description Send message to iframe
577
+ */
578
+ }, {
579
+ key: "dispatchToApp",
580
+ value: function dispatchToApp(payload) {
581
+ var data = Object.assign({}, payload, {
582
+ name: messageName.SDK_TO_APP,
583
+ mode: this.AMSSDK.options.mode,
584
+ appId: COMPONENTPLUGINID,
585
+ instanceId: this.AMSSDK._instanceId
586
+ });
587
+ if (this.app && this.app.contentWindow) {
588
+ this.app.contentWindow.postMessage(JSON.stringify(data), this.appDomain);
589
+ }
590
+ }
591
+
592
+ /**
593
+ * @description Subscribe to messages from SDK
594
+ */
595
+ }, {
596
+ key: "subscribeFromSDK",
597
+ value: function subscribeFromSDK() {
598
+ var eventKeyMap = {};
599
+ for (var key in eventKeyMap) {
600
+ // eslint-disable-next-line no-prototype-builtins
601
+ if (eventKeyMap.hasOwnProperty(key)) {
602
+ this.AMSSDK.eventCenter.on("".concat(COMPONENTPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
603
+ }
604
+ }
605
+ }
606
+
607
+ /**
608
+ * @description Send rendering events to iframe
609
+ */
610
+ }, {
611
+ key: "sendRenderEvent",
612
+ value: function () {
613
+ var _sendRenderEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
614
+ var _this$_renderParams, _this$_renderParams2, res;
615
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
616
+ while (1) switch (_context.prev = _context.next) {
617
+ case 0:
618
+ _context.prev = 0;
619
+ if (this._actionQueryPromise) {
620
+ _context.next = 3;
621
+ break;
622
+ }
623
+ return _context.abrupt("return");
624
+ case 3:
625
+ _context.next = 5;
626
+ return this._actionQueryPromise;
627
+ case 5:
628
+ res = _context.sent;
629
+ this._performanceData.push({
630
+ key: 'sdk_render_component',
631
+ value: Date.now()
632
+ });
633
+ this.dispatchToApp({
634
+ context: {
635
+ event: 'renderComponent',
636
+ data: {
637
+ queryResult: res,
638
+ sessionResult: (_this$_renderParams = this._renderParams) === null || _this$_renderParams === void 0 ? void 0 : _this$_renderParams.paymentSessionMetaData,
639
+ paymentSessionData: (_this$_renderParams2 = this._renderParams) === null || _this$_renderParams2 === void 0 ? void 0 : _this$_renderParams2.paymentSessionData,
640
+ heightOfVisible: Math.max(innerHeight, window.innerHeight),
641
+ envInfo: {
642
+ screenHeight: screen.height,
643
+ screenWidth: screen.width
644
+ }
645
+ }
646
+ }
647
+ });
648
+ this.dispatchToApp({
649
+ context: {
650
+ event: 'web-sdk-performance',
651
+ data: {
652
+ performanceData: this._performanceData
653
+ }
654
+ }
655
+ });
656
+ // eslint-disable-next-line no-empty
657
+ _context.next = 13;
658
+ break;
659
+ case 11:
660
+ _context.prev = 11;
661
+ _context.t0 = _context["catch"](0);
662
+ case 13:
663
+ case "end":
664
+ return _context.stop();
665
+ }
666
+ }, _callee, this, [[0, 11]]);
667
+ }));
668
+ function sendRenderEvent() {
669
+ return _sendRenderEvent.apply(this, arguments);
670
+ }
671
+ return sendRenderEvent;
672
+ }()
673
+ }, {
674
+ key: "showLoading",
675
+ value: function showLoading() {
676
+ var loading = document.createElement('div');
677
+ loading === null || loading === void 0 ? void 0 : loading.classList.add(loadingId);
678
+ loading.id = loadingId;
679
+ loading.innerHTML = '<div class="line"><div></div><div></div><div></div><div></div></div>';
680
+ loading.style.fontSize = "".concat(getDesignFontSize(), "px");
681
+ var body = document.getElementsByTagName('body')[0];
682
+ body === null || body === void 0 ? void 0 : body.appendChild(loading);
683
+ }
684
+
685
+ /**
686
+ * @description show cashier
687
+ */
688
+ }, {
689
+ key: "showCashier",
690
+ value: function showCashier() {
691
+ var cashier = document.getElementById('ams-component-container');
692
+ cashier === null || cashier === void 0 ? void 0 : cashier.classList.remove("ams-component-container-hidden-".concat(this.platform));
693
+ cashier === null || cashier === void 0 ? void 0 : cashier.classList.add("ams-component-container-".concat(this.platform));
694
+ }
695
+
696
+ /**
697
+ * @description close cashier
698
+ */
699
+ }, {
700
+ key: "closeCashier",
701
+ value: function closeCashier() {
702
+ var _document$getElementB2;
703
+ var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
704
+ this._performanceData = [];
705
+ this._isInitComponent = false;
706
+ (_document$getElementB2 = document.getElementById(loadingId)) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.remove();
707
+ this.hideComponentAndCleanDom(immediately);
708
+ }
709
+ }, {
710
+ key: "hideComponentAndCleanDom",
711
+ value: function hideComponentAndCleanDom() {
712
+ var _this4 = this;
713
+ var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
714
+ var container = document.getElementById('ams-component-container');
715
+ // size变化动画取消
716
+ container.style.transition = '';
717
+ container === null || container === void 0 ? void 0 : container.classList.remove("ams-component-container-".concat(this.platform));
718
+ container === null || container === void 0 ? void 0 : container.classList.remove("ams-component-container-".concat(this.platform, "-animation"));
719
+ container === null || container === void 0 ? void 0 : container.classList.add("ams-component-container-hidden-".concat(this.platform));
720
+ var removeMockupAndApp = function removeMockupAndApp() {
721
+ var _document$getElementB3;
722
+ var body = document.getElementsByTagName('body')[0];
723
+ body.style.overflow = 'auto';
724
+ var mockup = document.getElementById(mockupId);
725
+ mockup === null || mockup === void 0 ? void 0 : mockup.remove();
726
+ if (container) container.style.height = '';
727
+ (_document$getElementB3 = document.getElementById('ams-component-container-mobile-animation-style')) === null || _document$getElementB3 === void 0 ? void 0 : _document$getElementB3.remove();
728
+ _this4.removeRetentionPopup();
729
+ _this4.cleanApp();
730
+ };
731
+ if (immediately) removeMockupAndApp();else {
732
+ setTimeout(function () {
733
+ removeMockupAndApp();
734
+ }, 300);
735
+ }
736
+ }
737
+ }, {
738
+ key: "closeBtnFunc",
739
+ value: function closeBtnFunc() {
740
+ // element && element.removeEventListener()
741
+ if (this._isRetention) this.showRetentionPopup();else {
742
+ this.closeCashier();
743
+ this.dispatchToSDK(EVENT.onClose.name, {});
744
+ }
745
+ }
746
+
747
+ /**
748
+ * @description create mount node
749
+ */
750
+ }, {
751
+ key: "createMountElement",
752
+ value: function createMountElement() {
753
+ componentAddCSS();
754
+ var amsComponentContainer = document.createElement('div');
755
+ amsComponentContainer.className = "ams-component-container-hidden-".concat(this.platform);
756
+ amsComponentContainer.id = 'ams-component-container';
757
+ amsSetSize(null, amsComponentContainer);
758
+ document.body.appendChild(amsComponentContainer);
759
+ var amsComponentSection = document.createElement('div');
760
+ amsComponentSection.className = "ams-component-section-".concat(this.platform);
761
+ amsComponentSection.id = this._selector.slice(1);
762
+ amsComponentContainer.appendChild(amsComponentSection);
763
+ this.createCloseBtn();
764
+ }
765
+ }, {
766
+ key: "createCloseBtn",
767
+ value: function createCloseBtn() {
768
+ var _this5 = this;
769
+ var container = document.getElementById('ams-component-container');
770
+ // close btn
771
+ var closeBtnHTML = "<img class='asm-component-close-btn-".concat(this.platform, "' src=\"https://cdn.marmot-cloud.com/storage/2023/5/18/1692a487-99b5-4314-9d6f-e9814bc1ca41.svg\"/>");
772
+ var closeBlock = document.createElement('div');
773
+ closeBlock.classList.add("asm-component-close-block-".concat(this.platform), 'asm-component-close-block-hidden');
774
+ closeBlock.id = 'asm-component-section-close-block';
775
+ closeBlock.innerHTML = closeBtnHTML;
776
+ closeBlock.addEventListener(this._clickEventName, function () {
777
+ _this5.closeBtnFunc();
778
+ });
779
+ if (container) container.appendChild(closeBlock);
780
+ }
781
+ }, {
782
+ key: "createRetentionPopup",
783
+ value: function createRetentionPopup() {
784
+ // retention popup
785
+ var retentionPopup = document.createElement('div');
786
+ retentionPopup.id = 'ams-component-retention';
787
+ retentionPopup.classList.add("ams-component-retention-".concat(this.platform));
788
+ retentionPopup.innerHTML = "\n <span id=\"ams-component-retention-title\" class=\"ams-component-retention-title-".concat(this.platform, "\">\n Are you sure you want to leave?\n </span>\n <span\n id=\"ams-component-retention-sub-title\"\n class=\"ams-component-retention-sub-title-").concat(this.platform, "\"\n >\n If you leave this page, you'll have to start over again.\n </span>\n <div class=\"ams-component-retention-btn-block-").concat(this.platform, "\">\n <div id=\"ams-component-retention-remain\" class=\"ams-component-retention-remain-").concat(this.platform, "\">\n Continue Payment\n </div>\n <div id=\"ams-component-retention-leave\" class=\"ams-component-retention-leave-").concat(this.platform, "\">\n Leave\n </div>\n </div>");
789
+ document.body.appendChild(retentionPopup);
790
+ var remainBtn = document.getElementById('ams-component-retention-remain');
791
+ if (remainBtn) {
792
+ remainBtn.addEventListener(this._clickEventName, this.hideRetentionPopup.bind(this));
793
+ }
794
+ var leaveBtn = document.getElementById('ams-component-retention-leave');
795
+ if (leaveBtn) {
796
+ leaveBtn.addEventListener(this._clickEventName, this.retentionPopupLeaveFunc.bind(this));
797
+ }
798
+ }
799
+ }, {
800
+ key: "retentionPopupLeaveFunc",
801
+ value: function retentionPopupLeaveFunc() {
802
+ this.dispatchToSDK(EVENT.onClose.name, {});
803
+ this.hideRetentionPopup();
804
+ this.closeCashier();
805
+ }
806
+ }, {
807
+ key: "removeRetentionPopup",
808
+ value: function removeRetentionPopup() {
809
+ var _document$getElementB4;
810
+ var remainBtn = document.getElementById('ams-component-retention-remain');
811
+ if (remainBtn) {
812
+ remainBtn.removeEventListener(this._clickEventName, this.hideRetentionPopup);
813
+ }
814
+ var leaveBtn = document.getElementById('ams-component-retention-leave');
815
+ if (leaveBtn) {
816
+ leaveBtn.removeEventListener(this._clickEventName, this.retentionPopupLeaveFunc);
817
+ }
818
+ (_document$getElementB4 = document.getElementById('ams-component-retention')) === null || _document$getElementB4 === void 0 ? void 0 : _document$getElementB4.remove();
819
+ }
820
+ }, {
821
+ key: "showRetentionPopup",
822
+ value: function showRetentionPopup() {
823
+ var retentionPopup = document.getElementById('ams-component-retention');
824
+ var container = document.getElementById('ams-component-container');
825
+ if (retentionPopup) {
826
+ container === null || container === void 0 ? void 0 : container.classList.add('ams-component-container-opacity');
827
+ retentionPopup.classList.remove('ams-component-retention-hidden');
828
+ retentionPopup.classList.add('ams-component-retention-show');
829
+ }
830
+ }
831
+ }, {
832
+ key: "hideRetentionPopup",
833
+ value: function hideRetentionPopup() {
834
+ var retentionPopup = document.getElementById('ams-component-retention');
835
+ var container = document.getElementById('ams-component-container');
836
+ if (retentionPopup) {
837
+ retentionPopup.classList.remove('ams-component-retention-show');
838
+ retentionPopup.classList.add('ams-component-retention-hidden');
839
+ setTimeout(function () {
840
+ retentionPopup.classList.remove('ams-component-retention-hidden');
841
+ container === null || container === void 0 ? void 0 : container.classList.remove('ams-component-container-opacity');
842
+ }, 250);
843
+ }
844
+ }
845
+ /**
846
+ * @description create mockup
847
+ */
848
+ }, {
849
+ key: "createMockup",
850
+ value: function createMockup() {
851
+ var body = document.getElementsByTagName('body')[0];
852
+ body.style.overflow = 'hidden';
853
+ var mockup = document.createElement('div');
854
+ mockup.style.width = '100vw';
855
+ mockup.style.height = '100vh';
856
+ mockup.style.position = 'fixed';
857
+ mockup.style.top = '0';
858
+ mockup.style.left = '0';
859
+ mockup.style.zIndex = '1000';
860
+ mockup.style.background = '#ffffff';
861
+ mockup.style.opacity = '0.5';
862
+ mockup.style.display = 'none';
863
+ mockup.id = mockupId;
864
+ body.appendChild(mockup);
865
+ }
866
+ }, {
867
+ key: "submitForm",
868
+ value: function submitForm(data) {
869
+ var attributes = data.attributes;
870
+ var _document = document,
871
+ body = _document.body;
872
+ var form = document.createElement('form');
873
+ form.setAttribute('height', '1');
874
+ form.setAttribute('width', '1');
875
+ Object.keys(attributes.data).forEach(function (key) {
876
+ var input = document.createElement('input');
877
+ input.setAttribute('type', 'hidden');
878
+ input.setAttribute('name', key);
879
+ input.setAttribute('value', attributes.data[key]);
880
+ form.appendChild(input);
881
+ });
882
+ form.setAttribute('action', attributes.action);
883
+ form.setAttribute('method', 'post');
884
+ body.appendChild(form);
885
+ this.closeCashier(true);
886
+ setTimeout(function () {
887
+ form.submit();
888
+ }, 0);
889
+ }
890
+ }]);
891
+ return ComponentApp;
892
+ }();
893
+ export { ComponentApp as default };