Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update nuget 1 2 1 #152

Merged
merged 24 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2f7593f
add Dimensions Settings
MaxymGorn May 5, 2023
89089b1
Fix whitespace formatting.
MaxymGorn May 5, 2023
ed60820
Add Dimensions Settings (#130)
MaxymGorn May 5, 2023
6e441da
Merge branch 'dev' of https://github.com/CropperBlazor/Cropper.Blazor…
MaxymGorn May 28, 2023
ca0865a
add aspect ratio settings
MaxymGorn May 28, 2023
bac52dc
Feature/add aspect ratio settings (#136)
MaxymGorn May 28, 2023
26ec4f4
fix update current aspect ratio in settings
MaxymGorn May 29, 2023
2a4d534
small fix
MaxymGorn May 29, 2023
8dcea02
update nuget packages
MaxymGorn May 29, 2023
5f4ce94
fix tests
MaxymGorn May 29, 2023
78dbbfb
fix update current aspect ratio in settings (#138)
MaxymGorn May 30, 2023
c82d4e6
add download cropped image functionality to UI
MaxymGorn Jun 21, 2023
9c9b371
format file
MaxymGorn Jun 21, 2023
b816777
add download cropped image functionality to UI (#149)
MaxymGorn Jun 21, 2023
220aa78
add replace image functionality
MaxymGorn Jun 22, 2023
bbe58f0
align code
MaxymGorn Jun 22, 2023
33d1746
fix comment
MaxymGorn Jun 22, 2023
9f3b953
update version nuget package
MaxymGorn Jun 22, 2023
63f83ca
add replace image functionality (#151)
MaxymGorn Jun 22, 2023
ed9969b
fix incorrect Base Path Resolution for CropperJSInterop.min.js
MaxymGorn Jun 22, 2023
8536753
fix incorrect Base Path Resolution for CropperJSInterop.min.js (#153)
MaxymGorn Jun 22, 2023
46edcc6
consolidate nuget versions
MaxymGorn Jun 22, 2023
2a98eb2
Merge branch 'dev' into feature/fix_Base_Path_Resolution_for_CropperJ…
MaxymGorn Jun 22, 2023
eafeae3
consolidate nuget versions (#155)
MaxymGorn Jun 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.2.2" />
<PackageReference Include="MudBlazor" Version="6.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="MudBlazor" Version="6.2.2" />
<PackageReference Include="MudBlazor" Version="6.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.2.2" />
<PackageReference Include="MudBlazor" Version="6.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.2.2" />
<PackageReference Include="MudBlazor" Version="6.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.2.2" />
<PackageReference Include="MudBlazor" Version="6.4.1" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor
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 src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor.cs
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();
}
}
}
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>
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(); } }
}
}
11 changes: 7 additions & 4 deletions src/Cropper.Blazor/Client/Components/GetSetCropperData.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@using Cropper.Blazor.Models

@*//---Cropper Data---//*@
<MudItem xxl="3" xl="3" lg="3" md="3" sm="12" xs="12">
<MudCard>
@*//---Enable setup minimum and maximum cropped dimensions---//*@
<CroppedDimensionsSettings @ref="CroppedDimensionsSettings" />
@*//---Cropper Data---//*@
<MudCard Class="d-flex justify-space-between flex-column">
<MudCardContent @key="CropperData">
<MudText>Cropper Data</MudText>
<MudNumericField Class="mb-2" HideSpinButtons="true" @bind-Value="CropperData.X" Label="X, px" Variant="Variant.Text" Step=".2M" />
Expand Down Expand Up @@ -70,8 +72,9 @@
</MudItem>
@*//---Image Data---//*@
<MudItem xxl="3" xl="3" lg="3" md="3" sm="12" xs="12">
<AspectRatioSettings @ref="AspectRatioSettings" />
<MudCard>
<MudCardContent @key="ImageData">
<MudCardContent @key="ImageData" Class="d-flex justify-space-between flex-column">
<MudText>Image Data</MudText>
<MudNumericField ReadOnly="true" Class="mb-2" HideSpinButtons="true" @bind-Value="ImageData.Height" Label="Height, px" Variant="Variant.Text" Step=".2M" />
<MudNumericField ReadOnly="true" Class="mb-2" HideSpinButtons="true" @bind-Value="ImageData.Width" Label="Width, px" Variant="Variant.Text" Step=".2M" />
Expand All @@ -95,7 +98,7 @@
</MudItem>
<MudItem xxl="3" xl="3" lg="3" md="3" sm="12" xs="12">
@*//---Enable setup max/min zoom ratio---//*@
<ZoomRationSettings @ref="ZoomRationSettingszoomRationSettings" />
<ZoomRatioSettings @ref="ZoomRatioSettings" />
@*//---Canvas Data---//*@
<MudCard Class="d-flex justify-space-between flex-column">
<MudCardContent @key="CanvasData">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ public partial class GetSetCropperData
[Parameter, Required]
public Func<ValueTask<CanvasData>> GetCanvasData { get; set; } = null!;

public AspectRatioSettings AspectRatioSettings = null!;

private CropBoxData CropBoxData = null!;
private CropperData CropperData = null!;
private ContainerData ContainerData = null!;
private ImageData ImageData = null!;
private CanvasData CanvasData = null!;
private ZoomRationSettings ZoomRationSettingszoomRationSettings = null!;
private ZoomRatioSettings ZoomRatioSettings = null!;
public CroppedDimensionsSettings CroppedDimensionsSettings = null!;

protected override void OnInitialized()
{
Expand All @@ -42,7 +45,7 @@ protected override void OnInitialized()

public void OnZoomEvent(ZoomEvent? zoomEvent)
{
ZoomRationSettingszoomRationSettings!.OnZoomEvent(zoomEvent);
ZoomRatioSettings!.OnZoomEvent(zoomEvent);
}

public void SetCropBoxData(SetCropBoxDataOptions cropBoxDataOptions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<MudCard Class="d-flex justify-space-between flex-column mb-6">
<MudCardContent Class="pb-0">
<MudCardContent>
<MudText>Zoom Ratio Settings</MudText>
<MudNumericField @bind-Value="MinZoomRatio"
Label="Min zoom ratio"
Min="0"
Expand All @@ -16,12 +17,4 @@
Zoom event ratio: @Ratio
</MudText>
</MudCardContent>
<MudCardActions Class="d-flex justify-space-between flex-column mt-0">
<MudButton Variant="Variant.Outlined"
Color="Color.Primary"
FullWidth="true"
OnClick="ApplyZoomRulesForCropperAsync">
Apply zoom rules for Cropper
</MudButton>
</MudCardActions>
</MudCard>
49 changes: 49 additions & 0 deletions src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor.cs
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 src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor.cs

This file was deleted.

Loading