Skip to content

Commit f642f13

Browse files
committed
chore: add net9.0 support and improve documentation and type definitions
1 parent 16904bd commit f642f13

8 files changed

Lines changed: 103 additions & 11 deletions

Blazor.Cropper/Blazor.Cropper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<RootNamespace>Json_exe.Blazor.Cropper</RootNamespace>
2020
<PackageIcon>Json_exe.Blazor.Cropper-Logo.png</PackageIcon>
2121
<GenerateDocumentationFile>true</GenerateDocumentationFile>
22-
<TargetFramework>net8.0</TargetFramework>
22+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
2323
</PropertyGroup>
2424

2525

Blazor.Cropper/CropperJsInterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Json_exe.Blazor.Cropper;
1111
// This class can be registered as scoped DI service and then injected into Blazor
1212
// components for use.
1313

14-
public class CropperJsInterop : IAsyncDisposable
14+
internal sealed class CropperJsInterop : IAsyncDisposable
1515
{
1616
private readonly Lazy<Task<IJSObjectReference>> _moduleTask;
1717
private IJSObjectReference _cropModule = null!;

Blazor.Cropper/CropperWrapper.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public partial class CropperWrapper : IAsyncDisposable
4444

4545
private ElementReference ElementRef { get; set; }
4646

47+
/// <inheritdoc />
4748
protected override async Task OnAfterRenderAsync(bool firstRender)
4849
{
4950
if (firstRender)
@@ -250,6 +251,7 @@ public async Task DestroyBlobs()
250251
await CropperJsInterop.DestroyBlobs();
251252
}
252253

254+
/// <inheritdoc />
253255
public async ValueTask DisposeAsync()
254256
{
255257
if (CropperJsInterop != null) await CropperJsInterop.DisposeAsync();

Blazor.Cropper/DependencyInjectionExtension.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
namespace Json_exe.Blazor.Cropper;
44

5+
/// <summary>
6+
/// Provides extension methods for dependency injection related to the Cropper component.
7+
/// </summary>
58
public static class DependencyInjectionExtension
69
{
10+
/// <summary>
11+
/// Registers the required services for the CropperWrapper in the dependency injection container.
12+
/// </summary>
13+
/// <param name="services">The service collection in which to register the services.</param>
14+
/// <returns>The IServiceCollection instance for chaining further configuration.</returns>
715
public static IServiceCollection AddCropper(this IServiceCollection services)
816
{
917
services.AddScoped<CropperJsInterop>();

Blazor.Cropper/Model/CropperEvents.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace Json_exe.Blazor.Cropper.Model;
22

3+
/// <summary>
4+
/// Represents an event triggered during the zooming process in the cropper tool.
5+
/// This class provides information about the current and previous zoom ratios.
6+
/// </summary>
37
public sealed class ZoomEvent
48
{
59
/// <summary>
@@ -12,4 +16,8 @@ public sealed class ZoomEvent
1216
public double OldRatio { get; set; }
1317
}
1418

19+
/// <summary>
20+
/// Represents an event that occurs during the cropping process within the cropper tool.
21+
/// This class extends CropData to include positional and dimension details of the crop.
22+
/// </summary>
1523
public sealed record CropEvent : CropData;

Blazor.Cropper/Model/CropperException.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
namespace Json_exe.Blazor.Cropper.Model;
22

3+
/// <summary>
4+
/// Represents an exception that occurs in the Cropper functionality within the Blazor component.
5+
/// </summary>
6+
/// <remarks>
7+
/// This exception is thrown when an error specific to CropperJS operations happens. It can encapsulate
8+
/// a custom error message and an optional inner exception to provide more detailed error context.
9+
/// </remarks>
310
public sealed class CropperException : Exception
411
{
12+
/// <summary>
13+
/// Represents an exception that occurs specifically within the Cropper functionality in Blazor.
14+
/// </summary>
15+
/// <remarks>
16+
/// This exception is used to capture and handle errors that arise from operations performed
17+
/// by the Cropper functionality, such as invoking JS interops or working with cropper-specific
18+
/// data. It supports providing a detailed error message and an optional inner exception for
19+
/// further context.
20+
/// </remarks>
521
public CropperException(string? message, Exception? innerException) : base(message, innerException)
622
{
723
}

Blazor.Cropper/Model/CropperObjects.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,111 @@
22

33
namespace Json_exe.Blazor.Cropper.Model;
44

5+
/// <summary>
6+
/// Represents the cropping data of an image, including position, size, rotation, and scaling factors.
7+
/// </summary>
58
public record CropData
69
{
7-
public double X { get; set; }
8-
public double Y { get; set; }
9-
public double Width { get; set; }
10-
public double Height { get; set; }
11-
public double Rotate { get; set; }
12-
public double ScaleX { get; set; }
13-
public double ScaleY { get; set; }
10+
/// <summary>
11+
/// The horizontal position of the cropping area on the source image.
12+
/// </summary>
13+
public double X { get; init; }
14+
15+
/// <summary>
16+
/// The vertical position of the cropping area on the source image.
17+
/// </summary>
18+
public double Y { get; init; }
19+
20+
/// <summary>
21+
/// The width dimension of the object, typically used to define size or scale in rendering or cropping contexts.
22+
/// </summary>
23+
public double Width { get; init; }
24+
25+
/// <summary>
26+
/// The destination height of the output canvas.
27+
/// </summary>
28+
public double Height { get; init; }
29+
30+
/// <summary>
31+
/// The rotation angle of the cropped image, in degrees.
32+
/// </summary>
33+
public double Rotate { get; init; }
34+
35+
/// <summary>
36+
/// The horizontal scaling factor applied to the image during cropping.
37+
/// </summary>
38+
public double ScaleX { get; init; }
39+
40+
/// <summary>
41+
/// The vertical scaling factor applied to the image during cropping.
42+
/// </summary>
43+
public double ScaleY { get; init; }
1444
}
1545

46+
/// <summary>
47+
/// Represents configurable options for customizing the output canvas of a cropped image,
48+
/// including canvas dimensions, color settings, and image smoothing properties.
49+
/// Read more at: https://github.com/fengyuanchen/cropperjs/blob/v1/README.md#getcroppedcanvasoptions
50+
/// </summary>
1651
public sealed class CropCanvasOptions
1752
{
1853
/// <summary>
1954
/// The destination width of the output canvas.
2055
/// </summary>
2156
public double Width { get; set; }
57+
2258
/// <summary>
2359
/// The destination height of the output canvas.
2460
/// </summary>
2561
public double Height { get; set; }
62+
2663
/// <summary>
2764
/// The minimum destination width of the output canvas.
2865
/// </summary>
2966
public double MinWidth { get; set; } = 0;
67+
3068
/// <summary>
3169
/// The minimum destination height of the output canvas.
3270
/// </summary>
3371
public double MinHeight { get; set; } = 0;
72+
3473
/// <summary>
3574
/// The maximum destination width of the output canvas.
3675
/// </summary>
3776
[JsonNumberHandling(JsonNumberHandling.AllowNamedFloatingPointLiterals)]
3877
public double MaxWidth { get; set; } = double.PositiveInfinity;
78+
3979
/// <summary>
4080
/// The maximum destination height of the output canvas.
4181
/// </summary>
4282
[JsonNumberHandling(JsonNumberHandling.AllowNamedFloatingPointLiterals)]
4383
public double MaxHeight { get; set; } = double.PositiveInfinity;
84+
4485
/// <summary>
4586
/// A color to fill any alpha values in the output canvas.
4687
/// </summary>
4788
public string FillColor { get; set; } = "transparent";
89+
4890
/// <summary>
4991
/// Set to change if images are smoothed or not.
5092
/// </summary>
5193
public bool ImageSmoothingEnabled { get; set; } = true;
94+
5295
/// <summary>
5396
/// Set the quality of image smoothing.
5497
/// </summary>
5598
[JsonConverter(typeof(JsonStringEnumConverter))]
5699
public ImageSmoothingQuality ImageSmoothingQuality { get; set; } = ImageSmoothingQuality.low;
100+
57101
/// <summary>
58102
/// Set to true to use rounded values.
59103
/// </summary>
60104
public bool Rounded { get; set; } = false;
61105
}
62106

107+
/// <summary>
108+
/// Defines the quality levels for image smoothing when rendering a cropped image on a canvas.
109+
/// </summary>
63110
public enum ImageSmoothingQuality
64111
{
65112
low,

Blazor.Cropper/Model/CropperOptions.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Json_exe.Blazor.Cropper.Model;
44

5+
/// <summary>
6+
/// Represents the configuration options for a cropper instance. Read more at https://github.com/fengyuanchen/cropperjs/blob/v1/README.md#options
7+
/// </summary>
58
public class CropperOptions
69
{
710
[JsonPropertyName("viewMode")] public int ViewMode { get; set; } = 0;
@@ -42,14 +45,22 @@ public class CropperOptions
4245

4346
[JsonPropertyName("toggleDragModeOnDblclick")]
4447
public bool ToggleDragModeOnDblclick { get; set; } = true;
45-
[JsonPropertyName("minContainerWidth")] public double MinContainerWidth { get; set; } = 200;
46-
[JsonPropertyName("minContainerHeight")] public double MinContainerHeight { get; set; } = 100;
48+
49+
[JsonPropertyName("minContainerWidth")]
50+
public double MinContainerWidth { get; set; } = 200;
51+
52+
[JsonPropertyName("minContainerHeight")]
53+
public double MinContainerHeight { get; set; } = 100;
54+
4755
[JsonPropertyName("minCanvasWidth")] public double MinCanvasWidth { get; set; } = 0;
4856
[JsonPropertyName("minCanvasHeight")] public double MinCanvasHeight { get; set; } = 0;
4957
[JsonPropertyName("minCropBoxWidth")] public double MinCropBoxWidth { get; set; } = 0;
5058
[JsonPropertyName("minCropBoxHeight")] public double MinCropBoxHeight { get; set; } = 0;
5159
}
5260

61+
/// <summary>
62+
/// Specifies the drag mode for a cropper instance, determining how the crop box or canvas can be manipulated by user interactions.
63+
/// </summary>
5364
public enum DragMode
5465
{
5566
crop,

0 commit comments

Comments
 (0)