| 69 | }); |
| 70 | |
| 71 | const updateStateWithCodes = (state, codes) => { |
| 72 | codes.forEach((code) => { |
| 73 | if (code === 0) { |
| 74 | // Reset state |
| 75 | state.modifiers.clear(); |
| 76 | state.textColor = null; |
| 77 | state.bgColor = null; |
| 78 | state.reverse = false; |
| 79 | return; |
| 80 | } |
| 81 | // Instead of swapping immediately, we set a flag |
| 82 | if (code === 7) { |
| 83 | state.reverse = true; |
| 84 | return; |
| 85 | } |
| 86 | const tailwindClass = ANSI_TAILWIND_MAP[code]; |
| 87 | if (tailwindClass && tailwindClass !== "reset") { |
| 88 | if (tailwindClass.startsWith("text-")) { |
| 89 | state.textColor = tailwindClass; |
| 90 | } else if (tailwindClass.startsWith("bg-")) { |
| 91 | state.bgColor = tailwindClass; |
| 92 | } else { |
| 93 | state.modifiers.add(tailwindClass); |
| 94 | } |
| 95 | } |
| 96 | }); |
| 97 | return state; |
| 98 | }; |
| 99 | |
| 100 | const stateToClasses = (state: InternalStateType) => { |
| 101 | const classes = []; |