/* * Copyright (c) 2023 Discover Financial Services * Licensed under Apache-2.0 License. See License.txt in the project root for license information */ import { Node } from "../common/node"; import { CSSGenerator, CSSVarGroup } from "./cssGenerator"; import { JSONGenerator } from "./jsonGenerator"; import { IDesignSystem, VarListener, INode } from "../interfaces"; /** * Code generation for theme builder. * @category Generators */ export class Code extends Node { /** The CSS code generator */ public cssGenerator: CSSGenerator; public jsonGenerator: JSONGenerator; constructor(ds: IDesignSystem) { super("code", ds); this.cssGenerator = new CSSGenerator(ds); this.jsonGenerator = new JSONGenerator(ds); this.addDependency(ds.atoms); } public generate() { this.cssGenerator.generate(); } /** * Get all CSS variables for this design system. * @returns All CSS variables for this design system. */ public getCSSVars(): {[name: string]: string} { return this.cssGenerator.getVars(); } /** * Set a CSS variable listener which is called each time a CSS variable value is changed. * @param name The listener name. * @param listener The listener callback. */ public setCSSVarListener(name: string, listener?: VarListener) { this.cssGenerator.setCSSVarListener(name, listener); } /** * Get a group of CSS variables associated with a particular node (i.e. atom, molecule, or organism). * @param node The node for which we are getting the group of variables. * @returns The variable group */ public getCSSVarGroup(node: INode): CSSVarGroup { return this.cssGenerator.getVarGroup(node.key); } /** * Get all keys of all CSS variable groups. * @returns All keys associated with all CSS variable groups. */ public getCSSVarGroupKeys(): string[] { return this.cssGenerator.getVarGroupKeys(); } /** * Get the base JSON code generated by the theme builder for the default theme. * @returns The JSON object. */ public getJSONBase(): Object { return this.jsonGenerator.getJSONBase(); } /** * Get the lightmode JSON code generated by the theme builder for the default theme. * @returns The JSON object. */ public getJSONLM(): Object { return this.jsonGenerator.getJSONLM(); } /** * Get the darkmode JSON code generated by the theme builder for the default theme. * @returns The JSON object. */ public getJSONDM(): Object { return this.jsonGenerator.getJSONDM(); } /** * Get the JSON code generated by the theme builder for the default theme for light or dark mode. * @returns The JSON object. */ public getJSON(lm: boolean): Object { return this.jsonGenerator.getJSON(lm); } }