react-children-hooks 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/isElementOfType.ts","../src/useChildWhere.ts","../src/childrenToElements.ts","../src/isReactElement.ts","../src/useChildByType.ts","../src/useChildrenWhere.ts","../src/useChildrenByType.ts","../src/reporter.ts","../src/useExactChildrenWhere.ts","../src/useHasChildWhere.ts","../src/useMaximumChildrenWhere.ts","../src/useMinimumChildrenWhere.ts","../src/useRequiredChildWhere.ts"],"sourcesContent":["/**\n * Public package entrypoint.\n *\n * Hooks and child utilities will be exported here as the API is defined.\n */\nexport { useChildByType } from \"./useChildByType\";\nexport { useChildWhere } from \"./useChildWhere\";\nexport { useChildrenByType } from \"./useChildrenByType\";\nexport { useChildrenWhere } from \"./useChildrenWhere\";\nexport { useExactChildrenWhere } from \"./useExactChildrenWhere\";\nexport { useHasChildWhere } from \"./useHasChildWhere\";\nexport { useMaximumChildrenWhere } from \"./useMaximumChildrenWhere\";\nexport { useMinimumChildrenWhere } from \"./useMinimumChildrenWhere\";\nexport { useRequiredChildWhere } from \"./useRequiredChildWhere\";\nexport { childrenToElements } from \"./childrenToElements\";\nexport { isElementOfType } from \"./isElementOfType\";\nexport { isReactElement } from \"./isReactElement\";\nexport type { ElementOfType } from \"./types\";\nexport type { UseExactChildrenWhereOptions } from \"./useExactChildrenWhere\";\nexport type { UseMaximumChildrenWhereOptions } from \"./useMaximumChildrenWhere\";\nexport type { UseMinimumChildrenWhereOptions } from \"./useMinimumChildrenWhere\";\nexport type { UseRequiredChildWhereOptions } from \"./useRequiredChildWhere\";\n","import type { ElementType, ReactElement } from \"react\";\n\nimport type { ElementOfType } from \"./types\";\n\n/**\n * Determines whether a React element exactly matches the provided element or component type.\n *\n * @param element The React element to compare.\n * @param type The element or component type to match.\n * @returns `true` when the element's type exactly matches the provided type; otherwise `false`.\n */\nexport function isElementOfType<T extends ElementType>(\n element: ReactElement,\n type: T\n): element is ElementOfType<T> {\n return element.type === type;\n}\n","import { useMemo, type ReactElement, type ReactNode } from \"react\";\n\nimport { childrenToElements } from \"./childrenToElements\";\n\n/**\n * Returns the first direct child element that satisfies the provided predicate.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @returns The first direct child element that satisfies the provided predicate, or `null` when no match is found.\n */\nexport function useChildWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T\n): T | null;\nexport function useChildWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean\n): ReactElement | null;\nexport function useChildWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean\n): ReactElement | null {\n return useMemo(\n () => childrenToElements(children).find(predicate) ?? null,\n [children, predicate]\n );\n}\n","import { Children, type ReactElement, type ReactNode } from \"react\";\n\nimport { isReactElement } from \"./isReactElement\";\n\n/**\n * Normalizes a React children value into an array containing only valid direct child elements.\n *\n * @param children The React children value to normalize.\n * @returns An array of valid React elements from the provided direct children.\n */\nexport function childrenToElements(children: ReactNode): ReactElement[] {\n return Children.toArray(children).filter(isReactElement);\n}\n","import { isValidElement, type ReactElement, type ReactNode } from \"react\";\n\n/**\n * Determines whether a React node is a valid React element.\n *\n * @param node The React node to check.\n * @returns `true` when the node is a valid React element; otherwise `false`.\n */\nexport function isReactElement(node: ReactNode): node is ReactElement {\n return isValidElement(node);\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport { useChildWhere } from \"./useChildWhere\";\nimport type { ElementOfType } from \"./types\";\n\n/**\n * Returns the first direct child element whose React element type exactly matches the provided type.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @returns The first direct child element whose type matches the provided element type, or `null` when no match is found.\n */\nexport function useChildByType<T extends ElementType>(\n children: ReactNode,\n type: T\n): ElementOfType<T> | null {\n return useChildWhere(children, (element): element is ElementOfType<T> =>\n isElementOfType(element, type)\n );\n}\n","import { useMemo, type ReactElement, type ReactNode } from \"react\";\n\nimport { childrenToElements } from \"./childrenToElements\";\n\n/**\n * Returns the direct child elements that satisfy the provided predicate.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it should be included in the result.\n * @returns An array of direct child elements that satisfy the provided predicate.\n */\nexport function useChildrenWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T\n): T[];\nexport function useChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean\n): ReactElement[];\nexport function useChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean\n): ReactElement[] {\n return useMemo(\n () => childrenToElements(children).filter(predicate),\n [children, predicate]\n );\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport { useChildrenWhere } from \"./useChildrenWhere\";\nimport type { ElementOfType } from \"./types\";\n\n/**\n * Returns the direct child elements whose React element type exactly matches the provided type.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @returns An array of direct child elements whose type matches the provided element type.\n */\nexport function useChildrenByType<T extends ElementType>(\n children: ReactNode,\n type: T\n): ElementOfType<T>[] {\n return useChildrenWhere(children, (element): element is ElementOfType<T> =>\n isElementOfType(element, type)\n );\n}\n","import { createReporter, type RuntimeReporterMessages } from \"runtime-reporter\";\n\nconst messages: RuntimeReporterMessages<\n | {\n code: \"REQUIRED_CHILD_WHERE_PREDICATE_FAILED\";\n template: \"{{ traceCodePrefix }}Required child validation failed{{ childNameSegment }} because no direct child satisfied the provided predicate.\";\n tokens: \"traceCodePrefix\" | \"childNameSegment\";\n }\n | {\n code: \"MINIMUM_CHILDREN_WHERE_PREDICATE_FAILED\";\n template: \"{{ traceCodePrefix }}Minimum children validation failed{{ childNameSegment }} because only {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at least {{ minimumCount }}.\";\n tokens:\n | \"traceCodePrefix\"\n | \"childNameSegment\"\n | \"actualCount\"\n | \"actualCountPluralSuffix\"\n | \"minimumCount\";\n }\n | {\n code: \"MAXIMUM_CHILDREN_WHERE_PREDICATE_FAILED\";\n template: \"{{ traceCodePrefix }}Maximum children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at most {{ maximumCount }}.\";\n tokens:\n | \"traceCodePrefix\"\n | \"childNameSegment\"\n | \"actualCount\"\n | \"actualCountPluralSuffix\"\n | \"maximumCount\";\n }\n | {\n code: \"EXACT_CHILDREN_WHERE_PREDICATE_FAILED\";\n template: \"{{ traceCodePrefix }}Exact children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected exactly {{ exactCount }}.\";\n tokens:\n | \"traceCodePrefix\"\n | \"childNameSegment\"\n | \"actualCount\"\n | \"actualCountPluralSuffix\"\n | \"exactCount\";\n }\n> = {\n REQUIRED_CHILD_WHERE_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Required child validation failed{{ childNameSegment }} because no direct child satisfied the provided predicate.\",\n MINIMUM_CHILDREN_WHERE_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Minimum children validation failed{{ childNameSegment }} because only {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at least {{ minimumCount }}.\",\n MAXIMUM_CHILDREN_WHERE_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Maximum children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at most {{ maximumCount }}.\",\n EXACT_CHILDREN_WHERE_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Exact children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected exactly {{ exactCount }}.\"\n};\n\n/** The runtime reporter for react-children-hooks */\nconst reporter = createReporter(\n process.env.NODE_ENV === \"production\" ? ({} as typeof messages) : messages,\n { formatMessage: (message) => message }\n);\n\nexport default reporter;\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport { useChildrenWhere } from \"./useChildrenWhere\";\n\nexport type UseExactChildrenWhereOptions = {\n /**\n * An optional consumer-defined trace code that is prefixed to the thrown validation message.\n */\n traceCode?: string;\n /**\n * An optional human-readable child name that is included in the thrown validation message.\n */\n childName?: string;\n};\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when the exact count is not met.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param exactCount The exact number of matching direct child elements required.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useExactChildrenWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n exactCount: number,\n options?: UseExactChildrenWhereOptions\n): T[];\nexport function useExactChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n exactCount: number,\n options?: UseExactChildrenWhereOptions\n): ReactElement[];\nexport function useExactChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n exactCount: number,\n options?: UseExactChildrenWhereOptions\n): ReactElement[] {\n const matchingChildren = useChildrenWhere(children, predicate);\n\n if (matchingChildren.length === exactCount) {\n return matchingChildren;\n }\n\n return reporter.fail(\"EXACT_CHILDREN_WHERE_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n exactCount\n });\n}\n","import { useMemo, type ReactElement, type ReactNode } from \"react\";\n\nimport { childrenToElements } from \"./childrenToElements\";\n\n/**\n * Determines whether any direct child element satisfies the provided predicate.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @returns `true` when at least one direct child element satisfies the provided predicate; otherwise `false`.\n */\nexport function useHasChildWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T\n): boolean;\nexport function useHasChildWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean\n): boolean;\nexport function useHasChildWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean\n): boolean {\n return useMemo(\n () => childrenToElements(children).some(predicate),\n [children, predicate]\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport { useChildrenWhere } from \"./useChildrenWhere\";\n\nexport type UseMaximumChildrenWhereOptions = {\n /**\n * An optional consumer-defined trace code that is prefixed to the thrown validation message.\n */\n traceCode?: string;\n /**\n * An optional human-readable child name that is included in the thrown validation message.\n */\n childName?: string;\n};\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when more than the maximum count are found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param maximumCount The maximum number of matching direct child elements allowed.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useMaximumChildrenWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n maximumCount: number,\n options?: UseMaximumChildrenWhereOptions\n): T[];\nexport function useMaximumChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n maximumCount: number,\n options?: UseMaximumChildrenWhereOptions\n): ReactElement[];\nexport function useMaximumChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n maximumCount: number,\n options?: UseMaximumChildrenWhereOptions\n): ReactElement[] {\n const matchingChildren = useChildrenWhere(children, predicate);\n\n if (matchingChildren.length <= maximumCount) {\n return matchingChildren;\n }\n\n return reporter.fail(\"MAXIMUM_CHILDREN_WHERE_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n maximumCount\n });\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport { useChildrenWhere } from \"./useChildrenWhere\";\n\nexport type UseMinimumChildrenWhereOptions = {\n /**\n * An optional consumer-defined trace code that is prefixed to the thrown validation message.\n */\n traceCode?: string;\n /**\n * An optional human-readable child name that is included in the thrown validation message.\n */\n childName?: string;\n};\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when fewer than the minimum count are found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param minimumCount The minimum number of matching direct child elements required.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useMinimumChildrenWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n minimumCount: number,\n options?: UseMinimumChildrenWhereOptions\n): T[];\nexport function useMinimumChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n minimumCount: number,\n options?: UseMinimumChildrenWhereOptions\n): ReactElement[];\nexport function useMinimumChildrenWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n minimumCount: number,\n options?: UseMinimumChildrenWhereOptions\n): ReactElement[] {\n const matchingChildren = useChildrenWhere(children, predicate);\n\n if (matchingChildren.length >= minimumCount) {\n return matchingChildren;\n }\n\n return reporter.fail(\"MINIMUM_CHILDREN_WHERE_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n minimumCount\n });\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport { useChildWhere } from \"./useChildWhere\";\n\nexport type UseRequiredChildWhereOptions = {\n /**\n * An optional consumer-defined trace code that is prefixed to the thrown validation message.\n */\n traceCode?: string;\n /**\n * An optional human-readable child name that is included in the thrown validation message.\n */\n childName?: string;\n};\n\n/**\n * Returns the first direct child element that satisfies the provided predicate, or throws when no match is found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The first direct child element that satisfies the provided predicate.\n */\nexport function useRequiredChildWhere<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: UseRequiredChildWhereOptions\n): T;\nexport function useRequiredChildWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: UseRequiredChildWhereOptions\n): ReactElement;\nexport function useRequiredChildWhere(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: UseRequiredChildWhereOptions\n): ReactElement {\n const child = useChildWhere(children, predicate);\n\n if (child !== null) {\n return child;\n }\n\n return reporter.fail(\"REQUIRED_CHILD_WHERE_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\"\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,SAAS,gBACZ,SACA,MAC2B;AAC3B,SAAO,QAAQ,SAAS;AAC5B;;;AChBA,IAAAA,gBAA2D;;;ACA3D,IAAAC,gBAA4D;;;ACA5D,mBAAkE;AAQ3D,SAAS,eAAe,MAAuC;AAClE,aAAO,6BAAe,IAAI;AAC9B;;;ADAO,SAAS,mBAAmB,UAAqC;AACpE,SAAO,uBAAS,QAAQ,QAAQ,EAAE,OAAO,cAAc;AAC3D;;;ADOO,SAAS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_react","import_react","import_react","import_react"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/isElementOfType.ts","../src/useChildMatching.ts","../src/childrenToElements.ts","../src/isReactElement.ts","../src/reporter.ts","../src/useChildByType.ts","../src/useCallbackChild.ts","../src/useChildrenMatching.ts","../src/useBoundedChildrenMatching.ts","../src/useBoundedChildrenByType.ts","../src/useChildrenByType.ts","../src/useExactChildrenMatching.ts","../src/useExactChildrenByType.ts","../src/useHasChildMatching.ts","../src/useMaximumChildrenMatching.ts","../src/useMaximumChildrenByType.ts","../src/useMinimumChildrenMatching.ts","../src/useMinimumChildrenByType.ts","../src/useOptionalChildMatching.ts","../src/useOptionalChildByType.ts","../src/useRequiredChildMatching.ts","../src/useRequiredChildByType.ts","../src/useRequiredCallbackChild.ts","../src/useUniqueChildMatching.ts","../src/useUniqueChildByType.ts"],"sourcesContent":["export { useChildByType } from \"./useChildByType\";\nexport { useCallbackChild } from \"./useCallbackChild\";\nexport { useChildMatching } from \"./useChildMatching\";\nexport { useBoundedChildrenByType } from \"./useBoundedChildrenByType\";\nexport { useBoundedChildrenMatching } from \"./useBoundedChildrenMatching\";\nexport { useChildrenByType } from \"./useChildrenByType\";\nexport { useChildrenMatching } from \"./useChildrenMatching\";\nexport { useExactChildrenByType } from \"./useExactChildrenByType\";\nexport { useExactChildrenMatching } from \"./useExactChildrenMatching\";\nexport { useHasChildMatching } from \"./useHasChildMatching\";\nexport { useMaximumChildrenByType } from \"./useMaximumChildrenByType\";\nexport { useMaximumChildrenMatching } from \"./useMaximumChildrenMatching\";\nexport { useMinimumChildrenByType } from \"./useMinimumChildrenByType\";\nexport { useMinimumChildrenMatching } from \"./useMinimumChildrenMatching\";\nexport { useOptionalChildByType } from \"./useOptionalChildByType\";\nexport { useOptionalChildMatching } from \"./useOptionalChildMatching\";\nexport { useRequiredChildByType } from \"./useRequiredChildByType\";\nexport { useRequiredCallbackChild } from \"./useRequiredCallbackChild\";\nexport { useRequiredChildMatching } from \"./useRequiredChildMatching\";\nexport { useUniqueChildByType } from \"./useUniqueChildByType\";\nexport { useUniqueChildMatching } from \"./useUniqueChildMatching\";\nexport { childrenToElements } from \"./childrenToElements\";\nexport { isElementOfType } from \"./isElementOfType\";\nexport { isReactElement } from \"./isReactElement\";\nexport type * from \"./types\";\n","import type { ElementType, ReactElement } from \"react\";\n\nimport type { ElementOfType } from \"./types\";\n\n/**\n * Determines whether a React element exactly matches the provided element or component type.\n *\n * @param element The React element to compare.\n * @param type The element or component type to match.\n * @returns `true` when the element's type exactly matches the provided type; otherwise `false`.\n */\nexport function isElementOfType<T extends ElementType>(\n element: ReactElement,\n type: T\n): element is ElementOfType<T> {\n return element.type === type;\n}\n","import { useMemo, type ReactElement, type ReactNode } from \"react\";\n\nimport { childrenToElements } from \"./childrenToElements\";\nimport type { QueryOptions } from \"./types\";\n\n/**\n * Returns the first direct child element that satisfies the provided predicate.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param options Optional query metadata used to configure how child elements are inspected.\n * @returns The first direct child element that satisfies the provided predicate, or `null` when no match is found.\n */\nexport function useChildMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: QueryOptions\n): T | null;\nexport function useChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: QueryOptions\n): ReactElement | null;\nexport function useChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: QueryOptions\n): ReactElement | null {\n return useMemo(\n () => childrenToElements(children, options).find(predicate) ?? null,\n [children, options, predicate]\n );\n}\n","import { Children, type ReactElement, type ReactNode } from \"react\";\n\nimport { isReactElement } from \"./isReactElement\";\nimport reporter from \"./reporter\";\nimport type { TraversalOptions } from \"./types\";\n\n/**\n * Normalizes traversal bounds and validates that the provided options define a valid inclusive depth range.\n *\n * @param options Optional traversal bounds supplied to an element-inspection API.\n * @returns The normalized inclusive traversal bounds, defaulting to direct children only when omitted.\n */\nfunction getTraversalBounds(options?: TraversalOptions): {\n depth: number;\n maximumDepth: number;\n} {\n const depth = options?.depth ?? 0;\n const maximumDepth = options?.maximumDepth ?? 0;\n\n if (!Number.isInteger(depth) || depth < 0) {\n return reporter.fail(\"RCH001\");\n }\n\n if (!Number.isInteger(maximumDepth) || maximumDepth < 0) {\n return reporter.fail(\"RCH002\");\n }\n\n if (depth > maximumDepth) {\n return reporter.fail(\"RCH003\");\n }\n\n return { depth, maximumDepth };\n}\n\n/**\n * Recursively collects valid React child elements within the provided inclusive depth range.\n *\n * @param children The React children value to inspect at the current traversal level.\n * @param currentDepth The zero-based depth of the current traversal level, where `0` represents direct children.\n * @param depth The minimum inclusive child depth to include in the collected results.\n * @param maximumDepth The maximum inclusive child depth to include in the collected results.\n * @returns An array of valid React elements collected from the current level and any eligible descendant levels.\n */\nfunction collectElementsAtDepth(\n children: ReactNode,\n currentDepth: number,\n depth: number,\n maximumDepth: number\n): ReactElement[] {\n const directElements = Children.toArray(children).filter(isReactElement);\n let elements: ReactElement[] = [];\n\n if (currentDepth >= depth && currentDepth <= maximumDepth) {\n elements = [...directElements];\n }\n\n for (const element of directElements) {\n const elementProps = element.props as { children?: ReactNode };\n const elementsAtDepth = collectElementsAtDepth(\n elementProps.children,\n currentDepth + 1,\n depth,\n maximumDepth\n );\n\n elements.push(...elementsAtDepth);\n }\n\n return elements;\n}\n\n/**\n * Normalizes a React children value into an array containing valid child elements within the configured depth range.\n *\n * @param children The React children value to normalize.\n * @param options Optional traversal bounds that control which child depths are included.\n * @returns An array of valid React elements from the provided child depths.\n */\nexport function childrenToElements(\n children: ReactNode,\n options?: TraversalOptions\n): ReactElement[] {\n const { depth, maximumDepth } = getTraversalBounds(options);\n\n return collectElementsAtDepth(children, 0, depth, maximumDepth);\n}\n","import { isValidElement, type ReactElement, type ReactNode } from \"react\";\n\n/**\n * Determines whether a React node is a valid React element.\n *\n * @param node The React node to check.\n * @returns `true` when the node is a valid React element; otherwise `false`.\n */\nexport function isReactElement(node: ReactNode): node is ReactElement {\n return isValidElement(node);\n}\n","import { createReporter } from \"runtime-reporter\";\n\n/** Internal validation reporter messages used by the hook validation APIs */\nconst validationMessages = {\n OPTIONAL_CHILD_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Optional child validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at most 1.\",\n UNIQUE_CHILD_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Unique child validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected exactly 1.\",\n REQUIRED_CHILD_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Required child validation failed{{ childNameSegment }} because no direct child satisfied the provided predicate.\",\n REQUIRED_CALLBACK_CHILD_FAILED:\n \"{{ traceCodePrefix }}Required callback child validation failed{{ childNameSegment }} because no direct callback child was found.\",\n MINIMUM_CHILDREN_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Minimum children validation failed{{ childNameSegment }} because only {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at least {{ minimumCount }}.\",\n MAXIMUM_CHILDREN_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Maximum children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected at most {{ maximumCount }}.\",\n EXACT_CHILDREN_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Exact children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected exactly {{ exactCount }}.\",\n BOUNDED_CHILDREN_MATCHING_PREDICATE_FAILED:\n \"{{ traceCodePrefix }}Bounded children validation failed{{ childNameSegment }} because {{ actualCount }} direct child{{ actualCountPluralSuffix }} satisfied the provided predicate; expected between {{ minimumCount }} and {{ maximumCount }} inclusive.\"\n} as const;\n\n/** Public-facing reporter messages for this library */\nconst publicMessages = {\n RCH001: '[RCH001] Traversal option \"depth\" must be a non-negative integer.',\n RCH002: '[RCH002] Traversal option \"maximumDepth\" must be a non-negative integer.',\n RCH003: '[RCH003] Traversal option \"depth\" cannot be greater than \"maximumDepth\".'\n} as const;\n\n/** All reporter messages for this library */\nconst messages = {\n ...validationMessages,\n ...publicMessages\n} as const;\n\n/** The runtime reporter for react-children-hooks */\nconst reporter = createReporter(\n process.env.NODE_ENV === \"production\" ? ({} as typeof messages) : messages,\n { formatMessage: (message) => message }\n);\n\nexport default reporter;\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, QueryOptions } from \"./types\";\nimport { useChildMatching } from \"./useChildMatching\";\n\n/**\n * Returns the first direct child element whose React element type exactly matches the provided type.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param options Optional query metadata used to configure how child elements are inspected.\n * @returns The first direct child element whose type matches the provided element type, or `null` when no match is found.\n */\nexport function useChildByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n options?: QueryOptions\n): ElementOfType<T> | null {\n return useChildMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n options\n );\n}\n","import { useMemo, type ReactNode } from \"react\";\n\nimport type { CallbackChild, CallbackChildren } from \"./types\";\n\nfunction findFirstCallbackChild<TArguments extends unknown[], TResult>(\n children: CallbackChildren<TArguments, TResult>\n): CallbackChild<TArguments, TResult> | null {\n if (typeof children === \"function\") {\n return children;\n }\n\n if (!Array.isArray(children)) {\n return null;\n }\n\n for (const child of children) {\n const callbackChild = findFirstCallbackChild<TArguments, TResult>(\n child\n );\n\n if (callbackChild) {\n return callbackChild;\n }\n }\n\n return null;\n}\n\n/**\n * Returns the first direct callback child from the provided children value.\n *\n * @param children The direct children value to inspect.\n * @returns The first direct callback child, or `null` when no callback child is found.\n */\nexport function useCallbackChild<\n TArguments extends unknown[] = [],\n TResult = ReactNode\n>(\n children: CallbackChildren<TArguments, TResult>\n): CallbackChild<TArguments, TResult> | null {\n return useMemo(() => findFirstCallbackChild(children), [children]);\n}\n","import { useMemo, type ReactElement, type ReactNode } from \"react\";\n\nimport { childrenToElements } from \"./childrenToElements\";\nimport type { QueryOptions } from \"./types\";\n\n/**\n * Returns the direct child elements that satisfy the provided predicate.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it should be included in the result.\n * @param options Optional query metadata used to configure how child elements are inspected.\n * @returns An array of direct child elements that satisfy the provided predicate.\n */\nexport function useChildrenMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: QueryOptions\n): T[];\nexport function useChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: QueryOptions\n): ReactElement[];\nexport function useChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: QueryOptions\n): ReactElement[] {\n return useMemo(\n () => childrenToElements(children, options).filter(predicate),\n [children, options, predicate]\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ChildrenCountBounds, ValidationOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when the count falls outside the inclusive bounds.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useBoundedChildrenMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n bounds: ChildrenCountBounds,\n options?: ValidationOptions\n): T[];\nexport function useBoundedChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n bounds: ChildrenCountBounds,\n options?: ValidationOptions\n): ReactElement[];\nexport function useBoundedChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n bounds: ChildrenCountBounds,\n options?: ValidationOptions\n): ReactElement[] {\n const matchingChildren = useChildrenMatching(children, predicate, options);\n\n if (\n matchingChildren.length >= bounds.minimum &&\n matchingChildren.length <= bounds.maximum\n ) {\n return matchingChildren;\n }\n\n return reporter.fail(\"BOUNDED_CHILDREN_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n minimumCount: bounds.minimum,\n maximumCount: bounds.maximum\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type {\n ChildrenCountBounds,\n ElementOfType,\n ValidationOptions\n} from \"./types\";\nimport { useBoundedChildrenMatching } from \"./useBoundedChildrenMatching\";\n\n/**\n * Returns the direct child elements whose React element type exactly matches the provided type, or throws when the count falls outside the inclusive bounds.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements whose type matches the provided element type.\n */\nexport function useBoundedChildrenByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n bounds: ChildrenCountBounds,\n options?: ValidationOptions\n): ElementOfType<T>[] {\n return useBoundedChildrenMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n bounds,\n options\n );\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, QueryOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the direct child elements whose React element type exactly matches the provided type.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param options Optional query metadata used to configure how child elements are inspected.\n * @returns An array of direct child elements whose type matches the provided element type.\n */\nexport function useChildrenByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n options?: QueryOptions\n): ElementOfType<T>[] {\n return useChildrenMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n options\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ValidationOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when the exact count is not met.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param exactCount The exact number of matching direct child elements required.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useExactChildrenMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n exactCount: number,\n options?: ValidationOptions\n): T[];\nexport function useExactChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n exactCount: number,\n options?: ValidationOptions\n): ReactElement[];\nexport function useExactChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n exactCount: number,\n options?: ValidationOptions\n): ReactElement[] {\n const matchingChildren = useChildrenMatching(children, predicate, options);\n\n if (matchingChildren.length === exactCount) {\n return matchingChildren;\n }\n\n return reporter.fail(\"EXACT_CHILDREN_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n exactCount\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, ValidationOptions } from \"./types\";\nimport { useExactChildrenMatching } from \"./useExactChildrenMatching\";\n\n/**\n * Returns the direct child elements whose React element type exactly matches the provided type, or throws when the exact count is not met.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param exactCount The exact number of matching direct child elements required.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements whose type matches the provided element type.\n */\nexport function useExactChildrenByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n exactCount: number,\n options?: ValidationOptions\n): ElementOfType<T>[] {\n return useExactChildrenMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n exactCount,\n options\n );\n}\n","import { useMemo, type ReactElement, type ReactNode } from \"react\";\n\nimport { childrenToElements } from \"./childrenToElements\";\nimport type { QueryOptions } from \"./types\";\n\n/**\n * Determines whether any direct child element satisfies the provided predicate.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param options Optional query metadata used to configure how child elements are inspected.\n * @returns `true` when at least one direct child element satisfies the provided predicate; otherwise `false`.\n */\nexport function useHasChildMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: QueryOptions\n): boolean;\nexport function useHasChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: QueryOptions\n): boolean;\nexport function useHasChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: QueryOptions\n): boolean {\n return useMemo(\n () => childrenToElements(children, options).some(predicate),\n [children, options, predicate]\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ValidationOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when more than the maximum count are found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param maximumCount The maximum number of matching direct child elements allowed.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useMaximumChildrenMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n maximumCount: number,\n options?: ValidationOptions\n): T[];\nexport function useMaximumChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n maximumCount: number,\n options?: ValidationOptions\n): ReactElement[];\nexport function useMaximumChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n maximumCount: number,\n options?: ValidationOptions\n): ReactElement[] {\n const matchingChildren = useChildrenMatching(children, predicate, options);\n\n if (matchingChildren.length <= maximumCount) {\n return matchingChildren;\n }\n\n return reporter.fail(\"MAXIMUM_CHILDREN_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n maximumCount\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, ValidationOptions } from \"./types\";\nimport { useMaximumChildrenMatching } from \"./useMaximumChildrenMatching\";\n\n/**\n * Returns the direct child elements whose React element type exactly matches the provided type, or throws when more than the maximum count are found.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param maximumCount The maximum number of matching direct child elements allowed.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements whose type matches the provided element type.\n */\nexport function useMaximumChildrenByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n maximumCount: number,\n options?: ValidationOptions\n): ElementOfType<T>[] {\n return useMaximumChildrenMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n maximumCount,\n options\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ValidationOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the direct child elements that satisfy the provided predicate, or throws when fewer than the minimum count are found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param minimumCount The minimum number of matching direct child elements required.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements that satisfy the provided predicate.\n */\nexport function useMinimumChildrenMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n minimumCount: number,\n options?: ValidationOptions\n): T[];\nexport function useMinimumChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n minimumCount: number,\n options?: ValidationOptions\n): ReactElement[];\nexport function useMinimumChildrenMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n minimumCount: number,\n options?: ValidationOptions\n): ReactElement[] {\n const matchingChildren = useChildrenMatching(children, predicate, options);\n\n if (matchingChildren.length >= minimumCount) {\n return matchingChildren;\n }\n\n return reporter.fail(\"MINIMUM_CHILDREN_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\",\n minimumCount\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, ValidationOptions } from \"./types\";\nimport { useMinimumChildrenMatching } from \"./useMinimumChildrenMatching\";\n\n/**\n * Returns the direct child elements whose React element type exactly matches the provided type, or throws when fewer than the minimum count are found.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param minimumCount The minimum number of matching direct child elements required.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The direct child elements whose type matches the provided element type.\n */\nexport function useMinimumChildrenByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n minimumCount: number,\n options?: ValidationOptions\n): ElementOfType<T>[] {\n return useMinimumChildrenMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n minimumCount,\n options\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ValidationOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the optional direct child element that satisfies the provided predicate, or throws when more than one match is found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The optional direct child element that satisfies the provided predicate, or `null` when no match is found.\n */\nexport function useOptionalChildMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: ValidationOptions\n): T | null;\nexport function useOptionalChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: ValidationOptions\n): ReactElement | null;\nexport function useOptionalChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: ValidationOptions\n): ReactElement | null {\n const matchingChildren = useChildrenMatching(children, predicate, options);\n\n if (matchingChildren.length <= 1) {\n return matchingChildren[0] ?? null;\n }\n\n return reporter.fail(\"OPTIONAL_CHILD_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\"\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, ValidationOptions } from \"./types\";\nimport { useOptionalChildMatching } from \"./useOptionalChildMatching\";\n\n/**\n * Returns the optional direct child element whose React element type exactly matches the provided type, or throws when more than one match is found.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The optional direct child element whose type matches the provided element type, or `null` when no match is found.\n */\nexport function useOptionalChildByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n options?: ValidationOptions\n): ElementOfType<T> | null {\n return useOptionalChildMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n options\n );\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ValidationOptions } from \"./types\";\nimport { useChildMatching } from \"./useChildMatching\";\n\n/**\n * Returns the first direct child element that satisfies the provided predicate, or throws when no match is found.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The first direct child element that satisfies the provided predicate.\n */\nexport function useRequiredChildMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: ValidationOptions\n): T;\nexport function useRequiredChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: ValidationOptions\n): ReactElement;\nexport function useRequiredChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: ValidationOptions\n): ReactElement {\n const child = useChildMatching(children, predicate, options);\n\n if (child !== null) {\n return child;\n }\n\n return reporter.fail(\"REQUIRED_CHILD_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\"\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, ValidationOptions } from \"./types\";\nimport { useRequiredChildMatching } from \"./useRequiredChildMatching\";\n\n/**\n * Returns the first direct child element whose React element type exactly matches the provided type, or throws when no match is found.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The first direct child element whose type matches the provided element type.\n */\nexport function useRequiredChildByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n options?: ValidationOptions\n): ElementOfType<T> {\n return useRequiredChildMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n options\n );\n}\n","import { type ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type {\n CallbackChild,\n CallbackChildren,\n ValidationOptions\n} from \"./types\";\nimport { useCallbackChild } from \"./useCallbackChild\";\n\n/**\n * Returns the first direct callback child from the provided children value, or throws when none is found.\n *\n * @param children The direct children value to inspect.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The first direct callback child from the provided children value.\n */\nexport function useRequiredCallbackChild<\n TArguments extends unknown[] = [],\n TResult = ReactNode\n>(\n children: CallbackChildren<TArguments, TResult>,\n options?: ValidationOptions\n): CallbackChild<TArguments, TResult> {\n const callbackChild = useCallbackChild(children);\n\n if (callbackChild !== null) {\n return callbackChild;\n }\n\n return reporter.fail(\"REQUIRED_CALLBACK_CHILD_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\"\n });\n}\n","import type { ReactElement, ReactNode } from \"react\";\n\nimport reporter from \"./reporter\";\nimport type { ValidationOptions } from \"./types\";\nimport { useChildrenMatching } from \"./useChildrenMatching\";\n\n/**\n * Returns the only direct child element that satisfies the provided predicate, or throws when the match is not unique.\n *\n * @param children The React children value to inspect.\n * @param predicate A predicate that is called with each direct child element to determine whether it matches.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The only direct child element that satisfies the provided predicate.\n */\nexport function useUniqueChildMatching<T extends ReactElement>(\n children: ReactNode,\n predicate: (element: ReactElement) => element is T,\n options?: ValidationOptions\n): T;\nexport function useUniqueChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: ValidationOptions\n): ReactElement;\nexport function useUniqueChildMatching(\n children: ReactNode,\n predicate: (element: ReactElement) => boolean,\n options?: ValidationOptions\n): ReactElement {\n const matchingChildren = useChildrenMatching(children, predicate, options);\n\n if (matchingChildren.length === 1) {\n return matchingChildren[0] as ReactElement;\n }\n\n return reporter.fail(\"UNIQUE_CHILD_MATCHING_PREDICATE_FAILED\", {\n traceCodePrefix: options?.traceCode ? `[${options.traceCode}] ` : \"\",\n childNameSegment: options?.childName ? ` for ${options.childName}` : \"\",\n actualCount: matchingChildren.length,\n actualCountPluralSuffix: matchingChildren.length === 1 ? \"\" : \"ren\"\n });\n}\n","import type { ElementType, ReactNode } from \"react\";\n\nimport { isElementOfType } from \"./isElementOfType\";\nimport type { ElementOfType, ValidationOptions } from \"./types\";\nimport { useUniqueChildMatching } from \"./useUniqueChildMatching\";\n\n/**\n * Returns the only direct child element whose React element type exactly matches the provided type, or throws when the match is not unique.\n *\n * @param children The React children value to inspect.\n * @param type The element or component type to match against each direct child element.\n * @param options Optional reporting metadata used to derive the thrown validation message.\n * @returns The only direct child element whose type matches the provided element type.\n */\nexport function useUniqueChildByType<T extends ElementType>(\n children: ReactNode,\n type: T,\n options?: ValidationOptions\n): ElementOfType<T> {\n return useUniqueChildMatching(\n children,\n (element): element is ElementOfType<T> =>\n isElementOfType(element, type),\n options\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,SAAS,gBACZ,SACA,MAC2B;AAC3B,SAAO,QAAQ,SAAS;AAC5B;;;AChBA,IAAAA,gBAA2D;;;ACA3D,IAAAC,gBAA4D;;;ACA5D,mBAAkE;AAQ3D,SAAS,eAAe,MAAuC;AAClE,aAAO,6BAAe,IAAI;AAC9B;;;ACVA,8BAA+B;AAG/B,IAAM,qBAAqB;AAAA,EACvB,0CACI;AAAA,EACJ,wCACI;AAAA,EACJ,0CACI;AAAA,EACJ,gCACI;AAAA,EACJ,4CACI;AAAA,EACJ,4CACI;AAAA,EACJ,0CACI;AAAA,EACJ,4CACI;AACR;AA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C7B;AAEA,SAAO,iBAAS,KAAK,0CAA0C;AAAA,IAC3D,iBAAiB,SAAS,YAAY,IAAI,QAAQ,SAAS,OAAO;AAAA,IAClE,kBAAkB,SAAS,YAAY,QAAQ,QAAQ,SAAS,KAAK;AAAA,IACrE,aAAa,iBAAiB;AAAA,IAC9B,yBAAyB,iBAAiB,WAAW,IAAI,KAAK;AAAA,EAClE,CAAC;AACL;;;AC3BO,SAAS,qBACZ,UACA,MACA,SACgB;AAChB,SAAO;AAAA,IACH;AAAA,IACA,CAAC,YACG,gBAAgB,SAAS,IAAI;AAAA,IACjC;AAAA,EACJ;AACJ;","names":["import_react","import_react","import_react","import_react","import_react","import_react"]}
package/dist/index.d.cts CHANGED
@@ -1,61 +1,158 @@
1
1
  import * as React from 'react';
2
2
  import { ElementType, ReactNode, ReactElement } from 'react';
3
3
 
4
+ /**
5
+ * Inclusive minimum and maximum bounds used by the bounded validation hooks.
6
+ */
7
+ type ChildrenCountBounds = {
8
+ /**
9
+ * The minimum number of matching direct child elements required.
10
+ */
11
+ minimum: number;
12
+ /**
13
+ * The maximum number of matching direct child elements allowed.
14
+ */
15
+ maximum: number;
16
+ };
17
+ /**
18
+ * Optional traversal bounds used by the element-based query and validation hooks.
19
+ */
20
+ type TraversalOptions = {
21
+ /**
22
+ * The minimum inclusive child depth to include in results, where `0` represents direct children.
23
+ */
24
+ depth?: number;
25
+ /**
26
+ * The maximum inclusive child depth to include in results, where `0` represents direct children.
27
+ */
28
+ maximumDepth?: number;
29
+ };
30
+ /**
31
+ * Optional traversal metadata used by the element-based query hooks.
32
+ */
33
+ type QueryOptions = TraversalOptions;
4
34
  /**
5
35
  * Represents a React element whose props and element type are narrowed to the provided React element type.
6
36
  *
7
37
  * @typeParam T The React element type used to narrow the element's props and type.
8
38
  */
9
39
  type ElementOfType<T extends React.ElementType> = React.ReactElement<React.ComponentProps<T>, T>;
40
+ /**
41
+ * A callback child, also known as a render-prop child.
42
+ *
43
+ * @typeParam TArguments The positional argument tuple accepted by the callback.
44
+ * @typeParam TResult The value returned by the callback.
45
+ */
46
+ type CallbackChild<TArguments extends unknown[] = [], TResult = React.ReactNode> = (...args: TArguments) => TResult;
47
+ /**
48
+ * A direct-children value that may include callback children alongside regular React children.
49
+ *
50
+ * @typeParam TArguments The positional argument tuple accepted by callback children.
51
+ * @typeParam TResult The value returned by callback children.
52
+ */
53
+ type CallbackChildren<TArguments extends unknown[] = [], TResult = React.ReactNode> = React.ReactNode | CallbackChild<TArguments, TResult> | readonly CallbackChildren<TArguments, TResult>[];
54
+ /**
55
+ * Optional reporting metadata used by the validation hooks to derive thrown validation messages.
56
+ */
57
+ type ValidationMessageOptions = {
58
+ /**
59
+ * An optional consumer-defined trace code that is prefixed to the thrown validation message.
60
+ */
61
+ traceCode?: string;
62
+ /**
63
+ * An optional human-readable child name that is included in the thrown validation message.
64
+ */
65
+ childName?: string;
66
+ };
67
+ /**
68
+ * Optional reporting and traversal metadata used by the validation hooks.
69
+ */
70
+ type ValidationOptions = ValidationMessageOptions & TraversalOptions;
10
71
 
11
72
  /**
12
73
  * Returns the first direct child element whose React element type exactly matches the provided type.
13
74
  *
14
75
  * @param children The React children value to inspect.
15
76
  * @param type The element or component type to match against each direct child element.
77
+ * @param options Optional query metadata used to configure how child elements are inspected.
16
78
  * @returns The first direct child element whose type matches the provided element type, or `null` when no match is found.
17
79
  */
18
- declare function useChildByType<T extends ElementType>(children: ReactNode, type: T): ElementOfType<T> | null;
80
+ declare function useChildByType<T extends ElementType>(children: ReactNode, type: T, options?: QueryOptions): ElementOfType<T> | null;
81
+
82
+ /**
83
+ * Returns the first direct callback child from the provided children value.
84
+ *
85
+ * @param children The direct children value to inspect.
86
+ * @returns The first direct callback child, or `null` when no callback child is found.
87
+ */
88
+ declare function useCallbackChild<TArguments extends unknown[] = [], TResult = ReactNode>(children: CallbackChildren<TArguments, TResult>): CallbackChild<TArguments, TResult> | null;
19
89
 
20
90
  /**
21
91
  * Returns the first direct child element that satisfies the provided predicate.
22
92
  *
23
93
  * @param children The React children value to inspect.
24
94
  * @param predicate A predicate that is called with each direct child element to determine whether it matches.
95
+ * @param options Optional query metadata used to configure how child elements are inspected.
25
96
  * @returns The first direct child element that satisfies the provided predicate, or `null` when no match is found.
26
97
  */
27
- declare function useChildWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): T | null;
28
- declare function useChildWhere(children: ReactNode, predicate: (element: ReactElement) => boolean): ReactElement | null;
98
+ declare function useChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: QueryOptions): T | null;
99
+ declare function useChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: QueryOptions): ReactElement | null;
100
+
101
+ /**
102
+ * Returns the direct child elements whose React element type exactly matches the provided type, or throws when the count falls outside the inclusive bounds.
103
+ *
104
+ * @param children The React children value to inspect.
105
+ * @param type The element or component type to match against each direct child element.
106
+ * @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.
107
+ * @param options Optional reporting metadata used to derive the thrown validation message.
108
+ * @returns The direct child elements whose type matches the provided element type.
109
+ */
110
+ declare function useBoundedChildrenByType<T extends ElementType>(children: ReactNode, type: T, bounds: ChildrenCountBounds, options?: ValidationOptions): ElementOfType<T>[];
111
+
112
+ /**
113
+ * Returns the direct child elements that satisfy the provided predicate, or throws when the count falls outside the inclusive bounds.
114
+ *
115
+ * @param children The React children value to inspect.
116
+ * @param predicate A predicate that is called with each direct child element to determine whether it matches.
117
+ * @param bounds The inclusive minimum and maximum number of matching direct child elements allowed.
118
+ * @param options Optional reporting metadata used to derive the thrown validation message.
119
+ * @returns The direct child elements that satisfy the provided predicate.
120
+ */
121
+ declare function useBoundedChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, bounds: ChildrenCountBounds, options?: ValidationOptions): T[];
122
+ declare function useBoundedChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, bounds: ChildrenCountBounds, options?: ValidationOptions): ReactElement[];
29
123
 
30
124
  /**
31
125
  * Returns the direct child elements whose React element type exactly matches the provided type.
32
126
  *
33
127
  * @param children The React children value to inspect.
34
128
  * @param type The element or component type to match against each direct child element.
129
+ * @param options Optional query metadata used to configure how child elements are inspected.
35
130
  * @returns An array of direct child elements whose type matches the provided element type.
36
131
  */
37
- declare function useChildrenByType<T extends ElementType>(children: ReactNode, type: T): ElementOfType<T>[];
132
+ declare function useChildrenByType<T extends ElementType>(children: ReactNode, type: T, options?: QueryOptions): ElementOfType<T>[];
38
133
 
39
134
  /**
40
135
  * Returns the direct child elements that satisfy the provided predicate.
41
136
  *
42
137
  * @param children The React children value to inspect.
43
138
  * @param predicate A predicate that is called with each direct child element to determine whether it should be included in the result.
139
+ * @param options Optional query metadata used to configure how child elements are inspected.
44
140
  * @returns An array of direct child elements that satisfy the provided predicate.
45
141
  */
46
- declare function useChildrenWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): T[];
47
- declare function useChildrenWhere(children: ReactNode, predicate: (element: ReactElement) => boolean): ReactElement[];
142
+ declare function useChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: QueryOptions): T[];
143
+ declare function useChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: QueryOptions): ReactElement[];
144
+
145
+ /**
146
+ * Returns the direct child elements whose React element type exactly matches the provided type, or throws when the exact count is not met.
147
+ *
148
+ * @param children The React children value to inspect.
149
+ * @param type The element or component type to match against each direct child element.
150
+ * @param exactCount The exact number of matching direct child elements required.
151
+ * @param options Optional reporting metadata used to derive the thrown validation message.
152
+ * @returns The direct child elements whose type matches the provided element type.
153
+ */
154
+ declare function useExactChildrenByType<T extends ElementType>(children: ReactNode, type: T, exactCount: number, options?: ValidationOptions): ElementOfType<T>[];
48
155
 
49
- type UseExactChildrenWhereOptions = {
50
- /**
51
- * An optional consumer-defined trace code that is prefixed to the thrown validation message.
52
- */
53
- traceCode?: string;
54
- /**
55
- * An optional human-readable child name that is included in the thrown validation message.
56
- */
57
- childName?: string;
58
- };
59
156
  /**
60
157
  * Returns the direct child elements that satisfy the provided predicate, or throws when the exact count is not met.
61
158
  *
@@ -65,29 +162,31 @@ type UseExactChildrenWhereOptions = {
65
162
  * @param options Optional reporting metadata used to derive the thrown validation message.
66
163
  * @returns The direct child elements that satisfy the provided predicate.
67
164
  */
68
- declare function useExactChildrenWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, exactCount: number, options?: UseExactChildrenWhereOptions): T[];
69
- declare function useExactChildrenWhere(children: ReactNode, predicate: (element: ReactElement) => boolean, exactCount: number, options?: UseExactChildrenWhereOptions): ReactElement[];
165
+ declare function useExactChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, exactCount: number, options?: ValidationOptions): T[];
166
+ declare function useExactChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, exactCount: number, options?: ValidationOptions): ReactElement[];
70
167
 
71
168
  /**
72
169
  * Determines whether any direct child element satisfies the provided predicate.
73
170
  *
74
171
  * @param children The React children value to inspect.
75
172
  * @param predicate A predicate that is called with each direct child element to determine whether it matches.
173
+ * @param options Optional query metadata used to configure how child elements are inspected.
76
174
  * @returns `true` when at least one direct child element satisfies the provided predicate; otherwise `false`.
77
175
  */
78
- declare function useHasChildWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T): boolean;
79
- declare function useHasChildWhere(children: ReactNode, predicate: (element: ReactElement) => boolean): boolean;
176
+ declare function useHasChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: QueryOptions): boolean;
177
+ declare function useHasChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: QueryOptions): boolean;
178
+
179
+ /**
180
+ * Returns the direct child elements whose React element type exactly matches the provided type, or throws when more than the maximum count are found.
181
+ *
182
+ * @param children The React children value to inspect.
183
+ * @param type The element or component type to match against each direct child element.
184
+ * @param maximumCount The maximum number of matching direct child elements allowed.
185
+ * @param options Optional reporting metadata used to derive the thrown validation message.
186
+ * @returns The direct child elements whose type matches the provided element type.
187
+ */
188
+ declare function useMaximumChildrenByType<T extends ElementType>(children: ReactNode, type: T, maximumCount: number, options?: ValidationOptions): ElementOfType<T>[];
80
189
 
81
- type UseMaximumChildrenWhereOptions = {
82
- /**
83
- * An optional consumer-defined trace code that is prefixed to the thrown validation message.
84
- */
85
- traceCode?: string;
86
- /**
87
- * An optional human-readable child name that is included in the thrown validation message.
88
- */
89
- childName?: string;
90
- };
91
190
  /**
92
191
  * Returns the direct child elements that satisfy the provided predicate, or throws when more than the maximum count are found.
93
192
  *
@@ -97,19 +196,20 @@ type UseMaximumChildrenWhereOptions = {
97
196
  * @param options Optional reporting metadata used to derive the thrown validation message.
98
197
  * @returns The direct child elements that satisfy the provided predicate.
99
198
  */
100
- declare function useMaximumChildrenWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, maximumCount: number, options?: UseMaximumChildrenWhereOptions): T[];
101
- declare function useMaximumChildrenWhere(children: ReactNode, predicate: (element: ReactElement) => boolean, maximumCount: number, options?: UseMaximumChildrenWhereOptions): ReactElement[];
199
+ declare function useMaximumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, maximumCount: number, options?: ValidationOptions): T[];
200
+ declare function useMaximumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, maximumCount: number, options?: ValidationOptions): ReactElement[];
201
+
202
+ /**
203
+ * Returns the direct child elements whose React element type exactly matches the provided type, or throws when fewer than the minimum count are found.
204
+ *
205
+ * @param children The React children value to inspect.
206
+ * @param type The element or component type to match against each direct child element.
207
+ * @param minimumCount The minimum number of matching direct child elements required.
208
+ * @param options Optional reporting metadata used to derive the thrown validation message.
209
+ * @returns The direct child elements whose type matches the provided element type.
210
+ */
211
+ declare function useMinimumChildrenByType<T extends ElementType>(children: ReactNode, type: T, minimumCount: number, options?: ValidationOptions): ElementOfType<T>[];
102
212
 
103
- type UseMinimumChildrenWhereOptions = {
104
- /**
105
- * An optional consumer-defined trace code that is prefixed to the thrown validation message.
106
- */
107
- traceCode?: string;
108
- /**
109
- * An optional human-readable child name that is included in the thrown validation message.
110
- */
111
- childName?: string;
112
- };
113
213
  /**
114
214
  * Returns the direct child elements that satisfy the provided predicate, or throws when fewer than the minimum count are found.
115
215
  *
@@ -119,19 +219,49 @@ type UseMinimumChildrenWhereOptions = {
119
219
  * @param options Optional reporting metadata used to derive the thrown validation message.
120
220
  * @returns The direct child elements that satisfy the provided predicate.
121
221
  */
122
- declare function useMinimumChildrenWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, minimumCount: number, options?: UseMinimumChildrenWhereOptions): T[];
123
- declare function useMinimumChildrenWhere(children: ReactNode, predicate: (element: ReactElement) => boolean, minimumCount: number, options?: UseMinimumChildrenWhereOptions): ReactElement[];
222
+ declare function useMinimumChildrenMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, minimumCount: number, options?: ValidationOptions): T[];
223
+ declare function useMinimumChildrenMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, minimumCount: number, options?: ValidationOptions): ReactElement[];
224
+
225
+ /**
226
+ * Returns the optional direct child element whose React element type exactly matches the provided type, or throws when more than one match is found.
227
+ *
228
+ * @param children The React children value to inspect.
229
+ * @param type The element or component type to match against each direct child element.
230
+ * @param options Optional reporting metadata used to derive the thrown validation message.
231
+ * @returns The optional direct child element whose type matches the provided element type, or `null` when no match is found.
232
+ */
233
+ declare function useOptionalChildByType<T extends ElementType>(children: ReactNode, type: T, options?: ValidationOptions): ElementOfType<T> | null;
234
+
235
+ /**
236
+ * Returns the optional direct child element that satisfies the provided predicate, or throws when more than one match is found.
237
+ *
238
+ * @param children The React children value to inspect.
239
+ * @param predicate A predicate that is called with each direct child element to determine whether it matches.
240
+ * @param options Optional reporting metadata used to derive the thrown validation message.
241
+ * @returns The optional direct child element that satisfies the provided predicate, or `null` when no match is found.
242
+ */
243
+ declare function useOptionalChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T | null;
244
+ declare function useOptionalChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement | null;
245
+
246
+ /**
247
+ * Returns the first direct child element whose React element type exactly matches the provided type, or throws when no match is found.
248
+ *
249
+ * @param children The React children value to inspect.
250
+ * @param type The element or component type to match against each direct child element.
251
+ * @param options Optional reporting metadata used to derive the thrown validation message.
252
+ * @returns The first direct child element whose type matches the provided element type.
253
+ */
254
+ declare function useRequiredChildByType<T extends ElementType>(children: ReactNode, type: T, options?: ValidationOptions): ElementOfType<T>;
255
+
256
+ /**
257
+ * Returns the first direct callback child from the provided children value, or throws when none is found.
258
+ *
259
+ * @param children The direct children value to inspect.
260
+ * @param options Optional reporting metadata used to derive the thrown validation message.
261
+ * @returns The first direct callback child from the provided children value.
262
+ */
263
+ declare function useRequiredCallbackChild<TArguments extends unknown[] = [], TResult = ReactNode>(children: CallbackChildren<TArguments, TResult>, options?: ValidationOptions): CallbackChild<TArguments, TResult>;
124
264
 
125
- type UseRequiredChildWhereOptions = {
126
- /**
127
- * An optional consumer-defined trace code that is prefixed to the thrown validation message.
128
- */
129
- traceCode?: string;
130
- /**
131
- * An optional human-readable child name that is included in the thrown validation message.
132
- */
133
- childName?: string;
134
- };
135
265
  /**
136
266
  * Returns the first direct child element that satisfies the provided predicate, or throws when no match is found.
137
267
  *
@@ -140,16 +270,38 @@ type UseRequiredChildWhereOptions = {
140
270
  * @param options Optional reporting metadata used to derive the thrown validation message.
141
271
  * @returns The first direct child element that satisfies the provided predicate.
142
272
  */
143
- declare function useRequiredChildWhere<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: UseRequiredChildWhereOptions): T;
144
- declare function useRequiredChildWhere(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: UseRequiredChildWhereOptions): ReactElement;
273
+ declare function useRequiredChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
274
+ declare function useRequiredChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
275
+
276
+ /**
277
+ * Returns the only direct child element whose React element type exactly matches the provided type, or throws when the match is not unique.
278
+ *
279
+ * @param children The React children value to inspect.
280
+ * @param type The element or component type to match against each direct child element.
281
+ * @param options Optional reporting metadata used to derive the thrown validation message.
282
+ * @returns The only direct child element whose type matches the provided element type.
283
+ */
284
+ declare function useUniqueChildByType<T extends ElementType>(children: ReactNode, type: T, options?: ValidationOptions): ElementOfType<T>;
285
+
286
+ /**
287
+ * Returns the only direct child element that satisfies the provided predicate, or throws when the match is not unique.
288
+ *
289
+ * @param children The React children value to inspect.
290
+ * @param predicate A predicate that is called with each direct child element to determine whether it matches.
291
+ * @param options Optional reporting metadata used to derive the thrown validation message.
292
+ * @returns The only direct child element that satisfies the provided predicate.
293
+ */
294
+ declare function useUniqueChildMatching<T extends ReactElement>(children: ReactNode, predicate: (element: ReactElement) => element is T, options?: ValidationOptions): T;
295
+ declare function useUniqueChildMatching(children: ReactNode, predicate: (element: ReactElement) => boolean, options?: ValidationOptions): ReactElement;
145
296
 
146
297
  /**
147
- * Normalizes a React children value into an array containing only valid direct child elements.
298
+ * Normalizes a React children value into an array containing valid child elements within the configured depth range.
148
299
  *
149
300
  * @param children The React children value to normalize.
150
- * @returns An array of valid React elements from the provided direct children.
301
+ * @param options Optional traversal bounds that control which child depths are included.
302
+ * @returns An array of valid React elements from the provided child depths.
151
303
  */
152
- declare function childrenToElements(children: ReactNode): ReactElement[];
304
+ declare function childrenToElements(children: ReactNode, options?: TraversalOptions): ReactElement[];
153
305
 
154
306
  /**
155
307
  * Determines whether a React element exactly matches the provided element or component type.
@@ -168,4 +320,4 @@ declare function isElementOfType<T extends ElementType>(element: ReactElement, t
168
320
  */
169
321
  declare function isReactElement(node: ReactNode): node is ReactElement;
170
322
 
171
- export { type ElementOfType, type UseExactChildrenWhereOptions, type UseMaximumChildrenWhereOptions, type UseMinimumChildrenWhereOptions, type UseRequiredChildWhereOptions, childrenToElements, isElementOfType, isReactElement, useChildByType, useChildWhere, useChildrenByType, useChildrenWhere, useExactChildrenWhere, useHasChildWhere, useMaximumChildrenWhere, useMinimumChildrenWhere, useRequiredChildWhere };
323
+ export { type CallbackChild, type CallbackChildren, type ChildrenCountBounds, type ElementOfType, type QueryOptions, type TraversalOptions, type ValidationOptions, childrenToElements, isElementOfType, isReactElement, useBoundedChildrenByType, useBoundedChildrenMatching, useCallbackChild, useChildByType, useChildMatching, useChildrenByType, useChildrenMatching, useExactChildrenByType, useExactChildrenMatching, useHasChildMatching, useMaximumChildrenByType, useMaximumChildrenMatching, useMinimumChildrenByType, useMinimumChildrenMatching, useOptionalChildByType, useOptionalChildMatching, useRequiredCallbackChild, useRequiredChildByType, useRequiredChildMatching, useUniqueChildByType, useUniqueChildMatching };