├── .github └── workflows │ └── azure-swa.yml ├── .gitignore ├── Directory.Build.props ├── FluentEditor.sln ├── FluentEditorBrowser ├── AppBundle │ ├── Logo.svg │ ├── app.css │ ├── favicon.ico │ ├── index.html │ ├── main.js │ └── staticwebapp.config.json ├── FluentEditorBrowser.csproj ├── Program.cs └── runtimeconfig.template.json ├── FluentEditorDesktop ├── FluentEditorDesktop.csproj ├── Program.cs └── app.manifest ├── FluentEditorShared ├── App.axaml ├── App.axaml.cs ├── ColorPalette │ ├── ColorPalette.cs │ ├── ColorPaletteEditor.cs │ ├── ColorPaletteEntry.cs │ ├── ColorPaletteEntryEditor.cs │ ├── ContrastColorWrapper.cs │ ├── ContrastListItem.cs │ ├── EditableColorPaletteEntry.cs │ ├── ExpandedColorPaletteEntryEditor.axaml │ ├── ExpandedColorPaletteEntryEditor.axaml.cs │ ├── IColorPalette.cs │ └── IColorPaletteEntry.cs ├── ControlPalette │ ├── ColorMapping.cs │ ├── ControlPaletteTestContent.axaml │ ├── ControlPaletteTestContent.axaml.cs │ ├── ControlPaletteView.axaml │ ├── ControlPaletteView.axaml.cs │ ├── ControlPaletteViewModel.cs │ ├── ExportView.axaml │ ├── ExportView.axaml.cs │ ├── ExportViewModel.cs │ └── Model │ │ ├── ControlPaletteExportProvider.cs │ │ ├── ControlPaletteModel.cs │ │ └── Preset.cs ├── Converters.cs ├── FluentEditorShared.csproj ├── FluentEditorSharedResources.axaml ├── LocExtension.cs ├── Model │ └── MainNavModel.cs ├── OuterNav │ ├── INavItem.cs │ ├── OuterNavPage.axaml │ ├── OuterNavPage.axaml.cs │ └── OuterNavViewModel.cs ├── Resources │ ├── Resources.en-US.resx │ ├── Resources.resx │ ├── controlPaletteData.json │ └── demodata.json ├── StringProvider.cs └── Utils │ ├── ColorBlending.cs │ ├── ColorScale.cs │ ├── ColorTypes.cs │ ├── ColorUtils.cs │ ├── JSONExtensionMethods.cs │ └── MathUtils.cs ├── LICENSE ├── README.md └── README_Images ├── App.png ├── ColorContrast_Bad.png ├── ColorContrast_Good.png ├── ExportTheme.png ├── RegionBasePrimary_DetailColorProperties.png └── RegionBasePrimary_Properties.png /.github/workflows/azure-swa.yml: -------------------------------------------------------------------------------- 1 | name: Azure Static Web Apps CI/CD 2 | 3 | on: 4 | push: 5 | branches: 6 | - release/* 7 | 8 | jobs: 9 | build_and_deploy_job: 10 | runs-on: ubuntu-latest 11 | name: Build and Deploy Job 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | submodules: recursive 16 | 17 | - name: Setup .NET 7 18 | uses: actions/setup-dotnet@v3 19 | with: 20 | dotnet-version: 7.0.100 21 | 22 | - name: Install wasm-tools 23 | run: dotnet workload install wasm-tools wasm-experimental 24 | 25 | - name: Install DotNetCompress 26 | run: dotnet tool install --global DotNetCompress --version 1.0.0-preview.7 --no-cache 27 | 28 | - name: Publish .NET Project 29 | run: dotnet publish FluentEditorBrowser/FluentEditorBrowser.csproj -c Release -o release --nologo 30 | 31 | - name: Brotli Compress Output (dll) 32 | run: DotNetCompress -d FluentEditorBrowser/bin/Release/net7.0/browser-wasm/AppBundle/ -p '*.dll' -p '*.js' -p '*.symbols' -p '*.blat' -p '*.bin' -p '*.wasm' 33 | 34 | - name: Build And Deploy 35 | id: builddeploy 36 | uses: Azure/static-web-apps-deploy@v1 37 | with: 38 | azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APP_DEPLOY_KEY }} 39 | repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) 40 | action: "upload" 41 | ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### 42 | # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig 43 | app_location: "FluentEditorBrowser/bin/Release/net7.0/browser-wasm/AppBundle/" # App source code path 44 | api_location: "" # Api source code path - optional 45 | output_location: "" # Modify this to where your SSG places the built HTML - could be `dist`, `build`... check your config 46 | skip_app_build: true 47 | ###### End of Repository/Build Configurations ###### 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | 11.0-rc1.1 5 | true 6 | 7 | 8 | 9 | False 10 | None 11 | 12 | 13 | -------------------------------------------------------------------------------- /FluentEditor.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29324.140 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentEditorShared", "FluentEditorShared\FluentEditorShared.csproj", "{42A312EF-7C4A-4661-A684-DB14E40A2A90}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentEditorBrowser", "FluentEditorBrowser\FluentEditorBrowser.csproj", "{B52910F3-58C8-4253-8B1F-952A7DDBE2AE}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentEditorDesktop", "FluentEditorDesktop\FluentEditorDesktop.csproj", "{9A8C8058-E145-4644-A7A9-FA0792ACCDCE}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{73ED66C7-8A44-40E8-A1CD-024DDD55BAAD}" 13 | ProjectSection(SolutionItems) = preProject 14 | .gitignore = .gitignore 15 | Directory.Build.props = Directory.Build.props 16 | README.md = README.md 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Any CPU = Debug|Any CPU 22 | Debug|ARM = Debug|ARM 23 | Debug|x64 = Debug|x64 24 | Debug|x86 = Debug|x86 25 | Release|Any CPU = Release|Any CPU 26 | Release|ARM = Release|ARM 27 | Release|x64 = Release|x64 28 | Release|x86 = Release|x86 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|ARM.ActiveCfg = Debug|ARM 34 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|ARM.Build.0 = Debug|ARM 35 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|x64.ActiveCfg = Debug|x64 36 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|x64.Build.0 = Debug|x64 37 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|x86.ActiveCfg = Debug|x86 38 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Debug|x86.Build.0 = Debug|x86 39 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|ARM.ActiveCfg = Release|ARM 42 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|ARM.Build.0 = Release|ARM 43 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|x64.ActiveCfg = Release|x64 44 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|x64.Build.0 = Release|x64 45 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|x86.ActiveCfg = Release|x86 46 | {42A312EF-7C4A-4661-A684-DB14E40A2A90}.Release|x86.Build.0 = Release|x86 47 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|ARM.ActiveCfg = Debug|Any CPU 50 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|ARM.Build.0 = Debug|Any CPU 51 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|x64.ActiveCfg = Debug|Any CPU 52 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|x64.Build.0 = Debug|Any CPU 53 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|x86.ActiveCfg = Debug|Any CPU 54 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Debug|x86.Build.0 = Debug|Any CPU 55 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|Any CPU.Build.0 = Release|Any CPU 57 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|ARM.ActiveCfg = Release|Any CPU 58 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|ARM.Build.0 = Release|Any CPU 59 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|x64.ActiveCfg = Release|Any CPU 60 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|x64.Build.0 = Release|Any CPU 61 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|x86.ActiveCfg = Release|Any CPU 62 | {B52910F3-58C8-4253-8B1F-952A7DDBE2AE}.Release|x86.Build.0 = Release|Any CPU 63 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 64 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|Any CPU.Build.0 = Debug|Any CPU 65 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|ARM.ActiveCfg = Debug|Any CPU 66 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|ARM.Build.0 = Debug|Any CPU 67 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|x64.ActiveCfg = Debug|Any CPU 68 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|x64.Build.0 = Debug|Any CPU 69 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|x86.ActiveCfg = Debug|Any CPU 70 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Debug|x86.Build.0 = Debug|Any CPU 71 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|Any CPU.ActiveCfg = Release|Any CPU 72 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|Any CPU.Build.0 = Release|Any CPU 73 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|ARM.ActiveCfg = Release|Any CPU 74 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|ARM.Build.0 = Release|Any CPU 75 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|x64.ActiveCfg = Release|Any CPU 76 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|x64.Build.0 = Release|Any CPU 77 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|x86.ActiveCfg = Release|Any CPU 78 | {9A8C8058-E145-4644-A7A9-FA0792ACCDCE}.Release|x86.Build.0 = Release|Any CPU 79 | EndGlobalSection 80 | GlobalSection(SolutionProperties) = preSolution 81 | HideSolutionNode = FALSE 82 | EndGlobalSection 83 | GlobalSection(ExtensibilityGlobals) = postSolution 84 | SolutionGuid = {7EA96CDE-0998-4389-A162-963C75A4307E} 85 | EndGlobalSection 86 | EndGlobal 87 | -------------------------------------------------------------------------------- /FluentEditorBrowser/AppBundle/Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FluentEditorBrowser/AppBundle/app.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --sat: env(safe-area-inset-top); 3 | --sar: env(safe-area-inset-right); 4 | --sab: env(safe-area-inset-bottom); 5 | --sal: env(safe-area-inset-left); 6 | } 7 | 8 | /* HTML styles for the splash screen */ 9 | 10 | .highlight { 11 | color: white; 12 | font-size: 2.5rem; 13 | display: block; 14 | } 15 | 16 | .purple { 17 | color: #8b44ac; 18 | } 19 | 20 | .icon { 21 | opacity: 0.05; 22 | height: 35%; 23 | width: 35%; 24 | position: absolute; 25 | background-repeat: no-repeat; 26 | right: 0px; 27 | bottom: 0px; 28 | margin-right: 3%; 29 | margin-bottom: 5%; 30 | z-index: 5000; 31 | background-position: right bottom; 32 | pointer-events: none; 33 | } 34 | 35 | #avalonia-splash a { 36 | color: whitesmoke; 37 | text-decoration: none; 38 | } 39 | 40 | .center { 41 | display: flex; 42 | justify-content: center; 43 | align-items: center; 44 | height: 100vh; 45 | } 46 | 47 | #avalonia-splash { 48 | position: relative; 49 | height: 100%; 50 | width: 100%; 51 | color: whitesmoke; 52 | background: #1b2a4e; 53 | font-family: 'Nunito', sans-serif; 54 | background-position: center; 55 | background-size: cover; 56 | background-repeat: no-repeat; 57 | justify-content: center; 58 | align-items: center; 59 | } 60 | 61 | .splash-close { 62 | animation: fadeout 0.25s linear forwards; 63 | } 64 | 65 | @keyframes fadeout { 66 | 0% { 67 | opacity: 100%; 68 | } 69 | 70 | 100% { 71 | opacity: 0; 72 | visibility: collapse; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /FluentEditorBrowser/AppBundle/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvaloniaUI/fluent-xaml-theme-editor/e8e61182439ebc4bb034568db44654b2feb6efb6/FluentEditorBrowser/AppBundle/favicon.ico -------------------------------------------------------------------------------- /FluentEditorBrowser/AppBundle/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | FluentEditor 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |
19 |

20 | Powered by 21 | Avalonia UI 22 |

23 |
24 | Avalonia Logo 25 |
26 |
27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /FluentEditorBrowser/AppBundle/main.js: -------------------------------------------------------------------------------- 1 | import { dotnet } from './dotnet.js' 2 | 3 | const is_browser = typeof window != "undefined"; 4 | if (!is_browser) throw new Error(`Expected to be running in a browser`); 5 | 6 | const dotnetRuntime = await dotnet 7 | .withDiagnosticTracing(false) 8 | .withApplicationArgumentsFromQuery() 9 | .create(); 10 | 11 | const config = dotnetRuntime.getConfig(); 12 | 13 | await dotnetRuntime.runMainAndExit(config.mainAssemblyName, [window.location.search]); 14 | -------------------------------------------------------------------------------- /FluentEditorBrowser/AppBundle/staticwebapp.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "routes": [ 3 | { 4 | "route": "/*", 5 | "headers": { 6 | "Cache-Control": "no-cache" 7 | } 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /FluentEditorBrowser/FluentEditorBrowser.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | browser-wasm 6 | AppBundle\main.js 7 | Exe 8 | true 9 | true 10 | FluentEditor 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /FluentEditorBrowser/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Versioning; 2 | using System.Threading.Tasks; 3 | using Avalonia; 4 | using Avalonia.Browser; 5 | 6 | [assembly: System.Resources.NeutralResourcesLanguageAttribute("en")] 7 | [assembly: SupportedOSPlatform("browser")] 8 | 9 | namespace FluentEditor; 10 | 11 | internal class Program 12 | { 13 | private static Task Main(string[] args) 14 | { 15 | return BuildAvaloniaApp() 16 | .WithInterFont() 17 | .StartBrowserAppAsync("out"); 18 | } 19 | 20 | public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure(); 21 | } 22 | -------------------------------------------------------------------------------- /FluentEditorBrowser/runtimeconfig.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "wasmHostProperties": { 3 | "perHostConfig": [ 4 | { 5 | "name": "browser", 6 | "html-path": "index.html", 7 | "Host": "browser" 8 | } 9 | ] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /FluentEditorDesktop/FluentEditorDesktop.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | WinExe 4 | net7.0 5 | true 6 | app.manifest 7 | 0.1.0 8 | 9 | true 10 | true 11 | FluentEditor 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /FluentEditorDesktop/Program.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using System; 3 | 4 | [assembly: System.Resources.NeutralResourcesLanguageAttribute("en")] 5 | 6 | namespace FluentEditor; 7 | 8 | internal class Program 9 | { 10 | [STAThread] 11 | public static void Main(string[] args) => BuildAvaloniaApp() 12 | .StartWithClassicDesktopLifetime(args); 13 | 14 | public static AppBuilder BuildAvaloniaApp() 15 | { 16 | return AppBuilder.Configure() 17 | .UsePlatformDetect() 18 | .WithInterFont() 19 | .AfterSetup(_ => 20 | { 21 | #if DEBUG 22 | Application.Current!.AttachDevTools(); 23 | #endif 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /FluentEditorDesktop/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /FluentEditorShared/App.axaml: -------------------------------------------------------------------------------- 1 |  5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /FluentEditorShared/App.axaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System.Threading.Tasks; 5 | using Avalonia; 6 | using Avalonia.Controls; 7 | using Avalonia.Controls.ApplicationLifetimes; 8 | using Avalonia.Markup.Xaml; 9 | using Avalonia.Platform.Storage; 10 | using FluentEditor.ControlPalette.Model; 11 | using FluentEditor.Model; 12 | using FluentEditor.OuterNav; 13 | using FluentEditorShared; 14 | 15 | namespace FluentEditor 16 | { 17 | public sealed class App : Application 18 | { 19 | public static FilePickerFileType JsonFileType { get; } = new("JSON") 20 | { 21 | Patterns = new[] { "*.json" }, 22 | MimeTypes = new[] { "application/json" }, 23 | AppleUniformTypeIdentifiers = new[] { "public.json" } 24 | }; 25 | 26 | public static OuterNavPage NavPage { get; private set; } 27 | public static IStringProvider StringProvider { get; private set; } 28 | 29 | public App() 30 | { 31 | AvaloniaXamlLoader.Load(this); 32 | } 33 | 34 | public override async void OnFrameworkInitializationCompleted() 35 | { 36 | base.OnFrameworkInitializationCompleted(); 37 | 38 | await SetupDependencies(); 39 | 40 | NavPage = new OuterNavPage(_outerNavViewModel); 41 | 42 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime classicDesktopStyleApplicationLifetime) 43 | { 44 | var window = new Window 45 | { 46 | Content = NavPage 47 | }; 48 | classicDesktopStyleApplicationLifetime.MainWindow = window; 49 | classicDesktopStyleApplicationLifetime.Exit += (sender, args) => 50 | { 51 | _ = SuspendApp(_mainNavModel, _paletteModel); 52 | }; 53 | window.Show(); 54 | } 55 | else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewApplicationLifetime) 56 | { 57 | singleViewApplicationLifetime.MainView = NavPage; 58 | } 59 | } 60 | 61 | private async Task SuspendApp(IMainNavModel mainModel, IControlPaletteModel controlPaletteModel) 62 | { 63 | await controlPaletteModel.HandleAppSuspend(); 64 | await mainModel.HandleAppSuspend(); 65 | } 66 | 67 | private async Task SetupDependencies() 68 | { 69 | var stringProvider = new StringProvider(); 70 | var exportProvider = new ControlPaletteExportProvider(); 71 | 72 | var paletteModel = new ControlPaletteModel(); 73 | await paletteModel.InitializeData(stringProvider, stringProvider.GetString("ControlPaletteDataPath")); 74 | 75 | var navModel = new MainNavModel(stringProvider); 76 | await navModel.InitializeData(stringProvider.GetString("MainDataPath"), paletteModel, exportProvider); 77 | 78 | _stringProvider = stringProvider; 79 | _exportProvider = exportProvider; 80 | 81 | _paletteModel = paletteModel; 82 | 83 | _mainNavModel = navModel; 84 | _outerNavViewModel = new OuterNavViewModel(_mainNavModel.NavItems, _mainNavModel.DefaultNavItem); 85 | StringProvider = stringProvider; 86 | } 87 | 88 | private StringProvider _stringProvider; 89 | private ControlPaletteExportProvider _exportProvider; 90 | private IMainNavModel _mainNavModel; 91 | private IControlPaletteModel _paletteModel; 92 | 93 | private OuterNavViewModel _outerNavViewModel; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/ColorPaletteEditor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System.Collections.Generic; 5 | using Avalonia; 6 | using Avalonia.Controls; 7 | using Avalonia.Controls.Primitives; 8 | 9 | namespace FluentEditorShared.ColorPalette 10 | { 11 | public class ColorPaletteEditor : TemplatedControl 12 | { 13 | #region ColorPaletteProperty 14 | 15 | public static readonly StyledProperty ColorPaletteProperty = AvaloniaProperty.Register("ColorPalette"); 16 | 17 | private void OnColorPaletteChanged(ColorPalette oldValue, ColorPalette newValue) 18 | { 19 | if(newValue == null) 20 | { 21 | SetValue(PaletteEntriesProperty, null); 22 | } 23 | else 24 | { 25 | SetValue(PaletteEntriesProperty, newValue.Palette); 26 | } 27 | } 28 | 29 | public ColorPalette ColorPalette 30 | { 31 | get => GetValue(ColorPaletteProperty); 32 | set => SetValue(ColorPaletteProperty, value); 33 | } 34 | 35 | #endregion 36 | 37 | #region PaletteEntriesProperty 38 | 39 | public static readonly StyledProperty> PaletteEntriesProperty = AvaloniaProperty.Register>("PaletteEntries"); 40 | 41 | public IReadOnlyList PaletteEntries => GetValue(PaletteEntriesProperty); 42 | 43 | #endregion 44 | 45 | #region IsExpandedProperty 46 | 47 | public static readonly StyledProperty IsExpandedProperty = AvaloniaProperty.Register("IsExpanded", true); 48 | 49 | public bool IsExpanded 50 | { 51 | get => GetValue(IsExpandedProperty); 52 | set => SetValue(IsExpandedProperty, value); 53 | } 54 | 55 | #endregion 56 | 57 | protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) 58 | { 59 | base.OnPropertyChanged(change); 60 | 61 | if (change.Property == ColorPaletteProperty) 62 | { 63 | var (oldValue, newValue) = change.GetOldAndNewValue(); 64 | OnColorPaletteChanged(oldValue, newValue); 65 | } 66 | else if (change.Property == IsExpandedProperty) 67 | { 68 | PseudoClasses.Set(":expanded", IsExpanded); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/ColorPaletteEntry.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text.Json.Nodes; 7 | using Avalonia.Media; 8 | using FluentEditorShared.Utils; 9 | 10 | namespace FluentEditorShared.ColorPalette 11 | { 12 | // These classes are not intended to be viewmodels. 13 | // They deal with the data about an editable palette and are passed to special purpose controls for editing 14 | public class ColorPaletteEntry : IColorPaletteEntry 15 | { 16 | public static ColorPaletteEntry Parse(JsonObject data, IReadOnlyList contrastColors) 17 | { 18 | Color color; 19 | if (data.ContainsKey("Color")) 20 | { 21 | color = data["Color"].GetColor(); 22 | } 23 | else 24 | { 25 | color = default(Color); 26 | } 27 | 28 | ColorStringFormat activeColorStringFormat = ColorStringFormat.PoundRGB; 29 | if (data.ContainsKey("ActiveColorStringFormat")) 30 | { 31 | activeColorStringFormat = data.GetEnum(); 32 | } 33 | 34 | return new ColorPaletteEntry(color, data.GetOptionalString("Title"), data.GetOptionalString("Description"), activeColorStringFormat, contrastColors); 35 | } 36 | 37 | public ColorPaletteEntry(Color color, string title, string description, ColorStringFormat activeColorStringFormat, IReadOnlyList contrastColors) 38 | { 39 | _activeColor = color; 40 | _title = title; 41 | _description = description; 42 | _activeColorStringFormat = activeColorStringFormat; 43 | 44 | ContrastColors = contrastColors; 45 | } 46 | 47 | private string _title; 48 | public string Title 49 | { 50 | get => _title; 51 | set => _title = value; 52 | } 53 | 54 | private string _description; 55 | public string Description 56 | { 57 | get => _description; 58 | set => _description = value; 59 | } 60 | 61 | private Color _activeColor; 62 | public Color ActiveColor 63 | { 64 | get => _activeColor; 65 | set 66 | { 67 | if (_activeColor != value) 68 | { 69 | _activeColor = value; 70 | ActiveColorChanged?.Invoke(this); 71 | 72 | UpdateContrastColor(); 73 | } 74 | } 75 | } 76 | 77 | public string ActiveColorString => ColorUtils.FormatColorString(_activeColor, _activeColorStringFormat); 78 | 79 | private ColorStringFormat _activeColorStringFormat = ColorStringFormat.PoundRGB; 80 | public ColorStringFormat ActiveColorStringFormat => _activeColorStringFormat; 81 | 82 | public event Action ActiveColorChanged; 83 | 84 | private IReadOnlyList _contrastColors; 85 | public IReadOnlyList ContrastColors 86 | { 87 | get => _contrastColors; 88 | set 89 | { 90 | if (_contrastColors != value) 91 | { 92 | if (_contrastColors != null) 93 | { 94 | foreach (var c in _contrastColors) 95 | { 96 | c.Color.ActiveColorChanged -= ContrastColor_ActiveColorChanged; 97 | } 98 | } 99 | 100 | _contrastColors = value; 101 | 102 | if (_contrastColors != null) 103 | { 104 | foreach (var c in _contrastColors) 105 | { 106 | c.Color.ActiveColorChanged += ContrastColor_ActiveColorChanged; 107 | } 108 | } 109 | 110 | UpdateContrastColor(); 111 | } 112 | } 113 | } 114 | 115 | private void ContrastColor_ActiveColorChanged(IColorPaletteEntry obj) 116 | { 117 | UpdateContrastColor(); 118 | } 119 | 120 | private ContrastColorWrapper _bestContrastColor; 121 | public ContrastColorWrapper BestContrastColor => _bestContrastColor; 122 | 123 | public double BestContrastValue 124 | { 125 | get 126 | { 127 | if (_bestContrastColor == null) 128 | { 129 | return 0; 130 | } 131 | return ColorUtils.ContrastRatio(ActiveColor, _bestContrastColor.Color.ActiveColor); 132 | } 133 | } 134 | 135 | private void UpdateContrastColor() 136 | { 137 | ContrastColorWrapper newContrastColor = null; 138 | 139 | if (_contrastColors != null && _contrastColors.Count > 0) 140 | { 141 | double maxContrast = -1; 142 | foreach (var c in _contrastColors) 143 | { 144 | double contrast = ColorUtils.ContrastRatio(ActiveColor, c.Color.ActiveColor); 145 | if (contrast > maxContrast) 146 | { 147 | maxContrast = contrast; 148 | newContrastColor = c; 149 | } 150 | } 151 | } 152 | 153 | if (_bestContrastColor != newContrastColor) 154 | { 155 | _bestContrastColor = newContrastColor; 156 | ContrastColorChanged?.Invoke(this); 157 | } 158 | } 159 | 160 | public event Action ContrastColorChanged; 161 | } 162 | } 163 | 164 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/ColorPaletteEntryEditor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using Avalonia; 5 | using Avalonia.Controls; 6 | using Avalonia.Interactivity; 7 | using Avalonia.Layout; 8 | using Avalonia.Markup.Xaml.Templates; 9 | using Avalonia.Media; 10 | using Avalonia.Styling; 11 | 12 | namespace FluentEditorShared.ColorPalette 13 | { 14 | public enum ColorPaletteEntryCaptionMode { None, ActiveColorString, Title } 15 | 16 | public class ColorPaletteEntryEditor : Button 17 | { 18 | public ColorPaletteEntryEditor() 19 | { 20 | // Make sure each instance of the control gets its own brush instances 21 | ActiveColorBrush = new SolidColorBrush(); 22 | ContrastColorBrush = new SolidColorBrush(); 23 | 24 | Click += ColorPaletteEntryEditor_Click; 25 | } 26 | 27 | #region ColorPaletteEntryProperty 28 | 29 | public static readonly StyledProperty ColorPaletteEntryProperty = AvaloniaProperty.Register("ColorPaletteEntry"); 30 | 31 | private void OnColorPaletteEntryChanged(IColorPaletteEntry oldValue, IColorPaletteEntry newValue) 32 | { 33 | if (oldValue != null) 34 | { 35 | oldValue.ActiveColorChanged -= ColorPaletteEntry_ActiveColorChanged; 36 | oldValue.ContrastColorChanged -= ColorPaletteEntry_ContrastColorChanged; 37 | } 38 | 39 | if (newValue != null) 40 | { 41 | ActiveColorBrush.Color = newValue.ActiveColor; 42 | ContrastColorBrush.Color = newValue.BestContrastColor != null ? newValue.BestContrastColor.Color.ActiveColor : default(Color); 43 | newValue.ActiveColorChanged += ColorPaletteEntry_ActiveColorChanged; 44 | newValue.ContrastColorChanged += ColorPaletteEntry_ContrastColorChanged; 45 | 46 | if (_flyoutContent != null) 47 | { 48 | _flyoutContent.Content = newValue; 49 | } 50 | } 51 | else 52 | { 53 | HideFlyout(); 54 | ActiveColorBrush.Color = default(Color); 55 | ContrastColorBrush.Color = default(Color); 56 | } 57 | 58 | UpdateCaption(); 59 | } 60 | 61 | public IColorPaletteEntry ColorPaletteEntry 62 | { 63 | get => GetValue(ColorPaletteEntryProperty); 64 | set => SetValue(ColorPaletteEntryProperty, value); 65 | } 66 | 67 | #endregion 68 | 69 | #region CaptionModeProperty 70 | 71 | public static readonly StyledProperty CaptionModeProperty = AvaloniaProperty.Register("CaptionMode", ColorPaletteEntryCaptionMode.ActiveColorString); 72 | 73 | public ColorPaletteEntryCaptionMode CaptionMode 74 | { 75 | get => GetValue(CaptionModeProperty); 76 | set => SetValue(CaptionModeProperty, value); 77 | } 78 | 79 | #endregion 80 | 81 | #region CaptionProperty 82 | 83 | public static readonly StyledProperty CaptionProperty = AvaloniaProperty.Register("Caption"); 84 | 85 | public string Caption 86 | { 87 | get => GetValue(CaptionProperty); 88 | private set => SetValue(CaptionProperty, value); 89 | } 90 | 91 | #endregion 92 | 93 | #region FlyoutTemplateProperty 94 | 95 | public static readonly StyledProperty FlyoutTemplateProperty = AvaloniaProperty.Register("FlyoutTemplate"); 96 | 97 | public DataTemplate FlyoutTemplate 98 | { 99 | get => GetValue(FlyoutTemplateProperty); 100 | set => SetValue(FlyoutTemplateProperty, value); 101 | } 102 | 103 | #endregion 104 | 105 | #region FlyoutPresenterStyleProperty 106 | 107 | public static readonly StyledProperty FlyoutPresenterStyleProperty = AvaloniaProperty.Register("FlyoutPresenterStyle"); 108 | 109 | public ControlTheme FlyoutPresenterStyle 110 | { 111 | get => GetValue(FlyoutPresenterStyleProperty); 112 | set => SetValue(FlyoutPresenterStyleProperty, value); 113 | } 114 | 115 | #endregion 116 | 117 | #region ActiveColorBrushProperty 118 | 119 | public static readonly StyledProperty ActiveColorBrushProperty = AvaloniaProperty.Register("ActiveColorBrush", new SolidColorBrush()); 120 | 121 | public SolidColorBrush ActiveColorBrush 122 | { 123 | get => GetValue(ActiveColorBrushProperty); 124 | private set => SetValue(ActiveColorBrushProperty, value); 125 | } 126 | 127 | #endregion 128 | 129 | #region ContrastColorBrushProperty 130 | 131 | public static readonly StyledProperty ContrastColorBrushProperty = AvaloniaProperty.Register("ContrastColorBrush", new SolidColorBrush()); 132 | 133 | public SolidColorBrush ContrastColorBrush 134 | { 135 | get => GetValue(ContrastColorBrushProperty); 136 | private set => SetValue(ContrastColorBrushProperty, value); 137 | } 138 | 139 | #endregion 140 | 141 | private void ColorPaletteEntry_ActiveColorChanged(IColorPaletteEntry obj) 142 | { 143 | var paletteEntry = ColorPaletteEntry; 144 | if (paletteEntry == null) 145 | { 146 | return; 147 | } 148 | ActiveColorBrush.Color = paletteEntry.ActiveColor; 149 | 150 | UpdateCaption(); 151 | } 152 | 153 | private void ColorPaletteEntry_ContrastColorChanged(IColorPaletteEntry obj) 154 | { 155 | var paletteEntry = ColorPaletteEntry; 156 | if (paletteEntry == null) 157 | { 158 | return; 159 | } 160 | ContrastColorBrush.Color = paletteEntry.BestContrastColor != null ? paletteEntry.BestContrastColor.Color.ActiveColor : default(Color); 161 | } 162 | 163 | private void UpdateCaption() 164 | { 165 | var captionMode = CaptionMode; 166 | var paletteEntry = ColorPaletteEntry; 167 | switch (captionMode) 168 | { 169 | case ColorPaletteEntryCaptionMode.None: 170 | Caption = string.Empty; 171 | break; 172 | case ColorPaletteEntryCaptionMode.ActiveColorString: 173 | Caption = paletteEntry != null ? paletteEntry.ActiveColorString : string.Empty; 174 | break; 175 | case ColorPaletteEntryCaptionMode.Title: 176 | Caption = paletteEntry != null ? paletteEntry.Title : string.Empty; 177 | break; 178 | } 179 | } 180 | 181 | private void ColorPaletteEntryEditor_Click(object sender, RoutedEventArgs e) 182 | { 183 | ShowFlyout(); 184 | } 185 | 186 | private Flyout _flyout; 187 | private ContentControl _flyoutContent; 188 | 189 | private void ShowFlyout() 190 | { 191 | HideFlyout(); 192 | 193 | var flyoutTemplate = FlyoutTemplate; 194 | if (flyoutTemplate == null) 195 | { 196 | return; 197 | } 198 | 199 | var paletteEntry = ColorPaletteEntry; 200 | 201 | Flyout flyout = new Flyout(); 202 | 203 | var flyoutPresenterStyle = FlyoutPresenterStyle; 204 | if(flyoutPresenterStyle != null) 205 | { 206 | flyout.FlyoutPresenterTheme = flyoutPresenterStyle; 207 | } 208 | 209 | ContentControl flyoutContent = new ContentControl(); 210 | flyoutContent.ContentTemplate = flyoutTemplate; 211 | flyoutContent.Content = paletteEntry; 212 | flyoutContent.HorizontalAlignment = HorizontalAlignment.Stretch; 213 | flyoutContent.VerticalAlignment = VerticalAlignment.Stretch; 214 | flyoutContent.Margin = new Thickness(0); 215 | flyoutContent.Padding = new Thickness(0); 216 | 217 | flyout.Content = flyoutContent; 218 | 219 | flyout.ShowAt(this); 220 | } 221 | 222 | private void HideFlyout() 223 | { 224 | if (_flyout != null) 225 | { 226 | _flyout.Hide(); 227 | _flyout = null; 228 | _flyoutContent = null; 229 | } 230 | } 231 | 232 | protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) 233 | { 234 | base.OnPropertyChanged(change); 235 | 236 | if (change.Property == CaptionModeProperty) 237 | { 238 | UpdateCaption(); 239 | } 240 | else if (change.Property == ColorPaletteEntryProperty) 241 | { 242 | var (oldValue, newValue) = change.GetOldAndNewValue(); 243 | OnColorPaletteEntryChanged(oldValue, newValue); 244 | } 245 | } 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/ContrastColorWrapper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System; 5 | 6 | namespace FluentEditorShared.ColorPalette 7 | { 8 | public class ContrastColorWrapper 9 | { 10 | public ContrastColorWrapper(IColorPaletteEntry color, bool showInContrastList, bool showContrastErrors) 11 | { 12 | if(color == null) 13 | { 14 | throw new ArgumentNullException("color"); 15 | } 16 | Color = color; 17 | ShowInContrastList = showInContrastList; 18 | ShowContrastErrors = showContrastErrors; 19 | } 20 | 21 | public IColorPaletteEntry Color { get; } 22 | 23 | public bool ShowInContrastList { get; } 24 | 25 | public bool ShowContrastErrors { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/ContrastListItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System.ComponentModel; 5 | using System.Runtime.CompilerServices; 6 | using Avalonia.Media; 7 | using FluentEditorShared.Utils; 8 | 9 | namespace FluentEditorShared.ColorPalette 10 | { 11 | public class ContrastListItem : INotifyPropertyChanged 12 | { 13 | public ContrastListItem() { } 14 | public ContrastListItem(IColorPaletteEntry baseColor, IColorPaletteEntry contrastColor, double minContrast = 4.5) 15 | { 16 | _minContrast = minContrast; 17 | _baseColorBrush = new SolidColorBrush(); 18 | _contrastColorBrush = new SolidColorBrush(); 19 | 20 | BaseColor = baseColor; 21 | ContrastColor = contrastColor; 22 | } 23 | 24 | private void RecalcContrast() 25 | { 26 | if (_baseColor == null || _contrastColor == null) 27 | { 28 | Contrast = 0.0; 29 | return; 30 | } 31 | 32 | Contrast = ColorUtils.ContrastRatio(_baseColor.ActiveColor, _contrastColor.ActiveColor); 33 | } 34 | 35 | private double _minContrast; 36 | private double _contrast; 37 | public double Contrast 38 | { 39 | get => _contrast; 40 | private set 41 | { 42 | if (_contrast != value) 43 | { 44 | _contrast = value; 45 | RaisePropertyChangedFromSource(); 46 | 47 | RaisePropertyChanged("ContrastError"); 48 | } 49 | } 50 | } 51 | 52 | public bool ContrastError 53 | { 54 | get 55 | { 56 | if(_minContrast <= 0) 57 | { 58 | return false; 59 | } 60 | return _contrast < _minContrast; 61 | } 62 | } 63 | 64 | private IColorPaletteEntry _baseColor; 65 | public IColorPaletteEntry BaseColor 66 | { 67 | get => _baseColor; 68 | set 69 | { 70 | if (_baseColor != value) 71 | { 72 | if (_baseColor != null) 73 | { 74 | _baseColor.ActiveColorChanged -= _baseColor_ActiveColorChanged; 75 | } 76 | 77 | _baseColor = value; 78 | RaisePropertyChangedFromSource(); 79 | 80 | if (_baseColor != null) 81 | { 82 | _baseColorBrush.Color = _baseColor.ActiveColor; 83 | _baseColor.ActiveColorChanged += _baseColor_ActiveColorChanged; 84 | } 85 | 86 | RecalcContrast(); 87 | } 88 | } 89 | } 90 | 91 | private void _baseColor_ActiveColorChanged(IColorPaletteEntry obj) 92 | { 93 | _baseColorBrush.Color = obj.ActiveColor; 94 | RecalcContrast(); 95 | } 96 | 97 | private SolidColorBrush _baseColorBrush; 98 | public SolidColorBrush BaseColorBrush => _baseColorBrush; 99 | 100 | private IColorPaletteEntry _contrastColor; 101 | public IColorPaletteEntry ContrastColor 102 | { 103 | get => _contrastColor; 104 | set 105 | { 106 | if (_contrastColor != value) 107 | { 108 | if (_contrastColor != null) 109 | { 110 | _contrastColor.ActiveColorChanged -= _contrastColor_ActiveColorChanged; 111 | } 112 | 113 | _contrastColor = value; 114 | RaisePropertyChangedFromSource(); 115 | 116 | if (_contrastColor != null) 117 | { 118 | _contrastColorBrush.Color = _contrastColor.ActiveColor; 119 | _contrastColor.ActiveColorChanged += _contrastColor_ActiveColorChanged; 120 | } 121 | 122 | RecalcContrast(); 123 | } 124 | } 125 | } 126 | 127 | private void _contrastColor_ActiveColorChanged(IColorPaletteEntry obj) 128 | { 129 | _contrastColorBrush.Color = obj.ActiveColor; 130 | RecalcContrast(); 131 | } 132 | 133 | private SolidColorBrush _contrastColorBrush; 134 | public SolidColorBrush ContrastColorBrush => _contrastColorBrush; 135 | 136 | #region INotifyPropertyChanged 137 | 138 | public event PropertyChangedEventHandler PropertyChanged; 139 | 140 | private void RaisePropertyChanged(string name) 141 | { 142 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); 143 | } 144 | 145 | private void RaisePropertyChangedFromSource([CallerMemberName] string name = null) 146 | { 147 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); 148 | } 149 | 150 | #endregion 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/EditableColorPaletteEntry.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text.Json.Nodes; 7 | using Avalonia.Media; 8 | using FluentEditorShared.Utils; 9 | 10 | namespace FluentEditorShared.ColorPalette 11 | { 12 | // These classes are not intended to be viewmodels. 13 | // They deal with the data about an editable palette and are passed to special purpose controls for editing 14 | public class EditableColorPaletteEntry : IColorPaletteEntry 15 | { 16 | public static EditableColorPaletteEntry Parse(JsonObject data, IColorPaletteEntry sourceColor, IReadOnlyList contrastColors) 17 | { 18 | Color customColor; 19 | if (data.ContainsKey("CustomColor")) 20 | { 21 | customColor = data["CustomColor"].GetColor(); 22 | } 23 | else 24 | { 25 | customColor = default(Color); 26 | } 27 | bool useCustomColor = false; 28 | if (data.ContainsKey("UseCustomColor")) 29 | { 30 | useCustomColor = data["UseCustomColor"].GetValue(); 31 | } 32 | 33 | ColorStringFormat activeColorStringFormat = ColorStringFormat.PoundRGB; 34 | if (data.ContainsKey("ActiveColorStringFormat")) 35 | { 36 | activeColorStringFormat = data.GetEnum(); 37 | } 38 | 39 | return new EditableColorPaletteEntry(sourceColor, customColor, useCustomColor, data.GetOptionalString("Title"), data.GetOptionalString("Description"), activeColorStringFormat, contrastColors); 40 | } 41 | 42 | public EditableColorPaletteEntry(IColorPaletteEntry sourceColor, Color customColor, bool useCustomColor, string title, string description, ColorStringFormat activeColorStringFormat, IReadOnlyList contrastColors) 43 | { 44 | _sourceColor = sourceColor; 45 | _customColor = customColor; 46 | _useCustomColor = useCustomColor; 47 | _title = title; 48 | _description = description; 49 | _activeColorStringFormat = activeColorStringFormat; 50 | 51 | if (_useCustomColor || _sourceColor == null) 52 | { 53 | _activeColor = _customColor; 54 | } 55 | else 56 | { 57 | _activeColor = _sourceColor.ActiveColor; 58 | } 59 | 60 | ContrastColors = contrastColors; 61 | } 62 | 63 | private string _title; 64 | public string Title 65 | { 66 | get => _title; 67 | set => _title = value; 68 | } 69 | 70 | private string _description; 71 | public string Description 72 | { 73 | get => _description; 74 | set => _description = value; 75 | } 76 | 77 | private IColorPaletteEntry _sourceColor; 78 | public IColorPaletteEntry SourceColor 79 | { 80 | get => _sourceColor; 81 | set 82 | { 83 | if (_sourceColor != null) 84 | { 85 | _sourceColor.ActiveColorChanged -= _sourceColor_ActiveColorChanged; 86 | } 87 | 88 | _sourceColor = value; 89 | 90 | if (_sourceColor != null) 91 | { 92 | _sourceColor.ActiveColorChanged += _sourceColor_ActiveColorChanged; 93 | } 94 | 95 | CheckActiveColor(); 96 | } 97 | } 98 | 99 | private void _sourceColor_ActiveColorChanged(IColorPaletteEntry obj) 100 | { 101 | CheckActiveColor(); 102 | } 103 | 104 | private Color _customColor; 105 | public Color CustomColor 106 | { 107 | get => _customColor; 108 | set 109 | { 110 | if (_customColor != value) 111 | { 112 | _customColor = value; 113 | CustomColorChanged?.Invoke(this); 114 | 115 | CheckActiveColor(); 116 | } 117 | } 118 | } 119 | 120 | public event Action CustomColorChanged; 121 | 122 | private bool _useCustomColor; 123 | public bool UseCustomColor 124 | { 125 | get => _useCustomColor; 126 | set 127 | { 128 | if (_useCustomColor != value) 129 | { 130 | _useCustomColor = value; 131 | 132 | CheckActiveColor(); 133 | } 134 | } 135 | } 136 | 137 | private void CheckActiveColor() 138 | { 139 | Color newVal; 140 | 141 | if (_useCustomColor || _sourceColor == null) 142 | { 143 | newVal = _customColor; 144 | } 145 | else 146 | { 147 | newVal = _sourceColor.ActiveColor; 148 | } 149 | 150 | if (newVal != _activeColor) 151 | { 152 | _activeColor = newVal; 153 | ActiveColorChanged?.Invoke(this); 154 | 155 | UpdateContrastColor(); 156 | } 157 | } 158 | 159 | private Color _activeColor; 160 | public Color ActiveColor 161 | { 162 | get => _activeColor; 163 | set 164 | { 165 | CustomColor = value; 166 | if (_sourceColor != null) 167 | { 168 | UseCustomColor = _customColor != _sourceColor.ActiveColor; 169 | } 170 | } 171 | } 172 | 173 | public string ActiveColorString => ColorUtils.FormatColorString(_activeColor, _activeColorStringFormat); 174 | 175 | private ColorStringFormat _activeColorStringFormat = ColorStringFormat.PoundRGB; 176 | public ColorStringFormat ActiveColorStringFormat => _activeColorStringFormat; 177 | 178 | public event Action ActiveColorChanged; 179 | 180 | private IReadOnlyList _contrastColors; 181 | public IReadOnlyList ContrastColors 182 | { 183 | get => _contrastColors; 184 | set 185 | { 186 | if (_contrastColors != value) 187 | { 188 | if (_contrastColors != null) 189 | { 190 | foreach (var c in _contrastColors) 191 | { 192 | c.Color.ActiveColorChanged -= ContrastColor_ActiveColorChanged; 193 | } 194 | } 195 | 196 | _contrastColors = value; 197 | 198 | if (_contrastColors != null) 199 | { 200 | foreach (var c in _contrastColors) 201 | { 202 | c.Color.ActiveColorChanged += ContrastColor_ActiveColorChanged; 203 | } 204 | } 205 | 206 | UpdateContrastColor(); 207 | } 208 | } 209 | } 210 | 211 | private void ContrastColor_ActiveColorChanged(IColorPaletteEntry obj) 212 | { 213 | UpdateContrastColor(); 214 | } 215 | 216 | private ContrastColorWrapper _bestContrastColor; 217 | public ContrastColorWrapper BestContrastColor => _bestContrastColor; 218 | 219 | public double BestContrastValue 220 | { 221 | get 222 | { 223 | if (_bestContrastColor == null) 224 | { 225 | return 0; 226 | } 227 | return ColorUtils.ContrastRatio(ActiveColor, _bestContrastColor.Color.ActiveColor); 228 | } 229 | } 230 | 231 | private void UpdateContrastColor() 232 | { 233 | ContrastColorWrapper newContrastColor = null; 234 | 235 | if (_contrastColors != null && _contrastColors.Count > 0) 236 | { 237 | double maxContrast = -1; 238 | foreach (var c in _contrastColors) 239 | { 240 | double contrast = ColorUtils.ContrastRatio(ActiveColor, c.Color.ActiveColor); 241 | if (contrast > maxContrast) 242 | { 243 | maxContrast = contrast; 244 | newContrastColor = c; 245 | } 246 | } 247 | } 248 | 249 | if (_bestContrastColor != newContrastColor) 250 | { 251 | _bestContrastColor = newContrastColor; 252 | ContrastColorChanged?.Invoke(this); 253 | } 254 | } 255 | 256 | public event Action ContrastColorChanged; 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /FluentEditorShared/ColorPalette/ExpandedColorPaletteEntryEditor.axaml: -------------------------------------------------------------------------------- 1 |  5 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 38 | 44 | 51 | 56 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 76 | 84 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 104 | 105 |