import { Element, SourceLocation } from "@opticss/element-analysis"; import { ObjectDictionary } from "@opticss/util"; import { AttrValue, Attribute, Block, BlockClass, Style } from "../BlockTree"; import { ResolvedConfiguration } from "../configuration"; export interface HasAttrValue { value: Set; } export declare function hasAttrValue(o: object): o is HasAttrValue | SerializedHasAttrValue; export interface HasGroup { group: ObjectDictionary; } export declare function isAttrGroup(o: object): o is HasGroup; /** * A boolean condition. */ export interface Conditional { condition: BooleanExpression; } export declare function isConditional(o: object): o is Conditional; /** * A string expression used to switch between attribute values. * When falsy is allowed, it's possible to disable the attribute. */ export interface Switch { stringExpression: StringExpression; /** whether the attribute can be disabled. */ disallowFalsy?: boolean; } export declare function isSwitch(o: object): o is Switch; /** * When the style container is dynamic but the style itself is not. */ export interface Dependency { container: Container; } export declare function hasDependency(o: object): o is Dependency; /** * the main branch of the style-if helper and the else branch of the * style-unless helper */ export interface TrueCondition { whenTrue: Array; } export declare function isTrueCondition(o: object): o is TrueCondition; /** * the else branch of the style-if helper and the main branch of the * style-unless helper */ export interface FalseCondition { whenFalse: Array; } export declare function isFalseCondition(o: object): o is FalseCondition; export interface StaticClass { klass: BlockClass; } export declare function isStaticClass(o: object): o is StaticClass | SerializedStaticClass; /** An attribute value that is conditionally set */ export declare type ConditionalAttr = Conditional & HasAttrValue; /** An attribute value that is only set when its dynamic class is set */ export declare type DependentAttr = Dependency & HasAttrValue; /** An attribute value that is only set when its condition is true and its dynamic class is set */ export declare type ConditionalDependentAttr = Conditional & Dependency & HasAttrValue; /** An attribute value that is dynamic for any reason */ export declare type DynamicAttr = ConditionalAttr | DependentAttr | ConditionalDependentAttr; /** An attribute group where one is set conditionally */ export declare type ConditionalAttrGroup = Switch & HasGroup & HasAttrValue; /** An attribute group that are only set when its dynamic class is set and where one (or none) is selected at runtime. */ export declare type ConditionalDependentAttrGroup = Switch & Dependency & HasGroup & HasAttrValue; /** An attribute group that are dynamic for any reason */ export declare type DynamicAttrGroup = ConditionalAttrGroup | ConditionalDependentAttrGroup; /** Any type of dynamic attribute or group of attributes. */ export declare type DynamicAttrs = DynamicAttr | DynamicAttrGroup; /** a ternary expression where different classes can be set when true or false */ export declare type DynamicClasses = (Conditional & TrueCondition) | (Conditional & FalseCondition) | (Conditional & TrueCondition & FalseCondition); export interface SerializedHasAttrValue { value: number[]; } export interface SerializedStaticClass { klass: number; } export declare type SerializedConditionalAttr = Conditional & SerializedHasAttrValue; export declare type SerializedDependentAttr = Dependency & SerializedHasAttrValue; export declare type SerializedConditionalDependentAttr = Conditional & Dependency & SerializedHasAttrValue; export declare type SerializedDynamicAttr = SerializedConditionalAttr | SerializedDependentAttr | SerializedConditionalDependentAttr; export declare type SerializedConditionalAttrGroup = Switch & HasGroup; export declare type SerializedDependentAttrGroup = Dependency & HasGroup; export declare type SerializedConditionalDependentAttrGroup = Switch & Dependency & HasGroup; export declare type SerializedDynamicAttrGroup = SerializedConditionalAttrGroup | SerializedDependentAttrGroup | SerializedConditionalDependentAttrGroup; export declare type SerializedDynamicContainer = Conditional & (TrueCondition | FalseCondition | (TrueCondition & FalseCondition)); export declare type SerializedDynamicAttrs = SerializedDynamicAttr | SerializedDynamicAttrGroup; export declare type SerializedDynamicClasses = (Conditional & TrueCondition) | (Conditional & FalseCondition) | (Conditional & TrueCondition & FalseCondition); export interface SerializedElementAnalysis { id?: string | undefined; tagName?: string | undefined; sourceLocation?: SourceLocation; staticStyles: Array; dynamicClasses: Array; dynamicAttributes: Array; } /** * This serialization is just the styles that were set explicitly * by the source code. */ export interface SerializedElementSourceAnalysis { id?: string | undefined; tagName?: string | undefined; sourceLocation?: SourceLocation; analyzedStyles: Array; } declare type AnalyzedStyle = DependentAttr | ConditionalDependentAttr | ConditionalDependentAttrGroup | StaticClass | DynamicClasses; declare type SerializedAnalyzedStyle = SerializedDependentAttr | SerializedConditionalDependentAttr | SerializedConditionalDependentAttrGroup | SerializedStaticClass | SerializedDynamicClasses; /** * 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. */ export declare class ElementAnalysis { static autoGenerateId: symbol; /** an opaque id assigned from the analyzer for later retrieval */ id: string | undefined; /** The name of the tag these styles are applied -- if known. */ tagName: string | undefined; /** where the element starts and ends */ sourceLocation: SourceLocation; /** static styles explicitly declared on this element */ static: Set