mirror of
https://github.com/taigrr/wasm-experiments
synced 2025-01-18 04:03:21 -08:00
Remove dom dependency
This commit is contained in:
parent
5a07f70561
commit
5bada70f17
16
Gopkg.lock
generated
16
Gopkg.lock
generated
@ -54,17 +54,6 @@
|
||||
pruneopts = "UT"
|
||||
revision = "cd9f1b82897a926ec9df9397711bb4c6732069f7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:4a2cfc3902d8d9b797c6c47d4d0d957f16fc65f0339fa79dcbe2bf5369e6ce81"
|
||||
name = "github.com/dennwc/dom"
|
||||
packages = [
|
||||
".",
|
||||
"js",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "42c0f3b773203d4ea24045cc84f6ed3a25da1af1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:a8fc2604eb5975548b14b5bc9db87f90bf2d2b2e08ecc6be9310ec1a1d640ae0"
|
||||
name = "github.com/golang/protobuf"
|
||||
@ -309,9 +298,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/dave/wasmgo",
|
||||
"github.com/dennwc/dom",
|
||||
]
|
||||
input-imports = ["github.com/dave/wasmgo"]
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
@ -5,7 +5,3 @@ required = [
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/dennwc/dom"
|
||||
|
3
vendor/github.com/dennwc/dom/.gitignore
generated
vendored
3
vendor/github.com/dennwc/dom/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
*.wasmcmd/app/app
|
||||
app.wasm
|
||||
/cmd/app/app
|
201
vendor/github.com/dennwc/dom/LICENSE
generated
vendored
201
vendor/github.com/dennwc/dom/LICENSE
generated
vendored
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
3
vendor/github.com/dennwc/dom/color.go
generated
vendored
3
vendor/github.com/dennwc/dom/color.go
generated
vendored
@ -1,3 +0,0 @@
|
||||
package dom
|
||||
|
||||
type Color string
|
42
vendor/github.com/dennwc/dom/document.go
generated
vendored
42
vendor/github.com/dennwc/dom/document.go
generated
vendored
@ -1,42 +0,0 @@
|
||||
package dom
|
||||
|
||||
import "github.com/dennwc/dom/js"
|
||||
|
||||
func GetDocument() *Document {
|
||||
doc := js.Get("document")
|
||||
if !doc.Valid() {
|
||||
return nil
|
||||
}
|
||||
return &Document{NodeBase{v: doc}}
|
||||
}
|
||||
|
||||
var _ Node = (*Document)(nil)
|
||||
|
||||
type Document struct {
|
||||
NodeBase
|
||||
}
|
||||
|
||||
func (d *Document) CreateElement(tag string) *Element {
|
||||
v := d.v.Call("createElement", tag)
|
||||
return AsElement(v)
|
||||
}
|
||||
func (d *Document) CreateElementNS(ns string, tag string) *Element {
|
||||
v := d.v.Call("createElementNS", ns, tag)
|
||||
return AsElement(v)
|
||||
}
|
||||
func (d *Document) GetElementById(id string) *Element {
|
||||
v := d.v.Call("getElementById", id)
|
||||
return AsElement(v)
|
||||
}
|
||||
func (d *Document) GetElementsByTagName(tag string) NodeList {
|
||||
v := d.v.Call("getElementsByTagName", tag)
|
||||
return AsNodeList(v)
|
||||
}
|
||||
func (d *Document) QuerySelector(qu string) *Element {
|
||||
v := d.v.Call("querySelector", qu)
|
||||
return AsElement(v)
|
||||
}
|
||||
func (d *Document) QuerySelectorAll(qu string) NodeList {
|
||||
v := d.v.Call("querySelectorAll", qu)
|
||||
return AsNodeList(v)
|
||||
}
|
78
vendor/github.com/dennwc/dom/element.go
generated
vendored
78
vendor/github.com/dennwc/dom/element.go
generated
vendored
@ -1,78 +0,0 @@
|
||||
package dom
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dennwc/dom/js"
|
||||
sjs "syscall/js"
|
||||
)
|
||||
|
||||
var _ Node = (*Element)(nil)
|
||||
|
||||
func AsElement(v js.Value) *Element {
|
||||
if !v.Valid() {
|
||||
return nil
|
||||
}
|
||||
return &Element{NodeBase{v: v}}
|
||||
}
|
||||
|
||||
func AsNodeList(v js.Value) NodeList {
|
||||
if !v.Valid() {
|
||||
return nil
|
||||
}
|
||||
arr := make(NodeList, v.Length())
|
||||
for i := range arr {
|
||||
arr[i] = AsElement(v.Index(i))
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
var _ Node = (*Element)(nil)
|
||||
|
||||
type Element struct {
|
||||
NodeBase
|
||||
}
|
||||
|
||||
func (e *Element) SetInnerHTML(s string) {
|
||||
e.v.Set("innerHTML", s)
|
||||
}
|
||||
|
||||
func (e *Element) SetAttribute(k string, v interface{}) {
|
||||
e.v.Call("setAttribute", k, fmt.Sprint(v))
|
||||
}
|
||||
|
||||
func (e *Element) GetAttribute(k string) js.Value {
|
||||
return e.v.Call("getAttribute", k)
|
||||
}
|
||||
|
||||
func (e *Element) Style() *Style {
|
||||
return &Style{v: e.v.Get("style")}
|
||||
}
|
||||
|
||||
func (e *Element) GetBoundingClientRect() Rect {
|
||||
rv := e.v.Call("getBoundingClientRect")
|
||||
x, y := rv.Get("x").Int(), rv.Get("y").Int()
|
||||
w, h := rv.Get("width").Int(), rv.Get("height").Int()
|
||||
return Rect{Min: Point{x, y}, Max: Point{x + w, y + h}}
|
||||
}
|
||||
|
||||
func (e *Element) onMouseEvent(typ string, flags int, h MouseEventHandler) {
|
||||
e.AddEventListenerFlags(typ, flags, func(e Event) {
|
||||
h(e.(*MouseEvent))
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Element) OnClick(h MouseEventHandler) {
|
||||
e.onMouseEvent("click", int(sjs.StopPropagation), h)
|
||||
}
|
||||
|
||||
func (e *Element) OnMouseDown(h MouseEventHandler) {
|
||||
e.onMouseEvent("mousedown", int(sjs.StopPropagation), h)
|
||||
}
|
||||
|
||||
func (e *Element) OnMouseMove(h MouseEventHandler) {
|
||||
e.onMouseEvent("mousemove", 0, h)
|
||||
}
|
||||
|
||||
func (e *Element) OnMouseUp(h MouseEventHandler) {
|
||||
e.onMouseEvent("mouseup", int(sjs.StopPropagation), h)
|
||||
}
|
171
vendor/github.com/dennwc/dom/event.go
generated
vendored
171
vendor/github.com/dennwc/dom/event.go
generated
vendored
@ -1,171 +0,0 @@
|
||||
package dom
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dennwc/dom/js"
|
||||
)
|
||||
|
||||
type EventTarget interface {
|
||||
Value
|
||||
AddEventListener(typ string, h EventHandler)
|
||||
// TODO: removeEventListener
|
||||
// TODO: dispatchEvent
|
||||
}
|
||||
|
||||
type Event interface {
|
||||
Value
|
||||
Bubbles() bool
|
||||
Cancelable() bool
|
||||
Composed() bool
|
||||
CurrentTarget() *Element
|
||||
DefaultPrevented() bool
|
||||
Target() *Element
|
||||
Type() string
|
||||
IsTrusted() bool
|
||||
Path() NodeList
|
||||
}
|
||||
|
||||
type EventHandler func(Event)
|
||||
|
||||
type EventConstructor func(e BaseEvent) Event
|
||||
|
||||
func RegisterEventType(typ string, fnc EventConstructor) {
|
||||
cl := js.Get(typ)
|
||||
if !cl.Valid() {
|
||||
panic(fmt.Errorf("class undefined: %q", typ))
|
||||
}
|
||||
eventClasses = append(eventClasses, eventClass{
|
||||
Class: cl, New: fnc,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterEventType("MouseEvent", func(e BaseEvent) Event {
|
||||
return &MouseEvent{e}
|
||||
})
|
||||
}
|
||||
|
||||
type eventClass struct {
|
||||
Class js.Value
|
||||
New EventConstructor
|
||||
}
|
||||
|
||||
var (
|
||||
eventClasses []eventClass
|
||||
)
|
||||
|
||||
func convertEvent(v js.Value) Event {
|
||||
e := BaseEvent{v: v}
|
||||
// TODO: get class name directly
|
||||
for _, cl := range eventClasses {
|
||||
if v.InstanceOf(cl.Class) {
|
||||
return cl.New(e)
|
||||
}
|
||||
}
|
||||
return &e
|
||||
}
|
||||
|
||||
type BaseEvent struct {
|
||||
v js.Value
|
||||
}
|
||||
|
||||
func (e *BaseEvent) getBool(name string) bool {
|
||||
return e.v.Get(name).Bool()
|
||||
}
|
||||
func (e *BaseEvent) Bubbles() bool {
|
||||
return e.getBool("bubbles")
|
||||
}
|
||||
|
||||
func (e *BaseEvent) Cancelable() bool {
|
||||
return e.getBool("cancelable")
|
||||
}
|
||||
|
||||
func (e *BaseEvent) Composed() bool {
|
||||
return e.getBool("composed")
|
||||
}
|
||||
|
||||
func (e *BaseEvent) CurrentTarget() *Element {
|
||||
return AsElement(e.v.Get("currentTarget"))
|
||||
}
|
||||
|
||||
func (e *BaseEvent) DefaultPrevented() bool {
|
||||
return e.getBool("defaultPrevented")
|
||||
}
|
||||
|
||||
func (e *BaseEvent) IsTrusted() bool {
|
||||
return e.getBool("isTrusted")
|
||||
}
|
||||
|
||||
func (e *BaseEvent) JSRef() js.Ref {
|
||||
return e.v.JSRef()
|
||||
}
|
||||
|
||||
func (e *BaseEvent) Type() string {
|
||||
return e.v.Get("type").String()
|
||||
}
|
||||
|
||||
func (e *BaseEvent) Target() *Element {
|
||||
return AsElement(e.v.Get("target"))
|
||||
}
|
||||
|
||||
func (e *BaseEvent) Path() NodeList {
|
||||
return AsNodeList(e.v.Get("path"))
|
||||
}
|
||||
|
||||
type MouseEventHandler func(*MouseEvent)
|
||||
|
||||
type MouseEvent struct {
|
||||
BaseEvent
|
||||
}
|
||||
|
||||
func (e *MouseEvent) getPos(nameX, nameY string) Point {
|
||||
x := e.v.Get(nameX).Int()
|
||||
y := e.v.Get(nameY).Int()
|
||||
return Point{X: x, Y: y}
|
||||
}
|
||||
|
||||
func (e *MouseEvent) getPosPref(pref string) Point {
|
||||
return e.getPos(pref+"X", pref+"Y")
|
||||
}
|
||||
|
||||
const (
|
||||
MouseLeft = MouseButton(0)
|
||||
)
|
||||
|
||||
type MouseButton int
|
||||
|
||||
func (e *MouseEvent) Button() MouseButton {
|
||||
return MouseButton(e.v.Get("button").Int())
|
||||
}
|
||||
|
||||
func (e *MouseEvent) ClientPos() Point {
|
||||
return e.getPosPref("client")
|
||||
}
|
||||
|
||||
func (e *MouseEvent) OffsetPos() Point {
|
||||
return e.getPosPref("offset")
|
||||
}
|
||||
|
||||
func (e *MouseEvent) PagePos() Point {
|
||||
return e.getPosPref("page")
|
||||
}
|
||||
|
||||
func (e *MouseEvent) ScreenPos() Point {
|
||||
return e.getPosPref("screen")
|
||||
}
|
||||
|
||||
func (e *MouseEvent) AltKey() bool {
|
||||
return e.v.Get("altKey").Bool()
|
||||
}
|
||||
|
||||
func (e *MouseEvent) CtrlKey() bool {
|
||||
return e.v.Get("ctrlKey").Bool()
|
||||
}
|
||||
|
||||
func (e *MouseEvent) ShiftKey() bool {
|
||||
return e.v.Get("shiftKey").Bool()
|
||||
}
|
||||
|
||||
func (e *MouseEvent) MetaKey() bool {
|
||||
return e.v.Get("metaKey").Bool()
|
||||
}
|
24
vendor/github.com/dennwc/dom/global.go
generated
vendored
24
vendor/github.com/dennwc/dom/global.go
generated
vendored
@ -1,24 +0,0 @@
|
||||
package dom
|
||||
|
||||
import (
|
||||
"github.com/dennwc/dom/js"
|
||||
"image"
|
||||
)
|
||||
|
||||
var (
|
||||
Doc = GetDocument()
|
||||
Body = Doc.GetElementsByTagName("body")[0]
|
||||
)
|
||||
|
||||
type Value = js.JSRef
|
||||
|
||||
func ConsoleLog(args ...interface{}) {
|
||||
js.Get("console").Call("log", args...)
|
||||
}
|
||||
|
||||
func Loop() {
|
||||
<-(chan struct{})(nil)
|
||||
}
|
||||
|
||||
type Point = image.Point
|
||||
type Rect = image.Rectangle
|
46
vendor/github.com/dennwc/dom/input.go
generated
vendored
46
vendor/github.com/dennwc/dom/input.go
generated
vendored
@ -1,46 +0,0 @@
|
||||
package dom
|
||||
|
||||
func (d *Document) NewInput(typ string) *Input {
|
||||
e := d.CreateElement("input")
|
||||
inp := &Input{*e}
|
||||
inp.SetType(typ)
|
||||
return inp
|
||||
}
|
||||
|
||||
type Input struct {
|
||||
Element
|
||||
}
|
||||
|
||||
func (inp *Input) Value() string {
|
||||
return inp.v.Get("value").String()
|
||||
}
|
||||
func (inp *Input) SetType(typ string) {
|
||||
inp.SetAttribute("type", typ)
|
||||
}
|
||||
func (inp *Input) SetName(name string) {
|
||||
inp.SetAttribute("name", name)
|
||||
}
|
||||
func (inp *Input) SetValue(val interface{}) {
|
||||
inp.v.Set("value", val)
|
||||
}
|
||||
func (inp *Input) OnChange(h EventHandler) {
|
||||
inp.AddEventListener("change", h)
|
||||
}
|
||||
func (inp *Input) OnInput(h EventHandler) {
|
||||
inp.AddEventListener("input", h)
|
||||
}
|
||||
|
||||
func (d *Document) NewButton(s string) *Button {
|
||||
e := d.CreateElement("button")
|
||||
b := &Button{*e}
|
||||
b.SetInnerHTML(s)
|
||||
return b
|
||||
}
|
||||
|
||||
type Button struct {
|
||||
Element
|
||||
}
|
||||
|
||||
func (b *Button) OnClick(h EventHandler) {
|
||||
b.AddEventListener("click", h)
|
||||
}
|
131
vendor/github.com/dennwc/dom/js/js.go
generated
vendored
131
vendor/github.com/dennwc/dom/js/js.go
generated
vendored
@ -1,131 +0,0 @@
|
||||
package js
|
||||
|
||||
import "syscall/js"
|
||||
|
||||
var (
|
||||
global = js.Global()
|
||||
null = js.Null()
|
||||
undefined = js.Undefined()
|
||||
)
|
||||
|
||||
func Get(name string) Value {
|
||||
return Value{global.Get(name)}
|
||||
}
|
||||
|
||||
func Set(name string, v Value) {
|
||||
global.Set(name, v.JSRef())
|
||||
}
|
||||
|
||||
type Ref = js.Value
|
||||
|
||||
type JSRef interface {
|
||||
JSRef() Ref
|
||||
}
|
||||
|
||||
func toJS(o interface{}) interface{} {
|
||||
switch v := o.(type) {
|
||||
case JSRef:
|
||||
o = v.JSRef()
|
||||
case []Value:
|
||||
refs := make([]Ref, 0, len(v))
|
||||
for _, ref := range v {
|
||||
refs = append(refs, ref.JSRef())
|
||||
}
|
||||
o = refs
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
var _ JSRef = Value{}
|
||||
|
||||
type Value struct {
|
||||
Ref
|
||||
}
|
||||
|
||||
func (v Value) JSRef() Ref {
|
||||
return v.Ref
|
||||
}
|
||||
func (v Value) String() string {
|
||||
if !v.Valid() {
|
||||
return ""
|
||||
}
|
||||
return v.Ref.String()
|
||||
}
|
||||
func (v Value) IsNull() bool {
|
||||
return v.Ref == null
|
||||
}
|
||||
func (v Value) IsUndefined() bool {
|
||||
return v.Ref == undefined
|
||||
}
|
||||
func (v Value) Valid() bool {
|
||||
return !v.IsNull() && !v.IsUndefined()
|
||||
}
|
||||
func (v Value) Get(name string) Value {
|
||||
return Value{v.Ref.Get(name)}
|
||||
}
|
||||
func (v Value) Set(name string, val interface{}) {
|
||||
v.Ref.Set(name, toJS(val))
|
||||
}
|
||||
func (v Value) Del(name string) {
|
||||
|
||||
}
|
||||
func (v Value) Index(i int) Value {
|
||||
return Value{v.Ref.Index(i)}
|
||||
}
|
||||
func (v Value) SetIndex(i int, val interface{}) {
|
||||
v.Ref.SetIndex(i, toJS(val))
|
||||
}
|
||||
func (v Value) Call(name string, args ...interface{}) Value {
|
||||
for i, a := range args {
|
||||
args[i] = toJS(a)
|
||||
}
|
||||
return Value{v.Ref.Call(name, args...)}
|
||||
}
|
||||
func (v Value) Invoke(args ...interface{}) Value {
|
||||
for i, a := range args {
|
||||
args[i] = toJS(a)
|
||||
}
|
||||
return Value{v.Ref.Invoke(args...)}
|
||||
}
|
||||
func (v Value) New(args ...interface{}) Value {
|
||||
for i, a := range args {
|
||||
args[i] = toJS(a)
|
||||
}
|
||||
return Value{v.Ref.New(args...)}
|
||||
}
|
||||
func (v Value) InstanceOf(class Value) bool {
|
||||
return v.Ref.InstanceOf(class.Ref)
|
||||
}
|
||||
func (v Value) Slice() []Value {
|
||||
if !v.Valid() {
|
||||
return nil
|
||||
}
|
||||
n := v.Length()
|
||||
vals := make([]Value, 0, n)
|
||||
for i := 0; i < n; i++ {
|
||||
vals = append(vals, v.Index(i))
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
type Callback = js.Callback
|
||||
|
||||
func NewCallback(fnc func(v []Value)) Callback {
|
||||
return js.NewCallback(func(refs []js.Value) {
|
||||
vals := make([]Value, 0, len(refs))
|
||||
for _, ref := range refs {
|
||||
vals = append(vals, Value{ref})
|
||||
}
|
||||
fnc(vals)
|
||||
})
|
||||
}
|
||||
|
||||
func NewEventCallback(fnc func(v Value)) Callback {
|
||||
return NewEventCallbackFlags(0, fnc)
|
||||
}
|
||||
|
||||
func NewEventCallbackFlags(flags int, fnc func(v Value)) Callback {
|
||||
return js.NewEventCallback(js.EventCallbackFlag(flags), func(ref js.Value) {
|
||||
fnc(Value{ref})
|
||||
})
|
||||
}
|
108
vendor/github.com/dennwc/dom/node.go
generated
vendored
108
vendor/github.com/dennwc/dom/node.go
generated
vendored
@ -1,108 +0,0 @@
|
||||
package dom
|
||||
|
||||
import "github.com/dennwc/dom/js"
|
||||
|
||||
type Node interface {
|
||||
EventTarget
|
||||
|
||||
// properties
|
||||
|
||||
BaseURI() string
|
||||
NodeName() string
|
||||
ChildNodes() NodeList
|
||||
ParentNode() Node
|
||||
ParentElement() *Element
|
||||
TextContent() string
|
||||
SetTextContent(s string)
|
||||
|
||||
// methods
|
||||
|
||||
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 NodeList []*Element
|
||||
|
||||
type NodeBase struct {
|
||||
v js.Value
|
||||
callbacks []js.Callback
|
||||
}
|
||||
|
||||
func (e *NodeBase) JSRef() js.Ref {
|
||||
return e.v.JSRef()
|
||||
}
|
||||
|
||||
func (e *NodeBase) Remove() {
|
||||
e.ParentNode().RemoveChild(e)
|
||||
for _, c := range e.callbacks {
|
||||
c.Release()
|
||||
}
|
||||
e.callbacks = nil
|
||||
}
|
||||
|
||||
func (e *NodeBase) AddEventListenerFlags(typ string, flags int, h EventHandler) {
|
||||
cb := js.NewEventCallbackFlags(flags, func(v js.Value) {
|
||||
h(convertEvent(v))
|
||||
})
|
||||
e.callbacks = append(e.callbacks, cb)
|
||||
e.v.Call("addEventListener", typ, cb)
|
||||
}
|
||||
func (e *NodeBase) AddEventListener(typ string, h EventHandler) {
|
||||
e.AddEventListenerFlags(typ, 0, h)
|
||||
}
|
||||
|
||||
func (e *NodeBase) BaseURI() string {
|
||||
return e.v.Get("baseURI").String()
|
||||
}
|
||||
|
||||
func (e *NodeBase) NodeName() string {
|
||||
return e.v.Get("nodeName").String()
|
||||
}
|
||||
|
||||
func (e *NodeBase) ChildNodes() NodeList {
|
||||
return AsNodeList(e.v.Get("childNodes"))
|
||||
}
|
||||
|
||||
func (e *NodeBase) ParentNode() Node {
|
||||
return AsElement(e.v.Get("parentNode"))
|
||||
}
|
||||
|
||||
func (e *NodeBase) ParentElement() *Element {
|
||||
return AsElement(e.v.Get("parentElement"))
|
||||
}
|
||||
|
||||
func (e *NodeBase) TextContent() string {
|
||||
return e.v.Get("textContent").String()
|
||||
}
|
||||
|
||||
func (e *NodeBase) SetTextContent(s string) {
|
||||
e.v.Set("textContent", s)
|
||||
}
|
||||
|
||||
func (e *NodeBase) AppendChild(n Node) {
|
||||
e.v.Call("appendChild", n.JSRef())
|
||||
}
|
||||
|
||||
func (e *NodeBase) Contains(n Node) bool {
|
||||
return e.v.Call("contains", n.JSRef()).Bool()
|
||||
}
|
||||
|
||||
func (e *NodeBase) IsEqualNode(n Node) bool {
|
||||
return e.v.Call("isEqualNode", n.JSRef()).Bool()
|
||||
}
|
||||
|
||||
func (e *NodeBase) IsSameNode(n Node) bool {
|
||||
return e.v.Call("isSameNode", n.JSRef()).Bool()
|
||||
}
|
||||
|
||||
func (e *NodeBase) RemoveChild(n Node) Node {
|
||||
return AsElement(e.v.Call("removeChild", n.JSRef()))
|
||||
}
|
||||
|
||||
func (e *NodeBase) ReplaceChild(n, old Node) Node {
|
||||
return AsElement(e.v.Call("replaceChild", n.JSRef(), old.JSRef()))
|
||||
}
|
23
vendor/github.com/dennwc/dom/style.go
generated
vendored
23
vendor/github.com/dennwc/dom/style.go
generated
vendored
@ -1,23 +0,0 @@
|
||||
package dom
|
||||
|
||||
import "github.com/dennwc/dom/js"
|
||||
|
||||
type Style struct {
|
||||
v js.Value
|
||||
}
|
||||
|
||||
func (s *Style) SetWidth(v Unit) {
|
||||
s.v.Set("width", v.String())
|
||||
}
|
||||
|
||||
func (s *Style) SetHeight(v Unit) {
|
||||
s.v.Set("height", v.String())
|
||||
}
|
||||
|
||||
func (s *Style) SetMarginsRaw(m string) {
|
||||
s.v.Set("margin", m)
|
||||
}
|
||||
|
||||
func (s *Style) Set(k string, v interface{}) {
|
||||
s.v.Set(k, v)
|
||||
}
|
74
vendor/github.com/dennwc/dom/units.go
generated
vendored
74
vendor/github.com/dennwc/dom/units.go
generated
vendored
@ -1,74 +0,0 @@
|
||||
package dom
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
_ Unit = Px(0)
|
||||
_ Unit = Em(0)
|
||||
_ Unit = Rem(0)
|
||||
_ Unit = Vw(0)
|
||||
_ Unit = Vh(0)
|
||||
_ Unit = Vmin(0)
|
||||
_ Unit = Vmax(0)
|
||||
_ Unit = Perc(0)
|
||||
)
|
||||
|
||||
type Unit interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
type Auto struct{}
|
||||
|
||||
func (Auto) String() string {
|
||||
return "auto"
|
||||
}
|
||||
|
||||
type Px int
|
||||
|
||||
func (v Px) String() string {
|
||||
return strconv.Itoa(int(v)) + "px"
|
||||
}
|
||||
|
||||
type Em float64
|
||||
|
||||
func (v Em) String() string {
|
||||
return strconv.FormatFloat(float64(v), 'g', -1, 64) + "em"
|
||||
}
|
||||
|
||||
type Rem int
|
||||
|
||||
func (v Rem) String() string {
|
||||
return strconv.Itoa(int(v)) + "rem"
|
||||
}
|
||||
|
||||
type Vw int
|
||||
|
||||
func (v Vw) String() string {
|
||||
return strconv.Itoa(int(v)) + "vw"
|
||||
}
|
||||
|
||||
type Vh int
|
||||
|
||||
func (v Vh) String() string {
|
||||
return strconv.Itoa(int(v)) + "vh"
|
||||
}
|
||||
|
||||
type Vmin int
|
||||
|
||||
func (v Vmin) String() string {
|
||||
return strconv.Itoa(int(v)) + "vmin"
|
||||
}
|
||||
|
||||
type Vmax int
|
||||
|
||||
func (v Vmax) String() string {
|
||||
return strconv.Itoa(int(v)) + "vmax"
|
||||
}
|
||||
|
||||
type Perc int
|
||||
|
||||
func (v Perc) String() string {
|
||||
return strconv.Itoa(int(v)) + "%"
|
||||
}
|
31
vendor/github.com/dennwc/dom/window.go
generated
vendored
31
vendor/github.com/dennwc/dom/window.go
generated
vendored
@ -1,31 +0,0 @@
|
||||
package dom
|
||||
|
||||
import "github.com/dennwc/dom/js"
|
||||
|
||||
func GetWindow() *Window {
|
||||
win := js.Get("window")
|
||||
if !win.Valid() {
|
||||
return nil
|
||||
}
|
||||
return &Window{v: win}
|
||||
}
|
||||
|
||||
var _ EventTarget = (*Window)(nil)
|
||||
|
||||
type Window struct {
|
||||
v js.Value
|
||||
}
|
||||
|
||||
func (w *Window) JSRef() js.Ref {
|
||||
return w.v.JSRef()
|
||||
}
|
||||
|
||||
func (w *Window) AddEventListener(typ string, h EventHandler) {
|
||||
w.v.Call("addEventListener", typ, js.NewEventCallback(func(v js.Value) {
|
||||
h(convertEvent(v))
|
||||
}))
|
||||
}
|
||||
|
||||
func (w *Window) OnResize(fnc func(e Event)) {
|
||||
w.AddEventListener("resize", fnc)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user