All Projects → swiftwasm → Javascriptkit

swiftwasm / Javascriptkit

Licence: mit
Swift framework to interact with JavaScript through WebAssembly.

Programming Languages

javascript
184084 projects - #8 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to Javascriptkit

Ant Design Blazor
🌈A set of enterprise-class UI components based on Ant Design and Blazor WebAssembly.
Stars: ✭ 3,890 (+1017.82%)
Mutual labels:  webassembly
Awesome Wasi
😎 Curated list of awesome things regarding WebAssembly WASI ecosystem.
Stars: ✭ 319 (-8.33%)
Mutual labels:  webassembly
Cicadaplayer
CicadaPlayer is the player core of AliPlayer, which support multiple platform Android, iOS, macOS, Windows, Linux, and WebAssembly for now. The goal is providing a player core which support multi platform, hardware accelerator, customizable and extensible features. Which support WideVine drm and LHLS.
Stars: ✭ 334 (-4.02%)
Mutual labels:  webassembly
Pigo
Fast face detection, pupil/eyes localization and facial landmark points detection library in pure Go.
Stars: ✭ 3,542 (+917.82%)
Mutual labels:  webassembly
Jsc.js
JavaScriptCore on WebAssembly
Stars: ✭ 311 (-10.63%)
Mutual labels:  webassembly
Canvas
HTML5 Canvas API implementation for Microsoft Blazor
Stars: ✭ 319 (-8.33%)
Mutual labels:  webassembly
Essentia.js
JavaScript library for music/audio analysis and processing powered by Essentia WebAssembly
Stars: ✭ 294 (-15.52%)
Mutual labels:  webassembly
Unrust
unrust - A pure rust based (webgl 2.0 / native) game engine
Stars: ✭ 341 (-2.01%)
Mutual labels:  webassembly
Parity Wasm
WebAssembly serialization/deserialization in rust
Stars: ✭ 314 (-9.77%)
Mutual labels:  webassembly
Wasm3
🚀 The fastest WebAssembly interpreter, and the most universal runtime
Stars: ✭ 4,375 (+1157.18%)
Mutual labels:  webassembly
Jessibuca
Jessibuca是一款开源的纯H5直播流播放器
Stars: ✭ 301 (-13.51%)
Mutual labels:  webassembly
V8.js.cn
V8 官方网站中文翻译
Stars: ✭ 308 (-11.49%)
Mutual labels:  webassembly
Webml
A Standard ML Compiler for the Web
Stars: ✭ 326 (-6.32%)
Mutual labels:  webassembly
Stdweb
A standard library for the client-side Web
Stars: ✭ 3,201 (+819.83%)
Mutual labels:  webassembly
Magnum
Lightweight and modular C++11 graphics middleware for games and data visualization
Stars: ✭ 3,728 (+971.26%)
Mutual labels:  webassembly
Speedy.js
Accelerate JavaScript Applications by Compiling to WebAssembly
Stars: ✭ 300 (-13.79%)
Mutual labels:  webassembly
Perspective
A data visualization and analytics component, especially well-suited for large and/or streaming datasets.
Stars: ✭ 3,989 (+1046.26%)
Mutual labels:  webassembly
Blog Core
Modular blog using Blazor with clean domain-driven design patterns
Stars: ✭ 345 (-0.86%)
Mutual labels:  webassembly
Simd
Branch of the spec repo scoped to discussion of SIMD in WebAssembly
Stars: ✭ 330 (-5.17%)
Mutual labels:  webassembly
Wabt
The WebAssembly Binary Toolkit
Stars: ✭ 4,026 (+1056.9%)
Mutual labels:  webassembly

JavaScriptKit

Run unit tests

Swift framework to interact with JavaScript through WebAssembly.

Getting started

This JavaScript code

const alert = window.alert;
const document = window.document;

const divElement = document.createElement("div");
divElement.innerText = "Hello, world";
const body = document.body;
body.appendChild(divElement);

const pet = {
  age: 3,
  owner: {
    name: "Mike",
  },
};

alert("JavaScript is running on browser!");

Can be written in Swift using JavaScriptKit

import JavaScriptKit

let document = JSObject.global.document

var divElement = document.createElement("div")
divElement.innerText = "Hello, world"
_ = document.body.appendChild(divElement)

struct Owner: Codable {
  let name: String
}

struct Pet: Codable {
  let age: Int
  let owner: Owner
}

let jsPet = JSObject.global.pet
let swiftPet: Pet = try JSValueDecoder().decode(from: jsPet)

JSObject.global.alert!("Swift is running in the browser!")

Usage in a browser application

The easiest way to get started with JavaScriptKit in your browser app is with the carton bundler.

As a part of these steps you'll install carton via Homebrew on macOS (you can also use the ghcr.io/swiftwasm/carton Docker image if you prefer to run the build steps on Linux). Assuming you already have Homebrew installed, you can create a new app that uses JavaScriptKit by following these steps:

  1. Install carton:
brew install swiftwasm/tap/carton

If you had carton installed before this, make sure you have version 0.6.1 or greater:

carton --version
  1. Create a directory for your project and make it current:
mkdir SwiftWasmApp && cd SwiftWasmApp
  1. Initialize the project from a template with carton:
carton init --template basic
  1. Build the project and start the development server, carton dev can be kept running during development:
carton dev
  1. Open http://127.0.0.1:8080/ in your browser and a developer console within it. You'll see Hello, world! output in the console. You can edit the app source code in your favorite editor and save it, carton will immediately rebuild the app and reload all browser tabs that have the app open.

You can also build your project with webpack.js and a manually installed SwiftWasm toolchain. Please see the following sections and the Example directory for more information in this more advanced use case.

Manual toolchain installation

This library only supports swiftwasm/swift toolchain distribution. The toolchain can be installed via swiftenv, in the same way as the official Swift nightly toolchain.

You have to install the toolchain manually when working on the source code of JavaScriptKit itself, especially if you change anything in the JavaScript runtime parts. This is because the runtime parts are embedded in carton and currently can't be replaced dynamically with the JavaScript code you've updated locally.

Just pass a toolchain archive URL for the latest SwiftWasm 5.3 snapshot appropriate for your platform:

$ swiftenv install https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.3.0-RELEASE/swift-wasm-5.3.0-RELEASE-macos_x86_64.pkg

You can also use the install-toolchain.sh helper script that uses a hardcoded toolchain snapshot:

$ ./scripts/install-toolchain.sh
$ swift --version
Swift version 5.3 (swiftlang-5.3.0)
Target: x86_64-apple-darwin19.6.0
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].