@@ -36,18 +36,23 @@ import {
3636 transformVariantSelection
3737} from "./utils.js" ;
3838
39- const mergeObject = deepmerge ( ) ;
39+ // == Rules ====================================================================
40+ export const rules = Object . assign ( rulesImpl , {
41+ multiple : rulesMultiple ,
42+ raw : rulesRaw
43+ } ) ;
4044
41- // Helper function to safely set properties on a CSSRule
42- function setCSSProperty (
43- styles : CSSRule ,
44- property : string ,
45- value : string
46- ) : void {
47- // @ts -expect-error: Intentionally bypassing type checking for dynamic property assignment
48- styles [ property ] = value ;
45+ function rulesRaw <
46+ Variants extends VariantGroups | undefined = undefined ,
47+ ToggleVariants extends VariantDefinitions | undefined = undefined ,
48+ Props extends ComplexPropDefinitions < PropTarget > | undefined = undefined
49+ > ( options : PatternOptions < Variants , ToggleVariants , Props > ) {
50+ return options ;
4951}
5052
53+ // == Rules Impl ===============================================================
54+ const mergeObject = deepmerge ( ) ;
55+
5156export function rulesImpl <
5257 Variants extends VariantGroups | undefined = undefined ,
5358 ToggleVariants extends VariantDefinitions | undefined = undefined ,
@@ -186,7 +191,49 @@ export function rulesImpl<
186191 ) ;
187192}
188193
189- // Improved type-safe transformations that preserve pattern structure
194+ // Helper function to safely set properties on a CSSRule
195+ function setCSSProperty (
196+ styles : CSSRule ,
197+ property : string ,
198+ value : string
199+ ) : void {
200+ // @ts -expect-error: Intentionally bypassing type checking for dynamic property assignment
201+ styles [ property ] = value ;
202+ }
203+
204+ function processPropObject < Target extends PropTarget > (
205+ props : PropDefinition < Target > ,
206+ propVars : Record < string , PureCSSVarKey > ,
207+ propStyles : CSSRule ,
208+ debugId ?: string
209+ ) {
210+ Object . entries ( props ) . forEach ( ( [ propName , propValue ] ) => {
211+ const debugName = getDebugName ( debugId , propName ) ;
212+ const propVar = createVar ( debugName ) ;
213+ propVars [ propName ] = getVarName ( propVar ) ;
214+
215+ const isBaseValue = propValue ?. base !== undefined ;
216+ propValue ?. targets . forEach ( ( target ) => {
217+ setCSSProperty (
218+ propStyles ,
219+ target ,
220+ isBaseValue ? fallbackVar ( propVar , `${ propValue . base } ` ) : propVar
221+ ) ;
222+ } ) ;
223+ } ) ;
224+ }
225+
226+ function processCompoundStyle (
227+ style : RecipeStyleRule ,
228+ debugId : string | undefined ,
229+ index : number
230+ ) : string {
231+ return typeof style === "string"
232+ ? style
233+ : css ( style , getDebugName ( debugId , `compound_${ index } ` ) ) ;
234+ }
235+
236+ // == Rules Multiple ==========================================================
190237type RuntimeFnFromPatternOptions < Options > =
191238 Options extends PatternOptions <
192239 infer Variants extends VariantGroups | undefined ,
@@ -343,51 +390,6 @@ function processMultipleRules<
343390 return patternsMap ;
344391}
345392
346- function rulesRaw <
347- Variants extends VariantGroups | undefined = undefined ,
348- ToggleVariants extends VariantDefinitions | undefined = undefined ,
349- Props extends ComplexPropDefinitions < PropTarget > | undefined = undefined
350- > ( options : PatternOptions < Variants , ToggleVariants , Props > ) {
351- return options ;
352- }
353-
354- export const rules = Object . assign ( rulesImpl , {
355- multiple : rulesMultiple ,
356- raw : rulesRaw
357- } ) ;
358-
359- function processPropObject < Target extends PropTarget > (
360- props : PropDefinition < Target > ,
361- propVars : Record < string , PureCSSVarKey > ,
362- propStyles : CSSRule ,
363- debugId ?: string
364- ) {
365- Object . entries ( props ) . forEach ( ( [ propName , propValue ] ) => {
366- const debugName = getDebugName ( debugId , propName ) ;
367- const propVar = createVar ( debugName ) ;
368- propVars [ propName ] = getVarName ( propVar ) ;
369-
370- const isBaseValue = propValue ?. base !== undefined ;
371- propValue ?. targets . forEach ( ( target ) => {
372- setCSSProperty (
373- propStyles ,
374- target ,
375- isBaseValue ? fallbackVar ( propVar , `${ propValue . base } ` ) : propVar
376- ) ;
377- } ) ;
378- } ) ;
379- }
380-
381- function processCompoundStyle (
382- style : RecipeStyleRule ,
383- debugId : string | undefined ,
384- index : number
385- ) : string {
386- return typeof style === "string"
387- ? style
388- : css ( style , getDebugName ( debugId , `compound_${ index } ` ) ) ;
389- }
390-
391393// == Tests ====================================================================
392394// Ignore errors when compiling to CommonJS.
393395// eslint-disable-next-line @typescript-eslint/ban-ts-comment
0 commit comments