From 37884f1054a4d8974f442e0ea4dd01bc98fc7e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Sun, 23 Oct 2022 16:56:17 +0200 Subject: [PATCH] Added Figma tool --- .../AlohaKit.UI.Figma.csproj | 61 ++ src/AlohaKit.UI.Figma/App.xaml | 14 + src/AlohaKit.UI.Figma/App.xaml.cs | 12 + src/AlohaKit.UI.Figma/AppShell.xaml | 14 + src/AlohaKit.UI.Figma/AppShell.xaml.cs | 10 + .../IsGeneratingToVisibleConverter.cs | 19 + .../Figma/Converters/ElipseConverter.cs | 96 +++ .../Figma/Converters/FrameConverter.cs | 102 +++ .../Figma/Converters/ImageConverter.cs | 111 +++ .../Figma/Converters/LineConverter.cs | 22 + .../Figma/Converters/PolygonConverter.cs | 22 + .../Figma/Converters/RectangleConverter.cs | 96 +++ .../Figma/Converters/TextConverter.cs | 70 ++ .../Extensions/CodeGenerationExtensions.cs | 174 +++++ .../Figma/Extensions/FigmaExtensions.cs | 136 ++++ .../Figma/FigmaApplication.cs | 12 + src/AlohaKit.UI.Figma/Figma/FigmaDelegate.cs | 77 ++ .../Figma/Helpers/CodeGenerationHelpers.cs | 65 ++ .../CodePropertyConfigure.cs | 14 + src/AlohaKit.UI.Figma/MainPage.xaml | 152 ++++ src/AlohaKit.UI.Figma/MainPage.xaml.cs | 10 + src/AlohaKit.UI.Figma/MauiProgram.cs | 25 + .../Platforms/Android/AndroidManifest.xml | 6 + .../Platforms/Android/MainActivity.cs | 11 + .../Platforms/Android/MainApplication.cs | 16 + .../Android/Resources/values/colors.xml | 6 + .../Platforms/MacCatalyst/AppDelegate.cs | 10 + .../Platforms/MacCatalyst/FolderPicker.cs | 83 ++ .../Platforms/MacCatalyst/Info.plist | 30 + .../Platforms/MacCatalyst/Program.cs | 16 + src/AlohaKit.UI.Figma/Platforms/Tizen/Main.cs | 17 + .../Platforms/Tizen/tizen-manifest.xml | 15 + .../Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 24 + .../Platforms/Windows/FolderPicker.cs | 26 + .../Platforms/Windows/Package.appxmanifest | 43 ++ .../Platforms/Windows/app.manifest | 15 + .../Platforms/iOS/AppDelegate.cs | 10 + .../Platforms/iOS/Info.plist | 32 + .../Platforms/iOS/Program.cs | 16 + .../Properties/launchSettings.json | 8 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107136 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111028 bytes .../Resources/Images/dotnet_bot.svg | 93 +++ .../Resources/Raw/AboutAssets.txt | 15 + .../Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 44 ++ .../Resources/Styles/Styles.xaml | 403 ++++++++++ .../Services/DialogService.cs | 28 + .../Services/IFolderPicker.cs | 7 + .../ViewModels/MainViewModel.cs | 179 +++++ src/AlohaKit.UI.sln | 31 +- src/AlohaKit.UI/Controls/Element.cs | 2 + src/AlohaKit.UI/Controls/Path.cs | 24 +- src/FigmaSharp.Views/AnchorStyles.cs | 53 ++ src/FigmaSharp.Views/Color.cs | 59 ++ src/FigmaSharp.Views/Extensions.cs | 34 + src/FigmaSharp.Views/FigmaColor.cs | 222 ++++++ src/FigmaSharp.Views/FigmaSharp.Views.csproj | 15 + src/FigmaSharp.Views/FileHelper.cs | 77 ++ src/FigmaSharp.Views/ITransitionButton.cs | 39 + src/FigmaSharp.Views/Interfaces/IButton.cs | 41 + src/FigmaSharp.Views/Interfaces/ICheckBox.cs | 38 + src/FigmaSharp.Views/Interfaces/IComboBox.cs | 32 + .../Interfaces/IDeviceWindow.cs | 38 + .../Interfaces/IHorizontalBar.cs | 31 + src/FigmaSharp.Views/Interfaces/IImage.cs | 31 + src/FigmaSharp.Views/Interfaces/IImageView.cs | 36 + src/FigmaSharp.Views/Interfaces/ILabel.cs | 33 + src/FigmaSharp.Views/Interfaces/IObject.cs | 33 + .../Interfaces/IScrollView.cs | 38 + src/FigmaSharp.Views/Interfaces/ISearchBox.cs | 31 + src/FigmaSharp.Views/Interfaces/ISlider.cs | 31 + src/FigmaSharp.Views/Interfaces/ISpinner.cs | 44 ++ src/FigmaSharp.Views/Interfaces/IStackView.cs | 37 + src/FigmaSharp.Views/Interfaces/ITextBox.cs | 50 ++ src/FigmaSharp.Views/Interfaces/ITransform.cs | 34 + src/FigmaSharp.Views/Interfaces/IView.cs | 67 ++ src/FigmaSharp.Views/Interfaces/IWindow.cs | 56 ++ src/FigmaSharp.Views/Key.cs | 151 ++++ src/FigmaSharp.Views/Padding.cs | 48 ++ src/FigmaSharp.Views/Svg/Definitions.cs | 120 +++ src/FigmaSharp.Views/Svg/HtmlElements.cs | 189 +++++ src/FigmaSharp.Views/Svg/Svg.cs | 120 +++ src/FigmaSharp.Views/Svg/ViewBoxRectangle.cs | 52 ++ src/FigmaSharp.Views/Transform.cs | 33 + src/FigmaSharp/AppContext.cs | 120 +++ .../Converters/Layers/ElipseConverterBase.cs | 47 ++ .../Converters/Layers/FrameConverterBase.cs | 38 + .../Converters/Layers/LineConverterBase.cs | 38 + .../Converters/Layers/PointConverterBase.cs | 38 + .../Layers/RectangleVectorConverterBase.cs | 38 + .../Layers/RegularPolygonConverterBase.cs | 38 + .../Layers/VectorEntityConverterBase.cs | 39 + src/FigmaSharp/Converters/NodeConverter.cs | 143 ++++ src/FigmaSharp/Converters/StackViewBase.cs | 42 + .../Converters/TextConverterBase.cs | 38 + .../Extensions/CodeGenerationExtensions.cs | 36 + .../Extensions/FigmaStyleExtensions.cs | 55 ++ src/FigmaSharp/Extensions/NodeExtensions.cs | 281 +++++++ .../Extensions/ServiceExtensions.cs | 213 ++++++ src/FigmaSharp/Extensions/StringExtensions.cs | 38 + src/FigmaSharp/FigmaFile/FigmaFile.cs | 121 +++ src/FigmaSharp/FigmaFile/IFigmaFile.cs | 41 + .../FigmaPackage/FigmaAssemblyManifest.cs | 32 + src/FigmaSharp/FigmaPackage/FigmaManifest.cs | 92 +++ .../FigmaPackage/ManifestDescription.cs | 36 + src/FigmaSharp/FigmaSharp.csproj | 44 ++ src/FigmaSharp/Helpers/ResourceHelper.cs | 40 + src/FigmaSharp/Helpers/WebApiHelper.cs | 130 ++++ src/FigmaSharp/IFigmaDelegate.cs | 55 ++ src/FigmaSharp/Properties/AssemblyInfo.cs | 18 + .../CodePropertyConfigureBase.cs | 34 + .../PropertyConfigure/PropertyNames.cs | 35 + .../ViewPropertyConfigureBase.cs | 34 + src/FigmaSharp/Resources.cs | 37 + src/FigmaSharp/Resources/AssemblyInfo.cs | 7 + .../Services/CodeRenderServiceOptions.cs | 43 ++ .../Services/CodeRendererService.cs | 343 +++++++++ .../Services/ITranslationService.cs | 36 + src/FigmaSharp/Services/LoggingService.cs | 135 ++++ src/FigmaSharp/Services/ModuleService.cs | 262 +++++++ src/FigmaSharp/Services/Nodes/CodeNode.cs | 46 ++ .../Services/Nodes/ContainerNode.cs | 38 + src/FigmaSharp/Services/Nodes/ViewNode.cs | 44 ++ .../Providers/AssemblyResourceNodeProvider.cs | 70 ++ .../Services/Providers/FileNodeProvider.cs | 90 +++ .../Services/Providers/INodeProvider.cs | 61 ++ .../Services/Providers/NodeProvider.cs | 298 ++++++++ .../Services/Providers/RemoteNodeProvider.cs | 186 +++++ src/FigmaSharp/Services/RenderService.cs | 159 ++++ .../Services/StoryboardLayoutManager.cs | 95 +++ src/FigmaSharp/Services/ViewRenderService.cs | 499 ++++++++++++ .../Services/ViewRenderServiceOptions.cs | 49 ++ src/FigmaSharp/WebApi/FigmaApi.cs | 147 ++++ src/FigmaSharp/WebApi/FigmaFileVersion.cs | 41 + src/FigmaSharp/WebApi/FigmaJsonConverter.cs | 154 ++++ src/FigmaSharp/WebApi/FigmaUser.cs | 33 + src/FigmaSharp/WebApi/Models/Enums.cs | 72 ++ src/FigmaSharp/WebApi/Models/Interfaces.cs | 51 ++ src/FigmaSharp/WebApi/Models/Models.cs | 716 ++++++++++++++++++ .../WebApi/Query/FigmaApiBaseQuery.cs | 38 + src/FigmaSharp/WebApi/Query/FigmaFileQuery.cs | 46 ++ .../WebApi/Query/FigmaFileVersionQuery.cs | 33 + .../WebApi/Query/FigmaImageQuery.cs | 84 ++ .../WebApi/Query/IImageNodeRequest.cs | 37 + .../WebApi/Query/ImageNodeRequest.cs | 47 ++ .../Response/FigmaFileVersionResponse.cs | 31 + .../WebApi/Response/FigmaImageResponse.cs | 37 + .../WebApi/Response/FigmaResponse.cs | 77 ++ 152 files changed, 10556 insertions(+), 5 deletions(-) create mode 100644 src/AlohaKit.UI.Figma/AlohaKit.UI.Figma.csproj create mode 100644 src/AlohaKit.UI.Figma/App.xaml create mode 100644 src/AlohaKit.UI.Figma/App.xaml.cs create mode 100644 src/AlohaKit.UI.Figma/AppShell.xaml create mode 100644 src/AlohaKit.UI.Figma/AppShell.xaml.cs create mode 100644 src/AlohaKit.UI.Figma/Converters/IsGeneratingToVisibleConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/ElipseConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/FrameConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/ImageConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/LineConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/PolygonConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/RectangleConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Converters/TextConverter.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Extensions/CodeGenerationExtensions.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Extensions/FigmaExtensions.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/FigmaApplication.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/FigmaDelegate.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/Helpers/CodeGenerationHelpers.cs create mode 100644 src/AlohaKit.UI.Figma/Figma/PropertyConfigure/CodePropertyConfigure.cs create mode 100644 src/AlohaKit.UI.Figma/MainPage.xaml create mode 100644 src/AlohaKit.UI.Figma/MainPage.xaml.cs create mode 100644 src/AlohaKit.UI.Figma/MauiProgram.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Android/AndroidManifest.xml create mode 100644 src/AlohaKit.UI.Figma/Platforms/Android/MainActivity.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Android/MainApplication.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Android/Resources/values/colors.xml create mode 100644 src/AlohaKit.UI.Figma/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/MacCatalyst/FolderPicker.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/MacCatalyst/Info.plist create mode 100644 src/AlohaKit.UI.Figma/Platforms/MacCatalyst/Program.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Tizen/Main.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Tizen/tizen-manifest.xml create mode 100644 src/AlohaKit.UI.Figma/Platforms/Windows/App.xaml create mode 100644 src/AlohaKit.UI.Figma/Platforms/Windows/App.xaml.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Windows/FolderPicker.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/Windows/Package.appxmanifest create mode 100644 src/AlohaKit.UI.Figma/Platforms/Windows/app.manifest create mode 100644 src/AlohaKit.UI.Figma/Platforms/iOS/AppDelegate.cs create mode 100644 src/AlohaKit.UI.Figma/Platforms/iOS/Info.plist create mode 100644 src/AlohaKit.UI.Figma/Platforms/iOS/Program.cs create mode 100644 src/AlohaKit.UI.Figma/Properties/launchSettings.json create mode 100644 src/AlohaKit.UI.Figma/Resources/AppIcon/appicon.svg create mode 100644 src/AlohaKit.UI.Figma/Resources/AppIcon/appiconfg.svg create mode 100644 src/AlohaKit.UI.Figma/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 src/AlohaKit.UI.Figma/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 src/AlohaKit.UI.Figma/Resources/Images/dotnet_bot.svg create mode 100644 src/AlohaKit.UI.Figma/Resources/Raw/AboutAssets.txt create mode 100644 src/AlohaKit.UI.Figma/Resources/Splash/splash.svg create mode 100644 src/AlohaKit.UI.Figma/Resources/Styles/Colors.xaml create mode 100644 src/AlohaKit.UI.Figma/Resources/Styles/Styles.xaml create mode 100644 src/AlohaKit.UI.Figma/Services/DialogService.cs create mode 100644 src/AlohaKit.UI.Figma/Services/IFolderPicker.cs create mode 100644 src/AlohaKit.UI.Figma/ViewModels/MainViewModel.cs create mode 100644 src/FigmaSharp.Views/AnchorStyles.cs create mode 100644 src/FigmaSharp.Views/Color.cs create mode 100644 src/FigmaSharp.Views/Extensions.cs create mode 100644 src/FigmaSharp.Views/FigmaColor.cs create mode 100644 src/FigmaSharp.Views/FigmaSharp.Views.csproj create mode 100644 src/FigmaSharp.Views/FileHelper.cs create mode 100644 src/FigmaSharp.Views/ITransitionButton.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IButton.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ICheckBox.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IComboBox.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IDeviceWindow.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IHorizontalBar.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IImage.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IImageView.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ILabel.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IObject.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IScrollView.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ISearchBox.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ISlider.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ISpinner.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IStackView.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ITextBox.cs create mode 100644 src/FigmaSharp.Views/Interfaces/ITransform.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IView.cs create mode 100644 src/FigmaSharp.Views/Interfaces/IWindow.cs create mode 100644 src/FigmaSharp.Views/Key.cs create mode 100644 src/FigmaSharp.Views/Padding.cs create mode 100644 src/FigmaSharp.Views/Svg/Definitions.cs create mode 100644 src/FigmaSharp.Views/Svg/HtmlElements.cs create mode 100644 src/FigmaSharp.Views/Svg/Svg.cs create mode 100644 src/FigmaSharp.Views/Svg/ViewBoxRectangle.cs create mode 100644 src/FigmaSharp.Views/Transform.cs create mode 100644 src/FigmaSharp/AppContext.cs create mode 100644 src/FigmaSharp/Converters/Layers/ElipseConverterBase.cs create mode 100644 src/FigmaSharp/Converters/Layers/FrameConverterBase.cs create mode 100644 src/FigmaSharp/Converters/Layers/LineConverterBase.cs create mode 100644 src/FigmaSharp/Converters/Layers/PointConverterBase.cs create mode 100644 src/FigmaSharp/Converters/Layers/RectangleVectorConverterBase.cs create mode 100644 src/FigmaSharp/Converters/Layers/RegularPolygonConverterBase.cs create mode 100644 src/FigmaSharp/Converters/Layers/VectorEntityConverterBase.cs create mode 100644 src/FigmaSharp/Converters/NodeConverter.cs create mode 100644 src/FigmaSharp/Converters/StackViewBase.cs create mode 100644 src/FigmaSharp/Converters/TextConverterBase.cs create mode 100644 src/FigmaSharp/Extensions/CodeGenerationExtensions.cs create mode 100644 src/FigmaSharp/Extensions/FigmaStyleExtensions.cs create mode 100644 src/FigmaSharp/Extensions/NodeExtensions.cs create mode 100644 src/FigmaSharp/Extensions/ServiceExtensions.cs create mode 100644 src/FigmaSharp/Extensions/StringExtensions.cs create mode 100644 src/FigmaSharp/FigmaFile/FigmaFile.cs create mode 100644 src/FigmaSharp/FigmaFile/IFigmaFile.cs create mode 100644 src/FigmaSharp/FigmaPackage/FigmaAssemblyManifest.cs create mode 100644 src/FigmaSharp/FigmaPackage/FigmaManifest.cs create mode 100644 src/FigmaSharp/FigmaPackage/ManifestDescription.cs create mode 100644 src/FigmaSharp/FigmaSharp.csproj create mode 100644 src/FigmaSharp/Helpers/ResourceHelper.cs create mode 100644 src/FigmaSharp/Helpers/WebApiHelper.cs create mode 100644 src/FigmaSharp/IFigmaDelegate.cs create mode 100644 src/FigmaSharp/Properties/AssemblyInfo.cs create mode 100644 src/FigmaSharp/PropertyConfigure/CodePropertyConfigureBase.cs create mode 100644 src/FigmaSharp/PropertyConfigure/PropertyNames.cs create mode 100644 src/FigmaSharp/PropertyConfigure/ViewPropertyConfigureBase.cs create mode 100644 src/FigmaSharp/Resources.cs create mode 100644 src/FigmaSharp/Resources/AssemblyInfo.cs create mode 100644 src/FigmaSharp/Services/CodeRenderServiceOptions.cs create mode 100644 src/FigmaSharp/Services/CodeRendererService.cs create mode 100644 src/FigmaSharp/Services/ITranslationService.cs create mode 100644 src/FigmaSharp/Services/LoggingService.cs create mode 100644 src/FigmaSharp/Services/ModuleService.cs create mode 100644 src/FigmaSharp/Services/Nodes/CodeNode.cs create mode 100644 src/FigmaSharp/Services/Nodes/ContainerNode.cs create mode 100644 src/FigmaSharp/Services/Nodes/ViewNode.cs create mode 100644 src/FigmaSharp/Services/Providers/AssemblyResourceNodeProvider.cs create mode 100644 src/FigmaSharp/Services/Providers/FileNodeProvider.cs create mode 100644 src/FigmaSharp/Services/Providers/INodeProvider.cs create mode 100644 src/FigmaSharp/Services/Providers/NodeProvider.cs create mode 100644 src/FigmaSharp/Services/Providers/RemoteNodeProvider.cs create mode 100644 src/FigmaSharp/Services/RenderService.cs create mode 100644 src/FigmaSharp/Services/StoryboardLayoutManager.cs create mode 100644 src/FigmaSharp/Services/ViewRenderService.cs create mode 100644 src/FigmaSharp/Services/ViewRenderServiceOptions.cs create mode 100644 src/FigmaSharp/WebApi/FigmaApi.cs create mode 100644 src/FigmaSharp/WebApi/FigmaFileVersion.cs create mode 100644 src/FigmaSharp/WebApi/FigmaJsonConverter.cs create mode 100644 src/FigmaSharp/WebApi/FigmaUser.cs create mode 100644 src/FigmaSharp/WebApi/Models/Enums.cs create mode 100644 src/FigmaSharp/WebApi/Models/Interfaces.cs create mode 100644 src/FigmaSharp/WebApi/Models/Models.cs create mode 100644 src/FigmaSharp/WebApi/Query/FigmaApiBaseQuery.cs create mode 100644 src/FigmaSharp/WebApi/Query/FigmaFileQuery.cs create mode 100644 src/FigmaSharp/WebApi/Query/FigmaFileVersionQuery.cs create mode 100644 src/FigmaSharp/WebApi/Query/FigmaImageQuery.cs create mode 100644 src/FigmaSharp/WebApi/Query/IImageNodeRequest.cs create mode 100644 src/FigmaSharp/WebApi/Query/ImageNodeRequest.cs create mode 100644 src/FigmaSharp/WebApi/Response/FigmaFileVersionResponse.cs create mode 100644 src/FigmaSharp/WebApi/Response/FigmaImageResponse.cs create mode 100644 src/FigmaSharp/WebApi/Response/FigmaResponse.cs diff --git a/src/AlohaKit.UI.Figma/AlohaKit.UI.Figma.csproj b/src/AlohaKit.UI.Figma/AlohaKit.UI.Figma.csproj new file mode 100644 index 0000000..c50c322 --- /dev/null +++ b/src/AlohaKit.UI.Figma/AlohaKit.UI.Figma.csproj @@ -0,0 +1,61 @@ + + + + net7.0-maccatalyst + $(TargetFrameworks);net7.0-windows10.0.19041.0 + + + Exe + AlohaKit.UI.Figma + true + true + enable + + + AlohaKit.UI.Figma + + + com.companyname.alohakit.ui.figma + bd33300f-7d11-47df-95ae-c835a27d86e1 + + + 1.0 + 1 + + 11.0 + 13.1 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AlohaKit.UI.Figma/App.xaml b/src/AlohaKit.UI.Figma/App.xaml new file mode 100644 index 0000000..ecc0acc --- /dev/null +++ b/src/AlohaKit.UI.Figma/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/src/AlohaKit.UI.Figma/App.xaml.cs b/src/AlohaKit.UI.Figma/App.xaml.cs new file mode 100644 index 0000000..75a21de --- /dev/null +++ b/src/AlohaKit.UI.Figma/App.xaml.cs @@ -0,0 +1,12 @@ +namespace AlohaKit.UI.Figma +{ + public partial class App : Application + { + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/AppShell.xaml b/src/AlohaKit.UI.Figma/AppShell.xaml new file mode 100644 index 0000000..4b3a7bd --- /dev/null +++ b/src/AlohaKit.UI.Figma/AppShell.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/src/AlohaKit.UI.Figma/AppShell.xaml.cs b/src/AlohaKit.UI.Figma/AppShell.xaml.cs new file mode 100644 index 0000000..d7e6dc8 --- /dev/null +++ b/src/AlohaKit.UI.Figma/AppShell.xaml.cs @@ -0,0 +1,10 @@ +namespace AlohaKit.UI.Figma +{ + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/Converters/IsGeneratingToVisibleConverter.cs b/src/AlohaKit.UI.Figma/Converters/IsGeneratingToVisibleConverter.cs new file mode 100644 index 0000000..92c31e8 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Converters/IsGeneratingToVisibleConverter.cs @@ -0,0 +1,19 @@ +using System.Globalization; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class IsGeneratingToVisibleConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var text = (string)value; + + return !string.IsNullOrEmpty(text); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/ElipseConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/ElipseConverter.cs new file mode 100644 index 0000000..99082dd --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/ElipseConverter.cs @@ -0,0 +1,96 @@ +using FigmaSharp.Converters; +using AlohaKit.UI.Figma.Extensions; +using FigmaSharp.Models; +using FigmaSharp.Services; +using System.Globalization; +using System.Text; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class ElipseConverter : ElipseConverterBase + { + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + if (currentNode.Node is not FigmaElipse elipseNode) + { + return string.Empty; + } + + StringBuilder builder = new StringBuilder(); + + builder.AppendLine(""); + + if (elipseNode.HasFills) + { + var backgroundPaint = elipseNode.fills.FirstOrDefault(); + + if (backgroundPaint != null && backgroundPaint.visible) + { + builder.AppendLine("\n\t"); + + if (backgroundPaint.color != null) + { + builder.AppendLine($"\t\t"); + } + + if (backgroundPaint.gradientStops != null) + { + if (backgroundPaint.type.Equals("GRADIENT_LINEAR", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToLinearGradientPaint()}"); + + if (backgroundPaint.type.Equals("GRADIENT_RADIAL", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToRadialGradientPaint()}"); + } + + if (backgroundPaint.imageRef != null) + builder.AppendLine("\t\t"); + + builder.AppendLine("\t"); + } + } + + builder.AppendLine(""); + + return builder.ToString(); + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/FrameConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/FrameConverter.cs new file mode 100644 index 0000000..ab0d2c4 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/FrameConverter.cs @@ -0,0 +1,102 @@ +using AlohaKit.UI.Figma.Extensions; +using FigmaSharp.Converters; +using FigmaSharp.Models; +using FigmaSharp.Services; +using System.Globalization; +using System.Text; + +namespace AlohaKit.UI.Figma.Converters +{ + public class FrameConverter : FrameConverterBase + { + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + if (currentNode.Node is not FigmaFrame frameNode) + { + return string.Empty; + } + + StringBuilder builder = new StringBuilder(); + + builder.AppendLine(""); + + if (frameNode.HasFills) + { + var backgroundPaint = frameNode.fills.FirstOrDefault(); + + if (backgroundPaint != null && backgroundPaint.visible) + { + builder.AppendLine("\n\t"); + + if (backgroundPaint.color != null) + { + builder.AppendLine($"\t\t"); + } + + if (backgroundPaint.gradientStops != null) + { + if (backgroundPaint.type.Equals("GRADIENT_LINEAR", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToLinearGradientPaint()}"); + + if (backgroundPaint.type.Equals("GRADIENT_RADIAL", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToRadialGradientPaint()}"); + } + + if (backgroundPaint.imageRef != null) + builder.AppendLine("\t\t"); + + builder.AppendLine("\t"); + } + } + + builder.AppendLine(""); + + return builder.ToString(); + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + + public override bool ScanChildren(FigmaNode currentNode) + => true; + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/ImageConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/ImageConverter.cs new file mode 100644 index 0000000..7d3d963 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/ImageConverter.cs @@ -0,0 +1,111 @@ +using AlohaKit.UI.Figma.Extensions; +using FigmaSharp.Converters; +using FigmaSharp.Models; +using FigmaSharp.Services; +using System.Globalization; +using System.Text; +using System.Xml.Linq; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class ImageConverter : NodeConverter + { + public override bool CanConvert(FigmaNode currentNode) + => currentNode.GetType() == typeof(FigmaVector); + + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + if (currentNode.Node is not FigmaVector figmaVector) + { + return string.Empty; + } + + if (figmaVector.fillGeometry == null || figmaVector.fillGeometry.Length == 0) + { + return string.Empty; + } + + StringBuilder builder = new StringBuilder(); + + NumberFormatInfo nfi = new NumberFormatInfo + { + NumberDecimalSeparator = "." + }; + + builder.AppendLine(" 0) + { + var geometry = figmaVector.fillGeometry[0]; + builder.AppendLine($"\tData=\"{geometry.path}\""); + } + + if (figmaVector.HasStrokes) + { + var strokePaint = figmaVector.strokes.FirstOrDefault(); + + if (strokePaint.color != null) + { + builder.AppendLine($"\tStroke=\"{strokePaint.color.ToCodeString()}\""); + } + + if (figmaVector.strokeWeight != 0) + { + var strokeSize = figmaVector.strokeWeight; + builder.AppendLine($"\tStrokeThickness=\"{strokeSize}\""); + } + } + + builder.Append("\t>"); + + if (figmaVector.HasFills) + { + var backgroundPaint = figmaVector.fills.FirstOrDefault(); + + if (backgroundPaint != null && backgroundPaint.visible) + { + builder.AppendLine("\n\t"); + + if (backgroundPaint.color != null) + { + builder.AppendLine($"\t\t"); + } + + if (backgroundPaint.gradientStops != null) + { + if (backgroundPaint.type.Equals("GRADIENT_LINEAR", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToLinearGradientPaint()}"); + + if (backgroundPaint.type.Equals("GRADIENT_RADIAL", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToRadialGradientPaint()}"); + } + + if (backgroundPaint.imageRef != null) + builder.AppendLine("\t\t"); + + builder.AppendLine("\t"); + } + } + + builder.AppendLine(""); + + return builder.ToString(); + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/LineConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/LineConverter.cs new file mode 100644 index 0000000..1b7a4b4 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/LineConverter.cs @@ -0,0 +1,22 @@ +using FigmaSharp.Converters; +using FigmaSharp.Models; +using FigmaSharp.Services; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class LineConverter : LineConverterBase + { + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + return ""; + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/PolygonConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/PolygonConverter.cs new file mode 100644 index 0000000..324304b --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/PolygonConverter.cs @@ -0,0 +1,22 @@ +using FigmaSharp.Converters; +using FigmaSharp.Models; +using FigmaSharp.Services; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class PolygonConverter : RegularPolygonConverterBase + { + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + return ""; + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/RectangleConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/RectangleConverter.cs new file mode 100644 index 0000000..5d93875 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/RectangleConverter.cs @@ -0,0 +1,96 @@ +using AlohaKit.UI.Figma.Extensions; +using FigmaSharp.Converters; +using FigmaSharp.Models; +using FigmaSharp.Services; +using System.Globalization; +using System.Text; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class RectangleConverter : RectangleVectorConverterBase + { + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + if (currentNode.Node is not RectangleVector rectangleVector) + { + return string.Empty; + } + + StringBuilder builder = new StringBuilder(); + + builder.AppendLine(""); + + if (rectangleVector.HasFills) + { + var backgroundPaint = rectangleVector.fills.FirstOrDefault(); + + if (backgroundPaint != null && backgroundPaint.visible) + { + builder.AppendLine("\n\t"); + + if (backgroundPaint.color != null) + { + builder.AppendLine($"\t\t"); + } + + if (backgroundPaint.gradientStops != null) + { + if (backgroundPaint.type.Equals("GRADIENT_LINEAR", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToLinearGradientPaint()}"); + + if (backgroundPaint.type.Equals("GRADIENT_RADIAL", StringComparison.CurrentCultureIgnoreCase)) + builder.AppendLine($"{backgroundPaint.gradientStops.ToRadialGradientPaint()}"); + } + + if (backgroundPaint.imageRef != null) + builder.AppendLine("\t\t"); + + builder.AppendLine("\t"); + } + } + + builder.AppendLine(""); + + return builder.ToString(); + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Converters/TextConverter.cs b/src/AlohaKit.UI.Figma/Figma/Converters/TextConverter.cs new file mode 100644 index 0000000..0b74a69 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Converters/TextConverter.cs @@ -0,0 +1,70 @@ +using FigmaSharp.Converters; +using AlohaKit.UI.Figma.Extensions; +using FigmaSharp.Models; +using FigmaSharp.Services; +using System.Globalization; +using System.Text; + +namespace AlohaKit.UI.Figma.Converters +{ + internal class TextConverter : TextConverterBase + { + public override string ConvertToCode(CodeNode currentNode, CodeNode parentNode, ICodeRenderService rendererService) + { + if (currentNode.Node is not FigmaText textNode) + { + return string.Empty; + } + + StringBuilder builder = new StringBuilder(); + + builder.AppendLine(""); + + return builder.ToString(); + } + + public override FigmaSharp.Views.IView ConvertToView(FigmaNode currentNode, ViewNode parent, ViewRenderService rendererService) + { + throw new NotImplementedException(); + } + + public override Type GetControlType(FigmaNode currentNode) + => typeof(View); + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Extensions/CodeGenerationExtensions.cs b/src/AlohaKit.UI.Figma/Figma/Extensions/CodeGenerationExtensions.cs new file mode 100644 index 0000000..bd4e079 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Extensions/CodeGenerationExtensions.cs @@ -0,0 +1,174 @@ +using AlohaKit.UI.Figma.Helpers; +using FigmaSharp; +using FigmaSharp.Models; +using FigmaSharp.Services; +using System.Text; + +namespace AlohaKit.UI.Figma.Extensions +{ + public static class CodeGenerationExtensions + { + public static string GetFullProperty(this Enum enumeration, string property) + { + return enumeration.GetType().WithProperty(property.ToCamelCase()); + } + + public static string WithProperty(this Type type, string property) + { + return string.Format("{0}.{1}", type.FullName, property); + } + + public static string CreatePropertyName(this CodeNode sender, string propertyName) + { + return string.Format("{0}.{1}", sender.Name, propertyName); + } + + public static string CreateChildObjectName(this CodeNode sender, string propertyName) + { + return string.Format("{0}{1}", sender.Name, propertyName); + } + + public static string GetConstructor(this Type type, params string[] parameters) + { + string args; + if (parameters.Length > 0) + { + args = string.Join(", ", parameters); + } + else + { + args = string.Empty; + } + return $"new {type.FullName} ({args})"; + } + + public static string GetMethod(this Type type, string methodName, string parameters, bool inQuotes = false, bool includesSemicolon = true) + { + return CodeGenerationHelpers.GetMethod(type.FullName, methodName, parameters, inQuotes, includesSemicolon); + } + + public static string GetFullName(this Enum myEnum) + { + return string.Format("{0}.{1}", myEnum.GetType().Name, myEnum.ToString()); + } + + public static string GetConstructor(this CodeNode sender, Type type, bool includesVar = true) + { + return GetConstructor(sender, type.FullName, includesVar); + } + + public static string GetConstructor(this CodeNode sender, string typeFullName, bool includesVar = true) + { + return CodeGenerationHelpers.GetConstructor(sender.Name, typeFullName, includesVar); + } + + public static string GetPropertyEquality(this CodeNode sender, string propertyName, Enum value) + { + return GetPropertyEquality(sender, propertyName, value.GetFullName()); + } + + public static string GetPropertyEquality(this CodeNode sender, string propertyName, bool value) + { + return GetPropertyEquality(sender, propertyName, value.ToString()); + } + + public static string GetPropertyEquality(this CodeNode sender, string propertyName, string value, bool inQuotes = false) + { + return CodeGenerationHelpers.GetPropertyEquality(sender.Name, propertyName, value, inQuotes); + } + + public static string GetMethod(this CodeNode sender, string methodName, Enum parameter) + { + return GetMethod(sender, methodName, parameter.GetFullName()); + } + + public static string GetMethod(this CodeNode sender, string methodName, bool parameter) + { + return CodeGenerationHelpers.GetMethod(sender.Name, methodName, parameter); + } + + public static string GetMethod(this CodeNode sender, string methodName, string parameters, bool inQuotes = false) + { + return CodeGenerationHelpers.GetMethod(sender.Name, methodName, parameters, inQuotes); + } + + #region StringBuilder Code Generation + + public static void WriteConstructor(this StringBuilder builder, string viewName, Type type, bool includesVar = true) + { + WriteConstructor(builder, viewName, type.FullName, includesVar); + } + + public static void WriteConstructor(this StringBuilder builder, string viewName, string typeFullName, bool includesVar = true) + { + builder.AppendLine(CodeGenerationHelpers.GetConstructor(viewName, typeFullName, includesVar)); + } + + public static void WritePropertyEquality(this StringBuilder builder, string viewName, string propertyName, Enum value) + { + WritePropertyEquality(builder, viewName, propertyName, value.GetFullName()); + } + + public static void WriteEquality(this StringBuilder builder, string viewName, string value, bool inQuotes = false, bool instanciate = false) + { + builder.AppendLine(CodeGenerationHelpers.GetEquality(viewName, value, inQuotes, instanciate)); + } + + public static void WritePropertyEquality(this StringBuilder builder, string viewName, string propertyName, bool value) + { + WritePropertyEquality(builder, viewName, propertyName, value.ToString()); + } + + public static void WritePropertyEquality(this StringBuilder builder, string viewName, string propertyName, string value, bool inQuotes = false, bool instanciate = false) + { + builder.AppendLine(CodeGenerationHelpers.GetPropertyEquality(viewName, propertyName, value, inQuotes, instanciate)); + } + + public static void WriteTranslatedEquality(this StringBuilder builder, string viewName, string propertyName, FigmaText value, ICodeRenderService codeRenderService, bool instanciate = false) + { + WriteTranslatedEquality(builder, viewName, propertyName, value.characters, codeRenderService, instanciate, value.visible); + } + + public static void WriteTranslatedEquality(this StringBuilder builder, string viewName, string propertyName, string value, ICodeRenderService codeRenderService, bool instanciate = false, bool textCondition = true) + { + bool needQuotes; + string result; + if (textCondition && !string.IsNullOrEmpty(value)) + { + if (codeRenderService.Options != null && codeRenderService.Options.TranslateLabels) + { + result = codeRenderService.GetTranslatedText(value); + needQuotes = false; + } + else + { + result = value; + needQuotes = true; + } + } + else + { + result = string.Empty; + needQuotes = true; + } + builder.AppendLine(CodeGenerationHelpers.GetPropertyEquality(viewName, propertyName, result, inQuotes: needQuotes, instanciate: instanciate)); + } + + public static void WriteMethod(this StringBuilder builder, string viewName, string methodName, Enum parameter) + { + WriteMethod(builder, viewName, methodName, parameter.GetFullName()); + } + + public static void WriteMethod(this StringBuilder builder, string viewName, string methodName, bool parameter) + { + WriteMethod(builder, viewName, methodName, parameter.ToString()); + } + + public static void WriteMethod(this StringBuilder builder, string viewName, string methodName, string parameters, bool inQuotes = false) + { + builder.AppendLine(CodeGenerationHelpers.GetMethod(viewName, methodName, parameters, inQuotes)); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/Figma/Extensions/FigmaExtensions.cs b/src/AlohaKit.UI.Figma/Figma/Extensions/FigmaExtensions.cs new file mode 100644 index 0000000..76c7e68 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Extensions/FigmaExtensions.cs @@ -0,0 +1,136 @@ +using FigmaSharp.Models; +using System.Text; + +namespace AlohaKit.UI.Figma.Extensions +{ + public static class FigmaExtensions + { + public static string ToCodeString(this FigmaSharp.Color color) + { + int red = Convert.ToInt32(color.R * 255); + int green = Convert.ToInt32(color.G * 255); + int blue = Convert.ToInt32(color.B * 255); + + return "#" + red.ToString("X2") + green.ToString("X2") + blue.ToString("X2"); + } + + public static string ToLinearGradientPaint(this ColorStop[] colorStops) + { + StringBuilder builder = new StringBuilder(); + + builder.Append("\t\t"); + builder.AppendLine("\n\t\t\t"); + + foreach (var colorStop in colorStops) + { + var color = colorStop.color; + string hexColor = color.ToCodeString(); + + builder.AppendLine($"\t\t\t\t"); + } + + builder.AppendLine("\t\t\t"); + + builder.Append("\t\t"); + + return builder.ToString(); + } + + public static string ToRadialGradientPaint(this ColorStop[] colorStops) + { + StringBuilder builder = new StringBuilder(); + + builder.Append("\t\t"); + builder.AppendLine("\n\t\t\t"); + + foreach (var colorStop in colorStops) + { + var color = colorStop.color; + string hexColor = color.ToCodeString(); + + builder.AppendLine($"\t\t\t\t"); + } + + builder.AppendLine("\t\t\t"); + + builder.Append("\t\t"); + + return builder.ToString(); + } + + public static string ToCodeString(this float[] values) + { + StringBuilder builder = new StringBuilder(); + + builder.Append("new float[] {"); + var separator = ","; + int i = 0; + + foreach (var value in values) + { + builder.Append($"{ToCodeString(value)}{(i < values.Length ? separator : string.Empty)}"); + i++; + } + + builder.Append("}"); + + return builder.ToString(); + } + + public static string ToCodeString(this float value) + { + return string.Concat(value.ToString(), "f"); + } + + public static string ToCodeString(this double value) + { + return string.Concat(value.ToString(), "f"); + } + + public static string ToCodeString(this FigmaTypeStyle style) + { + var fontFamily = style.fontPostScriptName ?? style.fontFamily; + var fontWeight = style.fontWeight; + + string fontStyleType = "FontStyleType.Normal"; + + if (!string.IsNullOrEmpty(fontFamily) && fontFamily.Contains("Italic", StringComparison.CurrentCultureIgnoreCase)) + fontStyleType = "FontStyleType.Italic"; + + return $"new Microsoft.Maui.Graphics.Font(\"{fontFamily}\", {fontWeight}, {fontStyleType})"; + } + + public static string ToHorizontalAignment(this string value) + { + switch(value) + { + case "LEFT": + return "HorizontalAlignment.Left"; + case "CENTER": + return "HorizontalAlignment.Center"; + case "RIGHT": + return "HorizontalAlignment.Right"; + case "SCALE": + return "HorizontalAlignment.Justified"; + default: + return "HorizontalAlignment.Left"; + } + } + + public static string ToVerticalAlignment(this string value) + { + switch (value) + { + case "TOP": + return "VerticalAlignment.Top"; + case "CENTER": + case "SCALE": + return "VerticalAlignment.Center"; + case "BOTTOM": + return "VerticalAlignment.Bottom"; + default: + return "VerticalAlignment.Top"; + } + } + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/Figma/FigmaApplication.cs b/src/AlohaKit.UI.Figma/Figma/FigmaApplication.cs new file mode 100644 index 0000000..c113f62 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/FigmaApplication.cs @@ -0,0 +1,12 @@ +namespace AlohaKit.UI.Figma +{ + public class FigmaApplication + { + public static void Init(string token) + { + var applicationDelegate = new FigmaDelegate(); + + FigmaSharp.AppContext.Current.Configuration(applicationDelegate, token); + } + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/Figma/FigmaDelegate.cs b/src/AlohaKit.UI.Figma/Figma/FigmaDelegate.cs new file mode 100644 index 0000000..ea1f7d5 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/FigmaDelegate.cs @@ -0,0 +1,77 @@ +using AlohaKit.UI.Figma.Converters; +using FigmaSharp; +using FigmaSharp.Converters; +using FigmaSharp.PropertyConfigure; +using FigmaSharp.Views; +using System.Reflection; + +namespace AlohaKit.UI.Figma +{ + public class FigmaDelegate : IFigmaDelegate + { + public bool IsVerticalAxisFlipped => false; + + public void BeginInvoke(Action handler) + { + throw new NotImplementedException(); + } + + public FigmaSharp.Views.IView CreateEmptyView() + { + throw new NotImplementedException(); + } + + public CodePropertyConfigureBase GetCodePropertyConfigure() + { + throw new NotImplementedException(); + } + + public NodeConverter[] GetFigmaConverters() + { + return new NodeConverter[]{ + new ElipseConverter(), + new FrameConverter(), + new ImageConverter(), + new LineConverter(), + new PolygonConverter(), + new RectangleConverter(), + new TextConverter() + }; + } + + public FigmaSharp.Views.IImage GetImage(string url) + { + throw new NotImplementedException(); + } + + public FigmaSharp.Views.IImage GetImageFromFilePath(string filePath) + { + throw new NotImplementedException(); + } + + public FigmaSharp.Views.IImage GetImageFromManifest(Assembly assembly, string imageRef) + { + throw new NotImplementedException(); + } + + public IImageView GetImageView(FigmaSharp.Views.IImage image) + { + throw new NotImplementedException(); + } + + public string GetManifestResource(Assembly assembly, string file) + { + throw new NotImplementedException(); + } + + public string GetSvgData(string url) + { + throw new NotImplementedException(); + } + + public ViewPropertyConfigureBase GetViewPropertyConfigure() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/Helpers/CodeGenerationHelpers.cs b/src/AlohaKit.UI.Figma/Figma/Helpers/CodeGenerationHelpers.cs new file mode 100644 index 0000000..141f7e6 --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/Helpers/CodeGenerationHelpers.cs @@ -0,0 +1,65 @@ +using AlohaKit.UI.Figma.Extensions; + +namespace AlohaKit.UI.Figma.Helpers +{ + public static class CodeGenerationHelpers + { + public static string GetConstructor(string viewName, Type type, bool includesVar = true) + { + return GetConstructor(viewName, type.FullName, includesVar); + } + + public static string GetConstructor(string viewName, string typeFullName, bool includesVar = true) + { + return $"{(includesVar ? "var " : string.Empty)}{viewName} = new {typeFullName}();"; + } + + public static string GetPropertyEquality(string viewName, string propertyName, Enum value) + { + return GetPropertyEquality(viewName, propertyName, value.GetFullName()); + } + + public static string GetPropertyEquality(string viewName, string propertyName, bool value) + { + return GetPropertyEquality(viewName, propertyName, value.ToString()); + } + + public static string GetPropertyEquality(string viewName, string propertyName, string value, bool inQuotes = false, bool instanciate = false) + { + string fullPropertyName; + if (string.IsNullOrEmpty(propertyName)) + fullPropertyName = viewName; + else + fullPropertyName = $"{viewName}.{propertyName}"; + return GetEquality(fullPropertyName, value, inQuotes, instanciate); + } + + public static string GetEquality(string viewName, string value, bool inQuotes = false, bool instanciate = false) + { + if (inQuotes) + { + value = string.Format("\"{0}\"", value.Replace("\n", "\\n")); + } + + var instanciateText = instanciate ? "var " : ""; + return $"{instanciateText}{viewName} = {value};"; + } + + public static string GetMethod(string viewName, string methodName, Enum parameter) + { + return GetMethod(viewName, methodName, parameter.GetFullName()); + } + + public static string GetMethod(string viewName, string methodName, bool value) + { + return GetMethod(viewName, methodName, value.ToString()); + } + + public static string GetMethod(string viewName, string methodName, string parameters, bool inQuotes = false, bool includesSemicolon = true) + { + parameters = inQuotes ? $"\"{parameters}\"" : parameters; + var semicolon = includesSemicolon ? ";" : ""; + return $"{viewName}.{methodName} ({parameters}){semicolon}"; + } + } +} diff --git a/src/AlohaKit.UI.Figma/Figma/PropertyConfigure/CodePropertyConfigure.cs b/src/AlohaKit.UI.Figma/Figma/PropertyConfigure/CodePropertyConfigure.cs new file mode 100644 index 0000000..5307c4d --- /dev/null +++ b/src/AlohaKit.UI.Figma/Figma/PropertyConfigure/CodePropertyConfigure.cs @@ -0,0 +1,14 @@ +using FigmaSharp.Converters; +using FigmaSharp.PropertyConfigure; +using FigmaSharp.Services; + +namespace AlohaKit.UI.Figma.PropertyConfigure +{ + public class CodePropertyConfigure : CodePropertyConfigureBase + { + public override string ConvertToCode(string propertyName, CodeNode currentNode, CodeNode parentNode, NodeConverter converter, CodeRenderService rendererService) + { + return string.Empty; + } + } +} \ No newline at end of file diff --git a/src/AlohaKit.UI.Figma/MainPage.xaml b/src/AlohaKit.UI.Figma/MainPage.xaml new file mode 100644 index 0000000..056bb40 --- /dev/null +++ b/src/AlohaKit.UI.Figma/MainPage.xaml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +