@alipay/ams-checkout 0.0.1720509876-dev.2 → 0.0.1723203704-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/request.js +3 -3
  3. package/esm/constant/index.d.ts +10 -1
  4. package/esm/constant/index.js +9 -0
  5. package/esm/core/component/address.d.ts +34 -0
  6. package/esm/core/component/address.js +298 -0
  7. package/esm/core/component/appPreloadProcessing.d.ts +1 -0
  8. package/esm/core/component/appPreloadProcessing.js +89 -0
  9. package/esm/core/component/index.d.ts +1 -1
  10. package/esm/core/component/index.js +39 -14
  11. package/esm/core/instance/address.d.ts +76 -0
  12. package/esm/core/instance/address.js +283 -0
  13. package/esm/index.d.ts +12 -1
  14. package/esm/index.js +57 -19
  15. package/esm/plugin/address/cashierApp.d.ts +34 -0
  16. package/esm/plugin/address/cashierApp.js +218 -0
  17. package/esm/plugin/address/channel.d.ts +20 -0
  18. package/esm/plugin/address/channel.js +52 -0
  19. package/esm/plugin/address/component.inline.style.d.ts +11 -0
  20. package/esm/plugin/address/component.inline.style.js +38 -0
  21. package/esm/plugin/address/component.popup.style.d.ts +16 -0
  22. package/esm/plugin/address/component.popup.style.js +174 -0
  23. package/esm/plugin/address/index.d.ts +108 -0
  24. package/esm/plugin/address/index.js +860 -0
  25. package/esm/plugin/address/popupWindow.style.d.ts +8 -0
  26. package/esm/plugin/address/popupWindow.style.js +65 -0
  27. package/esm/plugin/component/cashierApp.js +9 -5
  28. package/esm/plugin/component/component.inline.style.d.ts +8 -9
  29. package/esm/plugin/component/component.inline.style.js +87 -6
  30. package/esm/plugin/component/index.js +49 -25
  31. package/esm/plugin/component/popupWindow.style.d.ts +5 -2
  32. package/esm/plugin/component/popupWindow.style.js +55 -7
  33. package/esm/plugin/type.d.ts +1 -0
  34. package/esm/types/address.d.ts +92 -0
  35. package/esm/types/address.js +7 -0
  36. package/esm/types/index.d.ts +13 -3
  37. package/esm/types/index.js +5 -0
  38. package/esm/util/index.d.ts +7 -1
  39. package/esm/util/index.js +67 -1
  40. package/esm/util/upgrade.d.ts +4 -4
  41. package/esm/util/upgrade.js +6 -6
  42. package/package.json +1 -1
@@ -0,0 +1,860 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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 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; }
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ 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); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ 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; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ /**
12
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
+ * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
15
+ * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
16
+ */
17
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+ import { sdkVersion } from "../../config";
19
+ import { COMPONENTPLUGINID, COMPONENT_CONTAINER_ID, COMPONENT_RETENTION_ID, COMPONENT_SECTION_ID, ERRORMESSAGE, EVENT, LISTENER_PREFIX, LOADING_ID, LOADTIME_LIMIT, MOCKUP_ID, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../constant";
20
+ import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
21
+ import { getType, isJsonString, isPC } from "../../util";
22
+ import { createIframe, createPreloadIframe, getAppDomain, getIframeUrl } from "./cashierApp";
23
+ import { addInlineLoading, createInlineBaseElement } from "./component.inline.style";
24
+ import { addPopupLoading, createBaseElement, createRetentionPopup, hideRetentionPopup, removeRetentionPopup as _removeRetentionPopup, slideInAndOutKeyframes } from "./component.popup.style";
25
+ import { insertStyleSheet } from "./popupWindow.style";
26
+ window.changingPageHeight = window.innerHeight;
27
+ var ComponentApp = /*#__PURE__*/function () {
28
+ function ComponentApp() {
29
+ _classCallCheck(this, ComponentApp);
30
+ _defineProperty(this, "app", void 0);
31
+ _defineProperty(this, "AMSSDK", void 0);
32
+ _defineProperty(this, "platform", void 0);
33
+ _defineProperty(this, "_performanceData", []);
34
+ _defineProperty(this, "_loadAppPromiseResolve", null);
35
+ _defineProperty(this, "_isInitComponent", void 0);
36
+ _defineProperty(this, "_globalData", void 0);
37
+ _defineProperty(this, "popupApp", void 0);
38
+ _defineProperty(this, "appDomain", void 0);
39
+ _defineProperty(this, "createIframeNode", void 0);
40
+ _defineProperty(this, "createPreloadIframeNode", void 0);
41
+ _defineProperty(this, "_selector", void 0);
42
+ _defineProperty(this, "_appVersion", void 0);
43
+ _defineProperty(this, "_isRetention", void 0);
44
+ _defineProperty(this, "_allowSubmitPayCallAhead", void 0);
45
+ _defineProperty(this, "_actionQueryPromise", null);
46
+ _defineProperty(this, "_actionSubmitPromise", null);
47
+ _defineProperty(this, "_renderParams", null);
48
+ _defineProperty(this, "_componentSign", componentSignEnum.NONE);
49
+ _defineProperty(this, "_appLocationSearch", void 0);
50
+ _defineProperty(this, "_renderDisplayType", renderDisplayTypeEnum.popup);
51
+ _defineProperty(this, "_multipleCallbackEvents", void 0);
52
+ _defineProperty(this, "_merchantAppointParam", void 0);
53
+ _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
54
+ this._appVersion = '1.19.0';
55
+ this._isInitComponent = false;
56
+ this._selector = "#".concat(COMPONENT_SECTION_ID);
57
+ this.createIframeNode = function () {
58
+ return Promise.resolve();
59
+ };
60
+ this.createPreloadIframeNode = function () {
61
+ return Promise.resolve();
62
+ };
63
+ this.platform = isPC() ? platformEnum.desktop : platformEnum.mobile;
64
+ this._isRetention = true;
65
+ this._appLocationSearch = '';
66
+ this._performanceData.push({
67
+ key: 'sdk_init',
68
+ value: Date.now()
69
+ });
70
+ this._globalData = new Map();
71
+ }
72
+
73
+ /**
74
+ * @description Cancel listening and destroy the dom
75
+ */
76
+ _createClass(ComponentApp, [{
77
+ key: "logoutPlugin",
78
+ value: function logoutPlugin() {
79
+ this.cleanContainer(true);
80
+ }
81
+
82
+ /**
83
+ * @description When SDK registers plug-ins, it is a required function to receive SDK instances
84
+ */
85
+ }, {
86
+ key: "applyPlugin",
87
+ value: function applyPlugin(AMSSDK) {
88
+ this.AMSSDK = AMSSDK;
89
+ this.subscribeFromSDK();
90
+ }
91
+ }, {
92
+ key: "initLoggerMeta",
93
+ value: function initLoggerMeta() {
94
+ this.AMSSDK.logger.setMedta({
95
+ platform: this.platform === platformEnum.desktop ? 'PC' : 'WAP',
96
+ // PC/WAP,
97
+ sdkVersion: sdkVersion,
98
+ webAppVersion: this._appVersion,
99
+ instanceId: this.AMSSDK._instanceId,
100
+ storageId: this.AMSSDK._storageId // the better way to use md5 paymentSesionID
101
+ });
102
+ }
103
+
104
+ /**
105
+ * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
106
+ */
107
+ }, {
108
+ key: "setRender",
109
+ value: function setRender(renderFunc) {
110
+ this.createIframeNode = renderFunc;
111
+ }
112
+ }, {
113
+ key: "setPreloadRender",
114
+ value: function setPreloadRender(renderFunc) {
115
+ this.createPreloadIframeNode = renderFunc;
116
+ }
117
+ }, {
118
+ key: "initSecurity",
119
+ value: function initSecurity() {
120
+ var _this = this;
121
+ var product = productSceneEnum.ELEMENT_ADDRESS;
122
+ if (componentSignEnum.ELEMENT_ADDRESS === this._componentSign) return;
123
+ var securitySDK = this.AMSSDK._getSecuritySDKByProductScene({
124
+ product: product
125
+ });
126
+ if (!securitySDK) {
127
+ this.AMSSDK.logger.logInfo({
128
+ title: 'sdk_event_securitySdkInit'
129
+ });
130
+ this.AMSSDK._newSecuritySDKByScene({
131
+ product: product
132
+ }, function () {
133
+ _this.AMSSDK.logger.logInfo({
134
+ title: 'sdk_event_securitySdkInitSuccess'
135
+ });
136
+ }, function () {
137
+ _this.AMSSDK.logger.logError({
138
+ title: 'sdk_error_securitySdkInitFailed'
139
+ }, {
140
+ sign: 'SDK internal initialization'
141
+ });
142
+ });
143
+ }
144
+ }
145
+ }, {
146
+ key: "getDeviceIdAndLog",
147
+ value: function getDeviceIdAndLog() {
148
+ var _this2 = this;
149
+ var deviceIdParameter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
150
+ var isPolling = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
151
+ return new Promise(function (resolve) {
152
+ // To avoid rendering being blocked, move the logic to the next event loop for processing
153
+ setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
154
+ var getDeviceIdStartTime, securitySDK, deviceId;
155
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
156
+ while (1) switch (_context.prev = _context.next) {
157
+ case 0:
158
+ getDeviceIdStartTime = Date.now();
159
+ securitySDK = _this2.AMSSDK._getSecuritySDKByProductScene({
160
+ product: productSceneEnum.ELEMENT_ADDRESS
161
+ });
162
+ deviceId = '';
163
+ if (!securitySDK) {
164
+ _context.next = 15;
165
+ break;
166
+ }
167
+ if (!(isPolling && parseInt(deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.tokenCollectTime) > 0)) {
168
+ _context.next = 10;
169
+ break;
170
+ }
171
+ _context.next = 7;
172
+ return securitySDK.pollingGetApdidToken(deviceIdParameter);
173
+ case 7:
174
+ _context.t0 = _context.sent;
175
+ _context.next = 13;
176
+ break;
177
+ case 10:
178
+ _context.next = 12;
179
+ return securitySDK.getApdidToken();
180
+ case 12:
181
+ _context.t0 = _context.sent;
182
+ case 13:
183
+ deviceId = _context.t0;
184
+ _this2.logDeviceId(deviceId, getDeviceIdStartTime);
185
+ case 15:
186
+ resolve(deviceId);
187
+ case 16:
188
+ case "end":
189
+ return _context.stop();
190
+ }
191
+ }, _callee);
192
+ })), 0);
193
+ });
194
+ }
195
+ }, {
196
+ key: "logDeviceId",
197
+ value: function logDeviceId(deviceId, getDeviceIdStartTime) {
198
+ var time = "".concat(Date.now() - getDeviceIdStartTime);
199
+ if (deviceId) {
200
+ this.AMSSDK.logger.logInfo({
201
+ title: 'sdk_event_securitySdkGetTokenSuccess'
202
+ }, {
203
+ deviceId: deviceId,
204
+ time: time
205
+ }).send();
206
+ } else {
207
+ this.AMSSDK.logger.logInfo({
208
+ title: 'sdk_error_securitySdkGetTokenFailed'
209
+ }, {
210
+ deviceId: deviceId,
211
+ time: time
212
+ }).send();
213
+ }
214
+ }
215
+
216
+ /**
217
+ * @description render iframe content
218
+ */
219
+ }, {
220
+ key: "appendIframeNodes",
221
+ value: function appendIframeNodes(componentSign, renderParams) {
222
+ var _this3 = this;
223
+ if (this._isInitComponent) {
224
+ this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
225
+ return Promise.reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.SINGLETON_COMPONENT_ERROR);
226
+ }
227
+ this._isInitComponent = true;
228
+ this._renderParams = renderParams;
229
+ this._componentSign = componentSign;
230
+ if (renderParams !== null && renderParams !== void 0 && renderParams.selector) this._selector = renderParams.selector;
231
+ this._renderDisplayType = renderParams.renderDisplayType;
232
+ var insertedNode = this._renderDisplayType === renderDisplayTypeEnum.inline ? "#".concat(COMPONENT_CONTAINER_ID) : this._selector;
233
+ this.initLoggerMeta();
234
+ this.initSecurity();
235
+ this._performanceData.push({
236
+ key: 'sdk_create_component',
237
+ value: Date.now()
238
+ });
239
+ this.AMSSDK.logger.logInfo({
240
+ title: 'sdk_event_createComponent'
241
+ }, {
242
+ product: productSceneEnum.ELEMENT_ADDRESS
243
+ }).send();
244
+ this.dispatchToSDK(EVENT.eventCallback.name, {
245
+ code: eventCodeEnum.SDK_START_OF_LOADING
246
+ });
247
+ if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
248
+ var container = createInlineBaseElement(this._selector);
249
+ if (container) this.renderInlineLoading(renderParams, container);
250
+ insertStyleSheet();
251
+ }
252
+ if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
253
+ createBaseElement(this.platform, this.closeBtnFunc.bind(this));
254
+ createRetentionPopup(this.platform, this.hideRetentionPopupFunc.bind(this), this.retentionPopupLeaveFunc.bind(this));
255
+ this.renderPopupLoading(renderParams);
256
+ }
257
+ this.createApp(renderParams);
258
+ return Promise.all([this.createIframeNode(this, insertedNode, this._renderDisplayType), this._createLoadAppPromise()]).then(function () {
259
+ return Promise.resolve();
260
+ }).catch(function (error) {
261
+ _this3.AMSSDK.logger.logError({
262
+ title: 'sdk_error_created_app_process_failed'
263
+ }).send();
264
+ _this3._isInitComponent = false;
265
+ _this3.cleanContainer();
266
+ return Promise.reject(error);
267
+ });
268
+ }
269
+ }, {
270
+ key: "showRetentionPopup",
271
+ value: function showRetentionPopup() {
272
+ var retentionPopup = document.getElementById(COMPONENT_RETENTION_ID);
273
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
274
+ if (retentionPopup) {
275
+ container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-opacity"));
276
+ retentionPopup.classList.remove("".concat(COMPONENT_RETENTION_ID, "-hidden"));
277
+ retentionPopup.classList.add("".concat(COMPONENT_RETENTION_ID, "-show"));
278
+ }
279
+ }
280
+ }, {
281
+ key: "closeBtnFunc",
282
+ value: function closeBtnFunc() {
283
+ // element && element.removeEventListener()
284
+ if (this._isRetention) this.showRetentionPopup();else {
285
+ this.cleanContainer();
286
+ this.dispatchToSDK(EVENT.close.name, {});
287
+ this.handleDeclarePopWindowCallback();
288
+ }
289
+ }
290
+ }, {
291
+ key: "appendPreloadIframeNodes",
292
+ value: function appendPreloadIframeNodes(componentSign, productSceneVersion) {
293
+ var virtualPreloadIframe = this.createPreloadApp(componentSign, productSceneVersion);
294
+ this.createPreloadIframeNode(virtualPreloadIframe);
295
+ this.AMSSDK.logger.logInfo({
296
+ title: 'performance_optimization_preload'
297
+ }, {
298
+ componentSign: componentSign,
299
+ productSceneVersion: productSceneVersion
300
+ });
301
+ }
302
+ }, {
303
+ key: "renderInlineLoading",
304
+ value: function renderInlineLoading(renderParams, selector) {
305
+ var _renderParams$appeara;
306
+ var showLoading = renderParams === null || renderParams === void 0 || (_renderParams$appeara = renderParams.appearance) === null || _renderParams$appeara === void 0 ? void 0 : _renderParams$appeara.showLoading;
307
+ showLoading = typeof showLoading === 'boolean' ? showLoading : true;
308
+ if (showLoading) addInlineLoading(selector, this.platform);
309
+ }
310
+ }, {
311
+ key: "renderPopupLoading",
312
+ value: function renderPopupLoading(renderParams) {
313
+ var _renderParams$appeara2;
314
+ var showLoading = renderParams === null || renderParams === void 0 || (_renderParams$appeara2 = renderParams.appearance) === null || _renderParams$appeara2 === void 0 ? void 0 : _renderParams$appeara2.showLoading;
315
+ showLoading = typeof showLoading === 'boolean' ? showLoading : true;
316
+ if (!showLoading) return;
317
+ var mockup = document.getElementById(MOCKUP_ID);
318
+ if (mockup) mockup.style.display = 'block';
319
+ addPopupLoading();
320
+ }
321
+ }, {
322
+ key: "_createLoadAppPromise",
323
+ value: function _createLoadAppPromise(loadTimeLimit) {
324
+ var _this4 = this;
325
+ return new Promise(function (resolve, reject) {
326
+ _this4._loadAppPromiseResolve = resolve;
327
+ setTimeout(function () {
328
+ reject(ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
329
+ }, loadTimeLimit !== null && loadTimeLimit !== void 0 ? loadTimeLimit : LOADTIME_LIMIT);
330
+ }).catch(function (error) {
331
+ _this4.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
332
+ _this4.AMSSDK.logger.logError({
333
+ title: 'sdk_error_web_app_timeout'
334
+ }).send();
335
+ return Promise.reject(error);
336
+ });
337
+ }
338
+ }, {
339
+ key: "cleanElement",
340
+ value: function cleanElement() {
341
+ try {
342
+ var _document$getElementB;
343
+ // selector and container
344
+ if (getType(this._selector) === 'string') {
345
+ var selectorDom = document.querySelector(this._selector);
346
+ if (selectorDom) selectorDom.innerHTML = '';
347
+ }
348
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
349
+ if (container) container === null || container === void 0 || container.remove();
350
+
351
+ // animation
352
+ (_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style"))) === null || _document$getElementB === void 0 || _document$getElementB.remove();
353
+
354
+ // mockup
355
+ var body = document.getElementsByTagName('body')[0];
356
+ body.style.overflow = 'auto';
357
+ var mockup = document.getElementById(MOCKUP_ID);
358
+ mockup === null || mockup === void 0 || mockup.remove();
359
+
360
+ // retentionPopup
361
+ this.removeRetentionPopup(this.platform);
362
+
363
+ // listener
364
+ this.removeEventListener();
365
+ } catch (error) {
366
+ console.error(error);
367
+ }
368
+ }
369
+ }, {
370
+ key: "removeRetentionPopup",
371
+ value: function removeRetentionPopup(platform) {
372
+ _removeRetentionPopup(platform, this.hideRetentionPopupFunc.bind(this), this.retentionPopupLeaveFunc.bind(this));
373
+ }
374
+ }, {
375
+ key: "hideRetentionPopupFunc",
376
+ value: function hideRetentionPopupFunc() {
377
+ hideRetentionPopup();
378
+ }
379
+ }, {
380
+ key: "retentionPopupLeaveFunc",
381
+ value: function retentionPopupLeaveFunc() {
382
+ this.dispatchToSDK(EVENT.close.name, {});
383
+ this.hideRetentionPopupFunc();
384
+ this.cleanContainer();
385
+ this.handleDeclarePopWindowCallback();
386
+ }
387
+ }, {
388
+ key: "handleDeclarePopWindowCallback",
389
+ value: function handleDeclarePopWindowCallback() {
390
+ var eventInfoName = 'popWindowEventInfo';
391
+ if (this._multipleCallbackEvents && eventInfoName in this._multipleCallbackEvents) {
392
+ var eventInfo = this._multipleCallbackEvents[eventInfoName];
393
+ if (eventInfo.enableCallback) {
394
+ this.dispatchToSDK(EVENT.eventCallback.name, {
395
+ code: eventInfo.eventName,
396
+ result: {
397
+ result: eventInfo.eventResult || {}
398
+ }
399
+ });
400
+ }
401
+ } else {
402
+ console.log("not valid ".concat(eventInfoName, " in "), this._multipleCallbackEvents);
403
+ }
404
+ }
405
+
406
+ // 预加载iframe创建
407
+ }, {
408
+ key: "createPreloadApp",
409
+ value: function createPreloadApp(componentSign) {
410
+ var productSceneVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1.0';
411
+ var preloadIframe = createPreloadIframe(componentSign, productSceneVersion);
412
+ var _getIframeUrl = getIframeUrl({
413
+ renderDisplayType: renderDisplayTypeEnum.popup,
414
+ componentSign: componentSign,
415
+ analytics: {
416
+ enabled: false
417
+ },
418
+ productScene: componentSign,
419
+ productSceneVersion: productSceneVersion,
420
+ environment: this.AMSSDK.options.env.environment,
421
+ appVersion: this._appVersion,
422
+ instanceId: '',
423
+ isPreload: 'true'
424
+ }),
425
+ path = _getIframeUrl.path,
426
+ locationSearch = _getIframeUrl.locationSearch;
427
+ preloadIframe.src = "".concat(path, "?").concat(locationSearch);
428
+ if (!path) {
429
+ this.AMSSDK.logger.logError({
430
+ title: 'performance_optimization_preload_path_error'
431
+ }, {
432
+ path: path,
433
+ locationSearch: locationSearch
434
+ });
435
+ }
436
+ return preloadIframe;
437
+ }
438
+ /**
439
+ * @description Create app
440
+ */
441
+ }, {
442
+ key: "createApp",
443
+ value: function createApp(renderParams) {
444
+ if (!!window.postMessage !== true) {
445
+ this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE);
446
+ return;
447
+ }
448
+ this._performanceData.push({
449
+ key: 'sdk_popup_start',
450
+ value: Date.now()
451
+ });
452
+ try {
453
+ var productSceneVersion = '';
454
+ var productScene = '';
455
+ var extendInfo = '';
456
+ var mid = '';
457
+ var environment = this.AMSSDK.options.env.environment;
458
+ this.appDomain = getAppDomain({
459
+ environment: environment,
460
+ appVersion: this._appVersion,
461
+ componentSign: this._componentSign,
462
+ productScene: productScene,
463
+ productSceneVersion: productSceneVersion,
464
+ extendInfo: extendInfo,
465
+ mid: mid
466
+ });
467
+ // TODO: 暂时写死本地调试
468
+ this.appDomain = 'http://30.98.176.105:5173';
469
+ this.app = createIframe(this.AMSSDK.options.mode, this.platform);
470
+ // const hostSign = (renderParams?.sessionData || '').split('&&')[1] || '';
471
+ var _getIframeUrl2 = getIframeUrl({
472
+ renderDisplayType: renderParams.renderDisplayType,
473
+ componentSign: this._componentSign,
474
+ analytics: this.AMSSDK.options.analytics,
475
+ productScene: productScene,
476
+ productSceneVersion: productSceneVersion,
477
+ environment: environment,
478
+ appVersion: this._appVersion,
479
+ extendInfo: extendInfo,
480
+ locale: this.AMSSDK.options.locale,
481
+ instanceId: this.AMSSDK._instanceId,
482
+ // hostSign,
483
+ mid: mid
484
+ }),
485
+ path = _getIframeUrl2.path,
486
+ locationSearch = _getIframeUrl2.locationSearch;
487
+ // TODO: 暂时写死本地调试
488
+ path = 'http://30.98.176.105:5173/address/src/pages/address/index.html';
489
+ this._appLocationSearch = locationSearch;
490
+ // locationSearch 是一个序列化好的字符串
491
+ // 先判断path 是否有QueryParams,如果有需要扩展,否则直接拼?xx=xx
492
+ if (path.indexOf('?') !== -1) {
493
+ this.app.src = "".concat(path, "&").concat(locationSearch);
494
+ } else {
495
+ this.app.src = "".concat(path, "?").concat(locationSearch);
496
+ }
497
+ // Subscribe to messages from iframe
498
+ this.addEventListener();
499
+ } catch (error) {
500
+ this.AMSSDK.logger.logError({
501
+ title: 'sdk_error_created_app_failed'
502
+ }).send();
503
+ this.dispatchToSDK(EVENT.error.name, Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
504
+ stack: error
505
+ }));
506
+ }
507
+ }
508
+ }, {
509
+ key: "listener",
510
+ value: function listener(e) {
511
+ var _e$data;
512
+ if (e.origin !== this.appDomain) return;
513
+ if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.source) === 'react-devtools-content-script') {
514
+ // 防止 react 开发工具发的消息,非常频繁影响查看日志
515
+ return;
516
+ }
517
+ var isJson = isJsonString(e.data);
518
+ if (isJson) {
519
+ var data = JSON.parse(e.data);
520
+ if (data.name !== messageName.APP_TO_SDK && data.name !== messageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) return;
521
+ this._handleAppMessage(data);
522
+ } else {
523
+ console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
524
+ this.dispatchToSDK(EVENT.error.name, ERRORMESSAGE.NOT_JSON_FORMAT);
525
+ }
526
+ }
527
+ }, {
528
+ key: "resizeListener",
529
+ value: function resizeListener(e) {
530
+ var _e$target, _e$target2;
531
+ var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
532
+ cashier.style.transition = 'none';
533
+ this.dispatchToApp({
534
+ context: {
535
+ event: 'renderResize',
536
+ data: {
537
+ heightOfVisible: (e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.innerHeight) || window.innerHeight,
538
+ widthOfVisible: (e === null || e === void 0 || (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : _e$target2.innerWidth) || window.innerWidth
539
+ }
540
+ }
541
+ });
542
+ }
543
+
544
+ /**
545
+ * @description Initialize subscription iframe message
546
+ */
547
+ }, {
548
+ key: "addEventListener",
549
+ value: function addEventListener() {
550
+ console.log('进行了监听898989', this.AMSSDK._instanceId);
551
+ this.removeEventListener();
552
+ window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)] = this.listener.bind(this);
553
+ window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")] = this.resizeListener.bind(this);
554
+ window.addEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
555
+ window.addEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
556
+ }
557
+ }, {
558
+ key: "removeEventListener",
559
+ value: function removeEventListener() {
560
+ window.removeEventListener('message', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId)]);
561
+ window.removeEventListener('resize', window["".concat(LISTENER_PREFIX, "_").concat(this.AMSSDK._instanceId, "_resize")]);
562
+ }
563
+
564
+ /**
565
+ * @description Processing messages from iframe
566
+ */
567
+ }, {
568
+ key: "_handleAppMessage",
569
+ value: function _handleAppMessage(data) {
570
+ var eventKeyMap = Object.keys(EVENT).map(function (key) {
571
+ return EVENT[key].name;
572
+ });
573
+ if (!eventKeyMap.includes(data.context.event)) {
574
+ return;
575
+ }
576
+ if (data.context.event === EVENT.launch.name) {
577
+ this._performanceData.push({
578
+ key: 'sdk_onLaunch',
579
+ value: Date.now()
580
+ });
581
+ this.AMSSDK.logger.logInfo({
582
+ title: 'sdk_event_webAppOnLaunch'
583
+ }).send();
584
+ this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
585
+ this.sendRenderEvent();
586
+ return;
587
+ }
588
+ if (data.context.event === EVENT.sizeChanged.name) {
589
+ this.handleSizeChanged(data);
590
+ }
591
+ if (data.context.event === EVENT.appHeartBeat.name) {
592
+ this.handleAppHeartBeat();
593
+ return;
594
+ }
595
+ // The plug-in communicates with the sdk after processing
596
+ this.dispatchToSDK(data.context.event, data.context.data, data.context.eventCallbackId);
597
+ }
598
+ }, {
599
+ key: "dismissLoadingFunc",
600
+ value: function dismissLoadingFunc() {
601
+ var _document$getElementB2;
602
+ var isShowMockup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
603
+ var mockup = document.getElementById(MOCKUP_ID);
604
+ if (mockup) {
605
+ mockup.style.background = 'rgb(0, 0, 0, 0.6)';
606
+ mockup.style.display = isShowMockup ? 'block' : 'none';
607
+ }
608
+ (_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 || _document$getElementB2.remove();
609
+ }
610
+ }, {
611
+ key: "handleSizeChanged",
612
+ value: function handleSizeChanged(data) {
613
+ var _data$context$data;
614
+ console.log(data, 'datadatadatadatadata');
615
+ var cashier = document.getElementById(COMPONENT_CONTAINER_ID);
616
+ if (((_data$context$data = data.context.data) === null || _data$context$data === void 0 ? void 0 : _data$context$data.height) <= 1 || data.context.data.height === parseInt(cashier.style.height)) return;
617
+ cashier.style.height = "".concat(data.context.data.height, "px");
618
+ this.app.style.opacity = '1';
619
+ // alert(this._renderDisplayType)
620
+ if (this._renderDisplayType === renderDisplayTypeEnum.popup) {
621
+ if (this.platform === 'desktop') {
622
+ if (data.context.data.width) cashier.style.width = "".concat(data.context.data.width, "px");
623
+ cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
624
+ this.app.style.height = "".concat(data.context.data.height, "px");
625
+ }
626
+ if (this.platform === 'mobile') {
627
+ cashier.classList.add("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
628
+ var animationStyleId = "".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation-style");
629
+ var animationStyle = document.getElementById(animationStyleId);
630
+ if (animationStyle) animationStyle === null || animationStyle === void 0 || animationStyle.remove();
631
+
632
+ // 此style用于弹窗出现和高度变化时动画,动画不同,属性不同
633
+ this.app.style.height = parseInt(this.app.style.height) > 0 ? '100%' : "".concat(data.context.data.height, "px");
634
+ // 弹出和弹入动画
635
+ var runkeyframes = slideInAndOutKeyframes(COMPONENT_CONTAINER_ID, data.context.data.height);
636
+ // 创建style标签
637
+ var style = document.createElement('style');
638
+ style.id = animationStyleId;
639
+ // 设置style属性
640
+ style.type = 'text/css';
641
+ // 将 keyframes样式写入style内
642
+ style.innerHTML = runkeyframes;
643
+ // 将style样式存放到head标签
644
+ document.getElementsByTagName('head')[0].appendChild(style);
645
+ // size变动时动画
646
+ setTimeout(function () {
647
+ cashier.style.transition = 'height 0.28s ease-in-out';
648
+ }, 500);
649
+ }
650
+ // 关闭loading,保留蒙层
651
+ this.dismissLoadingFunc();
652
+ }
653
+ if (this._renderDisplayType === renderDisplayTypeEnum.inline) {
654
+ var _document$getElementB3;
655
+ (_document$getElementB3 = document.getElementById(LOADING_ID)) === null || _document$getElementB3 === void 0 || _document$getElementB3.remove();
656
+ this.app.style.height = "".concat(data.context.data.height, "px");
657
+ }
658
+ }
659
+ }, {
660
+ key: "handleAppHeartBeat",
661
+ value: function handleAppHeartBeat() {
662
+ var _this5 = this;
663
+ try {
664
+ if (!this._webAppHeartBeatTimeoutFn) {
665
+ this._webAppHeartBeatTimeoutFn = function () {
666
+ if (_this5.isAppAttached()) {
667
+ _this5.AMSSDK.logger.logError({
668
+ title: 'sdk_error_appHeartBeatTimeout'
669
+ });
670
+ }
671
+ };
672
+ }
673
+ if (window._webAppHeartBeatTimeoutId) {
674
+ clearTimeout(window._webAppHeartBeatTimeoutId);
675
+ window._webAppHeartBeatTimeoutId = null;
676
+ }
677
+ if (this._webAppHeartBeatTimeoutFn) {
678
+ window._webAppHeartBeatTimeoutId = setTimeout(this._webAppHeartBeatTimeoutFn, TIMEOUT_WEB_APP_HEART_BEAT);
679
+ }
680
+ setTimeout(function () {
681
+ if (_this5.isAppAttached()) {
682
+ _this5.dispatchToApp({
683
+ context: {
684
+ event: 'sdkHeartBeat',
685
+ data: {}
686
+ }
687
+ });
688
+ }
689
+ }, TIME_DELAY_SEND_HEART_BEAT);
690
+ } catch (error) {
691
+ this.AMSSDK.logger.logError({
692
+ title: 'sdk_error_handleAppHeartBeat'
693
+ }, {
694
+ errorMessage: error.message
695
+ });
696
+ }
697
+ }
698
+ }, {
699
+ key: "isAppAttached",
700
+ value: function isAppAttached() {
701
+ return this.app || this.popupApp;
702
+ }
703
+
704
+ /**
705
+ * @description Send message to SDK
706
+ */
707
+ }, {
708
+ key: "dispatchToSDK",
709
+ value: function dispatchToSDK(event, data, eventCallbackId) {
710
+ this.AMSSDK._eventCenter.emit(event, data);
711
+ if (eventCallbackId) this.AMSSDK._eventCenter.emit(eventCallbackId, data);
712
+ }
713
+
714
+ /**
715
+ * @description Send message to iframe
716
+ */
717
+ }, {
718
+ key: "dispatchToApp",
719
+ value: function dispatchToApp(payload) {
720
+ var targetElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
721
+ var data = Object.assign({}, payload, {
722
+ name: messageName.SDK_TO_APP,
723
+ mode: this.AMSSDK.options.mode,
724
+ appId: COMPONENTPLUGINID,
725
+ instanceId: this.AMSSDK._instanceId
726
+ });
727
+ if (targetElement && targetElement.contentWindow) {
728
+ return targetElement.contentWindow.postMessage(JSON.stringify(data), '*');
729
+ }
730
+ if (this.app || this.popupApp) {
731
+ var _this$app, _this$app2, _this$popupApp, _this$popupApp2;
732
+ (this === null || this === void 0 || (_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.contentWindow) && (this === null || this === void 0 || (_this$app2 = this.app) === null || _this$app2 === void 0 ? void 0 : _this$app2.contentWindow.postMessage(JSON.stringify(data), this.appDomain));
733
+ (this === null || this === void 0 || (_this$popupApp = this.popupApp) === null || _this$popupApp === void 0 ? void 0 : _this$popupApp.contentWindow) && (this === null || this === void 0 || (_this$popupApp2 = this.popupApp) === null || _this$popupApp2 === void 0 ? void 0 : _this$popupApp2.contentWindow.postMessage(JSON.stringify(data), '*'));
734
+ return;
735
+ }
736
+ throw new Error(ERRORMESSAGE.SDK_SUBMIT_ERROR.message);
737
+ }
738
+
739
+ /**
740
+ * @description Subscribe to messages from SDK
741
+ */
742
+ }, {
743
+ key: "subscribeFromSDK",
744
+ value: function subscribeFromSDK() {
745
+ var eventKeyMap = {};
746
+ for (var key in eventKeyMap) {
747
+ // eslint-disable-next-line no-prototype-builtins
748
+ if (eventKeyMap.hasOwnProperty(key)) {
749
+ this.AMSSDK._eventCenter.on("".concat(COMPONENTPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
750
+ }
751
+ }
752
+ console.log(eventKeyMap, 'eventKeyMap');
753
+ }
754
+
755
+ /**
756
+ * @description Send rendering events to iframe
757
+ */
758
+ }, {
759
+ key: "sendRenderEvent",
760
+ value: (function () {
761
+ var _sendRenderEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
762
+ var _this$_renderParams, _this$_renderParams2, _this$_renderParams3, _this$_renderParams4, _this$_renderParams5, _this$AMSSDK$logger, _this$_renderParams6, _this$AMSSDK;
763
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
764
+ while (1) switch (_context2.prev = _context2.next) {
765
+ case 0:
766
+ try {
767
+ this._performanceData.push({
768
+ key: 'sdk_render_component',
769
+ value: Date.now()
770
+ });
771
+ this.dispatchToApp({
772
+ context: {
773
+ event: 'renderComponent',
774
+ data: {
775
+ heightOfVisible: Math.max(window.changingPageHeight, window.innerHeight),
776
+ renderDisplayType: (_this$_renderParams = this._renderParams) === null || _this$_renderParams === void 0 ? void 0 : _this$_renderParams.renderDisplayType,
777
+ appearance: (_this$_renderParams2 = this._renderParams) === null || _this$_renderParams2 === void 0 ? void 0 : _this$_renderParams2.appearance,
778
+ configParams: (_this$_renderParams3 = this._renderParams) === null || _this$_renderParams3 === void 0 ? void 0 : _this$_renderParams3.configParams,
779
+ appId: (_this$_renderParams4 = this._renderParams) === null || _this$_renderParams4 === void 0 ? void 0 : _this$_renderParams4.appId,
780
+ prefillValue: (_this$_renderParams5 = this._renderParams) === null || _this$_renderParams5 === void 0 ? void 0 : _this$_renderParams5.prefillValue,
781
+ envInfo: {
782
+ screenHeight: screen.height,
783
+ screenWidth: screen.width
784
+ },
785
+ logMetaData: {
786
+ platform: this.platform,
787
+ firstLogTime: (_this$AMSSDK$logger = this.AMSSDK.logger) === null || _this$AMSSDK$logger === void 0 ? void 0 : _this$AMSSDK$logger.getComponentStartTime(),
788
+ renderDisplayType: (_this$_renderParams6 = this._renderParams) === null || _this$_renderParams6 === void 0 ? void 0 : _this$_renderParams6.renderDisplayType,
789
+ sdkVersion: this._appVersion,
790
+ instanceId: (_this$AMSSDK = this.AMSSDK) === null || _this$AMSSDK === void 0 ? void 0 : _this$AMSSDK._instanceId,
791
+ performanceData: this._performanceData
792
+ }
793
+ }
794
+ }
795
+ }, null);
796
+ this.AMSSDK.logger.logInfo({
797
+ title: 'sdk_event_renderComponent'
798
+ });
799
+ this.dispatchToApp({
800
+ context: {
801
+ event: 'web-sdk-performance',
802
+ data: {
803
+ performanceData: this._performanceData
804
+ }
805
+ }
806
+ });
807
+ // eslint-disable-next-line no-empty
808
+ } catch (error) {}
809
+ case 1:
810
+ case "end":
811
+ return _context2.stop();
812
+ }
813
+ }, _callee2, this);
814
+ }));
815
+ function sendRenderEvent() {
816
+ return _sendRenderEvent.apply(this, arguments);
817
+ }
818
+ return sendRenderEvent;
819
+ }()
820
+ /**
821
+ * @description close cashier
822
+ */
823
+ )
824
+ }, {
825
+ key: "cleanContainer",
826
+ value: function cleanContainer() {
827
+ var _document$getElementB4,
828
+ _this6 = this;
829
+ var immediately = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
830
+ (_document$getElementB4 = document.getElementById(LOADING_ID)) === null || _document$getElementB4 === void 0 || _document$getElementB4.remove();
831
+ this.hideComponentAnimation();
832
+ var mockup = document.getElementById(MOCKUP_ID);
833
+ mockup === null || mockup === void 0 || mockup.classList.add("".concat(MOCKUP_ID, "-hidden"));
834
+ this._loadAppPromiseResolve && this._loadAppPromiseResolve(true);
835
+ this._performanceData = [];
836
+ this._isInitComponent = false;
837
+ this.app = null;
838
+ if (immediately) this.cleanElement();else {
839
+ setTimeout(function () {
840
+ _this6.cleanElement();
841
+ }, 300);
842
+ }
843
+ }
844
+ }, {
845
+ key: "hideComponentAnimation",
846
+ value: function hideComponentAnimation() {
847
+ var container = document.getElementById(COMPONENT_CONTAINER_ID);
848
+ if (this.app) this.app.style.height = container.style.height;
849
+ if (container) {
850
+ // size变化动画取消
851
+ container.style.transition = '';
852
+ container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform));
853
+ container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.platform, "-animation"));
854
+ container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.platform));
855
+ }
856
+ }
857
+ }]);
858
+ return ComponentApp;
859
+ }();
860
+ export { ComponentApp as default };