@hamur/adapter-html 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 (54) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +31 -2
  3. package/dist/chunks/browser-index-2h1699xv.js +148 -0
  4. package/dist/chunks/browser-index-n6x04zrf.js +28 -0
  5. package/dist/chunks/browser-index-naq02zzj.js +4 -0
  6. package/dist/chunks/browser-index-qx74bd1y.js +302 -0
  7. package/dist/src/adapter.js +141 -0
  8. package/dist/src/error-page.js +335 -0
  9. package/dist/src/index.js +1241 -0
  10. package/dist/src/runtime/client.js +330 -0
  11. package/dist/src/runtime/island.js +40 -0
  12. package/dist/src/runtime/server.js +59 -0
  13. package/dist/types/src/adapter.d.ts +2 -0
  14. package/dist/types/src/async-data.d.ts +13 -0
  15. package/dist/types/src/context.d.ts +109 -0
  16. package/dist/types/src/error-page.d.ts +1 -0
  17. package/dist/types/src/index.d.ts +343 -0
  18. package/dist/types/src/island-html.d.ts +13 -0
  19. package/dist/types/src/island.d.ts +40 -0
  20. package/dist/types/src/lazy-hydration.d.ts +11 -0
  21. package/dist/types/src/markdown-page.d.ts +9 -0
  22. package/dist/types/src/markdown.d.ts +11 -0
  23. package/dist/types/src/plugin.d.ts +11 -0
  24. package/dist/types/src/runtime/client.d.ts +15 -0
  25. package/dist/types/src/runtime/hmr.d.ts +8 -0
  26. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  27. package/dist/types/src/runtime/hydration.d.ts +10 -0
  28. package/dist/types/src/runtime/island.d.ts +8 -0
  29. package/dist/types/src/runtime/server.d.ts +8 -0
  30. package/dist/types/src/runtime/svg-id.d.ts +2 -0
  31. package/dist/types/src/server-component.d.ts +4 -0
  32. package/dist/types/src/svg.d.ts +10 -0
  33. package/package.json +62 -4
  34. package/src/adapter.ts +25 -0
  35. package/src/async-data.ts +65 -0
  36. package/src/context.ts +445 -0
  37. package/src/env.d.ts +3 -0
  38. package/src/error-page.ts +1 -0
  39. package/src/index.ts +1620 -0
  40. package/src/island-html.ts +58 -0
  41. package/src/island.ts +126 -0
  42. package/src/lazy-hydration.ts +56 -0
  43. package/src/markdown-page.ts +17 -0
  44. package/src/markdown.ts +29 -0
  45. package/src/plugin.ts +70 -0
  46. package/src/runtime/client.ts +363 -0
  47. package/src/runtime/hmr.ts +38 -0
  48. package/src/runtime/hydration-dev.ts +12 -0
  49. package/src/runtime/hydration.ts +11 -0
  50. package/src/runtime/island.ts +52 -0
  51. package/src/runtime/server.ts +56 -0
  52. package/src/runtime/svg-id.ts +12 -0
  53. package/src/server-component.ts +30 -0
  54. package/src/svg.ts +54 -0
@@ -0,0 +1,343 @@
1
+ import { addRouteMiddleware, clearError, disableScrollHandling, forbidden, navigateTo, notFound, permanentRedirect, refreshCookie, setPageLayout, showError, unauthorized } from "hamur/app";
2
+ import type { AppHooks, WebVitalMetric } from "hamur/app";
3
+ import type { SyncedStateOptions } from "hamur/app";
4
+ import { clearState as clearStateOf } from "hamur/app";
5
+ import type { PreviewMode } from "hamur/app";
6
+ import type { $Fetch, FetchCheckedInput, FetchInputField } from "hamur/app";
7
+ import type { StateKey } from "hamur/app";
8
+ import type { HamurEvent } from "hamur/server";
9
+ import type { LinkDefaults, LinkSlot, Navigation, UseLinkOptions } from "hamur/adapter";
10
+ import type { AnnouncerActions, AnnouncerPoliteness, AnnouncerState, RouteAnnouncerActions, RouteAnnouncerProps, RouteAnnouncerState, LoadingIndicatorActions, LoadingIndicatorProps as LoadingIndicatorCoreProps, LoadingIndicatorOptions, LoadingIndicatorState, TimeInput } from "hamur/adapter";
11
+ import type { ActionOptions, ActionRunner, PrefetchOn, Handler, AfterNavigateHook, BeforeNavigateHook, NavigateHook, NavigationBlocker, NavigationGuard, Blocker, ShouldBlock, UseBlockerOptions, SnapshotOptions } from "hamur/adapter";
12
+ import type { HandlerForm, HamurLinkProps } from "hamur/app";
13
+ import type { ActionFailure, AppContext, PickFrom, RouteLocation, ClientRuntimeConfig, SiteConfig, ErrorPageProps, FetchData, AsyncDataOptions, AsyncDataStatus, HeadInput, HeadSafeInput, SeoMetaInput, UseCookieOptions, HamurError } from "hamur/app";
14
+ import type { RouteLoaderData, UseDataArgs, AsyncDataHandler, ErrorBoundaryFallbackProps, FetchRequest, GetCachedData, CheckedTarget, NavigationState, RouteValue, RouterApi } from "hamur/adapter";
15
+ import type { HtmlChildren, HtmlProps } from "./context.ts";
16
+ export { addRouteMiddleware, clearError, disableScrollHandling, forbidden, navigateTo, notFound, permanentRedirect, refreshCookie, setPageLayout, showError, unauthorized, };
17
+ export { defineLazyHydrationComponent } from "./lazy-hydration.ts";
18
+ export { defineIsland, island, serverIsland } from "./island.ts";
19
+ export type { HtmlIsland, IslandOptions, ServerIslandOptions } from "./island.ts";
20
+ export { MarkdownRenderer } from "./markdown.ts";
21
+ export type { MarkdownRendererProps } from "./markdown.ts";
22
+ import type { SetSearch } from "hamur/adapter";
23
+ import type { AppUpdateActions, AppUpdateState } from "hamur/adapter";
24
+ import type { MatchedRoute, RouteDataName, RouteDataOf, RouteError, RouteFor, RouteName } from "hamur/adapter";
25
+ export type { MatchedRoute, RouteDataName, RouteDataOf } from "hamur/adapter";
26
+ export type { NavigateToOptions, PickFrom } from "hamur/app";
27
+ export type { HtmlChildren, HtmlProps };
28
+ export type { Blocker, BlockerArgs, SnapshotOptions, UseBlockerOptions } from "hamur/adapter";
29
+ export type { AfterNavigateHook, AsyncDataHandler, BeforeNavigateHook, ErrorBoundaryFallbackProps, FetchRequest, GetCachedData, GetCachedDataCause, NavigateHook, NavigateOptions, Navigation, NavigationState, NavigationType, RouteValue, RouterApi, } from "hamur/adapter";
30
+ export type { LinkDefaults, LinkSlot, UseLinkOptions } from "hamur/adapter";
31
+ interface LinkBaseProps extends Record<string, unknown>, HamurLinkProps {
32
+ replace?: boolean;
33
+ prefetch?: boolean;
34
+ prefetchOn?: PrefetchOn;
35
+ /** Removed: write `to`. */
36
+ href?: never;
37
+ /** Removed: write `prefetch={false}`. */
38
+ noPrefetch?: never;
39
+ /** The query as a function of the validated search of the page on screen. */
40
+ query?: (prev: RouteValue["search"]) => RouteValue["search"];
41
+ /** A serializable object kept in the history entry the click pushes, read as `useRoute().state`. */
42
+ state?: Record<string, unknown>;
43
+ /** `"route"` resolves a relative `to` against the path of the route, its pattern filled with its params, not the URL. */
44
+ relative?: "route";
45
+ /** The app path the address bar shows while `to` renders. */
46
+ mask?: string;
47
+ /** `false` renders `to` again after a reload of the masked entry. */
48
+ unmaskOnReload?: boolean;
49
+ /** `true` or `{ types }` runs this navigation in a view transition, `false` turns it off. */
50
+ viewTransition?: boolean | {
51
+ types: readonly string[];
52
+ };
53
+ activeClass?: string;
54
+ exactActiveClass?: string;
55
+ /** The class the navigator adds to this anchor while a navigation to it is in flight; `""` adds none. */
56
+ pendingClass?: string;
57
+ ariaCurrentValue?: "page" | "step" | "location" | "date" | "time" | "true";
58
+ /** A plain link the navigator never intercepts, with no prefetch and `rel="external"`. */
59
+ external?: boolean;
60
+ /** No `rel` is added for a `target="_blank"` or an other-origin `to`. */
61
+ noRel?: boolean;
62
+ /** The class the navigator adds to this anchor once its prefetch finished. */
63
+ prefetchedClass?: string;
64
+ /** `false` keeps the scroll position for the navigation the click starts. */
65
+ scroll?: boolean;
66
+ /** ms a hover or focus waits before it prefetches; one that ends sooner prefetches nothing. */
67
+ prefetchDelay?: number;
68
+ /** Runs for a navigation this anchor started, after the `onBeforeNavigate` hooks; `nav.cancel()` stops it. Kept like `state`, through `data-hamur-link`. */
69
+ onBeforeNavigate?: (nav: Navigation) => void;
70
+ /** A function renders the link itself: it is given the `LinkSlot` and `Link` returns what it returns. */
71
+ children?: string | ((link: LinkSlot) => string);
72
+ }
73
+ /** `T` is the string `to`, which is checked against the route table. */
74
+ export type LinkProps<T extends string = string> = LinkBaseProps & {
75
+ to: CheckedTarget<T> | RouteLocation;
76
+ };
77
+ export declare function Link<T extends string = string>(props: LinkProps<T>): string;
78
+ /** A `Link` with `defaults` over `app.link`; a prop of the element wins. */
79
+ export declare function defineLink(defaults: LinkDefaults): typeof Link;
80
+ /** The `LinkSlot` of a link to `to`, a plain object read while the page is painted; `app.link` sets its defaults. */
81
+ export declare function useLink<T extends string = string>(to: CheckedTarget<T> | RouteLocation, options?: UseLinkOptions): LinkSlot;
82
+ export interface NavigateProps<T extends string = string> {
83
+ to: CheckedTarget<T, false> | RouteLocation;
84
+ replace?: boolean;
85
+ }
86
+ /** Navigates to `to` once after the page is painted; during SSR it throws the redirect `navigateTo` throws there. */
87
+ export declare function Navigate<T extends string = string>({ to, replace }: NavigateProps<T>): string;
88
+ interface FormBaseProps extends Record<string, unknown> {
89
+ encType?: "application/x-www-form-urlencoded" | "multipart/form-data";
90
+ replace?: boolean;
91
+ reset?: boolean;
92
+ reloadDocument?: boolean;
93
+ refresh?: boolean;
94
+ /** With a server function: the store of `useAction(fn, { instance })` this form belongs to. */
95
+ instance?: string | number;
96
+ restore?: boolean;
97
+ }
98
+ export type FormProps<N extends string = string> = FormBaseProps &
99
+ /** A server function posts to this page with `?_fn=<id>`; the post is a document post, as a hydrated html page runs no component code. */
100
+ ({
101
+ action: ((...args: never[]) => unknown) & {
102
+ readonly url: string;
103
+ };
104
+ method?: "post";
105
+ } | {
106
+ action?: string | (RouteLocation & {
107
+ name: N;
108
+ });
109
+ method?: "get";
110
+ });
111
+ export declare function Form<N extends string = string>({ action, method, encType, replace, reset, reloadDocument, refresh, instance, restore, ...rest }: FormProps<N>, body?: string): string;
112
+ export type TimeProps = TimeInput & Record<string, unknown>;
113
+ export declare function Time(props: TimeProps): string;
114
+ /** `estimatedProgress` is a function and cannot cross the server's string; pass it to `useLoadingIndicator(options)`. */
115
+ export type LoadingIndicatorProps = Omit<LoadingIndicatorCoreProps, "estimatedProgress">;
116
+ export declare function LoadingIndicator(props?: LoadingIndicatorProps): string;
117
+ export declare function useLoadingIndicator(options?: LoadingIndicatorOptions): LoadingIndicatorState & LoadingIndicatorActions;
118
+ export declare function useAppUpdate(): AppUpdateState & AppUpdateActions & {
119
+ subscribe(listener: () => void): () => void;
120
+ };
121
+ export type { RouteAnnouncerProps };
122
+ export declare function RouteAnnouncer(props?: RouteAnnouncerProps): string;
123
+ export declare function useRouteAnnouncer(): RouteAnnouncerState & RouteAnnouncerActions;
124
+ export declare function Announcer(): string;
125
+ export declare function useAnnouncer({ politeness }?: {
126
+ politeness?: AnnouncerPoliteness;
127
+ }): Pick<AnnouncerState, "message" | "politeness"> & AnnouncerActions;
128
+ export declare function useRoute<N extends RouteName>(name: N): RouteFor<N>;
129
+ export declare function useRoute<N extends RouteName = never>(): RouteFor<N>;
130
+ export declare function useRoute(): RouteValue;
131
+ export declare function useResolvedPath(to: string, { relative }?: {
132
+ relative?: "route";
133
+ }): string;
134
+ export declare function useRouter(): RouterApi;
135
+ export declare function useData<T = unknown>(...unknownRoute: UseDataArgs<T>): RouteLoaderData<T>;
136
+ export declare function useError(): RouteError | undefined;
137
+ export declare function useRouteData<N extends RouteDataName>(name: N): RouteDataOf<N>;
138
+ export declare function useMatches(): MatchedRoute[];
139
+ export declare function Outlet({ context, name }?: {
140
+ context?: unknown;
141
+ name?: string;
142
+ }): string;
143
+ export declare function useOutletContext<T = unknown>(): T;
144
+ export declare function useLayoutSegments(): string[];
145
+ export declare function useLayoutSegment(): string | null;
146
+ export declare function useLayout(): {
147
+ name: string | false;
148
+ props: Record<string, unknown>;
149
+ };
150
+ export interface ErrorBoundaryProps {
151
+ children: () => string | HtmlChildren;
152
+ fallback: (props: ErrorBoundaryFallbackProps) => string;
153
+ }
154
+ export declare function ErrorBoundary({ children, fallback }: ErrorBoundaryProps): string;
155
+ export interface AwaitOptions<T> {
156
+ fallback?: string;
157
+ then: (value: Awaited<T>) => string;
158
+ error?: (error: Error) => string;
159
+ }
160
+ export declare function Await<T>(promise: T, { fallback, then, error }: AwaitOptions<T>): string;
161
+ /** The server writes `fallback` and, after it, the children in a `<template>` that the client entry swaps in once the app mounted; a script-free page keeps the fallback. The browser paints the children at once. */
162
+ export declare function ClientOnly(children: () => string, { fallback }?: {
163
+ fallback?: string;
164
+ }): string;
165
+ /** The children under `import.meta.dev` or in the `hamur dev` client, `fallback` otherwise; the production build rewrites the call to `DevOnly(undefined, …)` so the children's code is gone. */
166
+ export declare function DevOnly(children: (() => string) | undefined, { fallback }?: {
167
+ fallback?: string;
168
+ }): string;
169
+ export declare function DefaultErrorPage({ error }: {
170
+ error: ErrorPageProps;
171
+ }): string;
172
+ export declare function useApp(): AppContext;
173
+ export declare function useId(): string;
174
+ export declare function useHydrated(): () => boolean;
175
+ export declare function useRequestEvent(): HamurEvent | undefined;
176
+ /** 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. */
177
+ export declare function usePreviewMode(): PreviewMode;
178
+ export declare function useRequestHeaders(names?: readonly string[]): Record<string, string>;
179
+ export declare function useRequestHeader(name: string): string | undefined;
180
+ export declare function useRequestURL(): URL;
181
+ export declare function useRequestFetch(): $Fetch;
182
+ export declare function setResponseStatus(status: number, statusText?: string): void;
183
+ export declare function useResponseHeader(name: string): {
184
+ value: string | undefined;
185
+ };
186
+ export declare function useAsyncDataEntry<T = unknown>(key: string): {
187
+ data: T | undefined;
188
+ };
189
+ export declare function useAsyncDataEntry<I, O>(fn: Handler<I, O>, input?: I): {
190
+ data: O | undefined;
191
+ };
192
+ export declare function clearState(keys?: Parameters<typeof clearStateOf>[1], options?: {
193
+ reset?: boolean;
194
+ }): void;
195
+ export declare function callOnce(key: string, fn: () => unknown | Promise<unknown>, options?: {
196
+ mode?: "render" | "navigation";
197
+ }): Promise<void>;
198
+ export declare function useRuntimeConfig(): ClientRuntimeConfig;
199
+ export declare function useSiteConfig(): SiteConfig;
200
+ export declare function onPrehydrate(fn: (el: Element) => void): string;
201
+ export declare const onBeforeNavigate: (fn: BeforeNavigateHook) => (() => void);
202
+ export declare const onNavigate: (fn: NavigateHook) => (() => void);
203
+ export declare const onAfterNavigate: (fn: AfterNavigateHook) => (() => void);
204
+ export declare const onBeforeRouteLeave: (fn: NavigationGuard) => (() => void);
205
+ export declare const onBeforeRouteUpdate: (fn: NavigationGuard) => (() => void);
206
+ export declare const usePreventNavigate: (fn: NavigationBlocker) => (() => void);
207
+ export declare const useSnapshot: <T>(key: string, options: SnapshotOptions<T>) => (() => void);
208
+ /** Registered while the page renders in the browser and removed before the next paint, so before the next page's `adapter.update`. */
209
+ export declare function useRuntimeHook<K extends keyof AppHooks>(name: K, fn: AppHooks[K]): void;
210
+ /** Registered while the page renders in the browser and removed before the next paint. */
211
+ export declare function useReportWebVitals(fn: (metric: WebVitalMetric) => void | Promise<void>): void;
212
+ /** The page function runs again on each repaint: the calls of one render are counted, and only those beyond the count already scheduled in this visit run. A navigation starts a new visit. */
213
+ export declare function onAppReady(fn: () => void | Promise<void>): void;
214
+ /** Registers at once (during a render, until the next paint); `subscribe` tells a page script when the state changes, `remove()` unregisters. */
215
+ export declare function useBlocker(options: ShouldBlock | UseBlockerOptions): Blocker & {
216
+ subscribe(listener: () => void): () => void;
217
+ remove(): void;
218
+ };
219
+ export declare function useNavigation(): NavigationState;
220
+ export declare function useSearch(): {
221
+ readonly value: RouteValue["search"];
222
+ set: SetSearch;
223
+ };
224
+ export declare function useSearch<S>(select: (search: RouteValue["search"]) => S): {
225
+ readonly value: S;
226
+ set: SetSearch;
227
+ };
228
+ export declare function usePoll(ms: number, options?: {
229
+ keys?: string[];
230
+ }): () => void;
231
+ export declare function useOnline(): {
232
+ readonly value: boolean;
233
+ };
234
+ /** During a server render, asks `hydrate` to run the page again in the browser, for a composable whose work happens only there. */
235
+ export declare function rerunOnHydrate(): void;
236
+ export declare function useSyncedState<T>(key: string, initial: T, options?: SyncedStateOptions): {
237
+ get(): T;
238
+ set(value: T): void;
239
+ subscribe(callback: (value: T) => void): () => void;
240
+ };
241
+ export declare function useForm<I, O>(fn: Handler<I, O>): HandlerForm<I, O>;
242
+ export declare function useAction<I, O>(fn: Handler<I, O>, options?: ActionOptions<O> & {
243
+ instance?: string | number;
244
+ }): {
245
+ run: ActionRunner<I, O>["run"];
246
+ readonly state: O | undefined;
247
+ readonly pending: boolean;
248
+ readonly error: HamurError | undefined;
249
+ readonly failure: ActionFailure | undefined;
250
+ reset(): void;
251
+ subscribe(listener: () => void): () => void;
252
+ };
253
+ export declare function useHead(input: HeadInput): void;
254
+ export declare function useSeoMeta(input: SeoMetaInput): void;
255
+ type ServerHeadInput = Omit<HeadInput, "title" | "titleTemplate">;
256
+ type ServerSeoMetaInput = Omit<SeoMetaInput, "title" | "titleTemplate">;
257
+ export declare function useHeadSafe(input: HeadSafeInput): void;
258
+ export declare function useServerHead(input: ServerHeadInput): void;
259
+ export declare function useServerSeoMeta(input: ServerSeoMetaInput): void;
260
+ export declare function useState<T>(key: StateKey<T>): {
261
+ value: T;
262
+ };
263
+ export declare function useState<T = unknown>(key: string, init?: T | (() => T)): {
264
+ value: T;
265
+ };
266
+ export declare function useCookie<T = string>(name: string, options: Omit<UseCookieOptions<T>, "app"> & {
267
+ default: () => T;
268
+ }): {
269
+ value: T;
270
+ };
271
+ export declare function useCookie<T = string>(name: string, options?: Omit<UseCookieOptions<T>, "app">): {
272
+ value: T | undefined;
273
+ };
274
+ export interface UseAsyncDataOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends Omit<AsyncDataOptions<T, R, D>, "pick"> {
275
+ /** Accepted for the same options in every adapter and ignored: nothing watches. */
276
+ watch?: false;
277
+ getCachedData?: GetCachedData<T>;
278
+ /** Top-level keys of an object result to keep. */
279
+ pick?: readonly K[];
280
+ }
281
+ export interface UseFetchOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends FetchRequest, UseAsyncDataOptions<T, R, K, D> {
282
+ /** The store key, instead of the one derived from the url and the request. */
283
+ key?: string;
284
+ }
285
+ export interface UseAsyncDataResult<T, D = undefined> {
286
+ readonly data: T | D;
287
+ readonly error: HamurError | undefined;
288
+ readonly status: AsyncDataStatus;
289
+ /** `status === "pending"`, or `idle` without data under `app.asyncData.pendingWhenIdle`. */
290
+ readonly pending: boolean;
291
+ refresh(): Promise<void>;
292
+ /** The same function as `refresh`. */
293
+ execute(): Promise<void>;
294
+ /** Resets the entry of this key to `idle` (`clearAsyncData`). */
295
+ clear(): void;
296
+ /** A browser render that left the entry pending paints the page again when it settles; for other changes, such as `refresh()`, render from the listener. */
297
+ subscribe(listener: () => void): () => void;
298
+ }
299
+ 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> & {
300
+ default: () => D;
301
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
302
+ 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>>;
303
+ 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> & {
304
+ default: () => D;
305
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
306
+ 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>>;
307
+ /** What a literal `useFetch` call is checked against; any other call stays loose. */
308
+ type FetchInput<X> = X extends {
309
+ key: infer K extends string;
310
+ input: infer I;
311
+ } ? FetchInputField<I, K, I | (() => I)> : unknown;
312
+ type Unkeyed<O, X> = X extends {
313
+ key: infer K extends string;
314
+ } ? Omit<O, K> : O;
315
+ type FetchCall<U extends string, M extends string, B extends string | undefined> = {
316
+ method?: M | string;
317
+ baseURL?: B | string;
318
+ } & FetchInput<FetchCheckedInput<U, M, B>>;
319
+ 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>;
320
+ 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>> & {
321
+ default: () => D;
322
+ } & FetchCall<U, M, B>): UseAsyncDataResult<PickFrom<T, K>, D>;
323
+ 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>>;
324
+ /** `createUseFetch` defaults change what a call sends (method, body, query, baseURL), so its calls check nothing. */
325
+ interface UseFetchLoose {
326
+ <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> & {
327
+ method?: M;
328
+ }): UseAsyncDataResult<PickFrom<FetchData<U, M>, K>, D>;
329
+ <T = unknown, R = T, K extends keyof T & string = never, D = T>(url: string | (() => string), options: UseFetchOptions<T, R, K, D> & {
330
+ default: () => D;
331
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
332
+ <T = unknown, R = T, K extends keyof T & string = never>(url: string | (() => string), options?: UseFetchOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
333
+ }
334
+ type AnyFetchOptions = UseFetchOptions<any, any, any, any>;
335
+ /** `useFetch` with `defaults` under every call's options; `$fetch` replaces the request-bound client, e.g. a `$fetch.create` one. */
336
+ export declare function createUseFetch(defaults: AnyFetchOptions | ((options: AnyFetchOptions) => AnyFetchOptions), { $fetch: client }?: {
337
+ $fetch?: $Fetch;
338
+ }): UseFetchLoose;
339
+ /** `useAsyncData` with `defaults` under every call's options. */
340
+ export declare function createUseAsyncData(defaults: UseAsyncDataOptions<any, any, any, any> | ((options: UseAsyncDataOptions<any, any, any, any>) => UseAsyncDataOptions<any, any, any, any>)): typeof useAsyncData;
341
+ export declare const useLazyFetch: typeof useFetch;
342
+ export declare const useLazyAsyncData: typeof useAsyncData;
343
+ export declare function transitionName(name: string): string;
@@ -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,40 @@
1
+ import { type IslandOn } from "hamur/adapter";
2
+ import type { ComponentRenderContext } from "hamur/adapter";
3
+ /** An html island: the string it renders on the server and the function that makes it live in the browser, which may return its cleanup. */
4
+ export interface HtmlIsland<P extends object = Record<string, unknown>> {
5
+ render(props: P): string;
6
+ hydrate(el: Element, props: P): void | (() => void);
7
+ /** Gives the live island new props when a swap keeps it; without it the island's HTML is written again from `render` and `hydrate` runs anew. */
8
+ update?(el: Element, props: P): void;
9
+ }
10
+ export interface IslandOptions {
11
+ /** The island directive: when the island hydrates, `"only"` to mount it in the browser alone, or a directive a module adds; default `"load"`. */
12
+ on?: IslandOn;
13
+ /** The island's id across swaps; a swap to a page with the same id keeps its element and state. */
14
+ persist?: string;
15
+ /** With `persist`, a swap keeps the island's old props. */
16
+ persistProps?: boolean;
17
+ /** What the server writes in place of the island under `on: "only"`. */
18
+ fallback?: string;
19
+ }
20
+ export interface ServerIslandOptions {
21
+ /** What the server writes inside the element until the browser has the island's HTML. */
22
+ fallback?: string;
23
+ }
24
+ /** The default export of a file under `app/islands/`. */
25
+ export declare function defineIsland<P extends object>(island: HtmlIsland<P>): HtmlIsland<P>;
26
+ /** Runs `render` for the island root `ctx.idPrefix`: the islands it writes count their ids from this root, so a render done again gives them the same ones. */
27
+ export declare function inIslandRoot<T>(ctx: Pick<ComponentRenderContext, "app" | "idPrefix"> | undefined, render: () => T): T;
28
+ /** The default export of an `app/islands/**` file of a library in `experimental.islands.libraries`: a component of that library. */
29
+ export type LibraryComponent = object;
30
+ /**
31
+ * On an island page, `component` rendered as a root of its own inside `<hamur-island>` and hydrated on its own in the browser.
32
+ * A component of a library in `experimental.islands.libraries` is rendered and hydrated by that library's adapter.
33
+ */
34
+ export declare function island<P extends object>(component: HtmlIsland<P>, props?: P, options?: IslandOptions): string;
35
+ export declare function island(component: LibraryComponent, props?: Record<string, unknown>, options?: IslandOptions): string;
36
+ /**
37
+ * The server island `name` with `props`, rendered on the server in its own request: the page holds `fallback`, the core swaps the
38
+ * answer in, and the page's own paints never see it. A browser render has no seal for the props, so the element carries them in the clear.
39
+ */
40
+ export declare function serverIsland(name: string, props?: Record<string, unknown>, options?: ServerIslandOptions): string;
@@ -0,0 +1,11 @@
1
+ import type { HydrateOn, HydrateOnOptions } from "hamur/adapter";
2
+ type Module<P> = {
3
+ default: (props: P) => string;
4
+ };
5
+ /** Pages render synchronously, so `render` awaits the lazy modules still loading before each pass. */
6
+ export declare function lazyModules(): Promise<unknown> | undefined;
7
+ /** An html page has no client components, so the component renders inline inside `<hamur-hydrate>` and `on` only names the attribute. */
8
+ export declare function defineLazyHydrationComponent<P extends object>(on: HydrateOn, loader: () => Promise<Module<P>>, options?: Omit<HydrateOnOptions, "signal">): (props: P & {
9
+ onHydrated?: () => void;
10
+ }) => string;
11
+ 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,11 @@
1
+ import type { MarkdownDocument, MdNode } from "hamur/markdown";
2
+ export interface MarkdownRendererProps {
3
+ /** A Markdown AST node, a list of nodes, or a document, which renders its `ast`. */
4
+ value: MdNode | MdNode[] | MarkdownDocument;
5
+ /** Components by Markdown component name (kebab case), each called with the node's props, `children` and a string argument per named slot. */
6
+ components?: Record<string, (props: Record<string, any>) => string>;
7
+ /** 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. */
8
+ raw?: (html: string) => string;
9
+ }
10
+ /** Renders the Markdown AST as an HTML string, an internal link through `Link`, a component node through its function in `components`. */
11
+ export declare function MarkdownRenderer({ value, components: given, raw }: MarkdownRendererProps): string;
@@ -0,0 +1,11 @@
1
+ import type { AdapterBuildContext, AdapterTransform } from "hamur/adapter";
2
+ /**
3
+ * Wraps a route module's default export in a stable function and self-accepts, so a re-evaluated module
4
+ * swaps the implementation behind it and renders the tree again. A module without a default export is left alone.
5
+ */
6
+ export declare function hotTransform(source: string, id: string): string;
7
+ export declare function htmlPlugin(ctx: AdapterBuildContext): AdapterTransform;
8
+ /** A production build turns the children of every `DevOnly(fn, …)` imported from `@hamur/adapter-html` into `undefined`. */
9
+ export declare function htmlProductionPlugin(ctx: AdapterBuildContext): AdapterTransform;
10
+ /** In `hamur dev` the client runtime imports `runtime/hydration-dev.ts` first, which feeds the hydration mismatch report; a build adds nothing. */
11
+ export declare function htmlHydrationPlugin(): AdapterTransform;
@@ -0,0 +1,15 @@
1
+ import type { ClientContext } from "hamur/adapter";
2
+ export declare function hydrate(ctx: ClientContext): Promise<void>;
3
+ export declare function mount(ctx: ClientContext): Promise<void>;
4
+ export declare function update(ctx: ClientContext): void;
5
+ /** The element nodes between the page markers and between the layout markers of the HTML under `ctx.root`; a pair the HTML does not hold gives none. */
6
+ export declare function transitionTargets(ctx: ClientContext): {
7
+ page: Element[];
8
+ layout: Element[];
9
+ };
10
+ /**
11
+ * The client side of a server-only component. A paint is a string, so the answer of a component the browser has not
12
+ * seen is requested once and paints again; the server HTML of the page that loaded, and the markup of a server-only page the
13
+ * navigator fetched, are taken from the DOM and kept by name and props.
14
+ */
15
+ export declare function serverComponent(name: string): (props?: Record<string, unknown>) => string;
@@ -0,0 +1,8 @@
1
+ import type { ClientContext } from "hamur/adapter";
2
+ import type { HtmlComponent } from "../context.ts";
3
+ /** Called by the client entry on every hydrate, mount and update, so `rerender` knows the context on screen. */
4
+ export declare function track(ctx: ClientContext, repaint: (ctx: ClientContext) => void): void;
5
+ /** Paints the last context again after a page, layout or app module was re-evaluated; a throw reloads the document. */
6
+ export declare function rerender(): void;
7
+ /** The module's default export under a stable identity: importers and the render tree keep calling the latest implementation. */
8
+ export declare function hot(id: string, impl: HtmlComponent): HtmlComponent;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ /** What `hydration-dev.ts` hands the client runtime in `hamur dev`; a production client never sets it. */
2
+ export interface HydrationWatch {
3
+ /** The client's render string of the first page, compared with the server markup saved before. */
4
+ done(client: string): void;
5
+ }
6
+ export declare const devHydration: {
7
+ watch?: (root: Element, swapClientOnly: (root: Element) => void) => HydrationWatch;
8
+ /** `true` in the `hamur dev` client, where `import.meta.dev` is not defined, so `DevOnly` renders what the dev server rendered. */
9
+ devClient?: true;
10
+ };
@@ -0,0 +1,8 @@
1
+ import type { IslandContext } from "hamur/adapter";
2
+ /** Hands the island's server HTML in `el` to its `hydrate`. */
3
+ export declare function hydrateIsland(el: Element, component: unknown, props: Record<string, unknown>, _ctx: IslandContext): void;
4
+ /** Writes the island's `render` into `el` in place of the fallback it holds, then hydrates it. */
5
+ export declare function mountIsland(el: Element, component: unknown, props: Record<string, unknown>, _ctx: IslandContext): void;
6
+ export declare function unmountIsland(el: Element): void;
7
+ /** Calls the island's `update` with the new props, or, without one, writes its `render` again and hydrates it anew. */
8
+ export declare function updateIsland(el: Element, props: Record<string, unknown>): void;
@@ -0,0 +1,8 @@
1
+ import type { ComponentRenderContext, RenderContext, RenderResult } from "hamur/adapter";
2
+ export declare function render(ctx: RenderContext): Promise<RenderResult>;
3
+ /** `component` rendered with `props`: a function returning a string, or an object whose `render` is one. */
4
+ export declare function renderComponent(component: unknown, props: Record<string, unknown>, ctx?: ComponentRenderContext): Promise<{
5
+ html: string;
6
+ }>;
7
+ /** The server side of a server-only component: its string inside `hamur-component`, its props checked as the client sends them. */
8
+ export declare function serverComponent(name: string, component: (props: Record<string, unknown>) => string): (props?: Record<string, unknown>) => string;
@@ -0,0 +1,2 @@
1
+ /** Counted per render, so the server's markup and a repaint's agree. */
2
+ export declare function svgInstanceId(): string;
@@ -0,0 +1,4 @@
1
+ /** html has no component ids: the position in the render and a hash of the name and props, so the browser takes the server HTML only for the same component with the same props. */
2
+ export declare function serverComponentId(name: string, text: string): string;
3
+ export declare const isPage: (name: string) => boolean;
4
+ export declare function serverComponentHTML(name: string, uid: string, html: string): string;
@@ -0,0 +1,10 @@
1
+ import { type SvgSource } from "hamur/adapter";
2
+ declare function module(svg: SvgSource): {
3
+ contents: string;
4
+ extension: string;
5
+ };
6
+ export declare const svgComponent: {
7
+ types: string;
8
+ module: typeof module;
9
+ };
10
+ export {};
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@hamur/adapter-html",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/productdevbook/hamur.git",
9
+ "directory": "packages/adapter-html"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/types/src/index.d.ts",
14
+ "bun": "./src/index.ts",
15
+ "hamur-source": "./src/index.ts",
16
+ "node": "./dist/src/index.js",
17
+ "default": "./src/index.ts"
18
+ },
19
+ "./adapter": {
20
+ "types": "./dist/types/src/adapter.d.ts",
21
+ "bun": "./src/adapter.ts",
22
+ "hamur-source": "./src/adapter.ts",
23
+ "node": "./dist/src/adapter.js",
24
+ "default": "./src/adapter.ts"
25
+ },
26
+ "./runtime/server": {
27
+ "types": "./dist/types/src/runtime/server.d.ts",
28
+ "bun": "./src/runtime/server.ts",
29
+ "hamur-source": "./src/runtime/server.ts",
30
+ "node": "./dist/src/runtime/server.js",
31
+ "default": "./src/runtime/server.ts"
32
+ },
33
+ "./runtime/client": {
34
+ "types": "./dist/types/src/runtime/client.d.ts",
35
+ "bun": "./src/runtime/client.ts",
36
+ "hamur-source": "./src/runtime/client.ts",
37
+ "node": "./dist/src/runtime/client.js",
38
+ "default": "./src/runtime/client.ts"
39
+ },
40
+ "./runtime/island": {
41
+ "types": "./dist/types/src/runtime/island.d.ts",
42
+ "bun": "./src/runtime/island.ts",
43
+ "hamur-source": "./src/runtime/island.ts",
44
+ "node": "./dist/src/runtime/island.js",
45
+ "default": "./src/runtime/island.ts"
46
+ },
47
+ "./error-page": {
48
+ "types": "./dist/types/src/error-page.d.ts",
49
+ "bun": "./src/error-page.ts",
50
+ "hamur-source": "./src/error-page.ts",
51
+ "node": "./dist/src/error-page.js",
52
+ "default": "./src/error-page.ts"
53
+ },
54
+ "./package.json": "./package.json"
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "src"
59
+ ],
60
+ "dependencies": {},
61
+ "peerDependencies": {
62
+ "hamur": "^0.0.2"
63
+ }
64
+ }
package/src/adapter.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { ADAPTER_CONTRACT, defineAdapter } from "hamur/adapter"
2
+ import { serverComponentModule } from "hamur/adapter/build"
3
+ import { htmlHydrationPlugin, htmlPlugin, htmlProductionPlugin } from "./plugin.ts"
4
+ import { svgComponent } from "./svg.ts"
5
+ import { markdownComponent } from "./markdown-page.ts"
6
+
7
+ export default defineAdapter({
8
+ name: "html",
9
+ contract: ADAPTER_CONTRACT,
10
+ extensions: [".ts", ".js"],
11
+ clientEntry: "@hamur/adapter-html/runtime/client",
12
+ serverEntry: "@hamur/adapter-html/runtime/server",
13
+ islandEntry: "@hamur/adapter-html/runtime/island",
14
+ transforms: (ctx) =>
15
+ ctx.dev
16
+ ? ctx.target === "client"
17
+ ? [...(ctx.hmr ? [htmlPlugin(ctx)] : []), htmlHydrationPlugin()]
18
+ : []
19
+ : [htmlProductionPlugin(ctx)],
20
+ errorPage: "@hamur/adapter-html/error-page",
21
+ peers: [],
22
+ svgComponent,
23
+ markdownComponent,
24
+ serverComponent: { module: (component) => serverComponentModule(component, "@hamur/adapter-html/runtime") },
25
+ })