{"version":3,"file":"ContainerMixin.cjs","sources":["../../../src/core/mixins/ContainerMixin.ts"],"sourcesContent":["import { Container, extensions } from 'pixi.js';\nimport { Layout, type LayoutOptions } from '../Layout';\nimport { type ComputedLayout } from '../types';\nimport { baseComputeLayoutData } from './utils/baseComputeLayoutData';\n\n/**\n * Extended interface for Container with private properties needed for layout\n * Provides type safety for internal properties we need to access\n */\ninterface PrivateContainer extends Omit<Container, '_didLocalTransformChangeId'> {\n    _didLocalTransformChangeId: number;\n}\n\nconst visibility = Object.getOwnPropertyDescriptor(Container.prototype, 'visible')!;\n\nconst mixin: Partial<PrivateContainer> = {\n    // Internal reference to the layout object\n    _layout: null,\n\n    /**\n     * Gets the current layout associated with this container\n     * @returns The container's layout or null if no layout is attached\n     */\n    get layout(): Layout | null {\n        return this._layout ?? null;\n    },\n\n    /**\n     * Sets the layout for this container\n     * @param value - Layout options to apply, or null to remove layout\n     */\n    set layout(value: Omit<LayoutOptions, 'target'> | null | boolean) {\n        // If the value is a boolean, we want to treat it as an empty object\n        value = value === true ? {} : value;\n\n        if (!value) {\n            if (this._layout) {\n                this._layout.destroy();\n                this._layout = null;\n                this.updateLocalTransform = Container.prototype.updateLocalTransform;\n                Object.defineProperty(Container.prototype, 'visible', visibility);\n            }\n\n            return;\n        }\n\n        if (!this._layout) {\n            this._layout = new Layout({ target: this as unknown as Container });\n\n            // eslint-disable-next-line accessor-pairs\n            Object.defineProperty(Container.prototype, 'visible', {\n                ...visibility,\n                set(visibleValue: boolean) {\n                    visibility.set!.call(this, visibleValue);\n                    if (this.layout) {\n                        if (visibleValue && this.parent) {\n                            this.layout._onChildAdded(this.parent);\n                        } else {\n                            this.layout._onChildRemoved();\n                        }\n                    }\n                },\n            });\n\n            // update the children's layout if they have one to be this container\n            for (const child of this.children) {\n                if (child.layout && child.visible) {\n                    child.layout!._onChildRemoved();\n                    child.layout!._onChildAdded(this as unknown as Container);\n                }\n            }\n            if (this.parent && this.visible) {\n                this._layout._onChildAdded(this.parent);\n            }\n        }\n\n        this._layout.setStyle(value);\n\n        this.updateLocalTransform = this.updateLocalTransformWithLayout;\n        this._onUpdate!();\n    },\n\n    /**\n     * This function overrides how we calculate the local transform of the container.\n     * For the layout, we need to not only calculate the transform matrix, but also\n     * take into account the yoga layout's position and scale.\n     */\n    updateLocalTransformWithLayout() {\n        const localTransformChangeId = this._didContainerChangeTick;\n        // early out if nothing has changed\n\n        if (this._didLocalTransformChangeId === localTransformChangeId) return;\n        this._didLocalTransformChangeId = localTransformChangeId;\n\n        const layout = this._layout!;\n\n        // this will return the position and scale offsets we should add to the local matrix\n        const { x, y, offsetX, offsetY, scaleX, scaleY, originX, originY } = layout._computedPixiLayout!;\n\n        // if this is a leaf node then we must pretend that the leaf is inside of a container\n        // this allows use to define the \"box\" that the leaf is inside of\n        // and then apply the transform to the container instead of the leaf\n        // we then apply the additional transforms to the leaf to push it around inside of its box\n        // this effectively splits the transform into two parts\n        const lt = this.localTransform;\n        const { rotation, skew, scale, position } = this;\n\n        // Precompute trig values\n        const xRotY = rotation + skew._y;\n        const xRotX = rotation - skew._x;\n\n        const a = Math.cos(xRotY) * scale._x;\n        const b = Math.sin(xRotY) * scale._x;\n        const c = -Math.sin(xRotX) * scale._y;\n        const d = Math.cos(xRotX) * scale._y;\n\n        // Apply offset, origin and position in one step\n        const tx = position._x + x - originX * a - originY * c;\n        const ty = position._y + y - originX * b - originY * d;\n\n        // Apply additional static transform and re-add origin\n        lt.a = a * scaleX;\n        lt.b = b * scaleX;\n        lt.c = c * scaleY;\n        lt.d = d * scaleY;\n        lt.tx = tx + (offsetX * a + offsetY * c) + originX;\n        lt.ty = ty + (offsetX * b + offsetY * d) + originY;\n    },\n\n    /**\n     * Apply the computed layout to the container\n     * Converts Yoga layout information into PixiJS positioning\n     * @param computedLayout - Layout data from Yoga engine\n     * @returns Transformed position and scale data for this container\n     * @memberof scene.Container#\n     */\n    computeLayoutData(computedLayout: ComputedLayout) {\n        const layout = this._layout!;\n        const { isLeaf } = layout._styles.custom;\n\n        if (isLeaf) {\n            return baseComputeLayoutData(this as unknown as Container, computedLayout, 'fill');\n        }\n\n        return {\n            x: computedLayout.left,\n            y: computedLayout.top,\n            offsetX: 0,\n            offsetY: 0,\n            scaleX: 1,\n            scaleY: 1,\n        };\n    },\n} as PrivateContainer;\n\nextensions.mixin(Container, mixin);\n"],"names":["Container","Layout","baseComputeLayoutData","extensions"],"mappings":";;;;AAaA,MAAM,aAAa,OAAO,yBAAyBA,QAAAA,UAAU,WAAW,SAAS;AAEjF,MAAM,QAAmC;AAAA;AAAA,EAErC,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAMT,IAAI,SAAwB;AACxB,WAAO,KAAK,WAAW;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,OAAO,OAAuD;AAEtD,YAAA,UAAU,OAAO,CAAA,IAAK;AAE9B,QAAI,CAAC,OAAO;AACR,UAAI,KAAK,SAAS;AACd,aAAK,QAAQ,QAAQ;AACrB,aAAK,UAAU;AACV,aAAA,uBAAuBA,kBAAU,UAAU;AAChD,eAAO,eAAeA,QAAAA,UAAU,WAAW,WAAW,UAAU;AAAA,MAAA;AAGpE;AAAA,IAAA;AAGA,QAAA,CAAC,KAAK,SAAS;AACf,WAAK,UAAU,IAAIC,OAAAA,OAAO,EAAE,QAAQ,MAA8B;AAG3D,aAAA,eAAeD,kBAAU,WAAW,WAAW;AAAA,QAClD,GAAG;AAAA,QACH,IAAI,cAAuB;AACZ,qBAAA,IAAK,KAAK,MAAM,YAAY;AACvC,cAAI,KAAK,QAAQ;AACT,gBAAA,gBAAgB,KAAK,QAAQ;AACxB,mBAAA,OAAO,cAAc,KAAK,MAAM;AAAA,YAAA,OAClC;AACH,mBAAK,OAAO,gBAAgB;AAAA,YAAA;AAAA,UAChC;AAAA,QACJ;AAAA,MACJ,CACH;AAGU,iBAAA,SAAS,KAAK,UAAU;AAC3B,YAAA,MAAM,UAAU,MAAM,SAAS;AAC/B,gBAAM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