ladybird/Libraries/LibWeb/HTML/Scripting/ImportMap.h

50 lines
2 KiB
C
Raw Normal View History

2022-10-23 04:05:11 +02:00
/*
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
2024-04-13 21:22:05 +01:00
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
2022-10-23 04:05:11 +02:00
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
2024-04-13 21:22:05 +01:00
#include <LibURL/URL.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
2022-10-23 04:05:11 +02:00
namespace Web::HTML {
using ModuleSpecifierMap = HashMap<String, Optional<URL::URL>>;
using ModuleIntegrityMap = HashMap<URL::URL, String>;
2022-10-23 04:05:11 +02:00
// https://html.spec.whatwg.org/multipage/webappapis.html#import-map
class ImportMap {
public:
ImportMap() = default;
ModuleSpecifierMap const& imports() const { return m_imports; }
ModuleSpecifierMap& imports() { return m_imports; }
2024-04-13 21:22:05 +01:00
void set_imports(ModuleSpecifierMap const& imports) { m_imports = imports; }
2022-10-23 04:05:11 +02:00
HashMap<URL::URL, ModuleSpecifierMap> const& scopes() const { return m_scopes; }
HashMap<URL::URL, ModuleSpecifierMap>& scopes() { return m_scopes; }
2024-04-13 21:22:05 +01:00
void set_scopes(HashMap<URL::URL, ModuleSpecifierMap> const& scopes) { m_scopes = scopes; }
2022-10-23 04:05:11 +02:00
ModuleIntegrityMap const& integrity() const { return m_integrity; }
ModuleIntegrityMap integrity() { return m_integrity; }
void set_integrity(ModuleIntegrityMap const& integrity) { m_integrity = integrity; }
2022-10-23 04:05:11 +02:00
private:
ModuleSpecifierMap m_imports;
HashMap<URL::URL, ModuleSpecifierMap> m_scopes;
ModuleIntegrityMap m_integrity;
2022-10-23 04:05:11 +02:00
};
2024-04-13 21:22:05 +01:00
WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteString const& input, URL::URL base_url);
Optional<FlyString> normalize_specifier_key(JS::Realm& realm, FlyString specifier_key, URL::URL base_url);
2024-04-13 21:22:05 +01:00
WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);
WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);
WebIDL::ExceptionOr<ModuleIntegrityMap> normalize_module_integrity_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);
void merge_existing_and_new_import_maps(Window&, ImportMap&);
2024-04-13 21:22:05 +01:00
2022-10-23 04:05:11 +02:00
}