Skip to content

Commit 10a0dac

Browse files
committed
Refactor: code order
1 parent 6f7b980 commit 10a0dac

File tree

2 files changed

+66
-64
lines changed

2 files changed

+66
-64
lines changed

packages/css/src/css/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,20 @@ function hoistSelectors(input: CSSRule): HoistResult {
102102
}
103103

104104
// == CSS ======================================================================
105-
export function cssImpl(style: ComplexCSSRule, debugId?: string) {
106-
return vStyle(transform(style), debugId);
107-
}
105+
export const css = Object.assign(cssImpl, {
106+
raw: cssRaw,
107+
multiple: cssMultiple,
108+
with: cssWith
109+
});
108110

109111
function cssRaw(style: ComplexCSSRule) {
110112
return style;
111113
}
112114

115+
export function cssImpl(style: ComplexCSSRule, debugId?: string) {
116+
return vStyle(transform(style), debugId);
117+
}
118+
113119
function cssWith<const T extends CSSRule>(
114120
callback?: (style: CSSRuleWith<T>) => ComplexCSSRule
115121
) {
@@ -159,12 +165,6 @@ function cssWith<const T extends CSSRule>(
159165
});
160166
}
161167

162-
export const css = Object.assign(cssImpl, {
163-
raw: cssRaw,
164-
multiple: cssMultiple,
165-
with: cssWith
166-
});
167-
168168
// == CSS Multiple =============================================================
169169
// TODO: Need to optimize
170170
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#smart_self-overwriting_lazy_getters

packages/css/src/rules/index.ts

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5156
export 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 ==========================================================
190237
type 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

Comments
 (0)