How can I attach the same library with Javascript multiple times on the same page with different settings?
Thanks to responses from 4k4, the following works:
$id = $items[0]-&gt;getEntity()-&gt;uuid() . '__' . $this-&gt;fieldDefinition-&gt;getName();
$settings = [
  'id' =&gt; '#' . $id,
  'setting1' =&gt; 'foo',
  'setting2' =&gt; 'bar',
];
$elements['#attached']['drupalSettings']['gallery'][$id] = $settings;

And then in the javascript:
(function ($) {
  Drupal.behaviors.galleryBehavior = {
    attach: function (context, settings) {
      $.each(settings.gallery, function(key, item) {
        var main_selector = item.id + ' .gallery-main';
        alert(main_selector);
      });
    }
  };
})(jQuery);