1
1
<script setup lang="ts">
2
2
import { onMounted , ref } from ' vue'
3
3
import Prism from ' vue-prism-component'
4
- // @ts-ignore
5
4
import PrismJS from ' prismjs' ;
6
5
const { highlight, languages } = PrismJS
7
6
8
7
import { Elysia } from ' elysia'
9
- import { text } from ' stream/consumers'
10
8
11
9
let code = ` const app = new Elysia()
12
10
.get('/', () => 'Hello!')
@@ -18,7 +16,6 @@ export default app
18
16
`
19
17
20
18
function saveCaretPosition(context ) {
21
- // @ts-ignore
22
19
const selection = window .getSelection ()
23
20
const range = selection .getRangeAt (0 )
24
21
range .setStart (context , 0 )
@@ -28,15 +25,13 @@ function saveCaretPosition(context) {
28
25
const pos = getTextNodeAtPosition (context , len )
29
26
selection .removeAllRanges ()
30
27
31
- // @ts-ignore
32
28
const range = new Range ()
33
29
range .setStart (pos .node , pos .position )
34
30
selection .addRange (range )
35
31
}
36
32
}
37
33
38
34
function nextCaretPosition(context ) {
39
- // @ts-ignore
40
35
const selection = window .getSelection ()
41
36
const range = selection .getRangeAt (0 )
42
37
range .setStart (context , 0 )
@@ -46,28 +41,23 @@ function nextCaretPosition(context) {
46
41
const pos = getTextNodeAtPosition (context , len )
47
42
selection .removeAllRanges ()
48
43
49
- // @ts-ignore
50
44
const range = new Range ()
51
45
range .setStart (pos .node , pos .position )
52
46
selection .addRange (range )
53
47
}
54
48
}
55
49
56
50
function getTextNodeAtPosition(root , index ) {
57
- // @ts-ignore
58
51
const NODE_TYPE = NodeFilter .SHOW_TEXT
59
- // @ts-ignore
60
52
const treeWalker = document .createTreeWalker (
61
53
root ,
62
54
NODE_TYPE ,
63
55
function next(elem ) {
64
56
if (index > elem .textContent .length ) {
65
57
index -= elem .textContent .length
66
- // @ts-ignore
67
58
return NodeFilter .FILTER_REJECT
68
59
}
69
60
70
- // @ts-ignore
71
61
return NodeFilter .FILTER_ACCEPT
72
62
}
73
63
)
@@ -84,7 +74,7 @@ let response = ref('Hello from Elysia!')
84
74
85
75
let instance = new Elysia ()
86
76
.get (' /' , () => ' Hello!' )
87
- .get (' /hello' , () => ' Hello from Elysia!' )
77
+ .get (' /hello' , () => ' Hello from Elysia!' ) as Elysia < any , any >
88
78
89
79
let editorError = ref (undefined as Error | undefined )
90
80
let responseError = ref (undefined as Error | undefined )
@@ -113,8 +103,7 @@ const execute = async () => {
113
103
}
114
104
115
105
onMounted (() => {
116
- // @ts-ignore
117
- const editor = document .querySelector (' pre.elysia-editor' )
106
+ const editor = document .querySelector <HTMLElement >(' pre.elysia-editor' )
118
107
119
108
function rehighlight(event ) {
120
109
const restore = saveCaretPosition (this )
@@ -135,6 +124,7 @@ onMounted(() => {
135
124
' export default is missing'
136
125
))
137
126
127
+
138
128
instance = new Function (
139
129
' Elysia' ,
140
130
`
@@ -165,63 +155,46 @@ onMounted(() => {
165
155
</script >
166
156
167
157
<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" >
171
159
<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" >
174
161
Try it out
175
162
</h2 >
176
163
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" >
180
165
Being WinterCG compliant, Elysia can run in your browser!
181
166
<br />
182
167
Edit the code and see live update immediately.
183
168
</p >
184
169
185
170
<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" >
189
172
<div class =" mockup-window flex relative w-full h-full shadow-xl" >
190
173
<Prism
191
174
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" >
195
176
{{ code }}
196
177
</Prism >
197
178
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" >
202
181
{{ editorError.cause }}
203
182
{{ editorError.stack }}
204
183
</footer >
205
184
</div >
206
185
</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" >
208
188
<div class =" mockup-browser-toolbar" >
209
189
<form class =" input font-medium !bg-gray-100 dark:!bg-slate-700" @submit.prevent =" execute" >
210
190
<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" />
217
192
</form >
218
193
</div >
219
194
<div class =" flex px-4" >{{ response }}</div >
220
195
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" >
225
198
{{ responseError.cause }}
226
199
{{ responseError.stack }}
227
200
</footer >
0 commit comments