@hamur/adapter-preact 0.0.0-stage → 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.
Files changed (68) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +35 -2
  3. package/dist/chunks/browser-index-89d71ade.js +118 -0
  4. package/dist/chunks/browser-index-ezte15pp.js +67 -0
  5. package/dist/chunks/browser-index-hsy7tnbg.js +21 -0
  6. package/dist/chunks/browser-index-k3m2axbw.js +274 -0
  7. package/dist/src/adapter.js +456 -0
  8. package/dist/src/error-page.js +391 -0
  9. package/dist/src/index.js +1506 -0
  10. package/dist/src/keepalive.js +6 -0
  11. package/dist/src/runtime/client.js +96 -0
  12. package/dist/src/runtime/island.js +33 -0
  13. package/dist/src/runtime/server.js +95 -0
  14. package/dist/types/src/activation.d.ts +15 -0
  15. package/dist/types/src/adapter.d.ts +2 -0
  16. package/dist/types/src/async-data.d.ts +13 -0
  17. package/dist/types/src/client-component.d.ts +11 -0
  18. package/dist/types/src/client-fallback.d.ts +2 -0
  19. package/dist/types/src/context.d.ts +81 -0
  20. package/dist/types/src/error-page.d.ts +1 -0
  21. package/dist/types/src/head.d.ts +5 -0
  22. package/dist/types/src/index.d.ts +429 -0
  23. package/dist/types/src/island-html.d.ts +13 -0
  24. package/dist/types/src/island.d.ts +19 -0
  25. package/dist/types/src/jsx-locator.d.ts +6 -0
  26. package/dist/types/src/keepalive.d.ts +26 -0
  27. package/dist/types/src/lazy-hydration.d.ts +12 -0
  28. package/dist/types/src/markdown-page.d.ts +9 -0
  29. package/dist/types/src/markdown.d.ts +12 -0
  30. package/dist/types/src/plugin.d.ts +36 -0
  31. package/dist/types/src/route-boundary.d.ts +41 -0
  32. package/dist/types/src/runtime/client.d.ts +10 -0
  33. package/dist/types/src/runtime/hmr.d.ts +31 -0
  34. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  35. package/dist/types/src/runtime/hydration.d.ts +8 -0
  36. package/dist/types/src/runtime/island.d.ts +8 -0
  37. package/dist/types/src/runtime/server.d.ts +11 -0
  38. package/dist/types/src/server-island.d.ts +10 -0
  39. package/dist/types/src/svg.d.ts +10 -0
  40. package/package.json +71 -4
  41. package/src/activation.ts +51 -0
  42. package/src/adapter.ts +35 -0
  43. package/src/async-data.ts +65 -0
  44. package/src/client-component.ts +23 -0
  45. package/src/client-fallback.ts +2 -0
  46. package/src/context.ts +372 -0
  47. package/src/env.d.ts +3 -0
  48. package/src/error-page.ts +1 -0
  49. package/src/head.ts +34 -0
  50. package/src/index.ts +1868 -0
  51. package/src/island-html.ts +58 -0
  52. package/src/island.ts +56 -0
  53. package/src/jsx-locator.ts +199 -0
  54. package/src/keepalive.ts +100 -0
  55. package/src/lazy-hydration.ts +101 -0
  56. package/src/markdown-page.ts +18 -0
  57. package/src/markdown.ts +58 -0
  58. package/src/plugin.ts +231 -0
  59. package/src/route-boundary.ts +51 -0
  60. package/src/runtime/client.ts +85 -0
  61. package/src/runtime/hmr.ts +141 -0
  62. package/src/runtime/hydration-dev.ts +8 -0
  63. package/src/runtime/hydration.ts +7 -0
  64. package/src/runtime/island.ts +37 -0
  65. package/src/runtime/server.ts +102 -0
  66. package/src/server-island.ts +35 -0
  67. package/src/svg.ts +27 -0
  68. package/src/webmcp.d.ts +18 -0
@@ -0,0 +1,429 @@
1
+ import { Component } from "preact";
2
+ import type { SyncedStateOptions } from "hamur/app";
3
+ import type { ComponentChildren, CSSProperties, FunctionComponent, TimeHTMLAttributes } from "preact";
4
+ import { useId } from "preact/hooks";
5
+ import { clearState as clearStateOf } from "hamur/app";
6
+ import type { PreviewMode } from "hamur/app";
7
+ import type { $Fetch, FetchCheckedInput, FetchInputField } from "hamur/app";
8
+ import type { StateKey } from "hamur/app";
9
+ import type { HamurEvent } from "hamur/server";
10
+ import type { AppHooks, WebVitalMetric } from "hamur/app";
11
+ import type { AnnouncerActions, AnnouncerPoliteness, AnnouncerState, RouteAnnouncerActions, RouteAnnouncerPoliteness, RouteAnnouncerState, LoadingIndicatorActions, LoadingIndicatorProps, LoadingIndicatorOptions, LoadingIndicatorState, TimeInput } from "hamur/adapter";
12
+ import type { LinkDefaults, LinkSlot, UseLinkOptions } from "hamur/adapter";
13
+ import type { ActionOptions, ActionRunner, FormStatus, PrefetchOn, Handler, AfterNavigateHook, BeforeNavigateHook, NavigateHook, Navigation, NavigationBlocker, NavigationGuard, Blocker, ShouldBlock, UseBlockerOptions, SnapshotOptions } from "hamur/adapter";
14
+ import type { HandlerForm, HamurLinkProps } from "hamur/app";
15
+ import type { RouteLoaderData, UseDataArgs, AsyncDataHandler, ErrorBoundaryFallbackProps, FetchRequest, GetCachedData, CheckedTarget, NavigationState, RouteValue, RouterApi } from "hamur/adapter";
16
+ import type { ActionFailure, AppContext, FormSubmitArgs, PendingRun, PickFrom, RouteLocation, ClientRuntimeConfig, SiteConfig, FetchData, AsyncDataOptions, AsyncDataStatus, UseCookieOptions, ErrorPageProps, HeadInput, HeadSafeInput, SeoMetaInput, HamurError } from "hamur/app";
17
+ export { addRouteMiddleware, clearError, disableScrollHandling, forbidden, navigateTo, notFound, permanentRedirect, refreshCookie, setPageLayout, showError, unauthorized, } from "hamur/app";
18
+ export { defineLazyHydrationComponent } from "./lazy-hydration.ts";
19
+ export { Island } from "./island.ts";
20
+ export type { IslandProps } from "./island.ts";
21
+ export { ServerIsland } from "./server-island.ts";
22
+ export type { ServerIslandProps } from "./server-island.ts";
23
+ export { MarkdownRenderer } from "./markdown.ts";
24
+ export type { MarkdownRendererProps } from "./markdown.ts";
25
+ import type { SetSearch } from "hamur/adapter";
26
+ import type { AppUpdateActions, AppUpdateState } from "hamur/adapter";
27
+ import type { MatchedRoute, RouteDataName, RouteDataOf, RouteError, RouteFor, RouteName } from "hamur/adapter";
28
+ export type { MatchedRoute, RouteDataName, RouteDataOf } from "hamur/adapter";
29
+ export type { NavigateToOptions, PickFrom } from "hamur/app";
30
+ export type { Blocker, BlockerArgs, SnapshotOptions, UseBlockerOptions } from "hamur/adapter";
31
+ export type { AfterNavigateHook, AsyncDataHandler, BeforeNavigateHook, ErrorBoundaryFallbackProps, FetchRequest, GetCachedData, GetCachedDataCause, NavigateHook, NavigateOptions, Navigation, NavigationState, NavigationType, RouteValue, RouterApi, } from "hamur/adapter";
32
+ export type { LinkDefaults, LinkSlot, UseLinkOptions } from "hamur/adapter";
33
+ interface LinkBaseProps extends Record<string, unknown>, HamurLinkProps {
34
+ replace?: boolean;
35
+ prefetch?: boolean;
36
+ prefetchOn?: PrefetchOn;
37
+ /** Removed: write `to`. */
38
+ href?: never;
39
+ /** Removed: write `prefetch={false}`. */
40
+ noPrefetch?: never;
41
+ /** The query as a function of the validated search of the page on screen. */
42
+ query?: (prev: RouteValue["search"]) => RouteValue["search"];
43
+ /** A serializable object kept in the history entry the click pushes, read as `useRoute().state`. */
44
+ state?: Record<string, unknown>;
45
+ /** `"route"` resolves a relative `to` against the path of the route, its pattern filled with its params, not the URL. */
46
+ relative?: "route";
47
+ /** The app path the address bar shows while `to` renders. */
48
+ mask?: string;
49
+ /** `false` renders `to` again after a reload of the masked entry. */
50
+ unmaskOnReload?: boolean;
51
+ /** `true` or `{ types }` runs this navigation in a view transition, `false` turns it off. */
52
+ viewTransition?: boolean | {
53
+ types: readonly string[];
54
+ };
55
+ activeClass?: string;
56
+ exactActiveClass?: string;
57
+ /** The class the navigator adds to this anchor while a navigation to it is in flight; `""` adds none. */
58
+ pendingClass?: string;
59
+ ariaCurrentValue?: "page" | "step" | "location" | "date" | "time" | "true";
60
+ /** A plain link the navigator never intercepts, with no prefetch and `rel="external"`. */
61
+ external?: boolean;
62
+ /** No `rel` is added for a `target="_blank"` or an other-origin `to`. */
63
+ noRel?: boolean;
64
+ /** The class the navigator adds to this anchor once its prefetch finished. */
65
+ prefetchedClass?: string;
66
+ /** `false` keeps the scroll position for the navigation the click starts. */
67
+ scroll?: boolean;
68
+ /** ms a hover or focus waits before it prefetches; one that ends sooner prefetches nothing. */
69
+ prefetchDelay?: number;
70
+ /** Runs for a navigation this anchor started, after the `onBeforeNavigate` hooks; `nav.cancel()` stops it. */
71
+ onBeforeNavigate?: (nav: Navigation) => void;
72
+ /** A function renders the link itself: it is given the `LinkSlot` and `Link` renders only what it returns. */
73
+ children?: ComponentChildren | ((link: LinkSlot) => ComponentChildren);
74
+ }
75
+ /** `T` is the string `to`, which is checked against the route table. */
76
+ export type LinkProps<T extends string = string> = LinkBaseProps & {
77
+ to: CheckedTarget<T> | RouteLocation;
78
+ };
79
+ export declare function Link<T extends string = string>(props: LinkProps<T>): import("preact").VNode<{
80
+ link: LinkProps;
81
+ defaults: LinkDefaults;
82
+ }>;
83
+ /** A `Link` with `defaults` over `app.link`; a prop of the element wins. */
84
+ export declare function defineLink(defaults: LinkDefaults): typeof Link;
85
+ /** The `LinkSlot` of a link to `to`, for an element that renders its own `<a>`; `app.link` sets its defaults. */
86
+ export declare function useLink<T extends string = string>(to: CheckedTarget<T> | RouteLocation, options?: UseLinkOptions): LinkSlot;
87
+ export interface NavigateProps<T extends string = string> {
88
+ to: CheckedTarget<T, false> | RouteLocation;
89
+ replace?: boolean;
90
+ }
91
+ /** Navigates to `to` once after mount; during SSR it throws the redirect `navigateTo` throws there. */
92
+ export declare function Navigate<T extends string = string>({ to, replace }: NavigateProps<T>): null;
93
+ interface FormBaseProps extends Record<string, unknown> {
94
+ encType?: "application/x-www-form-urlencoded" | "multipart/form-data";
95
+ replace?: boolean;
96
+ reset?: boolean;
97
+ reloadDocument?: boolean;
98
+ refresh?: boolean;
99
+ /** With a server function: the store of `useAction(fn, { instance })` this form belongs to. */
100
+ instance?: string | number;
101
+ restore?: boolean;
102
+ onSubmit?: (args: FormSubmitArgs) => void;
103
+ children?: ComponentChildren;
104
+ }
105
+ export type FormProps<N extends string = string> = FormBaseProps &
106
+ /** A server function posts to this page with `?_fn=<id>`. */
107
+ ({
108
+ action: ((...args: never[]) => unknown) & {
109
+ readonly url: string;
110
+ };
111
+ method?: "post";
112
+ } | {
113
+ action?: string | (RouteLocation & {
114
+ name: N;
115
+ });
116
+ method?: "get";
117
+ });
118
+ export declare function Form<N extends string = string>({ action, method, encType, replace, reset, reloadDocument, refresh, instance, restore, onSubmit, children, ...rest }: FormProps<N>): import("preact").VNode<{
119
+ value: import("hamur/adapter").FormStatusStore | null;
120
+ children?: ComponentChildren;
121
+ }>;
122
+ export declare function useFormStatus(): FormStatus;
123
+ export declare function useForm<I, O>(fn: Handler<I, O>): HandlerForm<I, O>;
124
+ export interface UseActionResult<I, O> {
125
+ run: ActionRunner<I, O>["run"];
126
+ state: O | undefined;
127
+ pending: boolean;
128
+ error: HamurError | undefined;
129
+ failure: ActionFailure | undefined;
130
+ reset(): void;
131
+ }
132
+ export declare function useAction<I, O>(fn: Handler<I, O>, options?: ActionOptions<O> & {
133
+ instance?: string | number;
134
+ }): UseActionResult<I, O>;
135
+ export declare function useRoute<N extends RouteName>(name: N): RouteFor<N>;
136
+ export declare function useRoute<N extends RouteName = never>(): RouteFor<N>;
137
+ export declare function useRoute(): RouteValue;
138
+ export declare function useResolvedPath(to: string, { relative }?: {
139
+ relative?: "route";
140
+ }): string;
141
+ export declare function useRouter(): RouterApi;
142
+ export declare function useData<T = unknown>(...unknownRoute: UseDataArgs<T>): RouteLoaderData<T>;
143
+ export declare function useRouteData<N extends RouteDataName>(name: N): RouteDataOf<N>;
144
+ export declare function useMatches(): MatchedRoute[];
145
+ export declare function Outlet({ context, name }: {
146
+ context?: unknown;
147
+ name?: string;
148
+ }): string | number | bigint | boolean | object | null;
149
+ export declare function useOutletContext<T = unknown>(): T;
150
+ export declare function useLayoutSegments(): string[];
151
+ export declare function useLayoutSegment(): string | null;
152
+ export declare function useLayout(): {
153
+ name: string | false;
154
+ props: Record<string, unknown>;
155
+ };
156
+ export declare function ClientOnly({ children, fallback }: {
157
+ children?: ComponentChildren;
158
+ fallback?: ComponentChildren;
159
+ }): string | number | bigint | boolean | object | null;
160
+ export { useId };
161
+ export declare function useHydrated(): boolean;
162
+ export declare function DevOnly({ children, fallback }: {
163
+ children?: ComponentChildren;
164
+ fallback?: ComponentChildren;
165
+ }): ComponentChildren;
166
+ export interface AwaitProps<T> {
167
+ resolve: T;
168
+ fallback?: ComponentChildren;
169
+ error?: (error: Error) => ComponentChildren;
170
+ children: (value: Awaited<T>) => ComponentChildren;
171
+ }
172
+ export declare function Await<T>({ fallback, ...props }: AwaitProps<T>): ComponentChildren;
173
+ export declare function useDeferred<T>(promise: T): Awaited<T>;
174
+ export type TimeProps = TimeInput & Omit<TimeHTMLAttributes<HTMLTimeElement>, keyof TimeInput>;
175
+ export declare function Time(props: TimeProps): import("preact").VNode<{
176
+ datetime: string;
177
+ "data-locale": string;
178
+ "data-time-zone": string;
179
+ }>;
180
+ export type { LoadingIndicatorProps } from "hamur/adapter";
181
+ export declare function useLoadingIndicator(options?: LoadingIndicatorOptions): LoadingIndicatorState & LoadingIndicatorActions;
182
+ export declare function useAppUpdate(): AppUpdateState & AppUpdateActions;
183
+ export declare function LoadingIndicator(props: LoadingIndicatorProps): import("preact").VNode<import("preact").ClassAttributes<HTMLDivElement> & {
184
+ ref: import("preact").RefObject<HTMLDivElement | null>;
185
+ "data-hamur-loading-indicator": string;
186
+ "aria-hidden": "true";
187
+ }>;
188
+ export declare function useRouteAnnouncer(): RouteAnnouncerState & RouteAnnouncerActions;
189
+ export declare function RouteAnnouncer({ politeness, class: className, style, }: {
190
+ politeness?: RouteAnnouncerPoliteness;
191
+ class?: string;
192
+ style?: CSSProperties | string;
193
+ children?: ComponentChildren;
194
+ }): import("preact").VNode<import("preact").ClassAttributes<HTMLDivElement> & {
195
+ ref: import("preact").RefObject<HTMLDivElement | null>;
196
+ id: string;
197
+ "aria-live": RouteAnnouncerPoliteness;
198
+ "aria-atomic": "true";
199
+ role: "alert" | "status" | undefined;
200
+ class: string | undefined;
201
+ style: string | CSSProperties | undefined;
202
+ }> | import("preact").VNode<import("preact").ClassAttributes<HTMLElement> & {
203
+ "aria-live": "off";
204
+ "aria-atomic": "true";
205
+ }>;
206
+ export declare function useAnnouncer({ politeness }?: {
207
+ politeness?: AnnouncerPoliteness;
208
+ }): Pick<AnnouncerState, "message" | "politeness"> & AnnouncerActions;
209
+ export declare function Announcer(): import("preact").VNode<{}>;
210
+ export declare function useApp(): AppContext;
211
+ export declare function useRuntimeHook<K extends keyof AppHooks>(name: K, fn: AppHooks[K]): void;
212
+ export declare function useReportWebVitals(fn: (metric: WebVitalMetric) => void | Promise<void>): void;
213
+ export declare function onAppReady(fn: () => void | Promise<void>): void;
214
+ export declare function onPrehydrate(fn: (el: Element) => void): string | undefined;
215
+ export declare function useRequestEvent(): HamurEvent | undefined;
216
+ /** Preview mode: enabled by the payload's `draft` or by `?preview=true` on the first URL; `state` is the app's own store for preview values. */
217
+ export declare function usePreviewMode(): PreviewMode;
218
+ export declare function useRequestHeaders(names?: readonly string[]): Record<string, string>;
219
+ export declare function useRequestHeader(name: string): string | undefined;
220
+ export declare function useRequestURL(): URL;
221
+ export declare function useRequestFetch(): $Fetch;
222
+ export declare function setResponseStatus(status: number, statusText?: string): void;
223
+ export declare function useResponseHeader(name: string): [string | undefined, (value: string | undefined) => void];
224
+ export declare function HttpStatusCode({ code, text }: {
225
+ code: number;
226
+ text?: string;
227
+ }): null;
228
+ export declare function HttpHeader({ name, value }: {
229
+ name: string;
230
+ value: string;
231
+ }): null;
232
+ export declare function useAsyncDataEntry<T = unknown>(key: string): {
233
+ data: T | undefined;
234
+ setData(data: T): void;
235
+ };
236
+ export declare function useAsyncDataEntry<I, O>(fn: Handler<I, O>, input?: I): {
237
+ data: O | undefined;
238
+ setData(data: O): void;
239
+ };
240
+ export declare function clearState(keys?: Parameters<typeof clearStateOf>[1], options?: {
241
+ reset?: boolean;
242
+ }): void;
243
+ export declare function callOnce(key: string, fn: () => unknown | Promise<unknown>, options?: {
244
+ mode?: "render" | "navigation";
245
+ }): Promise<void>;
246
+ export declare function useRuntimeConfig(): ClientRuntimeConfig;
247
+ export declare function useSiteConfig(): SiteConfig;
248
+ export declare function useNavigation(): NavigationState;
249
+ /** Inside a `Link`'s children, whether a navigation to that link is in flight; `{ pending: false }` anywhere else. */
250
+ export declare function useLinkStatus(): {
251
+ pending: boolean;
252
+ };
253
+ export declare const onBeforeNavigate: (fn: BeforeNavigateHook) => void;
254
+ export declare const onNavigate: (fn: NavigateHook) => void;
255
+ export declare const onAfterNavigate: (fn: AfterNavigateHook) => void;
256
+ /** Runs `fn` after the component mounts and each time its kept page is shown again. */
257
+ export declare function onPageActivated(fn: () => void): void;
258
+ /** Runs `fn` each time its kept page is hidden and when the component unmounts on screen. */
259
+ export declare function onPageDeactivated(fn: () => void): void;
260
+ export declare const onBeforeRouteLeave: (fn: NavigationGuard) => void;
261
+ export declare const onBeforeRouteUpdate: (fn: NavigationGuard) => void;
262
+ export declare function usePreventNavigate(fn: NavigationBlocker): void;
263
+ export declare function useBlocker(options: ShouldBlock | UseBlockerOptions): Blocker;
264
+ export declare function useSnapshot<T>(key: string, options: SnapshotOptions<T>): void;
265
+ export declare function useSearch(): {
266
+ value: RouteValue["search"];
267
+ set: SetSearch;
268
+ };
269
+ export declare function useSearch<S>(select: (search: RouteValue["search"]) => S): {
270
+ value: S;
271
+ set: SetSearch;
272
+ };
273
+ export declare function usePoll(ms: number, options?: {
274
+ keys?: string[];
275
+ }): void;
276
+ export declare function useOnline(): boolean;
277
+ export declare function useSyncedState<T>(key: string, initial: T, options?: SyncedStateOptions): [T, (value: T) => void];
278
+ export declare function useOptimistic<T, A = PendingRun>(value: T, reduce: (current: T, pending: A[]) => T): T;
279
+ export declare function useError(): RouteError | undefined;
280
+ export interface ErrorBoundaryProps {
281
+ fallback: (props: ErrorBoundaryFallbackProps) => ComponentChildren;
282
+ children?: ComponentChildren;
283
+ }
284
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
285
+ failed: boolean;
286
+ error: unknown;
287
+ }> {
288
+ state: {
289
+ failed: boolean;
290
+ error: unknown;
291
+ };
292
+ key: string | undefined;
293
+ app: AppContext | null;
294
+ static getDerivedStateFromError(error: unknown): {
295
+ failed: boolean;
296
+ error: unknown;
297
+ };
298
+ reset: () => void;
299
+ render(): ComponentChildren;
300
+ }
301
+ export interface ClientFallbackProps {
302
+ fallback?: ComponentChildren;
303
+ keepFallback?: boolean;
304
+ onSsrError?: (error: unknown) => unknown;
305
+ children?: ComponentChildren;
306
+ }
307
+ /** A throw in `children` during SSR renders `fallback` in the HTML; the browser renders `children` again from scratch. */
308
+ export declare class ClientFallback extends Component<ClientFallbackProps, {
309
+ failed: boolean;
310
+ error: unknown;
311
+ }> {
312
+ state: {
313
+ failed: boolean;
314
+ error: unknown;
315
+ };
316
+ id: string | undefined;
317
+ app: AppContext | null;
318
+ static getDerivedStateFromError(error: unknown): {
319
+ failed: boolean;
320
+ error: unknown;
321
+ };
322
+ render(): string | number | bigint | boolean | object | null;
323
+ }
324
+ export declare function DefaultErrorPage({ error }: {
325
+ error: ErrorPageProps;
326
+ }): import("preact").VNode<import("preact").ClassAttributes<HTMLElement> & {
327
+ style: {
328
+ fontFamily: string;
329
+ textAlign: string;
330
+ padding: string;
331
+ };
332
+ }>;
333
+ export declare function useHead(input: HeadInput): void;
334
+ export declare function useSeoMeta(input: SeoMetaInput): void;
335
+ type ServerHeadInput = Omit<HeadInput, "title" | "titleTemplate">;
336
+ type ServerSeoMetaInput = Omit<SeoMetaInput, "title" | "titleTemplate">;
337
+ export declare function useHeadSafe(input: HeadSafeInput): void;
338
+ type HeadProps<K extends "meta" | "link" | "script" | "style"> = NonNullable<HeadInput[K]>[number];
339
+ type HeadAttrsProps = Record<string, string>;
340
+ export declare function HeadTitle({ title, template }: {
341
+ title: string;
342
+ template?: string;
343
+ }): null;
344
+ export declare const HeadMeta: FunctionComponent<HeadProps<"meta">>;
345
+ export declare const HeadLink: FunctionComponent<HeadProps<"link">>;
346
+ export declare const HeadScript: FunctionComponent<HeadProps<"script">>;
347
+ export declare const HeadStyle: FunctionComponent<HeadProps<"style">>;
348
+ export declare const HtmlAttrs: FunctionComponent<HeadAttrsProps>;
349
+ export declare const BodyAttrs: FunctionComponent<HeadAttrsProps>;
350
+ export declare function useServerHead(input: ServerHeadInput): void;
351
+ export declare function useServerSeoMeta(input: ServerSeoMetaInput): void;
352
+ export declare function useState<T>(key: StateKey<T>): [T, (value: T | ((previous: T) => T)) => void];
353
+ export declare function useState<T>(key: string, init?: T | (() => T)): [T, (value: T | ((previous: T) => T)) => void];
354
+ export declare function useCookie<T = string>(name: string, options: Omit<UseCookieOptions<T>, "app"> & {
355
+ default: () => T;
356
+ }): [T, (value: T | undefined) => void];
357
+ export declare function useCookie<T = string>(name: string, options?: Omit<UseCookieOptions<T>, "app">): [T | undefined, (value: T | undefined) => void];
358
+ export interface UseAsyncDataOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends Omit<AsyncDataOptions<T, R, D>, "pick"> {
359
+ /** Values that re-run the handler when they change. `false` is accepted and does nothing: nothing watches implicitly. */
360
+ watch?: readonly unknown[] | false;
361
+ getCachedData?: GetCachedData<T>;
362
+ /** Top-level keys of an object result to keep. */
363
+ pick?: readonly K[];
364
+ }
365
+ export interface UseAsyncDataResult<T, D = undefined> {
366
+ data: T | D;
367
+ error: HamurError | undefined;
368
+ status: AsyncDataStatus;
369
+ /** `status === "pending"`, or `idle` without data under `app.asyncData.pendingWhenIdle`. */
370
+ pending: boolean;
371
+ refresh(): Promise<void>;
372
+ /** The same function as `refresh`. */
373
+ execute(): Promise<void>;
374
+ /** Resets the entry of this key to `idle` (`clearAsyncData`). */
375
+ clear(): void;
376
+ }
377
+ export interface UseFetchOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends FetchRequest, UseAsyncDataOptions<T, R, K, D> {
378
+ /** The store key, instead of the one derived from the url and the request. */
379
+ key?: string;
380
+ }
381
+ export declare function useAsyncData<I, R, T = R, K extends keyof T & string = never, D = T>(fn: Handler<I, R>, input: NoInfer<I> | (() => NoInfer<I>) | undefined, options: UseAsyncDataOptions<T, R, K, D> & {
382
+ default: () => D;
383
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
384
+ export declare function useAsyncData<I, R, T = R, K extends keyof T & string = never>(fn: Handler<I, R>, input?: NoInfer<I> | (() => NoInfer<I>), options?: UseAsyncDataOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
385
+ export declare function useAsyncData<T = unknown, R = T, K extends keyof T & string = never, D = T>(keyOrGetter: string | (() => string), handler: AsyncDataHandler<R>, options: UseAsyncDataOptions<T, R, K, D> & {
386
+ default: () => D;
387
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
388
+ export declare function useAsyncData<T = unknown, R = T, K extends keyof T & string = never>(keyOrGetter: string | (() => string), handler: AsyncDataHandler<R>, options?: UseAsyncDataOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
389
+ /** What a literal `useFetch` call is checked against; any other call stays loose. */
390
+ type FetchInput<X> = X extends {
391
+ key: infer K extends string;
392
+ input: infer I;
393
+ } ? FetchInputField<I, K, I | (() => I)> : unknown;
394
+ type Unkeyed<O, X> = X extends {
395
+ key: infer K extends string;
396
+ } ? Omit<O, K> : O;
397
+ type FetchCall<U extends string, M extends string, B extends string | undefined> = {
398
+ method?: M | string;
399
+ baseURL?: B | string;
400
+ } & FetchInput<FetchCheckedInput<U, M, B>>;
401
+ export declare function useFetch<U extends string, M extends string = "GET", K extends keyof FetchData<U, M> & string = never, D = undefined, B extends string | undefined = undefined>(url: U | (() => U), options?: Unkeyed<UseFetchOptions<FetchData<U, M>, FetchData<U, M>, K, D>, FetchCheckedInput<U, M, B>> & FetchCall<U, M, B>): UseAsyncDataResult<PickFrom<FetchData<U, M>, K>, D>;
402
+ export declare function useFetch<T = unknown, R = T, K extends keyof T & string = never, D = T, U extends string = string, M extends string = "GET", B extends string | undefined = undefined>(urlOrGetter: U | (() => U), options: Unkeyed<UseFetchOptions<T, R, K, D>, FetchCheckedInput<U, M, B>> & {
403
+ default: () => D;
404
+ } & FetchCall<U, M, B>): UseAsyncDataResult<PickFrom<T, K>, D>;
405
+ export declare function useFetch<T = unknown, R = T, K extends keyof T & string = never, U extends string = string, M extends string = "GET", B extends string | undefined = undefined>(urlOrGetter: U | (() => U), options?: Unkeyed<UseFetchOptions<T, R, K, undefined>, FetchCheckedInput<U, M, B>> & FetchCall<U, M, B>): UseAsyncDataResult<PickFrom<T, K>>;
406
+ /** `createUseFetch` defaults change what a call sends (method, body, query, baseURL), so its calls check nothing. */
407
+ interface UseFetchLoose {
408
+ <U extends string, M extends string = "GET", K extends keyof FetchData<U, M> & string = never, D = undefined>(url: U | (() => U), options?: UseFetchOptions<FetchData<U, M>, FetchData<U, M>, K, D> & {
409
+ method?: M;
410
+ }): UseAsyncDataResult<PickFrom<FetchData<U, M>, K>, D>;
411
+ <T = unknown, R = T, K extends keyof T & string = never, D = T>(url: string | (() => string), options: UseFetchOptions<T, R, K, D> & {
412
+ default: () => D;
413
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
414
+ <T = unknown, R = T, K extends keyof T & string = never>(url: string | (() => string), options?: UseFetchOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
415
+ }
416
+ type AnyFetchOptions = UseFetchOptions<any, any, any, any>;
417
+ /** `useFetch` with `defaults` under every call's options; `$fetch` replaces the request-bound client, e.g. a `$fetch.create` one. */
418
+ export declare function createUseFetch(defaults: AnyFetchOptions | ((options: AnyFetchOptions) => AnyFetchOptions), { $fetch: client }?: {
419
+ $fetch?: $Fetch;
420
+ }): UseFetchLoose;
421
+ /** `useAsyncData` with `defaults` under every call's options. */
422
+ export declare function createUseAsyncData(defaults: UseAsyncDataOptions<any, any, any, any> | ((options: UseAsyncDataOptions<any, any, any, any>) => UseAsyncDataOptions<any, any, any, any>)): typeof useAsyncData;
423
+ export declare const useLazyFetch: typeof useFetch;
424
+ export declare const useLazyAsyncData: typeof useAsyncData;
425
+ export declare function transitionName(name: string): {
426
+ style: {
427
+ viewTransitionName: string;
428
+ };
429
+ };
@@ -0,0 +1,13 @@
1
+ import type { AppContext } from "hamur/app";
2
+ /**
3
+ * The HTML of an island whose root has finished rendering (or the attributes of a server island), or `undefined` while it renders, recorded in `pending`
4
+ * so the render is done again once it has settled. A failed island throws where its `Island` renders, so the nearest
5
+ * route boundary shows the error. An island's HTML is always rendered in its place, never spliced into the markup.
6
+ */
7
+ export declare function settledIsland<T = string>(promise: Promise<T>, pending?: Promise<void>[] | undefined): T | undefined;
8
+ /** Runs a synchronous render whose `Island`s record the islands still rendering in `pending`. */
9
+ export declare function collectingIslands<T>(pending: Promise<void>[], render: () => T): T;
10
+ /** A pass of `renderInPasses` that met islands still rendering waits for them and is dropped, so the next pass renders them in place. */
11
+ export declare function islandsSettled(app: AppContext, pending: Promise<void>[]): Promise<void>;
12
+ /** An island's own root, rendered again until every island inside it has settled. */
13
+ export declare function renderSettled<T>(render: (pending: Promise<void>[]) => T | Promise<T>): Promise<T>;
@@ -0,0 +1,19 @@
1
+ import type { ComponentChild, ComponentType } from "preact";
2
+ import { type IslandOn } from "hamur/adapter";
3
+ export interface IslandProps<P extends object> {
4
+ /** The default export of a file under `app/islands/`. */
5
+ component: ComponentType<P>;
6
+ props?: P;
7
+ /** The island directive: when the island hydrates, `"only"` to mount it in the browser alone, or a directive a module adds; default `"load"`. */
8
+ on?: IslandOn;
9
+ /** The island's id across swaps; a swap to a page with the same id keeps its element and state. */
10
+ persist?: string;
11
+ /** With `persist`, a swap keeps the island's old props. */
12
+ persistProps?: boolean;
13
+ /** What the server renders in place of the island under `on="only"`. */
14
+ fallback?: ComponentChild;
15
+ /** Rendered on the server only and given to the island as its `children`, inside `<hamur-slot>`; never hydrated. */
16
+ children?: ComponentChild;
17
+ }
18
+ /** On an island page, `component` rendered as a root of its own inside `<hamur-island>`, hydrated on its own in the browser. */
19
+ export declare function Island<P extends object>({ component, props, on, fallback, children, persist, persistProps, }: IslandProps<P>): ComponentChild;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The source locator: adds `data-hamur-src="<file>:<line>:<column>"` to the host element each component of
3
+ * `source` returns from its own body (a capitalised function or arrow, a default export, `memo` and `forwardRef`
4
+ * around one); the position is the element's `<`, 1-based. Insertions stay on their line, so no line moves.
5
+ */
6
+ export declare function locateJsx(source: string, file: string): string;
@@ -0,0 +1,26 @@
1
+ import type { ComponentChildren, Context, VNode, createElement, Fragment } from "preact";
2
+ import type { useContext, useLayoutEffect, useMemo } from "preact/hooks";
3
+ import type { KeptUnit, RenderEntry, RenderTree, RouteValue } from "hamur/adapter";
4
+ import type { Activation, activation, detach, setHidden } from "./activation.ts";
5
+ import type { Source, routeValue } from "./context.ts";
6
+ /** What the outlet takes from the adapter's base: this module imports nothing at run time, so loading it splits no chunk of the base. */
7
+ export interface KeepAliveBase {
8
+ createElement: typeof createElement;
9
+ Fragment: typeof Fragment;
10
+ useContext: typeof useContext;
11
+ useMemo: typeof useMemo;
12
+ useLayoutEffect: typeof useLayoutEffect;
13
+ ActivationContext: Context<Activation | undefined>;
14
+ activation: typeof activation;
15
+ detach: typeof detach;
16
+ setHidden: typeof setHidden;
17
+ RouteContext: Context<RouteValue | null>;
18
+ DataContext: Context<Record<string, unknown>>;
19
+ routeValue: typeof routeValue;
20
+ nest(tree: RenderTree, ctx: Source): ComponentChildren | undefined;
21
+ }
22
+ export type KeptOutlet = (holder: {
23
+ kept?: KeptUnit[];
24
+ }, below: RenderEntry | undefined, child: ComponentChildren | undefined, ctx: Source) => VNode[];
25
+ /** The outlet of `holder` (an entry, or the tree's top level): each kept unit hidden under its own route, payload and tree, then the current child, keyed by the keep-alive key, so a page keeps its instance between the two. */
26
+ export declare function createKeptOutlet({ createElement, Fragment, useContext, useMemo, useLayoutEffect, ActivationContext, activation, detach, setHidden, RouteContext, DataContext, routeValue, nest, }: KeepAliveBase): KeptOutlet;
@@ -0,0 +1,12 @@
1
+ import type { ComponentType } from "preact";
2
+ import type { HydrateOn, HydrateOnOptions } from "hamur/adapter";
3
+ type Module<P> = {
4
+ default: ComponentType<P>;
5
+ };
6
+ /** The server renders synchronously, so `render` awaits the lazy modules still loading before each pass. */
7
+ export declare function lazyModules(): Promise<unknown> | undefined;
8
+ /** Renders the component on the server and, after hydration, keeps its server DOM until `on` fires; after a client navigation it mounts at once. */
9
+ export declare function defineLazyHydrationComponent<P extends object>(on: HydrateOn, loader: () => Promise<Module<P>>, options?: Omit<HydrateOnOptions, "signal">): ComponentType<P & {
10
+ onHydrated?: () => void;
11
+ }>;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { MarkdownSource } from "hamur/adapter";
2
+ declare function module(source: MarkdownSource): {
3
+ contents: string;
4
+ extension: string;
5
+ };
6
+ export declare const markdownComponent: {
7
+ module: typeof module;
8
+ };
9
+ export {};
@@ -0,0 +1,12 @@
1
+ import { type ComponentType, type VNode } from "preact";
2
+ import type { MarkdownDocument, MdNode } from "hamur/markdown";
3
+ export interface MarkdownRendererProps {
4
+ /** A Markdown AST node, a list of nodes, or a document, which renders its `ast`. */
5
+ value: MdNode | MdNode[] | MarkdownDocument;
6
+ /** Components by Markdown component name (kebab case); each gets the node's props as written, `children` and a prop per named slot. */
7
+ components?: Record<string, ComponentType<any>>;
8
+ /** Renders `html` nodes, writing what it returns as their inner HTML; without it they are left out. A Markdown page under config `markdown.html` passes the core's Trusted Types writer. */
9
+ raw?: (html: string) => string;
10
+ }
11
+ /** Renders the Markdown AST as Preact elements, an internal link as `Link`, a component node as its component in `components`. */
12
+ export declare function MarkdownRenderer({ value, components: given, raw }: MarkdownRendererProps): VNode;
@@ -0,0 +1,36 @@
1
+ import type { AdapterBuildContext, AdapterTransform } from "hamur/adapter";
2
+ /**
3
+ * One `<binding>=<call>` entry per call in source order; the calls in `withArguments`
4
+ * also carry their arguments, so reordering or swapping two of them changes the signature.
5
+ */
6
+ export declare function refreshSignature(source: string, calls: RegExp, withArguments: ReadonlySet<string>): string;
7
+ export interface RefreshOptions {
8
+ /** Path relative to `rootDir`, also the module's key in the hot runtime. */
9
+ id: string;
10
+ /** Pages, layouts and `app.<ext>` accept themselves even with other exports (`meta`). */
11
+ route: boolean;
12
+ runtime?: string;
13
+ }
14
+ export interface RefreshResult {
15
+ code: string;
16
+ signature: string;
17
+ accepted: boolean;
18
+ }
19
+ /**
20
+ * Wraps every component export in the hot runtime and bakes the module's refresh signature. A component is
21
+ * a capitalised function or arrow whose declaration renders JSX. Its binding stays the module's own (a hoisted
22
+ * `function` or a `let`) and is reassigned to the wrapper at the end, so the export, a circular importer and the
23
+ * module's other components all see the wrapper once the module has run.
24
+ */
25
+ export declare function refreshTransform(source: string, { id, route, runtime }: RefreshOptions): RefreshResult;
26
+ /** The module's path relative to `rootDir` when it is an app source (not under `node_modules` or the build dir). */
27
+ export declare function appModuleId(rootDir: string, buildDir: string): (path: string) => string | undefined;
28
+ export declare function preactPlugin(ctx: AdapterBuildContext): AdapterTransform;
29
+ /** The source locator: in `hamur dev`, each app component's root host element gets `data-hamur-src`, on the server and in the client alike. */
30
+ export declare function preactLocatorPlugin(ctx: AdapterBuildContext): AdapterTransform;
31
+ /** A production build empties the children of every `<DevOnly>` imported from `@hamur/adapter-preact`. */
32
+ export declare function preactProductionPlugin(ctx: AdapterBuildContext): AdapterTransform;
33
+ /** In `hamur dev` the client runtime imports `preact/debug` first, so Preact's devtools hooks are set before the first render; a build adds nothing. */
34
+ export declare function preactDebugPlugin(): AdapterTransform;
35
+ /** In `hamur dev` the client runtime imports `runtime/hydration-dev.ts` first, which feeds the hydration mismatch report; a build adds nothing. */
36
+ export declare function preactHydrationPlugin(): AdapterTransform;
@@ -0,0 +1,41 @@
1
+ import { Component } from "preact";
2
+ import type { ComponentChildren } from "preact";
3
+ interface Props {
4
+ resetOn: unknown;
5
+ fallback: (error: unknown) => ComponentChildren;
6
+ children?: ComponentChildren;
7
+ }
8
+ interface Held {
9
+ failed: boolean;
10
+ error: unknown;
11
+ }
12
+ /** Shows its fallback for an error below it until `resetOn` is another object, which every navigation and update builds. */
13
+ export declare class RouteBoundary extends Component<Props, Held> {
14
+ state: Held;
15
+ private failedFor;
16
+ static getDerivedStateFromError(error: unknown): {
17
+ failed: boolean;
18
+ error: unknown;
19
+ };
20
+ render(): ComponentChildren;
21
+ }
22
+ /** Errors a route boundary's own render threw, which no route boundary above may catch. */
23
+ export declare const rethrown: WeakSet<object>;
24
+ /** Marks an error that comes up from its children and throws it again to the next boundary. */
25
+ export declare class Guard extends Component<{
26
+ children?: ComponentChildren;
27
+ }, {
28
+ failed: boolean;
29
+ error: unknown;
30
+ }> {
31
+ state: {
32
+ failed: boolean;
33
+ error: unknown;
34
+ };
35
+ static getDerivedStateFromError(error: unknown): {
36
+ failed: boolean;
37
+ error: unknown;
38
+ };
39
+ render(): ComponentChildren;
40
+ }
41
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { ComponentChild } from "preact";
2
+ import type { ClientContext } from "hamur/adapter";
3
+ export { installKeepAlive } from "../context.ts";
4
+ export declare const hydrationCanBeAborted = true;
5
+ export declare function hydrate(ctx: ClientContext): Promise<void>;
6
+ export declare function mount(ctx: ClientContext): Promise<void>;
7
+ export declare function update(ctx: ClientContext): void | Promise<void>;
8
+ export { clientComponent } from "../client-component.ts";
9
+ /** The client side of a server-only component: the server HTML, never hydrated; a new props text fetches it anew. */
10
+ export declare function serverComponent(name: string): (props: Record<string, unknown>) => ComponentChild;