|
| 1 | +<script setup> |
| 2 | +import { reactive } from "vue"; |
| 3 | +
|
| 4 | +const props = defineProps([ |
| 5 | + "result", |
| 6 | + "solution", |
| 7 | + "time", |
| 8 | + "tokens", |
| 9 | + "html", |
| 10 | + "latex", |
| 11 | + "error", |
| 12 | +]); |
| 13 | +
|
| 14 | +const tabs = [ |
| 15 | + { id: "result", title: "Result" }, |
| 16 | + { id: "tokens", title: "Tokens" }, |
| 17 | + { id: "html", title: "HTML" }, |
| 18 | + { id: "latex", title: "LaTeX" }, |
| 19 | +]; |
| 20 | +
|
| 21 | +const state = reactive({ |
| 22 | + active: "result", |
| 23 | +}); |
| 24 | +</script> |
| 25 | + |
| 26 | +<template> |
| 27 | + <div class="output"> |
| 28 | + <div class="tabs"> |
| 29 | + <button v-for="tab in tabs" :key="tab.id" :class="{ active: state.active === tab.id }" |
| 30 | + @click="state.active = tab.id"> |
| 31 | + {{ tab.title }} |
| 32 | + </button> |
| 33 | + </div> |
| 34 | + |
| 35 | + <div class="tab-content"> |
| 36 | + <!-- Result Tab --> |
| 37 | + <div v-show="state.active === 'result'"> |
| 38 | + <div class="output-group"> |
| 39 | + <h3>Result</h3> |
| 40 | + <div :class="[ |
| 41 | + 'output-content', |
| 42 | + props.error ? 'error' : 'result', |
| 43 | + ]"> |
| 44 | + <div v-if="props.error"> |
| 45 | + {{ props.error?.toString() }} |
| 46 | + </div> |
| 47 | + <textarea v-else-if="props.result" rows="15" |
| 48 | + style="width: 100%;background: transparent;">{{ JSON.stringify(props.result, null, 4) }}</textarea> |
| 49 | + <span v-else>Ready to evaluate...</span> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + |
| 53 | + <div class="output-group"> |
| 54 | + <h3>Solution</h3> |
| 55 | + <div class="output-content" v-html="props.solution"></div> |
| 56 | + </div> |
| 57 | + |
| 58 | + <div class="output-group"> |
| 59 | + <h3>Execution Info</h3> |
| 60 | + <div class="output-content"> |
| 61 | + <strong>Execution Time:</strong> {{ props.time }}ms |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + |
| 66 | + <!-- Tokens Tab --> |
| 67 | + <div v-show="state.active === 'tokens'"> |
| 68 | + <div class="output-group"> |
| 69 | + <h3>Token Stream</h3> |
| 70 | + <div class="output-content token-list"> |
| 71 | + <div v-for="(t, i) in props.tokens" :key="i" class="token" |
| 72 | + :title="`Type: ${t.type}, Line: ${t.line}, Column: ${t.column}`"> |
| 73 | + <span>{{ t.type }}({{ t.value }})</span> |
| 74 | + <span>{{ t.line }}:{{ t.column }}</span> |
| 75 | + </div> |
| 76 | + <span v-if="!props.tokens.length"> |
| 77 | + No tokens to display |
| 78 | + </span> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + |
| 83 | + <!-- HTML Tab --> |
| 84 | + <div v-show="state.active === 'html'"> |
| 85 | + <div class="output-group"> |
| 86 | + <h3>HTML Render</h3> |
| 87 | + <div v-html="props.html"></div> |
| 88 | + </div> |
| 89 | + <div class="output-group"> |
| 90 | + <h3>HTML Code</h3> |
| 91 | + <div class="output-content"> |
| 92 | + <textarea readonly rows="15" style="width: 100%">{{ |
| 93 | + props.html |
| 94 | + }}</textarea> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + |
| 99 | + <!-- LaTeX Tab --> |
| 100 | + <div v-show="state.active === 'latex'"> |
| 101 | + <div class="output-group"> |
| 102 | + <h3>LaTeX Output</h3> |
| 103 | + <div class="output-content"> |
| 104 | + <textarea readonly rows="15" style="width: 100%">{{ |
| 105 | + props.latex |
| 106 | + }}</textarea> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | +</template> |
| 113 | + |
| 114 | +<style scoped> |
| 115 | +.output { |
| 116 | + background: var(--vp-c-bg); |
| 117 | + /* border: 1px solid var(--vp-c-divider); */ |
| 118 | + /* border-left: 0; */ |
| 119 | +} |
| 120 | +
|
| 121 | +.tabs { |
| 122 | + display: flex; |
| 123 | + border-bottom: 1px solid var(--vp-c-divider); |
| 124 | + background: var(--vp-c-bg-alt); |
| 125 | +} |
| 126 | +
|
| 127 | +.tabs button { |
| 128 | + padding: 15px 20px; |
| 129 | + border: none; |
| 130 | + background: none; |
| 131 | + color: var(--vp-c-text-1); |
| 132 | + font-weight: 500; |
| 133 | + cursor: pointer; |
| 134 | + border-bottom: 2px solid transparent; |
| 135 | + transition: all 0.2s ease; |
| 136 | +} |
| 137 | +
|
| 138 | +.tabs button.active { |
| 139 | + color: var(--vp-c-brand-1); |
| 140 | + border-bottom-color: var(--vp-c-brand-1); |
| 141 | +} |
| 142 | +
|
| 143 | +.tab-content { |
| 144 | + padding: 20px; |
| 145 | + overflow-y: auto; |
| 146 | +} |
| 147 | +
|
| 148 | +.output-group { |
| 149 | + margin-bottom: 24px; |
| 150 | + /* max-height: 75vh; */ |
| 151 | +} |
| 152 | +
|
| 153 | +.output-group h3 { |
| 154 | + font-size: 14px; |
| 155 | + font-weight: 600; |
| 156 | + color: var(--vp-c-text-2); |
| 157 | + margin-bottom: 12px; |
| 158 | + text-transform: uppercase; |
| 159 | + letter-spacing: 0.05em; |
| 160 | +} |
| 161 | +
|
| 162 | +.output-content { |
| 163 | + background: var(--vp-c-bg-soft); |
| 164 | + border: 1px solid var(--vp-c-divider); |
| 165 | + border-radius: 8px; |
| 166 | + padding: 16px; |
| 167 | + font-family: var(--vp-font-family-mono); |
| 168 | + font-size: 14px; |
| 169 | + line-height: 1.6; |
| 170 | + overflow-x: auto; |
| 171 | + min-height: 60px; |
| 172 | +} |
| 173 | +
|
| 174 | +.output-content.result { |
| 175 | + background: var(--vp-c-success-soft); |
| 176 | + border-color: var(--vp-c-success-soft); |
| 177 | + color: var(--vp-c-green-1); |
| 178 | + font-size: 18px; |
| 179 | + font-weight: 600; |
| 180 | +} |
| 181 | +
|
| 182 | +.output-content.error { |
| 183 | + background: var(--vp-c-danger-soft); |
| 184 | + border-color: var(--vp-c-danger-soft); |
| 185 | + color: var(--vp-c-danger); |
| 186 | +} |
| 187 | +
|
| 188 | +.token-list { |
| 189 | + display: grid; |
| 190 | + gap: 1rem; |
| 191 | +} |
| 192 | +
|
| 193 | +.token { |
| 194 | + display: block; |
| 195 | + padding: 4px 8px; |
| 196 | + border-radius: 4px; |
| 197 | + font-weight: 500; |
| 198 | + clear: both; |
| 199 | +} |
| 200 | +
|
| 201 | +.token>span:first-child { |
| 202 | + float: left; |
| 203 | +} |
| 204 | +
|
| 205 | +.token>span:last-child { |
| 206 | + float: right; |
| 207 | +} |
| 208 | +</style> |
0 commit comments