import { Bounds , DisplayObject } from '@pixi/display' ; import { Rectangle } from '@pixi/math' ; import { ObjectPoolFactory } from '@pixi-essentials/object-pool' ; const rectanglePool = ObjectPoolFactory . build ( Rectangle ) ; const tempBounds = new Bounds ( ) ; const tempRect = new Rectangle ( ) ; const EMPTY_ARRAY = [ ] ; type { PIXI . DisplayObject } DisplayObject . prototype . smartMask = null ; method param recursive param skipUpdate DisplayObject . prototype . updateSmartMask = function updateSmartMask ( recursive = true , skipUpdate = true ) : Rectangle { if ( ! this . smartMask ) { if ( recursive ) { return this . getBounds ( skipUpdate , rectanglePool . allocate ( ) ) ; } return null ; } const smartMask = this . smartMask ; const maskBounds = rectanglePool . allocate ( ) ; const unmaskedTargetBounds = rectanglePool . allocate ( ) ; smartMask . getBounds ( skipUpdate , maskBounds ) ; if ( ! skipUpdate ) { this . _recursivePostUpdateTransform ( ) ; if ( ! this . parent ) { this . parent = this . _tempDisplayObjectParent ; this . displayObjectUpdateTransform ( ) ; this . parent = null ; } else { this . displayObjectUpdateTransform ( ) ; } } if ( this . filterArea ) { unmaskedTargetBounds . copyFrom ( this . filterArea ) ; } else { const originalBounds = this . _bounds ; const originalChildren = this . children ; tempBounds . clear ( ) ; this . _bounds = tempBounds ; this . children = EMPTY_ARRAY ; this . calculateBounds ( ) ; this . _bounds = originalBounds ; this . children = originalChildren ; unmaskedTargetBounds . copyFrom ( tempBounds . getRectangle ( unmaskedTargetBounds ) ) ; } const children = this . children ; if ( children && children . length ) { if ( recursive ) { for ( let i = 0 , j = children . length ; i < j ; i ++ ) { const child = children [ i ] ; if ( ! child . renderable || ! child . visible ) { continue ; } const childBounds = child . updateSmartMask ( true , skipUpdate ) ; unmaskedTargetBounds . enlarge ( childBounds ) ; rectanglePool . release ( childBounds ) ; } } else { for ( let i = 0 , j = children . length ; i < j ; i ++ ) { const child = children [ i ] ; if ( ! child . renderable || ! child . visible ) { continue ; } unmaskedTargetBounds . enlarge ( child . getBounds ( skipUpdate , tempRect ) ) ; } } } if ( unmaskedTargetBounds . left < maskBounds . left || unmaskedTargetBounds . top < maskBounds . top || unmaskedTargetBounds . right > maskBounds . right || unmaskedTargetBounds . bottom > maskBounds . bottom ) { this . mask = smartMask ; } else { this . mask = null ; } if ( recursive ) { unmaskedTargetBounds . fit ( maskBounds ) ; rectanglePool . release ( maskBounds ) ; return unmaskedTargetBounds ; } rectanglePool . release ( maskBounds ) ; rectanglePool . release ( unmaskedTargetBounds ) ; return null ; } ;