@@ -9,6 +9,7 @@ import { is } from "tsafe/is";
99import { parseColorOptionName , getThemePath as getColorOptionThemePath } from "./colorOptions" ;
1010import * as crypto from "crypto" ;
1111import { multiReplace } from "../../tools/multiReplace" ;
12+ import memoize from "memoizee" ;
1213
1314const contexts = [ "background" , "text" , "border" , "artwork" ] as const ;
1415
@@ -159,11 +160,12 @@ export function getThemePath(parsedColorDecisionName: ParsedColorDecisionName) {
159160}
160161
161162export type ColorDecision = {
163+ colorDecisionName : `--${string } `;
162164 themePath : string [ ] ;
163165 optionThemePath : string [ ] ;
164166} ;
165167
166- export function parseColorDecision ( rawCssCode : string ) : ColorDecision [ ] {
168+ export const parseColorDecision = memoize ( ( rawCssCode : string ) : ColorDecision [ ] => {
167169 const { parseColorDecisionName } = createParseColorDecisionName ( rawCssCode ) ;
168170
169171 const parsedCss = parseCss ( rawCssCode ) ;
@@ -179,13 +181,13 @@ export function parseColorDecision(rawCssCode: string): ColorDecision[] {
179181
180182 assert ( node !== undefined ) ;
181183
182- const { declarations } = node as any ;
184+ const { declarations } = node as { declarations : { property : string ; value : string } [ ] } ;
183185
184186 return { declarations } ;
185187 } ) ( ) ;
186188
187189 return declarations
188- . map ( ( { property, value } : { property : string ; value : string } ) => {
190+ . map ( ( { property, value } ) => {
189191 const mathArray = value . match ( / ^ v a r \( ( - - [ ^ ) ] + ) \) $ / ) ;
190192
191193 if ( mathArray === null ) {
@@ -203,12 +205,13 @@ export function parseColorDecision(rawCssCode: string): ColorDecision[] {
203205 assert ( is < `--${string } `> ( property ) ) ;
204206
205207 return {
208+ "colorDecisionName" : property ,
206209 "themePath" : getThemePath ( parseColorDecisionName ( property ) ) ,
207210 "optionThemePath" : getColorOptionThemePath ( parseColorOptionName ( colorOptionName ) )
208211 } ;
209212 } )
210213 . filter ( exclude ( undefined ) ) ;
211- }
214+ } ) ;
212215
213216export function generateGetColorDecisionsTsCode ( rawCssCode : string ) : string {
214217 const obj : any = { } ;
0 commit comments