ilha 0.7.0 → 0.8.0

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,297 @@
1
+ //#region src/index.d.ts
2
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
4
+ }
5
+ declare namespace StandardSchemaV1 {
6
+ interface Props<Input = unknown, Output = Input> {
7
+ readonly version: 1;
8
+ readonly vendor: string;
9
+ readonly types?: Types<Input, Output> | undefined;
10
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
11
+ }
12
+ type Result<Output> = SuccessResult<Output> | FailureResult;
13
+ interface SuccessResult<Output> {
14
+ readonly value: Output;
15
+ readonly issues?: undefined;
16
+ }
17
+ interface FailureResult {
18
+ readonly issues: ReadonlyArray<Issue>;
19
+ }
20
+ interface Issue {
21
+ readonly message: string;
22
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
23
+ }
24
+ interface PathSegment {
25
+ readonly key: PropertyKey;
26
+ }
27
+ interface Types<Input = unknown, Output = Input> {
28
+ readonly input: Input;
29
+ readonly output: Output;
30
+ }
31
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
32
+ }
33
+ declare const RAW: unique symbol;
34
+ declare const SIGNAL_ACCESSOR: unique symbol;
35
+ declare const ISLAND: unique symbol;
36
+ declare const ISLAND_CALL: unique symbol;
37
+ /** @internal Internal hook used by a parent's mountSlots to mount a child island and
38
+ * retain a handle to push updated props into it on subsequent parent
39
+ * re-renders. Not part of the public surface. */
40
+ declare const ISLAND_MOUNT_INTERNAL: unique symbol;
41
+ interface RawHtml {
42
+ [RAW]: true;
43
+ value: string;
44
+ }
45
+ interface IslandCall {
46
+ [ISLAND_CALL]: true;
47
+ island: AnyIsland;
48
+ props: Record<string, unknown> | undefined;
49
+ key: string | undefined;
50
+ }
51
+ interface MarkedSignalAccessor<T> {
52
+ (): T;
53
+ (...args: [value: T]): void;
54
+ select<S>(selector: (state: T) => S): MarkedSignalAccessor<S>;
55
+ [SIGNAL_ACCESSOR]: true;
56
+ }
57
+ declare function ilhaRaw(value: string): RawHtml;
58
+ declare function ilhaCss(strings: TemplateStringsArray | string, ...values: (string | number)[]): string;
59
+ declare function ilhaHtml(strings: TemplateStringsArray, ...values: unknown[]): RawHtml;
60
+ type ContextSignal<T> = {
61
+ (): T;
62
+ (value: T): void;
63
+ };
64
+ declare function ilhaContext<T>(key: string, initial: T): ContextSignal<T>;
65
+ /**
66
+ * Create a free-standing reactive signal that lives outside any island.
67
+ * Useful for sharing state across islands without prop drilling, or for
68
+ * binding form inputs to module-level state via the `bind:value=${signal}`
69
+ * template syntax.
70
+ *
71
+ * The returned accessor is a getter when called with no arguments and a
72
+ * setter when called with one. Reading it inside a `.derived()`, `.effect()`,
73
+ * or `.render()` automatically subscribes the surrounding reactive scope —
74
+ * so when the signal changes, dependents re-run as if it were local state.
75
+ */
76
+ declare function ilhaSignal<T>(initial: T): SignalAccessor<T>;
77
+ /**
78
+ * Run `fn` with reactive tracking suspended. Reading signals inside `fn`
79
+ * returns their current value without subscribing the surrounding scope.
80
+ * Use this in effects/deriveds when you want to peek at state without
81
+ * causing a re-run on its changes.
82
+ */
83
+ declare function untrack<T>(fn: () => T): T;
84
+ /**
85
+ * Run `fn` as an atomic batch — multiple signal writes inside the callback
86
+ * produce a single propagation pass, so dependents (effects, deriveds,
87
+ * island re-renders) see the final state and run once instead of once per
88
+ * write. Returns whatever `fn` returns.
89
+ *
90
+ * Note: `.on()` handlers and `.effect()` runs are batched implicitly, so
91
+ * you only need this when triggering multiple writes from outside an
92
+ * island (e.g. from a top-level event listener or async callback).
93
+ */
94
+ declare function batch<T>(fn: () => T): T;
95
+ interface DerivedValue<T> {
96
+ loading: boolean;
97
+ value: T | undefined;
98
+ error: Error | undefined;
99
+ }
100
+ type DerivedAccessor<T> = {
101
+ readonly loading: boolean;
102
+ readonly value: T | undefined;
103
+ readonly error: Error | undefined;
104
+ (): T | undefined;
105
+ (value: T): void;
106
+ };
107
+ type DerivedFnContext<TInput, TStateMap extends Record<string, unknown>> = {
108
+ state: IslandState<TStateMap>;
109
+ input: TInput;
110
+ signal: AbortSignal;
111
+ };
112
+ type DerivedFn<TInput, TStateMap extends Record<string, unknown>, V> = (ctx: DerivedFnContext<TInput, TStateMap>) => V | Promise<V>;
113
+ interface DerivedEntry<TInput, TStateMap extends Record<string, unknown>> {
114
+ key: string;
115
+ fn: DerivedFn<TInput, TStateMap, unknown>;
116
+ }
117
+ type IslandDerived<TDerivedMap extends Record<string, unknown>> = { readonly [K in keyof TDerivedMap]: DerivedAccessor<TDerivedMap[K]> };
118
+ type ExternalSignal<T = unknown> = SignalAccessor<T>;
119
+ type SignalAccessor<T> = MarkedSignalAccessor<T>;
120
+ type MergeState<TStateMap extends Record<string, unknown>, K extends string, V> = Omit<TStateMap, K> & Record<K, V>;
121
+ type IslandState<TStateMap extends Record<string, unknown>> = { readonly [K in keyof TStateMap]-?: SignalAccessor<TStateMap[K]> };
122
+ interface HydratableOptions {
123
+ name: string;
124
+ as?: string;
125
+ snapshot?: boolean | {
126
+ state?: boolean;
127
+ derived?: boolean;
128
+ };
129
+ skipOnMount?: boolean;
130
+ }
131
+ interface Island<TInput = Record<string, unknown>, _TStateMap extends Record<string, unknown> = Record<string, unknown>> {
132
+ (props?: Partial<TInput>): string | Promise<string>;
133
+ toString(props?: Partial<TInput>): string;
134
+ mount(host: Element, props?: Partial<TInput>): () => void;
135
+ hydratable(props: Partial<TInput>, options: HydratableOptions): Promise<string>;
136
+ key(key: string): KeyedIsland<TInput>;
137
+ [ISLAND]: true;
138
+ }
139
+ interface KeyedIsland<TInput> {
140
+ (props?: Partial<TInput>): IslandCall;
141
+ [ISLAND_CALL]: true;
142
+ }
143
+ type AnyIsland = Island<any, any>;
144
+ type RenderContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> = {
145
+ state: IslandState<TStateMap>;
146
+ derived: IslandDerived<TDerivedMap>;
147
+ input: TInput;
148
+ };
149
+ type EffectContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
150
+ state: IslandState<TStateMap>;
151
+ derived: IslandDerived<TDerivedMap>;
152
+ input: TInput;
153
+ host: Element;
154
+ /**
155
+ * AbortSignal that aborts when the effect re-runs (because a dependency
156
+ * changed) or when the island unmounts. Pass to `fetch` or check
157
+ * `signal.aborted` after `await` boundaries to bail out of stale work
158
+ * without needing a manual cleanup function.
159
+ */
160
+ signal: AbortSignal;
161
+ };
162
+ type OnMountContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
163
+ state: IslandState<TStateMap>;
164
+ derived: IslandDerived<TDerivedMap>;
165
+ input: TInput;
166
+ host: Element;
167
+ hydrated: boolean;
168
+ };
169
+ type HandlerContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
170
+ state: IslandState<TStateMap>;
171
+ derived: IslandDerived<TDerivedMap>;
172
+ input: TInput;
173
+ host: Element;
174
+ target: Element;
175
+ event: Event;
176
+ /**
177
+ * AbortSignal that fires when the island unmounts. If the handler's selector
178
+ * was registered with the `:abortable` modifier, the signal is also aborted
179
+ * when the same listener fires again on the same target (giving you free
180
+ * race-cancellation for things like search-as-you-type fetches). Pass this
181
+ * to `fetch`, `AbortController`-aware APIs, or check `signal.aborted`
182
+ * after `await` boundaries to bail out of stale work.
183
+ */
184
+ signal: AbortSignal;
185
+ };
186
+ type HTMLEventFor<E extends string> = E extends keyof HTMLElementEventMap ? HTMLElementEventMap[E] : Event;
187
+ type HTMLTargetFor<E extends string> = E extends keyof HTMLElementEventMap ? NonNullable<HTMLElementEventMap[E]["target"]> extends Element ? NonNullable<HTMLElementEventMap[E]["target"]> : Element : Element;
188
+ type HandlerContextFor<TInput, TStateMap extends Record<string, unknown>, TEventName extends string, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
189
+ state: IslandState<TStateMap>;
190
+ derived: IslandDerived<TDerivedMap>;
191
+ input: TInput;
192
+ host: Element;
193
+ target: HTMLTargetFor<TEventName>;
194
+ event: HTMLEventFor<TEventName>;
195
+ /**
196
+ * AbortSignal that fires when the island unmounts. If the handler's selector
197
+ * was registered with the `:abortable` modifier, the signal is also aborted
198
+ * when the same listener fires again on the same target.
199
+ */
200
+ signal: AbortSignal;
201
+ };
202
+ type StateInit<TInput, V> = V | ((input: TInput) => V);
203
+ interface StateEntry<TInput> {
204
+ key: string;
205
+ init: StateInit<TInput, unknown>;
206
+ }
207
+ interface OnEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> {
208
+ selector: string;
209
+ event: string;
210
+ options: AddEventListenerOptions;
211
+ abortable: boolean;
212
+ handler: (ctx: HandlerContext<TInput, TStateMap, TDerivedMap>) => void | Promise<void>;
213
+ }
214
+ interface EffectEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
215
+ fn: (ctx: EffectContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void;
216
+ }
217
+ /** Where the error originated. `"on"` covers sync throws and async rejections
218
+ * from `.on()` handlers; `"effect"` covers sync throws from `.effect()` runs
219
+ * (async work spawned inside an effect is not awaited by the runtime). */
220
+ type ErrorSource = "on" | "effect";
221
+ type ErrorContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
222
+ error: Error;
223
+ source: ErrorSource;
224
+ state: IslandState<TStateMap>;
225
+ derived: IslandDerived<TDerivedMap>;
226
+ input: TInput;
227
+ host: Element;
228
+ };
229
+ interface OnErrorEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
230
+ fn: (ctx: ErrorContext<TInput, TStateMap, TDerivedMap>) => void;
231
+ }
232
+ interface OnMountEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
233
+ fn: (ctx: OnMountContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void;
234
+ }
235
+ interface TransitionOptions {
236
+ enter?: (host: Element) => Promise<void> | void;
237
+ leave?: (host: Element) => Promise<void> | void;
238
+ }
239
+ interface MountOptions {
240
+ root?: Element;
241
+ lazy?: boolean;
242
+ }
243
+ interface MountResult {
244
+ unmount: () => void | Promise<void>;
245
+ }
246
+ interface BuilderConfig<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
247
+ schema: StandardSchemaV1 | null;
248
+ states: StateEntry<TInput>[];
249
+ deriveds: DerivedEntry<TInput, TStateMap>[];
250
+ ons: OnEntry<TInput, TStateMap, TDerivedMap>[];
251
+ effects: EffectEntry<TInput, TStateMap, TDerivedMap>[];
252
+ onMounts: OnMountEntry<TInput, TStateMap, TDerivedMap>[];
253
+ onErrors: OnErrorEntry<TInput, TStateMap, TDerivedMap>[];
254
+ transition: TransitionOptions | null;
255
+ css: string | null;
256
+ /** Slot wrapper tag when this island is embedded in a parent (default div). */
257
+ as: string | null;
258
+ }
259
+ declare class IlhaBuilder<TInput extends Record<string, unknown>, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> {
260
+ readonly _cfg: BuilderConfig<TInput, TStateMap, TDerivedMap>;
261
+ constructor(cfg: BuilderConfig<TInput, TStateMap, TDerivedMap>);
262
+ input<T extends Record<string, unknown>>(): IlhaBuilder<T, Record<never, never>, Record<never, never>>;
263
+ input<S extends StandardSchemaV1>(schema: S): IlhaBuilder<StandardSchemaV1.InferOutput<S> & Record<string, unknown>, Record<never, never>, Record<never, never>>;
264
+ as<Tag extends string>(tag: Tag): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
265
+ state<V = undefined, K extends string = string>(key: K, init?: StateInit<TInput, V> | undefined): IlhaBuilder<TInput, MergeState<TStateMap, K, V>, TDerivedMap>;
266
+ derived<K extends string, V>(key: K, fn: DerivedFn<TInput, TStateMap, V>): IlhaBuilder<TInput, TStateMap, TDerivedMap & Record<K, V>>;
267
+ on<S extends string>(selectorOrCombined: S, handler: (ctx: S extends `${string}@${infer E}:${string}` ? HandlerContextFor<TInput, TStateMap, E, TDerivedMap> : S extends `${string}@${infer E}` ? HandlerContextFor<TInput, TStateMap, E, TDerivedMap> : HandlerContext<TInput, TStateMap, TDerivedMap>) => void | Promise<void>): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
268
+ effect(fn: (ctx: EffectContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
269
+ onMount(fn: (ctx: OnMountContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
270
+ onError(fn: (ctx: ErrorContext<TInput, TStateMap, TDerivedMap>) => void): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
271
+ transition(opts: TransitionOptions): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
272
+ css(strings: TemplateStringsArray | string, ...values: (string | number)[]): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
273
+ render(fn: (ctx: RenderContext<TInput, TStateMap, TDerivedMap>) => string | RawHtml): Island<TInput, TStateMap>;
274
+ }
275
+ declare function ilhaFrom<TInput, TStateMap extends Record<string, unknown>>(selector: string | Element, island: Island<TInput, TStateMap>, props?: Partial<TInput>): (() => void) | null;
276
+ type IslandRegistry = Record<string, AnyIsland>;
277
+ declare function mountAll(registry: IslandRegistry, options?: MountOptions): MountResult;
278
+ declare const ilha: IlhaBuilder<Record<string, unknown>, Record<never, never>, Record<never, never>> & {
279
+ html: typeof ilhaHtml;
280
+ raw: typeof ilhaRaw;
281
+ mount: typeof mountAll;
282
+ from: typeof ilhaFrom;
283
+ context: typeof ilhaContext;
284
+ signal: typeof ilhaSignal;
285
+ batch: typeof batch;
286
+ untrack: typeof untrack;
287
+ };
288
+ /** @internal Used by the separate JSX runtime entry to preserve island slot composition. */
289
+ declare function __ilhaJsxSlot(island: unknown, props: Record<string, unknown> | undefined, key: string | undefined): RawHtml;
290
+ declare const html: typeof ilhaHtml;
291
+ declare const raw: typeof ilhaRaw;
292
+ declare const css: typeof ilhaCss;
293
+ declare const mount: typeof mountAll;
294
+ declare const from: typeof ilhaFrom;
295
+ declare const context: typeof ilhaContext;
296
+ //#endregion
297
+ export { untrack as A, css as C, ilhaSignal as D, ilha as E, mount as O, context as S, html as T, OnMountContext as _, ErrorSource as a, __ilhaJsxSlot as b, HandlerContextFor as c, Island as d, IslandDerived as f, MountResult as g, MountOptions as h, ErrorContext as i, raw as k, HydratableOptions as l, KeyedIsland as m, DerivedValue as n, ExternalSignal as o, IslandState as p, EffectContext as r, HandlerContext as s, DerivedAccessor as t, ISLAND_MOUNT_INTERNAL as u, RawHtml as v, from as w, batch as x, SignalAccessor as y };
package/dist/index.d.ts CHANGED
@@ -1,308 +1,2 @@
1
- //#region src/index.d.ts
2
- interface StandardSchemaV1<Input = unknown, Output = Input> {
3
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
4
- }
5
- declare namespace StandardSchemaV1 {
6
- interface Props<Input = unknown, Output = Input> {
7
- readonly version: 1;
8
- readonly vendor: string;
9
- readonly types?: Types<Input, Output> | undefined;
10
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
11
- }
12
- type Result<Output> = SuccessResult<Output> | FailureResult;
13
- interface SuccessResult<Output> {
14
- readonly value: Output;
15
- readonly issues?: undefined;
16
- }
17
- interface FailureResult {
18
- readonly issues: ReadonlyArray<Issue>;
19
- }
20
- interface Issue {
21
- readonly message: string;
22
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
23
- }
24
- interface PathSegment {
25
- readonly key: PropertyKey;
26
- }
27
- interface Types<Input = unknown, Output = Input> {
28
- readonly input: Input;
29
- readonly output: Output;
30
- }
31
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
32
- }
33
- declare const RAW: unique symbol;
34
- declare const SIGNAL_ACCESSOR: unique symbol;
35
- declare const ISLAND: unique symbol;
36
- declare const ISLAND_CALL: unique symbol;
37
- /** @internal Internal hook used by a parent's mountSlots to mount a child island and
38
- * retain a handle to push updated props into it on subsequent parent
39
- * re-renders. Not part of the public surface. */
40
- declare const ISLAND_MOUNT_INTERNAL: unique symbol;
41
- interface RawHtml {
42
- [RAW]: true;
43
- value: string;
44
- }
45
- interface IslandCall {
46
- [ISLAND_CALL]: true;
47
- island: AnyIsland;
48
- props: Record<string, unknown> | undefined;
49
- key: string | undefined;
50
- }
51
- interface MarkedSignalAccessor<T> {
52
- (): T;
53
- (...args: [value: T]): void;
54
- select<S>(selector: (state: T) => S): MarkedSignalAccessor<S>;
55
- [SIGNAL_ACCESSOR]: true;
56
- }
57
- declare function ilhaRaw(value: string): RawHtml;
58
- declare function ilhaCss(strings: TemplateStringsArray | string, ...values: (string | number)[]): string;
59
- type JsxChild = unknown;
60
- type JsxProps = Record<string, unknown> | null | undefined;
61
- type JsxType = string | ((props: Record<string, unknown>) => unknown);
62
- declare function ilhaJsx(type: JsxType, props: JsxProps, maybeKey?: JsxChild | string | number, ...restChildren: JsxChild[]): RawHtml;
63
- declare function ilhaFragment(props: {
64
- children?: JsxChild;
65
- } | null, ...children: JsxChild[]): RawHtml;
66
- declare function ilhaJsxDEV(type: JsxType, props: JsxProps, maybeKey?: string | number, _source?: unknown, _self?: unknown): RawHtml;
67
- declare function ilhaHtml(strings: TemplateStringsArray, ...values: unknown[]): RawHtml;
68
- type ContextSignal<T> = {
69
- (): T;
70
- (value: T): void;
71
- };
72
- declare function ilhaContext<T>(key: string, initial: T): ContextSignal<T>;
73
- /**
74
- * Create a free-standing reactive signal that lives outside any island.
75
- * Useful for sharing state across islands without prop drilling, or for
76
- * binding form inputs to module-level state via the `bind:value=${signal}`
77
- * template syntax.
78
- *
79
- * The returned accessor is a getter when called with no arguments and a
80
- * setter when called with one. Reading it inside a `.derived()`, `.effect()`,
81
- * or `.render()` automatically subscribes the surrounding reactive scope —
82
- * so when the signal changes, dependents re-run as if it were local state.
83
- */
84
- declare function ilhaSignal<T>(initial: T): SignalAccessor<T>;
85
- /**
86
- * Run `fn` with reactive tracking suspended. Reading signals inside `fn`
87
- * returns their current value without subscribing the surrounding scope.
88
- * Use this in effects/deriveds when you want to peek at state without
89
- * causing a re-run on its changes.
90
- */
91
- declare function untrack<T>(fn: () => T): T;
92
- /**
93
- * Run `fn` as an atomic batch — multiple signal writes inside the callback
94
- * produce a single propagation pass, so dependents (effects, deriveds,
95
- * island re-renders) see the final state and run once instead of once per
96
- * write. Returns whatever `fn` returns.
97
- *
98
- * Note: `.on()` handlers and `.effect()` runs are batched implicitly, so
99
- * you only need this when triggering multiple writes from outside an
100
- * island (e.g. from a top-level event listener or async callback).
101
- */
102
- declare function batch<T>(fn: () => T): T;
103
- interface DerivedValue<T> {
104
- loading: boolean;
105
- value: T | undefined;
106
- error: Error | undefined;
107
- }
108
- type DerivedAccessor<T> = {
109
- readonly loading: boolean;
110
- readonly value: T | undefined;
111
- readonly error: Error | undefined;
112
- (): T | undefined;
113
- (value: T): void;
114
- };
115
- type DerivedFnContext<TInput, TStateMap extends Record<string, unknown>> = {
116
- state: IslandState<TStateMap>;
117
- input: TInput;
118
- signal: AbortSignal;
119
- };
120
- type DerivedFn<TInput, TStateMap extends Record<string, unknown>, V> = (ctx: DerivedFnContext<TInput, TStateMap>) => V | Promise<V>;
121
- interface DerivedEntry<TInput, TStateMap extends Record<string, unknown>> {
122
- key: string;
123
- fn: DerivedFn<TInput, TStateMap, unknown>;
124
- }
125
- type IslandDerived<TDerivedMap extends Record<string, unknown>> = { readonly [K in keyof TDerivedMap]: DerivedAccessor<TDerivedMap[K]> };
126
- type ExternalSignal<T = unknown> = SignalAccessor<T>;
127
- type SignalAccessor<T> = MarkedSignalAccessor<T>;
128
- type MergeState<TStateMap extends Record<string, unknown>, K extends string, V> = Omit<TStateMap, K> & Record<K, V>;
129
- type IslandState<TStateMap extends Record<string, unknown>> = { readonly [K in keyof TStateMap]-?: SignalAccessor<TStateMap[K]> };
130
- interface HydratableOptions {
131
- name: string;
132
- as?: string;
133
- snapshot?: boolean | {
134
- state?: boolean;
135
- derived?: boolean;
136
- };
137
- skipOnMount?: boolean;
138
- }
139
- interface Island<TInput = Record<string, unknown>, _TStateMap extends Record<string, unknown> = Record<string, unknown>> {
140
- (props?: Partial<TInput>): string | Promise<string>;
141
- toString(props?: Partial<TInput>): string;
142
- mount(host: Element, props?: Partial<TInput>): () => void;
143
- hydratable(props: Partial<TInput>, options: HydratableOptions): Promise<string>;
144
- key(key: string): KeyedIsland<TInput>;
145
- [ISLAND]: true;
146
- }
147
- interface KeyedIsland<TInput> {
148
- (props?: Partial<TInput>): IslandCall;
149
- [ISLAND_CALL]: true;
150
- }
151
- type AnyIsland = Island<any, any>;
152
- type RenderContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> = {
153
- state: IslandState<TStateMap>;
154
- derived: IslandDerived<TDerivedMap>;
155
- input: TInput;
156
- };
157
- type EffectContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
158
- state: IslandState<TStateMap>;
159
- derived: IslandDerived<TDerivedMap>;
160
- input: TInput;
161
- host: Element;
162
- /**
163
- * AbortSignal that aborts when the effect re-runs (because a dependency
164
- * changed) or when the island unmounts. Pass to `fetch` or check
165
- * `signal.aborted` after `await` boundaries to bail out of stale work
166
- * without needing a manual cleanup function.
167
- */
168
- signal: AbortSignal;
169
- };
170
- type OnMountContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
171
- state: IslandState<TStateMap>;
172
- derived: IslandDerived<TDerivedMap>;
173
- input: TInput;
174
- host: Element;
175
- hydrated: boolean;
176
- };
177
- type HandlerContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
178
- state: IslandState<TStateMap>;
179
- derived: IslandDerived<TDerivedMap>;
180
- input: TInput;
181
- host: Element;
182
- target: Element;
183
- event: Event;
184
- /**
185
- * AbortSignal that fires when the island unmounts. If the handler's selector
186
- * was registered with the `:abortable` modifier, the signal is also aborted
187
- * when the same listener fires again on the same target (giving you free
188
- * race-cancellation for things like search-as-you-type fetches). Pass this
189
- * to `fetch`, `AbortController`-aware APIs, or check `signal.aborted`
190
- * after `await` boundaries to bail out of stale work.
191
- */
192
- signal: AbortSignal;
193
- };
194
- type HTMLEventFor<E extends string> = E extends keyof HTMLElementEventMap ? HTMLElementEventMap[E] : Event;
195
- type HTMLTargetFor<E extends string> = E extends keyof HTMLElementEventMap ? NonNullable<HTMLElementEventMap[E]["target"]> extends Element ? NonNullable<HTMLElementEventMap[E]["target"]> : Element : Element;
196
- type HandlerContextFor<TInput, TStateMap extends Record<string, unknown>, TEventName extends string, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
197
- state: IslandState<TStateMap>;
198
- derived: IslandDerived<TDerivedMap>;
199
- input: TInput;
200
- host: Element;
201
- target: HTMLTargetFor<TEventName>;
202
- event: HTMLEventFor<TEventName>;
203
- /**
204
- * AbortSignal that fires when the island unmounts. If the handler's selector
205
- * was registered with the `:abortable` modifier, the signal is also aborted
206
- * when the same listener fires again on the same target.
207
- */
208
- signal: AbortSignal;
209
- };
210
- type StateInit<TInput, V> = V | ((input: TInput) => V);
211
- interface StateEntry<TInput> {
212
- key: string;
213
- init: StateInit<TInput, unknown>;
214
- }
215
- interface OnEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> {
216
- selector: string;
217
- event: string;
218
- options: AddEventListenerOptions;
219
- abortable: boolean;
220
- handler: (ctx: HandlerContext<TInput, TStateMap, TDerivedMap>) => void | Promise<void>;
221
- }
222
- interface EffectEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
223
- fn: (ctx: EffectContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void;
224
- }
225
- /** Where the error originated. `"on"` covers sync throws and async rejections
226
- * from `.on()` handlers; `"effect"` covers sync throws from `.effect()` runs
227
- * (async work spawned inside an effect is not awaited by the runtime). */
228
- type ErrorSource = "on" | "effect";
229
- type ErrorContext<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> = {
230
- error: Error;
231
- source: ErrorSource;
232
- state: IslandState<TStateMap>;
233
- derived: IslandDerived<TDerivedMap>;
234
- input: TInput;
235
- host: Element;
236
- };
237
- interface OnErrorEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
238
- fn: (ctx: ErrorContext<TInput, TStateMap, TDerivedMap>) => void;
239
- }
240
- interface OnMountEntry<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
241
- fn: (ctx: OnMountContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void;
242
- }
243
- interface TransitionOptions {
244
- enter?: (host: Element) => Promise<void> | void;
245
- leave?: (host: Element) => Promise<void> | void;
246
- }
247
- interface MountOptions {
248
- root?: Element;
249
- lazy?: boolean;
250
- }
251
- interface MountResult {
252
- unmount: () => void | Promise<void>;
253
- }
254
- interface BuilderConfig<TInput, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown>> {
255
- schema: StandardSchemaV1 | null;
256
- states: StateEntry<TInput>[];
257
- deriveds: DerivedEntry<TInput, TStateMap>[];
258
- ons: OnEntry<TInput, TStateMap, TDerivedMap>[];
259
- effects: EffectEntry<TInput, TStateMap, TDerivedMap>[];
260
- onMounts: OnMountEntry<TInput, TStateMap, TDerivedMap>[];
261
- onErrors: OnErrorEntry<TInput, TStateMap, TDerivedMap>[];
262
- transition: TransitionOptions | null;
263
- css: string | null;
264
- }
265
- declare class IlhaBuilder<TInput extends Record<string, unknown>, TStateMap extends Record<string, unknown>, TDerivedMap extends Record<string, unknown> = Record<never, never>> {
266
- readonly _cfg: BuilderConfig<TInput, TStateMap, TDerivedMap>;
267
- constructor(cfg: BuilderConfig<TInput, TStateMap, TDerivedMap>);
268
- input<T extends Record<string, unknown>>(): IlhaBuilder<T, Record<never, never>, Record<never, never>>;
269
- input<S extends StandardSchemaV1>(schema: S): IlhaBuilder<StandardSchemaV1.InferOutput<S> & Record<string, unknown>, Record<never, never>, Record<never, never>>;
270
- state<V = undefined, K extends string = string>(key: K, init?: StateInit<TInput, V> | undefined): IlhaBuilder<TInput, MergeState<TStateMap, K, V>, TDerivedMap>;
271
- derived<K extends string, V>(key: K, fn: DerivedFn<TInput, TStateMap, V>): IlhaBuilder<TInput, TStateMap, TDerivedMap & Record<K, V>>;
272
- on<S extends string>(selectorOrCombined: S, handler: (ctx: S extends `${string}@${infer E}:${string}` ? HandlerContextFor<TInput, TStateMap, E, TDerivedMap> : S extends `${string}@${infer E}` ? HandlerContextFor<TInput, TStateMap, E, TDerivedMap> : HandlerContext<TInput, TStateMap, TDerivedMap>) => void | Promise<void>): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
273
- effect(fn: (ctx: EffectContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
274
- onMount(fn: (ctx: OnMountContext<TInput, TStateMap, TDerivedMap>) => (() => void) | void): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
275
- onError(fn: (ctx: ErrorContext<TInput, TStateMap, TDerivedMap>) => void): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
276
- transition(opts: TransitionOptions): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
277
- css(strings: TemplateStringsArray | string, ...values: (string | number)[]): IlhaBuilder<TInput, TStateMap, TDerivedMap>;
278
- render(fn: (ctx: RenderContext<TInput, TStateMap, TDerivedMap>) => string | RawHtml): Island<TInput, TStateMap>;
279
- }
280
- declare function ilhaFrom<TInput, TStateMap extends Record<string, unknown>>(selector: string | Element, island: Island<TInput, TStateMap>, props?: Partial<TInput>): (() => void) | null;
281
- type IslandRegistry = Record<string, AnyIsland>;
282
- declare function mountAll(registry: IslandRegistry, options?: MountOptions): MountResult;
283
- declare const ilha: IlhaBuilder<Record<string, unknown>, Record<never, never>, Record<never, never>> & {
284
- html: typeof ilhaHtml;
285
- raw: typeof ilhaRaw;
286
- jsx: typeof ilhaJsx;
287
- jsxs: typeof ilhaJsx;
288
- jsxDEV: typeof ilhaJsxDEV;
289
- Fragment: typeof ilhaFragment;
290
- mount: typeof mountAll;
291
- from: typeof ilhaFrom;
292
- context: typeof ilhaContext;
293
- signal: typeof ilhaSignal;
294
- batch: typeof batch;
295
- untrack: typeof untrack;
296
- };
297
- declare const html: typeof ilhaHtml;
298
- declare const raw: typeof ilhaRaw;
299
- declare const jsx: typeof ilhaJsx;
300
- declare const jsxs: typeof ilhaJsx;
301
- declare const jsxDEV: typeof ilhaJsxDEV;
302
- declare const Fragment: typeof ilhaFragment;
303
- declare const css: typeof ilhaCss;
304
- declare const mount: typeof mountAll;
305
- declare const from: typeof ilhaFrom;
306
- declare const context: typeof ilhaContext;
307
- //#endregion
308
- export { DerivedAccessor, DerivedValue, EffectContext, ErrorContext, ErrorSource, ExternalSignal, Fragment, HandlerContext, HandlerContextFor, HydratableOptions, ISLAND_MOUNT_INTERNAL, Island, IslandDerived, IslandState, KeyedIsland, MountOptions, MountResult, OnMountContext, RawHtml, SignalAccessor, batch, context, css, ilha as default, from, html, ilhaSignal, ilhaSignal as signal, jsx, jsxDEV, jsxs, mount, raw, untrack };
1
+ import { A as untrack, C as css, D as ilhaSignal, E as ilha, O as mount, S as context, T as html, _ as OnMountContext, a as ErrorSource, b as __ilhaJsxSlot, c as HandlerContextFor, d as Island, f as IslandDerived, g as MountResult, h as MountOptions, i as ErrorContext, k as raw, l as HydratableOptions, m as KeyedIsland, n as DerivedValue, o as ExternalSignal, p as IslandState, r as EffectContext, s as HandlerContext, t as DerivedAccessor, u as ISLAND_MOUNT_INTERNAL, v as RawHtml, w as from, x as batch, y as SignalAccessor } from "./index-Dy3wGh4z.js";
2
+ export { DerivedAccessor, DerivedValue, EffectContext, ErrorContext, ErrorSource, ExternalSignal, HandlerContext, HandlerContextFor, HydratableOptions, ISLAND_MOUNT_INTERNAL, Island, IslandDerived, IslandState, KeyedIsland, MountOptions, MountResult, OnMountContext, RawHtml, SignalAccessor, __ilhaJsxSlot, batch, context, css, ilha as default, from, html, ilhaSignal, ilhaSignal as signal, mount, raw, untrack };