@@ -13,15 +13,15 @@ function render(instance: IRectpackr) {
1313}
1414
1515function restartObservingChildren ( instance : IRectpackr ) {
16- if ( instance . pendingStartObservingChildren ) {
16+ if ( instance . isPendingStartObservingChildren ) {
1717 return ;
1818 }
1919
20- instance . pendingStartObservingChildren = true ;
20+ instance . isPendingStartObservingChildren = true ;
2121 stopObservingChildren ( instance ) ;
2222
2323 requestAnimationFrame ( ( ) => {
24- instance . pendingStartObservingChildren = false ;
24+ instance . isPendingStartObservingChildren = false ;
2525 startObservingChildren ( instance ) ;
2626 } ) ;
2727}
@@ -53,15 +53,15 @@ function startObservingContainer(instance: IRectpackr) {
5353}
5454
5555function startObservingImages ( instance : IRectpackr ) {
56- function callback ( this : HTMLImageElement ) {
56+ function onImgLoad ( this : HTMLImageElement ) {
5757 instance . loadingImages . delete ( this ) ;
5858 restartObservingChildren ( instance ) ;
5959 }
6060
6161 for ( const img of instance . childrenContainer . querySelectorAll ( 'img' ) ) {
6262 if ( ! img . complete && ! instance . loadingImages . get ( img ) ) {
63- instance . loadingImages . set ( img , callback ) ;
64- img . addEventListener ( 'load' , callback , { once : true , passive : true } ) ;
63+ instance . loadingImages . set ( img , onImgLoad ) ;
64+ img . addEventListener ( 'load' , onImgLoad , { once : true , passive : true } ) ;
6565 }
6666 }
6767}
@@ -80,8 +80,8 @@ function stopObservingContainer(instance: IRectpackr) {
8080}
8181
8282function stopObservingImages ( instance : IRectpackr ) {
83- for ( const [ img , callback ] of instance . loadingImages ) {
84- img . removeEventListener ( 'load' , callback ) ;
83+ for ( const [ img , onImgLoad ] of instance . loadingImages ) {
84+ img . removeEventListener ( 'load' , onImgLoad ) ;
8585 instance . loadingImages . delete ( img ) ;
8686 }
8787}
@@ -112,9 +112,7 @@ function updateStyle(
112112 instance : IRectpackr ,
113113 children : { element : IRectpackrChildElement ; point : [ number , number ] } [ ]
114114) {
115- /*
116- * Update children style.
117- */
115+ // Update children style
118116 for ( const { element, point } of children ) {
119117 const xVal =
120118 point [ 0 ] *
@@ -143,9 +141,7 @@ function updateStyle(
143141 }
144142 }
145143
146- /*
147- * Update container style.
148- */
144+ // Update container style
149145 instance . container . style . height = `${ instance . stripPack . packedHeight } px` ;
150146}
151147
@@ -154,6 +150,10 @@ function updateStyle(
154150/* ------------------------------------------------------------------------- */
155151
156152export function onChildrenContainerMutation ( instance : IRectpackr ) {
153+ if ( instance . childrenContainer . children . length === 0 ) {
154+ onChildResize ( instance , [ ] ) ;
155+ }
156+
157157 restartObservingChildren ( instance ) ;
158158 restartObservingImages ( instance ) ;
159159}
@@ -196,9 +196,7 @@ export function onContainerResize(instance: IRectpackr) {
196196}
197197
198198export function resetStyle ( instance : IRectpackr ) {
199- /*
200- * Reset children style.
201- */
199+ // Reset children style
202200 for ( const { element } of instance . children ) {
203201 if ( instance . config . positioning === 'offset' ) {
204202 element . style . inset = '' ;
@@ -207,9 +205,7 @@ export function resetStyle(instance: IRectpackr) {
207205 }
208206 }
209207
210- /*
211- * Reset container style.
212- */
208+ // Reset container style
213209 instance . container . style . height = '' ;
214210}
215211
0 commit comments