From c161e2d2b55547aa209e524ff918f4947a07c04c Mon Sep 17 00:00:00 2001 From: Sam Alexander Date: Thu, 22 Aug 2019 16:53:15 +0100 Subject: [PATCH] Add types for ccapture.js (#37643) * Add types for ccapture.js * Make types global * Remove package ref --- types/ccapture.js/ccapture.js-tests.ts | 6 +++ types/ccapture.js/index.d.ts | 63 ++++++++++++++++++++++++++ types/ccapture.js/tsconfig.json | 24 ++++++++++ types/ccapture.js/tslint.json | 1 + 4 files changed, 94 insertions(+) create mode 100644 types/ccapture.js/ccapture.js-tests.ts create mode 100644 types/ccapture.js/index.d.ts create mode 100644 types/ccapture.js/tsconfig.json create mode 100644 types/ccapture.js/tslint.json diff --git a/types/ccapture.js/ccapture.js-tests.ts b/types/ccapture.js/ccapture.js-tests.ts new file mode 100644 index 0000000000..efdfafe63a --- /dev/null +++ b/types/ccapture.js/ccapture.js-tests.ts @@ -0,0 +1,6 @@ +const canvas = document.createElement('canvas'); +const capturer = new CCapture({ format: 'webm' }); +capturer.start(); // $ExpectType void +capturer.capture(canvas); // $ExpectType void +capturer.stop(); // $ExpectType void +capturer.save(); // $ExpectType void diff --git a/types/ccapture.js/index.d.ts b/types/ccapture.js/index.d.ts new file mode 100644 index 0000000000..7df4b2c663 --- /dev/null +++ b/types/ccapture.js/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for ccapture.js 1.1 +// Project: https://github.com/spite/ccapture.js#readme +// Definitions by: Sam Alexander +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class CCapture { + constructor(settings: CCapture.Settings); + + start(): void; + + capture(canvas: HTMLElement): void; + + stop(): void; + + save(cb?: (blob: Blob) => void): void; +} + +declare namespace CCapture { + interface Settings { + /** + * Target framerate for the capture + */ + framerate?: number; + /** + * Super-sampling of frames to create a motion-blurred frame (0 or 1 make no effect) + */ + motionBlurFrames?: number; + format: "webm" | "gif" | "png" | "jpg" | "ffmpegserver"; + /** + * Quality for webm/jpg + */ + quality?: number; + /** + * Name of the files to be exported. if no name is provided, a GUID will be generated + */ + name?: string; + /** + * Dumps info on the console + */ + verbose?: boolean; + /** + * Adds a widget with capturing info + */ + display?: boolean; + /** + * Automatically stops and downloads when reaching that time (seconds). + * Very convenient for long captures: set it and forget it (remember autoSaveTime!) + */ + timeLimit?: number; + /** + * It will automatically download the captured data every n seconds (only available for webm/png/jpg) + */ + autoSaveTime?: number; + /** + * Skip to that mark (seconds) + */ + startTime?: number; + /** + * Path to the gif worker script + */ + workersPath?: string; + } +} diff --git a/types/ccapture.js/tsconfig.json b/types/ccapture.js/tsconfig.json new file mode 100644 index 0000000000..41e3fc84b5 --- /dev/null +++ b/types/ccapture.js/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ccapture.js-tests.ts" + ] +} diff --git a/types/ccapture.js/tslint.json b/types/ccapture.js/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ccapture.js/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }