Skip to content

Commit e7d500a

Browse files
committed
Use TypeScript 4.6's devicePixelContentBoxSize
1 parent 83dd25b commit e7d500a

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/ExtendedResizeObserverEntry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ObservedElement } from './ObservedElement';
22

33
export interface ExtendedResizeObserverEntry extends ResizeObserverEntry {
4-
readonly devicePixelContentBoxSize?: ReadonlyArray<ResizeObserverSize>; // https://github.com/w3c/csswg-drafts/pull/4476
54
target: ObservedElement;
65
}

src/useResizeObserver.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Context } from './Context';
66
const boxOptions = {
77
BORDER_BOX: 'border-box', // https://caniuse.com/mdn-api_resizeobserverentry_borderboxsize
88
CONTENT_BOX: 'content-box', // https://caniuse.com/mdn-api_resizeobserverentry_contentboxsize
9-
DEVICE_PIXEL_CONTENT_BOX: 'device-pixel-content-box' // https://github.com/w3c/csswg-drafts/pull/4476
9+
DEVICE_PIXEL_CONTENT_BOX: 'device-pixel-content-box' // https://caniuse.com/mdn-api_resizeobserverentry_devicepixelcontentboxsize
1010
};
1111

1212
/**
@@ -55,21 +55,11 @@ export const useResizeObserver = (
5555
break;
5656

5757
case boxOptions.DEVICE_PIXEL_CONTENT_BOX:
58-
/* TypeScript 4.2 is missing devicePixelContentBoxSize. */
59-
if (typeof resizeObserverEntry.devicePixelContentBoxSize !== 'undefined') {
60-
isIdentical = resizeObserverEntry.devicePixelContentBoxSize.every((boxSize, index) => {
61-
if (typeof observedEntry.devicePixelContentBoxSize !== 'undefined') {
62-
return (
63-
boxSize.inlineSize === observedEntry.devicePixelContentBoxSize[index].inlineSize &&
64-
boxSize.blockSize === observedEntry.devicePixelContentBoxSize[index].blockSize
65-
);
66-
} else {
67-
throw Error('resizeObserverEntry does not contain devicePixelContentBoxSize.');
68-
}
69-
});
70-
} else {
71-
throw Error('resizeObserverEntry does not contain devicePixelContentBoxSize.');
72-
}
58+
isIdentical = resizeObserverEntry.devicePixelContentBoxSize.every(
59+
(boxSize, index) =>
60+
boxSize.inlineSize === observedEntry.devicePixelContentBoxSize[index].inlineSize &&
61+
boxSize.blockSize === observedEntry.devicePixelContentBoxSize[index].blockSize
62+
);
7363
break;
7464

7565
default:

0 commit comments

Comments
 (0)