| null;
/**
* @private
*/
export declare type Props> = {
[K in keyof P]: Prop
;
};
/**
* @private
*/
export interface NormalizedProp extends PropInstance {
type: PropConstructor[] | null;
cast?: boolean;
}
/**
* @private
*/
export declare type NormalizedProps = {
[K in keyof T]: NormalizedProp ? V : any>;
};
/**
* @private
*/
export declare type PropsData = {
[K in keyof T]: T[K] extends NormalizedProp ? V : any;
};
export declare type RequiredKeys = {
[K in keyof T]: T[K] extends {
required: true;
} | {
default: any;
} ? K : never;
}[keyof T];
export declare type OptionalKeys = Exclude>;
export declare type InferPropType = T extends null | {
type: null;
} ? any : T extends typeof Object | {
type: typeof Object;
} ? {
[key: string]: any;
} : T extends Prop ? V : T;
/**
* @private
*/
export declare type ResolvePropTypes = {
[K in RequiredKeys]: InferPropType;
} & {
[K in OptionalKeys]?: InferPropType;
};
export declare type EmitsOptions = string[] | Record;
export declare type NormalizedEmitsOptions = Record;
export declare type EmitsValidator = (...args: any[]) => boolean;
/**
* Setup function result type
*/
export declare type SetupResult = () => Template | Node;
/**
* @private
*/
export interface ComponentOptions> {
name: string;
props?: P;
setup(this: void, props: T, ctx: SetupContext): SetupResult | Promise;
styles?: StyleSheet | StyleSheet[];
directives?: Record;
emits?: EmitsOptions;
}
/**
* @private
*/
export interface NormalizedComponentOptions extends Omit, "props" | "emits"> {
props: NormalizedProps;
styles: StyleSheet[];
emits: NormalizedEmitsOptions;
tag: string;
attrs: Record;
hooks?: Record;
attributes: string[];
filename?: string;
}
/**
* @private
*/
export interface SetupContext {
readonly el: IComponent;
readonly attrs: Record;
/**
* Dispatches an event from the host Component
* @param event Event to emit
*/
emit(event: string, ...args: any[]): void;
}
/**
* @private
*/
export interface ComponentInstance {
readonly hooks: Record>;
readonly effect: ReactiveEffect;
readonly root: ComponentInstance;
readonly el: IComponent;
readonly parent: ComponentInstance;
readonly props: PropsData;
readonly setupResult: Promise | SetupResult;
readonly shadowRoot: ShadowRoot;
readonly provides: Record;
readonly directives?: Record;
readonly emitted?: Record;
readonly events: Record;
options: NormalizedComponentOptions;
/**
* Checks if the Component instance is currently mounted
* @returns If the Component is mounted
*/
mounted: boolean;
/**
* Binds event to element
* @param event - Event to bind
* @param listener - Function to run when event is fired
*/
on(event: string, listener: Function): void;
/**
* Binds event to element which is only called once
* @param event - Event to bind
* @param listener - Function to run when event is fired
*/
once(event: string, listener: Function): void;
/**
* Unbind event(s) from the element
* @param event - Event to unbind
* @param listener - Specific listener to unbind
*/
off(event: string, listener?: Function): void;
/**
* Dispatches an event to parent instance
* @param eventName - Event to emit
* @param detail - Custom event value
*/
emit(event: string, ...args: any[]): void;
/**
* Runs the setup function to collect dependencies and run logic
*/
setup(): void | Promise;
/**
* Provides a value for the instance
*/
provide(key: InjectionKey | string, value: T): void;
/**
* Reflows styles with shady shims or adopted stylesheets
* @param mount - True If mounting or false if updating
*/
reflowStyles(mount?: boolean): Promise;
/**
* Create shadow root and shim styles
*/
mount(): void;
/**
* Call unmounting lifecycle hooks
*/
unmount(): void;
/**
* Runs all the specified hooks on the Fx instance
* @param hook - Specified hook name
*/
runHooks(hook: string, ...args: any[]): void;
/**
* Adds a lifecycle hook to instance
*/
injectHook(name: string, hook: Function): void;
/**
* Renders shadow root content
*/
update(): void;
}
/**
* @private
*/
export interface IComponent extends HTMLElement {
/**
* Runs when mounted from DOM
*/
connectedCallback(): void;
/**
* Runs when unmounted from DOM
*/
disconnectedCallback(): void;
/**
* Observes attribute changes, triggers updates on props
*/
attributeChangedCallback(attr: string, oldValue: string, newValue: string): void;
}
/**
* Gets the current active component instance, or null if there is no active instance
* @returns The current active component instance or null if there isn't any
*/
export declare function getCurrentInstance(): ComponentInstance | null;
/**
* Sets the current active instance to the stack, if instance is null the last element is popped
* @param instance - Component instance to push to the stack
*/
export declare function setCurrentInstance(instance: ComponentInstance | null): void;
/**
* Normalizes the raw options object to a more predictable format
* @param options - Raw element options
* @returns The normalized options
* @private
*/
export declare function normalizeOptions(options: ComponentOptions): NormalizedComponentOptions;
/**
* Element to use custom elements functionality, as it required a class
*/
export declare class Component extends HTMLElement implements IComponent {
/**
* Options for this element, used for creating Kirei instances
*/
static options: NormalizedComponentOptions;
/**
* Returns the tagName of the element
* @static
*/
static get is(): string;
/**
* The attributes to observe changes for
* @static
*/
static get observedAttributes(): string[];
/**
* Constructs a new Component
*/
constructor();
/**
* Runs when mounted from DOM
*/
connectedCallback(): void;
/**
* Runs when unmounted from DOM
*/
disconnectedCallback(): void;
/**
* Observes attribute changes, triggers updates on props
*/
attributeChangedCallback(attr: string, oldValue: string, newValue: string): void;
}
/**
* Wait for next flush of the queue, as a Promise or as a callback function
* @param fn - Optional callback function
*/
export declare function nextTick(fn?: () => void): Promise;
/**
* Defines a new component
* @param options - Raw element options
* @returns A constructor to create a new Component element
*/
export declare function defineComponent>(options: ComponentOptions): typeof Component;
/**
* An enumerator of the standard lifecycle hooks
* @private
*/
export declare enum HookTypes {
BEFORE_MOUNT = "beforeMount",
MOUNTED = "mounted",
BEFORE_UPDATE = "beforeUpdate",
UPDATED = "updated",
BEFORE_UNMOUNT = "beforeUnmount",
UNMOUNTED = "unmounted",
ERROR_CAPTURED = "errorCaptured"
}
/**
* Creates a new hook to set on the active instance
* @param hook - Hook name
* @return The defined hook factory
*/
export declare function defineHook(name: string): (hook: T) => void;
/** Registers a new hook it runs before instance is mounted */
export declare const onBeforeMount: (hook: Function) => void;
/** Registers a new hook it runs after instance is mounted */
export declare const onMount: (hook: Function) => void;
/** Registers a new hook it runs before instance is updated */
export declare const onBeforeUpdate: (hook: Function) => void;
/** Registers a new hook it runs after instance is updated */
export declare const onUpdate: (hook: Function) => void;
/** Registers a new hook it runs before instance is unmounted */
export declare const onBeforeUnmount: (hook: Function) => void;
/** Registers a new hook it runs after instance is unmounted */
export declare const onUnmount: (hook: Function) => void;
/** Registers a hook it runs when an error occurs in the component or any of it's children */
export declare const onErrorCaptured: (hook: Function) => void;
/**
* Function to stop a reactive watcher
*/
export declare type StopWatcher = () => void;
/**
*/
export declare type WatchTarget = Ref | T | (() => T);
/**
* Infers value types from an array of WatchTargets
*/
export declare type InferWatchValues = {
[K in keyof T]: T[K] extends WatchTarget ? V : never;
};
/**
* Optional configuration to pass to a watcher
*/
export interface WatchOptions {
/**
* If watcher should be run immediately, with undefined value(s)
*/
immediate?: boolean;
/**
* If watch should traverse every child of the watched target(s)
*/
deep?: boolean;
}
/**
* Creates a function that runs anytime a reactive dependency updates.
* Runs immediately to collect dependencies.
* Returns a function to effectivly stop the watcher.
* @param target - Function to run when an update is triggered
* @returns A function to stop the effect from watching
*/
export declare function watchEffect(target: () => void): StopWatcher;
/**
* Watches one or multiple sources for changes, to easily consume the updates with a before and after value.
* Has an option to trigger an immediate call (with oldValue set to undefined or empty array).
* Returns a function to effectivly stop the watcher.
* @param target - Target or targets to watch
* @param callback - Callback to run when a target is updated
* @param options - Optional watcher options
* @returns A function to stop the effect from watching
*/
export declare function watch(target: T, callback: (values: InferWatchValues, oldValues: InferWatchValues) => void, options?: WatchOptions): StopWatcher;
export declare function watch(target: WatchTarget, callback: (values: T, oldValues: T) => void, options?: WatchOptions): StopWatcher;
export declare type PluginInstallFunction = (app: App, ...args: any[]) => any;
export declare type Plugin = PluginInstallFunction & {
install?: PluginInstallFunction;
} | {
install: PluginInstallFunction;
};
export interface App {
container: ComponentInstance | null;
context: AppContext;
version: string;
config: AppConfig;
use(plugin: Plugin, ...options: any[]): this;
directive(name: string): Directive;
directive(name: string, directive: Directive): this;
provide(key: InjectionKey | string, value: T): this;
}
export interface AppConfig {
performance: boolean;
errorHandler?(err: unknown, instance: ComponentInstance | null, info: string): void;
warnHandler?(msg: string, instance: ComponentInstance | null, trace: string): void;
}
export interface AppContext {
app: App;
config: AppConfig;
directives: Record;
provides: Record;
/**
* HMR only?
* @internal
*/
reload?(): void;
}
export declare const applications: Map;
export declare function createApp(root: string): App;
export * from "@vue/reactivity";
export {};