"If only I had been like this, or done that, he would still love me."

My husband is leaving me. I wasn’t expecting it, I love him, I’m devastated.
What hurts me the most is that I think back on everything I missed, everything I did wrong, everything I could have said, done, or been better at. If I had been like this, if I had done that, etc., I would have been better and he would still be with me. I’m redoing the film of our life, looking at pictures from 2, 5 or 10 years ago, and I torture myself thinking that if I had acted differently he would still love me and we would still be together. That’s really what’s most painful. I have the feeling that all this would hurt less if someone came to me and said for sure: “you couldn’t have done anything about it, he would have dis-loved you anyway, there’s nothing you could have done about it”. But I know that’s not true. I made mistakes. I pay the price. Big time.
This thought is extremely painful, to the point of taking my breath away and provoking monstrous panic attacks. I feel like I failed on him, I hurt him, I ruined him and our family and my life. Nothing like cheating or so – just being me, with my personality, my flaws, my emotional issues, my lack of perfection, the way I wasn’t a good enough wife…
I don’t know what to do to help me with this painful thoughts.
Do you have an idea?
Thank you very much.