-
Notifications
You must be signed in to change notification settings - Fork 0
/
gun.min.js
1 lines (1 loc) · 32.3 KB
/
gun.min.js
1
!function(){var t;"undefined"!=typeof window&&(t=window),"undefined"!=typeof global&&(t=global);var b=(t=t||{}).console||{log:function(){}};function _(o,t){return t?require(o):o.slice?_[i(o)]:function(t,n){o(t={exports:{}}),_[i(n)]=t.exports};function i(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var f=module;_(function(t){var p={fn:{is:function(t){return!!t&&"function"==typeof t}}};p.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},p.num={is:function(t){return!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},p.text={is:function(t){return"string"==typeof t}},p.text.ify=function(t){return p.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},p.text.random=function(t,n){var o="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0<t;)o+=n.charAt(Math.floor(Math.random()*n.length)),t--;return o},p.text.match=function(n,t){var o=!1;if(n=n||"",t=p.text.is(t)?{"=":t}:t||{},p.obj.has(t,"~")&&(n=n.toLowerCase(),t["="]=(t["="]||t["~"]).toLowerCase()),p.obj.has(t,"="))return n===t["="];if(p.obj.has(t,"*")){if(n.slice(0,t["*"].length)!==t["*"])return!1;o=!0,n=n.slice(t["*"].length)}if(p.obj.has(t,"!")){if(n.slice(-t["!"].length)!==t["!"])return!1;o=!0}if(p.obj.has(t,"+")&&p.list.map(p.list.is(t["+"])?t["+"]:[t["+"]],function(t){if(!(0<=n.indexOf(t)))return!0;o=!0}))return!1;if(p.obj.has(t,"-")&&p.list.map(p.list.is(t["-"])?t["-"]:[t["-"]],function(t){if(!(n.indexOf(t)<0))return!0;o=!0}))return!1;if(p.obj.has(t,">")){if(!(n>t[">"]))return!1;o=!0}if(p.obj.has(t,"<")){if(!(n<t["<"]))return!1;o=!0}if(p.obj.has(t,"?")){if(!function(t,n){for(var o,i=-1,e=0;o=n[e++];)if(!~(i=t.indexOf(o,i+1)))return!1;return!0}(n,t["?"]))return!1;o=!0}return o},p.list={is:function(t){return t instanceof Array}},p.list.slit=Array.prototype.slice,p.list.sort=function(o){return function(t,n){return t&&n?(t=t[o])<(n=n[o])?-1:n<t?1:0:0}},p.list.map=function(t,n,o){return i(t,n,o)},p.list.index=1,p.obj={is:function(t){return!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},p.obj.put=function(t,n,o){return(t||{})[n]=o,t},p.obj.has=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},p.obj.del=function(t,n){if(t)return t[n]=null,delete t[n],t},p.obj.as=function(t,n,o,i){return t[n]=t[n]||(i===o?{}:o)},p.obj.ify=function(n){if(g(n))return n;try{n=JSON.parse(n)}catch(t){n={}}return n},function(){function o(t,n){v(this,n)&&void 0!==this[n]||(this[n]=t)}p.obj.to=function(t,n){return i(t,o,n=n||{}),n}}(),p.obj.copy=function(t){return t?JSON.parse(JSON.stringify(t)):t},function(){function o(t,n){var o=this.n;if(!o||!(n===o||g(o)&&v(o,n)))return!!n||void 0}p.obj.empty=function(t,n){return!t||!i(t,o,{n:n})}}(),function(){function c(t,n){2!==arguments.length?(c.r=c.r||[]).push(t):(c.r=c.r||{})[t]=n}var l=Object.keys;p.obj.map=function(t,n,o){var i,e,r,a,u=0,s=h(n);if(c.r=null,l&&g(t)&&(r=l(t),a=!0),d(t)||r)for(i=(r||t).length;u<i;u++){var f=u+p.list.index;if(s){if(void 0!==(e=a?n.call(o||this,t[r[u]],r[u],c):n.call(o||this,t[u],f,c)))return e}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!==(e=o?n.call(o,t[u],u,c):n(t[u],u,c)))return e}else if(n===t[u])return u;return s?c.r:p.list.index?0:-1}}(),p.time={},p.time.is=function(t){return t?t instanceof Date:+(new Date).getTime()};var h=p.fn.is,d=p.list.is,n=p.obj,g=n.is,v=n.has,i=n.map;t.exports=p})(_,"./type"),_(function(t){t.exports=function t(n,o,i){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(o instanceof Function){var e={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:o,the:n,on:this,as:i};return(e.back=n.last||n).to=e,n.last=e}return(n=n.to)&&void 0!==o&&n.next(o),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,o,i,e){if(t<n)return{defer:!0};if(n<o)return{historical:!0};if(o<n)return{converge:!0,incoming:!0};if(n===o){if((i=r(i)||"")===(e=r(e)||""))return{state:!0};if(i<e)return{converge:!0,current:!0};if(e<i)return{converge:!0,incoming:!0}}return{err:"Invalid CRDT Data: "+i+" to "+e+" at "+n+" to "+o+"!"}}})(_,"./HAM"),_(function(t){var n=_("./type"),i={is:function(t){return void 0!==t&&(null===t||t!==1/0&&(!!(a(t)||o(t)||r(t))||(i.link.is(t)||!1)))}};i.link=i.rel={_:"#"},function(){function o(t,n){return this.id?this.id=!1:n==e&&a(t)?void(this.id=t):this.id=!1}i.link.is=function(t){if(t&&t[e]&&!t._&&s(t)){var n={};if(c(t,o,n),n.id)return n.id}return!1}}(),i.link.ify=function(t){return f({},e,t)},n.obj.has._=".";var e=i.link._,o=n.bi.is,r=n.num.is,a=n.text.is,u=n.obj,s=u.is,f=u.put,c=u.map;t.exports=i})(_,"./val"),_(function(t){var n=_("./type"),r=_("./val"),a={_:"_",soul:function(t,n){return t&&t._&&t._[n||f]}};a.soul.ify=function(t,n){return n="string"==typeof n?{soul:n}:n||{},(t=t||{})._=t._||{},t._[f]=n.soul||t._[f]||i(),t},a.soul._=r.link._,function(){function e(t,n){if(n!==a._)return!r.is(t)||void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s))}a.is=function(t,n,o){var i;return!!u(t)&&(!!(i=a.soul(t))&&!s(t,e,{as:o,cb:n,s:i,n:t}))}}(),function(){function i(t,n){var o,i=this.o;i.map?void 0===(o=i.map.call(this.as,t,""+n,i.node))?e(i.node,n):i.node&&(i.node[n]=o):r.is(t)&&(i.node[n]=t)}a.ify=function(t,n,o){return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n={map:n}):n={},n.map&&(n.node=n.map.call(o,t,void 0,n.node||{})),(n.node=a.soul.ify(n.node||{},n))&&s(t,i,{o:n,as:o}),n.node}}();var o=n.obj,u=o.is,e=o.del,s=o.map,i=n.text.random,f=a.soul._;t.exports=a})(_,"./node"),_(function(t){var n=_("./type"),a=_("./node");function s(){var t;return t=o(),i=i<t?(e=0,t+s.drift):t+(e+=1)/r+s.drift}var o=n.time.is,i=-1/0,e=0,r=1e3,u="undefined"!=typeof performance&&(performance.timing&&performance);u&&u.timing&&u.timing.navigationStart||(u=!1);s._=">",s.drift=0,s.is=function(t,n,o){var i=n&&t&&t[m]&&t[m][s._]||o;if(i)return g(i=i[n])?i:-1/0},s.lex=function(){return s().toString(36).replace(".","")},s.ify=function(t,n,o,i,e){if(!t||!t[m]){if(!e)return;t=a.soul.ify(t,e)}var r=c(t[m],s._);return void 0!==n&&n!==m&&(g(o)&&(r[n]=o),void 0!==i&&(t[n]=i)),t},s.to=function(t,n,o){var i=(t||{})[n];return p(i)&&(i=d(i)),s.ify(o,n,s.is(t,n),i,a.soul(t))},function(){function u(t,n){m!==n&&s.ify(this.o,n,this.s)}s.map=function(e,r,a){var t=p(t=e||r)?t:null;return e=v(e=e||r)?e:null,t&&!e?(r=g(r)?r:s(),t[m]=t[m]||{},h(t,u,{o:t,s:r}),t):(a=a||p(r)?r:void 0,r=g(r)?r:s(),function(t,n,o,i){if(!e)return u.call({o:o,s:r},t,n),t;e.call(a||this||{},t,n,o,i),l(o,n)&&void 0===o[n]||u.call({o:o,s:r},t,n)})}}();var f=n.obj,c=f.as,l=f.has,p=f.is,h=f.map,d=f.copy,g=n.num.is,v=n.fn.is,m=a._;t.exports=s})(_,"./state"),_(function(t){var a=_("./type"),f=_("./val"),c=_("./node"),r={};!function(){function e(t,n){if(!t||n!==c.soul(t)||!c.is(t,this.fn,this.as))return!0;this.cb&&(o.n=t,o.as=this.as,this.cb.call(o.as,t,n,o))}function o(t){t&&c.is(o.n,t,o.as)}r.is=function(t,n,o,i){return!(!t||!l(t)||u(t))&&!s(t,e,{cb:n,fn:o,as:i})}}(),function(){function u(t,n){var o;return(o=function(t,n){var o,i=t.seen,e=i.length;for(;e--;)if(o=i[e],n.obj===o.obj)return o;i.push(n)}(t,n))?o:(n.env=t,n.soul=e,c.ify(n.obj,i,n)&&(n.link=n.link||f.link.ify(c.soul(n.node)),n.obj!==t.shell&&(t.graph[f.link.is(n.link)]=n.node)),n)}function i(t,n,o){var i,e,r=this,a=r.env;if(c._===n&&h(t,f.link._))return o._;if(i=s(t,n,o,r,a)){if(n||(r.node=r.node||o||{},h(t,c._)&&c.soul(t)&&(r.node._=d(t._)),r.node=c.soul.ify(r.node,f.link.is(r.link)),r.link=r.link||f.link.ify(c.soul(r.node))),(e=a.map)&&(e.call(a.as||{},t,n,o,r),h(o,n))){if(void 0===(t=o[n]))return void p(o,n);if(!(i=s(t,n,o,r,a)))return}if(!n)return r.node;if(!0===i)return t;if((e=u(a,{obj:t,path:r.path.concat(n)})).node)return e.link}}function e(t){var n=this,o=f.link.is(n.link),i=n.env.graph;n.link=n.link||f.link.ify(t),n.link[f.link._]=t,n.node&&n.node[c._]&&(n.node[c._][f.link._]=t),h(i,o)&&(i[t]=i[o],p(i,o))}function s(t,n,o,i,e){var r;return!!f.is(t)||(l(t)?1:(r=e.invalid)?s(t=r.call(e.as||{},t,n,o),n,o,i,e):(e.err="Invalid value at '"+i.path.concat(n).join(".")+"'!",void(a.list.is(t)&&(e.err+=" Use `.set(item)` instead of an Array."))))}r.ify=function(t,n,o){var i={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n.map=n):n={},n.soul&&(i.link=f.link.ify(n.soul)),n.shell=(o||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||o,u(n,i),n.root=i.node,n.graph}}(),r.node=function(t){var n=c.soul(t);if(n)return o({},n,t)},function(){function e(t,n){var o,i;if(c._!==n)(o=f.link.is(t))?(i=this.opt.seen[o])?this.obj[n]=i:this.obj[n]=this.opt.seen[o]=r.to(this.graph,o,this.opt):this.obj[n]=t;else{if(u(t,f.link._))return;this.obj[n]=d(t)}}r.to=function(t,n,o){if(t){var i={};return o=o||{seen:{}},s(t[n],e,{obj:i,graph:t,opt:o}),i}}}();a.fn.is;var n=a.obj,l=n.is,p=n.del,h=n.has,u=n.empty,o=n.put,s=n.map,d=n.copy;t.exports=r})(_,"./graph"),_(function(t){_("./onto"),t.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var o=t["#"]||t,i=(this.tag||empty)[o];if(!i)return;return i=this.on(o,n),clearTimeout(i.err),!0}o=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return o;var e=this.on(o,t,n);return e.err=e.err||setTimeout(function(){e.next({err:"Error: No ACK received yet.",lack:!0}),e.off()},(this.opt||{}).lack||9e3),o}}})(_,"./ask"),_(function(t){var r=_("./type");var a=r.time.is;t.exports=function(i){var e={s:{}};return i=i||{max:1e3,age:9e3},e.check=function(t){var n;return!!(n=e.s[t])&&(n.pass?n.pass=!1:e.track(t))},e.track=function(t,n){var o=e.s[t]||(e.s[t]={});return o.was=a(),n&&(o.pass=!0),e.to||(e.to=setTimeout(function(){var o=a();r.obj.map(e.s,function(t,n){t&&i.age>o-t.was||r.obj.del(e.s,n)}),e.to=null},i.age+9)),o},e}})(_,"./dup"),_(function(t){function c(t){return t instanceof c?(this._={gun:this,$:this}).$:this instanceof c?c.create(this._={gun:this,$:this,opt:t}):new c(t)}c.is=function(t){return t instanceof c||t&&t._&&t===t._.$||!1},c.version=.9,(c.chain=c.prototype).toJSON=function(){};var n=_("./type");n.obj.to(n,c),c.HAM=_("./HAM"),c.val=_("./val"),c.node=_("./node"),c.state=_("./state"),c.graph=_("./graph"),c.on=_("./onto"),c.ask=_("./ask"),c.dup=_("./dup"),function(){function a(t){var n,o,i=this.as,e=i.at||i,r=e.$;(o=t["#"])||(o=t["#"]=u(9)),(n=e.dup).check(o)?i.out===t.out&&(t.out=void 0,this.to.next(t)):(n.track(o),e.ask(t["@"],t)||(t.get&&c.on.get(t,r),t.put&&c.on.put(t,r)),this.to.next(t),i.out||(t.out=a,e.on("out",t)))}c.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||c.on,t.ask=t.ask||c.ask,t.dup=t.dup||c.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",a,t),t.on("out",a,{at:t,out:a}),c.on("create",t),t.on("create",t)),t.once=1,n}}(),function(){function e(t,n,o,i){var e=this,r=c.state.is(o,n);if(!r)return e.err="Error: No state on '"+n+"' in node '"+i+"'!";var a=e.graph[i]||v,u=c.state.is(a,n,!0),s=a[n],f=c.HAM(e.machine,r,u,t,s);f.incoming?(e.put[i]=c.state.to(o,n,e.put[i]),(e.diff||(e.diff={}))[i]=c.state.to(o,n,e.diff[i]),e.souls[i]=!0):f.defer&&(e.defer=r<(e.defer||1/0)?r:e.defer)}function r(t,n){var o=this,i=o.$._,e=(i.next||v)[n];if(!e){if(!(i.opt||v).super)return void(o.souls[n]=!1);e=o.$.get(n)._}var r=o.map[n]={put:t,get:n,$:e.$},a={ctx:o,msg:r};o.async=!!i.tag.node,o.ack&&(r["@"]=o.ack),h(t,u,a),o.async&&(o.and||i.on("node",function(t){this.to.next(t),t===o.map[t.get]&&(o.souls[t.get]=!1,h(t.put,s,t),h(o.souls,function(t){if(t)return t})||o.c||(o.c=1,this.off(),h(o.map,f,o)))}),o.and=!0,i.on("node",r))}function u(t,n){var o=this.ctx,i=o.graph,e=this.msg,r=e.get,a=e.put,u=e.$._;i[r]=c.state.to(a,n,i[r]),o.async||(u.put=c.state.to(a,n,u.put))}function s(t,n){var o=this.put,i=this.$._;i.put=c.state.to(o,n,i.put)}function f(t,n){t.$&&(this.cat.stop=this.stop,t.$._.on("in",t),this.cat.stop=null)}c.on.put=function(t,n){var o=n._,i={$:n,graph:o.graph,put:{},map:{},souls:{},machine:c.state(),ack:t["@"],cat:o,stop:{}};if(c.graph.is(t.put,null,e,i)||(i.err="Error: Invalid graph!"),i.err)return o.on("in",{"@":t["#"],err:c.log(i.err)});h(i.put,r,i),i.async||h(i.map,f,i),void 0!==i.defer&&setTimeout(function(){c.on.put(t,n)},i.defer-i.machine),i.diff&&o.on("put",p(t,{put:i.diff}))},c.on.get=function(t,n){var o=n._,i=t.get,e=i[d],r=o.graph[e],a=i[g],u=(o.next||(o.next={}))[e];if(!r)return o.on("get",t);if(a){if("string"!=typeof a||!l(r,a))return o.on("get",t);r=c.state.to(r,a)}else r=c.obj.copy(r);r=c.graph.node(r),(u||v).ack,o.on("in",{"@":t["#"],how:"mem",put:r,$:n}),o.on("get",t)}}(),c.chain.opt=function(t){t=t||{};var n=this._,o=t.peers||t;return a(t)||(t={}),a(n.opt)||(n.opt=t),e(o)&&(o=[o]),i(o)&&(o=h(o,function(t,n,o){o(t,{url:t})}),a(n.opt.peers)||(n.opt.peers={}),n.opt.peers=p(o,n.opt.peers)),n.opt.peers=n.opt.peers||{},p(t,n.opt),c.on("opt",n),n.opt.uuid=n.opt.uuid||function(){return s()+u(12)},this};var i=c.list.is,o=c.text,e=o.is,u=o.random,r=c.obj,a=r.is,l=r.has,p=r.to,h=r.map,s=(r.copy,c.state.lex),d=c.val.link._,g=".",v=(c.node._,c.val.link.is,{});b.debug=function(t,n){return b.debug.i&&t===b.debug.i&&b.debug.i++&&(b.log.apply(b,arguments)||n)},(c.log=function(){return!c.log.off&&b.log.apply(b,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,o){return(o=c.log.once)[t]=o[t]||0,o[t]++||c.log(n)},c.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=c).window=window);try{void 0!==f&&(f.exports=c)}catch(t){}t.exports=c})(_,"./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 o=this._;if("string"==typeof t&&(t=t.split(".")),t instanceof Array){for(var i=0,e=t.length,r=o;i<e;i++)r=(r||s)[t[i]];return void 0!==r?n?this:r:(r=o.back)?r.$.back(t,n):void 0}if(t instanceof Function){var a;for(r={back:o};(r=r.back)&&void 0===(a=t(r,n)););return a}return u.num.is(t)?(o.back||o).$.back(t-1):this};var s={}})(_,"./back"),_(function(t){var s=_("./root");function r(t){var o,n,i=this.as,e=i.back,r=i.root;if(t.$||(t.$=i.$),this.to.next(t),o=t.get){if(i.lex&&(t.get=b(i.lex,t.get)),o["#"]||i.soul){if(o["#"]=o["#"]||i.soul,t["#"]||(t["#"]=y(9)),e=r.$.get(o["#"])._,o=o["."]){if(v(e.put,o)){if((n=(a=e.$.get(o)._).ack)||(a.ack=-1),e.on("in",{$:e.$,put:s.state.to(e.put,o),get:e.get}),n)return}else if("string"!=typeof o){var a={},u=(e.put||{})._;s.obj.map(e.put,function(t,n){s.text.match(n,o)&&(a[n]=t)}),s.obj.empty(a)||(a._=u,e.on("in",{$:e.$,put:a,get:e.get}))}}else{if((n=e.ack)||(e.ack=-1),v(e,"put")&&e.on("in",e),n)return;t.$=e.$}return r.ask(h,t),r.on("in",t)}if(r.now&&(r.now[i.id]=r.now[i.id]||!0,i.pass={}),o["."])return i.get?(t={get:{".":i.get},$:i.$},e.ask||(e.ask={}),e.ask[i.get]=t.$._):t={get:{},$:i.$},e.on("out",t);if(i.ack=i.ack||-1,i.get)return t.$=i.$,o["."]=i.get,(e.ask||(e.ask={}))[i.get]=t.$._,e.on("out",t)}return e.on("out",t)}function a(t){var n,o,i=this,e=i.as,r=e.root,a=(t.$||g)._||g,u=t.put;if(e.get&&t.get!==e.get&&(t=b(t,{get:e.get})),e.has&&a!==e&&(t=b(t,{$:e.$}),a.ack&&(e.ack=a.ack)),d===u){if(o=a.put,i.to.next(t),e.soul)return;if(d===o&&d!==a.put)return;return c(e,t,i),e.has&&p(e,t),m(a.echo,e.id),void m(e.map,a.id)}if(e.soul)return i.to.next(t),c(e,t,i),void(e.next&&k(u,l,{msg:t,cat:e}));if(!(n=s.val.link.is(u)))return s.val.is(u)?(e.has||e.soul?p(e,t):(a.has||a.soul)&&((a.echo||(a.echo={}))[e.id]=a.echo[a.id]||e,(e.map||(e.map={}))[a.id]=e.map[a.id]||{at:a}),i.to.next(t),void c(e,t,i)):(e.has&&a!==e&&v(a,"put")&&(e.put=a.put),(n=s.node.soul(u))&&a.has&&(a.put=e.root.$.get(n)._.put),o=(r.stop||{})[a.id],i.to.next(t),f(e,t,a,n),c(e,t,i),void(e.next&&k(u,l,{msg:t,cat:e})));r.stop;(o=(o=r.stop||{})[a.id]||(o[a.id]={})).is=o.is||a.put,o[e.id]=a.put||!0,i.to.next(t),f(e,t,a,n),c(e,t,i)}function f(t,n,o,i){if(i&&u!==t.get){var e=t.root.$.get(i)._;t.has?o=e:o.has&&f(o,n,o,i),o!==t&&(o.$||(o={}),(o.echo||(o.echo={}))[t.id]=o.echo[t.id]||t,t.has&&!(t.map||g)[o.id]&&p(t,n),(i!==(e=o.id?(t.map||(t.map={}))[o.id]=t.map[o.id]||{at:o}:{}).link||e.pass||t.pass)&&(t.pass&&(s.obj.map(t.map,function(t){t.pass=!0}),m(t,"pass")),e.pass&&m(e,"pass"),t.has&&(t.link=i),function(t,o){var n=t.root.$.get(o)._;if(t.ack&&(n.on("out",{get:{"#":o}}),!t.ask))return;n=t.ask,s.obj.del(t,"ask"),k(n||t.next,function(t,n){t.on("out",{get:{"#":o,".":n}})}),s.obj.del(t,"ask")}(t,e.link=i)))}}function c(t,n,o){t.echo&&k(t.echo,i,n)}function i(t){t&&t.on&&t.on("in",this)}function l(t,n){var o,i,e,r=this.cat.next||g,a=this.msg;(u!==n||r[n])&&(i=r[n])&&(i.has?(d!==i.put&&s.val.link.is(t)||(i.put=t),o=i.$):(e=a.$)&&(e=(o=a.$.get(n))._,d!==e.put&&s.val.link.is(t)||(e.put=t)),i.on("in",{put:t,get:n,$:o,via:a}))}function p(o,t){if(o.has||o.soul){var i=o.map;o.root;o.map=null,o.has&&(o.dub&&o.root.stop&&(o.dub=null),o.link=null),(o.pass||t["@"]||null!==i)&&(d===i&&s.val.link.is(o.put)||(k(i,function(t){(t=t.at)&&m(t.echo,o.id)}),i=o.put,k(o.next,function(t,n){if(d===i&&d!==o.put)return!0;t.put=d,t.ack&&(t.ack=-1),t.on("in",{get:n,$:t.$,put:d})})))}}function h(t,n){var o=this.as,i=o.get||g,e=o.$._,r=(t.put||g)[i["#"]];if(e.ack&&(e.ack=e.ack+1||1),t.put&&("string"!=typeof i["."]||v(r,e.get)))u!=i["."]?s.on.put(t,e.root.$):e.on("in",{get:e.get,put:s.val.link.ify(i["#"]),$:e.$,"@":t["@"]});else{if(e.put!==d)return;e.on("in",{get:e.get,put:e.put=d,$:e.$,"@":t["@"]})}}s.chain.chain=function(t){var n,o=this._,i=new(t||this).constructor(this),e=i._;return e.root=n=o.root,e.id=++n.once,e.back=this._,e.on=s.on,e.on("in",a,e),e.on("out",r,e),i};var d,g={},n=s.obj,v=n.has,m=(n.put,n.del),b=n.to,k=n.map,y=s.text.random,u=(s.val.link._,s.node._)})(_,"./chain"),_(function(t){var f=_("./root");function c(t){var n,o=this,i=o.as,e=i.at.root,r=(t.$||{})._||{},a=t.put||r.put;if((n=e.now)&&o!==n[i.now])return o.to.next(t);if(o.seen&&r.id&&o.seen[r.id])return o.to.next(t);if((n=a)&&n[v._]&&(n=v.is(n))&&(n=(t.$$=r.root.gun.get(n))._,p!==n.put&&(t=s(t,{put:a=n.put}))),(n=e.mum)&&r.id){var u=r.id+(o.id||(o.id=f.text.random(9)));if(n[u])return;p===a||v.is(a)||(n[u]=!0)}i.use(t,o),o.stun?o.stun=null:o.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 o;n.map;if((o=this.seen||(this.seen={}))[t])return!0;o[t]=!0}}f.chain.get=function(t,n,o){var i;if("string"!=typeof t){if(t instanceof Function){if(!0===n)return function(t,i,n,e){var r,a=t._,u=0;if(r=a.soul||a.link||a.dub)return i(r,e,a),t;return t.get(function(t,n){if(!(p===t.put&&(r=(d(a.root.opt.peers,function(t,n,o){o(n)})||[]).length)&&++u<r)){n.rid(t);var o=(o=t.$)&&o._||{};r=o.link||o.soul||v.is(t.put)||m(t.put)||o.dub,i(r,e,t,n)}},{out:{get:{".":!0}}}),t}(this,t,0,o);var e,r=(i=this)._,a=r.root,u=a.now;(o=n||{}).at=r,o.use=t,o.out=o.out||{},o.out.get=o.out.get||{},(e=r.on("in",c,o)).rid=l,(a.now={$:1})[o.now=r.id]=e;var s=a.mum;return a.mum={},r.on("out",o.out),a.mum=s,a.now=u,i}return g(t)?this.get(""+t,n,o):(u=v.is(t))?this.get(u,n,o):h.is(t)?(i=this,(u=((u=t["#"])||b)["="]||u)&&(i=i.get(u)),i._.lex=t,i):((o=this.chain())._.err={err:f.log("Invalid get request!",t)},n&&n.call(o,o._.err),o)}return(i=(this._.next||b)[t])||(i=function(t,n){var o=n._,i=o.next,e=n.chain()._;i||(i=o.next={});i[e.get=t]=e,n===o.root.$?e.soul=t:(o.soul||o.has)&&(e.has=t);return e}(t,this)),i=i.$,(u=this._.stun)&&(i._.stun=i._.stun||u),n&&n instanceof Function&&i.get(n,o),i};var p,h=f.obj,d=h.map,s=(h.has,f.obj.to),g=f.num.is,v=f.val.link,m=f.node.soul,b=(f.node._,{})})(_,"./get"),_(function(t){var f=_("./root");function u(t){t&&t()}function s(){var e=this;e.graph&&!o(e.stun,n)&&(e.res=e.res||function(t){t&&t()},e.res(function(){var n=e.$.back(-1)._,t=n.ask(function(t){n.root.on("ack",t),t.err&&f.log(t),t.lack||this.off(),e.ack&&e.ack(t,this)},e.opt),o=n.root.now;r.del(n.root,"now");var i=n.root.mum;n.root.mum={},e.ref._.on("out",{$:e.ref,put:e.out=e.env.graph,opt:e.opt,"#":t}),n.root.mum=i?r.to(i,n.root.mum):i,n.root.now=o},e),e.res&&e.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||i)(function(){for(var t=a.path,n=u.ref,o=(u.opt,0),i=t.length;o<i;o++)n=n.get(t[o]);s&&(n=r);var e=n._.dub;if(e||(e=f.node.soul(a.obj)))return n.back(-1).get(e),void a.soul(e);(u.stun=u.stun||{})[t]=!0,n.get(l,!0,{as:{at:a,as:u,p:t}})},{as:u,at:a})}function l(t,o,n,i){var e=(o=o.as).at;o=o.as;var r=((n||{}).$||{})._||{};t=r.dub=r.dub||t||f.node.soul(e.obj)||f.node.soul(n.put||r.put)||f.val.link.is(n.put||r.put)||(o.via.back("opt.uuid")||f.text.random)(),i&&(i.stun=!0),t?a(r,r.dub=t,e,o):r.via.back("opt.uuid")(function(t,n){if(t)return f.log(t);a(r,r.dub=r.dub||n,e,o)})}function a(t,n,o,i){t.$.back(-1).get(n),o.soul(n),i.stun[o.path]=!1,i.batch()}function p(t,o,n,i){if(o=o.as,n.$&&n.$._)if(n.err)b.log("Please report this as an issue! Put.any.err");else{var e,r=n.$._,a=r.put,u=o.opt||{};if(!(e=o.ref)||!e._.now){if(i&&(i.stun=!0),o.ref!==o.$){if(!(e=o.$._.get||r.get))return void b.log("Please report this as an issue! Put.no.get");o.data=d({},e,o.data),e=null}if(void 0===a){if(!r.get)return;t||(e=r.$.back(function(t){if(t.link||t.soul)return t.link||t.soul;o.data=d({},t.get,o.data)})),r=(e=e||r.soul||r.link||r.dub)?r.root.$.get(e)._:r,o.soul=e,a=o.data}o.not||(o.soul=o.soul||t)||(o.path&&h(o.data)?o.soul=(u.uuid||o.via.back("opt.uuid")||f.text.random)():(m==r.get&&(o.soul=(r.put||g)["#"]||r.dub),o.soul=o.soul||r.soul||r.link||(u.uuid||o.via.back("opt.uuid")||f.text.random)()),o.soul)?o.ref.put(o.data,o.soul,o):o.via.back("opt.uuid")(function(t,n){if(t)return f.log(t);o.ref.put(o.data,o.soul=n,o)})}}}f.chain.put=function(t,i,e){var n,r=this,o=r._,a=o.root.$;return(e=e||{}).data=t,e.via=e.$=e.via||e.$||r,"string"==typeof i?e.soul=i:e.ack=e.ack||i,o.soul&&(e.soul=o.soul),e.soul||a===r?h(e.data)?(e.soul=e.soul||(e.not=f.node.soul(e.data)||(e.via.back("opt.uuid")||f.text.random)()),e.soul?(e.$=a.get(e.soul),e.ref=e.$,function(t){t.batch=s;var n=t.opt||{},o=t.env=f.state.map(c,n.state);if(o.soul=t.soul,t.graph=f.graph.ify(t.data,o,t),o.err)return(t.ack||v).call(t,t.out={err:f.log(o.err)}),t.res&&t.res();t.batch()}(e)):e.via.back("opt.uuid")(function(t,n){if(t)return f.log(t);(e.ref||e.$).put(e.data,e.soul=n,e)}),r):((e.ack||v).call(e,e.out={err:f.log("Data saved to the root level of the graph must be a node (an object), not a",typeof e.data,'of "'+e.data+'"!')}),e.res&&e.res(),r):f.is(t)?(t.get(function(t,n,o){if(!t&&f.val.is(o.put))return f.log("The reference you are saving is a",typeof o.put,'"'+o.put+'", not a node (object)!');r.put(f.val.link.ify(t),i,e)},!0),r):(o.has&&(n=f.val.link.is(t))&&(o.dub=n),e.ref=e.ref||a._===(n=o.back)?r:n.$,e.ref._.soul&&f.val.is(e.data)&&o.get?(e.data=d({},o.get,e.data),e.ref.put(e.data,e.soul,e)):(e.ref.get(p,!0,{as:e}),e.out||(e.res=e.res||u,e.$._.stun=e.ref._.stun)),r)};var r=f.obj,h=r.is,d=r.put,o=r.map,g={},v=function(){},i=function(t,n){t.call(n||g)},m=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 o,i=this,e=t.$,r=((e||{})._||{}).put||t.put;i.at;if(l!==r){if(o=t.$$){if(o=t.$$._,l===o.put)return;r=o.put}i.change&&(r=t.put),i.as?i.ok.call(i.as,t,n):i.ok.call(e,r,t.get,t,n)}}function c(t,n,o){var i,e,r=this.as,a=(r.at,t.$),u=a._,s=u.put||t.put;(e=t.$$)&&(i=e=t.$$._,l!==i.put&&(s=i.put)),(e=n.wait)&&(e=e[u.id])&&clearTimeout(e),!o&&(l===s||u.soul||u.link||i&&!(0<i.ack))||l===s&&(e=(p(u.root.opt.peers,function(t,n,o){o(n)})||[]).length)&&!o&&(i||u).ack<=e?e=(n.wait={})[u.id]=setTimeout(function(){c.call({as:r},t,n,e||1)},r.wait||99):(i&&l===i.put&&(e=h.is(s))&&(s=f.node.ify({},e)),n.rid(t),r.ok.call(a||r.$,s,t.get))}f.chain.on=function(t,n,o,i){var e,r=this._;if("string"==typeof t)return n?(e=r.on(t,n,o||r,i),o&&o.$&&(o.subs||(o.subs=[])).push(e),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 o=this,i=o._,e=i.put;if(0<i.ack&&l!==e)return(t||a).call(o,e,i.get),o;if(t)return(n=n||{}).ok=t,n.at=i,n.out={"#":f.text.random(9)},o.get(c,{as:n}),n.async=!0,o;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=o.chain();return r._.nix=o.once(function(){r._.on("in",o._)}),r},f.chain.off=function(){var t,n=this._,o=n.back;if(o)return(t=o.next)&&t[n.get]&&i(t,n.get),(t=o.ask)&&i(t,n.get),(t=o.put)&&i(t,n.get),(t=n.soul)&&i(o.root.graph,t),(t=n.map)&&p(t,function(t){t.link&&o.root.$.get(t.link).off()}),(t=n.next)&&p(t,function(t){t.$.off()}),n.on("off",{}),this};var l,n=f.obj,p=n.map,i=(n.has,n.del),h=(n.to,f.val.link),a=function(){}})(_,"./on"),_(function(t){var u=_("./index");function e(t){if(!t.put||u.val.is(t.put))return this.to.next(t);this.as.nix&&this.off(),o(t.put,n,{at:this.as,msg:t}),this.to.next(t)}function n(t,n){if(a!==n){var o=this.msg.$,i=o._,e=this.at,r=i.lex;r&&!u.text.match(n,r["."]||r["#"]||r)||(((r=o.get(n)._).echo||(r.echo={}))[e.id]=r.echo[e.id]||e)}}u.chain.map=function(r,t,n){var a,o=this,i=o._;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=o.chain(),o.map().on(function(t,n,o,i){var e=(r||s).call(this,t,n,o,i);if(void 0!==e)return t===e?a._.on("in",o):u.is(e)?a._.on("in",e._):void a._.on("in",{get:n,put:e})})):(a=i.each)||(i.each=a=o.chain(),a._.nix=o.back("nix"),o.on("in",e,a._)),a};var o=u.obj.map,s=function(){},a=u.node._})(_,"./map"),_(function(t){var a=_("./index");a.chain.set=function(t,i,e){var n,r=this;return i=i||function(){},(e=e||{}).item=e.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,o){if(!t)return i.call(r,{err:a.log('Only a node can be linked! Not "'+o.put+'"!')});r.put(a.obj.put({},t,a.val.link.ify(t)),i,e)},!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,i,e))}})(_,"./set"),_(function(t){if("undefined"!=typeof Gun){var p;try{p=(Gun.window||function(){}).localStorage}catch(t){}p||(b.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,o=t.opt;if(t.once)return n.next(t);o.prefix=o.file||"gun/";var e,i,r=Gun.obj.ify(p.getItem("gap/"+o.prefix))||{},a=Gun.obj.empty;if(!a(r)){var u=Gun.obj.ify(p.getItem(o.prefix))||{},s={};Gun.obj.map(r,function(t,o){Gun.obj.map(t,function(t,n){s[o]=Gun.state.to(u[o],n,s[o])})}),setTimeout(function(){t.on("out",{put:s,"#":t.ask(f)})},1)}function f(t){if(!t.err&&t.ok){var i=t["@"];setTimeout(function(){Gun.obj.map(r,function(o,t){Gun.obj.map(o,function(t,n){i===t&&delete o[n]}),a(o)&&delete r[t]}),l()},o.wait||1)}}t.on("out",function(t){t.lS||(Gun.is(t.$)&&t.put&&!t["@"]&&!a(o.peers)&&(e=t["#"],Gun.graph.is(t.put,null,c),i||(i=setTimeout(l,o.wait||1))),this.to.next(t))}),t.on("ack",f),n.next(t);var c=function(t,n,o,i){(r[i]||(r[i]={}))[n]=e},l=function(){clearTimeout(i),i=!1;try{p.setItem("gap/"+o.prefix,JSON.stringify(r))}catch(t){Gun.log(err=t||"localStorage failure")}}}),Gun.on("create",function(a){this.to.next(a);var u=a.opt;if(!a.once&&!1!==u.localStorage){u.prefix=u.file||"gun/";a.graph;var i,e={},r=0,s=Gun.obj.ify(p.getItem(u.prefix))||{};a.on("localStorage",s),a.on("put",function(t){if(this.to.next(t),Gun.graph.is(t.put,null,n),t["@"]||(e[t["#"]]=!0),(r+=1)>=(u.batch||1e3))return f();i||(i=setTimeout(f,u.wait||1))}),a.on("get",function(n){this.to.next(n);var o,i,e,r=n.get;function t(){if(r&&(o=r["#"])){var t=r["."];(i=s[o]||e)&&t&&(i=Gun.state.to(i,t)),(i||Gun.obj.empty(u.peers))&&a.on("in",{"@":n["#"],put:Gun.graph.node(i),how:"lS",lS:n.$||a.$})}}Gun.debug?setTimeout(t,1):t()});var n=function(t,n,o,i){s[i]=Gun.state.to(o,n,s[i])},f=function(t){var o;r=0,clearTimeout(i),i=!1;var n=e;e={},t&&(s=t);try{p.setItem(u.prefix,JSON.stringify(s))}catch(t){Gun.log(o=(t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, temporary example at https://github.com/amark/gun/blob/master/test/tmp/indexedDB.html ."),a.on("localStorage:error",{err:o,file:u.prefix,flush:s,retry:f})}(o||Gun.obj.empty(u.peers))&&Gun.obj.map(n,function(t,n){a.on("in",{"@":n,err:o,ok:0})})}}})}})(_,"./adapters/localStorage"),_(function(t){var g=_("../type");function o(p){var h=function(){},d=p.opt||{};return d.log=d.log||b.log,d.gap=d.gap||d.wait||1,d.pack=d.pack||.3*(d.memory?1e3*d.memory*1e3:1399e6),h.out=function(t){var n;if(this.to&&this.to.next(t),(n=t["@"])&&(n=p.dup.s[n])&&(n=n.it)&&n._)return h.say(t,n._.via,1),void(n["##"]=t["##"]);h.say(t)},p.on("create",function(t){t.opt.pid=t.opt.pid||g.text.random(9),this.to.next(t),p.on("out",h.out)}),h.hear=function(t,n){if(t){var o,i,e,r=p.dup,a=t[0];if(d.pack<=t.length)return h.say({dam:"!",err:"Message too big!"},n);try{e=JSON.parse(t)}catch(t){d.log("DAM JSON parse error",t)}if("{"===a){if(!e)return;if(r.check(o=e["#"]))return;if((a=(r.track(o,!0).it=e)["@"])&&e.put&&(a+=i=e["##"]||(e["##"]=h.hash(e)))!=o){if(r.check(a))return;(a=r.s)[i]=a[o]}return(e._=function(){}).via=n,(a=e["><"])&&(e._.to=g.obj.map(a.split(","),function(t,n,o){o(t,!0)})),e.dam?void((a=h.hear[e.dam])&&a(e,n,p)):void p.on("in",e)}if("["!==a);else{if(!e)return;for(var u,s=0;u=e[s++];)h.hear(u,n)}}},function(){function a(t){var n=t.batch;if(n&&(t.batch=t.tail=null,n.length))try{u(JSON.stringify(n),t)}catch(t){d.log("DAM JSON stringify error",t)}}function u(n,o){var t=o.wire;try{t.send?t.send(n):o.say&&o.say(n)}catch(t){(o.queue=o.queue||[]).push(n)}}h.say=function(n,t,o){var i,e,r;if(t){if((t.wire||d.wire&&d.wire(t))&&(e=n._||s,t!==e.via&&((r=e.raw)||(r=h.raw(n)),!((i=n["@"])&&(i=p.dup.s[i])&&(i=i.it)&&i.get&&i["##"]&&i["##"]===n["##"])&&(!(i=e.to)||!i[t.url]&&!i[t.id]||o)))){if(t.batch){if(t.tail=(t.tail||0)+r.length,t.tail<=d.pack)return void t.batch.push(r);a(t)}t.batch=[],setTimeout(function(){a(t)},d.gap),u(r,t)}}else g.obj.map(d.peers,function(t){h.say(n,t)})}}(),function(){function f(t,n){var o;return n instanceof Object?(g.obj.map(Object.keys(n).sort(),i,{to:o={},on:n}),o):n}function i(t){this.to[t]=this.on[t]}h.raw=function(t){if(!t)return"";var n,o,i,e=p.dup,r=t._||{};if(i=r.raw)return i;if("string"==typeof t)return t;t["@"]&&(i=t.put)&&((o=t["##"])||(n=c(i,f)||"",o=h.hash(t,n),t["##"]=o),(i=e.s)[o=t["@"]+o]=i[t["#"]],t["#"]=o||t["#"],n&&((t=g.obj.to(t)).put=l));var a=0,u=[];g.obj.map(d.peers,function(t){if(u.push(t.url||t.id),9<++a)return!0}),t["><"]=u.join();var s=c(t);return v!==n&&(i=s.indexOf(l,s.indexOf("put")),s=s.slice(0,i-1)+n+s.slice(i+l.length+1)),r&&(r.raw=s),s},h.hash=function(t,n){return o.hash(n||c(t.put,f)||"")||t["#"]||g.text.random(9)};var c=JSON.stringify,l=":])([:"}(),h.hi=function(n){var t=n.wire||{};n.id||n.url?(d.peers[n.url||n.id]=n,g.obj.del(d.peers,t.id)):(t=t.id=t.id||g.text.random(9),h.say({dam:"?"},d.peers[t]=n)),t.hied||p.on(t.hied="hi",n),t=n.queue,n.queue=[],g.obj.map(t,function(t){h.say(t,n)})},h.bye=function(t){g.obj.del(d.peers,t.id),p.on("bye",t)},h.hear["!"]=function(t,n){d.log("Error:",t.err)},h.hear["?"]=function(t,n){if(!t.pid)return h.say({dam:"?",pid:d.pid,"@":t["#"]},n);n.id=n.id||t.pid,h.hi(n)},h}o.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var o=0,i=t.length;o<i;++o)n=(n<<5)-n+t.charCodeAt(o),n|=0;return n};var v,s={};Object.keys=Object.keys||function(t){return map(t,function(t,n,o){o(n)})};try{t.exports=o}catch(t){}})(_,"./adapters/mesh"),_(function(t){var a=_("../index");a.Mesh=_("./mesh"),a.on("opt",function(t){this.to.next(t);var i=t.opt;if(!t.once&&!1!==i.WebSocket){var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var o=i.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(o){i.WebSocket=o;i.mesh=i.mesh||a.Mesh(t),i.wire;i.wire=e}}function e(n){try{if(!n||!n.url)return o&&o(n);var t=n.url.replace("http","ws"),o=n.wire=new i.WebSocket(t);return o.onclose=function(){i.mesh.bye(n),r(n)},o.onerror=function(t){r(n),t&&t.code},o.onopen=function(){i.mesh.hi(n)},o.onmessage=function(t){t&&i.mesh.hear(t.data||t,n)},o}catch(t){}}function r(t){clearTimeout(t.defer),t.defer=setTimeout(function(){e(t)},2e3)}})})(_,"./adapters/websocket")}();