import { Template } from '@kirei/html'; import { ReactiveEffect, Ref, UnwrapRef } from '@vue/reactivity'; /** * StyleSheets to use with adoptStyleSheets */ export declare type StyleSheet = CSSResult | CSSStyleSheet; /** * Class to easily construct and cache style sheets, through template literals */ export declare class CSSResult { /** * Only used for testing, changing this could create problems * @private */ static supportsAdoptingStyleSheets: boolean; /** * Cached stylesheet, created by the generate() method */ private styleSheet; /** * Raw CSS styles, as passed in to the template literal */ readonly cssText: string; /** * Constructs a new CSSResult instance * @param strings - Template strings glue * @param values - Interpolated values */ constructor(strings: TemplateStringsArray, values: readonly any[]); /** * Generates the constructible stylesheet, singleton cached * @returns A promise that returns a stylesheet */ generate(): Promise; /** * Gets the raw CSS styles as a string * @returns A string with the CSS content */ toString(): string; } /** * Creates a new CSS result from a template literal * @param strings - Template strings as a glue for the values * @param values - Dynamic values to interpolate * @returns An object that represents a CSS Stylesheet */ export declare function css(strings: TemplateStringsArray, ...values: readonly any[]): CSSResult; /** * Helps type inference when providing/injecting a key */ export interface InjectionKey extends Symbol { } /** * Provides a value to itself and children, used to flow data down, such as stores * @param key - Key to provide value as, can be a InjectionKey for type inference * @param value - Value to set to the provider */ export declare function provide(key: InjectionKey | string, value: T): void; /** * Gets a inherited value shared by any parent in the instance tree * @param key - Key of injected value * @param defaultValue - Fallback value in case of not being provided, defaults to undefined * @returns Default value if value waw not found otherwise undefined */ export declare function inject(key: InjectionKey | string, defaultValue?: T): T | undefined; /** * Directive has a set of lifecycle hooks: */ export interface Directive { /** * Called before bound element's parent component is mounted * @param el - Target element of the directive * @param binding - Directive binding */ beforeMount?(el: HTMLElement, binding: DirectiveBinding): void; /** * Called when bound element's parent component is mounted * @param el - Target element of the directive * @param binding - Directive binding */ mounted?(el: HTMLElement, binding: DirectiveBinding): void; /** * Called before the containing component's VNode is updated * @param el - Target element of the directive * @param binding - Directive binding */ beforeUpdate?(el: HTMLElement, binding: DirectiveBinding): void; /** * Called after the containing component's VNode and the VNodes of its children // have updated * @param el - Target element of the directive * @param binding - Directive binding */ updated?(el: HTMLElement, binding: DirectiveBinding): void; /** * Called before the bound element's parent component is unmounted * @param el - Target element of the directive * @param binding - Directive binding */ beforeUnmount?(el: HTMLElement, binding: DirectiveBinding): void; /** * Called when the bound element's parent component is unmounted * @param el - Target element of the directive * @param binding - Directive binding */ unmounted?(el: HTMLElement, binding: DirectiveBinding): void; } export interface DirectiveBinding { instance: ComponentInstance; value: T; oldValue: T; arg: string; modifiers: string[]; dir: Directive; } declare const html: import("@kirei/html").TemplateLiteral, svg: import("@kirei/html").TemplateLiteral, render: { (template: Node | import("@kirei/html").Template, root: import("@kirei/html").RootContainer, renderOptions?: import("@kirei/html").RenderOptions): Node; (template: null, root: import("@kirei/html").RootContainer, renderOptions?: import("@kirei/html").RenderOptions): void; (template: Node | import("@kirei/html").Template, root: import("@kirei/html").RootContainer, renderOptions?: import("@kirei/html").RenderOptions): Node; }; /** * Unwraps refs recursively, essentially a reactive() from @vue/reactivity. * @private */ export declare type UnwrapNestedRefs = T extends Ref ? T : UnwrapRef; /** * @private */ export declare type PropConstructor = { new (...args: any[]): T & object; } | { (): T; }; /** * @private */ export declare type PropType = PropConstructor | PropConstructor[]; /** * @private */ export declare type DefaultFactory = () => T | null | undefined; /** * @private */ export interface PropInstance { type: PropType; required?: boolean; validator?(value: any): boolean; default?: DefaultFactory | T; } /** * @private */ export declare type Prop = PropInstance | PropType | 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 {};