2 |
3 | @Title
4 |
5 |
6 | Please take our
7 | brief survey
8 |
9 | and tell us what you think.
10 |
11 |
12 | @code {
13 | // Demonstrates how a parent component can supply parameters
14 | [Parameter]
15 | public string Title { get; set; }
16 | }
17 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Models/ElementApiMethod.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Threading.Tasks;
8 |
9 | namespace SvgBlazor.Docs.Models
10 | {
11 | public class ElementApiMethod : IElementApiElement
12 | {
13 | public string Name { get; set; }
14 |
15 | public string ReturnValue { get; set; }
16 |
17 | public IEnumerable Parameters { get; set; }
18 |
19 | public string Description { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/SvgValue/Examples/SvgValueImplicitOperatorsExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class SvgValueImplicitOperatorsExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | SvgValue svgValueInt = 10;
15 | SvgValue svgValueFloat = 10F;
16 | SvgValue svgValueString = "10";
17 | /* #example-code-end */
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SvgBlazor/Interfaces/ISvgAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Components.Rendering;
5 |
6 | namespace SvgBlazor.Interfaces
7 | {
8 | ///
9 | /// The interface that represents the SvgAttribute.
10 | ///
11 | public interface ISvgAttribute
12 | {
13 | ///
14 | /// Adds attributes to the RenderTreeBuilder.
15 | ///
16 | /// The RenderTreeBuilder used to build this attibute.
17 | public void RenderAttributes(RenderTreeBuilder builder);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/SvgBlazor/Enums/FillRule.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace SvgBlazor
7 | {
8 | ///
9 | /// The rule that determines which parts of the canvas are contained within the shape.
10 | ///
11 | public enum FillRule
12 | {
13 | ///
14 | /// Non zero fill rule.
15 | ///
16 | [Description("nonzero")]
17 | NonZero,
18 |
19 | ///
20 | /// Even odd fill rule.
21 | ///
22 | [Description("evenodd")]
23 | EvenOdd,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Components/ExampleComponent.razor:
--------------------------------------------------------------------------------
1 | @using SvgBlazor.Docs.Interfaces
2 |
3 |
4 |
5 |
6 |
7 | @code {
8 | [Parameter]
9 | public IExampleCode ExampleCode { get; set; }
10 |
11 | [Parameter]
12 | public int Width { get; set; } = 200;
13 |
14 | [Parameter]
15 | public int Height { get; set; } = 200;
16 |
17 | private SvgComponent svg;
18 |
19 | protected override void OnAfterRender(bool firstRender)
20 | {
21 | if (firstRender)
22 | {
23 | ExampleCode?.Example(svg);
24 | }
25 | }
26 |
27 | private string GetItemName() => ExampleCode?.GetType().Name;
28 | }
29 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Text/Examples/TextBasicExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class TextBasicExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var text = new SvgText
15 | {
16 | X = 10,
17 | Y = 20,
18 | Text = "This is just awesome!",
19 | };
20 | /* #example-code-end */
21 | svg.Add(text);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/SvgValue/SvgValuePage.razor:
--------------------------------------------------------------------------------
1 | @page "/elements/svgvalue"
2 | @using SvgBlazor.Docs.Components
3 | @using SvgBlazor.Docs.Extensions
4 |
5 | SvgValue
6 |
@( typeof(SvgValue).GetDocumentation() )
7 |
The simplest way to create a SvgValue is to use the provided implicit operators:
8 |
9 |
In the above example a SvgValue from int, float and string will be created respectively.
10 |
Please note that when using implicit operator initialization, no unit type will be added. If you wish to provide a unit type, use one of the dedicated constructors:
11 |
12 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/SvgComponent/Examples/SvgComponentSimpleAddExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class SvgComponentSimpleAddExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var circle = new SvgCircle
15 | {
16 | CenterX = 50,
17 | CenterY = 50,
18 | Radius = 25,
19 | };
20 |
21 | svg.Add(circle);
22 | /* #example-code-end */
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Text/Examples/TextRotateExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class TextRotateExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var text = new SvgText
15 | {
16 | X = 10,
17 | Y = 20,
18 | Text = "Whoa! Nice rotation!",
19 | Rotate = "20 0 20",
20 | };
21 | /* #example-code-end */
22 | svg.Add(text);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Circle/Examples/CircleExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class CircleExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var circle = new SvgCircle
14 | {
15 | CenterX = 50,
16 | CenterY = 50,
17 | Radius = 50,
18 | Fill = new SvgFill { Color = "#27ba0d" },
19 | };
20 | /* #example-code-end */
21 |
22 | svg.Add(circle);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Line/Examples/LineExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class LineExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var line = new SvgLine
15 | {
16 | X1 = 0,
17 | Y1 = 0,
18 | X2 = 200,
19 | Y2 = 200,
20 | Stroke = new SvgStroke { Color = "red" },
21 | };
22 | /* #example-code-end */
23 |
24 | svg.Add(line);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Text/Examples/TextShiftXYExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class TextShiftXYExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var text = new SvgText
15 | {
16 | X = 10,
17 | Y = 20,
18 | Text = "That's a nice shift!",
19 | ShiftX = 20,
20 | ShiftY = 10,
21 | };
22 | /* #example-code-end */
23 | svg.Add(text);
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/SvgBlazor/Enums/TextLengthAdjust.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace SvgBlazor
7 | {
8 | ///
9 | /// The lengthAdjust attribute sets how the text is stretched to the length specified by the textLength attribute.
10 | ///
11 | public enum TextLengthAdjust
12 | {
13 | ///
14 | /// Adjusts only the spacing between the glyphs.
15 | ///
16 | [Description("spacing")]
17 | Spacing,
18 |
19 | ///
20 | /// Adjust spacing and glyph size.
21 | ///
22 | [Description("spacingAndGlyphs")]
23 | SpacingAndGlyphs,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Rect/Examples/RectExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class RectExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var rect = new SvgRect
15 | {
16 | X = 10,
17 | Y = 20,
18 | Width = 180,
19 | Height = 180,
20 | Fill = new SvgFill { Color = "purple" },
21 | };
22 | /* #example-code-end */
23 |
24 | svg.Add(rect);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/wwwroot/css/atom-one-dark.min.css:
--------------------------------------------------------------------------------
1 | pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#abb2bf;background:#282c34}.hljs-comment,.hljs-quote{color:#5c6370;font-style:italic}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#c678dd}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e06c75}.hljs-literal{color:#56b6c2}.hljs-addition,.hljs-attribute,.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#98c379}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#d19a66}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#61aeee}.hljs-built_in,.hljs-class .hljs-title,.hljs-title.class_{color:#e6c07b}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-link{text-decoration:underline}
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Ellipse/Examples/EllipseExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class EllipseExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var ellipse = new SvgEllipse
15 | {
16 | CenterX = 100,
17 | CenterY = 100,
18 | RadiusX = 40,
19 | RadiusY = 20,
20 | Fill = new SvgFill { Color = "orange" },
21 | };
22 | /* #example-code-end */
23 |
24 | svg.Add(ellipse);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/.github/workflows/push-tag-release.yml:
--------------------------------------------------------------------------------
1 | name: Push tag release
2 |
3 | on:
4 | push:
5 | tags:
6 | - v[0-9].[0-9]+.[0-9]+
7 |
8 | jobs:
9 | get-version-from-tag:
10 | runs-on: ubuntu-latest
11 | outputs:
12 | version: ${{ steps.get_version.outputs.VERSION }}
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Get the version
16 | id: get_version
17 | run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
18 | - name: Print info about the version
19 | run: echo Version ${{ steps.get_version.outputs.VERSION }}
20 |
21 | cd:
22 | needs: get-version-from-tag
23 | uses: Approxoft/SvgBlazor/.github/workflows/base-workflow.yml@main
24 | with:
25 | publish-nuget: true
26 | version: ${{ needs.get-version-from-tag.outputs.version }}
27 | secrets:
28 | nuget-api-key: ${{ secrets.NUGET_API_KEY }}
29 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Text/Examples/TextLengthAdjustSpacingExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class TextLengthAdjustSpacingExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var text = new SvgText
15 | {
16 | X = 10,
17 | Y = 20,
18 | Text = "I wish there was more space here...",
19 | LengthAdjust = TextLengthAdjust.Spacing,
20 | TextLength = 200,
21 | };
22 | /* #example-code-end */
23 | svg.Add(text);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs.Generator/ProjectPaths.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace SvgBlazor.Docs.Generator
12 | {
13 | public class ProjectPaths
14 | {
15 | public const string ExampleIdentifier = "Example";
16 |
17 | private const string DocsDirectory = "SvgBlazor.Docs";
18 |
19 | private const string DocsPagesDirectory = "Pages";
20 |
21 | public static string SourcePath { get; set; }
22 |
23 | public static string DocsDirectoryPath => Path.Combine(SourcePath, DocsDirectory);
24 |
25 | public static string PagesDirectoryPath => Path.Combine(DocsDirectoryPath, DocsPagesDirectory);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Text/Examples/TextLengthAdjustSpacingAndGlyphsExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class TextLengthAdjustSpacingAndGlyphsExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var text = new SvgText
15 | {
16 | X = 10,
17 | Y = 20,
18 | Text = "I wish there was more space here...",
19 | LengthAdjust = TextLengthAdjust.SpacingAndGlyphs,
20 | TextLength = 200,
21 | };
22 | /* #example-code-end */
23 | svg.Add(text);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Stroke/Examples/StrokeBasicExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class StrokeBasicExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var stroke = new SvgStroke
14 | {
15 | Color = "pink",
16 | Width = 15,
17 | };
18 | /* #example-code-end */
19 |
20 | var circle = new SvgCircle
21 | {
22 | CenterX = 100,
23 | CenterY = 100,
24 | Radius = 75,
25 | Stroke = stroke,
26 | };
27 |
28 | svg.Add(circle);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/Elements/SvgUseTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Bunit;
3 | using Xunit;
4 |
5 | namespace SvgBlazor.Tests.Elements
6 | {
7 | public class SvgUseTest : TestContextWithSvgBlazorJsModule
8 | {
9 | [Fact]
10 | public void RendersSvgWithDuplicatedElement()
11 | {
12 | var comp = RenderComponent();
13 |
14 | comp.InvokeAsync(() => comp.Instance.Add(new SvgUse
15 | {
16 | X = 20,
17 | Y = 30,
18 | Element = new SvgCircle { Id = "circleId", CenterX = 10, CenterY = 10 },
19 | Fill = new SvgFill { Color = "blue" },
20 | }));
21 |
22 | var element = comp.Find("use");
23 | Assert.Contains("#circleId", element.GetAttribute("href"));
24 | Assert.Contains("20", element.GetAttribute("x"));
25 | Assert.Contains("30", element.GetAttribute("y"));
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/SvgBlazor/Enums/TextAnchor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System.ComponentModel;
5 |
6 | namespace SvgBlazor
7 | {
8 | ///
9 | /// The anchor of the text.
10 | ///
11 | public enum TextAnchor
12 | {
13 | ///
14 | /// The given x and y coordinates will become the start location of the text.
15 | ///
16 | [Description("start")]
17 | Start,
18 |
19 | ///
20 | /// The given x and y coordinates will become the middle location of the text.
21 | ///
22 | [Description("middle")]
23 | Middle,
24 |
25 | ///
26 | /// The given x and y coordinates will become the end location of the text.
27 | ///
28 | [Description("end")]
29 | End,
30 | }
31 | }
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/Base/TestContextWithSvgBlazorJsModule.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Drawing;
6 | using Bunit;
7 |
8 | namespace SvgBlazor.Tests
9 | {
10 | public class TestContextWithSvgBlazorJsModule : TestContext
11 | {
12 | public TestContextWithSvgBlazorJsModule()
13 | {
14 | SetupJSInterop();
15 | }
16 |
17 | private void SetupJSInterop()
18 | {
19 | JSInterop
20 | .SetupModule("./_content/SvgBlazor/SvgBlazor.js")
21 | .Setup("BBox", _ => true)
22 | .SetResult(new RectangleF
23 | {
24 | X = 0,
25 | Y = 0,
26 | Width = 10,
27 | Height = 10,
28 | });
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/Extensions/EnumExtensionTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.ComponentModel;
6 | using Bunit;
7 | using SvgBlazor.Extensions;
8 | using Xunit;
9 |
10 | namespace SvgBlazor.Tests.Extensions
11 | {
12 | public class EnumExtensionTests
13 | {
14 | [Fact]
15 | public void ReturnsString()
16 | {
17 | Assert.Equal("dumb", Dummy.Dumb.ToDescriptionString());
18 | Assert.Equal("dumber", Dummy.Dumber.ToDescriptionString());
19 | Assert.Equal("EvenMoreDumber", Dummy.EvenMoreDumber.ToDescriptionString());
20 | }
21 |
22 | private enum Dummy
23 | {
24 | [Description("dumb")]
25 | Dumb,
26 |
27 | [Description("dumber")]
28 | Dumber,
29 | EvenMoreDumber,
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.cs]
2 |
3 | # SA1600: Elements should be documented
4 | dotnet_diagnostic.SA1600.severity = silent
5 |
6 | # SA1200: Using directives should be placed correctly
7 | dotnet_diagnostic.SA1200.severity = silent
8 |
9 | # SA1101: Prefix local calls with this
10 | dotnet_diagnostic.SA1101.severity = silent
11 |
12 | # SA1309: Field names should not begin with underscore
13 | dotnet_diagnostic.SA1309.severity = silent
14 |
15 | [*.cshtml.cs]
16 |
17 | # SA1649: File name should match first type name
18 | dotnet_diagnostic.SA1649.severity = silent
19 |
20 | [**/Migrations/**.cs]
21 |
22 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.ReadabilityRules'
23 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.ReadabilityRules.severity = silent
24 |
25 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules'
26 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = silent
--------------------------------------------------------------------------------
/src/SvgBlazor/Enums/StrokeLineCapStyle.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.ComponentModel;
6 |
7 | namespace SvgBlazor
8 | {
9 | ///
10 | /// The stroke's line cap styles.
11 | ///
12 | public enum StrokeLineCapStyle
13 | {
14 | ///
15 | /// The end of each subpath will not be extended beyond its two endpoints.
16 | ///
17 | [Description("butt")]
18 | Butt,
19 |
20 | ///
21 | /// The end of each subpath will be extended by a rectangle.
22 | ///
23 | [Description("square")]
24 | Square,
25 |
26 | ///
27 | /// The end of each subpath will be extended by a half circle.
28 | ///
29 | [Description("round")]
30 | Round,
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/Elements/SvgGTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System.Drawing;
5 | using Xunit;
6 | using Bunit;
7 |
8 | namespace SvgBlazor.Tests
9 | {
10 | public class SvgGTest : TestContextWithSvgBlazorJsModule
11 | {
12 | [Fact]
13 | public void RendersSvgGWithChildContent()
14 | {
15 | var comp = RenderComponent();
16 |
17 | var group = new SvgG();
18 | group.Add(new ChildElement());
19 | comp.InvokeAsync(() => comp.Instance.Add(group));
20 |
21 | comp.Render();
22 |
23 | var element = comp.Find("g");
24 | Assert.Equal("tester", element.Children[0].TagName);
25 | }
26 |
27 | private class ChildElement : SvgElement
28 | {
29 | public override string Tag() => "tester";
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Fill/FillPage.razor:
--------------------------------------------------------------------------------
1 | @page "/attributes/fill"
2 | @using SvgBlazor.Docs.Extensions
3 |
4 | Fill
5 |
6 |
7 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Stroke/Examples/StrokeOpacityExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class StrokeOpacityExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var stroke = new SvgStroke
14 | {
15 | Color = "yellow",
16 | Width = 15,
17 | Opacity = 0.5f,
18 | };
19 | /* #example-code-end */
20 |
21 | var circle = new SvgCircle
22 | {
23 | CenterX = 100,
24 | CenterY = 100,
25 | Radius = 75,
26 | Stroke = stroke,
27 | };
28 |
29 | svg.Add(circle);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Path/Examples/PathExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class PathExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var line = new SvgPath()
15 | {
16 | Path = "M 10, 30 " +
17 | "A 20, 20 0, 0, 1 50, 30 " +
18 | "A 20, 20 0, 0, 1 90, 30 " +
19 | "Q 90, 60 50, 90 " +
20 | "Q 10, 60 10, 30 z",
21 | Fill = new SvgFill { Color = "pink" },
22 | Stroke = new SvgStroke { Color = "red" },
23 | };
24 | /* #example-code-end */
25 |
26 | svg.Add(line);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:36489",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "SvgBlazor.Docs": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
23 | "applicationUrl": "http://localhost:51383",
24 | "environmentVariables": {
25 | "ASPNETCORE_ENVIRONMENT": "Development"
26 | }
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Stroke/Examples/Dash/StrokeDashArrayExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class StrokeDashArrayExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var dashArrayStroke = new SvgStroke
14 | {
15 | Color = "green",
16 | Width = 15,
17 | DashArray = "1 2",
18 | };
19 | /* #example-code-end */
20 |
21 | var circle = new SvgCircle
22 | {
23 | CenterX = 100,
24 | CenterY = 100,
25 | Radius = 75,
26 | Stroke = dashArrayStroke,
27 | };
28 |
29 | svg.Add(circle);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/Components/SvgComponentTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Drawing;
6 | using Bunit;
7 | using Xunit;
8 |
9 | namespace SvgBlazor.Tests.Components
10 | {
11 | public class SvgComponentTests : TestContextWithSvgBlazorJsModule
12 | {
13 | [Fact]
14 | public async void CalculatesBoudingBox()
15 | {
16 | var comp = RenderComponent();
17 | var circle = new SvgCircle
18 | {
19 | CenterX = 1,
20 | CenterY = 2,
21 | Radius = 3,
22 | };
23 |
24 | await comp.InvokeAsync(() => comp.Instance.Add(circle));
25 |
26 | comp.Render();
27 |
28 | var bbox = await comp.Instance.GetBoundingBox(circle);
29 | Assert.Equal(new RectangleF(0, 0, 10, 10), bbox);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Stroke/Examples/Dash/StrokeDashOffsetExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class StrokeDashOffsetExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var dashOffsetStroke = new SvgStroke
14 | {
15 | Color = "blue",
16 | Width = 10,
17 | DashArray = "50",
18 | DashOffset = 50,
19 | };
20 | /* #example-code-end */
21 | var line = new SvgLine
22 | {
23 | X1 = 20,
24 | Y1 = 20,
25 | X2 = 175,
26 | Y2 = 20,
27 | Stroke = dashOffsetStroke,
28 | };
29 |
30 | svg.Add(line);
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/G/Examples/GExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class GExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var group = new SvgG
15 | {
16 | Fill = new SvgFill { Color = "red" },
17 | };
18 |
19 | group.Add(new SvgCircle
20 | {
21 | CenterX = 50,
22 | CenterY = 50,
23 | Radius = 50,
24 | });
25 |
26 | group.Add(new SvgCircle
27 | {
28 | CenterX = 150,
29 | CenterY = 150,
30 | Radius = 50,
31 | });
32 | /* #example-code-end */
33 |
34 | svg.Add(group);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Net.Http;
7 | using System.Reflection;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
11 | using Microsoft.Extensions.Configuration;
12 | using Microsoft.Extensions.DependencyInjection;
13 | using Microsoft.Extensions.Logging;
14 | using SvgBlazor.Docs.Extensions;
15 |
16 | namespace SvgBlazor.Docs
17 | {
18 | public class Program
19 | {
20 | public static async Task Main(string[] args)
21 | {
22 | var builder = WebAssemblyHostBuilder.CreateDefault(args);
23 | builder.RootComponents.Add("#app");
24 |
25 | builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
26 |
27 | await builder.Build().RunAsync();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Svg/Examples/SvgExample.razor:
--------------------------------------------------------------------------------
1 |
2 |
3 | @code {
4 | SvgComponent svgref;
5 |
6 | protected override void OnAfterRender(bool firstRender)
7 | {
8 | if (firstRender)
9 | {
10 | var svg1 = new Svg
11 | {
12 | X = 0,
13 | Y = 0,
14 | Width = 400,
15 | Height = 400,
16 | Fill = new SvgFill { Color = "red" },
17 | };
18 |
19 | svg1.Add(new SvgCircle { CenterX = 200, CenterY = 200, Radius = 100, });
20 |
21 | svgref.Add(svg1);
22 |
23 | var svg2 = new Svg
24 | {
25 | X = 0,
26 | Y = 0,
27 | Width = 400,
28 | Height = 400,
29 | Fill = new SvgFill { Color = "blue" },
30 | };
31 |
32 | svg2.Add(new SvgRect { X = 50, Y = 50, Width = 100, Height = 100, });
33 |
34 | svgref.Add(svg2);
35 | }
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/SvgComponent/SvgComponentPage.razor:
--------------------------------------------------------------------------------
1 | @page "/elements/svgcomponent"
2 | @using SvgBlazor.Docs.Pages.Elements.SvgComponent.Examples
3 |
4 | SvgComponent
5 |
6 |
SvgComponent can be created as follows:
7 |
8 |
9 |
Adding elements
10 |
Adding an element is done by creating one of the available elements and then passing it to the Add method on an existing SvgComponent reference:
11 |
12 |
13 |
Removing elements
14 |
Removing an element is done by passing its reference to the Remove method on an existing SvgComponent reference:
15 |
16 |
17 |
BoudingBox calculation
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Polygon/Examples/PolygonExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Drawing;
7 | using SvgBlazor.Docs.Interfaces;
8 |
9 | namespace SvgBlazor.Docs.Examples
10 | {
11 | public class PolygonExample : IExampleCode
12 | {
13 | public void Example(SvgComponent svg)
14 | {
15 | /* #example-code-start */
16 | var polygon = new SvgPolygon
17 | {
18 | Points = new List
19 | {
20 | new PointF(160, 200),
21 | new PointF(40, 200),
22 | new PointF(0, 80),
23 | new PointF(100, 0),
24 | new PointF(200, 80),
25 | },
26 | Fill = new SvgFill { Color = "#aabbcc" },
27 | };
28 | /* #example-code-end */
29 |
30 | svg.Add(polygon);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/SvgComponent/Examples/SvgComponentRemoveExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Components;
6 | using Microsoft.AspNetCore.Components.Web;
7 | using SvgBlazor.Docs.Interfaces;
8 |
9 | namespace SvgBlazor.Docs.Examples
10 | {
11 | public class SvgComponentRemoveExample : IExampleCode
12 | {
13 | public void Example(SvgComponent svg)
14 | {
15 | /* #example-code-start */
16 | var text = new SvgText
17 | {
18 | X = 35,
19 | Y = 50,
20 | Text = "Click me to remove",
21 | Stroke = new SvgStroke { Color = "red", },
22 | };
23 |
24 | text.OnClick = EventCallback.Factory.Create(text, (args) =>
25 | {
26 | svg.Remove(text);
27 | });
28 |
29 | svg.Add(text);
30 | /* #example-code-end */
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/SvgBlazor/Elements/SvgG.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Drawing;
6 | using Microsoft.AspNetCore.Components;
7 | using Microsoft.AspNetCore.Components.Rendering;
8 |
9 | namespace SvgBlazor
10 | {
11 | ///
12 | /// The SvgG class is responsible for providing the SVG group element.
13 | ///
14 | public partial class SvgG : SvgContainer
15 | {
16 | ///
17 | /// Initializes a new instance of the class.
18 | ///
19 | public SvgG()
20 | {
21 | }
22 |
23 | ///
24 | /// Initializes a new instance of the class with provided SvgG.
25 | ///
26 | /// Initial SvgG.
27 | public SvgG(SvgG svgg)
28 | : base(svgg)
29 | {
30 | }
31 |
32 | ///
33 | public override string Tag() => "g";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/SvgBlazor/Extensions/EnumExtension.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.ComponentModel;
6 |
7 | namespace SvgBlazor.Extensions
8 | {
9 | ///
10 | /// Extensions for enum.
11 | ///
12 | public static class EnumExtension
13 | {
14 | ///
15 | /// Gets the DescriptionAttribute of the enum.
16 | ///
17 | /// The enum to get the description.
18 | /// The DescriptionAttribute of the enum.
19 | public static string ToDescriptionString(this Enum en)
20 | {
21 | var attributes = (DescriptionAttribute[])en
22 | .GetType()
23 | .GetField(en.ToString())
24 | .GetCustomAttributes(typeof(DescriptionAttribute), false);
25 |
26 | return attributes.Length > 0
27 | ? attributes[0].Description
28 | : en.ToString();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Cosmopolex
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/tests/SvgBlazor.Docs.Tests/SvgBlazor.Docs.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 | all
16 |
17 |
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 | all
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/Elements/SvgPathTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using Bunit;
6 | using Xunit;
7 |
8 | namespace SvgBlazor.Tests.Elements
9 | {
10 | public class SvgPathTest : TestContextWithSvgBlazorJsModule
11 | {
12 | [Fact]
13 | public void RendersAttributes()
14 | {
15 | var comp = RenderComponent();
16 |
17 | comp.InvokeAsync(() => comp.Instance.Add(new SvgPath
18 | {
19 | Path = "M10 10",
20 | }));
21 |
22 | comp.Render();
23 |
24 | var element = comp.Find("path");
25 | Assert.Contains("M10 10", element.GetAttribute("d"));
26 | }
27 |
28 | [Fact]
29 | public void CopyConstructor()
30 | {
31 | var e1 = new SvgPath()
32 | {
33 | Path = "M10 10",
34 | };
35 |
36 | var e2 = new SvgPath(e1);
37 |
38 | Assert.Equal("M10 10", e2.Path);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/SvgBlazor/Interfaces/ISvgContainer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Components.Rendering;
6 | using Microsoft.AspNetCore.Components.Web;
7 |
8 | namespace SvgBlazor.Interfaces
9 | {
10 | ///
11 | /// Provides methods to manage container elements.
12 | ///
13 | public interface ISvgContainer : ISvgElement
14 | {
15 | ///
16 | /// Adds the given element to the container.
17 | ///
18 | /// Element to be added.
19 | /// The container to which the element was added.
20 | ISvgContainer Add(ISvgElement element);
21 |
22 | ///
23 | /// Removes the given element from the container.
24 | ///
25 | /// Element to be removed.
26 | /// The container from which the element was removed.
27 | ISvgContainer Remove(ISvgElement element);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/SvgComponent/Examples/SvgComponentGetBoundingBoxExample.razor:
--------------------------------------------------------------------------------
1 | @using System.Drawing
2 |
3 |
4 |
5 |
6 |
7 |
12 |
Bounding box: @(boundingBox.IsEmpty ? "Click the button to calculate" : boundingBox)
13 |
14 |
15 | @code
16 | {
17 | private RectangleF boundingBox;
18 |
19 | private SvgComponent svg;
20 | private SvgCircle circle;
21 |
22 | protected override void OnAfterRender(bool firstRender)
23 | {
24 | if (firstRender)
25 | {
26 | circle = new SvgCircle
27 | {
28 | CenterX = 50,
29 | CenterY = 50,
30 | Radius = 25,
31 | };
32 |
33 | svg.Add(circle);
34 | }
35 | }
36 |
37 | private async Task OnButtonClickedCalculateBoundingBox()
38 | {
39 | boundingBox = await svg.GetBoundingBox(circle);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/wwwroot/css/open-iconic/ICON-LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/tests/SvgBlazor.Docs.Generator.Tests/SvgBlazor.Docs.Generator.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 | all
16 |
17 |
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 | all
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/tests/SvgBlazor.Tests/SvgBlazor.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 | all
16 |
17 |
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 | all
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Fill/Examples/FillRuleEvenOddExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class FillRuleEvenOddExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var shape1 = new SvgPath
14 | {
15 | Path = "M 20 180 H 180 L 100 20 Z M 80 148 H 120 L 100 108 Z",
16 | Fill = new SvgFill { Rule = FillRule.EvenOdd },
17 | Stroke = new SvgStroke { Color = "grey" },
18 | };
19 |
20 | var shape2 = new SvgPath
21 | {
22 | Path = "M 220 180 H 380 L 300 20 z M 320 147 H 280 L 300 108 Z",
23 | Fill = new SvgFill { Rule = FillRule.EvenOdd },
24 | Stroke = new SvgStroke { Color = "grey" },
25 | };
26 | /* #example-code-end */
27 |
28 | svg.Add(shape1);
29 | svg.Add(shape2);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Attributes/Fill/Examples/FillRuleNonZeroExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using SvgBlazor.Docs.Interfaces;
5 |
6 | namespace SvgBlazor.Docs.Examples
7 | {
8 | public class FillRuleNonZeroExample : IExampleCode
9 | {
10 | public void Example(SvgComponent svg)
11 | {
12 | /* #example-code-start */
13 | var shape1 = new SvgPath
14 | {
15 | Path = "M 20 180 H 180 L 100 20 Z M 80 148 H 120 L 100 108 Z",
16 | Fill = new SvgFill { Rule = FillRule.NonZero },
17 | Stroke = new SvgStroke { Color = "grey" },
18 | };
19 |
20 | var shape2 = new SvgPath
21 | {
22 | Path = "M 220 180 H 380 L 300 20 z M 320 147 H 280 L 300 108 Z",
23 | Fill = new SvgFill { Rule = FillRule.NonZero },
24 | Stroke = new SvgStroke { Color = "grey" },
25 | };
26 | /* #example-code-end */
27 |
28 | svg.Add(shape1);
29 | svg.Add(shape2);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/SvgValue/Examples/SvgValueUnitTypeExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using SvgBlazor.Docs.Interfaces;
6 |
7 | namespace SvgBlazor.Docs.Examples
8 | {
9 | public class SvgValueUnitTypeExample : IExampleCode
10 | {
11 | public void Example(SvgComponent svg)
12 | {
13 | /* #example-code-start */
14 | var rectPercentage = new SvgRect
15 | {
16 | X = 0,
17 | Y = 0,
18 | Height = 50,
19 | Width = new SvgValue(50F, ValueUnit.Percentage),
20 | Fill = new SvgFill { Color = "blue" },
21 | };
22 |
23 | var rectPixels = new SvgRect
24 | {
25 | X = 0,
26 | Y = 100,
27 | Height = 50,
28 | Width = new SvgValue(50F, ValueUnit.Px),
29 | Fill = new SvgFill { Color = "red" },
30 | };
31 | /* #example-code-end */
32 |
33 | svg.Add(rectPercentage);
34 | svg.Add(rectPixels);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # These are some examples of commonly ignored file patterns.
2 | # You should customize this list as applicable to your project.
3 | # Learn more about .gitignore:
4 | # https://www.atlassian.com/git/tutorials/saving-changes/gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 | *.userprefs
13 |
14 | # Node artifact files
15 | node_modules/
16 | dist/
17 |
18 | # Compiled Java class files
19 | *.class
20 |
21 | # Compiled Python bytecode
22 | *.py[cod]
23 |
24 | # Log files
25 | *.log
26 |
27 | # Package files
28 | *.jar
29 |
30 | # Maven
31 | target/
32 | dist/
33 |
34 | # JetBrains IDE
35 | .idea/
36 |
37 | # Unit test reports
38 | TEST*.xml
39 |
40 | # Generated by MacOS
41 | .DS_Store
42 |
43 | # Generated by Windows
44 | Thumbs.db
45 |
46 | # Applications
47 | *.app
48 | *.exe
49 | *.war
50 |
51 | # Large media files
52 | *.mp4
53 | *.tiff
54 | *.avi
55 | *.flv
56 | *.mov
57 | *.wmv
58 |
59 | # Visual Studio files and outputs
60 | .vs/
61 | bin/
62 | obj/
63 |
64 | # Visual Studio Code
65 | .vscode/*
66 | !.vscode/settings.json
67 | !.vscode/tasks.json
68 | !.vscode/launch.json
69 | !.vscode/extensions.json
70 | *.code-workspace
71 |
72 | # Local History for Visual Studio Code
73 | .history/
74 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Index.razor:
--------------------------------------------------------------------------------
1 | @page "/"
2 | @inject IJSRuntime JS
3 | @using Markdig
4 | @using System.IO;
5 | @((MarkupString)_htmlReadme)
6 |
7 | @code {
8 | string _htmlReadme;
9 |
10 | protected override void OnInitialized()
11 | {
12 | var readmeContent = loadFromResources("README.md");
13 |
14 | if (!String.IsNullOrEmpty(readmeContent))
15 | {
16 | _htmlReadme = Markdown.ToHtml(readmeContent);
17 | }
18 | }
19 |
20 | private string loadFromResources(string name)
21 | {
22 | var assembly = typeof(Index).Assembly;
23 | var resourceName = assembly
24 | .GetManifestResourceNames()
25 | .FirstOrDefault(x => x.Contains(name));
26 |
27 | if (resourceName is null)
28 | {
29 | return String.Empty;
30 | }
31 |
32 | using var resourceStream = assembly.GetManifestResourceStream(resourceName);
33 | using var reader = new StreamReader(resourceStream);
34 |
35 | return reader.ReadToEnd();
36 | }
37 |
38 | protected override async Task OnAfterRenderAsync(bool firstRender)
39 | {
40 | if (firstRender)
41 | {
42 | await JS.InvokeVoidAsync("highlightAllCode");
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs.Generator/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Diagnostics;
6 | using System.IO;
7 |
8 | namespace SvgBlazor.Docs.Generator
9 | {
10 | public class Program
11 | {
12 | public static int Main(string[] args)
13 | {
14 | if (args.Length == 1)
15 | {
16 | ProjectPaths.SourcePath = Path.Combine(args[0], "src");
17 | }
18 | else
19 | {
20 | Console.WriteLine($"SvgBlazor.Docs.Generator failed: no solution path provided!");
21 | return 1;
22 | }
23 |
24 | try
25 | {
26 | var stopWatch = Stopwatch.StartNew();
27 |
28 | new ExamplesCode().Generate();
29 |
30 | Console.WriteLine($"SvgBlazor.Docs.Generator completed in {stopWatch.ElapsedMilliseconds} msecs");
31 |
32 | return 0;
33 | }
34 | catch (Exception ex)
35 | {
36 | Console.WriteLine($"SvgBlazor.Docs.Generator failed: {ex}");
37 | return 1;
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Extensions/ReflectionTypesExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Approxoft. All rights reserved.
2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Text.RegularExpressions;
10 | using System.Xml;
11 | using SvgBlazor.Docs.Models;
12 |
13 | namespace SvgBlazor.Docs.Extensions
14 | {
15 | public static class ReflectionTypesExtensions
16 | {
17 | private static readonly XmlDoc XmlDocumentation = new (Assembly.GetExecutingAssembly());
18 |
19 | public static string GetDocumentation(this Type type) =>
20 | XmlDocumentation.GetDocumentation(type);
21 |
22 | public static string GetDocumentation(this PropertyInfo propertyInfo) =>
23 | XmlDocumentation.GetDocumentation(propertyInfo);
24 |
25 | public static string GetSignature(this MethodInfo methodInfo) =>
26 | XmlDocumentation.GetSignature(methodInfo);
27 |
28 | public static string GetDocumentation(this MethodInfo methodInfo) =>
29 | XmlDocumentation.GetDocumentation(methodInfo);
30 |
31 | public static XmlDoc GetXmlDoc() => XmlDocumentation;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/SvgBlazor.Docs/Pages/Elements/Text/TextPage.razor:
--------------------------------------------------------------------------------
1 | @page "/elements/text"
2 |
3 | Text
4 |
5 |
6 |
7 |
Shift
8 |
To shift the position of the text assign values to ShiftX and ShiftY properties:
9 |
10 |
11 |
Rotate
12 |
Text rotation can be achieved by assigning properly formatted string to Rotate property:
13 |
14 |
15 |
LengthAdjust
16 |
The following examples show how to control the text stretch based on its length: