TLDR: A girl hit me in the face several times, I restrained her and cursed her out massively. Didn't end particularly well. How should this be handled if it ever occurs again?

Detail below:

I was out last night with friends. Started talking to a girl and her boyfriend at the bar. Asked if I could get a water with her order to which she duly obliged. There was some playful banter back and forth and after thanking her I ribbed her for the fact that the water came in a warm glass.

Moments later she slapped me (I honestly do not have a clue as to why). Not too hard at first, but she did it again so I restrained her hand. She looked down and shuffled about as if she wanted to knee me in the crotch, so I blocked accordingly. Then she slapped me in the face hard with her other hand. She managed this three times before I could stop her (I had the water in my free hand).

I absolutely lost it at this point. Held back her other hand and cursed her out big time. Her boyfriend got involved and pushed me away saying that it doesn't matter that she hit me because she is a girl. Then a bouncer stepped in and separated us.

I was so angry that this girl felt entitled to hit me in the face with zero repercussion. I wanted to put her face through the bar. Obviously such an act would have landed me in the hospital/prison, but the desire was there in the back of my mind.

The best response would be to not allow yourself to get into such a situation in the first place, but any advice on how to handle this better in the future? Any of you experienced the same thing?

For clarity, I wear glasses so tend to avoid confrontation where possible due to the potential financial cost when my lenses get smashed.