@aegis-framework/artemis 0.3.25 → 0.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artemis.js +1 -1
- package/dist/artemis.js.map +1 -1
- package/dist/artemis.min.js +1 -1
- package/dist/artemis.min.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SpaceAdapter/IndexedDB.js +9 -2
package/dist/artemis.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t,s,r){Object.defineProperty(e,t,{get:s,set:r,enumerable:!0,configurable:!0})}var t={};e(t,"DebugLevel",(()=>s)),e(t,"Debug",(()=>r));const s={NONE:0,ERROR:1,WARNING:2,INFO:3,DEBUG:4,ALL:5};class r{static level(e){return"number"==typeof e&&(this._level=e),this._level}static log(...e){this.level()>=s.DEBUG&&console.log(...e)}static debug(...e){this.level()>=s.DEBUG&&console.debug(...e)}static info(...e){this.level()>=s.INFO&&console.info(...e)}static error(...e){this.level()>=s.ERROR&&console.error(...e)}static warning(...e){this.level()>=s.WARNING&&console.warn(...e)}static table(...e){this.level()>=s.DEBUG&&console.table(...e)}static group(...e){this.level()>=s.DEBUG&&console.group(...e)}static groupCollapsed(...e){this.level()>=s.DEBUG&&console.groupCollapsed(...e)}static groupEnd(...e){this.level()>=s.DEBUG&&console.groupEnd(...e)}static time(...e){this.level()>=s.DEBUG&&console.time(...e)}static timeLog(...e){this.level()>=s.DEBUG&&console.timeLog(...e)}static timeEnd(...e){this.level()>=s.DEBUG&&console.timeEnd(...e)}static trace(...e){this.level()>=s.DEBUG&&console.trace(...e)}}r._level=s.NONE;var n={};e(n,"DOM",(()=>i)),e(n,"$_",(()=>o)),e(n,"$_ready",(()=>a));class i{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 i)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=o(e.target).closestParent(t,this._selector);r.exists()&&s.call(r.get(0),e)}),!1);return this}filter(e){return this.length>0?new i(this.collection[0].querySelector(e)):new i(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 i(this.collection[0]):new i(null)}last(){return this.length>0?new i(this.collection[this.collection.length-1]):new i(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 i(this.collection[0].parentElement):new i(null)}find(e){return this.length>0?new i(this.collection[0].querySelectorAll(e)):new i(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 i(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&&"undefined"!==t)return this.collection[s].style[e]=t,this;if("string"==typeof e&&"undefined"===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 o(e){return void 0!==e?new i(e):i}function a(e){window.addEventListener("load",e)}e({},"FileSystem",(()=>c));e({},"Request",(()=>l));class l{static serialize(e){return Object.keys(e).map((t=>encodeURIComponent(t)+"="+encodeURIComponent(e[t]))).join("&")}static get(e,t={},s={}){const r=l.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):l.serialize(t)}else r=l.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 l.post(e,t,Object.assign({},{method:"PUT"},s))}static delete(e,t,s={}){return l.get(e,t,Object.assign({},{method:"DELETE"},s))}static json(e,t={},s={}){return l.get(e,t,s).then((e=>e.json()))}static blob(e,t={},s={}){return l.get(e,t,s).then((e=>e.blob()))}}class c{static readRemote(e,t="base64",s={}){return l.blob(e,{},s).then((e=>c.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(c.extension(e).toLowerCase())>-1}}e({},"Form",(()=>h));class h{static fill(e,t){for(const s in t){const r=o(`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 o(`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}}e({},"Platform",(()=>O));var u,d,f,p=u={};function g(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}function v(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}!function(){try{d="function"==typeof setTimeout?setTimeout:g}catch(e){d=g}try{f="function"==typeof clearTimeout?clearTimeout:m}catch(e){f=m}}();var y,w=[],b=!1,k=-1;function P(){b&&y&&(b=!1,y.length?w=y.concat(w):k=-1,w.length&&j())}function j(){if(!b){var e=v(P);b=!0;for(var t=w.length;t;){for(y=w,w=[];++k<t;)y&&y[k].run();k=-1,t=w.length}y=null,b=!1,function(e){if(f===clearTimeout)return clearTimeout(e);if((f===m||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{f(e)}catch(t){try{return f.call(null,e)}catch(t){return f.call(this,e)}}}(e)}}function E(e,t){this.fun=e,this.array=t}function L(){}p.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];w.push(new E(e,t)),1!==w.length||b||v(j)},E.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=L,p.addListener=L,p.once=L,p.off=L,p.removeListener=L,p.removeAllListeners=L,p.emit=L,p.prependListener=L,p.prependOnceListener=L,p.listeners=function(e){return[]},p.binding=function(e){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(e){throw new Error("process.chdir is not supported")},p.umask=function(){return 0};class O{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 O.portrait()?"portrait":"landscape"}static electron(){return"undefined"!=typeof window&&"object"==typeof window.process&&"renderer"===window.process.type||(!(void 0===u||"object"!=typeof u.versions||!u.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}}e({},"Preload",(()=>S));class S{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 l.blob(e)}}var x={};e(x,"SpaceAdapter",(()=>I)),e(x,"Space",(()=>T));class A{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 I={LocalStorage:A,SessionStorage:class extends A{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.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;i=null!==e?n.put(Object.assign({},{id:e},t)):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=>{t(e.target.result)})),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=>{e(t.target.result)})),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=l),Promise.resolve(this)}set(e,t){return this.open().then((()=>this.storage.post(this.endpoint+e,t,this.props).then((t=>Promise.resolve({key:e,response:t.json()})))))}update(e,t){return this.get(e).then((s=>this.storage.put(this.endpoint+e,Object.assign({},s,t),this.props).then((t=>Promise.resolve({key:e,response:t.json()})))))}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((t=>Promise.resolve(e,t.json())))))}clear(){return this.open().then((()=>this.storage.delete(this.endpoint,{},this.props)))}}};class T{constructor(e=I.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()}}e({},"Text",(()=>$));class ${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}}e({},"Util",(()=>D));class D{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()}}}export{s as DebugLevel,r as Debug,i as DOM,o as $_,a as $_ready,c as FileSystem,h as Form,O as Platform,S as Preload,l as Request,I as SpaceAdapter,T as Space,$ as Text,D as Util};
|
|
1
|
+
function e(e,t,s,r){Object.defineProperty(e,t,{get:s,set:r,enumerable:!0,configurable:!0})}var t={};e(t,"DebugLevel",(()=>s)),e(t,"Debug",(()=>r));const s={NONE:0,ERROR:1,WARNING:2,INFO:3,DEBUG:4,ALL:5};class r{static level(e){return"number"==typeof e&&(this._level=e),this._level}static log(...e){this.level()>=s.DEBUG&&console.log(...e)}static debug(...e){this.level()>=s.DEBUG&&console.debug(...e)}static info(...e){this.level()>=s.INFO&&console.info(...e)}static error(...e){this.level()>=s.ERROR&&console.error(...e)}static warning(...e){this.level()>=s.WARNING&&console.warn(...e)}static table(...e){this.level()>=s.DEBUG&&console.table(...e)}static group(...e){this.level()>=s.DEBUG&&console.group(...e)}static groupCollapsed(...e){this.level()>=s.DEBUG&&console.groupCollapsed(...e)}static groupEnd(...e){this.level()>=s.DEBUG&&console.groupEnd(...e)}static time(...e){this.level()>=s.DEBUG&&console.time(...e)}static timeLog(...e){this.level()>=s.DEBUG&&console.timeLog(...e)}static timeEnd(...e){this.level()>=s.DEBUG&&console.timeEnd(...e)}static trace(...e){this.level()>=s.DEBUG&&console.trace(...e)}}r._level=s.NONE;var n={};e(n,"DOM",(()=>i)),e(n,"$_",(()=>o)),e(n,"$_ready",(()=>a));class i{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 i)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=o(e.target).closestParent(t,this._selector);r.exists()&&s.call(r.get(0),e)}),!1);return this}filter(e){return this.length>0?new i(this.collection[0].querySelector(e)):new i(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 i(this.collection[0]):new i(null)}last(){return this.length>0?new i(this.collection[this.collection.length-1]):new i(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 i(this.collection[0].parentElement):new i(null)}find(e){return this.length>0?new i(this.collection[0].querySelectorAll(e)):new i(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 i(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&&"undefined"!==t)return this.collection[s].style[e]=t,this;if("string"==typeof e&&"undefined"===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 o(e){return void 0!==e?new i(e):i}function a(e){window.addEventListener("load",e)}e({},"FileSystem",(()=>c));e({},"Request",(()=>l));class l{static serialize(e){return Object.keys(e).map((t=>encodeURIComponent(t)+"="+encodeURIComponent(e[t]))).join("&")}static get(e,t={},s={}){const r=l.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):l.serialize(t)}else r=l.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 l.post(e,t,Object.assign({},{method:"PUT"},s))}static delete(e,t,s={}){return l.get(e,t,Object.assign({},{method:"DELETE"},s))}static json(e,t={},s={}){return l.get(e,t,s).then((e=>e.json()))}static blob(e,t={},s={}){return l.get(e,t,s).then((e=>e.blob()))}}class c{static readRemote(e,t="base64",s={}){return l.blob(e,{},s).then((e=>c.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(c.extension(e).toLowerCase())>-1}}e({},"Form",(()=>h));class h{static fill(e,t){for(const s in t){const r=o(`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 o(`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}}e({},"Platform",(()=>O));var u,d,f,p=u={};function g(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}function v(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}!function(){try{d="function"==typeof setTimeout?setTimeout:g}catch(e){d=g}try{f="function"==typeof clearTimeout?clearTimeout:m}catch(e){f=m}}();var y,w=[],b=!1,k=-1;function P(){b&&y&&(b=!1,y.length?w=y.concat(w):k=-1,w.length&&j())}function j(){if(!b){var e=v(P);b=!0;for(var t=w.length;t;){for(y=w,w=[];++k<t;)y&&y[k].run();k=-1,t=w.length}y=null,b=!1,function(e){if(f===clearTimeout)return clearTimeout(e);if((f===m||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{f(e)}catch(t){try{return f.call(null,e)}catch(t){return f.call(this,e)}}}(e)}}function E(e,t){this.fun=e,this.array=t}function L(){}p.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];w.push(new E(e,t)),1!==w.length||b||v(j)},E.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=L,p.addListener=L,p.once=L,p.off=L,p.removeListener=L,p.removeAllListeners=L,p.emit=L,p.prependListener=L,p.prependOnceListener=L,p.listeners=function(e){return[]},p.binding=function(e){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(e){throw new Error("process.chdir is not supported")},p.umask=function(){return 0};class O{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 O.portrait()?"portrait":"landscape"}static electron(){return"undefined"!=typeof window&&"object"==typeof window.process&&"renderer"===window.process.type||(!(void 0===u||"object"!=typeof u.versions||!u.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}}e({},"Preload",(()=>S));class S{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 l.blob(e)}}var x={};e(x,"SpaceAdapter",(()=>I)),e(x,"Space",(()=>T));class A{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 I={LocalStorage:A,SessionStorage:class extends A{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.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;i=null!==e?n.put(Object.assign({},{id:e},t)):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=>{e(t.target.result)})),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=l),Promise.resolve(this)}set(e,t){return this.open().then((()=>this.storage.post(this.endpoint+e,t,this.props).then((t=>Promise.resolve({key:e,response:t.json()})))))}update(e,t){return this.get(e).then((s=>this.storage.put(this.endpoint+e,Object.assign({},s,t),this.props).then((t=>Promise.resolve({key:e,response:t.json()})))))}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((t=>Promise.resolve(e,t.json())))))}clear(){return this.open().then((()=>this.storage.delete(this.endpoint,{},this.props)))}}};class T{constructor(e=I.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()}}e({},"Text",(()=>$));class ${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}}e({},"Util",(()=>D));class D{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()}}}export{s as DebugLevel,r as Debug,i as DOM,o as $_,a as $_ready,c as FileSystem,h as Form,O as Platform,S as Preload,l as Request,I as SpaceAdapter,T as Space,$ as Text,D as Util};
|
|
2
2
|
//# sourceMappingURL=artemis.js.map
|