@hamur/adapter-svelte 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 (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 +58 -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
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 productdevbook
4
+ Copyright (c) 2019 Material-UI SAS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @hamur/adapter-svelte
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Svelte 5 adapter for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. It renders pages and layouts from `.svelte` files (server rendering returns a string) and gives you `useData`, `useHead`, `useState` and the other functions. Routing, loaders, head, state and the server come from `hamur`.
4
+
5
+ One app uses one library. Set `framework: "svelte"` in `hamur.config.ts`, or install only this adapter and Hamur detects it.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add hamur @hamur/adapter-svelte svelte
11
+ ```
12
+
13
+ Or start from a template: `bunx hamur init my-app --framework svelte`.
14
+
15
+ ## Example
16
+
17
+ `app/pages/post.svelte`:
18
+
19
+ ```svelte
20
+ <script lang="ts">
21
+ import { useData, useHead, useState } from "@hamur/adapter-svelte"
22
+ const data = useData<{ title: string }>()
23
+ const likes = useState("likes", 0)
24
+ useHead(() => ({ title: data.value.title }))
25
+ </script>
26
+
27
+ <button onclick={() => likes.value++}>{data.value.title}: {likes.value}</button>
28
+ ```
29
+
30
+ ## Docs
31
+
32
+ [Documentation](https://docs.productdevbook.com/) and the [adapters page](https://docs.productdevbook.com/adapters). MIT license.
@@ -0,0 +1,190 @@
1
+ // packages/adapter-svelte/src/context.ts
2
+ import { createRawSnippet, getContext } from "svelte";
3
+ import { createRouterApi } from "hamur/adapter";
4
+ import { routeStateOf, setServerHTML, SLOT_ELEMENT } from "hamur/adapter";
5
+
6
+ // packages/adapter-svelte/src/store.ts
7
+ import { createSubscriber } from "svelte/reactivity";
8
+ function createSource(initial) {
9
+ let value = initial;
10
+ const listeners = new Set;
11
+ return {
12
+ get: () => value,
13
+ set(next) {
14
+ value = next;
15
+ for (const listener of [...listeners])
16
+ listener();
17
+ },
18
+ subscribe(listener) {
19
+ listeners.add(listener);
20
+ return () => listeners.delete(listener);
21
+ }
22
+ };
23
+ }
24
+ function track(source) {
25
+ const subscribe = createSubscriber((update) => source.subscribe(update));
26
+ return () => {
27
+ subscribe();
28
+ return source.get();
29
+ };
30
+ }
31
+
32
+ // packages/adapter-svelte/src/context.ts
33
+ import Slotted from "../../src/Slotted.svelte";
34
+
35
+ // packages/adapter-svelte/src/activation.ts
36
+ function shown(own) {
37
+ return !own || !own.hidden && shown(own.parent);
38
+ }
39
+ var queue;
40
+ function later(isShown, fn) {
41
+ if (!queue) {
42
+ queue = [];
43
+ queueMicrotask(() => {
44
+ const run = queue;
45
+ queue = undefined;
46
+ for (const item of run)
47
+ if (!item.shown)
48
+ item.fn();
49
+ for (const item of run)
50
+ if (item.shown)
51
+ item.fn();
52
+ });
53
+ }
54
+ queue.push({ shown: isShown, fn });
55
+ }
56
+
57
+ // packages/adapter-svelte/src/context.ts
58
+ import { withBase } from "hamur/app";
59
+ var APP_KEY = Symbol("hamur.app");
60
+ var PENDING_ISLANDS_KEY = Symbol("hamur.pendingIslands");
61
+ var LEVEL_KEY = Symbol("hamur.level");
62
+ var NEVER_HYDRATED_KEY = Symbol("hamur.never-hydrated");
63
+ var OUTLET_VALUE_KEY = Symbol("hamur.outlet-value");
64
+ var FORM_STATUS_KEY = Symbol("hamur.form-status");
65
+ var ERROR_KEY = Symbol("hamur.error");
66
+ var LINK_KEY = Symbol("hamur.link");
67
+ var ACTIVATION_KEY = Symbol("hamur.activation");
68
+ var IDS_KEY = Symbol("hamur.ids");
69
+ function nextId(ids) {
70
+ return `${ids.base}${ids.next++}`;
71
+ }
72
+ function detachedHref(to) {
73
+ if (typeof to !== "string")
74
+ throw new Error(`Link to the route "${to.name}" must be rendered inside a Hamur app`);
75
+ return withBase(to, "/");
76
+ }
77
+ function routerOf(navigator, baseURL = "/", page) {
78
+ return createRouterApi({ ...page, navigator, baseURL });
79
+ }
80
+ var idle = { state: "idle", pending: false };
81
+ function navigationOf(navigator) {
82
+ const source = navigator;
83
+ return {
84
+ get: () => source?.get?.() ?? idle,
85
+ subscribe: (listener) => source?.subscribe?.(listener) ?? (() => {})
86
+ };
87
+ }
88
+ function routeValue(ctx) {
89
+ const { route } = ctx;
90
+ return {
91
+ path: route.path,
92
+ fullPath: route.fullPath,
93
+ params: route.params,
94
+ query: route.query,
95
+ search: route.search,
96
+ hash: route.hash,
97
+ name: route.name,
98
+ meta: route.meta,
99
+ matched: route.matched,
100
+ groups: route.groups ?? [],
101
+ ...routeStateOf(ctx)
102
+ };
103
+ }
104
+ function appState(ctx) {
105
+ const { data = {} } = ctx.payload;
106
+ return {
107
+ route: routeValue(ctx),
108
+ router: routerOf(ctx.navigator, ctx.baseURL, ctx),
109
+ baseURL: ctx.baseURL ?? "/",
110
+ href: ctx.href,
111
+ components: ctx.tree.components,
112
+ data,
113
+ handlerState: ctx.payload.handlerState,
114
+ tree: ctx.tree,
115
+ head: ctx.head,
116
+ navigation: navigationOf(ctx.navigator),
117
+ app: ctx.app,
118
+ context: ctx
119
+ };
120
+ }
121
+ var keptComponent;
122
+ function installKeepAlive2(module) {
123
+ keptComponent ??= module.default;
124
+ }
125
+ function errorOf(state) {
126
+ const stored = state.app.error?.get();
127
+ if (stored)
128
+ return stored;
129
+ return state.tree.error ? state.route.error : undefined;
130
+ }
131
+ function appSource(ctx) {
132
+ return createSource(appState(ctx));
133
+ }
134
+ var ISLAND_ENTRY = "island";
135
+ function slotSnippet(uid, html) {
136
+ if (typeof document === "undefined")
137
+ return createRawSnippet(() => ({ render: () => `<${SLOT_ELEMENT} uid="${uid}">${html}</${SLOT_ELEMENT}>` }));
138
+ return createRawSnippet(() => ({
139
+ render: () => `<${SLOT_ELEMENT} uid="${uid}"></${SLOT_ELEMENT}>`,
140
+ setup(node) {
141
+ if (html && !node.hasChildNodes())
142
+ setServerHTML(node, html);
143
+ }
144
+ }));
145
+ }
146
+ function islandSource(component, props, ctx, kept = {}) {
147
+ const href = (to) => {
148
+ if (typeof to !== "string")
149
+ throw new Error(`Link to the route "${to.name}" cannot render in an island; give it a path`);
150
+ return withBase(to, ctx.baseURL);
151
+ };
152
+ const slot = ctx.slots?.default;
153
+ const entry = slot === undefined ? { id: ISLAND_ENTRY, component, props } : {
154
+ id: ISLAND_ENTRY,
155
+ component: Slotted,
156
+ props: { component, props, slot: kept.slot ??= slotSnippet(`s${ctx.idPrefix}`, slot) }
157
+ };
158
+ return appSource({
159
+ app: ctx.app,
160
+ head: ctx.app.head,
161
+ route: ctx.route,
162
+ baseURL: ctx.baseURL,
163
+ href,
164
+ tree: { components: [entry] },
165
+ payload: {}
166
+ });
167
+ }
168
+ function useAppState(name) {
169
+ const source = getContext(APP_KEY);
170
+ if (!source)
171
+ throw new Error(`${name}() must be called inside a Hamur app`);
172
+ return track(source);
173
+ }
174
+
175
+ // packages/adapter-svelte/src/hydrating.ts
176
+ var hydrating = false;
177
+ var ADOPT_SERVER_NODES = "<!---->";
178
+ function whileHydratingPage(run) {
179
+ hydrating = true;
180
+ try {
181
+ return run();
182
+ } finally {
183
+ hydrating = false;
184
+ }
185
+ }
186
+ function keptServerHTML() {
187
+ return hydrating ? ADOPT_SERVER_NODES : "";
188
+ }
189
+
190
+ export { track, shown, later, APP_KEY, PENDING_ISLANDS_KEY, LEVEL_KEY, NEVER_HYDRATED_KEY, OUTLET_VALUE_KEY, FORM_STATUS_KEY, ERROR_KEY, LINK_KEY, ACTIVATION_KEY, IDS_KEY, nextId, detachedHref, appState, installKeepAlive2, errorOf, appSource, islandSource, useAppState, whileHydratingPage, keptServerHTML };
@@ -0,0 +1,64 @@
1
+ import {
2
+ NEVER_HYDRATED_KEY,
3
+ keptServerHTML
4
+ } from "./browser-index-324qgh1c.js";
5
+
6
+ // packages/adapter-svelte/src/lazy-hydration.ts
7
+ import { hydrateOnAttribute, markWaiting } from "hamur/adapter";
8
+ import LazyHydration from "../../src/LazyHydration.svelte";
9
+ var isServer = typeof document === "undefined";
10
+ var pending = new Set;
11
+ var renderChild;
12
+ function setLazyRenderer(render) {
13
+ renderChild = render;
14
+ }
15
+ function lazyModules() {
16
+ return pending.size ? Promise.allSettled(pending) : undefined;
17
+ }
18
+ function defineLazyHydrationComponent2(on, loader, options = {}) {
19
+ const attribute = hydrateOnAttribute(on);
20
+ let resolved;
21
+ let failed;
22
+ let loading;
23
+ const load = () => {
24
+ if (loading)
25
+ return loading;
26
+ const current = loading = loader().then((loaded) => resolved = loaded.default, (error) => {
27
+ if (isServer)
28
+ failed = { error };
29
+ loading = undefined;
30
+ throw error;
31
+ });
32
+ if (isServer) {
33
+ pending.add(current);
34
+ current.then(() => pending.delete(current), () => pending.delete(current));
35
+ }
36
+ return current;
37
+ };
38
+ if (isServer)
39
+ load().catch(() => {});
40
+ const lazy = {
41
+ on,
42
+ attributes: isServer ? { on: attribute } : {},
43
+ options,
44
+ load,
45
+ html(props, context, app) {
46
+ if (!isServer)
47
+ return keptServerHTML();
48
+ if (failed)
49
+ throw failed.error;
50
+ if (resolved && renderChild)
51
+ return renderChild(resolved, props, on === "never" ? new Map(context).set(NEVER_HYDRATED_KEY, true) : context);
52
+ if (app?.asyncData)
53
+ markWaiting(app.asyncData);
54
+ load().catch(() => {});
55
+ return "";
56
+ }
57
+ };
58
+ const bound = (anchor, props) => LazyHydration(anchor, new Proxy(props, {
59
+ get: (target, key, receiver) => key === "lazy" ? lazy : Reflect.get(target, key, receiver)
60
+ }));
61
+ return bound;
62
+ }
63
+
64
+ export { setLazyRenderer, lazyModules, defineLazyHydrationComponent2 };
@@ -0,0 +1,9 @@
1
+ // packages/adapter-svelte/src/server-component.ts
2
+ function withServer(wrapper, server) {
3
+ const call = wrapper;
4
+ return (anchor, props) => call(anchor, new Proxy(props, {
5
+ get: (target, key, receiver) => key === "server" ? server : Reflect.get(target, key, receiver)
6
+ }));
7
+ }
8
+
9
+ export { withServer };