Documentation
¶
Overview ¶
Package wasm embeds Kite and Kitex applications in an HTML canvas. Build the application with GOOS=js GOARCH=wasm and load it with the matching Go wasm_exec.js runtime after the canvas exists. Only New and Backend require the browser target; grid operations and input translation run natively.
For a page containing <canvas id="terminal"></canvas>:
package main
import (
"context"
"log"
"syscall/js"
"github.com/masterkeysrd/kite"
"github.com/masterkeysrd/kite/backend/wasm"
"github.com/masterkeysrd/kite/element"
)
func main() {
canvas := js.Global().Get("document").Call("getElementById", "terminal")
b, err := wasm.New(canvas, wasm.WithSize(60, 18))
if err != nil {
log.Fatal(err)
}
app := kite.New(b, kite.WithMouseMode(kite.MouseModeTrack))
app.Mount(element.Box("Hello, canvas!"))
if err := app.Run(context.Background()); err != nil {
log.Print(err)
}
}
Hosts can call Restore when unmounting to release listeners and close input.
Index ¶
- func TranslateKeyEvent(in DOMKeyInput) (*backend.RawKeyEvent, bool)
- func TranslateMouseEvent(in DOMMouseInput, m CellMetrics, mode backend.MouseSupport) (*backend.RawMouseEvent, bool)
- func TranslateWheelEvent(in DOMWheelInput, m CellMetrics, mode backend.MouseSupport) (*backend.RawMouseEvent, bool)
- type CellMetrics
- type DOMKeyInput
- type DOMMouseInput
- type DOMWheelInput
- type Option
- type Surface
- func (s *Surface) At(x, y int) backend.Cell
- func (s *Surface) CellAt(x, y int) backend.Cell
- func (s *Surface) Clear()
- func (s *Surface) Clip(rect geom.Rect) *Surface
- func (s *Surface) Diff(previous *Surface, damage []geom.Point, visit func(int, int, backend.Cell))
- func (s *Surface) Resize(size geom.Size)
- func (s *Surface) Set(x, y int, cell backend.Cell)
- func (s *Surface) SetCell(x, y int, cell backend.Cell)
- func (s *Surface) Size() geom.Size
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TranslateKeyEvent ¶
func TranslateKeyEvent(in DOMKeyInput) (*backend.RawKeyEvent, bool)
TranslateKeyEvent translates named keys and single printable characters.
func TranslateMouseEvent ¶
func TranslateMouseEvent(in DOMMouseInput, m CellMetrics, mode backend.MouseSupport) (*backend.RawMouseEvent, bool)
TranslateMouseEvent maps button transitions and filters motion by tracking mode.
func TranslateWheelEvent ¶
func TranslateWheelEvent(in DOMWheelInput, m CellMetrics, mode backend.MouseSupport) (*backend.RawMouseEvent, bool)
TranslateWheelEvent converts each moving axis into a signed wheel tick.
Types ¶
type CellMetrics ¶
CellMetrics describes the grid in canvas-local CSS pixels.
func (CellMetrics) PixelToCell ¶
func (m CellMetrics) PixelToCell(x, y float64) (col, row int, inside bool)
PixelToCell returns clamped coordinates and whether the point hits the grid.
type DOMKeyInput ¶
DOMKeyInput describes a browser keydown, including its physical code.
type DOMMouseInput ¶
DOMMouseInput describes a mouse event with local CSS coordinates and DOM button values.
type DOMWheelInput ¶
DOMWheelInput describes a wheel gesture over the canvas.
type Option ¶
type Option func(*config)
Option configures a canvas backend before its first frame.
func WithCursorColor ¶
WithCursorColor sets the default hardware cursor color.
func WithDefaultColors ¶
WithDefaultColors sets fallback cell colors. Nil leaves a color unchanged.
func WithLineHeight ¶
WithLineHeight sets the cell height as a multiple of the font size.
func WithPadding ¶
WithPadding sets the space around the grid in CSS pixels.
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface stores a terminal grid or an absolute-coordinate view of one.
func NewSurface ¶
NewSurface allocates a blank terminal grid.
func (*Surface) Clear ¶
func (s *Surface) Clear()
Clear resets only the cells visible through this surface.
func (*Surface) Diff ¶
Diff visits changed glyph origins in row order. A nil previous frame forces a full repaint. Damage points invalidate their entire containing glyph.