@@ -3,53 +3,53 @@ import { animationFrameThrottle, createDisposalBin } from 'maverick.js/std';
33import type { RemotionSrc } from './types' ;
44
55export class RemotionLayoutEngine {
6- protected _src : RemotionSrc | null = null ;
7- protected _viewport : HTMLElement | null = null ;
8- protected _canvas : HTMLElement | null = null ;
9- protected _container : HTMLElement | null = null ;
10- protected _disposal = createDisposalBin ( ) ;
6+ #src : RemotionSrc | null = null ;
7+ #viewport : HTMLElement | null = null ;
8+ #canvas : HTMLElement | null = null ;
9+ #container : HTMLElement | null = null ;
10+ #disposal = createDisposalBin ( ) ;
1111
1212 constructor ( ) { }
1313
1414 setSrc ( src : RemotionSrc | null ) {
15- this . _src = src ;
16- this . setContainer ( this . _container ) ;
15+ this . #src = src ;
16+ this . setContainer ( this . #container ) ;
1717 }
1818
1919 setContainer ( container : HTMLElement | null ) {
2020 if ( __SERVER__ ) return ;
2121
22- this . _disposal . empty ( ) ;
22+ this . #disposal . empty ( ) ;
2323
24- this . _container = container ;
25- this . _canvas = container ?. parentElement ?? null ;
26- this . _viewport = this . _canvas ?. parentElement ?? null ;
24+ this . #container = container ;
25+ this . #canvas = container ?. parentElement ?? null ;
26+ this . #viewport = this . #canvas ?. parentElement ?? null ;
2727
28- if ( this . _src && this . _viewport ) {
29- const onResize = animationFrameThrottle ( this . _onResize . bind ( this ) ) ;
28+ if ( this . #src && this . #viewport ) {
29+ const onResize = animationFrameThrottle ( this . #onResize . bind ( this ) ) ;
3030
3131 onResize ( ) ;
3232 const observer = new ResizeObserver ( onResize ) ;
33- observer . observe ( this . _viewport ) ;
33+ observer . observe ( this . #viewport ) ;
3434
35- this . _disposal . add ( ( ) => observer . disconnect ( ) ) ;
35+ this . #disposal . add ( ( ) => observer . disconnect ( ) ) ;
3636 }
3737 }
3838
3939 destroy ( ) {
40- this . _disposal . empty ( ) ;
40+ this . #disposal . empty ( ) ;
4141 }
4242
43- protected _onResize ( entries ?: ResizeObserverEntry [ ] ) {
44- if ( ! this . _viewport || ! this . _src ) return ;
43+ #onResize ( entries ?: ResizeObserverEntry [ ] ) {
44+ if ( ! this . #viewport || ! this . #src ) return ;
4545
46- const rect = this . _getRect ( this . _viewport , entries ?. [ 0 ] ) ,
47- scale = this . _calcScale ( rect ) ,
48- transform = this . _calcTransform ( rect , scale ) ;
46+ const rect = this . #getRect ( this . #viewport , entries ?. [ 0 ] ) ,
47+ scale = this . #calcScale ( rect ) ,
48+ transform = this . #calcTransform ( rect , scale ) ;
4949
50- Object . assign ( this . _canvas ! . style , {
51- width : this . _src . compositionWidth ! * scale + 'px' ,
52- height : this . _src . compositionHeight ! * scale + 'px' ,
50+ Object . assign ( this . #canvas ! . style , {
51+ width : this . #src . compositionWidth ! * scale + 'px' ,
52+ height : this . #src . compositionHeight ! * scale + 'px' ,
5353 display : 'flex' ,
5454 flexDirection : 'column' ,
5555 position : 'absolute' ,
@@ -58,10 +58,10 @@ export class RemotionLayoutEngine {
5858 overflow : 'hidden' ,
5959 } ) ;
6060
61- Object . assign ( this . _container ! . style , {
61+ Object . assign ( this . #container ! . style , {
6262 position : 'absolute' ,
63- width : this . _src . compositionWidth + 'px' ,
64- height : this . _src . compositionHeight + 'px' ,
63+ width : this . #src . compositionWidth + 'px' ,
64+ height : this . #src . compositionHeight + 'px' ,
6565 display : 'flex' ,
6666 transform : `scale(${ scale } )` ,
6767 marginLeft : transform . x ,
@@ -70,7 +70,7 @@ export class RemotionLayoutEngine {
7070 } ) ;
7171 }
7272
73- protected _getRect ( el : HTMLElement , entry ?: ResizeObserverEntry ) : LayoutRect {
73+ #getRect ( el : HTMLElement , entry ?: ResizeObserverEntry ) : LayoutRect {
7474 const rect = el . getBoundingClientRect ( ) ;
7575 if ( ! entry ) return rect ;
7676
@@ -91,23 +91,23 @@ export class RemotionLayoutEngine {
9191 } ;
9292 }
9393
94- protected _calcScale ( rect : LayoutRect ) {
95- if ( ! this . _src ) return 0 ;
94+ #calcScale ( rect : LayoutRect ) {
95+ if ( ! this . #src ) return 0 ;
9696
97- const heightRatio = rect . height / this . _src . compositionHeight ! ,
98- widthRatio = rect . width / this . _src . compositionWidth ! ;
97+ const heightRatio = rect . height / this . #src . compositionHeight ! ,
98+ widthRatio = rect . width / this . #src . compositionWidth ! ;
9999
100100 return Math . min ( heightRatio || 0 , widthRatio || 0 ) ;
101101 }
102102
103- protected _calcTransform ( rect : LayoutRect , scale : number ) {
104- if ( ! this . _src ) return { } ;
103+ #calcTransform ( rect : LayoutRect , scale : number ) {
104+ if ( ! this . #src ) return { } ;
105105
106106 const correction = 0 - ( 1 - scale ) / 2 ,
107- x = correction * this . _src . compositionWidth ! ,
108- y = correction * this . _src . compositionHeight ! ,
109- width = this . _src . compositionWidth ! * scale ,
110- height = this . _src . compositionHeight ! * scale ,
107+ x = correction * this . #src . compositionWidth ! ,
108+ y = correction * this . #src . compositionHeight ! ,
109+ width = this . #src . compositionWidth ! * scale ,
110+ height = this . #src . compositionHeight ! * scale ,
111111 centerX = rect . width / 2 - width / 2 ,
112112 centerY = rect . height / 2 - height / 2 ;
113113
0 commit comments