|
| 1 | +import type { ObservedElement } from './ObservedElement'; |
| 2 | +import type { ExtendedResizeObserverEntry } from './ExtendedResizeObserverEntry'; |
1 | 3 | import { useContext, useCallback, useRef, useState } from 'react'; |
2 | 4 | import { Context } from './Context'; |
3 | | -import { ObservedElement } from './ObservedElement'; |
4 | | -import { ExtendedResizeObserverEntry } from './ExtendedResizeObserverEntry'; |
5 | 5 |
|
6 | 6 | const boxOptions = { |
7 | 7 | BORDER_BOX: 'border-box', // https://caniuse.com/mdn-api_resizeobserverentry_borderboxsize |
8 | 8 | 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 |
10 | 10 | }; |
11 | 11 |
|
12 | 12 | /** |
13 | | - * See API Docs: {@linkcode https://github.com/envato/react-breakpoints/blob/master/docs/api.md#useresizeobserver|useResizeObserver} |
| 13 | + * See API Docs: {@linkcode https://github.com/envato/react-breakpoints/blob/main/docs/api.md#useresizeobserver useResizeObserver} |
14 | 14 | * |
15 | 15 | * Returns a React callback ref to attach to a DOM element. It also returns |
16 | 16 | * a resize observation entry every time the observed element changes size. |
@@ -55,21 +55,11 @@ export const useResizeObserver = ( |
55 | 55 | break; |
56 | 56 |
|
57 | 57 | 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 | + ); |
73 | 63 | break; |
74 | 64 |
|
75 | 65 | default: |
|
0 commit comments