@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
@@ -0,0 +1,107 @@
1
+ import { APP_ID, DestroyRef, Directive, InjectionToken, PendingTasks, TemplateRef, ViewContainerRef, afterNextRender, assertInInjectionContext, computed, inject, signal, } from "@angular/core";
2
+ import { checkTransitionName, prehydrate, settledOf } from "hamur/adapter";
3
+ import { HAMUR_APP, mode, onServer, required } from "./context.ts";
4
+ import * as i0 from "@angular/core";
5
+ /**
6
+ * `<div *hamurDevOnly>…</div>` renders its template only in a dev build. A production client keeps the template's code:
7
+ * a component named in it is a static import of the compiled one.
8
+ */
9
+ export class DevOnly {
10
+ constructor() {
11
+ if (mode.dev)
12
+ inject(ViewContainerRef).createEmbeddedView(inject(TemplateRef));
13
+ }
14
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DevOnly, deps: [], target: i0.ɵɵFactoryTarget.Directive });
15
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.3.2", type: DevOnly, isStandalone: true, selector: "[hamurDevOnly]", ngImport: i0 });
16
+ }
17
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: DevOnly, decorators: [{
18
+ type: Directive,
19
+ args: [{ selector: "[hamurDevOnly]" }]
20
+ }], ctorParameters: () => [] });
21
+ const isThenable = (value) => typeof value?.then === "function";
22
+ /**
23
+ * The value of a promise a loader returned, as Angular's `Resource<T>`: read with `@if (value.hasValue()) … @else if
24
+ * (value.error()) … @else …`. On the server the render waits for it; `value()` throws the error of a rejected promise,
25
+ * as Angular's own resources do.
26
+ */
27
+ export function injectDeferred(promise) {
28
+ assertInInjectionContext(injectDeferred);
29
+ const snapshot = signal({ status: "loading", value: undefined }, /* @ts-ignore */
30
+ ...(ngDevMode ? [{ debugName: "snapshot" }] : /* istanbul ignore next */ []));
31
+ const known = isThenable(promise) ? settledOf(promise) : { status: "fulfilled", value: promise };
32
+ if (known)
33
+ snapshot.set(known.status === "fulfilled"
34
+ ? { status: "resolved", value: known.value }
35
+ : { status: "error", error: errorOf(known.reason) });
36
+ else {
37
+ const done = onServer() ? inject(PendingTasks).add() : undefined;
38
+ const destroyed = { value: false };
39
+ inject(DestroyRef).onDestroy(() => (destroyed.value = true));
40
+ Promise.resolve(promise).then((value) => {
41
+ if (!destroyed.value)
42
+ snapshot.set({ status: "resolved", value });
43
+ done?.();
44
+ }, (reason) => {
45
+ if (!destroyed.value)
46
+ snapshot.set({ status: "error", error: errorOf(reason) });
47
+ done?.();
48
+ });
49
+ }
50
+ const read = snapshot.asReadonly();
51
+ return {
52
+ value: computed(() => {
53
+ const current = read();
54
+ if (current.status === "error")
55
+ throw current.error;
56
+ return current.value;
57
+ }),
58
+ status: computed(() => read().status),
59
+ error: computed(() => {
60
+ const current = read();
61
+ return current.status === "error" ? current.error : undefined;
62
+ }),
63
+ isLoading: computed(() => read().status === "loading"),
64
+ snapshot: read,
65
+ hasValue: () => {
66
+ const current = read();
67
+ return current.status === "resolved";
68
+ },
69
+ };
70
+ }
71
+ const errorOf = (reason) => (reason instanceof Error ? reason : new Error(String(reason)));
72
+ /** `false` on the server and until the first render of a hydrated page is done; `true` at once after a client navigation. */
73
+ export function injectHydrated() {
74
+ assertInInjectionContext(injectHydrated);
75
+ const app = required(HAMUR_APP, "injectHydrated");
76
+ const hydrated = signal(typeof document !== "undefined" && !onServer() && !app.asyncData.hydrating, /* @ts-ignore */
77
+ ...(ngDevMode ? [{ debugName: "hydrated" }] : /* istanbul ignore next */ []));
78
+ const destroy = inject(DestroyRef);
79
+ afterNextRender(() => {
80
+ hydrated.set(!app.asyncData.hydrating);
81
+ destroy.onDestroy(app.hooks.hook("app:mounted", () => hydrated.set(true)));
82
+ });
83
+ return hydrated.asReadonly();
84
+ }
85
+ /** The counter `injectId` reads; a server-only component's render has one of its own, with a prefix, so it leaves the page's numbering alone. */
86
+ export const HAMUR_IDS = new InjectionToken("hamur ids", {
87
+ providedIn: "root",
88
+ factory: () => ({ next: 0, prefix: "" }),
89
+ });
90
+ /**
91
+ * An id that is the same in the server's HTML and in hydration, `<APP_ID>-<n>`: Angular 22 has no id function of
92
+ * its own, and the components of both renders are created in the same order.
93
+ */
94
+ export function injectId() {
95
+ assertInInjectionContext(injectId);
96
+ const counter = inject(HAMUR_IDS);
97
+ return `${counter.prefix}${inject(APP_ID)}-${counter.next++}`;
98
+ }
99
+ /** The id for `data-hamur-p` on the element `fn` is called with, as an inline script before hydration; `undefined` in the browser. */
100
+ export function onPrehydrate(fn) {
101
+ assertInInjectionContext(onPrehydrate);
102
+ return prehydrate(required(HAMUR_APP, "onPrehydrate"), fn);
103
+ }
104
+ /** The `[style]` that names an element for a view transition. */
105
+ export function transitionName(name) {
106
+ return { "view-transition-name": checkTransitionName(name) };
107
+ }