feat(docs): enhance JavaScript runtime and browser-as-os content

refactor(demos): improve variable box, scope, and type annotation demos
style(demos): update visual styles and animations for better UX
docs(browser-as-os): restructure content with tables and practical examples
feat(demos): add new TypeScript and runtime environment demos
This commit is contained in:
sanbuphy
2026-02-17 01:39:59 +08:00
parent 9ee3312569
commit 47377646df
20 changed files with 8097 additions and 1310 deletions
@@ -5,85 +5,80 @@ const name = ref('张三')
const age = ref(25)
const isStudent = ref(true)
const showMessage = ref('')
const showSuccess = ref(false)
const messageType = ref('')
let messageTimer = null
const clearMessage = () => {
showMessage.value = ''
messageType.value = ''
}
const setMessage = (msg, type) => {
if (messageTimer) clearTimeout(messageTimer)
showMessage.value = msg
messageType.value = type
messageTimer = setTimeout(() => clearMessage(), 2000)
}
const modifyAge = () => {
age.value = 26
showMessage.value = '✅ let 变量可以修改'
showSuccess.value = true
setTimeout(() => {
showMessage.value = ''
showSuccess.value = false
}, 2000)
setMessage('✅ let 可以修改', 'success')
}
const modifyName = () => {
showMessage.value = '❌ const 不能重新赋值'
showSuccess.value = false
setTimeout(() => {
showMessage.value = ''
}, 2000)
setMessage('❌ const 不能改', 'error')
}
const reset = () => {
name.value = '张三'
age.value = 25
isStudent.value = true
showMessage.value = ''
clearMessage()
}
const codeLines = ref([
`const name = "张三"`,
`let age = 25`,
`const isStudent = true`
])
const executeCode = ref([])
</script>
<template>
<div class="variable-box-demo">
<h3>变量就像带名字的盒子</h3>
<div class="demo-header">
<span class="title">📦 变量就像带名字的盒子</span>
</div>
<div class="boxes-container">
<!-- 盒子 1: const name -->
<div class="variable-box const-box">
<div class="box-label">const name</div>
<div class="boxes-row">
<div class="var-box" :class="{ error: messageType === 'error' }">
<div class="box-tag const">const</div>
<div class="box-name">name</div>
<div class="box-value">{{ name }}</div>
<div class="box-icon">🔒</div>
<div class="box-lock">🔒</div>
</div>
<!-- 盒子 2: let age -->
<div class="variable-box let-box" :class="{ 'success': showSuccess && age === 26 }">
<div class="box-label">let age</div>
<div class="var-box" :class="{ success: messageType === 'success' }">
<div class="box-tag let">let</div>
<div class="box-name">age</div>
<div class="box-value">{{ age }}</div>
<div class="box-icon">🔓</div>
<div class="box-lock">🔓</div>
</div>
<!-- 盒子 3: const isStudent -->
<div class="variable-box const-box">
<div class="box-label">const isStudent</div>
<div class="var-box">
<div class="box-tag const">const</div>
<div class="box-name">isStudent</div>
<div class="box-value">{{ isStudent }}</div>
<div class="box-icon">🔒</div>
<div class="box-lock">🔒</div>
</div>
</div>
<div class="message-bubble" :class="{ 'error': !showSuccess, 'success': showSuccess }" v-if="showMessage">
<div class="message" v-if="showMessage" :class="messageType">
{{ showMessage }}
</div>
<div class="controls">
<button @click="modifyAge" class="btn-primary">修改 age 26</button>
<button @click="modifyName" class="btn-danger">修改 name 为李四</button>
<button @click="reset" class="btn-secondary">重置</button>
<button @click="modifyAge" class="btn btn-primary">修改 age</button>
<button @click="modifyName" class="btn btn-danger">修改 name</button>
<button @click="reset" class="btn btn-secondary">重置</button>
</div>
<div class="code-display">
<pre><code>const name = "张三"
let age = 25
const isStudent = true
{{ executeCode.join('\n') }}</code></pre>
<div class="code-snippet">
<code>const name = "{{ name }}"</code>
<code>let age = {{ age }}</code>
</div>
</div>
</template>
@@ -92,42 +87,59 @@ const isStudent = true
.variable-box-demo {
border: 1px solid var(--vp-c-border);
border-radius: 12px;
padding: 24px;
margin: 24px 0;
padding: 20px;
margin: 16px 0;
background: var(--vp-c-bg);
}
h3 {
margin: 0 0 16px 0;
font-size: 18px;
.demo-header {
margin-bottom: 16px;
}
.title {
font-size: 16px;
font-weight: 600;
color: var(--vp-c-text-1);
}
.boxes-container {
.boxes-row {
display: flex;
gap: 16px;
justify-content: center;
margin-bottom: 20px;
margin-bottom: 16px;
flex-wrap: wrap;
}
.variable-box {
position: relative;
width: 120px;
height: 120px;
.var-box {
width: 100px;
height: 100px;
border: 2px solid var(--vp-c-border);
border-radius: 12px;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
background: var(--vp-c-bg);
transition: all 0.3s ease;
}
.variable-box.success {
border-color: #3eaf7c;
animation: pulse 0.5s ease;
.var-box.error {
border-color: #ef4444;
background: #fef2f2;
animation: shake 0.4s ease;
}
.var-box.success {
border-color: #10b981;
background: #ecfdf5;
animation: pulse 0.4s ease;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-4px); }
75% { transform: translateX(4px); }
}
@keyframes pulse {
@@ -135,144 +147,107 @@ h3 {
50% { transform: scale(1.05); }
}
.box-label {
.box-tag {
position: absolute;
top: -12px;
left: 50%;
transform: translateX(-50%);
background: var(--vp-c-brand-1);
top: -10px;
padding: 2px 8px;
border-radius: 10px;
font-size: 10px;
font-weight: 600;
color: white;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
white-space: nowrap;
}
.let-box .box-label {
background: #42b983;
.box-tag.const {
background: #3b82f6;
}
.box-tag.let {
background: #10b981;
}
.box-name {
font-size: 13px;
color: var(--vp-c-text-2);
margin-bottom: 4px;
}
.box-value {
font-size: 24px;
font-size: 20px;
font-weight: 600;
font-family: 'Courier New', monospace;
font-family: monospace;
color: var(--vp-c-text-1);
margin-bottom: 8px;
}
.box-icon {
font-size: 16px;
.box-lock {
position: absolute;
bottom: 8px;
font-size: 12px;
}
.message-bubble {
.message {
text-align: center;
padding: 12px;
border-radius: 8px;
margin-bottom: 20px;
font-size: 14px;
padding: 10px;
border-radius: 6px;
margin-bottom: 12px;
font-size: 13px;
font-weight: 500;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
.message.error {
background: #fef2f2;
color: #dc2626;
}
.message-bubble.error {
background: #fee;
color: #c00;
}
.message-bubble.success {
background: #e8f5e9;
color: #2e7d32;
.message.success {
background: #ecfdf5;
color: #059669;
}
.controls {
display: flex;
gap: 12px;
gap: 8px;
justify-content: center;
flex-wrap: wrap;
margin-bottom: 20px;
margin-bottom: 12px;
}
button {
padding: 8px 16px;
.btn {
padding: 8px 14px;
border: none;
border-radius: 6px;
font-size: 14px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
button:active {
transform: scale(0.95);
transition: all 0.2s;
}
.btn-primary {
background: var(--vp-c-brand-1);
background: #3b82f6;
color: white;
}
.btn-primary:hover {
background: var(--vp-c-brand-2);
}
.btn-danger {
background: #f56565;
background: #ef4444;
color: white;
}
.btn-danger:hover {
background: #e53e3e;
}
.btn-secondary {
background: var(--vp-c-bg-soft);
color: var(--vp-c-text-1);
border: 1px solid var(--vp-c-border);
}
.btn-secondary:hover {
background: var(--vp-c-bg-soft-hover);
}
.code-display {
.code-snippet {
background: #1e1e1e;
border-radius: 8px;
padding: 16px;
overflow-x: auto;
border-radius: 6px;
padding: 10px 14px;
display: flex;
flex-direction: column;
gap: 4px;
}
.code-display pre {
margin: 0;
}
.code-display code {
font-family: 'Courier New', monospace;
font-size: 13px;
line-height: 1.6;
.code-snippet code {
font-family: monospace;
font-size: 12px;
color: #d4d4d4;
}
@media (max-width: 640px) {
.boxes-container {
flex-direction: column;
align-items: center;
}
.variable-box {
width: 200px;
}
.controls {
flex-direction: column;
}
button {
width: 100%;
}
}
</style>