@@ -207,7 +207,13 @@ vtt.addRegion('bottom', 40, 3, [0, 100], [10, 90], 'up');
207207import { Region } from ' js-vtt' ;
208208
209209const 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
227233vtt .addStyle ([' ::cue' ], { color: ' white' , backgroundColor: ' rgba(0,0,0,0.8)' });
228234vtt .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
376391try {
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}
0 commit comments