@hamur/adapter-angular 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 (88) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +42 -2
  3. package/dist/chunks/browser-index-7h7x2xz2.js +131 -0
  4. package/dist/chunks/browser-index-nann848q.js +205 -0
  5. package/dist/chunks/browser-index-qn8q5fa2.js +580 -0
  6. package/dist/src/adapter.js +1075 -0
  7. package/dist/src/error-page.js +34 -0
  8. package/dist/src/index.js +1729 -0
  9. package/dist/src/keepalive.js +0 -0
  10. package/dist/src/runtime/client.js +21 -0
  11. package/dist/src/runtime/island.js +92 -0
  12. package/dist/src/runtime/server.js +175 -0
  13. package/dist/types/src/activation.d.ts +20 -0
  14. package/dist/types/src/adapter.d.ts +7 -0
  15. package/dist/types/src/app.d.ts +6 -0
  16. package/dist/types/src/async-data.d.ts +21 -0
  17. package/dist/types/src/client-parts.d.ts +35 -0
  18. package/dist/types/src/compile.d.ts +99 -0
  19. package/dist/types/src/context.d.ts +74 -0
  20. package/dist/types/src/data.d.ts +65 -0
  21. package/dist/types/src/definition.d.ts +13 -0
  22. package/dist/types/src/error-page.d.ts +8 -0
  23. package/dist/types/src/error.d.ts +4 -0
  24. package/dist/types/src/form.d.ts +68 -0
  25. package/dist/types/src/head.d.ts +12 -0
  26. package/dist/types/src/hmr.d.ts +14 -0
  27. package/dist/types/src/hydration.d.ts +16 -0
  28. package/dist/types/src/index.d.ts +24 -0
  29. package/dist/types/src/indicators.d.ts +76 -0
  30. package/dist/types/src/island.d.ts +42 -0
  31. package/dist/types/src/keepalive.d.ts +1 -0
  32. package/dist/types/src/link.d.ts +68 -0
  33. package/dist/types/src/markdown-page.d.ts +10 -0
  34. package/dist/types/src/markdown.d.ts +40 -0
  35. package/dist/types/src/mask.d.ts +12 -0
  36. package/dist/types/src/navigate.d.ts +17 -0
  37. package/dist/types/src/outlet.d.ts +76 -0
  38. package/dist/types/src/request.d.ts +31 -0
  39. package/dist/types/src/routing.d.ts +47 -0
  40. package/dist/types/src/runtime/client.d.ts +29 -0
  41. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  42. package/dist/types/src/runtime/hydration.d.ts +8 -0
  43. package/dist/types/src/runtime/island.d.ts +8 -0
  44. package/dist/types/src/runtime/server.d.ts +15 -0
  45. package/dist/types/src/server-island.d.ts +24 -0
  46. package/dist/types/src/state.d.ts +14 -0
  47. package/dist/types/src/svg.d.ts +15 -0
  48. package/dist/types/src/time.d.ts +40 -0
  49. package/dist/types/src/wrapper.d.ts +21 -0
  50. package/package.json +77 -4
  51. package/src/activation.ts +83 -0
  52. package/src/adapter.ts +107 -0
  53. package/src/app.ts +12 -0
  54. package/src/async-data.ts +105 -0
  55. package/src/client-parts.ts +107 -0
  56. package/src/compile.ts +963 -0
  57. package/src/context.ts +189 -0
  58. package/src/data.ts +389 -0
  59. package/src/definition.ts +144 -0
  60. package/src/error-page.ts +30 -0
  61. package/src/error.ts +15 -0
  62. package/src/form.ts +182 -0
  63. package/src/head.ts +63 -0
  64. package/src/hmr.ts +61 -0
  65. package/src/hydration.ts +120 -0
  66. package/src/index.ts +98 -0
  67. package/src/indicators.ts +220 -0
  68. package/src/island.ts +89 -0
  69. package/src/keepalive.ts +1 -0
  70. package/src/link.ts +214 -0
  71. package/src/markdown-page.ts +31 -0
  72. package/src/markdown.ts +140 -0
  73. package/src/mask.ts +36 -0
  74. package/src/navigate.ts +22 -0
  75. package/src/outlet.ts +316 -0
  76. package/src/request.ts +170 -0
  77. package/src/routing.ts +218 -0
  78. package/src/runtime/client.ts +140 -0
  79. package/src/runtime/contract.d.ts +4 -0
  80. package/src/runtime/hydration-dev.ts +18 -0
  81. package/src/runtime/hydration.ts +7 -0
  82. package/src/runtime/island.ts +109 -0
  83. package/src/runtime/server.ts +228 -0
  84. package/src/server-island.ts +67 -0
  85. package/src/state.ts +70 -0
  86. package/src/svg.ts +65 -0
  87. package/src/time.ts +115 -0
  88. package/src/wrapper.ts +187 -0
package/src/index.ts ADDED
@@ -0,0 +1,98 @@
1
+ export { default as DefaultErrorPage } from "./error-page.ts"
2
+ export { Outlet } from "./outlet.ts"
3
+ export { Link, injectLink, injectLinkStatus } from "./link.ts"
4
+ export { Navigate } from "./navigate.ts"
5
+ export { injectError } from "./error.ts"
6
+ export { clearError, forbidden, navigateTo, notFound, permanentRedirect, showError, unauthorized } from "hamur/app"
7
+ export {
8
+ callOnce,
9
+ clearState,
10
+ injectAsyncData,
11
+ injectData,
12
+ injectFetch,
13
+ injectLazyAsyncData,
14
+ injectLazyFetch,
15
+ injectNuxtData,
16
+ } from "./data.ts"
17
+ export type { AsyncDataResource, InjectAsyncDataOptions, InjectFetchOptions } from "./data.ts"
18
+ export { injectHead, injectHeadSafe, injectSeoMeta, injectServerHead, injectServerSeoMeta } from "./head.ts"
19
+ export { injectCookie, injectState, injectSyncedState } from "./state.ts"
20
+ export { DevOnly, injectDeferred, injectHydrated, injectId, onPrehydrate, transitionName } from "./client-parts.ts"
21
+ export { onPageActivated, onPageDeactivated } from "./activation.ts"
22
+ export { Time } from "./time.ts"
23
+ export {
24
+ Announcer,
25
+ LoadingIndicator,
26
+ RouteAnnouncer,
27
+ injectAnnouncer,
28
+ injectLoadingIndicator,
29
+ injectRouteAnnouncer,
30
+ } from "./indicators.ts"
31
+ export { MarkdownRenderer } from "./markdown.ts"
32
+ export type { MarkdownRendererProps } from "./markdown.ts"
33
+ export { Island } from "./island.ts"
34
+ export { ServerIsland } from "./server-island.ts"
35
+ export { Form, injectAction, injectForm, injectFormStatus, injectOptimistic } from "./form.ts"
36
+ export type { InjectActionResult, InjectFormInstance, InjectFormResult } from "./form.ts"
37
+ export {
38
+ injectApp,
39
+ injectAppUpdate,
40
+ injectOnline,
41
+ injectPoll,
42
+ injectPreviewMode,
43
+ injectReportWebVitals,
44
+ injectRequestEvent,
45
+ injectRequestFetch,
46
+ injectRequestHeader,
47
+ injectRequestHeaders,
48
+ injectRequestURL,
49
+ injectResponseHeader,
50
+ injectRuntimeConfig,
51
+ injectRuntimeHook,
52
+ injectSiteConfig,
53
+ onAppReady,
54
+ setResponseStatus,
55
+ } from "./request.ts"
56
+ export {
57
+ injectBlocker,
58
+ injectLayout,
59
+ injectLayoutSegment,
60
+ injectLayoutSegments,
61
+ injectMatches,
62
+ injectNavigation,
63
+ injectOutletContext,
64
+ injectPreventNavigate,
65
+ injectResolvedPath,
66
+ injectRoute,
67
+ injectRouteData,
68
+ injectRouter,
69
+ injectSearch,
70
+ injectSnapshot,
71
+ onAfterNavigate,
72
+ onBeforeNavigate,
73
+ onBeforeRouteLeave,
74
+ onBeforeRouteUpdate,
75
+ onNavigate,
76
+ } from "./routing.ts"
77
+ export type { AngularSetup } from "./context.ts"
78
+ export type {
79
+ AnnouncerPoliteness,
80
+ Blocker,
81
+ BlockerArgs,
82
+ LinkDefaults,
83
+ LinkSlot,
84
+ LoadingIndicatorOptions,
85
+ LoadingIndicatorProps,
86
+ MatchedRoute,
87
+ NavigateOptions,
88
+ Navigation,
89
+ NavigationState,
90
+ RouteDataName,
91
+ RouteAnnouncerPoliteness,
92
+ RouteDataOf,
93
+ RouteValue,
94
+ RouterApi,
95
+ SnapshotOptions,
96
+ UseBlockerOptions,
97
+ UseLinkOptions,
98
+ } from "hamur/adapter"
@@ -0,0 +1,220 @@
1
+ import { Component, DestroyRef, ElementRef, HostAttributeToken, Injector, afterNextRender, afterRenderEffect, assertInInjectionContext, computed, effect, inject, input, runInInjectionContext, signal, untracked, viewChild, } from "@angular/core";
2
+ import { ANNOUNCER_ASSERTIVE_ID, ANNOUNCER_POLITE_ID, ROUTE_ANNOUNCER_ID, announcerActions, announcerRole, createAnnouncer, createLoadingIndicator, createRouteAnnouncer, hideAnnouncer, loadingIndicatorOptions, paintLoadingIndicator, } from "hamur/adapter";
3
+ import { HAMUR_APP, HAMUR_NAVIGATION, required } from "./context.ts";
4
+ import * as i0 from "@angular/core";
5
+ /** The bar's state as signals, and its `start`, `finish`, `set` and `clear`; it follows the navigation while a component that called it is alive. */
6
+ export function injectLoadingIndicator(options) {
7
+ assertInInjectionContext(injectLoadingIndicator);
8
+ const store = createLoadingIndicator(required(HAMUR_APP, "injectLoadingIndicator"), options);
9
+ const navigation = required(HAMUR_NAVIGATION, "injectLoadingIndicator");
10
+ const state = signal(store.get(), /* @ts-ignore */
11
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
12
+ const injector = inject(Injector);
13
+ const destroy = inject(DestroyRef);
14
+ afterNextRender(() => {
15
+ state.set(store.get());
16
+ const stopState = store.subscribe(() => state.set(store.get()));
17
+ const listeners = new Set();
18
+ const watcher = effect(() => {
19
+ navigation();
20
+ untracked(() => {
21
+ for (const listener of [...listeners])
22
+ listener();
23
+ });
24
+ }, { ...(ngDevMode ? { debugName: "watcher" } : /* istanbul ignore next */ {}), injector });
25
+ const stopFollow = store.follow({
26
+ get: () => untracked(navigation),
27
+ subscribe(listener) {
28
+ listeners.add(listener);
29
+ return () => void listeners.delete(listener);
30
+ },
31
+ });
32
+ destroy.onDestroy(() => {
33
+ stopState();
34
+ stopFollow();
35
+ watcher.destroy();
36
+ });
37
+ });
38
+ return {
39
+ progress: computed(() => state().progress),
40
+ isLoading: computed(() => state().isLoading),
41
+ error: computed(() => state().error),
42
+ start: store.start,
43
+ finish: store.finish,
44
+ set: store.set,
45
+ clear: store.clear,
46
+ };
47
+ }
48
+ /**
49
+ * `<hamur-loading-indicator />`, the bar at the top of the page that follows `injectNavigation().state`. Its look is
50
+ * written through `element.style` after the first render, so the server's element has no `style` attribute.
51
+ */
52
+ export class LoadingIndicator {
53
+ color = input(/* @ts-ignore */
54
+ ...(ngDevMode ? [undefined, { debugName: "color" }] : /* istanbul ignore next */ []));
55
+ errorColor = input(/* @ts-ignore */
56
+ ...(ngDevMode ? [undefined, { debugName: "errorColor" }] : /* istanbul ignore next */ []));
57
+ height = input(/* @ts-ignore */
58
+ ...(ngDevMode ? [undefined, { debugName: "height" }] : /* istanbul ignore next */ []));
59
+ duration = input(/* @ts-ignore */
60
+ ...(ngDevMode ? [undefined, { debugName: "duration" }] : /* istanbul ignore next */ []));
61
+ throttle = input(/* @ts-ignore */
62
+ ...(ngDevMode ? [undefined, { debugName: "throttle" }] : /* istanbul ignore next */ []));
63
+ estimatedProgress = input(/* @ts-ignore */
64
+ ...(ngDevMode ? [undefined, { debugName: "estimatedProgress" }] : /* istanbul ignore next */ []));
65
+ injector = inject(Injector);
66
+ element = inject(ElementRef).nativeElement;
67
+ ngOnInit() {
68
+ runInInjectionContext(this.injector, () => {
69
+ const { progress, isLoading, error } = injectLoadingIndicator(loadingIndicatorOptions({
70
+ duration: this.duration(),
71
+ throttle: this.throttle(),
72
+ estimatedProgress: this.estimatedProgress(),
73
+ }));
74
+ afterRenderEffect(() => paintLoadingIndicator(this.element, { progress: progress(), isLoading: isLoading(), error: error() }, { color: this.color(), errorColor: this.errorColor(), height: this.height() }));
75
+ });
76
+ }
77
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: LoadingIndicator, deps: [], target: i0.ɵɵFactoryTarget.Component });
78
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: LoadingIndicator, isStandalone: true, selector: "hamur-loading-indicator", inputs: { color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: false, transformFunction: null }, errorColor: { classPropertyName: "errorColor", publicName: "errorColor", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, duration: { classPropertyName: "duration", publicName: "duration", isSignal: true, isRequired: false, transformFunction: null }, throttle: { classPropertyName: "throttle", publicName: "throttle", isSignal: true, isRequired: false, transformFunction: null }, estimatedProgress: { classPropertyName: "estimatedProgress", publicName: "estimatedProgress", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "data-hamur-loading-indicator": "", "aria-hidden": "true" } }, ngImport: i0, template: "", isInline: true });
79
+ }
80
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: LoadingIndicator, decorators: [{
81
+ type: Component,
82
+ args: [{
83
+ selector: "hamur-loading-indicator",
84
+ template: "",
85
+ host: { "data-hamur-loading-indicator": "", "aria-hidden": "true" },
86
+ }]
87
+ }], propDecorators: { color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: false }] }], errorColor: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorColor", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], duration: [{ type: i0.Input, args: [{ isSignal: true, alias: "duration", required: false }] }], throttle: [{ type: i0.Input, args: [{ isSignal: true, alias: "throttle", required: false }] }], estimatedProgress: [{ type: i0.Input, args: [{ isSignal: true, alias: "estimatedProgress", required: false }] }] } });
88
+ /** The page's route announcer as signals, and `set`, `polite` and `assertive`. */
89
+ export function injectRouteAnnouncer() {
90
+ assertInInjectionContext(injectRouteAnnouncer);
91
+ const store = createRouteAnnouncer(required(HAMUR_APP, "injectRouteAnnouncer"));
92
+ const state = signal(store.get(), /* @ts-ignore */
93
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
94
+ const destroy = inject(DestroyRef);
95
+ afterNextRender(() => {
96
+ state.set(store.get());
97
+ destroy.onDestroy(store.subscribe(() => state.set(store.get())));
98
+ });
99
+ return {
100
+ message: computed(() => state().message),
101
+ politeness: computed(() => state().politeness),
102
+ set: store.set,
103
+ polite: store.polite,
104
+ assertive: store.assertive,
105
+ };
106
+ }
107
+ /**
108
+ * `<hamur-route-announcer />` is the region that speaks each navigation; the first one mounted holds `#__hamur_announcer`
109
+ * and the navigator's own region goes away while it is. A `politeness` pins `aria-live` and `role`; a `class` or `style` on the
110
+ * element keeps it visible.
111
+ */
112
+ export class RouteAnnouncer {
113
+ politeness = input(/* @ts-ignore */
114
+ ...(ngDevMode ? [undefined, { debugName: "politeness" }] : /* istanbul ignore next */ []));
115
+ id = ROUTE_ANNOUNCER_ID;
116
+ store = createRouteAnnouncer(required(HAMUR_APP, "RouteAnnouncer"));
117
+ state = injectRouteAnnouncer();
118
+ element = inject(ElementRef).nativeElement;
119
+ styled = inject(new HostAttributeToken("class"), { optional: true }) !== null ||
120
+ inject(new HostAttributeToken("style"), { optional: true }) !== null;
121
+ key = {};
122
+ tick = signal(0, /* @ts-ignore */
123
+ ...(ngDevMode ? [{ debugName: "tick" }] : /* istanbul ignore next */ []));
124
+ message = this.state.message;
125
+ live = computed(() => this.politeness() ?? this.state.politeness(), /* @ts-ignore */
126
+ ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
127
+ role = computed(() => announcerRole(this.live()), /* @ts-ignore */
128
+ ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
129
+ owner = computed(() => {
130
+ this.tick();
131
+ return this.store.claim(this.key, () => this.tick.update((count) => count + 1));
132
+ }, /* @ts-ignore */
133
+ ...(ngDevMode ? [{ debugName: "owner" }] : /* istanbul ignore next */ []));
134
+ constructor() {
135
+ afterRenderEffect((onCleanup) => {
136
+ if (!this.owner())
137
+ return;
138
+ onCleanup(this.store.mount());
139
+ if (!this.styled)
140
+ hideAnnouncer(this.element);
141
+ });
142
+ inject(DestroyRef).onDestroy(() => this.store.release(this.key));
143
+ }
144
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: RouteAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Component });
145
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: RouteAnnouncer, isStandalone: true, selector: "hamur-route-announcer", inputs: { politeness: { classPropertyName: "politeness", publicName: "politeness", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "aria-atomic": "true" }, properties: { "attr.id": "owner() ? id : null", "attr.aria-live": "owner() ? live() : 'off'", "attr.role": "owner() ? role() : null", "textContent": "owner() ? message() : ''" } }, ngImport: i0, template: "", isInline: true });
146
+ }
147
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: RouteAnnouncer, decorators: [{
148
+ type: Component,
149
+ args: [{
150
+ selector: "hamur-route-announcer",
151
+ template: "",
152
+ host: {
153
+ "[attr.id]": "owner() ? id : null",
154
+ "[attr.aria-live]": "owner() ? live() : 'off'",
155
+ "aria-atomic": "true",
156
+ "[attr.role]": "owner() ? role() : null",
157
+ "[textContent]": "owner() ? message() : ''",
158
+ },
159
+ }]
160
+ }], ctorParameters: () => [], propDecorators: { politeness: [{ type: i0.Input, args: [{ isSignal: true, alias: "politeness", required: false }] }] } });
161
+ /** The page's announcer as signals, and `set`, `polite` and `assertive` (`polite` unless `politeness` says otherwise). */
162
+ export function injectAnnouncer({ politeness = "polite" } = {}) {
163
+ assertInInjectionContext(injectAnnouncer);
164
+ const store = createAnnouncer(required(HAMUR_APP, "injectAnnouncer"));
165
+ const state = signal(store.get(), /* @ts-ignore */
166
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
167
+ const destroy = inject(DestroyRef);
168
+ afterNextRender(() => {
169
+ state.set(store.get());
170
+ destroy.onDestroy(store.subscribe(() => state.set(store.get())));
171
+ });
172
+ return {
173
+ message: computed(() => state().message),
174
+ politeness: computed(() => state().politeness),
175
+ ...announcerActions(store, politeness),
176
+ };
177
+ }
178
+ /** `<hamur-announcer />` holds the two regions `injectAnnouncer()` writes to: `#__hamur_announcer_polite` and `#__hamur_announcer_assertive`. */
179
+ export class Announcer {
180
+ politeId = ANNOUNCER_POLITE_ID;
181
+ assertiveId = ANNOUNCER_ASSERTIVE_ID;
182
+ store = createAnnouncer(required(HAMUR_APP, "Announcer"));
183
+ state = signal(this.store.get(), /* @ts-ignore */
184
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
185
+ regions = computed(() => this.state().regions, /* @ts-ignore */
186
+ ...(ngDevMode ? [{ debugName: "regions" }] : /* istanbul ignore next */ []));
187
+ polite = viewChild.required("polite", /* @ts-ignore */
188
+ ...(ngDevMode ? [{ debugName: "polite" }] : /* istanbul ignore next */ []));
189
+ assertive = viewChild.required("assertive", /* @ts-ignore */
190
+ ...(ngDevMode ? [{ debugName: "assertive" }] : /* istanbul ignore next */ []));
191
+ constructor() {
192
+ const destroy = inject(DestroyRef);
193
+ afterNextRender(() => {
194
+ this.state.set(this.store.get());
195
+ hideAnnouncer(this.polite().nativeElement);
196
+ hideAnnouncer(this.assertive().nativeElement);
197
+ const stop = this.store.subscribe(() => this.state.set(this.store.get()));
198
+ const unmount = this.store.mount();
199
+ destroy.onDestroy(() => {
200
+ stop();
201
+ unmount();
202
+ });
203
+ });
204
+ }
205
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Announcer, deps: [], target: i0.ɵɵFactoryTarget.Component });
206
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.3.2", type: Announcer, isStandalone: true, selector: "hamur-announcer", viewQueries: [{ propertyName: "polite", first: true, predicate: ["polite"], descendants: true, isSignal: true }, { propertyName: "assertive", first: true, predicate: ["assertive"], descendants: true, isSignal: true }], ngImport: i0, template: `<div #polite [attr.id]="politeId" aria-live="polite" aria-atomic="true" role="status">{{ regions().polite }}</div
207
+ ><div #assertive [attr.id]="assertiveId" aria-live="assertive" aria-atomic="true" role="alert">{{
208
+ regions().assertive
209
+ }}</div>`, isInline: true });
210
+ }
211
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Announcer, decorators: [{
212
+ type: Component,
213
+ args: [{
214
+ selector: "hamur-announcer",
215
+ template: `<div #polite [attr.id]="politeId" aria-live="polite" aria-atomic="true" role="status">{{ regions().polite }}</div
216
+ ><div #assertive [attr.id]="assertiveId" aria-live="assertive" aria-atomic="true" role="alert">{{
217
+ regions().assertive
218
+ }}</div>`,
219
+ }]
220
+ }], ctorParameters: () => [], propDecorators: { polite: [{ type: i0.ViewChild, args: ["polite", { isSignal: true }] }], assertive: [{ type: i0.ViewChild, args: ["assertive", { isSignal: true }] }] } });
package/src/island.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { ApplicationRef, Component, DestroyRef, ElementRef, InjectionToken, Injector, PendingTasks, Renderer2, booleanAttribute, inject, input, } from "@angular/core";
2
+ import { ISLAND_ELEMENT, renderIsland } from "hamur/adapter";
3
+ import { injectId } from "./client-parts.ts";
4
+ import { HAMUR_APP, HAMUR_FAIL, onServer } from "./context.ts";
5
+ import * as i0 from "@angular/core";
6
+ /** A component that writes its own nodes below its host: a template it renders there is a view the application checks. */
7
+ export class HostWriter {
8
+ host = inject(ElementRef).nativeElement;
9
+ renderer = inject(Renderer2);
10
+ appRef = inject(ApplicationRef);
11
+ injector = inject(Injector);
12
+ destroyRef = inject(DestroyRef);
13
+ append(template, into = this.host) {
14
+ const view = template.createEmbeddedView({}, this.injector);
15
+ this.appRef.attachView(view);
16
+ for (const node of view.rootNodes)
17
+ this.renderer.appendChild(into, node);
18
+ this.destroyRef.onDestroy(() => view.destroy());
19
+ }
20
+ }
21
+ /** The element the core's islands runtime reads, `<appId>-island` of the build; a token, so a test gives it another app id. */
22
+ export const HAMUR_ISLAND_ELEMENT = new InjectionToken("hamur island element", {
23
+ providedIn: "root",
24
+ factory: () => ISLAND_ELEMENT,
25
+ });
26
+ /**
27
+ * On an island page, `component` rendered on the server as an application of its own inside `<hamur-island>`,
28
+ * hydrated on its own in the browser; `fallback` is what the server renders under `on="only"`. Its template is empty: the island's
29
+ * HTML is written below its host on the server and left as it is in the browser. The host is the core's element when the app id is
30
+ * `hamur`; under another app id the host holds `<appId>-island`, which the runtime reads.
31
+ */
32
+ export class Island extends HostWriter {
33
+ /** The default export of a file under `app/islands/`. */
34
+ component = input.required(/* @ts-ignore */
35
+ ...(ngDevMode ? [{ debugName: "component" }] : /* istanbul ignore next */ []));
36
+ props = input(/* @ts-ignore */
37
+ ...(ngDevMode ? [undefined, { debugName: "props" }] : /* istanbul ignore next */ []));
38
+ /** The island directive: when the island hydrates, `"only"` to mount it in the browser alone, or a directive a module adds; default `"load"`. */
39
+ on = input(/* @ts-ignore */
40
+ ...(ngDevMode ? [undefined, { debugName: "on" }] : /* istanbul ignore next */ []));
41
+ fallback = input(/* @ts-ignore */
42
+ ...(ngDevMode ? [undefined, { debugName: "fallback" }] : /* istanbul ignore next */ []));
43
+ /** The island's id across swaps; a swap to a page with the same id keeps its element and state. */
44
+ persist = input(/* @ts-ignore */
45
+ ...(ngDevMode ? [undefined, { debugName: "persist" }] : /* istanbul ignore next */ []));
46
+ /** With `persist`, a swap keeps the island's old props. */
47
+ persistProps = input(false, { ...(ngDevMode ? { debugName: "persistProps" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
48
+ app = inject(HAMUR_APP, { optional: true });
49
+ id = injectId();
50
+ tasks = inject(PendingTasks);
51
+ fail = inject(HAMUR_FAIL, { optional: true });
52
+ server = onServer();
53
+ element = inject(HAMUR_ISLAND_ELEMENT);
54
+ constructor() {
55
+ super();
56
+ if (!this.app)
57
+ throw new Error("Island must be rendered inside a Hamur app");
58
+ }
59
+ ngOnInit() {
60
+ if (!this.server)
61
+ return;
62
+ const island = renderIsland(this.app, this.id, this.component(), this.props() ?? {}, this.on(), undefined, {
63
+ persist: this.persist(),
64
+ persistProps: this.persistProps(),
65
+ });
66
+ const element = this.host.localName === this.element ? this.host : this.renderer.createElement(this.element);
67
+ if (element !== this.host)
68
+ this.renderer.appendChild(this.host, element);
69
+ for (const [name, value] of Object.entries(island.attributes))
70
+ this.renderer.setAttribute(element, name, value);
71
+ if (!island.html) {
72
+ const fallback = this.fallback();
73
+ if (fallback)
74
+ this.append(fallback, element);
75
+ return;
76
+ }
77
+ const done = this.tasks.add();
78
+ island.html
79
+ .then((html) => this.renderer.setProperty(element, "innerHTML", html))
80
+ .catch((error) => this.fail?.(error))
81
+ .finally(done);
82
+ }
83
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Island, deps: [], target: i0.ɵɵFactoryTarget.Component });
84
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.2", type: Island, isStandalone: true, selector: "hamur-island", inputs: { component: { classPropertyName: "component", publicName: "component", isSignal: true, isRequired: true, transformFunction: null }, props: { classPropertyName: "props", publicName: "props", isSignal: true, isRequired: false, transformFunction: null }, on: { classPropertyName: "on", publicName: "on", isSignal: true, isRequired: false, transformFunction: null }, fallback: { classPropertyName: "fallback", publicName: "fallback", isSignal: true, isRequired: false, transformFunction: null }, persist: { classPropertyName: "persist", publicName: "persist", isSignal: true, isRequired: false, transformFunction: null }, persistProps: { classPropertyName: "persistProps", publicName: "persistProps", isSignal: true, isRequired: false, transformFunction: null } }, usesInheritance: true, ngImport: i0, template: "", isInline: true });
85
+ }
86
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Island, decorators: [{
87
+ type: Component,
88
+ args: [{ selector: "hamur-island", template: "" }]
89
+ }], ctorParameters: () => [], propDecorators: { component: [{ type: i0.Input, args: [{ isSignal: true, alias: "component", required: true }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "props", required: false }] }], on: [{ type: i0.Input, args: [{ isSignal: true, alias: "on", required: false }] }], fallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "fallback", required: false }] }], persist: [{ type: i0.Input, args: [{ isSignal: true, alias: "persist", required: false }] }], persistProps: [{ type: i0.Input, args: [{ isSignal: true, alias: "persistProps", required: false }] }] } });
@@ -0,0 +1 @@
1
+ export {}
package/src/link.ts ADDED
@@ -0,0 +1,214 @@
1
+ import { DestroyRef, Directive, ElementRef, HostAttributeToken, InjectionToken, assertInInjectionContext, booleanAttribute, computed, effect, forwardRef, inject, input, numberAttribute, output, } from "@angular/core";
2
+ import { withoutBase } from "hamur/app";
3
+ import { createLinkSlot, linkAttributes, linkDefaultsOf, linkPending, linkPrefetchProps, linkState, relativeTarget, resolveLinkTarget, searchTarget, setLinkState, } from "hamur/adapter";
4
+ import { HAMUR_APP, HAMUR_BASE_URL, HAMUR_HREF, HAMUR_NAVIGATION, HAMUR_ROUTE, HAMUR_ROUTER, detachedHref, } from "./context.ts";
5
+ import * as i0 from "@angular/core";
6
+ /** What a `Link`'s content reads through `injectLinkStatus()`. */
7
+ const LINK_HREF = new InjectionToken("hamur link href");
8
+ const optionalBoolean = (value) => value === undefined ? undefined : booleanAttribute(value);
9
+ /**
10
+ * `<a hamurLink="/path">`. The host bindings write what the other adapters' `Link` writes on its anchor; the
11
+ * core navigator takes the click. A `target`, `rel` or `aria-current` written on the element stays.
12
+ */
13
+ export class Link {
14
+ to = input.required({ ...(ngDevMode ? { debugName: "to" } : /* istanbul ignore next */ {}), alias: "hamurLink" });
15
+ replace = input(false, { ...(ngDevMode ? { debugName: "replace" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
16
+ prefetch = input(undefined, { ...(ngDevMode ? { debugName: "prefetch" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
17
+ prefetchOn = input(/* @ts-ignore */
18
+ ...(ngDevMode ? [undefined, { debugName: "prefetchOn" }] : /* istanbul ignore next */ []));
19
+ prefetchDelay = input(undefined, { ...(ngDevMode ? { debugName: "prefetchDelay" } : /* istanbul ignore next */ {}), transform: (value) => (value === undefined ? undefined : numberAttribute(value)) });
20
+ viewTransition = input(/* @ts-ignore */
21
+ ...(ngDevMode ? [undefined, { debugName: "viewTransition" }] : /* istanbul ignore next */ []));
22
+ query = input(/* @ts-ignore */
23
+ ...(ngDevMode ? [undefined, { debugName: "query" }] : /* istanbul ignore next */ []));
24
+ state = input(/* @ts-ignore */
25
+ ...(ngDevMode ? [undefined, { debugName: "state" }] : /* istanbul ignore next */ []));
26
+ relative = input(/* @ts-ignore */
27
+ ...(ngDevMode ? [undefined, { debugName: "relative" }] : /* istanbul ignore next */ []));
28
+ mask = input(/* @ts-ignore */
29
+ ...(ngDevMode ? [undefined, { debugName: "mask" }] : /* istanbul ignore next */ []));
30
+ unmaskOnReload = input(undefined, { ...(ngDevMode ? { debugName: "unmaskOnReload" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
31
+ activeClass = input(/* @ts-ignore */
32
+ ...(ngDevMode ? [undefined, { debugName: "activeClass" }] : /* istanbul ignore next */ []));
33
+ exactActiveClass = input(/* @ts-ignore */
34
+ ...(ngDevMode ? [undefined, { debugName: "exactActiveClass" }] : /* istanbul ignore next */ []));
35
+ pendingClass = input(/* @ts-ignore */
36
+ ...(ngDevMode ? [undefined, { debugName: "pendingClass" }] : /* istanbul ignore next */ []));
37
+ prefetchedClass = input(/* @ts-ignore */
38
+ ...(ngDevMode ? [undefined, { debugName: "prefetchedClass" }] : /* istanbul ignore next */ []));
39
+ ariaCurrentValue = input("page", /* @ts-ignore */
40
+ ...(ngDevMode ? [{ debugName: "ariaCurrentValue" }] : /* istanbul ignore next */ []));
41
+ external = input(false, { ...(ngDevMode ? { debugName: "external" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
42
+ noRel = input(false, { ...(ngDevMode ? { debugName: "noRel" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
43
+ scroll = input(undefined, { ...(ngDevMode ? { debugName: "scroll" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
44
+ keepFocus = input(false, { ...(ngDevMode ? { debugName: "keepFocus" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
45
+ beforeNavigate = output();
46
+ app = inject(HAMUR_APP, { optional: true });
47
+ route = inject(HAMUR_ROUTE, { optional: true });
48
+ resolve = inject(HAMUR_HREF, { optional: true }) ?? detachedHref;
49
+ baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/";
50
+ element = inject(ElementRef).nativeElement;
51
+ rel = inject(new HostAttributeToken("rel"), { optional: true });
52
+ target = inject(new HostAttributeToken("target"), { optional: true });
53
+ given = inject(new HostAttributeToken("aria-current"), { optional: true });
54
+ defaults = computed(() => linkDefaultsOf(this.app), /* @ts-ignore */
55
+ ...(ngDevMode ? [{ debugName: "defaults" }] : /* istanbul ignore next */ []));
56
+ classNames = computed(() => ({
57
+ active: this.activeClass() ?? this.defaults().activeClass,
58
+ exact: this.exactActiveClass() ?? this.defaults().exactActiveClass,
59
+ pending: this.pendingClass() ?? this.defaults().pendingClass,
60
+ prefetched: this.prefetchedClass() ?? this.defaults().prefetchedClass,
61
+ }), /* @ts-ignore */
62
+ ...(ngDevMode ? [{ debugName: "classNames" }] : /* istanbul ignore next */ []));
63
+ linked = computed(() => {
64
+ const route = this.route?.();
65
+ const to = this.to();
66
+ return resolveLinkTarget(this.app, route ? searchTarget(relativeTarget(to, route, this.relative()), route, this.query()) : to, {
67
+ replace: this.replace(),
68
+ prefetch: this.prefetch(),
69
+ prefetchOn: this.prefetchOn(),
70
+ external: this.external(),
71
+ scroll: this.scroll(),
72
+ mask: this.mask(),
73
+ ...(this.target === null ? {} : { target: this.target }),
74
+ }, this.resolve, this.external());
75
+ }, /* @ts-ignore */
76
+ ...(ngDevMode ? [{ debugName: "linked" }] : /* istanbul ignore next */ []));
77
+ matched = computed(() => {
78
+ const route = this.route?.();
79
+ const target = this.linked().to;
80
+ if (!route)
81
+ return { active: false, exact: false };
82
+ return linkState(typeof target === "string" ? target : withoutBase(this.href(), this.baseURL), route);
83
+ }, /* @ts-ignore */
84
+ ...(ngDevMode ? [{ debugName: "matched" }] : /* istanbul ignore next */ []));
85
+ /** The based `href` of the link. */
86
+ href = computed(() => this.resolve(this.linked().to), /* @ts-ignore */
87
+ ...(ngDevMode ? [{ debugName: "href" }] : /* istanbul ignore next */ []));
88
+ ariaCurrent = computed(() => this.given ?? (this.matched().exact ? this.ariaCurrentValue() : undefined), /* @ts-ignore */
89
+ ...(ngDevMode ? [{ debugName: "ariaCurrent" }] : /* istanbul ignore next */ []));
90
+ keepFocusValue = computed(() => (this.keepFocus() ? "" : undefined), /* @ts-ignore */
91
+ ...(ngDevMode ? [{ debugName: "keepFocusValue" }] : /* istanbul ignore next */ []));
92
+ classes = computed(() => {
93
+ const { active, exact } = this.matched();
94
+ return [active && this.classNames().active, exact && this.classNames().exact].filter(Boolean).join(" ");
95
+ }, /* @ts-ignore */
96
+ ...(ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []));
97
+ attrs = computed(() => {
98
+ const defaults = this.defaults();
99
+ return linkAttributes({
100
+ href: this.href(),
101
+ external: this.external(),
102
+ ...linkPrefetchProps({ prefetch: this.prefetch(), prefetchOn: this.prefetchOn() }, defaults),
103
+ replace: this.replace(),
104
+ viewTransition: this.viewTransition(),
105
+ pendingClass: this.classNames().pending,
106
+ trim: !!this.query(),
107
+ mask: this.mask() === undefined ? undefined : this.resolve(this.mask()),
108
+ unmaskOnReload: this.unmaskOnReload(),
109
+ rel: this.rel ?? undefined,
110
+ target: this.target ?? undefined,
111
+ noRel: this.noRel(),
112
+ prefetchedClass: this.classNames().prefetched,
113
+ scroll: this.scroll(),
114
+ prefetchDelay: this.prefetchDelay() ?? defaults.prefetchDelay,
115
+ externalRelAttribute: defaults.externalRelAttribute,
116
+ });
117
+ }, /* @ts-ignore */
118
+ ...(ngDevMode ? [{ debugName: "attrs" }] : /* istanbul ignore next */ []));
119
+ constructor() {
120
+ effect(() => {
121
+ const state = this.state();
122
+ setLinkState(this.element, state, (navigation) => this.beforeNavigate.emit(navigation));
123
+ });
124
+ inject(DestroyRef).onDestroy(() => setLinkState(this.element, undefined));
125
+ }
126
+ attr(name) {
127
+ return this.attrs()[name] ?? (name === "rel" ? (this.rel ?? undefined) : undefined);
128
+ }
129
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Link, deps: [], target: i0.ɵɵFactoryTarget.Directive });
130
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.2", type: Link, isStandalone: true, selector: "a[hamurLink]", inputs: { to: { classPropertyName: "to", publicName: "hamurLink", isSignal: true, isRequired: true, transformFunction: null }, replace: { classPropertyName: "replace", publicName: "replace", isSignal: true, isRequired: false, transformFunction: null }, prefetch: { classPropertyName: "prefetch", publicName: "prefetch", isSignal: true, isRequired: false, transformFunction: null }, prefetchOn: { classPropertyName: "prefetchOn", publicName: "prefetchOn", isSignal: true, isRequired: false, transformFunction: null }, prefetchDelay: { classPropertyName: "prefetchDelay", publicName: "prefetchDelay", isSignal: true, isRequired: false, transformFunction: null }, viewTransition: { classPropertyName: "viewTransition", publicName: "viewTransition", isSignal: true, isRequired: false, transformFunction: null }, query: { classPropertyName: "query", publicName: "query", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, relative: { classPropertyName: "relative", publicName: "relative", isSignal: true, isRequired: false, transformFunction: null }, mask: { classPropertyName: "mask", publicName: "mask", isSignal: true, isRequired: false, transformFunction: null }, unmaskOnReload: { classPropertyName: "unmaskOnReload", publicName: "unmaskOnReload", isSignal: true, isRequired: false, transformFunction: null }, activeClass: { classPropertyName: "activeClass", publicName: "activeClass", isSignal: true, isRequired: false, transformFunction: null }, exactActiveClass: { classPropertyName: "exactActiveClass", publicName: "exactActiveClass", isSignal: true, isRequired: false, transformFunction: null }, pendingClass: { classPropertyName: "pendingClass", publicName: "pendingClass", isSignal: true, isRequired: false, transformFunction: null }, prefetchedClass: { classPropertyName: "prefetchedClass", publicName: "prefetchedClass", isSignal: true, isRequired: false, transformFunction: null }, ariaCurrentValue: { classPropertyName: "ariaCurrentValue", publicName: "ariaCurrentValue", isSignal: true, isRequired: false, transformFunction: null }, external: { classPropertyName: "external", publicName: "external", isSignal: true, isRequired: false, transformFunction: null }, noRel: { classPropertyName: "noRel", publicName: "noRel", isSignal: true, isRequired: false, transformFunction: null }, scroll: { classPropertyName: "scroll", publicName: "scroll", isSignal: true, isRequired: false, transformFunction: null }, keepFocus: { classPropertyName: "keepFocus", publicName: "keepFocus", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { beforeNavigate: "beforeNavigate" }, host: { properties: { "attr.href": "href()", "attr.aria-current": "ariaCurrent()", "attr.rel": "attr('rel')", "attr.data-hamur-prefetch": "attr('data-hamur-prefetch')", "attr.data-hamur-replace": "attr('data-hamur-replace')", "attr.data-hamur-view-transition": "attr('data-hamur-view-transition')", "attr.data-hamur-pending-class": "attr('data-hamur-pending-class')", "attr.data-hamur-trim": "attr('data-hamur-trim')", "attr.data-hamur-mask": "attr('data-hamur-mask')", "attr.data-hamur-unmask": "attr('data-hamur-unmask')", "attr.data-hamur-prefetched-class": "attr('data-hamur-prefetched-class')", "attr.data-hamur-scroll": "attr('data-hamur-scroll')", "attr.data-hamur-prefetch-delay": "attr('data-hamur-prefetch-delay')", "attr.data-hamur-keepfocus": "keepFocusValue()", "class": "classes()" } }, providers: [{ provide: LINK_HREF, useExisting: forwardRef(() => Link) }], ngImport: i0 });
131
+ }
132
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: Link, decorators: [{
133
+ type: Directive,
134
+ args: [{
135
+ selector: "a[hamurLink]",
136
+ providers: [{ provide: LINK_HREF, useExisting: forwardRef(() => Link) }],
137
+ host: {
138
+ "[attr.href]": "href()",
139
+ "[attr.aria-current]": "ariaCurrent()",
140
+ "[attr.rel]": "attr('rel')",
141
+ "[attr.data-hamur-prefetch]": "attr('data-hamur-prefetch')",
142
+ "[attr.data-hamur-replace]": "attr('data-hamur-replace')",
143
+ "[attr.data-hamur-view-transition]": "attr('data-hamur-view-transition')",
144
+ "[attr.data-hamur-pending-class]": "attr('data-hamur-pending-class')",
145
+ "[attr.data-hamur-trim]": "attr('data-hamur-trim')",
146
+ "[attr.data-hamur-mask]": "attr('data-hamur-mask')",
147
+ "[attr.data-hamur-unmask]": "attr('data-hamur-unmask')",
148
+ "[attr.data-hamur-prefetched-class]": "attr('data-hamur-prefetched-class')",
149
+ "[attr.data-hamur-scroll]": "attr('data-hamur-scroll')",
150
+ "[attr.data-hamur-prefetch-delay]": "attr('data-hamur-prefetch-delay')",
151
+ "[attr.data-hamur-keepfocus]": "keepFocusValue()",
152
+ "[class]": "classes()",
153
+ },
154
+ }]
155
+ }], ctorParameters: () => [], propDecorators: { to: [{ type: i0.Input, args: [{ isSignal: true, alias: "hamurLink", required: true }] }], replace: [{ type: i0.Input, args: [{ isSignal: true, alias: "replace", required: false }] }], prefetch: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetch", required: false }] }], prefetchOn: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetchOn", required: false }] }], prefetchDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetchDelay", required: false }] }], viewTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewTransition", required: false }] }], query: [{ type: i0.Input, args: [{ isSignal: true, alias: "query", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], relative: [{ type: i0.Input, args: [{ isSignal: true, alias: "relative", required: false }] }], mask: [{ type: i0.Input, args: [{ isSignal: true, alias: "mask", required: false }] }], unmaskOnReload: [{ type: i0.Input, args: [{ isSignal: true, alias: "unmaskOnReload", required: false }] }], activeClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeClass", required: false }] }], exactActiveClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "exactActiveClass", required: false }] }], pendingClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "pendingClass", required: false }] }], prefetchedClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefetchedClass", required: false }] }], ariaCurrentValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaCurrentValue", required: false }] }], external: [{ type: i0.Input, args: [{ isSignal: true, alias: "external", required: false }] }], noRel: [{ type: i0.Input, args: [{ isSignal: true, alias: "noRel", required: false }] }], scroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "scroll", required: false }] }], keepFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "keepFocus", required: false }] }], beforeNavigate: [{ type: i0.Output, args: ["beforeNavigate"] }] } });
156
+ /** The `LinkSlot` of a link to `to`, for an element that renders its own `<a>`; `app.link` sets its defaults. */
157
+ export function injectLink(to, options) {
158
+ assertInInjectionContext(injectLink);
159
+ const app = inject(HAMUR_APP, { optional: true });
160
+ const route = inject(HAMUR_ROUTE, { optional: true });
161
+ const router = inject(HAMUR_ROUTER, { optional: true });
162
+ const navigation = inject(HAMUR_NAVIGATION, { optional: true });
163
+ const resolve = inject(HAMUR_HREF, { optional: true }) ?? detachedHref;
164
+ const baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/";
165
+ return computed(() => {
166
+ const given = (typeof options === "function" ? options() : options) ?? {};
167
+ const defaults = linkDefaultsOf(app);
168
+ const base = (typeof to === "function" ? to() : to);
169
+ const current = route?.();
170
+ const searched = current ? searchTarget(relativeTarget(base, current, given.relative), current, given.query) : base;
171
+ const { to: target } = resolveLinkTarget(app, searched, given, resolve, given.external);
172
+ const href = resolve(target);
173
+ const state = current
174
+ ? linkState(typeof target === "string" ? target : withoutBase(href, baseURL), current)
175
+ : { active: false, exact: false };
176
+ return createLinkSlot({
177
+ href,
178
+ to: target,
179
+ attrs: linkAttributes({
180
+ href,
181
+ external: given.external,
182
+ ...linkPrefetchProps({}, defaults),
183
+ replace: given.replace,
184
+ viewTransition: given.viewTransition,
185
+ pendingClass: defaults.pendingClass,
186
+ trim: !!given.query,
187
+ ariaCurrent: state.exact ? "page" : undefined,
188
+ prefetchedClass: defaults.prefetchedClass,
189
+ scroll: given.scroll,
190
+ prefetchDelay: defaults.prefetchDelay,
191
+ externalRelAttribute: defaults.externalRelAttribute,
192
+ }),
193
+ active: state.active,
194
+ exact: state.exact,
195
+ pending: navigation ? linkPending(href, navigation(), baseURL) : false,
196
+ external: given.external,
197
+ options: {
198
+ replace: given.replace,
199
+ state: given.state,
200
+ viewTransition: given.viewTransition,
201
+ scroll: given.scroll === false ? false : undefined,
202
+ },
203
+ router,
204
+ });
205
+ });
206
+ }
207
+ /** Inside a `Link`'s content, whether a navigation to that link is in flight; `false` anywhere else. */
208
+ export function injectLinkStatus() {
209
+ assertInInjectionContext(injectLinkStatus);
210
+ const link = inject(LINK_HREF, { optional: true });
211
+ const navigation = inject(HAMUR_NAVIGATION, { optional: true });
212
+ const baseURL = inject(HAMUR_BASE_URL, { optional: true }) ?? "/";
213
+ return { pending: computed(() => !!link && !!navigation && linkPending(link.href(), navigation(), baseURL)) };
214
+ }