class CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer

def self.url_resource_preload_type(url)

def self.url_resource_preload_type(url)
  case File.extname(url)
  when '.js' then 'script'
  when '.css' then 'style'
  else 'fetch'
  end
end

def initialize(bundle)

def initialize(bundle)
  raise TypeError, 'bundle must be an instance of AssetsBundle' unless bundle.is_a?(AssetsBundle)
  @bundle = bundle
end

def preload_tags

def preload_tags
  @preload_tags ||= safe_join(bundle.preloads.map do |url|
    tag.link(href: url, rel: 'preload', as: self.class.url_resource_preload_type(url))
  end)
end

def scripts_import_map_tag

def scripts_import_map_tag
  return @scripts_import_map_tag if defined?(@scripts_import_map_tag)
  import_map = bundle.scripts.each_with_object({}) do |script, map|
    map[script.import_name] = script.url if script.esm?
  end
  @scripts_import_map_tag = tag.script(
    { imports: import_map }.to_json.html_safe,
    type: 'importmap',
    nonce: true
  )
end

def styles_tags

def styles_tags
  @styles_tags ||= safe_join(bundle.stylesheets.map do |url|
    tag.link(href: url, rel: 'stylesheet')
  end)
end

def to_html

def to_html
  safe_join([
              preload_tags,
              styles_tags,
              window_scripts_tags,
              scripts_import_map_tag,
              web_component_tag
            ])
end

def web_component_tag

def web_component_tag
  @web_component_tag ||= tag.script(WEBCOMPONENT_SOURCE, type: 'module', nonce: true)
end

def window_scripts_tags

def window_scripts_tags
  @window_scripts_tags ||= safe_join(bundle.scripts.filter_map do |script|
    tag.script(src: script.url, nonce: true, async: true) if script.window?
  end)
end