Skip to content

Commit

Permalink
refactor(wasm-api-dom): update generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 22, 2022
1 parent f1eef25 commit 298f194
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
26 changes: 13 additions & 13 deletions packages/wasm-api-dom/src/generated/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by @thi.ng/wasm-api at 2022-11-15T05:49:10.956Z - DO NOT EDIT!
* Generated by @thi.ng/wasm-api at 2022-11-22T16:29:44.590Z - DO NOT EDIT!
*/

// @ts-ignore possibly includes unused imports
Expand Down Expand Up @@ -1192,20 +1192,20 @@ export const $CreateElementOpts: WasmTypeConstructor<CreateElementOpts> = (mem)
mem.i32[(base + 28) >>> 2] = x;
},
get children(): CreateElementOpts[] {
const len = mem.u32[(base + 36) >>> 2];
const addr = mem.u32[(base + 32) >>> 2];
const len = mem.u32[(base + 36) >>> 2];
const inst = $CreateElementOpts(mem);
const slice: CreateElementOpts[] = [];
for(let i = 0; i < len; i++) slice.push(inst.instance(addr + i * 48));
return slice;
const buf: CreateElementOpts[] = [];
for(let i = 0; i < len; i++) buf.push(inst.instance(addr + i * 48));
return buf;
},
get attribs(): Attrib[] {
const len = mem.u32[(base + 44) >>> 2];
const addr = mem.u32[(base + 40) >>> 2];
const len = mem.u32[(base + 44) >>> 2];
const inst = $Attrib(mem);
const slice: Attrib[] = [];
for(let i = 0; i < len; i++) slice.push(inst.instance(addr + i * 24));
return slice;
const buf: Attrib[] = [];
for(let i = 0; i < len; i++) buf.push(inst.instance(addr + i * 24));
return buf;
},
};
}
Expand Down Expand Up @@ -1316,12 +1316,12 @@ export const $CreateCanvasOpts: WasmTypeConstructor<CreateCanvasOpts> = (mem) =>
mem.u8[(base + 20)] = x;
},
get attribs(): Attrib[] {
const len = mem.u32[(base + 28) >>> 2];
const addr = mem.u32[(base + 24) >>> 2];
const len = mem.u32[(base + 28) >>> 2];
const inst = $Attrib(mem);
const slice: Attrib[] = [];
for(let i = 0; i < len; i++) slice.push(inst.instance(addr + i * 24));
return slice;
const buf: Attrib[] = [];
for(let i = 0; i < len; i++) buf.push(inst.instance(addr + i * 24));
return buf;
},
};
}
Expand Down
12 changes: 6 additions & 6 deletions packages/wasm-api-dom/src/typedefs-config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"zig": {
"pre": [
"/// Syntax sugar for: `CreateElementOptsSlice.wrap()`",
"pub inline fn children(items: []const CreateElementOpts) CreateElementOptsSlice {",
" return CreateElementOptsSlice.wrap(items);",
"/// Syntax sugar for: `ConstCreateElementOptsSlice.wrap()`",
"pub inline fn children(items: []const CreateElementOpts) ConstCreateElementOptsSlice {",
" return ConstCreateElementOptsSlice.wrap(items);",
"}",
"",
"/// Syntax sugar for: `AttribSlice.wrap()`",
"pub inline fn attribs(items: []const Attrib) AttribSlice {",
" return AttribSlice.wrap(items);",
"/// Syntax sugar for: `ConstAttribSlice.wrap()`",
"pub inline fn attribs(items: []const Attrib) ConstAttribSlice {",
" return ConstAttribSlice.wrap(items);",
"}"
]
}
Expand Down
58 changes: 29 additions & 29 deletions packages/wasm-api-dom/zig/api.zig
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//! Generated by @thi.ng/wasm-api at 2022-11-15T05:49:10.960Z - DO NOT EDIT!
//! Generated by @thi.ng/wasm-api at 2022-11-22T16:29:44.594Z - DO NOT EDIT!

const std = @import("std");
const wasm = @import("wasmapi");

pub const CreateElementOptsSlice = wasm.Slice([]const CreateElementOpts, [*]const CreateElementOpts);
pub const MutCreateElementOptsSlice = wasm.Slice([]CreateElementOpts, [*]CreateElementOpts);
pub const CreateElementOptsSlice = wasm.Slice([]CreateElementOpts, [*]CreateElementOpts);
pub const ConstCreateElementOptsSlice = wasm.Slice([]const CreateElementOpts, [*]const CreateElementOpts);

pub const AttribSlice = wasm.Slice([]const Attrib, [*]const Attrib);
pub const MutAttribSlice = wasm.Slice([]Attrib, [*]Attrib);
pub const AttribSlice = wasm.Slice([]Attrib, [*]Attrib);
pub const ConstAttribSlice = wasm.Slice([]const Attrib, [*]const Attrib);

/// Syntax sugar for: `CreateElementOptsSlice.wrap()`
pub inline fn children(items: []const CreateElementOpts) CreateElementOptsSlice {
return CreateElementOptsSlice.wrap(items);
/// Syntax sugar for: `ConstCreateElementOptsSlice.wrap()`
pub inline fn children(items: []const CreateElementOpts) ConstCreateElementOptsSlice {
return ConstCreateElementOptsSlice.wrap(items);
}

/// Syntax sugar for: `AttribSlice.wrap()`
pub inline fn attribs(items: []const Attrib) AttribSlice {
return AttribSlice.wrap(items);
/// Syntax sugar for: `ConstAttribSlice.wrap()`
pub inline fn attribs(items: []const Attrib) ConstAttribSlice {
return ConstAttribSlice.wrap(items);
}

pub const EventType = enum(i32) {
Expand Down Expand Up @@ -107,7 +107,7 @@ pub const InputEvent = extern struct {
/// Value of the targeted input element.
/// The memory is owned by the DOM API and will be freed immediately after the
/// event handler has returned.
value: wasm.StringPtr,
value: wasm.ConstStringPtr,
/// Length of the value string
len: u32,
/// Encoded bitmask of currently pressed modifier keys, see `KeyModifier` enum
Expand Down Expand Up @@ -252,10 +252,10 @@ pub const Event = extern struct {
body: EventBody,
};

pub const EventCallback = *const fn(event: *const Event, ctx: ?wasm.MutOpaquePtr) void;
pub const EventCallback = *const fn(event: *const Event, ctx: ?wasm.OpaquePtr) void;

/// Function signature for RAF (requestAnimationFrame) event handler
pub const RAFCallback = *const fn(time: f64, ctx: ?wasm.MutOpaquePtr) void;
pub const RAFCallback = *const fn(time: f64, ctx: ?wasm.OpaquePtr) void;

/// DOM event listener
pub const EventListener = extern struct {
Expand All @@ -267,7 +267,7 @@ pub const EventListener = extern struct {
/// cast back into the desired type using this form:
/// `@ptrCast(?*Foo, @alignCast(@alignOf(Foo), raw))`
/// Also see: `wasmapi.ptrCast()`
ctx: ?wasm.MutOpaquePtr = null,
ctx: ?wasm.OpaquePtr = null,
};

/// RAF event listener
Expand All @@ -280,36 +280,36 @@ pub const RAFListener = extern struct {
/// cast back into the desired type using this form:
/// `@ptrCast(?*Foo, @alignCast(@alignOf(Foo), raw))`
/// Also see: `wasmapi.ptrCast()`
ctx: ?wasm.MutOpaquePtr = null,
ctx: ?wasm.OpaquePtr = null,
};

/// Data structure used for declarative creation of DOM elements / trees (passed
/// to `createElement()`)
/// Also see `CreateCanvasOpts` for canvas specific use cases
pub const CreateElementOpts = extern struct {
/// DOM element name
tag: wasm.StringPtr,
tag: wasm.ConstStringPtr,
/// Namespace URI or wellknown registered alias (e.g. svg, xlink, xmlns)
ns: wasm.StringPtr = "",
ns: wasm.ConstStringPtr = "",
/// ID attrib
id: wasm.StringPtr = "",
id: wasm.ConstStringPtr = "",
/// Element class attrib
class: wasm.StringPtr = "",
class: wasm.ConstStringPtr = "",
/// Element inner text body
text: wasm.StringPtr = "",
text: wasm.ConstStringPtr = "",
/// Element inner HTML body
html: wasm.StringPtr = "",
html: wasm.ConstStringPtr = "",
/// Parent element ID. If >=0 the new element will be attached to that parent
/// element. Set to -1 to leave new element unattached (default unless nested)
parent: i32 = -1,
/// Insertion index for new element or -1 to append (default)
index: i32 = -1,
/// Optional slice of child element specs, which will be automatically attached
/// as children to this element (their `parent` ID will be ignored)
children: CreateElementOptsSlice = children(&[_]CreateElementOpts{}),
children: ConstCreateElementOptsSlice = children(&[_]CreateElementOpts{}),
/// Optional slice of attribute definitions for this element. Also see provided
/// `Attrib` factory functions for convenience.
attribs: AttribSlice = attribs(&[_]Attrib{}),
attribs: ConstAttribSlice = attribs(&[_]Attrib{}),
};

/// Data structure used for declarative creation of canvas elements (passed to
Expand All @@ -320,9 +320,9 @@ pub const CreateCanvasOpts = extern struct {
/// Canvas height (in CSS pixels)
height: u16,
/// Element ID attrib
id: wasm.StringPtr = "",
id: wasm.ConstStringPtr = "",
/// Element class attrib
class: wasm.StringPtr = "",
class: wasm.ConstStringPtr = "",
/// Same as CreateElementOpts.parent
parent: i32,
/// Same as CreateElementOpts.index
Expand All @@ -332,12 +332,12 @@ pub const CreateCanvasOpts = extern struct {
dpr: u8 = 1,
/// Optional slice of attribute definitions for this element. Also see provided
/// `Attrib` factory functions for convenience.
attribs: AttribSlice = attribs(&[_]Attrib{}),
attribs: ConstAttribSlice = attribs(&[_]Attrib{}),
};

/// DOM element attribute definition given as part of `CreateElementOpts`
pub const Attrib = extern struct {
name: wasm.StringPtr,
name: wasm.ConstStringPtr,
value: AttribValue,
kind: AttribType,

Expand All @@ -363,7 +363,7 @@ pub const AttribValue = extern union {
event: EventListener,
flag: u8,
num: f64,
str: wasm.StringPtr,
str: wasm.ConstStringPtr,
};

pub const AttribType = enum(u8) {
Expand Down

0 comments on commit 298f194

Please sign in to comment.