mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add type definitions for ResizeObserver API
This commit is contained in:
parent
bc86129ad7
commit
fcfcae44fa
19
types/resize-observer-browser/index.d.ts
vendored
Normal file
19
types/resize-observer-browser/index.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Type definitions for non-npm package resize-observer-browser 0.1
|
||||
// Project: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver, https://developers.google.com/web/updates/2016/10/resizeobserver, https://wicg.github.io/ResizeObserver/
|
||||
// Definitions by: Chives <https://github.com/chivesrs>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.7
|
||||
|
||||
export class ResizeObserver {
|
||||
constructor(callback: ResizeObserverCallback);
|
||||
disconnect(): void;
|
||||
observe(target: Element): void;
|
||||
unobserve(target: Element): void;
|
||||
}
|
||||
|
||||
export type ResizeObserverCallback = (entries: ResizeObserverEntry[]) => void;
|
||||
|
||||
export interface ResizeObserverEntry {
|
||||
readonly target: Element;
|
||||
readonly contentRect: DOMRectReadOnly;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { ResizeObserver } from "resize-observer-browser";
|
||||
|
||||
function resizeObserverCreates(): void {
|
||||
const resizeObserver: ResizeObserver = new ResizeObserver((entries) => {
|
||||
const div = document.getElementById('display-div')!;
|
||||
const rect = entries[0].contentRect;
|
||||
div.textContent = `${rect.left} ${rect.right}`;
|
||||
});
|
||||
const div = document.getElementById('resized-div')!;
|
||||
resizeObserver.observe(div);
|
||||
resizeObserver.unobserve(div);
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
24
types/resize-observer-browser/tsconfig.json
Normal file
24
types/resize-observer-browser/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"resize-observer-browser-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/resize-observer-browser/tslint.json
Normal file
1
types/resize-observer-browser/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user