@scarlett-player/captions 1.8.0 → 1.9.0

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.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @scarlett-player/captions
2
+
3
+ WebVTT subtitles and closed captions for [Scarlett Player](https://scarlettplayer.com). External `.vtt` files are attached as `<track>` elements, subtitle renditions that hls.js parses out of an HLS manifest are picked up as they arrive, and on native HLS (Safari, iOS) the browser's own text tracks are observed. Rendering is left to the browser; there is no custom VTT parser.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @scarlett-player/core @scarlett-player/captions
9
+ ```
10
+
11
+ `@scarlett-player/core` is a peer dependency. Two optional companions:
12
+
13
+ - `@scarlett-player/ui` supplies the captions button and the settings menu entry that let the viewer pick a track.
14
+ - `@scarlett-player/hls` is what `extractFromHLS` talks to. Without it, HLS extraction is simply skipped.
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { createPlayer } from '@scarlett-player/core';
20
+ import { uiPlugin } from '@scarlett-player/ui';
21
+ import { createCaptionsPlugin } from '@scarlett-player/captions';
22
+
23
+ const player = await createPlayer({
24
+ container: '#player',
25
+ src: 'https://example.com/video.m3u8',
26
+ plugins: [
27
+ uiPlugin(),
28
+ createCaptionsPlugin({
29
+ sources: [
30
+ { language: 'en', label: 'English', src: '/subs/en.vtt' },
31
+ { language: 'es', label: 'Spanish', src: '/subs/es.vtt', kind: 'captions' },
32
+ ],
33
+ autoSelect: true,
34
+ defaultLanguage: 'en',
35
+ }),
36
+ ],
37
+ });
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ | Option | Type | Default | Description |
43
+ |---|---|---|---|
44
+ | `sources` | `CaptionSource[]` | - | External WebVTT tracks, attached to the video on every `media:loaded` |
45
+ | `extractFromHLS` | `boolean` | `true` | Sync the subtitle renditions hls.js has parsed into player state. Ignored on native HLS, where the browser's tracks are observed instead |
46
+ | `autoSelect` | `boolean` | `false` | Select the track matching `defaultLanguage` once per media. Stands down if a track is already showing, for example one picked from Safari's own subtitle menu |
47
+ | `defaultLanguage` | `string` | `'en'` | BCP 47 language code used by `autoSelect` |
48
+
49
+ ### CaptionSource
50
+
51
+ | Field | Type | Default | Description |
52
+ |---|---|---|---|
53
+ | `language` | `string` | required | BCP 47 code, written to the track's `srclang` |
54
+ | `label` | `string` | required | Human readable name shown in the picker |
55
+ | `src` | `string` | required | WebVTT URL. Cross-origin URLs need CORS |
56
+ | `kind` | `'subtitles' \| 'captions'` | `'subtitles'` | Track kind |
57
+ | `default` | `boolean` | - | Declared on the interface but not read. Every track starts disabled and selection is managed by the plugin; use `autoSelect` and `defaultLanguage` instead |
58
+
59
+ ## How tracks reach the player
60
+
61
+ The plugin does not render anything or add controls. It keeps two state keys current:
62
+
63
+ - `textTracks`: every subtitle or caption track on the video element, as `{ id, label, language, kind, active }`. Ids are `track-<index>` into the video's `TextTrackList`, so they are only stable for the current media.
64
+ - `currentTextTrack`: the track whose mode is `showing`, or `null`.
65
+
66
+ Selection happens through the `track:text` event with a payload of `{ trackId }`, where `trackId` is `null` to turn captions off. The UI package's captions button and settings menu emit it; any other plugin can emit it through the plugin API. An explicit selection ends auto-selection for that media.
67
+
68
+ ```ts
69
+ player.getState().textTracks; // what the picker shows
70
+ player.getState().currentTextTrack; // what is on screen
71
+ ```
72
+
73
+ HLS renditions are never mirrored onto `<track>` elements. hls.js already creates a `TextTrack` per rendition and feeds it cues, so they show up in `textTracks` through the same sync as everything else.
74
+
75
+ ## Lifecycle
76
+
77
+ - `media:load-request`: the plugin removes the `<track>` elements it added, stops observing the old track list and clears both state keys. Tracks the browser created itself are left alone.
78
+ - `media:loaded`: external sources are re-attached, the new `TextTrackList` is observed for `addtrack`, `removetrack` and `change`, state is synced, and the hls.js subscription is set up. If the hls.js instance is not ready yet it retries once after 500 ms.
79
+
80
+ ## Events
81
+
82
+ None emitted. The plugin listens to `track:text`, `media:loaded` and `media:load-request`.
83
+
84
+ ## CSS
85
+
86
+ None. The browser draws the cues; style them with the `::cue` pseudo-element if you need to.
87
+
88
+ ## License
89
+
90
+ MIT
package/dist/index.cjs CHANGED
@@ -26,7 +26,7 @@ __export(index_exports, {
26
26
  module.exports = __toCommonJS(index_exports);
27
27
 
28
28
  // src/version.ts
29
- var PKG_VERSION = true ? "1.7.1" : "0.0.0-dev";
29
+ var PKG_VERSION = true ? "1.9.0" : "0.0.0-dev";
30
30
 
31
31
  // src/index.ts
32
32
  var HLS_SUBTITLE_TRACKS_UPDATED = "hlsSubtitleTracksUpdated";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var PKG_VERSION = true ? "1.7.1" : "0.0.0-dev";
2
+ var PKG_VERSION = true ? "1.9.0" : "0.0.0-dev";
3
3
 
4
4
  // src/index.ts
5
5
  var HLS_SUBTITLE_TRACKS_UPDATED = "hlsSubtitleTracksUpdated";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/captions",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Captions Plugin for Scarlett Player - WebVTT subtitles and closed captions",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@scarlett-player/core": "^1.7.0"
25
+ "@scarlett-player/core": "^1.8.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@vitest/coverage-v8": "^1.6.0",
@@ -30,7 +30,7 @@
30
30
  "tsup": "^8.5.1",
31
31
  "typescript": "^5.3.0",
32
32
  "vitest": "^1.6.0",
33
- "@scarlett-player/core": "1.8.0"
33
+ "@scarlett-player/core": "1.9.0"
34
34
  },
35
35
  "keywords": [
36
36
  "video",