import { _hoist_read_error } from "../common/errors";
import { type Opt } from "../common/opt";
import { type $Global, type Accessor, type Falsy, ResumeSymbol } from "../common/types";
import { K_SCOPE_ID, Serializer } from "./serializer";
import type { ServerRenderer } from "./template";
export type PartialScope = Record<Accessor, unknown>;
interface SerializeState {
    readyId?: string;
    parent?: SerializeState;
    resumes: string;
    writeScopes: Record<number, PartialScope>;
    passiveScopes?: Record<number, PartialScope>;
    flushScopes: boolean;
}
type ScopeInternals = PartialScope & {
    [K_SCOPE_ID]?: number;
};
declare enum Mark {
    Placeholder = "!^",
    PlaceholderEnd = "!",
    ReorderMarker = "#"
}
export declare function getChunk(): Chunk | undefined;
export declare function getContext(key: keyof NonNullable<Chunk["context"]>): unknown;
export declare function getState(): State;
export declare function getScopeId(scope: unknown): number | undefined;
export declare function _html(html: string): void;
export declare function writeScript(script: string): void;
export declare function writeWaitReady(readyId: string, renderer: ServerRenderer, input: unknown): void;
export declare function _script(scopeId: number, registryId: string): void;
export declare function _attr_content(nodeAccessor: Accessor, scopeId: number, content: unknown, serializeReason?: 1 | 0): void;
export declare function withContext<T>(key: PropertyKey, value: unknown, cb: () => T): T;
export declare function withContext<T, U>(key: PropertyKey, value: unknown, cb: (value: U) => T, cbValue: U): T;
export declare function _var(parentScopeId: number, scopeOffsetAccessor: Accessor, childScopeId: number, registryId: string, nodeAccessor?: Accessor): void;
export declare function _resume<T extends WeakKey>(val: T, id: string, scopeId?: number): T;
export declare function _id(): string;
export declare function _scope_id(): number;
export declare function _peek_scope_id(): number;
export declare function getScopeById(scopeId: number | undefined): ScopeInternals | undefined;
export declare function _set_serialize_reason(reason: undefined | 0 | 1): void;
export declare function _scope_reason(): 0 | 1 | undefined;
export declare function _serialize_if(condition: undefined | 1 | Record<string, 1>, key: string): 1 | undefined;
export declare function _serialize_guard(condition: undefined | 1 | Record<string, 1>, key: string): 1 | 0;
export declare function _el_resume(scopeId: number, accessor: Accessor, shouldResume?: 0 | 1): string;
export declare function _sep(shouldResume: 0 | 1): "" | "<!>";
export declare function _el(scopeId: number, id: string): () => void;
export declare function _hoist(scopeId: number, id: string): {
    (): void;
    [Symbol.iterator]: typeof _hoist_read_error;
};
export declare function _resume_branch(scopeId: number): void;
export declare function isInResumedBranch(): boolean;
export declare function withBranchId<T>(branchId: number, cb: () => T): T;
export declare function _for_of(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, by: Falsy | ((item: unknown, index: number) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, serializeStateful?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
export declare function _for_in(obj: Falsy | {}, cb: (key: string, value: unknown) => void, by: Falsy | ((key: string, v: unknown) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, serializeStateful?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
export declare function _for_to(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, by: Falsy | ((v: number) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, serializeStateful?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
export declare function _for_until(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, by: Falsy | ((v: number) => unknown), scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, serializeStateful?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
export declare function _if(cb: () => void | number, scopeId: number, accessor: Accessor, serializeBranch?: 0 | 1, serializeMarker?: 0 | 1, serializeStateful?: 0 | 1, parentEndTag?: string | 0, singleNode?: 1): void;
declare let writeScope: (scopeId: number, partialScope: PartialScope) => ScopeInternals;
export { writeScope as _scope };
export declare function _existing_scope(scopeId: number): ScopeInternals;
export declare function _scope_with_id(scopeId: number): ScopeInternals;
export declare function $global(): $Global & {
    renderId: string;
    runtimeId: string;
};
export declare function _await<T>(scopeId: number, accessor: Accessor, promise: Promise<T> | T, content: (value: T) => void, serializeMarker?: 0 | 1): void;
export declare function _try(scopeId: number, accessor: Accessor, content: () => void, input: {
    placeholder?: {
        content?(): void;
    };
    catch?: {
        content?(err: unknown): void;
    };
}): void;
export declare class State implements SerializeState {
    $global: $Global & {
        renderId: string;
        runtimeId: string;
    };
    tagId: number;
    scopeId: number;
    reorderId: number;
    readyGate: number;
    hasGlobals: boolean;
    needsMainRuntime: boolean;
    hasMainRuntime: boolean;
    hasReadyRuntime: boolean;
    hasReorderRuntime: boolean;
    hasWrittenResume: boolean;
    walkOnNextFlush: boolean;
    trailerHTML: string;
    resumes: string;
    nonceAttr: string;
    serializer: Serializer;
    writeReorders: Chunk[] | null;
    scopes: Map<number, ScopeInternals>;
    flushScopes: boolean;
    writeScopes: Record<number, PartialScope>;
    readyIds: Set<string> | null;
    serializeReason: undefined | 0 | 1;
    constructor($global: $Global & {
        renderId: string;
        runtimeId: string;
    });
    get runtimePrefix(): string;
    get commentPrefix(): string;
    reorder(chunk: Chunk): void;
    writeReady(id: string, resumes: string): string;
    readyAccess(readyKey: string): string;
    nextReorderId(): string;
    mark(code: ResumeSymbol | Mark, str: string): string;
}
export declare enum FlushStatus {
    complete = 0,
    continue = 1,
    aborted = 2
}
export declare class Boundary extends AbortController {
    state: State;
    onNext: () => void;
    count: number;
    constructor(state: State, parent?: AbortSignal);
    flush(): FlushStatus;
    startAsync(): void;
    endAsync(chunk?: Chunk): void;
}
export declare class Chunk {
    boundary: Boundary;
    next: Chunk | null;
    context: Record<string | symbol, unknown> | null;
    serializeState: SerializeState;
    html: string;
    scripts: string;
    effects: string;
    lastEffect: string;
    async: boolean;
    consumed: boolean;
    needsWalk: boolean;
    reorderId: string | null;
    deferredReady: Opt<Chunk>;
    placeholder: {
        body: Chunk;
        render: () => void;
        branchId: number;
    } | null;
    constructor(boundary: Boundary, next: Chunk | null, context: Record<string | symbol, unknown> | null, serializeState: SerializeState);
    fork(boundary: Boundary, next: Chunk | null): Chunk;
    writeHTML(html: string): void;
    writeEffect(scopeId: number, registryId: string): void;
    writeScript(script: string): void;
    append(chunk: Chunk): void;
    takeDeferredReady(): Opt<Chunk>;
    deferOwnReady(): void;
    flushPlaceholder(): void;
    consume(): Chunk;
    render(content: () => void): Chunk;
    render<T>(content: (val: T) => void, val: T): Chunk;
    flushReadyScripts(reservations?: string[]): string;
    flushScript(): this;
    flushHTML(): string;
}
export declare function _trailers(html: string): void;
type QueueCallback = (ticked: true) => void;
export declare function queueTick(cb: QueueCallback): void;
export declare function offTick(cb: QueueCallback): void;
export declare function _subscribe(subscribers: Set<ScopeInternals> | undefined, scope: ScopeInternals): ScopeInternals;
