Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Style<Self, Root, Parent, Child, Token, Token>

Abstract class that serves as the base for all Styles. Contains basic properties and abstract methods that extenders must implement.

Type parameters

Hierarchy

Implements

  • SelectorFactory

Index

Constructors

constructor

Properties

Protected _base

_base: Self | undefined

Protected _children

_children: Map<string, Child> = new Map()

Protected _parent

_parent: Parent | null

Private _resolvedStyles

_resolvedStyles: Set<Self> | undefined

cache of resolveStyles()

Protected _root

_root: Root | Self

Protected _token

_token: Token

Abstract rulesets

rulesets: RulesetContainer<any>

Accessors

Protected ChildConstructor

  • get ChildConstructor(): object | never

base

  • get base(): Self | undefined
  • 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.

    Returns Self | undefined

block

  • get block(): Root
  • 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 Root

    The base node in this tree.

Protected parent

  • get parent(): Parent

Protected root

  • get root(): Root

token

  • get token(): Token

Protected uid

  • get uid(): string

Methods

asDebug

Abstract asSource

  • asSource(scope?: Root | boolean): string
  • Return the source selector this Style was read from.

    Parameters

    • Optional scope: Root | boolean

      Optional scope to resolve this name relative to. If true, return the Block name instead of :scope. If a Block object, return with the local name instead of :scope.

    Returns string

    The source selector.

Abstract asSourceAttributes

  • asSourceAttributes(): Attr[]

Private asStyle

  • asStyle(): Self

Protected children

  • children(): Child[]

Protected childrenHash

  • childrenHash(): ObjectDictionary<Child>

Protected childrenMap

  • childrenMap(): Map<string, Child>

Abstract cssClass

cssClasses

Protected ensureChild

  • ensureChild(token: Child["token"], key?: undefined | string): 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.

    Parameters

    • token: Child["token"]
    • Optional key: undefined | string

      string The key at which this child object should be (optional)

    Returns Child

    The child node.

Protected getChild

  • getChild(token: Child["token"]): Child | null

getParsedSelectors

  • getParsedSelectors(rule: Rule): ParsedSelector[]
  • 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.

    Parameters

    • rule: Rule

      PostCSS Rule

    Returns ParsedSelector[]

    ParsedSelector array

impliedStyles

  • impliedStyles(): Set<Self> | undefined

Protected newChild

  • newChild(token: Child["token"]): Child

Protected resolveChild

  • resolveChild(token: Child["token"]): Child | null

Protected resolveChildren

  • resolveChildren(): Child[]

Protected resolveChildrenHash

  • resolveChildrenHash(): ObjectDictionary<Child>

Protected resolveChildrenMap

  • resolveChildrenMap(): Map<string, Child>

resolveInheritance

  • resolveInheritance(): Self[]
  • 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 Self[]

    The array of nodes this node inherits from.

resolveStyles

  • resolveStyles(): Set<Self>
  • Return all Block Objects that are implied by this object. This takes inheritance, attr/class correlations, and any other declared links between styles into account.

    This block object is included in the returned result so the resolved value's size is always 1 or greater.

    Returns Set<Self>

Protected setChild

  • setChild(token: Child["token"], value: Child): Child

Protected tokenToUid

  • tokenToUid(token: Token): string
  • 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.

    Parameters

    • token: Token

    Returns string

    A unique string that represents this token.

Generated using TypeDoc