Open History to see the last commit
1import { expect, it } from "vite-plus/test";
2
3import { parseXml } from "./documentPreviewXml";
4import { ttmlCaptions } from "./epubMedia";
5
6const ttml = "http://www.w3.org/ns/ttml";
7const dfxp = "http://www.w3.org/2006/04/ttaf1";
8const smpte = 'p:timeBase="smpte" p:markerMode="continuous"';
9const ntscRate = 'p:frameRate="30" p:frameRateMultiplier="1000 1001"';
10
11it.each([
12 ["frame clock times", ttml, "", "00:01:01:15", "00:01:03:00", "00:01:01.500 --> 00:01:03.000"],
13 [
14 "frame offsets at 25 fps",
15 ttml,
16 'p:frameRate="25"',
17 "25f",
18 "50f",
19 "00:00:01.000 --> 00:00:02.000",
20 ],
21 [
22 "frame offsets at a fractional DFXP rate",
23 dfxp,
24 'p:frameRate="24" p:frameRateMultiplier="1000 1001"',
25 "24f",
26 "48f",
27 "00:00:01.001 --> 00:00:02.002",
28 ],
29 [
30 "frame clock times with subframes",
31 ttml,
32 'p:frameRate="24" p:subFrameRate="2"',
33 "00:00:01:12.1",
34 "00:00:02:00.0",
35 "00:00:01.521 --> 00:00:02.000",
36 ],
37 [
38 "continuous non-drop SMPTE timecodes",
39 ttml,
40 `${smpte} p:dropMode="nonDrop" p:frameRate="25"`,
41 "00:00:01:12",
42 "00:00:02:00",
43 "00:00:01.480 --> 00:00:02.000",
44 ],
45 [
46 "continuous SMPTE timecodes at a fractional rate",
47 ttml,
48 `${smpte} ${ntscRate}`,
49 "00:00:01:00",
50 "00:00:02",
51 "00:00:01.001 --> 00:00:02.002",
52 ],
53 [
54 "continuous SMPTE NTSC drop-frame timecodes",
55 ttml,
56 `${smpte} ${ntscRate} p:dropMode="dropNTSC"`,
57 "00:00:59:29",
58 "00:01:00:02",
59 "00:01:00.027 --> 00:01:00.060",
60 ],
61 [
62 "continuous SMPTE PAL drop-frame timecodes",
63 ttml,
64 `${smpte} ${ntscRate} p:dropMode="dropPAL"`,
65 "00:01:59:29",
66 "00:02:00:04",
67 "00:02:00.087 --> 00:02:00.120",
68 ],
69 [
70 "continuous SMPTE NTSC clocks without a frame label at a drop minute",
71 ttml,
72 `${smpte} ${ntscRate} p:dropMode="dropNTSC"`,
73 "00:00:59:27",
74 "00:01:00",
75 "00:00:59.960 --> 00:00:59.993",
76 ],
77 [
78 "continuous SMPTE PAL clocks without a frame label at a drop minute",
79 ttml,
80 `${smpte} ${ntscRate} p:dropMode="dropPAL"`,
81 "00:01:59:25",
82 "00:02:00",
83 "00:01:59.953 --> 00:01:59.987",
84 ],
85 [
86 "tick offsets at an explicit tick rate",
87 ttml,
88 'p:tickRate="10000000"',
89 "10010000t",
90 "30030000t",
91 "00:00:01.001 --> 00:00:03.003",
92 ],
93 [
94 "tick offsets defaulting to one tick per second",
95 ttml,
96 "",
97 "2t",
98 "4t",
99 "00:00:02.000 --> 00:00:04.000",
100 ],
101 [
102 "tick offsets derived from frame and subframe rates",
103 ttml,
104 'p:frameRate="25" p:subFrameRate="2"',
105 "50t",
106 "125t",
107 "00:00:01.000 --> 00:00:02.500",
108 ],
109])("keeps captions using %s", (_label, namespace, parameters, begin, end, timing) => {
110 const captions = parseXml(`
111 <tt xmlns="${namespace}" xmlns:p="${namespace}#parameter" ${parameters}>
112 <body><div><p begin="${begin}" end="${end}">Door closes</p></div></body>
113 </tt>
114 `);
115 expect(ttmlCaptions(captions)).toBe(`WEBVTT\n\n${timing}\nDoor closes\n`);
116});