-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Target <!-- Why are you making this change? --> #### Open Questions <!-- OPTIONAL - [ ] Use the GitHub checklists to spark discussion on issues that may arise from your approach. Please tick the box and explain your answer. --> ## Checklist <!-- It serves as a gentle reminder for common tasks. Confirm it's done and check everything that applies. --> - [x] Documentation updated - [x] Tests cover new or modified code - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] New dependencies added - [ ] Includes breaking changes - [x] Version bumped ## Visuals <!-- OPTIONAL Show results both before and after this change. When the output changes, it can be a screenshot of a trace, metric, or log illustrating the change. -->
- Loading branch information
Showing
42 changed files
with
919 additions
and
347 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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor
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,19 @@ | ||
<MudCard Class="d-flex justify-space-between flex-column mb-6"> | ||
<MudCardContent> | ||
<MudText>Aspect Ratio Settings (only for FREE aspect ratio)</MudText> | ||
<MudNumericField @bind-Value="MinAspectRatio" | ||
Label="Min aspect ratio" | ||
Disabled="!IsEnableAspectRatioSettings" | ||
Min="0" | ||
Max="MaxAspectRatio"> | ||
</MudNumericField> | ||
<MudNumericField @bind-Value="MaxAspectRatio" | ||
Label="Max aspect ratio" | ||
Disabled="!IsEnableAspectRatioSettings" | ||
Min="MinAspectRatio ?? 0"> | ||
</MudNumericField> | ||
<MudText Class="mt-4"> | ||
Current aspect ratio: @AspectRatio | ||
</MudText> | ||
</MudCardContent> | ||
</MudCard> |
89 changes: 89 additions & 0 deletions
89
src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor.cs
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,89 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Cropper.Blazor.Client.Pages; | ||
using Cropper.Blazor.Models; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Cropper.Blazor.Client.Components | ||
{ | ||
public partial class AspectRatioSettings | ||
{ | ||
private decimal? maxAspectRatio; | ||
private decimal? minAspectRatio; | ||
private bool isEnableAspectRatioSettings; | ||
|
||
public decimal? MaxAspectRatio | ||
{ | ||
get => maxAspectRatio; | ||
set | ||
{ | ||
maxAspectRatio = value; | ||
ApplyAspectRatioRulesForCropperAsync(); | ||
} | ||
} | ||
|
||
public decimal? MinAspectRatio | ||
{ | ||
get => minAspectRatio; | ||
set | ||
{ | ||
minAspectRatio = value; | ||
ApplyAspectRatioRulesForCropperAsync(); | ||
} | ||
} | ||
|
||
[CascadingParameter(Name = "AspectRatio"), Required] | ||
private decimal? AspectRatio { get; set; } | ||
|
||
[CascadingParameter(Name = "CropperDemo"), Required] | ||
private CropperDemo CropperDemo { get; set; } = null!; | ||
|
||
[CascadingParameter(Name = "IsEnableAspectRatioSettings"), Required] | ||
private bool IsEnableAspectRatioSettings | ||
{ | ||
get => isEnableAspectRatioSettings; | ||
set | ||
{ | ||
if (!value) | ||
{ | ||
minAspectRatio = null; | ||
maxAspectRatio = null; | ||
} | ||
|
||
isEnableAspectRatioSettings = value; | ||
} | ||
} | ||
|
||
public async Task ApplyAspectRatioRulesForCropperAsync() | ||
{ | ||
if (minAspectRatio is not null || maxAspectRatio is not null) | ||
{ | ||
ContainerData containerData = await CropperDemo.CropperComponent!.GetContainerDataAsync(); | ||
CropBoxData cropBoxData = await CropperDemo.CropperComponent!.GetCropBoxDataAsync(); | ||
|
||
if (cropBoxData.Height != 0) | ||
{ | ||
decimal aspectRatio = cropBoxData.Width / cropBoxData.Height; | ||
|
||
if (aspectRatio < minAspectRatio || aspectRatio > maxAspectRatio) | ||
{ | ||
decimal? newCropBoxWidth = cropBoxData.Height * ((minAspectRatio + maxAspectRatio) / 2); | ||
|
||
CropperDemo.CropperComponent!.SetCropBoxData(new SetCropBoxDataOptions | ||
{ | ||
Left = (containerData.Width - newCropBoxWidth) / 2, | ||
Width = newCropBoxWidth, | ||
}); | ||
} | ||
|
||
SetUpAspectRatio(aspectRatio); | ||
} | ||
} | ||
} | ||
|
||
public void SetUpAspectRatio(decimal? aspectRatio) | ||
{ | ||
AspectRatio = aspectRatio; | ||
StateHasChanged(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor
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,26 @@ | ||
<MudCard Class="d-flex justify-space-between flex-column mb-6"> | ||
<MudCardContent> | ||
<MudText> | ||
Dimensions Settings | ||
<h6>This option may not work with arbitrary 'Aspect Ratios' images, it is recommended to use a free Aspect Ratio for this option or calculate the allowed values yourself</h6> | ||
</MudText> | ||
<MudNumericField @bind-Value="MinimumWidth" | ||
Label="Minimum Width" | ||
Min="0" | ||
Max="MaximumWidth"> | ||
</MudNumericField> | ||
<MudNumericField @bind-Value="MaximumWidth" | ||
Label="Maximum Width" | ||
Min="MinimumWidth ?? 0"> | ||
</MudNumericField> | ||
<MudNumericField @bind-Value="MinimumHeight" | ||
Label="Minimum Height" | ||
Min="0" | ||
Max="MaximumHeight"> | ||
</MudNumericField> | ||
<MudNumericField @bind-Value="MaximumHeight" | ||
Label="Maximum Height" | ||
Min="MinimumHeight ?? 0"> | ||
</MudNumericField> | ||
</MudCardContent> | ||
</MudCard> |
21 changes: 21 additions & 0 deletions
21
src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor.cs
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,21 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Cropper.Blazor.Client.Components | ||
{ | ||
public partial class CroppedDimensionsSettings | ||
{ | ||
private decimal? minimumWidth = null; | ||
private decimal? maximumWidth = null; | ||
private decimal? minimumHeight = null; | ||
private decimal? maximumHeight = null; | ||
|
||
[CascadingParameter(Name = "ResetCropperAction"), Required] | ||
public Action ResetCropperAction { get; set; } = null!; | ||
|
||
public decimal? MinimumWidth { get => minimumWidth; set { minimumWidth = value; ResetCropperAction.Invoke(); } } | ||
public decimal? MaximumWidth { get => maximumWidth; set { maximumWidth = value; ResetCropperAction.Invoke(); } } | ||
public decimal? MinimumHeight { get => minimumHeight; set { minimumHeight = value; ResetCropperAction.Invoke(); } } | ||
public decimal? MaximumHeight { get => maximumHeight; set { maximumHeight = value; ResetCropperAction.Invoke(); } } | ||
} | ||
} |
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
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
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
49 changes: 49 additions & 0 deletions
49
src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor.cs
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,49 @@ | ||
using Cropper.Blazor.Events.ZoomEvent; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.JSInterop; | ||
|
||
namespace Cropper.Blazor.Client.Components | ||
{ | ||
public partial class ZoomRatioSettings | ||
{ | ||
private decimal? minZoomRatio = null; | ||
private decimal? maxZoomRatio = null; | ||
|
||
private decimal? MinZoomRatio | ||
{ | ||
get => minZoomRatio; | ||
set | ||
{ | ||
minZoomRatio = value; | ||
ApplyZoomRulesForCropperAsync(); | ||
} | ||
} | ||
private decimal? MaxZoomRatio | ||
{ | ||
get => maxZoomRatio; | ||
set | ||
{ | ||
maxZoomRatio = value; | ||
ApplyZoomRulesForCropperAsync(); | ||
} | ||
} | ||
[Inject] private IJSRuntime? JSRuntime { get; set; } | ||
|
||
private decimal? OldRatio { get; set; } = null; | ||
|
||
private decimal? Ratio { get; set; } = null; | ||
|
||
public void OnZoomEvent(ZoomEvent? zoomEvent) | ||
{ | ||
OldRatio = zoomEvent?.OldRatio; | ||
Ratio = zoomEvent?.Ratio; | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
public async Task ApplyZoomRulesForCropperAsync() | ||
{ | ||
await JSRuntime!.InvokeVoidAsync("window.overrideOnZoomCropperEvent", MinZoomRatio, MaxZoomRatio); | ||
} | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.