Performs any necessary mutations on the VDOM attributes to meet VDOM spec. Currently, this function only transforms the ``style`` attribute into a dictionary whose keys are camelCase so as to be renderable by React. This function may be extended in the future.
(vdom: VdomDict)
| 200 | |
| 201 | |
| 202 | def _mutate_vdom(vdom: VdomDict) -> None: |
| 203 | """Performs any necessary mutations on the VDOM attributes to meet VDOM spec. |
| 204 | |
| 205 | Currently, this function only transforms the ``style`` attribute into a dictionary whose keys are |
| 206 | camelCase so as to be renderable by React. |
| 207 | |
| 208 | This function may be extended in the future. |
| 209 | """ |
| 210 | # Determine if the style attribute needs to be converted to a dict |
| 211 | if ( |
| 212 | "attributes" in vdom |
| 213 | and "style" in vdom["attributes"] |
| 214 | and isinstance(vdom["attributes"]["style"], str) |
| 215 | ): |
| 216 | # Convince type checker that it's safe to mutate attributes |
| 217 | assert isinstance(vdom["attributes"], dict) # noqa: S101 |
| 218 | |
| 219 | # Convert style attribute from str -> dict with camelCase keys |
| 220 | vdom["attributes"]["style"] = { |
| 221 | key.strip().replace("-", "_"): value.strip() |
| 222 | for key, value in ( |
| 223 | part.split(":", 1) |
| 224 | for part in vdom["attributes"]["style"].split(";") |
| 225 | if ":" in part |
| 226 | ) |
| 227 | } |
| 228 | |
| 229 | |
| 230 | def _generate_vdom_children( |