(rawStyle: Record<string, string>)
| 1106 | } |
| 1107 | |
| 1108 | export function cssToTailwind(rawStyle: Record<string, string>): string { |
| 1109 | if (!rawStyle || Object.keys(rawStyle).length === 0) return '' |
| 1110 | |
| 1111 | const expandedStyle = rawStyle |
| 1112 | const buffers: Record<string, FamilyBuffer> = {} |
| 1113 | |
| 1114 | for (const [prop, rawVal] of Object.entries(expandedStyle)) { |
| 1115 | if (!rawVal) continue |
| 1116 | |
| 1117 | const lookup = PROPERTY_MAP[prop] |
| 1118 | if (!lookup) continue |
| 1119 | |
| 1120 | const { familyKey, field, defaultValue } = lookup |
| 1121 | const val = normalizeStyleValue(rawVal) |
| 1122 | |
| 1123 | if (!val) continue |
| 1124 | if (defaultValue && val === defaultValue) continue |
| 1125 | |
| 1126 | if (!buffers[familyKey]) buffers[familyKey] = {} |
| 1127 | const buf = buffers[familyKey] |
| 1128 | const config = TAILWIND_CONFIG[familyKey] |
| 1129 | |
| 1130 | if (config.mode === 'side' && isSide(field)) { |
| 1131 | const sides = buf.sides || (buf.sides = {}) |
| 1132 | sides[field] = val |
| 1133 | } else if (config.mode === 'corner' && isCorner(field)) { |
| 1134 | const corners = buf.corners || (buf.corners = {}) |
| 1135 | corners[field] = val |
| 1136 | } else if (config.mode === 'axis' && isAxis(field)) { |
| 1137 | const axes = buf.axes || (buf.axes = {}) |
| 1138 | axes[field] = val |
| 1139 | } else if (config.mode === 'direct') { |
| 1140 | buf.val = val |
| 1141 | } else { |
| 1142 | // Remaining mode is composite for PROPERTY_MAP-derived entries. |
| 1143 | const comp = buf.composite || (buf.composite = {}) |
| 1144 | comp[field] = val |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | const classes: string[] = [] |
| 1149 | |
| 1150 | for (const [familyKey, buf] of Object.entries(buffers)) { |
| 1151 | const config = TAILWIND_CONFIG[familyKey] |
| 1152 | |
| 1153 | if (config.mode === 'side' && buf.sides) { |
| 1154 | classes.push(...collapseSides(config, familyKey, buf.sides)) |
| 1155 | } else if (config.mode === 'corner' && buf.corners) { |
| 1156 | classes.push(...collapseCorners(config, familyKey, buf.corners)) |
| 1157 | } else if (config.mode === 'axis' && buf.axes) { |
| 1158 | classes.push(...collapseAxes(config, familyKey, buf.axes)) |
| 1159 | } else if (config.mode === 'direct' && buf.val) { |
| 1160 | classes.push(buildClass(config, '', extractValuePart(buf.val, config, familyKey))) |
| 1161 | } else { |
| 1162 | // Direct-mode buffers always have val; remaining families are composite. |
| 1163 | classes.push( |
| 1164 | ...collapseComposite( |
| 1165 | config as CompositeFamily, |
no test coverage detected