@thi.ng/wasm-api-dom
Advanced tools
Comparing version 0.11.53 to 0.11.54
14
api.js
import { XML_SVG, XML_XLINK, XML_XMLNS } from "@thi.ng/prefixes/xml"; | ||
export * from "./generated/api.js"; | ||
/** | ||
* Registry of wellknown namespace URIs and their aliases. | ||
*/ | ||
export const NS_PREFIXES = { | ||
svg: XML_SVG, | ||
xlink: XML_XLINK, | ||
xmlns: XML_XMLNS, | ||
const NS_PREFIXES = { | ||
svg: XML_SVG, | ||
xlink: XML_XLINK, | ||
xmlns: XML_XMLNS | ||
}; | ||
export { | ||
NS_PREFIXES | ||
}; |
# Change Log | ||
- **Last updated**: 2023-12-09T19:12:04Z | ||
- **Last updated**: 2023-12-11T10:07:09Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -5,0 +5,0 @@ |
637
dom.js
import { adaptDPI } from "@thi.ng/adapt-dpi"; | ||
import { assert } from "@thi.ng/errors/assert"; | ||
import { WasmStringSlice, } from "@thi.ng/wasm-api"; | ||
import { | ||
WasmStringSlice | ||
} from "@thi.ng/wasm-api"; | ||
import { ObjectIndex } from "@thi.ng/wasm-api/object-index"; | ||
import { $CreateCanvasOpts, $CreateElementOpts, $Event, $WindowInfo, AttribType, EventType, NS_PREFIXES, } from "./api.js"; | ||
/** | ||
* Hidden property for managed DOM elements to track IDs of attached WASM event | ||
* listeners | ||
*/ | ||
import { | ||
$CreateCanvasOpts, | ||
$CreateElementOpts, | ||
$Event, | ||
$WindowInfo, | ||
AttribType, | ||
EventType, | ||
NS_PREFIXES | ||
} from "./api.js"; | ||
const __listeners = "__wasm_listeners"; | ||
/** | ||
* Map of JS event name regexps to {@link EventType} enums and {@link EventBody} | ||
* field names | ||
*/ | ||
const EVENT_MAP = [ | ||
[/^drag(end|enter|leave|over|start)|drop$/, "drag", EventType.DRAG], | ||
[/^blur|focus(in|out)?$/, , EventType.FOCUS], | ||
[/^change|(before)?input$/, "input", EventType.INPUT], | ||
[/^key(down|press|up)$/, "key", EventType.KEY], | ||
[ | ||
/^(dbl)?click|contextmenu|mouse(down|enter|leave|move|out|over|up)$/, | ||
"mouse", | ||
EventType.MOUSE, | ||
], | ||
[ | ||
/^(got|lost)pointercapture|pointer(cancel|down|enter|leave|move|out|over|up)$/, | ||
"pointer", | ||
EventType.POINTER, | ||
], | ||
[/^scroll$/, "scroll", EventType.SCROLL], | ||
[/^touch(cancel|end|move|start)$/, "touch", EventType.TOUCH], | ||
[/^wheel$/, "touch", EventType.WHEEL], | ||
[/^drag(end|enter|leave|over|start)|drop$/, "drag", EventType.DRAG], | ||
[/^blur|focus(in|out)?$/, , EventType.FOCUS], | ||
[/^change|(before)?input$/, "input", EventType.INPUT], | ||
[/^key(down|press|up)$/, "key", EventType.KEY], | ||
[ | ||
/^(dbl)?click|contextmenu|mouse(down|enter|leave|move|out|over|up)$/, | ||
"mouse", | ||
EventType.MOUSE | ||
], | ||
[ | ||
/^(got|lost)pointercapture|pointer(cancel|down|enter|leave|move|out|over|up)$/, | ||
"pointer", | ||
EventType.POINTER | ||
], | ||
[/^scroll$/, "scroll", EventType.SCROLL], | ||
[/^touch(cancel|end|move|start)$/, "touch", EventType.TOUCH], | ||
[/^wheel$/, "touch", EventType.WHEEL] | ||
]; | ||
export class WasmDom { | ||
static id = "dom"; | ||
id = WasmDom.id; | ||
parent; | ||
$Event; | ||
$CreateElementOpts; | ||
elements = new ObjectIndex({ name: "elements" }); | ||
listeners = {}; | ||
currEvent = null; | ||
currDataTransfer = null; | ||
async init(parent) { | ||
this.parent = parent; | ||
if (parent.exports._dom_init) { | ||
parent.exports._dom_init(); | ||
class WasmDom { | ||
static id = "dom"; | ||
id = WasmDom.id; | ||
parent; | ||
$Event; | ||
$CreateElementOpts; | ||
elements = new ObjectIndex({ name: "elements" }); | ||
listeners = {}; | ||
currEvent = null; | ||
currDataTransfer = null; | ||
async init(parent) { | ||
this.parent = parent; | ||
if (parent.exports._dom_init) { | ||
parent.exports._dom_init(); | ||
} else { | ||
parent.logger.warn("DOM module unused, skipping auto-init..."); | ||
} | ||
this.elements.add(document.head); | ||
this.elements.add(document.body); | ||
this.$Event = $Event(this.parent); | ||
this.$CreateElementOpts = $CreateElementOpts(this.parent); | ||
return true; | ||
} | ||
getImports() { | ||
return { | ||
getWindowInfo: (ptr) => { | ||
const info = $WindowInfo(this.parent).instance(ptr); | ||
info.innerWidth = window.innerWidth; | ||
info.innerHeight = window.innerHeight; | ||
info.dpr = window.devicePixelRatio || 1; | ||
info.scrollX = window.scrollX; | ||
info.scrollY = window.scrollY; | ||
info.fullscreen = (document.fullscreenElement || document.webkitFullscreenElement ? 1 : 0) | (document.fullscreenEnabled || document.webkitFullscreenEnabled ? 2 : 0); | ||
}, | ||
getElementByID: (nameAddr) => { | ||
const name = this.parent.getString(nameAddr); | ||
let id = this.elements.find((el) => el.id === name); | ||
if (id === void 0) { | ||
const el = document.getElementById(name); | ||
return el ? this.elements.add(el) : -1; | ||
} | ||
else { | ||
parent.logger.warn("DOM module unused, skipping auto-init..."); | ||
return id; | ||
}, | ||
createElement: (optsAddr) => { | ||
const create = (opts, nestedParent) => { | ||
const tagName = opts.tag.deref(); | ||
const ns = opts.ns.deref(); | ||
const el = ns ? document.createElementNS( | ||
NS_PREFIXES[ns] || ns, | ||
tagName | ||
) : document.createElement(tagName); | ||
const id = this.elements.add(el); | ||
this.initElement(id, el, opts, nestedParent); | ||
if (opts.children.length > 0) { | ||
for (let child of opts.children) { | ||
create(child, id); | ||
} | ||
} | ||
return id; | ||
}; | ||
return create(this.$CreateElementOpts.instance(optsAddr)); | ||
}, | ||
removeElement: (elementID) => { | ||
assert(elementID > 1, "can't remove reserved element"); | ||
const el = this.elements.get(elementID, false); | ||
if (!el) | ||
return; | ||
const remove = (el2) => { | ||
const elementID2 = this.elements.find( | ||
(x) => x === el2, | ||
false | ||
); | ||
if (elementID2 !== void 0) { | ||
this.elements.delete(elementID2, false); | ||
const elementListeners = el2[__listeners]; | ||
if (elementListeners) { | ||
for (let listenerID of elementListeners) { | ||
this.removeListener(el2, listenerID); | ||
this.parent.exports._dom_removeListener( | ||
listenerID | ||
); | ||
} | ||
} | ||
} | ||
el2.parentNode?.removeChild(el2); | ||
for (let child of [...el2.children]) | ||
remove(child); | ||
}; | ||
remove(el); | ||
}, | ||
createCanvas: (optsAddr) => { | ||
const opts = $CreateCanvasOpts(this.parent).instance(optsAddr); | ||
const el = document.createElement("canvas"); | ||
adaptDPI(el, opts.width, opts.height, opts.dpr); | ||
const id = this.elements.add(el); | ||
this.initElement(id, el, opts); | ||
return id; | ||
}, | ||
setCanvasSize: (elementID, width, height, dpr) => adaptDPI( | ||
this.elements.get(elementID), | ||
width, | ||
height, | ||
dpr | ||
), | ||
setStringAttrib: (elementID, name, val) => this.setAttrib(elementID, name, this.parent.getString(val)), | ||
setNumericAttrib: (elementID, name, val) => this.setAttrib(elementID, name, val), | ||
_setBooleanAttrib: (elementID, nameAddr, val) => { | ||
const el = this.elements.get(elementID); | ||
const name = this.parent.getString(nameAddr); | ||
if (name in el) { | ||
el[name] = !!val; | ||
} else { | ||
val ? el.setAttribute(name, "") : el.removeAttribute(name); | ||
} | ||
this.elements.add(document.head); | ||
this.elements.add(document.body); | ||
this.$Event = $Event(this.parent); | ||
this.$CreateElementOpts = $CreateElementOpts(this.parent); | ||
return true; | ||
} | ||
getImports() { | ||
return { | ||
getWindowInfo: (ptr) => { | ||
const info = $WindowInfo(this.parent).instance(ptr); | ||
info.innerWidth = window.innerWidth; | ||
info.innerHeight = window.innerHeight; | ||
info.dpr = window.devicePixelRatio || 1; | ||
info.scrollX = window.scrollX; | ||
info.scrollY = window.scrollY; | ||
info.fullscreen = | ||
(document.fullscreenElement || | ||
document.webkitFullscreenElement | ||
? 1 | ||
: 0) | | ||
(document.fullscreenEnabled || | ||
document.webkitFullscreenEnabled | ||
? 2 | ||
: 0); | ||
}, | ||
getElementByID: (nameAddr) => { | ||
const name = this.parent.getString(nameAddr); | ||
let id = this.elements.find((el) => el.id === name); | ||
if (id === undefined) { | ||
const el = document.getElementById(name); | ||
return el ? this.elements.add(el) : -1; | ||
} | ||
return id; | ||
}, | ||
createElement: (optsAddr) => { | ||
const create = (opts, nestedParent) => { | ||
const tagName = opts.tag.deref(); | ||
const ns = opts.ns.deref(); | ||
const el = ns | ||
? document.createElementNS(NS_PREFIXES[ns] || ns, tagName) | ||
: document.createElement(tagName); | ||
const id = this.elements.add(el); | ||
this.initElement(id, el, opts, nestedParent); | ||
if (opts.children.length > 0) { | ||
for (let child of opts.children) { | ||
create(child, id); | ||
} | ||
} | ||
return id; | ||
}; | ||
return create(this.$CreateElementOpts.instance(optsAddr)); | ||
}, | ||
removeElement: (elementID) => { | ||
assert(elementID > 1, "can't remove reserved element"); | ||
const el = this.elements.get(elementID, false); | ||
if (!el) | ||
return; | ||
const remove = (el) => { | ||
const elementID = this.elements.find((x) => x === el, false); | ||
if (elementID !== undefined) { | ||
this.elements.delete(elementID, false); | ||
const elementListeners = el[__listeners]; | ||
if (elementListeners) { | ||
for (let listenerID of elementListeners) { | ||
this.removeListener(el, listenerID); | ||
// WASM side cleanup | ||
this.parent.exports._dom_removeListener(listenerID); | ||
} | ||
} | ||
} | ||
el.parentNode?.removeChild(el); | ||
for (let child of [...el.children]) | ||
remove(child); | ||
}; | ||
remove(el); | ||
}, | ||
createCanvas: (optsAddr) => { | ||
const opts = $CreateCanvasOpts(this.parent).instance(optsAddr); | ||
const el = document.createElement("canvas"); | ||
adaptDPI(el, opts.width, opts.height, opts.dpr); | ||
const id = this.elements.add(el); | ||
this.initElement(id, el, opts); | ||
return id; | ||
}, | ||
setCanvasSize: (elementID, width, height, dpr) => adaptDPI(this.elements.get(elementID), width, height, dpr), | ||
setStringAttrib: (elementID, name, val) => this.setAttrib(elementID, name, this.parent.getString(val)), | ||
setNumericAttrib: (elementID, name, val) => this.setAttrib(elementID, name, val), | ||
_setBooleanAttrib: (elementID, nameAddr, val) => { | ||
const el = this.elements.get(elementID); | ||
const name = this.parent.getString(nameAddr); | ||
if (name in el) { | ||
// @ts-ignore | ||
el[name] = !!val; | ||
} | ||
else { | ||
val ? el.setAttribute(name, "") : el.removeAttribute(name); | ||
} | ||
}, | ||
_getStringAttrib: (elementID, nameAddr, valAddr, maxBytes) => this.parent.setString(String(this.getAttrib(elementID, nameAddr) || ""), valAddr, maxBytes, true), | ||
_getStringAttribAlloc: (elementID, nameAddr, slice) => new WasmStringSlice(this.parent, slice).setAlloc(String(this.getAttrib(elementID, nameAddr) || ""), true), | ||
getNumericAttrib: (elementID, nameAddr) => Number(this.getAttrib(elementID, nameAddr) || ""), | ||
_getBooleanAttrib: (elementID, nameAddr) => ~~(this.getAttrib(elementID, nameAddr) != null), | ||
addClass: (elementID, name) => this.elements | ||
.get(elementID) | ||
.classList.add(this.parent.getString(name)), | ||
removeClass: (elementID, name) => this.elements | ||
.get(elementID) | ||
.classList.remove(this.parent.getString(name)), | ||
_addListener: (ctxID, name, listenerID) => { | ||
const ctx = ctxID < 0 ? window : this.elements.get(ctxID); | ||
const eventName = this.parent.getString(name); | ||
const eventSpec = EVENT_MAP.find(([re]) => re.test(eventName)); | ||
const [eventBodyID, eventTypeID] = eventSpec | ||
? [eventSpec[1], eventSpec[2]] | ||
: [undefined, EventType.UNKOWN]; | ||
const hasModifiers = [ | ||
EventType.DRAG, | ||
EventType.INPUT, | ||
EventType.KEY, | ||
EventType.MOUSE, | ||
EventType.POINTER, | ||
EventType.TOUCH, | ||
EventType.WHEEL, | ||
].includes(eventTypeID); | ||
const event = this.$Event.instance(this.parent.allocate(this.$Event.size)[0]); | ||
const body = eventBodyID ? event.body[eventBodyID] : undefined; | ||
const fn = (e) => { | ||
this.currEvent = e; | ||
this.parent.ensureMemory(); | ||
event.__bytes.fill(0); | ||
const target = e.target === ctx | ||
? ctxID | ||
: e.target === window | ||
? -1 | ||
: this.elements.find((x) => x === e.target, false); | ||
event.target = target !== undefined ? target : -2; | ||
event.id = eventTypeID; | ||
const slice = body ? body.fromEvent(e) : undefined; | ||
if (hasModifiers) { | ||
body.modifiers = this.encodeModifiers(e); | ||
} | ||
if (eventTypeID === EventType.DRAG) { | ||
this.currDataTransfer = e.dataTransfer; | ||
} | ||
this.parent.exports._dom_callListener(listenerID, event.__base); | ||
if (slice) | ||
this.parent.free(slice); | ||
this.currEvent = null; | ||
this.currDataTransfer = null; | ||
}; | ||
this.parent.logger.debug(`ctx ${ctxID} - adding ${eventName} listener #${listenerID}`); | ||
ctx.addEventListener(eventName, fn); | ||
this.listeners[listenerID] = { | ||
ctx: ctxID, | ||
name: eventName, | ||
event, | ||
fn, | ||
}; | ||
if (ctxID >= 0) { | ||
(ctx[__listeners] || | ||
(ctx[__listeners] = new Set())).add(listenerID); | ||
} | ||
}, | ||
preventDefault: () => { | ||
this.currEvent && this.currEvent.preventDefault(); | ||
}, | ||
stopPropagation: () => { | ||
this.currEvent && this.currEvent.stopPropagation(); | ||
}, | ||
stopImmediatePropagation: () => { | ||
this.currEvent && this.currEvent.stopImmediatePropagation(); | ||
}, | ||
_removeListener: (listenerID) => { | ||
const listener = this.listeners[listenerID]; | ||
assert(!!listener, `unknown listener ID: ${listenerID}`); | ||
const ctx = listener.ctx < 0 ? window : this.elements.get(listener.ctx); | ||
this.removeListener(ctx, listenerID); | ||
if (listener.ctx >= 0) { | ||
const listeners = ctx[__listeners]; | ||
if (listeners.has(listenerID)) | ||
listeners.delete(listenerID); | ||
} | ||
}, | ||
setInnerHtml: (elementID, body) => { | ||
this.elements.get(elementID).innerHTML = | ||
this.parent.getString(body); | ||
}, | ||
setInnerText: (elementID, body) => { | ||
this.elements.get(elementID).innerText = | ||
this.parent.getString(body); | ||
}, | ||
_requestAnimationFrame: (rafID) => { | ||
this.parent.logger.fine(`requestAnimationFrame #${rafID}`); | ||
requestAnimationFrame((t) => this.parent.exports._dom_callRAF(rafID, t)); | ||
}, | ||
_requestFullscreen: async (elementID) => { | ||
if (!(document.fullscreenElement || | ||
document.webkitFullscreenElement)) { | ||
const el = elementID <= 1 | ||
? document.documentElement | ||
: this.elements.get(elementID); | ||
const method = el.requestFullscreen || | ||
el.webkitRequestFullscreen; | ||
await method.bind(el)(); | ||
this.parent.exports._dom_fullscreenChanged(); | ||
} | ||
}, | ||
_exitFullscreen: async () => { | ||
if (document.fullscreenElement || | ||
document.webkitFullscreenElement) { | ||
const method = document.exitFullscreen || | ||
document.webkitExitFullscreen; | ||
await method.bind(document)(); | ||
this.parent.exports._dom_fullscreenChanged(); | ||
} | ||
}, | ||
}, | ||
_getStringAttrib: (elementID, nameAddr, valAddr, maxBytes) => this.parent.setString( | ||
String(this.getAttrib(elementID, nameAddr) || ""), | ||
valAddr, | ||
maxBytes, | ||
true | ||
), | ||
_getStringAttribAlloc: (elementID, nameAddr, slice) => new WasmStringSlice(this.parent, slice).setAlloc( | ||
String(this.getAttrib(elementID, nameAddr) || ""), | ||
true | ||
), | ||
getNumericAttrib: (elementID, nameAddr) => Number(this.getAttrib(elementID, nameAddr) || ""), | ||
_getBooleanAttrib: (elementID, nameAddr) => ~~(this.getAttrib(elementID, nameAddr) != null), | ||
addClass: (elementID, name) => this.elements.get(elementID).classList.add(this.parent.getString(name)), | ||
removeClass: (elementID, name) => this.elements.get(elementID).classList.remove(this.parent.getString(name)), | ||
_addListener: (ctxID, name, listenerID) => { | ||
const ctx = ctxID < 0 ? window : this.elements.get(ctxID); | ||
const eventName = this.parent.getString(name); | ||
const eventSpec = EVENT_MAP.find(([re]) => re.test(eventName)); | ||
const [eventBodyID, eventTypeID] = eventSpec ? [eventSpec[1], eventSpec[2]] : [void 0, EventType.UNKOWN]; | ||
const hasModifiers = [ | ||
EventType.DRAG, | ||
EventType.INPUT, | ||
EventType.KEY, | ||
EventType.MOUSE, | ||
EventType.POINTER, | ||
EventType.TOUCH, | ||
EventType.WHEEL | ||
].includes(eventTypeID); | ||
const event = this.$Event.instance( | ||
this.parent.allocate(this.$Event.size)[0] | ||
); | ||
const body = eventBodyID ? event.body[eventBodyID] : void 0; | ||
const fn = (e) => { | ||
this.currEvent = e; | ||
this.parent.ensureMemory(); | ||
event.__bytes.fill(0); | ||
const target = e.target === ctx ? ctxID : e.target === window ? -1 : this.elements.find((x) => x === e.target, false); | ||
event.target = target !== void 0 ? target : -2; | ||
event.id = eventTypeID; | ||
const slice = body ? body.fromEvent(e) : void 0; | ||
if (hasModifiers) { | ||
body.modifiers = this.encodeModifiers( | ||
e | ||
); | ||
} | ||
if (eventTypeID === EventType.DRAG) { | ||
this.currDataTransfer = e.dataTransfer; | ||
} | ||
this.parent.exports._dom_callListener( | ||
listenerID, | ||
event.__base | ||
); | ||
if (slice) | ||
this.parent.free(slice); | ||
this.currEvent = null; | ||
this.currDataTransfer = null; | ||
}; | ||
} | ||
initElement(elementID, el, opts, nestedParent) { | ||
const { id, attribs, class: $class, index } = opts; | ||
if (id.length) | ||
el.setAttribute("id", id.deref()); | ||
if ($class.length) | ||
el.setAttribute("class", $class.deref()); | ||
if (opts.html?.length) { | ||
el.innerHTML = opts.html.deref(); | ||
this.parent.logger.debug( | ||
`ctx ${ctxID} - adding ${eventName} listener #${listenerID}` | ||
); | ||
ctx.addEventListener(eventName, fn); | ||
this.listeners[listenerID] = { | ||
ctx: ctxID, | ||
name: eventName, | ||
event, | ||
fn | ||
}; | ||
if (ctxID >= 0) { | ||
(ctx[__listeners] || (ctx[__listeners] = /* @__PURE__ */ new Set())).add(listenerID); | ||
} | ||
else if (opts.text?.length) { | ||
el.innerText = opts.text.deref(); | ||
}, | ||
preventDefault: () => { | ||
this.currEvent && this.currEvent.preventDefault(); | ||
}, | ||
stopPropagation: () => { | ||
this.currEvent && this.currEvent.stopPropagation(); | ||
}, | ||
stopImmediatePropagation: () => { | ||
this.currEvent && this.currEvent.stopImmediatePropagation(); | ||
}, | ||
_removeListener: (listenerID) => { | ||
const listener = this.listeners[listenerID]; | ||
assert(!!listener, `unknown listener ID: ${listenerID}`); | ||
const ctx = listener.ctx < 0 ? window : this.elements.get(listener.ctx); | ||
this.removeListener(ctx, listenerID); | ||
if (listener.ctx >= 0) { | ||
const listeners = ctx[__listeners]; | ||
if (listeners.has(listenerID)) | ||
listeners.delete(listenerID); | ||
} | ||
if (attribs && attribs.length) { | ||
for (let attr of attribs) { | ||
const name = attr.name.deref(); | ||
if (attr.kind === AttribType.EVENT) { | ||
const listenerAddr = attr.value.event.__base; | ||
const listenerID = this.parent.exports._dom_addListener(listenerAddr); | ||
this.getImports()._addListener(elementID, attr.name.addr, listenerID); | ||
} | ||
else if (attr.kind === AttribType.FLAG) { | ||
attr.value.flag && el.setAttribute(name, ""); | ||
} | ||
else { | ||
el.setAttribute(name, attr.kind === AttribType.STR | ||
? attr.value.str.deref() | ||
: String(attr.value.num)); | ||
} | ||
} | ||
}, | ||
setInnerHtml: (elementID, body) => { | ||
this.elements.get(elementID).innerHTML = this.parent.getString(body); | ||
}, | ||
setInnerText: (elementID, body) => { | ||
this.elements.get(elementID).innerText = this.parent.getString(body); | ||
}, | ||
_requestAnimationFrame: (rafID) => { | ||
this.parent.logger.fine(`requestAnimationFrame #${rafID}`); | ||
requestAnimationFrame( | ||
(t) => this.parent.exports._dom_callRAF(rafID, t) | ||
); | ||
}, | ||
_requestFullscreen: async (elementID) => { | ||
if (!(document.fullscreenElement || document.webkitFullscreenElement)) { | ||
const el = elementID <= 1 ? document.documentElement : this.elements.get(elementID); | ||
const method = el.requestFullscreen || el.webkitRequestFullscreen; | ||
await method.bind(el)(); | ||
this.parent.exports._dom_fullscreenChanged(); | ||
} | ||
const parent = nestedParent != undefined ? nestedParent : opts.parent; | ||
if (parent >= 0) { | ||
const parentEl = this.elements.get(parent); | ||
index < 0 | ||
? parentEl.appendChild(el) | ||
: parentEl.insertBefore(el, parentEl.childNodes[index]); | ||
}, | ||
_exitFullscreen: async () => { | ||
if (document.fullscreenElement || document.webkitFullscreenElement) { | ||
const method = document.exitFullscreen || document.webkitExitFullscreen; | ||
await method.bind(document)(); | ||
this.parent.exports._dom_fullscreenChanged(); | ||
} | ||
} | ||
}; | ||
} | ||
initElement(elementID, el, opts, nestedParent) { | ||
const { id, attribs, class: $class, index } = opts; | ||
if (id.length) | ||
el.setAttribute("id", id.deref()); | ||
if ($class.length) | ||
el.setAttribute("class", $class.deref()); | ||
if (opts.html?.length) { | ||
el.innerHTML = opts.html.deref(); | ||
} else if (opts.text?.length) { | ||
el.innerText = opts.text.deref(); | ||
} | ||
encodeModifiers(e) { | ||
return ((e.shiftKey ? 1 : 0) | | ||
(e.ctrlKey ? 2 : 0) | | ||
(e.altKey ? 4 : 0) | | ||
(e.metaKey ? 8 : 0)); | ||
if (attribs && attribs.length) { | ||
for (let attr of attribs) { | ||
const name = attr.name.deref(); | ||
if (attr.kind === AttribType.EVENT) { | ||
const listenerAddr = attr.value.event.__base; | ||
const listenerID = this.parent.exports._dom_addListener(listenerAddr); | ||
this.getImports()._addListener( | ||
elementID, | ||
attr.name.addr, | ||
listenerID | ||
); | ||
} else if (attr.kind === AttribType.FLAG) { | ||
attr.value.flag && el.setAttribute(name, ""); | ||
} else { | ||
el.setAttribute( | ||
name, | ||
attr.kind === AttribType.STR ? attr.value.str.deref() : String(attr.value.num) | ||
); | ||
} | ||
} | ||
} | ||
getAttrib(elementID, nameAddr) { | ||
const el = this.elements.get(elementID); | ||
const name = this.parent.getString(nameAddr); | ||
return name in el ? el[name] : el.getAttribute(name); | ||
const parent = nestedParent != void 0 ? nestedParent : opts.parent; | ||
if (parent >= 0) { | ||
const parentEl = this.elements.get(parent); | ||
index < 0 ? parentEl.appendChild(el) : parentEl.insertBefore(el, parentEl.childNodes[index]); | ||
} | ||
setAttrib(elementID, nameAddr, value) { | ||
const el = this.elements.get(elementID); | ||
const name = this.parent.getString(nameAddr); | ||
return name in el | ||
? // @ts-ignore | ||
(el[name] = value) | ||
: el.setAttribute(name, String(value)); | ||
} | ||
removeListener(ctx, listenerID) { | ||
const listener = this.listeners[listenerID]; | ||
assert(!!listener, `invalid listener ID ${listenerID}`); | ||
this.parent.logger.debug(`removing event listener #${listenerID}`); | ||
delete this.listeners[listenerID]; | ||
ctx.removeEventListener(listener.name, listener.fn); | ||
this.parent.free([listener.event.__base, this.$Event.size]); | ||
} | ||
} | ||
encodeModifiers(e) { | ||
return (e.shiftKey ? 1 : 0) | (e.ctrlKey ? 2 : 0) | (e.altKey ? 4 : 0) | (e.metaKey ? 8 : 0); | ||
} | ||
getAttrib(elementID, nameAddr) { | ||
const el = this.elements.get(elementID); | ||
const name = this.parent.getString(nameAddr); | ||
return name in el ? el[name] : el.getAttribute(name); | ||
} | ||
setAttrib(elementID, nameAddr, value) { | ||
const el = this.elements.get(elementID); | ||
const name = this.parent.getString(nameAddr); | ||
return name in el ? ( | ||
// @ts-ignore | ||
el[name] = value | ||
) : el.setAttribute(name, String(value)); | ||
} | ||
removeListener(ctx, listenerID) { | ||
const listener = this.listeners[listenerID]; | ||
assert(!!listener, `invalid listener ID ${listenerID}`); | ||
this.parent.logger.debug(`removing event listener #${listenerID}`); | ||
delete this.listeners[listenerID]; | ||
ctx.removeEventListener(listener.name, listener.fn); | ||
this.parent.free([listener.event.__base, this.$Event.size]); | ||
} | ||
} | ||
export { | ||
WasmDom | ||
}; |
1955
generated/api.js
@@ -1,985 +0,1004 @@ | ||
/** | ||
* Generated by @thi.ng/wasm-api-bindgen at 2023-03-26T00:14:48.760Z | ||
* DO NOT EDIT! | ||
*/ | ||
// @ts-ignore possibly includes unused imports | ||
import { Pointer, WasmStringPtr } from "@thi.ng/wasm-api"; | ||
export var EventType; | ||
(function (EventType) { | ||
EventType[EventType["UNKOWN"] = -1] = "UNKOWN"; | ||
EventType[EventType["DRAG"] = 0] = "DRAG"; | ||
EventType[EventType["FOCUS"] = 1] = "FOCUS"; | ||
EventType[EventType["INPUT"] = 2] = "INPUT"; | ||
EventType[EventType["KEY"] = 3] = "KEY"; | ||
EventType[EventType["MOUSE"] = 4] = "MOUSE"; | ||
EventType[EventType["POINTER"] = 5] = "POINTER"; | ||
EventType[EventType["SCROLL"] = 6] = "SCROLL"; | ||
EventType[EventType["TOUCH"] = 7] = "TOUCH"; | ||
EventType[EventType["WHEEL"] = 8] = "WHEEL"; | ||
})(EventType || (EventType = {})); | ||
export var MouseButton; | ||
(function (MouseButton) { | ||
MouseButton[MouseButton["NONE"] = 0] = "NONE"; | ||
MouseButton[MouseButton["PRIMARY"] = 1] = "PRIMARY"; | ||
MouseButton[MouseButton["SECONDARY"] = 2] = "SECONDARY"; | ||
MouseButton[MouseButton["MIDDLE"] = 4] = "MIDDLE"; | ||
})(MouseButton || (MouseButton = {})); | ||
export var PointerType; | ||
(function (PointerType) { | ||
PointerType[PointerType["MOUSE"] = 0] = "MOUSE"; | ||
PointerType[PointerType["PEN"] = 1] = "PEN"; | ||
PointerType[PointerType["TOUCH"] = 2] = "TOUCH"; | ||
})(PointerType || (PointerType = {})); | ||
export var WheelDeltaMode; | ||
(function (WheelDeltaMode) { | ||
WheelDeltaMode[WheelDeltaMode["PIXEL"] = 0] = "PIXEL"; | ||
WheelDeltaMode[WheelDeltaMode["LINE"] = 1] = "LINE"; | ||
WheelDeltaMode[WheelDeltaMode["PAGE"] = 2] = "PAGE"; | ||
})(WheelDeltaMode || (WheelDeltaMode = {})); | ||
export var KeyModifier; | ||
(function (KeyModifier) { | ||
KeyModifier[KeyModifier["SHIFT"] = 1] = "SHIFT"; | ||
KeyModifier[KeyModifier["CTRL"] = 2] = "CTRL"; | ||
KeyModifier[KeyModifier["ALT"] = 4] = "ALT"; | ||
KeyModifier[KeyModifier["META"] = 8] = "META"; | ||
})(KeyModifier || (KeyModifier = {})); | ||
export const $WindowInfo = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 16; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 16) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 16); | ||
}, | ||
get innerWidth() { | ||
return mem.u16[base >>> 1]; | ||
}, | ||
set innerWidth(x) { | ||
mem.u16[base >>> 1] = x; | ||
}, | ||
get innerHeight() { | ||
return mem.u16[(base + 2) >>> 1]; | ||
}, | ||
set innerHeight(x) { | ||
mem.u16[(base + 2) >>> 1] = x; | ||
}, | ||
get scrollX() { | ||
return mem.f32[(base + 4) >>> 2]; | ||
}, | ||
set scrollX(x) { | ||
mem.f32[(base + 4) >>> 2] = x; | ||
}, | ||
get scrollY() { | ||
return mem.f32[(base + 8) >>> 2]; | ||
}, | ||
set scrollY(x) { | ||
mem.f32[(base + 8) >>> 2] = x; | ||
}, | ||
get dpr() { | ||
return mem.u8[(base + 12)]; | ||
}, | ||
set dpr(x) { | ||
mem.u8[(base + 12)] = x; | ||
}, | ||
get fullscreen() { | ||
return mem.u8[(base + 13)]; | ||
}, | ||
set fullscreen(x) { | ||
mem.u8[(base + 13)] = x; | ||
}, | ||
}; | ||
} | ||
var EventType = /* @__PURE__ */ ((EventType2) => { | ||
EventType2[EventType2["UNKOWN"] = -1] = "UNKOWN"; | ||
EventType2[EventType2["DRAG"] = 0] = "DRAG"; | ||
EventType2[EventType2["FOCUS"] = 1] = "FOCUS"; | ||
EventType2[EventType2["INPUT"] = 2] = "INPUT"; | ||
EventType2[EventType2["KEY"] = 3] = "KEY"; | ||
EventType2[EventType2["MOUSE"] = 4] = "MOUSE"; | ||
EventType2[EventType2["POINTER"] = 5] = "POINTER"; | ||
EventType2[EventType2["SCROLL"] = 6] = "SCROLL"; | ||
EventType2[EventType2["TOUCH"] = 7] = "TOUCH"; | ||
EventType2[EventType2["WHEEL"] = 8] = "WHEEL"; | ||
return EventType2; | ||
})(EventType || {}); | ||
var MouseButton = /* @__PURE__ */ ((MouseButton2) => { | ||
MouseButton2[MouseButton2["NONE"] = 0] = "NONE"; | ||
MouseButton2[MouseButton2["PRIMARY"] = 1] = "PRIMARY"; | ||
MouseButton2[MouseButton2["SECONDARY"] = 2] = "SECONDARY"; | ||
MouseButton2[MouseButton2["MIDDLE"] = 4] = "MIDDLE"; | ||
return MouseButton2; | ||
})(MouseButton || {}); | ||
var PointerType = /* @__PURE__ */ ((PointerType2) => { | ||
PointerType2[PointerType2["MOUSE"] = 0] = "MOUSE"; | ||
PointerType2[PointerType2["PEN"] = 1] = "PEN"; | ||
PointerType2[PointerType2["TOUCH"] = 2] = "TOUCH"; | ||
return PointerType2; | ||
})(PointerType || {}); | ||
var WheelDeltaMode = /* @__PURE__ */ ((WheelDeltaMode2) => { | ||
WheelDeltaMode2[WheelDeltaMode2["PIXEL"] = 0] = "PIXEL"; | ||
WheelDeltaMode2[WheelDeltaMode2["LINE"] = 1] = "LINE"; | ||
WheelDeltaMode2[WheelDeltaMode2["PAGE"] = 2] = "PAGE"; | ||
return WheelDeltaMode2; | ||
})(WheelDeltaMode || {}); | ||
var KeyModifier = /* @__PURE__ */ ((KeyModifier2) => { | ||
KeyModifier2[KeyModifier2["SHIFT"] = 1] = "SHIFT"; | ||
KeyModifier2[KeyModifier2["CTRL"] = 2] = "CTRL"; | ||
KeyModifier2[KeyModifier2["ALT"] = 4] = "ALT"; | ||
KeyModifier2[KeyModifier2["META"] = 8] = "META"; | ||
return KeyModifier2; | ||
})(KeyModifier || {}); | ||
const $WindowInfo = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 16; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 16) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 16); | ||
}, | ||
get innerWidth() { | ||
return mem.u16[base >>> 1]; | ||
}, | ||
set innerWidth(x) { | ||
mem.u16[base >>> 1] = x; | ||
}, | ||
get innerHeight() { | ||
return mem.u16[base + 2 >>> 1]; | ||
}, | ||
set innerHeight(x) { | ||
mem.u16[base + 2 >>> 1] = x; | ||
}, | ||
get scrollX() { | ||
return mem.f32[base + 4 >>> 2]; | ||
}, | ||
set scrollX(x) { | ||
mem.f32[base + 4 >>> 2] = x; | ||
}, | ||
get scrollY() { | ||
return mem.f32[base + 8 >>> 2]; | ||
}, | ||
set scrollY(x) { | ||
mem.f32[base + 8 >>> 2] = x; | ||
}, | ||
get dpr() { | ||
return mem.u8[base + 12]; | ||
}, | ||
set dpr(x) { | ||
mem.u8[base + 12] = x; | ||
}, | ||
get fullscreen() { | ||
return mem.u8[base + 13]; | ||
}, | ||
set fullscreen(x) { | ||
mem.u8[base + 13] = x; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $DragEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[(base + 2) >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[(base + 2) >>> 1] = x; | ||
}, | ||
get isDataTransfer() { | ||
return mem.u8[(base + 4)]; | ||
}, | ||
set isDataTransfer(x) { | ||
mem.u8[(base + 4)] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 5)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 5)] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[(base + 6)]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[(base + 6)] = x; | ||
}, | ||
get button() { | ||
return mem.u8[(base + 7)]; | ||
}, | ||
set button(x) { | ||
mem.u8[(base + 7)] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = (e.target).getBoundingClientRect(); | ||
this.clientX = e.clientX - bounds.left; | ||
this.clientY = e.clientY - bounds.top; | ||
this.buttons = e.buttons; | ||
this.button = e.button; | ||
this.isDataTransfer = e.dataTransfer ? 1 : 0; | ||
} | ||
}; | ||
} | ||
const $DragEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[base + 2 >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[base + 2 >>> 1] = x; | ||
}, | ||
get isDataTransfer() { | ||
return mem.u8[base + 4]; | ||
}, | ||
set isDataTransfer(x) { | ||
mem.u8[base + 4] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 5]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 5] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[base + 6]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[base + 6] = x; | ||
}, | ||
get button() { | ||
return mem.u8[base + 7]; | ||
}, | ||
set button(x) { | ||
mem.u8[base + 7] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = e.target.getBoundingClientRect(); | ||
this.clientX = e.clientX - bounds.left; | ||
this.clientY = e.clientY - bounds.top; | ||
this.buttons = e.buttons; | ||
this.button = e.button; | ||
this.isDataTransfer = e.dataTransfer ? 1 : 0; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $InputEvent = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 12; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 12) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $value = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 12); | ||
}, | ||
get value() { | ||
return $value || ($value = new WasmStringPtr(mem, base, true)); | ||
}, | ||
get len() { | ||
return mem.u32[(base + 4) >>> 2]; | ||
}, | ||
set len(x) { | ||
mem.u32[(base + 4) >>> 2] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 8)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 8)] = x; | ||
}, | ||
fromEvent(e) { | ||
const el = e.target; | ||
const value = el.type === "checkbox" ? el.checked ? "on" : "off" : el.value; | ||
const slice = this.value.setAlloc(value); | ||
this.len = slice[1] - 1; | ||
return slice; | ||
} | ||
}; | ||
} | ||
const $InputEvent = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 12; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 12) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $value = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 12); | ||
}, | ||
get value() { | ||
return $value || ($value = new WasmStringPtr(mem, base, true)); | ||
}, | ||
get len() { | ||
return mem.u32[base + 4 >>> 2]; | ||
}, | ||
set len(x) { | ||
mem.u32[base + 4 >>> 2] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 8]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 8] = x; | ||
}, | ||
fromEvent(e) { | ||
const el = e.target; | ||
const value = el.type === "checkbox" ? el.checked ? "on" : "off" : el.value; | ||
const slice = this.value.setAlloc(value); | ||
this.len = slice[1] - 1; | ||
return slice; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $KeyEvent = (mem) => ({ | ||
get align() { | ||
return 1; | ||
}, | ||
get size() { | ||
return 19; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 19) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 19); | ||
}, | ||
get key() { | ||
const addr = base; | ||
return mem.u8.subarray(addr, addr + 15); | ||
}, | ||
get len() { | ||
return mem.u8[(base + 16)]; | ||
}, | ||
set len(x) { | ||
mem.u8[(base + 16)] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 17)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 17)] = x; | ||
}, | ||
get repeat() { | ||
return mem.u8[(base + 18)]; | ||
}, | ||
set repeat(x) { | ||
mem.u8[(base + 18)] = x; | ||
}, | ||
fromEvent(e) { | ||
this.len = mem.setString(e.key, this.key.byteOffset, 16, true); | ||
} | ||
}; | ||
} | ||
const $KeyEvent = (mem) => ({ | ||
get align() { | ||
return 1; | ||
}, | ||
get size() { | ||
return 19; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 19) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 19); | ||
}, | ||
get key() { | ||
const addr = base; | ||
return mem.u8.subarray(addr, addr + 15); | ||
}, | ||
get len() { | ||
return mem.u8[base + 16]; | ||
}, | ||
set len(x) { | ||
mem.u8[base + 16] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 17]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 17] = x; | ||
}, | ||
get repeat() { | ||
return mem.u8[base + 18]; | ||
}, | ||
set repeat(x) { | ||
mem.u8[base + 18] = x; | ||
}, | ||
fromEvent(e) { | ||
this.len = mem.setString(e.key, this.key.byteOffset, 16, true); | ||
} | ||
}; | ||
} | ||
}); | ||
export const $MouseEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[(base + 2) >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[(base + 2) >>> 1] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 4)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 4)] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[(base + 5)]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[(base + 5)] = x; | ||
}, | ||
get button() { | ||
return mem.u8[(base + 6)]; | ||
}, | ||
set button(x) { | ||
mem.u8[(base + 6)] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = (e.target).getBoundingClientRect(); | ||
this.clientX = e.clientX - bounds.left; | ||
this.clientY = e.clientY - bounds.top; | ||
this.buttons = e.buttons; | ||
this.button = e.button; | ||
} | ||
}; | ||
} | ||
const $MouseEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[base + 2 >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[base + 2 >>> 1] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 4]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 4] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[base + 5]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[base + 5] = x; | ||
}, | ||
get button() { | ||
return mem.u8[base + 6]; | ||
}, | ||
set button(x) { | ||
mem.u8[base + 6] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = e.target.getBoundingClientRect(); | ||
this.clientX = e.clientX - bounds.left; | ||
this.clientY = e.clientY - bounds.top; | ||
this.buttons = e.buttons; | ||
this.button = e.button; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $PointerEvent = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 24; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 24) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 24); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[(base + 2) >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[(base + 2) >>> 1] = x; | ||
}, | ||
get id() { | ||
return mem.u32[(base + 4) >>> 2]; | ||
}, | ||
set id(x) { | ||
mem.u32[(base + 4) >>> 2] = x; | ||
}, | ||
get pressure() { | ||
return mem.f32[(base + 8) >>> 2]; | ||
}, | ||
set pressure(x) { | ||
mem.f32[(base + 8) >>> 2] = x; | ||
}, | ||
get tiltX() { | ||
return mem.i8[(base + 12)]; | ||
}, | ||
set tiltX(x) { | ||
mem.i8[(base + 12)] = x; | ||
}, | ||
get tiltY() { | ||
return mem.i8[(base + 13)]; | ||
}, | ||
set tiltY(x) { | ||
mem.i8[(base + 13)] = x; | ||
}, | ||
get twist() { | ||
return mem.u16[(base + 14) >>> 1]; | ||
}, | ||
set twist(x) { | ||
mem.u16[(base + 14) >>> 1] = x; | ||
}, | ||
get pointerType() { | ||
return mem.u8[(base + 16)]; | ||
}, | ||
set pointerType(x) { | ||
mem.u8[(base + 16)] = x; | ||
}, | ||
get isPrimary() { | ||
return mem.u8[(base + 17)]; | ||
}, | ||
set isPrimary(x) { | ||
mem.u8[(base + 17)] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 18)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 18)] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[(base + 19)]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[(base + 19)] = x; | ||
}, | ||
get button() { | ||
return mem.u8[(base + 20)]; | ||
}, | ||
set button(x) { | ||
mem.u8[(base + 20)] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = (e.target).getBoundingClientRect(); | ||
this.clientX = e.clientX - bounds.left; | ||
this.clientY = e.clientY - bounds.top; | ||
this.tiltX = e.tiltX; | ||
this.tiltY = e.tiltY; | ||
this.twist = e.twist; | ||
this.isPrimary = ~~e.isPrimary; | ||
this.pointerType = PointerType[e.pointerType.toUpperCase()]; | ||
this.buttons = e.buttons; | ||
this.button = e.button; | ||
} | ||
}; | ||
} | ||
const $PointerEvent = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 24; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 24) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 24); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[base + 2 >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[base + 2 >>> 1] = x; | ||
}, | ||
get id() { | ||
return mem.u32[base + 4 >>> 2]; | ||
}, | ||
set id(x) { | ||
mem.u32[base + 4 >>> 2] = x; | ||
}, | ||
get pressure() { | ||
return mem.f32[base + 8 >>> 2]; | ||
}, | ||
set pressure(x) { | ||
mem.f32[base + 8 >>> 2] = x; | ||
}, | ||
get tiltX() { | ||
return mem.i8[base + 12]; | ||
}, | ||
set tiltX(x) { | ||
mem.i8[base + 12] = x; | ||
}, | ||
get tiltY() { | ||
return mem.i8[base + 13]; | ||
}, | ||
set tiltY(x) { | ||
mem.i8[base + 13] = x; | ||
}, | ||
get twist() { | ||
return mem.u16[base + 14 >>> 1]; | ||
}, | ||
set twist(x) { | ||
mem.u16[base + 14 >>> 1] = x; | ||
}, | ||
get pointerType() { | ||
return mem.u8[base + 16]; | ||
}, | ||
set pointerType(x) { | ||
mem.u8[base + 16] = x; | ||
}, | ||
get isPrimary() { | ||
return mem.u8[base + 17]; | ||
}, | ||
set isPrimary(x) { | ||
mem.u8[base + 17] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 18]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 18] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[base + 19]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[base + 19] = x; | ||
}, | ||
get button() { | ||
return mem.u8[base + 20]; | ||
}, | ||
set button(x) { | ||
mem.u8[base + 20] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = e.target.getBoundingClientRect(); | ||
this.clientX = e.clientX - bounds.left; | ||
this.clientY = e.clientY - bounds.top; | ||
this.tiltX = e.tiltX; | ||
this.tiltY = e.tiltY; | ||
this.twist = e.twist; | ||
this.isPrimary = ~~e.isPrimary; | ||
this.pointerType = PointerType[e.pointerType.toUpperCase()]; | ||
this.buttons = e.buttons; | ||
this.button = e.button; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $ScrollEvent = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get scrollX() { | ||
return mem.f32[base >>> 2]; | ||
}, | ||
set scrollX(x) { | ||
mem.f32[base >>> 2] = x; | ||
}, | ||
get scrollY() { | ||
return mem.f32[(base + 4) >>> 2]; | ||
}, | ||
set scrollY(x) { | ||
mem.f32[(base + 4) >>> 2] = x; | ||
}, | ||
fromEvent(e) { | ||
const target = (e.target.scrollTop != null ? e.target : document.scrollingElement); | ||
this.scrollX = target.scrollLeft || 0; | ||
this.scrollY = target.scrollTop || 0; | ||
} | ||
}; | ||
} | ||
const $ScrollEvent = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get scrollX() { | ||
return mem.f32[base >>> 2]; | ||
}, | ||
set scrollX(x) { | ||
mem.f32[base >>> 2] = x; | ||
}, | ||
get scrollY() { | ||
return mem.f32[base + 4 >>> 2]; | ||
}, | ||
set scrollY(x) { | ||
mem.f32[base + 4 >>> 2] = x; | ||
}, | ||
fromEvent(e) { | ||
const target = e.target.scrollTop != null ? e.target : document.scrollingElement; | ||
this.scrollX = target.scrollLeft || 0; | ||
this.scrollY = target.scrollTop || 0; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $TouchEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 6; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 6) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 6); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[(base + 2) >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[(base + 2) >>> 1] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 4)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 4)] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = (e.target).getBoundingClientRect(); | ||
this.clientX = e.touches[0].clientX - bounds.left; | ||
this.clientY = e.touches[0].clientY - bounds.top; | ||
} | ||
}; | ||
} | ||
const $TouchEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 6; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 6) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 6); | ||
}, | ||
get clientX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set clientX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get clientY() { | ||
return mem.i16[base + 2 >>> 1]; | ||
}, | ||
set clientY(x) { | ||
mem.i16[base + 2 >>> 1] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 4]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 4] = x; | ||
}, | ||
fromEvent(e) { | ||
const bounds = e.target.getBoundingClientRect(); | ||
this.clientX = e.touches[0].clientX - bounds.left; | ||
this.clientY = e.touches[0].clientY - bounds.top; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $WheelEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 10; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 10) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 10); | ||
}, | ||
get deltaX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set deltaX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get deltaY() { | ||
return mem.i16[(base + 2) >>> 1]; | ||
}, | ||
set deltaY(x) { | ||
mem.i16[(base + 2) >>> 1] = x; | ||
}, | ||
get deltaZ() { | ||
return mem.i16[(base + 4) >>> 1]; | ||
}, | ||
set deltaZ(x) { | ||
mem.i16[(base + 4) >>> 1] = x; | ||
}, | ||
get mode() { | ||
return mem.u8[(base + 6)]; | ||
}, | ||
set mode(x) { | ||
mem.u8[(base + 6)] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[(base + 7)]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[(base + 7)] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[(base + 8)]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[(base + 8)] = x; | ||
}, | ||
fromEvent(e) { | ||
this.deltaX = e.deltaX; | ||
this.deltaY = e.deltaY; | ||
this.deltaZ = e.deltaZ; | ||
this.mode = e.deltaMode; | ||
this.buttons = e.buttons; | ||
} | ||
}; | ||
} | ||
const $WheelEvent = (mem) => ({ | ||
get align() { | ||
return 2; | ||
}, | ||
get size() { | ||
return 10; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 10) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 10); | ||
}, | ||
get deltaX() { | ||
return mem.i16[base >>> 1]; | ||
}, | ||
set deltaX(x) { | ||
mem.i16[base >>> 1] = x; | ||
}, | ||
get deltaY() { | ||
return mem.i16[base + 2 >>> 1]; | ||
}, | ||
set deltaY(x) { | ||
mem.i16[base + 2 >>> 1] = x; | ||
}, | ||
get deltaZ() { | ||
return mem.i16[base + 4 >>> 1]; | ||
}, | ||
set deltaZ(x) { | ||
mem.i16[base + 4 >>> 1] = x; | ||
}, | ||
get mode() { | ||
return mem.u8[base + 6]; | ||
}, | ||
set mode(x) { | ||
mem.u8[base + 6] = x; | ||
}, | ||
get modifiers() { | ||
return mem.u8[base + 7]; | ||
}, | ||
set modifiers(x) { | ||
mem.u8[base + 7] = x; | ||
}, | ||
get buttons() { | ||
return mem.u8[base + 8]; | ||
}, | ||
set buttons(x) { | ||
mem.u8[base + 8] = x; | ||
}, | ||
fromEvent(e) { | ||
this.deltaX = e.deltaX; | ||
this.deltaY = e.deltaY; | ||
this.deltaZ = e.deltaZ; | ||
this.mode = e.deltaMode; | ||
this.buttons = e.buttons; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $EventBody = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 24; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 24) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 24); | ||
}, | ||
get drag() { | ||
return $DragEvent(mem).instance(base); | ||
}, | ||
set drag(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get input() { | ||
return $InputEvent(mem).instance(base); | ||
}, | ||
set input(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get key() { | ||
return $KeyEvent(mem).instance(base); | ||
}, | ||
set key(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get mouse() { | ||
return $MouseEvent(mem).instance(base); | ||
}, | ||
set mouse(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get pointer() { | ||
return $PointerEvent(mem).instance(base); | ||
}, | ||
set pointer(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get scroll() { | ||
return $ScrollEvent(mem).instance(base); | ||
}, | ||
set scroll(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get touch() { | ||
return $TouchEvent(mem).instance(base); | ||
}, | ||
set touch(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get wheel() { | ||
return $WheelEvent(mem).instance(base); | ||
}, | ||
set wheel(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
}; | ||
} | ||
const $EventBody = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 24; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 24) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 24); | ||
}, | ||
get drag() { | ||
return $DragEvent(mem).instance(base); | ||
}, | ||
set drag(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get input() { | ||
return $InputEvent(mem).instance(base); | ||
}, | ||
set input(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get key() { | ||
return $KeyEvent(mem).instance(base); | ||
}, | ||
set key(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get mouse() { | ||
return $MouseEvent(mem).instance(base); | ||
}, | ||
set mouse(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get pointer() { | ||
return $PointerEvent(mem).instance(base); | ||
}, | ||
set pointer(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get scroll() { | ||
return $ScrollEvent(mem).instance(base); | ||
}, | ||
set scroll(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get touch() { | ||
return $TouchEvent(mem).instance(base); | ||
}, | ||
set touch(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get wheel() { | ||
return $WheelEvent(mem).instance(base); | ||
}, | ||
set wheel(x) { | ||
mem.u8.set(x.__bytes, base); | ||
} | ||
}; | ||
} | ||
}); | ||
export const $Event = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 32; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 32) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 32); | ||
}, | ||
get id() { | ||
return mem.i32[base >>> 2]; | ||
}, | ||
set id(x) { | ||
mem.i32[base >>> 2] = x; | ||
}, | ||
get target() { | ||
return mem.i32[(base + 4) >>> 2]; | ||
}, | ||
set target(x) { | ||
mem.i32[(base + 4) >>> 2] = x; | ||
}, | ||
get body() { | ||
return $EventBody(mem).instance((base + 8)); | ||
}, | ||
set body(x) { | ||
mem.u8.set(x.__bytes, (base + 8)); | ||
}, | ||
}; | ||
} | ||
const $Event = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 32; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 32) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 32); | ||
}, | ||
get id() { | ||
return mem.i32[base >>> 2]; | ||
}, | ||
set id(x) { | ||
mem.i32[base >>> 2] = x; | ||
}, | ||
get target() { | ||
return mem.i32[base + 4 >>> 2]; | ||
}, | ||
set target(x) { | ||
mem.i32[base + 4 >>> 2] = x; | ||
}, | ||
get body() { | ||
return $EventBody(mem).instance(base + 8); | ||
}, | ||
set body(x) { | ||
mem.u8.set(x.__bytes, base + 8); | ||
} | ||
}; | ||
} | ||
}); | ||
export const $EventListener = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get callback() { | ||
return mem.u32[base >>> 2]; | ||
}, | ||
set callback(x) { | ||
mem.u32[base >>> 2] = x; | ||
}, | ||
get ctx() { | ||
return mem.u32[(base + 4) >>> 2]; | ||
}, | ||
set ctx(x) { | ||
mem.u32[(base + 4) >>> 2] = x; | ||
}, | ||
}; | ||
} | ||
const $EventListener = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get callback() { | ||
return mem.u32[base >>> 2]; | ||
}, | ||
set callback(x) { | ||
mem.u32[base >>> 2] = x; | ||
}, | ||
get ctx() { | ||
return mem.u32[base + 4 >>> 2]; | ||
}, | ||
set ctx(x) { | ||
mem.u32[base + 4 >>> 2] = x; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $CreateElementOpts = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 48; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 48) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $tag = null; | ||
let $ns = null; | ||
let $id = null; | ||
let $class = null; | ||
let $text = null; | ||
let $html = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 48); | ||
}, | ||
get tag() { | ||
return $tag || ($tag = new WasmStringPtr(mem, base, true)); | ||
}, | ||
get ns() { | ||
return $ns || ($ns = new WasmStringPtr(mem, (base + 4), true)); | ||
}, | ||
get id() { | ||
return $id || ($id = new WasmStringPtr(mem, (base + 8), true)); | ||
}, | ||
get class() { | ||
return $class || ($class = new WasmStringPtr(mem, (base + 12), true)); | ||
}, | ||
get text() { | ||
return $text || ($text = new WasmStringPtr(mem, (base + 16), true)); | ||
}, | ||
get html() { | ||
return $html || ($html = new WasmStringPtr(mem, (base + 20), true)); | ||
}, | ||
get parent() { | ||
return mem.i32[(base + 24) >>> 2]; | ||
}, | ||
set parent(x) { | ||
mem.i32[(base + 24) >>> 2] = x; | ||
}, | ||
get index() { | ||
return mem.i32[(base + 28) >>> 2]; | ||
}, | ||
set index(x) { | ||
mem.i32[(base + 28) >>> 2] = x; | ||
}, | ||
get children() { | ||
const addr = mem.u32[(base + 32) >>> 2]; | ||
const len = mem.u32[(base + 36) >>> 2]; | ||
const inst = $CreateElementOpts(mem); | ||
const buf = []; | ||
for (let i = 0; i < len; i++) | ||
buf.push(inst.instance(addr + i * 48)); | ||
return buf; | ||
}, | ||
get attribs() { | ||
const addr = mem.u32[(base + 40) >>> 2]; | ||
const len = mem.u32[(base + 44) >>> 2]; | ||
const inst = $Attrib(mem); | ||
const buf = []; | ||
for (let i = 0; i < len; i++) | ||
buf.push(inst.instance(addr + i * 24)); | ||
return buf; | ||
}, | ||
}; | ||
} | ||
const $CreateElementOpts = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 48; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 48) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $tag = null; | ||
let $ns = null; | ||
let $id = null; | ||
let $class = null; | ||
let $text = null; | ||
let $html = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 48); | ||
}, | ||
get tag() { | ||
return $tag || ($tag = new WasmStringPtr(mem, base, true)); | ||
}, | ||
get ns() { | ||
return $ns || ($ns = new WasmStringPtr(mem, base + 4, true)); | ||
}, | ||
get id() { | ||
return $id || ($id = new WasmStringPtr(mem, base + 8, true)); | ||
}, | ||
get class() { | ||
return $class || ($class = new WasmStringPtr(mem, base + 12, true)); | ||
}, | ||
get text() { | ||
return $text || ($text = new WasmStringPtr(mem, base + 16, true)); | ||
}, | ||
get html() { | ||
return $html || ($html = new WasmStringPtr(mem, base + 20, true)); | ||
}, | ||
get parent() { | ||
return mem.i32[base + 24 >>> 2]; | ||
}, | ||
set parent(x) { | ||
mem.i32[base + 24 >>> 2] = x; | ||
}, | ||
get index() { | ||
return mem.i32[base + 28 >>> 2]; | ||
}, | ||
set index(x) { | ||
mem.i32[base + 28 >>> 2] = x; | ||
}, | ||
get children() { | ||
const addr = mem.u32[base + 32 >>> 2]; | ||
const len = mem.u32[base + 36 >>> 2]; | ||
const inst = $CreateElementOpts(mem); | ||
const buf = []; | ||
for (let i = 0; i < len; i++) | ||
buf.push(inst.instance(addr + i * 48)); | ||
return buf; | ||
}, | ||
get attribs() { | ||
const addr = mem.u32[base + 40 >>> 2]; | ||
const len = mem.u32[base + 44 >>> 2]; | ||
const inst = $Attrib(mem); | ||
const buf = []; | ||
for (let i = 0; i < len; i++) | ||
buf.push(inst.instance(addr + i * 24)); | ||
return buf; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $CreateCanvasOpts = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 32; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 32) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $id = null; | ||
let $class = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 32); | ||
}, | ||
get width() { | ||
return mem.u16[base >>> 1]; | ||
}, | ||
set width(x) { | ||
mem.u16[base >>> 1] = x; | ||
}, | ||
get height() { | ||
return mem.u16[(base + 2) >>> 1]; | ||
}, | ||
set height(x) { | ||
mem.u16[(base + 2) >>> 1] = x; | ||
}, | ||
get id() { | ||
return $id || ($id = new WasmStringPtr(mem, (base + 4), true)); | ||
}, | ||
get class() { | ||
return $class || ($class = new WasmStringPtr(mem, (base + 8), true)); | ||
}, | ||
get parent() { | ||
return mem.i32[(base + 12) >>> 2]; | ||
}, | ||
set parent(x) { | ||
mem.i32[(base + 12) >>> 2] = x; | ||
}, | ||
get index() { | ||
return mem.i32[(base + 16) >>> 2]; | ||
}, | ||
set index(x) { | ||
mem.i32[(base + 16) >>> 2] = x; | ||
}, | ||
get dpr() { | ||
return mem.u8[(base + 20)]; | ||
}, | ||
set dpr(x) { | ||
mem.u8[(base + 20)] = x; | ||
}, | ||
get attribs() { | ||
const addr = mem.u32[(base + 24) >>> 2]; | ||
const len = mem.u32[(base + 28) >>> 2]; | ||
const inst = $Attrib(mem); | ||
const buf = []; | ||
for (let i = 0; i < len; i++) | ||
buf.push(inst.instance(addr + i * 24)); | ||
return buf; | ||
}, | ||
}; | ||
} | ||
const $CreateCanvasOpts = (mem) => ({ | ||
get align() { | ||
return 4; | ||
}, | ||
get size() { | ||
return 32; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 32) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $id = null; | ||
let $class = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 32); | ||
}, | ||
get width() { | ||
return mem.u16[base >>> 1]; | ||
}, | ||
set width(x) { | ||
mem.u16[base >>> 1] = x; | ||
}, | ||
get height() { | ||
return mem.u16[base + 2 >>> 1]; | ||
}, | ||
set height(x) { | ||
mem.u16[base + 2 >>> 1] = x; | ||
}, | ||
get id() { | ||
return $id || ($id = new WasmStringPtr(mem, base + 4, true)); | ||
}, | ||
get class() { | ||
return $class || ($class = new WasmStringPtr(mem, base + 8, true)); | ||
}, | ||
get parent() { | ||
return mem.i32[base + 12 >>> 2]; | ||
}, | ||
set parent(x) { | ||
mem.i32[base + 12 >>> 2] = x; | ||
}, | ||
get index() { | ||
return mem.i32[base + 16 >>> 2]; | ||
}, | ||
set index(x) { | ||
mem.i32[base + 16 >>> 2] = x; | ||
}, | ||
get dpr() { | ||
return mem.u8[base + 20]; | ||
}, | ||
set dpr(x) { | ||
mem.u8[base + 20] = x; | ||
}, | ||
get attribs() { | ||
const addr = mem.u32[base + 24 >>> 2]; | ||
const len = mem.u32[base + 28 >>> 2]; | ||
const inst = $Attrib(mem); | ||
const buf = []; | ||
for (let i = 0; i < len; i++) | ||
buf.push(inst.instance(addr + i * 24)); | ||
return buf; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $Attrib = (mem) => ({ | ||
get align() { | ||
return 8; | ||
}, | ||
get size() { | ||
return 24; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 24) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $name = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 24); | ||
}, | ||
get name() { | ||
return $name || ($name = new WasmStringPtr(mem, base, true)); | ||
}, | ||
get value() { | ||
return $AttribValue(mem).instance((base + 8)); | ||
}, | ||
set value(x) { | ||
mem.u8.set(x.__bytes, (base + 8)); | ||
}, | ||
get kind() { | ||
return mem.u8[(base + 16)]; | ||
}, | ||
set kind(x) { | ||
mem.u8[(base + 16)] = x; | ||
}, | ||
}; | ||
} | ||
const $Attrib = (mem) => ({ | ||
get align() { | ||
return 8; | ||
}, | ||
get size() { | ||
return 24; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 24) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $name = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 24); | ||
}, | ||
get name() { | ||
return $name || ($name = new WasmStringPtr(mem, base, true)); | ||
}, | ||
get value() { | ||
return $AttribValue(mem).instance(base + 8); | ||
}, | ||
set value(x) { | ||
mem.u8.set(x.__bytes, base + 8); | ||
}, | ||
get kind() { | ||
return mem.u8[base + 16]; | ||
}, | ||
set kind(x) { | ||
mem.u8[base + 16] = x; | ||
} | ||
}; | ||
} | ||
}); | ||
export const $AttribValue = (mem) => ({ | ||
get align() { | ||
return 8; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $str = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get event() { | ||
return $EventListener(mem).instance(base); | ||
}, | ||
set event(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get flag() { | ||
return mem.u8[base]; | ||
}, | ||
set flag(x) { | ||
mem.u8[base] = x; | ||
}, | ||
get num() { | ||
return mem.f64[base >>> 3]; | ||
}, | ||
set num(x) { | ||
mem.f64[base >>> 3] = x; | ||
}, | ||
get str() { | ||
return $str || ($str = new WasmStringPtr(mem, base, true)); | ||
}, | ||
}; | ||
} | ||
const $AttribValue = (mem) => ({ | ||
get align() { | ||
return 8; | ||
}, | ||
get size() { | ||
return 8; | ||
}, | ||
instanceArray(base, num) { | ||
const items = []; | ||
for (; num-- > 0; base += 8) | ||
items.push(this.instance(base)); | ||
return items; | ||
}, | ||
instance: (base) => { | ||
let $str = null; | ||
return { | ||
get __base() { | ||
return base; | ||
}, | ||
get __bytes() { | ||
return mem.u8.subarray(base, base + 8); | ||
}, | ||
get event() { | ||
return $EventListener(mem).instance(base); | ||
}, | ||
set event(x) { | ||
mem.u8.set(x.__bytes, base); | ||
}, | ||
get flag() { | ||
return mem.u8[base]; | ||
}, | ||
set flag(x) { | ||
mem.u8[base] = x; | ||
}, | ||
get num() { | ||
return mem.f64[base >>> 3]; | ||
}, | ||
set num(x) { | ||
mem.f64[base >>> 3] = x; | ||
}, | ||
get str() { | ||
return $str || ($str = new WasmStringPtr(mem, base, true)); | ||
} | ||
}; | ||
} | ||
}); | ||
export var AttribType; | ||
(function (AttribType) { | ||
AttribType[AttribType["EVENT"] = 0] = "EVENT"; | ||
AttribType[AttribType["FLAG"] = 1] = "FLAG"; | ||
AttribType[AttribType["NUM"] = 2] = "NUM"; | ||
AttribType[AttribType["STR"] = 3] = "STR"; | ||
})(AttribType || (AttribType = {})); | ||
var AttribType = /* @__PURE__ */ ((AttribType2) => { | ||
AttribType2[AttribType2["EVENT"] = 0] = "EVENT"; | ||
AttribType2[AttribType2["FLAG"] = 1] = "FLAG"; | ||
AttribType2[AttribType2["NUM"] = 2] = "NUM"; | ||
AttribType2[AttribType2["STR"] = 3] = "STR"; | ||
return AttribType2; | ||
})(AttribType || {}); | ||
export { | ||
$Attrib, | ||
$AttribValue, | ||
$CreateCanvasOpts, | ||
$CreateElementOpts, | ||
$DragEvent, | ||
$Event, | ||
$EventBody, | ||
$EventListener, | ||
$InputEvent, | ||
$KeyEvent, | ||
$MouseEvent, | ||
$PointerEvent, | ||
$ScrollEvent, | ||
$TouchEvent, | ||
$WheelEvent, | ||
$WindowInfo, | ||
AttribType, | ||
EventType, | ||
KeyModifier, | ||
MouseButton, | ||
PointerType, | ||
WheelDeltaMode | ||
}; |
{ | ||
"name": "@thi.ng/wasm-api-dom", | ||
"version": "0.11.53", | ||
"version": "0.11.54", | ||
"description": "Browser DOM bridge API for hybrid TypeScript & WASM (Zig) applications", | ||
@@ -30,3 +30,5 @@ "type": "module", | ||
"scripts": { | ||
"build": "yarn clean && tsc --declaration", | ||
"build": "yarn build:esbuild && yarn build:decl", | ||
"build:decl": "tsc --declaration --emitDeclarationOnly", | ||
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts", | ||
"build:types": "npx wasm-api-bindgen -a analytics.json --config src/typedefs-config.json --lang ts -o src/generated/api.ts --lang zig -o zig/api.zig src/typedefs.json", | ||
@@ -41,11 +43,12 @@ "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc generated", | ||
"dependencies": { | ||
"@thi.ng/adapt-dpi": "^2.2.27", | ||
"@thi.ng/api": "^8.9.11", | ||
"@thi.ng/errors": "^2.4.5", | ||
"@thi.ng/prefixes": "^2.2.7", | ||
"@thi.ng/wasm-api": "^1.4.36" | ||
"@thi.ng/adapt-dpi": "^2.2.28", | ||
"@thi.ng/api": "^8.9.12", | ||
"@thi.ng/errors": "^2.4.6", | ||
"@thi.ng/prefixes": "^2.2.8", | ||
"@thi.ng/wasm-api": "^1.4.37" | ||
}, | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.38.3", | ||
"@thi.ng/wasm-api-bindgen": "^0.4.32", | ||
"@thi.ng/wasm-api-bindgen": "^0.4.33", | ||
"esbuild": "^0.19.8", | ||
"rimraf": "^5.0.5", | ||
@@ -104,3 +107,3 @@ "tools": "^0.0.1", | ||
}, | ||
"gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n" | ||
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n" | ||
} |
@@ -300,3 +300,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (brotli'd, pre-treeshake): ESM: 4.27 KB | ||
Package sizes (brotli'd, pre-treeshake): ESM: 4.26 KB | ||
@@ -303,0 +303,0 @@ ## Dependencies |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2181
116864
7
Updated@thi.ng/adapt-dpi@^2.2.28
Updated@thi.ng/api@^8.9.12
Updated@thi.ng/errors@^2.4.6
Updated@thi.ng/prefixes@^2.2.8
Updated@thi.ng/wasm-api@^1.4.37