DanVP commited on
Commit
4f78790
·
verified ·
1 Parent(s): 10b99ec

feat: add quick-start text samples

Browse files
Files changed (4) hide show
  1. app.js +37 -0
  2. dist-manifest.json +7 -7
  3. index.html +9 -0
  4. styles.css +53 -0
app.js CHANGED
@@ -11,6 +11,22 @@ import { prepareGuardedTopK } from './guarded-topk.js';
11
  // to per-step on both builds, 12x fewer GPU<->CPU syncs).
12
  const SPEC_WINDOW = 16;
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  const $ = (id) => document.getElementById(id);
15
  const status = (message, state = '', short = message) => {
16
  $('status').textContent = message;
@@ -48,6 +64,22 @@ function updateInputState() {
48
  $('clear').disabled = !value || $('run').disabled && document.body.classList.contains('running');
49
  }
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  function setProgress(done, total) {
52
  const active = total > 0 && done < total;
53
  $('progress').hidden = !active;
@@ -92,6 +124,9 @@ async function warmEngine(ctx, weights, pieceTable, bias, tok) {
92
 
93
  async function boot() {
94
  $('input').addEventListener('input', updateInputState);
 
 
 
95
  $('clear').addEventListener('click', () => {
96
  $('input').value = '';
97
  $('input').focus();
@@ -150,6 +185,7 @@ async function boot() {
150
  $('run').disabled = true;
151
  $('clear').disabled = true;
152
  $('copy').disabled = true;
 
153
  copyText = '';
154
  status(`Đang polish · 0/${jobs.length} dòng`, 'running', `Đang chạy · 0/${jobs.length}`);
155
  setProgress(0, jobs.length);
@@ -217,6 +253,7 @@ async function boot() {
217
  } finally {
218
  setProgress(1, 1);
219
  $('run').disabled = false;
 
220
  updateInputState();
221
  }
222
  };
 
11
  // to per-step on both builds, 12x fewer GPU<->CPU syncs).
12
  const SPEC_WINDOW = 16;
13
 
14
+ const SAMPLES = Object.freeze({
15
+ story: [
16
+ 'Hắn đối với chuyện này cũng không có biện pháp nào.',
17
+ 'Nghe được lời này, mọi người ở đây đều là hơi sững sờ.',
18
+ ].join('\n'),
19
+ dialogue: [
20
+ '“Ngươi xác định muốn cùng ta động thủ?” hắn nhíu mày hỏi.',
21
+ '“Nếu đã như vậy, vậy thì không cần nhiều lời.” nàng nhàn nhạt nói.',
22
+ ].join('\n'),
23
+ action: [
24
+ 'Kiếm quang xẹt qua, đem trước mặt cự thạch sinh sinh bổ thành hai nửa.',
25
+ 'Đối mặt một chưởng này, hắn không lùi mà tiến tới.',
26
+ 'Chỉ thấy thân hình hắn lóe lên, trong nháy mắt liền xuất hiện tại đối phương trước người.',
27
+ ].join('\n'),
28
+ });
29
+
30
  const $ = (id) => document.getElementById(id);
31
  const status = (message, state = '', short = message) => {
32
  $('status').textContent = message;
 
64
  $('clear').disabled = !value || $('run').disabled && document.body.classList.contains('running');
65
  }
66
 
67
+ function setSampleButtonsDisabled(disabled) {
68
+ for (const button of document.querySelectorAll('[data-sample]')) {
69
+ button.disabled = disabled;
70
+ }
71
+ }
72
+
73
+ function loadSample(name) {
74
+ const value = SAMPLES[name];
75
+ if (!value) return;
76
+ const input = $('input');
77
+ input.value = value;
78
+ updateInputState();
79
+ input.focus();
80
+ input.setSelectionRange(value.length, value.length);
81
+ }
82
+
83
  function setProgress(done, total) {
84
  const active = total > 0 && done < total;
85
  $('progress').hidden = !active;
 
124
 
125
  async function boot() {
126
  $('input').addEventListener('input', updateInputState);
127
+ for (const button of document.querySelectorAll('[data-sample]')) {
128
+ button.addEventListener('click', () => loadSample(button.dataset.sample));
129
+ }
130
  $('clear').addEventListener('click', () => {
131
  $('input').value = '';
132
  $('input').focus();
 
185
  $('run').disabled = true;
186
  $('clear').disabled = true;
187
  $('copy').disabled = true;
188
+ setSampleButtonsDisabled(true);
189
  copyText = '';
190
  status(`Đang polish · 0/${jobs.length} dòng`, 'running', `Đang chạy · 0/${jobs.length}`);
191
  setProgress(0, jobs.length);
 
253
  } finally {
254
  setProgress(1, 1);
255
  $('run').disabled = false;
256
+ setSampleButtonsDisabled(false);
257
  updateInputState();
258
  }
259
  };
dist-manifest.json CHANGED
@@ -10,8 +10,8 @@
10
  },
11
  {
12
  "path": "app.js",
13
- "bytes": 10090,
14
- "sha256": "c7b340857785fa7faf19afc08aa34f6de8ad217b5b228c2d7bfe8b4f21fc4286"
15
  },
16
  {
17
  "path": "decode-guard.js",
@@ -270,8 +270,8 @@
270
  },
271
  {
272
  "path": "index.html",
273
- "bytes": 3221,
274
- "sha256": "2e1c55c247483577699727f1818e68d16ea4abfdaef8137f697529c926c99871"
275
  },
276
  {
277
  "path": "model/vp2vi/piece_table.json",
@@ -290,8 +290,8 @@
290
  },
291
  {
292
  "path": "styles.css",
293
- "bytes": 9004,
294
- "sha256": "4e798236d0169daa6b6467f3f98f8e3aba35cb02124a7ee322848f4eb78ce88c"
295
  },
296
  {
297
  "path": "weights/manifest.json",
@@ -319,5 +319,5 @@
319
  "sha256": "030b8178c17fc02b3ed38f3d2248ee2565065c39cd38e549a7fed0d58cde12e6"
320
  }
321
  ],
322
- "totalBytes": 76300003
323
  }
 
10
  },
11
  {
12
  "path": "app.js",
13
+ "bytes": 11482,
14
+ "sha256": "aa56286d4012e6ab44027f85bf906d7b84fa1a43db7dac21cbe3a46b39c5ed87"
15
  },
16
  {
17
  "path": "decode-guard.js",
 
270
  },
271
  {
272
  "path": "index.html",
273
+ "bytes": 3727,
274
+ "sha256": "b24c7ed319e3de94fbf9868a2115366f28e1c101ac38ed52b56b5e4903272ad1"
275
  },
276
  {
277
  "path": "model/vp2vi/piece_table.json",
 
290
  },
291
  {
292
  "path": "styles.css",
293
+ "bytes": 10099,
294
+ "sha256": "4e01e6d7de6467c47584ef42f1fc2de32f37411d2f0cd312c0377c9971fd2789"
295
  },
296
  {
297
  "path": "weights/manifest.json",
 
319
  "sha256": "030b8178c17fc02b3ed38f3d2248ee2565065c39cd38e549a7fed0d58cde12e6"
320
  }
321
  ],
322
+ "totalBytes": 76302996
323
  }
index.html CHANGED
@@ -40,6 +40,15 @@
40
 
41
  <textarea id="input" spellcheck="false" placeholder="Dán nội dung vào đây…" aria-describedby="input-note"></textarea>
42
 
 
 
 
 
 
 
 
 
 
43
  <div class="panel-actions">
44
  <button id="clear" class="button button-quiet" type="button" disabled>Xóa</button>
45
  <div class="run-group">
 
40
 
41
  <textarea id="input" spellcheck="false" placeholder="Dán nội dung vào đây…" aria-describedby="input-note"></textarea>
42
 
43
+ <div class="samples" aria-label="Văn bản mẫu">
44
+ <span class="samples-label">Thử nhanh</span>
45
+ <div class="sample-options">
46
+ <button class="sample-button" type="button" data-sample="story">Kể chuyện</button>
47
+ <button class="sample-button" type="button" data-sample="dialogue">Đối thoại</button>
48
+ <button class="sample-button" type="button" data-sample="action">Giao chiến</button>
49
+ </div>
50
+ </div>
51
+
52
  <div class="panel-actions">
53
  <button id="clear" class="button button-quiet" type="button" disabled>Xóa</button>
54
  <div class="run-group">
styles.css CHANGED
@@ -210,6 +210,57 @@ textarea::selection,
210
  .out::selection,
211
  .draft::selection { background: rgba(227, 111, 69, .35); }
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  .panel-actions {
214
  min-height: 72px;
215
  flex: 0 0 auto;
@@ -425,6 +476,8 @@ kbd {
425
  .heading > p:last-child { font-size: 13px; }
426
  .panel-head { height: 64px; padding-inline: 16px; }
427
  textarea { padding: 20px 18px; }
 
 
428
  .panel-actions { padding-inline: 10px 12px; }
429
  .shortcut { display: none; }
430
  .result-row { padding-inline: 22px 16px; }
 
210
  .out::selection,
211
  .draft::selection { background: rgba(227, 111, 69, .35); }
212
 
213
+ .samples {
214
+ min-height: 48px;
215
+ flex: 0 0 auto;
216
+ display: flex;
217
+ align-items: center;
218
+ gap: 18px;
219
+ padding: 8px 22px;
220
+ border-top: 1px solid var(--line-soft);
221
+ }
222
+
223
+ .samples-label {
224
+ color: var(--faint);
225
+ font: 400 10px/1 "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
226
+ letter-spacing: .04em;
227
+ text-transform: uppercase;
228
+ }
229
+
230
+ .sample-options {
231
+ display: flex;
232
+ align-items: center;
233
+ gap: 16px;
234
+ }
235
+
236
+ .sample-button {
237
+ border: 0;
238
+ border-bottom: 1px solid transparent;
239
+ border-radius: 0;
240
+ padding: 4px 0;
241
+ color: var(--muted);
242
+ background: transparent;
243
+ cursor: pointer;
244
+ font-size: 11px;
245
+ line-height: 1.2;
246
+ transition: color 160ms ease, border-color 160ms ease, opacity 160ms ease;
247
+ }
248
+
249
+ .sample-button:hover:not(:disabled) {
250
+ color: var(--ink);
251
+ border-bottom-color: var(--accent);
252
+ }
253
+
254
+ .sample-button:focus-visible {
255
+ outline: 2px solid var(--accent-soft);
256
+ outline-offset: 3px;
257
+ }
258
+
259
+ .sample-button:disabled {
260
+ cursor: default;
261
+ opacity: .34;
262
+ }
263
+
264
  .panel-actions {
265
  min-height: 72px;
266
  flex: 0 0 auto;
 
476
  .heading > p:last-child { font-size: 13px; }
477
  .panel-head { height: 64px; padding-inline: 16px; }
478
  textarea { padding: 20px 18px; }
479
+ .samples { align-items: flex-start; gap: 10px; padding-inline: 18px; }
480
+ .sample-options { flex-wrap: wrap; gap: 12px; }
481
  .panel-actions { padding-inline: 10px 12px; }
482
  .shortcut { display: none; }
483
  .result-row { padding-inline: 22px 16px; }