@@ -13,7 +13,7 @@ import {
1313 type MediaQueryStatus ,
1414 type Observer ,
1515} from './shared'
16- import type * as shared from './shared'
16+ import * as shared from './shared'
1717
1818const DELEGATE_EVENTS = [
1919 'touchstart' ,
@@ -453,6 +453,47 @@ export class CurrentWindowBackendContext implements Context {
453453 }
454454 }
455455
456+ createResizeObserver (
457+ targetElement : Element ,
458+ mode : shared . ResizeObserverMode ,
459+ listener : ( res : shared . ResizeStatus ) => void ,
460+ ) : Observer {
461+ const observer = new ResizeObserver ( ( entries ) => {
462+ entries . forEach ( ( entry ) => {
463+ const elem = entry . target
464+ const isVertialWritingMode = window
465+ . getComputedStyle ( elem )
466+ . writingMode . startsWith ( 'vertical-' )
467+ if ( entry . contentBoxSize . length !== 1 || entry . borderBoxSize . length !== 1 ) {
468+ // eslint-disable-next-line no-console
469+ console . error ( 'currently multiple boxes are not supported in resize observer' )
470+ return
471+ }
472+ const contentBox = entry . contentBoxSize [ 0 ] !
473+ const borderBox = entry . borderBoxSize [ 0 ] !
474+ listener ( {
475+ boundingContentBoxWidth : isVertialWritingMode
476+ ? contentBox . blockSize
477+ : contentBox . inlineSize ,
478+ boundingContentBoxHeight : isVertialWritingMode
479+ ? contentBox . inlineSize
480+ : contentBox . blockSize ,
481+ boundingBorderBoxWidth : isVertialWritingMode ? borderBox . blockSize : borderBox . inlineSize ,
482+ boundingBorderBoxHeight : isVertialWritingMode
483+ ? borderBox . inlineSize
484+ : borderBox . blockSize ,
485+ } )
486+ } )
487+ } )
488+ const box = mode === shared . ResizeObserverMode . BorderBox ? 'border-box' : 'content-box'
489+ observer . observe ( targetElement as unknown as HTMLElement , { box } )
490+ return {
491+ disconnect ( ) {
492+ observer . disconnect ( )
493+ } ,
494+ }
495+ }
496+
456497 createMediaQueryObserver (
457498 status : MediaQueryStatus ,
458499 listener : ( res : { matches : boolean } ) => void ,
0 commit comments