Fix the logical property rewriter for chat bubble CSS
Your task
Your chat product is launching in Arabic and Hebrew. An AI wrote the message bubble's CSS with physical sides: margin-left, border-left, text-align: left and float: right. In a right-to-left (RTL) layout those stay where they are instead of mirroring. Your team is converting the declarations to CSS logical properties, which follow the writing direction.
An assistant wrote rewrite_to_logical_properties(declarations). It is in the editor. It has a bug. Find it and fix it.
Input and output:
declarations: CSS declarations, one per entry, like"margin-left: 48px".- Return the rewritten declarations, in the same order.
Rules the tests check:
- Trim the declaration. If it then ends with
;, remove that one;and trim again. - If there is no
:, return the declaration as it now is. - Otherwise split at the first
:. Trim both parts, and lowercase the property name. CSS property names and keywords are not case sensitive. - Rename these properties and keep the value:
margin-leftandmargin-rightbecomemargin-inline-startandmargin-inline-end.padding-left,padding-right,border-leftandborder-rightchange the same way.leftandrightbecomeinset-inline-startandinset-inline-end. - For
text-align, a value ofleftorrightin any case becomesstartorend. Forfloat, it becomesinline-startorinline-end. - Leave every other property and value as it is. Block sides like
margin-topdo not mirror, and neither do values likecenter. - Write the result as
<property>: <value>, with one space after the colon.
Examples
rewrite_to_logical_properties(declarations: list[str]) -> list[str]Example 1
Input
rewrite_to_logical_properties(["margin-left: 48px", "padding-right: 12px", "text-align: left", "border-left: 3px solid var(--accent)", "float: right"])Output
["margin-inline-start: 48px", "padding-inline-end: 12px", "text-align: start", "border-inline-start: 3px solid var(--accent)", "float: inline-end"]Example 2
Input
rewrite_to_logical_properties(["margin-top: 8px", "text-align: center", "color: var(--ink)"])Output
["margin-top: 8px", "text-align: center", "color: var(--ink)"]Example 3
Input
rewrite_to_logical_properties(["left: 0", "right: 12px"])Output
["inset-inline-start: 0", "inset-inline-end: 12px"]