/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { ElementTag } from "#common/ElementTag.js"; import type { Model } from "./Model.js"; import type { ModelTreePosition } from "./ModelTreePosition.js"; /** * Children of a model. This is a {@link Model} array with some specialization for model-specific operations. * * A model is listed at most once and its parent is the model that lists it. Inserting a model that is already a child * moves it, so array algorithms applied through `Array.prototype` methods that assign indices one by one do not keep * the order; use the methods of this interface. * * @template T the type of model that owns the children */ export interface Children extends Array { /** * Add children. * * Operates like a standard array push but we adjust the type to allow insertion of elements as well as models. A * model that is already a child moves to the end; listing a model twice in one call throws. */ push(...children: Model.TaggedDefinition[]): number; /** * Array splice. * * Allows splicing in elements or models. A model that is already a child moves to the insertion point; listing a * model twice in one call throws. */ splice(index: number, deleteCount?: number, ...toAdd: Model.TaggedDefinition[]): T[]; /** * Add children at the start. * * Operates like a standard array unshift but allows insertion of elements as well as models. A model that is * already a child moves to the start; listing a model twice in one call throws. */ unshift(...children: Model.TaggedDefinition[]): number; /** * Access a model of specific type by ID or name. This is an optimized operation that uses internal index lookup. */ get(type: Model.Type, idOrName: number | string): C | undefined; /** * Access all models of a specific type in list order, optionally filtered to a specific ID or name. Even if filtered there * may be multiple return values if there are different variants of the element defined. */ all(type: Model.Type, idOrName?: number | string): C[]; /** * Access a model using a {@link Children.Selector}. This is an optimized primitive used by various tree traversal * algorithms. */ select(selector: Children.Selector, allowedTags?: Children.TagSelector, except?: Set): Model.ChildOf | undefined; /** * Like {@link select} but retrieves all models for which selection applies. */ selectAll(selector: Children.Selector, allowedTags?: Children.TagSelector, except?: Set): Model.ChildOf[]; } export interface InternalChildren extends Children { /** * Models invoke this when their ID or name changes so we can update internal bookkeeping. */ keysChanged(): void; /** * Freeze the set of children. */ freeze(): void; /** * Ensure roots of children are synced with parent. */ rerootAll(isOwned: boolean): void; /** * Changes on every mutation of the list or of a child's ID or name. Unique across all lists so a model that * replaces its list never reports a generation a cache saw for the old one. */ readonly generation: number; } /** * Invoked by {@link Model} to instantiate a new child array. */ export declare function Children(initial: Children.InputIterable, position: ModelTreePosition): InternalChildren; export declare namespace Children { var installModelConstructor: (constructor: typeof Model) => typeof Model; } export declare namespace Children { /** * A model selector designates models for retrieval. It may be a model name, number, or a predicate function. */ type Selector = string | number | ((child: Model) => boolean); /** * A tag selector filters models based on type. It may be a tag name, a list of tag names, or "*" or undefined to * disable type filtering. */ type TagSelector = undefined | ElementTag | "*" | ElementTag[]; /** * An iterable of input definitions. */ type InputIterable = Iterable>; } //# sourceMappingURL=Children.d.ts.map