!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).stcMessage={})}(this,function(t){"use strict";function a(t){return(a="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)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var c=function(){function r(t,e){o(this,r);var n="";if(arguments.length<2?n="target error - target and name are both required":"object"!=a(t)?n="target error - target itself must be window object":"string"!=typeof e&&(n="target error - target name must be string type"),n)throw new Error(n);this.target=t,this.name=e}return n(r,[{key:"send",value:function(t,e,n){var r={msgType:t,data:e};this.target.postMessage(r,n)}}]),r}(),e=function(){function e(t){o(this,e),this.targets={},this.listenCallBack=null,this.trustedOrigin=t}return n(e,[{key:"addTarget",value:function(t,e){var n=new c(t,e);this.targets[e]=n}},{key:"send",value:function(t,e,n){var r,o=1<arguments.length&&void 0!==e?e:"",i=2<arguments.length?n:void 0,a=this.targets,s=i||this.trustedOrigin;for(r in a)a.hasOwnProperty(r)&&a[r].send(t,o,s)}},{key:"listener",value:function(n,r,o){var i=this;this.listenCallBack=function(t){var e=o||i.trustedOrigin;if(t.origin===e){if("object"!==a(t)||!t.data)throw new Error("传参格式错误");t=t.data,"string"==typeof n?t.msgType===n&&r(t.data):"boolean"==typeof n&&n&&r(t.data)}},"addEventListener"in document?window.addEventListener("message",this.listenCallBack,!1):"attachEvent"in document&&window.attachEvent("onmessage",this.listenCallBack)}},{key:"destroy",value:function(){this.targets={},"addEventListener"in document?window.removeEventListener("message",this.listenCallBack,!1):"attachEvent"in document&&window.detachEvent("onmessage",this.listenCallBack)}}]),e}(),f=function(){function r(t,e){var n;return o(this,r),(n=u(this,i(r).call(this,t))).init(e),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}(r,e),n(r,[{key:"init",value:function(t){var e;"wrap"===t?(e=window.parent,self==top&&(e=null)):"inner"===t&&(e=document.querySelector("iframe")&&document.querySelector("iframe").contentWindow),e&&this.addTarget(e,t)}}]),r}();t.STCMessage=f,t.default=f,Object.defineProperty(t,"__esModule",{value:!0})});
