11<script setup lang="ts">
22import { onMounted , ref } from ' vue'
33import Prism from ' vue-prism-component'
4- // @ts-ignore
54import PrismJS from ' prismjs' ;
65const { highlight, languages } = PrismJS
76
87import { Elysia } from ' elysia'
9- import { text } from ' stream/consumers'
108
119let code = ` const app = new Elysia()
1210 .get('/', () => 'Hello!')
@@ -18,7 +16,6 @@ export default app
1816`
1917
2018function saveCaretPosition(context ) {
21- // @ts-ignore
2219 const selection = window .getSelection ()
2320 const range = selection .getRangeAt (0 )
2421 range .setStart (context , 0 )
@@ -28,15 +25,13 @@ function saveCaretPosition(context) {
2825 const pos = getTextNodeAtPosition (context , len )
2926 selection .removeAllRanges ()
3027
31- // @ts-ignore
3228 const range = new Range ()
3329 range .setStart (pos .node , pos .position )
3430 selection .addRange (range )
3531 }
3632}
3733
3834function nextCaretPosition(context ) {
39- // @ts-ignore
4035 const selection = window .getSelection ()
4136 const range = selection .getRangeAt (0 )
4237 range .setStart (context , 0 )
@@ -46,28 +41,23 @@ function nextCaretPosition(context) {
4641 const pos = getTextNodeAtPosition (context , len )
4742 selection .removeAllRanges ()
4843
49- // @ts-ignore
5044 const range = new Range ()
5145 range .setStart (pos .node , pos .position )
5246 selection .addRange (range )
5347 }
5448}
5549
5650function getTextNodeAtPosition(root , index ) {
57- // @ts-ignore
5851 const NODE_TYPE = NodeFilter .SHOW_TEXT
59- // @ts-ignore
6052 const treeWalker = document .createTreeWalker (
6153 root ,
6254 NODE_TYPE ,
6355 function next(elem ) {
6456 if (index > elem .textContent .length ) {
6557 index -= elem .textContent .length
66- // @ts-ignore
6758 return NodeFilter .FILTER_REJECT
6859 }
6960
70- // @ts-ignore
7161 return NodeFilter .FILTER_ACCEPT
7262 }
7363 )
@@ -84,7 +74,7 @@ let response = ref('Hello from Elysia!')
8474
8575let instance = new Elysia ()
8676 .get (' /' , () => ' Hello!' )
87- .get (' /hello' , () => ' Hello from Elysia!' )
77+ .get (' /hello' , () => ' Hello from Elysia!' ) as Elysia < any , any >
8878
8979let editorError = ref (undefined as Error | undefined )
9080let responseError = ref (undefined as Error | undefined )
@@ -113,8 +103,7 @@ const execute = async () => {
113103}
114104
115105onMounted (() => {
116- // @ts-ignore
117- const editor = document .querySelector (' pre.elysia-editor' )
106+ const editor = document .querySelector <HTMLElement >(' pre.elysia-editor' )
118107
119108 function rehighlight(event ) {
120109 const restore = saveCaretPosition (this )
@@ -135,6 +124,7 @@ onMounted(() => {
135124 ' export default is missing'
136125 ))
137126
127+
138128 instance = new Function (
139129 ' Elysia' ,
140130 `
@@ -165,63 +155,46 @@ onMounted(() => {
165155 </script >
166156
167157<template >
168- <article
169- class =" flex flex-col justify-center items-center w-full max-w-6xl mx-auto mt-6 md:my-12"
170- >
158+ <article class =" flex flex-col justify-center items-center w-full max-w-6xl mx-auto mt-6 md:my-12" >
171159 <h2
172- class =" text-6xl w-full text-left sm:text-center font-bold !leading-tight text-transparent bg-clip-text bg-gradient-to-br from-blue-400 to-violet-400 mb-6"
173- >
160+ class =" text-6xl w-full text-left sm:text-center font-bold !leading-tight text-transparent bg-clip-text bg-gradient-to-br from-blue-400 to-violet-400 mb-6" >
174161 Try it out
175162 </h2 >
176163
177- <p
178- class =" text-xl md:text-2xl leading-relaxed text-gray-400 text-left md:text-center w-full max-w-2xl"
179- >
164+ <p class =" text-xl md:text-2xl leading-relaxed text-gray-400 text-left md:text-center w-full max-w-2xl" >
180165 Being WinterCG compliant, Elysia can run in your browser!
181166 <br />
182167 Edit the code and see live update immediately.
183168 </p >
184169
185170 <aside class =" flex flex-col md:flex-row justify-center items-center w-full max-w-6xl gap-8 my-8" >
186- <section
187- class =" flex flex-col w-full h-96 border dark:border-slate-700 bg-white dark:bg-slate-800 rounded-2xl"
188- >
171+ <section class =" flex flex-col w-full h-96 border dark:border-slate-700 bg-white dark:bg-slate-800 rounded-2xl" >
189172 <div class =" mockup-window flex relative w-full h-full shadow-xl" >
190173 <Prism
191174 class =" elysia-editor block !bg-transparent !text-base !font-mono rounded-xl w-full max-w-xl h-full !pt-0 !px-2 outline-none"
192- language =" typescript"
193- contenteditable =" true"
194- >
175+ language =" typescript" contenteditable =" true" >
195176 {{ code }}
196177 </Prism >
197178
198- <footer
199- v-if =" editorError"
200- class =" absolute bottom-0 flex flex-col w-full max-h-40 overflow-y-auto text-white font-medium px-4 py-2 bg-red-500"
201- >
179+ <footer v-if =" editorError"
180+ class =" absolute bottom-0 flex flex-col w-full max-h-40 overflow-y-auto text-white font-medium px-4 py-2 bg-red-500" >
202181 {{ editorError.cause }}
203182 {{ editorError.stack }}
204183 </footer >
205184 </div >
206185 </section >
207- <div class =" w-full mockup-browser h-96 shadow-xl border dark:border-slate-700 bg-white dark:bg-slate-800 max-w-full" >
186+ <div
187+ class =" w-full mockup-browser h-96 shadow-xl border dark:border-slate-700 bg-white dark:bg-slate-800 max-w-full" >
208188 <div class =" mockup-browser-toolbar" >
209189 <form class =" input font-medium !bg-gray-100 dark:!bg-slate-700" @submit.prevent =" execute" >
210190 <span class =" text-gray-400 dark:text-gray-300" >localhost</span >
211- <input
212- class =" absolute"
213- type =" text"
214- v-model =" url"
215- v-on:blur =" execute"
216- />
191+ <input class =" absolute" type =" text" v-model =" url" v-on:blur =" execute" />
217192 </form >
218193 </div >
219194 <div class =" flex px-4" >{{ response }}</div >
220195
221- <footer
222- v-if =" responseError"
223- class =" absolute bottom-0 flex flex-col w-full max-h-40 overflow-y-auto text-white font-medium px-4 py-2 bg-red-500"
224- >
196+ <footer v-if =" responseError"
197+ class =" absolute bottom-0 flex flex-col w-full max-h-40 overflow-y-auto text-white font-medium px-4 py-2 bg-red-500" >
225198 {{ responseError.cause }}
226199 {{ responseError.stack }}
227200 </footer >
0 commit comments