Skip to content

Commit 66479c0

Browse files
zhongyrjianliang00
authored andcommitted
[Feature][CSS] Add comment to the generated css type according to description.
Add description in comment of the index.d.ts for each property. Properties with empty desc will be logged out to terminal. issue: f-6748648523
1 parent f0bab5c commit 66479c0

File tree

12 files changed

+182
-15
lines changed

12 files changed

+182
-15
lines changed

tools/css_generator/css_defines/1-top.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "1.0",
77
"author": "wangzhixuan",
88
"consumption_status": "layout-only",
9-
"desc": "top offset",
9+
"desc": "The `top` CSS property participates in specifying the vertical position.",
1010
"compat_data": {
1111
"top": {
1212
"__compat": {

tools/css_generator/css_defines/120-overflow-x.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"hidden",
1111
"visible"
1212
],
13-
"desc": "",
13+
"desc": "The `overflow-x` property specifies whether to clip the content when it overflows at the left and right edges.",
1414
"is_shorthand": false,
1515
"formal_syntax": "<overflow-block>"
1616
}

tools/css_generator/css_defines/121-overflow-y.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"hidden",
1111
"visible"
1212
],
13-
"desc": "",
13+
"desc": "The `overflow-y` property specifies whether to clip the content when it overflows at the top and bottom edges.",
1414
"is_shorthand": false,
1515
"formal_syntax": "<overflow-block>"
1616
}

tools/css_generator/css_defines/2-left.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "1.0",
77
"author": "wangzhixuan",
88
"consumption_status": "layout-only",
9-
"desc": "left offset",
9+
"desc": "The `left` CSS property participates in specifying the horizontal position of a positioned element.",
1010
"compat_data": {
1111
"left": {
1212
"__compat": {

tools/css_generator/css_defines/25-overflow.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"hidden",
1111
"visible"
1212
],
13-
"desc": "",
13+
"desc": "The `overflow` property specifies whether to clip the content when the content of an element is too big.",
1414
"is_shorthand": true,
1515
"formal_syntax": "<overflow-block>{1,2}"
1616
}

tools/css_generator/css_defines/3-right.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "1.0",
77
"author": "wangzhixuan",
88
"consumption_status": "layout-only",
9-
"desc": "right offset",
9+
"desc": "The `right` CSS property participates in specifying the horizontal position of a positioned element.",
1010
"compat_data": {
1111
"right": {
1212
"__compat": {

tools/css_generator/css_defines/4-bottom.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "1.0",
77
"author": "wangzhixuan",
88
"consumption_status": "layout-only",
9-
"desc": "bottom offset",
9+
"desc": "The `bottom` CSS property participates in specifying the vertical position.",
1010
"compat_data": {
1111
"bottom": {
1212
"__compat": {

tools/css_generator/css_defines/98-background-image.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"version": "1.0",
77
"author": "tangruiwen",
88
"consumption_status": "skip",
9-
"desc": "",
10-
"is_shorthand": false
9+
"desc": "The `background-image` CSS property sets one or more background images on an element.",
10+
"is_shorthand": false,
11+
"formal_syntax": "<bg-image>#"
1112
}

tools/css_generator/generate_types.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def resolve_type(type_str, values_map, resolved_cache):
3333

3434
# Handle direct primitives in the syntax string like '<length> | 0'
3535
if type_str not in values_map:
36+
# It's a complex syntax like `url(<string>)` or `linear-gradient(...)`
37+
if "(" in type_str:
38+
return "(string & {})"
39+
3640
if type_str == "string":
3741
return "(string & {})"
3842

@@ -49,6 +53,12 @@ def resolve_type(type_str, values_map, resolved_cache):
4953
return type_str
5054

5155
definition = values_map[type_str]
56+
57+
# If the definition itself is a complex function, treat as string
58+
if "(" in definition:
59+
resolved_cache[type_str] = "(string & {})"
60+
return "(string & {})"
61+
5262
parts = [part.strip() for part in definition.split("|")]
5363

5464
resolved_parts = [resolve_type(part, values_map, resolved_cache) for part in parts]
@@ -78,6 +88,7 @@ def main():
7888

7989
processed_properties = {}
8090
print(f"Processing property definitions from: {CSS_DEFINES_PATH}")
91+
properties_with_empty_desc = []
8192

8293
for filename in sorted(os.listdir(CSS_DEFINES_PATH)):
8394
if not filename.endswith(".json"):
@@ -96,8 +107,13 @@ def main():
96107
print(f"Warning: 'name' not found in {filename}, skipping.")
97108
continue
98109

110+
prop_desc = prop_define.get("desc", "").strip()
111+
if not prop_desc:
112+
properties_with_empty_desc.append(prop_name)
113+
99114
print(f"- Processing {prop_name} from {filename}")
100115
prop_syntax = prop_define.get("formal_syntax")
116+
original_syntax = prop_syntax
101117

102118
final_types = set()
103119
if not prop_syntax:
@@ -109,6 +125,11 @@ def main():
109125
if has_multiplier:
110126
prop_syntax = re.sub(r"\{[0-9,]+\}", "", prop_syntax).strip()
111127

128+
# Handle hash multiplier for comma-separated lists
129+
has_hash_multiplier = prop_syntax.endswith("#")
130+
if has_hash_multiplier:
131+
prop_syntax = prop_syntax[:-1].strip()
132+
112133
# Split syntax to handle cases like '<length-percentage> | auto'
113134
syntax_parts = [part.strip() for part in prop_syntax.split("|")]
114135
resolved_syntax_parts = [
@@ -120,7 +141,7 @@ def main():
120141
for t in p.split("|"):
121142
final_types.add(t.strip())
122143

123-
if has_multiplier:
144+
if has_multiplier or has_hash_multiplier:
124145
# For properties that can have multiple values (e.g., `overflow: hidden visible`),
125146
# we also add a general string type to cover all combinations.
126147
final_types.add("(string & {})")
@@ -131,7 +152,12 @@ def main():
131152
ts_type = " | ".join(sorted(list(final_types)))
132153

133154
camel_prop_name = to_camel_case(prop_name)
134-
processed_properties[camel_prop_name] = ts_type
155+
processed_properties[camel_prop_name] = {
156+
"type": ts_type,
157+
"desc": prop_desc,
158+
"syntax": original_syntax,
159+
"name": prop_name,
160+
}
135161

136162
print(f"Loading Mako template from: {TEMPLATE_PATH}")
137163
template = Template(filename=TEMPLATE_PATH)
@@ -143,6 +169,11 @@ def main():
143169
with open(OUTPUT_PATH, "w", encoding="utf-8") as f:
144170
f.write(output_content)
145171

172+
if properties_with_empty_desc:
173+
print("\nProperties with empty 'desc':")
174+
for prop_name in properties_with_empty_desc:
175+
print(f"- {prop_name}")
176+
146177
print(f"\n✅ Successfully generated {OUTPUT_PATH}")
147178

148179

tools/css_generator/index.d.ts

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
*/
55

66
export interface Properties {
7+
/**
8+
* The `top` CSS property participates in specifying the vertical position.
9+
*
10+
* **Syntax**: `<length-percentage> | auto`
11+
*
12+
* @see https://lynxjs.org/api/css/properties/top
13+
*/
714
top?: 'auto' | (string & {}) | 0 | undefined;
815
borderTopColor?: (string & {}) | number | undefined;
916
backgroundOrigin?: (string & {}) | number | undefined;
@@ -28,7 +35,21 @@ export interface Properties {
2835
borderBottomStyle?: (string & {}) | number | undefined;
2936
implicitAnimation?: (string & {}) | number | undefined;
3037
borderRadius?: (string & {}) | number | undefined;
38+
/**
39+
* The `overflow-x` property specifies whether to clip the content when it overflows at the left and right edges.
40+
*
41+
* **Syntax**: `<overflow-block>`
42+
*
43+
* @see https://lynxjs.org/api/css/properties/overflow-x
44+
*/
3145
overflowX?: 'hidden' | 'visible' | undefined;
46+
/**
47+
* The `overflow-y` property specifies whether to clip the content when it overflows at the top and bottom edges.
48+
*
49+
* **Syntax**: `<overflow-block>`
50+
*
51+
* @see https://lynxjs.org/api/css/properties/overflow-y
52+
*/
3253
overflowY?: 'hidden' | 'visible' | undefined;
3354
wordBreak?: (string & {}) | number | undefined;
3455
backgroundClip?: (string & {}) | number | undefined;
@@ -37,8 +58,18 @@ export interface Properties {
3758
outlineStyle?: (string & {}) | number | undefined;
3859
outlineWidth?: (string & {}) | number | undefined;
3960
verticalAlign?: (string & {}) | number | undefined;
61+
/**
62+
* auto
63+
*
64+
* @see https://lynxjs.org/api/css/properties/caret-color
65+
*/
4066
caretColor?: (string & {}) | number | undefined;
4167
borderTopLeftRadius?: (string & {}) | number | undefined;
68+
/**
69+
* lynx layout direction
70+
*
71+
* @see https://lynxjs.org/api/css/properties/direction
72+
*/
4273
direction?: (string & {}) | number | undefined;
4374
relativeId?: (string & {}) | number | undefined;
4475
relativeAlignTop?: (string & {}) | number | undefined;
@@ -51,14 +82,49 @@ export interface Properties {
5182
relativeLeftOf?: (string & {}) | number | undefined;
5283
borderBottomLeftRadius?: (string & {}) | number | undefined;
5384
relativeLayoutOnce?: (string & {}) | number | undefined;
85+
/**
86+
* TBD
87+
*
88+
* @see https://lynxjs.org/api/css/properties/relative-center
89+
*/
5490
relativeCenter?: (string & {}) | number | undefined;
91+
/**
92+
* enter transition name
93+
*
94+
* @see https://lynxjs.org/api/css/properties/enter-transition-name
95+
*/
5596
enterTransitionName?: (string & {}) | number | undefined;
97+
/**
98+
* enter transition name
99+
*
100+
* @see https://lynxjs.org/api/css/properties/exit-transition-name
101+
*/
56102
exitTransitionName?: (string & {}) | number | undefined;
103+
/**
104+
* enter transition name
105+
*
106+
* @see https://lynxjs.org/api/css/properties/pause-transition-name
107+
*/
57108
pauseTransitionName?: (string & {}) | number | undefined;
109+
/**
110+
* enter transition name
111+
*
112+
* @see https://lynxjs.org/api/css/properties/resume-transition-name
113+
*/
58114
resumeTransitionName?: (string & {}) | number | undefined;
115+
/**
116+
* flex and wrap
117+
*
118+
* @see https://lynxjs.org/api/css/properties/flex-flow
119+
*/
59120
flexFlow?: (string & {}) | number | undefined;
60121
zIndex?: (string & {}) | number | undefined;
61122
textDecorationColor?: (string & {}) | number | undefined;
123+
/**
124+
* default linear layout gravity for children
125+
*
126+
* @see https://lynxjs.org/api/css/properties/linear-cross-gravity
127+
*/
62128
linearCrossGravity?: (string & {}) | number | undefined;
63129
borderTopRightRadius?: (string & {}) | number | undefined;
64130
marginInlineStart?: (string & {}) | number | undefined;
@@ -100,6 +166,11 @@ export interface Properties {
100166
justifyItems?: (string & {}) | number | undefined;
101167
justifySelf?: (string & {}) | number | undefined;
102168
gridAutoFlow?: (string & {}) | number | undefined;
169+
/**
170+
* The filter CSS property applies graphical effects like blur or color shift to an element. Filters are commonly used to adjust the rendering of images, backgrounds, and borders.
171+
*
172+
* @see https://lynxjs.org/api/css/properties/filter
173+
*/
103174
filter?: (string & {}) | number | undefined;
104175
listMainAxisGap?: (string & {}) | number | undefined;
105176
listCrossAxisGap?: (string & {}) | number | undefined;
@@ -115,6 +186,13 @@ export interface Properties {
115186
XAutoFontSize?: (string & {}) | number | undefined;
116187
XAutoFontSizePresetSizes?: (string & {}) | number | undefined;
117188
mask?: (string & {}) | number | undefined;
189+
/**
190+
* The `left` CSS property participates in specifying the horizontal position of a positioned element.
191+
*
192+
* **Syntax**: `<length-percentage> | auto`
193+
*
194+
* @see https://lynxjs.org/api/css/properties/left
195+
*/
118196
left?: 'auto' | (string & {}) | 0 | undefined;
119197
borderTopWidth?: (string & {}) | number | undefined;
120198
maskRepeat?: (string & {}) | number | undefined;
@@ -139,13 +217,32 @@ export interface Properties {
139217
fontFeatureSettings?: (string & {}) | number | undefined;
140218
fontOpticalSizing?: (string & {}) | number | undefined;
141219
color?: (string & {}) | number | undefined;
220+
XPlaceholderColor?: (string & {}) | number | undefined;
221+
XPlaceholderFontFamily?: (string & {}) | number | undefined;
222+
XPlaceholderFontSize?: (string & {}) | number | undefined;
223+
XPlaceholderFontWeight?: (string & {}) | number | undefined;
224+
XPlaceholderFontStyle?: (string & {}) | number | undefined;
142225
opacity?: (string & {}) | number | undefined;
143226
display?: (string & {}) | number | undefined;
227+
/**
228+
* The `overflow` property specifies whether to clip the content when the content of an element is too big.
229+
*
230+
* **Syntax**: `<overflow-block>{1,2}`
231+
*
232+
* @see https://lynxjs.org/api/css/properties/overflow
233+
*/
144234
overflow?: 'hidden' | 'visible' | (string & {}) | undefined;
145235
height?: (string & {}) | number | undefined;
146236
width?: (string & {}) | number | undefined;
147237
maxWidth?: (string & {}) | number | undefined;
148238
minWidth?: (string & {}) | number | undefined;
239+
/**
240+
* The `right` CSS property participates in specifying the horizontal position of a positioned element.
241+
*
242+
* **Syntax**: `<length-percentage> | auto`
243+
*
244+
* @see https://lynxjs.org/api/css/properties/right
245+
*/
149246
right?: 'auto' | (string & {}) | 0 | undefined;
150247
maxHeight?: (string & {}) | number | undefined;
151248
minHeight?: (string & {}) | number | undefined;
@@ -157,6 +254,13 @@ export interface Properties {
157254
margin?: (string & {}) | number | undefined;
158255
marginLeft?: (string & {}) | number | undefined;
159256
marginRight?: (string & {}) | number | undefined;
257+
/**
258+
* The `bottom` CSS property participates in specifying the vertical position.
259+
*
260+
* **Syntax**: `<length-percentage> | auto`
261+
*
262+
* @see https://lynxjs.org/api/css/properties/bottom
263+
*/
160264
bottom?: 'auto' | (string & {}) | 0 | undefined;
161265
marginTop?: (string & {}) | number | undefined;
162266
marginBottom?: (string & {}) | number | undefined;
@@ -221,6 +325,13 @@ export interface Properties {
221325
aspectRatio?: (string & {}) | number | undefined;
222326
textDecoration?: (string & {}) | number | undefined;
223327
textShadow?: (string & {}) | number | undefined;
224-
backgroundImage?: (string & {}) | number | undefined;
328+
/**
329+
* The `background-image` CSS property sets one or more background images on an element.
330+
*
331+
* **Syntax**: `<bg-image>#`
332+
*
333+
* @see https://lynxjs.org/api/css/properties/background-image
334+
*/
335+
backgroundImage?: 'none' | (string & {}) | undefined;
225336
backgroundPosition?: (string & {}) | number | undefined;
226337
}

0 commit comments

Comments
 (0)