Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add type definition #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
127 changes: 127 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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 `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
*/
fonts?: string[]

/**
* Object with all available fonts - Key is font name in lower case, value is link
*
* @example `{"arial": "/font1.ttf"}`
*/
availableFonts?: Record<string, string>

/**
* 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