2828 color : red;
2929 }
3030
31- a , a : visited {
31+ a ,
32+ a : visited {
3233 color : blue;
3334 }
3435
3536 @media screen and (prefers-color-scheme : dark) {
36- body , textarea {
37+
38+ body ,
39+ textarea {
3740 color : white;
3841 background : black;
3942 }
40- a , a : visited {
43+
44+ a ,
45+ a : visited {
4146 color : magenta;
4247 }
4348 }
4752
4853 < body >
4954 < h1 > Schemascii Playground</ h1 >
50- < h2 id ="version "> Loading version... </ h2 >
55+ < h2 > using schemascii version < select id ="version "> </ select > </ h2 >
5156 < div class ="flex row ">
5257 < div class ="flex column ">
5358 < h2 > Schemascii Source</ h2 > < textarea id ="schemascii " disabled > </ textarea >
@@ -63,46 +68,25 @@ <h2>Messages</h2>
6368 < h2 > Errors</ h2 >
6469 < pre id ="errors "> </ pre >
6570 < 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 >
6773 </ body >
6874 < script >
69- // cSpell:ignore pyodide pyproject pyimport
75+ // cSpell:ignore pyodide pyproject
7076 var pyodide ;
71- var output = document . getElementById ( "output" ) ;
72- var css = document . getElementById ( "css" ) ;
7377 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+
7780 async function main ( ) {
7881 try {
7982 info ( "Loading Python... " ) ;
8083 pyodide = await loadPyodide ( { stdout : info , stderr : error } ) ;
8184 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 ( ) ) ) ;
10488 } catch ( e ) {
105- error ( `\n${ e . stack } \n` ) ;
89+ error ( `\nFATAL ERROR:\ n${ e . stack } \n` ) ;
10690 throw e ;
10791 }
10892 }
@@ -112,32 +96,7 @@ <h2>More Information</h2>
11296 function error ( text ) {
11397 errors . textContent += text ;
11498 }
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- }
14099 main ( ) ;
141100 </ script >
142101
143- </ html >
102+ </ html >
0 commit comments