{"version":3,"file":"NineSliceSprite.mjs","sources":["../../../src/scene/sprite-nine-slice/NineSliceSprite.ts"],"sourcesContent":["import { Texture } from '../../rendering/renderers/shared/texture/Texture';\nimport { deprecation, v8_0_0 } from '../../utils/logging/deprecation';\nimport { ViewContainer } from '../view/View';\nimport { NineSliceGeometry } from './NineSliceGeometry';\n\nimport type { Size } from '../../maths/misc/Size';\nimport type { View } from '../../rendering/renderers/shared/view/View';\nimport type { Bounds, BoundsData } from '../container/bounds/Bounds';\nimport type { ContainerOptions } from '../container/Container';\nimport type { Optional } from '../container/container-mixins/measureMixin';\nimport type { DestroyOptions } from '../container/destroyTypes';\n\n/**\n * Constructor options used for `NineSliceSprite` instances.\n * ```js\n * const nineSliceSprite = new NineSliceSprite({\n * texture: Texture.from('button.png'),\n * leftWidth: 20,\n * topHeight: 20,\n * rightWidth: 20,\n * bottomHeight: 20,\n * });\n * ```\n * @see {@link scene.NineSliceSprite}\n * @memberof scene\n */\nexport interface NineSliceSpriteOptions extends ContainerOptions\n{\n /** The texture to use on the NineSliceSprite. */\n texture: Texture;\n /** Width of the left vertical bar (A) */\n leftWidth?: number;\n /** Height of the top horizontal bar (C) */\n topHeight?: number;\n /** Width of the right vertical bar (B) */\n rightWidth?: number;\n /** Height of the bottom horizontal bar (D) */\n bottomHeight?: number;\n /** Width of the NineSliceSprite, setting this will actually modify the vertices and not the UV's of this plane. */\n width?: number;\n /** Height of the NineSliceSprite, setting this will actually modify the vertices and not UV's of this plane. */\n height?: number;\n /** Whether or not to round the x/y position. */\n roundPixels?: boolean;\n}\n\n/**\n * The NineSliceSprite allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful\n * for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically\n *\n *
\n * A B\n * +---+----------------------+---+\n * C | 1 | 2 | 3 |\n * +---+----------------------+---+\n * | | | |\n * | 4 | 5 | 6 |\n * | | | |\n * +---+----------------------+---+\n * D | 7 | 8 | 9 |\n * +---+----------------------+---+\n * When changing this objects width and/or height:\n * areas 1 3 7 and 9 will remain unscaled.\n * areas 2 and 8 will be stretched horizontally\n * areas 4 and 6 will be stretched vertically\n * area 5 will be stretched both horizontally and vertically\n *\n * @example\n * import { NineSliceSprite, Texture } from 'pixi.js';\n *\n * const plane9 = new NineSliceSprite(Texture.from('BoxWithRoundedCorners.png'), 15, 15, 15, 15);\n * @memberof scene\n */\nexport class NineSliceSprite extends ViewContainer implements View\n{\n /** The default options, used to override the initial values of any options passed in the constructor. */\n public static defaultOptions: NineSliceSpriteOptions = {\n /** @default Texture.EMPTY */\n texture: Texture.EMPTY,\n };\n\n public override readonly renderPipeId: string = 'nineSliceSprite';\n public _texture: Texture;\n\n public batched = true;\n\n private _leftWidth: number;\n private _topHeight: number;\n private _rightWidth: number;\n private _bottomHeight: number;\n private _width: number;\n private _height: number;\n\n public _didSpriteUpdate = true;\n\n /**\n * @param {scene.NineSliceSpriteOptions|Texture} options - Options to use\n * @param options.texture - The texture to use on the NineSliceSprite.\n * @param options.leftWidth - Width of the left vertical bar (A)\n * @param options.topHeight - Height of the top horizontal bar (C)\n * @param options.rightWidth - Width of the right vertical bar (B)\n * @param options.bottomHeight - Height of the bottom horizontal bar (D)\n * @param options.width - Width of the NineSliceSprite,\n * setting this will actually modify the vertices and not the UV's of this plane.\n * @param options.height - Height of the NineSliceSprite,\n * setting this will actually modify the vertices and not UV's of this plane.\n */\n constructor(options: NineSliceSpriteOptions | Texture)\n {\n if ((options instanceof Texture))\n {\n options = { texture: options };\n }\n\n const {\n width,\n height,\n leftWidth,\n rightWidth,\n topHeight,\n bottomHeight,\n texture,\n roundPixels,\n ...rest\n } = options;\n\n super({\n label: 'NineSliceSprite',\n ...rest\n });\n\n this._leftWidth = leftWidth ?? texture?.defaultBorders?.left ?? NineSliceGeometry.defaultOptions.leftWidth;\n this._topHeight = topHeight ?? texture?.defaultBorders?.top ?? NineSliceGeometry.defaultOptions.topHeight;\n this._rightWidth = rightWidth ?? texture?.defaultBorders?.right ?? NineSliceGeometry.defaultOptions.rightWidth;\n this._bottomHeight = bottomHeight\n ?? texture?.defaultBorders?.bottom\n ?? NineSliceGeometry.defaultOptions.bottomHeight;\n this.bounds.maxX = this._width = width ?? texture.width ?? NineSliceGeometry.defaultOptions.width;\n this.bounds.maxY = this._height = height ?? texture.height ?? NineSliceGeometry.defaultOptions.height;\n\n this.allowChildren = false;\n this.texture = texture ?? NineSliceSprite.defaultOptions.texture;\n this.roundPixels = roundPixels ?? false;\n }\n\n /** The local bounds of the view. */\n public get bounds(): BoundsData\n {\n return this._bounds;\n }\n\n /** The width of the NineSliceSprite, setting this will actually modify the vertices and UV's of this plane. */\n override get width(): number\n {\n return this._width;\n }\n\n override set width(value: number)\n {\n this.bounds.maxX = this._width = value;\n this.onViewUpdate();\n }\n\n /** The height of the NineSliceSprite, setting this will actually modify the vertices and UV's of this plane. */\n override get height(): number\n {\n return this._height;\n }\n\n override set height(value: number)\n {\n this.bounds.maxY = this._height = value;\n this.onViewUpdate();\n }\n\n /**\n * Sets the size of the NiceSliceSprite to the specified width and height.\n * setting this will actually modify the vertices and UV's of this plane\n * This is faster than setting the width and height separately.\n * @param value - This can be either a number or a [Size]{@link Size} object.\n * @param height - The height to set. Defaults to the value of `width` if not provided.\n */\n public override setSize(value: number | Optional