-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_main.js
89 lines (89 loc) · 2.42 KB
/
index_main.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
/*arcLandscape
* index_main.js
*===================================================================
* Copyright (c) 2022 Yuji SODE <yuji.sode@gmail.com>
*
* This software is released under the MIT License.
* See LICENSE or http://opensource.org/licenses/mit-license.php
*===================================================================
*/
(()=>{
let slf=window.document,
cId='outputCvs',C=slf.getElementById(cId),
/* === === */
REVERSE=slf.getElementById('reverseOrder'),
A=slf.getElementById('downloadPNG'),
INPUT=slf.getElementById('textInput'),
/* === canvas size inputs === */
WIDTH=slf.getElementById('cWidth'),
HEIGHT=slf.getElementById('cHeight'),
/* === buttons === */
CLEARB=slf.getElementById('clearB'),
LOADB_txt=slf.getElementById('loadB_txt'),
LOADB_hex=slf.getElementById('loadB_hex'),
LINKB=slf.getElementById('linkB'),
/* === TYPE := undefined|txt|hex === */
TYPE=undefined;
//
//form event
slf.getElementById('arcLandscapeForm').addEventListener('change',()=>{
//
//the upper limit for canvas size: 3000
WIDTH.value=WIDTH.value>3000?3000:WIDTH.value;
HEIGHT.value=HEIGHT.value>3000?3000:HEIGHT.value;
//
C.width=WIDTH.value;
C.height=HEIGHT.value;
//
//overriding value of TYPE
TYPE=undefined;
},false);
//
//clearing text input
CLEARB.addEventListener('click',()=>{
INPUT.value='';
//
//overriding value of TYPE
TYPE=undefined;
},false);
//
//load input as text string
LOADB_txt.addEventListener('click',()=>{
arcLandscape.fromText(cId,INPUT.value,!REVERSE.checked);
//
//overriding value of TYPE
TYPE='txt';
},false);
//
//load input as hexadecimal sequence
LOADB_hex.addEventListener('click',()=>{
arcLandscape(cId,INPUT.value.replaceAll(/[^0-1A-Fa-f]/g,''),!REVERSE.checked);
//
//overriding value of TYPE
TYPE='hex';
},false);
//
//generating download link
LINKB.addEventListener('click',()=>{
let url,time=new Date();
//reset download link
A.href='#';
A.download='#';
A.style='display:none;';
//
url=async ()=>await C.toDataURL();
//
setTimeout(()=>{
//set download link
url().then((v)=>{
A.href=v;
}).then(()=>{
A.textContent=time.toTimeString();
//
//output filename:"AL<number>_TYPE<type|typeReverse><width>x<height>.png"
A.download=`AL${time.getTime()}_TYPE${TYPE}${!REVERSE.checked?'':'Reverse'}${C.width}x${C.height}.png`;
A.style='display:inline;';
});
},2000);
},false);
})();