Skip to content

Commit dc1a5e0

Browse files
📝 Add docstrings to ve-compat-entry
Docstrings generation was requested by @black7375. * #219 (comment) The following files were modified: * `packages/babel/src/styled.ts` * `packages/css/src/css/index.ts` * `packages/css/src/rules/index.ts`
1 parent 90cde80 commit dc1a5e0

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

packages/babel/src/styled.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import type { PluginState, ProgramScope } from "@/types.js";
33
import { registerImportMethod } from "@/utils.js";
44

55
/**
6-
* The plugin for transforming styled components
6+
* Babel plugin that transforms `styled` calls from "@mincho-js/react" into runtime calls with tree-shaking annotations.
77
*
8-
* This plugin transforms calls to `styled` from "@mincho-js/react" into runtime
9-
* calls with proper tree-shaking annotations.
8+
* Replaces calls to `styled` with calls to runtime-imported `$$styled` and `rules`, preserving comments and source locations for accurate source maps. Ensures transformed calls are annotated for tree-shaking and updates scope references after transformation.
109
*
11-
* @returns The plugin object
10+
* @returns A Babel plugin object for transforming styled component calls.
1211
*/
1312
export function styledComponentPlugin(): PluginObj<PluginState> {
1413
return {

packages/css/src/css/index.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import { style as vStyle, globalStyle as gStyle } from "@vanilla-extract/css";
1414
import type { GlobalStyleRule } from "@vanilla-extract/css";
1515
import { className, getDebugName } from "../utils.js";
1616

17-
// == Global CSS ===============================================================
17+
/**
18+
* Applies a global CSS rule to the specified selector, supporting nested at-rules.
19+
*
20+
* Transforms the provided rule and applies it globally, including any nested at-rules such as `@media` or `@supports`.
21+
*
22+
* @param selector - The CSS selector to which the global rule will be applied
23+
* @param rule - The global CSS rule object to apply
24+
*/
1825
export function globalCss(selector: string, rule: GlobalCSSRule) {
1926
const transformedStyle = transform({
2027
selectors: {
@@ -100,7 +107,15 @@ function hoistSelectors(input: CSSRule): HoistResult {
100107
return result;
101108
}
102109

103-
// == CSS ======================================================================
110+
/**
111+
* Creates a CSS class from a complex style rule.
112+
*
113+
* Transforms the provided style rule and generates a class name using vanilla-extract.
114+
*
115+
* @param style - The complex CSS rule to transform and apply
116+
* @param debugId - Optional identifier for debugging or naming the class
117+
* @returns The generated CSS class name
118+
*/
104119
export function css(style: ComplexCSSRule, debugId?: string) {
105120
return vStyle(transform(style), debugId);
106121
}
@@ -117,6 +132,16 @@ export function cssVariants<
117132
Key extends keyof Data,
118133
MapData extends (value: Data[Key], key: Key) => ComplexCSSRule
119134
>(data: Data, mapData: MapData, debugId?: string): Record<keyof Data, string>;
135+
/**
136+
* Generates a map of class names for style variants, supporting both direct style maps and data-to-style mapping functions.
137+
*
138+
* Accepts either a map of style objects keyed by variant names, or a data object with a mapping function that produces style rules for each key.
139+
*
140+
* @param styleMapOrData - Either a style map or a data object to generate variants from
141+
* @param mapDataOrDebugId - A mapping function to convert data items to style rules, or a debug identifier if using a style map
142+
* @param debugId - Optional debug identifier for naming the generated classes
143+
* @returns A map of variant keys to generated class names
144+
*/
120145
export function cssVariants<
121146
StyleMap extends Record<string | number, ComplexCSSRule>,
122147
Data extends Record<string | number, unknown>,
@@ -137,6 +162,11 @@ export function cssVariants<
137162
}
138163
}
139164

165+
/**
166+
* Type guard that determines if the provided argument is a mapping function for variant data.
167+
*
168+
* @returns `true` if the argument is a function; otherwise, `false`
169+
*/
140170
function isMapDataFunction<
141171
Data extends Record<string | number, unknown>,
142172
Key extends keyof Data,

packages/css/src/rules/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ function setCSSProperty(
4747
styles[property] = value;
4848
}
4949

50+
/**
51+
* Creates a runtime CSS style function supporting variants, toggle variants, compound variants, and CSS property variables.
52+
*
53+
* @param options - Pattern options defining base styles, variants, toggles, compound variants, default variants, and props
54+
* @param debugId - Optional identifier used for debugging and naming generated classes and variables
55+
* @returns A runtime function that generates class names and CSS variable mappings based on selected variants and props
56+
*/
5057
export function rules<
5158
Variants extends VariantGroups | undefined = undefined,
5259
ToggleVariants extends VariantDefinitions | undefined = undefined,
@@ -185,6 +192,16 @@ export function rules<
185192
);
186193
}
187194

195+
/**
196+
* Processes a prop definition object to generate CSS variables and assign them to specified CSS properties.
197+
*
198+
* For each prop, creates a CSS variable (optionally with a debug name), stores its key in `propVars`, and sets the variable as the value for each target CSS property in `propStyles`. If a base value is provided, uses it as a fallback.
199+
*
200+
* @param props - The prop definitions mapping prop names to their configuration
201+
* @param propVars - Object to store generated CSS variable keys for each prop
202+
* @param propStyles - CSS rule object to which the variables are assigned as property values
203+
* @param debugId - Optional identifier used for debugging and variable naming
204+
*/
188205
function processPropObject<Target extends PropTarget>(
189206
props: PropDefinition<Target>,
190207
propVars: Record<string, PureCSSVarKey>,

0 commit comments

Comments
 (0)