/* Copyright Yukino Song, SudoMaker Ltd. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import type { MaybeSignal, Signal } from './signal.js' import type { Renderer } from './renderer.js' export type RenderFunction = (renderer: R) => Result export type PossibleRender = | RenderFunction | PromiseLike | null | undefined> | null | undefined export type ComponentTemplate

= ( props: P, ...children: any[] ) => PossibleRender export function capture any>(fn: T): T export function snapshot(): any>(fn: T, ...args: Parameters) => ReturnType export function render(instance: Component, renderer: Renderer): unknown export function dispose(instance: Component): void export function getCurrentSelf = Component>(): T | undefined export interface ContextProps { value: T } export type ContextProvider = (props: ContextProps, ...children: any[]) => RenderFunction export function createContext(defaultValue: T, name?: string): ContextProvider export function useContext(Context: ContextProvider): T export function lazy(loader: () => PromiseLike | T, symbol?: string | null): ComponentTemplate export function memo any>(fn: T): (...args: Parameters) => ReturnType export function useMemo any>(fn: T): () => (...args: Parameters) => ReturnType export interface FnOptions { name?: string ctx?: unknown catch?: MaybeSignal<(error: unknown, name: string, context: unknown) => PossibleRender> } export function Fn( options: FnOptions, handler?: (context: unknown) => PossibleRender, catchHandler?: (error: unknown, name: string, context: unknown) => PossibleRender ): RenderFunction export interface ForExpose { getItem(key: unknown): T | undefined remove(key: unknown): void clear(): void } export interface ForProps { entries: MaybeSignal track?: MaybeSignal indexed?: boolean name?: string expose?: (api: ForExpose) => void } export type ForTemplate = | ComponentTemplate | ((input: { item: T; index: Signal }) => PossibleRender) export function For(props: ForProps, template: ForTemplate): RenderFunction export interface IfProps { condition?: MaybeSignal | (() => any) | any true?: MaybeSignal | (() => any) | any else?: MaybeSignal | (() => any) | any } export function If(props: IfProps, whenTrue?: PossibleRender, whenFalse?: PossibleRender): PossibleRender export interface DynamicExpose { current: Signal } export interface DynamicProps { is: MaybeSignal | Component | null | undefined> current?: Signal | ((value: unknown) => void) [key: string]: any } export function Dynamic(props: DynamicProps, ...children: any[]): RenderFunction export interface AsyncProps { future: PromiseLike | T fallback?: MaybeSignal, ...children: any[]) => PossibleRender)> catch?: MaybeSignal & { error: E }, ...children: any[]) => PossibleRender)> suspensed?: boolean onLoad?: () => void | Promise [key: string]: any } export function Async( props: AsyncProps, then?: (payload: Record & { result: T }) => PossibleRender, now?: PossibleRender, catchHandler?: (payload: Record & { error: E }) => PossibleRender ): RenderFunction export interface TransitionProps { name?: string data?: Record fallback?: MaybeSignal PossibleRender)> loading?: Signal pending?: Signal catch?: MaybeSignal PossibleRender)> onLoad?: (state: TransitionState, hasCurrent: boolean, swap: () => Promise) => void | Promise } export interface TransitionState { loading: Signal pending: Signal leaving: Signal entered: Signal entering: Signal data: Record } export function Transition( props: TransitionProps, then: (state: TransitionState) => PossibleRender, now?: PossibleRender, catchHandler?: (error: unknown) => PossibleRender ): RenderFunction export interface SuspenseProps { fallback?: MaybeSignal, ...children: any[]) => PossibleRender)> catch?: MaybeSignal & { error: E }, ...children: any[]) => PossibleRender)> onLoad?: () => void | Promise [key: string]: any } export function Suspense( props: SuspenseProps, ...children: any[] ): RenderFunction export interface RenderProps { from: MaybeSignal | null | undefined> } export function Render(props: RenderProps): RenderFunction export class Component

{ constructor(template: ComponentTemplate

, props?: P, ...children: any[]) } export function createComponent

(template: ComponentTemplate

, props?: P, ...children: any[]): Component

export type ComponentInstance

= Component

/** @internal */ export function _asyncContainer( this: PromiseLike, name: string | null, fallback: | MaybeSignal, ...children: any[]) => PossibleRender)> | undefined, catchErr: | MaybeSignal & { error: unknown }, ...children: any[]) => PossibleRender)> | undefined, onLoad: (() => void | Promise) | undefined, suspensed: boolean, props: Record, children: any[] ): RenderFunction