@@ -25,7 +25,9 @@ export type ResizeHandler<T extends Element = Element> = (
25
25
) => void ;
26
26
27
27
export type Size = { width : number ; height : number } ;
28
- export type NullableSize = { width : number ; height : number } | { width : null ; height : null } ;
28
+ export type NullableSize =
29
+ | { width : number ; height : number ; clientWidth : number ; clientHeight : number }
30
+ | { width : null ; height : null ; clientWidth : null ; clientHeight : null } ;
29
31
30
32
/**
31
33
* Instantiate a new ResizeObserver that automatically get's disposed on cleanup.
@@ -139,7 +141,12 @@ export function createWindowSize(): Readonly<Size> {
139
141
export const useWindowSize : typeof createWindowSize =
140
142
/*#__PURE__*/ createHydratableSingletonRoot ( createWindowSize ) ;
141
143
142
- const ELEMENT_SIZE_FALLBACK = { width : null , height : null } as const satisfies NullableSize ;
144
+ const ELEMENT_SIZE_FALLBACK = {
145
+ width : null ,
146
+ height : null ,
147
+ clientWidth : null ,
148
+ clientHeight : null ,
149
+ } as const satisfies NullableSize ;
143
150
144
151
/**
145
152
* @param target html element
@@ -150,7 +157,8 @@ export function getElementSize(target: Element | false | undefined | null): Null
150
157
return { ...ELEMENT_SIZE_FALLBACK } ;
151
158
}
152
159
const { width, height } = target . getBoundingClientRect ( ) ;
153
- return { width, height } ;
160
+ const { clientWidth, clientHeight } = target ;
161
+ return { width, height, clientWidth, clientHeight } ;
154
162
}
155
163
156
164
/**
@@ -163,7 +171,7 @@ export function getElementSize(target: Element | false | undefined | null): Null
163
171
* console.log(size.width, size.height)
164
172
* })
165
173
*/
166
- export function createElementSize ( target : Element ) : Readonly < Size > ;
174
+ export function createElementSize ( target : Element ) : Readonly < NullableSize > ;
167
175
export function createElementSize (
168
176
target : Accessor < Element | false | undefined | null > ,
169
177
) : Readonly < NullableSize > ;
0 commit comments