Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Funput runs on:
- [Funput for Android](https://funput.app/android/): Vietnamese keyboard for phones and tablets; Google Play package app.funput.funput.
- [Introducing Funput](https://funput.app/blog/funput-la-gi/): Vietnamese introduction to Funput, Telex/VNI, supported devices and official downloads.
- [Telex, VNI and advanced Telex](https://funput.app/blog/telex-vni-va-telex-nang-cao/): Vietnamese typing guide with key mappings, examples and Funput advanced Telex shortcuts.
- [Practice typing Vietnamese with VNI](https://funput.app/blog/cach-go-vni/): Vietnamese-language guide with a VNI number-key chart, progressive typing exercises and answers.
- [Type Vietnamese and English together with Telex](https://funput.app/blog/go-xen-tieng-viet-va-tieng-anh/): Fix unwanted Vietnamese accents in English words with Funput's automatic English restore on Windows, macOS, Linux, Android, iPhone and iPad.
- [Set up Funput on iPhone and iPad](https://funput.app/blog/cach-bat-ban-phim-funput-iphone-ipad/): Illustrated keyboard setup, Full Access explanation and troubleshooting.
- [Install Funput on Windows](https://funput.app/blog/cai-funput-windows-10-11/): Windows 10/11 Microsoft Store installation, typing methods, system tray, troubleshooting, Store updates and optional portable setup.
Expand Down
299 changes: 299 additions & 0 deletions src/components/blog/VniExercise.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
---
interface Props {
number: number;
title: string;
target: string;
hint: string;
answers: string[];
}

const { number, title, target, hint, answers } = Astro.props;
const inputId = `vni-exercise-${number}-input`;
const hintId = `vni-exercise-${number}-hint`;
---

<vni-exercise class="exercise-shell" data-answers={JSON.stringify(answers)} data-target={target}>
<details class="exercise-card">
<summary class="exercise-summary">
<span class="exercise-number" aria-hidden="true">
{number}
</span>
<span class="exercise-prompt">
<span class="exercise-title">
<span class="sr-only">Bài {number}. </span>
{title}
</span>
<span class="exercise-target">{target}</span>
</span>
<span class="exercise-chevron" aria-hidden="true"></span>
</summary>
<div class="exercise-body">
<p id={hintId} class="exercise-hint">
<strong>Gợi ý</strong> {hint}
</p>
<form class="exercise-form" hidden>
<label for={inputId}>
Chuỗi phím VNI <span class="sr-only">cho bài {number}</span>
</label>
<div class="exercise-controls">
<input
id={inputId}
type="text"
autocomplete="off"
autocapitalize="off"
autocorrect="off"
spellcheck="false"
enterkeyhint="done"
aria-describedby={hintId}
/>
<button type="submit">Kiểm tra</button>
</div>
<p class="exercise-status" role="status" aria-atomic="true"></p>
</form>
<details class="exercise-answer">
<summary>Xem đáp án</summary>
<p>
<kbd>{answers[0]}</kbd> <span aria-hidden="true">→</span> <strong>{target}</strong>
</p>
</details>
</div>
</details>
</vni-exercise>

<script>
function normalizeKeys(value: string) {
return value.trim().toLowerCase().replace(/\s+/g, ' ');
}

class VniExercise extends HTMLElement {
connectedCallback() {
const form = this.querySelector<HTMLFormElement>('.exercise-form');
const input = form?.querySelector('input');
const status = form?.querySelector<HTMLElement>('.exercise-status');
if (!form || !input || !status || !form.hidden) return;

const answers: string[] = JSON.parse(this.dataset.answers ?? '[]');
const validKeys = new Set(answers.map(normalizeKeys));

form.addEventListener('submit', (event) => {
event.preventDefault();
const attempt = normalizeKeys(input.value);
const correct = validKeys.has(attempt);
this.dataset.result = correct ? 'correct' : 'retry';

if (correct) {
input.removeAttribute('aria-invalid');
status.textContent = `Đúng rồi! Bạn đã gõ được “${this.dataset.target}”.`;
} else {
input.setAttribute('aria-invalid', 'true');
status.textContent = attempt
? 'Chưa đúng. Xem gợi ý rồi thử lại.'
: 'Nhập chuỗi phím VNI để kiểm tra.';
}
});

input.addEventListener('input', () => {
input.removeAttribute('aria-invalid');
status.textContent = '';
delete this.dataset.result;
});

form.hidden = false;
}
}

customElements.define('vni-exercise', VniExercise);
</script>

<style>
.exercise-shell {
display: block;
margin-block: 10px;
}

.exercise-card {
border: 1px solid #ded4c5;
border-radius: 13px;
background: #fffbf3;
}

.exercise-card[open] {
border-color: #bf8a71;
}

.exercise-summary {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: clamp(10px, 2.5vw, 16px);
padding: 12px clamp(12px, 3vw, 20px);
border-radius: 12px;
cursor: pointer;
list-style: none;
}

.exercise-summary::-webkit-details-marker {
display: none;
}

.exercise-summary:hover,
.exercise-card[open] > .exercise-summary {
background: #f7ebde;
}

.exercise-card[open] > .exercise-summary {
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}

.exercise-summary:focus-visible {
outline-offset: 3px;
}

.exercise-number {
display: grid;
width: 36px;
height: 36px;
place-items: center;
border: 1px solid #e6bca5;
border-radius: 8px;
background: #f8dfd0;
color: #87341f;
font-size: 14px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}

.exercise-prompt {
display: grid;
gap: 2px;
overflow-wrap: anywhere;
}

.exercise-title {
color: #68534a;
font-size: 12px;
font-weight: 700;
line-height: 1.35;
}

.exercise-target {
color: var(--ink);
font-family: var(--font-display);
font-size: clamp(18px, 3.8vw, 22px);
font-weight: 700;
line-height: 1.32;
}

.exercise-chevron {
width: 9px;
height: 9px;
margin-inline: 4px;
transform: rotate(45deg);
border-right: 2px solid #8b442d;
border-bottom: 2px solid #8b442d;
}

.exercise-card[open] .exercise-chevron {
transform: rotate(225deg);
}

.exercise-body {
padding: 13px clamp(12px, 3vw, 20px) 15px;
border-top: 1px solid #ead9c8;
}

.exercise-body .exercise-hint {
margin: 0 0 12px;
color: #544941;
font-size: 14px;
line-height: 1.55;
}

.exercise-hint strong {
margin-right: 4px;
}

.exercise-form label {
display: block;
margin-bottom: 5px;
font-size: 13px;
font-weight: 700;
}

.exercise-controls {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 8px;
}

.exercise-controls input,
.exercise-controls button {
min-height: 44px;
border: 1px solid;
border-radius: 8px;
}

.exercise-controls input {
min-width: 0;
width: 100%;
padding: 8px 10px;
border-color: #9f8471;
background: #fffdf8;
font-family: ui-monospace, monospace;
font-size: 16px;
line-height: 1.4;
}

.exercise-controls button {
padding: 8px 12px;
border-color: #8b371f;
background: #a13f25;
color: #fffaf2;
font-size: 14px;
font-weight: 700;
cursor: pointer;
}

.exercise-controls button:hover {
background: #83321d;
}

.exercise-form .exercise-status {
min-height: 1.4em;
margin: 7px 0 4px;
font-size: 13px;
font-weight: 700;
line-height: 1.4;
}

.exercise-shell[data-result='retry'] .exercise-status {
color: #883720;
}

.exercise-shell[data-result='correct'] .exercise-status {
color: #36512d;
}

.exercise-answer summary {
width: fit-content;
padding-block: 5px;
color: #83321d;
font-size: 13px;
font-weight: 700;
cursor: pointer;
}

.exercise-answer p {
margin: 6px 0 0;
overflow-wrap: anywhere;
font-size: 14px;
}

.exercise-answer kbd {
display: inline;
padding: 2px 5px;
border-radius: 4px;
background: #edeadc;
}
</style>
Loading
Loading