import type { EffectFn, Signal } from '../vendored/preact-core'; import type { SignalsRoot } from './signals'; export type OnRemovalFn = () => void; export declare enum PluginType { Attribute = 1, Watcher = 2, Action = 3 } export interface DatastarPlugin { type: PluginType; name: string; } export declare enum Requirement { Allowed = 0, Must = 1, Denied = 2, Exclusive = 3 } export interface DatastarSignalEvent { added: Array; removed: Array; updated: Array; } export declare const DATASTAR_SIGNAL_EVENT = "datastar-signals"; export interface CustomEventMap { [DATASTAR_SIGNAL_EVENT]: CustomEvent; } export type WatcherFn = (this: Document, ev: CustomEventMap[K]) => void; declare global { interface Document { dispatchEvent(ev: CustomEventMap[K]): void; addEventListener(type: K, listener: WatcherFn): void; removeEventListener(type: K, listener: WatcherFn): void; } } export interface AttributePlugin extends DatastarPlugin { type: PluginType.Attribute; onGlobalInit?: (ctx: InitContext) => void; onLoad: (ctx: RuntimeContext) => OnRemovalFn | void; keyReq?: Requirement; valReq?: Requirement; argNames?: string[]; } export interface WatcherPlugin extends DatastarPlugin { type: PluginType.Watcher; onGlobalInit?: (ctx: InitContext) => void; } export type ActionPlugins = Record; export type ActionMethod = (ctx: RuntimeContext, ...args: any[]) => any; export interface ActionPlugin extends DatastarPlugin { type: PluginType.Action; fn: ActionMethod; } export type GlobalInitializer = (ctx: InitContext) => void; export type InitContext = { plugin: DatastarPlugin; signals: SignalsRoot; effect: (fn: EffectFn) => OnRemovalFn; actions: Readonly; removals: Map>; applyToElement: (el: HTMLorSVGElement) => void; }; export type HTMLorSVGElement = Element & (HTMLElement | SVGElement); export type Modifiers = Map>; export type RuntimeContext = InitContext & { plugin: DatastarPlugin; el: HTMLorSVGElement; rawKey: Readonly; key: Readonly; value: Readonly; mods: Modifiers; genRX: () => (...args: any[]) => T; fnContent?: string; }; export type NestedValues = { [key: string]: NestedValues | any; }; export type NestedSignal = { [key: string]: NestedSignal | Signal; }; export type RuntimeExpressionFunction = (ctx: RuntimeContext, ...args: any[]) => any; export type EventCallbackHandler = (...args: any[]) => void;