@aegis-framework/artemis
Version:
Aegis Framework Javascript Library
3 lines (2 loc) • 27.6 kB
JavaScript
function e(e,t){return Object.keys(t).forEach((function(s){"default"===s||"__esModule"===s||e.hasOwnProperty(s)||Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[s]}})})),e}function t(e,t,s,r){Object.defineProperty(e,t,{get:s,set:r,enumerable:!0,configurable:!0})}var s={};t(s,"DebugLevel",(()=>r)),t(s,"Debug",(()=>n));const r={NONE:0,ERROR:1,WARNING:2,INFO:3,DEBUG:4,ALL:5};class n{static level(e){return"number"==typeof e&&(this._level=e),this._level}static log(...e){this.level()>=r.DEBUG&&console.log(...e)}static debug(...e){this.level()>=r.DEBUG&&console.debug(...e)}static info(...e){this.level()>=r.INFO&&console.info(...e)}static error(...e){this.level()>=r.ERROR&&console.error(...e)}static warning(...e){this.level()>=r.WARNING&&console.warn(...e)}static table(...e){this.level()>=r.DEBUG&&console.table(...e)}static group(...e){this.level()>=r.DEBUG&&console.group(...e)}static groupCollapsed(...e){this.level()>=r.DEBUG&&console.groupCollapsed(...e)}static groupEnd(...e){this.level()>=r.DEBUG&&console.groupEnd(...e)}static time(...e){this.level()>=r.DEBUG&&console.time(...e)}static timeLog(...e){this.level()>=r.DEBUG&&console.timeLog(...e)}static timeEnd(...e){this.level()>=r.DEBUG&&console.timeEnd(...e)}static trace(...e){this.level()>=r.DEBUG&&console.trace(...e)}}n._level=r.NONE;var i={};t(i,"DOM",(()=>o)),t(i,"$_",(()=>a)),t(i,"$_ready",(()=>l));class o{constructor(e){if(null===e)return this.collection=[],void(this.length=0);if("string"==typeof e)this.collection=document.querySelectorAll(e),this.length=this.collection.length,this._selector=e;else if(e instanceof NodeList)this.collection=e,this.length=e.length,this._selector=e;else if(e instanceof o)this.collection=e.collection,this.length=this.collection.length,this._selector=e._selector;else if(e instanceof HTMLElement)this.collection=[e],this.length=this.collection.length,this._selector=e;else{if("object"!=typeof e)return;e.length>=1?this.collection=e:this.collection=[e],this.length=this.collection.length,this._selector=e}}hide(){for(const e of this.collection)e.style.display="none";return this}show(e="block"){for(const t of this.collection)t.style.display=e;return this}addClass(e){for(const t of this.collection)t.classList.add(e);return this}removeClass(e=null){if(null!==e)for(const t of this.collection)t.classList.remove(e);else for(const e of this.collection)for(;e.classList.length>0;)e.classList.remove(e.classList.item(0));return this}toggleClass(e){e=e.split(" ");for(const t of this.collection)for(let s=0;s<e.length;s++)t.classList.toggle(e[s]);return this}hasClass(e){for(const t of this.collection)if(!t.classList.contains(e))return!1;return!0}value(e){if(void 0!==e){for(const t of this.collection)t.value=e;return this}if(this.length>0)return this.collection[0].value}focus(){return this.length>0&&this.collection[0].focus(),this}click(e){for(const t of this.collection)t.addEventListener("click",e,!1);return this}keyup(e){for(const t of this.collection)t.addEventListener("keyup",e,!1);return this}keydown(e){for(const t of this.collection)t.addEventListener("keydown",e,!1);return this}submit(e){for(const t of this.collection)t.addEventListener("submit",e,!1);return this}change(e){for(const t of this.collection)t.addEventListener("change",e,!1);return this}scroll(e){for(const t of this.collection)t.addEventListener("scroll",e,!1);return this}on(e,t,s){e=e.split(" ");for(const r of this.collection)for(let n=0;n<e.length;n++)"function"==typeof t?r.addEventListener(e[n],t,!1):"string"==typeof t&&"function"==typeof s&&r.addEventListener(e[n],(e=>{if(!e.target)return;const r=a(e.target).closestParent(t,this._selector);r.exists()&&s.call(r.get(0),e)}),!1);return this}filter(e){return this.length>0?new o(this.collection[0].querySelector(e)):new o(null)}exists(){return this.length>0}data(e,t){if(void 0!==t){for(const s of this.collection)s.dataset[e]=t;return this}if(this.length>0)return this.collection[0].dataset[e]}removeData(e){for(const t of this.collection)delete t.dataset[e];return this}text(e){if(void 0!==e){for(const t of this.collection)t.textContent=e;return this}if(this.length>0)return this.collection[0].textContent}html(e){if(void 0!==e){for(const t of this.collection)t.innerHTML=e;return this}if(this.length>0)return this.collection[0].innerHTML}append(e){if(this.length>0)if("string"==typeof e){const t=document.createElement("div");t.innerHTML="string"==typeof e?e.trim():e,this.collection[0].appendChild(t.firstChild)}else this.collection[0].appendChild(e);return this}prepend(e){if(this.length>0)if("string"==typeof e){const t=document.createElement("div");t.innerHTML="string"==typeof e?e.trim():e,this.collection[0].childNodes.length>0?this.collection[0].insertBefore(t.firstChild,this.collection[0].childNodes[0]):this.collection[0].appendChild(t.firstChild)}else this.collection[0].childNodes.length>0?this.collection[0].insertBefore(e,this.collection[0].childNodes[0]):this.collection[0].appendChild(e);return this}each(e){for(const t of this.collection)e(t);return this}get(e){return this.collection[e]}first(){return this.length>0?new o(this.collection[0]):new o(null)}last(){return this.length>0?new o(this.collection[this.collection.length-1]):new o(null)}isVisible(){for(const e of this.collection)if("none"!=e.display&&e.offsetWidth>0&&e.offsetHeight>0)return!0;return!1}parent(){return this.length>0?new o(this.collection[0].parentElement):new o(null)}find(e){return this.length>0?new o(this.collection[0].querySelectorAll(e)):new o(null)}offset(){if(this.length>0){const e=this.collection[0].getBoundingClientRect();return{top:e.top+document.body.scrollTop,left:e.left+document.body.scrollLeft}}}closest(e){let t=null,s=this;for(;s.exists()&&null===t;){if(!0===s.matches(e))return s;const r=s.find(e);r&&r.length>0&&(t=r),s=s.parent()}return null!==t?t:s}closestParent(e,t){let s=this;for(;s.exists();){if(!0===s.matches(e))return s;if("string"==typeof t&&s.matches(t))break;s=s.parent()}return new o(null)}attribute(e,t){if(void 0!==t){for(const s of this.collection)s.setAttribute(e,t);return this}if(this.length>0)return this.collection[0].getAttribute(e)}hasAttribute(e){for(const t of this.collection)if(!t.hasAttribute(e))return!1;return!0}after(e){for(const t of this.collection)t.insertAdjacentHTML("afterend",e);return this}before(e){for(const t of this.collection)t.insertAdjacentHTML("beforebegin",e);return this}style(e,t){for(let s=0;s<this.collection.length;s++)if("string"==typeof e&&void 0!==t)this.collection[s].style[e]=t;else{if("string"==typeof e&&void 0===t)return this.collection[s].style[e];if("object"==typeof e)for(const t in e)this.collection[s].style[t]=e[t]}return this}animate(e,t){for(let s=0;s<this.collection.length;s++)for(const r in e){const n=(new Date).getTime(),i=this.collection;let o,a;void 0!==this.collection[s].style[r]?(a=this.collection[s].style[r],o=setInterval((()=>{const l=Math.min(1,((new Date).getTime()-n)/t);i[s].style[r]=a+l*(e[r]-a),1==l&&clearInterval(o)}),25),this.collection[s].style[r]=a):void 0!==this.collection[s][r]&&(a=this.collection[s][r],o=setInterval((()=>{const l=Math.min(1,((new Date).getTime()-n)/t);i[s][r]=a+l*(e[r]-a),1==l&&clearInterval(o)}),25),this.collection[s][r]=a)}return this}fadeIn(e=400,t){if(this.length>0){const s=this.collection[0];s.style.opacity=0;let r=+new Date;const n=()=>{s.style.opacity=+s.style.opacity+(new Date-r)/e,r=+new Date,+s.style.opacity<1?window.requestAnimationFrame&&requestAnimationFrame(n)||setTimeout(n,16):"function"==typeof t&&t()};n()}return this}fadeOut(e=400,t){if(this.length>0){let s=+new Date;const r=this.collection[0],n=()=>{r.style.opacity=+r.style.opacity-(new Date-s)/e,s=+new Date,+r.style.opacity>0?window.requestAnimationFrame&&requestAnimationFrame(n)||setTimeout(n,16):"function"==typeof t&&t()};n()}return this}matches(e){const t=Element.prototype,s=t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||function(){return-1!==[].indexOf.call(document.querySelectorAll(e),this)};return this.length>0&&s.call(this.collection[0],e)}remove(){for(const e of this.collection)e.parentNode.removeChild(e);return this}replaceWith(e){let t=e;if("string"==typeof e){const s=document.createElement("div");s.innerHTML=e,t=s.firstChild}for(const e of this.collection)e.parentElement.replaceChild(t,e);return this}reset(){for(const e of this.collection)e.reset();return this}property(e,t){if(void 0!==t){for(const s of this.collection)s[e]=t;return this}if(this.length>0)return this.collection[0][e]}}function a(e){return void 0!==e?new o(e):o}function l(e){window.addEventListener("load",e)}var c={};t(c,"FileSystem",(()=>d));var h={};t(h,"Request",(()=>u));class u{static serialize(e){return Object.keys(e).map((t=>encodeURIComponent(t)+"="+encodeURIComponent(e[t]))).join("&")}static get(e,t={},s={}){const r=u.serialize(t);return""!==r&&(e=`${e}?${r}`),fetch(e,s)}static post(e,t,s={}){let r;if(void 0!==s.headers){const e=s.headers["Content-Type"];if(void 0!==e)if("multipart/form-data"==e){r=new FormData;for(const e in t)r.append(e,t[e])}else r="application/json"==e?JSON.stringify(t):u.serialize(t)}else r=u.serialize(t);const n=Object.assign({},{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r},s);return void 0!==n.headers&&"multipart/form-data"===n.headers["Content-Type"]&&delete n.headers["Content-Type"],fetch(e,n)}static put(e,t,s={}){return u.post(e,t,Object.assign({},{method:"PUT"},s))}static delete(e,t,s={}){return u.get(e,t,Object.assign({},{method:"DELETE"},s))}static json(e,t={},s={}){return u.get(e,t,s).then((e=>e.json()))}static blob(e,t={},s={}){return u.get(e,t,s).then((e=>e.blob()))}}class d{static readRemote(e,t="base64",s={}){return u.blob(e,{},s).then((e=>d.read(e,t)))}static read(e,t="text"){return new Promise(((s,r)=>{const n=new FileReader;n.onload=e=>{s(e,e.target.result)},n.onerror=e=>{r(e)},"base64"===t?n.readAsDataURL(e):"buffer"===t?n.readAsArrayBuffer(e):n.readAsText(e,"UTF-8")}))}static create(e,t,s="text/plain"){return Promise.resolve(new File([t],e,{type:s}))}static extension(e){return e.split(".").pop()}static isImage(e){return["jpg","jpeg","png","gif","svg","webp","bmp"].indexOf(d.extension(e).toLowerCase())>-1}}var f={};t(f,"Form",(()=>p));class p{static fill(e,t){for(const s in t){const r=a(`form[data-form='${e}'] [name='${s}']`).get(0);if(void 0!==r)switch(r.type){case"file":case"file[]":break;default:r.value=t[s]}}}static values(e){const t={};return a(`form[data-form='${e}'] [name]`).each((e=>{let s;switch(e.type){case"file[]":s=e.files;break;case"file":s=e.files[0];break;default:s=e.value}null!=s&&(t[e.name]=s)})),t}}var g={};t(g,"Platform",(()=>T));var m,v,y,w=m={};function b(){throw new Error("setTimeout has not been defined")}function k(){throw new Error("clearTimeout has not been defined")}function P(e){if(v===setTimeout)return setTimeout(e,0);if((v===b||!v)&&setTimeout)return v=setTimeout,setTimeout(e,0);try{return v(e,0)}catch(t){try{return v.call(null,e,0)}catch(t){return v.call(this,e,0)}}}!function(){try{v="function"==typeof setTimeout?setTimeout:b}catch(e){v=b}try{y="function"==typeof clearTimeout?clearTimeout:k}catch(e){y=k}}();var j,E=[],L=!1,x=-1;function O(){L&&j&&(L=!1,j.length?E=j.concat(E):x=-1,E.length&&A())}function A(){if(!L){var e=P(O);L=!0;for(var t=E.length;t;){for(j=E,E=[];++x<t;)j&&j[x].run();x=-1,t=E.length}j=null,L=!1,function(e){if(y===clearTimeout)return clearTimeout(e);if((y===k||!y)&&clearTimeout)return y=clearTimeout,clearTimeout(e);try{y(e)}catch(t){try{return y.call(null,e)}catch(t){return y.call(this,e)}}}(e)}}function I(e,t){this.fun=e,this.array=t}function S(){}w.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var s=1;s<arguments.length;s++)t[s-1]=arguments[s];E.push(new I(e,t)),1!==E.length||L||P(A)},I.prototype.run=function(){this.fun.apply(null,this.array)},w.title="browser",w.browser=!0,w.env={},w.argv=[],w.version="",w.versions={},w.on=S,w.addListener=S,w.once=S,w.off=S,w.removeListener=S,w.removeAllListeners=S,w.emit=S,w.prependListener=S,w.prependOnceListener=S,w.listeners=function(e){return[]},w.binding=function(e){throw new Error("process.binding is not supported")},w.cwd=function(){return"/"},w.chdir=function(e){throw new Error("process.chdir is not supported")},w.umask=function(){return 0};class T{static retina(){return window.devicePixelRatio>=2}static portrait(){return 0===window.orientation||180===window.orientation}static landscape(){return 90===window.orientation||-90===window.orientation}static orientation(){return T.portrait()?"portrait":"landscape"}static electron(){return"undefined"!=typeof window&&"object"==typeof window.process&&"renderer"===window.process.type||(!(void 0===m||"object"!=typeof m.versions||!m.versions.electron)||"object"==typeof navigator&&"string"==typeof navigator.userAgent&&navigator.userAgent.indexOf("Electron")>-1)}static cordova(){return!!window.cordova}static desktop(e="Any"){let t=!1;switch(e){case"Windows":t=navigator.platform.includes("Win");break;case"macOS":t=navigator.platform.includes("Mac");break;case"Linux":t=navigator.platform.includes("Linux");break;case"FreeBSD":t=navigator.platform.includes("FreeBSD");break;case"webOS":t=navigator.platform.includes("WebTV");break;default:t=navigator.platform.includes("Win")||navigator.platform.includes("Mac")||navigator.platform.includes("Linux")||navigator.platform.includes("FreeBSD")||navigator.platform.includes("WebTV")}return t}static mobile(e="Any"){let t=!1;switch(e){case"Android":t=/Android/i.test(navigator.userAgent);break;case"iOS":t=/iPhone|iPad|iPod/i.test(navigator.userAgent);break;case"Opera":t=/Opera Mini/i.test(navigator.userAgent);break;case"Windows":t=/Windows Phone|IEMobile|WPDesktop/i.test(navigator.userAgent);break;case"BlackBerry":t=/BlackBerry|BB10/i.test(navigator.userAgent);break;default:t=/Android|iPhone|iPad|iPod|Windows Phone|IEMobile|WPDesktop|BlackBerry|BB10/i.test(navigator.userAgent)}return t}static serviceWorkers(){return"undefined"!=typeof navigator&&"serviceWorker"in navigator&&location.protocol.indexOf("http")>-1}}var $={};t($,"Preload",(()=>D));class D{static image(e){return new Promise(((t,s)=>{const r=new Image;r.onload=()=>{t(r)},r.onerror=e=>{s(e)},r.src=e}))}static file(e){return u.blob(e)}}var _={};t(_,"SpaceAdapter",(()=>C)),t(_,"Space",(()=>N));class B{constructor({name:e="",version:t="",store:s=""}){this.name=e,this.version=t,this.store=s,this.upgrades={},""===this.version?this.numericVersion=0:this.numericVersion=parseInt(t.replace(/\./g,"")),this.id=""!==e&&""!==t&&""!==s?`${this.name}::${this.store}::${this.version}_`:""!==e&&""!==t?`${this.name}::${this.version}_`:""!==e?`${this.name}::_`:""}open(){return"object"!=typeof this.storage||this.storage instanceof Promise?(this.storage instanceof Promise||(this.storage=new Promise((e=>{let t=[];if(""!==this.version){let e="";""!==this.name&&""!==this.version&&""!==this.store?e=`${this.name}::${this.store}::`:""!==this.name&&""!==this.version&&(e=`${this.name}::`);const s=Object.keys(window.localStorage).filter((t=>0===t.indexOf(e))).map((t=>t.replace(e,"").split("_")[0])).filter((e=>-1===e.indexOf("::"))).sort();if(s.length>0){const e=s[0],r=parseInt(e.replace(/\./g,""));if(r<this.numericVersion){const s=Object.keys(this.upgrades).sort(),n=s.findIndex((e=>{const[t]=e.split("::");return parseInt(t)===r}));n>-1&&(t=s.slice(n).filter((e=>{const[t,s]=e.split("::");return parseInt(t)<this.numericVersion&&parseInt(s)<=this.numericVersion})));let i=`${this.name}::${e}_`;""!==this.name&&""!==this.version&&""!==this.store?i=`${this.name}::${this.store}::${e}_`:""!==this.name&&""!==this.version&&(i=`${this.name}::${e}_`);const o=Object.keys(window.localStorage).filter((e=>0===e.indexOf(i))).map((e=>e.replace(i,"")));for(const e of o){const t=window.localStorage.getItem(`${i}${e}`);window.localStorage.setItem(this.id+e,t),window.localStorage.removeItem(`${i}${e}`)}}}}e({upgrades:t})})).then((({upgrades:e})=>(this.storage=window.localStorage,new Promise((t=>{this._upgrade(e,(()=>t(this)))})))))),this.storage):Promise.resolve(this)}set(e,t){return this.open().then((()=>("object"==typeof t?this.storage.setItem(this.id+e,JSON.stringify(t)):this.storage.setItem(this.id+e,t),Promise.resolve({key:e,value:t}))))}update(e,t){return this.get(e).then((s=>("object"==typeof s?("object"==typeof t&&(t=Object.assign({},s,t)),this.storage.setItem(this.id+e,JSON.stringify(t))):this.storage.setItem(this.id+e,t),Promise.resolve({key:e,value:t})))).catch((()=>this.set(e,t)))}get(e){return this.open().then((()=>new Promise(((t,s)=>{let r=null;r=this.storage.getItem(this.id+e);try{const e=JSON.parse(r);e&&"object"==typeof e&&(r=e)}catch(e){}null!=r?t(r):s()}))))}getAll(){return this.keys().then((e=>{const t={},s=[];for(const r of e)s.push(this.get(r).then((e=>{t[r]=e})));return Promise.all(s).then((()=>t))}))}contains(e){return this.keys().then((t=>{if(!t.includes(e))return Promise.reject();Promise.resolve()}))}upgrade(e,t,s){return this.upgrades[`${parseInt(e.replace(/\./g,""))}::${parseInt(t.replace(/\./g,""))}`]=s,Promise.resolve()}_upgrade(e,t){e.length>0?this.upgrades[e[0]].call(this,this).then((()=>{this._upgrade(e.slice(1),t)})).catch((e=>console.error(e))):t()}rename(e){return this.name!==e?this.keys().then((t=>{const s=this.id;this.name=e,""!==this.name&&""!==this.version&&""!==this.store?this.id=`${this.name}::${this.store}::${this.version}_`:""!==this.name&&""!==this.version?this.id=`${this.name}::${this.version}_`:""!==this.name?this.id=`${this.name}::_`:this.id="";const r=[];for(const e of t)r.push(this.set(e,this.storage.getItem(`${s}${e}`)).then((()=>{this.storage.removeItem(`${s}${e}`)})));return Promise.all(r)})):Promise.reject()}key(e,t=!1){return this.open().then((()=>!0===t?Promise.resolve(this.storage.key(e)):Promise.resolve(this.storage.key(e).replace(this.id,""))))}keys(e=!1){return this.open().then((()=>Promise.resolve(Object.keys(this.storage).filter((e=>0===e.indexOf(this.id))).map((t=>!0===e?t:t.replace(this.id,""))))))}remove(e){return this.get(e).then((t=>(this.storage.removeItem(this.id+e),Promise.resolve(t))))}clear(){return this.keys().then((e=>{for(const t of e)this.remove(t);return Promise.resolve()}))}}const C={LocalStorage:B,SessionStorage:class extends B{constructor({name:e="",version:t="",store:s=""}){super({name:e,version:t,store:s})}open(){return void 0===this.storage&&(this.storage=window.sessionStorage),Promise.resolve(this)}},IndexedDB:class{constructor({name:e="",version:t="",store:s="",props:r={},index:n={}}){this.name=e,this.version=t,this.store=s,this.props=r||{},this.index=n,this.keyPath=r.keyPath||"id",this.upgrades={},""===this.version?this.numericVersion=0:this.numericVersion=parseInt(t.replace(/\./g,""))}open(){return""===this.name?(console.error("No name has been defined for IndexedDB space."),Promise.reject()):""===this.store?(console.error("No store has been defined for IndexedDB space."),Promise.reject()):this.storage instanceof IDBDatabase?Promise.resolve(this):(this.storage instanceof Promise||(this.storage=new Promise(((e,t)=>{let s=[];const r=window.indexedDB.open(this.name,this.numericVersion);r.onerror=e=>{t(e)},r.onsuccess=t=>{e({storage:t.target.result,upgrades:s})},r.onupgradeneeded=t=>{if(t.oldVersion<1){const e=t.target.result.createObjectStore(this.store,this.props);for(const t of Object.keys(this.index))e.createIndex(this.index[t].name,this.index[t].field,this.index[t].props)}else{const e=Object.keys(this.upgrades).sort(),r=e.findIndex((e=>{const[s]=e.split("::");return parseInt(s)===t.oldVersion}));r>-1&&(s=e.slice(r).filter((e=>{const[t,s]=e.split("::");return parseInt(t)<this.numericVersion&&parseInt(s)<=this.numericVersion})))}t.target.transaction.addEventListener("success",(()=>{e({storage:t.target.result,upgrades:s})}))}})).then((({storage:e,upgrades:t})=>(this.storage=e,new Promise((s=>{this._upgrade(t,(()=>s(e)),event)})))))),this.storage)}set(e=null,t){return this.open().then((()=>new Promise(((s,r)=>{const n=this.storage.transaction(this.store,"readwrite").objectStore(this.store);let i;if(null!==e){const s={};s[this.keyPath]=e,i=n.put(Object.assign({},s,t))}else i=n.add(t);i.addEventListener("success",(e=>{s({key:e.target.result,value:t})})),i.addEventListener("error",(e=>{r(e)}))}))))}update(e,t){return this.get(e).then((s=>void 0===s?this.set(e,t):new Promise(((e,r)=>{const n=this.storage.transaction(this.store,"readwrite").objectStore(this.store).put(Object.assign({},s,t));n.addEventListener("success",(s=>{e({key:s.target.result,value:t})})),n.addEventListener("error",(e=>{r(e)}))}))))}get(e){return this.open().then((()=>new Promise(((t,s)=>{const r=this.storage.transaction(this.store).objectStore(this.store).get(e);r.addEventListener("success",(e=>{const r=e.target.result;null!=r?t(r):s()})),r.addEventListener("error",(e=>{s(e)}))}))))}getAll(){return this.open().then((()=>new Promise(((e,t)=>{const s=this.storage.transaction(this.store).objectStore(this.store).getAll();s.addEventListener("success",(t=>{const s={};t.target.result.forEach((e=>{const t=e[this.keyPath];delete e[this.keyPath],s[t]=e})),e(s)})),s.addEventListener("error",(e=>{t(e)}))}))))}contains(e){return this.get(e).then((t=>{if(!t.includes(e))return Promise.reject();Promise.resolve()}))}upgrade(e,t,s){return this.upgrades[`${parseInt(e.replace(/\./g,""))}::${parseInt(t.replace(/\./g,""))}`]=s,Promise.resolve()}_upgrade(e,t,s){e.length>0?this.upgrades[e[0]].call(this,this,s).then((()=>{this._upgrade(e.slice(1),t,s)})).catch((e=>console.error(e))):t()}rename(){return Promise.reject()}key(){return Promise.reject()}keys(){return this.open().then((()=>new Promise(((e,t)=>{const s=this.storage.transaction(this.store,"readwrite").objectStore(this.store).getAllKeys();s.addEventListener("success",(t=>{e(t.target.result)}),!1),s.addEventListener("error",(e=>{t(e)}),!1)}))))}remove(e){return this.get(e).then((t=>new Promise(((s,r)=>{const n=this.storage.transaction(this.store,"readwrite").objectStore(this.store).delete(e);n.addEventListener("success",(()=>{s(t)}),!1),n.addEventListener("error",(e=>{r(e)}),!1)}))))}clear(){return this.open().then((()=>new Promise(((e,t)=>{const s=this.storage.transaction(this.store,"readwrite").objectStore(this.store).clear();s.addEventListener("success",(()=>{e()}),!1),s.addEventListener("error",(e=>{t(e)}),!1)}))))}},RemoteStorage:class{constructor({name:e="",version:t="",store:s="",endpoint:r="",props:n={}}){this.name=e,this.version=t,this.store=s,this.endpoint=`${r}${s}/`,this.props=n}open(){return void 0===this.storage&&(this.storage=u),Promise.resolve(this)}set(e,t){return this.open().then((()=>this.storage.post(this.endpoint+e,t,this.props).then((e=>e.json())).then((t=>Promise.resolve({key:e,value:t})))))}update(e,t){return this.get(e).then((s=>this.storage.put(this.endpoint+e,Object.assign({},s,t),this.props).then((e=>e.json())).then((t=>Promise.resolve({key:e,value:t})))))}get(e){return this.open().then((()=>this.storage.json(this.endpoint+e,{},this.props)))}getAll(){return this.open().then((()=>this.storage.json(this.endpoint,{},this.props)))}contains(e){return this.keys().then((t=>{if(!t.includes(e))return Promise.reject();Promise.resolve()}))}upgrade(){return Promise.reject()}rename(){return Promise.reject()}key(){return Promise.reject()}keys(){return this.open().then((()=>this.storage.json(this.endpoint,{keys:!0},this.props)))}remove(e){return this.open().then((()=>this.storage.delete(this.endpoint+e,{},this.props).then((e=>e.json())).then((t=>Promise.resolve(e,t)))))}clear(){return this.open().then((()=>this.storage.delete(this.endpoint,{},this.props)))}}};class N{constructor(e=C.LocalStorage,t={}){this._configuration=Object.assign({},{name:"",version:"",store:""},t),this.adapter=new e(this._configuration),this.callbacks={create:[],update:[],delete:[]},this.transformations={}}configuration(e=null){if(null===e)return this._configuration;this._configuration=Object.assign({},this._configuration,e),this.adapter.configuration(e)}open(){return this.adapter.open().then((()=>Promise.resolve(this)))}set(e,t){for(const s of Object.keys(this.transformations))"function"==typeof this.transformations[s].set&&(t=this.transformations[s].set.call(null,e,t));return this.adapter.set(e,t).then((({key:e,value:t})=>{for(const s of this.callbacks.create)s.call(null,e,t);return Promise.resolve({key:e,value:t})}))}update(e,t){for(const s of Object.keys(this.transformations))"function"==typeof this.transformations[s].set&&(t=this.transformations[s].set.call(null,e,t));return this.adapter.update(e,t).then((({key:e,value:t})=>{for(const s of this.callbacks.update)s.call(null,e,t);return Promise.resolve({key:e,value:t})}))}get(e){return this.adapter.get(e).then((t=>{for(const s of Object.keys(this.transformations))"function"==typeof this.transformations[s].get&&(t=this.transformations[s].get.call(null,e,t));return t}))}getAll(){return this.adapter.getAll().then((e=>{for(const t of Object.keys(e))for(const s of Object.keys(this.transformations))"function"==typeof this.transformations[s].get&&(e[t]=this.transformations[s].get.call(null,t,e[t]));return e}))}each(e){return this.getAll().then((t=>{const s=[];for(const r of Object.keys(t))s.push(e.call(this,r,t[r]));return Promise.all(s)}))}contains(e){return this.adapter.contains(e)}upgrade(e,t,s){return this.adapter.upgrade(e,t,s).then((()=>Promise.resolve(this)))}rename(e){return this.adapter.rename(e)}onCreate(e){this.callbacks.create.push(e)}onUpdate(e){this.callbacks.update.push(e)}onDelete(e){this.callbacks.delete.push(e)}addTransformation({id:e,get:t,set:s}){this.transformations[e]={id:e,get:t,set:s}}removeTransformation(e){delete this.transformations[e]}key(e,t=!1){return this.adapter.key(e,t)}keys(e=!1){return this.adapter.keys(e)}remove(e){return this.adapter.remove(e).then((t=>{for(const s of this.callbacks.delete)s.call(null,e,t)}))}clear(){return this.adapter.clear()}}var M={};t(M,"Text",(()=>U));class U{static capitalize(e){return e.replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()))}static suffix(e,t){let s="",r=t.indexOf(e);return-1!==r&&(r+=e.length,s=t.substr(r,t.length-r)),s}static selection(){return window.getSelection?window.getSelection().toString():document.selection&&"Control"!=document.selection.type?document.selection.createRange().text:void 0}static prefix(e,t){let s="";const r=t.indexOf(e);return-1!=r&&(s=t.substr(0,r)),s}static friendly(e){const t=[/[áàâãªä]/,/[ÁÀÂÃÄ]/,/[ÍÌÎÏ]/,/[íìîï]/,/[éèêë]/,/[ÉÈÊË]/,/[óòôõºö]/,/[ÓÒÔÕÖ]/,/[úùûü]/,/[ÚÙÛÜ]/,/ç/,/Ç/,/ñ/,/Ñ/,/_/,/[’‘‹›<>']/,/[“”«»„"]/,/[(){}[\]]/,/[?¿!¡#$%&^*´`~/°|]/,/[,.:;]/,/ /],s=["a","A","I","i","e","E","o","O","u","U","c","C","n","N","-","","","","","","-"];for(const r in t)e=e.replace(new RegExp(t[r],"g"),s[r]);return e}}var R={};t(R,"Util",(()=>V));class V{static callAsync(e,t,...s){try{const r=e.apply(t,s);return r instanceof Promise?r:Promise.resolve(r)}catch(e){return Promise.reject(e)}}static uuid(){if(window.crypto)return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)));{const e=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}}}e(module.exports,s),e(module.exports,i),e(module.exports,c),e(module.exports,f),e(module.exports,g),e(module.exports,$),e(module.exports,h),e(module.exports,_),e(module.exports,M),e(module.exports,R);
//# sourceMappingURL=index.js.map