11<!DOCTYPE html>
2+
23< html lang ="es ">
4+
35< head >
6+
47 < meta charset ="UTF-8 ">
58 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6- < title > Edge Python Code Edior</ title >
9+
10+ < title > Edge Python Demo</ title >
11+
712 < script src ="https://cdn.tailwindcss.com "> </ script >
13+ < script type ="module " src ="./main.js " defer > </ script >
14+
815 < link rel ="icon " type ="image/svg " href ="icon.svg ">
16+
917 < style >
1018 .no-scrollbar ::-webkit-scrollbar { display : none; }
1119 .no-scrollbar { -ms-overflow-style : none; scrollbar-width : none; }
1523 line-height : 1.625 ;
1624 }
1725 </ style >
26+
1827</ head >
28+
1929< body class ="bg-[#161616] text-[#ffffff] h-screen flex flex-col p-4 gap-4 overflow-hidden ">
2030
2131 < div class ="w-full bg-[#222222] border border-[#2d2d2d] rounded-md flex flex-col flex-[70] basis-0 overflow-hidden ">
5565 < div id ="term " class ="code-font text-sm p-3 text-[#c2c2c2] flex-1 overflow-y-auto no-scrollbar whitespace-pre-wrap "> </ div >
5666 </ div >
5767
58- < script >
59- const SZ = 1 << 20 ;
60-
61- const ed = document . getElementById ( 'ed' ) ;
62- const ln = document . getElementById ( 'ln' ) ;
63- const btn = document . getElementById ( 'run' ) ;
64- const term = document . getElementById ( 'term' ) ;
65- const status = document . getElementById ( 'status' ) ;
66-
67- let wasm = null ;
68-
69- async function loadWasm ( ) {
70- try {
71- status . textContent = 'loading wasm…' ;
72- const res = await fetch ( './compiler_lib.wasm' ) ;
73- if ( ! res . ok ) throw new Error ( `HTTP ${ res . status } ` ) ;
74- const { instance } = await WebAssembly . instantiateStreaming ( res , { } ) ;
75- wasm = instance . exports ;
76- btn . disabled = false ;
77- status . textContent = 'ready' ;
78- status . className = 'ml-auto text-emerald-500' ;
79- } catch ( e ) {
80- status . textContent = `load failed: ${ e . message } ` ;
81- status . className = 'ml-auto text-red-500' ;
82- }
83- }
84-
85- function runCode ( ) {
86- if ( ! wasm ) return ;
87- const srcBytes = new TextEncoder ( ) . encode ( ed . value ) ;
88- if ( srcBytes . length > SZ ) {
89- term . textContent = `error: source exceeds ${ SZ } bytes` ;
90- return ;
91- }
92- const mem = new Uint8Array ( wasm . memory . buffer ) ;
93- mem . set ( srcBytes , wasm . src_ptr ( ) ) ;
94- const outLen = wasm . run ( srcBytes . length ) ;
95- const outView = new Uint8Array ( wasm . memory . buffer , wasm . out_ptr ( ) , outLen ) ;
96- term . textContent = new TextDecoder ( ) . decode ( outView ) ;
97- }
98-
99- btn . addEventListener ( 'click' , runCode ) ;
100-
101- ed . addEventListener ( 'keydown' , ( e ) => {
102- if ( ( e . ctrlKey || e . metaKey ) && e . key === 'Enter' ) {
103- e . preventDefault ( ) ;
104- runCode ( ) ;
105- return ;
106- }
107- if ( e . key === 'Enter' && ed . value . split ( '\n' ) . length >= 99 ) {
108- e . preventDefault ( ) ;
109- }
110- } ) ;
111-
112- const sync = ( ) => {
113- let lines = ed . value . split ( '\n' ) ;
114- if ( lines . length > 99 ) {
115- ed . value = lines . slice ( 0 , 99 ) . join ( '\n' ) ;
116- lines = ed . value . split ( '\n' ) ;
117- }
118- ln . textContent = Array . from ( { length : lines . length } , ( _ , i ) =>
119- String ( i + 1 ) . padStart ( 2 , '0' )
120- ) . join ( '\n' ) ;
121- ln . scrollTop = ed . scrollTop ;
122- } ;
123-
124- ed . oninput = sync ;
125- ed . onscroll = sync ;
126-
127- sync ( ) ;
128- loadWasm ( ) ;
129- </ script >
130-
13168</ body >
69+
13270</ html >
0 commit comments