@@ -10,6 +10,7 @@ let monacoTimeout;
10
10
document . addEventListener ( 'DOMContentLoaded' , async ( ) => {
11
11
const elInpWidth = document . querySelector ( '#width' )
12
12
const elInpHeight = document . querySelector ( '#height' )
13
+ const elInpStroke = document . querySelector ( '#stroke' )
13
14
const elSelFormat = document . querySelector ( '#resolution' )
14
15
const elBtnDownload = document . querySelector ( '#download' )
15
16
const elChkAntiAliasing = document . querySelector ( '#antialiasing' )
@@ -26,7 +27,24 @@ document.addEventListener('DOMContentLoaded', async () => {
26
27
} ) ;
27
28
28
29
monacoEditor . setValue ( defaultScript )
29
-
30
+ if ( location . hash ) {
31
+ const params = new URLSearchParams ( window . location . hash . slice ( 1 ) )
32
+ const code = atob ( params . get ( 'code' ) . replace ( / _ / g, '=' ) )
33
+ const res = params . get ( 'res' ) . split ( 'x' )
34
+ if ( code && code . length > 0 ) {
35
+ monacoEditor . setValue ( code )
36
+ }
37
+ if ( res && res . length == 2 ) {
38
+ [ elInpWidth . value , elInpHeight . value ] = res
39
+ }
40
+ if ( params . has ( 'line' ) ) {
41
+ elInpStroke . value = parseFloat ( params . get ( 'line' ) )
42
+ }
43
+ if ( params . has ( 'aa' ) ) {
44
+ elChkAntiAliasing . checked = parseInt ( params . get ( 'aa' ) ) == 1
45
+ }
46
+ }
47
+
30
48
const factory = new LuaFactory ( wasmFile )
31
49
const lua = await factory . createEngine ( )
32
50
await lua . doString ( gly_engine )
@@ -63,13 +81,20 @@ document.addEventListener('DOMContentLoaded', async () => {
63
81
gly . init ( elCanvas )
64
82
65
83
const apply = ( ) => {
84
+ const params = new URLSearchParams ( )
66
85
const code = monacoEditor . getValue ( )
67
86
gly . load ( `return {init=function()end,loop=function()end,draw=function(std)\n${ code } \nend}` )
68
87
window . requestAnimationFrame ( gly . update )
88
+ params . set ( 'res' , `${ elInpWidth . value } x${ elInpHeight . value } ` )
89
+ params . set ( 'code' , btoa ( code ) . replace ( / = / g, '_' ) )
90
+ params . set ( 'line' , elInpStroke . value )
91
+ params . set ( 'aa' , elChkAntiAliasing . checked ? 1 : 0 )
92
+ location . hash = params . toString ( )
69
93
}
70
94
71
95
const resizeAndApply = ( ) => {
72
96
gly . resize ( elInpWidth . value , elInpHeight . value )
97
+ gly . stroke ( parseFloat ( elInpStroke . value ) )
73
98
apply ( )
74
99
}
75
100
@@ -98,14 +123,16 @@ document.addEventListener('DOMContentLoaded', async () => {
98
123
const ext = elSelFormat . value
99
124
const url = elCanvas . toDataURL ( `image/${ ext } ` )
100
125
const downloadLink = document . createElement ( 'a' )
126
+ const uptime = ( new Date ( ) ) . toISOString ( ) . slice ( 2 , 16 ) . replace ( / [ - T : ] / g, '' ) . replace ( / ^ ( \d { 6 } ) ( \d { 4 } ) $ / , '$1-$2' )
101
127
downloadLink . href = url
102
128
downloadLink . target = '_blank'
103
- downloadLink . download = `icon .${ ext } `
129
+ downloadLink . download = `img- ${ uptime } - ${ elInpWidth . value } x ${ elInpHeight . value } .${ ext } `
104
130
downloadLink . click ( )
105
131
URL . revokeObjectURL ( url )
106
132
} )
107
133
108
134
elChkAntiAliasing . addEventListener ( 'change' , toggleAntiAliasing ) ;
135
+ elInpStroke . addEventListener ( 'change' , resizeAndApply ) ;
109
136
elInpWidth . addEventListener ( 'change' , resizeAndApply ) ;
110
137
elInpHeight . addEventListener ( 'change' , resizeAndApply ) ;
111
138
0 commit comments