diff --git a/devtools-detect/devtools-detect-tests.ts b/devtools-detect/devtools-detect-tests.ts new file mode 100644 index 0000000000..9cd1d2f7a7 --- /dev/null +++ b/devtools-detect/devtools-detect-tests.ts @@ -0,0 +1,12 @@ +/// + +// check if it's open +console.log('is DevTools open?', window.devtools.open); +// check it's orientation, null if not open +console.log('and DevTools orientation?', window.devtools.orientation); + +// get notified when it's opened/closed or orientation changes +window.addEventListener('devtoolschange', function (e) { + console.log('is DevTools open?', e.detail.open); + console.log('and DevTools orientation?', e.detail.orientation); +}); diff --git a/devtools-detect/devtools-detect.d.ts b/devtools-detect/devtools-detect.d.ts new file mode 100644 index 0000000000..c66d63f0fa --- /dev/null +++ b/devtools-detect/devtools-detect.d.ts @@ -0,0 +1,16 @@ +// Type definitions for ajv +// Project: https://github.com/sindresorhus/devtools-detect +// Definitions by: York Yao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type DevTools = { + open: boolean; + orientation: "vertical" | "horizontal"; +} +interface DevToolsEvent extends Event { + detail: DevTools; +} +interface Window { + devtools: DevTools; + addEventListener(type: "devtoolschange", listener: (ev: DevToolsEvent) => any, useCapture?: boolean): void; +}