• Stars
    star
    132
  • Rank 273,008 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created about 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This project is a Blazor Interop C# Generator, has a sample against the BabylonJS library.

Build Status codecov EventHorizon.Blazor.TypeScript.Interop.Generator

GitHub GitHub tag (latest SemVer pre-release)

EventHorizon.Blazor.TypeScript.Interop.Generator EventHorizon.Blazor.TypeScript.Interop.Generator.Model EventHorizon.Blazor.TypeScript.Interop.Generator.Writers.Project

EventHorizon.Blazor.TypeScript.Interop.Tool

About EventHorizon Blazor TypeScript Interop Generator

This project generates a C# Blazor Interop proxy using a TypeScript definition file.

Details

The generated project can be used with Blazor Wasm/Server to interface with JavaScript from C#, this gives most JavaScript libraries an easy to use interface from C#. It uses the JSRuntime to interop directly with the underlying JavaScript from C#, this is done with a custom interop abstraction.

The Wasm interop project can be found in the canhorn/EventHorizon.Blazor.Interop repository, it gives the generated code access to a common set of access patterns it then uses to interface with the JavaScript. The canhorn/EventHorizon.Blazor.Server.Interop repository contains the Blazor Server, async first, JavaScript access patterns.

Tech Used

TypeScript Parser

The generation relies heavily on the TypeScript Abstract Syntax Tree and so the code includes ways to parse the source files into a AST representation for easier generation.

The code has two supported parser types, .NET and NodeJS, to do realtime parsing of code. Using a .NET library it's able to do very quick parsing, but since it has not been maintained it can not handle complex or modern TypeScript syntax. But with the NodeJS TypeScript parser it can handle modern more complex TypeScript syntax, but with the trade off of in speed.

Having NodeJS installed is required to use the NodeJS TypeScript parser. (This is required when using the parser with the Tool)

Supported API's Generated

Below is a list of API that will be generated.

API Details Example Support
Constructor You can use the default constructor of Classes, causes new call in JavaScript. new BabylonJS.Engine() ✔️
Constructor with arguments Same as Constructor, but can also pass in arguments. new BabylonJS.Engine("canvas-window-id") ✔️
Property You can get or set properties supplied by the object. var isDisabled = engine.disableManifestCheck and engine.disableManifestCheck = true ✔️
Property You can set properties supplied by created objects. engine.disableManifestCheck = true ✔️
Static Property You can get Static properties of a Class. var isDisabled = Engine.ALPHA_DISABLE ✔️
Method You can call a method supplied by an object. var ratio = engine.getScreenAspectRatio() ✔️
Async Methods You can call a Task method and await the result. var ratio = await SceneLoader.LoadSceneAsync(...) ✔️
Static Method You can call a Static method provided by a Class. engine.DefaultLoadingScreenFactory(canvas) ✔️
Callback Method You can supply a callback action to a method supplied by an object. observer.add(() => doSomething()) ✔️
Static Callback Method You can call a Static method provided by a Class. Engine.AudioEngineFactory() ✔️
Get Instance Accessor You can have access to the get accessor on an object. var check = engine.disableManifestCheck ✔️
Set Instance Accessor You can use the set accessor on an objects. engine.onCanvasPointerOutObservable.add(() => doSomething()) ✔️
Action Callback You can run Async based code. meshLoader.OnSuccess(new ActionCallback<Mesh>(mesh => { return Task.CompletedTask; })) ✔️
Action Callback in Literal You can run Async based code. new HeightMapMesh({ onReady = new ActionCallback<Mesh>(mesh => { return Task.CompletedTask; }) }) ✔️
Action Result Callback You can run an action with a result to the caller. meshLoader.OnSuccess(new ActionResultCallback<Mesh, bool>(mesh => { return mesh != null; })) ✔️

Notes on the framework, it might not have the exact API supplied by a TypeScript definition file, in that it might transform the API into something more general and friendly to C#. I used C# as my main source of inspiration for the generated code.

Example

Checkout /Sample for a BabylonJS working example solution. The solution includes a BabylonJS generated proxy, with a working Blazor Wasm site. You can also checkout the website on this repository for deployed website using the generated BabylonJS. The Sample also includes a Blazor Server project, showing the same example as the Wasm but using Async/Await patterns.

More Repositories

1

Blazor.Contentful.Blog.Starter

A ASP.NET Core Blazor and Contentful blog site starter to get you up and running quickly with your new blog site.
C#
18
star
2

BabylonJS.Blazor.Game.Tutorial

A Blazor Game Created from the Guided Learning of BabylonJS.
C#
13
star
3

EventHorizon.Blazor.Interop.Generator

C#
8
star
4

EventHorizon.Blazor.Interop

This project contains utilities that make Blazor WASM C# interfacing with JavaScript easier, will trigger corresponding JavaScript functionality. Includes Scenario Testing Blazor WASM website in the Sample project.
HTML
7
star
5

EventHorizon.Blazor.UX

A Dark Themed UX Library for Blazor. | NuGet: https://www.nuget.org/packages/EventHorizon.Blazor.UX/
C#
5
star
6

EventHorizon.Shimeji

JavaScript
4
star
7

EventHorizon.Blazor.Server.Interop

HTML
3
star
8

EventHorizon.Blazor.WebApi.IntersectionObserver

This repository is an example project showing off the generation of WebApi's using a C# Blazor Interop Generator.
C#
3
star
9

EventHorizon.Blazor.UserManagement

An Real-Time User Management UX showing off how SiganlR can be used in a Blazor Wasm application.
C#
3
star
10

EventHorizon.Blazor.Dynamic.Scripting

C#
2
star
11

EventHorizon.Blazor.Chat

C#
2
star
12

EventHorizon.Identity.Demo

TypeScript
2
star
13

AutoAnimate.Blazor.Wasm

Just an example of using AutoAnimate in the context of a ASP.NET Core Blazor Wasm application.
C#
2
star
14

Blazor.Mockup.GettingStarted

A Getting Started Repository showing off the EventHorizon.Blazor.Mockup library.
C#
1
star
15

og-image

TypeScript
1
star
16

EventHorizon.Blazor.DocumentMetadata

This package helps to address the issue of setting the Metadata tags of the head, on initial page request and on page navigation.
C#
1
star
17

EventHorizon.DeployDockerBuildVersion

C#
1
star
18

EventHorizon.CreateScriptDll

Sample project showing how to create, load, and call a dynamically created DLL.
C#
1
star
19

EventHorizon.Blazor.BabylonJS-poc

C#
1
star
20

EventHorizon.Blazor.Query.Caching

C#
1
star
21

EventHorizon.Blazor.Scripter

Need a way to call dynamic JavaScript from a Blazor Application? Look no further!
C#
1
star
22

EventHorizon.Platform.Docs

A simple project that frameworks out the creation of new pages in a Blazor site.
HTML
1
star
23

EventHorizon.Blazor.ManualRender

A example project of how to create C# based components, without a razor file.
C#
1
star
24

EventHorizon.Basic.Bot

This project is a bear minimum library for creating Bots.
C#
1
star
25

EventHorizon.Blazor.Mascot

All you need to display a little mascot on your website built with Blazor.
C#
1
star
26

EventHorizon.Blazor.Pattern.Observer

Project showing the Observer pattern in the context of a Blazor application.
C#
1
star