Files
svgedit/dist/editor/system/extensions/ext-xdomain-messaging.js
2020-09-04 22:34:30 +02:00

2 lines
3.0 KiB
JavaScript

System.register([],(function(e){"use strict";return{execute:function(){function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,r;function resume(t,r){try{var n=e[t](r),o=n.value,a=o instanceof _AwaitValue;Promise.resolve(a?o.wrapped:o).then((function(e){a?resume("return"===t?"return":"next",e):settle(n.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,n){switch(e){case"return":t.resolve({value:n,done:!0});break;case"throw":t.reject(n);break;default:t.resolve({value:n,done:!1})}(t=t.next)?resume(t.key,t.arg):r=null}this._invoke=function send(e,n){return new Promise((function(o,a){var i={key:e,arg:n,resolve:o,reject:a,next:null};r?r=r.next=i:(t=r=i,resume(e,n))}))},"function"!=typeof e.return&&(this.return=void 0)}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},_AsyncGenerator.prototype.throw=function(e){return this._invoke("throw",e)},_AsyncGenerator.prototype.return=function(e){return this._invoke("return",e)};e("default",{name:"xdomain-messaging",init:function init(){var e=this,t=e.canvas;try{window.addEventListener("message",(function(r){if(r.data&&["string","object"].includes(_typeof(r.data))&&"|"!==r.data.charAt()){var n="object"===_typeof(r.data)?r.data:JSON.parse(r.data);if(n&&"object"===_typeof(n)&&"svgCanvas"===n.namespace){var o=e.curConfig.allowedOrigins;if(o.includes("*")||o.includes(r.origin)){var a=n.id,i=n.name,s=n.args,u={namespace:"svg-edit",id:a};try{u.result=t[i].apply(t,_toConsumableArray(s))}catch(e){u.error=e.message}r.source.postMessage(JSON.stringify(u),"*")}else console.log("Origin ".concat(r.origin," not whitelisted for posting to ").concat(window.origin))}}}))}catch(e){console.log("Error with xdomain message listener: "+e)}}})}}}));