export type PluginType = 'attribute' | 'watcher' | 'action'; export type Requirement = 'allowed' | 'must' | 'denied' | 'exclusive'; export type OnRemovalFn = () => void; export type DatastarPlugin = AttributePlugin | WatcherPlugin | ActionPlugin; export declare const DATASTAR_SIGNAL_PATCH_EVENT = "datastar-signal-patch"; export type JSONPatch = Record; export interface CustomEventMap { [DATASTAR_SIGNAL_PATCH_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 type AttributePlugin = { type: 'attribute'; name: string; onGlobalInit?: (ctx: InitContext) => void; onLoad: (ctx: RuntimeContext) => OnRemovalFn | void; keyReq?: Requirement; valReq?: Requirement; returnsValue?: boolean; shouldEvaluate?: boolean; argNames?: string[]; }; export type WatcherPlugin = { type: 'watcher'; name: string; onGlobalInit?: (ctx: InitContext) => void; }; export type ActionPlugins = Record; export type ActionMethod = (ctx: RuntimeContext, ...args: any[]) => any; export type ActionPlugin = { type: 'action'; name: string; fn: ActionMethod; }; export type GlobalInitializer = (ctx: InitContext) => void; export type InitContext = { plugin: DatastarPlugin; actions: Readonly; root: Record; filtered: (opts?: SignalFilterOptions, obj?: JSONPatch) => Record; signal(initialValue?: T | undefined): Signal; computed(getter: (previousValue?: T) => T): Computed; effect(fn: (...args: any[]) => void): OnRemovalFn; mergePatch: (patch: any, args?: { ifMissing?: boolean; }) => any; peek: (fn: () => T) => T; getPath: (path: string) => T | undefined; startBatch: () => void; endBatch: () => void; initErr: (reason: string, metadata?: object) => Error; }; export type HTMLOrSVG = Element & (HTMLElement | SVGElement); export type Modifiers = Map>; export type ReactiveExpressionFn = (...argsThenDeps: any[]) => T; export type RuntimeContext = InitContext & { el: HTMLOrSVG; rawKey: Readonly; key: Readonly; value: Readonly; mods: Modifiers; rx: ReactiveExpressionFn; fnContent?: string; evt?: Event; runtimeErr: (reason: string, metadata?: object) => Error; }; export type RuntimeExpressionFunction = (ctx: RuntimeContext, ...args: any[]) => any; export type EventCallbackHandler = (...args: any[]) => void; export type SignalFilter = RegExp; export type SignalFilterOptions = { include?: RegExp | string; exclude?: RegExp | string; }; export type Signal = { (): T; (value: T): boolean; }; export type Computed = () => T; export type Effect = () => void;