/
window-rivet-umd-min.js
6 lines (6 loc) · 4.55 KB
/
window-rivet-umd-min.js
1
2
3
4
5
6
/**!
* @cidekar/window-rivet version 1.0.0
* Copyright 2019 Cidekar, LLC
* @license Released under the Apache-2.0 license.
*/
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.rivet=i()}(this,function(){"use strict";var n=function(t,i){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)i.hasOwnProperty(e)&&(t[e]=i[e])})(t,i)};function t(t,i){function e(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(e.prototype=i.prototype,new e)}var a=(e.store={cache:{},hooks:{}},e.getConfiguration=function(t){return t?e.store.cache[t]:{}},e.listConfiguration=function(t){return void 0===t&&(t="cache"),e.store[t]},e.putConfiguration=function(t,i){void 0===t&&(t="cache"),Object.assign(e.store[t],i)},e);function e(){this.configuration={component:void 0,dispatcherOrigin:"*",receiverOrigin:"*",silent:!1,warningOrigin:!0},this.setConfiguration=function(t){try{return e.store.cache=Object.assign(e.store.cache,t),!0}catch(t){return t}},e.store.cache=this.configuration}function c(){a.getConfiguration("silent")}var r=(o.bind=function(){function i(t){}["created","mounted"].forEach(function(t){try{o.register(t,i)}catch(t){c()}})},o.boot=function(){o.bind(),o.call("created")},o.call=function(t,i){var e=a.listConfiguration("hooks")[t];void 0!==e&&(e.callback&&e.callback.apply(o,[i]),e.lifecycle=!0,e.lineage=e.lineage.concat(["ready"]))},o.register=function(t,i,e){var n;void 0===i&&(i=null),void 0===e&&(e="register");try{var r=a.listConfiguration("hooks")[t];if(void 0===r){var o=((n={})[t]={lifecycle:e,callback:i,lineage:[e]},n);a.putConfiguration("hooks",o)}else void 0!==r&&(r.callback=i,r.lifecycle=e,r.lineage=r.lineage.concat([e]))}catch(t){c()}},o.ready=function(){var t=!1,i=a.listConfiguration("hooks");return i&&i.created.lifecycle&&i.mounted.lifecycle&&(t=!0),t},o);function o(){}var i=(s.boot=function(t){var i=t?"dispatcher":"receiver";r.register(i,null,"boot"),r.register(i,function(t){})},s);function s(t){var n=this;this.supported_message_types=["string","object"],this.target=null,this.targetOrigin=null,this.warningOrigin=null,this.componentType=null,this.bind=function(){n.listen("message",n.handler)},this.listen=function(t,i){try{window.addEventListener(t,i)}catch(t){c()}},this.handler=function(t){if(n.trusted(t.origin)&&t.data)try{n.isSupported(t)&&r.ready()&&("*"===n.targetOrigin&&n.warningOrigin&&c(n.componentType),c(),n.emit(t.data.event,t))}catch(t){c()}},this.emit=function(t,i){try{var e=new Event(t);Object.assign(e,{messageEvent:i}),"dispatcher"===n.componentType?window.dispatchEvent(e):n.target.dispatchEvent(e)}catch(t){c()}},this.isSupported=function(t){for(var i=!1,e=0;e<n.supported_message_types.length;e++)if(n.supported_message_types[e]===typeof t.data){i=!0;break}return i},this.message=function(t,i){try{if(!t)throw new Error("attempt to dispatch without payload");if(!t.event)throw new Error("attempt to dispatch without defining an event");"*"===n.targetOrigin&&n.warningOrigin&&c(n.componentType),i?i.messageEvent.source.postMessage(t,i.messageEvent.origin):n.target.postMessage(t,n.targetOrigin)}catch(t){c()}},this.trusted=function(t){var i=!1,e=a.getConfiguration("dispatcherOrigin");if("string"==typeof e&&"*"===e&&(i=!0),"object"==typeof e)for(var n=0;n<e.length;n++)if(e[n]===t){i=!0;break}return i},this.componentType=t,this.warningOrigin=a.getConfiguration("warningOrigin"),"dispatcher"===t?(this.target=window.parent,this.targetOrigin=a.getConfiguration("receiverOrigin")):(this.target=window,this.targetOrigin=a.getConfiguration("dispatcherOrigin")),r.call(t),this.bind()}var u,g=(t(f,u=i),f);function f(){return u.call(this,"dispatcher")||this}var h,l,d=(t(p,h=i),p.boot=function(){i.boot("receiver")},p);function p(){return h.call(this,"receiver")||this}function v(){var i=l.call(this)||this;return i.boot=function(t){i.checkSecurityConcerns(t),i.setConfiguration(t),r.boot(),g.boot(),d.boot(),r.call("mounted")},i.checkSecurityConcerns=function(t){for(var i={origin:{validator:function(){return!(!t.dispatcherOrigin&&!t.receiverOrigin)&&!(t.dispatcherOrigin&&"*"===t.dispatcherOrigin.toString()||t.receiverOrigin&&"*"===t.receiverOrigin.toString())},message:"Always specify an exact target origin, not *. Please update your configuration to fix this security issue."}},e=0,n=Object.entries(i);e<n.length;e++){var r=n[e],o=(r[0],r[1]);o.validator()||window.console.warn("[@cidekar/window-rivet] "+o.message)}},i}var y=new(t(v,l=a),v);function O(t){y.boot(t),this.dispatcher=g,this.receiver=d}return O.version="1.0.0",O});