@zeus-js/runtime-dom 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,225 @@
1
+ type JSXPrimitive = string | number | boolean | null | undefined;
2
+ export type JSXValue = JSXPrimitive | Node | JSXValue[];
3
+ export type JSXGetter = () => JSXValue;
4
+ export type Component<P extends Record<string, unknown> = Record<string, unknown>> = (props: P) => JSXValue;
5
+ export type TemplateFactory<T extends Node = Node> = () => T;
6
+ export type AttrValue = string | number | boolean | null | undefined;
7
+ export type ClassValue = string | null | undefined | false | Record<string, boolean | null | undefined> | Array<ClassValue>;
8
+ export type StyleValue = string | null | undefined | Partial<CSSStyleDeclaration> | Record<string, string | number | null | undefined>;
9
+ export type RefTarget<T> = ((value: T | null) => void) | {
10
+ value: T | null;
11
+ } | {
12
+ current: T | null;
13
+ };
14
+
15
+ import type { TemplateFactory } from './types';
16
+ export declare function template<T extends Node = Node>(html: string, _isImportNode?: boolean, _isSVG?: boolean, _isMathML?: boolean): TemplateFactory<T>;
17
+
18
+ import type { JSXValue } from './types';
19
+ export type ContextId = symbol;
20
+ export interface Context<T = unknown> {
21
+ readonly id: ContextId;
22
+ /**
23
+ * The default value passed to createContext().
24
+ *
25
+ * Note:
26
+ * - `defaultValue` itself may be `undefined`.
27
+ * - Use `hasDefaultValue` to check whether a default value was provided.
28
+ */
29
+ readonly defaultValue: T | undefined;
30
+ readonly hasDefaultValue: boolean;
31
+ readonly Provider: ContextProvider<T>;
32
+ readonly Bridge: ContextBridge<T>;
33
+ }
34
+ export interface ContextProviderProps<T> {
35
+ value: T;
36
+ children?: JSXValue | (() => JSXValue);
37
+ /**
38
+ * When true, creates a DOM context boundary for native custom elements /
39
+ * Web Components that live outside the Zeus owner tree.
40
+ */
41
+ bridge?: boolean;
42
+ }
43
+ export interface ContextBridgeProps<T> {
44
+ value: T;
45
+ children?: JSXValue | (() => JSXValue);
46
+ }
47
+ type ContextProvider<T> = (props: ContextProviderProps<T>) => JSXValue;
48
+ type ContextBridge<T> = (props: ContextBridgeProps<T>) => JSXValue;
49
+ export interface Owner {
50
+ parent?: Owner;
51
+ provides: Map<ContextId, unknown>;
52
+ }
53
+ export declare function getCurrentOwner(): Owner | undefined;
54
+ export declare function createOwner(parent?: Owner | undefined): Owner;
55
+ export declare function runWithOwner<T>(owner: Owner | undefined, fn: () => T): T;
56
+ export declare function createContext<T>(): Context<T>;
57
+ export declare function createContext<T>(defaultValue: T): Context<T>;
58
+ export declare function provide<T>(context: Context<T>, value: T): void;
59
+ export declare function inject<T>(context: Context<T>): T;
60
+ export declare function inject<T>(context: Context<T>, fallback: T): T;
61
+ export declare function useContext<T>(context: Context<T>): T;
62
+ export declare function useContext<T>(context: Context<T>, fallback: T): T;
63
+ export declare const ZEUS_CONTEXT_REQUEST = "zeus:context-request";
64
+ export interface ZeusContextRequestDetail<T = unknown> {
65
+ id: ContextId;
66
+ resolved: boolean;
67
+ value?: T;
68
+ resolve: (value: T) => void;
69
+ }
70
+ export type ZeusContextRequestEvent<T = unknown> = CustomEvent<ZeusContextRequestDetail<T>>;
71
+ export interface DOMContextResolution<T> {
72
+ found: boolean;
73
+ value: T | undefined;
74
+ }
75
+ /**
76
+ * Creates a transparent DOM element that acts as a context boundary.
77
+ * Native custom elements inside it can use `requestDOMContext` to receive
78
+ * context values via the DOM event protocol.
79
+ */
80
+ export declare function createDOMContextBoundary<T>(context: Context<T>, value: T, children: JSXValue): Element;
81
+ /**
82
+ * Registers a context value on a DOM target so that any descendant custom
83
+ * element can pick it up via `requestDOMContext`.
84
+ */
85
+ export declare function provideDOMContext<T>(target: EventTarget, context: Context<T>, value: T): void;
86
+ /**
87
+ * Internal precise DOM context resolver.
88
+ *
89
+ * Unlike requestDOMContext(), this can distinguish:
90
+ * - found: false, value: undefined
91
+ * - found: true, value: undefined
92
+ */
93
+ export declare function resolveDOMContext<T>(host: HTMLElement, context: Context<T>): DOMContextResolution<T>;
94
+ /**
95
+ * Public compatibility API.
96
+ *
97
+ * Returns the resolved value if found, otherwise undefined.
98
+ * If you need to distinguish "not found" from "found undefined",
99
+ * use resolveDOMContext().
100
+ */
101
+ export declare function requestDOMContext<T>(host: HTMLElement, context: Context<T>): T | undefined;
102
+
103
+ import { createOwner } from './context';
104
+ import type { JSXValue } from './types';
105
+ export interface RenderOptions {
106
+ owner?: ReturnType<typeof createOwner>;
107
+ }
108
+ export declare function render(value: JSXValue | (() => JSXValue), container: Element | DocumentFragment, options?: RenderOptions): () => void;
109
+
110
+ import type { JSXValue } from './types';
111
+ declare class DynamicRange {
112
+ private readonly parent;
113
+ private readonly marker;
114
+ private nodes;
115
+ constructor(parent: Node, marker: Node | null);
116
+ replace(value: JSXValue): void;
117
+ clear(): void;
118
+ current(): readonly Node[];
119
+ }
120
+ declare function insertTracked(parent: Node, value: JSXValue, marker: Node | null): Node[];
121
+ export declare function removeNodes(nodes: readonly Node[]): void;
122
+ declare function moveRangeBefore(nodes: readonly Node[], parent: Node, marker: Node | null): void;
123
+ declare function firstNode(nodes: readonly Node[]): Node | null;
124
+ declare function lastNode(nodes: readonly Node[]): Node | null;
125
+
126
+ import { insertTracked } from './range';
127
+ import type { JSXValue } from './types';export declare function insert(parent: Node, value: JSXValue, marker?: Node | null): void;
128
+ export declare function mountDynamic(parent: Node, marker: Node, value: () => JSXValue): void;
129
+
130
+ export declare function marker(parent: ParentNode, index: number): Comment;
131
+ export declare function child(parent: ParentNode, index: number): ChildNode;
132
+ declare function removeNodes$1(nodes: readonly Node[]): void;
133
+
134
+ import type { AttrValue, ClassValue, JSXValue, StyleValue } from './types';
135
+ export declare function bindText(node: Text, value: () => JSXValue): void;
136
+ export declare function bindTextContent(el: Node, value: () => JSXValue): void;
137
+ export declare function setAttr(el: Element, name: string, value: AttrValue): void;
138
+ export declare function bindAttr(el: Element, name: string, value: () => AttrValue): void;
139
+ export declare function bindProp<T extends Element, K extends keyof T>(el: T, name: K, value: () => T[K]): void;
140
+ export declare function bindClass(el: Element, value: () => ClassValue): void;
141
+ export declare function normalizeClass(value: ClassValue): string;
142
+ export declare function bindStyle(el: HTMLElement | SVGElement, value: () => StyleValue): void;
143
+
144
+ export declare function bindEvent(el: Element, name: string, handler: EventListener): void;
145
+ export declare function delegateEvents(events: readonly string[]): void;
146
+ declare function resetDelegatedEvents(): void;
147
+
148
+ import type { RefTarget } from './types';
149
+ export declare function setRef<T>(target: RefTarget<T> | null | undefined, value: T | null): void;
150
+ export declare function bindRef<T extends Element>(el: T, target: RefTarget<T> | null | undefined): void;
151
+
152
+ import type { JSXValue } from './types';
153
+ export declare function createComponent<P extends Record<string, unknown>, R extends JSXValue>(component: (props: P) => R, props: P): R;
154
+
155
+ import type { JSXValue } from './types';
156
+ export type ShowProps = {
157
+ when: unknown;
158
+ fallback?: JSXValue | (() => JSXValue);
159
+ children?: JSXValue | (() => JSXValue);
160
+ };
161
+ export declare function Show(props: ShowProps): JSXValue;
162
+ export declare function resolveValue(value: JSXValue | (() => JSXValue) | undefined): JSXValue;
163
+ export declare function mountShow(parent: Node, marker: Node, when: () => unknown, children: () => JSXValue, fallback?: () => JSXValue): void;
164
+ export type ForProps<T, K = unknown> = {
165
+ each: readonly T[] | null | undefined;
166
+ by?: (item: T, index: number) => K;
167
+ children: (item: T, index: number) => JSXValue;
168
+ };
169
+ export declare function For<T, K = unknown>(props: ForProps<T, K>): JSXValue;
170
+ export declare function mountFor<T, K = unknown>(parent: Node, marker: Node, each: () => readonly T[] | null | undefined, key: ((item: T, index: number) => K) | undefined, render: (item: T, index: number) => JSXValue): void;
171
+
172
+ import type { Context } from './context';
173
+ import type { JSXValue } from './types';
174
+ export type ElementPropConstructor = StringConstructor | NumberConstructor | BooleanConstructor | ObjectConstructor | ArrayConstructor;
175
+ export type PropDefinition<T = unknown> = ElementPropConstructor | {
176
+ type?: ElementPropConstructor;
177
+ attr?: string | false;
178
+ reflect?: boolean;
179
+ default?: T | (() => T);
180
+ };
181
+ export type PropOptions<P extends Record<string, unknown>> = Partial<{
182
+ [K in keyof P]: PropDefinition<P[K]>;
183
+ }>;
184
+ export interface DefineElementOptions<P extends Record<string, unknown>> {
185
+ shadow?: boolean | ShadowRootInit;
186
+ props?: PropOptions<P>;
187
+ styles?: string | string[];
188
+ consumes?: Context<any>[];
189
+ }
190
+ export interface DefineElementContext<E extends HTMLElement = HTMLElement> {
191
+ host: E;
192
+ emit: (name: string, detail?: unknown, options?: CustomEventInit) => boolean;
193
+ }
194
+ export type DefineElementSetup<P extends Record<string, unknown>, E extends HTMLElement = HTMLElement> = (props: Readonly<P>, context: DefineElementContext<E>) => JSXValue;
195
+ export declare function defineElement<P extends Record<string, unknown> = Record<string, unknown>, E extends HTMLElement = HTMLElement>(tagName: string, options: DefineElementOptions<P>, setup: DefineElementSetup<P, E>): CustomElementConstructor;
196
+
197
+ import type { JSXValue } from './types';
198
+ export interface HostProps {
199
+ children?: JSXValue | (() => JSXValue);
200
+ }
201
+ export interface SlotProps {
202
+ name?: string;
203
+ children?: JSXValue | (() => JSXValue);
204
+ }
205
+ export declare function Host(props: HostProps): JSXValue;
206
+ export declare function Slot(props: SlotProps): JSXValue;
207
+
208
+ import type { JSXValue } from './types';
209
+ export declare function createSlot(name?: string, fallback?: () => JSXValue): JSXValue;
210
+
211
+ export type HostRenderMode = 'light' | 'shadow';
212
+ export interface HostRenderContext {
213
+ host: HTMLElement;
214
+ mode: HostRenderMode;
215
+ lightChildren: readonly Node[];
216
+ }
217
+ export declare function getCurrentHostContext(): HostRenderContext | undefined;
218
+ export declare function withHostContext<T>(context: HostRenderContext | undefined, fn: () => T): T;
219
+ export declare function captureCurrentHostContext(): HostRenderContext | undefined;
220
+ export declare function withCapturedHostContext<T extends (...args: never[]) => unknown>(fn: T): T;
221
+
222
+ import './types';
223
+
224
+
225
+