From fa0d366269f42ad5127ff0caf8b0b1dc0b5f2f96 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Wed, 12 May 2021 21:28:09 +0300 Subject: [PATCH 1/3] feat: Add type definition --- package.json | 4 +- types.d.ts | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 types.d.ts diff --git a/package.json b/package.json index 056801b8..455a82b0 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,10 @@ "version": "4.0.0", "description": "libass Subtitle Renderer and Parser library for browsers", "main": "dist/js/subtitles-octopus.js", + "types": "types.d.ts", "files": [ - "dist/js/subtitles*" + "dist/js/subtitles*", + "types.d.ts" ], "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 00000000..270583d4 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,120 @@ +interface OptionsBase { + /** + * The video element to attach listeners to + */ + video?: HTMLVideoElement, + + /** + * The canvas to render the subtitles to. + * If none is given it will create a new canvas and insert it as a sibling of the video element (only if the video element exists) + */ + canvas?: HTMLCanvasElement, + + /** + * The URL of the worker + * + * @default libassjs-worker.js + */ + workerUrl?: string, + + /** + * An array of links to the fonts used in the subtitle + */ + fonts?: string[] + + /** + * Object with all available fonts - Key is font name in lower case, value is link + * + * @example `{"arial": "/font1.ttf"}` + */ + availableFonts?: Record + + /** + * The amount of time the subtitles should be offset from the video + * + * @default 0 + */ + timeOffset?: number + + /** + * Whether performance info is printed in the console + * + * @default false + */ + debug?: boolean + + /** + * Function that's called when SubtitlesOctopus is ready + */ + onReady?: () => void + + /** + * Function called in case of critical error meaning the subtitles wouldn't be shown + * and you should use an alternative method (for instance it occurs if browser doesn't support web workers) + */ + onError?: () => void + + + /** + * Enable Fast Render Mode (Lossy) + * + * This is experimental feature + * + * @default false + * @see https://github.com/libass/JavascriptSubtitlesOctopus#fast-render-mode-lossy-experimental + */ + lossyRender: boolean +} + +interface OptionsWithSubUrl extends OptionsBase { + subUrl: string +} + +interface OptionsWithSubContent extends OptionsBase { + subContent: string +} + +export type Options = OptionsWithSubUrl | OptionsWithSubContent + +declare class SubtitlesOctopus { + constructor(options: Options) + + /** + * Render subtitles at specified time + * @param time + */ + setCurrentTime(time: number): void + + + + /** + * Works the same as the {@link subUrl} option. It will set the subtitle to display by its URL. + * @param url + */ + setTrackByUrl(url: string): void + + + + /** + * Works the same as the {@link subContent} option. It will set the subtitle to display by its content. + * @param content + */ + setTrack(content: string): void + + + + /** + * This simply removes the subtitles. + * You can use {@link setTrackByUrl} or {@link setTrack} methods to set a new subtitle file to be displayed. + */ + freeTrack(): void + + + + /** + * Destroy instance + */ + dispose(): void +} + +export default SubtitlesOctopus From 6add951e46da920f58ef4fd052dfbc8f168f8ada Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Thu, 13 May 2021 13:52:35 +0000 Subject: [PATCH 2/3] fix: Make `lossyRender` optional --- types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types.d.ts b/types.d.ts index 270583d4..c3a8e69d 100644 --- a/types.d.ts +++ b/types.d.ts @@ -63,7 +63,7 @@ interface OptionsBase { * @default false * @see https://github.com/libass/JavascriptSubtitlesOctopus#fast-render-mode-lossy-experimental */ - lossyRender: boolean + lossyRender?: boolean } interface OptionsWithSubUrl extends OptionsBase { From ac309b09b0dfd8bc5c3e598cb78568b6aec845d1 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Thu, 13 May 2021 13:56:25 +0000 Subject: [PATCH 3/3] fix: Add `legacyWorkerUrl` --- types.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types.d.ts b/types.d.ts index c3a8e69d..ffaab25c 100644 --- a/types.d.ts +++ b/types.d.ts @@ -13,10 +13,17 @@ interface OptionsBase { /** * The URL of the worker * - * @default libassjs-worker.js + * @default `subtitles-octopus-worker.js` */ workerUrl?: string, + /** + * The URL of the legacy worker + * + * @default `subtitles-octopus-worker-legacy.js` + */ + legacyWorkerUrl?: string, + /** * An array of links to the fonts used in the subtitle */