{"version":3,"file":"LayoutView.cjs","sources":["../../src/components/LayoutView.ts"],"sourcesContent":["import { Container, type ContainerChild, type RenderLayer } from 'pixi.js';\nimport { type Layout, type LayoutOptions } from '../core/Layout';\nimport { LayoutContainer, type LayoutContainerOptions } from './LayoutContainer';\n\nexport interface LayoutViewOptions<T extends Container = Container> extends LayoutContainerOptions {\n    /** The slot container for holding content */\n    slot?: T;\n}\n\n/**\n * A specialized container that implements leaf node behavior similar to HTML elements\n * like `<img>` or `<video>`. It manages content through a single slot while supporting\n * layout and styling capabilities.\n *\n * Supports objectFit, objectPosition, backgroundColor, borderColor, and overflow\n *\n * @example\n * ```typescript\n * // Create a view container with an image\n * const view = new LayoutView({ slot: new Sprite() });\n * view.layout = {\n *     width: 200,\n *     height: 200,\n *     objectFit: 'cover',\n *     objectPosition: 'center',\n *     backgroundColor: 'red',\n * };\n * ```\n */\nexport class LayoutView<T extends Container = Container> extends LayoutContainer {\n    /** The slot container for holding content */\n    public slot: T;\n\n    constructor(params: LayoutViewOptions<T>) {\n        const { slot, layout, ...rest } = params;\n\n        super(rest);\n        this.slot = (params.slot as T) ?? new Container({ label: 'slot' });\n        this.layout = layout ?? {};\n        this.addChild(this.slot);\n        this.addChild = this._addChild.bind(this);\n    }\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    override get layout(): Layout | null {\n        return super.layout;\n    }\n\n    /**\n     * Sets the layout for this container and configures its slot.\n     *\n     * The layout is split between the container and slot:\n     * - Container: Handles positioning, size, and background\n     * - Slot: Manages content fitting and positioning\n     *\n     * @param value - Layout options to apply, or null to remove layout\n     *\n     * @example\n     * ```typescript\n     * view.layout = {`\n     *     width: '100%',\n     *     objectFit: 'contain',\n     *     objectPosition: 'center',\n     *     backgroundColor: 'red'\n     * };\n     * ```\n     */\n    override 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        if (!value) {\n            this.slot.layout = null;\n            super.layout = null;\n\n            return;\n        }\n\n        const { applySizeDirectly, objectFit, objectPosition, isLeaf, ...rest } = value ?? {};\n\n        super.layout = rest;\n\n        if (this.layout && this.slot) {\n            this.slot.layout = {\n                width: '100%',\n                height: '100%',\n                ...(objectFit && { objectFit }),\n                ...(objectPosition && { objectPosition }),\n                ...(applySizeDirectly && { applySizeDirectly }),\n                ...(isLeaf && { isLeaf }),\n            };\n        }\n    }\n\n    /**\n     * Prevents adding children directly to this container.\n     * Content should be added to the slot instead.\n     *\n     * @throws {Error} Always throws an error to enforce leaf node behavior\n     * @private\n     */\n    protected _addChild<U extends (ContainerChild | RenderLayer)[]>(..._children: U): U[0] {\n        if (this.overflowContainer.children.length >= 1) {\n            throw new Error('Leaf nodes should not have multiple children');\n        }\n\n        return this.overflowContainer.addChild(..._children);\n    }\n}\n"],"names":["LayoutContainer","Container"],"mappings":";;;;;;;AA6BO,MAAM,mBAAoDA,gBAAAA,gBAAgB;AAAA,EAI7E,YAAY,QAA8B;AACtC,UAAM,EAAE,MAAM,QAAQ,GAAG,KAAS,IAAA;AAElC,UAAM,IAAI;AALP;AAAA;AAME,SAAA,OAAQ,OAAO,QAAc,IAAIC,QAAAA,UAAU,EAAE,OAAO,QAAQ;AAC5D,SAAA,SAAS,UAAU,CAAC;AACpB,SAAA,SAAS,KAAK,IAAI;AACvB,SAAK,WAAW,KAAK,UAAU,KAAK,IAAI;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO5C,IAAa,SAAwB;AACjC,WAAO,MAAM;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBjB,IAAa,OAAO,OAAuD;AAE/D,YAAA,UAAU,OAAO,CAAA,IAAK;AAC9B,QAAI,CAAC,OAAO;AACR,WAAK,KAAK,SAAS;AACnB,YAAM,SAAS;AAEf;A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