@hamur/adapter-svelte 0.0.0-stage → 0.0.1

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 (106) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +31 -2
  3. package/dist/chunks/browser-index-324qgh1c.js +190 -0
  4. package/dist/chunks/browser-index-evqp5a71.js +64 -0
  5. package/dist/chunks/browser-index-xc6081e3.js +9 -0
  6. package/dist/src/adapter.js +480 -0
  7. package/dist/src/index.js +1161 -0
  8. package/dist/src/runtime/client.js +65 -0
  9. package/dist/src/runtime/island.js +72 -0
  10. package/dist/src/runtime/server.js +142 -0
  11. package/dist/types/src/activation.d.ts +15 -0
  12. package/dist/types/src/adapter.d.ts +2 -0
  13. package/dist/types/src/async-data.d.ts +21 -0
  14. package/dist/types/src/boundary-error.d.ts +9 -0
  15. package/dist/types/src/client-only.d.ts +6 -0
  16. package/dist/types/src/context.d.ts +87 -0
  17. package/dist/types/src/deferred.svelte.d.ts +6 -0
  18. package/dist/types/src/effect.svelte.d.ts +2 -0
  19. package/dist/types/src/hydrating.d.ts +4 -0
  20. package/dist/types/src/index.d.ts +270 -0
  21. package/dist/types/src/island-html.d.ts +13 -0
  22. package/dist/types/src/keepalive.d.ts +11 -0
  23. package/dist/types/src/lazy-hydration.d.ts +25 -0
  24. package/dist/types/src/markdown-page.d.ts +9 -0
  25. package/dist/types/src/plugin.d.ts +52 -0
  26. package/dist/types/src/runtime/client.d.ts +12 -0
  27. package/dist/types/src/runtime/hmr.d.ts +28 -0
  28. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  29. package/dist/types/src/runtime/hydration.d.ts +8 -0
  30. package/dist/types/src/runtime/island.d.ts +8 -0
  31. package/dist/types/src/runtime/server.d.ts +12 -0
  32. package/dist/types/src/server-component.d.ts +3 -0
  33. package/dist/types/src/store.d.ts +7 -0
  34. package/dist/types/src/svg.d.ts +10 -0
  35. package/package.json +43 -4
  36. package/src/Announcer.svelte +26 -0
  37. package/src/Await.svelte +43 -0
  38. package/src/AwaitAsync.svelte +42 -0
  39. package/src/BodyAttrs.svelte +7 -0
  40. package/src/Caught.svelte +41 -0
  41. package/src/ClientComponent.svelte +35 -0
  42. package/src/ClientFallback.svelte +46 -0
  43. package/src/ClientOnly.svelte +22 -0
  44. package/src/DefaultErrorPage.svelte +15 -0
  45. package/src/DevOnly.svelte +12 -0
  46. package/src/ErrorBoundary.svelte +14 -0
  47. package/src/FallbackEffect.svelte +9 -0
  48. package/src/Form.svelte +96 -0
  49. package/src/HeadLink.svelte +7 -0
  50. package/src/HeadMeta.svelte +7 -0
  51. package/src/HeadScript.svelte +7 -0
  52. package/src/HeadStyle.svelte +7 -0
  53. package/src/HeadTitle.svelte +6 -0
  54. package/src/HtmlAttrs.svelte +7 -0
  55. package/src/HttpHeader.svelte +7 -0
  56. package/src/HttpStatusCode.svelte +7 -0
  57. package/src/Island.svelte +59 -0
  58. package/src/IslandChildren.svelte +7 -0
  59. package/src/KeptOutlet.svelte +46 -0
  60. package/src/KeptPage.svelte +55 -0
  61. package/src/LazyHydration.svelte +54 -0
  62. package/src/Link.svelte +209 -0
  63. package/src/LoadingIndicator.svelte +18 -0
  64. package/src/MarkdownNodes.svelte +36 -0
  65. package/src/MarkdownRenderer.svelte +20 -0
  66. package/src/MarkdownSlots.svelte +33 -0
  67. package/src/Navigate.svelte +10 -0
  68. package/src/Nest.svelte +83 -0
  69. package/src/Outlet.svelte +31 -0
  70. package/src/Rethrow.svelte +7 -0
  71. package/src/Root.svelte +29 -0
  72. package/src/RouteAnnouncer.svelte +47 -0
  73. package/src/Scoped.svelte +11 -0
  74. package/src/ServerComponent.svelte +19 -0
  75. package/src/ServerComponentClient.svelte +64 -0
  76. package/src/ServerIsland.svelte +26 -0
  77. package/src/Slotted.svelte +11 -0
  78. package/src/Thrown.svelte +9 -0
  79. package/src/Time.svelte +23 -0
  80. package/src/activation.ts +51 -0
  81. package/src/adapter.ts +24 -0
  82. package/src/async-data.ts +105 -0
  83. package/src/boundary-error.ts +77 -0
  84. package/src/client-only.ts +8 -0
  85. package/src/context.ts +227 -0
  86. package/src/deferred.svelte.ts +33 -0
  87. package/src/effect.svelte.ts +7 -0
  88. package/src/env.d.ts +3 -0
  89. package/src/hydrating.ts +18 -0
  90. package/src/index.ts +1337 -0
  91. package/src/island-html.ts +58 -0
  92. package/src/keepalive.ts +12 -0
  93. package/src/lazy-hydration.ts +89 -0
  94. package/src/markdown-page.ts +17 -0
  95. package/src/plugin.ts +558 -0
  96. package/src/runtime/client.ts +61 -0
  97. package/src/runtime/hmr.ts +177 -0
  98. package/src/runtime/hydration-dev.ts +22 -0
  99. package/src/runtime/hydration.ts +7 -0
  100. package/src/runtime/island.ts +94 -0
  101. package/src/runtime/server.ts +87 -0
  102. package/src/server-component.ts +13 -0
  103. package/src/store.ts +31 -0
  104. package/src/svelte.d.ts +5 -0
  105. package/src/svg.ts +30 -0
  106. package/src/webmcp.d.ts +18 -0
@@ -0,0 +1,270 @@
1
+ import type { AppHooks, WebVitalMetric } from "hamur/app";
2
+ import type { SyncedStateOptions } from "hamur/app";
3
+ import { clearState as clearStateOf } from "hamur/app";
4
+ import type { PreviewMode } from "hamur/app";
5
+ import type { $Fetch, FetchCheckedInput, FetchInputField } from "hamur/app";
6
+ import type { StateKey } from "hamur/app";
7
+ import type { HamurEvent } from "hamur/server";
8
+ import type { AnnouncerActions, AnnouncerPoliteness, AnnouncerState, RouteAnnouncerActions, RouteAnnouncerState, LoadingIndicatorActions, LoadingIndicatorOptions, LoadingIndicatorState, ActionOptions, ActionRunner, FormStatus, Handler, AfterNavigateHook, BeforeNavigateHook, NavigateHook, NavigationBlocker, NavigationGuard, Blocker, ShouldBlock, UseBlockerOptions, SnapshotOptions } from "hamur/adapter";
9
+ import type { HandlerForm } from "hamur/app";
10
+ import type { CheckedTarget, LinkDefaults, LinkSlot, UseLinkOptions } from "hamur/adapter";
11
+ import type { ActionFailure, AppContext, RouteLocation, PendingRun, PickFrom, ClientRuntimeConfig, SiteConfig, FetchData, AsyncDataOptions, AsyncDataStatus, HeadInput, HeadSafeInput, SeoMetaInput, UseCookieOptions, HamurError } from "hamur/app";
12
+ import type { RouteLoaderData, UseDataArgs, AsyncDataHandler, FetchRequest, GetCachedData, NavigationState, RouteValue, RouterApi } from "hamur/adapter";
13
+ export { default as Link } from "./Link.svelte";
14
+ import LinkComponent from "./Link.svelte";
15
+ export { default as Form } from "./Form.svelte";
16
+ export { default as ClientFallback } from "./ClientFallback.svelte";
17
+ export { default as ClientOnly } from "./ClientOnly.svelte";
18
+ export { default as DevOnly } from "./DevOnly.svelte";
19
+ export { default as Await } from "./Await.svelte";
20
+ export { useDeferred } from "./deferred.svelte.ts";
21
+ export type { Deferred } from "./deferred.svelte.ts";
22
+ export { default as Navigate } from "./Navigate.svelte";
23
+ export { default as Time } from "./Time.svelte";
24
+ export { default as LoadingIndicator } from "./LoadingIndicator.svelte";
25
+ export { default as RouteAnnouncer } from "./RouteAnnouncer.svelte";
26
+ export { default as Announcer } from "./Announcer.svelte";
27
+ export { default as HttpHeader } from "./HttpHeader.svelte";
28
+ export { default as HeadTitle } from "./HeadTitle.svelte";
29
+ export { default as HeadMeta } from "./HeadMeta.svelte";
30
+ export { default as HeadLink } from "./HeadLink.svelte";
31
+ export { default as HeadScript } from "./HeadScript.svelte";
32
+ export { default as HeadStyle } from "./HeadStyle.svelte";
33
+ export { default as HtmlAttrs } from "./HtmlAttrs.svelte";
34
+ export { default as BodyAttrs } from "./BodyAttrs.svelte";
35
+ export { default as HttpStatusCode } from "./HttpStatusCode.svelte";
36
+ export { default as Outlet } from "./Outlet.svelte";
37
+ export { default as ErrorBoundary } from "./ErrorBoundary.svelte";
38
+ export { default as DefaultErrorPage } from "./DefaultErrorPage.svelte";
39
+ export { addRouteMiddleware, clearError, disableScrollHandling, forbidden, navigateTo, notFound, permanentRedirect, refreshCookie, setPageLayout, showError, unauthorized, } from "hamur/app";
40
+ export { defineLazyHydrationComponent } from "./lazy-hydration.ts";
41
+ export { default as Island } from "./Island.svelte";
42
+ export { default as ServerIsland } from "./ServerIsland.svelte";
43
+ export { default as MarkdownRenderer } from "./MarkdownRenderer.svelte";
44
+ import type { SetSearch } from "hamur/adapter";
45
+ import type { AppUpdateActions, AppUpdateState } from "hamur/adapter";
46
+ import type { MatchedRoute, RouteDataName, RouteDataOf, RouteError, RouteFor, RouteName } from "hamur/adapter";
47
+ export type { MatchedRoute, RouteDataName, RouteDataOf } from "hamur/adapter";
48
+ export type { NavigateToOptions, PickFrom } from "hamur/app";
49
+ export type { LoadingIndicatorProps } from "hamur/adapter";
50
+ export type { Blocker, BlockerArgs, SnapshotOptions, UseBlockerOptions } from "hamur/adapter";
51
+ export type { AfterNavigateHook, AsyncDataHandler, BeforeNavigateHook, ErrorBoundaryFallbackProps, FetchRequest, GetCachedData, GetCachedDataCause, NavigateHook, NavigateOptions, Navigation, NavigationState, NavigationType, RouteValue, RouterApi, } from "hamur/adapter";
52
+ export type { LinkDefaults, LinkSlot, UseLinkOptions } from "hamur/adapter";
53
+ export declare function useRoute<N extends RouteName>(name: N): RouteFor<N>;
54
+ export declare function useRoute<N extends RouteName = never>(): RouteFor<N>;
55
+ export declare function useRoute(): RouteValue;
56
+ export declare function useRouter(): RouterApi;
57
+ export declare function useData<T = unknown>(...unknownRoute: UseDataArgs<T>): {
58
+ readonly value: RouteLoaderData<T>;
59
+ };
60
+ export declare function useRouteData<N extends RouteDataName>(name: N): {
61
+ readonly value: RouteDataOf<N>;
62
+ };
63
+ export declare function useOutletContext<T = unknown>(): {
64
+ readonly value: T;
65
+ };
66
+ export declare function useLayoutSegments(): {
67
+ readonly value: string[];
68
+ };
69
+ export declare function useLayoutSegment(): {
70
+ readonly value: string | null;
71
+ };
72
+ export declare function useLayout(): {
73
+ readonly value: {
74
+ name: string | false;
75
+ props: Record<string, unknown>;
76
+ };
77
+ };
78
+ export declare function useMatches(): {
79
+ readonly value: MatchedRoute[];
80
+ };
81
+ export declare function useError(): {
82
+ readonly value: RouteError | undefined;
83
+ };
84
+ export declare function useApp(): AppContext;
85
+ export declare function useRuntimeHook<K extends keyof AppHooks>(name: K, fn: AppHooks[K]): void;
86
+ export declare function useReportWebVitals(fn: (metric: WebVitalMetric) => void | Promise<void>): void;
87
+ export declare function onAppReady(fn: () => void | Promise<void>): void;
88
+ export declare function onPrehydrate(fn: (el: Element) => void): string | undefined;
89
+ export declare function useRouteAnnouncer(): RouteAnnouncerState & RouteAnnouncerActions;
90
+ export declare function useAnnouncer({ politeness }?: {
91
+ politeness?: AnnouncerPoliteness;
92
+ }): Pick<AnnouncerState, "message" | "politeness"> & AnnouncerActions;
93
+ export declare function useRequestEvent(): HamurEvent | undefined;
94
+ /** 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. */
95
+ export declare function usePreviewMode(): PreviewMode;
96
+ export declare function useRequestHeaders(names?: readonly string[]): Record<string, string>;
97
+ export declare function useRequestHeader(name: string): string | undefined;
98
+ export declare function useRequestURL(): URL;
99
+ export declare function useRequestFetch(): $Fetch;
100
+ export declare function setResponseStatus(status: number, statusText?: string): void;
101
+ export declare function useResponseHeader(name: string): {
102
+ value: string | undefined;
103
+ };
104
+ export declare function useAsyncDataEntry<T = unknown>(key: string): {
105
+ data: T | undefined;
106
+ };
107
+ export declare function useAsyncDataEntry<I, O>(fn: Handler<I, O>, input?: I): {
108
+ data: O | undefined;
109
+ };
110
+ export declare function clearState(keys?: Parameters<typeof clearStateOf>[1], options?: {
111
+ reset?: boolean;
112
+ }): void;
113
+ export declare function callOnce(key: string, fn: () => unknown | Promise<unknown>, options?: {
114
+ mode?: "render" | "navigation";
115
+ }): Promise<void>;
116
+ export declare function useRuntimeConfig(): ClientRuntimeConfig;
117
+ export declare function useSiteConfig(): SiteConfig;
118
+ export declare const onBeforeNavigate: (fn: BeforeNavigateHook) => void;
119
+ export declare const onNavigate: (fn: NavigateHook) => void;
120
+ export declare const onAfterNavigate: (fn: AfterNavigateHook) => void;
121
+ /** Runs `fn` after the component mounts and each time its kept page is shown again. */
122
+ export declare function onPageActivated(fn: () => void): void;
123
+ /** Runs `fn` each time its kept page is hidden and when the component unmounts on screen. */
124
+ export declare function onPageDeactivated(fn: () => void): void;
125
+ export declare function onBeforeRouteLeave(fn: NavigationGuard): void;
126
+ export declare function onBeforeRouteUpdate(fn: NavigationGuard): void;
127
+ export declare const usePreventNavigate: (fn: NavigationBlocker) => void;
128
+ export declare function useBlocker(options: ShouldBlock | UseBlockerOptions): Blocker;
129
+ export declare const useSnapshot: <T>(key: string, options: SnapshotOptions<T>) => void;
130
+ export declare function useLoadingIndicator(options?: LoadingIndicatorOptions): LoadingIndicatorState & LoadingIndicatorActions;
131
+ export declare function useAppUpdate(): AppUpdateState & AppUpdateActions;
132
+ export declare function useNavigation(): NavigationState;
133
+ /** A `Link` with `defaults` over `app.link`; a prop of the element wins. */
134
+ export declare function defineLink(defaults: LinkDefaults): typeof LinkComponent;
135
+ /** The `LinkSlot` of a link to `to` as getters, for an element that renders its own `<a>`; `to` and `options` may be functions. `app.link` sets its defaults. */
136
+ export declare function useLink<T extends string = string>(to: CheckedTarget<T> | RouteLocation | (() => CheckedTarget<T> | RouteLocation), options?: UseLinkOptions | (() => UseLinkOptions)): Readonly<LinkSlot>;
137
+ /** Inside a `Link`'s children, whether a navigation to that link is in flight; `pending` is false anywhere else. */
138
+ export declare function useLinkStatus(): {
139
+ readonly pending: boolean;
140
+ };
141
+ export declare function useResolvedPath(to: string | (() => string), { relative }?: {
142
+ relative?: "route";
143
+ }): {
144
+ readonly value: string;
145
+ };
146
+ export declare function useSearch(): {
147
+ readonly value: RouteValue["search"];
148
+ set: SetSearch;
149
+ };
150
+ export declare function useSearch<S>(select: (search: RouteValue["search"]) => S): {
151
+ readonly value: S;
152
+ set: SetSearch;
153
+ };
154
+ export declare function usePoll(ms: number, options?: {
155
+ keys?: string[];
156
+ }): void;
157
+ export declare function useOnline(): {
158
+ readonly value: boolean;
159
+ };
160
+ export declare function useSyncedState<T>(key: string, initial: T, options?: SyncedStateOptions): {
161
+ value: T;
162
+ };
163
+ export declare function useId(): string;
164
+ export declare function useHydrated(): {
165
+ readonly current: boolean;
166
+ };
167
+ export declare function useFormStatus(): Readonly<FormStatus>;
168
+ export declare function useForm<I, O>(fn: Handler<I, O>): HandlerForm<I, O>;
169
+ export declare function useAction<I, O>(fn: Handler<I, O>, options?: ActionOptions<O> & {
170
+ instance?: string | number;
171
+ }): {
172
+ readonly run: ActionRunner<I, O>["run"];
173
+ readonly state: O | undefined;
174
+ readonly pending: boolean;
175
+ readonly error: HamurError | undefined;
176
+ readonly failure: ActionFailure | undefined;
177
+ reset(): void;
178
+ };
179
+ export declare function useOptimistic<T, A = PendingRun>(value: T | (() => T), reduce: (current: T, pending: A[]) => T): {
180
+ readonly value: T;
181
+ };
182
+ export declare function useHead(input: HeadInput | (() => HeadInput)): void;
183
+ export declare function useSeoMeta(input: SeoMetaInput | (() => SeoMetaInput)): void;
184
+ type ServerHeadInput = Omit<HeadInput, "title" | "titleTemplate">;
185
+ type ServerSeoMetaInput = Omit<SeoMetaInput, "title" | "titleTemplate">;
186
+ export declare function useHeadSafe(input: HeadSafeInput | (() => HeadSafeInput)): void;
187
+ export declare function useServerHead(input: ServerHeadInput | (() => ServerHeadInput)): void;
188
+ export declare function useServerSeoMeta(input: ServerSeoMetaInput | (() => ServerSeoMetaInput)): void;
189
+ export declare function useState<T>(key: StateKey<T>): {
190
+ value: T;
191
+ };
192
+ export declare function useState<T = unknown>(key: string, init?: T | (() => T)): {
193
+ value: T;
194
+ };
195
+ export declare function useCookie<T = string>(name: string, options: Omit<UseCookieOptions<T>, "app"> & {
196
+ default: () => T;
197
+ }): {
198
+ value: T;
199
+ };
200
+ export declare function useCookie<T = string>(name: string, options?: Omit<UseCookieOptions<T>, "app">): {
201
+ value: T | undefined;
202
+ };
203
+ export interface UseAsyncDataOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends Omit<AsyncDataOptions<T, R, D>, "pick"> {
204
+ /** Getters whose change re-runs the handler. `false` is accepted and does nothing: nothing watches implicitly. */
205
+ watch?: ReadonlyArray<() => unknown> | false;
206
+ getCachedData?: GetCachedData<T>;
207
+ /** Top-level keys of an object result to keep. */
208
+ pick?: readonly K[];
209
+ }
210
+ export interface UseAsyncDataResult<T, D = undefined> {
211
+ readonly data: T | D;
212
+ readonly error: HamurError | undefined;
213
+ readonly status: AsyncDataStatus;
214
+ /** `status === "pending"`, or `idle` without data under `app.asyncData.pendingWhenIdle`. */
215
+ readonly pending: boolean;
216
+ refresh(): Promise<void>;
217
+ /** The same function as `refresh`. */
218
+ execute(): Promise<void>;
219
+ /** Resets the entry of the current key to `idle` (`clearAsyncData`). */
220
+ clear(): void;
221
+ }
222
+ export interface UseFetchOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends FetchRequest, UseAsyncDataOptions<T, R, K, D> {
223
+ /** The store key, instead of the one derived from the url and the request. */
224
+ key?: string;
225
+ }
226
+ 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> & {
227
+ default: () => D;
228
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
229
+ 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>>;
230
+ export declare function useAsyncData<T = unknown, R = T, K extends keyof T & string = never, D = T>(key: string | (() => string), handler: AsyncDataHandler<R>, options: UseAsyncDataOptions<T, R, K, D> & {
231
+ default: () => D;
232
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
233
+ export declare function useAsyncData<T = unknown, R = T, K extends keyof T & string = never>(key: string | (() => string), handler: AsyncDataHandler<R>, options?: UseAsyncDataOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
234
+ /** What a literal `useFetch` call is checked against; any other call stays loose. */
235
+ type FetchInput<X> = X extends {
236
+ key: infer K extends string;
237
+ input: infer I;
238
+ } ? FetchInputField<I, K, I | (() => I)> : unknown;
239
+ type Unkeyed<O, X> = X extends {
240
+ key: infer K extends string;
241
+ } ? Omit<O, K> : O;
242
+ type FetchCall<U extends string, M extends string, B extends string | undefined> = {
243
+ method?: M | string;
244
+ baseURL?: B | string;
245
+ } & FetchInput<FetchCheckedInput<U, M, B>>;
246
+ 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>;
247
+ 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>(url: U | (() => U), options: Unkeyed<UseFetchOptions<T, R, K, D>, FetchCheckedInput<U, M, B>> & {
248
+ default: () => D;
249
+ } & FetchCall<U, M, B>): UseAsyncDataResult<PickFrom<T, K>, D>;
250
+ 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>(url: U | (() => U), options?: Unkeyed<UseFetchOptions<T, R, K, undefined>, FetchCheckedInput<U, M, B>> & FetchCall<U, M, B>): UseAsyncDataResult<PickFrom<T, K>>;
251
+ /** `createUseFetch` defaults change what a call sends (method, body, query, baseURL), so its calls check nothing. */
252
+ interface UseFetchLoose {
253
+ <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> & {
254
+ method?: M;
255
+ }): UseAsyncDataResult<PickFrom<FetchData<U, M>, K>, D>;
256
+ <T = unknown, R = T, K extends keyof T & string = never, D = T>(url: string | (() => string), options: UseFetchOptions<T, R, K, D> & {
257
+ default: () => D;
258
+ }): UseAsyncDataResult<PickFrom<T, K>, D>;
259
+ <T = unknown, R = T, K extends keyof T & string = never>(url: string | (() => string), options?: UseFetchOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
260
+ }
261
+ type AnyFetchOptions = UseFetchOptions<any, any, any, any>;
262
+ /** `useFetch` with `defaults` under every call's options; `$fetch` replaces the request-bound client, e.g. a `$fetch.create` one. */
263
+ export declare function createUseFetch(defaults: AnyFetchOptions | ((options: AnyFetchOptions) => AnyFetchOptions), { $fetch: client }?: {
264
+ $fetch?: $Fetch;
265
+ }): UseFetchLoose;
266
+ /** `useAsyncData` with `defaults` under every call's options. */
267
+ export declare function createUseAsyncData(defaults: UseAsyncDataOptions<any, any, any, any> | ((options: UseAsyncDataOptions<any, any, any, any>) => UseAsyncDataOptions<any, any, any, any>)): typeof useAsyncData;
268
+ export declare const useLazyFetch: typeof useFetch;
269
+ export declare const useLazyAsyncData: typeof useAsyncData;
270
+ 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,11 @@
1
+ import type { activation, detach, setHidden } from "./activation.ts";
2
+ import type { routeValue } from "./context.ts";
3
+ /** What `KeptOutlet.svelte` takes from the adapter's base as its `base` prop: it imports nothing from the base at run time, so loading it splits no chunk of the base. */
4
+ export interface KeepAliveBase {
5
+ APP_KEY: symbol;
6
+ ACTIVATION_KEY: symbol;
7
+ routeValue: typeof routeValue;
8
+ activation: typeof activation;
9
+ detach: typeof detach;
10
+ setHidden: typeof setHidden;
11
+ }
@@ -0,0 +1,25 @@
1
+ import type { Component } from "svelte";
2
+ import type { HydrateOn, HydrateOnOptions } from "hamur/adapter";
3
+ import type { AppContext } from "hamur/app";
4
+ type Props = Record<string, unknown>;
5
+ export interface Lazy {
6
+ on: HydrateOn;
7
+ /** `{ on }` on the server, empty in the browser: Svelte reads an `on` attribute or spread key there as an event handler. */
8
+ attributes: Record<string, string>;
9
+ options: Omit<HydrateOnOptions, "signal">;
10
+ load(): Promise<Component<Props>>;
11
+ /** The component's server HTML, `""` while its module loads on the server and in a client render, a marker while the page hydrates. */
12
+ html(props: Props, context: Map<unknown, unknown>, app: AppContext | undefined): string;
13
+ }
14
+ type RenderChild = (component: Component<Props>, props: Props, context: Map<unknown, unknown>) => string;
15
+ /** Set by the server entry, so `svelte/server` stays out of the browser build. */
16
+ export declare function setLazyRenderer(render: RenderChild): void;
17
+ /** The server renders synchronously, so `render` awaits the lazy modules still loading before each pass. */
18
+ export declare function lazyModules(): Promise<unknown> | undefined;
19
+ /** Renders the component on the server and, after hydration, keeps its server DOM until `on` fires; after a client navigation it mounts at once. */
20
+ export declare function defineLazyHydrationComponent<P extends Props>(on: HydrateOn, loader: () => Promise<{
21
+ default: Component<P>;
22
+ }>, options?: Omit<HydrateOnOptions, "signal">): Component<P & {
23
+ onHydrated?: () => void;
24
+ }>;
25
+ 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,52 @@
1
+ import type { BunPlugin } from "bun";
2
+ import type { AdapterBuildContext, AdapterTransform } from "hamur/adapter";
3
+ /** Production: empties every `<DevOnly>` of the markup except its `fallback` snippet; the removed text leaves its line breaks. */
4
+ export declare function dropDevOnlyMarkup(source: string): string;
5
+ /**
6
+ * The source locator, dev only: gives the markup's single root element, when it is a plain HTML element, `data-hamur-src="<file>:<line>:<column>"`.
7
+ * The insertion stays on its line, so no line moves; a source that does not parse is returned as it is.
8
+ */
9
+ export declare function locateRootElement(source: string, file: string): string;
10
+ /** A production client reads svelte's `DEV`, `BROWSER` and `NODE` as constants, so the minifier drops the dev branches. */
11
+ export declare function foldEsmEnv(source: string): string;
12
+ interface RawMap {
13
+ version: number;
14
+ sources: string[];
15
+ sourcesContent?: string[];
16
+ mappings: string;
17
+ names: string[];
18
+ }
19
+ /** `code` ends with its map, pointing at `written` (the file as authored) under its path relative to `rootDir`; `shift` empty lines were put above the compiled code. */
20
+ export declare function withInlineMap(code: string, map: RawMap | null, path: string, written: string, rootDir: string, shift?: number): string;
21
+ /** A component whose style blocks went through `preprocessStyle`: `code` is what `compile` reads, `original` what it was made from, `lineOf` takes a line of `code` back to `original`. */
22
+ export interface Preprocessed {
23
+ code: string;
24
+ original: string;
25
+ map: string | object | undefined;
26
+ lineOf(line: number): number;
27
+ }
28
+ /** `<style lang="scss" | "sass" | "less" | "styl" | "stylus">` blocks go through the build's style preprocessor, `undefined` when no block needs one. */
29
+ export declare function preprocessStyles(source: string, path: string, preprocessStyle: AdapterBuildContext["preprocessStyle"]): Promise<Preprocessed | undefined>;
30
+ export declare function compileSvelte(path: string, source: string, target: "client" | "server", hmr?: boolean, rootDir?: string, svelteAsync?: boolean, preprocessed?: Preprocessed, dev?: boolean): {
31
+ code: string;
32
+ css: string | undefined;
33
+ map: RawMap | null;
34
+ };
35
+ export declare function compileSvelteModule(path: string, source: string, target: "client" | "server", rootDir?: string, svelteAsync?: boolean, dev?: boolean): string;
36
+ /** The module's path relative to `rootDir` when it is an app source (not under `node_modules` or the build dir). */
37
+ export declare function appModuleId(rootDir: string, buildDir: string): (path: string) => string | undefined;
38
+ /**
39
+ * Numbers the recorded states of a component (top-level `$state`/`$state.raw` declarators with an
40
+ * identifier), routes their initial values through the hot runtime and starts the module script with the module's
41
+ * `hotModule` call. Every insertion stays on its line, so line numbers do not move. Returns `source` when it does not parse.
42
+ */
43
+ export declare function hotTransform(source: string, file: string, rootDir: string, runtime?: string): string;
44
+ /** Records the compiled component in the hot runtime, so `Nest.svelte` keeps rendering its first version. */
45
+ export declare function hotTail(code: string): string;
46
+ /** Bun 1.4.4 does not link a CSS import a self-accepting module gains or loses in an update, so the document loads again then; one line keeps the map shift at 1. */
47
+ export declare function styleGuard(styled: boolean): string;
48
+ export declare function svelteEsmEnv(): AdapterTransform;
49
+ export declare function sveltePlugin(ctx: AdapterBuildContext): BunPlugin;
50
+ /** In `hamur dev` the client runtime imports `runtime/hydration-dev.ts` first, which feeds the hydration mismatch report; a build adds nothing. */
51
+ export declare function svelteHydrationPlugin(): AdapterTransform;
52
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { ClientContext } from "hamur/adapter";
2
+ import type { Component } from "svelte";
3
+ export { installKeepAlive } from "../context.ts";
4
+ export declare function hydrate(ctx: ClientContext): Promise<void>;
5
+ export declare function mount(ctx: ClientContext): Promise<void>;
6
+ export declare function update(ctx: ClientContext): void;
7
+ /** The client side of a client-only component: nothing in the hydration render, the file's chunk once mounted. */
8
+ export declare function clientComponent(load: () => Promise<{
9
+ default: Component<Record<string, unknown>>;
10
+ }>): Component<Record<string, unknown>>;
11
+ /** The client side of a server-only component: the server HTML, never hydrated; a new props text fetches it anew. */
12
+ export declare function serverComponent(name: string): Component<Record<string, unknown>>;
@@ -0,0 +1,28 @@
1
+ import { getContext, onDestroy, setContext, untrack } from "svelte";
2
+ /** What the runtime calls outside itself; the unit tests replace it, as there is no component context without a DOM. */
3
+ export declare const host: {
4
+ getContext: typeof getContext;
5
+ setContext: typeof setContext;
6
+ onDestroy: typeof onDestroy;
7
+ untrack: typeof untrack;
8
+ reload: () => void;
9
+ };
10
+ export interface HotInstance {
11
+ /** Value `i` of the instance this one replaces, when there is one and its type matches `init`; else `init`. */
12
+ take<T>(i: number, init: T): T;
13
+ read(values: () => unknown[]): void;
14
+ }
15
+ export interface HotModule {
16
+ readonly id: string;
17
+ readonly signature: string;
18
+ readonly hash: string;
19
+ readonly deps: readonly object[];
20
+ /** The default export of the module's first version: Svelte's `update` makes it render the newest function. */
21
+ first?: Function;
22
+ enter(): HotInstance;
23
+ component(component: Function): void;
24
+ }
25
+ /** The first version of a hot-updated component, or `component` itself when it is unknown. */
26
+ export declare function stable(component: unknown): unknown;
27
+ /** One per module version, `previous` is what the module's last version returned. */
28
+ export declare function hotModule(previous: HotModule | undefined, id: string, signature: string, hash: string, deps: readonly object[]): HotModule;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /** What `hydration-dev.ts` hands the client runtime in `hamur dev`; a production client never sets it. */
2
+ export interface HydrationWatch {
3
+ /** `hydrate` returned: its DOM is compared with the server markup saved before. */
4
+ done(): void;
5
+ }
6
+ export declare const devHydration: {
7
+ watch?: (root: Element) => HydrationWatch;
8
+ };
@@ -0,0 +1,8 @@
1
+ import type { IslandContext } from "hamur/adapter";
2
+ /** Hydrates the island's server HTML in `el` as a root of its own, its ids prefixed as the server prefixed them. */
3
+ export declare function hydrateIsland(el: Element, component: unknown, props: Record<string, unknown>, ctx: IslandContext): void;
4
+ /** Mounts the island into `el` in place of the fallback it holds. */
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
+ /** Hands the island's root new props through its source, which keeps its state. */
8
+ export declare function updateIsland(el: Element, props: Record<string, unknown>): void;
@@ -0,0 +1,12 @@
1
+ import type { ComponentRenderContext, RenderContext, RenderResult } from "hamur/adapter";
2
+ import type { Component } from "svelte";
3
+ export declare function render(ctx: RenderContext): Promise<RenderResult>;
4
+ /** `component` as a root of its own, its ids prefixed with `ctx.idPrefix` as `hydrateIsland` prefixes them, with each island inside it rendered in place. */
5
+ export declare function renderComponent(component: unknown, props: Record<string, unknown>, ctx: ComponentRenderContext): Promise<{
6
+ html: string;
7
+ head?: string;
8
+ }>;
9
+ /** The server side of a client-only component renders the wrapper with no loader, so its markers match the client's hydration render. */
10
+ export declare function clientComponent(): Component<Record<string, unknown>>;
11
+ /** The server side of a server-only component: the component itself inside `hamur-component`, its props checked as the client sends them. */
12
+ export declare function serverComponent(name: string, component: Component<Record<string, unknown>>): Component<Record<string, unknown>>;
@@ -0,0 +1,3 @@
1
+ import type { Component } from "svelte";
2
+ /** Calls the compiled `wrapper` with the props it was given and a `server` prop that reads the wrapper's own settings, as lazy hydration reads `lazy`. */
3
+ export declare function withServer(wrapper: unknown, server: object): Component<Record<string, unknown>>;
@@ -0,0 +1,7 @@
1
+ export interface Source<T> {
2
+ get(): T;
3
+ set(value: T): void;
4
+ subscribe(listener: () => void): () => void;
5
+ }
6
+ export declare function createSource<T>(initial: T): Source<T>;
7
+ export declare function track<T>(source: Source<T>): () => T;
@@ -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,45 @@
1
1
  {
2
2
  "name": "@hamur/adapter-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/productdevbook/hamur.git",
9
+ "directory": "packages/adapter-svelte"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/types/src/index.d.ts",
14
+ "default": "./dist/src/index.js"
15
+ },
16
+ "./adapter": {
17
+ "types": "./dist/types/src/adapter.d.ts",
18
+ "default": "./dist/src/adapter.js"
19
+ },
20
+ "./runtime/server": {
21
+ "types": "./dist/types/src/runtime/server.d.ts",
22
+ "default": "./dist/src/runtime/server.js"
23
+ },
24
+ "./runtime/client": {
25
+ "types": "./dist/types/src/runtime/client.d.ts",
26
+ "default": "./dist/src/runtime/client.js"
27
+ },
28
+ "./runtime/keepalive": "./src/KeptOutlet.svelte",
29
+ "./runtime/island": {
30
+ "types": "./dist/types/src/runtime/island.d.ts",
31
+ "default": "./dist/src/runtime/island.js"
32
+ },
33
+ "./error-page": "./src/DefaultErrorPage.svelte",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src"
39
+ ],
40
+ "dependencies": {},
41
+ "peerDependencies": {
42
+ "svelte": "^5.57.2",
43
+ "hamur": "^0.0.1"
44
+ }
45
+ }
@@ -0,0 +1,26 @@
1
+ <script lang="ts">
2
+ import { ANNOUNCER_ASSERTIVE_ID, ANNOUNCER_POLITE_ID, createAnnouncer, hideAnnouncer } from "hamur/adapter"
3
+ import { onMount } from "svelte"
4
+ import { createSubscriber } from "svelte/reactivity"
5
+ import { useApp } from "./index.ts"
6
+
7
+ const store = createAnnouncer(useApp())
8
+ const subscribe = createSubscriber((update) => store.subscribe(update))
9
+ const regions = $derived.by(() => {
10
+ subscribe()
11
+ return store.get().regions
12
+ })
13
+ let polite: HTMLElement | undefined = $state()
14
+ let assertive: HTMLElement | undefined = $state()
15
+ onMount(() => {
16
+ for (const element of [polite, assertive]) if (element) hideAnnouncer(element)
17
+ return store.mount()
18
+ })
19
+ </script>
20
+
21
+ <div bind:this={polite} id={ANNOUNCER_POLITE_ID} aria-live="polite" aria-atomic="true" role="status"
22
+ >{regions.polite}</div
23
+ >
24
+ <div bind:this={assertive} id={ANNOUNCER_ASSERTIVE_ID} aria-live="assertive" aria-atomic="true" role="alert"
25
+ >{regions.assertive}</div
26
+ >
@@ -0,0 +1,43 @@
1
+ <script lang="ts" generics="T">
2
+ import { settledOf } from "hamur/adapter"
3
+ import type { Snippet } from "svelte"
4
+ import Rethrow from "./Rethrow.svelte"
5
+
6
+ let {
7
+ resolve,
8
+ children,
9
+ fallback,
10
+ error,
11
+ }: { resolve: T; children?: Snippet<[Awaited<T>]>; fallback?: Snippet; error?: Snippet<[Error]> } = $props()
12
+
13
+ const isThenable = (value: unknown): value is PromiseLike<unknown> =>
14
+ typeof (value as { then?: unknown } | null)?.then === "function"
15
+ const settled = $derived(
16
+ isThenable(resolve) ? settledOf(resolve) : ({ status: "fulfilled", value: resolve } as const),
17
+ )
18
+
19
+ if ((import.meta as { dev?: boolean }).dev === true && !children)
20
+ console.warn("Await has nothing to render for its value")
21
+ </script>
22
+
23
+ {#if settled?.status === "fulfilled"}
24
+ {@render children?.(settled.value as Awaited<T>)}
25
+ {:else if settled?.status === "rejected"}
26
+ {#if error}
27
+ {@render error(settled.reason as Error)}
28
+ {:else}
29
+ <Rethrow error={settled.reason} />
30
+ {/if}
31
+ {:else}
32
+ {#await resolve}
33
+ {@render fallback?.()}
34
+ {:then value}
35
+ {@render children?.(value as Awaited<T>)}
36
+ {:catch reason}
37
+ {#if error}
38
+ {@render error(reason as Error)}
39
+ {:else}
40
+ <Rethrow error={reason} />
41
+ {/if}
42
+ {/await}
43
+ {/if}