Removed a no-longer needed file.
Working on the builder. Made a dark-mode-friendly hightlight file for Browser .
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<PackageVersion Include="Jint" Version="4.4.2" />
|
||||
<PackageVersion Include="Microsoft.Maui.Graphics" Version="10.0.11" />
|
||||
<PackageVersion Include="Microsoft.Maui.Graphics.Skia" Version="10.0.11" />
|
||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
<PackageVersion Include="PanAndZoom" Version="11.3.6" />
|
||||
<PackageVersion Include="SkiaSharp" Version="3.116.1" />
|
||||
<PackageVersion Include="SkiaSharp.NativeAssets.WebAssembly" Version="3.116.1" />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jint" />
|
||||
<PackageReference Include="Newtonsoft.Json" />
|
||||
<PackageReference Include="SkiaSharp" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
58
Progrart.Core/ProjectSystem/Builder.cs
Normal file
58
Progrart.Core/ProjectSystem/Builder.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Newtonsoft.Json;
|
||||
using Progrart.Core.JSExecution;
|
||||
|
||||
namespace Progrart.Core.ProjectSystem
|
||||
{
|
||||
public class Builder
|
||||
{
|
||||
public Project project;
|
||||
public string basePath;
|
||||
public Action<int, int>? OnProgressUpdate;
|
||||
public Action? OnCompleted;
|
||||
public Builder(StreamReader reader, string basePath)
|
||||
{
|
||||
var project = JsonConvert.DeserializeObject<Project>(reader.ReadToEnd());
|
||||
if (project is null) throw new JsonSerializationException();
|
||||
this.project = project;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
public Builder(Project project, string basePath)
|
||||
{
|
||||
this.project = project;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
public void Execute(BuildConfiguration config, BuildItem item)
|
||||
{
|
||||
FileInfo src = new FileInfo(Path.Combine(basePath, item.Source));
|
||||
FileInfo tgt = new FileInfo(Path.Combine(basePath, project.OutputDir, item.Target ?? item.Source + ".png"));
|
||||
var args = project.Arguments.Clone();
|
||||
args.MergeFrom(config.Arguments);
|
||||
args.MergeFrom(item.Arguments);
|
||||
ProgrartExecutor executor = new ProgrartExecutor();
|
||||
using var stream = src.OpenRead();
|
||||
using var reader = new StreamReader(stream);
|
||||
var img = executor.RenderImage(item.Size, reader.ReadToEnd(), args);
|
||||
using var img_stream = tgt.OpenWrite();
|
||||
img.DrawingCore.ToData().SaveTo(img_stream);
|
||||
img_stream.Flush();
|
||||
}
|
||||
public void Build(string targetConfig)
|
||||
{
|
||||
foreach (var config in project.Configurations)
|
||||
{
|
||||
if (config.Name == targetConfig)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var item in config.Items)
|
||||
{
|
||||
Execute(config, item);
|
||||
index++;
|
||||
OnProgressUpdate?.Invoke(config.Items.Count, index);
|
||||
}
|
||||
OnCompleted?.Invoke();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,18 +7,24 @@ namespace Progrart.Core.ProjectSystem
|
||||
[Serializable]
|
||||
public class Project
|
||||
{
|
||||
public string OutputDir = "output";
|
||||
public List<BuildConfiguration> Configurations = new List<BuildConfiguration>();
|
||||
public ExecuteArguments Arguments = new ExecuteArguments();
|
||||
}
|
||||
[Serializable]
|
||||
public class BuildConfiguration
|
||||
{
|
||||
public string? Name;
|
||||
public string? OutputDir;
|
||||
public List<BuildItem> Items = new List<BuildItem>();
|
||||
public ExecuteArguments Arguments = new ExecuteArguments();
|
||||
}
|
||||
[Serializable]
|
||||
public class BuildItem
|
||||
{
|
||||
public string? Source;
|
||||
public string Source = "";
|
||||
public string? Target;
|
||||
public int Size;
|
||||
public ExecuteArguments Arguments = new ExecuteArguments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Progrart.Core
|
||||
}
|
||||
public float TranslateSize(float s)
|
||||
{
|
||||
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height)/ Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
|
||||
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height) / Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
|
||||
}
|
||||
public RenderContext(int W, int H)
|
||||
{
|
||||
@@ -61,10 +61,27 @@ namespace Progrart.Core
|
||||
surface.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ExecuteArguments
|
||||
{
|
||||
public Dictionary<string, string> data = new Dictionary<string, string>();
|
||||
public ExecuteArguments Clone()
|
||||
{
|
||||
ExecuteArguments args = new ExecuteArguments();
|
||||
foreach (var item in data)
|
||||
{
|
||||
args.data.Add(item.Key, item.Value);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
public void MergeFrom(ExecuteArguments args)
|
||||
{
|
||||
|
||||
foreach (var item in args.data)
|
||||
{
|
||||
args.data.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class RenderConfig
|
||||
|
||||
129
Progrart/Assets/Styles/JavaScript.xml
Normal file
129
Progrart/Assets/Styles/JavaScript.xml
Normal file
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- syntaxdefinition for JavaScript 2.0 by Svante Lidman -->
|
||||
<!-- converted to AvalonEdit format by Siegfried Pammer in 2010 -->
|
||||
<!-- Modified from JavaScript-Mode.xml from AvaloniaEdit-->
|
||||
<SyntaxDefinition name="JavaScript" extensions=".js" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
|
||||
<Color name="Digits" foreground="#a8bf9c" exampleText="3.14" />
|
||||
<Color name="Comment" foreground="#57a64a" exampleText="// comment" />
|
||||
<Color name="String" foreground="#C18746" exampleText="var text = "Hello, World!";" />
|
||||
<Color name="Character" foreground="#C18746" exampleText="var char = 'a';" />
|
||||
<Color name="Regex" foreground="#C18746" exampleText="/abc/m" />
|
||||
<Color name="JavaScriptKeyWords" foreground="#C586C0" exampleText="return myVariable;" />
|
||||
<Color name="JavaScriptIntrinsics" foreground="#4ec9b5" exampleText="Math.random()" />
|
||||
<Color name="JavaScriptLiterals" foreground="#569cd6" exampleText="return false;" />
|
||||
<Color name="JavaScriptGlobalFunctions" foreground="#4ec9b5" exampleText="escape(myString);" />
|
||||
<RuleSet ignoreCase="false">
|
||||
<Keywords color="JavaScriptKeyWords">
|
||||
<Word>break</Word>
|
||||
<Word>continue</Word>
|
||||
<Word>delete</Word>
|
||||
<Word>else</Word>
|
||||
<Word>for</Word>
|
||||
<Word>function</Word>
|
||||
<Word>if</Word>
|
||||
<Word>in</Word>
|
||||
<Word>new</Word>
|
||||
<Word>return</Word>
|
||||
<Word>this</Word>
|
||||
<Word>typeof</Word>
|
||||
<Word>var</Word>
|
||||
<Word>void</Word>
|
||||
<Word>while</Word>
|
||||
<Word>with</Word>
|
||||
<Word>abstract</Word>
|
||||
<Word>boolean</Word>
|
||||
<Word>byte</Word>
|
||||
<Word>case</Word>
|
||||
<Word>catch</Word>
|
||||
<Word>char</Word>
|
||||
<Word>class</Word>
|
||||
<Word>const</Word>
|
||||
<Word>debugger</Word>
|
||||
<Word>default</Word>
|
||||
<Word>do</Word>
|
||||
<Word>double</Word>
|
||||
<Word>enum</Word>
|
||||
<Word>export</Word>
|
||||
<Word>extends</Word>
|
||||
<Word>final</Word>
|
||||
<Word>finally</Word>
|
||||
<Word>float</Word>
|
||||
<Word>goto</Word>
|
||||
<Word>implements</Word>
|
||||
<Word>import</Word>
|
||||
<Word>instanceof</Word>
|
||||
<Word>int</Word>
|
||||
<Word>interface</Word>
|
||||
<Word>long</Word>
|
||||
<Word>native</Word>
|
||||
<Word>package</Word>
|
||||
<Word>private</Word>
|
||||
<Word>protected</Word>
|
||||
<Word>public</Word>
|
||||
<Word>short</Word>
|
||||
<Word>static</Word>
|
||||
<Word>super</Word>
|
||||
<Word>switch</Word>
|
||||
<Word>synchronized</Word>
|
||||
<Word>throw</Word>
|
||||
<Word>throws</Word>
|
||||
<Word>transient</Word>
|
||||
<Word>try</Word>
|
||||
<Word>volatile</Word>
|
||||
</Keywords>
|
||||
<Keywords color="JavaScriptIntrinsics">
|
||||
<Word>Array</Word>
|
||||
<Word>Boolean</Word>
|
||||
<Word>Date</Word>
|
||||
<Word>Function</Word>
|
||||
<Word>Global</Word>
|
||||
<Word>Math</Word>
|
||||
<Word>Number</Word>
|
||||
<Word>Object</Word>
|
||||
<Word>RegExp</Word>
|
||||
<Word>String</Word>
|
||||
</Keywords>
|
||||
<Keywords color="JavaScriptLiterals">
|
||||
<Word>false</Word>
|
||||
<Word>null</Word>
|
||||
<Word>true</Word>
|
||||
<Word>NaN</Word>
|
||||
<Word>Infinity</Word>
|
||||
</Keywords>
|
||||
<Keywords color="JavaScriptGlobalFunctions">
|
||||
<Word>eval</Word>
|
||||
<Word>parseInt</Word>
|
||||
<Word>parseFloat</Word>
|
||||
<Word>escape</Word>
|
||||
<Word>unescape</Word>
|
||||
<Word>isNaN</Word>
|
||||
<Word>isFinite</Word>
|
||||
</Keywords>
|
||||
<Span color="Comment">
|
||||
<Begin>//</Begin>
|
||||
</Span>
|
||||
<Span color="Comment" multiline="true">
|
||||
<Begin>/\*</Begin>
|
||||
<End>\*/</End>
|
||||
</Span>
|
||||
<Span color="Regex">
|
||||
<Begin>(?<!([})\]\w]+\s*))/</Begin>
|
||||
<End>/</End>
|
||||
</Span>
|
||||
<Span color="String" multiline="true">
|
||||
<Begin>"</Begin>
|
||||
<End>"</End>
|
||||
<RuleSet>
|
||||
<Span begin="\\" end="." />
|
||||
</RuleSet>
|
||||
</Span>
|
||||
<Span color="Character">
|
||||
<Begin>'</Begin>
|
||||
<End>'</End>
|
||||
<RuleSet>
|
||||
<Span begin="\\" end="." />
|
||||
</RuleSet>
|
||||
</Span>
|
||||
<Rule color="Digits">\b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?</Rule>
|
||||
</RuleSet>
|
||||
</SyntaxDefinition>
|
||||
@@ -7,12 +7,14 @@
|
||||
x:Class="Progrart.Controls.BaseEditor">
|
||||
<avaloniaedit:TextEditor Name="CodeEditBox" Text=""
|
||||
ShowLineNumbers="True"
|
||||
FontFamily="Sarasa Mono Slab CL,Cascadia Code,Consolas,Menlo,Monospace">
|
||||
FontFamily="Sarasa Mono Slab CL,Cascadia Code,Roboto Mono,Consolas,Menlo,Monospace">
|
||||
<avaloniaedit:TextEditor.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="_Copy" Click="Copy_Click"/>
|
||||
<MenuItem Header="Cut (_X)" Click="Cut_Click"/>
|
||||
<MenuItem Header="Paste (_V)" Click="Paste_Click"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="_Find" Click="Find_Click"/>
|
||||
</ContextMenu>
|
||||
</avaloniaedit:TextEditor.ContextMenu>
|
||||
</avaloniaedit:TextEditor>
|
||||
|
||||
@@ -2,12 +2,17 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform;
|
||||
using AvaloniaEdit;
|
||||
using AvaloniaEdit.Highlighting;
|
||||
using AvaloniaEdit.Highlighting.Xshd;
|
||||
using AvaloniaEdit.TextMate;
|
||||
using Progrart.Commands;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
using TextMateSharp.Grammars;
|
||||
|
||||
namespace Progrart.Controls;
|
||||
@@ -25,7 +30,19 @@ public partial class BaseEditor : UserControl
|
||||
public BaseEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
var uri = new Uri("avares://Progrart/Assets/Styles/JavaScript.xml");
|
||||
|
||||
if (AssetLoader.Exists(uri))
|
||||
{
|
||||
using (Stream stream = AssetLoader.Open(uri))
|
||||
{
|
||||
using (XmlReader reader = XmlReader.Create(stream))
|
||||
{
|
||||
var xshd = HighlightingLoader.LoadXshd(reader);
|
||||
CodeEditBox.SyntaxHighlighting = HighlightingLoader.Load(xshd, HighlightingManager.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!OperatingSystem.IsBrowser())
|
||||
{
|
||||
var _textEditor = CodeEditBox;
|
||||
@@ -74,4 +91,10 @@ public partial class BaseEditor : UserControl
|
||||
{
|
||||
CodeEditBox.Cut();
|
||||
}
|
||||
|
||||
private void Find_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
CodeEditBox.SearchPanel.Open();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Progrart.Pages
|
||||
{
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
{
|
||||
IStorageFile? file = null;
|
||||
TabButton? btn = null;
|
||||
Bitmap? image;
|
||||
public ProgrartEditorPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -52,16 +53,19 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
}
|
||||
var result = executor.RenderImage(1024, CodeEditor.Text, args ?? new ExecuteArguments());
|
||||
var data = result.DrawingCore.ToData();
|
||||
var imgFile = Path.GetTempFileName();
|
||||
Trace.WriteLine($"Generated to:{imgFile}");
|
||||
using (var stream = File.OpenWrite(imgFile))
|
||||
{
|
||||
using MemoryStream stream = new MemoryStream();
|
||||
|
||||
data.SaveTo(stream);
|
||||
stream.Flush();
|
||||
stream.Close();
|
||||
}
|
||||
Bitmap image = new Bitmap(imgFile);
|
||||
|
||||
stream.Position = 0;
|
||||
Bitmap image = new Bitmap(stream);
|
||||
PreviewImage.SetImage(image);
|
||||
if (this.image != null)
|
||||
{
|
||||
this.image.Dispose();
|
||||
}
|
||||
this.image = image;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
@@ -91,20 +95,16 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
{
|
||||
CodeEditor.SetGrammerByExtension(".js");
|
||||
}
|
||||
Trace.WriteLine($"File:{file.TryGetLocalPath() ?? "null"}");
|
||||
Task.Run(async () =>
|
||||
{
|
||||
using var stream = await file.OpenReadAsync();
|
||||
using StreamReader sr = new StreamReader(stream);
|
||||
var text = sr.ReadToEnd();
|
||||
if (OperatingSystem.IsBrowser())
|
||||
{
|
||||
|
||||
CodeEditor.Text = text;
|
||||
}
|
||||
else
|
||||
var text = await sr.ReadToEndAsync();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
CodeEditor.Text = text;
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Assets\Styles\JavaScript.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" />
|
||||
<PackageReference Include="Avalonia.AvaloniaEdit" />
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<MenuItem Header="_Open">
|
||||
<MenuItem Header="_Project" Name="OpenProjectMenuItem"/>
|
||||
</MenuItem>
|
||||
<Separator/>
|
||||
<MenuItem Header="_Save" Click="MenuItem_Save_Click"/>
|
||||
<MenuItem Header="Save A_ll" Click="MenuItem_SaveAll_Click"/>
|
||||
<MenuItem Header="Save _As"/>
|
||||
|
||||
@@ -22,16 +22,17 @@ public partial class MainView : UserControl
|
||||
InitializeComponent();
|
||||
Trace.Listeners.Add(new ConsoleLogger());
|
||||
EditorProvider.setHost(MainTabHost);
|
||||
MenuButton.Focus();
|
||||
this.KeyBindings.Add(new Avalonia.Input.KeyBinding()
|
||||
{
|
||||
Gesture = new Avalonia.Input.KeyGesture(Avalonia.Input.Key.Space,
|
||||
Avalonia.Input.KeyModifiers.Shift | Avalonia.Input.KeyModifiers.Control),
|
||||
Avalonia.Input.KeyModifiers.Control | Avalonia.Input.KeyModifiers.Shift),
|
||||
Command = new GenericCommand()
|
||||
{
|
||||
Checker = (_) => true,
|
||||
onExecute = (_) =>
|
||||
{
|
||||
MenuButton.ContextMenu?.Open();
|
||||
MenuButton.Flyout?.ShowAt(MenuButton);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user