// bridge.d.ts
export interface CanvasContext {
drawRect(x: number, y: number, width: number, height: number) => void;
}
// App.swift
public struct App {
let context: CanvasContext
@ExposeToJS
init(context: CanvasContext) {
self.context = context
}
struct PointerEvent {
let x: Int
let y: Int
let pointerId: Int
}
@ExposeToJS
func feedPointerEvents(_ events: [PointerEvent]) {
...
context.drawRect(...)
}
}
Motivation
Current JS interop system, JavaScriptKit, has two main issues:
Current Status
Try on our playground https://swiftwasm.org/JavaScriptKit/PlayBridgeJS/
High-level API
Given the following interface:
Then SwiftPM Build Plugin or standalone CLI tool should generate:
CanvasContextto SwiftAppmethods to JS/TSBreakdown
Other Languages