import { DOMEventHandlerKeys } from "./dom.js"; export type NoTypeFor = null; export type TypeForJsx = 1; export type TypeForInstance = 2; export type EventInit = CustomEventInit & { type: string; base?: typeof CustomEvent | typeof Event; }; /** * Interface to fill in unknown properties like any | null | undefined */ export interface FillObject { [index: string]: any; } export type FillArray = any[]; export type FillFunction = (...args: any[]) => any; export type FillPromise = Promise; export type FillConstructor = abstract new (...args: any) => any; export type TypeToConstructor = type extends string ? StringConstructor : type extends number ? NumberConstructor : type extends boolean ? BooleanConstructor : type extends FillPromise ? PromiseConstructor : type extends symbol ? SymbolConstructor : type extends FillFunction ? FunctionConstructor : type extends FillArray ? ArrayConstructor : type extends FillObject ? ObjectConstructor : TypeAny; export type ConstructorType = T extends { meta?: infer Type; } ? Type : T extends NumberConstructor ? number : T extends StringConstructor ? string : T extends BooleanConstructor ? boolean : T extends TypeCustom ? TypeFor extends NoTypeFor ? ReturnType : TypeFor extends TypeForJsx ? TypeCustomGetValue : ReturnType : T extends FunctionConstructor ? FillFunction : T extends SymbolConstructor ? symbol : T extends PromiseConstructor ? FillPromise : T extends ArrayConstructor ? any[] : T extends ObjectConstructor ? FillObject : T extends FillConstructor ? InstanceType : any; type SchemaEvent = { event?: EventInit; }; type SchemaBase = SchemaEvent & { attr?: string; }; type SchemaReflect = SchemaBase & { reflect?: boolean; } & type; type SchemaProp = SchemaEvent & type; type SchemaOnlyPropWrapper = | SchemaProp<{ type: Constructor; }> | SchemaProp<{ type: Constructor; value: Type; }> | SchemaProp<{ type: Constructor; value: () => Type; }>; type SchemaReflectWrapper = | SchemaReflect<{ type: Constructor; }> | SchemaReflect<{ type: Constructor; value: Type; }> | SchemaReflect<{ type: Constructor; value: () => Type; }>; type SchemaAny = | SchemaReflect<{ value: Type; }> | SchemaReflect<{ value: () => Type; }> | SchemaReflect<{}>; type SchemaTypeCustom = | TypeCustom | SchemaReflectWrapper, any>; type TypeString = | StringConstructor | SchemaReflectWrapper; type TypeBoolean = | BooleanConstructor | SchemaReflectWrapper; type TypeNumber = | NumberConstructor | SchemaReflectWrapper; type TypePromise = | PromiseConstructor | SchemaOnlyPropWrapper; type TypeSymbol = | SymbolConstructor | SchemaOnlyPropWrapper; type TypeFunction = | FunctionConstructor | SchemaOnlyPropWrapper; type TypeArray = | ArrayConstructor | SchemaReflectWrapper; type TypeObject = | ObjectConstructor | SchemaReflectWrapper; type TypeAny = null | SchemaAny; type Self = typeof window; type SelfIgnore = | StringConstructor | NumberConstructor | BooleanConstructor | FunctionConstructor | ObjectConstructor | PromiseConstructor | SymbolConstructor | ArrayConstructor; type SafeGlobal = | "Event" | "URL" | "Range" | "Image" | "Crypto" | "File" | "Date" | "Set" | "Map" | "RegExp" | "Animation" | `${string}Event` | `Event${string}` | `Clipboard${string}` | `Animation${string}` | `Form${string}` | `Font${string}` | `DOM${string}` | `Touch${string}` | `Mutation${string}` | `Intersection${string}` | `Message${string}` | `HTML${string}` | `SVG${string}` | `Audio${string}` | `Document${string}` | `Weak${string}` | `CSS${string}` | `File${string}`; type SelfConstructors = Pick< Self, { [I in keyof Self]-?: I extends string ? I extends Capitalize ? Self[I] extends FillConstructor ? Self[I] extends SelfIgnore ? never : I extends SafeGlobal ? I : never : never : never : never; }[keyof Self] >; type SelfConstructorValues = { [I in keyof SelfConstructors]-?: SelfConstructors[I]; }[keyof SelfConstructors]; type TypeConstructor = | type | SchemaOnlyPropWrapper>; type TypesSelf = { [I in keyof SelfConstructors]-?: TypeConstructor; }[keyof SelfConstructors]; type TypesSelfValues = { [I in keyof SelfConstructors]-?: InstanceType; }[keyof SelfConstructors]; type GetTypeSelf = { [I in keyof SelfConstructors]-?: value extends InstanceType< SelfConstructors[I] > ? keyof value extends keyof InstanceType ? SelfConstructors[I] : never : never; }[keyof SelfConstructors]; type TypesDiscard = type extends FillFunction ? TypeFunction : type extends FillObject ? TypeObject : TypeAny; export type Type = type extends string ? TypeString : type extends number ? TypeNumber : type extends boolean ? TypeBoolean : type extends TypeCustom ? SchemaTypeCustom : type extends FillPromise ? TypePromise : type extends symbol ? TypeSymbol : type extends FillArray ? TypeArray : type extends DOMStringMap ? TypeObject : type extends TypesSelfValues ? GetTypeSelf extends never ? TypesDiscard : TypeConstructor> : TypesDiscard; export type SchemaInfer = Required< Omit< { [I in keyof Props]: Type; }, DOMEventHandlerKeys > >; export type TypeCustom = { name: "Custom"; map: Map; serialize?: (value: ReturnType) => string; }; export type TypeCustomGetValue = Parameters extends [infer First] ? First : undefined; export type Types = | Type | Type | Type | Type> | Type | Type | Type | Type | TypesSelf | Type | Type; export type SchemaProps = { [index: string]: Types; };