Skip to content

Commit 25dc5f4

Browse files
committed
Update readme
1 parent 2234167 commit 25dc5f4

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

.changeset/eighty-spiders-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'js-vtt': patch
3+
---
4+
5+
Update readme

readme.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,13 @@ vtt.addRegion('bottom', 40, 3, [0, 100], [10, 90], 'up');
207207
import { Region } from 'js-vtt';
208208

209209
const region = new Region();
210-
region.setId('top').setWidth(80).setLines(2);
210+
region
211+
.setId('top')
212+
.setWidth(80)
213+
.setLines(2)
214+
.setRegionAnchor([50, 100])
215+
.setViewportAnchor([50, 90])
216+
.setScroll('up');
211217
```
212218

213219
---
@@ -218,17 +224,27 @@ Style blocks embed CSS that targets cue elements.
218224

219225
#### `addStyle(selectors, declarations)`
220226

221-
| Parameter | Type | Description |
222-
| -------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
223-
| `selectors` | `string[]` | CSS selectors (e.g. `['::cue']`) |
224-
| `declarations` | `Partial<CSSStyleDeclaration>` | Only [WebVTT-supported CSS properties](https://www.w3.org/TR/webvtt1/#the-cue-pseudo-element) are accepted |
227+
| Parameter | Type | Description |
228+
| -------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
229+
| `selectors` | `string[]` | CSS selectors (e.g. `['::cue']`) |
230+
| `declarations` | `Partial<Pick<CSSStyleDeclaration, CueCSSProperty>>` | Only [WebVTT-supported CSS properties](https://www.w3.org/TR/webvtt1/#the-cue-pseudo-element) are accepted |
225231

226232
```ts
227233
vtt.addStyle(['::cue'], { color: 'white', backgroundColor: 'rgba(0,0,0,0.8)' });
228234
vtt.addStyle(['::cue(b)'], { fontWeight: 'bold', color: 'yellow' });
229235
```
230236

231-
Supported CSS properties include: `color`, `opacity`, `background`, `backgroundColor`, `font`, `fontSize`, `fontFamily`, `fontWeight`, `fontStyle`, `textDecoration`, `textShadow`, `outline`, `lineHeight`, `whiteSpace`, `textCombineUpright`, `rubyPosition`, and their sub-properties.
237+
Supported CSS properties include: `color`, `opacity`, `visibility`, `background`, `backgroundColor`, `font`, `fontSize`, `fontFamily`, `fontWeight`, `fontStyle`, `fontVariant`, `fontStretch`, `textDecoration`, `textShadow`, `outline`, `lineHeight`, `whiteSpace`, `textCombineUpright`, `rubyPosition`, and their sub-properties.
238+
239+
#### Working with `Style` instances directly
240+
241+
```ts
242+
import { Style } from 'js-vtt';
243+
244+
const style = new Style([{ selectors: ['::cue'], declarations: { color: 'white' } }]);
245+
style.addRule({ selectors: ['::cue(b)'], declarations: { fontWeight: 'bold' } });
246+
style.removeRule(0); // remove rule at index 0
247+
```
232248

233249
---
234250

@@ -370,13 +386,12 @@ All errors extend the native `Error` class and include the offending segment str
370386
| `SrtValidationError` | SRT-specific validation failure |
371387

372388
```ts
373-
import { VTT } from 'js-vtt';
374-
import { InvalidHeaderError } from 'js-vtt/segments/header'; // errors are co-located
389+
import { VTT, InvalidVttError } from 'js-vtt';
375390

376391
try {
377392
VTT.fromString('not a vtt file');
378393
} catch (e) {
379-
if (e instanceof InvalidHeaderError) {
394+
if (e instanceof InvalidVttError) {
380395
console.error('Bad header:', e.message);
381396
}
382397
}

src/vtt.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import InvalidHeaderError from './errors/InvalidHeaderError';
21
import { isNote, isCue, isHeader, isRegion, isStyle } from './helpers';
3-
import { Cue, Region } from './index';
2+
import { Cue, InvalidVttError, Region } from './index';
43
import { Header } from './segments/header';
54
import { Segment } from './segments/segment';
65
import { CueCSSProperty, Style } from './segments/style';
@@ -266,7 +265,7 @@ export class VTT {
266265
const headerSegment = segments.shift()!;
267266

268267
if (!isHeader(headerSegment)) {
269-
throw new InvalidHeaderError('Invalid VTT file: Header is malformed', headerSegment);
268+
throw new InvalidVttError('Invalid VTT file: Header is malformed', headerSegment);
270269
}
271270

272271
const header = Header.fromString(headerSegment);

0 commit comments

Comments
 (0)