mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(canvas-fit): new type definition (#44065)
- definition file - tests https://github.com/hughsk/canvas-fit#usage Thanks!
This commit is contained in:
parent
1869bedd41
commit
a6bc3595f9
16
types/canvas-fit/canvas-fit-tests.ts
Normal file
16
types/canvas-fit/canvas-fit-tests.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import fit = require('canvas-fit');
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
window.addEventListener('resize', fit(canvas), false);
|
||||
window.addEventListener('resize', fit(canvas, window), false);
|
||||
window.addEventListener('resize', fit(canvas, window, '20%'), false);
|
||||
window.addEventListener('resize', fit(canvas, window, 20.5), false);
|
||||
|
||||
const resize = fit(canvas, window);
|
||||
resize.scale = window.devicePixelRatio;
|
||||
resize.parent = document.body;
|
||||
resize.parent = () => {
|
||||
return [window.innerWidth - 300, window.innerHeight];
|
||||
};
|
||||
35
types/canvas-fit/index.d.ts
vendored
Normal file
35
types/canvas-fit/index.d.ts
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
// Type definitions for canvas-fit 1.5
|
||||
// Project: https://github.com/hughsk/canvas-fit
|
||||
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Creates a resize function for your canvas element. Calling this function will resize the canvas to fit its parent element.
|
||||
*/
|
||||
declare function fit(
|
||||
canvas: HTMLCanvasElement | SVGElement,
|
||||
parent?: EventTarget | Document | HTMLElement,
|
||||
scale?: string | number,
|
||||
): resize;
|
||||
|
||||
interface resize {
|
||||
(this: any, ev: any): any;
|
||||
/**
|
||||
* Dynamically change the canvas' target scale.
|
||||
* Note that you still need to manually trigger a resize after doing this.
|
||||
*/
|
||||
scale?: number;
|
||||
/**
|
||||
* Dynamically change the canvas' target scale.
|
||||
* Note that you still need to manually trigger a resize after doing this.
|
||||
* Instead of filling a given element, explicitly set the width and height of the canvas.
|
||||
* Note that this value will still be scaled up according to resize.scale
|
||||
*/
|
||||
parent?: Element | (() => [number, number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Small module for fitting a canvas element within the bounds of its parent.
|
||||
* Useful, for example, for making a canvas fill the screen. Works with SVG elements too!
|
||||
*/
|
||||
export = fit;
|
||||
24
types/canvas-fit/tsconfig.json
Normal file
24
types/canvas-fit/tsconfig.json
Normal file
@ -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",
|
||||
"canvas-fit-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/canvas-fit/tslint.json
Normal file
1
types/canvas-fit/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user