@hamur/adapter-vue 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 (74) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +32 -2
  3. package/dist/chunks/browser-index-43pdsfp6.js +69 -0
  4. package/dist/chunks/browser-index-d1bxd40m.js +320 -0
  5. package/dist/chunks/browser-index-nhft0ewv.js +161 -0
  6. package/dist/src/adapter.js +402 -0
  7. package/dist/src/index.js +1348 -0
  8. package/dist/src/keepalive.js +6 -0
  9. package/dist/src/runtime/client.js +20 -0
  10. package/dist/src/runtime/island.js +45 -0
  11. package/dist/src/runtime/server.js +238 -0
  12. package/dist/types/src/adapter.d.ts +2 -0
  13. package/dist/types/src/async-data.d.ts +14 -0
  14. package/dist/types/src/client-component.d.ts +12 -0
  15. package/dist/types/src/client-fallback.d.ts +2 -0
  16. package/dist/types/src/components/AwaitValue.d.ts +15 -0
  17. package/dist/types/src/components/ClientFallback.server.d.ts +17 -0
  18. package/dist/types/src/components/ErrorBoundary.server.d.ts +21 -0
  19. package/dist/types/src/components/error-code.d.ts +1 -0
  20. package/dist/types/src/context.d.ts +65 -0
  21. package/dist/types/src/index.d.ts +329 -0
  22. package/dist/types/src/island.d.ts +68 -0
  23. package/dist/types/src/keepalive.d.ts +22 -0
  24. package/dist/types/src/lazy-hydration.d.ts +10 -0
  25. package/dist/types/src/markdown-page.d.ts +9 -0
  26. package/dist/types/src/markdown.d.ts +45 -0
  27. package/dist/types/src/plugin.d.ts +45 -0
  28. package/dist/types/src/route-boundary.d.ts +35 -0
  29. package/dist/types/src/route-boundary.server.d.ts +5 -0
  30. package/dist/types/src/runtime/client.d.ts +11 -0
  31. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  32. package/dist/types/src/runtime/hydration.d.ts +8 -0
  33. package/dist/types/src/runtime/island.d.ts +8 -0
  34. package/dist/types/src/runtime/server.d.ts +12 -0
  35. package/dist/types/src/server-island.d.ts +33 -0
  36. package/dist/types/src/svg.d.ts +10 -0
  37. package/package.json +64 -4
  38. package/src/adapter.ts +25 -0
  39. package/src/async-data.ts +77 -0
  40. package/src/client-component.ts +39 -0
  41. package/src/client-fallback.ts +2 -0
  42. package/src/components/Await.vue +30 -0
  43. package/src/components/AwaitValue.ts +41 -0
  44. package/src/components/ClientFallback.server.ts +41 -0
  45. package/src/components/ClientFallback.vue +31 -0
  46. package/src/components/ClientOnly.vue +16 -0
  47. package/src/components/DefaultErrorPage.vue +19 -0
  48. package/src/components/DevOnly.vue +8 -0
  49. package/src/components/ErrorBoundary.server.ts +69 -0
  50. package/src/components/ErrorBoundary.vue +32 -0
  51. package/src/components/Form.vue +85 -0
  52. package/src/components/Link.vue +200 -0
  53. package/src/components/Navigate.vue +16 -0
  54. package/src/components/Outlet.vue +28 -0
  55. package/src/components/error-code.ts +7 -0
  56. package/src/context.ts +391 -0
  57. package/src/index.ts +1528 -0
  58. package/src/island.ts +53 -0
  59. package/src/keepalive.ts +92 -0
  60. package/src/lazy-hydration.ts +53 -0
  61. package/src/markdown-page.ts +21 -0
  62. package/src/markdown.ts +80 -0
  63. package/src/plugin.ts +398 -0
  64. package/src/route-boundary.server.ts +29 -0
  65. package/src/route-boundary.ts +48 -0
  66. package/src/runtime/client.ts +137 -0
  67. package/src/runtime/hydration-dev.ts +38 -0
  68. package/src/runtime/hydration.ts +7 -0
  69. package/src/runtime/island.ts +60 -0
  70. package/src/runtime/server.ts +145 -0
  71. package/src/server-island.ts +38 -0
  72. package/src/svg.ts +28 -0
  73. package/src/vue.d.ts +5 -0
  74. 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,33 @@
1
- # Temporary Holding Version
1
+ # @hamur/adapter-vue
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 Vue 3.5 adapter for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. It renders pages and layouts from `.vue` files (server rendering returns a string) and gives you `useData`, `useHead`, `useState` and the other composables. Routing, loaders, head, state and the server come from `hamur`.
4
+
5
+ One app uses one library. Set `framework: "vue"` 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-vue vue
11
+ ```
12
+
13
+ Or start from a template: `bunx hamur init my-app --framework vue`.
14
+
15
+ ## Example
16
+
17
+ `app/pages/post.vue`:
18
+
19
+ ```vue
20
+ <script setup lang="ts">
21
+ import { useData, useHead, useState } from "@hamur/adapter-vue"
22
+ const data = useData<{ title: string }>()
23
+ const likes = useState("likes", 0)
24
+ useHead(() => ({ title: data.value.title }))
25
+ </script>
26
+ <template>
27
+ <button @click="likes++">{{ data.title }}: {{ likes }}</button>
28
+ </template>
29
+ ```
30
+
31
+ ## Docs
32
+
33
+ [Documentation](https://docs.productdevbook.com/) and the [adapters page](https://docs.productdevbook.com/adapters). MIT license.
@@ -0,0 +1,69 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+
16
+ // packages/adapter-vue/src/keepalive.ts
17
+ var exports_keepalive = {};
18
+ __export(exports_keepalive, {
19
+ createKeptOutlet: () => createKeptOutlet2
20
+ });
21
+ var SHOWN = "\x00shown";
22
+ var exact = (key) => new RegExp(`^${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`);
23
+ function createKeptOutlet2({
24
+ KeepAlive,
25
+ defineComponent,
26
+ h,
27
+ provide,
28
+ shallowReactive,
29
+ shallowRef,
30
+ watchEffect,
31
+ RouteKey,
32
+ DataKey,
33
+ routeValue,
34
+ dataOf
35
+ }) {
36
+ const keptPages = new Map;
37
+ function keptPage(name) {
38
+ let page = keptPages.get(name);
39
+ if (!page) {
40
+ page = defineComponent({
41
+ name,
42
+ props: {
43
+ route: { type: Object, required: true },
44
+ data: { type: Object, required: true }
45
+ },
46
+ setup(props, { slots }) {
47
+ const route = shallowReactive({ ...props.route });
48
+ const data = shallowRef(props.data);
49
+ watchEffect(() => void Object.assign(route, props.route));
50
+ watchEffect(() => void (data.value = props.data));
51
+ provide(RouteKey, route);
52
+ provide(DataKey, data);
53
+ return () => slots.default?.();
54
+ }
55
+ });
56
+ keptPages.set(name, page);
57
+ }
58
+ return page;
59
+ }
60
+ return (item, below, child, source) => {
61
+ const key = below?.keepalive;
62
+ const include = [...(item.kept ?? []).map((unit) => unit.key), ...key === undefined ? [] : [key]].map(exact);
63
+ const ctx = source();
64
+ const view = child && h(keptPage(key ?? SHOWN), { key, route: routeValue(ctx), data: dataOf(ctx) }, { default: () => child });
65
+ return h(KeepAlive, { include }, { default: () => view });
66
+ };
67
+ }
68
+
69
+ export { createKeptOutlet2, exports_keepalive };
@@ -0,0 +1,320 @@
1
+ // packages/adapter-vue/src/context.ts
2
+ import {
3
+ KeepAlive,
4
+ Suspense,
5
+ computed,
6
+ defineComponent as defineComponent2,
7
+ h,
8
+ nextTick,
9
+ onBeforeUpdate,
10
+ onUnmounted,
11
+ provide,
12
+ shallowReactive,
13
+ shallowRef as shallowRef2,
14
+ watchEffect
15
+ } from "vue";
16
+ import { APP_ROOT_ID, createRouterApi, layoutOf, routeBoundary } from "hamur/adapter";
17
+
18
+ // packages/adapter-vue/src/route-boundary.ts
19
+ import { defineComponent, getCurrentInstance, onErrorCaptured, shallowRef, watch } from "vue";
20
+ var caught = new WeakMap;
21
+ var rethrown = new WeakSet;
22
+ var Guard = defineComponent({
23
+ name: "HamurBoundaryGuard",
24
+ setup(_, { slots }) {
25
+ onErrorCaptured((thrown) => {
26
+ if (typeof thrown === "object" && thrown !== null)
27
+ rethrown.add(thrown);
28
+ });
29
+ return () => slots.default?.()[0];
30
+ }
31
+ });
32
+ var RouteBoundary = defineComponent({
33
+ name: "HamurRouteBoundary",
34
+ props: {
35
+ resetOn: { type: null, default: null },
36
+ fallback: { type: Function, required: true }
37
+ },
38
+ setup(props, { slots }) {
39
+ const failed = shallowRef(false);
40
+ const error = shallowRef();
41
+ watch(() => props.resetOn, () => {
42
+ failed.value = false;
43
+ error.value = undefined;
44
+ });
45
+ const instance = getCurrentInstance();
46
+ onErrorCaptured((thrown) => {
47
+ if (typeof thrown === "object" && thrown !== null && rethrown.has(thrown))
48
+ return;
49
+ error.value = thrown;
50
+ failed.value = true;
51
+ caught.set(instance, { error: thrown });
52
+ return false;
53
+ });
54
+ return () => failed.value ? props.fallback(error.value) : slots.default?.();
55
+ }
56
+ });
57
+
58
+ // packages/adapter-vue/src/context.ts
59
+ import { routeStateOf, setServerHTML, SLOT_ELEMENT } from "hamur/adapter";
60
+ import { withBase } from "hamur/app";
61
+ var RouteKey = Symbol("hamur-route");
62
+ var RouterKey = Symbol("hamur-router");
63
+ var NeverHydratedKey = Symbol("hamur-never-hydrated");
64
+ var BaseURLKey = Symbol("hamur-base-url");
65
+ var HrefKey = Symbol("hamur-href");
66
+ var DataKey = Symbol("hamur-data");
67
+ var EntryKey = Symbol("hamur-entry");
68
+ var ErrorKey = Symbol("hamur-error");
69
+ var HeadKey = Symbol("hamur-head");
70
+ var HeadPatchesKey = Symbol("hamur-head-patches");
71
+ var StateKey = Symbol("hamur-state");
72
+ var SubmittedKey = Symbol("hamur-submitted");
73
+ var FormStatusKey = Symbol("hamur-form-status");
74
+ var AppKey = Symbol("hamur-app");
75
+ var LinkHrefKey = Symbol("hamur-link-href");
76
+ var NavigationKey = Symbol("hamur-navigation");
77
+ var OutletValueKey = Symbol("hamur-outlet-value");
78
+ var OutletKey = Symbol("hamur-outlet");
79
+ var SlotsKey = Symbol("hamur-slots");
80
+ var LayoutKey = Symbol("hamur-layout");
81
+ function detachedHref(to) {
82
+ if (typeof to !== "string")
83
+ throw new Error(`Link to the route "${to.name}" must be rendered inside a Hamur app`);
84
+ return withBase(to, "/");
85
+ }
86
+ function routerOf(navigator, baseURL = "/", page) {
87
+ return createRouterApi({ ...page, navigator, baseURL });
88
+ }
89
+ function routeValue(ctx) {
90
+ const { route } = ctx;
91
+ return {
92
+ path: route.path,
93
+ fullPath: route.fullPath,
94
+ params: route.params,
95
+ query: route.query,
96
+ search: route.search,
97
+ hash: route.hash,
98
+ name: route.name,
99
+ meta: route.meta,
100
+ matched: route.matched,
101
+ groups: route.groups ?? [],
102
+ ...routeStateOf(ctx)
103
+ };
104
+ }
105
+ var Entry = defineComponent2({
106
+ name: "HamurEntry",
107
+ props: {
108
+ component: { type: null, required: true },
109
+ entryProps: { type: null, default: null },
110
+ dataKey: { type: String, required: true },
111
+ outlets: { type: Object, default: null },
112
+ caught: { type: Boolean, default: false },
113
+ route: { type: Object, default: null }
114
+ },
115
+ setup(props, { slots }) {
116
+ provide(EntryKey, () => props.dataKey);
117
+ provide(SlotsKey, () => props.outlets);
118
+ if (props.route) {
119
+ const own = shallowReactive({ ...props.route });
120
+ provide(RouteKey, own);
121
+ watchEffect(() => void Object.assign(own, props.route ?? {}));
122
+ }
123
+ if (props.caught)
124
+ provide(ErrorKey, { initial: props.entryProps.error });
125
+ const outlet = shallowRef2(slots.default);
126
+ onBeforeUpdate(() => void (outlet.value = slots.default));
127
+ provide(OutletKey, outlet);
128
+ return () => h(props.component, props.entryProps, slots);
129
+ }
130
+ });
131
+ function createPainting() {
132
+ const pending = new Set;
133
+ const waiting = [];
134
+ return {
135
+ pending: (boundary) => void pending.add(boundary),
136
+ done(boundary) {
137
+ pending.delete(boundary);
138
+ if (pending.size === 0)
139
+ for (const resolve of waiting.splice(0))
140
+ resolve();
141
+ },
142
+ settled: () => pending.size === 0 ? Promise.resolve() : new Promise((resolve) => void waiting.push(resolve))
143
+ };
144
+ }
145
+ var PageLevel = defineComponent2({
146
+ name: "HamurPage",
147
+ props: {
148
+ painting: { type: Object, required: true },
149
+ entry: { type: Object, required: true }
150
+ },
151
+ setup(props) {
152
+ const boundary = {};
153
+ onUnmounted(() => props.painting.done(boundary));
154
+ return () => h(Suspense, { onPending: () => props.painting.pending(boundary), onResolve: () => props.painting.done(boundary) }, { default: () => props.entry });
155
+ }
156
+ });
157
+ function boundaryView(ctx, painting, entry, error) {
158
+ const caught = routeBoundary(ctx, entry, error);
159
+ if (!caught)
160
+ throw error;
161
+ const clearError = (options) => ctx.app.error?.clear(options) ?? Promise.resolve();
162
+ const { id } = caught;
163
+ const view = h(PageLevel, {
164
+ painting,
165
+ entry: h(Entry, {
166
+ key: id,
167
+ component: caught.component,
168
+ entryProps: { error: caught.error, clearError },
169
+ dataKey: id,
170
+ caught: true
171
+ })
172
+ });
173
+ return h(Guard, null, { default: () => view });
174
+ }
175
+ function interceptedRoute(slot, ctx) {
176
+ const { state, key, navigationType } = ctx.route;
177
+ return routeValue({ ...ctx, route: { ...slot.route, state, key, navigationType }, tree: slot });
178
+ }
179
+ var keptOutlet;
180
+ function installKeepAlive2(module) {
181
+ keptOutlet ??= module.createKeptOutlet({
182
+ KeepAlive,
183
+ defineComponent: defineComponent2,
184
+ h,
185
+ provide,
186
+ shallowReactive,
187
+ shallowRef: shallowRef2,
188
+ watchEffect,
189
+ RouteKey,
190
+ DataKey,
191
+ routeValue,
192
+ dataOf
193
+ });
194
+ }
195
+ function keepAlive() {
196
+ if (!keptOutlet)
197
+ throw new Error("A tree with kept pages was rendered before the keep-alive part of the Vue adapter was installed");
198
+ return keptOutlet;
199
+ }
200
+ function nest(tree, painting, source) {
201
+ return level(tree, 0, painting, source);
202
+ }
203
+ function level(tree, index, painting, source) {
204
+ const item = tree.components[index];
205
+ if (!item)
206
+ return;
207
+ const { id, component, props, caught } = item;
208
+ const below = tree.components[index + 1];
209
+ const inner = item.kept !== undefined ? () => keepAlive()(item, below, level(tree, index + 1, painting, source), source) : below ? () => level(tree, index + 1, painting, source) : undefined;
210
+ const outlets = item.outlets ? Object.fromEntries(Object.entries(item.outlets).map(([name, slot]) => [name, () => nest(slot, painting, source)])) : null;
211
+ const entry = h(Entry, {
212
+ key: item.key === undefined ? id : `${id}\x00${item.key}`,
213
+ component,
214
+ entryProps: props ?? null,
215
+ dataKey: id,
216
+ outlets,
217
+ caught: caught !== undefined,
218
+ route: index === 0 && tree.route ? interceptedRoute(tree, source()) : null
219
+ }, inner ? { default: inner } : undefined);
220
+ let child = id === APP_ROOT_ID || id.startsWith("layout:") ? entry : h(PageLevel, { painting, entry });
221
+ if (caught) {
222
+ const view = child;
223
+ child = h(Guard, null, { default: () => view });
224
+ }
225
+ if (item.boundary) {
226
+ const view = child;
227
+ child = h(RouteBoundary, { key: id, resetOn: item, fallback: (error) => boundaryView(source(), painting, item, error) }, { default: () => view });
228
+ }
229
+ return child;
230
+ }
231
+ var dataOf = (ctx) => ctx.payload?.data ?? {};
232
+ var submittedOf = (ctx) => ({ handlerState: ctx.payload?.handlerState });
233
+ function navigationOf(navigator) {
234
+ const source = navigator;
235
+ if (typeof source?.get !== "function" || typeof source.subscribe !== "function")
236
+ return shallowRef2({ state: "idle", pending: false });
237
+ const navigation = shallowRef2(source.get());
238
+ source.subscribe(() => navigation.value = source.get());
239
+ return navigation;
240
+ }
241
+ function createRoot(ctx) {
242
+ const route = shallowReactive(routeValue(ctx));
243
+ const router = routerOf(ctx.navigator, ctx.baseURL, ctx);
244
+ const tree = shallowRef2(ctx.tree);
245
+ const data = shallowRef2(dataOf(ctx));
246
+ const submitted = shallowRef2(submittedOf(ctx));
247
+ const navigation = navigationOf(ctx.navigator);
248
+ const error = {
249
+ store: ctx.app.error,
250
+ initial: routeStateOf({ payload: ctx.payload, tree: ctx.tree }).error
251
+ };
252
+ const painting = createPainting();
253
+ let current = ctx;
254
+ return {
255
+ component: {
256
+ setup: () => () => {
257
+ const child = nest(tree.value, painting, () => current);
258
+ return tree.value.kept === undefined ? child : keepAlive()(tree.value, tree.value.components[0], child, () => current);
259
+ }
260
+ },
261
+ install(app) {
262
+ app.provide(RouteKey, route);
263
+ app.provide(RouterKey, router);
264
+ app.provide(BaseURLKey, ctx.baseURL ?? "/");
265
+ app.provide(HrefKey, ctx.href);
266
+ app.provide(DataKey, data);
267
+ app.provide(SubmittedKey, submitted);
268
+ app.provide(ErrorKey, error);
269
+ app.provide(NavigationKey, navigation);
270
+ app.provide(LayoutKey, computed(() => layoutOf(tree.value)));
271
+ const appContext = ctx.app;
272
+ if (appContext)
273
+ app.provide(AppKey, appContext);
274
+ if (ctx.head)
275
+ app.provide(HeadKey, ctx.head);
276
+ const state = ctx.app.state;
277
+ if (state)
278
+ app.provide(StateKey, state);
279
+ },
280
+ async update(next) {
281
+ Object.assign(route, routeValue(next));
282
+ data.value = dataOf(next);
283
+ submitted.value = submittedOf(next);
284
+ current = next;
285
+ tree.value = next.tree;
286
+ await nextTick();
287
+ await painting.settled();
288
+ }
289
+ };
290
+ }
291
+ var ISLAND_ENTRY = "island";
292
+ function slotted(component, uid, html) {
293
+ const fill = (node) => {
294
+ if (node instanceof Element && html && !node.hasChildNodes())
295
+ setServerHTML(node, html);
296
+ };
297
+ const slot = () => typeof document === "undefined" ? h(SLOT_ELEMENT, { uid, innerHTML: html }) : h(SLOT_ELEMENT, { uid, ref: fill });
298
+ return (props) => h(component, props, { default: slot });
299
+ }
300
+ function createIslandRoot(component, props, ctx) {
301
+ const href = (to) => {
302
+ if (typeof to !== "string")
303
+ throw new Error(`Link to the route "${to.name}" cannot render in an island; give it a path`);
304
+ return withBase(to, ctx.baseURL);
305
+ };
306
+ const slot = ctx.slots?.default;
307
+ const entry = slot === undefined ? component : slotted(component, `s${ctx.idPrefix}`, slot);
308
+ const source = (own) => ({
309
+ app: ctx.app,
310
+ head: ctx.app.head,
311
+ route: ctx.route,
312
+ baseURL: ctx.baseURL,
313
+ href,
314
+ tree: { components: [{ id: ISLAND_ENTRY, component: entry, props: own }] }
315
+ });
316
+ const root = createRoot(source(props));
317
+ return { ...root, setProps: (own) => root.update(source(own)) };
318
+ }
319
+
320
+ export { caught, RouteBoundary, RouteKey, RouterKey, NeverHydratedKey, BaseURLKey, HrefKey, DataKey, EntryKey, ErrorKey, HeadKey, HeadPatchesKey, StateKey, SubmittedKey, FormStatusKey, AppKey, LinkHrefKey, NavigationKey, OutletValueKey, LayoutKey, detachedHref, installKeepAlive2, createRoot, createIslandRoot };
@@ -0,0 +1,161 @@
1
+ import {
2
+ AppKey,
3
+ createRoot
4
+ } from "./browser-index-d1bxd40m.js";
5
+
6
+ // packages/adapter-vue/src/runtime/client.ts
7
+ import {
8
+ createApp,
9
+ createSSRApp,
10
+ defineComponent as defineComponent2,
11
+ h as h2,
12
+ inject as inject2,
13
+ onBeforeUnmount,
14
+ onMounted as onMounted2,
15
+ onUpdated,
16
+ shallowRef as shallowRef2,
17
+ useId
18
+ } from "vue";
19
+ import { setAdapterInstance } from "hamur/adapter";
20
+ import {
21
+ fetchServerComponent,
22
+ reportClientError,
23
+ serverComponentAttributes,
24
+ serverComponentProps,
25
+ takeServerHTML
26
+ } from "hamur/adapter";
27
+
28
+ // packages/adapter-vue/src/client-fallback.ts
29
+ var clientFallbackIds = new Set;
30
+
31
+ // packages/adapter-vue/src/runtime/hydration.ts
32
+ var devHydration = {};
33
+ // packages/adapter-vue/src/client-component.ts
34
+ import { Suspense, defineAsyncComponent, defineComponent, h, inject, onMounted, ref, shallowRef } from "vue";
35
+ var ClientOnlyKey = Symbol("hamur.clientOnly");
36
+ function clientComponent2(load) {
37
+ const Loaded = defineAsyncComponent(load);
38
+ return defineComponent({
39
+ name: "ClientComponent",
40
+ inheritAttrs: false,
41
+ setup(_, { attrs, slots, expose }) {
42
+ const scope = inject(ClientOnlyKey, null);
43
+ const hydrated = ref(scope !== null);
44
+ const inner = shallowRef(null);
45
+ onMounted(() => {
46
+ hydrated.value = true;
47
+ });
48
+ expose(new Proxy({}, {
49
+ get: (_target, key) => inner.value?.[key],
50
+ has: (_target, key) => inner.value !== null && (key in inner.value)
51
+ }));
52
+ return () => {
53
+ if (!hydrated.value)
54
+ return null;
55
+ const loaded = () => h(Loaded, { ...attrs, ref: inner }, slots);
56
+ return scope ? h(Suspense, null, { default: loaded, fallback: () => scope.fallback?.() }) : loaded();
57
+ };
58
+ }
59
+ });
60
+ }
61
+
62
+ // packages/adapter-vue/src/runtime/client.ts
63
+ var root;
64
+ var RENDER_INFO = new Set([
65
+ "setup function",
66
+ "render function",
67
+ "https://vuejs.org/error-reference/#runtime-0",
68
+ "https://vuejs.org/error-reference/#runtime-1"
69
+ ]);
70
+ function rootErrorHandler2(app) {
71
+ return (error, _instance, info) => {
72
+ const render = RENDER_INFO.has(info);
73
+ if (!render) {
74
+ if (undefined)
75
+ ;
76
+ else
77
+ console.error(error);
78
+ }
79
+ reportClientError(app, error, { render });
80
+ };
81
+ }
82
+ async function start(create, ctx) {
83
+ root = createRoot(ctx);
84
+ for (const id of create === createSSRApp && Array.isArray(ctx.payload.clientFallback) ? ctx.payload.clientFallback : [])
85
+ clientFallbackIds.add(String(id));
86
+ const app = create(root.component);
87
+ app.config.errorHandler = rootErrorHandler2(ctx.app);
88
+ root.install(app);
89
+ await setAdapterInstance(ctx.app, app);
90
+ const watch = create === createSSRApp ? devHydration.watch?.(ctx.root) : undefined;
91
+ try {
92
+ app.mount(ctx.root);
93
+ } finally {
94
+ watch?.done();
95
+ }
96
+ }
97
+ function hydrate2(ctx) {
98
+ return start(createSSRApp, ctx);
99
+ }
100
+ function mount2(ctx) {
101
+ return start(createApp, ctx);
102
+ }
103
+ function update2(ctx) {
104
+ if (!root)
105
+ throw new Error("update() called before hydrate() or mount()");
106
+ return root.update(ctx);
107
+ }
108
+ function serverComponent2(name) {
109
+ return defineComponent2({
110
+ name: `${name}.server`,
111
+ inheritAttrs: false,
112
+ setup(_, { attrs, slots }) {
113
+ const app = inject2(AppKey);
114
+ const uid = useId();
115
+ const textOf = () => serverComponentProps(name, { ...attrs }, slots.default !== undefined);
116
+ const initial = takeServerHTML(app, uid, name);
117
+ const view = shallowRef2({ html: initial ?? "" });
118
+ const failed = shallowRef2();
119
+ let requested = initial === undefined ? undefined : textOf();
120
+ let controller;
121
+ let head;
122
+ const sync = () => {
123
+ const text = textOf();
124
+ if (text === requested)
125
+ return;
126
+ requested = text;
127
+ controller?.abort();
128
+ const current = controller = new AbortController;
129
+ fetchServerComponent(app, name, text, current.signal).then((next) => {
130
+ if (current.signal.aborted)
131
+ return;
132
+ head?.dispose();
133
+ head = next.head ? app.head.push(next.head) : undefined;
134
+ view.value = next;
135
+ }).catch((error) => {
136
+ if (!current.signal.aborted)
137
+ failed.value = { error };
138
+ });
139
+ };
140
+ onMounted2(sync);
141
+ onUpdated(sync);
142
+ onBeforeUnmount(() => {
143
+ controller?.abort();
144
+ head?.dispose();
145
+ });
146
+ return () => {
147
+ if (failed.value)
148
+ throw failed.value.error;
149
+ textOf();
150
+ return h2("hamur-component", {
151
+ name,
152
+ uid,
153
+ ...serverComponentAttributes(name),
154
+ innerHTML: view.value.html
155
+ });
156
+ };
157
+ }
158
+ });
159
+ }
160
+
161
+ export { clientComponent2, rootErrorHandler2, hydrate2, mount2, update2, serverComponent2 };