-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.js
414 lines (373 loc) · 12.5 KB
/
general.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
import React, {useState, useEffect} from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {useSelector, useDispatch} from 'react-redux';
import './general.scss';
import * as FaIcons from '@fortawesome/free-solid-svg-icons';
import * as FaRegIcons from '@fortawesome/free-regular-svg-icons';
import * as AllIcons from './icons.js';
String.prototype.strip = function (c) {
var i = 0, j = this.length-1;
while (this[i] === c) i++;
while (this[j] === c) j--;
return this.slice(i,j+1);
}
String.prototype.count = function(c) {
var result = 0, i = 0;
for(i;i<this.length;i++) if(this[i]==c) result++;
return result;
};
export const Icon = (props)=>{
const dispatch = useDispatch();
var src = `img/icon/${props.ui!=null?'ui/':''}${props.src}.png`;
if(props.ext!=null || (props.src && props.src.includes("http"))){
src = props.src
}
var prtclk = "";
if(props.src){
if(props.onClick!=null || props.pr!=null){
prtclk="prtclk";
}
}
const clickDispatch = (event)=>{
var action = {
type: event.target.dataset.action,
payload: event.target.dataset.payload
};
if(action.type){
dispatch(action);
}
}
if(props.fafa!=null){
return (
<div className={`uicon prtclk ${props.className||""}`}
onClick={props.onClick || (props.click && clickDispatch) || null}
data-action={props.click} data-payload={props.payload}
data-menu={props.menu}>
<FontAwesomeIcon
data-flip={props.flip!=null}
data-invert={props.invert!=null?'true':'false'}
data-rounded={props.rounded!=null?'true':'false'}
style={{
width: props.width,
height: props.height || props.width,
color: props.color || null,
margin: props.margin || null
}}
icon={props.reg==null?FaIcons[props.fafa]:FaRegIcons[props.fafa]} />
</div>
);
}else if (props.icon!=null) {
var CustomIcon = AllIcons[props.icon];
return(
<div className={`uicon prtclk ${props.className||""}`}
onClick={props.onClick || (props.click && clickDispatch) || null}
data-action={props.click} data-payload={props.payload}
data-menu={props.menu}>
<CustomIcon
data-flip={props.flip!=null}
data-invert={props.invert!=null?'true':'false'}
data-rounded={props.rounded!=null?'true':'false'}
style={{
width: props.width,
height: props.height || props.width,
fill: props.color || null,
margin: props.margin || null
}}/>
</div>
);
}else if(props.msi!=null){
return (
<div className={`uicon prtclk ${props.className||""}`}
onClick={props.onClick || (props.click && clickDispatch) || null}
data-action={props.click} data-payload={props.payload}
data-menu={props.menu}>
<i className={"ms-Icon ms-Icon--"+props.msi} style={{
fontSize: props.width || '16px',
margin: props.margin || null
}} aria-hidden="true"
data-flip={props.flip!=null}
data-invert={!!props.invert}></i>
</div>
);
}else{
return (
<div className={`uicon ${props.className||""} ${prtclk}`}
data-open={props.open} data-action={props.click}
data-active={props.active} data-payload={props.payload}
onClick={props.onClick || (props.pr && clickDispatch) || null}
data-menu={props.menu} data-pr={props.pr}>
{props.className=='tsIcon'?
<div
onClick={props.click!=null?clickDispatch:null}
style={{width:props.width,height:props.width}}
data-action={props.click}
data-payload={props.payload}
data-click={props.click!=null}
data-flip={props.flip!=null}
data-invert={props.invert!=null?'true':'false'}
data-rounded={props.rounded!=null?'true':'false'}
>
<img
width={props.width} height={props.height}
data-action={props.click}
data-payload={props.payload}
data-click={props.click!=null}
data-flip={props.flip!=null}
data-invert={props.invert!=null?'true':'false'}
data-rounded={props.rounded!=null?'true':'false'}
src={src} style={{
margin: props.margin || null
}} alt=""/></div>
:
<img
width={props.width} height={props.height}
onClick={props.click!=null?clickDispatch:null}
data-action={props.click}
data-payload={props.payload}
data-click={props.click!=null}
data-flip={props.flip!=null}
data-invert={props.invert!=null?'true':'false'}
data-rounded={props.rounded!=null?'true':'false'}
src={src} style={{
margin: props.margin || null
}} alt=""/>
}
</div>
);
}
}
export const Image = (props)=>{
const dispatch = useDispatch();
var src = `img/${(props.dir?props.dir+"/":"")+props.src}.png`;
if(props.ext!=null){
src = props.src
}
const errorHandler = (e)=>{
if(props.err){
e.target.src = props.err
}
}
const clickDispatch = (event)=>{
var action = {
type: event.target.dataset.action,
payload: event.target.dataset.payload
};
if(action.type){
dispatch(action);
}
}
return (
<div className={`imageCont prtclk ${props.className||""}`} id={props.id} style={{
backgroundImage: props.back && `url(${src})`
}} data-back={props.back!=null} onClick={props.onClick || (props.click && clickDispatch)}
data-action={props.click} data-payload={props.payload} data-var={props.var}>
{!props.back?<img
width={props.w}
height={props.h}
data-free={props.free!=null}
data-var={props.var}
loading={props.lazy?"lazy":null}
src={src} alt="" onError={errorHandler}/>:null}
</div>
)
}
export const SnapScreen = (props)=>{
const dispatch = useDispatch();
const [delay, setDelay] = useState(false);
const lays = useSelector(state => state.globals.lays);
const vr = "var(--radii)";
const clickDispatch = (event)=>{
var action = {
type: event.target.dataset.action,
payload: event.target.dataset.payload,
dim: JSON.parse(event.target.dataset.dim)
};
if(action.dim && action.type){
dispatch(action);
props.closeSnap();
}
}
useEffect(()=>{
if(delay && props.snap){
setTimeout(()=>{
setDelay(false);
},500);
}else if(props.snap){
setDelay(true);
}
})
return props.snap || delay?(
<div className="snapcont mdShad" data-dark={props.invert!=null}>
{lays.map((x,i)=>{
return (
<div key={i} className="snapLay">
{x.map((y,j)=>(
<div key={j} className="snapper" style={{
borderTopLeftRadius: (y.br%2==0)*4,
borderTopRightRadius: (y.br%3==0)*4,
borderBottomRightRadius: (y.br%5==0)*4,
borderBottomLeftRadius: (y.br%7==0)*4
}} onClick={clickDispatch} data-dim={JSON.stringify(y.dim)}
data-action={props.app} data-payload="resize"></div>
))}
</div>
)
})}
</div>
):null
}
export const ToolBar = (props)=>{
const dispatch = useDispatch();
const [snap, setSnap] = useState(false);
const openSnap = ()=>{
setSnap(true);
}
const closeSnap = ()=>{
setSnap(false);
}
const toolClick = ()=>{
dispatch({
type: props.app,
payload: "front"
});
}
var posP = [0,0], dimP = [0,0], posM = [0,0],
wnapp = {}, op=0, vec = [0,0];
const toolDrag = (e)=>{
e = e || window.event;
e.preventDefault();
posM = [e.clientY, e.clientX];
op = e.target.dataset.op;
if(op==0){
wnapp = e.target.parentElement && e.target.parentElement.parentElement;
}else{
vec = e.target.dataset.vec.split(",")
wnapp = e.target.parentElement &&
e.target.parentElement.parentElement &&
e.target.parentElement.parentElement.parentElement;
}
if(wnapp){
wnapp.classList.add("notrans")
wnapp.classList.add("z9900")
posP = [wnapp.offsetTop,wnapp.offsetLeft]
dimP = [
parseFloat(getComputedStyle(wnapp).height.replaceAll('px','')),
parseFloat(getComputedStyle(wnapp).width.replaceAll('px',''))
]
}
document.onmouseup = closeDrag;
document.onmousemove = eleDrag;
}
const setPos = (pos0, pos1)=>{
wnapp.style.top = pos0 + "px"
wnapp.style.left = pos1 + "px"
}
const setDim = (dim0, dim1)=>{
wnapp.style.height = dim0 + "px"
wnapp.style.width = dim1 + "px"
}
const eleDrag = (e)=>{
e = e || window.event;
e.preventDefault();
var pos0 = posP[0] + e.clientY - posM[0],
pos1 = posP[1] + e.clientX - posM[1],
dim0 = dimP[0] + vec[0]*(e.clientY - posM[0]),
dim1 = dimP[1] + vec[1]*(e.clientX - posM[1])
if(op==0) setPos(pos0, pos1)
else{
dim0 = Math.max(dim0, 320)
dim1 = Math.max(dim1, 320)
pos0 = posP[0] + Math.min(vec[0],0)*(dim0 - dimP[0])
pos1 = posP[1] + Math.min(vec[1],0)*(dim1 - dimP[1])
setPos(pos0, pos1)
setDim(dim0, dim1)
}
}
const closeDrag = ()=>{
document.onmouseup = null;
document.onmousemove = null;
wnapp.classList.remove("notrans")
wnapp.classList.remove("z9900")
var action = {
type: props.app,
payload: "resize",
dim: {
width: getComputedStyle(wnapp).width,
height: getComputedStyle(wnapp).height,
top: getComputedStyle(wnapp).top,
left: getComputedStyle(wnapp).left
}
}
dispatch(action);
}
return (
<>
<div className="toolbar" data-float={props.float!=null}
data-noinvert={props.noinvert!=null} style={{
background: props.bg }}>
<div className="topInfo flex flex-grow items-center"
data-float={props.float!=null} onClick={toolClick}
onMouseDown={toolDrag} data-op="0">
<Icon src={props.icon} width={14}/>
<div className="appFullName text-xss"
data-white={props.invert!=null}>{props.name}</div>
</div>
<div className="actbtns flex items-center">
<Icon invert={props.invert} click={props.app}
payload="mnmz" pr src="minimize" ui width={8}/>
<div className="snapbox h-full" data-hv={snap}
onMouseOver={openSnap} onMouseLeave={closeSnap}>
<Icon invert={props.invert} click={props.app} ui pr width={8}
payload="mxmz" src={props.size=="full"?"maximize":"maxmin"}/>
<SnapScreen invert={props.invert} app={props.app}
snap={snap} closeSnap={closeSnap}/>
{/* {snap?<SnapScreen app={props.app} closeSnap={closeSnap}/>:null} */}
</div>
<Icon className="closeBtn" invert={props.invert} click={props.app}
payload="close" pr src="close" ui width={8}/>
</div>
</div>
<div className="resizecont topone">
<div className="flex">
<div className="conrsz cursor-nw" data-op="1"
onMouseDown={toolDrag} data-vec="-1,-1"></div>
<div className="edgrsz cursor-n wdws" data-op="1"
onMouseDown={toolDrag} data-vec="-1,0"></div>
</div>
</div>
<div className="resizecont leftone">
<div className="h-full">
<div className="edgrsz cursor-w hdws" data-op="1"
onMouseDown={toolDrag} data-vec="0,-1"></div>
</div>
</div>
<div className="resizecont rightone">
<div className="h-full">
<div className="edgrsz cursor-w hdws" data-op="1"
onMouseDown={toolDrag} data-vec="0,1"></div>
</div>
</div>
<div className="resizecont bottomone">
<div className="flex">
<div className="conrsz cursor-ne" data-op="1"
onMouseDown={toolDrag} data-vec="1,-1"></div>
<div className="edgrsz cursor-n wdws" data-op="1"
onMouseDown={toolDrag} data-vec="1,0"></div>
<div className="conrsz cursor-nw" data-op="1"
onMouseDown={toolDrag} data-vec="1,1"></div>
</div>
</div>
</>
);
}
export const LazyComponent = ({show, children})=>{
const [loaded, setLoad] = useState(false)
useEffect(()=>{
if(show && !loaded) setLoad(true)
}, [show])
return show || loaded?(
<>
{children}
</>
):null
}