raiutils 8.7.7 → 8.7.9
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 +17 -8
- package/package.json +1 -1
- package/schema.js +72 -45
- package/utils.js +92 -86
- package/utils.min.js +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,6 @@ For client-side use, the minified *utils.min.js* is recommended (Minified with h
|
|
|
47
47
|
- `[Element].insertChildAt(el,i)` Inserts child at index. Appends child to end if index exceeds child count.
|
|
48
48
|
- `UtilRect [Element].boundingRect` Element's bounding rect as a `UtilRect` object.
|
|
49
49
|
- `UtilRect [Element].innerRect` Element's inner rect (excluding margin, padding, and border)
|
|
50
|
-
- `Math.cot(x) returns Number` No idea why this isn't built-in, but it's not.
|
|
51
50
|
- `[TouchList].get(id) returns Touch` Gets touch by id, returns null if none found.
|
|
52
51
|
- `[Uint8Array].toBase64([opts]) returns String` Polyfill; See MDN docs.
|
|
53
52
|
- `Uint8Array.fromBase64(str[, opts]) returns Uint8Array` Polyfill; See MDN docs.
|
|
@@ -69,9 +68,8 @@ For client-side use, the minified *utils.min.js* is recommended (Minified with h
|
|
|
69
68
|
- `utils.setDateTime(el, date)` Set 'datetime-local' or 'date' input from JS Date, adjusting for local timezone.
|
|
70
69
|
- `utils.getDateTime(el) returns Date` Get value of 'datetime-local' or 'date' input as JS Date.
|
|
71
70
|
- `utils.formatDate(date[,opts]) returns String` Format Date object into a pretty string, with various options.
|
|
72
|
-
- `utils.months` Array of
|
|
71
|
+
- `utils.months` Array of 3-letter month names from Jan to Dec.
|
|
73
72
|
- `utils.suffix(n) returns String` Add appropriate suffix to number. (ex. 31st, 12th, 22nd)
|
|
74
|
-
- `utils.fixedNum(n,len[,radix=10]) returns String` Fix number to a given minimum length with padded 0's. Adds '0b' for binary *(radix=2)* and '0x' for hex *(radix=16)*
|
|
75
73
|
- `utils.goBack()` For AJAX navigation. Presses back button.
|
|
76
74
|
- `utils.goForward()` For AJAX navigation. Presses forward button.
|
|
77
75
|
- `utils.go(url, data)` Push new history state for AJAX navigation. You can provide additional data to access later.
|
|
@@ -87,8 +85,6 @@ For client-side use, the minified *utils.min.js* is recommended (Minified with h
|
|
|
87
85
|
- `utils.firstEmptyChar(obj) returns String` Like *firstEmpty*, but uses letters from `utils.numToChar` instead.
|
|
88
86
|
- `utils.numToChar(n) returns String` Converts a number into letters (upper and lower) from a to Z.
|
|
89
87
|
- `utils.merge(target,source[,source2...]) returns target` Merges two (or more) objects, giving the last precedence. If both objects contain a property at the same index, and both are Arrays/Objects, they are merged.
|
|
90
|
-
- `utils.bounds(n,min=0,max=1) returns Number` Keeps value within max/min bounds. Also handles NaN or null.
|
|
91
|
-
- `utils.norm` *OR* `utils.normalize(n,min=0,max=1) returns Number` 'Normalizes' a value so that it ranges from min to max, but unlike `utils.bounds`, this function retains input's offset. This can be used to normalize angles.
|
|
92
88
|
- `utils.cutStr(s,rem) returns String` Finds and removes all instances of 'rem' contained within String 's'
|
|
93
89
|
- `utils.dCut(data,startString,endString[,index[,searchStart]]) returns String` Cuts text out of 'data' from first instance of 'startString' to next instance of 'endString'.
|
|
94
90
|
- `utils.dCutToLast(data,startString,endString[,index[,searchStart]]) returns String` Same as *utils.dCut* but using lastIndexOf for end search.
|
|
@@ -99,8 +95,6 @@ For client-side use, the minified *utils.min.js* is recommended (Minified with h
|
|
|
99
95
|
- `utils.addId(id,propList)` Create a css selector and append it to the current document.
|
|
100
96
|
- `utils.addKeyframe(name,content)` Create a css keyframe and append it to the current document.
|
|
101
97
|
- `utils.removeSelector(name)` Remove a specific css selector (including the '.' or '#') from all stylesheets in the current document.
|
|
102
|
-
- `utils.hexToRgb(hex) returns Number` Converts HEX color to 24-bit RGB.
|
|
103
|
-
- `utils.rand(min,max[,res[,ease]]) returns Number` Generates random from min to max, optionally with a decimal resolution (10, 100, 1000, etc.) or custom ease, changing the probability of various numbers being generated.
|
|
104
98
|
- `utils.fromQuery(str) returns Object` Parses a url query string into an Object.
|
|
105
99
|
- `utils.toQuery(obj) returns String` Converts an object into a url query string.
|
|
106
100
|
- `utils.center(obj[,only[,type]])` Center objects with JavaScript, using a variety of methods. *See utils.js for details.*
|
|
@@ -109,6 +103,21 @@ For client-side use, the minified *utils.min.js* is recommended (Minified with h
|
|
|
109
103
|
- `utils.loadFile(path,callback,timeout)` Good fallback for `utils.loadAjax`. Loads a file at the address via HTML object tag. Callback is fired with either received data, or **false** if unsuccessful.
|
|
110
104
|
- `utils.dlFile(filename,uri) returns Promise` Downloads a file from a link.
|
|
111
105
|
- `utils.dlData(filename,data)` Downloads a file generated from a Blob or ArrayBuffer.
|
|
106
|
+
|
|
107
|
+
- `utils.delay(ms) returns Promise` setTimeout but async.
|
|
108
|
+
|
|
109
|
+
## Math & Numbers
|
|
110
|
+
Math operations that work with both `Number` and `BigInt`.
|
|
111
|
+
|
|
112
|
+
- `utils.abs(x)` / `utils.min(x)` / `utils.max(x)` Work like their **Math** equivalents.
|
|
113
|
+
- `utils.fixedNum(n,len[,radix=10]) returns String` Fix number to a given minimum length with padded 0's. Adds '0b' for binary *(radix=2)* and '0x' for hex *(radix=16)*
|
|
114
|
+
- `utils.bounds(n,min=0,max=1) returns Number` Truncate n to range [min,max]. Also handles NaN or null.
|
|
115
|
+
- `utils.norm` *OR* `utils.normalize(n,min=0,max=1) returns Number` Normalize n to the range [min,max). This can be used to normalize angles.
|
|
116
|
+
|
|
117
|
+
### Number Only
|
|
118
|
+
- `Math.cot(x) returns Number` No idea why this isn't built-in, but it's not.
|
|
112
119
|
- `utils.rad(deg)` / `utils.deg(rad)` Convert between radians and degrees.
|
|
113
120
|
- `utils.map(input,minIn,maxIn,minOut,maxOut,ease) returns Number` For unit translation and JS animation! See ease functions in *untils.js*.
|
|
114
|
-
- `utils.
|
|
121
|
+
- `utils.hexToRgb(hex) returns Number` Converts HEX color to 24-bit RGB.
|
|
122
|
+
- `utils.rgbToHsl(r,g,b) returns [Number, Number, Number]` Converts R,G,B to H,S,L values.
|
|
123
|
+
- `utils.rand(min,max[,res[,ease]]) returns Number` Generates random from min to max, optionally with a decimal resolution (10, 100, 1000, etc.) or custom ease, changing the probability of various numbers being generated
|
package/package.json
CHANGED
package/schema.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
//ChuSchema v1.
|
|
1
|
+
//ChuSchema v1.3, Pecacheu 2025. GNU GPL v3
|
|
2
|
+
|
|
3
|
+
class SubError extends Error {}
|
|
2
4
|
|
|
3
5
|
function errAt(k,e,l) {
|
|
4
|
-
let es=e.message||e;
|
|
5
|
-
k=(l?`[${k}]`:k)+(
|
|
6
|
-
if(
|
|
6
|
+
let s=e instanceof SubError, es=e.message||e;
|
|
7
|
+
k=(l?`[${k}]`:k)+(s ? es.startsWith('[')?'':'.' : ': ');
|
|
8
|
+
if(s) e.message=k+es;
|
|
9
|
+
else e=new SubError(k+es, e instanceof Error?{cause:e}:null);
|
|
7
10
|
return e;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
function
|
|
13
|
+
function isDictOrArr(d) {return typeof d==='object' && d!==null}
|
|
14
|
+
function isDict(d) {return isDictOrArr(d) && !Array.isArray(d)}
|
|
11
15
|
function oobStr(s) {return ` out-of-bounds (${s.min==null?'*':s.min}-${s.max==null?'*':s.max})`}
|
|
16
|
+
function dictFmt(s) {
|
|
17
|
+
if(typeof s.c==='string') s.c={t:s.c};
|
|
18
|
+
let dt=isDictOrArr(s.f)?2:isDictOrArr(s.c)?1:0;
|
|
19
|
+
if(!dt) throw "Schema lacks format or childType";
|
|
20
|
+
if(dt===2 && s.c) throw "Cannot require both format and childType";
|
|
21
|
+
return dt===2;
|
|
22
|
+
}
|
|
23
|
+
function tryAll(a,fn) {
|
|
24
|
+
if(Array.isArray(a)) {
|
|
25
|
+
let el=[];
|
|
26
|
+
a.forEach(s => {try {fn(s)} catch(e) {el.push(e)}});
|
|
27
|
+
if(el.length >= a.length) throw "[Failed all cases] "+el.map(e => e.message||e).join(', ');
|
|
28
|
+
} else fn(a);
|
|
29
|
+
}
|
|
30
|
+
|
|
12
31
|
function checkType(d,sr) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
tl.forEach((t,i) => {
|
|
32
|
+
let tt,el,sl,s,l,k,n,ds,dt,
|
|
33
|
+
run=(t,i) => {
|
|
16
34
|
//Get prop cache
|
|
17
|
-
if(!(s=
|
|
18
|
-
s=
|
|
19
|
-
for(k in
|
|
35
|
+
if(!(s=sl[k='$'+i])) {
|
|
36
|
+
s=sl[k]={};
|
|
37
|
+
for(k in sl) s[k]=Array.isArray(sl[k])?sl[k][i]:sl[k];
|
|
20
38
|
}
|
|
21
39
|
//Check type
|
|
22
40
|
try {switch(t) {
|
|
@@ -26,9 +44,10 @@ function checkType(d,sr) {
|
|
|
26
44
|
if(l<s.min || l>s.max) throw "Str len "+l+oobStr(s);
|
|
27
45
|
if(s.len!=null && l!==s.len) throw "Str len must be "+s.len;
|
|
28
46
|
if(typeof s.f==='string') s.f=new RegExp(`^(?:${s.f})$`);
|
|
29
|
-
if(s.f instanceof RegExp && !s.f.test(d)) throw `Str '${d}' does not match format`;
|
|
47
|
+
if(s.f instanceof RegExp && !s.f.test(d)) throw `Str '${d}' does not match format ${s.f}`;
|
|
30
48
|
break; case 'int': case 'float':
|
|
31
49
|
if(typeof d!=='number' || !(t==='int'?Number.isSafeInteger(d):Number.isFinite(d))) throw -1;
|
|
50
|
+
if(s.val!=null && d!==s.val) throw "Num != "+s.val;
|
|
32
51
|
if(d<s.min || d>s.max) throw "Num "+d+oobStr(s);
|
|
33
52
|
break; case 'bool':
|
|
34
53
|
if(typeof d!=='boolean') throw -1;
|
|
@@ -37,56 +56,64 @@ function checkType(d,sr) {
|
|
|
37
56
|
l=d.length; if(!l && s.min!==0) throw "Empty list";
|
|
38
57
|
if(s.len!=null && l!==s.len) throw "Array size must be "+s.len;
|
|
39
58
|
if(l<s.min || l>s.max) throw "Array size "+l+oobStr(s);
|
|
40
|
-
|
|
41
|
-
n
|
|
42
|
-
if(!dt) throw "List schema lacks format or childType";
|
|
43
|
-
if(dt===2 && s.c) throw "Cannot require both format and childType";
|
|
44
|
-
for(; n<l; ++n) try {dt===2?checkSchema(d[n],s.f):checkType(d[n],s.c)}
|
|
59
|
+
n=0, ds=tt.length>1?s:sl, dt=dictFmt(ds);
|
|
60
|
+
for(; n<l; ++n) try {dt?checkSchema(d[n],ds.f):checkType(d[n],ds.c)}
|
|
45
61
|
catch(e) {throw errAt(n,e,1)}
|
|
46
62
|
break; case 'dict':
|
|
47
63
|
if(!isDict(d)) throw -1;
|
|
48
|
-
k=Object.keys(d)
|
|
49
|
-
if(s.
|
|
50
|
-
if(typeof s.c==='string') s.c={t:s.c};
|
|
64
|
+
k=Object.keys(d);
|
|
65
|
+
if(!k.length && s.min!==0) throw "Empty dict";
|
|
51
66
|
if(typeof s.kf==='string') s.kf=new RegExp(`^(?:${s.kf})$`);
|
|
67
|
+
ds=tt.length>1?s:sl, dt=dictFmt(ds);
|
|
52
68
|
for(n of k) try {
|
|
53
69
|
if(n.startsWith('$')) throw "Key cannot start with $";
|
|
54
|
-
if(s.kf instanceof RegExp && !s.kf.test(n)) throw `Key '${n}' does not match format`;
|
|
55
|
-
checkType(d[n],
|
|
70
|
+
if(s.kf instanceof RegExp && !s.kf.test(n)) throw `Key '${n}' does not match format ${s.kf}`;
|
|
71
|
+
dt?checkSchema(d[n],ds.f):checkType(d[n],ds.c);
|
|
56
72
|
} catch(e) {throw errAt(n,e,1)}
|
|
57
73
|
break; default:
|
|
58
74
|
throw `Unknown type ${s.t} in schema`;
|
|
59
75
|
}} catch(e) {el.push(e)}
|
|
60
|
-
});
|
|
61
|
-
if(el.length >= tl.length) {
|
|
62
|
-
let e,m="Must be of type "+sr.t;
|
|
63
|
-
for(e of el) if(e!==-1) m=e;
|
|
64
|
-
throw m;
|
|
65
76
|
}
|
|
77
|
+
tryAll(sr, s => {
|
|
78
|
+
if(typeof s.t!=='string') throw "Missing type";
|
|
79
|
+
sl=s, el=[], tt=s.t.split('|'), tt.forEach(run);
|
|
80
|
+
if(el.length >= tt.length) {
|
|
81
|
+
let e,m;
|
|
82
|
+
for(e of el) if(e!==-1) m=e;
|
|
83
|
+
if(!m) m="Must be of type "+sr.t;
|
|
84
|
+
throw m;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
66
87
|
}
|
|
67
88
|
|
|
68
89
|
const R_FN=/\W+|(\w+)/g;
|
|
69
90
|
|
|
70
91
|
function checkSchema(data, schema, ignoreReq) {
|
|
71
92
|
if(!isDict(data)) throw "Data must be dict";
|
|
72
|
-
if(!
|
|
93
|
+
if(!isDictOrArr(schema)) throw "Schema must be dict|list[dict]";
|
|
73
94
|
let k,d,s,r,n,m;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
tryAll(schema, sch => {
|
|
96
|
+
for(k in data) try {
|
|
97
|
+
d=data[k], s=sch[k];
|
|
98
|
+
if(!s) throw "Not in schema";
|
|
99
|
+
if(k.startsWith('$')) throw "Key cannot start with $";
|
|
100
|
+
checkType(d,s);
|
|
101
|
+
} catch(e) {throw errAt(k,e)}
|
|
102
|
+
if(ignoreReq) return;
|
|
103
|
+
//Check missing
|
|
104
|
+
for(k in sch) if((s=sch[k]).req != null) {
|
|
105
|
+
d=s.req, r=typeof d==='string';
|
|
106
|
+
if(r) { //Conditional req
|
|
107
|
+
n='';
|
|
108
|
+
while(m=R_FN.exec(d)) n+=m[1] ? m[1] in data : m[0];
|
|
109
|
+
d=eval(n);
|
|
110
|
+
}
|
|
111
|
+
if(d) {
|
|
112
|
+
n=k in data;
|
|
113
|
+
if(d===-1 ? n : !n) throw k+": Required"+(r?" if "+s.req:'');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
90
117
|
}
|
|
91
118
|
|
|
92
119
|
function isNumArr(a) {
|
|
@@ -115,4 +142,4 @@ function prettyJSON(val, d=0) {
|
|
|
115
142
|
} else throw "Unknown type "+t;
|
|
116
143
|
}
|
|
117
144
|
|
|
118
|
-
export default {checkSchema, prettyJSON, errAt};
|
|
145
|
+
export default {checkSchema, checkType, prettyJSON, errAt};
|
package/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//https://github.com/Pecacheu/Utils.js; GNU GPL v3
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
|
-
const utils = {VER:'v8.7.
|
|
4
|
+
const utils = {VER:'v8.7.9'},
|
|
5
5
|
_uNJS = typeof global!='undefined';
|
|
6
6
|
|
|
7
7
|
//Node.js compat
|
|
@@ -119,6 +119,8 @@ if(window.TouchList) utils.proto(TouchList, 'get', function(id) {
|
|
|
119
119
|
for(let k in this) if(this[k].identifier == id) return this[k]; return 0;
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
+
const R_NFZ=/\.0*$/;
|
|
123
|
+
|
|
122
124
|
/*Turns your boring <input> into a mobile-friendly number entry field with max/min & negative support!
|
|
123
125
|
min: Min value, default min safe int
|
|
124
126
|
max: Max value, default max safe int
|
|
@@ -133,56 +135,60 @@ utils.numField=(f, min, max, decMax, sym) => {
|
|
|
133
135
|
const RM=RegExp(`[,${sym?RegExp.escape(sym):''}]`,'g');
|
|
134
136
|
f.type=(utils.mobile||decMax||sym)?'tel':'number';
|
|
135
137
|
f.setAttribute('pattern',"\\d*");
|
|
136
|
-
if(min==null) min=Number.MIN_SAFE_INTEGER;
|
|
137
|
-
if(max==null) max=Number.MAX_SAFE_INTEGER;
|
|
138
|
-
if(decMax==null) decMax=sym?2:0;
|
|
139
138
|
if(!f.step) f.step=1;
|
|
140
|
-
f.num=Math.max(0,min), f.ns='';
|
|
141
|
-
f.value=sym?utils.formatCost(f.num,sym):f.num.toString();
|
|
142
139
|
f.addEventListener('keydown',e => {
|
|
143
140
|
if(e.ctrlKey) return;
|
|
144
|
-
let k=e.key, kn=k.length
|
|
141
|
+
let k=e.key, kn=k.length===1&&Number.isFinite(Number(k)),
|
|
145
142
|
ns=f.ns, len=ns.length, dec=ns.indexOf('.');
|
|
146
143
|
|
|
147
|
-
if(k
|
|
148
|
-
else if(kn) {if(dec
|
|
149
|
-
else if(k
|
|
144
|
+
if(k==='Tab' || k==='Enter') return;
|
|
145
|
+
else if(kn) {if(dec===-1 || len-dec < decMax+1) ns+=k} //Number
|
|
146
|
+
else if(k==='.' || k==='*') {if(decMax && dec==-1
|
|
150
147
|
&& f.num!=max && (min>=0 || f.num!=min)) { //Decimal
|
|
151
148
|
if(!len && min>0) ns=Math.floor(min)+'.';
|
|
152
149
|
else ns+='.';
|
|
153
|
-
}} else if(k
|
|
154
|
-
if(min>0 && f.num
|
|
150
|
+
}} else if(k==='Backspace' || k==='Delete') { //Backspace
|
|
151
|
+
if(min>0 && f.num===min && ns.endsWith('.')) ns='';
|
|
155
152
|
else ns=ns.slice(0,-1);
|
|
156
|
-
} else if(k
|
|
157
|
-
else if(k
|
|
158
|
-
else if(k
|
|
153
|
+
} else if(k==='-' || k==='#') {if(min<0 && !len) ns='-'} //Negative
|
|
154
|
+
else if(k==='ArrowUp') ns=null, f.set(f.num+Number(f.step)); //Up
|
|
155
|
+
else if(k==='ArrowDown') ns=null, f.set(f.num-Number(f.step)); //Down
|
|
159
156
|
|
|
160
157
|
if(ns !== null && ns !== f.ns) {
|
|
161
|
-
|
|
158
|
+
len=ns.length, dec=ns.indexOf('.');
|
|
159
|
+
let neg=ns==='-'||ns==='-.', s=neg?'0':ns+(ns.endsWith('.')?'0':''),
|
|
162
160
|
nr=Number(s), n=Math.min(max,Math.max(min,nr));
|
|
163
|
-
if(!kn || f.num !== n ||
|
|
161
|
+
if(!kn || !ns || f.num !== n || (dec!==-1 && len-dec < decMax+1)) {
|
|
164
162
|
f.ns=ns, f.num=n;
|
|
165
|
-
f.value = sym ?
|
|
166
|
-
(
|
|
163
|
+
f.value = sym ? neg?sym+'-0.00':utils.formatCost(n,sym):
|
|
164
|
+
(ns[0]==='-'?'-':'')+Math.floor(Math.abs(n))
|
|
165
|
+
+(dec!==-1?ns.slice(dec)+(R_NFZ.test(ns)?'0':''):'');
|
|
167
166
|
if(f.onnuminput) f.onnuminput.call(f);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
e.preventDefault();
|
|
171
170
|
});
|
|
172
|
-
|
|
173
|
-
if(typeof n
|
|
171
|
+
function numRng(n) {
|
|
172
|
+
if(typeof n==='string') n=n.replace(RM,'');
|
|
174
173
|
n=Math.min(max,Math.max(min,Number(n)||0));
|
|
175
|
-
|
|
174
|
+
return decMax?Number(n.toFixed(decMax)):Math.round(n);
|
|
175
|
+
}
|
|
176
|
+
f.set=n => {
|
|
177
|
+
f.num = numRng(n);
|
|
176
178
|
f.ns = f.num.toString();
|
|
177
179
|
f.value = sym?utils.formatCost(f.num,sym):f.ns;
|
|
178
180
|
f.ns=f.ns.replace(/^(-?)0+/,'$1');
|
|
179
181
|
if(f.onnuminput) f.onnuminput.call(f);
|
|
180
182
|
}
|
|
181
183
|
f.setRange=(nMin, nMax, nDecMax) => {
|
|
182
|
-
min=nMin
|
|
184
|
+
min=nMin==null ? Number.MIN_SAFE_INTEGER : nMin;
|
|
185
|
+
max=nMax==null ? Number.MAX_SAFE_INTEGER : nMax;
|
|
186
|
+
decMax=nDecMax==null ? sym?2:0 : nDecMax;
|
|
187
|
+
if(numRng(f.num) !== f.num) f.set(f.num);
|
|
183
188
|
}
|
|
184
189
|
f.addEventListener('input',() => f.set(f.value));
|
|
185
190
|
f.addEventListener('paste',e => {f.set(e.clipboardData.getData('text')); e.preventDefault()});
|
|
191
|
+
f.setRange(min, max, decMax);
|
|
186
192
|
return f;
|
|
187
193
|
}
|
|
188
194
|
|
|
@@ -220,13 +226,73 @@ utils.formatCost = (n, sym='$') => {
|
|
|
220
226
|
n=='-'?n+a:n+(i&&!(i%3)?',':'')+a,'')+'.'+p[1];
|
|
221
227
|
}
|
|
222
228
|
|
|
229
|
+
//======== Number Methods ========
|
|
230
|
+
|
|
231
|
+
//JS Math w/ BigInt support
|
|
232
|
+
const BI=typeof BigInt==='undefined'?n=>n:BigInt, B0=BI(0);
|
|
233
|
+
utils.abs=x => typeof x==='bigint'?(x<B0?-x:x):Math.abs(x);
|
|
234
|
+
utils.min=function() {let v,m; for(v of arguments) v>m||(m=v); return m}
|
|
235
|
+
utils.max=function() {let v,m; for(v of arguments) v<m||(m=v); return m}
|
|
236
|
+
|
|
237
|
+
//Degrees <-> Radians
|
|
238
|
+
utils.deg = rad => rad*180/Math.PI;
|
|
239
|
+
utils.rad = deg => deg*Math.PI/180;
|
|
240
|
+
Math.cot = x => 1/Math.tan(x);
|
|
241
|
+
|
|
223
242
|
//Convert Number to fixed-length
|
|
224
|
-
//Set radix to 16 for HEX
|
|
225
|
-
utils.fixedNum =
|
|
226
|
-
|
|
243
|
+
//Set radix to 16 for HEX or 2 for Binary
|
|
244
|
+
utils.fixedNum = (n,len,radix=10) => {
|
|
245
|
+
if(typeof len==='bigint') len=Number(len);
|
|
246
|
+
let s=utils.abs(n).toString(radix).toUpperCase();
|
|
227
247
|
return (n<0?'-':'')+(radix==16?'0x':radix==2?'0b':'')+'0'.repeat(Math.max(len-s.length,0))+s;
|
|
228
248
|
}
|
|
229
249
|
|
|
250
|
+
//Truncate n to range [min,max]. Also handles NaN or null
|
|
251
|
+
utils.bounds = (n, min=0, max=1) => n>=min?n<=max?n:max:min;
|
|
252
|
+
|
|
253
|
+
//Normalize n to the range [min,max), keeping offset
|
|
254
|
+
//Behaves similar to modulus operator, but min doesn't have to be 0
|
|
255
|
+
utils.norm = utils.normalize = (n, min=0, max=1) => {
|
|
256
|
+
let r=max-min;
|
|
257
|
+
return ((n+utils.abs(min))%r+r)%r+min;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//Pecacheu's ultimate unit translation formula!
|
|
261
|
+
//This Version -- Bounds Checking: NO, Rounding: NO, Max/Min Switching: NO, Easing: YES
|
|
262
|
+
utils.map = (input, minIn, maxIn, minOut, maxOut, ease) => {
|
|
263
|
+
let i=(input-minIn)/(maxIn-minIn); return ((ease?ease(i):i)*(maxOut-minOut))+minOut;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
//Converts HEX color to 24-bit RGB
|
|
267
|
+
utils.hexToRgb = hex => {
|
|
268
|
+
const c = parseInt(hex.slice(1),16);
|
|
269
|
+
return [(c >> 16) & 255, (c >> 8) & 255, c & 255];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
//By mjackson @ GitHub
|
|
273
|
+
utils.rgbToHsl = (r,g,b) => {
|
|
274
|
+
r /= 255, g /= 255, b /= 255;
|
|
275
|
+
let max=Math.max(r,g,b), min=Math.min(r,g,b), h,s,l=(max+min)/2;
|
|
276
|
+
if(max===min) h=s=0; //Achromatic
|
|
277
|
+
else {
|
|
278
|
+
let d=max-min;
|
|
279
|
+
s=l>.5 ? d/(2-max-min) : d/(max+min);
|
|
280
|
+
switch(max) {
|
|
281
|
+
case r: h=(g-b)/d + (g<b?6:0); break;
|
|
282
|
+
case g: h=(b-r)/d + 2; break;
|
|
283
|
+
case b: h=(r-g)/d + 4;
|
|
284
|
+
}
|
|
285
|
+
h /= 6;
|
|
286
|
+
}
|
|
287
|
+
return [h*360, s*100, l*100];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//Generates random integer from min to max
|
|
291
|
+
utils.rand = (min, max, res, ease) => {
|
|
292
|
+
res=res||1; max*=res,min*=res; let r=Math.random();
|
|
293
|
+
return Math.round((ease?ease(r):r)*(max-min)+min)/res;
|
|
294
|
+
}
|
|
295
|
+
|
|
230
296
|
utils.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
231
297
|
function fixed2(n) {return n<=9?'0'+n:n}
|
|
232
298
|
|
|
@@ -455,9 +521,6 @@ utils.innerRect=e => {
|
|
|
455
521
|
utils.define(Element.prototype,'boundingRect',function() {return utils.boundingRect(this)});
|
|
456
522
|
utils.define(Element.prototype,'innerRect',function() {return utils.innerRect(this)});
|
|
457
523
|
|
|
458
|
-
//No idea why this isn't built-in, but it's not
|
|
459
|
-
Math.cot = x => 1/Math.tan(x);
|
|
460
|
-
|
|
461
524
|
//Check if string, array, or other object is empty
|
|
462
525
|
utils.isBlank = s => {
|
|
463
526
|
if(s == null) return true;
|
|
@@ -516,19 +579,6 @@ utils.merge = function(o/*, src1, src2...*/) {
|
|
|
516
579
|
return o;
|
|
517
580
|
}
|
|
518
581
|
|
|
519
|
-
//Keeps value within max/min bounds. Also handles NaN or null
|
|
520
|
-
utils.bounds = (n, min=0, max=1) => {
|
|
521
|
-
if(!(n>=min)) return min; if(!(n<=max)) return max; return n;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
//'Normalizes' a value so that it ranges from min to max, but unlike utils.bounds,
|
|
525
|
-
//this function retains input's offset. This can be used to normalize angles
|
|
526
|
-
utils.norm = utils.normalize = (n, min=0, max=1) => {
|
|
527
|
-
const c = Math.abs(max-min);
|
|
528
|
-
if(n < min) while(n < min) n += c; else while(n >= max) n -= c;
|
|
529
|
-
return n;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
582
|
//Finds and removes all instances of 'rem' contained within s
|
|
533
583
|
utils.cutStr = (s, rem) => {
|
|
534
584
|
let fnd; while((fnd=s.indexOf(rem)) != -1) {
|
|
@@ -627,36 +677,6 @@ utils.removeSelector = name => {
|
|
|
627
677
|
}
|
|
628
678
|
}
|
|
629
679
|
|
|
630
|
-
//Converts HEX color to 24-bit RGB
|
|
631
|
-
utils.hexToRgb = hex => {
|
|
632
|
-
const c = parseInt(hex.slice(1),16);
|
|
633
|
-
return [(c >> 16) & 255, (c >> 8) & 255, c & 255];
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
//By mjackson @ GitHub
|
|
637
|
-
utils.rgbToHsl = (r,g,b) => {
|
|
638
|
-
r /= 255, g /= 255, b /= 255;
|
|
639
|
-
let max=Math.max(r,g,b), min=Math.min(r,g,b), h,s,l=(max+min)/2;
|
|
640
|
-
if(max===min) h=s=0; //Achromatic
|
|
641
|
-
else {
|
|
642
|
-
let d=max-min;
|
|
643
|
-
s=l>.5 ? d/(2-max-min) : d/(max+min);
|
|
644
|
-
switch(max) {
|
|
645
|
-
case r: h=(g-b)/d + (g<b?6:0); break;
|
|
646
|
-
case g: h=(b-r)/d + 2; break;
|
|
647
|
-
case b: h=(r-g)/d + 4;
|
|
648
|
-
}
|
|
649
|
-
h /= 6;
|
|
650
|
-
}
|
|
651
|
-
return [h*360, s*100, l*100];
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
//Generates random integer from min to max
|
|
655
|
-
utils.rand = (min, max, res, ease) => {
|
|
656
|
-
res=res||1; max*=res,min*=res; let r=Math.random();
|
|
657
|
-
return Math.round((ease?ease(r):r)*(max-min)+min)/res;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
680
|
//Parses a url query string into an Object
|
|
661
681
|
utils.fromQuery = str => {
|
|
662
682
|
if(str.startsWith('?')) str=str.slice(1);
|
|
@@ -767,20 +787,6 @@ utils.dlData = (fn,d) => {
|
|
|
767
787
|
e.href=o,e.download=fn; e.click(); e.remove(); URL.revokeObjectURL(o);
|
|
768
788
|
}
|
|
769
789
|
|
|
770
|
-
//Converts from radians to degrees, so you can work in degrees
|
|
771
|
-
//Function by: The a**hole who invented radians
|
|
772
|
-
utils.deg = rad => rad*180/Math.PI;
|
|
773
|
-
|
|
774
|
-
//Converts from degrees to radians, so you can convert back for given stupid library
|
|
775
|
-
//Function by: The a**hole who invented radians
|
|
776
|
-
utils.rad = deg => deg*Math.PI/180;
|
|
777
|
-
|
|
778
|
-
//Pecacheu's ultimate unit translation formula!
|
|
779
|
-
//This Version -- Bounds Checking: NO, Rounding: NO, Max/Min Switching: NO, Easing: YES
|
|
780
|
-
utils.map = (input, minIn, maxIn, minOut, maxOut, ease) => {
|
|
781
|
-
let i=(input-minIn)/(maxIn-minIn); return ((ease?ease(i):i)*(maxOut-minOut))+minOut;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
790
|
//setTimeout but async
|
|
785
791
|
utils.delay = ms => new Promise(r => setTimeout(r,ms));
|
|
786
792
|
|
package/utils.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
//https://github.com/Pecacheu/Utils.js GNU GPL v3
|
|
2
|
-
"use strict";const utils={VER:"v8.7.7"},_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,l,n,s,r]=P;function u(t){return t<=9?"0"+t:t}utils.define=(t,e,i,l)=>{let n={};if(i&&(n.get=i),l&&(n.set=l),Array.isArray(e))for(let s of e)Object.defineProperty(t,s,n);else Object.defineProperty(t,e,n)},utils.proto=(t,e,i,l)=>{let n={value:i};if(l||(t=t.prototype),Array.isArray(e))for(let s of e)Object.defineProperty(t,s,n);else Object.defineProperty(t,e,n)},utils.setCookie=(t,e,i,l)=>{let n=`${encodeURIComponent(t)}=${null==e?"":encodeURIComponent(e)};path=/`;if(null!=i&&(-1===i&&(i=new Date(Number.MAX_SAFE_INTEGER/10)),i instanceof Date?n+=";expires="+i.toUTCString():n+=";max-age="+i),l&&(n+=";secure"),_uNJS)return n;document.cookie=n},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,l,n={};for(i of e)l=i.indexOf("="),n[decodeURIComponent(i.slice(0,l))]=decodeURIComponent(i.slice(l+1));return n},utils.getCookie=(t,e)=>{null==e&&(e=document.cookie),t=encodeURIComponent(t)+"=";let i=e.split("; "),l;for(l of i)if(l.startsWith(t))return decodeURIComponent(l.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,l)=>{i[l]=utils.copy(t,e)});else for(let l in i={},t)i[l]=utils.copy(t[l],e);return i},utils.deviceInfo=t=>{let e={};if(t||(t=navigator.userAgent),!t.startsWith("Mozilla/5.0 "))return e;let i=t.indexOf(")"),l=e.rawOS=t.slice(13,i),n,s;return l.startsWith("Windows")?(n=l.split("; "),e.os="Windows",e.type=-1!=n.indexOf("WOW64")?"x64 PC; x86 Browser":-1!=n.indexOf("x64")?"x64 PC":"x86 PC",n=l.indexOf("Windows NT "),e.version=l.slice(n+11,l.indexOf(";",n+12))):l.startsWith("iP")?(n=l.indexOf("OS"),e.os="iOS",e.type=l.slice(0,l.indexOf(";")),e.version=l.slice(n+3,l.indexOf(" ",n+4)).replace(/_/g,".")):l.startsWith("Macintosh;")?(n=l.indexOf(" Mac OS X"),e.os="MacOS",e.type=l.slice(11,n)+" Mac",e.version=l.slice(n+10).replace(/_/g,".")):-1!=(n=l.indexOf("Android"))?(e.os="Android",e.version=l.slice(n+8,l.indexOf(";",n+9)),n=l.lastIndexOf(";"),s=l.indexOf(" Build",n+2),e.type=l.slice(n+2,-1==s?void 0:s)):l.startsWith("X11;")&&(n=(l=l.slice(5).split(/[;\s]+/)).length,e.os=("Linux"==l[0]?"":"Linux ")+l[0],e.type=l[n-2],e.version=l[n-1]),(n=Number(e.version))&&(e.version=n),n=t.indexOf(" ",i+2),s=-1==(s=t.indexOf(")",n+1))?n+1:s+2,e.engine=t.slice(i+2,n),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}),utils.numField=(t,e,i,l,n)=>{let s=RegExp(`[,${n?RegExp.escape(n):""}]`,"g");return t.type=utils.mobile||l||n?"tel":"number",t.setAttribute("pattern","\\d*"),null==e&&(e=Number.MIN_SAFE_INTEGER),null==i&&(i=Number.MAX_SAFE_INTEGER),null==l&&(l=n?2:0),t.step||(t.step=1),t.num=Math.max(0,e),t.ns="",t.value=n?utils.formatCost(t.num,n):t.num.toString(),t.addEventListener("keydown",s=>{if(s.ctrlKey)return;let r=s.key,u=1==r.length&&Number.isFinite(Number(r)),o=t.ns,a=o.length,f=o.indexOf(".");if("Tab"!=r&&"Enter"!=r){if(u?(-1==f||a-f<l+1)&&(o+=r):"."==r||"*"==r?l&&-1==f&&t.num!=i&&(e>=0||t.num!=e)&&(!a&&e>0?o=Math.floor(e)+".":o+="."):"Backspace"==r||"Delete"==r?o=e>0&&t.num==e&&o.endsWith(".")?"":o.slice(0,-1):"-"==r||"#"==r?e<0&&!a&&(o="-"):"ArrowUp"==r?(o=null,t.set(t.num+Number(t.step))):"ArrowDown"==r&&(o=null,t.set(t.num-Number(t.step))),null!==o&&o!==t.ns){let c="-"==o||"-."==o,d=Number(c?"0":o+(o.endsWith(".")?"0":"")),h=Math.min(i,Math.max(e,d));(!u||t.num!==h||d===e)&&(t.ns=o,t.num=h,t.value=n?c?n+"-0.00":utils.formatCost(h,n):(c?"-":"")+h+(o.endsWith(".")&&(e<=0||h!=e)?".0":""),t.onnuminput&&t.onnuminput.call(t))}s.preventDefault()}}),t.set=r=>{"string"==typeof r&&(r=r.replace(s,"")),r=Math.min(i,Math.max(e,Number(r)||0)),t.num=l?Number(r.toFixed(l)):Math.round(r),t.ns=t.num.toString(),t.value=n?utils.formatCost(t.num,n):t.ns,t.ns=t.ns.replace(/^(-?)0+/,"$1"),t.onnuminput&&t.onnuminput.call(t)},t.setRange=(t,n,s)=>{e=t,i=n,l=s},t.addEventListener("input",()=>t.set(t.value)),t.addEventListener("paste",e=>{t.set(e.clipboardData.getData("text")),e.preventDefault()}),t},utils.autosize=(t,e=5,i=1)=>{t.set=e=>{t.value=e,n()};let l=t.style;function n(){if(0===t.scrollHeight)return setTimeout(n,1);t.setAttribute("rows",1);let s=getComputedStyle(t);l.setProperty("overflow","hidden","important"),l.width=t.innerRect.w+"px",l.boxSizing="content-box",l.borderWidth=l.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);l.overflow=l.width=l.boxSizing=l.borderWidth=l.paddingInline="",t.setAttribute("rows",utils.bounds(o,i,e))}l.maxHeight=l.resize="none",l.minHeight=0,l.height="auto",t.setAttribute("rows",i),t.addEventListener("input",n)},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]},utils.fixedNum=function(t,e,i=10){let l=Math.abs(t).toString(i).toUpperCase();return(t<0?"-":"")+(16==i?"0x":2==i?"0b":"")+"0".repeat(Math.max(e-l.length,0))+l},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="",l,n;if(null==t||!t.getDate||!((l=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+":"+u(t.getMinutes())+(e.sec?":"+u(t.getSeconds())+(e.ms?(t.getMilliseconds()/1e3).toFixed(Number.isFinite(e.ms)?e.ms:3).slice(1):""):""),i+=r,e.time)return i}return n=t.getDate(),n=utils.months[t.getMonth()]+" "+(null==e.suf||e.suf?utils.suffix(n):n),(null==e.year||e.year)&&e.year!==l&&(n=n+", "+l),e.df?n+(i&&" "+i):(i&&i+" ")+n},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 o=e;function a(t){utils.onNav&&utils.onNav.call(null,t)}function f(t,e,i){let n=this.length,s=Math.max(e<0?n+e:e||0,0),r;for(null!=i&&(n=Math.min(i<0?n+i:i,n));s<n;++s)if("!"===(r=t(this[s],s,n)))this instanceof l?this[s].remove():this.splice(s,1),--s,--n;else if(null!=r)return r}async function c(t,e,i,n=!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),!n&&"!"!==(u=await u)&&null!=u)return u;o.push(u)}for(n&&(o=await Promise.all(o)),r=e,u=0;r<s;++r,++u)if("!"===o[u])this instanceof l?this[r].remove():this.splice(r,1),--r,--s;else if(null!=o[u])return o[u]}utils.goBack=o.back.bind(o),utils.goForward=o.forward.bind(o),utils.go=(t,e)=>{o.pushState(e,"",t||location.pathname),a(e)},r("popstate",t=>a(t.state)),r("load",()=>setTimeout(a.wrap(o.state),1)),utils.mkEl=(t,e,i,l,n)=>{let s=document.createElement(t);if(null!=i&&(s.className=i),null!=n&&(s.innerHTML=n),l&&"object"==typeof l)for(let r in l)r in s.style?s.style[r]=l[r]:s.style.setProperty(r,l[r]);return null!=e&&e.appendChild(s),s},utils.mkDiv=(t,e,i,l)=>utils.mkEl("div",t,e,i,l),utils.addText=(t,e)=>t.appendChild(document.createTextNode(e)),utils.textWidth=(e,i)=>{let l=t.TWCanvas||(t.TWCanvas=utils.mkEl("canvas")),n=l.getContext("2d");return n.font=i,n.measureText(e).width},utils.define(utils,"w",()=>innerWidth),utils.define(utils,"h",()=>innerHeight),utils.setPropSafe=(t,e,i,l=!1)=>{"string"==typeof e&&(e=e.split("."));let n=e.length-1;return(e.each(e=>{t="object"==typeof t[e]?t[e]:t[e]={}},0,n),n=e[n],l&&null!=t[n])?t[n]:t[n]=i},utils.getPropSafe=(t,e)=>{"string"==typeof e&&(e=e.split("."));try{for(let i of e)t=t[i];return t}catch(l){}},utils.proto(Array,"clean",function(t){for(let e=0,i,l=this.length;e<l;++e)i=this[e],(utils.isBlank(i)||!1===i||!t&&0===i)&&(this.splice(e--,1),l--);return this}),utils.proto(Array,"remove",function(t){let e=this.indexOf(t);return -1!=e&&(this.splice(e,1),!0)}),[Array,l,s].forEach(t=>{utils.proto(t,"each",f),utils.proto(t,"eachAsync",c)});let d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=d.replace("+/","-_"),$={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 _(t,e){if(null==(t=$[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,l=t&&"base64url"===t.alphabet?h:d,n=0,s="",r;for(e-=i;n<e;n+=3)s+=l[(16515072&(r=this[n]<<16|this[n+1]<<8|this[n+2]))>>18]+l[(258048&r)>>12]+l[(4032&r)>>6]+l[63&r];return 1==i?(s+=l[(252&(r=this[e]))>>2]+l[(3&r)<<4],t&&t.omitPadding||(s+="=")):2!=i||(s+=l[(64512&(r=this[e]<<8|this[e+1]))>>10]+l[(1008&r)>>4]+l[(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 l=e%4;if(e-=l,1==l)throw"Bad b64 len";let n=new Uint8Array(3*e/4+(l?l-1:0)),s=-1,r;for(;i<e;i+=4)r=_(t,i)<<18|_(t,i+1)<<12|_(t,i+2)<<6|_(t,i+3),n[++s]=r>>16,n[++s]=r>>8,n[++s]=r;return 2==l?n[++s]=_(t,i)<<2|_(t,i+1)>>4:3==l&&(r=_(t,i)<<10|_(t,i+1)<<4|_(t,i+2)>>2,n[++s]=r>>8,n[++s]=r),n},1);let p=/[|\\{}()[\]^$+*?.]/g,g=/-/g;function m(t,e){for(;t>=e;)t-=e;return t}function y(){let t=document.styleSheets;for(let e=0,i=t.length;e<i;++e)try{return t[e].cssRules,t[e]}catch(l){}let n=utils.mkEl("style",document.head);return utils.addText(n,""),n.sheet}function x(t){return t.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}"escape"in RegExp||utils.proto(RegExp,"escape",t=>t.replace(p,"\\$&").replace(g,"\\x2d"),1),utils.define(n.prototype,"index",function(){let t=this.parentElement;return t?Array.prototype.indexOf.call(t.children,this):-1}),utils.proto(n,"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(n.prototype,"boundingRect",function(){return utils.boundingRect(this)}),utils.define(n.prototype,"innerRect",function(){return utils.innerRect(this)}),Math.cot=t=>1/Math.tan(t),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 l=0;l<i;++l)if(null==t[e[l]])return e[l];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=m(Math.floor(t/52)-1,52),i=m(t,52);else if(t<143364)e=m(Math.floor((t-52)/2704)-1,52),i=m(t-52,2704)+52;else{if(!(t<7454980))return!1;e=m(Math.floor((t-2756)/140608)-1,52),i=m(t-2756,140608)+2756}return utils.numToChar(e)+utils.numToChar(i)},utils.merge=function(t){for(let e=1,i=arguments.length,l,n,s;e<i;++e)for(let r in l=arguments[e]){if(n=t[r],s=l[r],n&&s){if(n.length>=0&&s.length>=0){for(let u=0,o=s.length,a=n.length;u<o;++u)n[u+a]=s[u];continue}if("object"==typeof n&&"object"==typeof s){for(let f in s)n[f]=s[f];continue}}t[r]=s}return t},utils.bounds=(t,e=0,i=1)=>t>=e?t<=i?t:i:e,utils.norm=utils.normalize=(t,e=0,i=1)=>{let l=Math.abs(i-e);if(t<e)for(;t<e;)t+=l;else for(;t>=i;)t-=l;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,l,n)=>{let s=t.indexOf(e,n||void 0)+e.length,r=t.indexOf(i,s);return l&&(l.s=s,l.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.dCutToLast=(t,e,i,l,n)=>{let s=t.indexOf(e,n||void 0)+e.length,r=t.lastIndexOf(i);return l&&(l.s=s,l.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.dCutLast=(t,e,i,l,n)=>{let s=t.lastIndexOf(e,n||void 0)+e.length,r=t.indexOf(i,s);return l&&(l.s=s,l.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.parseCSS=t=>{let e={},i="",l=0;function n(t){if(-1!==t.indexOf(",")){let e=utils.clean(t.split(","));for(let i=0,l=e.length;i<l;++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]=n(r),i="",t=t.slice(s+1)}else if(0==t.search(/[#!\w]/)){i&&(e[l++]=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[l]=i),e},utils.buildCSS=t=>{let e=Object.keys(t),i=e.length,l="",n=0;for(;n<i;){let s=e[n],r=t[e[n]];++n,0<=Number(s)?l+=r+" ":l+=`${s}(${r}) `}return l.slice(0,-1)},utils.addClass=(t,e)=>{let i=y(),l=Object.keys(e),n="";for(let s=0,r=l.length;s<r;++s)n+=x(l[s])+":"+e[l[s]]+";";i.addRule("."+t,n)},utils.addId=(t,e)=>{let i=y(),l=Object.keys(e),n="";for(let s=0,r=l.length;s<r;++s)n+=x(l[s])+":"+e[l[s]]+";";i.addRule("#"+t,n)},utils.addKeyframe=(t,e)=>{y().addRule("@keyframes "+t,e)},utils.removeSelector=t=>{for(let e=0,i,l,n=document.styleSheets.length;e<n;++e){i=document.styleSheets[e];try{l=i.cssRules}catch(s){continue}for(let r in l)"CSSStyleRule"==l[r].constructor.name&&l[r].selectorText==t&&i.deleteRule(r)}},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 l=Math.max(t,e/=255,i/=255),n=Math.min(t,e,i),s,r,u=(l+n)/2;if(l===n)s=r=0;else{let o=l-n;switch(r=u>.5?o/(2-l-n):o/(l+n),l){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,l)=>{e*=i=i||1,t*=i;let n=Math.random();return Math.round((l?l(n):n)*(e-t)+t)/i},utils.fromQuery=t=>{function e(t,i){let l=i[0],n=l.indexOf("="),s=decodeURIComponent(l.slice(0,n)),r=decodeURIComponent(l.slice(n+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,l;if("object"!=typeof t)return encodeURIComponent(t);for(i in t)"object"==typeof(l=t[i])&&null!=l&&(l=JSON.stringify(l)),e+="&"+i+"="+encodeURIComponent(l);return e.slice(1)},utils.center=(t,e,i)=>{let l=t.style;if("trans"==i){l.position||(l.position="absolute");let n=utils.cutStr(l.transform,"translateX(-50%)");n=utils.cutStr(n,"translateY(-50%)"),e&&"x"!=e||(l.left="50%",n+="translateX(-50%)"),e&&"y"!=e||(l.top="50%",n+="translateY(-50%)"),n&&(l.transform=n)}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,l,n)=>{let s;try{s=new XMLHttpRequest}catch(r){return e(r)}if(n)for(let u in n)s.setRequestHeader(u,n[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(l||void 0)},utils.loadFile=(t,e,i)=>{let l=utils.mkEl("object",document.body,null,{position:"fixed",opacity:0});l.data=t;let n=setTimeout(()=>{l.remove(),n=null,e(!1)},i||4e3);l.onload=()=>{n&&(clearTimeout(n),e(l.contentDocument.documentElement.outerHTML),l.remove())}},utils.loadJSONP=(t,e,i)=>{let l=utils.mkEl("script",document.head),n=utils.firstEmptyChar(utils.lJSONCall);l.type="application/javascript",l.src=t+(-1==t.indexOf("?")?"?":"&")+"callback=utils.lJSONCall."+n;let s=setTimeout(()=>{delete utils.lJSONCall[n],e(!1)},i||4e3);utils.lJSONCall[n]=t=>{s&&clearTimeout(s),delete utils.lJSONCall[n],e(t)},document.head.removeChild(l)},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,l=utils.mkEl("a",document.body,null,{display:"none"});"string"==typeof e?i=e:(e instanceof Blob||(e=Blob(e)),i=URL.createObjectURL(e)),l.href=i,l.download=t,l.click(),l.remove(),URL.revokeObjectURL(i)},utils.deg=t=>180*t/Math.PI,utils.rad=t=>t*Math.PI/180,utils.map=(t,e,i,l,n,s)=>{let r=(t-e)/(i-e);return(s?s(r):r)*(n-l)+l},utils.delay=t=>new Promise(e=>setTimeout(e,t)),UtilRect=function(t,e,l,n){if(!(this instanceof UtilRect))return new UtilRect(t,e,l,n);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=l,a=n)},utils.proto(UtilRect,"contains",function(t,e){return t instanceof n?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 n)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 n)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};if(_uNJS&&!global.utils){let t=import("os").then(e=>t=e);utils.getIPs=()=>{let e=[],i=t.networkInterfaces();for(let l in i)i[l].forEach(t=>{!t.internal&&"IPv4"==t.family&&"00:00:00:00:00:00"!=t.mac&&t.address&&e.push(t.address)});return e.length?e:0},utils.getOS=()=>{let e,i,l;switch(t.platform()){case"win32":e="Windows";break;case"darwin":e="MacOS";break;case"linux":e="Linux";break;default:e=t.platform()}switch(t.arch()){case"ia32":i="32-bit";break;case"x64":i="64-bit";break;case"arm":i="ARM";break;default:i=t.arch()}return[e,i,l=t.cpus()[0].model]},global.utils=utils,global.UtilRect=UtilRect,global.Easing=Easing}
|
|
2
|
+
"use strict";const utils={VER:"v8.7.9"},_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,l,n,s,r]=P;utils.define=(t,e,i,l)=>{let n={};if(i&&(n.get=i),l&&(n.set=l),Array.isArray(e))for(let s of e)Object.defineProperty(t,s,n);else Object.defineProperty(t,e,n)},utils.proto=(t,e,i,l)=>{let n={value:i};if(l||(t=t.prototype),Array.isArray(e))for(let s of e)Object.defineProperty(t,s,n);else Object.defineProperty(t,e,n)},utils.setCookie=(t,e,i,l)=>{let n=`${encodeURIComponent(t)}=${null==e?"":encodeURIComponent(e)};path=/`;if(null!=i&&(-1===i&&(i=new Date(Number.MAX_SAFE_INTEGER/10)),i instanceof Date?n+=";expires="+i.toUTCString():n+=";max-age="+i),l&&(n+=";secure"),_uNJS)return n;document.cookie=n},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,l,n={};for(i of e)l=i.indexOf("="),n[decodeURIComponent(i.slice(0,l))]=decodeURIComponent(i.slice(l+1));return n},utils.getCookie=(t,e)=>{null==e&&(e=document.cookie),t=encodeURIComponent(t)+"=";let i=e.split("; "),l;for(l of i)if(l.startsWith(t))return decodeURIComponent(l.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,l)=>{i[l]=utils.copy(t,e)});else for(let l in i={},t)i[l]=utils.copy(t[l],e);return i},utils.deviceInfo=t=>{let e={};if(t||(t=navigator.userAgent),!t.startsWith("Mozilla/5.0 "))return e;let i=t.indexOf(")"),l=e.rawOS=t.slice(13,i),n,s;return l.startsWith("Windows")?(n=l.split("; "),e.os="Windows",e.type=-1!=n.indexOf("WOW64")?"x64 PC; x86 Browser":-1!=n.indexOf("x64")?"x64 PC":"x86 PC",n=l.indexOf("Windows NT "),e.version=l.slice(n+11,l.indexOf(";",n+12))):l.startsWith("iP")?(n=l.indexOf("OS"),e.os="iOS",e.type=l.slice(0,l.indexOf(";")),e.version=l.slice(n+3,l.indexOf(" ",n+4)).replace(/_/g,".")):l.startsWith("Macintosh;")?(n=l.indexOf(" Mac OS X"),e.os="MacOS",e.type=l.slice(11,n)+" Mac",e.version=l.slice(n+10).replace(/_/g,".")):-1!=(n=l.indexOf("Android"))?(e.os="Android",e.version=l.slice(n+8,l.indexOf(";",n+9)),n=l.lastIndexOf(";"),s=l.indexOf(" Build",n+2),e.type=l.slice(n+2,-1==s?void 0:s)):l.startsWith("X11;")&&(n=(l=l.slice(5).split(/[;\s]+/)).length,e.os=("Linux"==l[0]?"":"Linux ")+l[0],e.type=l[n-2],e.version=l[n-1]),(n=Number(e.version))&&(e.version=n),n=t.indexOf(" ",i+2),s=-1==(s=t.indexOf(")",n+1))?n+1:s+2,e.engine=t.slice(i+2,n),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,l,n)=>{let s=RegExp(`[,${n?RegExp.escape(n):""}]`,"g");function r(t){return"string"==typeof t&&(t=t.replace(s,"")),t=Math.min(i,Math.max(e,Number(t)||0)),l?Number(t.toFixed(l)):Math.round(t)}return t.type=utils.mobile||l||n?"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<l+1)&&(a+=r):"."===r||"*"===r?l&&-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<l+1)&&(t.ns=a,t.num=h,t.value=n?d?n+"-0.00":utils.formatCost(h,n):("-"===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=n?utils.formatCost(t.num,n):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,l=null==o?n?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,l),t},utils.autosize=(t,e=5,i=1)=>{t.set=e=>{t.value=e,n()};let l=t.style;function n(){if(0===t.scrollHeight)return setTimeout(n,1);t.setAttribute("rows",1);let s=getComputedStyle(t);l.setProperty("overflow","hidden","important"),l.width=t.innerRect.w+"px",l.boxSizing="content-box",l.borderWidth=l.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);l.overflow=l.width=l.boxSizing=l.borderWidth=l.paddingInline="",t.setAttribute("rows",utils.bounds(o,i,e))}l.maxHeight=l.resize="none",l.minHeight=0,l.height="auto",t.setAttribute("rows",i),t.addEventListener("input",n)},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 l=utils.abs(t).toString(i).toUpperCase();return(t<0?"-":"")+(16==i?"0x":2==i?"0b":"")+"0".repeat(Math.max(e-l.length,0))+l},utils.bounds=(t,e=0,i=1)=>t>=e?t<=i?t:i:e,utils.norm=utils.normalize=(t,e=0,i=1)=>{let l=i-e;return((t+utils.abs(e))%l+l)%l+e},utils.map=(t,e,i,l,n,s)=>{let r=(t-e)/(i-e);return(s?s(r):r)*(n-l)+l},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 l=Math.max(t,e/=255,i/=255),n=Math.min(t,e,i),s,r,u=(l+n)/2;if(l===n)s=r=0;else{let o=l-n;switch(r=u>.5?o/(2-l-n):o/(l+n),l){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,l)=>{e*=i=i||1,t*=i;let n=Math.random();return Math.round((l?l(n):n)*(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="",l,n;if(null==t||!t.getDate||!((l=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 n=t.getDate(),n=utils.months[t.getMonth()]+" "+(null==e.suf||e.suf?utils.suffix(n):n),(null==e.year||e.year)&&e.year!==l&&(n=n+", "+l),e.df?n+(i&&" "+i):(i&&i+" ")+n},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 n=this.length,s=Math.max(e<0?n+e:e||0,0),r;for(null!=i&&(n=Math.min(i<0?n+i:i,n));s<n;++s)if("!"===(r=t(this[s],s,n)))this instanceof l?this[s].remove():this.splice(s,1),--s,--n;else if(null!=r)return r}async function $(t,e,i,n=!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),!n&&"!"!==(u=await u)&&null!=u)return u;o.push(u)}for(n&&(o=await Promise.all(o)),r=e,u=0;r<s;++r,++u)if("!"===o[u])this instanceof l?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,l,n)=>{let s=document.createElement(t);if(null!=i&&(s.className=i),null!=n&&(s.innerHTML=n),l&&"object"==typeof l)for(let r in l)r in s.style?s.style[r]=l[r]:s.style.setProperty(r,l[r]);return null!=e&&e.appendChild(s),s},utils.mkDiv=(t,e,i,l)=>utils.mkEl("div",t,e,i,l),utils.addText=(t,e)=>t.appendChild(document.createTextNode(e)),utils.textWidth=(e,i)=>{let l=t.TWCanvas||(t.TWCanvas=utils.mkEl("canvas")),n=l.getContext("2d");return n.font=i,n.measureText(e).width},utils.define(utils,"w",()=>innerWidth),utils.define(utils,"h",()=>innerHeight),utils.setPropSafe=(t,e,i,l=!1)=>{"string"==typeof e&&(e=e.split("."));let n=e.length-1;return(e.each(e=>{t="object"==typeof t[e]?t[e]:t[e]={}},0,n),n=e[n],l&&null!=t[n])?t[n]:t[n]=i},utils.getPropSafe=(t,e)=>{"string"==typeof e&&(e=e.split("."));try{for(let i of e)t=t[i];return t}catch(l){}},utils.proto(Array,"clean",function(t){for(let e=0,i,l=this.length;e<l;++e)i=this[e],(utils.isBlank(i)||!1===i||!t&&0===i)&&(this.splice(e--,1),l--);return this}),utils.proto(Array,"remove",function(t){let e=this.indexOf(t);return -1!=e&&(this.splice(e,1),!0)}),[Array,l,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 m(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,l=t&&"base64url"===t.alphabet?p:_,n=0,s="",r;for(e-=i;n<e;n+=3)s+=l[(16515072&(r=this[n]<<16|this[n+1]<<8|this[n+2]))>>18]+l[(258048&r)>>12]+l[(4032&r)>>6]+l[63&r];return 1==i?(s+=l[(252&(r=this[e]))>>2]+l[(3&r)<<4],t&&t.omitPadding||(s+="=")):2!=i||(s+=l[(64512&(r=this[e]<<8|this[e+1]))>>10]+l[(1008&r)>>4]+l[(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 l=e%4;if(e-=l,1==l)throw"Bad b64 len";let n=new Uint8Array(3*e/4+(l?l-1:0)),s=-1,r;for(;i<e;i+=4)r=m(t,i)<<18|m(t,i+1)<<12|m(t,i+2)<<6|m(t,i+3),n[++s]=r>>16,n[++s]=r>>8,n[++s]=r;return 2==l?n[++s]=m(t,i)<<2|m(t,i+1)>>4:3==l&&(r=m(t,i)<<10|m(t,i+1)<<4|m(t,i+2)>>2,n[++s]=r>>8,n[++s]=r),n},1);let y=/[|\\{}()[\]^$+*?.]/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(l){}let n=utils.mkEl("style",document.head);return utils.addText(n,""),n.sheet}function v(t){return t.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}"escape"in RegExp||utils.proto(RegExp,"escape",t=>t.replace(y,"\\$&").replace(x,"\\x2d"),1),utils.define(n.prototype,"index",function(){let t=this.parentElement;return t?Array.prototype.indexOf.call(t.children,this):-1}),utils.proto(n,"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(n.prototype,"boundingRect",function(){return utils.boundingRect(this)}),utils.define(n.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 l=0;l<i;++l)if(null==t[e[l]])return e[l];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,l,n,s;e<i;++e)for(let r in l=arguments[e]){if(n=t[r],s=l[r],n&&s){if(n.length>=0&&s.length>=0){for(let u=0,o=s.length,a=n.length;u<o;++u)n[u+a]=s[u];continue}if("object"==typeof n&&"object"==typeof s){for(let f in s)n[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,l,n)=>{let s=t.indexOf(e,n||void 0)+e.length,r=t.indexOf(i,s);return l&&(l.s=s,l.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.dCutToLast=(t,e,i,l,n)=>{let s=t.indexOf(e,n||void 0)+e.length,r=t.lastIndexOf(i);return l&&(l.s=s,l.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.dCutLast=(t,e,i,l,n)=>{let s=t.lastIndexOf(e,n||void 0)+e.length,r=t.indexOf(i,s);return l&&(l.s=s,l.t=r),s<e.length||r<=s?"":t.slice(s,r)},utils.parseCSS=t=>{let e={},i="",l=0;function n(t){if(-1!==t.indexOf(",")){let e=utils.clean(t.split(","));for(let i=0,l=e.length;i<l;++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]=n(r),i="",t=t.slice(s+1)}else if(0==t.search(/[#!\w]/)){i&&(e[l++]=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[l]=i),e},utils.buildCSS=t=>{let e=Object.keys(t),i=e.length,l="",n=0;for(;n<i;){let s=e[n],r=t[e[n]];++n,0<=Number(s)?l+=r+" ":l+=`${s}(${r}) `}return l.slice(0,-1)},utils.addClass=(t,e)=>{let i=O(),l=Object.keys(e),n="";for(let s=0,r=l.length;s<r;++s)n+=v(l[s])+":"+e[l[s]]+";";i.addRule("."+t,n)},utils.addId=(t,e)=>{let i=O(),l=Object.keys(e),n="";for(let s=0,r=l.length;s<r;++s)n+=v(l[s])+":"+e[l[s]]+";";i.addRule("#"+t,n)},utils.addKeyframe=(t,e)=>{O().addRule("@keyframes "+t,e)},utils.removeSelector=t=>{for(let e=0,i,l,n=document.styleSheets.length;e<n;++e){i=document.styleSheets[e];try{l=i.cssRules}catch(s){continue}for(let r in l)"CSSStyleRule"==l[r].constructor.name&&l[r].selectorText==t&&i.deleteRule(r)}},utils.fromQuery=t=>{function e(t,i){let l=i[0],n=l.indexOf("="),s=decodeURIComponent(l.slice(0,n)),r=decodeURIComponent(l.slice(n+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,l;if("object"!=typeof t)return encodeURIComponent(t);for(i in t)"object"==typeof(l=t[i])&&null!=l&&(l=JSON.stringify(l)),e+="&"+i+"="+encodeURIComponent(l);return e.slice(1)},utils.center=(t,e,i)=>{let l=t.style;if("trans"==i){l.position||(l.position="absolute");let n=utils.cutStr(l.transform,"translateX(-50%)");n=utils.cutStr(n,"translateY(-50%)"),e&&"x"!=e||(l.left="50%",n+="translateX(-50%)"),e&&"y"!=e||(l.top="50%",n+="translateY(-50%)"),n&&(l.transform=n)}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,l,n)=>{let s;try{s=new XMLHttpRequest}catch(r){return e(r)}if(n)for(let u in n)s.setRequestHeader(u,n[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(l||void 0)},utils.loadFile=(t,e,i)=>{let l=utils.mkEl("object",document.body,null,{position:"fixed",opacity:0});l.data=t;let n=setTimeout(()=>{l.remove(),n=null,e(!1)},i||4e3);l.onload=()=>{n&&(clearTimeout(n),e(l.contentDocument.documentElement.outerHTML),l.remove())}},utils.loadJSONP=(t,e,i)=>{let l=utils.mkEl("script",document.head),n=utils.firstEmptyChar(utils.lJSONCall);l.type="application/javascript",l.src=t+(-1==t.indexOf("?")?"?":"&")+"callback=utils.lJSONCall."+n;let s=setTimeout(()=>{delete utils.lJSONCall[n],e(!1)},i||4e3);utils.lJSONCall[n]=t=>{s&&clearTimeout(s),delete utils.lJSONCall[n],e(t)},document.head.removeChild(l)},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,l=utils.mkEl("a",document.body,null,{display:"none"});"string"==typeof e?i=e:(e instanceof Blob||(e=Blob(e)),i=URL.createObjectURL(e)),l.href=i,l.download=t,l.click(),l.remove(),URL.revokeObjectURL(i)},utils.delay=t=>new Promise(e=>setTimeout(e,t)),UtilRect=function(t,e,l,n){if(!(this instanceof UtilRect))return new UtilRect(t,e,l,n);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=l,a=n)},utils.proto(UtilRect,"contains",function(t,e){return t instanceof n?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 n)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 n)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};if(_uNJS&&!global.utils){let t=import("os").then(e=>t=e);utils.getIPs=()=>{let e=[],i=t.networkInterfaces();for(let l in i)i[l].forEach(t=>{!t.internal&&"IPv4"==t.family&&"00:00:00:00:00:00"!=t.mac&&t.address&&e.push(t.address)});return e.length?e:0},utils.getOS=()=>{let e,i,l;switch(t.platform()){case"win32":e="Windows";break;case"darwin":e="MacOS";break;case"linux":e="Linux";break;default:e=t.platform()}switch(t.arch()){case"ia32":i="32-bit";break;case"x64":i="64-bit";break;case"arm":i="ARM";break;default:i=t.arch()}return[e,i,l=t.cpus()[0].model]},global.utils=utils,global.UtilRect=UtilRect,global.Easing=Easing}
|