2020-05-14 16:26:21 +08:00
|
|
|
|
using System;
|
2020-08-14 07:13:28 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-14 16:26:21 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-06-10 21:44:21 +08:00
|
|
|
|
using Microsoft.JSInterop;
|
2020-05-14 16:26:21 +08:00
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
#pragma warning disable CA1822
|
|
|
|
|
#pragma warning disable CA1054
|
|
|
|
|
#pragma warning disable CA1062
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-05-14 16:26:21 +08:00
|
|
|
|
{
|
|
|
|
|
public class IconService
|
|
|
|
|
{
|
2020-06-10 21:44:21 +08:00
|
|
|
|
private IJSRuntime _js;
|
2020-05-14 16:26:21 +08:00
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
public IconService(IJSRuntime js)
|
2020-05-14 16:26:21 +08:00
|
|
|
|
{
|
2020-06-10 21:44:21 +08:00
|
|
|
|
_js = js;
|
2020-05-14 16:26:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
public static string GetIconImg(string type, string theme)
|
2020-05-14 16:26:21 +08:00
|
|
|
|
{
|
2020-12-08 10:01:43 +08:00
|
|
|
|
var iconImg = IconStore.GetIcon(type, theme);
|
2020-08-04 15:10:29 +08:00
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
if (string.IsNullOrEmpty(iconImg))
|
2020-08-04 15:10:29 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
2020-05-14 16:26:21 +08:00
|
|
|
|
return iconImg;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 15:39:58 +08:00
|
|
|
|
public static string GetStyledSvg(string svgImg, string svgClass = null, string width = "1em", string height = "1em", string fill = "currentColor", int rotate = 0)
|
2020-05-14 16:26:21 +08:00
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(svgImg))
|
|
|
|
|
{
|
2020-11-12 15:39:58 +08:00
|
|
|
|
string svgStyle = $"focusable=\"false\" width=\"{width}\" height=\"{height}\" fill=\"{fill}\" {(rotate == 0 ? "" : $"style=\"transform: rotate({rotate}deg);\"")}";
|
|
|
|
|
if (!string.IsNullOrEmpty(svgClass))
|
|
|
|
|
{
|
|
|
|
|
svgStyle += $" class=\"{svgClass}\"";
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 07:13:28 +08:00
|
|
|
|
return svgImg.Insert(svgImg.IndexOf("<svg", StringComparison.Ordinal) + 4, $" {svgStyle} ");
|
2020-05-14 16:26:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 21:44:21 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ValueTask CreateFromIconfontCN(string scriptUrl)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(scriptUrl))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _js.InvokeVoidAsync(JSInteropConstants.CreateIconFromfontCN, scriptUrl);
|
2020-05-14 16:26:21 +08:00
|
|
|
|
}
|
2020-08-14 07:13:28 +08:00
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
public IDictionary<string, string[]> GetAllIcons()
|
2020-08-14 07:13:28 +08:00
|
|
|
|
{
|
2020-12-08 10:01:43 +08:00
|
|
|
|
return IconStore.GetAllIconNames();
|
2020-08-16 22:51:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
public bool IconExists(string theme = "", string type = "")
|
2020-08-16 22:51:24 +08:00
|
|
|
|
{
|
2020-12-08 10:01:43 +08:00
|
|
|
|
var icon = IconStore.GetIcon(type, theme);
|
2020-08-14 07:13:28 +08:00
|
|
|
|
|
2020-12-08 10:01:43 +08:00
|
|
|
|
return !string.IsNullOrEmpty(icon);
|
2020-08-14 07:13:28 +08:00
|
|
|
|
}
|
2020-05-14 16:26:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|