Files
SnowLuma/.pnpm-store/v11/files/69/b0483e1e8b9879a8a986004bc0111428a183b006b5c08d165cb1f3579682802a066cb50151d18107aef68aa4efd16b7211c2c779d1d72f6c3b71d8807b6c1c
T
TanTan 2a69b23b47
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) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

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;