Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Skipped
63 lines
1.3 KiB
Plaintext
63 lines
1.3 KiB
Plaintext
import type { SerovalNode } from 'seroval';
|
|
import { createPlugin } from 'seroval';
|
|
|
|
function createEventOptions(current: Event): EventInit {
|
|
return {
|
|
bubbles: current.bubbles,
|
|
cancelable: current.cancelable,
|
|
composed: current.composed,
|
|
};
|
|
}
|
|
|
|
type EventNode = {
|
|
type: SerovalNode;
|
|
options: SerovalNode;
|
|
};
|
|
|
|
const EventPlugin = /* @__PURE__ */ createPlugin<Event, EventNode>({
|
|
tag: 'seroval-plugins/web/Event',
|
|
test(value) {
|
|
if (typeof Event === 'undefined') {
|
|
return false;
|
|
}
|
|
return value instanceof Event;
|
|
},
|
|
parse: {
|
|
sync(value, ctx) {
|
|
return {
|
|
type: ctx.parse(value.type),
|
|
options: ctx.parse(createEventOptions(value)),
|
|
};
|
|
},
|
|
async async(value, ctx) {
|
|
return {
|
|
type: await ctx.parse(value.type),
|
|
options: await ctx.parse(createEventOptions(value)),
|
|
};
|
|
},
|
|
stream(value, ctx) {
|
|
return {
|
|
type: ctx.parse(value.type),
|
|
options: ctx.parse(createEventOptions(value)),
|
|
};
|
|
},
|
|
},
|
|
serialize(node, ctx) {
|
|
return (
|
|
'new Event(' +
|
|
ctx.serialize(node.type) +
|
|
',' +
|
|
ctx.serialize(node.options) +
|
|
')'
|
|
);
|
|
},
|
|
deserialize(node, ctx) {
|
|
return new Event(
|
|
ctx.deserialize(node.type) as string,
|
|
ctx.deserialize(node.options) as EventInit,
|
|
);
|
|
},
|
|
});
|
|
|
|
export default EventPlugin;
|