svelte-sharp 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +311 -2
- package/compiler/win-x64/Microsoft.CSharp.dll +0 -0
- package/compiler/win-x64/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/compiler/win-x64/Microsoft.CodeAnalysis.dll +0 -0
- package/compiler/win-x64/Microsoft.DiaSymReader.Native.amd64.dll +0 -0
- package/compiler/win-x64/Microsoft.VisualBasic.Core.dll +0 -0
- package/compiler/win-x64/Microsoft.VisualBasic.dll +0 -0
- package/compiler/win-x64/Microsoft.Win32.Primitives.dll +0 -0
- package/compiler/win-x64/Microsoft.Win32.Registry.dll +0 -0
- package/compiler/win-x64/SvelteSharp.Compiler.deps.json +882 -0
- package/compiler/win-x64/SvelteSharp.Compiler.dll +0 -0
- package/compiler/win-x64/SvelteSharp.Compiler.exe +0 -0
- package/compiler/win-x64/SvelteSharp.Compiler.runtimeconfig.json +15 -0
- package/compiler/win-x64/System.AppContext.dll +0 -0
- package/compiler/win-x64/System.Buffers.dll +0 -0
- package/compiler/win-x64/System.Collections.Concurrent.dll +0 -0
- package/compiler/win-x64/System.Collections.Immutable.dll +0 -0
- package/compiler/win-x64/System.Collections.NonGeneric.dll +0 -0
- package/compiler/win-x64/System.Collections.Specialized.dll +0 -0
- package/compiler/win-x64/System.Collections.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.Annotations.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.DataAnnotations.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.EventBasedAsync.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.Primitives.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.TypeConverter.dll +0 -0
- package/compiler/win-x64/System.ComponentModel.dll +0 -0
- package/compiler/win-x64/System.Configuration.dll +0 -0
- package/compiler/win-x64/System.Console.dll +0 -0
- package/compiler/win-x64/System.Core.dll +0 -0
- package/compiler/win-x64/System.Data.Common.dll +0 -0
- package/compiler/win-x64/System.Data.DataSetExtensions.dll +0 -0
- package/compiler/win-x64/System.Data.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Contracts.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Debug.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.DiagnosticSource.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.FileVersionInfo.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Process.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.StackTrace.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.TextWriterTraceListener.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Tools.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.TraceSource.dll +0 -0
- package/compiler/win-x64/System.Diagnostics.Tracing.dll +0 -0
- package/compiler/win-x64/System.Drawing.Primitives.dll +0 -0
- package/compiler/win-x64/System.Drawing.dll +0 -0
- package/compiler/win-x64/System.Dynamic.Runtime.dll +0 -0
- package/compiler/win-x64/System.Formats.Asn1.dll +0 -0
- package/compiler/win-x64/System.Formats.Tar.dll +0 -0
- package/compiler/win-x64/System.Globalization.Calendars.dll +0 -0
- package/compiler/win-x64/System.Globalization.Extensions.dll +0 -0
- package/compiler/win-x64/System.Globalization.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.Brotli.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.FileSystem.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.Native.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.ZipFile.dll +0 -0
- package/compiler/win-x64/System.IO.Compression.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.AccessControl.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.DriveInfo.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.Primitives.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.Watcher.dll +0 -0
- package/compiler/win-x64/System.IO.FileSystem.dll +0 -0
- package/compiler/win-x64/System.IO.IsolatedStorage.dll +0 -0
- package/compiler/win-x64/System.IO.MemoryMappedFiles.dll +0 -0
- package/compiler/win-x64/System.IO.Pipelines.dll +0 -0
- package/compiler/win-x64/System.IO.Pipes.AccessControl.dll +0 -0
- package/compiler/win-x64/System.IO.Pipes.dll +0 -0
- package/compiler/win-x64/System.IO.UnmanagedMemoryStream.dll +0 -0
- package/compiler/win-x64/System.IO.dll +0 -0
- package/compiler/win-x64/System.Linq.Expressions.dll +0 -0
- package/compiler/win-x64/System.Linq.Parallel.dll +0 -0
- package/compiler/win-x64/System.Linq.Queryable.dll +0 -0
- package/compiler/win-x64/System.Linq.dll +0 -0
- package/compiler/win-x64/System.Memory.dll +0 -0
- package/compiler/win-x64/System.Net.Http.Json.dll +0 -0
- package/compiler/win-x64/System.Net.Http.dll +0 -0
- package/compiler/win-x64/System.Net.HttpListener.dll +0 -0
- package/compiler/win-x64/System.Net.Mail.dll +0 -0
- package/compiler/win-x64/System.Net.NameResolution.dll +0 -0
- package/compiler/win-x64/System.Net.NetworkInformation.dll +0 -0
- package/compiler/win-x64/System.Net.Ping.dll +0 -0
- package/compiler/win-x64/System.Net.Primitives.dll +0 -0
- package/compiler/win-x64/System.Net.Quic.dll +0 -0
- package/compiler/win-x64/System.Net.Requests.dll +0 -0
- package/compiler/win-x64/System.Net.Security.dll +0 -0
- package/compiler/win-x64/System.Net.ServicePoint.dll +0 -0
- package/compiler/win-x64/System.Net.Sockets.dll +0 -0
- package/compiler/win-x64/System.Net.WebClient.dll +0 -0
- package/compiler/win-x64/System.Net.WebHeaderCollection.dll +0 -0
- package/compiler/win-x64/System.Net.WebProxy.dll +0 -0
- package/compiler/win-x64/System.Net.WebSockets.Client.dll +0 -0
- package/compiler/win-x64/System.Net.WebSockets.dll +0 -0
- package/compiler/win-x64/System.Net.dll +0 -0
- package/compiler/win-x64/System.Numerics.Vectors.dll +0 -0
- package/compiler/win-x64/System.Numerics.dll +0 -0
- package/compiler/win-x64/System.ObjectModel.dll +0 -0
- package/compiler/win-x64/System.Private.CoreLib.dll +0 -0
- package/compiler/win-x64/System.Private.DataContractSerialization.dll +0 -0
- package/compiler/win-x64/System.Private.Uri.dll +0 -0
- package/compiler/win-x64/System.Private.Xml.Linq.dll +0 -0
- package/compiler/win-x64/System.Private.Xml.dll +0 -0
- package/compiler/win-x64/System.Reflection.DispatchProxy.dll +0 -0
- package/compiler/win-x64/System.Reflection.Emit.ILGeneration.dll +0 -0
- package/compiler/win-x64/System.Reflection.Emit.Lightweight.dll +0 -0
- package/compiler/win-x64/System.Reflection.Emit.dll +0 -0
- package/compiler/win-x64/System.Reflection.Extensions.dll +0 -0
- package/compiler/win-x64/System.Reflection.Metadata.dll +0 -0
- package/compiler/win-x64/System.Reflection.Primitives.dll +0 -0
- package/compiler/win-x64/System.Reflection.TypeExtensions.dll +0 -0
- package/compiler/win-x64/System.Reflection.dll +0 -0
- package/compiler/win-x64/System.Resources.Reader.dll +0 -0
- package/compiler/win-x64/System.Resources.ResourceManager.dll +0 -0
- package/compiler/win-x64/System.Resources.Writer.dll +0 -0
- package/compiler/win-x64/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/compiler/win-x64/System.Runtime.CompilerServices.VisualC.dll +0 -0
- package/compiler/win-x64/System.Runtime.Extensions.dll +0 -0
- package/compiler/win-x64/System.Runtime.Handles.dll +0 -0
- package/compiler/win-x64/System.Runtime.InteropServices.JavaScript.dll +0 -0
- package/compiler/win-x64/System.Runtime.InteropServices.RuntimeInformation.dll +0 -0
- package/compiler/win-x64/System.Runtime.InteropServices.dll +0 -0
- package/compiler/win-x64/System.Runtime.Intrinsics.dll +0 -0
- package/compiler/win-x64/System.Runtime.Loader.dll +0 -0
- package/compiler/win-x64/System.Runtime.Numerics.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Formatters.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Json.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Primitives.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.Xml.dll +0 -0
- package/compiler/win-x64/System.Runtime.Serialization.dll +0 -0
- package/compiler/win-x64/System.Runtime.dll +0 -0
- package/compiler/win-x64/System.Security.AccessControl.dll +0 -0
- package/compiler/win-x64/System.Security.Claims.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Algorithms.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Cng.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Csp.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Encoding.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.OpenSsl.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.Primitives.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.X509Certificates.dll +0 -0
- package/compiler/win-x64/System.Security.Cryptography.dll +0 -0
- package/compiler/win-x64/System.Security.Principal.Windows.dll +0 -0
- package/compiler/win-x64/System.Security.Principal.dll +0 -0
- package/compiler/win-x64/System.Security.SecureString.dll +0 -0
- package/compiler/win-x64/System.Security.dll +0 -0
- package/compiler/win-x64/System.ServiceModel.Web.dll +0 -0
- package/compiler/win-x64/System.ServiceProcess.dll +0 -0
- package/compiler/win-x64/System.Text.Encoding.CodePages.dll +0 -0
- package/compiler/win-x64/System.Text.Encoding.Extensions.dll +0 -0
- package/compiler/win-x64/System.Text.Encoding.dll +0 -0
- package/compiler/win-x64/System.Text.Encodings.Web.dll +0 -0
- package/compiler/win-x64/System.Text.Json.dll +0 -0
- package/compiler/win-x64/System.Text.RegularExpressions.dll +0 -0
- package/compiler/win-x64/System.Threading.Channels.dll +0 -0
- package/compiler/win-x64/System.Threading.Overlapped.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.Dataflow.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.Extensions.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.Parallel.dll +0 -0
- package/compiler/win-x64/System.Threading.Tasks.dll +0 -0
- package/compiler/win-x64/System.Threading.Thread.dll +0 -0
- package/compiler/win-x64/System.Threading.ThreadPool.dll +0 -0
- package/compiler/win-x64/System.Threading.Timer.dll +0 -0
- package/compiler/win-x64/System.Threading.dll +0 -0
- package/compiler/win-x64/System.Transactions.Local.dll +0 -0
- package/compiler/win-x64/System.Transactions.dll +0 -0
- package/compiler/win-x64/System.ValueTuple.dll +0 -0
- package/compiler/win-x64/System.Web.HttpUtility.dll +0 -0
- package/compiler/win-x64/System.Web.dll +0 -0
- package/compiler/win-x64/System.Windows.dll +0 -0
- package/compiler/win-x64/System.Xml.Linq.dll +0 -0
- package/compiler/win-x64/System.Xml.ReaderWriter.dll +0 -0
- package/compiler/win-x64/System.Xml.Serialization.dll +0 -0
- package/compiler/win-x64/System.Xml.XDocument.dll +0 -0
- package/compiler/win-x64/System.Xml.XPath.XDocument.dll +0 -0
- package/compiler/win-x64/System.Xml.XPath.dll +0 -0
- package/compiler/win-x64/System.Xml.XmlDocument.dll +0 -0
- package/compiler/win-x64/System.Xml.XmlSerializer.dll +0 -0
- package/compiler/win-x64/System.Xml.dll +0 -0
- package/compiler/win-x64/System.dll +0 -0
- package/compiler/win-x64/WindowsBase.dll +0 -0
- package/compiler/win-x64/clretwrc.dll +0 -0
- package/compiler/win-x64/clrgc.dll +0 -0
- package/compiler/win-x64/clrgcexp.dll +0 -0
- package/compiler/win-x64/clrjit.dll +0 -0
- package/compiler/win-x64/coreclr.dll +0 -0
- package/compiler/win-x64/createdump.exe +0 -0
- package/compiler/win-x64/cs/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/cs/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/de/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/de/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/es/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/es/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/fr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/fr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/hostfxr.dll +0 -0
- package/compiler/win-x64/hostpolicy.dll +0 -0
- package/compiler/win-x64/it/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/it/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/ja/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/ja/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/ko/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/ko/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/mscordaccore.dll +0 -0
- package/compiler/win-x64/mscordaccore_amd64_amd64_9.0.2026.41315.dll +0 -0
- package/compiler/win-x64/mscordbi.dll +0 -0
- package/compiler/win-x64/mscorlib.dll +0 -0
- package/compiler/win-x64/mscorrc.dll +0 -0
- package/compiler/win-x64/msquic.dll +0 -0
- package/compiler/win-x64/netstandard.dll +0 -0
- package/compiler/win-x64/pl/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/pl/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/pt-BR/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/ru/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/ru/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/tr/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/tr/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/zh-Hans/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/compiler/win-x64/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll +0 -0
- package/compiler/win-x64/zh-Hant/Microsoft.CodeAnalysis.resources.dll +0 -0
- package/dist/compiler-runner.d.ts +2 -0
- package/dist/compiler-runner.js +95 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/preprocessor.d.ts +3 -0
- package/dist/preprocessor.js +45 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/dist/vite-plugin.d.ts +3 -0
- package/dist/vite-plugin.js +26 -0
- package/dist/watcher.d.ts +3 -0
- package/dist/watcher.js +12 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,312 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SvelteSharp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Write C#. Build with Svelte.**
|
|
4
|
+
|
|
5
|
+
SvelteSharp is an experimental C# component authoring toolkit for **Svelte 5 and SvelteKit**.
|
|
6
|
+
|
|
7
|
+
It allows developers to write component logic using familiar C# syntax while using Svelte for rendering, reactivity, and DOM updates.
|
|
8
|
+
|
|
9
|
+
The goal is to bring a C# and Blazor-inspired development experience to the Svelte ecosystem without requiring developers to manually write component logic in JavaScript or TypeScript.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Write component logic in C#.
|
|
14
|
+
- Use separate `.svelte.cs` files or inline `@code` blocks.
|
|
15
|
+
- Keep markup in native `.svelte` files.
|
|
16
|
+
- Automatic reactive state generation using Svelte 5 `$state`.
|
|
17
|
+
- Computed properties using `$derived`.
|
|
18
|
+
- C# methods translated into JavaScript functions.
|
|
19
|
+
- Native Svelte two-way binding.
|
|
20
|
+
- Component parameters.
|
|
21
|
+
- Independent state for multiple component instances.
|
|
22
|
+
- C# syntax and semantic validation.
|
|
23
|
+
- Compile-time diagnostics for supported C# code.
|
|
24
|
+
- Compilation caching.
|
|
25
|
+
- Vite development integration.
|
|
26
|
+
- Local C# compiler execution.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Node.js
|
|
31
|
+
- npm
|
|
32
|
+
- Svelte 5
|
|
33
|
+
- SvelteKit
|
|
34
|
+
- Vite 6 or newer
|
|
35
|
+
- Windows x64 (current compiler distribution)
|
|
36
|
+
|
|
37
|
+
**Note:** The current compiler is distributed as a self-contained executable with its required .NET runtime files. Users do not need to install .NET separately.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
Install SvelteSharp in your SvelteKit project:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install svelte-sharp
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
Add SvelteSharp to your `vite.config.ts`:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import adapter from '@sveltejs/adapter-auto';
|
|
53
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
54
|
+
import { defineConfig } from 'vite';
|
|
55
|
+
|
|
56
|
+
import {
|
|
57
|
+
svelteSharp,
|
|
58
|
+
svelteSharpPreprocessor
|
|
59
|
+
} from 'svelte-sharp';
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
plugins: [
|
|
63
|
+
svelteSharp(),
|
|
64
|
+
|
|
65
|
+
sveltekit({
|
|
66
|
+
adapter: adapter(),
|
|
67
|
+
preprocess: [
|
|
68
|
+
svelteSharpPreprocessor()
|
|
69
|
+
]
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Your First C# Component
|
|
76
|
+
|
|
77
|
+
SvelteSharp supports two ways to write C# component logic.
|
|
78
|
+
|
|
79
|
+
### Option 1: Separate C# File
|
|
80
|
+
|
|
81
|
+
Create two files next to each other.
|
|
82
|
+
|
|
83
|
+
**1. Counter.svelte.cs**
|
|
84
|
+
|
|
85
|
+
Write your component logic in C#:
|
|
86
|
+
|
|
87
|
+
```csharp
|
|
88
|
+
public partial class Counter
|
|
89
|
+
{
|
|
90
|
+
private int count = 0;
|
|
91
|
+
|
|
92
|
+
private string Message =>
|
|
93
|
+
$"You clicked {count} times";
|
|
94
|
+
|
|
95
|
+
private void Increment()
|
|
96
|
+
{
|
|
97
|
+
count++;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private void Decrement()
|
|
101
|
+
{
|
|
102
|
+
count--;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**2. Counter.svelte**
|
|
108
|
+
|
|
109
|
+
Write your markup using native Svelte syntax:
|
|
110
|
+
|
|
111
|
+
```svelte
|
|
112
|
+
<div class="counter">
|
|
113
|
+
<h2>My C# Counter</h2>
|
|
114
|
+
|
|
115
|
+
<h3>Count: {count}</h3>
|
|
116
|
+
|
|
117
|
+
<p>{Message}</p>
|
|
118
|
+
|
|
119
|
+
<button onclick={Increment}>+</button>
|
|
120
|
+
<button onclick={Decrement}>-</button>
|
|
121
|
+
</div>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Option 2: Inline C# Code
|
|
125
|
+
|
|
126
|
+
You can also write C# directly inside your `.svelte` component using `@code`.
|
|
127
|
+
|
|
128
|
+
**Counter.svelte**
|
|
129
|
+
|
|
130
|
+
```svelte
|
|
131
|
+
<div class="counter">
|
|
132
|
+
<h2>My C# Counter</h2>
|
|
133
|
+
|
|
134
|
+
<h3>Count: {count}</h3>
|
|
135
|
+
|
|
136
|
+
<p>{Message}</p>
|
|
137
|
+
|
|
138
|
+
<button onclick={Increment}>+</button>
|
|
139
|
+
<button onclick={Decrement}>-</button>
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
@code {
|
|
143
|
+
private int count = 0;
|
|
144
|
+
|
|
145
|
+
private string Message =>
|
|
146
|
+
$"You clicked {count} times";
|
|
147
|
+
|
|
148
|
+
private void Increment()
|
|
149
|
+
{
|
|
150
|
+
count++;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private void Decrement()
|
|
154
|
+
{
|
|
155
|
+
count--;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Both approaches are supported. Choose whichever fits your project.
|
|
161
|
+
|
|
162
|
+
## Use Your Component
|
|
163
|
+
|
|
164
|
+
Import your component into a SvelteKit page:
|
|
165
|
+
|
|
166
|
+
```svelte
|
|
167
|
+
<script lang="ts">
|
|
168
|
+
import Counter from '$lib/Counter.svelte';
|
|
169
|
+
</script>
|
|
170
|
+
|
|
171
|
+
<h1>Welcome to SvelteSharp</h1>
|
|
172
|
+
|
|
173
|
+
<Counter />
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Run the Application
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
npm run dev
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
SvelteSharp translates your C# component logic into Svelte-compatible JavaScript during compilation. Svelte then handles rendering and reactive updates.
|
|
183
|
+
|
|
184
|
+
## Two-Way Binding
|
|
185
|
+
|
|
186
|
+
SvelteSharp works with Svelte's native binding system.
|
|
187
|
+
|
|
188
|
+
**Counter.svelte.cs**
|
|
189
|
+
|
|
190
|
+
```csharp
|
|
191
|
+
public partial class Counter
|
|
192
|
+
{
|
|
193
|
+
private string Name = "Ahsan";
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Counter.svelte**
|
|
198
|
+
|
|
199
|
+
```svelte
|
|
200
|
+
<input bind:value={Name} />
|
|
201
|
+
|
|
202
|
+
<p>Hello {Name}</p>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
You don't need to write a separate input event handler. Svelte handles the binding and reactive updates.
|
|
206
|
+
|
|
207
|
+
## Compile-Time Validation
|
|
208
|
+
|
|
209
|
+
SvelteSharp validates supported C# code before translating it.
|
|
210
|
+
|
|
211
|
+
For example, this component contains an undefined variable:
|
|
212
|
+
|
|
213
|
+
```csharp
|
|
214
|
+
@code {
|
|
215
|
+
private int count = ss0;
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Instead of allowing the generated JavaScript to fail later in the browser, SvelteSharp reports a compiler diagnostic:
|
|
220
|
+
|
|
221
|
+
```text
|
|
222
|
+
Counter.svelte(2,25):
|
|
223
|
+
SSW004: The name 'ss0' does not exist in the current context
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Compilation stops when an error is detected.
|
|
227
|
+
|
|
228
|
+
SvelteSharp also provides a diagnostics mode for inspecting compiler diagnostics:
|
|
229
|
+
|
|
230
|
+
```powershell
|
|
231
|
+
SvelteSharp.Compiler.exe --diagnostics Counter.svelte
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Semantic validation currently focuses on supported C# component members and expressions. It does not yet provide complete C# language validation or validate every Svelte markup reference.
|
|
235
|
+
|
|
236
|
+
## How It Works
|
|
237
|
+
|
|
238
|
+
```text
|
|
239
|
+
.svelte file + optional .svelte.cs file
|
|
240
|
+
|
|
|
241
|
+
v
|
|
242
|
+
SvelteSharp Preprocessor
|
|
243
|
+
|
|
|
244
|
+
v
|
|
245
|
+
C# Source Processing
|
|
246
|
+
|
|
|
247
|
+
v
|
|
248
|
+
Syntax Validation
|
|
249
|
+
|
|
|
250
|
+
v
|
|
251
|
+
Semantic Validation
|
|
252
|
+
|
|
|
253
|
+
v
|
|
254
|
+
C# Code Translation
|
|
255
|
+
|
|
|
256
|
+
v
|
|
257
|
+
Generated Svelte-Compatible Code
|
|
258
|
+
|
|
|
259
|
+
v
|
|
260
|
+
Svelte 5 Compiler
|
|
261
|
+
|
|
|
262
|
+
v
|
|
263
|
+
Browser
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
SvelteSharp handles C# source processing, validation, and translation.
|
|
267
|
+
|
|
268
|
+
Svelte remains responsible for rendering, reactivity, and DOM updates.
|
|
269
|
+
|
|
270
|
+
## Current Limitations
|
|
271
|
+
|
|
272
|
+
SvelteSharp is an experimental project. It does not support the complete C# language or the entire .NET platform.
|
|
273
|
+
|
|
274
|
+
Current limitations include:
|
|
275
|
+
|
|
276
|
+
- Limited C# language support.
|
|
277
|
+
- Windows x64 compiler distribution only.
|
|
278
|
+
- Not a replacement for the .NET runtime.
|
|
279
|
+
- Not a drop-in replacement for Blazor.
|
|
280
|
+
- Some advanced C# and Blazor features are not implemented.
|
|
281
|
+
- Semantic validation is limited to supported C# constructs.
|
|
282
|
+
- Complete validation of C# members referenced from Svelte markup is not yet implemented.
|
|
283
|
+
|
|
284
|
+
## Roadmap
|
|
285
|
+
|
|
286
|
+
- [x] Separate `.svelte.cs` component files.
|
|
287
|
+
- [x] Inline `@code` blocks.
|
|
288
|
+
- [x] Automatic reactive state generation.
|
|
289
|
+
- [x] Computed properties.
|
|
290
|
+
- [x] C# methods.
|
|
291
|
+
- [x] Basic syntax validation.
|
|
292
|
+
- [x] Semantic validation for supported C# constructs.
|
|
293
|
+
- [x] Compilation caching.
|
|
294
|
+
- [ ] Complete markup-to-C# member validation.
|
|
295
|
+
- [ ] Simplified project initialization.
|
|
296
|
+
- [ ] More C# language features.
|
|
297
|
+
- [ ] Component lifecycle integration.
|
|
298
|
+
- [ ] Dependency injection.
|
|
299
|
+
- [ ] Component communication.
|
|
300
|
+
- [ ] Improved Blazor and Razor compatibility.
|
|
301
|
+
- [ ] Blazor migration tooling.
|
|
302
|
+
- [ ] Linux and macOS support.
|
|
303
|
+
|
|
304
|
+
## Source Code
|
|
305
|
+
|
|
306
|
+
GitHub: https://github.com/theahsanbuilds/svelte-sharp
|
|
307
|
+
|
|
308
|
+
Bug reports, suggestions, and contributions are welcome.
|
|
309
|
+
|
|
310
|
+
## License
|
|
311
|
+
|
|
312
|
+
MIT License (subject to the license included with the package).
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|