1 |
- !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 b=module;_(function(t){var n,l,p={};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 void 0!==n||void 0}function h(t,n){2!==arguments.length?(h.r=h.r||[]).push(t):(h.r=h.r||{})[t]=n}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 e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0<t;)e+=n.charAt(Math.floor(Math.random()*n.length)),t--;return e},p.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["<"])))},p.text.hash=function(t,n){if("string"==typeof t){if(n=n||0,!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}},p.list={is:function(t){return t instanceof Array}},p.list.slit=Array.prototype.slice,p.list.sort=function(e){return function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n<t?1:0:0}},p.list.map=function(t,n,e){return r(t,n,e)},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,e){return(t||{})[n]=e,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,e,o){return t[n]=t[n]||(o===e?{}:e)},p.obj.ify=function(n){if(g(n))return n;try{n=JSON.parse(n)}catch(t){n={}}return n},p.obj.to=function(t,n){return r(t,e,n=n||{}),n},p.obj.copy=function(t){return t?JSON.parse(JSON.stringify(t)):t},p.obj.empty=function(t,n){return!t||!r(t,o,{n:n})},l=Object.keys,Object.keys=Object.keys||function(t){return n(t,function(t,n,e){e(n)})},p.obj.map=n=function(t,n,e){var o,i,r,a,u,s=0,f="function"==typeof n;if(h.r=o,l&&g(t)&&(a=l(t),u=!0),e=e||{},d(t)||a)for(i=(a||t).length;s<i;s++){var c=s+p.list.index;if(f){if((r=u?n.call(e,t[a[s]],a[s],h):n.call(e,t[s],c,h))!==o)return r}else if(n===t[u?a[s]:s])return a?a[s]:c}else for(s in t)if(f){if(v(t,s)&&(r=e?n.call(e,t[s],s,h):n(t[s],s,h))!==o)return r}else if(n===t[s])return s;return f?h.r:p.list.index?0:-1},p.time={},p.time.is=function(t){return t?t instanceof Date:+(new Date).getTime()};p.fn.is;var d=p.list.is,i=p.obj,g=i.is,v=i.has,r=i.map;t.exports=p})(_,"./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("function"!=typeof e)return(n=n.to)&&void 0!==e&&n.next(e),n;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}})(_,"./onto"),_(function(t){var i="undefined"!=typeof setImmediate?setImmediate:setTimeout,r=[];t.exports=setTimeout.puff=function(t){r.length?r.push(t):(r=[t],i(function t(n){n=n||+new Date;for(var e,o=0;o<9&&(e=r[o++]);)e();if(console.STAT&&console.STAT(n,new Date-n,"puff"),e&&!(new Date-n))return t(n);(r=r.slice(o)).length&&i(t,0)},0))}})(_,"./puff"),_(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}:"function"==typeof n&&(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=+new Date,e=e<t?(o=0,t+u.drift):t+(o+=1)/i+u.drift}n.time.is;var e=-1/0,o=0,i=1e3,r="undefined"!=typeof performance&&(performance.timing&&performance),s=(r&&r.timing&&r.timing.navigationStart||(r=!1),u._=">");function f(t,n){k!==n&&u.ify(this.o,n,this.s)}u.drift=0,u.is=function(t,n,e){var o=n&&t&&t[k]&&t[k][s]||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],s);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}:"function"==typeof n&&(n.map=n):n={},"string"==typeof e&&(n.soul=n.soul||e,e=void 0),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("function"!=typeof t){if(!t||!n)return;var e=t["#"]||t,o=(this.tag||"")[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 yet.",lack:!0}),i.off()},(this.opt||{}).lack||9e3),e}}})(_,"./ask"),_(function(t){var u=_("./type");t.exports=function(i){var r={s:{}},a=r.s;i=i||{max:1e3,age:27e3},r.check=function(t){return!!a[t]&&n(t)};var n=r.track=function(t){var n=a[t]||(a[t]={});return n.was=+new Date,r.to||(r.to=setTimeout(r.drop,i.age+9)),n};return r.drop=function(e){var o=+new Date;u.obj.map(a,function(t,n){t&&(e||i.age)>o-t.was||delete a[n]}),r.to=null,console.STAT&&9<(e=new Date-o)&&console.STAT(o,e,"dup drop")},r}})(_,"./dup"),_(function(t){function x(t){return t instanceof x?(this._={$:this}).$:this instanceof x?x.create(this._={$:this,opt:t}):new x(t)}x.is=function(t){return t instanceof x||t&&t._&&t===t._.$||!1},x.version=.202,(x.chain=x.prototype).toJSON=function(){};var n=_("./type");function r(t,n,e,o){var i=this,r=x.state.is(e,n);if(!r)return i.err="Error: No state on '"+n+"' in node '"+o+"'!";var a=i.graph[o]||G,u=x.state.is(a,n,!0),s=a[n],f=x.HAM(i.machine,r,u,t,s);f.incoming?(i.put[o]=x.state.to(e,n,i.put[o]),(i.diff||(i.diff={}))[o]=x.state.to(e,n,i.diff[o]),i.souls[o]=!0):f.defer&&(i.defer=r<(i.defer||1/0)?r:i.defer)}function a(t,n){var e=this,o=e.$._,i=(o.next||G)[n];if(!i){if(!(o.opt||G).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),m(t,u,a),e.async&&(e.and||o.on("node",function(t){this.to.next(t),t===e.map[t.get]&&(e.souls[t.get]=!1,m(t.put,s,t),m(e.souls,function(t){if(t)return t})||e.c||(e.c=1,this.off(),m(e.map,f,e)))}),e.and=!0,o.on("node",r))}function u(t,n){var e=this.ctx,o=e.graph,i=this.msg,r=i.get,a=i.put,u=i.$._;o[r]=x.state.to(a,n,o[r]),e.async||(u.put=x.state.to(a,n,u.put))}function s(t,n){var e=this.put,o=this.$._;o.put=x.state.to(e,n,o.put)}function f(t,n){t.$&&(this.cat.stop=this.stop,t.$._.on("in",t),this.cat.stop=null)}function c(t,n){if(t!==this.graph[n])return!0}n.obj.to(n,x),x.HAM=_("./HAM"),x.val=_("./val"),x.node=_("./node"),x.state=_("./state"),x.graph=_("./graph"),x.on=_("./onto"),x.ask=_("./ask"),x.dup=_("./dup"),x.puff=_("./puff"),function(){function f(t){if(t)if(t.out!==f){var n,e=this.as,o=e.at||e,i=o.$,r=o.dup,a=t.DBG;(n=t["#"])||(n=t["#"]=p(9)),r.check(n)||(r.track(n),n=t._,t._="function"==typeof n?n:function(){},t.$&&t.$===(t.$._||"").$||(t.$=i),o.ask(t["@"],t)||(a&&(a.u=+new Date),t.get&&x.on._get(t,i),!t.put)?(a&&(a.uc=+new Date),this.to.next(t),a&&(a.ua=+new Date),t.out=f,o.on("out",t),a&&(a.ue=+new Date)):u(t))}else this.to.next(t)}function u(t){if(t){var n,e,o=t._||"",i=o.root=((t.$||"")._||"").root,r=t.put,a=t["#"],u=o.DBG=t.DBG;if(r["#"]&&r["."])i.on("put",t);else{o.out=t,o.lot={s:0,more:1};var s=+new Date;for(var f in u&&(u.p=s),r){var c,l=r[f];if(!l){n=m+k(f)+"no node.";break}if(!(e=l._)){n=m+k(f)+"no meta.";break}if(f!==e[T]){n=m+k(f)+"soul not same.";break}if(!(c=e[A])){n=m+k(f)+"no state.";break}for(var p in l)if(S!==p){var h=l[p],d=c[p];if(w===d){n=m+k(p)+"on"+k(f)+"no state.";break}if(!D(h)){n=m+k(p)+"on"+k(f)+"bad "+typeof h+k(h);break}g(h,p,f,d,t)}if(n)break}u&&(u.pe=+new Date),console.STAT&&(console.STAT(s,new Date-s,"mix"),console.STAT(s,o.lot.s,"mix #")),(o.err=n)?i.on("in",{"@":a,err:x.log(n)}):(--o.lot.more||v(o),o.stun||t["@"]||i.on("in",{"@":a,ok:-1}))}}}function g(t,n,e,o,i){var r,a=i._||"",u=a.root,s=u.graph[e]||G,f=j(s,n,1),c=s[n],l=_(),p=b(l,o,f,t,c);if(p.incoming){(r=a.lot||"").s++,r.more++,(a.stun||(a.stun={}))[e+n]=1;var h=a.DBG;h&&(h.ph=h.ph||+new Date),u.on("put",{"#":i["#"],"@":i["@"],put:{"#":e,".":n,":":t,">":o},_:a})}else if(p.defer){var d=o-l;return setTimeout(function(){g(t,n,e,o,i)},y<d?y:d),a.to||u.on("in",{"@":i["#"],err:d}),a.to=1,d}}function e(t){var n;(n=(t._||"").DBG)&&(n.pa=+new Date,n.pm=n.pm||+new Date);var e,o=this.as.graph,i=t._,r=t.put,a=r["#"],u=r["."],s=r[":"],f=r[">"];t["#"];o[a]=$(o[a],u,f,s,a),function(t,n,e,o,i){var r,a,u=t.root;if((u.opt||"").super&&u.$.get(n),!(u&&(a=u.next)&&(a=a[n])&&a.$))return;(r=t.put||(t.put={}))[n]=$(r[n],e,i,o,n),a.put=$(a.put,e,i,o,n)}(i,a,u,w!==(e=r["="])?e:s,f),(e=i.out)&&(e=e.put)&&(e[a]=$(e[a],u,f,s,a)),--i.lot.more||v(i),this.to.next(t)}function v(t){if(!t.err){var n,e={},o=t.root,i=o.next||"",r=t.put,a=+new Date;for(var u in r){var s=r[u];(n=i[u])&&n.$&&(o.stop=e,n.on("in",{$:n.$,get:u,put:s}),o.stop=null)}console.STAT&&console.STAT(a,new Date-a,"fire"),t.DBG&&(t.DBG.f=+new Date),(n=t.out)&&(n.out=f,o.on("out",n))}}x.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||x.on,t.ask=t.ask||x.ask,t.dup=t.dup||x.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",f,t),t.on("out",f,t),t.on("put",e,t),x.on("create",t),t.on("create",t)),t.once=1,n},x.on.put=u;var m="Error: Invalid graph!",k=function(t){return" '"+(""+t).slice(0,9)+"...' "},b=x.HAM,y=2147483647,_=x.state}(),x.on._put=function(t,n){var e=n._,o={$:n,graph:e.graph,put:{},map:{},souls:{},machine:x.state(),ack:t["@"],cat:e,stop:{}};if(x.obj.map(t.put,c,o)){if(x.graph.is(t.put,null,r,o)||(o.err="Error: Invalid graph!"),o.err)return e.on("in",{"@":t["#"],err:x.log(o.err)});if(m(o.put,a,o),o.async||m(o.map,f,o),w!==o.defer){var i=o.defer-o.machine;setTimeout(function(){x.on._put(t,n)},i>MD?MD:i)}o.diff&&e.on("put",v(t,{put:o.diff}))}},x.on._get=function(t,n){var e=n._,o=t.get,i=o[T],r=e.graph[i],a=o[k],u=(e.next||(e.next={}))[i],s=(t._||"").DBG=t.DBG;if(s&&(s.g=+new Date),!r)return e.on("get",t);if(a){if("string"!=typeof a||!g(r,a))return e.on("get",t);r=x.state.to(r,a)}else r=x.window?x.obj.copy(r):r;r=x.graph.node(r),(u||G).ack;function f(){}f.ram=f.faith=!0,s&&(s.ga=+new Date),e.on("in",{"@":t["#"],put:r,ram:1,$:n,_:f}),s&&(s.gm=+new Date),e.on("get",t),s&&(s.gd=+new Date)},x.chain.opt=function(t){t=t||{};var n=this._,e=t.peers||t;return d(t)||(t={}),d(n.opt)||(n.opt=t),l(e)&&(e=[e]),o(e)&&(e=m(e,function(t,n,e){(n={}).id=n.url=t,e(t,n)}),d(n.opt.peers)||(n.opt.peers={}),n.opt.peers=v(e,n.opt.peers)),n.opt.peers=n.opt.peers||{},m(t,function t(n,e){!g(this,e)||i.is(n)||h.empty(n)?this[e]=n:n&&n.constructor!==Object&&!o(n)||m(n,t,this[e])},n.opt),x.on("opt",n),x.obj.native(),this},x.obj.native=function(){var t=Object.prototype;for(var n in t)console.log("Native Object.prototype polluted, reverting",n),delete t[n]};var w,e,o=x.list.is,i=x.text,l=i.is,p=i.random,h=x.obj,d=(h.empty,h.is),g=h.has,v=h.to,m=h.map,$=(h.copy,x.state.lex,x.state.ify),j=x.state.is,T=x.val.link._,k=".",S=x.node._,D=x.val.is,A=(x.val.link.is,x.state._),G={};(x.log=function(){return x.log.off||e.log.apply(e,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,e){return(e=x.log.once)[t]=e[t]||0,e[t]++||x.log(n)},"undefined"!=typeof window&&((window.GUN=window.Gun=x).window=window);try{void 0!==b&&(b.exports=x)}catch(t){}((t.exports=x).window||"").console=(x.window||"").console||{log:function(){}},(e=console).only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},x.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!")})(_,"./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("function"!=typeof t)return u.num.is(t)?(e.back||e).$.back(t-1):this;var a;for(r={back:e};(r=r.back)&&void 0===(a=t(r,n)););return a};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||{})._;if(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})),n=o.lex){if(n=n._||(n._=function(){}),i.ack<n.ask&&(n.ask=i.ack),n.ask)return;n.ask=1}}}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||"",i=e.$._,r=(t.put||"")[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.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.$.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("function"!=typeof t)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);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(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&&"function"==typeof n&&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 c=_("./root");function u(t){t&&t()}function s(){var r=this;r.graph&&n(r.stun)&&(r.res=r.res||function(t){t&&t()},r.res(function(){delete r.via._.stun;var n=r.$.back(-1)._,t=n.ask(function(t){n.root.on("ack",t),t.err&&c.log(t),++e>(r.acks||0)&&this.off(),r.ack&&r.ack(t,this)},r.opt),e=0,o=n.root.now;a.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?a.to(i,n.root.mum):i,n.root.now=o,r.via._.on("res",{}),delete r.via._.tag.res},r),r.res&&r.res())}function f(r,t,n,a){var u=this,s=c.is(r);!t&&a.path.length&&(u.res||e)(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||c.node.soul(a.obj))return n.back(-1).get(i),void a.soul(i);(u.stun=u.stun||{})[t]=1,n.get(l,!0,{as:{at:a,as:u,p:t,ref:n}})},{as:u,at:a})}c.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=c.node.soul(i.data)||(i.via.back("opt.uuid")||c.text.random)()),i.via._.stun={},i.soul?(i.$=a.get(i.soul),i.ref=i.$,function(t){t.batch=s;var n=t.opt||{},e=t.env=c.state.map(f,n.state);if(e.soul=t.soul,t.graph=c.graph.ify(t.data,e,t),e.err)return(t.ack||m).call(t,t.out={err:c.log(e.err)}),t.res&&t.res();t.batch()}(i)):i.via.back("opt.uuid")(function(t,n){if(t)return c.log(t);(i.ref||i.$).put(i.data,i.soul=n,i)}),r):((i.ack||m).call(i,i.out={err:c.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):(i.via._.stun={},c.is(t)?(t.get(function(t,n,e){if(!t)return delete i.via._.stun,c.log("The reference you are saving is a",typeof e.put,'"'+e.put+'", not a node (object)!');r.put(c.val.link.ify(t),o,i)},!0),r):(e.has&&(n=c.val.link.is(t))&&(e.dub=n),i.ref=i.ref||a._===(n=e.back)?r:n.$,i.ref._.soul&&c.val.is(i.data)&&e.get?(i.data=g({},e.get,i.data),i.ref.put(i.data,i.soul,i)):(i.ref.get(h,!0,{as:i}),i.out||(i.res=i.res||u,i.$._.stun=i.ref._.stun)),r))};String.fromCharCode(31);function l(t,e,n,o){var i=(e=e.as).p,r=e.ref,a=e.at;e=e.as;var u=r.back(function(t){return u=t.soul||t.link||t.dub}),s=[u||e.soul].concat(r._.has||r._.get||i),f=((n||{}).$||{})._||{};t=f.dub=f.dub||t||c.node.soul(a.obj)||c.node.soul(n.put||f.put)||c.val.link.is(n.put||f.put)||s.join("/"),o&&(o.stun=!0),t?p(f,f.dub=t,a,e):e.via.back("opt.uuid")(function(t,n){if(t)return c.log(t);p(f,f.dub=f.dub||n,a,e)})}function p(t,n,e,o){t.$.back(-1).get(n),e.soul(n),delete o.stun[e.path],o.batch()}function h(t,e,n,o){if(e=e.as,n.$&&n.$._)if(n.err)c.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 delete e.via._.stun,void c.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 void delete e.via._.stun;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")||c.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")||c.text.random)()),e.soul)?e.ref.put(e.data,e.soul,e):e.via.back("opt.uuid")(function(t,n){if(t)return delete e.via._.stun,c.log(t);e.ref.put(e.data,e.soul=n,e)})}}}var a=c.obj,d=a.is,g=a.put,n=(a.map,a.empty),v={},m=function(){},e=function(t,n){t.call(n||v)},k=c.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 u=_("./index");function n(){return u.state.lex()+u.text.random(7)}u.chain.set=function(o,i,r){var t,a=this;return i=i||function(){},(r=r||{}).item=r.item||o,(t=u.node.soul(o))&&(o=u.obj.put({},t,u.val.link.ify(t))),u.is(o)?(o.get(function(t,n,e){if(t||!o._.stun)return t?void a.put(u.obj.put({},t,u.val.link.ify(t)),i,r):i.call(a,{err:u.log('Only a node can be linked! Not "'+e.put+'"!')});o._.on("res",function(){this.off(),a.set(o,i,r)})},!0),o):(u.obj.is(o)&&(t=t||u.node.soul(o)||n()),a.get(t||n()).put(o,i,r))}})(_,"./set"),_(function(t){if("undefined"!=typeof Gun){var h;try{h=(Gun.window||function(){}).localStorage}catch(t){}h||(Gun.log("Warning: No localStorage exists to persist data to!"),h={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(h.getItem("gap/"+e.prefix))||{},a=Gun.obj.empty;if(!a(r)){var u=Gun.obj.ify(h.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{h.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 u=a.opt;if(!a.once&&!1!==u.localStorage){u.prefix=u.file||"gun/";a.graph;var s,f={},c=0,l=Gun.obj.ify(h.getItem(u.prefix))||{};a.on("localStorage",l),a.on("put",function(t){this.to.next(t);var n,e=t.put,o=e["#"],i=e["."],r=e[":"],a=e[">"];if(l[o]=Gun.state.ify(l[o],i,a,r,o),t["@"]||((f[t["#"]]=n=(t._||"").lot||{}).lS=(n.lS||0)+1),(c+=1)>=(u.batch||1e3))return p();s=s||setTimeout(p,u.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=l[e]||i)&&t&&(o=Gun.state.to(o,t)),a.on("in",{"@":n["#"],put:Gun.graph.node(o),lS:1})}}Gun.debug?setTimeout(t,1):t()});var p=function(t){var e;c=0,clearTimeout(s),s=!1;var n=f;f={},t&&(l=t);try{h.setItem(u.prefix,JSON.stringify(l))}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:u.prefix,flush:l,retry:p})}(e||Gun.obj.empty(u.peers))&&Gun.obj.map(n,function(t,n){if(t){if(t.more)return void(f[n]=t);t.s!==t.lS&&(e="localStorage batch not same.")}a.on("in",{"@":n,err:e,ok:0})})}}})}})(_,"./adapters/localStorage"),_(function(t){var e,x=_("../type");function o(t,n){var e;if(!(n instanceof Object))return n;var o=+new Date;return x.obj.map(Object.keys(n).sort(),i,{to:e={},on:n}),console.STAT&&console.STAT(o,new Date-o,"sort"),e}function i(t){this.to[t]=this.on[t]}e=JSON.stringify,x.obj.hash=function(t,n){if(n||void 0!==(t=e(t,o)))return x.text.hash(n||t||"")},x.obj.hash.sort=o;var w=x.obj.is;x.obj.map;try{t.exports=function(f){var l=function(){},p=f.opt||{};p.log=p.log||console.log,p.gap=p.gap||p.wait||0,p.pack=p.pack||.3*(p.memory?1e3*p.memory*1e3:1399e6),p.puff=p.puff||9;var h,d,g,v=setTimeout.puff||setTimeout,m=f.dup,c=m.check,k=m.track,b=l.hear=function(t,i){if(t){if(p.pack<=t.length)return l.say({dam:"!",err:"Message too big!"},i);var r,n,e,o=t[0];if(l===this&&(b.d+=t.length||0,++b.c),"["!==o){if("{"===o||(t["#"]||w(t))&&(r=t)){try{r=r||JSON.parse(t)}catch(t){return p.log("DAM JSON parse error",t)}if(!r)return;if(r.DBG&&(r.DBG=e={DBG:r.DBG}),e&&(e.hp=+new Date),(n=r["#"])||(n=r["#"]=x.text.random(9)),o=c(n))return;if((r._=function(){}).via=l.leap=i,o=r.dam)return(o=l.hear[o])&&o(r,i,f),void k(n);var a,u=+new Date;e&&(e.is=u),f.on("in",r),e&&(e.hd=+new Date),console.STAT&&9<(a=new Date-u)&&console.STAT(u,a,"msg"),k(n).via=i,l.leap=null}}else{try{r=JSON.parse(t)}catch(t){p.log("DAM JSON parse error",t)}if(t="",!r)return;console.STAT&&console.STAT(+new Date,r.length,"# on hear batch");var s=p.puff;(function t(){for(var n,e=+new Date,o=0;o<s&&(n=r[o++]);)b(n,i);r=r.slice(o),console.STAT&&console.STAT(e,new Date-e,"hear loop"),y(i),r.length&&v(t,0)})()}}};function y(t){var n=t.batch,e="string"==typeof n;if(e&&(n+="]"),t.batch=t.tail=null,n&&(e?!(n.length<3):n.length)){if(!e)try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return p.log("DAM JSON stringify error",t)}n&&_(n,t)}}function _(n,e){try{var t=e.wire;e.say?e.say(n):t.send&&t.send(n),l.say.d+=n.length||0,++l.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}b.c=b.d=0,d=0,g=l.say=function(r,t){if(this&&this.to&&this.to.next(r),!r)return!1;var n,e,a,o=r.DBG;t||(s=+new Date,o&&(o.y=s));var u=r._||(r._=function(){});if((n=r["#"])||(n=r["#"]=x.text.random(9)),(a=u.raw)||(a=l.raw(r)),s&&console.STAT&&console.STAT(s,new Date-s,"say prep"),h||k(n),!t&&(e=r["@"])&&(t=(e=m.s[e])&&(e.via||(e=e.it)&&(e=e._)&&e.via)||l.leap),!t&&r["@"])return console.STAT&&console.STAT(+new Date,++d,"total no peer to ack to"),!1;if(!t&&l.way)return l.way(r);if(t&&t.id){if(!t.wire&&l.wire&&l.wire(t),n!==t.last){if(t.last=n,t===u.via)return!1;if((e=u.to)&&(e[t.url]||e[t.pid]||e[t.id]))return!1;if(t.batch){if(t.tail=(e=t.tail||0)+a.length,t.tail<=p.pack)return void(t.batch+=(e?",":"")+a);y(t)}t.batch="[";var i,s=+new Date;setTimeout(function(){console.STAT&&9<(i=new Date-s)&&console.STAT(s,i,"0ms TO",n,t.id),y(t)},p.gap),_(a,t)}}else{if(!x.obj.is(t||p.peers))return!1;p.puff;var f=p.peers,c=Object.keys(t||p.peers||{});(function t(){var n=+new Date;h=1;var e=u.raw;u.raw=a;for(var o,i=0;i<9&&(o=(c||"")[i++]);)(o=f[o])&&g(r,o);u.raw=e,h=0,c=c.slice(i),console.STAT&&console.STAT(n,new Date-n,"say loop"),c.length&&(v(t,0),k(r["@"]))})()}},l.say.c=l.say.d=0,function(){l.raw=function(t){if(!t)return"";var n,e=t._||{};if(n=e.raw)return n;if("string"==typeof t)return t;var o=i(t);return e&&(o||"").length<1e5&&(e.raw=o),o};var i=JSON.stringify}(),l.hi=function(n){var t=n.wire||{};n.id?p.peers[n.url||n.id]=n:(t=n.id=n.id||x.text.random(9),l.say({dam:"?",pid:f.opt.pid},p.peers[t]=n),delete m.s[n.last]),n.met=n.met||+new Date,t.hied||f.on(t.hied="hi",n),t=n.queue,n.queue=[],x.obj.map(t,function(t){_(t,n)}),x.obj.native&&x.obj.native()},l.bye=function(t){f.on("bye",t);var n=+new Date;n-=t.met||n,l.bye.time=((l.bye.time||n)+n)/2},l.hear["!"]=function(t,n){p.log("Error:",t.err)},l.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(l.say({dam:"?",pid:p.pid,"@":t["#"]},n),delete m.s[n.last])},f.on("create",function(t){t.opt.pid=t.opt.pid||x.text.random(9),this.to.next(t),t.on("out",l.say)}),f.on("bye",function(t,n){t=p.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),x.obj.del(p.peers,t.id),t.wire=null});var i={};return f.on("bye",function(t,n){this.to.next(t),(n=t.url)&&(i[n]=!0,setTimeout(function(){delete i[n]},p.lack||9e3))}),f.on("hi",function(e,o){this.to.next(e),(o=e.url)&&i[o]&&(delete i[o],p.super||x.obj.map(f.next,function(t,n){(o={})[n]=f.graph[n],l.say({"##":x.obj.hash(o),get:{"#":n}},e)}))}),l}}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")}();
|