import { DATASTAR_SIGNAL_PATCH_EVENT } from '@engine/consts' export type JSONPatch = Record & { length?: never } export type Paths = [string, any][] export type WatcherArgsValue = string | Element | DocumentFragment | undefined export type WatcherArgs = Record export type DatastarFetchEvent = { type: string el: HTMLOrSVG argsRaw: WatcherArgs } export type CustomEventMap = { [DATASTAR_SIGNAL_PATCH_EVENT]: CustomEvent } export type WatcherFn = ( this: Document, ev: CustomEventMap[K], ) => void export type ErrorFn = (name: string, ctx?: Record) => void export type ActionContext = { el: HTMLOrSVG evt?: Event error: ErrorFn cleanups: Map void> } export type RequirementType = 'allowed' | 'must' | 'denied' | 'exclusive' export type Requirement = | RequirementType | { key: Exclude value?: Exclude } | { key?: Exclude value: Exclude } type Rx = (...args: any[]) => B extends true ? unknown : void type ReqField = R extends | 'must' | { [P in K]: 'must' } ? Return : R extends 'denied' | { [P in K]: 'denied' } ? undefined : R extends | 'allowed' | { [P in K]: 'allowed' } | (K extends keyof R ? never : R) ? Return | undefined : never type ReqFields = R extends 'exclusive' ? | { key: string; value: undefined; rx: undefined } | { key: undefined; value: string; rx: Rx } : { key: ReqField value: ReqField rx: ReqField> } export type AttributeContext< R extends Requirement = Requirement, RxReturn extends boolean = boolean, > = { el: HTMLOrSVG mods: Modifiers rawKey: string evt?: Event error: ErrorFn loadedPluginNames: { actions: Readonly> attributes: Readonly> } } & ReqFields export type AttributePlugin< R extends Requirement = Requirement, RxReturn extends boolean = boolean, > = { name: string apply: (ctx: AttributeContext) => void | (() => void) requirement?: R returnsValue?: RxReturn argNames?: string[] } export type WatcherContext = { error: ErrorFn } // A plugin that runs on the global scope of the Datastar instance export type WatcherPlugin = { name: string apply: (ctx: WatcherContext, args: WatcherArgs) => void } export type ActionPlugins = Record export type ActionPlugin = { name: string // The name of the plugin apply: (ctx: ActionContext, ...args: any[]) => T } export type MergePatchArgs = { ifMissing?: boolean } export type HTMLOrSVG = HTMLElement | SVGElement | MathMLElement export type Modifiers = Map> // mod name -> tags 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