-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgun.min.js
1 lines (1 loc) · 30.3 KB
/
gun.min.js
1
!function(){function t(n){function o(t){return t.split("/").slice(-1).toString().replace(".js","")}return n.slice?t[o(n)]:function(e,i){n(e={exports:{}}),t[o(i)]=e.exports}}var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var o=n.console||{log:function(){}};if("undefined"!=typeof module)var e=module;t(function(t){var n={};n.fns=n.fn={is:function(t){return!!t&&"function"==typeof t}},n.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},n.num={is:function(t){return!e(t)&&(t-parseFloat(t)+1>=0||1/0===t||-1/0===t)}},n.text={is:function(t){return"string"==typeof t}},n.text.ify=function(t){return n.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},n.text.random=function(t,n){var o="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)o+=n.charAt(Math.floor(Math.random()*n.length)),t--;return o},n.text.match=function(t,o){var e=!1;if(t=t||"",o=n.text.is(o)?{"=":o}:o||{},n.obj.has(o,"~")&&(t=t.toLowerCase(),o["="]=(o["="]||o["~"]).toLowerCase()),n.obj.has(o,"="))return t===o["="];if(n.obj.has(o,"*")){if(t.slice(0,o["*"].length)!==o["*"])return!1;e=!0,t=t.slice(o["*"].length)}if(n.obj.has(o,"!")){if(t.slice(-o["!"].length)!==o["!"])return!1;e=!0}if(n.obj.has(o,"+")&&n.list.map(n.list.is(o["+"])?o["+"]:[o["+"]],function(n){if(!(t.indexOf(n)>=0))return!0;e=!0}))return!1;if(n.obj.has(o,"-")&&n.list.map(n.list.is(o["-"])?o["-"]:[o["-"]],function(n){if(!(t.indexOf(n)<0))return!0;e=!0}))return!1;if(n.obj.has(o,">")){if(!(t>o[">"]))return!1;e=!0}if(n.obj.has(o,"<")){if(!(t<o["<"]))return!1;e=!0}if(n.obj.has(o,"?")){if(!function(t,n){for(var o,e=-1,i=0;o=n[i++];)if(!~(e=t.indexOf(o,e+1)))return!1;return!0}(t,o["?"]))return!1;e=!0}return e},n.list={is:function(t){return t instanceof Array}},n.list.slit=Array.prototype.slice,n.list.sort=function(t){return function(n,o){return n&&o?(n=n[t],o=o[t],n<o?-1:n>o?1:0):0}},n.list.map=function(t,n,o){return a(t,n,o)},n.list.index=1,n.obj={is:function(t){return!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},n.obj.put=function(t,n,o){return(t||{})[n]=o,t},n.obj.has=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n.obj.del=function(t,n){if(t)return t[n]=null,delete t[n],t},n.obj.as=function(t,n,o,e){return t[n]=t[n]||(e===o?{}:o)},n.obj.ify=function(t){if(r(t))return t;try{t=JSON.parse(t)}catch(n){t={}}return t},function(){function t(t,n){u(this,n)&&o!==this[n]||(this[n]=t)}var o;n.obj.to=function(n,o){return o=o||{},a(n,t,o),o}}(),n.obj.copy=function(t){return t?JSON.parse(JSON.stringify(t)):t},function(){function t(t,n){var o=this.n;if(!o||!(n===o||r(o)&&u(o,n)))return!!n||void 0}n.obj.empty=function(n,o){return!n||!a(n,t,{n:o})}}(),function(){function t(n,o){if(2===arguments.length)return t.r=t.r||{},void(t.r[n]=o);t.r=t.r||[],t.r.push(n)}var i=Object.keys;n.obj.map=function(a,s,f){var c,l,p,g,h,d=0,v=o(s);if(t.r=null,i&&r(a)&&(g=Object.keys(a),h=!0),e(a)||g)for(l=(g||a).length;d<l;d++){var _=d+n.list.index;if(v){if((p=h?s.call(f||this,a[g[d]],g[d],t):s.call(f||this,a[d],_,t))!==c)return p}else if(s===a[h?g[d]:d])return g?g[d]:_}else for(d in a)if(v){if(u(a,d)&&(p=f?s.call(f,a[d],d,t):s(a[d],d,t))!==c)return p}else if(s===a[d])return d;return v?t.r:n.list.index?0:-1}}(),n.time={},n.time.is=function(t){return t?t instanceof Date:+(new Date).getTime()};var o=n.fn.is,e=n.list.is,i=n.obj,r=i.is,u=i.has,a=i.map;t.exports=n})(t,"./type"),t(function(t){t.exports=function t(n,o,e){if(!n)return{to:t};var n=(this.tag||(this.tag={}))[n]||(this.tag[n]={tag:n,to:t._={next:function(){}}});if(o 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}),to:t._,next:o,the:n,on:this,as:e};return(i.back=n.last||n).to=i,n.last=i}return(n=n.to).next(o),n}})(t,"./onto"),t(function(n){function o(t,n){n=n||{},n.id=n.id||"#",n.rid=n.rid||"@",n.uuid=n.uuid||function(){return+new Date+Math.random()};var o=e;return o.stun=function(t){var n=function(t){return n.off&&n===this.stun?(this.stun=null,!1):!o.stun.skip&&(t&&(t.cb=t.fn,t.off(),e.queue.push(t)),!0)},e=n.res=function(t,r){if(!n.off){if(t instanceof Function)return o.stun.skip=!0,t.call(r),void(o.stun.skip=!1);n.off=!0;var u,a=0,s=e.queue,f=s.length;for(e.queue=[],n===i.stun&&(i.stun=null),a;a<f;a++)u=s[a],u.fn=u.cb,u.cb=null,o.stun.skip=!0,u.ctx.on(u.tag,u.fn,u),o.stun.skip=!1}},i=t._;return e.back=i.stun||(i.back||{_:{}})._.stun,e.back&&(e.back.next=n),e.queue=[],i.stun=n,e},o}var e=t("./onto");n.exports=o})(t,"./onify"),t(function(n){function o(t,n,e){o.time=e,o.waiting.push({when:t,event:n||function(){}}),o.soonest<t||o.set(t)}var e=t("./type");o.waiting=[],o.soonest=1/0,o.sort=e.list.sort("when"),o.set=function(t){if(!(1/0<=(o.soonest=t))){var n=o.time();t=t<=n?0:t-n,clearTimeout(o.id),o.id=setTimeout(o.check,t)}},o.each=function(t,n,o){var e=this;t&&(t.when<=e.now?t.event instanceof Function&&setTimeout(function(){t.event()},0):(e.soonest=e.soonest<t.when?e.soonest:t.when,o(t)))},o.check=function(){var t={now:o.time(),soonest:1/0};o.waiting.sort(o.sort),o.waiting=e.list.map(o.waiting,o.each,t)||[],o.set(t.soonest)},n.exports=o})(t,"./schedule"),t(function(t){function n(t,n,e,i,r){if(t<n)return{defer:!0};if(n<e)return{historical:!0};if(e<n)return{converge:!0,incoming:!0};if(n===e){if(i=o(i)||"",r=o(r)||"",i===r)return{state:!0};if(i<r)return{converge:!0,current:!0};if(r<i)return{converge:!0,incoming:!0}}return{err:"Invalid CRDT Data: "+i+" to "+r+" at "+n+" to "+e+"!"}}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 o=JSON.stringify;t.exports=n})(t,"./HAM"),t(function(n){var o=t("./type"),e={};e.is=function(t){return t!==i&&(null===t||t!==1/0&&(!!(s(t)||u(t)||a(t))||(e.rel.is(t)||!1)))},e.rel={_:"#"},function(){function t(t,n){var o=this;return o.id?o.id=!1:n==r&&s(t)?void(o.id=t):o.id=!1}e.rel.is=function(n){if(n&&n[r]&&!n._&&c(n)){var o={};if(p(n,t,o),o.id)return o.id}return!1}}(),e.rel.ify=function(t){return l({},r,t)};var i,r=e.rel._,u=o.bi.is,a=o.num.is,s=o.text.is,f=o.obj,c=f.is,l=f.put,p=f.map;n.exports=e})(t,"./val"),t(function(n){var o=t("./type"),e=t("./val"),i={_:"_"};i.soul=function(t,n){return t&&t._&&t._[n||p]},i.soul.ify=function(t,n){return n="string"==typeof n?{soul:n}:n||{},t=t||{},t._=t._||{},t._[p]=n.soul||t._[p]||l(),t},i.soul._=e.rel._,function(){function t(t,n){if(n!==i._)return!e.is(t)||void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s))}i.is=function(n,o,e){var r;return!!a(n)&&(!!(r=i.soul(n))&&!f(n,t,{as:e,cb:o,s:r,n:n}))}}(),function(){function t(t,n){var o,i=this.o;if(i.map)return o=i.map.call(this.as,t,""+n,i.node),void(void 0===o?s(i.node,n):i.node&&(i.node[n]=o));e.is(t)&&(i.node[n]=t)}i.ify=function(n,o,e){return o?"string"==typeof o?o={soul:o}:o instanceof Function&&(o={map:o}):o={},o.map&&(o.node=o.map.call(e,n,r,o.node||{})),(o.node=i.soul.ify(o.node||{},o))&&f(n,t,{o:o,as:e}),o.node}}();var r,u=o.obj,a=u.is,s=u.del,f=u.map,c=o.text,l=c.random,p=i.soul._;n.exports=i})(t,"./node"),t(function(n){function o(){var t;return t=f?c+f.now():r(),u<t?(a=0,u=t+o.drift):u=t+(a+=1)/s+o.drift}var e=t("./type"),i=t("./node"),r=e.time.is,u=-1/0,a=0,s=1e3,f="undefined"!=typeof performance&&(performance.timing&&performance),c=f&&f.timing&&f.timing.navigationStart||(f=!1);o._=">",o.drift=0,o.is=function(t,n,e){var i=n&&t&&t[x]&&t[x][o._]||e;if(i)return m(i=i[n])?i:-1/0},o.ify=function(t,n,e,r,u){if(!t||!t[x]){if(!u)return;t=i.soul.ify(t,u)}var a=g(t[x],o._);return l!==n&&n!==x&&(m(e)&&(a[n]=e),l!==r&&(t[n]=r)),t},o.to=function(t,n,e){var r=t[n];return d(r)&&(r=_(r)),o.ify(e,n,o.is(t,n),r,i.soul(t))},function(){function t(t,n){x!==n&&o.ify(this.o,n,this.s)}o.map=function(n,e,i){var r,u=d(u=n||e)?u:null;return n=k(n=n||e)?n:null,u&&!n?(e=m(e)?e:o(),u[x]=u[x]||{},v(u,t,{o:u,s:e}),u):(i=i||d(e)?e:r,e=m(e)?e:o(),function(o,u,a,s){if(!n)return t.call({o:a,s:e},o,u),o;n.call(i||this||{},o,u,a,s),h(a,u)&&r===a[u]||t.call({o:a,s:e},o,u)})}}();var l,p=e.obj,g=p.as,h=p.has,d=p.is,v=p.map,_=p.copy,b=e.num,m=b.is,y=e.fn,k=y.is,x=i._;n.exports=o})(t,"./state"),t(function(n){var o=t("./type"),e=t("./val"),i=t("./node"),r={};!function(){function t(t,o){if(!t||o!==i.soul(t)||!i.is(t,this.fn,this.as))return!0;this.cb&&(n.n=t,n.as=this.as,this.cb.call(n.as,t,o,n))}function n(t){t&&i.is(n.n,t,n.as)}r.is=function(n,o,e,i){return!(!n||!s(n)||l(n))&&!g(n,t,{cb:o,fn:e,as:i})}}(),function(){function t(t,r){var u;return(u=l(t,r))?u:(r.env=t,r.soul=o,i.ify(r.obj,n,r)&&(t.graph[e.rel.is(r.rel)]=r.node),r)}function n(n,o,r){var s,l,p=this,g=p.env;if(i._===o&&c(n,e.rel._))return r._;if(s=a(n,o,r,p,g)){if(o||(p.node=p.node||r||{},c(n,i._)&&(p.node._=h(n._)),p.node=i.soul.ify(p.node,e.rel.is(p.rel)),p.rel=p.rel||e.rel.ify(i.soul(p.node))),(l=g.map)&&(l.call(g.as||{},n,o,r,p),c(r,o))){if(n=r[o],u===n)return void f(r,o);if(!(s=a(n,o,r,p,g)))return}if(!o)return p.node;if(!0===s)return n;if(l=t(g,{obj:n,path:p.path.concat(o)}),l.node)return l.rel}}function o(t){var n=this,o=e.rel.is(n.rel),r=n.env.graph;n.rel=n.rel||e.rel.ify(t),n.rel[e.rel._]=t,n.node&&n.node[i._]&&(n.node[i._][e.rel._]=t),c(r,o)&&(r[t]=r[o],f(r,o))}function a(t,n,o,i,r){var u;return!!e.is(t)||(s(t)?1:(u=r.invalid)?(t=u.call(r.as||{},t,n,o),a(t,n,o,i,r)):void(r.err="Invalid value at '"+i.path.concat(n).join(".")+"'!"))}function l(t,n){for(var o,e=t.seen,i=e.length;i--;)if(o=e[i],n.obj===o.obj)return o;e.push(n)}r.ify=function(n,o,i){var r={path:[],obj:n};return o?"string"==typeof o?o={soul:o}:o instanceof Function&&(o.map=o):o={},o.soul&&(r.rel=e.rel.ify(o.soul)),o.graph=o.graph||{},o.seen=o.seen||[],o.as=o.as||i,t(o,r),o.root=r.node,o.graph}}(),r.node=function(t){var n=i.soul(t);if(n)return p({},n,t)},function(){function t(t,n){var o,u;if(i._===n){if(l(t,e.rel._))return;return void(this.obj[n]=h(t))}return(o=e.rel.is(t))?(u=this.opt.seen[o])?void(this.obj[n]=u):void(this.obj[n]=this.opt.seen[o]=r.to(this.graph,o,this.opt)):void(this.obj[n]=t)}r.to=function(n,o,e){if(n){var i={};return e=e||{seen:{}},g(n[o],t,{obj:i,graph:n,opt:e}),i}}}();var u,a=(o.fn.is,o.obj),s=a.is,f=a.del,c=a.has,l=a.empty,p=a.put,g=a.map,h=a.copy;n.exports=r})(t,"./graph"),t(function(n){function o(){this.cache={}}var e=t("./type");o.prototype.track=function(t){return this.cache[t]=e.time.is(),this.to||this.gc(),t},o.prototype.check=function(t){return!!e.obj.has(this.cache,t)&&this.track(t)},o.prototype.gc=function(){var t=this,n=e.time.is(),o=n;if(e.obj.map(t.cache,function(i,r){o=Math.min(n,i),n-i<3e5||e.obj.del(t.cache,r)}),e.obj.empty(t.cache))return void(t.to=null);var i=n-o,r=3e5-i;t.to=setTimeout(function(){t.gc()},r)},n.exports=o})(t,"./dup"),t(function(n){function i(t){return t instanceof i?(this._={gun:this}).gun:this instanceof i?i.create(this._={gun:this,opt:t}):new i(t)}i.is=function(t){return t instanceof i},i.version=.7,i.chain=i.prototype,i.chain.toJSON=function(){};var r=t("./type");r.obj.to(r,i),i.HAM=t("./HAM"),i.val=t("./val"),i.node=t("./node"),i.state=t("./state"),i.graph=t("./graph"),i.dup=t("./dup"),i.schedule=t("./schedule"),i.on=t("./onify")(),i._={node:i.node._,soul:i.val.rel._,state:i.state._,field:".",value:"="},function(){function t(t){var n,o=this,e=o.as;if(t.gun||(t.gun=e.gun),t["#"]||(t["#"]=i.text.random()),!e.dup.check(t["#"])){if(t["@"]){if(e.ack(t["@"],t))return;return e.dup.track(t["#"]),void i.on("out",p(t,{gun:e.gun}))}e.dup.track(t["#"]),n=p(t,{gun:e.gun}),t.get&&i.on("get",n),t.put&&i.on("put",n),i.on("out",n)}}i.create=function(n){n.on=n.on||i.on,n.root=n.root||n.gun,n.graph=n.graph||{},n.dup=n.dup||new i.dup,n.ask=i.on.ask,n.ack=i.on.ack;var o=n.gun.opt(n.opt);return n.once||(n.on("in",t,n),n.on("out",t,n)),n.once=1,o}}(),function(){function t(t,n,o,e){var r=this,u=i.state.is(o,n);if(!u)return r.err="Error: No state on '"+n+"' in node '"+e+"'!";var a=r.graph[e]||v,s=i.state.is(a,n,!0),f=a[n],c=i.HAM(r.machine,u,s,t,f);c.incoming||c.defer&&(r.defer=u<(r.defer||1/0)?u:r.defer),r.put[e]=i.state.to(o,n,r.put[e]),(r.diff||(r.diff={}))[e]=i.state.to(o,n,r.diff[e])}function n(t,n){var e=(this.gun._.next||v)[n];if(e){var r=this.map[n]={put:this.node=t,get:this.soul=n,gun:this.ref=e};g(t,o,this),i.on("node",r)}}function o(t,n){var o=this.graph,e=this.soul,r=this.ref._;o[e]=i.state.to(this.node,n,o[e]),(r.put||(r.put={}))[n]=t}function e(t,n){t.gun&&t.gun._.on("in",t)}i.on("put",function(o){if(!o["#"])return this.to.next(o);var r=this,a={gun:o.gun,graph:o.gun._.graph,put:{},map:{},machine:i.state()};if(i.graph.is(o.put,null,t,a)||(a.err="Error: Invalid graph!"),a.err)return a.gun.on("in",{"@":o["#"],err:i.log(a.err)});g(a.put,n,a),g(a.map,e,a),u!==a.defer&&i.schedule(a.defer,function(){i.on("put",o)},i.state),a.diff&&r.to.next(p(o,{put:a.diff}))})}(),function(){i.on("get",function(t){var n,o=this,e=t.get[h],r=t.gun._,u=r.graph[e],a=t.get[d],s=r.next||(r.next={}),f=(s[e]||v)._;if(!u||!f)return o.to.next(t);if(a){if(!l(u,a))return o.to.next(t);u=i.state.to(u,a)}else u=i.obj.copy(u);u=i.graph.node(u),n=f.ack,r.on("in",{"@":t["#"],how:"mem",put:u,gun:f.gun}),0<n||o.to.next(t)})}(),function(){i.on.ask=function(t,n){if(this.on){var o=i.text.random();return t&&this.on(o,t,n),o}},i.on.ack=function(t,n){if(t&&n&&this.on){var o=t["#"]||t;if(this.tag&&this.tag[o])return this.on(o,n),!0}}}(),function(){i.chain.opt=function(t){t=t||{};var n=this,o=n._,e=t.peers||t;return c(t)||(t={}),c(o.opt)||(o.opt=t),a(e)&&(e=[e]),s(e)&&(e=g(e,function(t,n,o){o(t,{url:t})}),c(o.opt.peers)||(o.opt.peers={}),o.opt.peers=p(e,o.opt.peers)),o.opt.wsc=o.opt.wsc||{protocols:[]},o.opt.peers=o.opt.peers||{},p(t,o.opt),i.on("opt",o),n}}();var u,a=i.text.is,s=i.list.is,f=i.obj,c=f.is,l=f.has,p=f.to,g=f.map,h=(f.copy,i._.soul),d=i._.field,v=(i.val.rel.is,{});o.debug=function(t,n){return o.debug.i&&t===o.debug.i&&o.debug.i++&&(o.log.apply(o,arguments)||n)},i.log=function(){return!i.log.off&&o.log.apply(o,arguments),[].slice.call(arguments).join(" ")},i.log.once=function(t,n,o){return(o=i.log.once)[t]=o[t]||0,o[t]++||i.log(n)},i.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=i),void 0!==e&&(e.exports=i),n.exports=i})(t,"./root"),t(function(n){t("./root").chain.back=function(t,n){var i;if(-1===t||1/0===t)return this._.root;if(1===t)return this._.back||this;var r=this,u=r._;if("string"==typeof t&&(t=t.split(".")),t instanceof Array){var a=0,s=t.length,i=u;for(a;a<s;a++)i=(i||e)[t[a]];if(o!==i)return n?r:i;if(i=u.back)return i.back(t,n)}else if(t instanceof Function){for(var f,i={back:r};(i=i.back)&&(i=i._)&&!(f=t(i,n)););return f}};var o,e={}})(t,"./back"),t(function(o){function e(t){var n,o,e,i=this.as,r=i.gun,u=r.back(-1);if(t.gun||(t.gun=r),o=t.get)if(e=o[y])e=u.get(e)._,d(o,k)?d(n=e.put,o=o[k])&&e.on("in",{get:e.get,put:l.state.to(n,o),gun:e.gun}):d(e,"put")&&e.on("in",e);else if(d(o,k)){o=o[k];var a=o?r.get(o)._:i;if(p!==a.put)return void a.on("in",a);if(d(i,"put")){var s,f=i.put;if((s=l.node.soul(f))&&(f=l.val.rel.ify(s)),s=l.val.rel.is(f)){if(!t.gun._)return;return void t.gun._.on("out",{get:e={"#":s,".":o,gun:t.gun},"#":u._.ask(l.HAM.synth,e),gun:t.gun})}if(p===f||l.val.is(f)){if(!t.gun._)return;return void t.gun._.on("in",{get:o,gun:t.gun})}}else i.map&&m(i.map,function(t){t.at.on("in",t.at)});if(i.soul){if(!t.gun._)return;return void t.gun._.on("out",{get:e={"#":i.soul,".":o,gun:t.gun},"#":u._.ask(l.HAM.synth,e),gun:t.gun})}if(i.get){if(!i.back._)return;return void i.back._.on("out",{get:v({},k,i.get),gun:r})}t=b(t,{get:{}})}else{if(d(i,"put")?i.on("in",i):i.map&&m(i.map,function(t){t.at.on("in",t.at)}),i.ack&&!d(i,"put"))return;if(i.ack=-1,i.soul)return void i.on("out",{get:e={"#":i.soul,gun:i.gun},"#":u._.ask(l.HAM.synth,e),gun:i.gun});if(i.get){if(!i.back._)return;return void i.back._.on("out",{get:v({},k,i.get),gun:i.gun})}}i.back._.on("out",t)}function i(t){t=t._||t;var n,o=this,e=this.as,i=t.gun,a=i._,c=t.put;e.back._;if(0>e.ack&&!t.ack&&!l.val.rel.is(c)&&(e.ack=1),e.get&&t.get!==e.get&&(t=b(t,{get:e.get})),e.field&&a!==e&&(t=b(t,{gun:e.gun}),a.ack&&(e.ack=e.ack||a.ack)),p===c){if(o.to.next(t),e.soul)return;return u(e,t,o),e.field&&f(e,t),_(a.echo,e.id),void _(e.map,a.id)}return e.soul?(e.root._.now&&(t=b(t,{put:c=a.put})),o.to.next(t),u(e,t,o),void m(c,s,{at:t,cat:e})):(n=l.val.rel.is(c))?(r(e,t,a,n),o.to.next(t),void u(e,t,o)):l.val.is(c)?(e.field||e.soul?f(e,t):(a.field||a.soul)&&((a.echo||(a.echo={}))[e.id]=e,(e.map||(e.map={}))[a.id]=e.map[a.id]||{at:a}),o.to.next(t),void u(e,t,o)):(e.field&&a!==e&&d(a,"put")&&(e.put=a.put),(n=l.node.soul(c))&&a.field&&(a.put=e.root.get(n)._.put),o.to.next(t),u(e,t,o),r(e,t,a,n),void m(c,s,{at:t,cat:e}))}function r(t,n,o,e){if(e&&x!==t.get){var i=t.root.get(e)._;t.field?o=i:o.field&&r(o,n,o,e),o!==t&&((o.echo||(o.echo={}))[t.id]=t,t.field&&!(t.map||g)[o.id]&&f(t,n),i=(t.map||(t.map={}))[o.id]=t.map[o.id]||{at:o},e!==i.rel&&c(t,i.rel=e))}}function u(t,n,o){t.echo&&(t.field&&(n=b(n,{event:o})),m(t.echo,a,n))}function a(t){t.on("in",this)}function s(t,n){var o,e,i,r=this.cat,u=r.next||g,a=this.at;(x!==n||u[n])&&(o=u[n])&&(i=o._,i.field?(t&&t[y]&&l.val.rel.is(t)===l.node.soul(i.put)||(i.put=t),e=o):e=a.gun.get(n),i.on("in",{put:t,get:n,gun:e,via:a}))}function f(t,n){if(t.field||t.soul){var o=t.map;t.map=null,null!==o&&(p===o&&t.put!==p||(m(o,function(n){(n=n.at)&&_(n.echo,t.id)}),m(t.next,function(t,n){var o=t._;o.put=p,o.ack&&(o.ack=-1),o.on("in",{get:n,gun:t,put:p})})))}}function c(t,n){var o=t.root.get(n)._;if(t.ack)return o.ack=o.ack||-1,void o.on("out",{get:o={"#":n,gun:o.gun},"#":t.root._.ask(l.HAM.synth,o)});m(t.next,function(o,e){o._.on("out",{get:o={"#":n,".":e,gun:o},"#":t.root._.ask(l.HAM.synth,o)})})}var l=t("./root");l.chain.chain=function(){var t=this._,o=new this.constructor(this),r=o._;return r.root=n=t.root,r.id=++n._.once,r.back=this,r.on=l.on,l.on("chain",r),r.on("in",i,r),r.on("out",e,r),o},l.chain.chain.input=i;var p,g={},h=l.obj,d=h.has,v=h.put,_=h.del,b=h.to,m=h.map,y=l._.soul,k=l._.field,x=l.node._})(t,"./chain"),t(function(n){function o(t,n){var o=n._,e=o.next,i=n.chain(),r=i._;return e||(e=o.next={}),e[r.get=t]=i,o.root===n?r.soul=t:(o.soul||o.field)&&(r.field=t),i}function e(t){var n,o=this,e=o.as,i=t.gun,u=i._,s=t.put;r===s&&(s=u.put),(n=s)&&n[f._]&&(n=f.is(n))&&(n=u.root.get(n)._,r!==n.put&&(t=a(t,{put:n.put}))),e.use(t,t.event||o),o.to.next(t)}var i=t("./root");i.chain.get=function(t,n,r){if("string"!=typeof t){if(t instanceof Function){var u=this,a=u._;return r=n||{},r.use=t,r.out=r.out||{cap:1},r.out.get=r.out.get||{},"_"!=a.get&&(a.root._.now=!0),a.on("in",e,r),a.on("out",r.out),a.root._.now=!1,u}return s(t)?this.get(""+t,n,r):((r=this.chain())._.err={err:i.log("Invalid get request!",t)},n&&n.call(r,r._.err),r)}var u,f,l=this,p=l._,g=p.next||c;return(u=g[t])||(u=o(t,l)),(f=p.stun)&&(u._.stun=u._.stun||f),n&&n instanceof Function&&u.get(n,r),u};var r,u=i.obj,a=(u.has,i.obj.to),s=i.num.is,f=i.val.rel,c=(i.node._,{})})(t,"./get"),t(function(n){function e(t){t.batch=i;var n=t.opt||{},o=t.env=f.state.map(u,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)}),void(t.res&&t.res());t.batch()}function i(){var t=this;t.graph&&!h(t.stun,r)&&((t.res||_)(function(){t.ref._.on("out",{cap:3,gun:t.ref,put:t.out=t.env.graph,opt:t.opt,"#":t.gun.back(-1)._.ask(function(n){this.off(),t.ack&&t.ack(n,this)},t.opt)})},t),t.res&&t.res())}function r(t,n){if(t)return!0}function u(t,n,o,e){var i=this;!n&&e.path.length&&(i.res||_)(function(){var t=e.path,n=i.ref,o=(i.opt,0),r=t.length;for(o;o<r;o++)n=n.get(t[o]);if(i.not||f.node.soul(e.obj)){var u=f.node.soul(e.obj)||((i.opt||{}).uuid||i.gun.back("opt.uuid")||f.text.random)();return n.back(-1).get(u),void e.soul(u)}(i.stun=i.stun||{})[t]=!0,n.get("_").get(a,{as:{at:e,as:i}})},{as:i,at:e})}function a(t,n){var o=this.as,e=o.at;if(o=o.as,t.gun&&t.gun._.back){n.off(),t=t.gun._.back._;var i=f.node.soul(e.obj)||f.node.soul(t.put)||f.val.rel.is(t.put)||((o.opt||{}).uuid||o.gun.back("opt.uuid")||f.text.random)();t.gun.back(-1).get(i),e.soul(i),o.stun[e.path]=!1,o.batch()}}function s(t,n){var e=this.as;if(t.gun&&t.gun._){if(t.err)return void o.log("Please report this as an issue! Put.any.err");var i,r=t.gun._.back._,u=r.put,a=e.opt||{};if(n.off(),e.ref!==e.gun){if(!(i=e.gun._.get||r.get))return void o.log("Please report this as an issue! Put.no.get");e.data=g({},i,e.data),i=null}if(c===u){if(!r.get)return;r.soul||(i=r.gun.back(function(t){if(t.soul)return t.soul;e.data=g({},t.get,e.data)})),i=i||r.get,r=r.root.get(i)._,e.not=e.soul=i,u=e.data}e.not||(e.soul=f.node.soul(u))||(e.path&&p(e.data)?e.soul=(a.uuid||r.root._.opt.uuid||f.text.random)():e.soul=t.soul||r.soul||(a.uuid||r.root._.opt.uuid||f.text.random)()),e.ref.put(e.data,e.soul,e)}}var f=t("./root");f.chain.put=function(t,n,o){var i,r=this,u=r._,a=u.root;return o=o||{},o.data=t,o.gun=o.gun||r,"string"==typeof n?o.soul=n:o.ack=n,u.soul&&(o.soul=u.soul),o.soul||a===r?p(o.data)?(o.gun=r=a.get(o.soul=o.soul||(o.not=f.node.soul(o.data)||(a._.opt.uuid||f.text.random)())),o.ref=o.gun,e(o),r):((o.ack||v).call(o,o.out={err:f.log("Data saved to the root level of the graph must be a node (an object), not a",typeof o.data,'of "'+o.data+'"!')}),o.res&&o.res(),r):f.is(t)?(t.get(function(t,e){e.off();var i=f.node.soul(t.put);if(!i)return void f.log("The reference you are saving is a",typeof t.put,'"'+o.put+'", not a node (object)!');r.put(f.val.rel.ify(i),n,o)}),r):(o.ref=o.ref||a===(i=u.back)?r:i,o.ref._.soul&&f.val.is(o.data)&&u.get?(o.data=g({},u.get,o.data),o.ref.put(o.data,o.soul,o),r):(o.ref.get("_").get(s,{as:o}),o.out||(o.res=o.res||f.on.stun(o.ref),o.gun._.stun=o.ref._.stun),r))};var c,l=f.obj,p=l.is,g=l.put,h=l.map,d={},v=function(){},_=function(t,n){t.call(n||d)}})(t,"./put"),t(function(n){var e=t("./root");n.exports=e,function(){function t(t,n){if(e._.node!==n){var r=this.node,u=this.vertex,a=this.union,s=this.machine,f=h(r,n),c=h(u,n);if(i===f||i===c)return!0;var l=t,p=u[n];if(!_(l)&&i!==l)return!0;if(!_(p)&&i!==p)return!0;var g=e.HAM(s,f,c,l,p);if(g.err)return void o.log(".!HYPOTHETICAL AMNESIA MACHINE ERR!.",n,g.err);if(!(g.state||g.historical||g.current))return g.incoming?(a[n]=t,void d(a,n,f)):g.defer?(a[n]=t,void d(a,n,f)):void 0}}function n(t,n){var o=this;if(e._.node!==n&&_(t)){var i=o.node,r=o.vertex,u=h(i,n,!0),a=h(r,n,!0),s=o.delta;e.HAM(o.machine,u,a,t,r[n]).incoming&&(s[n]=t,d(s,n,u))}}e.HAM.union=function(n,o,i){if(o&&o._&&(n=n||e.node.soul.ify({_:{">":{}}},e.node.soul(o)))&&n._&&(i=a(i)?{machine:i}:{machine:e.state()},i.union=n||e.obj.copy(n),i.vertex=n,i.node=o,!l(o,t,i)))return i.union},e.HAM.delta=function(t,o,i){return i=a(i)?{machine:i}:{machine:e.state()},t?(i.soul=e.node.soul(i.vertex=t),i.soul?(i.delta=e.node.soul.ify({},i.soul),l(i.node=o,n,i),i.delta):void 0):e.obj.copy(o)},e.HAM.synth=function(t,n){var o=this.as,r=o.gun._;if(!t.put||o["."]&&!f(t.put[o["#"]],r.get)){if(r.put!==i)return;return void r.on("in",{get:r.get,put:r.put=i,gun:r.gun})}t.gun=r.root,e.on("put",t)},e.HAM.synth_=function(t,n,o){var r=this.as||o,u=r._,a=u.root._,s={};if(!t.put){if(u.put!==i)return;return void u.on("in",{get:u.get,put:u.put=i,gun:r,via:t})}l(t.put,function(t,n){var o=this.graph;s[n]=e.HAM.delta(o[n],t,{graph:o}),o[n]=e.HAM.union(o[n],t)||o[n]},a),t.gun!==a.gun&&(s=t.put),l(s,function(o,r){var a=this,s=a.next||(a.next={}),l=s[r]||(s[r]=a.gun.get(r)),p=l._;if(p.put=a.graph[r],u.field&&!f(o,u.field))return(t=c(t,{})).put=i,void e.HAM.synth(t,n,u.gun);p.on("in",{put:o,get:r,gun:l,via:t})},a)}}();var i,r=e,u=r.num,a=u.is,s=r.obj,f=s.has,c=(s.put,s.to),l=s.map,p=e.node,g=(p.soul,p.is,p.ify,e.state),h=g.is,d=g.ify,v=e.val,_=v.is;v.rel.is})(t,"./index"),t(function(n){var o=t("./root");t("./index"),t("./opt"),t("./chain"),t("./back"),t("./put"),t("./get"),n.exports=o})(t,"./core"),t(function(n){var o=t("./core");o.chain.path=function(t,n,e){var i,r=this,u=r;if(e=e||{},e.path=!0,o.log.once("pathing","Warning: `.path` to be removed from core (but available as an extension), use `.get` chains instead. If you are opposed to this, please voice your opinion in https://gitter.im/amark/gun and ask others."),u===u._.root)return n&&n({err:o.log("Can't do that on root instance.")}),u;if("string"==typeof t){if(i=t.split(e.split||"."),1===i.length)return u=r.get(t,n,e),u._.opt=e,u;t=i}if(t instanceof Array){if(t.length>1){u=r;var a=0,s=t.length;for(a;a<s;a++)u=u.get(t[a],a+1===s?n:null,e)}else u=r.get(t[0],n,e);return u._.opt=e,u}return t||0==t?(u=r.get(""+t,n,e),u._.opt=e,u):r}})(t,"./path"),t(function(n){function o(t,n){var o,e=this,u=t.gun,a=u._,f=a.put||t.put,o=e.last,c=a.id+t.get;if(r!==f){if(f&&f[s._]&&(o=s.is(f))){if(o=a.root.get(o)._,r===o.put)return;f=o.put}e.change&&(f=t.put),(o.put!==f||o.get!==c||i.node.soul(f))&&(o.put=f,o.get=c,a.last=f,e.as?e.ok.call(e.as,t,n):e.ok.call(u,f,t.get,t,n))}}function e(t,n,o){var i,u=this.as,a=u.cat,f=t.gun,c=f._,l=c.put||t.put;if(l&&l[s._]&&(i=s.is(l))){if(i=a.root.get(i)._,r===i.put)return;l=i.put}if(n.wait&&clearTimeout(n.wait),!u.async)return void(n.wait=setTimeout(function(){e.call({as:u},t,n,n.wait||1)},u.wait||99));if(a.field||a.soul){if(n.off())return}else{if((u.seen=u.seen||{})[c.id])return;u.seen[c.id]=!0}u.ok.call(t.gun||u.gun,l,t.get)}var i=t("./core");i.chain.on=function(t,n,e,i){var r,u,a=this,s=a._;if("string"==typeof t)return n?(r=s.on(t,n,e||s,i),e&&e.gun&&(e.subs||(e.subs=[])).push(r),u=function(){r&&r.off&&r.off(),u.off()},u.off=a.off.bind(a)||f,a.off=u,a):s.on(t);var c=n;return c=!0===c?{change:!0}:c||{},c.ok=t,c.last={},a.get(o,c),a},i.chain.val=function(t,n){var o=this,u=o._,a=u.put;if(0<u.ack&&r!==a)return(t||f).call(o,a,u.get),o;if(!t){i.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 s=o.chain();return s._.val=o.val(function(){s._.on("in",o._)}),s}return(n=n||{}).ok=t,n.cat=u,o.get(e,{as:n}),n.async=!0,o},i.chain.off=function(){var t,n=this,o=n._,e=o.back||{},i=e._;if(i)return(t=i.next)&&(t[o.get]?a(t,o.get):obj_map(t,function(o,e){n===o&&a(t,e)})),(t=n.back(-1))===e&&a(t.graph,o.get),o.ons&&(t=o.ons["@$"])&&obj_map(t.s,function(t){t.off()}),n};var r,u=i.obj,a=(u.has,u.del),s=(u.to,i.val.rel),f=function(){}})(t,"./on"),t(function(n){function e(t,n){n.off(),t.err||i!==t.put||this.not&&this.not.call(t.gun,t.get,function(){o.log("Please report this bug on https://gitter.im/amark/gun and in the issues."),need.to.implement})}var i,r=t("./core");r.chain.not=function(t,n,o){return r.log.once("nottobe","Warning: `.not` to be removed from core (but available as an extension), use `.val` instead, which now supports (v0.7.x+) 'not found data' as `undefined` data in callbacks. If you are opposed to this, please voice your opinion in https://gitter.im/amark/gun and ask others."),this.get(e,{not:t})}})(t,"./not"),t(function(n){function o(t){t.put&&!i.val.is(t.put)&&(this.as.val&&this.off(),u(t.put,e,{cat:this.as,gun:t.gun}),this.to.next(t))}function e(t,n){if(s!==n){var o=this.cat,e=this.gun.get(n),i=e._;(i.echo||(i.echo={}))[o.id]=o}}var i=t("./core");i.chain.map=function(t,n,e){var u,s=this,f=s._;return t?(i.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."),u=s.chain(),s.map().on(function(n,o,e,s){var f=(t||a).call(this,n,o,e,s);if(r!==f)return i.is(f)?void u._.on("in",f._):void u._.on("in",{get:o,put:f,gun:u})}),u):(u=f.fields)?u:(u=f.fields=s.chain(),u._.val=s.back("val"),s.on("in",o,u._),u)};var r,u=i.obj.map,a=function(){},s=i.node._})(t,"./map"),t(function(n){var o=t("./core");o.chain.set=function(t,n,e){var i,r=this;return n=n||function(){},(i=o.node.soul(t))?r.set(r.back(-1).get(i),n,e):o.is(t)?(t.get("_").get(function(t,i){!t.gun||t.gun._.back,i.off(),t=t.gun._.back._;var u={},a=t.put,s=o.node.soul(a);if(!s)return n.call(r,{err:o.log('Only a node can be linked! Not "'+a+'"!')});r.put(o.obj.put(u,s,o.val.rel.ify(s)),n,e)},{wait:0}),t):o.obj.is(t)?r.set(r._.root.put(t),n,e):r.get(o.text.random()).put(t)}})(t,"./set"),t(function(t){if("undefined"!=typeof Gun){var n,o=function(){};"undefined"!=typeof window&&(n=window);var e,i=n.localStorage||{setItem:o,removeItem:o,getItem:o},r={},u={},a=0;Gun.on("put",function(t){function n(){clearTimeout(e);var n=r,f=u;a=0,e=!1,r={},u={},Gun.obj.map(f,function(t,n){t=c[n]||f[n]||t;try{i.setItem(s.prefix+n,JSON.stringify(t))}catch(t){o=t||"localStorage failure"}}),Gun.obj.empty(t.gun.back("opt.peers"))&&Gun.obj.map(n,function(t,n){t.on("in",{"@":n,err:o,ok:0})})}var o,s,f=t.gun._.root;this.to.next(t),(s={}).prefix=(t.opt||s).prefix||t.gun.back("opt.prefix")||"gun/";var c=f._.graph;if(Gun.obj.map(t.put,function(t,n){u[n]=u[n]||c[n]||t}),a+=1,r[t["#"]]=f,a>=1e4)return n();e||(clearTimeout(e),e=setTimeout(n,1e3))}),Gun.on("get",function(t){this.to.next(t);var n,o,e,r=t.gun,a=t.get;if((e=t.opt||{}).prefix=e.prefix||t.gun.back("opt.prefix")||"gun/",a&&(n=a[Gun._.soul])){var s=a["."];o=Gun.obj.ify(i.getItem(e.prefix+n)||null)||u[n]||void 0,o&&s&&(o=Gun.state.to(o,s)),(o||Gun.obj.empty(r.back("opt.peers")))&&r.on("in",{"@":t["#"],put:Gun.graph.node(o),how:"lS"})}})}})(t,"./adapters/localStorage"),t(function(n){function o(t){var n=s,o=this,e=t.wire||i(t,o);if(o.wsp&&o.wsp.count++,e)return e.readyState===e.OPEN?void e.send(n):void(t.queue=t.queue||[]).push(n)}function e(t,n,o){if(o&&t){try{t=JSON.parse(t.data||t)}catch(t){}if(t instanceof Array)for(var i,r=0;i=t[r++];)e(i,n,o);else o.wsp&&1===o.wsp.count&&((t.body||t).wsp=c),o.gun.on("in",t.body||t)}}function i(t,n){if(t&&t.url){var i=t.url.replace("http","ws"),f=t.wire=new a(i,n.opt.wsc.protocols,n.opt.wsc);return f.onclose=function(){r(t,n)},f.onerror=function(o){r(t,n),o&&o.code},f.onopen=function(){var e=t.queue;t.queue=[],u.obj.map(e,function(e){s=e,o.call(n,t)})},f.onmessage=function(o){e(o,t,n)},f}}function r(t,n){clearTimeout(t.defer),t.defer=setTimeout(function(){i(t,n)},2e3)}var u=t("./core");if("undefined"==typeof JSON)throw new Error("Gun depends on JSON. Please load it first:\najax.cdnjs.com/ajax/libs/json2/20110223/json2.js");var a;if("undefined"!=typeof window){a=window.WebSocket||window.webkitWebSocket||window.mozWebSocket;var s,f,c=function(){};u.on("out",function(t){this.to.next(t);var n=t.gun._.root._,e=n.wsp||(n.wsp={});if(!t.wsp||1!==e.count){if(s=JSON.stringify(t),n.udrain)return void n.udrain.push(s);n.udrain=[],clearTimeout(f),f=setTimeout(function(){if(n.udrain){var t=n.udrain;n.udrain=null,t.length&&(s=JSON.stringify(t),u.obj.map(n.opt.peers,o,n))}},1),e.count=0,u.obj.map(n.opt.peers,o,n)}})}})(t,"./polyfill/request")}();