You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@svta/cml-webvtt

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@svta/cml-webvtt - npm Package Compare versions

Comparing version
0.19.0
to
0.20.0
+25
README.md
# @svta/cml-webvtt
WebVTT parsing and rendering functionality.
## Installation
```bash
npm i @svta/cml-webvtt
```
## Usage
```typescript
import { parseWebVtt } from "@svta/cml-webvtt/parseWebVtt.js";
const vtt = `WEBVTT\n\nREGION\nid:test\n\nSTYLE\n::cue {}\n\nCUE_1\n00:00:00.000 --> 00:00:35.000\nWevVTT Sample\n`;
const { cues, errors, regions, styles } = await parseWebVtt(vtt);
assert(cues[0].id === "CUE_1");
assert(cues[0].text === "WevVTT Sample");
assert(errors.length === 0);
assert(regions[0].id === "test");
assert(styles.length === 1);
```
+411
-29

@@ -0,31 +1,413 @@

import { TypedResult, ValueOf } from "@svta/cml-utils";
//#region src/WebVttRegion.d.ts
/**
* A collection of tools for working with Web VTT.
*
* @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT: The Web Video Text Tracks Format}
*
* @packageDocumentation
*/
export * from './createWebVttCue.js';
export * from './createWebVttRegion.js';
export * from './parseWebVtt.js';
export * from './toVttCue.js';
export * from './toVttRegion.js';
export * from './WebVttParser.js';
export * from './WebVttParsingError.js';
export * from './WebVttTransformer.js';
export * from './WebVttTransformStream.js';
export * from './TimestampMap.js';
export * from './WebVttCue.js';
export * from './WebVttCueFactory.js';
export * from './WebVttCueResult.js';
export * from './WebVttErrorResult.js';
export * from './WebVttParseResult.js';
export * from './WebVttParserOptions.js';
export * from './WebVttRegion.js';
export * from './WebVttRegionFactory.js';
export * from './WebVttRegionResult.js';
export * from './WebVttResult.js';
export * from './WebVttResultType.js';
export * from './WebVttStyleResult.js';
export * from './WebVttTimestampMapResult.js';
* A WebVTT region.
*
*
* @beta
*/
type WebVttRegion = {
id: string;
width: number;
lines: number;
regionAnchorX: number;
regionAnchorY: number;
viewportAnchorX: number;
viewportAnchorY: number;
scroll: ScrollSetting;
};
//#endregion
//#region src/WebVttCue.d.ts
/**
* A WebVTT cue.
*
*
* @beta
*/
type WebVttCue = {
id: string;
startTime: number;
endTime: number;
pauseOnExit: boolean;
text: string;
align: AlignSetting;
region: WebVttRegion | null;
vertical: DirectionSetting;
snapToLines: boolean;
line: LineAndPositionSetting;
lineAlign: LineAlignSetting;
position: LineAndPositionSetting;
positionAlign: PositionAlignSetting;
size: number;
};
//#endregion
//#region src/createWebVttCue.d.ts
/**
* Create a generic WebVttCue object with default values
* that match the DOM VTTCue interface.
*
* @returns A WebVttCue object with default values
*
*
* @beta
*/
declare function createWebVttCue(): WebVttCue;
//#endregion
//#region src/createWebVttRegion.d.ts
/**
* Create a generic WebVttRegion object with default values
* that match the DOM VTTRegion interface.
*
* @returns A WebVttRegion object with default values
*
*
* @beta
*/
declare function createWebVttRegion(): WebVttRegion;
//#endregion
//#region src/WebVttParsingError.d.ts
/**
* A WebVTT parsing error.
*
*
* @beta
*/
declare class WebVttParsingError extends Error {
/**
* Create a new WebVTT parsing error.
*
* @param message - The message of the error.
*/
constructor(message: string);
}
//#endregion
//#region src/WebVttParseResult.d.ts
/**
* The result of parsing a WebVTT string.
*
*
* @beta
*/
type WebVttParseResult = {
/**
* The cues parsed from the WebVTT string.
*/
cues: WebVttCue[];
/**
* The regions parsed from the WebVTT string.
*/
regions: WebVttRegion[];
/**
* The styles parsed from the WebVTT string.
*/
styles: string[];
/**
* The errors that occurred while parsing the WebVTT string.
*/
errors: WebVttParsingError[];
};
//#endregion
//#region src/WebVttCueFactory.d.ts
/**
* A factory for creating WebVttCue objects.
*
*
* @beta
*/
type WebVttCueFactory = () => WebVttCue;
//#endregion
//#region src/WebVttRegionFactory.d.ts
/**
* A factory for creating WebVttRegion objects.
*
*
* @beta
*/
type WebVttRegionFactory = () => WebVttRegion;
//#endregion
//#region src/WebVttParserOptions.d.ts
/**
* Options for the WebVtt parser.
*
*
* @beta
*/
type WebVttParserOptions = {
/**
* Whether to use DOM VTTCue and VTTRegion or generic objects. If `createCue`
* or `createRegion` are provided, they will be used instead of the default
* factory functions.
*
* @defaultValue `true`
*/
useDomTypes?: boolean;
/**
* A factory for creating WebVttCue objects.
*
* By default the parser will create DOM VTTCue objects for each cue.
* In some environments, like node or a web worker, this class does not
* exist. In this case, you can provide a custom factory function that
* creates a custom cue object.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}
*/
createCue?: WebVttCueFactory;
/**
* A factory for creating WebVttRegion objects.
*
* By default the parser will create DOM VTTRegion objects for each region.
* In some environments, like node or a web worker, this class does not
* exist. In this case, you can provide a custom factory function that
* creates a custom region object.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}
*/
createRegion?: WebVttRegionFactory;
};
//#endregion
//#region src/parseWebVtt.d.ts
/**
* Parse a WebVTT string into a WebVttParseResult.
*
* @param text - The WebVTT string to parse.
* @param options - The options to use for the parser.
* @returns The parsed WebVttParseResult.
*
*
* @beta
*
* @example
* {@includeCode ../test/parseWebVtt.test.ts#example}
*/
declare function parseWebVtt(text: string, options?: WebVttParserOptions): Promise<WebVttParseResult>;
//#endregion
//#region src/toVttCue.d.ts
/**
* Convert a generic WebVTT cue to a VTTCue.
*
* @param cue - The WebVTT cue to convert.
* @returns The converted VTTCue.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}
*/
declare function toVttCue(cue: WebVttCue): VTTCue;
//#endregion
//#region src/toVttRegion.d.ts
/**
* Convert a WebVTT region to a VTTRegion.
*
* @param region - The WebVTT region to convert.
* @returns The converted VTTRegion.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}
*/
declare function toVttRegion(region: WebVttRegion): VTTRegion;
//#endregion
//#region src/TimestampMap.d.ts
/**
* A timestamp map is a mapping of MPEG timestamps to local timestamps.
*
*
* @beta
*
* @see {@link https://datatracker.ietf.org/doc/html/rfc8216#section-3.5 | RFC 8216}
*/
type TimestampMap = {
MPEGTS: number;
LOCAL: number;
};
//#endregion
//#region src/WebVttParser.d.ts
/**
* A WebVTT parser.
*
*
* @beta
*
* @example
* {@includeCode ../test/WebVttParser.test.ts#example}
*
* @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT Specification}
*/
declare class WebVttParser {
private state;
private buffer;
private regionList;
private regionSettings;
private style;
private cue;
private createCue;
private createRegion;
/**
* A callback function that is called when a parsing error occurs.
*/
onparsingerror?: (error: WebVttParsingError) => void;
/**
* A callback function that is called when a region is parsed.
*/
onregion?: (region: WebVttRegion) => void;
/**
* A callback function that is called when a timestamp map is parsed.
*/
ontimestampmap?: (timestampMap: TimestampMap) => void;
/**
* A callback function that is called when a cue is parsed.
*/
oncue?: (cue: WebVttCue) => void;
/**
* A callback function that is called when a style is parsed.
*/
onstyle?: (style: string) => void;
/**
* A callback function that is called when the parser is flushed.
*/
onflush?: () => void;
/**
* Create a new WebVTT parser.
*
* @param options - The options to use for the parser.
*/
constructor(options?: WebVttParserOptions);
/**
* Parse the given data.
*
* @param data - The data to parse.
* @param reuseCue - Whether to reuse the cue.
* @returns The parser.
*/
parse(data?: string, reuseCue?: boolean): WebVttParser;
/**
* Flush the parser.
*
* @returns The parser.
*/
flush(): WebVttParser;
private reportOrThrowError;
}
//#endregion
//#region src/WebVttCueResult.d.ts
/**
* WebVTT transform stream cue result.
*
*
* @beta
*/
type WebVttCueResult = TypedResult<"cue", WebVttCue>;
//#endregion
//#region src/WebVttErrorResult.d.ts
/**
* WebVTT transform stream error result.
*
*
* @beta
*/
type WebVttErrorResult = TypedResult<"error", WebVttParsingError>;
//#endregion
//#region src/WebVttRegionResult.d.ts
/**
* WebVTT transform stream region result.
*
*
* @beta
*/
type WebVttRegionResult = TypedResult<"region", WebVttRegion>;
//#endregion
//#region src/WebVttStyleResult.d.ts
/**
* WebVTT transform stream style result.
*
*
* @beta
*/
type WebVttStyleResult = TypedResult<"style", string>;
//#endregion
//#region src/WebVttTimestampMapResult.d.ts
/**
* WebVTT transform stream timestamp map result.
*
*
* @beta
*/
type WebVttTimestampMapResult = TypedResult<"timestampmap", TimestampMap>;
//#endregion
//#region src/WebVttResult.d.ts
/**
* WebVTT transform stream result.
*
*
* @beta
*/
type WebVttResult = WebVttCueResult | WebVttRegionResult | WebVttTimestampMapResult | WebVttStyleResult | WebVttErrorResult;
//#endregion
//#region src/WebVttTransformer.d.ts
/**
* WebVTT transform stream transformer.
*
*
* @beta
*/
declare class WebVttTransformer {
private readonly parser;
private results;
/**
* Creates a new WebVTT transformer.
*/
constructor();
private enqueueResults;
/**
* Transforms a chunk of WebVTT data.
*
* @param chunk - The chunk of WebVTT data to transform.
* @param controller - The controller to enqueue the results to.
*/
transform(chunk: string, controller: TransformStreamDefaultController<WebVttResult>): void;
/**
* Flushes the transformer.
*
* @param controller - The controller to enqueue the results to.
*/
flush(controller: TransformStreamDefaultController<WebVttResult>): void;
}
//#endregion
//#region src/WebVttTransformStream.d.ts
/**
* WebVTT transform stream.
*
*
* @beta
*/
declare class WebVttTransformStream extends TransformStream<string, WebVttResult> {
constructor(writableStrategy?: QueuingStrategy<string>, readableStrategy?: QueuingStrategy<WebVttResult>);
}
//#endregion
//#region src/WebVttResultType.d.ts
/**
* WebVTT result types.
*
*
* @beta
*
* @enum
*/
declare const WebVttResultType: {
readonly CUE: "cue";
readonly REGION: "region";
readonly TIMESTAMP_MAP: "timestampmap";
readonly STYLE: "style";
readonly ERROR: "error";
};
/**
* @beta
*/
type WebVttResultType = ValueOf<typeof WebVttResultType>;
//#endregion
export { TimestampMap, WebVttCue, WebVttCueFactory, WebVttCueResult, WebVttErrorResult, WebVttParseResult, WebVttParser, WebVttParserOptions, WebVttParsingError, WebVttRegion, WebVttRegionFactory, WebVttRegionResult, WebVttResult, WebVttResultType, WebVttStyleResult, WebVttTimestampMapResult, WebVttTransformStream, WebVttTransformer, createWebVttCue, createWebVttRegion, parseWebVtt, toVttCue, toVttRegion };
//# sourceMappingURL=index.d.ts.map
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC"}
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/WebVttRegion.ts","../src/WebVttCue.ts","../src/createWebVttCue.ts","../src/createWebVttRegion.ts","../src/WebVttParsingError.ts","../src/WebVttParseResult.ts","../src/WebVttCueFactory.ts","../src/WebVttRegionFactory.ts","../src/WebVttParserOptions.ts","../src/parseWebVtt.ts","../src/toVttCue.ts","../src/toVttRegion.ts","../src/TimestampMap.ts","../src/WebVttParser.ts","../src/WebVttCueResult.ts","../src/WebVttErrorResult.ts","../src/WebVttRegionResult.ts","../src/WebVttStyleResult.ts","../src/WebVttTimestampMapResult.ts","../src/WebVttResult.ts","../src/WebVttTransformer.ts","../src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;;;;AAAZ;;;;AAQW,KkBJC,YAAA,GAAe,elBIhB,GkBJkC,kBlBIlC,GkBJuD,wBlBIvD,GkBJkF,iBlBIlF,GkBJsG,iBlBItG;;;;;ADVX;;;;ACEY,cmBEC,iBAAA,CnBFD;EAAA,iBAAA,MAAA;UAMJ,OAAA;;;;aAKI,CAAA;UACD,cAAA;;;;;;ACTX;uCkB8BsC,iCAAiC;;;AjB9BvE;;;oBiB6CmB,iCAAiC;AhBlDpD;;;;;AJAA;;;;ACEY,coBCC,qBAAA,SAA8B,epBD/B,CAAA,MAAA,EoBCuD,YpBDvD,CAAA,CAAA;EAAA,WAAA,CAAA,gBAAA,CAAA,EoBEoB,epBFpB,CAAA,MAAA,CAAA,EAAA,gBAAA,CAAA,EoBEgE,epBFhE,CoBEgF,YpBFhF,CAAA;;;;;;ADFZ;;;;ACEA;;AAMQ,cqBJK,gBrBIL,EAAA;WACC,GAAA,EAAA,KAAA;WACE,MAAA,EAAA,QAAA;WAEJ,aAAA,EAAA,cAAA;WACK,KAAA,EAAA,OAAA;WACD,KAAA,EAAA,OAAA;;;;;KqBCC,gBAAA,GAAmB,eAAe"}

@@ -0,31 +1,710 @@

//#region src/createWebVttCue.ts
/**
* A collection of tools for working with Web VTT.
*
* @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT: The Web Video Text Tracks Format}
*
* @packageDocumentation
*/
export * from './createWebVttCue.js';
export * from './createWebVttRegion.js';
export * from './parseWebVtt.js';
export * from './toVttCue.js';
export * from './toVttRegion.js';
export * from './WebVttParser.js';
export * from './WebVttParsingError.js';
export * from './WebVttTransformer.js';
export * from './WebVttTransformStream.js';
export * from './TimestampMap.js';
export * from './WebVttCue.js';
export * from './WebVttCueFactory.js';
export * from './WebVttCueResult.js';
export * from './WebVttErrorResult.js';
export * from './WebVttParseResult.js';
export * from './WebVttParserOptions.js';
export * from './WebVttRegion.js';
export * from './WebVttRegionFactory.js';
export * from './WebVttRegionResult.js';
export * from './WebVttResult.js';
export * from './WebVttResultType.js';
export * from './WebVttStyleResult.js';
export * from './WebVttTimestampMapResult.js';
* Create a generic WebVttCue object with default values
* that match the DOM VTTCue interface.
*
* @returns A WebVttCue object with default values
*
*
* @beta
*/
function createWebVttCue() {
return {
id: "",
startTime: 0,
endTime: 0,
region: null,
snapToLines: true,
line: "auto",
lineAlign: "start",
position: "auto",
positionAlign: "auto",
size: 100,
align: "center",
vertical: "",
pauseOnExit: false,
text: ""
};
}
//#endregion
//#region src/createWebVttRegion.ts
/**
* Create a generic WebVttRegion object with default values
* that match the DOM VTTRegion interface.
*
* @returns A WebVttRegion object with default values
*
*
* @beta
*/
function createWebVttRegion() {
return {
id: "",
width: 100,
lines: 3,
regionAnchorX: 0,
regionAnchorY: 100,
viewportAnchorX: 0,
viewportAnchorY: 100,
scroll: ""
};
}
//#endregion
//#region src/WebVttParsingError.ts
/**
* A WebVTT parsing error.
*
*
* @beta
*/
var WebVttParsingError = class extends Error {
/**
* Create a new WebVTT parsing error.
*
* @param message - The message of the error.
*/
constructor(message) {
super(message);
this.name = "WebVttParsingError";
}
};
//#endregion
//#region src/parse/parseOptions.ts
function parseOptions(input, callback, keyValueDelim, groupDelim) {
const groups = groupDelim ? input.split(groupDelim) : [input];
for (const i in groups) {
if (typeof groups[i] !== "string") continue;
const kv = groups[i].split(keyValueDelim);
if (kv.length !== 2) continue;
const k = kv[0];
callback(k, kv[1].trim());
}
}
//#endregion
//#region src/parse/parseTimestamp.ts
function computeSeconds(h, m, s, f) {
return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1e3;
}
function parseTimeStamp(input) {
const m = input.match(/^(\d+):(\d{1,2})(:\d{1,2})?\.(\d{3})/);
if (!m) return null;
const first = parseInt(m[1]);
const second = parseInt(m[2]);
const third = parseInt(m[3]?.replace(":", "") || "0");
const fourth = parseInt(m[4]);
if (m[3]) return computeSeconds(first, second, third, fourth);
else if (first > 59) return computeSeconds(first, second, 0, fourth);
else return computeSeconds(0, first, second, fourth);
}
//#endregion
//#region src/parse/Settings.ts
var Settings = class {
constructor() {
this.values = Object.create(null);
}
set(k, v) {
if (this.get(k) || v === "") return;
this.values[k] = v;
}
get(k, dflt) {
if (this.has(k)) return this.values[k];
return dflt;
}
has(k) {
return k in this.values;
}
alt(k, v, a) {
for (let n = 0; n < a.length; ++n) if (v === a[n]) {
this.set(k, v);
break;
}
}
integer(k, v) {
if (/^-?\d+$/.test(v)) this.set(k, parseInt(v, 10));
}
percent(k, v) {
if (v.match(/^([\d]{1,3})(\.[\d]*)?%$/)) {
const value = parseFloat(v);
if (value >= 0 && value <= 100) {
this.set(k, value);
return true;
}
}
return false;
}
};
//#endregion
//#region src/parse/parseCue.ts
const BAD_TIMESTAMP = "Malformed time stamp.";
function parseCue(input, cue, regionList) {
const oInput = input;
function consumeTimeStamp() {
const ts = parseTimeStamp(input);
if (ts === null) throw new WebVttParsingError(BAD_TIMESTAMP + oInput);
input = input.replace(/^[^\sa-zA-Z-]+/, "");
return ts;
}
function consumeCueSettings(input$1, cue$1) {
const settings = new Settings();
parseOptions(input$1, function(k, v) {
switch (k) {
case "region":
for (let i = regionList.length - 1; i >= 0; i--) if (regionList[i].id === v) {
settings.set(k, regionList[i]);
break;
}
break;
case "vertical":
settings.alt(k, v, ["rl", "lr"]);
break;
case "line": {
const vals = v.split(",");
const vals0 = vals[0];
settings.integer(k, vals0);
settings.percent(k, vals0) && settings.set("snapToLines", false);
settings.alt(k, vals0, ["auto"]);
if (vals.length === 2) settings.alt("lineAlign", vals[1], [
"start",
"center",
"end"
]);
break;
}
case "position": {
const vals = v.split(",");
settings.percent(k, vals[0]);
if (vals.length === 2) settings.alt("positionAlign", vals[1], [
"line-left",
"center",
"line-right",
"auto"
]);
break;
}
case "size":
settings.percent(k, v);
break;
case "align":
settings.alt(k, v, [
"start",
"center",
"end",
"left",
"right"
]);
break;
}
}, /:/, /\s/);
cue$1.region = settings.get("region", null);
cue$1.vertical = settings.get("vertical", "");
try {
cue$1.line = settings.get("line", "auto");
} catch (e) {}
cue$1.lineAlign = settings.get("lineAlign", "start");
cue$1.snapToLines = settings.get("snapToLines", true);
cue$1.size = settings.get("size", 100);
try {
cue$1.align = settings.get("align", "center");
} catch (e) {
cue$1.align = settings.get("align", "middle");
}
try {
cue$1.position = settings.get("position", "auto");
} catch (e) {
cue$1.position = settings.get("position", {
start: 0,
left: 0,
center: 50,
middle: 50,
end: 100,
right: 100
}[cue$1.align]);
}
cue$1.positionAlign = settings.get("positionAlign", "auto");
}
function skipWhitespace() {
input = input.replace(/^\s+/, "");
}
skipWhitespace();
cue.startTime = consumeTimeStamp();
skipWhitespace();
if (input.substr(0, 3) !== "-->") throw new WebVttParsingError(BAD_TIMESTAMP + " (time stamps must be separated by '-->'): ");
input = input.substr(3);
skipWhitespace();
cue.endTime = consumeTimeStamp();
skipWhitespace();
consumeCueSettings(input, cue);
}
//#endregion
//#region src/parse/WebVttParserState.ts
const WebVttParserState = {
INITIAL: "INITIAL",
HEADER: "HEADER",
REGION: "REGION",
STYLE: "STYLE",
NOTE: "NOTE",
BLOCKS: "BLOCKS",
ID: "ID",
CUE: "CUE",
CUE_TEXT: "CUE_EXT",
BAD_CUE: "BAD_CUE",
BAD_WEBVTT: "BAD_WEBVTT"
};
//#endregion
//#region src/WebVttParser.ts
const BAD_SIGNATURE = "Malformed WebVTT signature.";
const createCue = () => typeof VTTCue !== "undefined" ? new VTTCue(0, 0, "") : createWebVttCue();
const createRegion = () => typeof VTTRegion !== "undefined" ? new VTTRegion() : createWebVttRegion();
/**
* A WebVTT parser.
*
*
* @beta
*
* @example
* {@includeCode ../test/WebVttParser.test.ts#example}
*
* @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT Specification}
*/
var WebVttParser = class {
/**
* Create a new WebVTT parser.
*
* @param options - The options to use for the parser.
*/
constructor(options = {}) {
this.regionSettings = null;
this.cue = null;
const useDomTypes = options.useDomTypes ?? true;
this.createCue = options.createCue || useDomTypes ? createCue : createWebVttCue;
this.createRegion = options.createRegion || useDomTypes ? createRegion : createWebVttRegion;
this.state = WebVttParserState.INITIAL;
this.buffer = "";
this.style = "";
this.regionList = [];
}
/**
* Parse the given data.
*
* @param data - The data to parse.
* @param reuseCue - Whether to reuse the cue.
* @returns The parser.
*/
parse(data, reuseCue = false) {
if (data) this.buffer += data;
const collectNextLine = () => {
const buffer = this.buffer;
let pos = 0;
while (pos < buffer.length && buffer[pos] !== "\r" && buffer[pos] !== "\n") ++pos;
const line = buffer.substr(0, pos);
if (buffer[pos] === "\r") ++pos;
if (buffer[pos] === "\n") ++pos;
this.buffer = buffer.substr(pos);
return line;
};
const parseTimestampMap = (input) => {
const settings = new Settings();
parseOptions(input, (k, v) => {
switch (k) {
case "MPEGT":
settings.integer(k + "S", v);
break;
case "LOCA":
settings.set(k + "L", parseTimeStamp(v));
break;
}
}, /[^\d]:/, /,/);
this.ontimestampmap?.({
"MPEGTS": settings.get("MPEGTS"),
"LOCAL": settings.get("LOCAL")
});
};
const parseHeader = (input) => {
if (input.match(/X-TIMESTAMP-MAP/)) parseOptions(input, (k, v) => {
switch (k) {
case "X-TIMESTAMP-MAP":
parseTimestampMap(v);
break;
}
}, /=/);
};
try {
let line;
if (this.state === WebVttParserState.INITIAL) {
if (!/\r\n|\n/.test(this.buffer)) return this;
line = collectNextLine();
if (line.charCodeAt(0) === 65279) line = line.slice(1);
const m = line.match(/^WEBVTT([ \t].*)?$/);
if (!m || !m[0]) throw new WebVttParsingError(BAD_SIGNATURE);
this.state = WebVttParserState.HEADER;
}
let alreadyCollectedLine = false;
var sawCue = reuseCue;
if (!reuseCue) {
this.cue = null;
this.regionSettings = null;
}
while (this.buffer) {
if (!/\r\n|\n/.test(this.buffer)) return this;
if (!alreadyCollectedLine) line = collectNextLine();
else alreadyCollectedLine = false;
switch (this.state) {
case WebVttParserState.HEADER:
if (/:/.test(line)) parseHeader(line);
else if (!line) this.state = WebVttParserState.BLOCKS;
continue;
case WebVttParserState.REGION:
if (!line && this.regionSettings) {
const region = this.createRegion();
region.id = this.regionSettings.get("id", "");
region.width = this.regionSettings.get("width", 100);
region.lines = this.regionSettings.get("lines", 3);
region.regionAnchorX = this.regionSettings.get("regionanchorX", 0);
region.regionAnchorY = this.regionSettings.get("regionanchorY", 100);
region.viewportAnchorX = this.regionSettings.get("viewportanchorX", 0);
region.viewportAnchorY = this.regionSettings.get("viewportanchorY", 100);
region.scroll = this.regionSettings.get("scroll", "");
this.onregion?.(region);
this.regionList.push(region);
this.regionSettings = null;
this.state = WebVttParserState.BLOCKS;
break;
}
if (this.regionSettings === null) this.regionSettings = new Settings();
const regionSettings = this.regionSettings;
parseOptions(line, (k, v) => {
switch (k) {
case "id":
regionSettings.set(k, v);
break;
case "width":
regionSettings.percent(k, v);
break;
case "lines":
regionSettings.integer(k, v);
break;
case "regionanchor":
case "viewportanchor":
const xy = v.split(",");
if (xy.length !== 2) break;
const anchor = new Settings();
anchor.percent("x", xy[0]);
anchor.percent("y", xy[1]);
if (!anchor.has("x") || !anchor.has("y")) break;
regionSettings.set(k + "X", anchor.get("x"));
regionSettings.set(k + "Y", anchor.get("y"));
break;
case "scroll":
regionSettings.alt(k, v, ["up"]);
break;
}
}, /:/, /\s/);
continue;
case WebVttParserState.STYLE:
if (!line) {
this.onstyle?.(this.style);
this.style = "";
this.state = WebVttParserState.BLOCKS;
break;
}
this.style += line + "\n";
continue;
case WebVttParserState.NOTE:
if (!line) this.state = WebVttParserState.ID;
continue;
case WebVttParserState.BLOCKS:
if (!line) continue;
if (/^NOTE($[ \t])/.test(line)) {
this.state = WebVttParserState.NOTE;
break;
}
if (/^REGION/.test(line) && !sawCue) {
this.state = WebVttParserState.REGION;
break;
}
if (/^STYLE/.test(line) && !sawCue) {
this.state = WebVttParserState.STYLE;
break;
}
this.state = WebVttParserState.ID;
case WebVttParserState.ID:
if (/^NOTE($|[ \t])/.test(line)) {
this.state = WebVttParserState.NOTE;
break;
}
if (!line) continue;
sawCue = true;
this.cue = this.createCue();
this.cue.text ??= "";
this.state = WebVttParserState.CUE;
if (line.indexOf("-->") === -1) {
this.cue.id = line;
continue;
}
case WebVttParserState.CUE:
try {
parseCue(line, this.cue, this.regionList);
} catch (e) {
this.reportOrThrowError(e);
this.cue = null;
this.state = WebVttParserState.BAD_CUE;
continue;
}
this.state = WebVttParserState.CUE_TEXT;
continue;
case WebVttParserState.CUE_TEXT:
const hasSubstring = line.indexOf("-->") !== -1;
if (!line || hasSubstring && (alreadyCollectedLine = true)) {
this.oncue?.(this.cue);
this.cue = null;
this.state = WebVttParserState.ID;
continue;
}
if (this.cue?.text) this.cue.text += "\n";
this.cue.text += line.replace(/\u2028/g, "\n").replace(/u2029/g, "\n");
continue;
case WebVttParserState.BAD_CUE:
if (!line) this.state = WebVttParserState.ID;
continue;
}
}
} catch (e) {
this.reportOrThrowError(e);
if (this.state === WebVttParserState.CUE_TEXT && this.cue && this.oncue) this.oncue(this.cue);
this.cue = null;
this.regionSettings = null;
this.state = this.state === WebVttParserState.INITIAL ? WebVttParserState.BAD_WEBVTT : WebVttParserState.BAD_CUE;
}
return this;
}
/**
* Flush the parser.
*
* @returns The parser.
*/
flush() {
try {
this.buffer += "";
if (this.cue || this.state === WebVttParserState.HEADER) {
this.buffer += "\n\n";
this.parse(void 0, true);
}
if (this.state === WebVttParserState.INITIAL) throw new WebVttParsingError(BAD_SIGNATURE);
} catch (e) {
this.reportOrThrowError(e);
}
this.onflush?.();
return this;
}
reportOrThrowError(error) {
if (error instanceof WebVttParsingError) this.onparsingerror?.(error);
else throw error;
}
};
//#endregion
//#region src/parseWebVtt.ts
/**
* Parse a WebVTT string into a WebVttParseResult.
*
* @param text - The WebVTT string to parse.
* @param options - The options to use for the parser.
* @returns The parsed WebVttParseResult.
*
*
* @beta
*
* @example
* {@includeCode ../test/parseWebVtt.test.ts#example}
*/
async function parseWebVtt(text, options) {
const parser = new WebVttParser(options);
const cues = [];
const regions = [];
const styles = [];
const errors = [];
parser.oncue = (cue) => cues.push(cue);
parser.onregion = (region) => regions.push(region);
parser.onstyle = (style) => styles.push(style);
parser.onparsingerror = (error) => errors.push(error);
parser.parse(text);
parser.flush();
return {
cues,
regions,
styles,
errors
};
}
//#endregion
//#region src/toVttCue.ts
/**
* Convert a generic WebVTT cue to a VTTCue.
*
* @param cue - The WebVTT cue to convert.
* @returns The converted VTTCue.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}
*/
function toVttCue(cue) {
const vttCue = new VTTCue(cue.startTime, cue.endTime, cue.text);
vttCue.id = cue.id;
vttCue.region = cue.region;
vttCue.vertical = cue.vertical;
vttCue.snapToLines = cue.snapToLines;
vttCue.line = cue.line;
vttCue.lineAlign = cue.lineAlign;
vttCue.position = cue.position;
vttCue.positionAlign = cue.positionAlign;
vttCue.size = cue.size;
vttCue.pauseOnExit = cue.pauseOnExit;
try {
vttCue.align = "center";
} catch (e) {
vttCue.align = "middle";
}
return vttCue;
}
//#endregion
//#region src/toVttRegion.ts
/**
* Convert a WebVTT region to a VTTRegion.
*
* @param region - The WebVTT region to convert.
* @returns The converted VTTRegion.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}
*/
function toVttRegion(region) {
const vttRegion = new VTTRegion();
vttRegion.id = region.id;
vttRegion.width = region.width;
vttRegion.lines = region.lines;
vttRegion.regionAnchorX = region.regionAnchorX;
vttRegion.regionAnchorY = region.regionAnchorY;
vttRegion.viewportAnchorX = region.viewportAnchorX;
vttRegion.viewportAnchorY = region.viewportAnchorY;
vttRegion.scroll = region.scroll;
return vttRegion;
}
//#endregion
//#region src/WebVttResultType.ts
/**
* WebVTT result types.
*
*
* @beta
*
* @enum
*/
const WebVttResultType = {
CUE: "cue",
REGION: "region",
TIMESTAMP_MAP: "timestampmap",
STYLE: "style",
ERROR: "error"
};
//#endregion
//#region src/WebVttTransformer.ts
/**
* WebVTT transform stream transformer.
*
*
* @beta
*/
var WebVttTransformer = class {
/**
* Creates a new WebVTT transformer.
*/
constructor() {
this.results = [];
this.parser = new WebVttParser();
this.parser.oncue = (cue) => this.results.push({
type: WebVttResultType.CUE,
data: cue
});
this.parser.onregion = (region) => this.results.push({
type: WebVttResultType.REGION,
data: region
});
this.parser.onstyle = (style) => this.results.push({
type: WebVttResultType.STYLE,
data: style
});
this.parser.ontimestampmap = (timestampmap) => this.results.push({
type: WebVttResultType.TIMESTAMP_MAP,
data: timestampmap
});
this.parser.onparsingerror = (error) => this.results.push({
type: WebVttResultType.ERROR,
data: error
});
}
enqueueResults(controller) {
for (const result of this.results) controller.enqueue(result);
this.results = [];
}
/**
* Transforms a chunk of WebVTT data.
*
* @param chunk - The chunk of WebVTT data to transform.
* @param controller - The controller to enqueue the results to.
*/
transform(chunk, controller) {
try {
this.parser.parse(chunk);
this.enqueueResults(controller);
} catch (error) {
controller.error(error);
}
}
/**
* Flushes the transformer.
*
* @param controller - The controller to enqueue the results to.
*/
flush(controller) {
try {
this.parser.flush();
this.enqueueResults(controller);
} catch (error) {
controller.error(error);
}
}
};
//#endregion
//#region src/WebVttTransformStream.ts
/**
* WebVTT transform stream.
*
*
* @beta
*/
var WebVttTransformStream = class extends TransformStream {
constructor(writableStrategy, readableStrategy) {
super(new WebVttTransformer(), writableStrategy, readableStrategy);
}
};
//#endregion
export { WebVttParser, WebVttParsingError, WebVttResultType, WebVttTransformStream, WebVttTransformer, createWebVttCue, createWebVttRegion, parseWebVtt, toVttCue, toVttRegion };
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC","sourcesContent":["/**\n * A collection of tools for working with Web VTT.\n *\n * @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT: The Web Video Text Tracks Format}\n *\n * @packageDocumentation\n */\nexport * from './createWebVttCue.js';\nexport * from './createWebVttRegion.js';\nexport * from './parseWebVtt.js';\nexport * from './toVttCue.js';\nexport * from './toVttRegion.js';\nexport * from './WebVttParser.js';\nexport * from './WebVttParsingError.js';\nexport * from './WebVttTransformer.js';\nexport * from './WebVttTransformStream.js';\n\nexport * from './TimestampMap.js';\nexport * from './WebVttCue.js';\nexport * from './WebVttCueFactory.js';\nexport * from './WebVttCueResult.js';\nexport * from './WebVttErrorResult.js';\nexport * from './WebVttParseResult.js';\nexport * from './WebVttParserOptions.js';\nexport * from './WebVttRegion.js';\nexport * from './WebVttRegionFactory.js';\nexport * from './WebVttRegionResult.js';\nexport * from './WebVttResult.js';\nexport * from './WebVttResultType.js';\nexport * from './WebVttStyleResult.js';\nexport * from './WebVttTimestampMapResult.js';\n"]}
{"version":3,"file":"index.js","names":["input","cue","line!: string","cues: WebVttCue[]","regions: WebVttRegion[]","styles: string[]","errors: WebVttParsingError[]"],"sources":["../src/createWebVttCue.ts","../src/createWebVttRegion.ts","../src/WebVttParsingError.ts","../src/parse/parseOptions.ts","../src/parse/parseTimestamp.ts","../src/parse/Settings.ts","../src/parse/parseCue.ts","../src/parse/WebVttParserState.ts","../src/WebVttParser.ts","../src/parseWebVtt.ts","../src/toVttCue.ts","../src/toVttRegion.ts","../src/WebVttResultType.ts","../src/WebVttTransformer.ts","../src/WebVttTransformStream.ts"],"sourcesContent":["import type { WebVttCue } from './WebVttCue.js';\n\n/**\n * Create a generic WebVttCue object with default values\n * that match the DOM VTTCue interface.\n *\n * @returns A WebVttCue object with default values\n *\n *\n * @beta\n */\nexport function createWebVttCue(): WebVttCue {\n\treturn {\n\t\tid: '',\n\t\tstartTime: 0,\n\t\tendTime: 0,\n\t\tregion: null,\n\t\tsnapToLines: true,\n\t\tline: 'auto',\n\t\tlineAlign: 'start',\n\t\tposition: 'auto',\n\t\tpositionAlign: 'auto',\n\t\tsize: 100,\n\t\talign: 'center',\n\t\tvertical: '',\n\t\tpauseOnExit: false,\n\t\ttext: '',\n\t};\n}\n","import type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * Create a generic WebVttRegion object with default values\n * that match the DOM VTTRegion interface.\n *\n * @returns A WebVttRegion object with default values\n *\n *\n * @beta\n */\nexport function createWebVttRegion(): WebVttRegion {\n\treturn {\n\t\tid: '',\n\t\twidth: 100,\n\t\tlines: 3,\n\t\tregionAnchorX: 0,\n\t\tregionAnchorY: 100,\n\t\tviewportAnchorX: 0,\n\t\tviewportAnchorY: 100,\n\t\tscroll: '',\n\t};\n}\n","/**\n * A WebVTT parsing error.\n *\n *\n * @beta\n */\nexport class WebVttParsingError extends Error {\n\n\t/**\n\t * Create a new WebVTT parsing error.\n\t *\n\t * @param message - The message of the error.\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'WebVttParsingError';\n\t}\n}\n","// Helper function to parse input into groups separated by 'groupDelim', and\n// interpet each group as a key/value pair separated by 'keyValueDelim'.\nexport function parseOptions(input: string, callback: (k: string, v: string) => void, keyValueDelim: string | RegExp, groupDelim?: string | RegExp): void {\n\t// TODO: Optimize parsing to avoid creating new arrays and strings.\n\tconst groups = groupDelim ? input.split(groupDelim) : [input];\n\n\tfor (const i in groups) {\n\t\tif (typeof groups[i] !== 'string') {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst kv = groups[i].split(keyValueDelim);\n\t\tif (kv.length !== 2) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst k = kv[0];\n\t\tconst v = kv[1].trim();\n\n\t\t// TODO: Return a value instead of using a callback.\n\t\tcallback(k, v);\n\t}\n}\n","function computeSeconds(h: number, m: number, s: number, f: number): number {\n\treturn (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;\n}\n\n// Try to parse input as a time stamp.\nexport function parseTimeStamp(input: string): number | null {\n\t// TODO: Optimize parsing to avoid creating new arrays and strings.\n\tconst m = input.match(/^(\\d+):(\\d{1,2})(:\\d{1,2})?\\.(\\d{3})/);\n\n\tif (!m) {\n\t\treturn null;\n\t}\n\n\tconst first = parseInt(m[1]);\n\tconst second = parseInt(m[2]);\n\tconst third = parseInt(m[3]?.replace(':', '') || '0');\n\tconst fourth = parseInt(m[4]);\n\n\tif (m[3]) {\n\t\t// Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]\n\t\treturn computeSeconds(first, second, third, fourth);\n\t}\n\telse if (first > 59) {\n\t\t// Timestamp takes the form of [hours]:[minutes].[milliseconds]\n\t\t// First position is hours as it's over 59.\n\t\treturn computeSeconds(first, second, 0, fourth);\n\t}\n\telse {\n\t\t// Timestamp takes the form of [minutes]:[seconds].[milliseconds]\n\t\treturn computeSeconds(0, first, second, fourth);\n\t}\n}\n","import type { WebVttRegion } from '../WebVttRegion.js';\n\nexport type SettingsValue = WebVttRegion | string | number | boolean | null;\n\n// A settings object holds key/value pairs and will ignore anything but the first\n// assignment to a specific key.\nexport class Settings {\n\tprivate values: Record<string, SettingsValue>;\n\n\tconstructor() {\n\t\tthis.values = Object.create(null);\n\t}\n\n\t// Only accept the first assignment to any key.\n\tset(k: string, v: SettingsValue): void {\n\t\tif (this.get(k) || v === '') {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.values[k] = v;\n\t}\n\n\t// Return the value for a key, or a default value.\n\t// If 'defaultKey' is passed then 'dflt' is assumed to be an object with\n\t// a number of possible default values as properties where 'defaultKey' is\n\t// the key of the property that will be chosen; otherwise it's assumed to be\n\t// a single value.\n\tget<T = SettingsValue>(k: string, dflt?: T): T {\n\t\tif (this.has(k)) {\n\t\t\treturn this.values[k] as T;\n\t\t}\n\n\t\treturn dflt as T;\n\t}\n\n\t// Check whether we have a value for a key.\n\thas(k: string): boolean {\n\t\treturn k in this.values;\n\t}\n\n\t// Accept a setting if its one of the given alternatives.\n\talt(k: string, v: string, a: string[]): void {\n\t\tfor (let n = 0; n < a.length; ++n) {\n\t\t\tif (v === a[n]) {\n\t\t\t\tthis.set(k, v);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Accept a setting if its a valid (signed) integer.\n\tinteger(k: string, v: string): void {\n\t\tif (/^-?\\d+$/.test(v)) { // integer\n\t\t\tthis.set(k, parseInt(v, 10));\n\t\t}\n\t}\n\n\t// Accept a setting if its a valid percentage.\n\tpercent(k: string, v: string): boolean {\n\t\tif (v.match(/^([\\d]{1,3})(\\.[\\d]*)?%$/)) {\n\t\t\tconst value = parseFloat(v);\n\t\t\tif (value >= 0 && value <= 100) {\n\t\t\t\tthis.set(k, value);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n}\n","import type { WebVttCue } from '../WebVttCue.js';\nimport { WebVttParsingError } from '../WebVttParsingError.js';\nimport type { WebVttRegion } from '../WebVttRegion.js';\nimport { parseOptions } from './parseOptions.js';\nimport { parseTimeStamp } from './parseTimestamp.js';\nimport { Settings } from './Settings.js';\n\nconst BAD_TIMESTAMP = 'Malformed time stamp.';\n\nexport function parseCue(input: string, cue: WebVttCue, regionList: WebVttRegion[]): void {\n\t// Remember the original input if we need to throw an error.\n\tconst oInput = input;\n\t// 4.1 WebVTT timestamp\n\tfunction consumeTimeStamp() {\n\t\tconst ts = parseTimeStamp(input);\n\t\tif (ts === null) {\n\t\t\tthrow new WebVttParsingError(BAD_TIMESTAMP + oInput);\n\t\t}\n\t\t// Remove time stamp from input.\n\t\tinput = input.replace(/^[^\\sa-zA-Z-]+/, '');\n\t\treturn ts;\n\t}\n\n\t// 4.4.2 WebVTT cue settings\n\tfunction consumeCueSettings(input: string, cue: WebVttCue): void {\n\t\tconst settings = new Settings();\n\n\t\tparseOptions(input, function (k, v) {\n\t\t\tswitch (k) {\n\t\t\t\tcase 'region': {\n\t\t\t\t\t// Find the last region we parsed with the same region id.\n\t\t\t\t\tfor (let i = regionList.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tif (regionList[i].id === v) {\n\t\t\t\t\t\t\tsettings.set(k, regionList[i]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'vertical': {\n\t\t\t\t\tsettings.alt(k, v, ['rl', 'lr']);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'line': {\n\t\t\t\t\tconst vals = v.split(',');\n\t\t\t\t\tconst vals0 = vals[0];\n\t\t\t\t\tsettings.integer(k, vals0);\n\t\t\t\t\tsettings.percent(k, vals0) ? settings.set('snapToLines', false) : null;\n\t\t\t\t\tsettings.alt(k, vals0, ['auto']);\n\t\t\t\t\tif (vals.length === 2) {\n\t\t\t\t\t\tsettings.alt('lineAlign', vals[1], ['start', 'center', 'end']);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'position': {\n\t\t\t\t\tconst vals = v.split(',');\n\t\t\t\t\tsettings.percent(k, vals[0]);\n\t\t\t\t\tif (vals.length === 2) {\n\t\t\t\t\t\tsettings.alt('positionAlign', vals[1], ['line-left', 'center', 'line-right', 'auto']);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'size': {\n\t\t\t\t\tsettings.percent(k, v);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'align': {\n\t\t\t\t\tsettings.alt(k, v, ['start', 'center', 'end', 'left', 'right']);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}, /:/, /\\s/);\n\n\t\t// Apply default values for any missing fields.\n\t\tcue.region = settings.get('region', null);\n\t\tcue.vertical = settings.get('vertical', '');\n\t\ttry {\n\t\t\tcue.line = settings.get('line', 'auto');\n\t\t}\n\t\tcatch (e) {\n\t\t\t// eslint-ignore-line\n\t\t}\n\t\tcue.lineAlign = settings.get('lineAlign', 'start');\n\t\tcue.snapToLines = settings.get('snapToLines', true);\n\t\tcue.size = settings.get('size', 100);\n\t\t// Safari still uses the old middle value and won't accept center\n\t\ttry {\n\t\t\tcue.align = settings.get('align', 'center');\n\t\t}\n\t\tcatch (e) {\n\t\t\tcue.align = settings.get('align', 'middle' as AlignSetting);\n\t\t}\n\t\ttry {\n\t\t\tcue.position = settings.get('position', 'auto');\n\t\t}\n\t\tcatch (e) {\n\t\t\tconst positions = {\n\t\t\t\tstart: 0,\n\t\t\t\tleft: 0,\n\t\t\t\tcenter: 50,\n\t\t\t\tmiddle: 50,\n\t\t\t\tend: 100,\n\t\t\t\tright: 100,\n\t\t\t};\n\n\t\t\tcue.position = settings.get('position', positions[cue.align]);\n\t\t}\n\n\t\tcue.positionAlign = settings.get('positionAlign', 'auto');\n\t}\n\n\tfunction skipWhitespace() {\n\t\tinput = input.replace(/^\\s+/, '');\n\t}\n\n\t// 4.1 WebVTT cue timings.\n\tskipWhitespace();\n\tcue.startTime = consumeTimeStamp(); // (1) collect cue start time\n\tskipWhitespace();\n\tif (input.substr(0, 3) !== '-->') { // (3) next characters must match \"-->\"\n\t\tthrow new WebVttParsingError(BAD_TIMESTAMP + \" (time stamps must be separated by '-->'): \");\n\t}\n\tinput = input.substr(3);\n\tskipWhitespace();\n\tcue.endTime = consumeTimeStamp(); // (5) collect cue end time\n\n\t// 4.1 WebVTT cue settings list.\n\tskipWhitespace();\n\tconsumeCueSettings(input, cue);\n}\n","import type { ValueOf } from '@svta/cml-utils';\n\nexport const WebVttParserState = {\n\tINITIAL: 'INITIAL',\n\tHEADER: 'HEADER',\n\tREGION: 'REGION',\n\tSTYLE: 'STYLE',\n\tNOTE: 'NOTE',\n\tBLOCKS: 'BLOCKS',\n\tID: 'ID',\n\tCUE: 'CUE',\n\tCUE_TEXT: 'CUE_EXT',\n\tBAD_CUE: 'BAD_CUE',\n\tBAD_WEBVTT: 'BAD_WEBVTT',\n} as const;\n\nexport type WebVttParserState = ValueOf<typeof WebVttParserState>;\n","import { createWebVttCue } from './createWebVttCue.js';\nimport { createWebVttRegion } from './createWebVttRegion.js';\nimport { parseCue } from './parse/parseCue.js';\nimport { parseOptions } from './parse/parseOptions.js';\nimport { parseTimeStamp } from './parse/parseTimestamp.js';\nimport { Settings } from './parse/Settings.js';\nimport { WebVttParserState } from './parse/WebVttParserState.js';\nimport type { TimestampMap } from './TimestampMap.js';\nimport type { WebVttCue } from './WebVttCue.js';\nimport type { WebVttCueFactory } from './WebVttCueFactory.js';\nimport type { WebVttParserOptions } from './WebVttParserOptions.js';\nimport { WebVttParsingError } from './WebVttParsingError.js';\nimport type { WebVttRegion } from './WebVttRegion.js';\nimport type { WebVttRegionFactory } from './WebVttRegionFactory.js';\n\nconst BAD_SIGNATURE = 'Malformed WebVTT signature.';\nconst createCue = (): WebVttCue => typeof VTTCue !== 'undefined' ? new VTTCue(0, 0, '') : createWebVttCue();\nconst createRegion = (): WebVttRegion => typeof VTTRegion !== 'undefined' ? new VTTRegion() : createWebVttRegion();\n\n/**\n * A WebVTT parser.\n *\n *\n * @beta\n *\n * @example\n * {@includeCode ../test/WebVttParser.test.ts#example}\n *\n * @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT Specification}\n */\nexport class WebVttParser {\n\tprivate state: WebVttParserState;\n\tprivate buffer: string;\n\tprivate regionList: WebVttRegion[];\n\tprivate regionSettings: Settings | null = null;\n\tprivate style: string;\n\tprivate cue: WebVttCue | null = null;\n\tprivate createCue: WebVttCueFactory;\n\tprivate createRegion: WebVttRegionFactory;\n\n\t/**\n\t * A callback function that is called when a parsing error occurs.\n\t */\n\tonparsingerror?: (error: WebVttParsingError) => void;\n\n\t/**\n\t * A callback function that is called when a region is parsed.\n\t */\n\tonregion?: (region: WebVttRegion) => void;\n\n\t/**\n\t * A callback function that is called when a timestamp map is parsed.\n\t */\n\tontimestampmap?: (timestampMap: TimestampMap) => void;\n\n\t/**\n\t * A callback function that is called when a cue is parsed.\n\t */\n\toncue?: (cue: WebVttCue) => void;\n\n\t/**\n\t * A callback function that is called when a style is parsed.\n\t */\n\tonstyle?: (style: string) => void;\n\n\t/**\n\t * A callback function that is called when the parser is flushed.\n\t */\n\tonflush?: () => void;\n\n\t/**\n\t * Create a new WebVTT parser.\n\t *\n\t * @param options - The options to use for the parser.\n\t */\n\tconstructor(options: WebVttParserOptions = {}) {\n\t\tconst useDomTypes = options.useDomTypes ?? true;\n\t\tthis.createCue = options.createCue || useDomTypes ? createCue : createWebVttCue;\n\t\tthis.createRegion = options.createRegion || useDomTypes ? createRegion : createWebVttRegion;\n\n\t\tthis.state = WebVttParserState.INITIAL;\n\t\tthis.buffer = '';\n\t\tthis.style = '';\n\t\tthis.regionList = [];\n\t}\n\n\t/**\n\t * Parse the given data.\n\t *\n\t * @param data - The data to parse.\n\t * @param reuseCue - Whether to reuse the cue.\n\t * @returns The parser.\n\t */\n\tparse(data?: string, reuseCue: boolean = false): WebVttParser {\n\t\t// If there is no data then we will just try to parse whatever is in buffer already.\n\t\t// This may occur in circumstances, for example when flush() is called.\n\t\tif (data) {\n\t\t\tthis.buffer += data;\n\t\t}\n\n\t\tconst collectNextLine = (): string => {\n\t\t\tconst buffer = this.buffer;\n\t\t\tlet pos = 0;\n\t\t\twhile (pos < buffer.length && buffer[pos] !== '\\r' && buffer[pos] !== '\\n') {\n\t\t\t\t++pos;\n\t\t\t}\n\t\t\tconst line = buffer.substr(0, pos);\n\t\t\t// Advance the buffer early in case we fail below.\n\t\t\tif (buffer[pos] === '\\r') {\n\t\t\t\t++pos;\n\t\t\t}\n\t\t\tif (buffer[pos] === '\\n') {\n\t\t\t\t++pos;\n\t\t\t}\n\t\t\tthis.buffer = buffer.substr(pos);\n\t\t\treturn line;\n\t\t};\n\n\t\t// draft-pantos-http-live-streaming-20\n\t\t// https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5\n\t\t// 3.5 WebVTT\n\t\tconst parseTimestampMap = (input: string): void => {\n\t\t\tconst settings = new Settings();\n\n\t\t\tparseOptions(input, (k: string, v: string): void => {\n\t\t\t\tswitch (k) {\n\t\t\t\t\tcase 'MPEGT':\n\t\t\t\t\t\tsettings.integer(k + 'S', v);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'LOCA':\n\t\t\t\t\t\tsettings.set(k + 'L', parseTimeStamp(v));\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}, /[^\\d]:/, /,/);\n\n\t\t\tthis.ontimestampmap?.({\n\t\t\t\t'MPEGTS': settings.get('MPEGTS'),\n\t\t\t\t'LOCAL': settings.get('LOCAL'),\n\t\t\t});\n\t\t};\n\n\t\t// 3.2 WebVtt metadata header syntax\n\t\tconst parseHeader = (input: string): void => {\n\t\t\tif (input.match(/X-TIMESTAMP-MAP/)) {\n\t\t\t\t// This line contains HLS X-TIMESTAMP-MAP metadata\n\t\t\t\tparseOptions(input, (k: string, v: string): void => {\n\t\t\t\t\tswitch (k) {\n\t\t\t\t\t\tcase 'X-TIMESTAMP-MAP':\n\t\t\t\t\t\t\tparseTimestampMap(v);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}, /=/);\n\t\t\t}\n\t\t};\n\n\t\t// 6.1 WebVTT file parsing.\n\t\ttry {\n\t\t\tlet line!: string;\n\n\t\t\tif (this.state === WebVttParserState.INITIAL) {\n\t\t\t\t// We can't start parsing until we have the first line.\n\t\t\t\tif (!/\\r\\n|\\n/.test(this.buffer)) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\n\t\t\t\tline = collectNextLine();\n\n\t\t\t\t// Remove the UTF-8 BOM if it exists.\n\t\t\t\tif (line.charCodeAt(0) === 0xFEFF) {\n\t\t\t\t\tline = line.slice(1);\n\t\t\t\t}\n\n\t\t\t\tconst m = line.match(/^WEBVTT([ \\t].*)?$/);\n\t\t\t\tif (!m || !m[0]) {\n\t\t\t\t\tthrow new WebVttParsingError(BAD_SIGNATURE);\n\t\t\t\t}\n\n\t\t\t\tthis.state = WebVttParserState.HEADER;\n\t\t\t}\n\n\t\t\tlet alreadyCollectedLine = false;\n\t\t\tvar sawCue = reuseCue;\n\n\t\t\tif (!reuseCue) {\n\t\t\t\tthis.cue = null;\n\t\t\t\tthis.regionSettings = null;\n\t\t\t}\n\n\t\t\twhile (this.buffer) {\n\t\t\t\t// We can't parse a line until we have the full line.\n\t\t\t\tif (!/\\r\\n|\\n/.test(this.buffer)) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\n\t\t\t\tif (!alreadyCollectedLine) {\n\t\t\t\t\tline = collectNextLine();\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\talreadyCollectedLine = false;\n\t\t\t\t}\n\n\t\t\t\tswitch (this.state) {\n\t\t\t\t\tcase WebVttParserState.HEADER:\n\t\t\t\t\t\t// 13-18 - Allow a header (metadata) under the WEBVTT line.\n\t\t\t\t\t\tif (/:/.test(line)) {\n\t\t\t\t\t\t\tparseHeader(line);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (!line) {\n\t\t\t\t\t\t\t// An empty line terminates the header and blocks section.\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BLOCKS;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.REGION:\n\t\t\t\t\t\tif (!line && this.regionSettings) {\n\t\t\t\t\t\t\t// create the region\n\t\t\t\t\t\t\tconst region = this.createRegion();\n\t\t\t\t\t\t\tregion.id = this.regionSettings.get('id', '');\n\t\t\t\t\t\t\tregion.width = this.regionSettings.get('width', 100);\n\t\t\t\t\t\t\tregion.lines = this.regionSettings.get('lines', 3);\n\t\t\t\t\t\t\tregion.regionAnchorX = this.regionSettings.get('regionanchorX', 0);\n\t\t\t\t\t\t\tregion.regionAnchorY = this.regionSettings.get('regionanchorY', 100);\n\t\t\t\t\t\t\tregion.viewportAnchorX = this.regionSettings.get('viewportanchorX', 0);\n\t\t\t\t\t\t\tregion.viewportAnchorY = this.regionSettings.get('viewportanchorY', 100);\n\t\t\t\t\t\t\tregion.scroll = this.regionSettings.get('scroll', '');\n\n\t\t\t\t\t\t\t// Register the region.\n\t\t\t\t\t\t\tthis.onregion?.(region);\n\n\t\t\t\t\t\t\t// Remember the VTTRegion for later in case we parse any VTTCues that reference it.\n\t\t\t\t\t\t\tthis.regionList.push(region);\n\n\t\t\t\t\t\t\t// An empty line terminates the REGION block\n\t\t\t\t\t\t\tthis.regionSettings = null;\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BLOCKS;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// if it's a new region block, create a new VTTRegion\n\t\t\t\t\t\tif (this.regionSettings === null) {\n\t\t\t\t\t\t\tthis.regionSettings = new Settings();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst regionSettings = this.regionSettings;\n\n\t\t\t\t\t\t// parse region options and set it as appropriate on the region\n\t\t\t\t\t\tparseOptions(line, (k, v) => {\n\t\t\t\t\t\t\tswitch (k) {\n\t\t\t\t\t\t\t\tcase 'id':\n\t\t\t\t\t\t\t\t\tregionSettings.set(k, v);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'width':\n\t\t\t\t\t\t\t\t\tregionSettings.percent(k, v);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'lines':\n\t\t\t\t\t\t\t\t\tregionSettings.integer(k, v);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'regionanchor':\n\t\t\t\t\t\t\t\tcase 'viewportanchor':\n\t\t\t\t\t\t\t\t\tconst xy = v.split(',');\n\t\t\t\t\t\t\t\t\tif (xy.length !== 2) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// We have to make sure both x and y parse, so use a temporary\n\t\t\t\t\t\t\t\t\t// settings object here.\n\t\t\t\t\t\t\t\t\tconst anchor = new Settings();\n\t\t\t\t\t\t\t\t\tanchor.percent('x', xy[0]);\n\t\t\t\t\t\t\t\t\tanchor.percent('y', xy[1]);\n\t\t\t\t\t\t\t\t\tif (!anchor.has('x') || !anchor.has('y')) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tregionSettings.set(k + 'X', anchor.get('x'));\n\t\t\t\t\t\t\t\t\tregionSettings.set(k + 'Y', anchor.get('y'));\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'scroll':\n\t\t\t\t\t\t\t\t\tregionSettings.alt(k, v, ['up']);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, /:/, /\\s/);\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.STYLE:\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tthis.onstyle?.(this.style);\n\t\t\t\t\t\t\tthis.style = '';\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BLOCKS;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.style += line + '\\n';\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.NOTE:\n\t\t\t\t\t\t// Ignore NOTE blocks.\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.BLOCKS:\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check for the start of a NOTE blocks\n\t\t\t\t\t\tif (/^NOTE($[ \\t])/.test(line)) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.NOTE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check for the start of a REGION blocks\n\t\t\t\t\t\tif (/^REGION/.test(line) && !sawCue) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.REGION;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check for the start of a STYLE blocks\n\t\t\t\t\t\tif (/^STYLE/.test(line) && !sawCue) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.STYLE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t// Process line as an ID.\n\t\t\t\t\t/* falls through */\n\t\t\t\t\tcase WebVttParserState.ID:\n\t\t\t\t\t\t// Check for the start of NOTE blocks.\n\t\t\t\t\t\tif (/^NOTE($|[ \\t])/.test(line)) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.NOTE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// 19-29 - Allow any number of line terminators, then initialize new cue values.\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsawCue = true;\n\n\t\t\t\t\t\tthis.cue = this.createCue();\n\t\t\t\t\t\tthis.cue.text ??= '';\n\n\t\t\t\t\t\tthis.state = WebVttParserState.CUE;\n\t\t\t\t\t\t// 30-39 - Check if this line contains an optional identifier or timing data.\n\t\t\t\t\t\tif (line.indexOf('-->') === -1) {\n\t\t\t\t\t\t\tthis.cue.id = line;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t// Process line as start of a cue.\n\t\t\t\t\t/*falls through*/\n\t\t\t\t\tcase WebVttParserState.CUE:\n\t\t\t\t\t\t// 40 - Collect cue timings and settings.\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tparseCue(line, this.cue!, this.regionList);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t\tthis.reportOrThrowError(e);\n\t\t\t\t\t\t\t// In case of an error ignore rest of the cue.\n\t\t\t\t\t\t\tthis.cue = null;\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BAD_CUE;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.state = WebVttParserState.CUE_TEXT;\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.CUE_TEXT:\n\t\t\t\t\t\tconst hasSubstring = line.indexOf('-->') !== -1;\n\n\t\t\t\t\t\t// 34 - If we have an empty line then report the cue.\n\t\t\t\t\t\t// 35 - If we have the special substring '-->' then report the cue,\n\t\t\t\t\t\t// but do not collect the line as we need to process the current\n\t\t\t\t\t\t// one as a new cue.\n\t\t\t\t\t\tif (!line || hasSubstring && (alreadyCollectedLine = true)) {\n\t\t\t\t\t\t\t// We are done parsing this cue.\n\t\t\t\t\t\t\tthis.oncue?.(this.cue!);\n\t\t\t\t\t\t\tthis.cue = null;\n\t\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (this.cue?.text) {\n\t\t\t\t\t\t\tthis.cue.text += '\\n';\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.cue!.text += line.replace(/\\u2028/g, '\\n').replace(/u2029/g, '\\n');\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.BAD_CUE: // BADCUE\n\t\t\t\t\t\t// 54-62 - Collect and discard the remaining cue.\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (e) {\n\t\t\tthis.reportOrThrowError(e);\n\n\t\t\t// If we are currently parsing a cue, report what we have.\n\t\t\tif (this.state === WebVttParserState.CUE_TEXT && this.cue && this.oncue) {\n\t\t\t\tthis.oncue(this.cue);\n\t\t\t}\n\t\t\tthis.cue = null;\n\t\t\tthis.regionSettings = null;\n\n\t\t\t// Enter BADWEBVTT state if header was not parsed correctly otherwise\n\t\t\t// another exception occurred so enter BADCUE state.\n\t\t\tthis.state = this.state === WebVttParserState.INITIAL ? WebVttParserState.BAD_WEBVTT : WebVttParserState.BAD_CUE;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Flush the parser.\n\t *\n\t * @returns The parser.\n\t */\n\tflush(): WebVttParser {\n\t\ttry {\n\t\t\t// Finish parsing the stream.\n\t\t\tthis.buffer += '';\n\t\t\t// Synthesize the end of the current cue or region.\n\t\t\tif (this.cue || this.state === WebVttParserState.HEADER) {\n\t\t\t\tthis.buffer += '\\n\\n';\n\t\t\t\tthis.parse(undefined, true);\n\t\t\t}\n\t\t\t// If we've flushed, parsed, and we're still on the INITIAL state then\n\t\t\t// that means we don't have enough of the stream to parse the first\n\t\t\t// line.\n\t\t\tif (this.state === WebVttParserState.INITIAL) {\n\t\t\t\tthrow new WebVttParsingError(BAD_SIGNATURE);\n\t\t\t}\n\t\t}\n\t\tcatch (e) {\n\t\t\tthis.reportOrThrowError(e);\n\t\t}\n\n\t\tthis.onflush?.();\n\n\t\treturn this;\n\t}\n\n\t// If the error is a ParsingError then report it to the consumer if\n\t// possible. If it's not a ParsingError then throw it like normal.\n\tprivate reportOrThrowError(error: any): void {\n\t\tif (error instanceof WebVttParsingError) {\n\t\t\tthis.onparsingerror?.(error);\n\t\t}\n\t\telse {\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n","import type { WebVttCue } from './WebVttCue.js';\nimport { WebVttParser } from './WebVttParser.js';\nimport type { WebVttParseResult } from './WebVttParseResult.js';\nimport type { WebVttParserOptions } from './WebVttParserOptions.js';\nimport type { WebVttParsingError } from './WebVttParsingError.js';\nimport type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * Parse a WebVTT string into a WebVttParseResult.\n *\n * @param text - The WebVTT string to parse.\n * @param options - The options to use for the parser.\n * @returns The parsed WebVttParseResult.\n *\n *\n * @beta\n *\n * @example\n * {@includeCode ../test/parseWebVtt.test.ts#example}\n */\nexport async function parseWebVtt(text: string, options?: WebVttParserOptions): Promise<WebVttParseResult> {\n\tconst parser = new WebVttParser(options);\n\tconst cues: WebVttCue[] = [];\n\tconst regions: WebVttRegion[] = [];\n\tconst styles: string[] = [];\n\tconst errors: WebVttParsingError[] = [];\n\tparser.oncue = cue => cues.push(cue);\n\tparser.onregion = region => regions.push(region);\n\tparser.onstyle = style => styles.push(style);\n\tparser.onparsingerror = error => errors.push(error);\n\tparser.parse(text);\n\tparser.flush();\n\n\treturn { cues, regions, styles, errors };\n}\n","import type { WebVttCue } from './WebVttCue.js';\n\n/**\n * Convert a generic WebVTT cue to a VTTCue.\n *\n * @param cue - The WebVTT cue to convert.\n * @returns The converted VTTCue.\n *\n *\n * @beta\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}\n */\nexport function toVttCue(cue: WebVttCue): VTTCue {\n\tconst vttCue = new VTTCue(cue.startTime, cue.endTime, cue.text);\n\tvttCue.id = cue.id;\n\tvttCue.region = cue.region;\n\tvttCue.vertical = cue.vertical;\n\tvttCue.snapToLines = cue.snapToLines;\n\tvttCue.line = cue.line;\n\tvttCue.lineAlign = cue.lineAlign;\n\tvttCue.position = cue.position;\n\tvttCue.positionAlign = cue.positionAlign;\n\tvttCue.size = cue.size;\n\tvttCue.pauseOnExit = cue.pauseOnExit;\n\n\t// Safari still uses the old middle value and won't accept center\n\ttry {\n\t\tvttCue.align = 'center';\n\t}\n\tcatch (e) {\n\t\tvttCue.align = 'middle' as AlignSetting;\n\t}\n\n\treturn vttCue;\n}\n","import type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * Convert a WebVTT region to a VTTRegion.\n *\n * @param region - The WebVTT region to convert.\n * @returns The converted VTTRegion.\n *\n *\n * @beta\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}\n */\nexport function toVttRegion(region: WebVttRegion): VTTRegion {\n\tconst vttRegion = new VTTRegion();\n\tvttRegion.id = region.id;\n\tvttRegion.width = region.width;\n\tvttRegion.lines = region.lines;\n\tvttRegion.regionAnchorX = region.regionAnchorX;\n\tvttRegion.regionAnchorY = region.regionAnchorY;\n\tvttRegion.viewportAnchorX = region.viewportAnchorX;\n\tvttRegion.viewportAnchorY = region.viewportAnchorY;\n\tvttRegion.scroll = region.scroll;\n\n\treturn vttRegion;\n}\n","import type { ValueOf } from '@svta/cml-utils';\n\n/**\n * WebVTT result types.\n *\n *\n * @beta\n *\n * @enum\n */\nexport const WebVttResultType = {\n\tCUE: 'cue',\n\tREGION: 'region',\n\tTIMESTAMP_MAP: 'timestampmap',\n\tSTYLE: 'style',\n\tERROR: 'error',\n} as const;\n\n/**\n * @beta\n */\nexport type WebVttResultType = ValueOf<typeof WebVttResultType>;\n","import { WebVttParser } from './WebVttParser.js';\nimport type { WebVttResult } from './WebVttResult.js';\nimport { WebVttResultType } from './WebVttResultType.js';\n\n/**\n * WebVTT transform stream transformer.\n *\n *\n * @beta\n */\nexport class WebVttTransformer {\n\tprivate readonly parser: WebVttParser;\n\tprivate results: WebVttResult[] = [];\n\n\t/**\n\t * Creates a new WebVTT transformer.\n\t */\n\tconstructor() {\n\t\tthis.parser = new WebVttParser();\n\t\tthis.parser.oncue = cue => this.results.push({ type: WebVttResultType.CUE, data: cue });\n\t\tthis.parser.onregion = region => this.results.push({ type: WebVttResultType.REGION, data: region });\n\t\tthis.parser.onstyle = style => this.results.push({ type: WebVttResultType.STYLE, data: style });\n\t\tthis.parser.ontimestampmap = timestampmap => this.results.push({ type: WebVttResultType.TIMESTAMP_MAP, data: timestampmap });\n\t\tthis.parser.onparsingerror = error => this.results.push({ type: WebVttResultType.ERROR, data: error });\n\t}\n\n\tprivate enqueueResults(controller: TransformStreamDefaultController<WebVttResult>): void {\n\t\t// TODO: Should parse errors throw?\n\t\tfor (const result of this.results) {\n\t\t\tcontroller.enqueue(result);\n\t\t}\n\n\t\tthis.results = [];\n\t}\n\n\t/**\n\t * Transforms a chunk of WebVTT data.\n\t *\n\t * @param chunk - The chunk of WebVTT data to transform.\n\t * @param controller - The controller to enqueue the results to.\n\t */\n\ttransform(chunk: string, controller: TransformStreamDefaultController<WebVttResult>): void {\n\t\ttry {\n\t\t\tthis.parser.parse(chunk);\n\t\t\tthis.enqueueResults(controller);\n\t\t}\n\t\tcatch (error) {\n\t\t\tcontroller.error(error);\n\t\t}\n\t}\n\n\t/**\n\t * Flushes the transformer.\n\t *\n\t * @param controller - The controller to enqueue the results to.\n\t */\n\tflush(controller: TransformStreamDefaultController<WebVttResult>): void {\n\t\ttry {\n\t\t\tthis.parser.flush();\n\t\t\tthis.enqueueResults(controller);\n\t\t}\n\t\tcatch (error) {\n\t\t\tcontroller.error(error);\n\t\t}\n\t}\n}\n","import type { WebVttResult } from './WebVttResult.js';\nimport { WebVttTransformer } from './WebVttTransformer.js';\n\n/**\n * WebVTT transform stream.\n *\n *\n * @beta\n */\nexport class WebVttTransformStream extends TransformStream<string, WebVttResult> {\n\tconstructor(writableStrategy?: QueuingStrategy<string>, readableStrategy?: QueuingStrategy<WebVttResult>) {\n\t\tsuper(new WebVttTransformer(), writableStrategy, readableStrategy);\n\t}\n}\n"],"mappings":";;;;;;;;;;AAWA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AAa,wBAAb,cAA2C,gBAAsC;CAChF,YAAY,kBAA4C,kBAAkD;AACzG,QAAM,IAAI,mBAAmB,EAAE,kBAAkB,iBAAiB"}
{
"name": "@svta/cml-webvtt",
"version": "0.19.0",
"version": "0.20.0",
"description": "WebVTT parsing and rendering functionality",
"license": "Apache-2.0",
"type": "module",
"homepage": "https://github.com/streaming-video-technology-alliance/common-media-library",
"homepage": "https://github.com/streaming-video-technology-alliance/common-media-library/tree/main/libs/webvtt",
"authors": "Casey Occhialini <1508707+littlespex@users.noreply.github.com>",

@@ -31,21 +31,4 @@ "repository": {

"default": "./dist/index.js"
},
"./*.js": {
"import": "./dist/*.js",
"default": "./dist/*.js"
},
"./*": {
"types": "./dist/*.d.ts",
"import": "./dist/*.js",
"default": "./dist/*.js"
}
},
"typesVersions": {
"*": {
"*": [
"dist/*",
"dist/cjs/*"
]
}
},
"keywords": [

@@ -60,6 +43,4 @@ "Common Media Library",

"scripts": {
"build": "tsc",
"postbuild": "api-extractor run --local",
"test": "node --no-warnings --test **/*.test.ts",
"prepublishOnly": "npm run build"
"build": "node ../../scripts/build.ts",
"test": "node ../../scripts/test.ts"
},

@@ -77,4 +58,4 @@ "engines": {

"peerDependencies": {
"@svta/cml-utils": "*"
"@svta/cml-utils": "0.20.0"
}
}
import type { WebVttCue } from './WebVttCue.js';
/**
* Create a generic WebVttCue object with default values
* that match the DOM VTTCue interface.
*
* @returns A WebVttCue object with default values
*
*
* @beta
*/
export declare function createWebVttCue(): WebVttCue;
//# sourceMappingURL=createWebVttCue.d.ts.map
{"version":3,"file":"createWebVttCue.d.ts","sourceRoot":"","sources":["../src/createWebVttCue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAiB3C"}
/**
* Create a generic WebVttCue object with default values
* that match the DOM VTTCue interface.
*
* @returns A WebVttCue object with default values
*
*
* @beta
*/
export function createWebVttCue() {
return {
id: '',
startTime: 0,
endTime: 0,
region: null,
snapToLines: true,
line: 'auto',
lineAlign: 'start',
position: 'auto',
positionAlign: 'auto',
size: 100,
align: 'center',
vertical: '',
pauseOnExit: false,
text: '',
};
}
//# sourceMappingURL=createWebVttCue.js.map
{"version":3,"file":"createWebVttCue.js","sourceRoot":"","sources":["../src/createWebVttCue.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO;QACN,EAAE,EAAE,EAAE;QACN,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,IAAI;QACjB,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,MAAM;QAChB,aAAa,EAAE,MAAM;QACrB,IAAI,EAAE,GAAG;QACT,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,KAAK;QAClB,IAAI,EAAE,EAAE;KACR,CAAC;AACH,CAAC","sourcesContent":["import type { WebVttCue } from './WebVttCue.js';\n\n/**\n * Create a generic WebVttCue object with default values\n * that match the DOM VTTCue interface.\n *\n * @returns A WebVttCue object with default values\n *\n *\n * @beta\n */\nexport function createWebVttCue(): WebVttCue {\n\treturn {\n\t\tid: '',\n\t\tstartTime: 0,\n\t\tendTime: 0,\n\t\tregion: null,\n\t\tsnapToLines: true,\n\t\tline: 'auto',\n\t\tlineAlign: 'start',\n\t\tposition: 'auto',\n\t\tpositionAlign: 'auto',\n\t\tsize: 100,\n\t\talign: 'center',\n\t\tvertical: '',\n\t\tpauseOnExit: false,\n\t\ttext: '',\n\t};\n}\n"]}
import type { WebVttRegion } from './WebVttRegion.js';
/**
* Create a generic WebVttRegion object with default values
* that match the DOM VTTRegion interface.
*
* @returns A WebVttRegion object with default values
*
*
* @beta
*/
export declare function createWebVttRegion(): WebVttRegion;
//# sourceMappingURL=createWebVttRegion.d.ts.map
{"version":3,"file":"createWebVttRegion.d.ts","sourceRoot":"","sources":["../src/createWebVttRegion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAWjD"}
/**
* Create a generic WebVttRegion object with default values
* that match the DOM VTTRegion interface.
*
* @returns A WebVttRegion object with default values
*
*
* @beta
*/
export function createWebVttRegion() {
return {
id: '',
width: 100,
lines: 3,
regionAnchorX: 0,
regionAnchorY: 100,
viewportAnchorX: 0,
viewportAnchorY: 100,
scroll: '',
};
}
//# sourceMappingURL=createWebVttRegion.js.map
{"version":3,"file":"createWebVttRegion.js","sourceRoot":"","sources":["../src/createWebVttRegion.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB;IACjC,OAAO;QACN,EAAE,EAAE,EAAE;QACN,KAAK,EAAE,GAAG;QACV,KAAK,EAAE,CAAC;QACR,aAAa,EAAE,CAAC;QAChB,aAAa,EAAE,GAAG;QAClB,eAAe,EAAE,CAAC;QAClB,eAAe,EAAE,GAAG;QACpB,MAAM,EAAE,EAAE;KACV,CAAC;AACH,CAAC","sourcesContent":["import type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * Create a generic WebVttRegion object with default values\n * that match the DOM VTTRegion interface.\n *\n * @returns A WebVttRegion object with default values\n *\n *\n * @beta\n */\nexport function createWebVttRegion(): WebVttRegion {\n\treturn {\n\t\tid: '',\n\t\twidth: 100,\n\t\tlines: 3,\n\t\tregionAnchorX: 0,\n\t\tregionAnchorY: 100,\n\t\tviewportAnchorX: 0,\n\t\tviewportAnchorY: 100,\n\t\tscroll: '',\n\t};\n}\n"]}
import type { WebVttCue } from '../WebVttCue.js';
import type { WebVttRegion } from '../WebVttRegion.js';
export declare function parseCue(input: string, cue: WebVttCue, regionList: WebVttRegion[]): void;
//# sourceMappingURL=parseCue.d.ts.map
{"version":3,"file":"parseCue.d.ts","sourceRoot":"","sources":["../../src/parse/parseCue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,IAAI,CAwHxF"}
import { WebVttParsingError } from '../WebVttParsingError.js';
import { parseOptions } from './parseOptions.js';
import { parseTimeStamp } from './parseTimestamp.js';
import { Settings } from './Settings.js';
const BAD_TIMESTAMP = 'Malformed time stamp.';
export function parseCue(input, cue, regionList) {
// Remember the original input if we need to throw an error.
const oInput = input;
// 4.1 WebVTT timestamp
function consumeTimeStamp() {
const ts = parseTimeStamp(input);
if (ts === null) {
throw new WebVttParsingError(BAD_TIMESTAMP + oInput);
}
// Remove time stamp from input.
input = input.replace(/^[^\sa-zA-Z-]+/, '');
return ts;
}
// 4.4.2 WebVTT cue settings
function consumeCueSettings(input, cue) {
const settings = new Settings();
parseOptions(input, function (k, v) {
switch (k) {
case 'region': {
// Find the last region we parsed with the same region id.
for (let i = regionList.length - 1; i >= 0; i--) {
if (regionList[i].id === v) {
settings.set(k, regionList[i]);
break;
}
}
break;
}
case 'vertical': {
settings.alt(k, v, ['rl', 'lr']);
break;
}
case 'line': {
const vals = v.split(',');
const vals0 = vals[0];
settings.integer(k, vals0);
settings.percent(k, vals0) ? settings.set('snapToLines', false) : null;
settings.alt(k, vals0, ['auto']);
if (vals.length === 2) {
settings.alt('lineAlign', vals[1], ['start', 'center', 'end']);
}
break;
}
case 'position': {
const vals = v.split(',');
settings.percent(k, vals[0]);
if (vals.length === 2) {
settings.alt('positionAlign', vals[1], ['line-left', 'center', 'line-right', 'auto']);
}
break;
}
case 'size': {
settings.percent(k, v);
break;
}
case 'align': {
settings.alt(k, v, ['start', 'center', 'end', 'left', 'right']);
break;
}
}
}, /:/, /\s/);
// Apply default values for any missing fields.
cue.region = settings.get('region', null);
cue.vertical = settings.get('vertical', '');
try {
cue.line = settings.get('line', 'auto');
}
catch (e) {
// eslint-ignore-line
}
cue.lineAlign = settings.get('lineAlign', 'start');
cue.snapToLines = settings.get('snapToLines', true);
cue.size = settings.get('size', 100);
// Safari still uses the old middle value and won't accept center
try {
cue.align = settings.get('align', 'center');
}
catch (e) {
cue.align = settings.get('align', 'middle');
}
try {
cue.position = settings.get('position', 'auto');
}
catch (e) {
const positions = {
start: 0,
left: 0,
center: 50,
middle: 50,
end: 100,
right: 100,
};
cue.position = settings.get('position', positions[cue.align]);
}
cue.positionAlign = settings.get('positionAlign', 'auto');
}
function skipWhitespace() {
input = input.replace(/^\s+/, '');
}
// 4.1 WebVTT cue timings.
skipWhitespace();
cue.startTime = consumeTimeStamp(); // (1) collect cue start time
skipWhitespace();
if (input.substr(0, 3) !== '-->') { // (3) next characters must match "-->"
throw new WebVttParsingError(BAD_TIMESTAMP + " (time stamps must be separated by '-->'): ");
}
input = input.substr(3);
skipWhitespace();
cue.endTime = consumeTimeStamp(); // (5) collect cue end time
// 4.1 WebVTT cue settings list.
skipWhitespace();
consumeCueSettings(input, cue);
}
//# sourceMappingURL=parseCue.js.map
{"version":3,"file":"parseCue.js","sourceRoot":"","sources":["../../src/parse/parseCue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,GAAc,EAAE,UAA0B;IACjF,4DAA4D;IAC5D,MAAM,MAAM,GAAG,KAAK,CAAC;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gBACV,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,GAAG;aACV,CAAC;YAEF,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,CAAC;QAED,GAAG,CAAC,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IAED,SAAS,cAAc;QACtB,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,0BAA0B;IAC1B,cAAc,EAAE,CAAC;IACjB,GAAG,CAAC,SAAS,GAAG,gBAAgB,EAAE,CAAC,CAAG,6BAA6B;IACnE,cAAc,EAAE,CAAC;IACjB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAK,uCAAuC;QAC9E,MAAM,IAAI,kBAAkB,CAAC,aAAa,GAAG,6CAA6C,CAAC,CAAC;IAC7F,CAAC;IACD,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,cAAc,EAAE,CAAC;IACjB,GAAG,CAAC,OAAO,GAAG,gBAAgB,EAAE,CAAC,CAAK,2BAA2B;IAEjE,gCAAgC;IAChC,cAAc,EAAE,CAAC;IACjB,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { WebVttCue } from '../WebVttCue.js';\nimport { WebVttParsingError } from '../WebVttParsingError.js';\nimport type { WebVttRegion } from '../WebVttRegion.js';\nimport { parseOptions } from './parseOptions.js';\nimport { parseTimeStamp } from './parseTimestamp.js';\nimport { Settings } from './Settings.js';\n\nconst BAD_TIMESTAMP = 'Malformed time stamp.';\n\nexport function parseCue(input: string, cue: WebVttCue, regionList: WebVttRegion[]): void {\n\t// Remember the original input if we need to throw an error.\n\tconst oInput = input;\n\t// 4.1 WebVTT timestamp\n\tfunction consumeTimeStamp() {\n\t\tconst ts = parseTimeStamp(input);\n\t\tif (ts === null) {\n\t\t\tthrow new WebVttParsingError(BAD_TIMESTAMP + oInput);\n\t\t}\n\t\t// Remove time stamp from input.\n\t\tinput = input.replace(/^[^\\sa-zA-Z-]+/, '');\n\t\treturn ts;\n\t}\n\n\t// 4.4.2 WebVTT cue settings\n\tfunction consumeCueSettings(input: string, cue: WebVttCue): void {\n\t\tconst settings = new Settings();\n\n\t\tparseOptions(input, function (k, v) {\n\t\t\tswitch (k) {\n\t\t\t\tcase 'region': {\n\t\t\t\t\t// Find the last region we parsed with the same region id.\n\t\t\t\t\tfor (let i = regionList.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tif (regionList[i].id === v) {\n\t\t\t\t\t\t\tsettings.set(k, regionList[i]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'vertical': {\n\t\t\t\t\tsettings.alt(k, v, ['rl', 'lr']);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'line': {\n\t\t\t\t\tconst vals = v.split(',');\n\t\t\t\t\tconst vals0 = vals[0];\n\t\t\t\t\tsettings.integer(k, vals0);\n\t\t\t\t\tsettings.percent(k, vals0) ? settings.set('snapToLines', false) : null;\n\t\t\t\t\tsettings.alt(k, vals0, ['auto']);\n\t\t\t\t\tif (vals.length === 2) {\n\t\t\t\t\t\tsettings.alt('lineAlign', vals[1], ['start', 'center', 'end']);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'position': {\n\t\t\t\t\tconst vals = v.split(',');\n\t\t\t\t\tsettings.percent(k, vals[0]);\n\t\t\t\t\tif (vals.length === 2) {\n\t\t\t\t\t\tsettings.alt('positionAlign', vals[1], ['line-left', 'center', 'line-right', 'auto']);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'size': {\n\t\t\t\t\tsettings.percent(k, v);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase 'align': {\n\t\t\t\t\tsettings.alt(k, v, ['start', 'center', 'end', 'left', 'right']);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}, /:/, /\\s/);\n\n\t\t// Apply default values for any missing fields.\n\t\tcue.region = settings.get('region', null);\n\t\tcue.vertical = settings.get('vertical', '');\n\t\ttry {\n\t\t\tcue.line = settings.get('line', 'auto');\n\t\t}\n\t\tcatch (e) {\n\t\t\t// eslint-ignore-line\n\t\t}\n\t\tcue.lineAlign = settings.get('lineAlign', 'start');\n\t\tcue.snapToLines = settings.get('snapToLines', true);\n\t\tcue.size = settings.get('size', 100);\n\t\t// Safari still uses the old middle value and won't accept center\n\t\ttry {\n\t\t\tcue.align = settings.get('align', 'center');\n\t\t}\n\t\tcatch (e) {\n\t\t\tcue.align = settings.get('align', 'middle' as AlignSetting);\n\t\t}\n\t\ttry {\n\t\t\tcue.position = settings.get('position', 'auto');\n\t\t}\n\t\tcatch (e) {\n\t\t\tconst positions = {\n\t\t\t\tstart: 0,\n\t\t\t\tleft: 0,\n\t\t\t\tcenter: 50,\n\t\t\t\tmiddle: 50,\n\t\t\t\tend: 100,\n\t\t\t\tright: 100,\n\t\t\t};\n\n\t\t\tcue.position = settings.get('position', positions[cue.align]);\n\t\t}\n\n\t\tcue.positionAlign = settings.get('positionAlign', 'auto');\n\t}\n\n\tfunction skipWhitespace() {\n\t\tinput = input.replace(/^\\s+/, '');\n\t}\n\n\t// 4.1 WebVTT cue timings.\n\tskipWhitespace();\n\tcue.startTime = consumeTimeStamp(); // (1) collect cue start time\n\tskipWhitespace();\n\tif (input.substr(0, 3) !== '-->') { // (3) next characters must match \"-->\"\n\t\tthrow new WebVttParsingError(BAD_TIMESTAMP + \" (time stamps must be separated by '-->'): \");\n\t}\n\tinput = input.substr(3);\n\tskipWhitespace();\n\tcue.endTime = consumeTimeStamp(); // (5) collect cue end time\n\n\t// 4.1 WebVTT cue settings list.\n\tskipWhitespace();\n\tconsumeCueSettings(input, cue);\n}\n"]}
export declare function parseOptions(input: string, callback: (k: string, v: string) => void, keyValueDelim: string | RegExp, groupDelim?: string | RegExp): void;
//# sourceMappingURL=parseOptions.d.ts.map
{"version":3,"file":"parseOptions.d.ts","sourceRoot":"","sources":["../../src/parse/parseOptions.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoBxJ"}
// Helper function to parse input into groups separated by 'groupDelim', and
// interpet each group as a key/value pair separated by 'keyValueDelim'.
export function parseOptions(input, callback, keyValueDelim, groupDelim) {
// TODO: Optimize parsing to avoid creating new arrays and strings.
const groups = groupDelim ? input.split(groupDelim) : [input];
for (const i in groups) {
if (typeof groups[i] !== 'string') {
continue;
}
const kv = groups[i].split(keyValueDelim);
if (kv.length !== 2) {
continue;
}
const k = kv[0];
const v = kv[1].trim();
// TODO: Return a value instead of using a callback.
callback(k, v);
}
}
//# sourceMappingURL=parseOptions.js.map
{"version":3,"file":"parseOptions.js","sourceRoot":"","sources":["../../src/parse/parseOptions.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,QAAwC,EAAE,aAA8B,EAAE,UAA4B;IACjJ,mEAAmE;IACnE,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAE9D,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACxB,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACnC,SAAS;QACV,CAAC;QAED,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC1C,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrB,SAAS;QACV,CAAC;QAED,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAEvB,oDAAoD;QACpD,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChB,CAAC;AACF,CAAC","sourcesContent":["// Helper function to parse input into groups separated by 'groupDelim', and\n// interpet each group as a key/value pair separated by 'keyValueDelim'.\nexport function parseOptions(input: string, callback: (k: string, v: string) => void, keyValueDelim: string | RegExp, groupDelim?: string | RegExp): void {\n\t// TODO: Optimize parsing to avoid creating new arrays and strings.\n\tconst groups = groupDelim ? input.split(groupDelim) : [input];\n\n\tfor (const i in groups) {\n\t\tif (typeof groups[i] !== 'string') {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst kv = groups[i].split(keyValueDelim);\n\t\tif (kv.length !== 2) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst k = kv[0];\n\t\tconst v = kv[1].trim();\n\n\t\t// TODO: Return a value instead of using a callback.\n\t\tcallback(k, v);\n\t}\n}\n"]}
export declare function parseTimeStamp(input: string): number | null;
//# sourceMappingURL=parseTimestamp.d.ts.map
{"version":3,"file":"parseTimestamp.d.ts","sourceRoot":"","sources":["../../src/parse/parseTimestamp.ts"],"names":[],"mappings":"AAKA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA0B3D"}
function computeSeconds(h, m, s, f) {
return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
}
// Try to parse input as a time stamp.
export function parseTimeStamp(input) {
var _a;
// TODO: Optimize parsing to avoid creating new arrays and strings.
const m = input.match(/^(\d+):(\d{1,2})(:\d{1,2})?\.(\d{3})/);
if (!m) {
return null;
}
const first = parseInt(m[1]);
const second = parseInt(m[2]);
const third = parseInt(((_a = m[3]) === null || _a === void 0 ? void 0 : _a.replace(':', '')) || '0');
const fourth = parseInt(m[4]);
if (m[3]) {
// Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
return computeSeconds(first, second, third, fourth);
}
else if (first > 59) {
// Timestamp takes the form of [hours]:[minutes].[milliseconds]
// First position is hours as it's over 59.
return computeSeconds(first, second, 0, fourth);
}
else {
// Timestamp takes the form of [minutes]:[seconds].[milliseconds]
return computeSeconds(0, first, second, fourth);
}
}
//# sourceMappingURL=parseTimestamp.js.map
{"version":3,"file":"parseTimestamp.js","sourceRoot":"","sources":["../../src/parse/parseTimestamp.ts"],"names":[],"mappings":"AAAA,SAAS,cAAc,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IACjE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AACjE,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,cAAc,CAAC,KAAa;;IAC3C,mEAAmE;IACnE,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAE9D,IAAI,CAAC,CAAC,EAAE,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAA,MAAA,CAAC,CAAC,CAAC,CAAC,0CAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,KAAI,GAAG,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9B,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACV,yEAAyE;QACzE,OAAO,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;SACI,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACrB,+DAA+D;QAC/D,2CAA2C;QAC3C,OAAO,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;SACI,CAAC;QACL,iEAAiE;QACjE,OAAO,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;AACF,CAAC","sourcesContent":["function computeSeconds(h: number, m: number, s: number, f: number): number {\n\treturn (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;\n}\n\n// Try to parse input as a time stamp.\nexport function parseTimeStamp(input: string): number | null {\n\t// TODO: Optimize parsing to avoid creating new arrays and strings.\n\tconst m = input.match(/^(\\d+):(\\d{1,2})(:\\d{1,2})?\\.(\\d{3})/);\n\n\tif (!m) {\n\t\treturn null;\n\t}\n\n\tconst first = parseInt(m[1]);\n\tconst second = parseInt(m[2]);\n\tconst third = parseInt(m[3]?.replace(':', '') || '0');\n\tconst fourth = parseInt(m[4]);\n\n\tif (m[3]) {\n\t\t// Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]\n\t\treturn computeSeconds(first, second, third, fourth);\n\t}\n\telse if (first > 59) {\n\t\t// Timestamp takes the form of [hours]:[minutes].[milliseconds]\n\t\t// First position is hours as it's over 59.\n\t\treturn computeSeconds(first, second, 0, fourth);\n\t}\n\telse {\n\t\t// Timestamp takes the form of [minutes]:[seconds].[milliseconds]\n\t\treturn computeSeconds(0, first, second, fourth);\n\t}\n}\n"]}
import type { WebVttRegion } from '../WebVttRegion.js';
export type SettingsValue = WebVttRegion | string | number | boolean | null;
export declare class Settings {
private values;
constructor();
set(k: string, v: SettingsValue): void;
get<T = SettingsValue>(k: string, dflt?: T): T;
has(k: string): boolean;
alt(k: string, v: string, a: string[]): void;
integer(k: string, v: string): void;
percent(k: string, v: string): boolean;
}
//# sourceMappingURL=Settings.d.ts.map
{"version":3,"file":"Settings.d.ts","sourceRoot":"","sources":["../../src/parse/Settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAI5E,qBAAa,QAAQ;IACpB,OAAO,CAAC,MAAM,CAAgC;;IAO9C,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,GAAG,IAAI;IAatC,GAAG,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC;IAS9C,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAKvB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI;IAU5C,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAOnC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;CAWtC"}
// A settings object holds key/value pairs and will ignore anything but the first
// assignment to a specific key.
export class Settings {
constructor() {
this.values = Object.create(null);
}
// Only accept the first assignment to any key.
set(k, v) {
if (this.get(k) || v === '') {
return;
}
this.values[k] = v;
}
// Return the value for a key, or a default value.
// If 'defaultKey' is passed then 'dflt' is assumed to be an object with
// a number of possible default values as properties where 'defaultKey' is
// the key of the property that will be chosen; otherwise it's assumed to be
// a single value.
get(k, dflt) {
if (this.has(k)) {
return this.values[k];
}
return dflt;
}
// Check whether we have a value for a key.
has(k) {
return k in this.values;
}
// Accept a setting if its one of the given alternatives.
alt(k, v, a) {
for (let n = 0; n < a.length; ++n) {
if (v === a[n]) {
this.set(k, v);
break;
}
}
}
// Accept a setting if its a valid (signed) integer.
integer(k, v) {
if (/^-?\d+$/.test(v)) { // integer
this.set(k, parseInt(v, 10));
}
}
// Accept a setting if its a valid percentage.
percent(k, v) {
if (v.match(/^([\d]{1,3})(\.[\d]*)?%$/)) {
const value = parseFloat(v);
if (value >= 0 && value <= 100) {
this.set(k, value);
return true;
}
}
return false;
}
}
//# sourceMappingURL=Settings.js.map
{"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../src/parse/Settings.ts"],"names":[],"mappings":"AAIA,iFAAiF;AACjF,gCAAgC;AAChC,MAAM,OAAO,QAAQ;IAGpB;QACC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,+CAA+C;IAC/C,GAAG,CAAC,CAAS,EAAE,CAAgB;QAC9B,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YAC7B,OAAO;QACR,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,kDAAkD;IAClD,wEAAwE;IACxE,0EAA0E;IAC1E,4EAA4E;IAC5E,kBAAkB;IAClB,GAAG,CAAoB,CAAS,EAAE,IAAQ;QACzC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAM,CAAC;QAC5B,CAAC;QAED,OAAO,IAAS,CAAC;IAClB,CAAC;IAED,2CAA2C;IAC3C,GAAG,CAAC,CAAS;QACZ,OAAO,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,yDAAyD;IACzD,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAW;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACf,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;IAED,oDAAoD;IACpD,OAAO,CAAC,CAAS,EAAE,CAAS;QAC3B,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU;YAClC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,8CAA8C;IAC9C,OAAO,CAAC,CAAS,EAAE,CAAS;QAC3B,IAAI,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE,CAAC;YACzC,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;gBAChC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACnB,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["import type { WebVttRegion } from '../WebVttRegion.js';\n\nexport type SettingsValue = WebVttRegion | string | number | boolean | null;\n\n// A settings object holds key/value pairs and will ignore anything but the first\n// assignment to a specific key.\nexport class Settings {\n\tprivate values: Record<string, SettingsValue>;\n\n\tconstructor() {\n\t\tthis.values = Object.create(null);\n\t}\n\n\t// Only accept the first assignment to any key.\n\tset(k: string, v: SettingsValue): void {\n\t\tif (this.get(k) || v === '') {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.values[k] = v;\n\t}\n\n\t// Return the value for a key, or a default value.\n\t// If 'defaultKey' is passed then 'dflt' is assumed to be an object with\n\t// a number of possible default values as properties where 'defaultKey' is\n\t// the key of the property that will be chosen; otherwise it's assumed to be\n\t// a single value.\n\tget<T = SettingsValue>(k: string, dflt?: T): T {\n\t\tif (this.has(k)) {\n\t\t\treturn this.values[k] as T;\n\t\t}\n\n\t\treturn dflt as T;\n\t}\n\n\t// Check whether we have a value for a key.\n\thas(k: string): boolean {\n\t\treturn k in this.values;\n\t}\n\n\t// Accept a setting if its one of the given alternatives.\n\talt(k: string, v: string, a: string[]): void {\n\t\tfor (let n = 0; n < a.length; ++n) {\n\t\t\tif (v === a[n]) {\n\t\t\t\tthis.set(k, v);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Accept a setting if its a valid (signed) integer.\n\tinteger(k: string, v: string): void {\n\t\tif (/^-?\\d+$/.test(v)) { // integer\n\t\t\tthis.set(k, parseInt(v, 10));\n\t\t}\n\t}\n\n\t// Accept a setting if its a valid percentage.\n\tpercent(k: string, v: string): boolean {\n\t\tif (v.match(/^([\\d]{1,3})(\\.[\\d]*)?%$/)) {\n\t\t\tconst value = parseFloat(v);\n\t\t\tif (value >= 0 && value <= 100) {\n\t\t\t\tthis.set(k, value);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n}\n"]}
import type { ValueOf } from '@svta/cml-utils/ValueOf.js';
export declare const WebVttParserState: {
readonly INITIAL: "INITIAL";
readonly HEADER: "HEADER";
readonly REGION: "REGION";
readonly STYLE: "STYLE";
readonly NOTE: "NOTE";
readonly BLOCKS: "BLOCKS";
readonly ID: "ID";
readonly CUE: "CUE";
readonly CUE_TEXT: "CUE_EXT";
readonly BAD_CUE: "BAD_CUE";
readonly BAD_WEBVTT: "BAD_WEBVTT";
};
export type WebVttParserState = ValueOf<typeof WebVttParserState>;
//# sourceMappingURL=WebVttParserState.d.ts.map
{"version":3,"file":"WebVttParserState.d.ts","sourceRoot":"","sources":["../../src/parse/WebVttParserState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;CAYpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
export const WebVttParserState = {
INITIAL: 'INITIAL',
HEADER: 'HEADER',
REGION: 'REGION',
STYLE: 'STYLE',
NOTE: 'NOTE',
BLOCKS: 'BLOCKS',
ID: 'ID',
CUE: 'CUE',
CUE_TEXT: 'CUE_EXT',
BAD_CUE: 'BAD_CUE',
BAD_WEBVTT: 'BAD_WEBVTT',
};
//# sourceMappingURL=WebVttParserState.js.map
{"version":3,"file":"WebVttParserState.js","sourceRoot":"","sources":["../../src/parse/WebVttParserState.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAChC,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,SAAS;IACnB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;CACf,CAAC","sourcesContent":["import type { ValueOf } from '@svta/cml-utils/ValueOf.js';\n\nexport const WebVttParserState = {\n\tINITIAL: 'INITIAL',\n\tHEADER: 'HEADER',\n\tREGION: 'REGION',\n\tSTYLE: 'STYLE',\n\tNOTE: 'NOTE',\n\tBLOCKS: 'BLOCKS',\n\tID: 'ID',\n\tCUE: 'CUE',\n\tCUE_TEXT: 'CUE_EXT',\n\tBAD_CUE: 'BAD_CUE',\n\tBAD_WEBVTT: 'BAD_WEBVTT',\n} as const;\n\nexport type WebVttParserState = ValueOf<typeof WebVttParserState>;\n"]}
import type { WebVttParseResult } from './WebVttParseResult.js';
import type { WebVttParserOptions } from './WebVttParserOptions.js';
/**
* Parse a WebVTT string into a WebVttParseResult.
*
* @param text - The WebVTT string to parse.
* @param options - The options to use for the parser.
* @returns The parsed WebVttParseResult.
*
*
* @beta
*
* @example
* {@includeCode ../test/parseWebVtt.test.ts#example}
*/
export declare function parseWebVtt(text: string, options?: WebVttParserOptions): Promise<WebVttParseResult>;
//# sourceMappingURL=parseWebVtt.d.ts.map
{"version":3,"file":"parseWebVtt.d.ts","sourceRoot":"","sources":["../src/parseWebVtt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIpE;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAczG"}
import { WebVttParser } from './WebVttParser.js';
/**
* Parse a WebVTT string into a WebVttParseResult.
*
* @param text - The WebVTT string to parse.
* @param options - The options to use for the parser.
* @returns The parsed WebVttParseResult.
*
*
* @beta
*
* @example
* {@includeCode ../test/parseWebVtt.test.ts#example}
*/
export async function parseWebVtt(text, options) {
const parser = new WebVttParser(options);
const cues = [];
const regions = [];
const styles = [];
const errors = [];
parser.oncue = cue => cues.push(cue);
parser.onregion = region => regions.push(region);
parser.onstyle = style => styles.push(style);
parser.onparsingerror = error => errors.push(error);
parser.parse(text);
parser.flush();
return { cues, regions, styles, errors };
}
//# sourceMappingURL=parseWebVtt.js.map
{"version":3,"file":"parseWebVtt.js","sourceRoot":"","sources":["../src/parseWebVtt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMjD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,OAA6B;IAC5E,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAmB,EAAE,CAAC;IACnC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAyB,EAAE,CAAC;IACxC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type { WebVttCue } from './WebVttCue.js';\nimport { WebVttParser } from './WebVttParser.js';\nimport type { WebVttParseResult } from './WebVttParseResult.js';\nimport type { WebVttParserOptions } from './WebVttParserOptions.js';\nimport type { WebVttParsingError } from './WebVttParsingError.js';\nimport type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * Parse a WebVTT string into a WebVttParseResult.\n *\n * @param text - The WebVTT string to parse.\n * @param options - The options to use for the parser.\n * @returns The parsed WebVttParseResult.\n *\n *\n * @beta\n *\n * @example\n * {@includeCode ../test/parseWebVtt.test.ts#example}\n */\nexport async function parseWebVtt(text: string, options?: WebVttParserOptions): Promise<WebVttParseResult> {\n\tconst parser = new WebVttParser(options);\n\tconst cues: WebVttCue[] = [];\n\tconst regions: WebVttRegion[] = [];\n\tconst styles: string[] = [];\n\tconst errors: WebVttParsingError[] = [];\n\tparser.oncue = cue => cues.push(cue);\n\tparser.onregion = region => regions.push(region);\n\tparser.onstyle = style => styles.push(style);\n\tparser.onparsingerror = error => errors.push(error);\n\tparser.parse(text);\n\tparser.flush();\n\n\treturn { cues, regions, styles, errors };\n}\n"]}
/**
* A timestamp map is a mapping of MPEG timestamps to local timestamps.
*
*
* @beta
*
* @see {@link https://datatracker.ietf.org/doc/html/rfc8216#section-3.5 | RFC 8216}
*/
export type TimestampMap = {
MPEGTS: number;
LOCAL: number;
};
//# sourceMappingURL=TimestampMap.d.ts.map
{"version":3,"file":"TimestampMap.d.ts","sourceRoot":"","sources":["../src/TimestampMap.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd,CAAC"}
export {};
//# sourceMappingURL=TimestampMap.js.map
{"version":3,"file":"TimestampMap.js","sourceRoot":"","sources":["../src/TimestampMap.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * A timestamp map is a mapping of MPEG timestamps to local timestamps.\n *\n *\n * @beta\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc8216#section-3.5 | RFC 8216}\n */\nexport type TimestampMap = {\n\tMPEGTS: number;\n\tLOCAL: number;\n};\n"]}
import type { WebVttCue } from './WebVttCue.js';
/**
* Convert a generic WebVTT cue to a VTTCue.
*
* @param cue - The WebVTT cue to convert.
* @returns The converted VTTCue.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}
*/
export declare function toVttCue(cue: WebVttCue): VTTCue;
//# sourceMappingURL=toVttCue.d.ts.map
{"version":3,"file":"toVttCue.d.ts","sourceRoot":"","sources":["../src/toVttCue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAsB/C"}
/**
* Convert a generic WebVTT cue to a VTTCue.
*
* @param cue - The WebVTT cue to convert.
* @returns The converted VTTCue.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}
*/
export function toVttCue(cue) {
const vttCue = new VTTCue(cue.startTime, cue.endTime, cue.text);
vttCue.id = cue.id;
vttCue.region = cue.region;
vttCue.vertical = cue.vertical;
vttCue.snapToLines = cue.snapToLines;
vttCue.line = cue.line;
vttCue.lineAlign = cue.lineAlign;
vttCue.position = cue.position;
vttCue.positionAlign = cue.positionAlign;
vttCue.size = cue.size;
vttCue.pauseOnExit = cue.pauseOnExit;
// Safari still uses the old middle value and won't accept center
try {
vttCue.align = 'center';
}
catch (e) {
vttCue.align = 'middle';
}
return vttCue;
}
//# sourceMappingURL=toVttCue.js.map
{"version":3,"file":"toVttCue.js","sourceRoot":"","sources":["../src/toVttCue.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAc;IACtC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;IACnB,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC3B,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC/B,MAAM,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;IACrC,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACvB,MAAM,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;IACjC,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC/B,MAAM,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;IACzC,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACvB,MAAM,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;IAErC,iEAAiE;IACjE,IAAI,CAAC;QACJ,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC;IACzB,CAAC;IACD,OAAO,CAAC,EAAE,CAAC;QACV,MAAM,CAAC,KAAK,GAAG,QAAwB,CAAC;IACzC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { WebVttCue } from './WebVttCue.js';\n\n/**\n * Convert a generic WebVTT cue to a VTTCue.\n *\n * @param cue - The WebVTT cue to convert.\n * @returns The converted VTTCue.\n *\n *\n * @beta\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}\n */\nexport function toVttCue(cue: WebVttCue): VTTCue {\n\tconst vttCue = new VTTCue(cue.startTime, cue.endTime, cue.text);\n\tvttCue.id = cue.id;\n\tvttCue.region = cue.region;\n\tvttCue.vertical = cue.vertical;\n\tvttCue.snapToLines = cue.snapToLines;\n\tvttCue.line = cue.line;\n\tvttCue.lineAlign = cue.lineAlign;\n\tvttCue.position = cue.position;\n\tvttCue.positionAlign = cue.positionAlign;\n\tvttCue.size = cue.size;\n\tvttCue.pauseOnExit = cue.pauseOnExit;\n\n\t// Safari still uses the old middle value and won't accept center\n\ttry {\n\t\tvttCue.align = 'center';\n\t}\n\tcatch (e) {\n\t\tvttCue.align = 'middle' as AlignSetting;\n\t}\n\n\treturn vttCue;\n}\n"]}
import type { WebVttRegion } from './WebVttRegion.js';
/**
* Convert a WebVTT region to a VTTRegion.
*
* @param region - The WebVTT region to convert.
* @returns The converted VTTRegion.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}
*/
export declare function toVttRegion(region: WebVttRegion): VTTRegion;
//# sourceMappingURL=toVttRegion.d.ts.map
{"version":3,"file":"toVttRegion.d.ts","sourceRoot":"","sources":["../src/toVttRegion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAY3D"}
/**
* Convert a WebVTT region to a VTTRegion.
*
* @param region - The WebVTT region to convert.
* @returns The converted VTTRegion.
*
*
* @beta
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}
*/
export function toVttRegion(region) {
const vttRegion = new VTTRegion();
vttRegion.id = region.id;
vttRegion.width = region.width;
vttRegion.lines = region.lines;
vttRegion.regionAnchorX = region.regionAnchorX;
vttRegion.regionAnchorY = region.regionAnchorY;
vttRegion.viewportAnchorX = region.viewportAnchorX;
vttRegion.viewportAnchorY = region.viewportAnchorY;
vttRegion.scroll = region.scroll;
return vttRegion;
}
//# sourceMappingURL=toVttRegion.js.map
{"version":3,"file":"toVttRegion.js","sourceRoot":"","sources":["../src/toVttRegion.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC/C,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAClC,SAAS,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACzB,SAAS,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,SAAS,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,SAAS,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC/C,SAAS,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC/C,SAAS,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IACnD,SAAS,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IACnD,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAEjC,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * Convert a WebVTT region to a VTTRegion.\n *\n * @param region - The WebVTT region to convert.\n * @returns The converted VTTRegion.\n *\n *\n * @beta\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}\n */\nexport function toVttRegion(region: WebVttRegion): VTTRegion {\n\tconst vttRegion = new VTTRegion();\n\tvttRegion.id = region.id;\n\tvttRegion.width = region.width;\n\tvttRegion.lines = region.lines;\n\tvttRegion.regionAnchorX = region.regionAnchorX;\n\tvttRegion.regionAnchorY = region.regionAnchorY;\n\tvttRegion.viewportAnchorX = region.viewportAnchorX;\n\tvttRegion.viewportAnchorY = region.viewportAnchorY;\n\tvttRegion.scroll = region.scroll;\n\n\treturn vttRegion;\n}\n"]}

Sorry, the diff of this file is not supported yet

import type { WebVttRegion } from './WebVttRegion.js';
/**
* A WebVTT cue.
*
*
* @beta
*/
export type WebVttCue = {
id: string;
startTime: number;
endTime: number;
pauseOnExit: boolean;
text: string;
align: AlignSetting;
region: WebVttRegion | null;
vertical: DirectionSetting;
snapToLines: boolean;
line: LineAndPositionSetting;
lineAlign: LineAlignSetting;
position: LineAndPositionSetting;
positionAlign: PositionAlignSetting;
size: number;
};
//# sourceMappingURL=WebVttCue.d.ts.map
{"version":3,"file":"WebVttCue.d.ts","sourceRoot":"","sources":["../src/WebVttCue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,sBAAsB,CAAC;IAC7B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,aAAa,EAAE,oBAAoB,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;CACb,CAAC"}
export {};
//# sourceMappingURL=WebVttCue.js.map
{"version":3,"file":"WebVttCue.js","sourceRoot":"","sources":["../src/WebVttCue.ts"],"names":[],"mappings":"","sourcesContent":["import type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * A WebVTT cue.\n *\n *\n * @beta\n */\nexport type WebVttCue = {\n\tid: string;\n\tstartTime: number;\n\tendTime: number;\n\tpauseOnExit: boolean;\n\ttext: string;\n\talign: AlignSetting;\n\tregion: WebVttRegion | null;\n\tvertical: DirectionSetting;\n\tsnapToLines: boolean;\n\tline: LineAndPositionSetting;\n\tlineAlign: LineAlignSetting;\n\tposition: LineAndPositionSetting;\n\tpositionAlign: PositionAlignSetting;\n\tsize: number;\n};\n"]}
import type { WebVttCue } from './WebVttCue';
/**
* A factory for creating WebVttCue objects.
*
*
* @beta
*/
export type WebVttCueFactory = () => WebVttCue;
//# sourceMappingURL=WebVttCueFactory.d.ts.map
{"version":3,"file":"WebVttCueFactory.d.ts","sourceRoot":"","sources":["../src/WebVttCueFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,SAAS,CAAC"}
export {};
//# sourceMappingURL=WebVttCueFactory.js.map
{"version":3,"file":"WebVttCueFactory.js","sourceRoot":"","sources":["../src/WebVttCueFactory.ts"],"names":[],"mappings":"","sourcesContent":["import type { WebVttCue } from './WebVttCue';\n\n/**\n * A factory for creating WebVttCue objects.\n *\n *\n * @beta\n */\nexport type WebVttCueFactory = () => WebVttCue;\n"]}
import type { TypedResult } from '@svta/cml-utils/TypedResult.js';
import type { WebVttCue } from './WebVttCue.js';
/**
* WebVTT transform stream cue result.
*
*
* @beta
*/
export type WebVttCueResult = TypedResult<'cue', WebVttCue>;
//# sourceMappingURL=WebVttCueResult.d.ts.map
{"version":3,"file":"WebVttCueResult.d.ts","sourceRoot":"","sources":["../src/WebVttCueResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC"}
export {};
//# sourceMappingURL=WebVttCueResult.js.map
{"version":3,"file":"WebVttCueResult.js","sourceRoot":"","sources":["../src/WebVttCueResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedResult } from '@svta/cml-utils/TypedResult.js';\nimport type { WebVttCue } from './WebVttCue.js';\n\n/**\n * WebVTT transform stream cue result.\n *\n *\n * @beta\n */\nexport type WebVttCueResult = TypedResult<'cue', WebVttCue>;\n"]}
import type { TypedResult } from '@svta/cml-utils/TypedResult.js';
import type { WebVttParsingError } from './WebVttParsingError.js';
/**
* WebVTT transform stream error result.
*
*
* @beta
*/
export type WebVttErrorResult = TypedResult<'error', WebVttParsingError>;
//# sourceMappingURL=WebVttErrorResult.d.ts.map
{"version":3,"file":"WebVttErrorResult.d.ts","sourceRoot":"","sources":["../src/WebVttErrorResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC"}
export {};
//# sourceMappingURL=WebVttErrorResult.js.map
{"version":3,"file":"WebVttErrorResult.js","sourceRoot":"","sources":["../src/WebVttErrorResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedResult } from '@svta/cml-utils/TypedResult.js';\nimport type { WebVttParsingError } from './WebVttParsingError.js';\n\n/**\n * WebVTT transform stream error result.\n *\n *\n * @beta\n */\nexport type WebVttErrorResult = TypedResult<'error', WebVttParsingError>;\n"]}
import type { TimestampMap } from './TimestampMap.js';
import type { WebVttCue } from './WebVttCue.js';
import type { WebVttParserOptions } from './WebVttParserOptions.js';
import { WebVttParsingError } from './WebVttParsingError.js';
import type { WebVttRegion } from './WebVttRegion.js';
/**
* A WebVTT parser.
*
*
* @beta
*
* @example
* {@includeCode ../test/WebVttParser.test.ts#example}
*
* @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT Specification}
*/
export declare class WebVttParser {
private state;
private buffer;
private regionList;
private regionSettings;
private style;
private cue;
private createCue;
private createRegion;
/**
* A callback function that is called when a parsing error occurs.
*/
onparsingerror?: (error: WebVttParsingError) => void;
/**
* A callback function that is called when a region is parsed.
*/
onregion?: (region: WebVttRegion) => void;
/**
* A callback function that is called when a timestamp map is parsed.
*/
ontimestampmap?: (timestampMap: TimestampMap) => void;
/**
* A callback function that is called when a cue is parsed.
*/
oncue?: (cue: WebVttCue) => void;
/**
* A callback function that is called when a style is parsed.
*/
onstyle?: (style: string) => void;
/**
* A callback function that is called when the parser is flushed.
*/
onflush?: () => void;
/**
* Create a new WebVTT parser.
*
* @param options - The options to use for the parser.
*/
constructor(options?: WebVttParserOptions);
/**
* Parse the given data.
*
* @param data - The data to parse.
* @param reuseCue - Whether to reuse the cue.
* @returns The parser.
*/
parse(data?: string, reuseCue?: boolean): WebVttParser;
/**
* Flush the parser.
*
* @returns The parser.
*/
flush(): WebVttParser;
private reportOrThrowError;
}
//# sourceMappingURL=WebVttParser.d.ts.map
{"version":3,"file":"WebVttParser.d.ts","sourceRoot":"","sources":["../src/WebVttParser.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOtD;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACxB,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,cAAc,CAAyB;IAC/C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,YAAY,CAAsB;IAE1C;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAErD;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAE1C;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAEtD;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC;IAEjC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;;;;OAIG;gBACS,OAAO,GAAE,mBAAwB;IAW7C;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,YAAY;IA4T7D;;;;OAIG;IACH,KAAK,IAAI,YAAY;IA2BrB,OAAO,CAAC,kBAAkB;CAQ1B"}
import { createWebVttCue } from './createWebVttCue.js';
import { createWebVttRegion } from './createWebVttRegion.js';
import { parseCue } from './parse/parseCue.js';
import { parseOptions } from './parse/parseOptions.js';
import { parseTimeStamp } from './parse/parseTimestamp.js';
import { Settings } from './parse/Settings.js';
import { WebVttParserState } from './parse/WebVttParserState.js';
import { WebVttParsingError } from './WebVttParsingError.js';
const BAD_SIGNATURE = 'Malformed WebVTT signature.';
const createCue = () => typeof VTTCue !== 'undefined' ? new VTTCue(0, 0, '') : createWebVttCue();
const createRegion = () => typeof VTTRegion !== 'undefined' ? new VTTRegion() : createWebVttRegion();
/**
* A WebVTT parser.
*
*
* @beta
*
* @example
* {@includeCode ../test/WebVttParser.test.ts#example}
*
* @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT Specification}
*/
export class WebVttParser {
/**
* Create a new WebVTT parser.
*
* @param options - The options to use for the parser.
*/
constructor(options = {}) {
var _a;
this.regionSettings = null;
this.cue = null;
const useDomTypes = (_a = options.useDomTypes) !== null && _a !== void 0 ? _a : true;
this.createCue = options.createCue || useDomTypes ? createCue : createWebVttCue;
this.createRegion = options.createRegion || useDomTypes ? createRegion : createWebVttRegion;
this.state = WebVttParserState.INITIAL;
this.buffer = '';
this.style = '';
this.regionList = [];
}
/**
* Parse the given data.
*
* @param data - The data to parse.
* @param reuseCue - Whether to reuse the cue.
* @returns The parser.
*/
parse(data, reuseCue = false) {
var _a, _b, _c, _d, _e;
var _f;
// If there is no data then we will just try to parse whatever is in buffer already.
// This may occur in circumstances, for example when flush() is called.
if (data) {
this.buffer += data;
}
const collectNextLine = () => {
const buffer = this.buffer;
let pos = 0;
while (pos < buffer.length && buffer[pos] !== '\r' && buffer[pos] !== '\n') {
++pos;
}
const line = buffer.substr(0, pos);
// Advance the buffer early in case we fail below.
if (buffer[pos] === '\r') {
++pos;
}
if (buffer[pos] === '\n') {
++pos;
}
this.buffer = buffer.substr(pos);
return line;
};
// draft-pantos-http-live-streaming-20
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5
// 3.5 WebVTT
const parseTimestampMap = (input) => {
var _a;
const settings = new Settings();
parseOptions(input, (k, v) => {
switch (k) {
case 'MPEGT':
settings.integer(k + 'S', v);
break;
case 'LOCA':
settings.set(k + 'L', parseTimeStamp(v));
break;
}
}, /[^\d]:/, /,/);
(_a = this.ontimestampmap) === null || _a === void 0 ? void 0 : _a.call(this, {
'MPEGTS': settings.get('MPEGTS'),
'LOCAL': settings.get('LOCAL'),
});
};
// 3.2 WebVtt metadata header syntax
const parseHeader = (input) => {
if (input.match(/X-TIMESTAMP-MAP/)) {
// This line contains HLS X-TIMESTAMP-MAP metadata
parseOptions(input, (k, v) => {
switch (k) {
case 'X-TIMESTAMP-MAP':
parseTimestampMap(v);
break;
}
}, /=/);
}
};
// 6.1 WebVTT file parsing.
try {
let line;
if (this.state === WebVttParserState.INITIAL) {
// We can't start parsing until we have the first line.
if (!/\r\n|\n/.test(this.buffer)) {
return this;
}
line = collectNextLine();
// Remove the UTF-8 BOM if it exists.
if (line.charCodeAt(0) === 0xFEFF) {
line = line.slice(1);
}
const m = line.match(/^WEBVTT([ \t].*)?$/);
if (!m || !m[0]) {
throw new WebVttParsingError(BAD_SIGNATURE);
}
this.state = WebVttParserState.HEADER;
}
let alreadyCollectedLine = false;
var sawCue = reuseCue;
if (!reuseCue) {
this.cue = null;
this.regionSettings = null;
}
while (this.buffer) {
// We can't parse a line until we have the full line.
if (!/\r\n|\n/.test(this.buffer)) {
return this;
}
if (!alreadyCollectedLine) {
line = collectNextLine();
}
else {
alreadyCollectedLine = false;
}
switch (this.state) {
case WebVttParserState.HEADER:
// 13-18 - Allow a header (metadata) under the WEBVTT line.
if (/:/.test(line)) {
parseHeader(line);
}
else if (!line) {
// An empty line terminates the header and blocks section.
this.state = WebVttParserState.BLOCKS;
}
continue;
case WebVttParserState.REGION:
if (!line && this.regionSettings) {
// create the region
const region = this.createRegion();
region.id = this.regionSettings.get('id', '');
region.width = this.regionSettings.get('width', 100);
region.lines = this.regionSettings.get('lines', 3);
region.regionAnchorX = this.regionSettings.get('regionanchorX', 0);
region.regionAnchorY = this.regionSettings.get('regionanchorY', 100);
region.viewportAnchorX = this.regionSettings.get('viewportanchorX', 0);
region.viewportAnchorY = this.regionSettings.get('viewportanchorY', 100);
region.scroll = this.regionSettings.get('scroll', '');
// Register the region.
(_a = this.onregion) === null || _a === void 0 ? void 0 : _a.call(this, region);
// Remember the VTTRegion for later in case we parse any VTTCues that reference it.
this.regionList.push(region);
// An empty line terminates the REGION block
this.regionSettings = null;
this.state = WebVttParserState.BLOCKS;
break;
}
// if it's a new region block, create a new VTTRegion
if (this.regionSettings === null) {
this.regionSettings = new Settings();
}
const regionSettings = this.regionSettings;
// parse region options and set it as appropriate on the region
parseOptions(line, (k, v) => {
switch (k) {
case 'id':
regionSettings.set(k, v);
break;
case 'width':
regionSettings.percent(k, v);
break;
case 'lines':
regionSettings.integer(k, v);
break;
case 'regionanchor':
case 'viewportanchor':
const xy = v.split(',');
if (xy.length !== 2) {
break;
}
// We have to make sure both x and y parse, so use a temporary
// settings object here.
const anchor = new Settings();
anchor.percent('x', xy[0]);
anchor.percent('y', xy[1]);
if (!anchor.has('x') || !anchor.has('y')) {
break;
}
regionSettings.set(k + 'X', anchor.get('x'));
regionSettings.set(k + 'Y', anchor.get('y'));
break;
case 'scroll':
regionSettings.alt(k, v, ['up']);
break;
}
}, /:/, /\s/);
continue;
case WebVttParserState.STYLE:
if (!line) {
(_b = this.onstyle) === null || _b === void 0 ? void 0 : _b.call(this, this.style);
this.style = '';
this.state = WebVttParserState.BLOCKS;
break;
}
this.style += line + '\n';
continue;
case WebVttParserState.NOTE:
// Ignore NOTE blocks.
if (!line) {
this.state = WebVttParserState.ID;
}
continue;
case WebVttParserState.BLOCKS:
if (!line) {
continue;
}
// Check for the start of a NOTE blocks
if (/^NOTE($[ \t])/.test(line)) {
this.state = WebVttParserState.NOTE;
break;
}
// Check for the start of a REGION blocks
if (/^REGION/.test(line) && !sawCue) {
this.state = WebVttParserState.REGION;
break;
}
// Check for the start of a STYLE blocks
if (/^STYLE/.test(line) && !sawCue) {
this.state = WebVttParserState.STYLE;
break;
}
this.state = WebVttParserState.ID;
// Process line as an ID.
/* falls through */
case WebVttParserState.ID:
// Check for the start of NOTE blocks.
if (/^NOTE($|[ \t])/.test(line)) {
this.state = WebVttParserState.NOTE;
break;
}
// 19-29 - Allow any number of line terminators, then initialize new cue values.
if (!line) {
continue;
}
sawCue = true;
this.cue = this.createCue();
(_c = (_f = this.cue).text) !== null && _c !== void 0 ? _c : (_f.text = '');
this.state = WebVttParserState.CUE;
// 30-39 - Check if this line contains an optional identifier or timing data.
if (line.indexOf('-->') === -1) {
this.cue.id = line;
continue;
}
// Process line as start of a cue.
/*falls through*/
case WebVttParserState.CUE:
// 40 - Collect cue timings and settings.
try {
parseCue(line, this.cue, this.regionList);
}
catch (e) {
this.reportOrThrowError(e);
// In case of an error ignore rest of the cue.
this.cue = null;
this.state = WebVttParserState.BAD_CUE;
continue;
}
this.state = WebVttParserState.CUE_TEXT;
continue;
case WebVttParserState.CUE_TEXT:
const hasSubstring = line.indexOf('-->') !== -1;
// 34 - If we have an empty line then report the cue.
// 35 - If we have the special substring '-->' then report the cue,
// but do not collect the line as we need to process the current
// one as a new cue.
if (!line || hasSubstring && (alreadyCollectedLine = true)) {
// We are done parsing this cue.
(_d = this.oncue) === null || _d === void 0 ? void 0 : _d.call(this, this.cue);
this.cue = null;
this.state = WebVttParserState.ID;
continue;
}
if ((_e = this.cue) === null || _e === void 0 ? void 0 : _e.text) {
this.cue.text += '\n';
}
this.cue.text += line.replace(/\u2028/g, '\n').replace(/u2029/g, '\n');
continue;
case WebVttParserState.BAD_CUE: // BADCUE
// 54-62 - Collect and discard the remaining cue.
if (!line) {
this.state = WebVttParserState.ID;
}
continue;
}
}
}
catch (e) {
this.reportOrThrowError(e);
// If we are currently parsing a cue, report what we have.
if (this.state === WebVttParserState.CUE_TEXT && this.cue && this.oncue) {
this.oncue(this.cue);
}
this.cue = null;
this.regionSettings = null;
// Enter BADWEBVTT state if header was not parsed correctly otherwise
// another exception occurred so enter BADCUE state.
this.state = this.state === WebVttParserState.INITIAL ? WebVttParserState.BAD_WEBVTT : WebVttParserState.BAD_CUE;
}
return this;
}
/**
* Flush the parser.
*
* @returns The parser.
*/
flush() {
var _a;
try {
// Finish parsing the stream.
this.buffer += '';
// Synthesize the end of the current cue or region.
if (this.cue || this.state === WebVttParserState.HEADER) {
this.buffer += '\n\n';
this.parse(undefined, true);
}
// If we've flushed, parsed, and we're still on the INITIAL state then
// that means we don't have enough of the stream to parse the first
// line.
if (this.state === WebVttParserState.INITIAL) {
throw new WebVttParsingError(BAD_SIGNATURE);
}
}
catch (e) {
this.reportOrThrowError(e);
}
(_a = this.onflush) === null || _a === void 0 ? void 0 : _a.call(this);
return this;
}
// If the error is a ParsingError then report it to the consumer if
// possible. If it's not a ParsingError then throw it like normal.
reportOrThrowError(error) {
var _a;
if (error instanceof WebVttParsingError) {
(_a = this.onparsingerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
}
else {
throw error;
}
}
}
//# sourceMappingURL=WebVttParser.js.map
{"version":3,"file":"WebVttParser.js","sourceRoot":"","sources":["../src/WebVttParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,E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ACb,CAAC;IAED,mEAAmE;IACnE,kEAAkE;IAC1D,kBAAkB,CAAC,KAAU;;QACpC,IAAI,KAAK,YAAY,kBAAkB,EAAE,CAAC;YACzC,MAAA,IAAI,CAAC,cAAc,qDAAG,KAAK,CAAC,CAAC;QAC9B,CAAC;aACI,CAAC;YACL,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;CACD","sourcesContent":["import { createWebVttCue } from './createWebVttCue.js';\nimport { createWebVttRegion } from './createWebVttRegion.js';\nimport { parseCue } from './parse/parseCue.js';\nimport { parseOptions } from './parse/parseOptions.js';\nimport { parseTimeStamp } from './parse/parseTimestamp.js';\nimport { Settings } from './parse/Settings.js';\nimport { WebVttParserState } from './parse/WebVttParserState.js';\nimport type { TimestampMap } from './TimestampMap.js';\nimport type { WebVttCue } from './WebVttCue.js';\nimport type { WebVttCueFactory } from './WebVttCueFactory.js';\nimport type { WebVttParserOptions } from './WebVttParserOptions.js';\nimport { WebVttParsingError } from './WebVttParsingError.js';\nimport type { WebVttRegion } from './WebVttRegion.js';\nimport type { WebVttRegionFactory } from './WebVttRegionFactory.js';\n\nconst BAD_SIGNATURE = 'Malformed WebVTT signature.';\nconst createCue = (): WebVttCue => typeof VTTCue !== 'undefined' ? new VTTCue(0, 0, '') : createWebVttCue();\nconst createRegion = (): WebVttRegion => typeof VTTRegion !== 'undefined' ? new VTTRegion() : createWebVttRegion();\n\n/**\n * A WebVTT parser.\n *\n *\n * @beta\n *\n * @example\n * {@includeCode ../test/WebVttParser.test.ts#example}\n *\n * @see {@link https://www.w3.org/TR/webvtt1/ | WebVTT Specification}\n */\nexport class WebVttParser {\n\tprivate state: WebVttParserState;\n\tprivate buffer: string;\n\tprivate regionList: WebVttRegion[];\n\tprivate regionSettings: Settings | null = null;\n\tprivate style: string;\n\tprivate cue: WebVttCue | null = null;\n\tprivate createCue: WebVttCueFactory;\n\tprivate createRegion: WebVttRegionFactory;\n\n\t/**\n\t * A callback function that is called when a parsing error occurs.\n\t */\n\tonparsingerror?: (error: WebVttParsingError) => void;\n\n\t/**\n\t * A callback function that is called when a region is parsed.\n\t */\n\tonregion?: (region: WebVttRegion) => void;\n\n\t/**\n\t * A callback function that is called when a timestamp map is parsed.\n\t */\n\tontimestampmap?: (timestampMap: TimestampMap) => void;\n\n\t/**\n\t * A callback function that is called when a cue is parsed.\n\t */\n\toncue?: (cue: WebVttCue) => void;\n\n\t/**\n\t * A callback function that is called when a style is parsed.\n\t */\n\tonstyle?: (style: string) => void;\n\n\t/**\n\t * A callback function that is called when the parser is flushed.\n\t */\n\tonflush?: () => void;\n\n\t/**\n\t * Create a new WebVTT parser.\n\t *\n\t * @param options - The options to use for the parser.\n\t */\n\tconstructor(options: WebVttParserOptions = {}) {\n\t\tconst useDomTypes = options.useDomTypes ?? true;\n\t\tthis.createCue = options.createCue || useDomTypes ? createCue : createWebVttCue;\n\t\tthis.createRegion = options.createRegion || useDomTypes ? createRegion : createWebVttRegion;\n\n\t\tthis.state = WebVttParserState.INITIAL;\n\t\tthis.buffer = '';\n\t\tthis.style = '';\n\t\tthis.regionList = [];\n\t}\n\n\t/**\n\t * Parse the given data.\n\t *\n\t * @param data - The data to parse.\n\t * @param reuseCue - Whether to reuse the cue.\n\t * @returns The parser.\n\t */\n\tparse(data?: string, reuseCue: boolean = false): WebVttParser {\n\t\t// If there is no data then we will just try to parse whatever is in buffer already.\n\t\t// This may occur in circumstances, for example when flush() is called.\n\t\tif (data) {\n\t\t\tthis.buffer += data;\n\t\t}\n\n\t\tconst collectNextLine = (): string => {\n\t\t\tconst buffer = this.buffer;\n\t\t\tlet pos = 0;\n\t\t\twhile (pos < buffer.length && buffer[pos] !== '\\r' && buffer[pos] !== '\\n') {\n\t\t\t\t++pos;\n\t\t\t}\n\t\t\tconst line = buffer.substr(0, pos);\n\t\t\t// Advance the buffer early in case we fail below.\n\t\t\tif (buffer[pos] === '\\r') {\n\t\t\t\t++pos;\n\t\t\t}\n\t\t\tif (buffer[pos] === '\\n') {\n\t\t\t\t++pos;\n\t\t\t}\n\t\t\tthis.buffer = buffer.substr(pos);\n\t\t\treturn line;\n\t\t};\n\n\t\t// draft-pantos-http-live-streaming-20\n\t\t// https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5\n\t\t// 3.5 WebVTT\n\t\tconst parseTimestampMap = (input: string): void => {\n\t\t\tconst settings = new Settings();\n\n\t\t\tparseOptions(input, (k: string, v: string): void => {\n\t\t\t\tswitch (k) {\n\t\t\t\t\tcase 'MPEGT':\n\t\t\t\t\t\tsettings.integer(k + 'S', v);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'LOCA':\n\t\t\t\t\t\tsettings.set(k + 'L', parseTimeStamp(v));\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}, /[^\\d]:/, /,/);\n\n\t\t\tthis.ontimestampmap?.({\n\t\t\t\t'MPEGTS': settings.get('MPEGTS'),\n\t\t\t\t'LOCAL': settings.get('LOCAL'),\n\t\t\t});\n\t\t};\n\n\t\t// 3.2 WebVtt metadata header syntax\n\t\tconst parseHeader = (input: string): void => {\n\t\t\tif (input.match(/X-TIMESTAMP-MAP/)) {\n\t\t\t\t// This line contains HLS X-TIMESTAMP-MAP metadata\n\t\t\t\tparseOptions(input, (k: string, v: string): void => {\n\t\t\t\t\tswitch (k) {\n\t\t\t\t\t\tcase 'X-TIMESTAMP-MAP':\n\t\t\t\t\t\t\tparseTimestampMap(v);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}, /=/);\n\t\t\t}\n\t\t};\n\n\t\t// 6.1 WebVTT file parsing.\n\t\ttry {\n\t\t\tlet line!: string;\n\n\t\t\tif (this.state === WebVttParserState.INITIAL) {\n\t\t\t\t// We can't start parsing until we have the first line.\n\t\t\t\tif (!/\\r\\n|\\n/.test(this.buffer)) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\n\t\t\t\tline = collectNextLine();\n\n\t\t\t\t// Remove the UTF-8 BOM if it exists.\n\t\t\t\tif (line.charCodeAt(0) === 0xFEFF) {\n\t\t\t\t\tline = line.slice(1);\n\t\t\t\t}\n\n\t\t\t\tconst m = line.match(/^WEBVTT([ \\t].*)?$/);\n\t\t\t\tif (!m || !m[0]) {\n\t\t\t\t\tthrow new WebVttParsingError(BAD_SIGNATURE);\n\t\t\t\t}\n\n\t\t\t\tthis.state = WebVttParserState.HEADER;\n\t\t\t}\n\n\t\t\tlet alreadyCollectedLine = false;\n\t\t\tvar sawCue = reuseCue;\n\n\t\t\tif (!reuseCue) {\n\t\t\t\tthis.cue = null;\n\t\t\t\tthis.regionSettings = null;\n\t\t\t}\n\n\t\t\twhile (this.buffer) {\n\t\t\t\t// We can't parse a line until we have the full line.\n\t\t\t\tif (!/\\r\\n|\\n/.test(this.buffer)) {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\n\t\t\t\tif (!alreadyCollectedLine) {\n\t\t\t\t\tline = collectNextLine();\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\talreadyCollectedLine = false;\n\t\t\t\t}\n\n\t\t\t\tswitch (this.state) {\n\t\t\t\t\tcase WebVttParserState.HEADER:\n\t\t\t\t\t\t// 13-18 - Allow a header (metadata) under the WEBVTT line.\n\t\t\t\t\t\tif (/:/.test(line)) {\n\t\t\t\t\t\t\tparseHeader(line);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (!line) {\n\t\t\t\t\t\t\t// An empty line terminates the header and blocks section.\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BLOCKS;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.REGION:\n\t\t\t\t\t\tif (!line && this.regionSettings) {\n\t\t\t\t\t\t\t// create the region\n\t\t\t\t\t\t\tconst region = this.createRegion();\n\t\t\t\t\t\t\tregion.id = this.regionSettings.get('id', '');\n\t\t\t\t\t\t\tregion.width = this.regionSettings.get('width', 100);\n\t\t\t\t\t\t\tregion.lines = this.regionSettings.get('lines', 3);\n\t\t\t\t\t\t\tregion.regionAnchorX = this.regionSettings.get('regionanchorX', 0);\n\t\t\t\t\t\t\tregion.regionAnchorY = this.regionSettings.get('regionanchorY', 100);\n\t\t\t\t\t\t\tregion.viewportAnchorX = this.regionSettings.get('viewportanchorX', 0);\n\t\t\t\t\t\t\tregion.viewportAnchorY = this.regionSettings.get('viewportanchorY', 100);\n\t\t\t\t\t\t\tregion.scroll = this.regionSettings.get('scroll', '');\n\n\t\t\t\t\t\t\t// Register the region.\n\t\t\t\t\t\t\tthis.onregion?.(region);\n\n\t\t\t\t\t\t\t// Remember the VTTRegion for later in case we parse any VTTCues that reference it.\n\t\t\t\t\t\t\tthis.regionList.push(region);\n\n\t\t\t\t\t\t\t// An empty line terminates the REGION block\n\t\t\t\t\t\t\tthis.regionSettings = null;\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BLOCKS;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// if it's a new region block, create a new VTTRegion\n\t\t\t\t\t\tif (this.regionSettings === null) {\n\t\t\t\t\t\t\tthis.regionSettings = new Settings();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst regionSettings = this.regionSettings;\n\n\t\t\t\t\t\t// parse region options and set it as appropriate on the region\n\t\t\t\t\t\tparseOptions(line, (k, v) => {\n\t\t\t\t\t\t\tswitch (k) {\n\t\t\t\t\t\t\t\tcase 'id':\n\t\t\t\t\t\t\t\t\tregionSettings.set(k, v);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'width':\n\t\t\t\t\t\t\t\t\tregionSettings.percent(k, v);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'lines':\n\t\t\t\t\t\t\t\t\tregionSettings.integer(k, v);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'regionanchor':\n\t\t\t\t\t\t\t\tcase 'viewportanchor':\n\t\t\t\t\t\t\t\t\tconst xy = v.split(',');\n\t\t\t\t\t\t\t\t\tif (xy.length !== 2) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// We have to make sure both x and y parse, so use a temporary\n\t\t\t\t\t\t\t\t\t// settings object here.\n\t\t\t\t\t\t\t\t\tconst anchor = new Settings();\n\t\t\t\t\t\t\t\t\tanchor.percent('x', xy[0]);\n\t\t\t\t\t\t\t\t\tanchor.percent('y', xy[1]);\n\t\t\t\t\t\t\t\t\tif (!anchor.has('x') || !anchor.has('y')) {\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tregionSettings.set(k + 'X', anchor.get('x'));\n\t\t\t\t\t\t\t\t\tregionSettings.set(k + 'Y', anchor.get('y'));\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'scroll':\n\t\t\t\t\t\t\t\t\tregionSettings.alt(k, v, ['up']);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, /:/, /\\s/);\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.STYLE:\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tthis.onstyle?.(this.style);\n\t\t\t\t\t\t\tthis.style = '';\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BLOCKS;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.style += line + '\\n';\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.NOTE:\n\t\t\t\t\t\t// Ignore NOTE blocks.\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.BLOCKS:\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check for the start of a NOTE blocks\n\t\t\t\t\t\tif (/^NOTE($[ \\t])/.test(line)) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.NOTE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check for the start of a REGION blocks\n\t\t\t\t\t\tif (/^REGION/.test(line) && !sawCue) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.REGION;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check for the start of a STYLE blocks\n\t\t\t\t\t\tif (/^STYLE/.test(line) && !sawCue) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.STYLE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t// Process line as an ID.\n\t\t\t\t\t/* falls through */\n\t\t\t\t\tcase WebVttParserState.ID:\n\t\t\t\t\t\t// Check for the start of NOTE blocks.\n\t\t\t\t\t\tif (/^NOTE($|[ \\t])/.test(line)) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.NOTE;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// 19-29 - Allow any number of line terminators, then initialize new cue values.\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsawCue = true;\n\n\t\t\t\t\t\tthis.cue = this.createCue();\n\t\t\t\t\t\tthis.cue.text ??= '';\n\n\t\t\t\t\t\tthis.state = WebVttParserState.CUE;\n\t\t\t\t\t\t// 30-39 - Check if this line contains an optional identifier or timing data.\n\t\t\t\t\t\tif (line.indexOf('-->') === -1) {\n\t\t\t\t\t\t\tthis.cue.id = line;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t// Process line as start of a cue.\n\t\t\t\t\t/*falls through*/\n\t\t\t\t\tcase WebVttParserState.CUE:\n\t\t\t\t\t\t// 40 - Collect cue timings and settings.\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tparseCue(line, this.cue!, this.regionList);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t\tthis.reportOrThrowError(e);\n\t\t\t\t\t\t\t// In case of an error ignore rest of the cue.\n\t\t\t\t\t\t\tthis.cue = null;\n\t\t\t\t\t\t\tthis.state = WebVttParserState.BAD_CUE;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.state = WebVttParserState.CUE_TEXT;\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.CUE_TEXT:\n\t\t\t\t\t\tconst hasSubstring = line.indexOf('-->') !== -1;\n\n\t\t\t\t\t\t// 34 - If we have an empty line then report the cue.\n\t\t\t\t\t\t// 35 - If we have the special substring '-->' then report the cue,\n\t\t\t\t\t\t// but do not collect the line as we need to process the current\n\t\t\t\t\t\t// one as a new cue.\n\t\t\t\t\t\tif (!line || hasSubstring && (alreadyCollectedLine = true)) {\n\t\t\t\t\t\t\t// We are done parsing this cue.\n\t\t\t\t\t\t\tthis.oncue?.(this.cue!);\n\t\t\t\t\t\t\tthis.cue = null;\n\t\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (this.cue?.text) {\n\t\t\t\t\t\t\tthis.cue.text += '\\n';\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.cue!.text += line.replace(/\\u2028/g, '\\n').replace(/u2029/g, '\\n');\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tcase WebVttParserState.BAD_CUE: // BADCUE\n\t\t\t\t\t\t// 54-62 - Collect and discard the remaining cue.\n\t\t\t\t\t\tif (!line) {\n\t\t\t\t\t\t\tthis.state = WebVttParserState.ID;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (e) {\n\t\t\tthis.reportOrThrowError(e);\n\n\t\t\t// If we are currently parsing a cue, report what we have.\n\t\t\tif (this.state === WebVttParserState.CUE_TEXT && this.cue && this.oncue) {\n\t\t\t\tthis.oncue(this.cue);\n\t\t\t}\n\t\t\tthis.cue = null;\n\t\t\tthis.regionSettings = null;\n\n\t\t\t// Enter BADWEBVTT state if header was not parsed correctly otherwise\n\t\t\t// another exception occurred so enter BADCUE state.\n\t\t\tthis.state = this.state === WebVttParserState.INITIAL ? WebVttParserState.BAD_WEBVTT : WebVttParserState.BAD_CUE;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Flush the parser.\n\t *\n\t * @returns The parser.\n\t */\n\tflush(): WebVttParser {\n\t\ttry {\n\t\t\t// Finish parsing the stream.\n\t\t\tthis.buffer += '';\n\t\t\t// Synthesize the end of the current cue or region.\n\t\t\tif (this.cue || this.state === WebVttParserState.HEADER) {\n\t\t\t\tthis.buffer += '\\n\\n';\n\t\t\t\tthis.parse(undefined, true);\n\t\t\t}\n\t\t\t// If we've flushed, parsed, and we're still on the INITIAL state then\n\t\t\t// that means we don't have enough of the stream to parse the first\n\t\t\t// line.\n\t\t\tif (this.state === WebVttParserState.INITIAL) {\n\t\t\t\tthrow new WebVttParsingError(BAD_SIGNATURE);\n\t\t\t}\n\t\t}\n\t\tcatch (e) {\n\t\t\tthis.reportOrThrowError(e);\n\t\t}\n\n\t\tthis.onflush?.();\n\n\t\treturn this;\n\t}\n\n\t// If the error is a ParsingError then report it to the consumer if\n\t// possible. If it's not a ParsingError then throw it like normal.\n\tprivate reportOrThrowError(error: any): void {\n\t\tif (error instanceof WebVttParsingError) {\n\t\t\tthis.onparsingerror?.(error);\n\t\t}\n\t\telse {\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"]}
import type { WebVttCue } from './WebVttCue.js';
import type { WebVttParsingError } from './WebVttParsingError.js';
import type { WebVttRegion } from './WebVttRegion.js';
/**
* The result of parsing a WebVTT string.
*
*
* @beta
*/
export type WebVttParseResult = {
/**
* The cues parsed from the WebVTT string.
*/
cues: WebVttCue[];
/**
* The regions parsed from the WebVTT string.
*/
regions: WebVttRegion[];
/**
* The styles parsed from the WebVTT string.
*/
styles: string[];
/**
* The errors that occurred while parsing the WebVTT string.
*/
errors: WebVttParsingError[];
};
//# sourceMappingURL=WebVttParseResult.d.ts.map
{"version":3,"file":"WebVttParseResult.d.ts","sourceRoot":"","sources":["../src/WebVttParseResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;OAEG;IACH,IAAI,EAAE,SAAS,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,YAAY,EAAE,CAAC;IAExB;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC7B,CAAC"}
export {};
//# sourceMappingURL=WebVttParseResult.js.map
{"version":3,"file":"WebVttParseResult.js","sourceRoot":"","sources":["../src/WebVttParseResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { WebVttCue } from './WebVttCue.js';\nimport type { WebVttParsingError } from './WebVttParsingError.js';\nimport type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * The result of parsing a WebVTT string.\n *\n *\n * @beta\n */\nexport type WebVttParseResult = {\n\t/**\n\t * The cues parsed from the WebVTT string.\n\t */\n\tcues: WebVttCue[];\n\n\t/**\n\t * The regions parsed from the WebVTT string.\n\t */\n\tregions: WebVttRegion[];\n\n\t/**\n\t * The styles parsed from the WebVTT string.\n\t */\n\tstyles: string[];\n\n\t/**\n\t * The errors that occurred while parsing the WebVTT string.\n\t */\n\terrors: WebVttParsingError[];\n};\n"]}
import type { WebVttCueFactory } from './WebVttCueFactory';
import type { WebVttRegionFactory } from './WebVttRegionFactory';
/**
* Options for the WebVtt parser.
*
*
* @beta
*/
export type WebVttParserOptions = {
/**
* Whether to use DOM VTTCue and VTTRegion or generic objects. If `createCue`
* or `createRegion` are provided, they will be used instead of the default
* factory functions.
*
* @defaultValue `true`
*/
useDomTypes?: boolean;
/**
* A factory for creating WebVttCue objects.
*
* By default the parser will create DOM VTTCue objects for each cue.
* In some environments, like node or a web worker, this class does not
* exist. In this case, you can provide a custom factory function that
* creates a custom cue object.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}
*/
createCue?: WebVttCueFactory;
/**
* A factory for creating WebVttRegion objects.
*
* By default the parser will create DOM VTTRegion objects for each region.
* In some environments, like node or a web worker, this class does not
* exist. In this case, you can provide a custom factory function that
* creates a custom region object.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}
*/
createRegion?: WebVttRegionFactory;
};
//# sourceMappingURL=WebVttParserOptions.d.ts.map
{"version":3,"file":"WebVttParserOptions.d.ts","sourceRoot":"","sources":["../src/WebVttParserOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAE7B;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACnC,CAAC"}
export {};
//# sourceMappingURL=WebVttParserOptions.js.map
{"version":3,"file":"WebVttParserOptions.js","sourceRoot":"","sources":["../src/WebVttParserOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { WebVttCueFactory } from './WebVttCueFactory';\nimport type { WebVttRegionFactory } from './WebVttRegionFactory';\n\n/**\n * Options for the WebVtt parser.\n *\n *\n * @beta\n */\nexport type WebVttParserOptions = {\n\t/**\n\t * Whether to use DOM VTTCue and VTTRegion or generic objects. If `createCue`\n\t * or `createRegion` are provided, they will be used instead of the default\n\t * factory functions.\n\t *\n\t * @defaultValue `true`\n\t */\n\tuseDomTypes?: boolean;\n\n\t/**\n\t * A factory for creating WebVttCue objects.\n\t *\n\t * By default the parser will create DOM VTTCue objects for each cue.\n\t * In some environments, like node or a web worker, this class does not\n\t * exist. In this case, you can provide a custom factory function that\n\t * creates a custom cue object.\n\t *\n\t * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTCue | VTTCue}\n\t */\n\tcreateCue?: WebVttCueFactory;\n\n\t/**\n\t * A factory for creating WebVttRegion objects.\n\t *\n\t * By default the parser will create DOM VTTRegion objects for each region.\n\t * In some environments, like node or a web worker, this class does not\n\t * exist. In this case, you can provide a custom factory function that\n\t * creates a custom region object.\n\t *\n\t * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion | VTTRegion}\n\t */\n\tcreateRegion?: WebVttRegionFactory;\n};\n"]}
/**
* A WebVTT parsing error.
*
*
* @beta
*/
export declare class WebVttParsingError extends Error {
/**
* Create a new WebVTT parsing error.
*
* @param message - The message of the error.
*/
constructor(message: string);
}
//# sourceMappingURL=WebVttParsingError.d.ts.map
{"version":3,"file":"WebVttParsingError.d.ts","sourceRoot":"","sources":["../src/WebVttParsingError.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAE5C;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAI3B"}
/**
* A WebVTT parsing error.
*
*
* @beta
*/
export class WebVttParsingError extends Error {
/**
* Create a new WebVTT parsing error.
*
* @param message - The message of the error.
*/
constructor(message) {
super(message);
this.name = 'WebVttParsingError';
}
}
//# sourceMappingURL=WebVttParsingError.js.map
{"version":3,"file":"WebVttParsingError.js","sourceRoot":"","sources":["../src/WebVttParsingError.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAE5C;;;;OAIG;IACH,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAClC,CAAC;CACD","sourcesContent":["/**\n * A WebVTT parsing error.\n *\n *\n * @beta\n */\nexport class WebVttParsingError extends Error {\n\n\t/**\n\t * Create a new WebVTT parsing error.\n\t *\n\t * @param message - The message of the error.\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'WebVttParsingError';\n\t}\n}\n"]}
/**
* A WebVTT region.
*
*
* @beta
*/
export type WebVttRegion = {
id: string;
width: number;
lines: number;
regionAnchorX: number;
regionAnchorY: number;
viewportAnchorX: number;
viewportAnchorY: number;
scroll: ScrollSetting;
};
//# sourceMappingURL=WebVttRegion.d.ts.map
{"version":3,"file":"WebVttRegion.d.ts","sourceRoot":"","sources":["../src/WebVttRegion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,aAAa,CAAC;CACtB,CAAC"}
export {};
//# sourceMappingURL=WebVttRegion.js.map
{"version":3,"file":"WebVttRegion.js","sourceRoot":"","sources":["../src/WebVttRegion.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * A WebVTT region.\n *\n *\n * @beta\n */\nexport type WebVttRegion = {\n\tid: string;\n\twidth: number;\n\tlines: number;\n\tregionAnchorX: number;\n\tregionAnchorY: number;\n\tviewportAnchorX: number;\n\tviewportAnchorY: number;\n\tscroll: ScrollSetting;\n};\n"]}
import type { WebVttRegion } from './WebVttRegion';
/**
* A factory for creating WebVttRegion objects.
*
*
* @beta
*/
export type WebVttRegionFactory = () => WebVttRegion;
//# sourceMappingURL=WebVttRegionFactory.d.ts.map
{"version":3,"file":"WebVttRegionFactory.d.ts","sourceRoot":"","sources":["../src/WebVttRegionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,YAAY,CAAC"}
export {};
//# sourceMappingURL=WebVttRegionFactory.js.map
{"version":3,"file":"WebVttRegionFactory.js","sourceRoot":"","sources":["../src/WebVttRegionFactory.ts"],"names":[],"mappings":"","sourcesContent":["import type { WebVttRegion } from './WebVttRegion';\n\n/**\n * A factory for creating WebVttRegion objects.\n *\n *\n * @beta\n */\nexport type WebVttRegionFactory = () => WebVttRegion;\n"]}
import type { TypedResult } from '@svta/cml-utils/TypedResult.js';
import type { WebVttRegion } from './WebVttRegion.js';
/**
* WebVTT transform stream region result.
*
*
* @beta
*/
export type WebVttRegionResult = TypedResult<'region', WebVttRegion>;
//# sourceMappingURL=WebVttRegionResult.d.ts.map
{"version":3,"file":"WebVttRegionResult.d.ts","sourceRoot":"","sources":["../src/WebVttRegionResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC"}
export {};
//# sourceMappingURL=WebVttRegionResult.js.map
{"version":3,"file":"WebVttRegionResult.js","sourceRoot":"","sources":["../src/WebVttRegionResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedResult } from '@svta/cml-utils/TypedResult.js';\nimport type { WebVttRegion } from './WebVttRegion.js';\n\n/**\n * WebVTT transform stream region result.\n *\n *\n * @beta\n */\nexport type WebVttRegionResult = TypedResult<'region', WebVttRegion>;\n"]}
import type { WebVttCueResult } from './WebVttCueResult.js';
import type { WebVttErrorResult } from './WebVttErrorResult.js';
import type { WebVttRegionResult } from './WebVttRegionResult.js';
import type { WebVttStyleResult } from './WebVttStyleResult.js';
import type { WebVttTimestampMapResult } from './WebVttTimestampMapResult.js';
/**
* WebVTT transform stream result.
*
*
* @beta
*/
export type WebVttResult = WebVttCueResult | WebVttRegionResult | WebVttTimestampMapResult | WebVttStyleResult | WebVttErrorResult;
//# sourceMappingURL=WebVttResult.d.ts.map
{"version":3,"file":"WebVttResult.d.ts","sourceRoot":"","sources":["../src/WebVttResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,kBAAkB,GAAG,wBAAwB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC"}
export {};
//# sourceMappingURL=WebVttResult.js.map
{"version":3,"file":"WebVttResult.js","sourceRoot":"","sources":["../src/WebVttResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { WebVttCueResult } from './WebVttCueResult.js';\nimport type { WebVttErrorResult } from './WebVttErrorResult.js';\nimport type { WebVttRegionResult } from './WebVttRegionResult.js';\nimport type { WebVttStyleResult } from './WebVttStyleResult.js';\nimport type { WebVttTimestampMapResult } from './WebVttTimestampMapResult.js';\n\n/**\n * WebVTT transform stream result.\n *\n *\n * @beta\n */\nexport type WebVttResult = WebVttCueResult | WebVttRegionResult | WebVttTimestampMapResult | WebVttStyleResult | WebVttErrorResult;\n"]}
import type { ValueOf } from '@svta/cml-utils/ValueOf.js';
/**
* WebVTT result types.
*
*
* @beta
*
* @enum
*/
export declare const WebVttResultType: {
readonly CUE: "cue";
readonly REGION: "region";
readonly TIMESTAMP_MAP: "timestampmap";
readonly STYLE: "style";
readonly ERROR: "error";
};
/**
* @beta
*/
export type WebVttResultType = ValueOf<typeof WebVttResultType>;
//# sourceMappingURL=WebVttResultType.d.ts.map
{"version":3,"file":"WebVttResultType.d.ts","sourceRoot":"","sources":["../src/WebVttResultType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
/**
* WebVTT result types.
*
*
* @beta
*
* @enum
*/
export const WebVttResultType = {
CUE: 'cue',
REGION: 'region',
TIMESTAMP_MAP: 'timestampmap',
STYLE: 'style',
ERROR: 'error',
};
//# sourceMappingURL=WebVttResultType.js.map
{"version":3,"file":"WebVttResultType.js","sourceRoot":"","sources":["../src/WebVttResultType.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,QAAQ;IAChB,aAAa,EAAE,cAAc;IAC7B,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;CACL,CAAC","sourcesContent":["import type { ValueOf } from '@svta/cml-utils/ValueOf.js';\n\n/**\n * WebVTT result types.\n *\n *\n * @beta\n *\n * @enum\n */\nexport const WebVttResultType = {\n\tCUE: 'cue',\n\tREGION: 'region',\n\tTIMESTAMP_MAP: 'timestampmap',\n\tSTYLE: 'style',\n\tERROR: 'error',\n} as const;\n\n/**\n * @beta\n */\nexport type WebVttResultType = ValueOf<typeof WebVttResultType>;\n"]}
import type { TypedResult } from '@svta/cml-utils/TypedResult.js';
/**
* WebVTT transform stream style result.
*
*
* @beta
*/
export type WebVttStyleResult = TypedResult<'style', string>;
//# sourceMappingURL=WebVttStyleResult.d.ts.map
{"version":3,"file":"WebVttStyleResult.d.ts","sourceRoot":"","sources":["../src/WebVttStyleResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC"}
export {};
//# sourceMappingURL=WebVttStyleResult.js.map
{"version":3,"file":"WebVttStyleResult.js","sourceRoot":"","sources":["../src/WebVttStyleResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedResult } from '@svta/cml-utils/TypedResult.js';\n\n/**\n * WebVTT transform stream style result.\n *\n *\n * @beta\n */\nexport type WebVttStyleResult = TypedResult<'style', string>;\n"]}
import type { TypedResult } from '@svta/cml-utils/TypedResult.js';
import type { TimestampMap } from './TimestampMap.js';
/**
* WebVTT transform stream timestamp map result.
*
*
* @beta
*/
export type WebVttTimestampMapResult = TypedResult<'timestampmap', TimestampMap>;
//# sourceMappingURL=WebVttTimestampMapResult.d.ts.map
{"version":3,"file":"WebVttTimestampMapResult.d.ts","sourceRoot":"","sources":["../src/WebVttTimestampMapResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,GAAG,WAAW,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC"}
export {};
//# sourceMappingURL=WebVttTimestampMapResult.js.map
{"version":3,"file":"WebVttTimestampMapResult.js","sourceRoot":"","sources":["../src/WebVttTimestampMapResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedResult } from '@svta/cml-utils/TypedResult.js';\nimport type { TimestampMap } from './TimestampMap.js';\n\n/**\n * WebVTT transform stream timestamp map result.\n *\n *\n * @beta\n */\nexport type WebVttTimestampMapResult = TypedResult<'timestampmap', TimestampMap>;\n"]}
import type { WebVttResult } from './WebVttResult.js';
/**
* WebVTT transform stream transformer.
*
*
* @beta
*/
export declare class WebVttTransformer {
private readonly parser;
private results;
/**
* Creates a new WebVTT transformer.
*/
constructor();
private enqueueResults;
/**
* Transforms a chunk of WebVTT data.
*
* @param chunk - The chunk of WebVTT data to transform.
* @param controller - The controller to enqueue the results to.
*/
transform(chunk: string, controller: TransformStreamDefaultController<WebVttResult>): void;
/**
* Flushes the transformer.
*
* @param controller - The controller to enqueue the results to.
*/
flush(controller: TransformStreamDefaultController<WebVttResult>): void;
}
//# sourceMappingURL=WebVttTransformer.d.ts.map
{"version":3,"file":"WebVttTransformer.d.ts","sourceRoot":"","sources":["../src/WebVttTransformer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,OAAO,CAAsB;IAErC;;OAEG;;IAUH,OAAO,CAAC,cAAc;IAStB;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,gCAAgC,CAAC,YAAY,CAAC,GAAG,IAAI;IAU1F;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,gCAAgC,CAAC,YAAY,CAAC,GAAG,IAAI;CASvE"}
import { WebVttParser } from './WebVttParser.js';
import { WebVttResultType } from './WebVttResultType.js';
/**
* WebVTT transform stream transformer.
*
*
* @beta
*/
export class WebVttTransformer {
/**
* Creates a new WebVTT transformer.
*/
constructor() {
this.results = [];
this.parser = new WebVttParser();
this.parser.oncue = cue => this.results.push({ type: WebVttResultType.CUE, data: cue });
this.parser.onregion = region => this.results.push({ type: WebVttResultType.REGION, data: region });
this.parser.onstyle = style => this.results.push({ type: WebVttResultType.STYLE, data: style });
this.parser.ontimestampmap = timestampmap => this.results.push({ type: WebVttResultType.TIMESTAMP_MAP, data: timestampmap });
this.parser.onparsingerror = error => this.results.push({ type: WebVttResultType.ERROR, data: error });
}
enqueueResults(controller) {
// TODO: Should parse errors throw?
for (const result of this.results) {
controller.enqueue(result);
}
this.results = [];
}
/**
* Transforms a chunk of WebVTT data.
*
* @param chunk - The chunk of WebVTT data to transform.
* @param controller - The controller to enqueue the results to.
*/
transform(chunk, controller) {
try {
this.parser.parse(chunk);
this.enqueueResults(controller);
}
catch (error) {
controller.error(error);
}
}
/**
* Flushes the transformer.
*
* @param controller - The controller to enqueue the results to.
*/
flush(controller) {
try {
this.parser.flush();
this.enqueueResults(controller);
}
catch (error) {
controller.error(error);
}
}
}
//# sourceMappingURL=WebVttTransformer.js.map
{"version":3,"file":"WebVttTransformer.js","sourceRoot":"","sources":["../src/WebVttTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAI7B;;OAEG;IACH;QALQ,YAAO,GAAmB,EAAE,CAAC;QAMpC,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,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AAC;QACjC,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACd,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAA0D;QAC/D,IAAI,CAAC;YACJ,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACpB,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACd,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;CACD","sourcesContent":["import { WebVttParser } from './WebVttParser.js';\nimport type { WebVttResult } from './WebVttResult.js';\nimport { WebVttResultType } from './WebVttResultType.js';\n\n/**\n * WebVTT transform stream transformer.\n *\n *\n * @beta\n */\nexport class WebVttTransformer {\n\tprivate readonly parser: WebVttParser;\n\tprivate results: WebVttResult[] = [];\n\n\t/**\n\t * Creates a new WebVTT transformer.\n\t */\n\tconstructor() {\n\t\tthis.parser = new WebVttParser();\n\t\tthis.parser.oncue = cue => this.results.push({ type: WebVttResultType.CUE, data: cue });\n\t\tthis.parser.onregion = region => this.results.push({ type: WebVttResultType.REGION, data: region });\n\t\tthis.parser.onstyle = style => this.results.push({ type: WebVttResultType.STYLE, data: style });\n\t\tthis.parser.ontimestampmap = timestampmap => this.results.push({ type: WebVttResultType.TIMESTAMP_MAP, data: timestampmap });\n\t\tthis.parser.onparsingerror = error => this.results.push({ type: WebVttResultType.ERROR, data: error });\n\t}\n\n\tprivate enqueueResults(controller: TransformStreamDefaultController<WebVttResult>): void {\n\t\t// TODO: Should parse errors throw?\n\t\tfor (const result of this.results) {\n\t\t\tcontroller.enqueue(result);\n\t\t}\n\n\t\tthis.results = [];\n\t}\n\n\t/**\n\t * Transforms a chunk of WebVTT data.\n\t *\n\t * @param chunk - The chunk of WebVTT data to transform.\n\t * @param controller - The controller to enqueue the results to.\n\t */\n\ttransform(chunk: string, controller: TransformStreamDefaultController<WebVttResult>): void {\n\t\ttry {\n\t\t\tthis.parser.parse(chunk);\n\t\t\tthis.enqueueResults(controller);\n\t\t}\n\t\tcatch (error) {\n\t\t\tcontroller.error(error);\n\t\t}\n\t}\n\n\t/**\n\t * Flushes the transformer.\n\t *\n\t * @param controller - The controller to enqueue the results to.\n\t */\n\tflush(controller: TransformStreamDefaultController<WebVttResult>): void {\n\t\ttry {\n\t\t\tthis.parser.flush();\n\t\t\tthis.enqueueResults(controller);\n\t\t}\n\t\tcatch (error) {\n\t\t\tcontroller.error(error);\n\t\t}\n\t}\n}\n"]}
import type { WebVttResult } from './WebVttResult.js';
/**
* WebVTT transform stream.
*
*
* @beta
*/
export declare class WebVttTransformStream extends TransformStream<string, WebVttResult> {
constructor(writableStrategy?: QueuingStrategy<string>, readableStrategy?: QueuingStrategy<WebVttResult>);
}
//# sourceMappingURL=WebVttTransformStream.d.ts.map
{"version":3,"file":"WebVttTransformStream.d.ts","sourceRoot":"","sources":["../src/WebVttTransformStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC;gBACnE,gBAAgB,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC;CAGxG"}
import { WebVttTransformer } from './WebVttTransformer.js';
/**
* WebVTT transform stream.
*
*
* @beta
*/
export class WebVttTransformStream extends TransformStream {
constructor(writableStrategy, readableStrategy) {
super(new WebVttTransformer(), writableStrategy, readableStrategy);
}
}
//# sourceMappingURL=WebVttTransformStream.js.map
{"version":3,"file":"WebVttTransformStream.js","sourceRoot":"","sources":["../src/WebVttTransformStream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,eAAqC;IAC/E,YAAY,gBAA0C,EAAE,gBAAgD;QACvG,KAAK,CAAC,IAAI,iBAAiB,EAAE,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;IACpE,CAAC;CACD","sourcesContent":["import type { WebVttResult } from './WebVttResult.js';\nimport { WebVttTransformer } from './WebVttTransformer.js';\n\n/**\n * WebVTT transform stream.\n *\n *\n * @beta\n */\nexport class WebVttTransformStream extends TransformStream<string, WebVttResult> {\n\tconstructor(writableStrategy?: QueuingStrategy<string>, readableStrategy?: QueuingStrategy<WebVttResult>) {\n\t\tsuper(new WebVttTransformer(), writableStrategy, readableStrategy);\n\t}\n}\n"]}
-205
Streaming Video Technology Alliance Common Media Library Copyright (c) 2023
Streaming Video Technology Alliance
---
The following implementation in this project is derived from the
`vtt.js` library (https://github.com/videojs/vtt.js)
- src/webvtt/WebVttParser.ts
```
Copyright Brightcove, Inc. and contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
```
---