raiutils 8.7.11 → 9.0.0
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/README.md +110 -118
- package/dist/router.d.ts +25 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1 -0
- package/dist/router.js.map +1 -0
- package/dist/schema.d.ts +113 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +1 -0
- package/dist/schema.js.map +1 -0
- package/dist/utils.d.ts +288 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/dist/uuid.d.ts +29 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +1 -0
- package/dist/uuid.js.map +1 -0
- package/package.json +22 -7
- package/src/router.ts +131 -0
- package/src/schema.ts +259 -0
- package/src/utils.ts +996 -0
- package/src/uuid.ts +102 -0
- package/router.js +0 -109
- package/schema.js +0 -148
- package/utils.js +0 -911
- package/utils.min.js +0 -2
- package/uuid.js +0 -69
package/utils.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
//https://github.com/Pecacheu/Utils.js GNU GPL v3
|
|
2
|
-
"use strict";const utils={VER:"v8.7.11"},_uNJS="undefined"!=typeof global;let UtilRect,P="undefined"==typeof window?[{},{back(){},forward(){}},class{},class{},class{},class{},()=>{}]:[window,history,DOMRect,HTMLCollection,Element,NodeList,addEventListener];(()=>{let[t,e,i,n,l,s,r]=P;utils.define=(t,e,i,n)=>{let l={};if(i&&(l.get=i),n&&(l.set=n),Array.isArray(e))for(let s of e)Object.defineProperty(t,s,l);else Object.defineProperty(t,e,l)},utils.proto=(t,e,i,n)=>{let l={value:i};if(n||(t=t.prototype),Array.isArray(e))for(let s of e)Object.defineProperty(t,s,l);else Object.defineProperty(t,e,l)},utils.setCookie=(t,e,i,n)=>{let l=`${encodeURIComponent(t)}=${null==e?"":encodeURIComponent(e)};path=/`;if(null!=i&&(-1===i&&(i=new Date(Number.MAX_SAFE_INTEGER/10)),i instanceof Date?l+=";expires="+i.toUTCString():l+=";max-age="+i),n&&(l+=";secure"),_uNJS)return l;document.cookie=l},utils.remCookie=t=>{let e=encodeURIComponent(t)+"=;max-age=0";if(_uNJS)return e;document.cookie=e},utils.getCookies=t=>{if(null==t&&(t=document.cookie),!t)return{};let e=t.split("; "),i,n,l={};for(i of e)n=i.indexOf("="),l[decodeURIComponent(i.slice(0,n))]=decodeURIComponent(i.slice(n+1));return l},utils.getCookie=(t,e)=>{null==e&&(e=document.cookie),t=encodeURIComponent(t)+"=";let i=e.split("; "),n;for(n of i)if(n.startsWith(t))return decodeURIComponent(n.slice(t.length))},utils.proto(Function,"wrap",function(){let t=this,e=arguments;return function(){return t.apply(arguments,e)}}),utils.copy=(t,e)=>{if(0===e||"object"!=typeof t)return t;e=e>0?e-1:null;let i;if(Array.isArray(t))i=Array(t.length),t.forEach((t,n)=>{i[n]=utils.copy(t,e)});else for(let n in i={},t)i[n]=utils.copy(t[n],e);return i},utils.deviceInfo=t=>{let e={};if(t||(t=navigator.userAgent),!t.startsWith("Mozilla/5.0 "))return e;let i=t.indexOf(")"),n=e.rawOS=t.slice(13,i),l,s;return n.startsWith("Windows")?(l=n.split("; "),e.os="Windows",e.type=-1!=l.indexOf("WOW64")?"x64 PC; x86 Browser":-1!=l.indexOf("x64")?"x64 PC":"x86 PC",l=n.indexOf("Windows NT "),e.version=n.slice(l+11,n.indexOf(";",l+12))):n.startsWith("iP")?(l=n.indexOf("OS"),e.os="iOS",e.type=n.slice(0,n.indexOf(";")),e.version=n.slice(l+3,n.indexOf(" ",l+4)).replace(/_/g,".")):n.startsWith("Macintosh;")?(l=n.indexOf(" Mac OS X"),e.os="MacOS",e.type=n.slice(11,l)+" Mac",e.version=n.slice(l+10).replace(/_/g,".")):-1!=(l=n.indexOf("Android"))?(e.os="Android",e.version=n.slice(l+8,n.indexOf(";",l+9)),l=n.lastIndexOf(";"),s=n.indexOf(" Build",l+2),e.type=n.slice(l+2,-1==s?void 0:s)):n.startsWith("X11;")&&(l=(n=n.slice(5).split(/[;\s]+/)).length,e.os=("Linux"==n[0]?"":"Linux ")+n[0],e.type=n[l-2],e.version=n[l-1]),(l=Number(e.version))&&(e.version=l),l=t.indexOf(" ",i+2),s=-1==(s=t.indexOf(")",l+1))?l+1:s+2,e.engine=t.slice(i+2,l),e.browser=t.slice(s),e.mobile=!!t.match(/Mobi/i),e},_uNJS||(utils.device=utils.deviceInfo(),utils.mobile=utils.device.mobile),t.TouchList&&utils.proto(TouchList,"get",function(t){for(let e in this)if(this[e].identifier==t)return this[e];return 0});let u=/\.0*$/;utils.numField=(t,e,i,n,l)=>{let s=RegExp(`[,${l?RegExp.escape(l):""}]`,"g");function r(t){return"string"==typeof t&&(t=t.replace(s,"")),t=Math.min(i,Math.max(e,Number(t)||0)),n?Number(t.toFixed(n)):Math.round(t)}return t.type=utils.mobile||n||l?"tel":"number",t.setAttribute("pattern","\\d*"),t.step||(t.step=1),t.addEventListener("keydown",s=>{if(s.ctrlKey)return;let r=s.key,o=1===r.length&&Number.isFinite(Number(r)),a=t.ns,f=a.length,c=a.indexOf(".");if("Tab"!==r&&"Enter"!==r){if(o?(-1===c||f-c<n+1)&&(a+=r):"."===r||"*"===r?n&&-1==c&&t.num!=i&&(e>=0||t.num!=e)&&(!f&&e>0?a=Math.floor(e)+".":a+="."):"Backspace"===r||"Delete"===r?a=e>0&&t.num===e&&a.endsWith(".")?"":a.slice(0,-1):"-"===r||"#"===r?e<0&&!f&&(a="-"):"ArrowUp"===r?(a=null,t.set(t.num+Number(t.step))):"ArrowDown"===r&&(a=null,t.set(t.num-Number(t.step))),null!==a&&a!==t.ns){f=a.length,c=a.indexOf(".");let d="-"===a||"-."===a,h=Math.min(i,Math.max(e,Number(d?"0":a+(a.endsWith(".")?"0":""))));(!o||!a||t.num!==h||-1!==c&&f-c<n+1)&&(t.ns=a,t.num=h,t.value=l?d?l+"-0.00":utils.formatCost(h,l):("-"===a[0]?"-":"")+Math.floor(Math.abs(h))+(-1!==c?a.slice(c)+(u.test(a)?"0":""):""),t.onnuminput&&t.onnuminput.call(t))}s.preventDefault()}}),t.set=e=>{t.num=r(e),t.ns=t.num.toString(),t.value=l?utils.formatCost(t.num,l):t.ns,t.ns=t.ns.replace(/^(-?)0+/,"$1"),t.onnuminput&&t.onnuminput.call(t)},t.setRange=(s,u,o)=>{e=null==s?Number.MIN_SAFE_INTEGER:s,i=null==u?Number.MAX_SAFE_INTEGER:u,n=null==o?l?2:0:o,r(t.num)!==t.num&&t.set(t.num)},t.addEventListener("input",()=>t.set(t.value)),t.addEventListener("paste",e=>{t.set(e.clipboardData.getData("text")),e.preventDefault()}),t.setRange(e,i,n),t},utils.autosize=(t,e=5,i=1)=>{t.set=e=>{t.value=e,l()};let n=t.style;function l(){if(0===t.scrollHeight)return setTimeout(l,1);t.setAttribute("rows",1);let s=getComputedStyle(t);n.setProperty("overflow","hidden","important"),n.width=t.innerRect.w+"px",n.boxSizing="content-box",n.borderWidth=n.paddingInline=0;let r=parseFloat(s.paddingTop)+parseFloat(s.paddingBottom),u="normal"===s.lineHeight?parseFloat(s.height):parseFloat(s.lineHeight),o=Math.round((Math.round(t.scrollHeight)-r)/u);n.overflow=n.width=n.boxSizing=n.borderWidth=n.paddingInline="",t.setAttribute("rows",utils.bounds(o,i,e))}n.maxHeight=n.resize="none",n.minHeight=0,n.height="auto",t.setAttribute("rows",i),t.addEventListener("input",l)},utils.formatCost=(t,e="$")=>{if(!t)return e+"0.00";let i=t.toFixed(2).split(".");return e+i[0].split("").reverse().reduce((t,e,i)=>"-"==e?e+t:e+(i&&!(i%3)?",":"")+t,"")+"."+i[1]};let o="undefined"==typeof BigInt?t=>t:BigInt,a=o(0);function f(t){return t<=9?"0"+t:t}utils.abs=t=>"bigint"==typeof t?t<a?-t:t:Math.abs(t),utils.min=function(){let t,e;for(t of arguments)t>e||(e=t);return e},utils.max=function(){let t,e;for(t of arguments)t<e||(e=t);return e},utils.deg=t=>180*t/Math.PI,utils.rad=t=>t*Math.PI/180,Math.cot=t=>1/Math.tan(t),utils.fixedNum=(t,e,i=10)=>{"bigint"==typeof e&&(e=Number(e));let n=utils.abs(t).toString(i).toUpperCase();return(t<0?"-":"")+(16==i?"0x":2==i?"0b":"")+"0".repeat(Math.max(e-n.length,0))+n},utils.bounds=(t,e=0,i=1)=>t>=e?t<=i?t:i:e,utils.norm=utils.normalize=(t,e=0,i=1)=>{let n=i-e;return((t+utils.abs(e))%n+n)%n+e},utils.map=(t,e,i,n,l,s)=>{let r=(t-e)/(i-e);return(s?s(r):r)*(l-n)+n},utils.hexToRgb=t=>{let e=parseInt(t.slice(1),16);return[e>>16&255,e>>8&255,255&e]},utils.rgbToHsl=(t,e,i)=>{t/=255;let n=Math.max(t,e/=255,i/=255),l=Math.min(t,e,i),s,r,u=(n+l)/2;if(n===l)s=r=0;else{let o=n-l;switch(r=u>.5?o/(2-n-l):o/(n+l),n){case t:s=(e-i)/o+(e<i?6:0);break;case e:s=(i-t)/o+2;break;case i:s=(t-e)/o+4}s/=6}return[360*s,100*r,100*u]},utils.rand=(t,e,i,n)=>{e*=i=i||1,t*=i;let l=Math.random();return Math.round((n?n(l):l)*(e-t)+t)/i},utils.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],utils.setDateTime=(t,e)=>{e instanceof Date||(e=new Date(e)),t.value=new Date(e.getTime()-6e4*e.getTimezoneOffset()).toISOString().slice(0,"date"===t.type?10:19)},utils.getDateTime=t=>new Date(t.value+("date"===t.type?"T00:00":"")),utils.formatDate=(t,e={})=>{let i="",n,l;if(null==t||!t.getDate||!((n=t.getFullYear())>1969))return"[Invalid Date]";if(null==e.time||e.time){let s=t.getHours(),r="";if(e.h24||(r=" AM",s>=12&&(r=" PM",s-=12),s||(s=12)),i=s+":"+f(t.getMinutes())+(e.sec?":"+f(t.getSeconds())+(e.ms?(t.getMilliseconds()/1e3).toFixed(Number.isFinite(e.ms)?e.ms:3).slice(1):""):""),i+=r,e.time)return i}return l=t.getDate(),l=utils.months[t.getMonth()]+" "+(null==e.suf||e.suf?utils.suffix(l):l),(null==e.year||e.year)&&e.year!==n&&(l=l+", "+n),e.df?l+(i&&" "+i):(i&&i+" ")+l},utils.suffix=t=>{let e=t%10,i=t%100;return 1==e&&11!=i?t+"st":2==e&&12!=i?t+"nd":3==e&&13!=i?t+"rd":t+"th"};let c=e;function d(t){utils.onNav&&utils.onNav.call(null,t)}function h(t,e,i){let l=this.length,s=Math.max(e<0?l+e:e||0,0),r;for(null!=i&&(l=Math.min(i<0?l+i:i,l));s<l;++s)if("!"===(r=t(this[s],s,l)))this instanceof n?this[s].remove():this.splice(s,1),--s,--l;else if(null!=r)return r}async function _(t,e,i,l=!0){let s=this.length,r=e=Math.max(e<0?s+e:e||0,0),u,o=[];for(null!=i&&(s=Math.min(i<0?s+i:i,s));r<s;++r){if(u=t(this[r],r,s),!l&&"!"!==(u=await u)&&null!=u)return u;o.push(u)}for(l&&(o=await Promise.all(o)),r=e,u=0;r<s;++r,++u)if("!"===o[u])this instanceof n?this[r].remove():this.splice(r,1),--r,--s;else if(null!=o[u])return o[u]}utils.goBack=c.back.bind(c),utils.goForward=c.forward.bind(c),utils.go=(t,e)=>{c.pushState(e,"",t||location.pathname),d(e)},r("popstate",t=>d(t.state)),r("load",()=>setTimeout(d.wrap(c.state),1)),utils.mkEl=(t,e,i,n,l)=>{let s=document.createElement(t);if(null!=i&&(s.className=i),null!=l&&(s.innerHTML=l),n&&"object"==typeof n)for(let r in n)r in s.style?s.style[r]=n[r]:s.style.setProperty(r,n[r]);return null!=e&&e.appendChild(s),s},utils.mkDiv=(t,e,i,n)=>utils.mkEl("div",t,e,i,n),utils.addText=(t,e)=>t.appendChild(document.createTextNode(e)),utils.textWidth=(e,i)=>{let n=t.TWCanvas||(t.TWCanvas=utils.mkEl("canvas")),l=n.getContext("2d");return l.font=i,l.measureText(e).width},utils.define(utils,"w",()=>innerWidth),utils.define(utils,"h",()=>innerHeight),utils.setPropSafe=(t,e,i,n=!1)=>{"string"==typeof e&&(e=e.split("."));let l=e.length-1;return(e.each(e=>{t="object"==typeof t[e]?t[e]:t[e]={}},0,l),l=e[l],n&&null!=t[l])?t[l]:t[l]=i},utils.getPropSafe=(t,e)=>{"string"==typeof e&&(e=e.split("."));try{for(let i of e)t=t[i];return t}catch(n){}},utils.proto(Array,"clean",function(t){for(let e=0,i,n=this.length;e<n;++e)i=this[e],(utils.isBlank(i)||!1===i||!t&&0===i)&&(this.splice(e--,1),n--);return this}),utils.proto(Array,"remove",function(t){let e=this.indexOf(t);return -1!=e&&(this.splice(e,1),!0)}),[Array,n,s].forEach(t=>{utils.proto(t,"each",h),utils.proto(t,"eachAsync",_)});let $="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=$.replace("+/","-_"),g={43:62,47:63,48:52,49:53,50:54,51:55,52:56,53:57,54:58,55:59,56:60,57:61,65:0,66:1,67:2,68:3,69:4,70:5,71:6,72:7,73:8,74:9,75:10,76:11,77:12,78:13,79:14,80:15,81:16,82:17,83:18,84:19,85:20,86:21,87:22,88:23,89:24,90:25,97:26,98:27,99:28,100:29,101:30,102:31,103:32,104:33,105:34,106:35,107:36,108:37,109:38,110:39,111:40,112:41,113:42,114:43,115:44,116:45,117:46,118:47,119:48,120:49,121:50,122:51,45:62,95:63};function y(t,e){if(null==(t=g[t.charCodeAt(e)]))throw"Bad char at "+e;return t}"toBase64"in Uint8Array.prototype||utils.proto(Uint8Array,"toBase64",function(t){let e=this.byteLength,i=e%3,n=t&&"base64url"===t.alphabet?p:$,l=0,s="",r;for(e-=i;l<e;l+=3)s+=n[(16515072&(r=this[l]<<16|this[l+1]<<8|this[l+2]))>>18]+n[(258048&r)>>12]+n[(4032&r)>>6]+n[63&r];return 1==i?(s+=n[(252&(r=this[e]))>>2]+n[(3&r)<<4],t&&t.omitPadding||(s+="=")):2!=i||(s+=n[(64512&(r=this[e]<<8|this[e+1]))>>10]+n[(1008&r)>>4]+n[(15&r)<<2],t&&t.omitPadding||(s+="==")),s}),"fromBase64"in Uint8Array||utils.proto(Uint8Array,"fromBase64",t=>{let e=t.length,i=e-1;for(;i>=0&&61===t.charCodeAt(i);--i);e=i+1,i=0;let n=e%4;if(e-=n,1==n)throw"Bad b64 len";let l=new Uint8Array(3*e/4+(n?n-1:0)),s=-1,r;for(;i<e;i+=4)r=y(t,i)<<18|y(t,i+1)<<12|y(t,i+2)<<6|y(t,i+3),l[++s]=r>>16,l[++s]=r>>8,l[++s]=r;return 2==n?l[++s]=y(t,i)<<2|y(t,i+1)>>4:3==n&&(r=y(t,i)<<10|y(t,i+1)<<4|y(t,i+2)>>2,l[++s]=r>>8,l[++s]=r),l},1);let m=/[|\\{}()[\]^$+*?.]/g,x=/-/g;function b(t,e){for(;t>=e;)t-=e;return t}function O(){let t=document.styleSheets;for(let e=0,i=t.length;e<i;++e)try{return t[e].cssRules,t[e]}catch(n){}let l=utils.mkEl("style",document.head);return utils.addText(l,""),l.sheet}function v(t){return t.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}"escape"in RegExp||utils.proto(RegExp,"escape",t=>t.replace(m,"\\$&").replace(x,"\\x2d"),1),utils.define(l.prototype,"index",function(){let t=this.parentElement;return t?Array.prototype.indexOf.call(t.children,this):-1}),utils.proto(l,"insertChildAt",function(t,e){e<0&&(e=0),e>=this.children.length?this.appendChild(t):this.insertBefore(t,this.children[e])}),utils.boundingRect=t=>new UtilRect(t.getBoundingClientRect()),utils.innerRect=t=>{let e=t.getBoundingClientRect(),i=getComputedStyle(t);return new UtilRect(e.top+parseFloat(i.paddingTop)+parseFloat(i.borderTopWidth),e.bottom-parseFloat(i.paddingBottom)-parseFloat(i.borderBottomWidth),e.left+parseFloat(i.paddingLeft)+parseFloat(i.borderLeftWidth),e.right-parseFloat(i.paddingRight)-parseFloat(i.borderRightWidth))},utils.define(l.prototype,"boundingRect",function(){return utils.boundingRect(this)}),utils.define(l.prototype,"innerRect",function(){return utils.innerRect(this)}),utils.isBlank=t=>null==t||("string"==typeof t?!/\S/.test(t):"object"==typeof t&&("number"==typeof t.length?0===t.length:0===Object.keys(t).length)),utils.firstEmpty=t=>{let e=t.length;for(let i=0;i<e;++i)if(null==t[i])return i;return e},utils.firstEmptyChar=t=>{let e=Object.keys(t),i=e.length;for(let n=0;n<i;++n)if(null==t[e[n]])return e[n];return utils.numToChar(i)},utils.numToChar=t=>{if(t<=25)return String.fromCharCode(t+97);if(t>=26&&t<=51)return String.fromCharCode(t+39);let e,i;if(t<2756)e=b(Math.floor(t/52)-1,52),i=b(t,52);else if(t<143364)e=b(Math.floor((t-52)/2704)-1,52),i=b(t-52,2704)+52;else{if(!(t<7454980))return!1;e=b(Math.floor((t-2756)/140608)-1,52),i=b(t-2756,140608)+2756}return utils.numToChar(e)+utils.numToChar(i)},utils.merge=function(t){for(let e=1,i=arguments.length,n,l,s;e<i;++e)for(let r in n=arguments[e]){if(l=t[r],s=n[r],l&&s){if(l.length>=0&&s.length>=0){for(let u=0,o=s.length,a=l.length;u<o;++u)l[u+a]=s[u];continue}if("object"==typeof l&&"object"==typeof s){for(let f in s)l[f]=s[f];continue}}t[r]=s}return t},utils.cutStr=(t,e)=>{let i;for(;-1!=(i=t.indexOf(e));)t=t.slice(0,i)+t.slice(i+e.length);return t},utils.dCut=(t,e,i,n,l)=>{let s=t.indexOf(e,l||void 0)+e.length,r=t.indexOf(i,s);return n&&(n.s=s,n.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.dCutToLast=(t,e,i,n,l)=>{let s=t.indexOf(e,l||void 0)+e.length,r=t.lastIndexOf(i);return n&&(n.s=s,n.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.dCutLast=(t,e,i,n,l)=>{let s=t.lastIndexOf(e,l||void 0)+e.length,r=t.indexOf(i,s);return n&&(n.s=s,n.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.parseCSS=t=>{let e={},i="",n=0;function l(t){if(-1!==t.indexOf(",")){let e=utils.clean(t.split(","));for(let i=0,n=e.length;i<n;++i)e[i]=e[i].trim();return e}return t.trim()}for(t=t.trim();t.length>0;)if("("==t[0]&&-1!==t.indexOf(")")&&i){let s=t.indexOf(")"),r=t.slice(1,s);e[i]=l(r),i="",t=t.slice(s+1)}else if(0==t.search(/[#!\w]/)){i&&(e[n++]=i);let u=t.search(/[^#!\w-%]/);-1==u&&(u=t.length),i=t.slice(0,u),t=t.slice(u)}else t=t.slice(1);return i&&(e[n]=i),e},utils.buildCSS=t=>{let e=Object.keys(t),i=e.length,n="",l=0;for(;l<i;){let s=e[l],r=t[e[l]];++l,0<=Number(s)?n+=r+" ":n+=`${s}(${r}) `}return n.slice(0,-1)},utils.addClass=(t,e)=>{let i=O(),n=Object.keys(e),l="";for(let s=0,r=n.length;s<r;++s)l+=v(n[s])+":"+e[n[s]]+";";i.addRule("."+t,l)},utils.addId=(t,e)=>{let i=O(),n=Object.keys(e),l="";for(let s=0,r=n.length;s<r;++s)l+=v(n[s])+":"+e[n[s]]+";";i.addRule("#"+t,l)},utils.addKeyframe=(t,e)=>{O().addRule("@keyframes "+t,e)},utils.removeSelector=t=>{for(let e=0,i,n,l=document.styleSheets.length;e<l;++e){i=document.styleSheets[e];try{n=i.cssRules}catch(s){continue}for(let r in n)"CSSStyleRule"==n[r].constructor.name&&n[r].selectorText==t&&i.deleteRule(r)}},utils.fromQuery=t=>{function e(t,i){let n=i[0],l=n.indexOf("="),s=decodeURIComponent(n.slice(0,l)),r=decodeURIComponent(n.slice(l+1));return null==t[s]?t[s]=r:Array.isArray(t[s])?t[s].push(r):t[s]=[t[s],r],1===i.length?t:e(t,i.slice(1))}return t.startsWith("?")&&(t=t.slice(1)),t?e({},t.split("&")):{}},utils.toQuery=t=>{let e="",i,n;if("object"!=typeof t)return encodeURIComponent(t);for(i in t)"object"==typeof(n=t[i])&&null!=n&&(n=JSON.stringify(n)),e+="&"+i+"="+encodeURIComponent(n);return e.slice(1)},utils.center=(t,e,i)=>{let n=t.style;if("trans"==i){n.position||(n.position="absolute");let l=utils.cutStr(n.transform,"translateX(-50%)");l=utils.cutStr(l,"translateY(-50%)"),e&&"x"!=e||(n.left="50%",l+="translateX(-50%)"),e&&"y"!=e||(n.top="50%",l+="translateY(-50%)"),l&&(n.transform=l)}else{let s=utils.mkDiv(t.parentNode,null,{display:"flex",top:0,left:0});s.appendChild(t),s=s.style,e&&"x"!=e||(s.justifyContent="center",s.width="100%"),e&&"y"!=e||(s.alignItems="center",s.height="100%",s.position="absolute")}},utils.loadAjax=(t,e,i,n,l)=>{let s;try{s=new XMLHttpRequest}catch(r){return e(r)}if(l)for(let u in l)s.setRequestHeader(u,l[u]);s.open(i||"GET",t),s.onreadystatechange=()=>{let t=s.status||-1;s.readyState==s.DONE&&e(200==t?0:t,s.response,s)},s.send(n||void 0)},utils.loadFile=(t,e,i)=>{let n=utils.mkEl("object",document.body,null,{position:"fixed",opacity:0});n.data=t;let l=setTimeout(()=>{n.remove(),l=null,e(!1)},i||4e3);n.onload=()=>{l&&(clearTimeout(l),e(n.contentDocument.documentElement.outerHTML),n.remove())}},utils.loadJSONP=(t,e,i)=>{let n=utils.mkEl("script",document.head),l=utils.firstEmptyChar(utils.lJSONCall);n.type="application/javascript",n.src=t+(-1==t.indexOf("?")?"?":"&")+"callback=utils.lJSONCall."+l;let s=setTimeout(()=>{delete utils.lJSONCall[l],e(!1)},i||4e3);utils.lJSONCall[l]=t=>{s&&clearTimeout(s),delete utils.lJSONCall[l],e(t)},document.head.removeChild(n)},utils.lJSONCall=[],utils.dlFile=(t,e)=>fetch(e).then(t=>{if(200!=t.status)throw"Code "+t.status;return t.blob()}).then(e=>{utils.dlData(t,e)}),utils.dlData=(t,e)=>{let i,n=utils.mkEl("a",document.body,null,{display:"none"});"string"==typeof e?i=e:(e instanceof Blob||(e=Blob(e)),i=URL.createObjectURL(e)),n.href=i,n.download=t,n.click(),n.remove(),URL.revokeObjectURL(i)},utils.delay=t=>new Promise(e=>setTimeout(e,t)),UtilRect=function(t,e,n,l){if(!(this instanceof UtilRect))return new UtilRect(t,e,n,l);let s=Number.isFinite,r=0,u=0,o=0,a=0;utils.define(this,"x",()=>o,t=>{s(t)&&(a+=t-o,o=t)}),utils.define(this,"y",()=>r,t=>{s(t)&&(u+=t-r,r=t)}),utils.define(this,"top",()=>r,t=>{r=s(t)?t:0}),utils.define(this,["bottom","y2"],()=>u,t=>{u=s(t)?t:0}),utils.define(this,"left",()=>o,t=>{o=s(t)?t:0}),utils.define(this,["right","x2"],()=>a,t=>{a=s(t)?t:0}),utils.define(this,["width","w"],()=>a-o,t=>{a=t>=0?o+t:0}),utils.define(this,["height","h"],()=>u-r,t=>{u=t>=0?r+t:0}),utils.define(this,"centerX",()=>o/2+a/2),utils.define(this,"centerY",()=>r/2+u/2),t instanceof i||t instanceof UtilRect?(r=t.top,u=t.bottom,o=t.left,a=t.right):(r=t,u=e,o=n,a=l)},utils.proto(UtilRect,"contains",function(t,e){return t instanceof l?this.contains(t.boundingRect):t instanceof UtilRect?t.x>=this.x&&t.x2<=this.x2&&t.y>=this.y&&t.y2<=this.y2:t>=this.x&&t<=this.x2&&e>=this.y&&e<=this.y2}),utils.proto(UtilRect,"overlaps",function(t){if(t instanceof l)return this.overlaps(t.boundingRect);if(!(t instanceof UtilRect))return 0;let e,i;return e=t.x2-t.x>=this.x2-this.x?this.x>=t.x&&this.x<=t.x2||this.x2>=t.x&&this.x2<=t.x2:t.x>=this.x&&t.x<=this.x2||t.x2>=this.x&&t.x2<=this.x2,i=t.y2-t.y>=this.y2-this.y?this.y>=t.y&&this.y<=t.y2||this.y2>=t.y&&this.y2<=t.y2:t.y>=this.y&&t.y<=this.y2||t.y2>=this.y&&t.y2<=this.y2,e&&i}),utils.proto(UtilRect,"dist",function(t,e){if(t instanceof l)return this.dist(t.boundingRect);let i=t instanceof UtilRect;return e=Math.abs((i?t.centerY:e)-this.centerY),Math.sqrt((t=Math.abs((i?t.centerX:t)-this.centerX))*t+e*e)}),utils.proto(UtilRect,"expand",function(t){return this.top-=t,this.left-=t,this.bottom+=t,this.right+=t,this})})();const Easing={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>t*(2-t),easeInOutQuad:t=>t<.5?2*t*t:-1+(4-2*t)*t,easeInCubic:t=>t*t*t,easeOutCubic:t=>--t*t*t+1,easeInOutCubic:t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,easeInQuart:t=>t*t*t*t,easeOutQuart:t=>1- --t*t*t*t,easeInOutQuart:t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t,easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>1+--t*t*t*t*t,easeInOutQuint:t=>t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t};
|
package/uuid.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
//Chu ID v1.4, Pecacheu 2025. GNU GPL v3
|
|
2
|
-
|
|
3
|
-
import os from 'os';
|
|
4
|
-
import fs from 'fs/promises';
|
|
5
|
-
import crypto from 'crypto';
|
|
6
|
-
import {promisify} from 'util';
|
|
7
|
-
import 'raiutils';
|
|
8
|
-
|
|
9
|
-
const ID_FN = 'uuid', ID_DELAY = 10000;
|
|
10
|
-
let IDCount, UT;
|
|
11
|
-
|
|
12
|
-
let mdb;
|
|
13
|
-
try {mdb=await import('mongodb')} catch(e) {}
|
|
14
|
-
|
|
15
|
-
//64-bit UUID Format
|
|
16
|
-
//<U8 CPUUptime><U16 CryptoRand><U8 Counter><U32 Date>
|
|
17
|
-
|
|
18
|
-
class UUID {
|
|
19
|
-
constructor(id) {
|
|
20
|
-
if(id instanceof Buffer) {}
|
|
21
|
-
else if(typeof id=='string' && id.length==UUID.LEN) id=Buffer.from(id,'base64');
|
|
22
|
-
else if(mdb && id instanceof mdb.Long) id.unsigned=true, id=Buffer.from(id.toString(16),'hex');
|
|
23
|
-
else throw `Unknown UUID format ${id}`;
|
|
24
|
-
this.id=id;
|
|
25
|
-
}
|
|
26
|
-
toString(f) {return this.id.toString(f||'base64url')}
|
|
27
|
-
toHexLE() {return swapHex(this.id.toString('hex'))}
|
|
28
|
-
toLong() {return mdb.Long.fromString(this.id.toString('hex'),16)}
|
|
29
|
-
getMagic() {return this.id.readUInt8(1)}
|
|
30
|
-
getDate() {
|
|
31
|
-
let d=this.id.readUInt32LE(4)*10000;
|
|
32
|
-
return new Date(d<1621543800000?0:d);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
UUID.LEN = 11;
|
|
37
|
-
|
|
38
|
-
function swapHex(h) {return h.match(/.{2}/g).reverse().join('')}
|
|
39
|
-
|
|
40
|
-
async function loadId() {
|
|
41
|
-
try {IDCount = Number(await fs.readFile(ID_FN, {encoding:'utf8'}))} catch(e) {}
|
|
42
|
-
if(!(IDCount>=0 && IDCount<=255)) {
|
|
43
|
-
console.error("IDCount Error, resetting");
|
|
44
|
-
IDCount=0; await fs.writeFile(ID_FN, IDCount.toString());
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
UUID.randBytes = promisify(crypto.randomBytes);
|
|
49
|
-
|
|
50
|
-
UUID.genUUID = async (dateMs, magic) => {
|
|
51
|
-
if(IDCount==null) await loadId();
|
|
52
|
-
const rb=await UUID.randBytes(magic!=null?1:2),
|
|
53
|
-
u=Buffer.allocUnsafe(8);
|
|
54
|
-
u.writeUInt8((os.uptime()*10)&255);
|
|
55
|
-
if(magic != null) {
|
|
56
|
-
u.writeUInt8(magic&255,1);
|
|
57
|
-
u.writeUInt8(rb.readUInt8(),2);
|
|
58
|
-
} else u.writeUInt16LE(rb.readUInt16LE(),1);
|
|
59
|
-
u.writeUInt8(IDCount,3);
|
|
60
|
-
u.writeUInt32LE((dateMs||Date.now())/10000,4);
|
|
61
|
-
if(++IDCount > 255) IDCount=0;
|
|
62
|
-
if(UT) clearTimeout(UT);
|
|
63
|
-
UT = setTimeout(() => {
|
|
64
|
-
UT=0; fs.writeFile(ID_FN, IDCount.toString());
|
|
65
|
-
}, ID_DELAY);
|
|
66
|
-
return new UUID(u);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default UUID;
|