完善韩泰 EOT 标注编辑器并更新标注规范与项目资料

This commit is contained in:
Xin Wang
2026-10-09 15:55:46 +08:00
parent 138b08a8e4
commit 0204f1288a
29 changed files with 1340 additions and 1271 deletions
@@ -0,0 +1,44 @@
import assert from "node:assert/strict";
import test from "node:test";
// @ts-expect-error Node's native TypeScript runner requires the explicit extension.
import { createEditHistory, commitEdit, undoEdit, redoEdit } from "../lib/edit-history.ts";
test("ASR and EOT snapshots restore together through multiple undo and redo steps", () => {
const initial = { transcripts: ["原转写"], points: [1000] };
const asr = { ...initial, transcripts: ["修正转写"] };
const eot = { ...asr, points: [1200, 1800] };
let history = commitEdit(commitEdit(createEditHistory(initial), asr), eot);
history = undoEdit(history);
assert.deepEqual(history.present, asr);
history = undoEdit(history);
assert.deepEqual(history.present, initial);
history = redoEdit(history);
assert.deepEqual(history.present, asr);
history = redoEdit(history);
assert.deepEqual(history.present, eot);
assert.equal(history.future.length, 0);
assert.deepEqual(initial, { transcripts: ["原转写"], points: [1000] });
});
test("a new edit after undo abandons the old redo branch", () => {
let history = commitEdit(commitEdit(createEditHistory(0), 1), 2);
history = commitEdit(undoEdit(history), 3);
assert.equal(history.future.length, 0);
assert.equal(redoEdit(history).present, 3);
assert.equal(undoEdit(history).present, 1);
});
test("empty and unchanged operations preserve history, and forty steps can be restored", () => {
const initial = createEditHistory(0);
assert.equal(undoEdit(initial), initial);
assert.equal(redoEdit(initial), initial);
assert.equal(commitEdit(initial, 0), initial);
let history = initial;
for (let i = 1; i <= 60; i++) history = commitEdit(history, i);
assert.equal(history.past.length, 40);
for (let i = 0; i < 40; i++) history = undoEdit(history);
assert.equal(history.present, 20);
assert.equal(undoEdit(history), history);
for (let i = 0; i < 40; i++) history = redoEdit(history);
assert.equal(history.present, 60);
});
@@ -0,0 +1,26 @@
import assert from "node:assert/strict";
import test from "node:test";
// @ts-expect-error Node's native TypeScript runner requires the explicit extension.
import { resizeTranscriptRange, snapTimelineTime } from "../lib/timeline-edit.ts";
test("playhead chooses the nearest boundary or EOT and Alt allows free positioning", () => {
const points = [{ ms: 2000, label: "片段结束" }, { ms: 2150, label: "判断点" }];
assert.equal(snapTimelineTime(2110, points, 10000, 400).ms, 2150);
assert.equal(snapTimelineTime(2030, points, 10000, 400).ms, 2000);
assert.equal(snapTimelineTime(2110, points, 10000, 400, true).ms, 2110);
assert.equal(snapTimelineTime(4000, points, 10000, 400).point, null);
});
test("zoom narrows magnetic distance and long calls cannot pull the head by seconds", () => {
const points = [{ ms: 2000, label: "片段" }];
assert.equal(snapTimelineTime(2100, points, 10000, 400).ms, 2000);
assert.equal(snapTimelineTime(2100, points, 10000, 3200).ms, 2100);
assert.equal(snapTimelineTime(2800, points, 600000, 400).ms, 2800);
});
test("resizing never crosses the opposite boundary or the recording ends", () => {
assert.deepEqual(resizeTranscriptRange(2000, 4000, "start", 4500, 10000), { start_ms: 3999, end_ms: 4000 });
assert.deepEqual(resizeTranscriptRange(2000, 4000, "end", 1500, 10000), { start_ms: 2000, end_ms: 2001 });
assert.deepEqual(resizeTranscriptRange(2000, 4000, "start", -500, 10000), { start_ms: 0, end_ms: 4000 });
assert.deepEqual(resizeTranscriptRange(2000, 4000, "end", 15000, 10000), { start_ms: 2000, end_ms: 10000 });
});