/** * The `Inheritable` module delivers the core data structure for making type safe, * single-typed-children, tree nodes. * * This abstract class, in order to support tree nodes of *any* kind, makes creative * use of the `any` type in a few places – but don't be fooled! These typing holes * are *required* to be plugged by any by any implementing class by virtue of the type * generics they are forced to provide when extending. By the time this abstract class * is exposed to the outside world, all typing holes have been plugged and we are left * with a fully typed tree structure. */ import { ObjectDictionary } from "@opticss/util"; import { ParsedSelector, SelectorFactory, postcss } from "opticss"; export declare type AnyNode = Inheritable; export declare abstract class Inheritable, Root extends Inheritable, Parent extends Inheritable | null, Child extends Inheritable | never, Token extends any = string> implements SelectorFactory { protected abstract get ChildConstructor(): { new (token: any, parent: Self): Child; } | never; private readonly parsedRuleSelectors; protected _token: Token; protected _base: Self | undefined; protected _root: Root; protected _parent: Parent | null; protected _children: Map; /** * Inheritable constructor * @param name Name for this Inheritable instance. * @param parent The parent Inheritable of this node. */ constructor(name: Token, parent?: Parent); /** * The `tokenToUid` method would *ideally* be a static method, but * Typescript doesn't expose class generics to static methods, so it * needs to be a protected method. * In order to map children to generic `Tokens`, we need a way to map * any given `Token` shape to a UID. By default, we stringify the token * passed to us. If more complex behavior is required, this method can * be overridden. * @returns A unique string that represents this token. */ protected tokenToUid(token: Token): string; /** * @param token The new child object's `Token` identifier. * @returns The new child object created from `token` */ protected newChild(token: Child["token"]): Child; /** * @param token A child object's `Token` identifier. * @returns The UID of this child's `Token`. */ private childToUid; /** @returns The token object used to create this node. */ get token(): Token; /** @returns The unique name of this node. */ protected get uid(): string; /** @returns The parent node in this tree. */ protected get parent(): Parent; /** @returns The root node in this tree. */ protected get root(): Root; /** @returns A boolean indicating if this is the root node in the Inheritable tree or not. */ private get isRootNode(); /** * Get the style that this style inherits from, if any. * * This walks down the declared styles of the parent's inheritance chain, * and attempts to find a matching directly declared style on each. * * The result is cached because it never changes and is decidable as soon * as the style is instantiated. */ get base(): Self | undefined; /** * The `block` property is an alias for `root`. This isn't the dryest place to put * this line, but every extension re-declared this interface itself and I wanted it * in one place. * @returns The base node in this tree. */ get block(): Root; /** * Compute all block objects that are implied by this block object through * inheritance. Does not include this object or the styles it implies through * other relationships to this object. * * The values are returned in inheritance order, with the first value * returned (if any) having no base, and the the last value returned (if any) * being the base of this object. * * If nothing is inherited, this returns an empty array. * @returns The array of nodes this node inherits from. */ resolveInheritance(): Self[]; /** * Resolves the child with the given name from this node's inheritance * chain. Returns null if the child is not found. * @param name The name of the child to resolve. * @returns The child node, or `null` */ protected resolveChild(token: Child["token"]): Child | null; /** * Retrieve a child node from this object at `key`. * @param key string The key to fetch the child object from. * @returns The child node. */ protected getChild(token: Child["token"]): Child | null; /** * Set a child node on this object at `key`. * @param key string The key to set the child object to. * @returns The child node. */ protected setChild(token: Child["token"], value: Child): Child; /** * Ensure a child node exists on this object at `key`. If it does not, create it. * If `key` is not provided, use the child name as the key. * @param name string The name of this object to ensure. * @param key string The key at which this child object should be (optional) * @returns The child node. */ protected ensureChild(token: Child["token"], key?: string): Child; /** * Returns an array of all children nodes in the order they were added for Self. * @returns The children array. */ protected children(): Child[]; /** * Returns an array of all children nodes in the order they were added for * self and all inherited children. * @returns The children array. */ protected resolveChildren(): Child[]; /** * Returns a map of all children nodes at the keys they are stored.. * @returns The children map. */ protected childrenMap(): Map; /** * Returns a map of all children nodes at the keys they are stored.. * @returns The children map. */ protected resolveChildrenMap(): Map; /** * Returns a hash of all children nodes at the keys they are stored.. * TODO: Cache this maybe? Convert entire model to only use hash?... * @returns The children hash. */ protected childrenHash(): ObjectDictionary; /** * Returns a map of all children nodes at the keys they are stored.. * @returns The children map. */ protected resolveChildrenHash(): ObjectDictionary; /** * Every Block tree maintains its own local cache of parsed selectors. * From any sub-inheritable, or from the root inheritable itself, * given a PostCSS Rule, ensure it is present in the root Block's parsed rule * selectors cache, and return the ParsedSelector array. * @param rule PostCSS Rule * @return ParsedSelector array */ getParsedSelectors(rule: postcss.Rule): ParsedSelector[]; /** * TypeScript can't figure out that `this` is the `Self` so this private * method casts it in a few places where it's needed. */ protected asSelf(): Self; /** * TypeScript can't figure out that `this` is the `Self` so this private * method casts it in a few places where it's needed. */ protected asRoot(): Root; } //# sourceMappingURL=Inheritable.d.ts.map