! function(t, e) {
	"object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define &&
		define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).MonitorMinSDK = e()
}(this, (function() {
	"use strict";

	function t(e) {
		return t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
			return typeof t
		} : function(t) {
			return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ?
				"symbol" : typeof t
		}, t(e)
	}

	function e(t, e) {
		for (var n = 0; n < e.length; n++) {
			var i = e[n];
			i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object
				.defineProperty(t, i.key, i)
		}
	}
	var n, i, r = r || function(t, e) {
		var n = {},
			i = n.lib = {},
			r = function() {},
			o = i.Base = {
				extend: function(t) {
					r.prototype = this;
					var e = new r;
					return t && e.mixIn(t), e.hasOwnProperty("init") || (e.init = function() {
						e.$super.init.apply(this, arguments)
					}), e.init.prototype = e, e.$super = this, e
				},
				create: function() {
					var t = this.extend();
					return t.init.apply(t, arguments), t
				},
				init: function() {},
				mixIn: function(t) {
					for (var e in t) t.hasOwnProperty(e) && (this[e] = t[e]);
					t.hasOwnProperty("toString") && (this.toString = t.toString)
				},
				clone: function() {
					return this.init.prototype.extend(this)
				}
			},
			s = i.WordArray = o.extend({
				init: function(t, e) {
					t = this.words = t || [], this.sigBytes = null != e ? e : 4 * t.length
				},
				toString: function(t) {
					return (t || c).stringify(this)
				},
				concat: function(t) {
					var e = this.words,
						n = t.words,
						i = this.sigBytes;
					if (t = t.sigBytes, this.clamp(), i % 4)
						for (var r = 0; r < t; r++) e[i + r >>> 2] |= (n[r >>> 2] >>> 24 - r % 4 *
							8 & 255) << 24 - (i + r) % 4 * 8;
					else if (65535 < n.length)
						for (r = 0; r < t; r += 4) e[i + r >>> 2] = n[r >>> 2];
					else e.push.apply(e, n);
					return this.sigBytes += t, this
				},
				clamp: function() {
					var e = this.words,
						n = this.sigBytes;
					e[n >>> 2] &= 4294967295 << 32 - n % 4 * 8, e.length = t.ceil(n / 4)
				},
				clone: function() {
					var t = o.clone.call(this);
					return t.words = this.words.slice(0), t
				},
				random: function(e) {
					for (var n = [], i = 0; i < e; i += 4) n.push(4294967296 * t.random() | 0);
					return new s.init(n, e)
				}
			}),
			a = n.enc = {},
			c = a.Hex = {
				stringify: function(t) {
					var e = t.words;
					t = t.sigBytes;
					for (var n = [], i = 0; i < t; i++) {
						var r = e[i >>> 2] >>> 24 - i % 4 * 8 & 255;
						n.push((r >>> 4).toString(16)), n.push((15 & r).toString(16))
					}
					return n.join("")
				},
				parse: function(t) {
					for (var e = t.length, n = [], i = 0; i < e; i += 2) n[i >>> 3] |= parseInt(t
						.substr(i, 2), 16) << 24 - i % 8 * 4;
					return new s.init(n, e / 2)
				}
			},
			u = a.Latin1 = {
				stringify: function(t) {
					var e = t.words;
					t = t.sigBytes;
					for (var n = [], i = 0; i < t; i++) n.push(String.fromCharCode(e[i >>> 2] >>> 24 -
						i % 4 * 8 & 255));
					return n.join("")
				},
				parse: function(t) {
					for (var e = t.length, n = [], i = 0; i < e; i++) n[i >>> 2] |= (255 & t.charCodeAt(
						i)) << 24 - i % 4 * 8;
					return new s.init(n, e)
				}
			},
			f = a.Utf8 = {
				stringify: function(t) {
					try {
						return decodeURIComponent(escape(u.stringify(t)))
					} catch (t) {
						throw Error("Malformed UTF-8 data")
					}
				},
				parse: function(t) {
					return u.parse(unescape(encodeURIComponent(t)))
				}
			},
			l = i.BufferedBlockAlgorithm = o.extend({
				reset: function() {
					this._data = new s.init, this._nDataBytes = 0
				},
				_append: function(t) {
					"string" == typeof t && (t = f.parse(t)), this._data.concat(t), this
						._nDataBytes += t.sigBytes
				},
				_process: function(e) {
					var n = this._data,
						i = n.words,
						r = n.sigBytes,
						o = this.blockSize,
						a = r / (4 * o);
					if (e = (a = e ? t.ceil(a) : t.max((0 | a) - this._minBufferSize, 0)) * o, r = t
						.min(4 * e, r), e) {
						for (var c = 0; c < e; c += o) this._doProcessBlock(i, c);
						c = i.splice(0, e), n.sigBytes -= r
					}
					return new s.init(c, r)
				},
				clone: function() {
					var t = o.clone.call(this);
					return t._data = this._data.clone(), t
				},
				_minBufferSize: 0
			});
		i.Hasher = l.extend({
			cfg: o.extend(),
			init: function(t) {
				this.cfg = this.cfg.extend(t), this.reset()
			},
			reset: function() {
				l.reset.call(this), this._doReset()
			},
			update: function(t) {
				return this._append(t), this._process(), this
			},
			finalize: function(t) {
				return t && this._append(t), this._doFinalize()
			},
			blockSize: 16,
			_createHelper: function(t) {
				return function(e, n) {
					return new t.init(n).finalize(e)
				}
			},
			_createHmacHelper: function(t) {
				return function(e, n) {
					return new p.HMAC.init(t, n).finalize(e)
				}
			}
		});
		var p = n.algo = {};
		return n
	}(Math);
	! function(t) {
		for (var e = r, n = (o = e.lib).WordArray, i = o.Hasher, o = e.algo, s = [], a = [], c = function(t) {
				return 4294967296 * (t - (0 | t)) | 0
			}, u = 2, f = 0; 64 > f;) {
			var l;
			t: {
				l = u;
				for (var p = t.sqrt(l), h = 2; h <= p; h++)
					if (!(l % h)) {
						l = !1;
						break t
					} l = !0
			}
			l && (8 > f && (s[f] = c(t.pow(u, .5))), a[f] = c(t.pow(u, 1 / 3)), f++), u++
		}
		var d = [];
		o = o.SHA256 = i.extend({
			_doReset: function() {
				this._hash = new n.init(s.slice(0))
			},
			_doProcessBlock: function(t, e) {
				for (var n = this._hash.words, i = n[0], r = n[1], o = n[2], s = n[3], c = n[4], u =
						n[5], f = n[6], l = n[7], p = 0; 64 > p; p++) {
					if (16 > p) d[p] = 0 | t[e + p];
					else {
						var h = d[p - 15],
							y = d[p - 2];
						d[p] = ((h << 25 | h >>> 7) ^ (h << 14 | h >>> 18) ^ h >>> 3) + d[p - 7] + (
							(y << 15 | y >>> 17) ^ (y << 13 | y >>> 19) ^ y >>> 10) + d[p - 16]
					}
					h = l + ((c << 26 | c >>> 6) ^ (c << 21 | c >>> 11) ^ (c << 7 | c >>> 25)) + (
							c & u ^ ~c & f) + a[p] + d[p], y = ((i << 30 | i >>> 2) ^ (i << 19 |
							i >>> 13) ^ (i << 10 | i >>> 22)) + (i & r ^ i & o ^ r & o), l = f, f =
						u, u = c, c = s + h | 0, s = o, o = r, r = i, i = h + y | 0
				}
				n[0] = n[0] + i | 0, n[1] = n[1] + r | 0, n[2] = n[2] + o | 0, n[3] = n[3] + s | 0,
					n[4] = n[4] + c | 0, n[5] = n[5] + u | 0, n[6] = n[6] + f | 0, n[7] = n[7] + l |
					0
			},
			_doFinalize: function() {
				var e = this._data,
					n = e.words,
					i = 8 * this._nDataBytes,
					r = 8 * e.sigBytes;
				return n[r >>> 5] |= 128 << 24 - r % 32, n[14 + (r + 64 >>> 9 << 4)] = t.floor(i /
						4294967296), n[15 + (r + 64 >>> 9 << 4)] = i, e.sigBytes = 4 * n.length,
					this._process(), this._hash
			},
			clone: function() {
				var t = i.clone.call(this);
				return t._hash = this._hash.clone(), t
			}
		});
		e.SHA256 = i._createHelper(o), e.HmacSHA256 = i._createHmacHelper(o)
	}(Math), i = (n = r).enc.Utf8, n.algo.HMAC = n.lib.Base.extend({
		init: function(t, e) {
			t = this._hasher = new t.init, "string" == typeof e && (e = i.parse(e));
			var n = t.blockSize,
				r = 4 * n;
			e.sigBytes > r && (e = t.finalize(e)), e.clamp();
			for (var o = this._oKey = e.clone(), s = this._iKey = e.clone(), a = o.words, c = s
					.words, u = 0; u < n; u++) a[u] ^= 1549556828, c[u] ^= 909522486;
			o.sigBytes = s.sigBytes = r, this.reset()
		},
		reset: function() {
			var t = this._hasher;
			t.reset(), t.update(this._iKey)
		},
		update: function(t) {
			return this._hasher.update(t), this
		},
		finalize: function(t) {
			var e = this._hasher;
			return t = e.finalize(t), e.reset(), e.finalize(this._oKey.clone().concat(t))
		}
	});
	var o = r.HmacSHA256;

	function s(t, e, n, i) {
		return new Promise((function(r, o) {
			try {
				var s = new XMLHttpRequest;
				s && (s.withCredentials = !1, s.onreadystatechange = function() {
					if (4 === s.readyState)
						if (s.status >= 200 && s.status < 300 || 304 == s.status) {
							var t = JSON.parse(s.responseText);
							n(t, r, o)
						} else i(s.status, r, o)
				}, s.open("POST", t, !0), s.setRequestHeader("Content-type",
					"application/json; charset=UTF-8"), s.send(JSON.stringify(e) || null))
			} catch (t) {
				i("请求异常", r, o)
			}
		}))
	}
	var a = {
			INIT_CONFIG: "monitorsdk_config",
			BASE_INFO: "monitorsdk_base_info",
			PENDING_DATA: "monitorsdk_pending_data",
			MAIN_APP_MONITORED: "monitorsdk_main_app"
		},
		c = function(t) {
			var e;
			try {
				e = JSON.parse(window.localStorage.getItem(t)) || null
			} catch (n) {
				e = window.localStorage.getItem(t)
			}
			return e
		},
		u = function(e, n) {
			"object" === t(n) && (n = JSON.stringify(n)), window.localStorage.setItem(e, n)
		},
		f = window.localStorage.clear;
	window.localStorage.clear = function() {
		var t = {},
			e = Object.values(a);
		e.forEach((function(e) {
			t[e] = c(e)
		})), f.apply(this, arguments), e.forEach((function(e) {
			u(e, t[e])
		}))
	};
	var l = ["token", "deviceId", "appId", "platform", "reportTime"],
		p = function() {
			var t = c("monitorsdk_base_info");
			if (null != t && t.deviceId) return t.deviceId;
			var e = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (function(t) {
				var e = 16 * Math.random() | 0;
				return ("x" == t ? e : 3 & e | 8).toString(16)
			}));
			return u("monitorsdk_base_info", {
				deviceId: e
			}), e
		};

	function h(t, e) {
		var n = l.sort().filter((function(e) {
			return t[e]
		})).map((function(e) {
			return e + "=" + t[e]
		})).join("&");
		return o("POST" + n, e).toString()
	}
	var d = function() {
		function n() {
			! function(t, e) {
				if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
			}(this, n), this.version = "min-1.0.3", this.initPrams = null, this.postbeUrl = {
				dev: "http://jpostbe.huifutest.com",
				pro: "https://jua.cloudpnr.com"
			}
		}
		var i, r, o;
		return i = n, r = [{
			key: "init",
			value: function(e) {
				if ("object" === t(e)) {
					var n = e.pid,
						i = e.appKey,
						r = e.appToken,
						o = e.isDev,
						s = void 0 !== o && o;
					if (n && i && r) return this.initPrams = {
						pid: n,
						appKey: i,
						appToken: r,
						isDev: s,
						deviceId: p()
					}, this;
					console.error("配置信息缺少必填字段！")
				} else console.error("初始化配置信息错误")
			}
		}, {
			key: "track",
			value: function(t, e) {
				var n = arguments.length > 2 && void 0 !== arguments[2] && arguments[2],
					i = this.initPrams,
					r = i.pid,
					o = i.appKey,
					a = i.appToken,
					c = i.isDev,
					u = i.deviceId,
					f = {
						actionCode: t,
						sensorAttr: e,
						actionType: 2,
						occurTime: Date.now()
					};
				n && (f.sensorNo = t, f.actionCode = "");
				var l = {
					appId: r,
					token: a,
					deviceId: u,
					platform: 3,
					reportTime: Date.now(),
					sensorData: [f]
				};
				l.sign = h(l, o);
				var p = this.postbeUrl.pro;
				return c && (p = this.postbeUrl.dev), s(p + "/api/jpostbeApi/autoTrack/save", l,
					(function(t, e) {
						"90000" === (null == t ? void 0 : t.respCode) ? e(!0): e(!1)
					}), (function(t, e) {
						e(!1)
					}))
			}
		}], r && e(i.prototype, r), o && e(i, o), n
	}();
	return new d
}));