-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
2,888 additions
and
1 deletion.
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,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
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,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Blazor.QrCode\Blazor.QrCode.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,34 @@ | ||
using FluentAssertions; | ||
|
||
namespace Blazor.QrCode.Tests | ||
{ | ||
using System; | ||
using System.Drawing; | ||
using Blazor.QrCode; | ||
using Xunit; | ||
|
||
public static class ColorConverterTests | ||
{ | ||
[Theory] | ||
[InlineData(KnownColor.White, "#ffffff")] | ||
[InlineData(KnownColor.Black, "#000000")] | ||
[InlineData(KnownColor.Red, "#ff0000")] | ||
[InlineData(KnownColor.Lime, "#00ff00")] | ||
[InlineData(KnownColor.Blue, "#0000ff")] | ||
[InlineData(KnownColor.Cyan, "#00ffff")] | ||
[InlineData(KnownColor.Yellow, "#ffff00")] | ||
[InlineData(KnownColor.Magenta, "#ff00ff")] | ||
public static void TestConversion(KnownColor colorId, string expected) | ||
{ | ||
// Arrange | ||
Color color = Color.FromKnownColor(colorId); | ||
|
||
// Act | ||
|
||
var result = Blazor.QrCode.ColorConverter.Convert(color); | ||
|
||
// Assert | ||
result.Should().Be(expected); | ||
} | ||
} | ||
} |
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 @@ | ||
global using Xunit; |
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
|
||
<ItemGroup> | ||
<SupportedPlatform Include="browser" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="wwwroot\js\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Update="wwwroot\qrcode.min.js"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Update="wwwroot\qrcodeInterop.js"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
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,18 @@ | ||
using System.Drawing; | ||
using System.Text; | ||
|
||
namespace Blazor.QrCode | ||
{ | ||
public static class ColorConverter | ||
{ | ||
public static string Convert(Color color) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
sb.Append("#"); | ||
sb.Append(color.R.ToString("x2")); | ||
sb.Append(color.G.ToString("x2")); | ||
sb.Append(color.B.ToString("x2")); | ||
return sb.ToString(); | ||
} | ||
} | ||
} |
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,13 @@ | ||
namespace Blazor.QrCode | ||
{ | ||
public enum EErrorCorrectionLevel | ||
{ | ||
Low = 1, | ||
|
||
Medium = 0, | ||
|
||
Quartile = 3, | ||
|
||
High = 2, | ||
} | ||
} |
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,37 @@ | ||
using Microsoft.JSInterop; | ||
|
||
namespace Blazor.QrCode | ||
{ | ||
// This class provides an example of how JavaScript functionality can be wrapped | ||
// in a .NET class for easy consumption. The associated JavaScript module is | ||
// loaded on demand when first needed. | ||
// | ||
// This class can be registered as scoped DI service and then injected into Blazor | ||
// components for use. | ||
|
||
public class ExampleJsInterop : IAsyncDisposable | ||
{ | ||
private readonly Lazy<Task<IJSObjectReference>> moduleTask; | ||
|
||
public ExampleJsInterop(IJSRuntime jsRuntime) | ||
{ | ||
moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>( | ||
"import", "./_content/Blazor.QrCode/exampleJsInterop.js").AsTask()); | ||
} | ||
|
||
public async ValueTask<string> Prompt(string message) | ||
{ | ||
var module = await moduleTask.Value.ConfigureAwait(false); | ||
return await module.InvokeAsync<string>("showPrompt", message).ConfigureAwait(false); | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (moduleTask.IsValueCreated) | ||
{ | ||
var module = await moduleTask.Value.ConfigureAwait(false); | ||
await module.DisposeAsync().ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} |
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,29 @@ | ||
using Microsoft.JSInterop; | ||
|
||
namespace Blazor.QrCode | ||
{ | ||
/// <summary> | ||
/// Class BabylonObject. | ||
/// Base object | ||
/// </summary> | ||
public class JsInteropObject : IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="JsInteropObject"/> class. | ||
/// </summary> | ||
/// <param name="jsObjRef">The java script object reference.</param> | ||
protected JsInteropObject(IJSObjectReference jsObjRef) | ||
{ | ||
JsObjRef = jsObjRef; | ||
} | ||
|
||
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.</summary> | ||
/// <returns>A task that represents the asynchronous dispose operation.</returns> | ||
public async ValueTask DisposeAsync() | ||
{ | ||
await JsObjRef.DisposeAsync().ConfigureAwait(false); | ||
} | ||
|
||
public IJSObjectReference JsObjRef { get; } | ||
} | ||
} |
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,22 @@ | ||
using Microsoft.JSInterop; | ||
|
||
namespace Blazor.QrCode; | ||
|
||
public class ModuleCreator | ||
{ | ||
public ModuleCreator(IJSRuntime jsInstance) | ||
{ | ||
JsInstance = jsInstance; | ||
} | ||
|
||
public async Task<QrCodeModule> CreateAsync() | ||
{ | ||
IJSObjectReference moduleRef = await JsInstance.InvokeAsync<IJSObjectReference>( | ||
"import", | ||
"./_content/Blazor.QrCode/qrcodeInterop.js").ConfigureAwait(false); | ||
|
||
return new QrCodeModule(JsInstance, moduleRef); | ||
} | ||
|
||
public IJSRuntime JsInstance { get; } | ||
} |
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,16 @@ | ||
@using Microsoft.JSInterop | ||
|
||
<div id=@CanvasId ></div> | ||
|
||
@code | ||
{ | ||
/// <summary> | ||
/// Gets or sets the canvas identifier. | ||
/// </summary> | ||
/// <value>The canvas identifier.</value> | ||
[Parameter] | ||
public string CanvasId { get; set; } = "qrcode"; | ||
|
||
[Parameter] | ||
public QrCodeOptions? Options { get; set; } | ||
} |
Oops, something went wrong.