UNPKG

rx-postmessenger

Version:

Minimal RxJS adapter for the window.postMessage API for request-response streams and notification streams across frame windows.

2 lines 26 kB
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.RxPostmessenger=n():t.RxPostmessenger=n()}(self,(function(){return function(){"use strict";var t={d:function(n,e){for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:function(t,n){return Object.prototype.hasOwnProperty.call(t,n)}},n={};t.d(n,{default:function(){return Pt}});var e=function(){function t(t){this.IDGenerator=t}return t.prototype.makeNotification=function(t,n){return{channel:t,id:this.IDGenerator.generateID(),payload:n,type:"notification"}},t.prototype.makeRequest=function(t,n){return{channel:t,id:this.IDGenerator.generateID(),payload:n,type:"request"}},t.prototype.makeResponse=function(t,n,e){return{channel:n,id:this.IDGenerator.generateID(),payload:e,requestId:t,type:"response"}},t.prototype.invalidateID=function(t){this.IDGenerator.invalidateID(t)},t}(),r=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};var o=function(){function t(t){void 0===t&&(t=function(){var t,n,e;return r(this,(function(r){switch(r.label){case 0:t=function(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)},n=function(n){return void 0===n&&(n=1),Array(n).fill(null).map(t).join("")},e=function(){return[n(2),n(),n(),n(),n(3)].join("-")},r.label=1;case 1:return[4,e()];case 2:return r.sent(),[3,1];case 3:return[2]}}))}()),this.gen=t,this.usedIDValues=[]}return t.prototype.generateID=function(){var t;do{t=this.gen.next().value}while(this.usedIDValues.indexOf(t)>=0);return this.invalidateID(t),t},t.prototype.invalidateID=function(t){this.usedIDValues.push(t)},t}(),i=function(){function t(t,n){this.acceptedSource=t,this.acceptedOrigin=n}return t.prototype.validate=function(t){return t instanceof MessageEvent&&t.origin===this.acceptedOrigin&&t.source===this.acceptedSource&&this.isWellFormedMessage(t.data)},t.prototype.isWellFormedMessage=function(t){return"string"==typeof t.id&&["request","response","notification"].indexOf(t.type)>=0&&"string"==typeof t.channel&&("response"!==t.type||"string"==typeof t.requestId)},t}(),u=function(t,n){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])})(t,n)};function c(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}u(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}function s(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}s((r=r.apply(t,n||[])).next())}))}function a(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}Object.create;function l(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u}function p(t,n){for(var e=0,r=n.length,o=t.length;e<r;e++,o++)t[o]=n[e];return t}function h(t){return this instanceof h?(this.v=t,this):new h(t)}function d(t,n,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=e.apply(t,n||[]),i=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(t){o[t]&&(r[t]=function(n){return new Promise((function(e,r){i.push([t,n,e,r])>1||c(t,n)}))})}function c(t,n){try{(e=o[t](n)).value instanceof h?Promise.resolve(e.value.v).then(s,a):l(i[0][2],e)}catch(t){l(i[0][3],t)}var e}function s(t){c("next",t)}function a(t){c("throw",t)}function l(t,n){t(n),i.shift(),i.length&&c(i[0][0],i[0][1])}}function v(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,e=t[Symbol.asyncIterator];return e?e.call(t):(t=l(t),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(e){n[e]=t[e]&&function(n){return new Promise((function(r,o){(function(t,n,e,r){Promise.resolve(r).then((function(n){t({value:n,done:e})}),n)})(r,o,(n=t[e](n)).done,n.value)}))}}}Object.create;function y(t){return"function"==typeof t}function b(t){var n=t((function(t){Error.call(t),t.stack=(new Error).stack}));return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var w=b((function(t){return function(n){t(this),this.message=n?n.length+" errors occurred during unsubscription:\n"+n.map((function(t,n){return n+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=n}}));function m(t,n){if(t){var e=t.indexOf(n);0<=e&&t.splice(e,1)}}var g=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._teardowns=null}return t.prototype.unsubscribe=function(){var t,n,e,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var u=l(i),c=u.next();!c.done;c=u.next()){c.value.remove(this)}}catch(n){t={error:n}}finally{try{c&&!c.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}else i.remove(this);var s=this.initialTeardown;if(y(s))try{s()}catch(t){o=t instanceof w?t.errors:[t]}var a=this._teardowns;if(a){this._teardowns=null;try{for(var h=l(a),d=h.next();!d.done;d=h.next()){var v=d.value;try{S(v)}catch(t){o=null!=o?o:[],t instanceof w?o=p(p([],f(o)),f(t.errors)):o.push(t)}}}catch(t){e={error:t}}finally{try{d&&!d.done&&(r=h.return)&&r.call(h)}finally{if(e)throw e.error}}}if(o)throw new w(o)}},t.prototype.add=function(n){var e;if(n&&n!==this)if(this.closed)S(n);else{if(n instanceof t){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._teardowns=null!==(e=this._teardowns)&&void 0!==e?e:[]).push(n)}},t.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},t.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},t.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&m(n,t)},t.prototype.remove=function(n){var e=this._teardowns;e&&m(e,n),n instanceof t&&n._removeParent(this)},t.EMPTY=function(){var n=new t;return n.closed=!0,n}(),t}(),x=g.EMPTY;function _(t){return t instanceof g||t&&"closed"in t&&y(t.remove)&&y(t.add)&&y(t.unsubscribe)}function S(t){y(t)?t():t.unsubscribe()}var E={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},I={setTimeout:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=I.delegate;return((null==e?void 0:e.setTimeout)||setTimeout).apply(void 0,p([],f(t)))},clearTimeout:function(t){var n=I.delegate;return((null==n?void 0:n.clearTimeout)||clearTimeout)(t)},delegate:void 0};function O(t){I.setTimeout((function(){var n=E.onUnhandledError;if(!n)throw t;n(t)}))}function T(){}var P=j("C",void 0,void 0);function j(t,n,e){return{kind:t,value:n,error:e}}var D=null;function k(t){if(E.useDeprecatedSynchronousErrorHandling){var n=!D;if(n&&(D={errorThrown:!1,error:null}),t(),n){var e=D,r=e.errorThrown,o=e.error;if(D=null,r)throw o}}else t()}function M(t){E.useDeprecatedSynchronousErrorHandling&&D&&(D.errorThrown=!0,D.error=t)}var R=function(t){function n(n){var e=t.call(this)||this;return e.isStopped=!1,n?(e.destination=n,_(n)&&n.add(e)):e.destination=H,e}return c(n,t),n.create=function(t,n,e){return new A(t,n,e)},n.prototype.next=function(t){this.isStopped?F(function(t){return j("N",t,void 0)}(t),this):this._next(t)},n.prototype.error=function(t){this.isStopped?F(j("E",void 0,t),this):(this.isStopped=!0,this._error(t))},n.prototype.complete=function(){this.isStopped?F(P,this):(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(t){this.destination.next(t)},n.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n}(g),A=function(t){function n(n,e,r){var o,i=t.call(this)||this;if(y(n))o=n;else if(n){var u;o=n.next,e=n.error,r=n.complete,i&&E.useDeprecatedNextContext?(u=Object.create(n)).unsubscribe=function(){return i.unsubscribe()}:u=n,o=null==o?void 0:o.bind(u),e=null==e?void 0:e.bind(u),r=null==r?void 0:r.bind(u)}return i.destination={next:o?q(o,i):T,error:q(null!=e?e:C,i),complete:r?q(r,i):T},i}return c(n,t),n}(R);function q(t,n){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];try{t.apply(void 0,p([],f(n)))}catch(t){E.useDeprecatedSynchronousErrorHandling?M(t):O(t)}}}function C(t){throw t}function F(t,n){var e=E.onStoppedNotification;e&&I.setTimeout((function(){return e(t,n)}))}var H={closed:!0,next:T,error:C,complete:T},L="function"==typeof Symbol&&Symbol.observable||"@@observable";function $(t){return t}function G(t){return 0===t.length?$:1===t.length?t[0]:function(n){return t.reduce((function(t,n){return n(t)}),n)}}var N=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(n){var e=new t;return e.source=this,e.operator=n,e},t.prototype.subscribe=function(t,n,e){var r,o=this,i=(r=t)&&r instanceof R||function(t){return t&&y(t.next)&&y(t.error)&&y(t.complete)}(r)&&_(r)?t:new A(t,n,e);return k((function(){var t=o,n=t.operator,e=t.source;i.add(n?n.call(i,e):e?o._subscribe(i):o._trySubscribe(i))})),i},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},t.prototype.forEach=function(t,n){var e=this;return new(n=U(n))((function(n,r){var o;o=e.subscribe((function(n){try{t(n)}catch(t){r(t),null==o||o.unsubscribe()}}),r,n)}))},t.prototype._subscribe=function(t){var n;return null===(n=this.source)||void 0===n?void 0:n.subscribe(t)},t.prototype[L]=function(){return this},t.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return G(t)(this)},t.prototype.toPromise=function(t){var n=this;return new(t=U(t))((function(t,e){var r;n.subscribe((function(t){return r=t}),(function(t){return e(t)}),(function(){return t(r)}))}))},t.create=function(n){return new t(n)},t}();function U(t){var n;return null!==(n=null!=t?t:E.Promise)&&void 0!==n?n:Promise}function V(t){return function(n){if(function(t){return y(null==t?void 0:t.lift)}(n))return n.lift((function(n){try{return t(n,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}var z=function(t){function n(n,e,r,o,i){var u=t.call(this,n)||this;return u.onFinalize=i,u._next=e?function(t){try{e(t)}catch(t){n.error(t)}}:t.prototype._next,u._error=o?function(t){try{o(t)}catch(t){n.error(t)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=r?function(){try{r()}catch(t){n.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,u}return c(n,t),n.prototype.unsubscribe=function(){var n,e=this.closed;t.prototype.unsubscribe.call(this),!e&&(null===(n=this.onFinalize)||void 0===n||n.call(this))},n}(R);function W(t,n){return V((function(e,r){var o=0;e.subscribe(new z(r,(function(e){r.next(t.call(n,e,o++))})))}))}var Y=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function Z(t){return y(null==t?void 0:t.then)}function B(t,n){return new N((function(e){var r=0;return n.schedule((function(){r===t.length?e.complete():(e.next(t[r++]),e.closed||this.schedule())}))}))}var J="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function K(t,n){if(!t)throw new Error("Iterable cannot be null");return new N((function(e){var r=new g;return r.add(n.schedule((function(){var o=t[Symbol.asyncIterator]();r.add(n.schedule((function(){var t=this;o.next().then((function(n){n.done?e.complete():(e.next(n.value),t.schedule())}))})))}))),r}))}function Q(t){return y(t[L])}function X(t){return y(null==t?void 0:t[J])}function tt(t){return Symbol.asyncIterator&&y(null==t?void 0:t[Symbol.asyncIterator])}function nt(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function et(t){return d(this,arguments,(function(){var n,e,r;return a(this,(function(o){switch(o.label){case 0:n=t.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,h(n.read())];case 3:return e=o.sent(),r=e.value,e.done?[4,h(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,h(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}}))}))}function rt(t){return y(null==t?void 0:t.getReader)}function ot(t,n){if(null!=t){if(Q(t))return function(t,n){return new N((function(e){var r=new g;return r.add(n.schedule((function(){var o=t[L]();r.add(o.subscribe({next:function(t){r.add(n.schedule((function(){return e.next(t)})))},error:function(t){r.add(n.schedule((function(){return e.error(t)})))},complete:function(){r.add(n.schedule((function(){return e.complete()})))}}))}))),r}))}(t,n);if(Y(t))return B(t,n);if(Z(t))return function(t,n){return new N((function(e){return n.schedule((function(){return t.then((function(t){e.add(n.schedule((function(){e.next(t),e.add(n.schedule((function(){return e.complete()})))})))}),(function(t){e.add(n.schedule((function(){return e.error(t)})))}))}))}))}(t,n);if(tt(t))return K(t,n);if(X(t))return function(t,n){return new N((function(e){var r;return e.add(n.schedule((function(){r=t[J](),function(t,n,e,r){void 0===r&&(r=0);var o=n.schedule((function(){try{e.call(this)}catch(n){t.error(n)}}),r);t.add(o)}(e,n,(function(){var t=r.next(),n=t.value;t.done?e.complete():(e.next(n),this.schedule())}))}))),function(){return y(null==r?void 0:r.return)&&r.return()}}))}(t,n);if(rt(t))return function(t,n){return K(et(t),n)}(t,n)}throw nt(t)}function it(t){if(t instanceof N)return t;if(null!=t){if(Q(t))return r=t,new N((function(t){var n=r[L]();if(y(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(Y(t))return ut(t);if(Z(t))return e=t,new N((function(t){e.then((function(n){t.closed||(t.next(n),t.complete())}),(function(n){return t.error(n)})).then(null,O)}));if(tt(t))return ct(t);if(X(t))return n=t,new N((function(t){var e,r;try{for(var o=l(n),i=o.next();!i.done;i=o.next()){var u=i.value;if(t.next(u),t.closed)return}}catch(t){e={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}t.complete()}));if(rt(t))return ct(et(t))}var n,e,r;throw nt(t)}function ut(t){return new N((function(n){for(var e=0;e<t.length&&!n.closed;e++)n.next(t[e]);n.complete()}))}function ct(t){return new N((function(n){(function(t,n){var e,r,o,i;return s(this,void 0,void 0,(function(){var u,c;return a(this,(function(s){switch(s.label){case 0:s.trys.push([0,5,6,11]),e=v(t),s.label=1;case 1:return[4,e.next()];case 2:if((r=s.sent()).done)return[3,4];if(u=r.value,n.next(u),n.closed)return[2];s.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=s.sent(),o={error:c},[3,11];case 6:return s.trys.push([6,,9,10]),r&&!r.done&&(i=e.return)?[4,i.call(e)]:[3,8];case 7:s.sent(),s.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return n.complete(),[2]}}))}))})(t,n).catch((function(t){return n.error(t)}))}))}function st(t,n,e){return void 0===e&&(e=1/0),y(n)?st((function(e,r){return W((function(t,o){return n(e,t,r,o)}))(it(t(e,r)))}),e):("number"==typeof n&&(e=n),V((function(n,r){return function(t,n,e,r,o,i,u,c){var s=[],a=0,l=0,f=!1,p=function(){!f||s.length||a||n.complete()},h=function(t){return a<r?d(t):s.push(t)},d=function(t){i&&n.next(t),a++;var c=!1;it(e(t,l++)).subscribe(new z(n,(function(t){null==o||o(t),i?h(t):n.next(t)}),(function(){c=!0}),void 0,(function(){if(c)try{a--;for(var t=function(){var t=s.shift();u?n.add(u.schedule((function(){return d(t)}))):d(t)};s.length&&a<r;)t();p()}catch(t){n.error(t)}})))};return t.subscribe(new z(n,h,(function(){f=!0,p()}))),function(){null==c||c()}}(n,r,t,e)})))}var at=Array.isArray;function lt(t){return W((function(n){return function(t,n){return at(n)?t.apply(void 0,p([],f(n))):t(n)}(t,n)}))}var ft=["addListener","removeListener"],pt=["addEventListener","removeEventListener"],ht=["on","off"];function dt(t,n,e,r){if(y(e)&&(r=e,e=void 0),r)return dt(t,n,e).pipe(lt(r));var o,i,u=f(function(t){return y(t.addEventListener)&&y(t.removeEventListener)}(t)?pt.map((function(r){return function(o){return t[r](n,o,e)}})):function(t){return y(t.addListener)&&y(t.removeListener)}(t)?ft.map(vt(t,n)):function(t){return y(t.on)&&y(t.off)}(t)?ht.map(vt(t,n)):[],2),c=u[0],s=u[1];if(!c&&Y(t))return st((function(t){return dt(t,n,e)}))((o=t,i?B(o,i):ut(o)));if(!c)throw new TypeError("Invalid event target");return new N((function(t){var n=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t.next(1<n.length?n:n[0])};return c(n),function(){return s(n)}}))}function vt(t,n){return function(e){return function(r){return t[e](n,r)}}}var yt=new N((function(t){return t.complete()}));function bt(t){return t<=0?function(){return yt}:V((function(n,e){var r=0;n.subscribe(new z(e,(function(n){++r<=t&&(e.next(n),t<=r&&e.complete())})))}))}var wt=b((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),mt=function(t){function n(){var n=t.call(this)||this;return n.closed=!1,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return c(n,t),n.prototype.lift=function(t){var n=new gt(this,this);return n.operator=t,n},n.prototype._throwIfClosed=function(){if(this.closed)throw new wt},n.prototype.next=function(t){var n=this;k((function(){var e,r;if(n._throwIfClosed(),!n.isStopped){var o=n.observers.slice();try{for(var i=l(o),u=i.next();!u.done;u=i.next()){u.value.next(t)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}}}))},n.prototype.error=function(t){var n=this;k((function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var e=n.observers;e.length;)e.shift().error(t)}}))},n.prototype.complete=function(){var t=this;k((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}}))},n.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=null},Object.defineProperty(n.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),n.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},n.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},n.prototype._innerSubscribe=function(t){var n=this,e=n.hasError,r=n.isStopped,o=n.observers;return e||r?x:(o.push(t),new g((function(){return m(o,t)})))},n.prototype._checkFinalizedStatuses=function(t){var n=this,e=n.hasError,r=n.thrownError,o=n.isStopped;e?t.error(r):o&&t.complete()},n.prototype.asObservable=function(){var t=new N;return t.source=this,t},n.create=function(t,n){return new gt(t,n)},n}(N),gt=function(t){function n(n,e){var r=t.call(this)||this;return r.destination=n,r.source=e,r}return c(n,t),n.prototype.next=function(t){var n,e;null===(e=null===(n=this.destination)||void 0===n?void 0:n.next)||void 0===e||e.call(n,t)},n.prototype.error=function(t){var n,e;null===(e=null===(n=this.destination)||void 0===n?void 0:n.error)||void 0===e||e.call(n,t)},n.prototype.complete=function(){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===n||n.call(t)},n.prototype._subscribe=function(t){var n,e;return null!==(e=null===(n=this.source)||void 0===n?void 0:n.subscribe(t))&&void 0!==e?e:x},n}(mt);function xt(t){void 0===t&&(t={});var n=t.connector,e=void 0===n?function(){return new mt}:n,r=t.resetOnError,o=void 0===r||r,i=t.resetOnComplete,u=void 0===i||i,c=t.resetOnRefCountZero,s=void 0===c||c;return function(t){var n=null,r=null,i=null,c=0,a=!1,l=!1,f=function(){null==r||r.unsubscribe(),r=null},p=function(){f(),n=i=null,a=l=!1},h=function(){var t=n;p(),null==t||t.unsubscribe()};return V((function(t,d){c++,l||a||f();var v,y,b=i=null!=i?i:e();d.add((function(){0!==--c||l||a||(r=_t(h,s))})),b.subscribe(d),n||(n=new A({next:function(t){return b.next(t)},error:function(t){l=!0,f(),r=_t(p,o,t),b.error(t)},complete:function(){a=!0,f(),r=_t(p,u),b.complete()}}),(v=t,y?ot(v,y):it(v)).subscribe(n))}))(t)}}function _t(t,n){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return!0===n?(t(),null):!1===n?null:n.apply(void 0,p([],f(e))).pipe(bt(1)).subscribe((function(){return t()}))}function St(t,n){return V((function(e,r){var o=0;e.subscribe(new z(r,(function(e){return t.call(n,e,o++)&&r.next(e)})))}))}function Et(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=t.length;if(0===e)throw new Error("list of properties cannot be empty.");return W((function(n){for(var r=n,o=0;o<e;o++){var i=null==r?void 0:r[t[o]];if(void 0===i)return;r=i}return r}))}var It=function(){function t(t,n,e,r){this.id=t,this.channel=n,this.payload=e,this._injectResponse=r,this._isHandled=!1}return Object.defineProperty(t.prototype,"isHandled",{get:function(){return this._isHandled},enumerable:!1,configurable:!0}),t.prototype.respond=function(t){this._isHandled||(this._injectResponse(t),this._isHandled=!0)},t}(),Ot=function(){function t(t,n,e){var r=this;this.messageFactory=t,this.messageValidator=n,this.adapter=e,this.inboundMessages$=dt(window,"message").pipe(St((function(t){return r.messageValidator.validate(t)})),Et("data"),xt()),this.requests$=this.messagesOfType("request"),this.responses$=this.messagesOfType("response"),this.notifications$=this.messagesOfType("notification"),this.inboundMessages$.subscribe((function(t){var n=t.id;return r.messageFactory.invalidateID(n)}))}return t.prototype.request=function(t,n){var e=this.messageFactory.makeRequest(t,n),r=this.createResponseObservable(e.id);return this.adapter.postMessage(e),r},t.prototype.notify=function(t,n){this.adapter.postMessage(this.messageFactory.makeNotification(t,n))},t.prototype.requests=function(t){var n=this;return this.requests$.pipe(St((function(n){return n.channel===t})),W((function(e){return new It(e.id,e.channel,e.payload,(function(r){return n.respond(e.id,t,r)}))})))},t.prototype.notifications=function(t){return this.notifications$.pipe(St((function(n){return n.channel===t})),Et("payload"))},t.prototype.respond=function(t,n,e){return this.adapter.postMessage(this.messageFactory.makeResponse(t,n,e)),this},t.prototype.createResponseObservable=function(t){return this.responses$.pipe(St((function(n){return n.requestId===t})),Et("payload"),bt(1))},t.prototype.messagesOfType=function(t){return this.inboundMessages$.pipe(St((function(n){return n.type===t})))},t}(),Tt=function(){function t(t,n){this.targetWindow=t,this.targetOrigin=n}return t.prototype.postMessage=function(t){this.targetWindow.postMessage(t,this.targetOrigin)},t}(),Pt={connect:function(t,n){if(window===t)throw new Error("Remote window can not be the same as the local window environment");return new Ot(new e(new o),new i(t,n),new Tt(t,n))}};return n=n.default}()})); //# sourceMappingURL=rx-postmessenger.min.js.map