-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a helper class for import maps.
- Loading branch information
1 parent
6468b01
commit 64fffe2
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace HtmlUtilities.Validated.Standardized; | ||
|
||
/// <summary> | ||
/// Contents for a specialized "script" element that allows developers to control how the browser resolves module specifiers when importing JavaScript modules. | ||
/// Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap | ||
/// </summary> | ||
public sealed class ImportMap | ||
{ | ||
/// <summary> | ||
/// Replaces module specifiers in matching import statements. | ||
/// Effects can be overridden by a match within <see cref="Scopes"/>. | ||
/// </summary> | ||
[JsonPropertyName("imports")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
public IDictionary<string, string>? Imports { get; set; } | ||
|
||
/// <summary> | ||
/// Provides integrity metadata for module sources. | ||
/// </summary> | ||
[JsonPropertyName("integrity")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
public IDictionary<string, string>? Integrity { get; set; } | ||
|
||
/// <summary> | ||
/// Path-specific module specifier maps. | ||
/// </summary> | ||
[JsonPropertyName("scopes")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
public IDictionary<string, IDictionary<string, string>>? Scopes { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() => JsonSerializer.Serialize(this, ImportMapSerializerContext.Default.ImportMap); | ||
} | ||
|
||
[JsonSerializable(typeof(ImportMap))] | ||
internal sealed partial class ImportMapSerializerContext : JsonSerializerContext | ||
{ | ||
} |