How can I copy formatted text using HTML and JavaScript?

I would like to implement a button on my webpage that allows users to copy formatted text to their clipboard. Shortcuts and context menus are disabled on my page, but I still want users to be able to copy formatted text, similar to using Ctrl + C. Can someone please point me in the right direction?

p.s. The execCommand() method is deprecated. so this will not be an answer.
p.s. i am looking for a method that does not use any external libraries.

i am a total beginner in js so any help will be appriciated