Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>

This class is used to track the styles and dynamic expressions on an element and produce a runtime class expression in conjunction with a style mapping.

This class tracks dependencies between attributes and classes and the runtime expression causes attributes to be removed if the parent class is not present at runtime.

With some syntaxes, if an element has different classes on it at runtime from the same block, the attributes in use become ambiguous. To manage this, the caller must ensure that the attribute names used exist for all possible classes and produce an error if not. Then add the attributes for each possible class with multiple calls to add(Static|Dynamic)(Attribute|Attribute-Group). If the AST can't handle multiple references pointing at the expression node, the caller must clone it -- This won't result in multiple expression invocations unless multiple classes from the same block are applied at the same time -- which would be illegal.

Type parameters

  • BooleanExpression

  • StringExpression

  • TernaryExpression

Hierarchy

  • ElementAnalysis

Index

Constructors

constructor

  • new ElementAnalysis(location: SourceLocation, tagName?: undefined | string, id?: undefined | string): ElementAnalysis

Properties

Private _sealed

_sealed: boolean

Private addedStyles

addedStyles: Array<DependentAttr | ConditionalDependentAttr<BooleanExpression> | ConditionalDependentAttrGroup<StringExpression> | StaticClass | DynamicClasses<TernaryExpression>>

Private allClasses

allClasses: MultiMap<Block, BlockClass>

All the classes on this element, by block.

Private allStaticStyles

allStaticStyles: Set<Style>

All the static styles including styles implied by the explicitly specified styles.

dynamicAttributes

dynamicAttributes: Array<DynamicAttrs<BooleanExpression, StringExpression>>

attributes set dynamically or depending on a dynamic class

Private dynamicClassExpressions

dynamicClassExpressions: Map<BlockClass, DynamicClasses<TernaryExpression>>

classes declared explicitly and found in at least one dynamic class expression.

dynamicClasses

dynamicClasses: Array<DynamicClasses<TernaryExpression>>

blocks/classes set conditionally

id

id: string | undefined

an opaque id assigned from the analyzer for later retrieval

sourceLocation

sourceLocation: SourceLocation

where the element starts and ends

static

static: Set<Style>

static styles explicitly declared on this element

tagName

tagName: string | undefined

The name of the tag these styles are applied -- if known.

Static autoGenerateId

autoGenerateId: symbol = Symbol("AutoGenerateID")

Accessors

sealed

  • get sealed(): boolean

Methods

Private _addDynamicAttr

Private _addDynamicClasses

  • _addDynamicClasses(dynClasses: DynamicClasses<TernaryExpression>): void

Private _addDynamicGroup

Private _addStaticAttr

Private _addStaticClass

addDynamicAttr

addDynamicClasses

  • addDynamicClasses(dynClasses: DynamicClasses<TernaryExpression>): void
  • Adds BlockClasses that are set based on a conditional. This is modeled as a ternary (if/else) expression.

    Nested ternaries are not supported at this time.

    Parameters

    Returns void

addDynamicGroup

  • addDynamicGroup(container: BlockClass, group: Attribute, stringExpression: StringExpression, disallowFalsy?: boolean): void
  • Adds a group of AttrValues that are toggled between at runtime.

    Parameters

    • container: BlockClass

      The class or block root to which the AttrValues belong.

    • group: Attribute

      The AttrValues that are to be chosen from. All must be children of the same group -- they can be from different blocks if they inherit.

    • stringExpression: StringExpression
    • Default value disallowFalsy: boolean = false

      Whether a missing value is expected or should be a runtime error.

    Returns void

addStaticAttr

addStaticClass

assertSealed

  • assertSealed(isSealed?: boolean): void

Private assertValidContainer

attributesFound

  • attributesFound(dynamic?: undefined | true | false): IterableIterator<AttrValue>
  • Iterate over all static and dynamic Attributes explicitly set on this element. The analysis must be sealed to call this method.

    Parameters

    • Optional dynamic: undefined | true | false
      • undefined - return all attributes,
      • true - return only dynamic attributes
      • false - return only static attributes

    Returns IterableIterator<AttrValue>

classesForBlock

classesFound

  • classesFound(dynamic?: undefined | true | false): IterableIterator<BlockClass>
  • iterate over all static and dynamic blocks and classes explicitly set on this element.

    the analysis must be sealed to call this method.

    Parameters

    • Optional dynamic: undefined | true | false
      • undefined - return all classes,
      • true - return only dynamic classes
      • false - return only static classes

    Returns IterableIterator<BlockClass>

countAllStaticStyles

  • countAllStaticStyles(): number

forOptimizer

  • Compute an OptiCSS element description and a map of class names back to the block objects for use in re-writing.

    This mapping of classname to block object is stable and the keys can be assumed to be unique per Style across all blocks -- so these maps can be merged safely.

    Parameters

    Returns [Element, Map<string, Style>]

getAllStaticStyles

  • getAllStaticStyles(): IterableIterator<Style>

hasClass

  • Checks if the given class or block is set on this element of if it is implied by one of the other styles on this element.

    This can be called before or after being sealed.

    Parameters

    Returns boolean

hasStyles

  • hasStyles(): boolean

Private mapBlocksForClass

  • this maps the class and all the classes that the explicit class implies to all the blocks those classes belong to via inheritance.

    These classes become valid containers for AttrValues even if they are not explicitly set on the element.

    Parameters

    Returns void

Private prepareCondition

  • prepareCondition(classes: DynamicClasses<TernaryExpression>, condition: "whenTrue" | "whenFalse"): void

Private prepareForAttributes

  • prepareForAttributes(): void
  • Because of the possibility for classes to inherit and imply other classes, we need to convert any dynamic class that is static because of another static class to be static This ensures that otherwise static AttrValues won't get hoisted into dynamic expressions because of a class dependency.

    Returns void

seal

  • seal(): void

serialize

Generated using TypeDoc