gun.min.js 34 KB

1
  1. !function(){var t;"undefined"!=typeof window&&(t=window),"undefined"!=typeof global&&(t=global);var e=(t=t||{}).console||{log:function(){}};function _(e,t){return t?require(e):e.slice?_[o(e)]:function(t,n){e(t={exports:{}}),_[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var l=module;_(function(t){var n,c,l={};function e(t,n){v(this,n)&&void 0!==this[n]||(this[n]=t)}function o(t,n){var e=this.n;if(!e||!(n===e||g(e)&&v(e,n)))return!!n||void 0}function p(t,n){2!==arguments.length?(p.r=p.r||[]).push(t):(p.r=p.r||{})[t]=n}l.fn={is:function(t){return!!t&&"function"==typeof t}},l.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},l.num={is:function(t){return!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},l.text={is:function(t){return"string"==typeof t}},l.text.ify=function(t){return l.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},l.text.random=function(t,n){var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0<t;)e+=n.charAt(Math.floor(Math.random()*n.length)),t--;return e},l.text.match=function(t,n){var e,o;return"string"==typeof t&&("string"==typeof n&&(n={"=":n}),t===(e=(n=n||{})["="]||n["*"]||n[">"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"]||n["<"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},l.list={is:function(t){return t instanceof Array}},l.list.slit=Array.prototype.slice,l.list.sort=function(e){return function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n<t?1:0:0}},l.list.map=function(t,n,e){return r(t,n,e)},l.list.index=1,l.obj={is:function(t){return!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},l.obj.put=function(t,n,e){return(t||{})[n]=e,t},l.obj.has=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},l.obj.del=function(t,n){if(t)return t[n]=null,delete t[n],t},l.obj.as=function(t,n,e,o){return t[n]=t[n]||(o===e?{}:e)},l.obj.ify=function(n){if(g(n))return n;try{n=JSON.parse(n)}catch(t){n={}}return n},l.obj.to=function(t,n){return r(t,e,n=n||{}),n},l.obj.copy=function(t){return t?JSON.parse(JSON.stringify(t)):t},l.obj.empty=function(t,n){return!t||!r(t,o,{n:n})},c=Object.keys,Object.keys=Object.keys||function(t){return n(t,function(t,n,e){e(n)})},l.obj.map=n=function(t,n,e){var o,i,r,a,u=0,s=h(n);if(p.r=null,c&&g(t)&&(r=c(t),a=!0),d(t)||r)for(o=(r||t).length;u<o;u++){var f=u+l.list.index;if(s){if(void 0!==(i=a?n.call(e||this,t[r[u]],r[u],p):n.call(e||this,t[u],f,p)))return i}else if(n===t[a?r[u]:u])return r?r[u]:f}else for(u in t)if(s){if(v(t,u)&&void 0!==(i=e?n.call(e,t[u],u,p):n(t[u],u,p)))return i}else if(n===t[u])return u;return s?p.r:l.list.index?0:-1},l.time={},l.time.is=function(t){return t?t instanceof Date:+(new Date).getTime()};var h=l.fn.is,d=l.list.is,i=l.obj,g=i.is,v=i.has,r=i.map;t.exports=l})(_,"./type"),_(function(t){t.exports=function t(n,e,o){if(!n)return{to:t};n=(this.tag||(this.tag={}))[n]||(this.tag[n]={tag:n,to:t._={next:function(t){var n;(n=this.to)&&n.next(t)}}});if(e instanceof Function){var i={off:t.off||(t.off=function(){if(this.next===t._.next)return!0;this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=t._.next,this.back.to=this.to,this.the.last===this.the&&delete this.on.tag[this.the.tag]}),to:t._,next:e,the:n,on:this,as:o};return(i.back=n.last||n).to=i,n.last=i}return(n=n.to)&&void 0!==e&&n.next(e),n}})(_,"./onto"),_(function(t){if("undefined"==typeof JSON)throw new Error("JSON is not included in this browser. Please load it first: ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js");var r=JSON.stringify;t.exports=function(t,n,e,o,i){if(t<n)return{defer:!0};if(n<e)return{historical:!0};if(e<n)return{converge:!0,incoming:!0};if(n===e){if((o=r(o)||"")===(i=r(i)||""))return{state:!0};if(o<i)return{converge:!0,current:!0};if(i<o)return{converge:!0,incoming:!0}}return{err:"Invalid CRDT Data: "+o+" to "+i+" at "+n+" to "+e+"!"}}})(_,"./HAM"),_(function(t){var n=_("./type"),e={};function o(t,n){return this.id?this.id=!1:n==i&&u(t)?void(this.id=t):this.id=!1}e.is=function(t){return void 0!==t&&(null===t||t!==1/0&&(!!(u(t)||r(t)||a(t))||(e.link.is(t)||!1)))},e.link=e.rel={_:"#"},e.link.is=function(t){if(t&&t[i]&&!t._&&f(t)){var n={};if(l(t,o,n),n.id)return n.id}return!1},e.link.ify=function(t){return c({},i,t)},n.obj.has._=".";var i=e.link._,r=n.bi.is,a=n.num.is,u=n.text.is,s=n.obj,f=s.is,c=s.put,l=s.map;t.exports=e})(_,"./val"),_(function(t){var n=_("./type"),i=_("./val"),r={_:"_"};function a(t,n){if(n!==r._)return!i.is(t)||void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s))}function o(t,n){var e,o=this.o;o.map?void 0===(e=o.map.call(this.as,t,""+n,o.node))?s(o.node,n):o.node&&(o.node[n]=e):i.is(t)&&(o.node[n]=t)}r.soul=function(t,n){return t&&t._&&t._[n||l]},r.soul.ify=function(t,n){return n="string"==typeof n?{soul:n}:n||{},(t=t||{})._=t._||{},t._[l]=n.soul||t._[l]||c(),t},r.soul._=i.link._,r.is=function(t,n,e){var o;return!!u(t)&&(!!(o=r.soul(t))&&!f(t,a,{as:e,cb:n,s:o,n:t}))},r.ify=function(t,n,e){return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n={map:n}):n={},n.map&&(n.node=n.map.call(e,t,void 0,n.node||{})),(n.node=r.soul.ify(n.node||{},n))&&f(t,o,{o:n,as:e}),n.node};var e=n.obj,u=e.is,s=e.del,f=e.map,c=n.text.random,l=r.soul._;t.exports=r})(_,"./node"),_(function(t){var n=_("./type"),a=_("./node");function u(){var t;return t=e(),o=o<t?(i=0,t+u.drift):t+(i+=1)/r+u.drift}var e=n.time.is,o=-1/0,i=0,r=1e3,s="undefined"!=typeof performance&&(performance.timing&&performance);s&&s.timing&&s.timing.navigationStart||(s=!1);function f(t,n){k!==n&&u.ify(this.o,n,this.s)}u._=">",u.drift=0,u.is=function(t,n,e){var o=n&&t&&t[k]&&t[k][u._]||e;if(o)return v(o=o[n])?o:-1/0},u.lex=function(){return u().toString(36).replace(".","")},u.ify=function(t,n,e,o,i){if(!t||!t[k]){if(!i)return;t=a.soul.ify(t,i)}var r=l(t[k],u._);return void 0!==n&&n!==k&&(v(e)&&(r[n]=e),void 0!==o&&(t[n]=o)),t},u.to=function(t,n,e){var o=(t||{})[n];return h(o)&&(o=g(o)),u.ify(e,n,u.is(t,n),o,a.soul(t))},u.map=function(i,r,a){var t=h(t=i||r)?t:null;return i=m(i=i||r)?i:null,t&&!i?(r=v(r)?r:u(),t[k]=t[k]||{},d(t,f,{o:t,s:r}),t):(a=a||h(r)?r:void 0,r=v(r)?r:u(),function(t,n,e,o){if(!i)return f.call({o:e,s:r},t,n),t;i.call(a||this||{},t,n,e,o),p(e,n)&&void 0===e[n]||f.call({o:e,s:r},t,n)})};var c=n.obj,l=c.as,p=c.has,h=c.is,d=c.map,g=c.copy,v=n.num.is,m=n.fn.is,k=a._;t.exports=u})(_,"./state"),_(function(t){var a=_("./type"),u=_("./val"),s=_("./node"),i={};function r(t,n){if(!t||n!==s.soul(t)||!s.is(t,this.fn,this.as))return!0;this.cb&&(e.n=t,e.as=this.as,this.cb.call(e.as,t,n,e))}function e(t){t&&s.is(e.n,t,e.as)}function f(t,n){var e;return(e=function(t,n){var e,o=t.seen,i=o.length;for(;i--;)if(e=o[i],n.obj===e.obj)return e;o.push(n)}(t,n))?e:(n.env=t,n.soul=c,s.ify(n.obj,o,n)&&(n.link=n.link||u.link.ify(s.soul(n.node)),n.obj!==t.shell&&(t.graph[u.link.is(n.link)]=n.node)),n)}function o(t,n,e){var o,i,r=this,a=r.env;if(s._===n&&g(t,u.link._))return e._;if(o=l(t,n,e,r,a)){if(n||(r.node=r.node||e||{},g(t,s._)&&s.soul(t)&&(r.node._=b(t._)),r.node=s.soul.ify(r.node,u.link.is(r.link)),r.link=r.link||u.link.ify(s.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),g(e,n))){if(void 0===(t=e[n]))return void d(e,n);if(!(o=l(t,n,e,r,a)))return}if(!n)return r.node;if(!0===o)return t;if((i=f(a,{obj:t,path:r.path.concat(n)})).node)return i.link}}function c(t){var n=this,e=u.link.is(n.link),o=n.env.graph;n.link=n.link||u.link.ify(t),n.link[u.link._]=t,n.node&&n.node[s._]&&(n.node[s._][u.link._]=t),g(o,e)&&(o[t]=o[e],d(o,e))}function l(t,n,e,o,i){var r;return!!u.is(t)||(h(t)?1:(r=i.invalid)?l(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(a.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}function p(t,n){var e,o;if(s._!==n)(e=u.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=i.to(this.graph,e,this.opt):this.obj[n]=t;else{if(v(t,u.link._))return;this.obj[n]=b(t)}}i.is=function(t,n,e,o){return!(!t||!h(t)||v(t))&&!k(t,r,{cb:n,fn:e,as:o})},i.ify=function(t,n,e){var o={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n.map=n):n={},n.soul&&(o.link=u.link.ify(n.soul)),n.shell=(e||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||e,f(n,o),n.root=o.node,n.graph},i.node=function(t){var n=s.soul(t);if(n)return m({},n,t)},i.to=function(t,n,e){if(t){var o={};return e=e||{seen:{}},k(t[n],p,{obj:o,graph:t,opt:e}),o}};a.fn.is;var n=a.obj,h=n.is,d=n.del,g=n.has,v=n.empty,m=n.put,k=n.map,b=n.copy;t.exports=i})(_,"./graph"),_(function(t){_("./onto"),t.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var e=t["#"]||t,o=(this.tag||empty)[e];if(!o)return;return o=this.on(e,n),clearTimeout(o.err),!0}e=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return e;var i=this.on(e,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet.",lack:!0}),i.off()},(this.opt||{}).lack||9e3),e}}})(_,"./ask"),_(function(t){var a=_("./type");var u=a.time.is;t.exports=function(i){var r={s:{}};return i=i||{max:1e3,age:27e3},r.check=function(t){var n;return!!(n=r.s[t])&&(n.pass?n.pass=!1:r.track(t))},r.track=function(t,n){var e=r.s[t]||(r.s[t]={});return e.was=u(),n&&(e.pass=!0),r.to||(r.to=setTimeout(r.drop,i.age+9)),e},r.drop=function(e){var o=u();a.obj.map(r.s,function(t,n){t&&(e||i.age)>o-t.was||a.obj.del(r.s,n)}),r.to=null},r}})(_,"./dup"),_(function(t){function p(t){return t instanceof p?(this._={gun:this,$:this}).$:this instanceof p?p.create(this._={gun:this,$:this,opt:t}):new p(t)}p.is=function(t){return t instanceof p||t&&t._&&t===t._.$||!1},p.version=.9,(p.chain=p.prototype).toJSON=function(){};var n=_("./type");function a(t){var n,e,o=this.as,i=o.at||o,r=i.$;(e=t["#"])||(e=t["#"]=u(9)),(n=i.dup).check(e)?o.out===t.out&&(t.out=void 0,this.to.next(t)):(n.track(e),(e=t["@"])&&n.track(e),i.ask(e,t)||(t.get&&p.on.get(t,r),t.put&&p.on.put(t,r)),this.to.next(t),o.out||(t.out=a,i.on("out",t)))}n.obj.to(n,p),p.HAM=_("./HAM"),p.val=_("./val"),p.node=_("./node"),p.state=_("./state"),p.graph=_("./graph"),p.on=_("./onto"),p.ask=_("./ask"),p.dup=_("./dup"),p.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||p.on,t.ask=t.ask||p.ask,t.dup=t.dup||p.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",a,t),t.on("out",a,{at:t,out:a}),p.on("create",t),t.on("create",t)),t.once=1,n},function(){p.on.put=function(t,n){var e=n._,o={$:n,graph:e.graph,put:{},map:{},souls:{},machine:p.state(),ack:t["@"],cat:e,stop:{}};if(p.obj.map(t.put,l,o)){if(p.graph.is(t.put,null,a,o)||(o.err="Error: Invalid graph!"),o.err)return e.on("in",{"@":t["#"],err:p.log(o.err)});if(g(o.put,u,o),o.async||g(o.map,c,o),void 0!==o.defer){var i=o.defer-o.machine;setTimeout(function(){p.on.put(t,n)},r<i?r:i)}o.diff&&e.on("put",d(t,{put:o.diff}))}};var r=2147483647;function a(t,n,e,o){var i=this,r=p.state.is(e,n);if(!r)return i.err="Error: No state on '"+n+"' in node '"+o+"'!";var a=i.graph[o]||k,u=p.state.is(a,n,!0),s=a[n],f=p.HAM(i.machine,r,u,t,s);f.incoming?(i.put[o]=p.state.to(e,n,i.put[o]),(i.diff||(i.diff={}))[o]=p.state.to(e,n,i.diff[o]),i.souls[o]=!0):f.defer&&(i.defer=r<(i.defer||1/0)?r:i.defer)}function u(t,n){var e=this,o=e.$._,i=(o.next||k)[n];if(!i){if(!(o.opt||k).super)return void(e.souls[n]=!1);i=e.$.get(n)._}var r=e.map[n]={put:t,get:n,$:i.$},a={ctx:e,msg:r};e.async=!!o.tag.node,e.ack&&(r["@"]=e.ack),g(t,s,a),e.async&&(e.and||o.on("node",function(t){this.to.next(t),t===e.map[t.get]&&(e.souls[t.get]=!1,g(t.put,f,t),g(e.souls,function(t){if(t)return t})||e.c||(e.c=1,this.off(),g(e.map,c,e)))}),e.and=!0,o.on("node",r))}function s(t,n){var e=this.ctx,o=e.graph,i=this.msg,r=i.get,a=i.put,u=i.$._;o[r]=p.state.to(a,n,o[r]),e.async||(u.put=p.state.to(a,n,u.put))}function f(t,n){var e=this.put,o=this.$._;o.put=p.state.to(e,n,o.put)}function c(t,n){t.$&&(this.cat.stop=this.stop,t.$._.on("in",t),this.cat.stop=null)}function l(t,n){if(t!==this.graph[n])return!0}p.on.get=function(t,n){var e=n._,o=t.get,i=o[v],r=e.graph[i],a=o[m],u=(e.next||(e.next={}))[i];if(!r)return e.on("get",t);if(a){if("string"!=typeof a||!h(r,a))return e.on("get",t);r=p.state.to(r,a)}else r=p.window?p.obj.copy(r):r;r=p.graph.node(r),(u||k).ack;function s(){}s.faith=!0,e.on("in",{"@":t["#"],how:"mem",put:r,$:n,_:s}),e.on("get",t)}}(),p.chain.opt=function(t){t=t||{};var n=this._,e=t.peers||t;return f(t)||(t={}),f(n.opt)||(n.opt=t),r(e)&&(e=[e]),o(e)&&(e=g(e,function(t,n,e){(n={}).id=n.url=t,e(t,n)}),f(n.opt.peers)||(n.opt.peers={}),n.opt.peers=d(e,n.opt.peers)),n.opt.peers=n.opt.peers||{},g(t,function t(n,e){!h(this,e)||i.is(n)||s.empty(n)?this[e]=n:n&&n.constructor!==Object&&!o(n)||g(n,t,this[e])},n.opt),p.on("opt",n),n.opt.uuid=n.opt.uuid||function(){return c()+u(12)},this};var o=p.list.is,i=p.text,r=i.is,u=i.random,s=p.obj,f=s.is,h=s.has,d=s.to,g=s.map,c=(s.copy,p.state.lex),v=p.val.link._,m=".",k=(p.node._,p.val.link.is,{});e.only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},(p.log=function(){return p.log.off||e.log.apply(e,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,e){return(e=p.log.once)[t]=e[t]||0,e[t]++||p.log(n)},p.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"),"undefined"!=typeof window&&((window.GUN=window.Gun=p).window=window);try{void 0!==l&&(l.exports=p)}catch(t){}t.exports=p})(_,"./root"),_(function(t){var u=_("./root");u.chain.back=function(t,n){if(-1===(t=t||1)||1/0===t)return this._.root.$;if(1===t)return(this._.back||this._).$;var e=this._;if("string"==typeof t&&(t=t.split(".")),t instanceof Array){for(var o=0,i=t.length,r=e;o<i;o++)r=(r||s)[t[o]];return void 0!==r?n?this:r:(r=e.back)?r.$.back(t,n):void 0}if(t instanceof Function){var a;for(r={back:e};(r=r.back)&&void 0===(a=t(r,n)););return a}return u.num.is(t)?(e.back||e).$.back(t-1):this};var s={}})(_,"./back"),_(function(t){var s=_("./root");function r(t){var e,n,o=this.as,i=o.back,r=o.root;if(t.$||(t.$=o.$),this.to.next(t),e=t.get){if(o.lex&&(t.get=k(o.lex,t.get)),e["#"]||o.soul){if(e["#"]=e["#"]||o.soul,t["#"]||(t["#"]=y(9)),i=r.$.get(e["#"])._,e=e["."]){if(v(i.put,e)){if((n=(a=i.$.get(e)._).ack)||(a.ack=-1),i.on("in",{$:i.$,put:s.state.to(i.put,e),get:i.get}),n)return}else if("string"!=typeof e){var a={},u=(i.put||{})._;s.obj.map(i.put,function(t,n){s.text.match(n,e)&&(a[n]=t)}),s.obj.empty(a)||(a._=u,i.on("in",{$:i.$,put:a,get:i.get}))}}else{if((n=i.ack)||(i.ack=-1),v(i,"put")&&i.on("in",i),n&&d!==i.put)return;t.$=i.$}return r.ask(h,t),r.on("in",t)}if(r.now&&(r.now[o.id]=r.now[o.id]||!0,o.pass={}),e["."])return o.get?(t={get:{".":o.get},$:o.$},i.ask||(i.ask={}),i.ask[o.get]=t.$._):t={get:{},$:o.$},i.on("out",t);if(o.ack=o.ack||-1,o.get)return t.$=o.$,e["."]=o.get,(i.ask||(i.ask={}))[o.get]=t.$._,i.on("out",t)}return i.on("out",t)}function a(t){var n,e,o=this,i=o.as,r=i.root,a=(t.$||g)._||g,u=t.put;if(i.get&&t.get!==i.get&&(t=k(t,{get:i.get})),i.has&&a!==i&&(t=k(t,{$:i.$}),a.ack&&(i.ack=a.ack)),d===u){if(e=a.put,o.to.next(t),i.soul)return;if(d===e&&d!==a.put)return;return c(i,t,o),i.has&&p(i,t),m(a.echo,i.id),void m(i.map,a.id)}if(i.soul)return o.to.next(t),c(i,t,o),void(i.next&&b(u,l,{msg:t,cat:i}));if(!(n=s.val.link.is(u)))return s.val.is(u)?(i.has||i.soul?p(i,t):(a.has||a.soul)&&((a.echo||(a.echo={}))[i.id]=a.echo[a.id]||i,(i.map||(i.map={}))[a.id]=i.map[a.id]||{at:a}),o.to.next(t),void c(i,t,o)):(i.has&&a!==i&&v(a,"put")&&(i.put=a.put),(n=s.node.soul(u))&&a.has&&(a.put=i.root.$.get(n)._.put),e=(r.stop||{})[a.id],o.to.next(t),f(i,t,a,n),c(i,t,o),void(i.next&&b(u,l,{msg:t,cat:i})));r.stop;(e=(e=r.stop||{})[a.id]||(e[a.id]={})).is=e.is||a.put,e[i.id]=a.put||!0,o.to.next(t),f(i,t,a,n),c(i,t,o)}function f(t,n,e,o){if(o&&u!==t.get){var i=t.root.$.get(o)._;t.has?e=i:e.has&&f(e,n,e,o),e!==t&&(e.$||(e={}),(e.echo||(e.echo={}))[t.id]=e.echo[t.id]||t,t.has&&!(t.map||g)[e.id]&&p(t,n),(o!==(i=e.id?(t.map||(t.map={}))[e.id]=t.map[e.id]||{at:e}:{}).link||i.pass||t.pass)&&(t.pass&&(s.obj.map(t.map,function(t){t.pass=!0}),m(t,"pass")),i.pass&&m(i,"pass"),t.has&&(t.link=o),function(t,o){var n=t.root.$.get(o)._,e=t.lex;if((t.ack||e)&&((e=e||{})["#"]=o,n.on("out",{get:e}),!t.ask))return;n=t.ask,s.obj.del(t,"ask"),b(n||t.next,function(t,n){var e=t.lex||{};e["#"]=o,e["."]=e["."]||n,t.on("out",{get:e})}),s.obj.del(t,"ask")}(t,i.link=o)))}}function c(t,n){t.echo&&b(t.echo,e,n)}function e(t){t&&t.on&&t.on("in",this)}function l(t,n){var e,o,i,r=this.cat.next||g,a=this.msg;(u!==n||r[n])&&(o=r[n])&&(o.has?(d!==o.put&&s.val.link.is(t)||(o.put=t),e=o.$):(i=a.$)&&(i=(e=a.$.get(n))._,d!==i.put&&s.val.link.is(t)||(i.put=t)),o.on("in",{put:t,get:n,$:e,via:a}))}function p(e,t){if(e.has||e.soul){var o=e.map;e.root;e.map=null,e.has&&(e.dub&&e.root.stop&&(e.dub=null),e.link=null),(e.pass||t["@"]||null!==o)&&(d===o&&s.val.link.is(e.put)||(b(o,function(t){(t=t.at)&&m(t.echo,e.id)}),o=e.put,b(e.next,function(t,n){if(d===o&&d!==e.put)return!0;t.put=d,t.ack&&(t.ack=-1),t.on("in",{get:n,$:t.$,put:d})})))}}function h(t,n){var e=this.as,o=e.get||g,i=e.$._,r=(t.put||g)[o["#"]];if(i.ack&&(i.ack=i.ack+1||1),t.put&&("string"!=typeof o["."]||v(r,i.get)))u!=o["."]?s.on.put(t,i.root.$):i.on("in",{get:i.get,put:s.val.link.ify(o["#"]),$:i.$,"@":t["@"]});else{if(i.put!==d)return;i.on("in",{get:i.get,put:i.put=d,$:i.$,"@":t["@"]})}}s.chain.chain=function(t){var n,e=this._,o=new(t||this).constructor(this),i=o._;return i.root=n=e.root,i.id=++n.once,i.back=this._,i.on=s.on,i.on("in",a,i),i.on("out",r,i),o};var d,g={},n=s.obj,v=n.has,m=(n.put,n.del),k=n.to,b=n.map,y=s.text.random,u=(s.val.link._,s.node._)})(_,"./chain"),_(function(t){var f=_("./root");function c(t){var n,e=this,o=e.as,i=o.at.root,r=(t.$||{})._||{},a=t.put||r.put;if((n=i.now)&&e!==n[o.now])return e.to.next(t);if(e.seen&&r.id&&e.seen[r.id])return e.to.next(t);if((n=a)&&n[g._]&&(n=g.is(n))&&(n=(t.$$=r.root.gun.get(n))._,p!==n.put&&(t=s(t,{put:a=n.put}))),(n=i.mum)&&r.id){var u=r.id+(e.id||(e.id=f.text.random(9)));if(n[u])return;p===a||g.is(a)||(n[u]=!0)}o.use(t,e),e.stun?e.stun=null:e.to.next(t)}function l(t){var n=this.on;if(!t||n.soul||n.has)return this.off();if(t=(t=(t=t.$||t)._||t).id){var e;n.map;if((e=this.seen||(this.seen={}))[t])return!0;e[t]=!0}}f.chain.get=function(t,n,e){var o;if("string"!=typeof t){if(t instanceof Function){if(!0===n)return function(t,n,e){var a,u=t._,s=0;if(a=u.soul||u.link||u.dub)return n(a,e,u);if(u.jam)return u.jam.push([n,e]);u.jam=[[n,e]],t.get(function(t,n){if(!(p===t.put&&(a=Object.keys(u.root.opt.peers).length)&&++s<a)){n.rid(t);var e,o=(o=t.$)&&o._||{},i=0;for(a=u.jam,delete u.jam;e=a[i++];){var r=e[0];e=e[1],r&&r(o.link||o.soul||g.is(t.put)||v(t.put)||o.dub,e,t,n)}}},{out:{get:{".":!0}}})}(this,t,e),this;var i,r=(o=this)._,a=r.root,u=a.now;(e=n||{}).at=r,e.use=t,e.out=e.out||{},e.out.get=e.out.get||{},(i=r.on("in",c,e)).rid=l,(a.now={$:1})[e.now=r.id]=i;var s=a.mum;return a.mum={},r.on("out",e.out),a.mum=s,a.now=u,o}return d(t)?this.get(""+t,n,e):(u=g.is(t))?this.get(u,n,e):h.is(t)?(o=this,(u=((u=t["#"])||m)["="]||u)&&(o=o.get(u)),o._.lex=t,o):((e=this.chain())._.err={err:f.log("Invalid get request!",t)},n&&n.call(e,e._.err),e)}return(o=(this._.next||m)[t])||(o=function(t,n){var e=n._,o=e.next,i=n.chain()._;o=o||(e.next={});o[i.get=t]=i,n===e.root.$?i.soul=t:(e.soul||e.has)&&(i.has=t);return i}(t,this)),o=o.$,(u=this._.stun)&&(o._.stun=o._.stun||u),n&&n instanceof Function&&o.get(n,e),o};var p,h=f.obj,s=(h.map,h.has,f.obj.to),d=f.num.is,g=f.val.link,v=f.node.soul,m=(f.node._,{})})(_,"./get"),_(function(t){var f=_("./root");function u(t){t&&t()}function s(){var r=this;r.graph&&!e(r.stun,n)&&(r.res=r.res||function(t){t&&t()},r.res(function(){var n=r.$.back(-1)._,t=n.ask(function(t){n.root.on("ack",t),t.err&&f.log(t),++e>(r.acks||0)&&this.off(),r.ack&&r.ack(t,this)},r.opt),e=0,o=n.root.now;h.del(n.root,"now");var i=n.root.mum;n.root.mum={},r.ref._.on("out",{$:r.ref,put:r.out=r.env.graph,opt:r.opt,"#":t}),n.root.mum=i?h.to(i,n.root.mum):i,n.root.now=o},r),r.res&&r.res())}function n(t,n){if(t)return!0}function c(r,t,n,a){var u=this,s=f.is(r);!t&&a.path.length&&(u.res||o)(function(){for(var t=a.path,n=u.ref,e=(u.opt,0),o=t.length;e<o;e++)n=n.get(t[e]);s&&(n=r);var i=n._.dub;if(i=i||f.node.soul(a.obj))return n.back(-1).get(i),void a.soul(i);(u.stun=u.stun||{})[t]=!0,n.get(l,!0,{as:{at:a,as:u,p:t}})},{as:u,at:a})}function l(t,e,n,o){var i=(e=e.as).at;e=e.as;var r=((n||{}).$||{})._||{};t=r.dub=r.dub||t||f.node.soul(i.obj)||f.node.soul(n.put||r.put)||f.val.link.is(n.put||r.put)||(e.via.back("opt.uuid")||f.text.random)(),o&&(o.stun=!0),t?a(r,r.dub=t,i,e):e.via.back("opt.uuid")(function(t,n){if(t)return f.log(t);a(r,r.dub=r.dub||n,i,e)})}function a(t,n,e,o){t.$.back(-1).get(n),e.soul(n),o.stun[e.path]=!1,o.batch()}function p(t,e,n,o){if(e=e.as,n.$&&n.$._)if(n.err)f.log("Please report this as an issue! Put.any.err");else{var i,r=n.$._,a=r.put,u=e.opt||{};if(!(i=e.ref)||!i._.now){if(o&&(o.stun=!0),e.ref!==e.$){if(!(i=e.$._.get||r.get))return void f.log("Please report this as an issue! Put.no.get");e.data=g({},i,e.data),i=null}if(void 0===a){if(!r.get)return;t||(i=r.$.back(function(t){if(t.link||t.soul)return t.link||t.soul;e.data=g({},t.get,e.data)}),e.not=!0),r=(i=i||r.soul||r.link||r.dub)?r.root.$.get(i)._:r,e.soul=i,a=e.data}e.not||(e.soul=e.soul||t)||(e.path&&d(e.data)?e.soul=(u.uuid||e.via.back("opt.uuid")||f.text.random)():(k==r.get&&(e.soul=(r.put||v)["#"]||r.dub),e.soul=e.soul||r.soul||r.link||(u.uuid||e.via.back("opt.uuid")||f.text.random)()),e.soul)?e.ref.put(e.data,e.soul,e):e.via.back("opt.uuid")(function(t,n){if(t)return f.log(t);e.ref.put(e.data,e.soul=n,e)})}}}f.chain.put=function(t,o,i){var n,r=this,e=r._,a=e.root.$;a._;return(i=i||{}).data=t,i.via=i.$=i.via||i.$||r,"string"==typeof o?i.soul=o:i.ack=i.ack||o,e.soul&&(i.soul=e.soul),i.soul||a===r?d(i.data)?(i.soul=i.soul||(i.not=f.node.soul(i.data)||(i.via.back("opt.uuid")||f.text.random)()),i.soul?(i.$=a.get(i.soul),i.ref=i.$,function(t){t.batch=s;var n=t.opt||{},e=t.env=f.state.map(c,n.state);if(e.soul=t.soul,t.graph=f.graph.ify(t.data,e,t),e.err)return(t.ack||m).call(t,t.out={err:f.log(e.err)}),t.res&&t.res();t.batch()}(i)):i.via.back("opt.uuid")(function(t,n){if(t)return f.log(t);(i.ref||i.$).put(i.data,i.soul=n,i)}),r):((i.ack||m).call(i,i.out={err:f.log("Data saved to the root level of the graph must be a node (an object), not a",typeof i.data,'of "'+i.data+'"!')}),i.res&&i.res(),r):f.is(t)?(t.get(function(t,n,e){if(!t)return f.log("The reference you are saving is a",typeof e.put,'"'+e.put+'", not a node (object)!');r.put(f.val.link.ify(t),o,i)},!0),r):(e.has&&(n=f.val.link.is(t))&&(e.dub=n),i.ref=i.ref||a._===(n=e.back)?r:n.$,i.ref._.soul&&f.val.is(i.data)&&e.get?(i.data=g({},e.get,i.data),i.ref.put(i.data,i.soul,i)):(i.ref.get(p,!0,{as:i}),i.out||(i.res=i.res||u,i.$._.stun=i.ref._.stun)),r)};var h=f.obj,d=h.is,g=h.put,e=h.map,v={},m=function(){},o=function(t,n){t.call(n||v)},k=f.node._})(_,"./put"),_(function(t){var n=_("./root");_("./chain"),_("./back"),_("./put"),_("./get"),t.exports=n})(_,"./index"),_(function(t){var f=_("./index");function u(t,n){var e,o=this,i=t.$,r=((i||{})._||{}).put||t.put;o.at;if(l!==r){if(e=t.$$){if(e=t.$$._,l===e.put)return;r=e.put}o.change&&(r=t.put),o.as?o.ok.call(o.as,t,n):o.ok.call(i,r,t.get,t,n)}}function c(t,n,e){if(t.$){var o,i,r=this.as,a=(r.at,t.$),u=a._,s=u.put||t.put;(i=t.$$)&&(o=i=t.$$._,l!==o.put&&(s=o.put)),(i=n.wait)&&(i=i[u.id])&&clearTimeout(i),n.ack=(n.ack||0)+1,!e&&l===s&&n.ack<=(r.acks||Object.keys(u.root.opt.peers).length)||(!e&&(l===s||u.soul||u.link||o&&!(0<o.ack))||l===s&&(i=Object.keys(u.root.opt.peers).length)&&!e&&(o||u).ack<i?i=(n.wait={})[u.id]=setTimeout(function(){c.call({as:r},t,n,i||1)},r.wait||99):(o&&l===o.put&&(i=p.is(s))&&(s=f.node.ify({},i)),n.rid?n.rid(t):n.off(),r.ok.call(a||r.$,s,t.get)))}else n.off()}f.chain.on=function(t,n,e,o){var i,r=this._;if("string"==typeof t)return n?(i=r.on(t,n,e||r,o),e&&e.$&&(e.subs||(e.subs=[])).push(i),this):r.on(t);var a=n;return(a=!0===a?{change:!0}:a||{}).at=r,a.ok=t,this.get(u,a),this},f.chain.val=function(t,n){return f.log.once("onceval","Future Breaking API Change: .val -> .once, apologies unexpected."),this.once(t,n)},f.chain.once=function(t,n){var e=this,o=e._,i=o.put;if(0<o.ack&&l!==i)return(t||a).call(e,i,o.get),e;if(t)return(n=n||{}).ok=t,n.at=o,n.out={"#":f.text.random(9)},e.get(c,{as:n}),n.async=!0,e;f.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");var r=e.chain();return r._.nix=e.once(function(){r._.on("in",e._)}),r},f.chain.off=function(){var t,n=this._,e=n.back;if(e)return n.ack=0,(t=e.next)&&t[n.get]&&i(t,n.get),(t=e.ask)&&i(t,n.get),(t=e.put)&&i(t,n.get),(t=n.soul)&&i(e.root.graph,t),(t=n.map)&&o(t,function(t){t.link&&e.root.$.get(t.link).off()}),(t=n.next)&&o(t,function(t){t.$.off()}),n.on("off",{}),this};var l,n=f.obj,o=n.map,i=(n.has,n.del),p=(n.to,f.val.link),a=function(){}})(_,"./on"),_(function(t){var u=_("./index");function i(t){if(!t.put||u.val.is(t.put))return this.to.next(t);this.as.nix&&this.off(),e(t.put,n,{at:this.as,msg:t}),this.to.next(t)}function n(t,n){if(a!==n){var e=this.msg.$,o=e._,i=this.at,r=o.lex;r&&!u.text.match(n,r["."]||r["#"]||r)||(((r=e.get(n)._).echo||(r.echo={}))[i.id]=r.echo[i.id]||i)}}u.chain.map=function(r,t,n){var a,e=this,o=e._;return r?(u.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),a=e.chain(),e.map().on(function(t,n,e,o){var i=(r||s).call(this,t,n,e,o);if(void 0!==i)return t===i?a._.on("in",e):u.is(i)?a._.on("in",i._):void a._.on("in",{get:n,put:i})})):(a=o.each)||(o.each=a=e.chain(),a._.nix=e.back("nix"),e.on("in",i,a._)),a};var e=u.obj.map,s=function(){},a=u.node._})(_,"./map"),_(function(t){var a=_("./index");a.chain.set=function(t,o,i){var n,r=this;return o=o||function(){},(i=i||{}).item=i.item||t,(n=a.node.soul(t))&&(t=a.obj.put({},n,a.val.link.ify(n))),a.is(t)?(t.get(function(t,n,e){if(!t)return o.call(r,{err:a.log('Only a node can be linked! Not "'+e.put+'"!')});r.put(a.obj.put({},t,a.val.link.ify(t)),o,i)},!0),t):(a.obj.is(t)&&(t=r.back(-1).get(n=n||a.node.soul(t)||r.back("opt.uuid")()).put(t)),r.get(n||a.state.lex()+a.text.random(7)).put(t,o,i))}})(_,"./set"),_(function(t){if("undefined"!=typeof Gun){var p;try{p=(Gun.window||function(){}).localStorage}catch(t){}p||(Gun.log("Warning: No localStorage exists to persist data to!"),p={setItem:function(t,n){this[t]=n},removeItem:function(t){delete this[t]},getItem:function(t){return this[t]}}),Gun.on("create",function(t){var n=this.to,e=t.opt;if(t.once)return n.next(t);if(!1===e.localStorage)return n.next(t);e.prefix=e.file||"gun/";var i,o,r=Gun.obj.ify(p.getItem("gap/"+e.prefix))||{},a=Gun.obj.empty;if(!a(r)){var u=Gun.obj.ify(p.getItem(e.prefix))||{},s={};Gun.obj.map(r,function(t,e){Gun.obj.map(t,function(t,n){s[e]=Gun.state.to(u[e],n,s[e])})}),setTimeout(function(){t.on("out",{put:s,"#":t.ask(f)})},1)}function f(t){if(!t.err&&t.ok){var o=t["@"];setTimeout(function(){Gun.obj.map(r,function(e,t){Gun.obj.map(e,function(t,n){o===t&&delete e[n]}),a(e)&&delete r[t]}),l()},e.wait||1)}}t.on("out",function(t){t.lS||(Gun.is(t.$)&&t.put&&!t["@"]&&(i=t["#"],Gun.graph.is(t.put,null,c),o=o||setTimeout(l,e.wait||1)),this.to.next(t))}),t.on("ack",f),n.next(t);var c=function(t,n,e,o){(r[o]||(r[o]={}))[n]=i},l=function(){clearTimeout(o),o=!1;try{p.setItem("gap/"+e.prefix,JSON.stringify(r))}catch(t){Gun.log(err=t||"localStorage failure")}}}),Gun.on("create",function(a){this.to.next(a);var o=a.opt;if(!a.once&&!1!==o.localStorage){o.prefix=o.file||"gun/";a.graph;var i,r={},u=0,s=Gun.obj.ify(p.getItem(o.prefix))||{};a.on("localStorage",s),a.on("put",function(t){if(this.to.next(t),Gun.graph.is(t.put,null,n),t["@"]||(r[t["#"]]=!0),(u+=1)>=(o.batch||1e3))return f();i=i||setTimeout(f,o.wait||1)}),a.on("get",function(n){this.to.next(n);var e,o,i,r=n.get;function t(){if(r&&(e=r["#"])){var t=r["."];(o=s[e]||i)&&t&&(o=Gun.state.to(o,t)),a.on("in",{"@":n["#"],put:Gun.graph.node(o),how:"lS",lS:n.$})}}Gun.debug?setTimeout(t,1):t()});var n=function(t,n,e,o){s[o]=Gun.state.to(e,n,s[o])},f=function(t){var e;u=0,clearTimeout(i),i=!1;var n=r;r={},t&&(s=t);try{p.setItem(o.prefix,JSON.stringify(s))}catch(t){Gun.log(e=(t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),a.on("localStorage:error",{err:e,file:o.prefix,flush:s,retry:f})}(e||Gun.obj.empty(o.peers))&&Gun.obj.map(n,function(t,n){a.on("in",{"@":n,err:e,ok:0})})}}})}})(_,"./adapters/localStorage"),_(function(t){var m=_("../type"),k="undefined"!=typeof setImmediate?setImmediate:setTimeout;function b(t){return t||{_:t._,"##":t["##"]}}!function(){m.text.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var e=0,o=t.length;e<o;++e)n=(n<<5)-n+t.charCodeAt(e),n|=0;return n};var e=JSON.stringify;function o(t,n){var e;return n instanceof Object?(m.obj.map(Object.keys(n).sort(),i,{to:e={},on:n}),e):n}function i(t){this.to[t]=this.on[t]}m.obj.hash=function(t,n){if(n||void 0!==(t=e(t,o)))return m.text.hash(n||t||"")},m.obj.hash.sort=o}();var y=e.LOG;try{t.exports=function(s){var f=function(){},c=s.opt||{};c.log=c.log||e.log,c.gap=c.gap||c.wait||1,c.pack=c.pack||.3*(c.memory?1e3*c.memory*1e3:1399e6);var l=s.dup;f.hear=function(t,i){if(t){var r,n,e,o=t[0];if(c.pack<=t.length)return f.say({dam:"!",err:"Message too big!"},i);if("{"!=t[2]&&(f.hear.d+=t.length||0,++f.hear.c),"["===o){try{r=JSON.parse(t)}catch(t){c.log("DAM JSON parse error",t)}if(!r)return;return y&&c.log(+new Date,r.length,"in hear batch"),void function t(){var n;y&&(n=+new Date);for(var e,o=100;o--&&(e=r.shift());)f.hear(e,i);y&&c.log(n,new Date-n,"batch heard"),r.length&&k(t,0)}()}if("{"===o||m.obj.is(t)&&(r=t)){try{r=r||JSON.parse(t)}catch(t){return c.log("DAM JSON parse error",t)}if(!r)return;if((n=r["#"])||(n=r["#"]=m.text.random(9)),r.DBG_s&&c.log(new Date-r.DBG_s,"to hear",n),l.check(n))return;if(l.track(n,!0).it=b(r),(e=r["##"])||void 0===r.put||(e=r["##"]=m.obj.hash(r.put)),e&&(o=r["@"]||r.get&&n)){if(l.check(o+e))return;l.track(o+e,!0).it=b(r)}return(r._=function(){}).via=i,(o=r["><"])&&(r._.to=m.obj.map(o.split(","),h)),r.dam?void((o=f.hear[r.dam])&&o(r,i,s)):(y&&(a=+new Date),s.on("in",r),void(y&&!r.nts&&9<(u=new Date-a)&&c.log(a,u,"msg",r["#"])));var a,u}}};var u,p,h=function(t,n,e){e(t,!0)};function d(t){f.say(u,t)}function g(t){var n=t.batch;if(t.batch=t.tail=null,n&&n.length){var e;y&&(e=+new Date);try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return c.log("DAM JSON stringify error",t)}y&&c.log(e,new Date-e,"say stringify",n.length),n&&v(n,t)}}function v(n,e){try{var t,o,i=e.wire;y&&(t=+new Date),e.say?e.say(n):i.send&&i.send(n),y&&9<(o=new Date-t)&&c.log(t,o,"wire send",n.length),f.say.d+=n.length||0,++f.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}f.hear.c=f.hear.d=0,p=0,f.say=function(t,n){if(this.to&&this.to.next(t),!t)return!1;var e,o,i,r;y&&new Date;var a=t._||(t._=function(){});if((e=t["#"])||(e=t["#"]=m.text.random(9)),(o=t["##"])||void 0===t.put||(o=t["##"]=m.obj.hash(t.put)),!(r=a.raw)&&(r=f.raw(t),o&&(i=t["@"])&&(l.track(i+o).it=b(t),i=(l.s[i]||!0).it))){if(o===i["##"])return!1;i["##"]=o}if(l.track(e).it=b(t),!(n=n||(i=l.s[t["@"]])&&(i=i.it)&&(i=i._)&&(i=i.via))&&t["@"])return y&&c.log(+new Date,++p,"total no peer to ack to"),!1;if(!n&&f.way)return f.way(t);if(!n||!n.id)return u=t,!!m.obj.is(n||c.peers)&&void m.obj.map(n||c.peers,d);if(!n.wire&&f.wire&&f.wire(n),e!==n.last){if(n.last=e,n===a.via)return!1;if((i=a.to)&&(i[n.url]||i[n.pid]||i[n.id]))return!1;if(n.batch){if(n.tail=(i=n.tail||0)+r.length,n.tail<=c.pack)return void n.batch.push(r);g(n)}n.batch=[],setTimeout(function(){g(n)},c.gap),v(r,n)}},f.say.c=f.say.d=0,function(){f.raw=function(t){if(!t)return"";var n,e=t._||{};if(n=e.raw)return n;if("string"==typeof t)return t;if(!t.dam){var o=0,i=[];m.obj.map(c.peers,function(t){if(i.push(t.url||t.pid||t.id),3<++o)return!0}),1<o&&(t["><"]=i.join())}var r=a(t);return e&&(r||"").length<1e5&&(e.raw=r),r};var a=JSON.stringify}(),f.hi=function(n){var t=n.wire||{};n.id?c.peers[n.url||n.id]=n:(t=n.id=n.id||m.text.random(9),f.say({dam:"?",pid:s.opt.pid},c.peers[t]=n),delete l.s[n.last]),n.met=n.met||+new Date,t.hied||s.on(t.hied="hi",n),t=n.queue,n.queue=[],m.obj.map(t,function(t){v(t,n)})},f.bye=function(t){s.on("bye",t);var n=+new Date;n-=t.met||n,f.bye.time=((f.bye.time||n)+n)/2,y=e.LOG},f.hear["!"]=function(t,n){c.log("Error:",t.err)},f.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(f.say({dam:"?",pid:c.pid,"@":t["#"]},n),delete l.s[n.last])},s.on("create",function(t){t.opt.pid=t.opt.pid||m.text.random(9),this.to.next(t),t.on("out",f.say)}),s.on("bye",function(t,n){t=c.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),m.obj.del(c.peers,t.id),t.wire=null});var i={};return s.on("bye",function(t,n){this.to.next(t),(n=t.url)&&(i[n]=!0,setTimeout(function(){delete i[n]},c.lack||9e3))}),s.on("hi",function(e,o){this.to.next(e),(o=e.url)&&i[o]&&(delete i[o],m.obj.map(s.next,function(t,n){(o={})[n]=s.graph[n],f.say({"##":m.obj.hash(o),get:{"#":n}},e)}))}),f}}catch(t){}})(_,"./adapters/mesh"),_(function(t){var f=_("../index");f.Mesh=_("./mesh"),f.on("opt",function(t){this.to.next(t);var o=t.opt;if(!t.once&&!1!==o.WebSocket){var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var e=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(e){o.WebSocket=e;var i=o.mesh=o.mesh||f.Mesh(t);i.wire||o.wire;i.wire=o.wire=u,setTimeout(function(){t.on("out",{dam:"hi"})},1);var r=2e3,a="undefined"!=typeof document&&document}}function u(n){try{if(!n||!n.url)return e&&e(n);var t=n.url.replace("http","ws"),e=n.wire=new o.WebSocket(t);return e.onclose=function(){o.mesh.bye(n),s(n)},e.onerror=function(t){s(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function s(n){clearTimeout(n.defer),a&&n.retry<=0||(n.retry=(n.retry||o.retry||60)-1,n.defer=setTimeout(function t(){if(a&&a.hidden)return setTimeout(t,r);u(n)},r))}})})(_,"./adapters/websocket")}();