My two main advices are:
Put the library in the assets folder
This solves CSP, makes the theme self-contained and is considered a good practice, instead of loading it from third-parties.
Load it lazily
Only when needed, you can load it lazily using await loadScript. This means it won’t be loaded in pages where it isn’t needed, slowing your whole site.
A good example of a theme that follows those good practices is GitHub - discourse/discourse-mermaid-theme-component · GitHub