-
Notifications
You must be signed in to change notification settings - Fork 0
/
gun.min.js
1 lines (1 loc) · 40.1 KB
/
gun.min.js
1
!function(){function T(e,t){return t?require(e):e.slice?T[o(e)]:function(t,n){e(t={exports:{}}),T[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}var n;"undefined"!=typeof module&&(n=module),T(function(t){String.random=function(t,n){var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0<t--;)e+=n.charAt(Math.floor(Math.random()*n.length));return e},String.match=function(t,n){var e,o;return"string"==typeof t&&(t===((n=(n="string"==typeof n?{"=":n}:n)||{})["="]||n["*"]||n[">"]||n["<"])||o===n["="]&&(e=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["<"])))},String.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}};var n,e,o,i,r,a,s,u,c,f,l,h,p,d,g,v,y=Object.prototype.hasOwnProperty;Object.plain=function(t){return!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])},Object.empty=function(t,n){for(var e in t)if(y.call(t,e)&&(!n||-1==n.indexOf(e)))return!1;return!0},Object.keys=Object.keys||function(t){var n,e=[];for(n in t)y.call(t,n)&&e.push(n);return e},o=setTimeout,r=i=0,a=typeof setImmediate!=""+g&&setImmediate||(typeof MessageChannel==""+g?o:((n=new MessageChannel).port1.onmessage=function(t){""==t.data&&e()},function(t){e=t,n.port2.postMessage("")})),s=o.check=o.check||typeof performance!=""+g&&performance||{now:function(){return+new Date}},o.hold=o.hold||9,o.poll=o.poll||function(t){o.hold>=s.now()-i&&r++<3333?t():a(function(){i=s.now(),t()},r=0)},g=setTimeout,f=(c=g.turn=g.turn||function(t){1==f.push(t)&&l(p)}).s=[],l=g.poll,h=0,p=function(){(u=f[h++])&&u(),h!=f.length&&99!=h||(f=c.s=f.slice(h),h=0),f.length&&l(p)},g=setTimeout,v=g.turn,(g.each=g.each||function(r,a,s,u){u=u||9,function t(n,e,o){if(e=(n=(r||[]).splice(0,u)).length){for(var i=0;i<e&&d===(o=a(n[i]));i++);if(d===o)return void v(t)}s&&s(o)}()})()})(T,"./shim"),T(function(t){t.exports=function t(n,e,o){if(!n)return{to:t};var i="function"==typeof e,n=(this.tag||(this.tag={}))[n]||i&&(this.tag[n]={tag:n,to:t._={next:function(t){var n;(n=this.to)&&n.next(t)}}});if(i){o={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(o.back=n.last||n).to=o,n.last=o}return(n=n.to)&&void 0!==e&&n.next(e),n}})(T,"./onto"),T(function(t){t.exports=function(t){return null===t||"string"==typeof t||"boolean"==typeof t||"number"==typeof t&&t!=1/0&&t!=-1/0&&t==t||!!t&&"string"==typeof t["#"]&&1===Object.keys(t).length&&t["#"]}})(T,"./valid"),T(function(t){function n(){var t=+new Date;return i=i<t?(e=0,t+n.drift):t+(e+=1)/o+n.drift}T("./shim");n.drift=0;var e=0,o=999,i=-1/0;n.is=function(t,n,e){e=n&&t&&t._&&t._[">"]||e;if(e)return"number"==typeof(e=e[n])?e:-1/0},n.ify=function(t,n,e,o,i){(t=t||{})._=t._||{},i&&(t._["#"]=i);i=t._[">"]||(t._[">"]={});return void 0!==n&&"_"!==n&&("number"==typeof e&&(i[n]=e),void 0!==o&&(t[n]=o)),t},t.exports=n})(T,"./state"),T(function(t){T("./shim"),t.exports=function(o){var i={s:{}},r=i.s;o=o||{max:999,age:9e3},i.check=function(t){return!!r[t]&&n(t)};var n=i.track=function(t){t=r[t]||(r[t]={});return t.was=i.now=+new Date,i.to||(i.to=setTimeout(i.drop,o.age+9)),t};return i.drop=function(e){i.to=null,i.now=+new Date;var t=Object.keys(r);console.STAT&&console.STAT(i.now,+new Date-i.now,"dup drop keys"),setTimeout.each(t,function(t){var n=r[t];n&&(e||o.age)>i.now-n.was||delete r[t]},0,99)},i}})(T,"./dup"),T(function(t){T("./onto"),t.exports=function(t,n){if(this.on){var e=(this.opt||{}).lack||9e3;if("function"!=typeof t){if(!t)return;var o=t["#"]||t,i=(this.tag||"")[o];return i?(n&&(i=this.on(o,n),clearTimeout(i.err),i.err=setTimeout(function(){i.off()},e)),!0):void 0}o=n&&n["#"]||a(9);if(!t)return o;var r=this.on(o,t,n);return r.err=r.err||setTimeout(function(){r.off(),r.next({err:"Error: No ACK yet.",lack:!0})},e),o}};var a=String.random||function(){return Math.random().toString(36).slice(2)}})(T,"./ask"),T(function(t){function f(t){return t instanceof f?(this._={$:this}).$:this instanceof f?f.create(this._={$:this,opt:t}):new f(t)}function a(t,a){var s=+new Date,n=t._||{},u=n.DBG=t.DBG,c=t["#"],f=g(9),l=Object.keys(a||"").sort(),h=((a||"")._||"")["#"],p=(l.length,t.$._.root),d=a===p.graph[h];console.STAT&&console.STAT(s,((u||n).gk=+new Date)-s,"got keys"),a&&function t(){s=+new Date;for(var n,e,o,i=0,r={};i<9&&(n=l[i++]);)v(r,n,G(a,n),a[n],h);l=l.slice(i),(e={})[h]=r,r=e,d&&((o=function(){}).ram=o.faith=!0),e=l.length,console.STAT&&console.STAT(s,-(s-(s=+new Date)),"got copied some"),u&&(u.ga=+new Date),p.on("in",{"@":c,"#":f,put:r,"%":e?f=g(9):O,$:p.$,_:o,DBG:u}),console.STAT&&console.STAT(s,+new Date-s,"got in"),e&&setTimeout.turn(t)}(),a||p.on("in",{"@":t["#"]})}f.is=function(t){return t instanceof f||t&&t._&&t===t._.$||!1},f.version=.202,(f.chain=f.prototype).toJSON=function(){},T("./shim"),f.valid=T("./valid"),f.state=T("./state"),f.on=T("./onto"),f.dup=T("./dup"),f.ask=T("./ask"),function(){function b(t){if(t)if(t.out!==b){var n,e,o=this.as,i=o.at||o,r=i.$,a=i.dup,s=t.DBG;if((e=t["#"])||(e=t["#"]=g(9)),!a.check(e)){if(a.track(e),e=t._,t._="function"==typeof e?e:function(){},t.$&&t.$===(t.$._||"").$||(t.$=r),t["@"]&&!t.put&&(a=(o=t)["@"]||"",(n=a._)?(n.acks=(n.acks||0)+1,(n.err=o.err)&&(o["@"]=n["#"],_(n)),n.ok=o.ok||n.ok,n.stop||n.crack||(n.crack=n.match&&n.match.push(function(){c(n)})),c(n)):(e=(e=(e=o.$)&&(e=e._)&&(e=e.root)&&e.dup).check(a))&&(o["@"]=e["#"]||o["@"])),!i.ask(t["@"],t)){if(s&&(s.u=+new Date),t.put)return void u(t);t.get&&f.on.get(t,r)}s&&(s.uc=+new Date),this.to.next(t),s&&(s.ua=+new Date),t.nts||t.NTS||(t.out=b,i.on("out",t),s&&(s.ue=+new Date))}}else this.to.next(t)}function u(a){if(a){var s=a._||"",t=s.root=((s.$=a.$||"")._||"").root;if(a["@"]&&s.faith&&!s.miss)return a.out=b,void t.on("out",a);s.latch=t.hatch,s.match=t.hatch=[];var u,c,f,l,h,p,d,g,v,y=a.put,k=s.DBG=a.DBG,m=+new Date;n=n||m,y["#"]&&y["."]||(k&&(k.p=m),s["#"]=a["#"],s.msg=a,s.all=0,s.stun=1,u=Object.keys(y),console.STAT&&console.STAT(m,((k||s).pk=+new Date)-m,"put sort"),c=0,function t(n){if(f!=c){if(!(h=u[f=c]))return console.STAT&&console.STAT(m,((k||s).pd=+new Date)-m,"put"),void _(s);(p=y[h])?(v=p._)?h!==v["#"]?g=w+$(h)+"soul not same.":(d=v[">"])||(g=w+$(h)+"no state."):g=w+$(h)+"no meta.":g=w+$(h)+"no node.",l=Object.keys(p||{})}if(g)return a.err=s.err=g,void _(s);var e,o=0;for(n=n||0;n++<9&&(e=l[o++]);)if("_"!==e){var i=p[e],r=d[e];if(O===r){g=w+$(e)+"on"+$(h)+"no state.";break}if(!A(i)){g=w+$(e)+"on"+$(h)+"bad "+typeof i+$(i);break}!function t(n,e,o,i,r){var a=r._||"",s=a.root,u=s.graph;var c=u[o]||N,f=G(c,e,1),l=c[e];var h=a.DBG;(c=console.STAT)&&(u[o]&&l||(c.has=(c.has||0)+1));u=x();if(u<i)return setTimeout(function(){t(n,e,o,i,r)},(c=i-u)>j?j:c),void(console.STAT&&console.STAT((h||a).Hf=+new Date,c,"future"));if(i<f)return void 0;if(!a.faith&&i===f&&(n===l||T(n)<=T(l))&&!a.miss)return;a.stun++;var p=r["#"]+a.all++,l={toString:function(){return p},_:a};l.toJSON=l.toString;s.dup.track(l)["#"]=r["#"];h&&(h.ph=h.ph||+new Date);s.on("put",{"#":l,"@":r["@"],put:{"#":o,".":e,":":n,">":i},ok:r.ok,_:a})}(i,e,h,r,a),++S}(l=l.slice(o)).length?D(t):(++c,l=null,t(n))}())}}function e(t){(u=(t._||"").DBG)&&(u.pa=+new Date,u.pm=u.pm||+new Date);var n=this.as,e=n.graph,o=t._,i=t.put,r=i["#"],a=i["."],s=i[":"],u=i[">"];t["#"];(i=o.msg)&&(i=i.put)&&(i=i[r])&&v(i,a,u,s,r),e[r]=v(e[r],a,u,s,r),(i=(n.next||"")[r])&&i.on("in",t),_(o),this.to.next(t)}function _(t,n){var e,o;t.stop||!t.err&&0<--t.stun||(t.stop=1,(e=t.root)&&((o=t.match).end=1,o===e.hatch&&(!(o=t.latch)||o.end?delete e.hatch:e.hatch=o),t.hatch&&t.hatch(),setTimeout.each(t.match,function(t){t&&t()}),!(n=t.msg)||t.err||n.err||(n.out=b,t.root.on("out",n),i())))}function c(t){t&&t.root&&(t.stun||t.acks!==t.all||t.root.on("in",{"@":t["#"],err:t.err,ok:t.err?O:t.ok||{"":1}}))}f.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||f.on,t.ask=t.ask||f.ask,t.dup=t.dup||f.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",b,t),t.on("out",b,t),t.on("put",e,t),f.on("create",t),t.on("create",t)),t.once=1,n},f.on.put=u;var n,w="Error: Invalid graph!",$=function(t){return" '"+(""+t).slice(0,9)+"...' "},T=JSON.stringify,j=2147483647,x=f.state,S=0,i=function(){999<S&&1<S/-(n-(n=+new Date))&&(f.window&&console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query."),i=function(){S=0})}}(),f.on.get=function(t,n){var e=n._,o=t.get,i=o["#"],r=e.graph[i],n=o["."],o=((e.next||(e.next={}))[i],(t._||{}).DBG=t.DBG);if(o&&(o.g=+new Date),!r)return e.on("get",t);if(n){if("string"!=typeof n||O===r[n])return e.on("get",t);r=v({},n,G(r,n),r[n],i)}r&&a(t,r),e.on("get",t)},f.on.get.ack=a,f.chain.opt=function(e){e=e||{};var o=this._,t=e.peers||e;return Object.plain(e)||(e={}),Object.plain(o.opt)||(o.opt=e),"string"==typeof t&&(t=[t]),Object.plain(o.opt.peers)||(o.opt.peers={}),t instanceof Array&&(e.peers={},t.forEach(function(t){var n={};n.id=n.url=t,e.peers[t]=o.opt.peers[t]=o.opt.peers[t]||n})),i(e,function t(n){var e=this[n];this&&this.hasOwnProperty(n)||"string"==typeof e||Object.empty(e)?this[n]=e:(!e||e.constructor===Object||e instanceof Array)&&i(e,t)}),o.opt.from=e,f.on("opt",o),o.opt.uuid=o.opt.uuid||function(t){return f.state().toString(36).replace(".","")+String.random(t||12)},this};var O,e,i=function(t,n){Object.keys(t).forEach(n,t)},g=String.random,D=setTimeout.turn,A=f.valid,G=f.state.is,v=f.state.ify,N={};(f.log=function(){return f.log.off||e.log.apply(e,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,e){return(e=f.log.once)[t]=e[t]||0,e[t]++||f.log(n)},"undefined"!=typeof window&&((window.GUN=window.Gun=f).window=window);try{void 0!==n&&(n.exports=f)}catch(t){}((t.exports=f).window||{}).console=(f.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)},f.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!")})(T,"./root"),T(function(t){T("./root").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((t="string"==typeof 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"number"==typeof t?(e.back||e).$.back(t-1):this;for(var a,r={back:e};(r=r.back)&&void 0===(a=t(r,n)););return a};var s={}})(T,"./back"),T(function(t){var r=T("./root");function l(t,n){if(n=n||this.as||t.$._,(!t.$$||this===r.on)&&t.put&&!n.soul){var e=t.put||"",o=e["="]||e[":"],t=n.root,e=t.$.get(e["#"]).get(e["."])._;if("string"==typeof(o=g(o))){if(!(e.echo||(e.echo={}))[n.id]||(t.pass||"")[n.id]){if(i=t.pass){if(i[o+n.id])return;i[o+n.id]=1}((e.echo||(e.echo={}))[n.id]=n).has&&(n.link=o);var i,t=t.$.get(e.link=o)._;(t.echo||(t.echo={}))[e.id]=e,((i=n.ask||"")[""]||n.lex)&&t.on("out",{get:{"#":o}}),setTimeout.each(Object.keys(i),function(t,n){t&&(n=i[t])&&n.on("out",{get:{"#":o,".":t}})},0,99)}}else this===r.on&&((e.echo||(e.echo={}))[n.id]=n)}}function h(t,e){var o,n,i=t.put||"",i=p!==i["="]?i["="]:i[":"],r=e.root;if(p===i)return e.soul&&p!==e.put?void 0:(n=(t.$$||t.$||"")._||"",!t["@"]||p===n.put&&p===e.put?((o=e.link||t.linked)&&delete(r.$.get(o)._.echo||"")[e.id],e.has&&(e.link=null),e.put=p,void setTimeout.each(Object.keys(e.next||""),function(t,n){(n=e.next[t])&&(o&&delete(r.$.get(o).get(t)._.echo||"")[n.id],n.on("in",{get:t,put:p,$:n.$}))},0,99)):void 0);e.soul||t.$$||(o=g(i),n=t.$._||"",(o!==n.link&&(!e.has||n.link)||(r.pass||"")[e.id]&&"string"!=typeof o)&&(delete(n.echo||"")[e.id],h({get:e.get,put:p,$:t.$,linked:t.linked=t.linked||n.link},e)))}function a(t,n){var e=this.as,o=e.$._,i=(o.root,e.get||""),e=(t.put||"")[i["#"]]||"";if(!t.put||"string"==typeof i["."]&&p===e[i["."]])return p===o.put&&(o.soul||o.has)?(o.ack=(o.ack||0)+1,void o.on("in",{get:o.get,put:o.put=p,$:o.$,"@":t["@"]})):void 0;(t._||{}).miss=1,r.on.put(t)}r.chain.chain=function(t){var n=this,e=n._,o=new(t||n).constructor(n),t=o._;return t.root=e=e.root,t.id=++e.once,t.back=n._,t.on=r.on,t.on("in",r.on.in,t),t.on("out",r.on.out,t),o},r.on.out=function(t){var n,e,o=this.as,i=o.back,r=o.root;if(t.$||(t.$=o.$),this.to.next(t),!o.err){if(n=t.get){if(r.pass&&(r.pass[o.id]=o),o.lex&&Object.keys(o.lex).forEach(function(t){e[t]=o.lex[t]},e=t.get=t.get||{}),n["#"]||o.soul){if(n["#"]=n["#"]||o.soul,t["#"]||(t["#"]=s(9)),i=r.$.get(n["#"])._,n=n["."]){if(u(i.put,n)&&(e=i.ask&&i.ask[n],(i.ask||(i.ask={}))[n]=i.$.get(n)._,i.on("in",{get:n,put:{"#":i.soul,".":n,":":i.put[n],">":v(r.graph[i.soul],n)}}),e))return}else{if(e=i.ask&&i.ask[""],(i.ask||(i.ask={}))[""]=i,p!==i.put&&(i.on("in",i),e))return;t.$=i.$}return r.ask(a,t),r.on("in",t)}if(n["."])return o.get?(t={get:{".":o.get},$:o.$},(i.ask||(i.ask={}))[o.get]=t.$._):t={get:o.lex?t.get:{},$:o.$},i.on("out",t);if(((o.ask||(o.ask={}))[""]=o).get)return n["."]=o.get,(i.ask||(i.ask={}))[o.get]=t.$._,i.on("out",t)}return i.on("out",t)}o.on("in",{put:o.put=p,$:o.$})},r.on.in=function(n,e){var o,t,i=(e=e||this.as).root,r=((o=n.$||(n.$=e.$))||"")._||d,a=n.put||"",s=a["#"],u=a["."],c=p!==a["="]?a["="]:a[":"],f=a[">"]||-1/0;if(p!==n.put&&(p===a["#"]||p===a["."]||p===a[":"]&&p===a["="]||p===a[">"]))return g(a)?void e.on("in",{$:r.back.$,put:{"#":s=r.back.soul,".":u=r.has||r.get,"=":a,">":v(r.back.put,u)},via:n}):(s=((a||"")._||"")["#"])?(o=e.root.$.get(s),setTimeout.each(Object.keys(a).sort(),function(t){"_"!=t&&p!==(f=v(a,t))&&e.on("in",{$:o,put:{"#":s,".":t,"=":a[t],">":f},VIA:n})})):void console.log("chain not yet supported for",a,"...",n,e);(n.seen||"")[e.id]||(((n.seen||(n.seen=function(){}))[e.id]=e)!==r&&(Object.keys(n).forEach(function(t){a[t]=n[t]},a={}),a.get=e.get||a.get,e.soul||e.has?r.soul&&(a.$=e.$,a.$$=a.$$||r.$):a.$$$=a.$$$||e.$,n=a),h(n,e),(e.soul||n.$$)&&f>=v(i.graph[s],u)&&((a=i.$.get(s)._).put=y(a.put,u,f,c,s)),!r.soul&&f>=v(i.graph[s],u)&&(t=(i.$.get(s)._.next||"")[u])&&(t.put=c,"string"==typeof(a=g(c))&&(t.put=i.$.get(a)._.put||c)),this.to&&this.to.next(n),e.any&&setTimeout.each(Object.keys(e.any),function(t){(t=e.any[t])&&t(n)},0,99),e.echo&&setTimeout.each(Object.keys(e.echo),function(t){(t=e.echo[t])&&t.on("in",n)},0,99),((n.$$||"")._||r).soul&&(t=e.next)&&(t=t[u])&&(a={},Object.keys(n).forEach(function(t){a[t]=n[t]}),a.$=(n.$$||n.$).get(a.get=u),delete a.$$,delete a.$$$,t.on("in",a)),l(n,e))},r.on.link=l,r.on.unlink=h;var p,d={},s=String.random,g=r.valid,u=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n=r.state,v=n.is,y=n.ify})(T,"./chain"),T(function(t){var g=T("./root");function r(t){var n=this.at||this.on;if(!t||n.soul||n.has)return this.off();if(t=(t=(t=t.$||t)._||t).id){n.map;if((n=this.seen||(this.seen={}))[t])return!0;n[t]=!0}}g.chain.get=function(t,n,e){var o;if("string"==typeof t){if(0==t.length)return(i=this.chain())._.err={err:g.log("0 length key!",t)},n&&n.call(i,i._.err),i;var i=(i=!(i=((f=this._).next||a)[t])?t&&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):i)&&i.$}else{if("function"==typeof t){if(!0===n)return function(t,n,e){var a,s=t._,u=0;if(a=s.soul||s.link)return n(a,e,s);if(s.jam)return s.jam.push([n,e]);s.jam=[[n,e]],t.get(function(t,n){if(!(v===t.put&&!s.root.opt.super&&(a=Object.keys(s.root.opt.peers).length)&&++u<=a)){n.rid(t);var e=(e=t.$)&&e._||{},o=0;for(a=s.jam,delete s.jam;r=a[o++];){var i=r[0],r=r[1];i&&i(e.link||e.soul||g.valid(t.put)||((t.put||{})._||{})["#"],r,t,n)}}},{out:{get:{".":!0}}})}(this,t,e),this;var c,f=(i=this)._,l=n||{},h=f.root;l.at=f,l.ok=t;var p={};function d(n,t,e){if(!d.stun&&(!(o=h.pass)||o[c])){var o,i=n.$._,r=(n.$$||"")._,a=(r||i).put,s=!i.has&&!i.soul,u={};if(!s&&v!==a||(a=v===((o=n.put)||"")["="]?v===(o||"")[":"]?o:o[":"]:o["="]),"string"==typeof(o=g.valid(a))&&(a=v===(o=h.$.get(o)._.put)?l.not?v:a:o),!l.not||v!==a){if(v===l.stun){if((o=h.stun)&&o.on&&(f.$.back(function(t){if(o.on(""+t.id,u={}),(u.run||0)<d.id)return u}),u.run||o.on(""+i.id,u={}),!u.run&&r&&o.on(""+r.id,u={}),d.id>u.run&&(u.stun&&!u.stun.end||(u.stun=o.on("stun"),u.stun=u.stun&&u.stun.last),u.stun&&!u.stun.end)))return void((u.stun.add||(u.stun.add={}))[c]=function(){d(n,t,1)});if(v===a&&(e=0),(o=h.hatch)&&!o.end&&v===l.hatch&&!e)return p[i.$._.id]?void 0:(p[i.$._.id]=1,void o.push(function(){d(n,t,1)}));p={}}if(h.pass){if(h.pass[c+i.id])return;h.pass[c+i.id]=1}l.on?l.ok.call(i.$,a,i.get,n,t||d):l.v2020?l.ok(n,t||d):(Object.keys(n).forEach(function(t){o[t]=n[t]},o={}),(n=o).put=a,l.ok.call(l.as,n,t||d))}}}return(((d.at=f).any||(f.any={}))[c=String.random(7)]=d).off=function(){d.stun=1,f.any&&delete f.any[c]},d.rid=r,d.id=l.run||++h.once,o=h.pass,(h.pass={})[c]=1,l.out=l.out||{get:{}},f.on("out",l.out),h.pass=o,i}if("number"==typeof t)return this.get(""+t,n,e);if("string"==typeof(o=s(t)))return this.get(o,n,e);(o=this.get.next)&&(i=o(this,t))}return i?n&&"function"==typeof n&&i.get(n,e):((i=this.chain())._.err={err:g.log("Invalid get request!",t)},n&&n.call(i,i._.err)),i};var v,a={},s=g.valid})(T,"./get"),T(function(t){var y=T("./root");function k(n,t){var e,o,i;t&&(t=(t._||"").id||t,e=n.root.stun||(n.root.stun={on:y.on}),o={},n.stun||(n.stun=e.on("stun",function(){})),(i=e.on(""+t))&&i.the.last.next(o),o.run>=n.run||e.on(""+t,function(t){return n.stun.end?(this.off(),void this.to.next(t)):(t.run=t.run||n.run,void(t.stun=t.stun||n.stun))}))}function m(n){var e,t,o,i,r;n.err?m.end(n.stun,n.root):n.todo.length||n.end||!Object.empty(n.wait)||(n.end=1,r=n.$.back(-1)._,e=r.root,t=r.ask(function(t){e.on("ack",t),t.err&&!t.lack&&y.log(t),++o>(n.acks||0)&&this.off(),n.ack&&n.ack(t,this)},n.opt),o=0,i=n.stun,(r=function(){i&&(m.end(i,e),setTimeout.each(Object.keys(i=i.add||""),function(t){(t=i[t])&&t()}))}).hatch=r,n.ack&&!n.ok&&(n.ok=n.acks||9),n.via._.on("out",{put:n.out=n.graph,ok:n.ok&&{"@":n.ok+1},opt:n.opt,"#":t,_:r}))}y.chain.put=function(t,n,g){var e=this,o=e._,i=o.root;(g=g||{}).root=o.root,g.run||(g.run=i.once),k(g,o.id),g.ack=g.ack||n,g.via=g.via||e,g.data=g.data||t,g.soul||(g.soul=o.soul||"string"==typeof n&&n);var v=g.state=g.state||y.state();return"function"==typeof t?t(function(t){g.data=t,e.put(void 0,void 0,g)}):g.soul?(g.$=i.$.get(g.soul),g.todo=[{it:g.data,ref:g.$}],g.turn=g.turn||r,g.ran=g.ran||m,function t(){var n,e,i,r,a,o,s,u=g.todo,c=u.pop(),f=c.it;c.ref&&c.ref._.id;if(k(g,c.ref),(r=c.todo)&&(f=f[e=r.pop()],r.length&&u.push(c)),e&&(u.path||(u.path=[])).push(e),!(n=b(f))&&!(a=y.is(f))){if(!Object.plain(f))return void m.err(g,"Invalid data: "+((o=f)&&(s=o.constructor)&&s.name||typeof o)+" at "+(g.via.back(function(t){t.get&&r.push(t.get)},r=[])||r.join("."))+"."+(u.path||[]).join("."));for(var l=g.seen||(g.seen=[]),h=l.length;h--;)if(f===(r=l[h]).it){n=f=r.link;break}}if(e&&n)c.node=_(c.node,e,v,f);else{if(!g.seen)return void m.err(g,"Data at root of graph must be a node (an object).");g.seen.push(i={it:f,link:{},todo:a?[]:Object.keys(f).sort().reverse(),path:(u.path||[]).slice(),up:c}),c.node=_(c.node,e,v,i.link),!a&&i.todo.length&&u.push(i);var p=g.seen.length;function d(t,n){var e=i.link["#"];n&&(n.off(),n.rid(t));var o=e||t.soul||(r=(t.$$||t.$)._||"").soul||r.link||((r=r.put||"")._||"")["#"]||r["#"]||((r=t.put||"")&&t.$$?r:r["="]||r[":"]||"")["#"];e||k(g,t.$),o||c.link["#"]?(o||(o=[],(t.$$||t.$).back(function(t){return(r=t.soul||t.link)?o.push(r):void o.push(t.get)}),o=o.reverse().join("/")),i.link["#"]=o,a||(((g.graph||(g.graph={}))[o]=i.node||(i.node={_:{}}))._["#"]=o),delete g.wait[p],i.wait&&setTimeout.each(i.wait,function(t){t&&t()}),g.ran(g)):(c.wait||(c.wait=[])).push(function(){d(t,n)})}(g.wait||(g.wait={}))[p]="",r=(i.ref=a?f:e?c.ref.get(e):c.ref)._,(r=f&&(f._||"")["#"]||r.soul||r.link)?d({soul:r}):i.ref.get(d,{run:g.run,v2020:1,out:{get:{".":" "}}})}if(!u.length)return g.ran(g);g.turn(t)}()):function(n){var e,t=n.via._;n.via=n.via.back(function(t){return t.soul||!t.get?t.$:(e=n.data,void((n.data={})[t.get]=e))}),n.via&&n.via._.soul||(n.via=t.root.$.get(((n.data||"")._||"")["#"]||t.$.back("opt.uuid")()));n.via.put(n.data,n.ack,n)}(g),e},m.end=function(t,n){t.end=e,t.the.to===t&&t===t.the.last&&delete n.stun,t.off()},m.err=function(t,n){(t.ack||e).call(t,t.out={err:t.err=y.log(n)}),t.ran(t)};var e=function(){},r=setTimeout.turn,b=y.valid,_=y.state.ify})(T,"./put"),T(function(t){var n=T("./root");T("./chain"),T("./back"),T("./put"),T("./get"),t.exports=n})(T,"./index"),T(function(t){var g=T("./index");g.chain.on=function(t,n,e,o){var i=this._;i.root;if("string"==typeof t)return n?(o=i.on(t,n,e||i,o),e&&e.$&&(e.subs||(e.subs=[])).push(o),this):i.on(t);(n=!0===n?{change:!0}:n||{}).not=1,n.on=1;return this.get(t,n),this},g.chain.once=function(c,f){if(f=f||{},!c)return t=this,g.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."),(e=t.chain())._.nix=t.once(function(t,n){e._.on("in",this._)}),e._.lex=t._.lex,e;var t,e,l,h=this._,p=h.root,d=(h.put,String.random(7));return this.get(function(n,e,o,i){var r=this,a=r._,s=a.one||(a.one={});function u(t){a.has||a.soul||(a={put:n,get:e}),void 0===(l=a.put)&&(l=((o.$$||"")._||"").put),"string"!=typeof g.valid(l)||void 0!==(l=p.$.get(l)._.put)||t?i.stun||""!==s[d]&&(s[d]="",(h.soul||h.has)&&i.off(),c.call(r,l,a.get),clearTimeout(s[d])):s[d]=setTimeout(function(){u(1)},f.wait||99)}i.stun||""!==s[d]&&(!0!==(l=g.valid(n))?"string"!=typeof l&&(clearTimeout((h.one||"")[d]),clearTimeout(s[d]),s[d]=setTimeout(u,f.wait||99)):u())},{on:1}),this},g.chain.off=function(){var e,t=this._,o=t.back;if(o)return t.ack=0,(e=o.next)&&e[t.get]&&delete e[t.get],(e=o.ask)&&delete e[t.get],(e=o.put)&&delete e[t.get],(e=t.soul)&&delete o.root.graph[e],(e=t.map)&&Object.keys(e).forEach(function(t,n){(n=e[t]).link&&o.root.$.get(n.link).off()}),(e=t.next)&&Object.keys(e).forEach(function(t,n){e[t].$.off()}),t.on("off",{}),this}})(T,"./on"),T(function(t){var s=T("./index"),o=s.chain.get.next;function u(t){this.to.next(t);var n=this.as,e=t.$._,o=t.put;(e.soul||t.$$)&&((e=n.lex)&&!String.match(t.get||(o||"")["."],e["."]||e["#"]||e)||s.on.link(t,n))}s.chain.get.next=function(t,n){var e;return Object.plain(n)?(e=((e=n["#"])||"")["="]||e)?t.get(e):((e=t.chain()._).lex=n,t.on("in",function(t){String.match(t.get||(t.put||"")["."],n["."]||n["#"]||n)&&e.on("in",t),this.to.next(t)}),e.$):(o||c)(t,n)},s.chain.map=function(r,t,n){var e,a,o=this,i=o._;return Object.plain(r)&&(e=r["."]?r:{".":r},r=void 0),r?(s.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,e,o){o=(r||c).call(this,t,n,e,o);if(void 0!==o){if(t===o)return a._.on("in",e);if(s.is(o))return a._.on("in",o._);var i={};Object.keys(e.put).forEach(function(t){i[t]=e.put[t]},i),i["="]=o,a._.on("in",{get:n,put:i})}})):(a=i.each)||((i.each=a=o.chain())._.lex=e||a._.lex||i.lex,a._.nix=o.back("nix"),o.on("in",u,a._)),a};var c=function(){}})(T,"./map"),T(function(t){var s=T("./index");s.chain.set=function(t,i,n){var e,r,a=this,o=a.back(-1);return i=i||function(){},(n=n||{}).item=n.item||t,(e=((t||"")._||"")["#"])&&((t={})["#"]=e),"string"==typeof(r=s.valid(t))?a.get(e=r).put(t,i,n):s.is(t)?(a.put(function(o){t.get(function(t,n,e){return t?((r={})[t]={"#":t},void o(r)):i.call(a,{err:s.log('Only a node can be linked! Not "'+e.put+'"!')})},!0)}),t):(Object.plain(t)&&(t=o.get(e=a.back("opt.uuid")()).put(t)),a.get(e||o.back("opt.uuid")(7)).put(t,i,n))}})(T,"./set"),T(function(t){T("./shim");function n(){}var r=JSON.parseAsync||function(t,n,e){var o=+new Date;try{n(void 0,JSON.parse(t,e),w.sucks(+new Date-o))}catch(t){n(t)}},w=JSON.stringifyAsync||function(t,n,e,o){var i=+new Date;try{n(void 0,JSON.stringify(t,e,o),w.sucks(+new Date-i))}catch(t){n(t)}};function e(u){var d=function(){},g=u.opt||{};g.log=g.log||console.log,g.gap=g.gap||g.wait||0,g.max=g.max||.3*(g.memory?999*g.memory*999:3e8),g.pack=g.pack||.01*g.max*.01,g.puff=g.puff||9;var v=setTimeout.turn||setTimeout,y=u.dup,k=y.check,m=y.track,i=(new Date,d.hear=function(t,a){if(t){if(g.max<=t.length)return d.say({dam:"!",err:"Message too big!"},a);d===this&&(i.d+=t.length||0,++i.c);var n,e=a.SH=+new Date,o=t[0];if("["===o)return r(t,function(t,i){if(t||!i)return d.say({dam:"!",err:"DAM JSON parse error."},a);console.STAT&&console.STAT(+new Date,i.length,"# on hear batch");var r=g.puff;!function t(){for(var n,e=+new Date,o=0;o<r&&(n=i[o++]);)d.hear(n,a);i=i.slice(o),console.STAT&&console.STAT(e,+new Date-e,"hear loop"),b(a),i.length&&v(t,0)}()}),void(t="");if("{"===o||(t["#"]||Object.plain(t))&&(n=t)){if(n)return i.one(n,a,e);r(t,function(t,n){return t||!n?d.say({dam:"!",err:"DAM JSON parse error."},a):void i.one(n,a,e)})}}});i.one=function(t,n,e){var o,i,r,a,s;if(t.DBG&&(t.DBG=s={DBG:t.DBG}),s&&(s.h=e),s&&(s.hp=+new Date),(o=t["#"])||(o=t["#"]=String.random(9)),!((r=k(o))||(i=t["##"])&&(r=t["@"]||t.get&&o)&&y.check(a=r+i))){if((t._=function(){}).via=d.leap=n,(r=t["><"])&&"string"==typeof r&&r.slice(0,99).split(",").forEach(function(t){this[t]=1},t._.yo={}),r=t.dam)return(r=d.hear[r])&&r(t,n,u),void m(o);(r=t.ok)&&(t._.near=r["/"]);e=+new Date;s&&(s.is=e),n.SI=o,u.on("in",d.last=t),s&&(s.hd=+new Date),console.STAT&&console.STAT(e,+new Date-e,t.get?"msg get":t.put?"msg put":"msg"),(r=m(o)).via=n,t.get&&(r.it=t),a&&m(a),d.leap=d.last=null}};function b(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 g.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),d.say.d+=n.length||0,++d.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}i.c=i.d=0,function(){var h,p=0;function t(t,n){var e;return n instanceof Object?(Object.keys(n).sort().forEach(o,{to:e={},on:n}),e):n}function o(t){this.to[t]=this.on[t]}d.hash=function(o,i){var r,a,s,u=+new Date;w(o.put,function t(n,e){e=(a=a||(s=e||"")).slice(0,32768);r=String.hash(e,r),(a=a.slice(32768))?v(t,0):(console.STAT&&console.STAT(u,+new Date-u,"say json+hash"),o._.$put=s,o["##"]=r,d.say(o,i),delete o._.$put)},t)};d.say=function(r,a){var t;if((t=this)&&(t=t.to)&&t.next&&t.next(r),!r)return!1;var n,s,u=r["@"],c=r._||(r._=function(){}),e=r.DBG,o=+new Date;if(c.y=c.y||o,a||e&&(e.y=o),(n=r["#"])||(n=r["#"]=String.random(9)),h||m(n),r["##"]||$===r.put||c.via||!u){if(!(a=!a&&u?(t=y.s[u])&&(t.via||(t=t.it)&&(t=t._)&&t.via)||(t=d.last)&&u===t["#"]&&d.leap:a)&&u)return y.s[u]?void 0:(console.STAT&&console.STAT(+new Date,++p,"total no peer to ack to"),!1);if(!a&&d.way)return d.way(r);if(e&&(e.yh=+new Date),s=c.raw){if(e&&(e.yr=+new Date),!a||!a.id){if(!Object.plain(a||g.peers))return!1;var o=+new Date,f=(g.puff,g.peers),l=Object.keys(a||g.peers||{});return console.STAT&&console.STAT(o,+new Date-o,"peer keys"),void function t(){var n=+new Date;h=1;var e=c.raw;c.raw=s;for(var o,i=0;i<9&&(o=(l||"")[i++]);)(o=f[o]||(a||"")[o])&&d.say(r,o);c.raw=e,h=0,l=l.slice(i),console.STAT&&console.STAT(n,+new Date-n,"say loop"),l.length&&(v(t,0),u&&m(u))}()}if(!a.wire&&d.wire&&d.wire(a),n!==a.last){if(a.last=n,a===c.via)return!1;if((t=c.yo)&&(t[a.url]||t[a.pid]||t[a.id]))return!1;if(console.STAT&&console.STAT(o,((e||c).yp=+new Date)-(c.y||o),"say prep"),!h&&u&&m(u),a.batch){if(a.tail=(t=a.tail||0)+s.length,a.tail<=g.pack)return void(a.batch+=(t?",":"")+s);b(a)}a.batch="[";var i=+new Date;setTimeout(function(){console.STAT&&console.STAT(i,+new Date-i,"0ms TO"),b(a)},g.gap),_(s,a),console.STAT&&u===a.SI&&console.STAT(o,+new Date-a.SH,"say ack")}}else d.raw(r,a)}else d.hash(r,a)};d.say.c=d.say.d=0,d.raw=function(e,o){if(!e)return"";var i,r=e._||{};if(s=r.raw)return s;if("string"==typeof e)return e;var t=e["##"],n=e["@"];if(t&&n){if(!r.via&&k(n+t))return!1;if((s=(y.s[n]||"").it)||(s=d.last)&&n===s["#"]){if(t===s["##"])return!1;s["##"]||(s["##"]=t)}}if(!e.dam&&!e["@"]){var a,s,u=0,c=[];for(a in s=g.peers){var f=s[a];if(c.push(f.url||f.pid||f.id),6<++u)break}1<u&&(e["><"]=c.join())}if(e.put&&(s=e.ok)&&(e.ok={"@":(s["@"]||1)-1,"/":s["/"]==e._.near?d.near:s["/"]}),i=r.$put)return s={},Object.keys(e).forEach(function(t){s[t]=e[t]}),s.put=":])([:",void w(s,function(t,n){t||(t=+new Date,s=n.indexOf('"put":":])([:"'),l($,n=n.slice(0,s+6)+i+n.slice(s+14)),console.STAT&&console.STAT(t,+new Date-t,"say slice"))});function l(t,n){t||(r.raw=n,d.say(e,o))}w(e,l)}}(),d.near=0,d.hi=function(n){var t;n.wire?(n.id?g.peers[n.url||n.id]=n:(t=n.id=n.id||n.url||String.random(9),d.say({dam:"?",pid:u.opt.pid},g.peers[t]=n),delete y.s[n.last]),n.met||(d.near++,n.met=+new Date,u.on("hi",n)),t=n.queue,n.queue=[],setTimeout.each(t||[],function(t){_(t,n)},0,9)):d.wire(n.length?{url:n,id:n}:n)},d.bye=function(t){t.met&&--d.near,delete t.met,u.on("bye",t);var n=+new Date;n-=t.met||n,d.bye.time=((d.bye.time||n)+n)/2},d.hear["!"]=function(t,n){g.log("Error:",t.err)},d.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(d.say({dam:"?",pid:g.pid,"@":t["#"]},n),delete y.s[n.last])},d.hear.mob=function(t,n){!t.peers||(t=(t=Object.keys(t.peers))[Math.random()*t.length>>0])&&(d.bye(n),d.hi(t))},u.on("create",function(t){t.opt.pid=t.opt.pid||String.random(9),this.to.next(t),t.on("out",d.say)}),u.on("bye",function(t,n){t=g.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),delete g.peers[t.id],t.wire=null});var e={};return u.on("bye",function(t,n){this.to.next(t),(n=console.STAT)&&(n.peers=d.near),(n=t.url)&&(e[n]=!0,setTimeout(function(){delete e[n]},g.lack||9e3))}),u.on("hi",function(e,t){this.to.next(e),(t=console.STAT)&&(t.peers=d.near),g.super||(9999<(t=Object.keys(u.next||"")).length&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(t,function(n){var t=u.next[n];g.super||(t.ask||"")[""]?d.say({get:{"#":n}},e):setTimeout.each(Object.keys(t.ask||""),function(t){t&&d.say({"##":String.hash((u.graph[n]||"")[t]),get:{"#":n,".":t}},e)})}))}),d}w.sucks=function(t){99<t&&(console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."),w.sucks=n)};var $;try{t.exports=e}catch(t){}})(T,"./mesh"),T(function(t){var s=T("./index");s.Mesh=T("./mesh"),s.on("opt",function(t){var o,n,e,i;function r(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(){a(n),o.mesh.bye(n)},e.onerror=function(t){a(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){o.mesh.bye(n)}}function a(n){clearTimeout(n.defer),o.peers[n.url]&&(i&&n.retry<=0||(n.retry=(n.retry||o.retry+1||60)-(-n.tried+(n.tried=+new Date)<4*e?1:0),n.defer=setTimeout(function t(){return i&&i.hidden?setTimeout(t,e):void r(n)},e)))}this.to.next(t),t.once||!1!==(o=t.opt).WebSocket&&(n=s.window||{},(n=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket)&&(o.WebSocket=n,(n=o.mesh=o.mesh||s.Mesh(t)).wire||o.wire,n.wire=o.wire=r,setTimeout(function(){o.super||t.on("out",{dam:"hi"})},1),e=1998,i=""+void 0!=typeof document&&document))})})(T,"./websocket"),T(function(t){if("undefined"!=typeof Gun){var i;try{i=(Gun.window||function(){}).localStorage}catch(t){}i||(Gun.log("Warning: No localStorage exists to persist data to!"),i={setItem:function(t,n){this[t]=n},removeItem:function(t){delete this[t]},getItem:function(t){return this[t]}});JSON.parseAsync;var r=JSON.stringifyAsync||function(t,n,e,o){try{n(void 0,JSON.stringify(t,e,o))}catch(t){n(t)}};Gun.on("create",function n(a){this.to.next(a);var s,u,c,f,o=a.opt,l=(a.graph,[]);if(!1!==o.localStorage){o.prefix=o.file||"gun/";try{s=n[o.prefix]=n[o.prefix]||JSON.parse(c=i.getItem(o.prefix))||{}}catch(t){s=n[o.prefix]={}}c=(c||"").length,a.on("get",function(t){this.to.next(t);var n,e,o,i=t.get;i&&(n=i["#"])&&((e=s[n]||void 0)&&(o=i["."])&&!Object.plain(o)&&(e=Gun.state.ify({},o,Gun.state.is(e,o),e[o],n)),Gun.on.get.ack(t,e))}),a.on("put",function(t){this.to.next(t);var n=t.put,e=n["#"],o=n["."],i=t["#"],r=t.ok||"";s[e]=Gun.state.ify(s[e],o,n[">"],n[":"],e),f&&4999880<c?a.on("in",{"@":i,err:"localStorage max!"}):(t["@"]||t._.via&&!(Math.random()<r["@"]/r["/"])||l.push(i),u=u||setTimeout(h,9+c/333))})}function h(){var e;l.length||!((setTimeout.turn||"").s||"").length?(e=l,clearTimeout(u),u=!1,l=[],r(s,function(n,t){try{n||i.setItem(o.prefix,t)}catch(t){n=f=t||"localStorage failure"}n&&(Gun.log(n+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),a.on("localStorage:error",{err:n,get:o.prefix,put:s})),c=t.length,setTimeout.each(e,function(t){a.on("in",{"@":t,err:n,ok:0})},0,99)})):setTimeout(h,99)}})}})(T,"./localStorage")}(),function(){var l,h,n,p,d,s,e,o,i,u,r,a,c,f,g,v,y,t,k,m,b,_,w,$,T,j;function x(t,n){b(this,n)&&void 0!==this[n]||(this[n]=t)}function S(t,n){var e=this.n;if(!e||!(n===e||k(e)&&b(e,n)))return void 0!==n||void 0}function O(t,n){if(2===arguments.length)return O.r=O.r||{},void(O.r[t]=n);O.r=O.r||[],O.r.push(t)}function D(t,n){return!this.id&&n==e&&i(t)?void(this.id=t):this.id=!1}function A(t,n){if(n!==u._)return!s.is(t)||void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s))}function G(t,n){var e,o=this.o;o.map?void 0===(e=o.map.call(this.as,t,""+n,o.node))?m(o.node,n):o.node&&(o.node[n]=e):s.is(t)&&(o.node[n]=t)}function N(t,n){g!==n&&c.ify(this.o,n,this.s)}function J(t,n){if(!t||n!==u.soul(t)||!u.is(t,this.fn,this.as))return!0;this.cb&&(B.n=t,B.as=this.as,this.cb.call(B.as,t,n,B))}function B(t){t&&u.is(B.n,t,B.as)}function M(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=E,u.ify(n.obj,I,n)&&(n.link=n.link||s.link.ify(u.soul(n.node)),n.obj!==t.shell&&(t.graph[s.link.is(n.link)]=n.node)),n)}function I(t,n,e){var o,i,r=this,a=r.env;if(u._===n&&b(t,s.link._))return e._;if(o=W(t,n,e,r,a)){if(n||(r.node=r.node||e||{},b(t,u._)&&u.soul(t)&&(r.node._=T(t._)),r.node=u.soul.ify(r.node,s.link.is(r.link)),r.link=r.link||s.link.ify(u.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),b(e,n))){if(t=e[n],j===t)return void m(e,n);if(!(o=W(t,n,e,r,a)))return}return n?!0===o?t:(i=M(a,{obj:t,path:r.path.concat(n)})).node?i.link:void 0:r.node}}function E(t){var n=this,e=s.link.is(n.link),o=n.env.graph;n.link=n.link||s.link.ify(t),n.link[s.link._]=t,n.node&&n.node[u._]&&(n.node[u._][s.link._]=t),b(o,e)&&(o[t]=o[e],m(o,e))}function W(t,n,e,o,i){var r;return!!s.is(t)||(k(t)?1:(r=i.invalid)?W(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(h.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}function P(t,n){var e,o;if(u._===n)return _(t,s.link._)?void 0:void(this.obj[n]=T(t));(e=s.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=v.to(this.graph,e,this.opt):this.obj[n]=t}""+j!=typeof Gun&&(l=function(t){console.warn("Warning! Deprecated internal utility will break in next version:",t)},(h=Gun).fn=h.fn||{is:function(t){return l("fn"),!!t&&"function"==typeof t}},h.bi=h.bi||{is:function(t){return l("bi"),t instanceof Boolean||"boolean"==typeof t}},h.num=h.num||{is:function(t){return l("num"),!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},h.text=h.text||{is:function(t){return l("text"),"string"==typeof t}},h.text.ify=h.text.ify||function(t){return l("text.ify"),h.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},h.text.random=h.text.random||function(t,n){l("text.random");var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0<t;)e+=n.charAt(Math.floor(Math.random()*n.length)),t--;return e},h.text.match=h.text.match||function(t,n){var e,o;return l("text.match"),"string"==typeof t&&(t===((n=(n="string"==typeof n?{"=":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["<"])))},h.text.hash=h.text.hash||function(t,n){if(l("text.hash"),"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}},h.list=h.list||{is:function(t){return l("list"),t instanceof Array}},h.list.slit=h.list.slit||Array.prototype.slice,h.list.sort=h.list.sort||function(e){return l("list.sort"),function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n<t?1:0:0}},h.list.map=h.list.map||function(t,n,e){return l("list.map"),$(t,n,e)},h.list.index=1,h.obj=h.boj||{is:function(t){return l("obj"),!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},h.obj.put=h.obj.put||function(t,n,e){return l("obj.put"),(t||{})[n]=e,t},h.obj.has=h.obj.has||function(t,n){return l("obj.has"),t&&Object.prototype.hasOwnProperty.call(t,n)},h.obj.del=h.obj.del||function(t,n){if(l("obj.del"),t)return t[n]=null,delete t[n],t},h.obj.as=h.obj.as||function(t,n,e,o){return l("obj.as"),t[n]=t[n]||(o===e?{}:e)},h.obj.ify=h.obj.ify||function(n){if(l("obj.ify"),k(n))return n;try{n=JSON.parse(n)}catch(t){n={}}return n},h.obj.to=h.obj.to||function(t,n){return l("obj.to"),$(t,x,n=n||{}),n},h.obj.copy=h.obj.copy||function(t){return l("obj.copy"),t&&JSON.parse(JSON.stringify(t))},h.obj.empty=h.obj.empty||function(t,n){return l("obj.empty"),!t||!$(t,S,{n:n})},p=Object.keys,Object.keys=Object.keys||function(t){return n(t,function(t,n,e){e(n)})},h.obj.map=n=h.obj.map||function(t,n,e){l("obj.map");var o,i,r,a,s,u=0,c="function"==typeof n;if(O.r=o,p&&k(t)&&(a=p(t),s=!0),e=e||{},d(t)||a)for(i=(a||t).length;u<i;u++){var f=u+h.list.index;if(c){if((r=s?n.call(e,t[a[u]],a[u],O):n.call(e,t[u],f,O))!==o)return r}else if(n===t[s?a[u]:u])return a?a[u]:f}else for(u in t)if(c){if(b(t,u)&&(r=e?n.call(e,t[u],u,O):n(t[u],u,O))!==o)return r}else if(n===t[u])return u;return c?O.r:h.list.index?0:-1},h.time=h.time||{},h.time.is=h.time.is||function(t){return l("time"),t?t instanceof Date:+(new Date).getTime()},y=h.fn.is,d=h.list.is,t=h.obj,k=t.is,b=t.has,$=t.map,(s={is:function(t){return l("val.is"),t!==j&&(null===t||t!==1/0&&(!!(i(t)||o(t)||f(t))||(s.link.is(t)||!1)))}}).link=s.rel={_:"#"},s.link.is=function(t){if(l("val.link.is"),t&&t[e]&&!t._&&k(t)){var n={};if($(t,D,n),n.id)return n.id}return!1},s.link.ify=function(t){return l("val.link.ify"),w({},e,t)},h.obj.has._=".",e=s.link._,o=h.bi.is,f=h.num.is,i=h.text.is,k=(t=h.obj).is,w=t.put,$=t.map,h.val=h.val||s,(u={_:"_",soul:function(t,n){return l("node.soul"),t&&t._&&t._[n||a]}}).soul.ify=function(t,n){return l("node.soul.ify"),n="string"==typeof n?{soul:n}:n||{},(t=t||{})._=t._||{},t._[a]=n.soul||t._[a]||r(),t},u.soul._=s.link._,u.is=function(t,n,e){var o;return l("node.is"),!!k(t)&&(!!(o=u.soul(t))&&!$(t,A,{as:e,cb:n,s:o,n:t}))},u.ify=function(t,n,e){return l("node.ify"),n?"string"==typeof n?n={soul:n}:"function"==typeof n&&(n={map:n}):n={},n.map&&(n.node=n.map.call(e,t,j,n.node||{})),(n.node=u.soul.ify(n.node||{},n))&&$(t,G,{o:n,as:e}),n.node},k=(t=h.obj).is,m=t.del,$=t.map,r=h.text.random,a=u.soul._,h.node=h.node||u,(c=h.state).lex=function(){return l("state.lex"),c().toString(36).replace(".","")},c.to=function(t,n,e){l("state.to");var o=(t||{})[n];return k(o)&&(o=T(o)),c.ify(e,n,c.is(t,n),o,u.soul(t))},c.map=function(i,r,a){l("state.map");var t=k(t=i||r)?t:null;return i=y(i=i||r)?i:null,t&&!i?(r=f(r)?r:c(),t[g]=t[g]||{},$(t,N,{o:t,s:r}),t):(a=a||k(r)?r:void 0,r=f(r)?r:c(),function(t,n,e,o){if(!i)return N.call({o:e,s:r},t,n),t;i.call(a||this||{},t,n,e,o),b(e,n)&&void 0===e[n]||N.call({o:e,s:r},t,n)})},(t=h.obj).as,b=t.has,k=t.is,$=t.map,T=t.copy,f=h.num.is,y=h.fn.is,g=u._,v={is:function(t,n,e,o){return l("graph.is"),!(!t||!k(t)||_(t))&&!$(t,J,{cb:n,fn:e,as:o})},ify:function(t,n,e){l("graph.ify");t={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=j),n.soul&&(t.link=s.link.ify(n.soul)),n.shell=(e||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||e,M(n,t),n.root=t.node,n.graph},node:function(t){l("graph.node");var n=u.soul(t);if(n)return w({},n,t)},to:function(t,n,e){if(l("graph.to"),t){var o={};return $(t[n],P,{obj:o,graph:t,opt:e=e||{seen:{}}}),o}}},y=h.fn.is,k=(t=h.obj).is,m=t.del,b=t.has,_=t.empty,w=t.put,$=t.map,T=t.copy,h.graph=h.graph||v)}();