UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 7.14 kB
{"version":3,"file":"findMixin.mjs","sources":["../../../../src/scene/container/container-mixins/findMixin.ts"],"sourcesContent":["import { deprecation, v8_0_0 } from '../../../utils/logging/deprecation';\n\nimport type { Container } from '../Container';\n\n/** @ignore */\nexport interface FindMixinConstructor\n{\n /**\n * The instance label of the object.\n * @default null\n */\n label?: string;\n}\n\n/**\n * The FindMixin interface provides methods for finding children within a container by their label.\n * It allows for searching for a single child or multiple children with a specific label,\n * either directly or recursively through the container's hierarchy.\n * @category scene\n * @advanced\n */\nexport interface FindMixin extends Required<FindMixinConstructor>\n{\n /**\n * The instance name of the object.\n * @deprecated since 8.0.0\n * @see Container#label\n * @default null\n */\n name: string;\n /**\n * @deprecated since 8.0.0\n * @param {string} label - Instance name.\n * @param {boolean}[deep=false] - Whether to search recursively\n * @returns {Container} The child with the specified name.\n * @see Container#getChildByLabel\n */\n getChildByName(label: RegExp | string, deep?: boolean): Container | null;\n /**\n * Returns the first child in the container with the specified label.\n * Recursive searches are done in a pre-order traversal.\n * @example\n * ```ts\n * // Basic label search\n * const child = container.getChildByLabel('player');\n *\n * // Search with regular expression\n * const enemy = container.getChildByLabel(/enemy-\\d+/);\n *\n * // Deep search through children\n * const deepChild = container.getChildByLabel('powerup', true);\n * ```\n * @param {RegExp|string} label - Instance label to search for\n * @param {boolean} deep - Whether to search recursively through children\n * @returns The first child with the specified label, or null if none found\n * @see {@link Container#getChildrenByLabel} For finding all matches\n * @see {@link Container#label} For setting labels\n */\n getChildByLabel(label: RegExp | string, deep?: boolean): Container | null;\n /**\n * Returns all children in the container with the specified label.\n * Recursive searches are done in a pre-order traversal.\n * @example\n * ```ts\n * // Basic label search\n * const enemies = container.getChildrenByLabel('enemy');\n * // Search with regular expression\n * const powerups = container.getChildrenByLabel(/powerup-\\d+/);\n * // Deep search with collection\n * const buttons = [];\n * container.getChildrenByLabel('button', true, buttons);\n * ```\n * @param {string|RegExp} label - Instance label to search for\n * @param {boolean}[deep=false] - Whether to search recursively through children\n * @param {Container[]} [out=[]] - Optional array to store matching children in\n * @returns An array of children with the specified label\n * @see {@link Container#getChildByLabel} For finding first match\n * @see {@link Container#label} For setting labels\n */\n getChildrenByLabel(label: RegExp | string, deep?: boolean, out?: Container[]): Container[];\n}\n\n/** @internal */\nexport const findMixin: Partial<Container> = {\n label: null,\n\n get name(): string\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'Container.name property has been removed, use Container.label instead');\n // #endif\n\n return this.label;\n },\n set name(value: string)\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'Container.name property has been removed, use Container.label instead');\n // #endif\n\n this.label = value;\n },\n\n getChildByName(name: string, deep = false): Container | null\n {\n return this.getChildByLabel(name, deep);\n },\n\n getChildByLabel(label: string | RegExp, deep = false): Container | null\n {\n const children = this.children;\n\n for (let i = 0; i < children.length; i++)\n {\n const child = children[i];\n\n if (child.label === label || (label instanceof RegExp && label.test(child.label))) return child;\n }\n\n if (deep)\n {\n for (let i = 0; i < children.length; i++)\n {\n const child = children[i];\n const found = child.getChildByLabel(label, true);\n\n if (found)\n {\n return found;\n }\n }\n }\n\n return null;\n },\n\n getChildrenByLabel(label: string | RegExp, deep = false, out = []): Container[]\n {\n const children = this.children;\n\n for (let i = 0; i < children.length; i++)\n {\n const child = children[i];\n\n if (child.label === label || (label instanceof RegExp && label.test(child.label)))\n {\n out.push(child);\n }\n }\n\n if (deep)\n {\n for (let i = 0; i < children.length; i++)\n {\n children[i].getChildrenByLabel(label, true, out);\n }\n }\n\n return out;\n },\n} as Container;\n"],"names":[],"mappings":";;;AAmFO,MAAM,SAAgC,GAAA;AAAA,EACzC,KAAO,EAAA,IAAA;AAAA,EAEP,IAAI,IACJ,GAAA;AAEI,IAAA,WAAA,CAAY,QAAQ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