@amazon/vinyl 2.0.4 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/index.cjs +624 -338
  2. package/dist/index.cjs.map +4 -4
  3. package/dist/index.js +643 -350
  4. package/dist/index.js.map +4 -4
  5. package/dist/test/benchmark.es5.js +8 -5
  6. package/dist/test/benchmark.js +228 -0
  7. package/dist/test/benchmark.js.map +4 -4
  8. package/dist/test/integ.es5.js +183 -157
  9. package/dist/test/integ.js +1966 -817
  10. package/dist/test/integ.js.map +4 -4
  11. package/dist/types/current/index.d.ts +4 -0
  12. package/dist/types/current/index.d.ts.map +1 -1
  13. package/dist/types/current/index.js +4 -0
  14. package/dist/types/current/streaming/AudioOptions.d.ts +39 -0
  15. package/dist/types/current/streaming/AudioOptions.d.ts.map +1 -0
  16. package/dist/types/current/streaming/AudioOptions.js +15 -0
  17. package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
  18. package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.d.ts.map +1 -1
  19. package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.js +5 -5
  20. package/dist/types/current/text/HtmlTextTrackRenderer.d.ts +60 -0
  21. package/dist/types/current/text/HtmlTextTrackRenderer.d.ts.map +1 -0
  22. package/dist/types/current/text/HtmlTextTrackRenderer.js +231 -0
  23. package/dist/types/current/text/SidecarTextTrackController.d.ts +65 -53
  24. package/dist/types/current/text/SidecarTextTrackController.d.ts.map +1 -1
  25. package/dist/types/current/text/SidecarTextTrackController.js +167 -154
  26. package/dist/types/current/text/SidecarTextTrackLoader.d.ts +5 -0
  27. package/dist/types/current/text/SidecarTextTrackLoader.d.ts.map +1 -1
  28. package/dist/types/current/text/SidecarTextTrackLoader.js +13 -7
  29. package/dist/types/current/text/TextTrack.d.ts +74 -20
  30. package/dist/types/current/text/TextTrack.d.ts.map +1 -1
  31. package/dist/types/current/text/TextTrack.js +20 -0
  32. package/dist/types/current/text/TextTrackRenderer.d.ts +24 -0
  33. package/dist/types/current/text/TextTrackRenderer.d.ts.map +1 -0
  34. package/dist/types/current/text/TextTrackRenderer.js +5 -0
  35. package/dist/types/current/text/mediaTextTrackProvider.d.ts +34 -0
  36. package/dist/types/current/text/mediaTextTrackProvider.d.ts.map +1 -0
  37. package/dist/types/current/text/mediaTextTrackProvider.js +42 -0
  38. package/dist/types/current/text/parseWebVtt.d.ts +16 -2
  39. package/dist/types/current/text/parseWebVtt.d.ts.map +1 -1
  40. package/dist/types/current/text/parseWebVtt.js +176 -48
  41. package/dist/types/current/text/pickPreferredTextTrack.d.ts +2 -1
  42. package/dist/types/current/text/pickPreferredTextTrack.d.ts.map +1 -1
  43. package/dist/types/current/text/pickPreferredTextTrack.js +6 -3
  44. package/dist/types/current/track/Track.d.ts +1 -1
  45. package/dist/types/current/track/TrackController.d.ts.map +1 -1
  46. package/dist/types/current/track/TrackController.js +30 -30
  47. package/dist/types/current/track/dash/createDashFactories.d.ts +21 -10
  48. package/dist/types/current/track/dash/createDashFactories.d.ts.map +1 -1
  49. package/dist/types/current/track/dash/createDashFactories.js +9 -21
  50. package/dist/types/current/track/hls/createHlsFactories.d.ts +21 -10
  51. package/dist/types/current/track/hls/createHlsFactories.d.ts.map +1 -1
  52. package/dist/types/current/track/hls/createHlsFactories.js +9 -21
  53. package/dist/types/current/track/mse/MseTrack.d.ts +1 -2
  54. package/dist/types/current/track/mse/MseTrack.d.ts.map +1 -1
  55. package/dist/types/current/track/mse/MseTrack.js +3 -7
  56. package/dist/types/current/tsconfig.tsbuildinfo +1 -1
  57. package/dist/types/current/vinyl/VinylOptions.d.ts +18 -40
  58. package/dist/types/current/vinyl/VinylOptions.d.ts.map +1 -1
  59. package/dist/types/current/vinyl/VinylOptions.js +12 -11
  60. package/dist/types/current/vinyl/VinylPlayer.d.ts +0 -6
  61. package/dist/types/current/vinyl/VinylPlayer.d.ts.map +1 -1
  62. package/dist/types/current/vinyl/VinylPlayer.js +2 -23
  63. package/dist/types/current/vinyl/createVinylFactories.d.ts +32 -18
  64. package/dist/types/current/vinyl/createVinylFactories.d.ts.map +1 -1
  65. package/dist/types/current/vinyl/createVinylFactories.js +6 -0
  66. package/dist/types/ts3.7/index.d.ts +4 -0
  67. package/dist/types/ts3.7/streaming/AudioOptions.d.ts +39 -0
  68. package/dist/types/ts3.7/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
  69. package/dist/types/ts3.7/text/HtmlTextTrackRenderer.d.ts +60 -0
  70. package/dist/types/ts3.7/text/SidecarTextTrackController.d.ts +65 -53
  71. package/dist/types/ts3.7/text/SidecarTextTrackLoader.d.ts +5 -0
  72. package/dist/types/ts3.7/text/TextTrack.d.ts +74 -20
  73. package/dist/types/ts3.7/text/TextTrackRenderer.d.ts +24 -0
  74. package/dist/types/ts3.7/text/mediaTextTrackProvider.d.ts +34 -0
  75. package/dist/types/ts3.7/text/parseWebVtt.d.ts +16 -2
  76. package/dist/types/ts3.7/text/pickPreferredTextTrack.d.ts +2 -1
  77. package/dist/types/ts3.7/track/Track.d.ts +1 -1
  78. package/dist/types/ts3.7/track/dash/createDashFactories.d.ts +21 -10
  79. package/dist/types/ts3.7/track/hls/createHlsFactories.d.ts +21 -10
  80. package/dist/types/ts3.7/track/mse/MseTrack.d.ts +1 -2
  81. package/dist/types/ts3.7/vinyl/VinylOptions.d.ts +18 -40
  82. package/dist/types/ts3.7/vinyl/VinylPlayer.d.ts +0 -6
  83. package/dist/types/ts3.7/vinyl/createVinylFactories.d.ts +32 -18
  84. package/dist/types/ts4.1/index.d.ts +4 -0
  85. package/dist/types/ts4.1/streaming/AudioOptions.d.ts +39 -0
  86. package/dist/types/ts4.1/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
  87. package/dist/types/ts4.1/text/HtmlTextTrackRenderer.d.ts +60 -0
  88. package/dist/types/ts4.1/text/SidecarTextTrackController.d.ts +65 -53
  89. package/dist/types/ts4.1/text/SidecarTextTrackLoader.d.ts +5 -0
  90. package/dist/types/ts4.1/text/TextTrack.d.ts +74 -20
  91. package/dist/types/ts4.1/text/TextTrackRenderer.d.ts +24 -0
  92. package/dist/types/ts4.1/text/mediaTextTrackProvider.d.ts +34 -0
  93. package/dist/types/ts4.1/text/parseWebVtt.d.ts +16 -2
  94. package/dist/types/ts4.1/text/pickPreferredTextTrack.d.ts +2 -1
  95. package/dist/types/ts4.1/track/Track.d.ts +1 -1
  96. package/dist/types/ts4.1/track/dash/createDashFactories.d.ts +21 -10
  97. package/dist/types/ts4.1/track/hls/createHlsFactories.d.ts +21 -10
  98. package/dist/types/ts4.1/track/mse/MseTrack.d.ts +1 -2
  99. package/dist/types/ts4.1/vinyl/VinylOptions.d.ts +18 -40
  100. package/dist/types/ts4.1/vinyl/VinylPlayer.d.ts +0 -6
  101. package/dist/types/ts4.1/vinyl/createVinylFactories.d.ts +32 -18
  102. package/dist/types/ts4.7/index.d.ts +4 -0
  103. package/dist/types/ts4.7/streaming/AudioOptions.d.ts +39 -0
  104. package/dist/types/ts4.7/streaming/createDefaultMediaTimelineTransformer.d.ts +2 -2
  105. package/dist/types/ts4.7/text/HtmlTextTrackRenderer.d.ts +60 -0
  106. package/dist/types/ts4.7/text/SidecarTextTrackController.d.ts +65 -53
  107. package/dist/types/ts4.7/text/SidecarTextTrackLoader.d.ts +5 -0
  108. package/dist/types/ts4.7/text/TextTrack.d.ts +74 -20
  109. package/dist/types/ts4.7/text/TextTrackRenderer.d.ts +24 -0
  110. package/dist/types/ts4.7/text/mediaTextTrackProvider.d.ts +34 -0
  111. package/dist/types/ts4.7/text/parseWebVtt.d.ts +16 -2
  112. package/dist/types/ts4.7/text/pickPreferredTextTrack.d.ts +2 -1
  113. package/dist/types/ts4.7/track/Track.d.ts +1 -1
  114. package/dist/types/ts4.7/track/dash/createDashFactories.d.ts +21 -10
  115. package/dist/types/ts4.7/track/hls/createHlsFactories.d.ts +21 -10
  116. package/dist/types/ts4.7/track/mse/MseTrack.d.ts +1 -2
  117. package/dist/types/ts4.7/vinyl/VinylOptions.d.ts +18 -40
  118. package/dist/types/ts4.7/vinyl/VinylPlayer.d.ts +0 -6
  119. package/dist/types/ts4.7/vinyl/createVinylFactories.d.ts +32 -18
  120. package/dist/unit/types/current/index.d.ts +2 -0
  121. package/dist/unit/types/current/index.d.ts.map +1 -1
  122. package/dist/unit/types/current/index.js +2 -0
  123. package/dist/unit/types/current/streaming/MseTrack.test.js +13 -7
  124. package/dist/unit/types/current/streaming/createDefaultMediaTimelineTransformer.test.js +8 -4
  125. package/dist/unit/types/current/text/HtmlTextTrackRenderer.test.d.ts +2 -0
  126. package/dist/unit/types/current/text/HtmlTextTrackRenderer.test.d.ts.map +1 -0
  127. package/dist/unit/types/current/text/HtmlTextTrackRenderer.test.js +231 -0
  128. package/dist/unit/types/current/text/SidecarTextTrackController.test.js +432 -333
  129. package/dist/unit/types/current/text/SidecarTextTrackLoader.test.js +29 -0
  130. package/dist/unit/types/current/text/mediaTextTrackProvider.test.d.ts +2 -0
  131. package/dist/unit/types/current/text/mediaTextTrackProvider.test.d.ts.map +1 -0
  132. package/dist/unit/types/current/text/mediaTextTrackProvider.test.js +86 -0
  133. package/dist/unit/types/current/text/parseWebVtt.test.js +187 -6
  134. package/dist/unit/types/current/text/pickPreferredTextTrack.test.js +12 -1
  135. package/dist/unit/types/current/track/TrackController.test.js +36 -0
  136. package/dist/unit/types/current/track/dash/createDashFactories.test.js +1 -2
  137. package/dist/unit/types/current/track/hls/buildHlsMediaTimeline.test.js +1 -2
  138. package/dist/unit/types/current/track/hls/createHlsFactories.test.js +1 -2
  139. package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -1
  140. package/dist/unit/types/current/vinyl/VinylPlayerTextTracks.test.js +102 -177
  141. package/dist/unit/types/current/vinyl/createVinylFactories.test.js +2 -0
  142. package/dist/vinylTestUtil/index.js +14 -8
  143. package/dist/vinylTestUtil/index.js.map +2 -2
  144. package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
  145. package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.d.ts.map +1 -1
  146. package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.js +5 -2
  147. package/dist/vinylTestUtil/types/current/mock/text/MockTextTrackController.d.ts +3 -3
  148. package/dist/vinylTestUtil/types/current/mock/text/MockTextTrackController.d.ts.map +1 -1
  149. package/dist/vinylTestUtil/types/current/mock/text/MockTextTrackController.js +3 -3
  150. package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.d.ts +1 -2
  151. package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.d.ts.map +1 -1
  152. package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.js +3 -2
  153. package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
  154. package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.d.ts.map +1 -1
  155. package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.js +3 -2
  156. package/dist/vinylTestUtil/types/current/tsconfig.tsbuildinfo +1 -1
  157. package/dist/vinylTestUtil/types/ts3.7/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
  158. package/dist/vinylTestUtil/types/ts3.7/mock/text/MockTextTrackController.d.ts +3 -3
  159. package/dist/vinylTestUtil/types/ts3.7/mock/track/dash/createMockDashDependencies.d.ts +1 -2
  160. package/dist/vinylTestUtil/types/ts3.7/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
  161. package/dist/vinylTestUtil/types/ts4.1/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
  162. package/dist/vinylTestUtil/types/ts4.1/mock/text/MockTextTrackController.d.ts +3 -3
  163. package/dist/vinylTestUtil/types/ts4.1/mock/track/dash/createMockDashDependencies.d.ts +1 -2
  164. package/dist/vinylTestUtil/types/ts4.1/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
  165. package/dist/vinylTestUtil/types/ts4.7/mock/player/MockVinylPlayerDependencies.d.ts +3 -2
  166. package/dist/vinylTestUtil/types/ts4.7/mock/text/MockTextTrackController.d.ts +3 -3
  167. package/dist/vinylTestUtil/types/ts4.7/mock/track/dash/createMockDashDependencies.d.ts +1 -2
  168. package/dist/vinylTestUtil/types/ts4.7/mock/track/hls/createMockHlsDependencies.d.ts +1 -2
  169. package/docs/USAGE.md +82 -31
  170. package/package.json +9 -9
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Renders a text track's cues. Injected into the player so an application can
3
+ * paint captions itself (as HTML) instead of relying on the browser's native
4
+ * `TextTrack` rendering — giving full control over styling and placement.
5
+ *
6
+ * The controller hands the renderer the DOM `TextTrack` (set to `'hidden'`, so
7
+ * the browser tracks cue timing but does not paint); the renderer listens for
8
+ * the track's active cues and draws them. See {@link HtmlTextTrackRenderer} for
9
+ * the built-in HTML implementation.
10
+ */
11
+ export interface TextTrackRenderer {
12
+ /**
13
+ * Renders the active cues of `track`, listening for cue changes. Passing
14
+ * `null` clears anything rendered and detaches from the previous track.
15
+ */
16
+ setTextTrack(track: TextTrack | null): void;
17
+ /**
18
+ * Supplies the CSS bodies of the track's WebVTT `STYLE` blocks (which carry
19
+ * `::cue` rules), so the renderer can style cue classes. Optional — a
20
+ * renderer may ignore authored styles.
21
+ */
22
+ setStyles?(styles: readonly string[]): void;
23
+ }
24
+ //# sourceMappingURL=TextTrackRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextTrackRenderer.d.ts","sourceRoot":"","sources":["../../../../src/text/TextTrackRenderer.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAA;IAE3C;;;;OAIG;IACH,SAAS,CAAC,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;CAC9C"}
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { TextTrackKind } from './TextTrack';
2
+ /**
3
+ * A handle to a DOM {@link TextTrack} created on the media element, plus a way
4
+ * to clear its cues.
5
+ */
6
+ export interface TextTrackRef {
7
+ readonly track: TextTrack;
8
+ /**
9
+ * Removes all cues from the track. Must be called while the track is not
10
+ * `disabled` — `TextTrack.cues` reads null in the disabled state, so
11
+ * clearing a disabled track silently leaves its cues attached.
12
+ */
13
+ clear(): void;
14
+ }
15
+ /**
16
+ * Creates and hands out DOM text tracks for a media element, memoized per
17
+ * `(kind, label, language)`.
18
+ *
19
+ * `HTMLMediaElement.addTextTrack` tracks can never be removed, so creating a
20
+ * fresh one per activation would accumulate tracks — and any left in `showing`
21
+ * mode renders alongside the active one (captions "bleed through"). Reusing one
22
+ * track per key keeps exactly one track per distinct rendition.
23
+ */
24
+ export interface MediaTextTrackProvider {
25
+ getOrCreate(kind: TextTrackKind, label?: string, language?: string): TextTrackRef;
26
+ }
27
+ export declare function createMediaTextTrackProvider(deps: {
28
+ /**
29
+ * The HTML media element on which to attach the in-band TextTrack
30
+ * representation.
31
+ */
32
+ readonly media: HTMLMediaElement;
33
+ }): MediaTextTrackProvider;
34
+ //# sourceMappingURL=mediaTextTrackProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediaTextTrackProvider.d.ts","sourceRoot":"","sources":["../../../../src/text/mediaTextTrackProvider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IAEzB;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAAA;CAChB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACnC,WAAW,CACP,IAAI,EAAE,aAAa,EACnB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAClB,YAAY,CAAA;CAClB;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE;IAC/C;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAA;CACnC,GAAG,sBAAsB,CAwCzB"}
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export function createMediaTextTrackProvider(deps) {
6
+ const { media } = deps;
7
+ const cache = new Map();
8
+ const isAttached = (track) => {
9
+ for (let i = 0; i < media.textTracks.length; i++) {
10
+ if (media.textTracks[i] === track)
11
+ return true;
12
+ }
13
+ return false;
14
+ };
15
+ const create = (kind, label, language) => {
16
+ const track = media.addTextTrack(kind, label, language);
17
+ return {
18
+ track,
19
+ clear() {
20
+ if (!track.cues)
21
+ return;
22
+ // Snapshot first — removeCue mutates the live list.
23
+ const all = Array.from(track.cues);
24
+ for (const cue of all)
25
+ track.removeCue(cue);
26
+ },
27
+ };
28
+ };
29
+ return {
30
+ getOrCreate(kind, label, language) {
31
+ const key = `${kind}-${label}-${language}`;
32
+ const cached = cache.get(key);
33
+ // Resetting the media source (MSE `src = null; load()`) drops added
34
+ // tracks, so a cached track can become detached; recreate when so.
35
+ if (cached && isAttached(cached.track))
36
+ return cached;
37
+ const ref = create(kind, label, language);
38
+ cache.set(key, ref);
39
+ return ref;
40
+ },
41
+ };
42
+ }
@@ -1,3 +1,4 @@
1
+ import type { VttCueStyle } from './VttCueStyle';
1
2
  /**
2
3
  * A single WebVTT cue.
3
4
  *
@@ -20,6 +21,12 @@ export interface WebVttCue {
20
21
  * The cue text payload, with line breaks preserved as `\n`.
21
22
  */
22
23
  readonly text: string;
24
+ /**
25
+ * The authored cue settings from the timing line (position/line/size/
26
+ * align/vertical), when any were present. Preserved so a renderer can
27
+ * position the cue faithfully. Absent when the cue declared no settings.
28
+ */
29
+ readonly settings?: VttCueStyle;
23
30
  }
24
31
  /**
25
32
  * The result of parsing a WebVTT document.
@@ -29,18 +36,25 @@ export interface WebVttDocument {
29
36
  * Parsed cues in document order.
30
37
  */
31
38
  readonly cues: readonly WebVttCue[];
39
+ /**
40
+ * The raw CSS body of each `STYLE` block, in document order. These carry
41
+ * `::cue` rules (e.g. `::cue(.loud) { font-weight: bold }`) an HTML renderer
42
+ * can apply. Empty when the document declared no styles.
43
+ */
44
+ readonly styles: readonly string[];
32
45
  }
33
46
  /**
34
47
  * Parses a WebVTT document into a list of cues.
35
48
  *
36
49
  * Implements a forgiving subset of the WebVTT 1.0 specification: header
37
50
  * detection, comment blocks (lines starting with `NOTE`), styling/region
38
- * blocks (skipped), cue identifiers, and HH:MM:SS.mmm or MM:SS.mmm timestamps.
39
- * Cue settings on the timing line are tolerated and ignored.
51
+ * blocks (STYLE bodies are captured, REGION skipped), cue identifiers, and
52
+ * HH:MM:SS.mmm or MM:SS.mmm timestamps with optional cue settings.
40
53
  *
41
54
  * @param input The raw WebVTT document text. Both LF and CRLF line endings
42
55
  * are supported, and a leading BOM is stripped if present.
43
56
  * @throws ValidationError if the input is missing the WEBVTT header.
57
+ * @see https://www.w3.org/TR/webvtt1/#webvtt-timestamp
44
58
  */
45
59
  export declare function parseWebVtt(input: string): WebVttDocument;
46
60
  //# sourceMappingURL=parseWebVtt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseWebVtt.d.ts","sourceRoot":"","sources":["../../../../src/text/parseWebVtt.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE1B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAA;CACtC;AAYD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAuFzD"}
1
+ {"version":3,"file":"parseWebVtt.d.ts","sourceRoot":"","sources":["../../../../src/text/parseWebVtt.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE1B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAA;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CACrC;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAoGzD"}
@@ -4,103 +4,153 @@
4
4
  */
5
5
  import { ErrorOrigin, ValidationError } from '@amazon/vinyl-util';
6
6
  const WEBVTT_HEADER = 'WEBVTT';
7
- // Trailing cue settings are tolerated but ignored. They are separated from the
8
- // end timestamp by whitespace, so the tail is matched as an optional group that
9
- // begins with a whitespace character. Using `(?:\s.*)?$` rather than `\s*(.*)$`
10
- // avoids the ambiguous overlap between `\s*` and `.*` (both match spaces), which
11
- // would allow polynomial backtracking on space-heavy input.
12
- const TIME_RE = /^\s*(?:(\d+):)?([0-5]?\d):([0-5]?\d)\.(\d{3})\s*-->\s*(?:(\d+):)?([0-5]?\d):([0-5]?\d)\.(\d{3})(?:\s.*)?$/;
7
+ // A single WebVTT timestamp anchored at the start: `[ hours ":" ] minutes ":"
8
+ // seconds "." ms`, with hours two-or-more digits (optional), minutes/seconds
9
+ // two digits in 0-59, and milliseconds three digits (per the spec's "collect a
10
+ // WebVTT timestamp"). Timestamp collection stops after the milliseconds — it is
11
+ // NOT anchored at the end — so the start match must be checked to consume its
12
+ // whole (pre-`-->`) token, while for the end match any remainder is cue
13
+ // settings. The only unbounded quantifier is `\d+`, followed by a literal `:`
14
+ // (no nested/overlapping quantifiers), so it matches in linear time, and it
15
+ // only ever runs against a single short token — backtracking is a non-issue.
16
+ const TIMESTAMP_RE = /^(?:(\d+):)?([0-5]\d):([0-5]\d)\.(\d{3})/;
13
17
  /**
14
18
  * Parses a WebVTT document into a list of cues.
15
19
  *
16
20
  * Implements a forgiving subset of the WebVTT 1.0 specification: header
17
21
  * detection, comment blocks (lines starting with `NOTE`), styling/region
18
- * blocks (skipped), cue identifiers, and HH:MM:SS.mmm or MM:SS.mmm timestamps.
19
- * Cue settings on the timing line are tolerated and ignored.
22
+ * blocks (STYLE bodies are captured, REGION skipped), cue identifiers, and
23
+ * HH:MM:SS.mmm or MM:SS.mmm timestamps with optional cue settings.
20
24
  *
21
25
  * @param input The raw WebVTT document text. Both LF and CRLF line endings
22
26
  * are supported, and a leading BOM is stripped if present.
23
27
  * @throws ValidationError if the input is missing the WEBVTT header.
28
+ * @see https://www.w3.org/TR/webvtt1/#webvtt-timestamp
24
29
  */
25
30
  export function parseWebVtt(input) {
26
31
  if (typeof input !== 'string') {
27
32
  throw new ValidationError('WebVTT input must be a string', ErrorOrigin.MEDIA);
28
33
  }
29
34
  let text = input;
30
- // Strip BOM
35
+ // Strip a leading BOM, then normalize line endings.
31
36
  if (text.charCodeAt(0) === 0xfeff)
32
37
  text = text.slice(1);
33
- // Normalize line endings
34
38
  const lines = text.split(/\r\n|\r|\n/);
35
39
  if (lines.length === 0 || !isWebVttHeader(lines[0])) {
36
40
  throw new ValidationError('WebVTT must begin with a WEBVTT header', ErrorOrigin.MEDIA);
37
41
  }
38
42
  const cues = [];
43
+ const styles = [];
39
44
  // Per the WebVTT spec, everything from the `WEBVTT` signature up to (and
40
- // including) the first blank line is the file header — any metadata
41
- // header lines (e.g. HLS's `X-TIMESTAMP-MAP=...`) belong in that block
42
- // and MUST NOT be interpreted as cue content.
45
+ // including) the first blank line is the file header — metadata lines (e.g.
46
+ // HLS's `X-TIMESTAMP-MAP=...`) belong in that block and MUST NOT be
47
+ // interpreted as cue content.
43
48
  let i = 1;
44
49
  while (i < lines.length && lines[i] !== '')
45
50
  i++;
46
51
  while (i < lines.length) {
47
- // Skip empty lines between blocks.
52
+ // Skip blank lines between blocks.
48
53
  if (lines[i] === '') {
49
54
  i++;
50
55
  continue;
51
56
  }
52
- // NOTE comment block: skip until blank line.
53
- if (lines[i] === 'NOTE' || lines[i].startsWith('NOTE ')) {
57
+ // NOTE comment / REGION blocks: skip until the blank line. A NOTE line
58
+ // is `NOTE` alone or `NOTE` followed by whitespace (space or tab).
59
+ if (lines[i] === 'NOTE' ||
60
+ lines[i].startsWith('NOTE ') ||
61
+ lines[i].startsWith('NOTE\t') ||
62
+ lines[i] === 'REGION') {
54
63
  i++;
55
64
  while (i < lines.length && lines[i] !== '')
56
65
  i++;
57
66
  continue;
58
67
  }
59
- // STYLE / REGION blocks - skip until blank line.
60
- if (lines[i] === 'STYLE' || lines[i] === 'REGION') {
68
+ // STYLE block: capture its CSS body (up to the blank line).
69
+ if (lines[i] === 'STYLE') {
61
70
  i++;
71
+ const start = i;
62
72
  while (i < lines.length && lines[i] !== '')
63
73
  i++;
74
+ const css = lines.slice(start, i).join('\n').trim();
75
+ if (css)
76
+ styles.push(css);
64
77
  continue;
65
78
  }
66
- // Cue: optional identifier, then a timing line, then payload.
79
+ // Cue: an optional identifier line, then a timing line, then payload.
80
+ // A cue identifier never contains `-->`, so a line without it is the
81
+ // identifier and the timing line follows (spec: "collect a WebVTT
82
+ // block").
67
83
  let id = null;
68
- let timingLine;
69
- const firstLine = lines[i];
70
- if (TIME_RE.test(firstLine)) {
71
- timingLine = firstLine;
72
- i++;
73
- }
74
- else {
75
- id = firstLine;
84
+ if (!lines[i].includes('-->')) {
85
+ id = lines[i];
76
86
  i++;
77
87
  if (i >= lines.length)
78
- break;
79
- timingLine = lines[i];
80
- i++;
88
+ break; // identifier with no timing line
81
89
  }
82
- const match = TIME_RE.exec(timingLine);
83
- if (!match) {
84
- // Skip malformed cue: drain to next blank line.
90
+ const timing = parseTiming(lines[i]);
91
+ i++;
92
+ if (!timing) {
93
+ // Malformed timing line: drain to the next blank line.
85
94
  while (i < lines.length && lines[i] !== '')
86
95
  i++;
87
96
  continue;
88
97
  }
89
- const startTime = toSeconds(match[1], match[2], match[3], match[4]);
90
- const endTime = toSeconds(match[5], match[6], match[7], match[8]);
91
98
  const payloadLines = [];
92
99
  while (i < lines.length && lines[i] !== '') {
93
100
  payloadLines.push(lines[i]);
94
101
  i++;
95
102
  }
96
- cues.push({
97
- id,
98
- startTime,
99
- endTime,
100
- text: payloadLines.join('\n'),
101
- });
103
+ const text = payloadLines.join('\n');
104
+ // Omit the optional `settings` key entirely when there are none.
105
+ cues.push(timing.settings === undefined
106
+ ? {
107
+ id,
108
+ startTime: timing.startTime,
109
+ endTime: timing.endTime,
110
+ text,
111
+ }
112
+ : {
113
+ id,
114
+ startTime: timing.startTime,
115
+ endTime: timing.endTime,
116
+ text,
117
+ settings: timing.settings,
118
+ });
102
119
  }
103
- return { cues };
120
+ return { cues, styles };
121
+ }
122
+ /**
123
+ * Parses a WebVTT timing line ("start --> end settings"), returning the two
124
+ * times (in seconds) and any parsed cue settings, or null if it is not a valid
125
+ * timing line. Splitting on the literal `-->` (and on the whitespace before the
126
+ * settings) keeps each timestamp match a fixed, anchored token.
127
+ */
128
+ function parseTiming(line) {
129
+ const arrow = line.indexOf('-->');
130
+ if (arrow < 0)
131
+ return null;
132
+ // Before the arrow: only the start timestamp (whitespace-trimmed), so the
133
+ // match must consume the whole token.
134
+ const before = line.slice(0, arrow).trim();
135
+ const start = TIMESTAMP_RE.exec(before);
136
+ if (!start || start[0].length !== before.length)
137
+ return null;
138
+ // After the arrow: the end timestamp, then whatever follows is cue settings.
139
+ const rest = line.slice(arrow + 3).trim();
140
+ const end = TIMESTAMP_RE.exec(rest);
141
+ if (!end)
142
+ return null;
143
+ return {
144
+ startTime: toSeconds(start[1], start[2], start[3], start[4]),
145
+ endTime: toSeconds(end[1], end[2], end[3], end[4]),
146
+ settings: parseCueSettings(rest.slice(end[0].length)),
147
+ };
148
+ }
149
+ function toSeconds(hours, minutes, seconds, millis) {
150
+ return ((hours ? Number(hours) * 3600 : 0) +
151
+ Number(minutes) * 60 +
152
+ Number(seconds) +
153
+ Number(millis) / 1000);
104
154
  }
105
155
  function isWebVttHeader(line) {
106
156
  if (!line.startsWith(WEBVTT_HEADER))
@@ -111,10 +161,88 @@ function isWebVttHeader(line) {
111
161
  // Header may be followed by space, tab, or any text after a separator.
112
162
  return next === 0x20 || next === 0x09;
113
163
  }
114
- function toSeconds(hours, minutes, seconds, millis) {
115
- const h = hours ? Number(hours) : 0;
116
- const m = Number(minutes);
117
- const s = Number(seconds);
118
- const ms = Number(millis);
119
- return h * 3600 + m * 60 + s + ms / 1000;
164
+ const ALIGN = new Set(['start', 'center', 'end', 'left', 'right']);
165
+ const LINE_ALIGN = new Set(['start', 'center', 'end']);
166
+ const POSITION_ALIGN = new Set(['line-left', 'center', 'line-right', 'auto']);
167
+ const VERTICAL = new Set(['rl', 'lr']);
168
+ /**
169
+ * Parses the cue-settings tail of a timing line (e.g.
170
+ * `align:center line:80% position:50%,center size:90% vertical:rl`) into a
171
+ * {@link VttCueStyle}. Unknown keys and malformed values are skipped; returns
172
+ * undefined when nothing valid was found.
173
+ */
174
+ function parseCueSettings(text) {
175
+ if (!text)
176
+ return undefined;
177
+ const settings = {};
178
+ for (const token of text.trim().split(/\s+/)) {
179
+ const colon = token.indexOf(':');
180
+ if (colon <= 0)
181
+ continue;
182
+ const key = token.slice(0, colon);
183
+ const value = token.slice(colon + 1);
184
+ switch (key) {
185
+ case 'align': {
186
+ // 'middle' is the legacy spelling of 'center'.
187
+ const align = value === 'middle' ? 'center' : value;
188
+ if (ALIGN.has(align))
189
+ settings.align = align;
190
+ break;
191
+ }
192
+ case 'vertical':
193
+ if (VERTICAL.has(value))
194
+ settings.vertical = value;
195
+ break;
196
+ case 'size': {
197
+ const size = parsePercent(value);
198
+ if (size != null)
199
+ settings.size = size;
200
+ break;
201
+ }
202
+ case 'line':
203
+ parseLine(value, settings);
204
+ break;
205
+ case 'position':
206
+ parsePosition(value, settings);
207
+ break;
208
+ }
209
+ }
210
+ return Object.keys(settings).length > 0 ? settings : undefined;
211
+ }
212
+ function parseLine(value, settings) {
213
+ const [pos, align] = value.split(',');
214
+ if (pos.endsWith('%')) {
215
+ const percent = parsePercent(pos);
216
+ if (percent == null)
217
+ return;
218
+ settings.line = percent;
219
+ settings.snapToLines = false;
220
+ }
221
+ else {
222
+ const n = Number(pos);
223
+ if (!Number.isInteger(n))
224
+ return;
225
+ settings.line = n;
226
+ settings.snapToLines = true;
227
+ }
228
+ const lineAlign = align === 'middle' ? 'center' : align;
229
+ if (lineAlign && LINE_ALIGN.has(lineAlign))
230
+ settings.lineAlign = lineAlign;
231
+ }
232
+ function parsePosition(value, settings) {
233
+ const [pos, align] = value.split(',');
234
+ const percent = parsePercent(pos);
235
+ if (percent == null)
236
+ return;
237
+ settings.position = percent;
238
+ const positionAlign = align === 'middle' ? 'center' : align;
239
+ if (positionAlign && POSITION_ALIGN.has(positionAlign))
240
+ settings.positionAlign = positionAlign;
241
+ }
242
+ /** Parses an `N%` token to its numeric percentage, or null when malformed. */
243
+ function parsePercent(value) {
244
+ if (!value.endsWith('%'))
245
+ return null;
246
+ const n = Number(value.slice(0, -1));
247
+ return Number.isFinite(n) ? n : null;
120
248
  }
@@ -1,4 +1,5 @@
1
1
  import type { TextTrackInfo } from './TextTrack';
2
+ import type { Maybe } from '@amazon/vinyl-util';
2
3
  /**
3
4
  * Chooses the text track that best matches the preferred language(s), or null
4
5
  * when none relate (or there is no preference / no tracks).
@@ -10,5 +11,5 @@ import type { TextTrackInfo } from './TextTrack';
10
11
  * forced foreign-dialogue cues), and a manifest-default track breaks any
11
12
  * remaining tie.
12
13
  */
13
- export declare function pickPreferredTextTrack(tracks: readonly TextTrackInfo[], preferred: string | readonly string[] | null): TextTrackInfo | null;
14
+ export declare function pickPreferredTextTrack(tracks: readonly TextTrackInfo[], preferred: Maybe<string | readonly string[]>): TextTrackInfo | null;
14
15
  //# sourceMappingURL=pickPreferredTextTrack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pickPreferredTextTrack.d.ts","sourceRoot":"","sources":["../../../../src/text/pickPreferredTextTrack.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAgBhD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,SAAS,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,GAC7C,aAAa,GAAG,IAAI,CActB"}
1
+ {"version":3,"file":"pickPreferredTextTrack.d.ts","sourceRoot":"","sources":["../../../../src/text/pickPreferredTextTrack.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAkB/C;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,GAC7C,aAAa,GAAG,IAAI,CActB"}
@@ -5,15 +5,18 @@
5
5
  import { languageRelatedness } from '../track/filters/languageFilter';
6
6
  /**
7
7
  * Resolves the preferred-text-language option to an ordered list of BCP 47
8
- * tags, most-preferred first. Unlike the audio equivalent, `null` resolves to
9
- * an empty list (no preference) rather than falling back to
10
- * `navigator.languages` — captions default to off.
8
+ * tags, most-preferred first. A string becomes a single-element list; an array
9
+ * is used as-is; unset (null/undefined) falls back to the platform's
10
+ * `navigator.languages`. Returns an empty list only when there is no preference
11
+ * and no `navigator.languages` — in which case nothing is selected.
11
12
  */
12
13
  function resolvePreferredTextLanguages(preferred) {
13
14
  if (typeof preferred === 'string')
14
15
  return [preferred];
15
16
  if (preferred)
16
17
  return preferred;
18
+ if (typeof navigator !== 'undefined')
19
+ return [...navigator.languages];
17
20
  return [];
18
21
  }
19
22
  /**
@@ -133,7 +133,7 @@ export interface ReadonlyTrack extends ReadonlyEventHost<TrackEventMap>, Readonl
133
133
  */
134
134
  readonly error: Error | null;
135
135
  /**
136
- * Controller for sidecar text tracks discovered for this track, or null
136
+ * Controller for text tracks discovered for this track, or null
137
137
  * if the track type does not surface text tracks.
138
138
  */
139
139
  readonly textTrackController: ReadonlyTextTrackController | null;
@@ -1 +1 @@
1
- {"version":3,"file":"TrackController.d.ts","sourceRoot":"","sources":["../../../../src/track/TrackController.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,KAAK,SAAS,EAGd,KAAK,UAAU,EACf,aAAa,EAUb,KAAK,KAAK,EAEV,KAAK,iBAAiB,EAGzB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,KAAK,EAAE,aAAa,EAAS,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,KAAK,EAER,YAAY,EACZ,gBAAgB,EACnB,MAAM,gBAAgB,C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B,OAAO,KAAK,qBAAqB,GAEhC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAwDvB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAK3B,IAAI,WAAW,IAAI,aAAa,GAAG,IAAI,CAEtC;IAED,KAAK,CAAC,IAAI,UAAQ;IAIlB,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,OAAO;CAMV"}
@@ -120,45 +120,45 @@ export class TrackControllerImpl extends EventHostImpl {
120
120
  logDebug(this, 'more adbreaks');
121
121
  return;
122
122
  }
123
- if (adParent.active) {
124
- logDebug(this, 'no ads began');
125
- return;
126
- }
127
123
  const adParentLoad = this._current;
128
124
  const placement = event.adBreak.placement;
129
125
  const isPreroll = placement === 'preroll';
130
126
  const isPostroll = placement === 'postroll';
131
- // A completed postroll marks the end of the whole track
132
- // (content + postroll); preroll/midroll only resume content.
127
+ // When the content track is still active no ad ever took over
128
+ // (an empty break): there is no ad track to switch away from.
129
+ const noAdBegan = adParent.active;
130
+ // Resumes/restores the content track at the given position.
131
+ const resumeContent = (startTime) => this.setCurrentTrack(adParent, {
132
+ config: { ...adParentLoad.config, startTime },
133
+ isAd: false,
134
+ checkPreroll: false,
135
+ });
133
136
  if (isPostroll) {
137
+ // The whole track (content + any postroll) is done.
134
138
  logDebug(this, 'trackEnded after postroll');
135
139
  this.dispatch('trackEnded', { track: adParentLoad });
136
- }
137
- if (isPostroll && this.hasNext()) {
138
- this.next();
139
- }
140
- else {
141
- // Overrides the config startTime to resume from the correct position.
142
- const startTime = isPreroll
143
- ? adParentLoad.config?.startTime
144
- : event.resumePosition;
145
- // Resume the main track.
146
- this.setCurrentTrack(adParent, {
147
- config: {
148
- ...adParentLoad.config,
149
- startTime,
150
- },
151
- isAd: false,
152
- checkPreroll: false,
153
- });
154
- if (isPostroll) {
155
- logInfo(this, 'queueEnded after postroll ad(s)');
156
- this.dispatch('queueEnded', {});
157
- }
158
- else {
159
- playbackController.play().catch(noop);
140
+ if (this.hasNext()) {
141
+ this.next();
142
+ return;
160
143
  }
144
+ // Last track: restore the content track (parked at the end)
145
+ // if an ad had taken over; an empty break never left it.
146
+ if (!noAdBegan)
147
+ resumeContent(event.resumePosition);
148
+ logInfo(this, 'queueEnded after postroll');
149
+ this.dispatch('queueEnded', {});
150
+ return;
151
+ }
152
+ // Preroll/midroll resume content — unless the break was empty,
153
+ // in which case content was never interrupted.
154
+ if (noAdBegan) {
155
+ logDebug(this, 'no ads began');
156
+ return;
161
157
  }
158
+ resumeContent(isPreroll
159
+ ? adParentLoad.config?.startTime
160
+ : event.resumePosition);
161
+ playbackController.play().catch(noop);
162
162
  }));
163
163
  }
164
164
  /**