@liascript/exporter
Version:
A generic exporter for LiaScript
2 lines (1 loc) • 4.85 kB
JavaScript
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("1dThA",(function(n,r){t(n.exports,"Sync",(function(){return u}));var o=e("2Xs1f"),i=e("5Owdb"),s=e("2O3kG");Object.defineProperty(Array.prototype,"flat",{value:function(t=1){return this.reduce((function(e,n){return e.concat(Array.isArray(n)&&t>1?n.flat(t-1):n)}),[])}});class u extends i.Sync{destroy(){this.gunServer=[],delete this.gun,super.destroy()}uniqueID(){const t=super.uniqueID();return t?btoa(t+(this.persistent?"p":"")):null}async connect(t){var e,n;super.connect(t),this.gunServer=(null===(e=t.config)||void 0===e?void 0:e.urls)||[],this.persistent=(null===(n=t.config)||void 0===n?void 0:n.persistent)||!1,window.Gun?this.init(!0):this.load(["https://cdn.jsdelivr.net/npm/gun/gun.js",s.Crypto.url],this)}init(t,e){if(0==this.gunServer.length)return this.sendDisconnectError("You have to provide at least one relay server.");const n=this.uniqueID();if(t&&window.Gun&&n){this.gun=window.Gun({peers:this.gunServer}),this.store=n,s.Crypto.init(this.password);let t=this;this.persistent&&this.gun.get(this.store).once((e=>{if(e&&e.msg)try{const[n,r]=s.Crypto.decode(e.msg);setTimeout((function(){var e;null===(e=t.gun)||void 0===e||e.get(t.store).put({msg:s.Crypto.encode(["",r])})}),1e3)}catch(t){console.warn("GunDB:",t.message)}})),this.gun.get(this.store).on((function(e,n){try{const[n,r,o]=s.Crypto.decode(e.msg);n!=t.token&&null!=r&&(o==t.db.timestamp?t.applyUpdate(i.base64_to_unit8(r)):o>t.db.timestamp?t.broadcast(!0,t.db.encode()):(t.applyUpdate(i.base64_to_unit8(r),!0),t.db.timestamp=o))}catch(t){console.warn("GunDB",t.message)}})),this.gun.get(this.store+"pubsub").on((function(e,n){try{const[n,r,o]=s.Crypto.decode(e.msg);n!=t.token&&null!=r&&t.pubsubReceive(i.base64_to_unit8(r))}catch(t){console.warn("GunDB",t.message)}})),this.persistent||(this.broadcast(!0,null),this.broadcast(!1,null)),this.sendConnect()}else{let t="GunDB unknown error";e?t="Could not load resource: "+e:window.Gun||(t="Could not load GunDB interface"),this.sendDisconnectError(t)}}broadcast(t,e){if(this.gun){const n=null==e?null:i.uint8_to_base64(e);this.gun.get(this.store+(t?"":"pubsub")).put({msg:s.Crypto.encode(["",n])})}}constructor(...t){super(...t),(0,o.default)(this,"store",""),(0,o.default)(this,"gunServer",[]),(0,o.default)(this,"persistent",!1)}}})),e.register("2O3kG",(function(e,n){t(e.exports,"Crypto",(function(){return r}));const 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("jhEmn",(function(t,e){var n,r,o=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function u(t){if(n===setTimeout)return setTimeout(t,0);if((n===i||!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:i}catch(t){n=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(t){r=s}}();var c,l=[],a=!1,p=-1;function d(){a&&c&&(a=!1,c.length?l=c.concat(l):p=-1,l.length&&h())}function h(){if(!a){var t=u(d);a=!0;for(var e=l.length;e;){for(c=l,l=[];++p<e;)c&&c[p].run();p=-1,e=l.length}c=null,a=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===s||!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 f(t,e){this.fun=t,this.array=e}function y(){}o.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];l.push(new f(t,e)),1!==l.length||a||u(h)},f.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(t){return[]},o.binding=function(t){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(t){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}}));