Release Subtitle Tools 0.2.0
Verify / verify (push) Canceled after 0s

This commit is contained in:
2026-09-02 08:44:49 +02:00
parent b92793eb82
commit 88c2bcd0ff
36 changed files with 1354 additions and 182 deletions
+74 -5
View File
@@ -1,4 +1,5 @@
import { expect, test, type Page } from "@playwright/test";
import { Buffer } from "node:buffer";
const ORIGIN = "http://127.0.0.1:4197";
async function localOnly(page: Page) {
@@ -36,10 +37,10 @@ test("parses, validates, edits and converts the example", async ({ page }) => {
const external = await localOnly(page);
await page.goto("/deep/nested/subtitle/");
await expect(page.getByText("SRT", { exact: true })).toBeVisible();
await page.getByRole("tab", { name: "Cues & checks" }).click();
await page.getByRole("button", { name: "Cues & checks" }).click();
await expect(page.getByText("overlap", { exact: true })).toBeVisible();
await page.getByLabel("Text").fill("Edited locally");
await page.getByRole("tab", { name: "Source & export" }).click();
await page.getByRole("button", { name: "Source & export" }).click();
await page.getByLabel("Output format").selectOption("vtt");
await expect(page.getByLabel("Export preview")).toHaveValue(/WEBVTT/u);
await expect(page.getByLabel("Export preview")).toHaveValue(
@@ -50,13 +51,57 @@ test("parses, validates, edits and converts the example", async ({ page }) => {
test("applies a bounded timing shift", async ({ page }) => {
await page.goto("/deep/nested/subtitle/");
await page.getByRole("tab", { name: "Timing" }).click();
await page.getByRole("button", { name: "Timing" }).click();
await page.getByLabel("Shift (ms)").fill("500");
await page.getByRole("button", { name: "Apply timing transform" }).click();
await page.getByRole("tab", { name: "Cues & checks" }).click();
await page.getByRole("button", { name: "Cues & checks" }).click();
await expect(page.getByText(/00:00:01\.500/u).first()).toBeVisible();
});
test("imports flat TTML and performs timeline edits", async ({ page }) => {
await page.goto("/deep/nested/subtitle/");
await page
.getByLabel("Subtitle source")
.fill(
`<tt xmlns="http://www.w3.org/ns/ttml"><body><div><p begin="1s" end="3s">One<br/>line</p></div></body></tt>`,
);
await page.getByRole("button", { name: "Parse source" }).click();
await expect(
page.getByLabel("Subtitle summary").getByText("TTML", { exact: true }),
).toBeVisible();
await page.getByRole("button", { name: "Cues & checks" }).click();
await page.getByRole("button", { name: "Duplicate" }).click();
await expect(
page
.getByLabel("Subtitle summary")
.locator(":scope > div")
.filter({ hasText: /^Cues2$/u })
.locator("strong"),
).toHaveText("2");
await page.getByRole("button", { name: "Uppercase" }).click();
await page.getByRole("button", { name: "Source & export" }).click();
await page.getByLabel("Output format").selectOption("ttml");
await expect(page.getByLabel("Export preview")).toHaveValue(/<tt/u);
await expect(page.getByLabel("Export preview")).toHaveValue(/ONE/u);
});
test("attaches playback before completing worker waveform extraction", async ({
page,
}) => {
await page.goto("/deep/nested/subtitle/");
await page.getByRole("button", { name: "Waveform" }).click();
await page.getByLabel("Open media").setInputFiles({
name: "tone.wav",
mimeType: "audio/wav",
buffer: wavFixture(),
});
await expect(page.locator("audio")).toBeVisible();
await expect(
page.getByLabel("Audio waveform with subtitle start markers"),
).toBeVisible();
await expect(page.getByRole("alert")).toHaveCount(0);
});
test("serves release identity and hardened local-only headers", async ({
request,
}) => {
@@ -72,8 +117,32 @@ test("serves release identity and hardened local-only headers", async ({
const manifest = await request.get("/deep/nested/subtitle/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.subtitle-tools",
version: "0.1.0",
version: "0.2.0",
entry: "./",
privacy: { processing: "local", telemetry: false },
});
});
function wavFixture(): Buffer {
const sampleRate = 8_000;
const samples = sampleRate / 4;
const output = Buffer.alloc(44 + samples * 2);
output.write("RIFF", 0);
output.writeUInt32LE(output.length - 8, 4);
output.write("WAVEfmt ", 8);
output.writeUInt32LE(16, 16);
output.writeUInt16LE(1, 20);
output.writeUInt16LE(1, 22);
output.writeUInt32LE(sampleRate, 24);
output.writeUInt32LE(sampleRate * 2, 28);
output.writeUInt16LE(2, 32);
output.writeUInt16LE(16, 34);
output.write("data", 36);
output.writeUInt32LE(samples * 2, 40);
for (let index = 0; index < samples; index += 1)
output.writeInt16LE(
Math.round(Math.sin((index / sampleRate) * Math.PI * 2 * 440) * 12_000),
44 + index * 2,
);
return output;
}
+18
View File
@@ -0,0 +1,18 @@
import { expect, test } from "@playwright/test";
test("keeps the primary workspace inside a narrow viewport", async ({
page,
}) => {
await page.goto("/deep/nested/subtitle/");
await expect(page.locator("main").first()).toBeVisible();
await expect(
page.locator("main .loading, main .workbench-loading"),
).toHaveCount(0);
const widths = await page.evaluate(() => ({
content: document.documentElement.scrollWidth,
viewport: document.documentElement.clientWidth,
}));
expect(widths.viewport).toBeLessThanOrEqual(430);
expect(widths.content).toBeLessThanOrEqual(widths.viewport + 1);
});
+1 -1
View File
@@ -13,6 +13,6 @@ describe("Subtitle Tools", () => {
await screen.findByRole("heading", { name: "Subtitle Tools" }),
).toBeVisible();
expect(await screen.findByText("No network requests")).toBeVisible();
expect(screen.getByRole("tab", { name: "Timing" })).toBeVisible();
expect(screen.getByRole("button", { name: "Timing" })).toBeVisible();
});
});
+15
View File
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest";
import { extractPeaks } from "../../src/media/peaks";
describe("waveform peak extraction", () => {
it("covers every sample when bucket sizes are uneven", () => {
const peaks = extractPeaks(Float32Array.of(0.1, -0.8, 0.2, 0.4, -1), 2);
expect(peaks[0]).toBeCloseTo(0.8);
expect(peaks[1]).toBe(1);
});
it("rejects invalid bounds and handles empty PCM", () => {
expect(extractPeaks(new Float32Array(), 5)).toHaveLength(0);
expect(() => extractPeaks(Float32Array.of(1), 0)).toThrow(/positive/u);
});
});
+47
View File
@@ -2,8 +2,14 @@ import { describe, expect, it } from "vitest";
import {
compareDocuments,
convertFrameRate,
insertCue,
mergeCueWithNext,
parseSubtitle,
removeCue,
serializeSubtitle,
snapCuesToFrames,
splitCue,
transformCueText,
transformTiming,
validateDocument,
} from "../../src/subtitle/model";
@@ -85,6 +91,47 @@ describe("subtitle model", () => {
]);
});
it("imports and exports a bounded flat TTML profile", () => {
const source = `<?xml version="1.0"?><tt xmlns="http://www.w3.org/ns/ttml" xmlns:ttp="http://www.w3.org/ns/ttml#parameter" ttp:frameRate="25"><body><div><p xml:id="one" begin="00:00:01.000" end="00:00:02.500" style="caption">Hello<br/>world</p><p begin="75f" dur="1s">Frames</p></div></body></tt>`;
const document = parseSubtitle(source);
expect(document.format).toBe("ttml");
expect(document.cues).toMatchObject([
{ id: "one", startMs: 1000, endMs: 2500, text: "Hello\nworld" },
{ startMs: 3000, endMs: 4000, text: "Frames" },
]);
const exported = serializeSubtitle(document, "ttml");
expect(exported).toContain('xml:id="one"');
expect(exported).toContain("Hello<br/>world");
expect(parseSubtitle(exported).cues).toHaveLength(2);
expect(() =>
parseSubtitle(
'<!DOCTYPE tt [<!ENTITY x SYSTEM "file:///etc/passwd">]><tt/>',
"ttml",
),
).toThrow(/entities/iu);
});
it("edits cue structure, text and frame timing without mutating input", () => {
const original = parseSubtitle(SRT);
const inserted = insertCue(original, 1, {
startMs: 2600,
endMs: 3000,
text: " New ",
});
expect(original.cues).toHaveLength(2);
expect(inserted.cues).toHaveLength(3);
const cleaned = transformCueText(inserted, "trim", [1]);
expect(cleaned.cues[1]?.text).toBe("New");
const split = splitCue(cleaned, 0, 1500);
expect(split.cues).toHaveLength(4);
const merged = mergeCueWithNext(split, 0);
expect(merged.cues).toHaveLength(3);
const removed = removeCue(merged, 1);
expect(removed.cues).toHaveLength(2);
const snapped = snapCuesToFrames(removed, 25);
expect(snapped.cues.every((cue) => cue.startMs % 40 === 0)).toBe(true);
});
it("rejects pathological input bounds", () => {
expect(() => parseSubtitle("x".repeat(4_000_001))).toThrow(/4,000,000/u);
expect(() =>