Skip to content

Commit ea64ce7

Browse files
committed
docs: add typescript definitions
1 parent a4a1ecf commit ea64ce7

File tree

5 files changed

+210
-19
lines changed

5 files changed

+210
-19
lines changed

package-lock.json

Lines changed: 169 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"eslint-plugin-prettier": "^3.4.0",
5858
"less": "^4.1.1",
5959
"prettier": "3.2.5",
60-
"rollup": "^4.43.0"
60+
"rollup": "^4.43.0",
61+
"rollup-plugin-copy": "^3.5.0"
6162
}
6263
}

rollup.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import resolve from "@rollup/plugin-node-resolve";
33
import rust from "@wasm-tool/rollup-plugin-rust";
44
import commonjs from '@rollup/plugin-commonjs';
55
import terser from "@rollup/plugin-terser";
6+
import copy from "rollup-plugin-copy";
67

78
const esmPlugins = [
89
babel({
@@ -15,7 +16,12 @@ const esmPlugins = [
1516
inlineWasm: true,
1617
wasmOptArgs: ["-O4", "--enable-bulk-memory", "--enable-sign-ext"]
1718
}),
18-
resolve({ extensions: [".js", ".jsx"] })
19+
resolve({ extensions: [".js", ".jsx"] }),
20+
copy({
21+
targets:[
22+
{ src: "src/*.d.ts", dest: "dist/" }
23+
]
24+
})
1925
];
2026

2127
const cjsPlugins = [

src/index.d.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
1+
/**
2+
* @param src the url for fetching the asciicast recording
3+
* @param element the container element to mount the player into
4+
* @param options player options
5+
* @returns the created AsciinemaPlayer instance
6+
*/
17
export function create(
28
src: RequestInfo | URL,
39
element: HTMLElement,
410
options?: options,
511
): AsciinemaPlayer;
12+
/**
13+
* @param data the object for fetching data and parsing it to a asciicast recording
14+
* @param element the container element to mount the player into
15+
* @param options player options
16+
* @returns the created AsciinemaPlayer instance
17+
*/
618
export function create(
719
data: {
820
url: RequestInfo | URL;
921
fetchOpts?: RequestInit;
10-
parser?: parser;
22+
parser?: "asciicast" | "ttyrec" | "typescript" | ((response: Response) => recording);
1123
},
1224
element: HTMLElement,
1325
options?: options,
1426
): AsciinemaPlayer;
27+
/**
28+
* @param data the object for providing asciicast recording, either directly or via a function
29+
* @param element the container element to mount the player into
30+
* @param options player options
31+
* @returns the created AsciinemaPlayer instance
32+
*/
1533
export function create(
1634
data: {
17-
data: asciicastDataSource;
35+
data: asciicastProvider;
1836
},
1937
element: HTMLElement,
2038
options?: options,
2139
): AsciinemaPlayer;
2240

23-
export type RecordingDataModel = {
41+
export type recording = {
2442
cols: number;
2543
rows: number;
2644
events: Array<[number, "o" | "i" | "m" | "r", string]>;
2745
};
28-
type parser = "asciicast" | "ttyrec" | "typescript" | ((response: Response) => RecordingDataModel);
2946

3047
export type asciicastV1 = {
3148
version: 1;
@@ -78,8 +95,8 @@ export type asciicastV3 = [
7895
...Array<[number, "o" | "i" | "m" | "r" | "x", string]>,
7996
];
8097

81-
type asciicastData = asciicastV1 | asciicastV2 | asciicastV3 | string;
82-
type asciicastDataSource = asciicastData | (() => Promise<asciicastData>) | (() => asciicastData);
98+
export type asciicast = asciicastV1 | asciicastV2 | asciicastV3 | string;
99+
export type asciicastProvider = asciicast | (() => Promise<asciicast>) | (() => asciicast);
83100

84101
/**
85102
* Look and feel of the asciinema player can be configured extensively by passing additional options
@@ -359,11 +376,11 @@ export interface options {
359376
* logger: console
360377
*/
361378
logger?: {
362-
log(...args: any[]): void;
363-
debug(...args: any[]): void;
364-
info(...args: any[]): void;
365-
warn(...args: any[]): void;
366-
error(...args: any[]): void;
379+
log(...args: unknown[]): void;
380+
debug(...args: unknown[]): void;
381+
info(...args: unknown[]): void;
382+
warn(...args: unknown[]): void;
383+
error(...args: unknown[]): void;
367384
};
368385
}
369386

@@ -500,15 +517,15 @@ interface AsciinemaPlayer {
500517
}
501518

502519
/** Seek location union matching the docs. */
503-
type SeekLocation =
520+
export type SeekLocation =
504521
| number // seconds
505522
| `${number}%` // percentage string, e.g. "50%"
506523
| { marker: number } // go to marker by 0-based index
507524
| { marker: "prev" } // previous marker
508525
| { marker: "next" }; // next marker
509526

510527
/** Payload for the `input` event. */
511-
type InputEventDetail = {
528+
export type InputEventDetail = {
512529
/**
513530
* Registered input value (ASCII or control char).
514531
*
@@ -521,7 +538,7 @@ type InputEventDetail = {
521538
};
522539

523540
/** Payload for the `marker` event. */
524-
type MarkerEventDetail = {
541+
export type MarkerEventDetail = {
525542
/** 0-based marker index. */
526543
index: number;
527544
/** Marker time in seconds. */

src/ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './index'

0 commit comments

Comments
 (0)