dom

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

Go DOM binding (and more) for WebAssembly

This library provides a Go API for different Web APIs for WebAssembly target.

It's in an active development, but an API will be carefully versioned to avoid breaking users. Use Go dependency management tools to lock a specific version.

More information about Go's WebAssembly support can be found on Go's WebAssembly wiki page.

Features:

  • Better JS API (wrappers for syscall/js)
  • Basic DOM manipulation, styles, events
  • Input elements
  • SVG elements and transforms
  • LocalStorage and SessionStorage
  • Extension APIs (tested on Chrome):
    • Native Messaging
    • Bookmarks
    • Tabs
  • net-like library for WebSockets
    • Tested with gRPC
  • wasm-server for fast prototyping

Quickstart

Pull the library and install wasm-server (optional):

go get -u github.com/dennwc/dom
go install github.com/dennwc/dom/cmd/wasm-server

Run an example app:

cd $GOPATH/src/github.com/dennwc/dom
wasm-server

Check result: http://localhost:8080/

The source code is recompiled on each page refresh, so feel free to experiment!

Similar Projects

Editor Configuration

If you are using Visual Studio Code, you can use workspace settings to configure the environment variables for the go tools.

Your settings.json file should look something like this:

{
    "go.toolsEnvVars": { "GOARCH": "wasm", "GOOS": "js" }
}

Documentation

Index

Constants

View Source
const (
	MouseLeft = MouseButton(0)
)

Variables

View Source
var (
	Doc  = GetDocument()
	Body = Doc.GetElementsByTagName("body")[0]
	Head = Doc.GetElementsByTagName("head")[0]
)

Functions

func ConsoleLog

func ConsoleLog(args ...interface{})

func Loop

func Loop()

func MustRequire added in v0.2.1

func MustRequire(path string)

MustRequire is the same as Require, but panics on an error.

func RegisterEventType

func RegisterEventType(typ string, fnc EventConstructor)

func Require added in v0.2.1

func Require(path string) error

Require loads a specified file (js or css) into the document and waits for it to apply.

Types

type Auto

type Auto struct{}

func (Auto) String

func (Auto) String() string

type BaseEvent

type BaseEvent struct {
	// contains filtered or unexported fields
}

func (*BaseEvent) Bubbles

func (e *BaseEvent) Bubbles() bool

func (*BaseEvent) Cancelable

func (e *BaseEvent) Cancelable() bool

func (*BaseEvent) Composed

func (e *BaseEvent) Composed() bool

func (*BaseEvent) CurrentTarget

func (e *BaseEvent) CurrentTarget() *Element

func (*BaseEvent) DefaultPrevented

func (e *BaseEvent) DefaultPrevented() bool

func (*BaseEvent) IsTrusted

func (e *BaseEvent) IsTrusted() bool

func (*BaseEvent) JSRef

func (e *BaseEvent) JSRef() js.Ref

func (*BaseEvent) Path

func (e *BaseEvent) Path() NodeList

func (*BaseEvent) PreventDefault added in v0.2.1

func (e *BaseEvent) PreventDefault()

func (*BaseEvent) StopImmediatePropagation added in v0.2.1

func (e *BaseEvent) StopImmediatePropagation()

func (*BaseEvent) StopPropagation added in v0.2.1

func (e *BaseEvent) StopPropagation()

func (*BaseEvent) Target

func (e *BaseEvent) Target() *Element

func (*BaseEvent) Type

func (e *BaseEvent) Type() string

type Button

type Button struct {
	Element
}

func NewButton added in v0.2.1

func NewButton(s string) *Button

func (*Button) OnClick

func (b *Button) OnClick(h EventHandler)

type Color

type Color string

type Document

type Document struct {
	NodeBase
}

func GetDocument

func GetDocument() *Document

func (*Document) CreateElement

func (d *Document) CreateElement(tag string) *Element

func (*Document) CreateElementNS

func (d *Document) CreateElementNS(ns string, tag string) *Element

func (*Document) GetElementById

func (d *Document) GetElementById(id string) *Element

func (*Document) GetElementsByTagName

func (d *Document) GetElementsByTagName(tag string) NodeList

func (*Document) NewButton

func (d *Document) NewButton(s string) *Button

func (*Document) NewInput

func (d *Document) NewInput(typ string) *Input

func (*Document) QuerySelector

func (d *Document) QuerySelector(qu string) *Element

func (*Document) QuerySelectorAll

func (d *Document) QuerySelectorAll(qu string) NodeList

type Element

type Element struct {
	NodeBase
}

func AsElement

func AsElement(v js.Value) *Element

func NewElement added in v0.2.1

func NewElement(tag string) *Element

func (*Element) GetAttribute

func (e *Element) GetAttribute(k string) js.Value

func (*Element) GetBoundingClientRect

func (e *Element) GetBoundingClientRect() Rect

func (*Element) OnClick

func (e *Element) OnClick(h MouseEventHandler)

func (*Element) OnMouseDown

func (e *Element) OnMouseDown(h MouseEventHandler)

func (*Element) OnMouseMove

func (e *Element) OnMouseMove(h MouseEventHandler)

func (*Element) OnMouseUp

func (e *Element) OnMouseUp(h MouseEventHandler)

func (*Element) SetAttribute

func (e *Element) SetAttribute(k string, v interface{})

func (*Element) SetInnerHTML

func (e *Element) SetInnerHTML(s string)

func (*Element) Style

func (e *Element) Style() *Style

type Em

type Em float64

func (Em) String

func (v Em) String() string

type Event

type Event interface {
	Value
	Bubbles() bool
	Cancelable() bool
	Composed() bool
	CurrentTarget() *Element
	DefaultPrevented() bool
	Target() *Element
	Type() string
	IsTrusted() bool
	Path() NodeList

	PreventDefault()
	StopPropagation()
	StopImmediatePropagation()
}

type EventConstructor

type EventConstructor func(e BaseEvent) Event

type EventHandler

type EventHandler func(Event)

type EventTarget

type EventTarget interface {
	Value
	AddEventListener(typ string, h EventHandler)
}

type Input

type Input struct {
	Element
}

func NewInput added in v0.2.1

func NewInput(typ string) *Input

func (*Input) OnChange

func (inp *Input) OnChange(h EventHandler)

func (*Input) OnInput

func (inp *Input) OnInput(h EventHandler)

func (*Input) SetName

func (inp *Input) SetName(name string)

func (*Input) SetType

func (inp *Input) SetType(typ string)

func (*Input) SetValue

func (inp *Input) SetValue(val interface{})

func (*Input) Value

func (inp *Input) Value() string

type MouseButton

type MouseButton int

type MouseEvent

type MouseEvent struct {
	BaseEvent
}

func (*MouseEvent) AltKey

func (e *MouseEvent) AltKey() bool

func (*MouseEvent) Button

func (e *MouseEvent) Button() MouseButton

func (*MouseEvent) ClientPos

func (e *MouseEvent) ClientPos() Point

func (*MouseEvent) CtrlKey

func (e *MouseEvent) CtrlKey() bool

func (*MouseEvent) MetaKey

func (e *MouseEvent) MetaKey() bool

func (*MouseEvent) OffsetPos

func (e *MouseEvent) OffsetPos() Point

func (*MouseEvent) PagePos

func (e *MouseEvent) PagePos() Point

func (*MouseEvent) ScreenPos

func (e *MouseEvent) ScreenPos() Point

func (*MouseEvent) ShiftKey

func (e *MouseEvent) ShiftKey() bool

type MouseEventHandler

type MouseEventHandler func(*MouseEvent)

type Node

type Node interface {
	EventTarget

	BaseURI() string
	NodeName() string
	ChildNodes() NodeList
	ParentNode() Node
	ParentElement() *Element
	TextContent() string
	SetTextContent(s string)

	AppendChild(n Node)
	Contains(n Node) bool
	IsEqualNode(n Node) bool
	IsSameNode(n Node) bool
	RemoveChild(n Node) Node
	ReplaceChild(n, old Node) Node
}

type NodeBase

type NodeBase struct {
	// contains filtered or unexported fields
}

func (*NodeBase) AddEventListener

func (e *NodeBase) AddEventListener(typ string, h EventHandler)

func (*NodeBase) AddEventListenerFlags

func (e *NodeBase) AddEventListenerFlags(typ string, flags int, h EventHandler)

func (*NodeBase) AppendChild

func (e *NodeBase) AppendChild(n Node)

func (*NodeBase) BaseURI

func (e *NodeBase) BaseURI() string

func (*NodeBase) ChildNodes

func (e *NodeBase) ChildNodes() NodeList

func (*NodeBase) Contains

func (e *NodeBase) Contains(n Node) bool

func (*NodeBase) IsEqualNode

func (e *NodeBase) IsEqualNode(n Node) bool

func (*NodeBase) IsSameNode

func (e *NodeBase) IsSameNode(n Node) bool

func (*NodeBase) JSRef

func (e *NodeBase) JSRef() js.Ref

func (*NodeBase) NodeName

func (e *NodeBase) NodeName() string

func (*NodeBase) ParentElement

func (e *NodeBase) ParentElement() *Element

func (*NodeBase) ParentNode

func (e *NodeBase) ParentNode() Node

func (*NodeBase) Remove

func (e *NodeBase) Remove()

func (*NodeBase) RemoveChild

func (e *NodeBase) RemoveChild(n Node) Node

func (*NodeBase) ReplaceChild

func (e *NodeBase) ReplaceChild(n, old Node) Node

func (*NodeBase) SetTextContent

func (e *NodeBase) SetTextContent(s string)

func (*NodeBase) TextContent

func (e *NodeBase) TextContent() string

type NodeList

type NodeList []*Element

func AsNodeList

func AsNodeList(v js.Value) NodeList

type Perc

type Perc int

func (Perc) String

func (v Perc) String() string

type Point

type Point = image.Point

type Px

type Px int

func (Px) String

func (v Px) String() string

type Rect

type Rect = image.Rectangle

type Rem

type Rem int

func (Rem) String

func (v Rem) String() string

type Style

type Style struct {
	// contains filtered or unexported fields
}

func (*Style) Set

func (s *Style) Set(k string, v interface{})

func (*Style) SetHeight

func (s *Style) SetHeight(v Unit)

func (*Style) SetMarginsRaw

func (s *Style) SetMarginsRaw(m string)

func (*Style) SetWidth

func (s *Style) SetWidth(v Unit)

type Unit

type Unit interface {
	String() string
}

type Value

type Value = js.JSRef

type Vh

type Vh int

func (Vh) String

func (v Vh) String() string

type Vmax

type Vmax int

func (Vmax) String

func (v Vmax) String() string

type Vmin

type Vmin int

func (Vmin) String

func (v Vmin) String() string

type Vw

type Vw int

func (Vw) String

func (v Vw) String() string

type Window

type Window struct {
	// contains filtered or unexported fields
}

func GetWindow

func GetWindow() *Window

func (*Window) AddEventListener

func (w *Window) AddEventListener(typ string, h EventHandler)

func (*Window) JSRef

func (w *Window) JSRef() js.Ref

func (*Window) OnResize

func (w *Window) OnResize(fnc func(e Event))

Directories

Path Synopsis
cmd
app
examples
grpc-over-ws/protocol
Package protocol is a generated protocol buffer package.
Package protocol is a generated protocol buffer package.
extension
chrome/native
Package native provides an API for Native Messaging for Chrome extensions.
Package native provides an API for Native Messaging for Chrome extensions.
net
ws
Package ws provides a functionality similar to Go net package on top of WebSockets.
Package ws provides a functionality similar to Go net package on top of WebSockets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL