UNPKG

@liascript/exporter

Version:
2 lines (1 loc) 5.67 kB
!function(){function t(t,e,n,r){Object.defineProperty(t,e,{get:n,set:r,enumerable:!0,configurable:!0})}var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("izF7z",(function(n,r){t(n.exports,"Sync",(function(){return v}));var i=e("f1evb"),o=e("hnmIs"),u=e("9Klpk"),s=e("3bWnf"),c=e("eT7f3"),a=e("9WzNc"),l=e("div3d"),f=e("kb0qF"),d=e("5ENmm"),p=e("bWNdT"),h=e("32Euv"),y=e("auvHb"),g=e("i4ll7");Object.defineProperty(Array.prototype,"flat",{value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.reduce((function(e,n){return e.concat(Array.isArray(n)&&t>1?n.flat(t-1):n)}),[])}});var v=function(t){"use strict";(0,f.default)(n,t);var e=(0,p.default)(n);function n(){var t;return(0,u.default)(this,n),t=e.apply(this,arguments),(0,c.default)((0,i.default)(t),"store",""),(0,c.default)((0,i.default)(t),"gunServer",[]),(0,c.default)((0,i.default)(t),"persistent",!1),t}return(0,s.default)(n,[{key:"destroy",value:function(){this.gunServer=[],delete this.gun,(0,a.default)((0,l.default)(n.prototype),"destroy",this).call(this)}},{key:"uniqueID",value:function(){var t=(0,a.default)((0,l.default)(n.prototype),"uniqueID",this).call(this);return t?btoa(t+(this.persistent?"p":"")):null}},{key:"connect",value:function(t){var e=this,r=this;return(0,o.default)((function(){var i,o;return(0,h.__generator)(this,(function(u){return(0,a.default)((0,l.default)(n.prototype),"connect",e).call(r,t),r.gunServer=(null===(i=t.config)||void 0===i?void 0:i.urls)||[],r.persistent=(null===(o=t.config)||void 0===o?void 0:o.persistent)||!1,window.Gun?r.init(!0):r.load(["https://cdn.jsdelivr.net/npm/gun/gun.js",g.Crypto.url],r),[2]}))}))()}},{key:"init",value:function(t,e){if(0==this.gunServer.length)return this.sendDisconnectError("You have to provide at least one relay server.");var n=this.uniqueID();if(t&&window.Gun&&n){this.gun=window.Gun({peers:this.gunServer}),this.store=n,g.Crypto.init(this.password);var r=this;this.persistent&&this.gun.get(this.store).once((function(t){if(t&&t.msg)try{var e=(0,d.default)(g.Crypto.decode(t.msg),2),n=(e[0],e[1]);setTimeout((function(){var t;null===(t=r.gun)||void 0===t||t.get(r.store).put({msg:g.Crypto.encode(["",n])})}),1e3)}catch(t){console.warn("GunDB:",t.message)}})),this.gun.get(this.store).on((function(t,e){try{var n=(0,d.default)(g.Crypto.decode(t.msg),3),i=n[0],o=n[1],u=n[2];i!=r.token&&null!=o&&(u==r.db.timestamp?r.applyUpdate(y.base64_to_unit8(o)):u>r.db.timestamp?r.broadcast(!0,r.db.encode()):(r.applyUpdate(y.base64_to_unit8(o),!0),r.db.timestamp=u))}catch(t){console.warn("GunDB",t.message)}})),this.gun.get(this.store+"pubsub").on((function(t,e){try{var n=(0,d.default)(g.Crypto.decode(t.msg),3),i=n[0],o=n[1];n[2],i!=r.token&&null!=o&&r.pubsubReceive(y.base64_to_unit8(o))}catch(t){console.warn("GunDB",t.message)}})),this.persistent||(this.broadcast(!0,null),this.broadcast(!1,null)),this.sendConnect()}else{var i="GunDB unknown error";e?i="Could not load resource: "+e:window.Gun||(i="Could not load GunDB interface"),this.sendDisconnectError(i)}}},{key:"broadcast",value:function(t,e){if(this.gun){var n=null==e?null:y.uint8_to_base64(e);this.gun.get(this.store+(t?"":"pubsub")).put({msg:g.Crypto.encode(["",n])})}}}]),n}(y.Sync)})),e.register("i4ll7",(function(e,n){t(e.exports,"Crypto",(function(){return r}));var r={url:"https://cdn.jsdelivr.net/npm/simple-crypto-js@2.5.0/dist/SimpleCrypto.min.js",crypt:null,check:function(){return!!window.SimpleCrypto},init:function(t){try{"string"==typeof t&&t.length>0?this.crypt=new SimpleCrypto(t):this.crypt=null}catch(t){console.warn("Crypto: ",t),this.crypt=null}},encode:function(t){return this.crypt?this.crypt.encrypt(btoa(encodeURIComponent(JSON.stringify(t)))):JSON.stringify(t)},decode:function(t){return this.crypt?JSON.parse(decodeURIComponent(atob(this.crypt.decrypt(t)))):JSON.parse(t)}}})),e.register("84cK9",(function(t,e){var n,r,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function s(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{r="function"==typeof clearTimeout?clearTimeout:u}catch(t){r=u}}();var c,a=[],l=!1,f=-1;function d(){l&&c&&(l=!1,c.length?a=c.concat(a):f=-1,a.length&&p())}function p(){if(!l){var t=s(d);l=!0;for(var e=a.length;e;){for(c=a,a=[];++f<e;)c&&c[f].run();f=-1,e=a.length}c=null,l=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===u||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function h(t,e){this.fun=t,this.array=e}function y(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];a.push(new h(t,e)),1!==a.length||l||s(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}))}();