( properties: CSSProperties, indent: string = " ", )
| 29 | }; |
| 30 | |
| 31 | const stringifyProperties = ( |
| 32 | properties: CSSProperties, |
| 33 | indent: string = " ", |
| 34 | ) => { |
| 35 | let css = ""; |
| 36 | |
| 37 | for (const [key, value] of Object.entries(properties)) { |
| 38 | const propertyName = kebabCase(key); |
| 39 | |
| 40 | if (typeof value === "object") { |
| 41 | if (key.startsWith("@")) { |
| 42 | css += `${key} { ${stringifyProperties(value as CSSProperties, indent + " ")}${indent} } `; |
| 43 | } else if (key === "from" || key === "to" || /^\d+%$/.test(key)) { |
| 44 | css += `${indent}${key} { ${stringifyProperties(value as CSSProperties, indent + " ")}${indent}} `; |
| 45 | } else { |
| 46 | css += stringifyProperties(value as CSSProperties, indent); |
| 47 | } |
| 48 | } else { |
| 49 | const formattedValue = formatCSSValue(propertyName, value); |
| 50 | css += `${indent}${propertyName}: ${formattedValue}; `; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return css; |
| 55 | }; |
| 56 | |
| 57 | export const css = (selector: string, properties: CSSProperties) => { |
| 58 | return `${selector} { ${stringifyProperties(properties)} } `; |
no test coverage detected