import { Attr } from "@opticss/element-analysis" ; import { ResolvedConfiguration } from "../configuration" ; import { AnyNode , Inheritable } from "./Inheritable" ; import { RulesetContainer } from "./RulesetContainer" ; export { RulesetContainer , Resolution , Ruleset } from "./RulesetContainer" ; const NO_STYLE_ALIASES = new Set < string > ( ) ; /**
 * Abstract class that serves as the base for all Styles. Contains basic
 * properties and abstract methods that extenders must implement.
 */ export abstract class Style < Self extends Style < Self , Root , Parent , Child , Token > , Root extends Inheritable < any , Root , never , AnyNode , any > , Parent extends Inheritable < any , Root , AnyNode | null , Self , any > | null , Child extends Inheritable < any , Root , Self , AnyNode | never , any > | never , Token extends any = string > extends Inheritable < Self , Root , Parent , Child > { /** cache of resolveStyles() */ private _resolvedStyles : Set < Self > | undefined ; /** cache of all style aliases */ private _styleAliases : Set < string > | undefined ; public abstract readonly rulesets : RulesetContainer < any > ; /**
     * The preset selector for this particular class node.
     * This is set when definition files encounter the `block-class` declaration.
     */ public presetCssClass : string | undefined ; /**
     * Save name, parent container, and create the PropertyContainer for this data object.
     */ constructor ( name , parent ) { super ( name , parent ) ; } param config returns public abstract cssClass ( config , reservedClassNames ) ; param scope returns public abstract asSource ( scope ? ) ; /**
     * Return an attribute for analysis using the authored source syntax.
     */ public abstract asSourceAttributes ( ) ; returns cssClasses ( config , reservedClassNames ) { let classes = [ ] ; for ( let style of this . resolveStyles ( ) ) { classes . push ( style . cssClass ( config , reservedClassNames ) ) ; } return classes ; } returns public cssClassesWithAliases ( config , reservedClassNames ) { let classes = new Set < string > ( ) ; for ( let style of this . resolveStyles ( ) ) { classes = new Set ( [ ... classes , style . cssClass ( config , reservedClassNames ) ] ) ; classes = new Set ( [ ... classes , ... style . getStyleAliases ( ) ] ) ; } return classes ; } /**
     * Adds a set of aliases to the to this object
     */ public setStyleAliases ( aliases ) { this . _styleAliases = aliases ; } param selector public setPresetClassName ( selector ) { this . presetCssClass = selector ; } /**
     * Returns the aliases on this object
     */ public getStyleAliases ( ) { return this . _styleAliases || NO_STYLE_ALIASES ; } /**
     * 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 itself is included in the returned result
     * so the resolved value's size is always 1 or greater.
     */ public resolveStyles ( ) { if ( this . _resolvedStyles ) { return new Set ( this . _resolvedStyles ) ; } let inheritedStyles = this . resolveInheritance ( ) ; this . _resolvedStyles = new Set ( inheritedStyles ) ; this . _resolvedStyles . add ( this . asSelf ( ) ) ; return new Set ( this . _resolvedStyles ) ; } param config returns asDebug ( config ) { const classes = [ ... this . cssClasses ( config , new Set ( ) ) ] . join ( "." ) ; const aliases = this . getStyleAliases ( ) ; return `${ this . asSource ( ) }${ classes ? ` (.${ classes }` : "" }${ aliases . size ? `, aliases: .${ [ ... aliases ] . join ( " ." ) }` : "" }${ classes || aliases ? ")" : "" }` ; } }