28
28
color : red;
29
29
}
30
30
31
- a , a : visited {
31
+ a ,
32
+ a : visited {
32
33
color : blue;
33
34
}
34
35
35
36
@media screen and (prefers-color-scheme : dark) {
36
- body , textarea {
37
+
38
+ body ,
39
+ textarea {
37
40
color : white;
38
41
background : black;
39
42
}
40
- a , a : visited {
43
+
44
+ a ,
45
+ a : visited {
41
46
color : magenta;
42
47
}
43
48
}
47
52
48
53
< body >
49
54
< h1 > Schemascii Playground</ h1 >
50
- < h2 id ="version "> Loading version... </ h2 >
55
+ < h2 > using schemascii version < select id ="version "> </ select > </ h2 >
51
56
< div class ="flex row ">
52
57
< div class ="flex column ">
53
58
< h2 > Schemascii Source</ h2 > < textarea id ="schemascii " disabled > </ textarea >
@@ -63,46 +68,25 @@ <h2>Messages</h2>
63
68
< h2 > Errors</ h2 >
64
69
< pre id ="errors "> </ pre >
65
70
< h2 > More Information</ h2 >
66
- < p > < a href ="https://github.com/dragoncoder047/schemascii/ " target ="_blank "> https://github.com/dragoncoder047/schemascii/</ a > </ p >
71
+ < p > < a href ="https://github.com/dragoncoder047/schemascii/ "
72
+ target ="_blank "> https://github.com/dragoncoder047/schemascii/</ a > </ p >
67
73
</ body >
68
74
< script >
69
- // cSpell:ignore pyodide pyproject pyimport
75
+ // cSpell:ignore pyodide pyproject
70
76
var pyodide ;
71
- var output = document . getElementById ( "output" ) ;
72
- var css = document . getElementById ( "css" ) ;
73
77
var console = document . getElementById ( "console" ) ;
74
- var source = document . getElementById ( "schemascii" ) ;
75
- var style_elem = document . getElementById ( "custom-css" ) ;
76
- var schemascii_render ;
78
+ var errors = document . getElementById ( "errors" )
79
+
77
80
async function main ( ) {
78
81
try {
79
82
info ( "Loading Python... " ) ;
80
83
pyodide = await loadPyodide ( { stdout : info , stderr : error } ) ;
81
84
info ( "done\nInstalling micropip..." ) ;
82
- await pyodide . loadPackage ( "micropip" , { errorCallback : error , messageCallback : ( ) => { } } ) ;
83
- info ( "done\nFetching current Schemascii version... " ) ;
84
- var pyproject_toml = await fetch ( "pyproject.toml" ) . then ( x => x . text ( ) ) ;
85
- var ver = / v e r s i o n = " ( [ \d . ] + ) " / . exec ( pyproject_toml ) [ 1 ] ;
86
- document . getElementById ( "version" ) . textContent = `using Schemascii version ${ ver } ` ;
87
- info ( `${ ver } \nInstalling schemascii-${ ver } ... ` ) ;
88
- await pyodide . pyimport ( "micropip" , { errorCallback : error , messageCallback : info } )
89
- . install ( `https://dragoncoder047.github.io/schemascii/dist/schemascii-${ ver } -py3-none-any.whl` ) ;
90
- schemascii_render = await pyodide . runPythonAsync ( `
91
- import warnings
92
- import schemascii
93
- def foo(*args, **kwargs):
94
- with warnings.catch_warnings(record=True) as captured_warnings:
95
- out = schemascii.render(*args, **kwargs)
96
- for warn in captured_warnings:
97
- print("warning:", warn.message)
98
- return out
99
-
100
- foo
101
- ` ) ;
102
- await setup ( ) ;
103
- console . textContent = "ready\n" ;
85
+ await pyodide . loadPackage ( "micropip" , { errorCallback : error , messageCallback : ( ) => { } } ) ;
86
+ info ( "done\n" ) ;
87
+ await pyodide . runPythonAsync ( await fetch ( "scripts/web_startup.py" ) . then ( r => r . text ( ) ) ) ;
104
88
} catch ( e ) {
105
- error ( `\n${ e . stack } \n` ) ;
89
+ error ( `\nFATAL ERROR:\ n${ e . stack } \n` ) ;
106
90
throw e ;
107
91
}
108
92
}
@@ -112,32 +96,7 @@ <h2>More Information</h2>
112
96
function error ( text ) {
113
97
errors . textContent += text ;
114
98
}
115
- async function setup ( ) {
116
- css . value = await fetch ( "schemascii_example.css" ) . then ( x => x . text ( ) ) ;
117
- style_elem . innerHTML = css . value ;
118
- css . addEventListener ( "input" , ( ) => {
119
- style_elem . innerHTML = css . value ;
120
- } ) ;
121
- var timeout = null ;
122
- source . addEventListener ( "input" , ( ) => {
123
- if ( timeout ) clearTimeout ( timeout ) ;
124
- // Debouncing
125
- timeout = setTimeout ( async ( ) => {
126
- console . textContent = "" ;
127
- errors . textContent = "" ;
128
- try {
129
- output . innerHTML = await schemascii_render ( "playground" , source . value ) ;
130
- } catch ( e ) {
131
- error ( `\n${ e . stack } \n` ) ;
132
- output . innerHTML = "" ;
133
- throw e ;
134
- }
135
- } , 100 ) ;
136
- } ) ;
137
- source . removeAttribute ( "disabled" ) ;
138
- css . removeAttribute ( "disabled" ) ;
139
- }
140
99
main ( ) ;
141
100
</ script >
142
101
143
- </ html >
102
+ </ html >
0 commit comments