@hamur/adapter-vue 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 (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 +46 -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
@@ -0,0 +1,1348 @@
1
+ import {
2
+ RouteKey,
3
+ RouterKey,
4
+ NeverHydratedKey,
5
+ BaseURLKey,
6
+ HrefKey,
7
+ DataKey,
8
+ EntryKey,
9
+ ErrorKey,
10
+ HeadKey,
11
+ HeadPatchesKey,
12
+ StateKey,
13
+ SubmittedKey,
14
+ FormStatusKey,
15
+ AppKey,
16
+ LinkHrefKey,
17
+ NavigationKey,
18
+ OutletValueKey,
19
+ LayoutKey,
20
+ detachedHref
21
+ } from "../chunks/browser-index-d1bxd40m.js";
22
+
23
+ // packages/adapter-vue/src/index.ts
24
+ import {
25
+ computed,
26
+ customRef,
27
+ defineComponent as defineComponent5,
28
+ getCurrentInstance,
29
+ getCurrentScope,
30
+ h as h5,
31
+ inject as inject3,
32
+ isRef as isRef2,
33
+ onActivated,
34
+ onBeforeUpdate,
35
+ onDeactivated,
36
+ onMounted as onMounted2,
37
+ onScopeDispose,
38
+ onServerPrefetch,
39
+ reactive,
40
+ shallowReactive,
41
+ shallowRef as shallowRef2,
42
+ toValue as toValue2,
43
+ useId as useId3,
44
+ watch,
45
+ watchEffect,
46
+ onUnmounted
47
+ } from "vue";
48
+ import { reportWebVitals, syncedState } from "hamur/app";
49
+ import {
50
+ asyncDataArguments,
51
+ asyncDataKey,
52
+ checkTransitionName,
53
+ stateArguments,
54
+ fetchKey,
55
+ TIME_PROPS,
56
+ timeView,
57
+ watchTime,
58
+ LOADING_INDICATOR_PROPS,
59
+ createLoadingIndicator,
60
+ loadingIndicatorOptions,
61
+ paintLoadingIndicator,
62
+ createRouteAnnouncer,
63
+ createAnnouncer,
64
+ announcerActions,
65
+ announcerRole,
66
+ hideAnnouncer,
67
+ ROUTE_ANNOUNCER_ID,
68
+ ANNOUNCER_POLITE_ID,
69
+ ANNOUNCER_ASSERTIVE_ID,
70
+ isHandlerReference,
71
+ isPending,
72
+ resolveCallOptions
73
+ } from "hamur/adapter";
74
+ import { whenAppReady } from "hamur/adapter";
75
+ import { clearAsyncData, createForm, useCookie as cookieOf, withoutBase } from "hamur/app";
76
+ import {
77
+ callOnce as callOnceOf,
78
+ clearState as clearStateOf,
79
+ setResponseStatus as setResponseStatusOf,
80
+ useResponseHeader as responseHeaderOf,
81
+ useRequestEvent as requestEventOf,
82
+ useRequestFetch as requestFetchOf,
83
+ useRequestHeader as requestHeaderOf,
84
+ useRequestHeaders as requestHeadersOf,
85
+ useRequestURL as requestURLOf,
86
+ usePreviewMode as previewModeOf
87
+ } from "hamur/app";
88
+ import {
89
+ layoutSegments,
90
+ IDLE_FORM_STATUS,
91
+ createActionRunner,
92
+ linkActionRunner,
93
+ restoredResult,
94
+ optimisticSource,
95
+ runtimeConfigOf,
96
+ siteConfigOf,
97
+ sanitizeHead,
98
+ seoMetaToHead,
99
+ navigationHook,
100
+ navigationBlocker,
101
+ routeGuard,
102
+ createBlocker,
103
+ registerSnapshot
104
+ } from "hamur/adapter";
105
+ import { prehydrate } from "hamur/adapter";
106
+ import {
107
+ linkPending,
108
+ createLinkSlot,
109
+ linkAttributes,
110
+ linkDefaultsOf,
111
+ linkPrefetchProps,
112
+ linkState,
113
+ relativeTarget,
114
+ resolveLinkTarget,
115
+ searchTarget
116
+ } from "hamur/adapter";
117
+ import { $fetch } from "hamur/app";
118
+
119
+ // packages/adapter-vue/src/async-data.ts
120
+ import { isRef, toValue } from "vue";
121
+ import { isPreviewMode } from "hamur/adapter";
122
+ var isPlain = (value) => {
123
+ if (value === null || typeof value !== "object")
124
+ return false;
125
+ const prototype = Object.getPrototypeOf(value);
126
+ return prototype === Object.prototype || prototype === null;
127
+ };
128
+ var plainFunction = (key, list) => key === "titleTemplate" || list === "script" && key === "innerHTML";
129
+ function unwrap(value, getters, key, list) {
130
+ if (isRef(value))
131
+ return unwrap(value.value, getters, key, list);
132
+ if (getters && typeof value === "function" && !plainFunction(key, list))
133
+ return unwrap(value(), getters, key, list);
134
+ if (Array.isArray(value))
135
+ return value.map((item) => unwrap(item, getters, undefined, key));
136
+ if (isPlain(value))
137
+ return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, unwrap(item, getters, name, list)]));
138
+ return value;
139
+ }
140
+ function hasReactive(value, key, list) {
141
+ if (isRef(value) || typeof value === "function" && !plainFunction(key, list))
142
+ return true;
143
+ if (Array.isArray(value))
144
+ return value.some((item) => hasReactive(item, undefined, key));
145
+ if (isPlain(value))
146
+ return Object.entries(value).some(([name, item]) => hasReactive(item, name, list));
147
+ return false;
148
+ }
149
+ var deepToValue = (source, getters = false) => unwrap(toValue(source), getters);
150
+ function defaultGetCachedData(key, app) {
151
+ if (!app.asyncData.hydrating || isPreviewMode(app))
152
+ return;
153
+ const entry = app.asyncData.get(key);
154
+ return entry?.status === "success" ? entry.data : undefined;
155
+ }
156
+ function refreshCached(app, key, handler, options, getCachedData, cause) {
157
+ const cached = getCachedData(key, app, { cause });
158
+ if (cached !== undefined) {
159
+ app.asyncData.fetch(key, handler, { ...options, cached });
160
+ return Promise.resolve();
161
+ }
162
+ if (!app.asyncData.has(key))
163
+ app.asyncData.fetch(key, handler, { ...options, immediate: false });
164
+ return app.asyncData.refresh(key, handler);
165
+ }
166
+ var kept = new WeakMap;
167
+ function keepCached(app, key, getCachedData) {
168
+ if (getCachedData === defaultGetCachedData)
169
+ return;
170
+ let keys = kept.get(app.asyncData);
171
+ if (!keys)
172
+ kept.set(app.asyncData, keys = new Set);
173
+ if (keys.has(key))
174
+ return;
175
+ keys.add(key);
176
+ app.asyncData.subscribe(key, () => {});
177
+ }
178
+ var signalOf = (own, run) => own ? AbortSignal.any([own, run]) : run;
179
+
180
+ // packages/adapter-vue/src/index.ts
181
+ import {
182
+ addRouteMiddleware,
183
+ clearError,
184
+ disableScrollHandling,
185
+ forbidden,
186
+ navigateTo,
187
+ notFound,
188
+ permanentRedirect,
189
+ refreshCookie,
190
+ setPageLayout,
191
+ showError,
192
+ unauthorized
193
+ } from "hamur/app";
194
+
195
+ // packages/adapter-vue/src/lazy-hydration.ts
196
+ import { defineAsyncComponent, defineComponent, h, onBeforeUnmount, onMounted, provide, shallowRef } from "vue";
197
+ import { HYDRATE_ELEMENT, hydrateOnAttribute, replayInteraction, whenTriggered } from "hamur/adapter";
198
+ var served = (element) => element.firstElementChild !== null || (element.textContent ?? "") !== "";
199
+ function defineLazyHydrationComponent(on, loader, options = {}) {
200
+ const attribute = hydrateOnAttribute(on);
201
+ return defineComponent({
202
+ name: "LazyHydration",
203
+ inheritAttrs: false,
204
+ props: { onHydrated: Function },
205
+ setup(props, { attrs, slots }) {
206
+ if (on === "never")
207
+ provide(NeverHydratedKey, true);
208
+ const wrapper = shallowRef();
209
+ let release;
210
+ const gate = typeof window === "undefined" ? undefined : new Promise((resolve) => release = resolve);
211
+ const Inner = defineAsyncComponent({
212
+ loader: () => (gate ? gate.then(loader) : loader()).then((loaded) => loaded.default),
213
+ suspensible: false
214
+ });
215
+ const controller = new AbortController;
216
+ let called = false;
217
+ const mounted = () => {
218
+ if (called)
219
+ return;
220
+ called = true;
221
+ props.onHydrated?.();
222
+ if (wrapper.value)
223
+ replayInteraction(wrapper.value);
224
+ };
225
+ onMounted(() => {
226
+ const element = wrapper.value;
227
+ if (!release || !element)
228
+ return;
229
+ if (served(element))
230
+ whenTriggered(element, on, { ...options, signal: controller.signal }).then(release);
231
+ else
232
+ release();
233
+ });
234
+ onBeforeUnmount(() => controller.abort());
235
+ return () => h(HYDRATE_ELEMENT, { on: attribute, ref: wrapper }, [h(Inner, { ...attrs, onVnodeMounted: mounted }, slots)]);
236
+ }
237
+ });
238
+ }
239
+ // packages/adapter-vue/src/island.ts
240
+ import { defineComponent as defineComponent2, h as h2, inject, useId } from "vue";
241
+ import { ISLAND_ELEMENT, renderIsland } from "hamur/adapter";
242
+ var isServer = typeof document === "undefined";
243
+ var Island = defineComponent2({
244
+ name: "Island",
245
+ props: {
246
+ component: { type: [Object, Function], required: true },
247
+ props: { type: Object, default: undefined },
248
+ on: { type: [String, Object], default: undefined },
249
+ persist: { type: String, default: undefined },
250
+ persistProps: { type: Boolean, default: false }
251
+ },
252
+ setup(props, { slots }) {
253
+ const app = inject(AppKey, null);
254
+ if (!app)
255
+ throw new Error("Island must be rendered inside a Hamur app");
256
+ const id = useId();
257
+ if (!isServer)
258
+ return () => h2(ISLAND_ELEMENT);
259
+ const children = slots.default;
260
+ const island = renderIsland(app, id, props.component, props.props ?? {}, props.on, children ? { component: () => children() } : undefined, { persist: props.persist, persistProps: props.persistProps });
261
+ if (!island.html)
262
+ return () => h2(ISLAND_ELEMENT, island.attributes, slots.fallback?.());
263
+ return island.html.then((html) => () => h2(ISLAND_ELEMENT, { ...island.attributes, innerHTML: html }));
264
+ }
265
+ });
266
+ // packages/adapter-vue/src/server-island.ts
267
+ import { defineComponent as defineComponent3, h as h3, inject as inject2, useId as useId2 } from "vue";
268
+ import { SERVER_ISLAND_ELEMENT, renderServerIsland, serverIslandProps } from "hamur/adapter";
269
+ var isServer2 = typeof document === "undefined";
270
+ var ServerIsland = defineComponent3({
271
+ name: "ServerIsland",
272
+ props: {
273
+ name: { type: String, required: true },
274
+ props: { type: Object, default: undefined }
275
+ },
276
+ setup(props, { slots }) {
277
+ const app = inject2(AppKey, null);
278
+ if (!app)
279
+ throw new Error("ServerIsland must be rendered inside a Hamur app");
280
+ const id = useId2();
281
+ if (isServer2)
282
+ return renderServerIsland(app, id, props.name, props.props).attributes.then((attributes) => () => h3(SERVER_ISLAND_ELEMENT, attributes, slots.fallback?.()));
283
+ if (app.asyncData.hydrating)
284
+ return () => h3(SERVER_ISLAND_ELEMENT);
285
+ const given = props.props && Object.keys(props.props).length ? { props: serverIslandProps(props.name, props.props) } : {};
286
+ return () => h3(SERVER_ISLAND_ELEMENT, { name: props.name, ...given }, slots.fallback?.());
287
+ }
288
+ });
289
+ // packages/adapter-vue/src/markdown.ts
290
+ import { Fragment, camelize, defineComponent as defineComponent4, h as h4 } from "vue";
291
+ import { markdownLink, markdownProse, markdownView } from "hamur/adapter";
292
+ import Link from "../../src/components/Link.vue";
293
+ function propsFor(component, props) {
294
+ const options = component.props;
295
+ const declared = new Set(Array.isArray(options) ? options : typeof options === "object" && options !== null ? Object.keys(options) : []);
296
+ const entries = Object.entries(props);
297
+ const [element] = markdownView([
298
+ "span",
299
+ Object.fromEntries(entries.filter(([name]) => !declared.has(camelize(name))))
300
+ ]);
301
+ return { ...element.attrs, ...Object.fromEntries(entries.filter(([name]) => declared.has(camelize(name)))) };
302
+ }
303
+ function render(view, raw, components) {
304
+ if (typeof view === "string")
305
+ return view;
306
+ if ("html" in view)
307
+ return h4("hamur-html", { style: "display:contents", innerHTML: raw(view.html) });
308
+ const children = () => view.children.map((child) => render(child, raw, components));
309
+ if ("component" in view) {
310
+ const component = Object.hasOwn(components, view.component) ? components[view.component] : undefined;
311
+ if (component) {
312
+ const slots = Object.fromEntries(Object.entries(view.slots).map(([name, views]) => [
313
+ name,
314
+ () => views.map((slot) => render(slot, raw, components))
315
+ ]));
316
+ return h4(component, propsFor(component, view.props), view.children.length ? { ...slots, default: children } : slots);
317
+ }
318
+ return view.attrs ? h4(view.component, view.attrs, children()) : h4(Fragment, children());
319
+ }
320
+ const link = markdownLink(view);
321
+ if (link)
322
+ return h4(Link, { ...link.attrs, to: link.to }, { default: children });
323
+ return h4(view.tag, view.attrs, children());
324
+ }
325
+ var MarkdownRenderer = defineComponent4({
326
+ name: "MarkdownRenderer",
327
+ props: {
328
+ value: { type: [String, Array, Object], required: true },
329
+ components: { type: Object, default: undefined },
330
+ raw: { type: Function, default: undefined }
331
+ },
332
+ setup(props) {
333
+ return () => {
334
+ const { value, components } = markdownProse(props.value, props.components ?? {});
335
+ return h4(Fragment, markdownView(value, { html: props.raw !== undefined, components }).map((view) => render(view, props.raw, components)));
336
+ };
337
+ }
338
+ });
339
+
340
+ // packages/adapter-vue/src/index.ts
341
+ import { matchesOf, routeDataOf } from "hamur/adapter";
342
+ import { equalSearch, isOnline, pollInterval, resolveRelative, startPoll, subscribeOnline } from "hamur/adapter";
343
+ import { APP_UPDATE_OFF, createAppUpdate } from "hamur/adapter";
344
+ import { default as default2 } from "../../src/components/Link.vue";
345
+ import LinkComponent from "../../src/components/Link.vue";
346
+ import { default as default3 } from "../../src/components/Form.vue";
347
+ import { default as default4 } from "../../src/components/Outlet.vue";
348
+ import { default as default5 } from "../../src/components/ClientFallback.vue";
349
+ import { default as default6 } from "../../src/components/ClientOnly.vue";
350
+ import { default as default7 } from "../../src/components/DevOnly.vue";
351
+ import { default as default8 } from "../../src/components/Await.vue";
352
+ import { default as default9 } from "../../src/components/Navigate.vue";
353
+ import { default as default10 } from "../../src/components/ErrorBoundary.vue";
354
+ import { default as default11 } from "../../src/components/DefaultErrorPage.vue";
355
+ function useDeferred(promise) {
356
+ return Promise.resolve(promise);
357
+ }
358
+ function useRoute(name) {
359
+ const route = inject3(RouteKey, null);
360
+ if (!route)
361
+ throw new Error("useRoute() must be called inside a Hamur app");
362
+ return route;
363
+ }
364
+ function useResolvedPath(to, { relative } = {}) {
365
+ const route = useRoute();
366
+ return computed(() => resolveRelative(toValue2(to), route, relative));
367
+ }
368
+ function useOutletContext() {
369
+ const value = inject3(OutletValueKey, null);
370
+ return computed(() => value?.());
371
+ }
372
+ function useLayoutSegments() {
373
+ const route = inject3(RouteKey, null);
374
+ const entry = inject3(EntryKey, null);
375
+ if (!route || !entry)
376
+ throw new Error("useLayoutSegments() must be called inside a Hamur app");
377
+ return computed(() => layoutSegments(route, entry()));
378
+ }
379
+ function useLayoutSegment() {
380
+ const segments = useLayoutSegments();
381
+ return computed(() => segments.value[0] ?? null);
382
+ }
383
+ function useLayout() {
384
+ const layout = inject3(LayoutKey, null);
385
+ if (!layout)
386
+ throw new Error("useLayout() must be called inside a Hamur app");
387
+ return layout;
388
+ }
389
+ function useRouter() {
390
+ const router = inject3(RouterKey, null);
391
+ if (!router)
392
+ throw new Error("useRouter() must be called inside a Hamur app");
393
+ return router;
394
+ }
395
+ function useData(...unknownRoute) {
396
+ const data = inject3(DataKey, null);
397
+ const key = inject3(EntryKey, null);
398
+ if (!data || !key)
399
+ throw new Error("useData() must be called inside a Hamur app");
400
+ return computed(() => data.value[key()] ?? null);
401
+ }
402
+ function useRouteData(name) {
403
+ const route = inject3(RouteKey, null);
404
+ const data = inject3(DataKey, null);
405
+ if (!route || !data)
406
+ throw new Error("useRouteData() must be called inside a Hamur app");
407
+ return computed(() => routeDataOf(route, data.value, name));
408
+ }
409
+ function useMatches() {
410
+ const route = inject3(RouteKey, null);
411
+ const data = inject3(DataKey, null);
412
+ if (!route || !data)
413
+ throw new Error("useMatches() must be called inside a Hamur app");
414
+ return computed(() => matchesOf(route, data.value));
415
+ }
416
+ function useApp() {
417
+ const app = inject3(AppKey, null);
418
+ if (!app)
419
+ throw new Error("useApp() must be called inside a Hamur app");
420
+ return app;
421
+ }
422
+ function useRuntimeHook(name, fn) {
423
+ onScopeDispose(useApp().hooks.hook(name, fn));
424
+ }
425
+ function useReportWebVitals(fn) {
426
+ onScopeDispose(reportWebVitals(useApp(), fn));
427
+ }
428
+ function onAppReady(fn) {
429
+ whenAppReady(useApp(), fn);
430
+ }
431
+ function onPrehydrate(fn) {
432
+ return prehydrate(useApp(), fn);
433
+ }
434
+ function useRequestEvent() {
435
+ return requestEventOf(useApp());
436
+ }
437
+ function usePreviewMode() {
438
+ return previewModeOf(useApp());
439
+ }
440
+ function useRequestHeaders(names) {
441
+ return requestHeadersOf(useApp(), names);
442
+ }
443
+ function useRequestHeader(name) {
444
+ return requestHeaderOf(useApp(), name);
445
+ }
446
+ function useRequestURL() {
447
+ return requestURLOf(useApp());
448
+ }
449
+ function useRequestFetch() {
450
+ return requestFetchOf(useApp());
451
+ }
452
+ function setResponseStatus(status, statusText) {
453
+ setResponseStatusOf(useApp(), status, statusText);
454
+ }
455
+ function useResponseHeader(name) {
456
+ const header = responseHeaderOf(useApp(), name);
457
+ return customRef((track) => ({
458
+ get() {
459
+ track();
460
+ return header.get();
461
+ },
462
+ set: header.set
463
+ }));
464
+ }
465
+ var HttpStatusCode = (props) => {
466
+ setResponseStatus(props.code, props.text);
467
+ return null;
468
+ };
469
+ HttpStatusCode.props = ["code", "text"];
470
+ var HttpHeader = (props) => {
471
+ responseHeaderOf(useApp(), props.name).set(props.value);
472
+ return null;
473
+ };
474
+ HttpHeader.props = ["name", "value"];
475
+ var Time = defineComponent5((props) => {
476
+ const app = useApp();
477
+ const route = useRoute();
478
+ const now = shallowRef2();
479
+ const view = computed(() => timeView(app, route.path, props, now.value));
480
+ let stop;
481
+ onMounted2(() => watch(() => view.value.interval, (interval) => {
482
+ stop?.();
483
+ stop = interval === undefined ? undefined : watchTime(interval, (next) => now.value = next);
484
+ }, { immediate: true }));
485
+ onUnmounted(() => stop?.());
486
+ return () => h5("time", { datetime: view.value.iso, "data-locale": view.value.locale, "data-time-zone": view.value.timeZone }, view.value.text);
487
+ }, {
488
+ name: "Time",
489
+ props: [...TIME_PROPS]
490
+ });
491
+ function useLoadingIndicator(options) {
492
+ const store = createLoadingIndicator(useApp(), options);
493
+ const navigation = useNavigation();
494
+ const state = shallowRef2(store.get());
495
+ whileMounted(() => {
496
+ state.value = store.get();
497
+ const stopState = store.subscribe(() => state.value = store.get());
498
+ const stopFollow = store.follow({
499
+ get: () => navigation.value,
500
+ subscribe: (listener) => watch(navigation, listener, { flush: "sync" })
501
+ });
502
+ return () => {
503
+ stopState();
504
+ stopFollow();
505
+ };
506
+ });
507
+ return {
508
+ progress: computed(() => state.value.progress),
509
+ isLoading: computed(() => state.value.isLoading),
510
+ error: computed(() => state.value.error),
511
+ start: store.start,
512
+ finish: store.finish,
513
+ set: store.set,
514
+ clear: store.clear
515
+ };
516
+ }
517
+ function useAppUpdate() {
518
+ const store = createAppUpdate(useApp());
519
+ const state = shallowRef2(APP_UPDATE_OFF);
520
+ whileMounted(() => {
521
+ state.value = store.get();
522
+ return store.subscribe(() => state.value = store.get());
523
+ });
524
+ return {
525
+ available: computed(() => state.value.available),
526
+ buildId: computed(() => state.value.buildId),
527
+ time: computed(() => state.value.time),
528
+ check: store.check
529
+ };
530
+ }
531
+ var LoadingIndicator = defineComponent5((props) => {
532
+ const { progress, isLoading, error } = useLoadingIndicator(loadingIndicatorOptions(props));
533
+ const element = shallowRef2(null);
534
+ onMounted2(() => watch(() => [progress.value, isLoading.value, error.value, props.color, props.errorColor, props.height], () => element.value && paintLoadingIndicator(element.value, { progress: progress.value, isLoading: isLoading.value, error: error.value }, { color: props.color, errorColor: props.errorColor, height: props.height }), { immediate: true, flush: "post" }));
535
+ return () => h5("div", { ref: element, "data-hamur-loading-indicator": "", "aria-hidden": "true" });
536
+ }, {
537
+ name: "LoadingIndicator",
538
+ props: [...LOADING_INDICATOR_PROPS]
539
+ });
540
+ function useRouteAnnouncer() {
541
+ const store = createRouteAnnouncer(useApp());
542
+ const state = shallowRef2(store.get());
543
+ whileMounted(() => {
544
+ state.value = store.get();
545
+ return store.subscribe(() => state.value = store.get());
546
+ });
547
+ return {
548
+ message: computed(() => state.value.message),
549
+ politeness: computed(() => state.value.politeness),
550
+ set: store.set,
551
+ polite: store.polite,
552
+ assertive: store.assertive
553
+ };
554
+ }
555
+ var RouteAnnouncer = defineComponent5((props, { attrs }) => {
556
+ const store = createRouteAnnouncer(useApp());
557
+ const { message, politeness } = useRouteAnnouncer();
558
+ const element = shallowRef2(null);
559
+ const key = {};
560
+ const tick = shallowRef2(0);
561
+ const owner = computed(() => (tick.value, store.claim(key, () => tick.value++)));
562
+ let unmount;
563
+ let stop;
564
+ onMounted2(() => {
565
+ stop = watch(owner, (owns) => {
566
+ unmount?.();
567
+ unmount = undefined;
568
+ if (!owns)
569
+ return;
570
+ unmount = store.mount();
571
+ if (!attrs.class && !attrs.style && element.value)
572
+ hideAnnouncer(element.value);
573
+ }, { immediate: true, flush: "post" });
574
+ });
575
+ onUnmounted(() => {
576
+ stop?.();
577
+ unmount?.();
578
+ store.release(key);
579
+ });
580
+ return () => {
581
+ if (!owner.value)
582
+ return h5("div", { "aria-live": "off", "aria-atomic": "true" });
583
+ const live = props.politeness ?? politeness.value;
584
+ return h5("div", { ref: element, id: ROUTE_ANNOUNCER_ID, "aria-live": live, "aria-atomic": "true", role: announcerRole(live) }, message.value);
585
+ };
586
+ }, {
587
+ name: "RouteAnnouncer",
588
+ props: ["politeness"]
589
+ });
590
+ function useAnnouncer({ politeness = "polite" } = {}) {
591
+ const store = createAnnouncer(useApp());
592
+ const state = shallowRef2(store.get());
593
+ whileMounted(() => {
594
+ state.value = store.get();
595
+ return store.subscribe(() => state.value = store.get());
596
+ });
597
+ return {
598
+ message: computed(() => state.value.message),
599
+ politeness: computed(() => state.value.politeness),
600
+ ...announcerActions(store, politeness)
601
+ };
602
+ }
603
+ var Announcer = defineComponent5(() => {
604
+ const store = createAnnouncer(useApp());
605
+ const state = shallowRef2(store.get());
606
+ const polite = shallowRef2(null);
607
+ const assertive = shallowRef2(null);
608
+ onMounted2(() => {
609
+ for (const element of [polite.value, assertive.value])
610
+ if (element)
611
+ hideAnnouncer(element);
612
+ });
613
+ whileMounted(() => {
614
+ state.value = store.get();
615
+ const stop = store.subscribe(() => state.value = store.get());
616
+ const unmount = store.mount();
617
+ return () => {
618
+ stop();
619
+ unmount();
620
+ };
621
+ });
622
+ return () => [
623
+ h5("div", { ref: polite, id: ANNOUNCER_POLITE_ID, "aria-live": "polite", "aria-atomic": "true", role: "status" }, state.value.regions.polite),
624
+ h5("div", { ref: assertive, id: ANNOUNCER_ASSERTIVE_ID, "aria-live": "assertive", "aria-atomic": "true", role: "alert" }, state.value.regions.assertive)
625
+ ];
626
+ }, { name: "Announcer" });
627
+ function useAsyncDataEntry(target, input) {
628
+ const store = useApp().asyncData;
629
+ const key = typeof target === "string" ? target : asyncDataKey(target, deepToValue(input));
630
+ const data = customRef((track, trigger) => {
631
+ if (getCurrentScope())
632
+ onScopeDispose(store.subscribe(key, trigger));
633
+ return {
634
+ get() {
635
+ track();
636
+ return store.get(key)?.data;
637
+ },
638
+ set(next) {
639
+ store.setData(key, next);
640
+ }
641
+ };
642
+ });
643
+ return { data };
644
+ }
645
+ var useNuxtData = useAsyncDataEntry;
646
+ function clearState(keys, options) {
647
+ clearStateOf(useApp(), keys, options);
648
+ }
649
+ function callOnce(key, fn, options) {
650
+ return callOnceOf(useApp(), key, fn, options);
651
+ }
652
+ function useRuntimeConfig() {
653
+ return runtimeConfigOf(useApp());
654
+ }
655
+ function useSiteConfig() {
656
+ return siteConfigOf(useApp());
657
+ }
658
+ function useNavigation() {
659
+ const navigation = inject3(NavigationKey, null);
660
+ if (!navigation)
661
+ throw new Error("useNavigation() must be called inside a Hamur app");
662
+ return navigation;
663
+ }
664
+ function defineLink(defaults) {
665
+ return defineComponent5({
666
+ name: "Link",
667
+ inheritAttrs: false,
668
+ setup: (_, { attrs, slots }) => () => h5(LinkComponent, { ...attrs, defaults }, slots)
669
+ });
670
+ }
671
+ function useLink(to, options) {
672
+ const baseURL = inject3(BaseURLKey, "/");
673
+ const resolve = inject3(HrefKey, detachedHref);
674
+ const route = inject3(RouteKey, null);
675
+ const app = inject3(AppKey, null);
676
+ const router = inject3(RouterKey, null);
677
+ const navigation = inject3(NavigationKey, null);
678
+ return computed(() => {
679
+ const given = toValue2(options) ?? {};
680
+ const defaults = linkDefaultsOf(app);
681
+ const base = toValue2(to);
682
+ const searched = route ? searchTarget(relativeTarget(base, route, given.relative), route, given.query) : base;
683
+ const { to: target } = resolveLinkTarget(app, searched, given, resolve, given.external);
684
+ const href = resolve(target);
685
+ const state = route ? linkState(typeof target === "string" ? target : withoutBase(href, baseURL), route) : { active: false, exact: false };
686
+ return createLinkSlot({
687
+ href,
688
+ to: target,
689
+ attrs: linkAttributes({
690
+ href,
691
+ external: given.external,
692
+ ...linkPrefetchProps({}, defaults),
693
+ replace: given.replace,
694
+ viewTransition: given.viewTransition,
695
+ pendingClass: defaults.pendingClass,
696
+ trim: !!given.query,
697
+ ariaCurrent: state.exact ? "page" : undefined,
698
+ prefetchedClass: defaults.prefetchedClass,
699
+ scroll: given.scroll,
700
+ prefetchDelay: defaults.prefetchDelay,
701
+ externalRelAttribute: defaults.externalRelAttribute
702
+ }),
703
+ active: state.active,
704
+ exact: state.exact,
705
+ pending: navigation !== null && linkPending(href, navigation.value, baseURL),
706
+ external: given.external,
707
+ options: {
708
+ replace: given.replace,
709
+ state: given.state,
710
+ viewTransition: given.viewTransition,
711
+ scroll: given.scroll === false ? false : undefined
712
+ },
713
+ router
714
+ });
715
+ });
716
+ }
717
+ function useLinkStatus() {
718
+ const href = inject3(LinkHrefKey, null);
719
+ const navigation = inject3(NavigationKey, null);
720
+ const baseURL = inject3(BaseURLKey, "/");
721
+ return {
722
+ pending: computed(() => href !== null && navigation !== null && linkPending(href.value, navigation.value, baseURL))
723
+ };
724
+ }
725
+ function navigationHookWhileMounted(kind, fn) {
726
+ let off;
727
+ onMounted2(() => off = navigationHook(kind, fn));
728
+ onUnmounted(() => off?.());
729
+ }
730
+ var onBeforeNavigate = (fn) => navigationHookWhileMounted("before", fn);
731
+ var onNavigate = (fn) => navigationHookWhileMounted("navigate", fn);
732
+ var onAfterNavigate = (fn) => navigationHookWhileMounted("after", fn);
733
+ var SHOULD_KEEP_ALIVE = 256;
734
+ function keptByKeepAlive() {
735
+ for (let instance = getCurrentInstance();instance?.parent; instance = instance.parent) {
736
+ if (instance.parent.vnode.type.__isKeepAlive)
737
+ return (instance.vnode.shapeFlag & SHOULD_KEEP_ALIVE) !== 0;
738
+ }
739
+ return false;
740
+ }
741
+ function onPageActivated(fn) {
742
+ if (keptByKeepAlive())
743
+ onActivated(fn);
744
+ else
745
+ onMounted2(fn);
746
+ }
747
+ function onPageDeactivated(fn) {
748
+ if (keptByKeepAlive())
749
+ onDeactivated(fn);
750
+ else
751
+ onUnmounted(fn);
752
+ }
753
+ function whileMounted(register) {
754
+ let off;
755
+ onMounted2(() => off = register());
756
+ onUnmounted(() => off?.());
757
+ }
758
+ function routeGuardWhileMounted(kind, fn) {
759
+ const entry = inject3(EntryKey, null);
760
+ whileMounted(() => routeGuard(kind, entry?.(), fn));
761
+ }
762
+ var onBeforeRouteLeave = (fn) => routeGuardWhileMounted("leave", fn);
763
+ var onBeforeRouteUpdate = (fn) => routeGuardWhileMounted("update", fn);
764
+ function usePreventNavigate(fn) {
765
+ whileMounted(() => navigationBlocker(fn));
766
+ }
767
+ function useBlocker(options) {
768
+ const store = createBlocker(options);
769
+ const value = shallowRef2(store.get());
770
+ whileMounted(() => {
771
+ const unsubscribe = store.subscribe(() => void (value.value = store.get()));
772
+ const stop = store.start();
773
+ const stopSync = watchEffect(() => store.sync());
774
+ return () => (stopSync(), stop(), unsubscribe());
775
+ });
776
+ return value;
777
+ }
778
+ function useSnapshot(key, options) {
779
+ whileMounted(() => registerSnapshot(key, options));
780
+ }
781
+ function useSearch(select) {
782
+ const route = inject3(RouteKey, null);
783
+ const router = inject3(RouterKey, null);
784
+ if (!route || !router)
785
+ throw new Error("useSearch() must be called inside a Hamur app");
786
+ const value = computed((previous) => {
787
+ const next = select ? select(route.search) : route.search;
788
+ return previous !== undefined && equalSearch(previous, next) ? previous : next;
789
+ });
790
+ const set = (change, { replace = true } = {}) => {
791
+ const update = { query: (prev) => typeof change === "function" ? change(prev) : change };
792
+ return replace ? router.replace(update) : router.navigate(update);
793
+ };
794
+ return { value, set };
795
+ }
796
+ function usePoll(ms, options = {}) {
797
+ pollInterval(ms);
798
+ const router = useRouter();
799
+ let stop;
800
+ onMounted2(() => stop = startPoll(ms, () => options.keys ? router.refresh(options.keys) : router.refresh()));
801
+ onUnmounted(() => stop?.());
802
+ }
803
+ function useOnline() {
804
+ const online = shallowRef2(true);
805
+ let off;
806
+ onMounted2(() => {
807
+ online.value = isOnline();
808
+ off = subscribeOnline((value) => online.value = value);
809
+ });
810
+ onUnmounted(() => off?.());
811
+ return online;
812
+ }
813
+ function useSyncedState(key, initial, options = {}) {
814
+ const state = syncedState(key, initial, options);
815
+ const value = shallowRef2(initial);
816
+ let off;
817
+ onMounted2(() => {
818
+ value.value = state.get();
819
+ off = state.subscribe((next) => value.value = next);
820
+ });
821
+ onUnmounted(() => off?.());
822
+ return computed({ get: () => value.value, set: (next) => state.set(next) });
823
+ }
824
+ function useHydrated() {
825
+ const app = useApp();
826
+ const hydrated = shallowRef2(typeof document !== "undefined" && !app.asyncData.hydrating);
827
+ let off;
828
+ onMounted2(() => {
829
+ hydrated.value = !app.asyncData.hydrating;
830
+ off = app.hooks.hook("app:mounted", () => void (hydrated.value = true));
831
+ });
832
+ onUnmounted(() => off?.());
833
+ return hydrated;
834
+ }
835
+ function useFormStatus() {
836
+ const store = inject3(FormStatusKey, null);
837
+ const status = shallowReactive({ ...store ? store.get() : IDLE_FORM_STATUS });
838
+ if (store)
839
+ onScopeDispose(store.subscribe(() => Object.assign(status, store.get())));
840
+ return status;
841
+ }
842
+ function useForm(fn) {
843
+ const submitted = inject3(SubmittedKey, null);
844
+ const version = shallowRef2(0);
845
+ const form = createForm(fn, {
846
+ app: inject3(AppKey, null),
847
+ submitted: () => submitted?.value ?? {},
848
+ track: () => void version.value
849
+ });
850
+ onScopeDispose(form.subscribe(() => version.value = form.version()));
851
+ return form;
852
+ }
853
+ function useAction(fn, options = {}) {
854
+ const router = useRouter();
855
+ const { handlerState } = inject3(SubmittedKey, null)?.value ?? {};
856
+ const { instance } = options;
857
+ const app = inject3(AppKey, null);
858
+ const runner = createActionRunner(fn, {
859
+ app,
860
+ instance,
861
+ options: () => options,
862
+ refresh: () => router.refresh(),
863
+ restored: restoredResult(handlerState, fn.id, instance)
864
+ });
865
+ const action = shallowReactive({ ...runner.get(), run: runner.run, reset: runner.reset });
866
+ onScopeDispose(runner.subscribe(() => Object.assign(action, runner.get())));
867
+ const below = inject3(FormStatusKey, null);
868
+ if (below)
869
+ onScopeDispose(below.owner.link(fn.id, runner, instance));
870
+ else if (app)
871
+ onScopeDispose(linkActionRunner(app, fn.id, runner, instance));
872
+ return action;
873
+ }
874
+ function useOptimistic(value, reduce) {
875
+ const source = optimisticSource(inject3(AppKey, null));
876
+ const pending = shallowRef2(source.get());
877
+ onScopeDispose(source.subscribe(() => pending.value = source.get()));
878
+ return computed(() => pending.value.length ? reduce(toValue2(value), pending.value) : toValue2(value));
879
+ }
880
+ function useError() {
881
+ const source = inject3(ErrorKey, null);
882
+ if (!source)
883
+ throw new Error("useError() must be called inside a Hamur app");
884
+ const { store } = source;
885
+ const error = shallowRef2(store ? store.get() : source.initial);
886
+ if (store)
887
+ onScopeDispose(store.subscribe(() => error.value = store.get()));
888
+ return error;
889
+ }
890
+ var pendingApply = new WeakSet;
891
+ function scheduleApply(head) {
892
+ if (pendingApply.has(head))
893
+ return;
894
+ pendingApply.add(head);
895
+ queueMicrotask(() => {
896
+ pendingApply.delete(head);
897
+ head.apply();
898
+ });
899
+ }
900
+ var headValue = (input) => deepToValue(input, true);
901
+ function useHead(input) {
902
+ const head = inject3(HeadKey, null);
903
+ if (!head)
904
+ throw new Error("useHead() must be called inside a Hamur app");
905
+ const entry = head.push(headValue(input));
906
+ if (hasReactive(input))
907
+ inject3(HeadPatchesKey, null)?.push(() => entry.patch(headValue(input)));
908
+ onMounted2(() => scheduleApply(head));
909
+ watch(() => headValue(input), (next) => {
910
+ entry.patch(next);
911
+ scheduleApply(head);
912
+ }, { deep: true });
913
+ if (getCurrentScope()) {
914
+ onScopeDispose(() => {
915
+ entry.dispose();
916
+ if (typeof document !== "undefined")
917
+ scheduleApply(head);
918
+ });
919
+ }
920
+ }
921
+ function useSeoMeta(input) {
922
+ useHead(() => seoMetaToHead(headValue(input)));
923
+ }
924
+ function useHeadSafe(input) {
925
+ useHead(() => sanitizeHead(headValue(input)));
926
+ }
927
+ function headAttrsComponent(name, toInput) {
928
+ return defineComponent5((_props, { attrs }) => {
929
+ const snapshot = shallowRef2({ ...attrs });
930
+ onBeforeUpdate(() => snapshot.value = { ...attrs });
931
+ useHead(() => toInput(snapshot.value));
932
+ return () => null;
933
+ }, { name, inheritAttrs: false });
934
+ }
935
+ var HeadTitle = defineComponent5((props) => {
936
+ useHead(() => ({ title: props.title, titleTemplate: props.template }));
937
+ return () => null;
938
+ }, { name: "HeadTitle", props: ["title", "template"] });
939
+ var HeadMeta = headAttrsComponent("HeadMeta", (attrs) => ({
940
+ meta: [attrs]
941
+ }));
942
+ var HeadLink = headAttrsComponent("HeadLink", (attrs) => ({
943
+ link: [attrs]
944
+ }));
945
+ var HeadScript = headAttrsComponent("HeadScript", (attrs) => ({
946
+ script: [attrs]
947
+ }));
948
+ var HeadStyle = headAttrsComponent("HeadStyle", (attrs) => ({
949
+ style: [attrs]
950
+ }));
951
+ var HtmlAttrs = headAttrsComponent("HtmlAttrs", (attrs) => ({
952
+ htmlAttrs: attrs
953
+ }));
954
+ var BodyAttrs = headAttrsComponent("BodyAttrs", (attrs) => ({
955
+ bodyAttrs: attrs
956
+ }));
957
+ function useServerHead(input) {
958
+ if (typeof document !== "undefined")
959
+ return;
960
+ const head = inject3(HeadKey, null);
961
+ if (!head)
962
+ throw new Error("useServerHead() must be called inside a Hamur app");
963
+ const entry = head.push(headValue(input), { server: true });
964
+ if (hasReactive(input))
965
+ inject3(HeadPatchesKey, null)?.push(() => entry.patch(headValue(input)));
966
+ }
967
+ function useServerSeoMeta(input) {
968
+ useServerHead(() => seoMetaToHead(headValue(input)));
969
+ }
970
+ function useState(...args) {
971
+ const { key, init } = stateArguments(args);
972
+ const state = inject3(StateKey, null);
973
+ if (!state)
974
+ throw new Error("useState() must be called inside a Hamur app");
975
+ state.use(key, init);
976
+ return customRef((track, trigger) => {
977
+ if (getCurrentScope())
978
+ onScopeDispose(state.subscribe(key, trigger));
979
+ return {
980
+ get() {
981
+ track();
982
+ return state.get(key);
983
+ },
984
+ set(value) {
985
+ state.set(key, value);
986
+ }
987
+ };
988
+ });
989
+ }
990
+ function useCookie(name, options = {}) {
991
+ const app = inject3(AppKey, null);
992
+ const { watch: mode = true, ...rest } = options;
993
+ const cookie = cookieOf(name, { ...rest, ...app ? { app } : {} });
994
+ const encode = (value) => {
995
+ if (value === undefined)
996
+ return;
997
+ try {
998
+ return rest.encode ? rest.encode(value) : JSON.stringify(value);
999
+ } catch {
1000
+ return;
1001
+ }
1002
+ };
1003
+ let seen;
1004
+ let baseline;
1005
+ let local;
1006
+ const ref = customRef((track, trigger) => {
1007
+ if (getCurrentScope())
1008
+ onScopeDispose(cookie.subscribe(() => {
1009
+ local = undefined;
1010
+ trigger();
1011
+ }));
1012
+ return {
1013
+ get() {
1014
+ track();
1015
+ if (local)
1016
+ return local.value;
1017
+ const value = cookie.get();
1018
+ if (value !== seen) {
1019
+ seen = value;
1020
+ baseline = encode(value);
1021
+ }
1022
+ return mode === true && typeof value === "object" && value !== null ? reactive(value) : value;
1023
+ },
1024
+ set(value) {
1025
+ if (mode === false) {
1026
+ local = { value };
1027
+ trigger();
1028
+ } else
1029
+ cookie.set(value);
1030
+ }
1031
+ };
1032
+ });
1033
+ if (mode === true && getCurrentScope())
1034
+ watch(ref, () => {
1035
+ const value = cookie.get();
1036
+ const now = encode(value);
1037
+ if (now === baseline)
1038
+ return;
1039
+ baseline = now;
1040
+ cookie.set(value);
1041
+ }, { deep: true });
1042
+ return ref;
1043
+ }
1044
+ function useAsyncData(...args) {
1045
+ const [first, second, given] = asyncDataArguments("useAsyncData", args, isRef2);
1046
+ const options = given ?? {};
1047
+ if (!isHandlerReference(first))
1048
+ return keyedAsyncData(first, () => second, options);
1049
+ return handlerAsyncData(first, second, options);
1050
+ }
1051
+ function handlerAsyncData(fn, input, options) {
1052
+ const app = useApp();
1053
+ const inputs = new Map;
1054
+ const keyOf = () => {
1055
+ const value = deepToValue(input);
1056
+ const name = asyncDataKey(fn, value);
1057
+ inputs.set(name, value);
1058
+ return name;
1059
+ };
1060
+ const handlerFor = (name) => {
1061
+ const value = inputs.has(name) ? inputs.get(name) : deepToValue(input);
1062
+ return ({ signal }) => fn(value, {
1063
+ signal,
1064
+ event: app.event
1065
+ });
1066
+ };
1067
+ if (getCurrentScope())
1068
+ onScopeDispose(() => inputs.clear());
1069
+ return keyedAsyncData(keyOf, handlerFor, options, (name) => inputs.delete(name));
1070
+ }
1071
+ function keyedAsyncData(key, handlerFor, options, release) {
1072
+ const app = inject3(AppKey, null);
1073
+ if (!app)
1074
+ throw new Error("useAsyncData() must be called inside a Hamur app");
1075
+ const store = app.asyncData;
1076
+ const never = inject3(NeverHydratedKey, false);
1077
+ const {
1078
+ server,
1079
+ lazy,
1080
+ default: init,
1081
+ transform,
1082
+ immediate,
1083
+ dedupe,
1084
+ pick,
1085
+ deep,
1086
+ watch: sources,
1087
+ getCachedData = defaultGetCachedData
1088
+ } = options;
1089
+ const settings = {
1090
+ server,
1091
+ lazy,
1092
+ default: init,
1093
+ transform,
1094
+ immediate,
1095
+ dedupe,
1096
+ pick
1097
+ };
1098
+ const first = (name) => {
1099
+ store.neverHydrated(name, never);
1100
+ keepCached(app, name, getCachedData);
1101
+ return store.fetch(name, handlerFor(name), {
1102
+ ...settings,
1103
+ cached: getCachedData(name, app, { cause: "initial" })
1104
+ });
1105
+ };
1106
+ const active = shallowRef2(toValue2(key));
1107
+ let entry = first(active.value);
1108
+ const changes = shallowRef2(0);
1109
+ const changed = () => void changes.value++;
1110
+ const scoped = getCurrentScope() !== undefined;
1111
+ let unsubscribe = scoped ? store.subscribe(active.value, changed) : () => {};
1112
+ let unhook = scoped ? store.onRefresh(active.value, () => again("refresh:hook")) : () => {};
1113
+ let disposed = false;
1114
+ if (scoped)
1115
+ onScopeDispose(() => (disposed = true, unsubscribe(), unhook()));
1116
+ if (typeof key !== "string") {
1117
+ watch(() => toValue2(key), (next, previous) => {
1118
+ unsubscribe();
1119
+ unhook();
1120
+ entry = first(next);
1121
+ if (scoped) {
1122
+ unsubscribe = store.subscribe(next, changed);
1123
+ unhook = store.onRefresh(next, () => again("refresh:hook"));
1124
+ }
1125
+ active.value = next;
1126
+ if (previous !== next)
1127
+ release?.(previous);
1128
+ });
1129
+ }
1130
+ const snapshot = computed(() => {
1131
+ changes.value;
1132
+ return store.get(active.value) ?? entry;
1133
+ });
1134
+ if (entry.status === "pending" && entry.promise) {
1135
+ const pending = entry.promise;
1136
+ onServerPrefetch(() => pending);
1137
+ }
1138
+ const again = async (cause) => {
1139
+ const name = active.value;
1140
+ const hold = disposed ? store.subscribe(name, () => {}) : undefined;
1141
+ try {
1142
+ await refreshCached(app, name, handlerFor(name), settings, getCachedData, cause);
1143
+ } finally {
1144
+ hold?.();
1145
+ }
1146
+ };
1147
+ if (Array.isArray(sources) && sources.length)
1148
+ watch(sources, () => void again("watch"));
1149
+ const refresh = () => again("refresh:manual");
1150
+ return {
1151
+ data: computed(() => {
1152
+ const value = snapshot.value.data;
1153
+ return deep === true && value !== null && typeof value === "object" ? reactive(value) : value;
1154
+ }),
1155
+ error: computed(() => snapshot.value.error),
1156
+ status: computed(() => snapshot.value.status),
1157
+ pending: computed(() => isPending(app, snapshot.value)),
1158
+ refresh,
1159
+ execute: refresh,
1160
+ clear: () => clearAsyncData(app, active.value)
1161
+ };
1162
+ }
1163
+ function useFetch(url, options = {}) {
1164
+ return fetchWith(undefined, url, options);
1165
+ }
1166
+ function fetchWith(client, url, options) {
1167
+ const {
1168
+ key: fixedKey,
1169
+ server,
1170
+ lazy,
1171
+ default: init,
1172
+ transform,
1173
+ immediate,
1174
+ dedupe,
1175
+ pick,
1176
+ deep,
1177
+ watch: sources,
1178
+ getCachedData,
1179
+ query,
1180
+ body,
1181
+ ...rest
1182
+ } = options;
1183
+ const request = () => {
1184
+ const resolved = { ...rest };
1185
+ const resolvedQuery = deepToValue(query);
1186
+ const resolvedBody = deepToValue(body);
1187
+ if (resolvedQuery !== undefined)
1188
+ resolved.query = resolvedQuery;
1189
+ if (resolvedBody !== undefined)
1190
+ resolved.body = resolvedBody;
1191
+ return resolved;
1192
+ };
1193
+ const fetcher = client ?? useApp().fetch ?? $fetch;
1194
+ const requests = new Map;
1195
+ const keyOf = () => {
1196
+ const target = toValue2(url);
1197
+ const resolved = request();
1198
+ const name = fetchKey(target, resolved);
1199
+ requests.set(name, { url: target, request: resolved });
1200
+ return name;
1201
+ };
1202
+ const fixed = fixedKey !== undefined || sources === false;
1203
+ const handlerFor = (name) => {
1204
+ const { url: target, request: resolved } = !fixed && requests.get(name) || {
1205
+ url: toValue2(url),
1206
+ request: request()
1207
+ };
1208
+ return ({ signal }) => fetcher(target, { ...resolved, signal: signalOf(resolved.signal, signal) });
1209
+ };
1210
+ if (getCurrentScope())
1211
+ onScopeDispose(() => requests.clear());
1212
+ const key = fixed ? fixedKey ?? fetchKey(toValue2(url), request()) : keyOf;
1213
+ const watched = fixedKey !== undefined && sources !== false ? [...sources ?? [], () => fetchKey(toValue2(url), request())] : sources;
1214
+ return keyedAsyncData(key, handlerFor, { server, lazy, default: init, transform, immediate, dedupe, pick, deep, watch: watched, getCachedData }, (name) => requests.delete(name));
1215
+ }
1216
+ function createUseFetch(defaults, { $fetch: client } = {}) {
1217
+ return (url, options) => fetchWith(client, url, resolveCallOptions(defaults, options, (value) => deepToValue(value)));
1218
+ }
1219
+ function createUseAsyncData(defaults) {
1220
+ return (...args) => {
1221
+ const [first, second, options] = asyncDataArguments("useAsyncData", args, isRef2);
1222
+ return useAsyncData(first, second, resolveCallOptions(defaults, options));
1223
+ };
1224
+ }
1225
+ var useLazyFetch = (url, options) => useFetch(url, { ...options, lazy: true });
1226
+ var useLazyAsyncData = (...args) => {
1227
+ const [first, second, options] = asyncDataArguments("useLazyAsyncData", args, isRef2);
1228
+ return useAsyncData(first, second, {
1229
+ ...options,
1230
+ lazy: true
1231
+ });
1232
+ };
1233
+ function transitionName(name) {
1234
+ return { style: { viewTransitionName: checkTransitionName(name) } };
1235
+ }
1236
+ export {
1237
+ Announcer,
1238
+ default8 as Await,
1239
+ BodyAttrs,
1240
+ default5 as ClientFallback,
1241
+ default6 as ClientOnly,
1242
+ default11 as DefaultErrorPage,
1243
+ default7 as DevOnly,
1244
+ default10 as ErrorBoundary,
1245
+ default3 as Form,
1246
+ HeadLink,
1247
+ HeadMeta,
1248
+ HeadScript,
1249
+ HeadStyle,
1250
+ HeadTitle,
1251
+ HtmlAttrs,
1252
+ HttpHeader,
1253
+ HttpStatusCode,
1254
+ Island,
1255
+ default2 as Link,
1256
+ LoadingIndicator,
1257
+ MarkdownRenderer,
1258
+ default9 as Navigate,
1259
+ default4 as Outlet,
1260
+ RouteAnnouncer,
1261
+ ServerIsland,
1262
+ Time,
1263
+ addRouteMiddleware,
1264
+ callOnce,
1265
+ clearError,
1266
+ clearState,
1267
+ createUseAsyncData,
1268
+ createUseFetch,
1269
+ defineLazyHydrationComponent,
1270
+ defineLink,
1271
+ disableScrollHandling,
1272
+ forbidden,
1273
+ navigateTo,
1274
+ notFound,
1275
+ onAfterNavigate,
1276
+ onAppReady,
1277
+ onBeforeNavigate,
1278
+ onBeforeRouteLeave,
1279
+ onBeforeRouteUpdate,
1280
+ onNavigate,
1281
+ onPageActivated,
1282
+ onPageDeactivated,
1283
+ onPrehydrate,
1284
+ permanentRedirect,
1285
+ refreshCookie,
1286
+ setPageLayout,
1287
+ setResponseStatus,
1288
+ showError,
1289
+ transitionName,
1290
+ unauthorized,
1291
+ useAction,
1292
+ useAnnouncer,
1293
+ useApp,
1294
+ useAppUpdate,
1295
+ useAsyncData,
1296
+ useAsyncDataEntry,
1297
+ useBlocker,
1298
+ useCookie,
1299
+ useData,
1300
+ useDeferred,
1301
+ useError,
1302
+ useFetch,
1303
+ useForm,
1304
+ useFormStatus,
1305
+ useHead,
1306
+ useHeadSafe,
1307
+ useHydrated,
1308
+ useId3 as useId,
1309
+ useLayout,
1310
+ useLayoutSegment,
1311
+ useLayoutSegments,
1312
+ useLazyAsyncData,
1313
+ useLazyFetch,
1314
+ useLink,
1315
+ useLinkStatus,
1316
+ useLoadingIndicator,
1317
+ useMatches,
1318
+ useNavigation,
1319
+ useNuxtData,
1320
+ useOnline,
1321
+ useOptimistic,
1322
+ useOutletContext,
1323
+ usePoll,
1324
+ usePreventNavigate,
1325
+ usePreviewMode,
1326
+ useReportWebVitals,
1327
+ useRequestEvent,
1328
+ useRequestFetch,
1329
+ useRequestHeader,
1330
+ useRequestHeaders,
1331
+ useRequestURL,
1332
+ useResolvedPath,
1333
+ useResponseHeader,
1334
+ useRoute,
1335
+ useRouteAnnouncer,
1336
+ useRouteData,
1337
+ useRouter,
1338
+ useRuntimeConfig,
1339
+ useRuntimeHook,
1340
+ useSearch,
1341
+ useSeoMeta,
1342
+ useServerHead,
1343
+ useServerSeoMeta,
1344
+ useSiteConfig,
1345
+ useSnapshot,
1346
+ useState,
1347
+ useSyncedState
1348
+ };