@hamur/adapter-angular 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 (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 +1073 -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 +3 -0
  16. package/dist/types/src/async-data.d.ts +21 -0
  17. package/dist/types/src/client-parts.d.ts +32 -0
  18. package/dist/types/src/compile.d.ts +97 -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 +5 -0
  23. package/dist/types/src/error.d.ts +4 -0
  24. package/dist/types/src/form.d.ts +65 -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 +69 -0
  30. package/dist/types/src/island.d.ts +39 -0
  31. package/dist/types/src/keepalive.d.ts +1 -0
  32. package/dist/types/src/link.d.ts +65 -0
  33. package/dist/types/src/markdown-page.d.ts +10 -0
  34. package/dist/types/src/markdown.d.ts +37 -0
  35. package/dist/types/src/mask.d.ts +12 -0
  36. package/dist/types/src/navigate.d.ts +14 -0
  37. package/dist/types/src/outlet.d.ts +71 -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 +21 -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 +37 -0
  49. package/dist/types/src/wrapper.d.ts +21 -0
  50. package/package.json +56 -4
  51. package/src/activation.ts +83 -0
  52. package/src/adapter.ts +107 -0
  53. package/src/app.ts +6 -0
  54. package/src/async-data.ts +105 -0
  55. package/src/client-parts.ts +127 -0
  56. package/src/compile.ts +959 -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 +17 -0
  61. package/src/error.ts +15 -0
  62. package/src/form.ts +253 -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 +251 -0
  68. package/src/island.ts +95 -0
  69. package/src/keepalive.ts +1 -0
  70. package/src/link.ts +251 -0
  71. package/src/markdown-page.ts +31 -0
  72. package/src/markdown.ts +170 -0
  73. package/src/mask.ts +36 -0
  74. package/src/navigate.ts +19 -0
  75. package/src/outlet.ts +344 -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 +54 -0
  85. package/src/state.ts +70 -0
  86. package/src/svg.ts +65 -0
  87. package/src/time.ts +108 -0
  88. package/src/wrapper.ts +187 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 productdevbook
4
+ Copyright (c) 2019 Material-UI SAS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @hamur/adapter-angular
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Angular 22 adapter for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. Pages, layouts and the error page are standalone `@Component` classes in `.ts` files, compiled ahead of time with Angular's own compiler; Angular's partial-compiled packages are linked in the same build. It gives you `injectData`, `injectHead`, `injectState` and the other inject functions, which return signals, and directives such as `a[hamurLink]`. Server rendering sends the string as one chunk. Routing, loaders, head, state and the server come from `hamur`, not from `@angular/router`.
4
+
5
+ One app uses one library. Set `framework: "angular"` in `hamur.config.ts`, or install only this adapter and Hamur detects it.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add hamur @hamur/adapter-angular @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-server @angular/compiler-cli rxjs
11
+ bun add -d typescript@~6.0.3
12
+ ```
13
+
14
+ The Angular compiler runs on TypeScript 6.0; TypeScript 7 does not ship the JavaScript API it needs.
15
+
16
+ Or start from a template: `bunx hamur init my-app --framework angular`.
17
+
18
+ ## Example
19
+
20
+ `app/pages/post.ts`:
21
+
22
+ ```ts
23
+ import { Component } from "@angular/core"
24
+ import { injectData, injectHead, injectState } from "@hamur/adapter-angular"
25
+
26
+ @Component({
27
+ template: `<button type="button" (click)="likes.set(likes() + 1)">{{ data().title }}: {{ likes() }}</button>`,
28
+ })
29
+ export default class Post {
30
+ readonly data = injectData<{ title: string }>()
31
+ readonly likes = injectState("likes", 0)
32
+
33
+ constructor() {
34
+ injectHead(() => ({ title: this.data().title }))
35
+ }
36
+ }
37
+ ```
38
+
39
+ An inject function must run in an injection context: a constructor, a field initializer or a factory.
40
+
41
+ ## Docs
42
+
43
+ [Documentation](https://docs.productdevbook.com/) and the [Angular section of the adapters page](https://docs.productdevbook.com/adapters#angular). MIT license.
@@ -0,0 +1,131 @@
1
+ import {
2
+ createState,
3
+ hamurProviders,
4
+ setupOf
5
+ } from "./browser-index-qn8q5fa2.js";
6
+ import {
7
+ HamurApp,
8
+ maskInPlace,
9
+ boundaryKey
10
+ } from "./browser-index-nann848q.js";
11
+
12
+ // packages/adapter-angular/src/runtime/client.ts
13
+ import {
14
+ APP_ID,
15
+ CSP_NONCE,
16
+ ErrorHandler
17
+ } from "@angular/core";
18
+ import {
19
+ createApplication,
20
+ provideClientHydration,
21
+ withEventReplay,
22
+ withNoHttpTransferCache
23
+ } from "@angular/platform-browser";
24
+ import { reportClientError, setAdapterInstance } from "hamur/adapter";
25
+
26
+ // packages/adapter-angular/src/runtime/hydration.ts
27
+ var devHydration = {};
28
+
29
+ // packages/adapter-angular/src/runtime/client.ts
30
+ var HOST = "hamur-app";
31
+ if (undefined)
32
+ ;
33
+
34
+ class ClientErrors2 extends ErrorHandler {
35
+ app;
36
+ hydrating;
37
+ watch;
38
+ viewErrors = new WeakSet;
39
+ caught = 0;
40
+ constructor(app, hydrating = false, watch) {
41
+ super();
42
+ this.app = app;
43
+ this.hydrating = hydrating;
44
+ this.watch = watch;
45
+ }
46
+ handleError(error) {
47
+ if (this.watch?.failed(error)) {
48
+ reportClientError(this.app, error, { render: false });
49
+ return;
50
+ }
51
+ if (undefined)
52
+ ;
53
+ else
54
+ console.error(error);
55
+ reportClientError(this.app, error, { render: false });
56
+ }
57
+ onViewError(error) {
58
+ if (this.viewErrors.has(error))
59
+ return;
60
+ this.viewErrors.add(error);
61
+ reportClientError(this.app, error, { render: false, source: "render" });
62
+ if (undefined)
63
+ ;
64
+ if (!this.hydrating)
65
+ return;
66
+ const key = boundaryKey(this.caught++);
67
+ const shown = this.app.state.get(key);
68
+ if (shown === undefined)
69
+ return;
70
+ this.app.state.set(key, undefined);
71
+ maskInPlace(error, shown);
72
+ }
73
+ }
74
+ var documentNonce2 = () => document.querySelector("script[nonce]")?.nonce || null;
75
+ var running;
76
+ async function start(ctx, hydrating) {
77
+ running?.appRef.destroy();
78
+ running = undefined;
79
+ const { setup, bootstrapped } = setupOf(ctx.app);
80
+ await setAdapterInstance(ctx.app, setup);
81
+ const state = createState(ctx);
82
+ const watch = hydrating ? devHydration.watch?.(ctx.root, () => ctx.navigator.currentRoute.name) : undefined;
83
+ const errors = new ClientErrors2(ctx.app, hydrating, watch);
84
+ const fail = (error) => {
85
+ const mismatch = watch?.failed(error) ?? false;
86
+ queueMicrotask(() => reportClientError(ctx.app, error, mismatch ? { render: false, source: "render" } : { render: true }));
87
+ };
88
+ const providers = [
89
+ { provide: APP_ID, useValue: "hamur" },
90
+ { provide: CSP_NONCE, useValue: documentNonce2() },
91
+ { provide: ErrorHandler, useValue: errors },
92
+ ...hamurProviders(ctx.app, state, fail)
93
+ ];
94
+ const appRef = await createApplication({
95
+ providers: [
96
+ ...hydrating ? [provideClientHydration(withEventReplay(), withNoHttpTransferCache())] : [],
97
+ ...providers,
98
+ ...setup.providers
99
+ ]
100
+ });
101
+ bootstrapped(appRef.injector);
102
+ running = { appRef, state };
103
+ let host = ctx.root.querySelector(`:scope > ${HOST}`);
104
+ if (!hydrating || !host) {
105
+ host?.remove();
106
+ host = ctx.root.appendChild(document.createElement(HOST));
107
+ }
108
+ try {
109
+ appRef.bootstrap(HamurApp, host);
110
+ } catch (error) {
111
+ if (!watch?.failed(error))
112
+ throw error;
113
+ }
114
+ await appRef.whenStable();
115
+ errors.hydrating = false;
116
+ }
117
+ function hydrate2(ctx) {
118
+ return start(ctx, true);
119
+ }
120
+ function mount2(ctx) {
121
+ return start(ctx, false);
122
+ }
123
+ async function update2(ctx) {
124
+ if (!running)
125
+ throw new Error("update() called before hydrate() or mount()");
126
+ running.state.write(ctx);
127
+ running.appRef.tick();
128
+ await running.appRef.whenStable();
129
+ }
130
+
131
+ export { ClientErrors2, documentNonce2, hydrate2, mount2, update2 };
@@ -0,0 +1,205 @@
1
+ import {
2
+ HAMUR_APP,
3
+ required,
4
+ Outlet2,
5
+ HAMUR_IDS,
6
+ injectId2
7
+ } from "./browser-index-qn8q5fa2.js";
8
+
9
+ // packages/adapter-angular/src/app.ts
10
+ import { Component } from "@angular/core";
11
+ import * as i0 from "@angular/core";
12
+
13
+ class HamurApp {
14
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: HamurApp, deps: [], target: i0.ɵɵFactoryTarget.Component });
15
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.3.2", type: HamurApp, isStandalone: true, selector: "hamur-app", ngImport: i0, template: "<hamur-outlet />", isInline: true, dependencies: [{ kind: "component", type: Outlet2, selector: "hamur-outlet", inputs: ["name", "context"] }] });
16
+ }
17
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.2", ngImport: i0, type: HamurApp, decorators: [{
18
+ type: Component,
19
+ args: [{ selector: "hamur-app", imports: [Outlet2], template: "<hamur-outlet />" }]
20
+ }] });
21
+
22
+ // packages/adapter-angular/src/mask.ts
23
+ function maskInPlace(error, shown) {
24
+ for (const key of Reflect.ownKeys(error))
25
+ Reflect.deleteProperty(error, key);
26
+ Object.defineProperties(error, {
27
+ name: { value: shown.name, configurable: true, writable: true },
28
+ message: { value: shown.message, configurable: true, writable: true },
29
+ stack: { value: `${shown.name}: ${shown.message}`, configurable: true, writable: true },
30
+ status: { value: shown.status, configurable: true, writable: true, enumerable: true },
31
+ statusText: { value: shown.statusText, configurable: true, writable: true, enumerable: true },
32
+ ...shown.data === undefined ? {} : { data: { value: shown.data, configurable: true, writable: true, enumerable: true } }
33
+ });
34
+ }
35
+ var boundaryKey = (index) => `$boundary:${index}`;
36
+ function shownError(error) {
37
+ const { status, statusText, data } = error;
38
+ return {
39
+ name: error.name,
40
+ message: error.message,
41
+ ...status === undefined ? {} : { status },
42
+ ...statusText === undefined ? {} : { statusText },
43
+ ...data === undefined ? {} : { data }
44
+ };
45
+ }
46
+
47
+ // packages/adapter-angular/src/wrapper.ts
48
+ import {
49
+ ApplicationRef,
50
+ DOCUMENT,
51
+ DestroyRef,
52
+ ElementRef,
53
+ EnvironmentInjector,
54
+ Injector,
55
+ afterNextRender,
56
+ createComponent,
57
+ inject
58
+ } from "@angular/core";
59
+ import {
60
+ fetchServerComponent,
61
+ serverComponentAttributes,
62
+ serverComponentProps,
63
+ setServerHTML,
64
+ takeServerHTML
65
+ } from "hamur/adapter";
66
+ function controller(behaviour) {
67
+ const instance = {
68
+ $values: {},
69
+ $host: inject(ElementRef).nativeElement,
70
+ $changed: new Set
71
+ };
72
+ const init = behaviour(instance);
73
+ return {
74
+ set(name, value) {
75
+ instance.$values[name] = value;
76
+ for (const listener of [...instance.$changed])
77
+ listener(name);
78
+ },
79
+ init() {
80
+ if (typeof init === "function")
81
+ init();
82
+ }
83
+ };
84
+ }
85
+ var nothing = () => {};
86
+ function clientComponentOnServer() {
87
+ return controller(nothing);
88
+ }
89
+ function clientComponentOnClient(load) {
90
+ return controller((instance) => {
91
+ const environment = inject(EnvironmentInjector);
92
+ const injector = inject(Injector);
93
+ const appRef = inject(ApplicationRef);
94
+ let ref;
95
+ let destroyed = false;
96
+ instance.$changed.add((name) => ref?.setInput(name, instance.$values[name]));
97
+ inject(DestroyRef).onDestroy(() => {
98
+ destroyed = true;
99
+ ref?.destroy();
100
+ });
101
+ afterNextRender(() => {
102
+ load().then((loaded) => {
103
+ if (destroyed)
104
+ return;
105
+ const type = "default" in loaded ? loaded.default : loaded;
106
+ ref = createComponent(type, { environmentInjector: environment, elementInjector: injector });
107
+ for (const [name, value] of Object.entries(instance.$values))
108
+ ref.setInput(name, value);
109
+ appRef.attachView(ref.hostView);
110
+ instance.$host.appendChild(ref.location.nativeElement);
111
+ });
112
+ });
113
+ });
114
+ }
115
+ function serverComponentOnServer(name, component) {
116
+ return controller((instance) => {
117
+ const uid = injectId2();
118
+ const document = inject(DOCUMENT);
119
+ const environment = inject(EnvironmentInjector);
120
+ const parent = inject(Injector);
121
+ const appRef = inject(ApplicationRef);
122
+ let ref;
123
+ inject(DestroyRef).onDestroy(() => ref?.destroy());
124
+ return () => {
125
+ serverComponentProps(name, { ...instance.$values });
126
+ const element = document.createElement("hamur-component");
127
+ element.setAttribute("name", name);
128
+ element.setAttribute("uid", uid);
129
+ for (const [key, value] of Object.entries(serverComponentAttributes(name)))
130
+ element.setAttribute(key, value);
131
+ const injector = Injector.create({
132
+ providers: [{ provide: HAMUR_IDS, useValue: { next: 0, prefix: `${uid}-` } }],
133
+ parent
134
+ });
135
+ ref = createComponent(component, { environmentInjector: environment, elementInjector: injector });
136
+ for (const [key, value] of Object.entries(instance.$values))
137
+ ref.setInput(key, value);
138
+ appRef.attachView(ref.hostView);
139
+ element.appendChild(ref.location.nativeElement);
140
+ instance.$host.appendChild(element);
141
+ };
142
+ });
143
+ }
144
+ function serverComponentOnClient(name) {
145
+ return controller((instance) => {
146
+ const app = required(HAMUR_APP, "serverComponent");
147
+ const uid = injectId2();
148
+ const document = inject(DOCUMENT);
149
+ const textOf = () => serverComponentProps(name, { ...instance.$values });
150
+ let controller;
151
+ let head;
152
+ let requested;
153
+ let mounted = false;
154
+ const initial = takeServerHTML(app, uid, name);
155
+ let element = instance.$host.querySelector(`:scope > hamur-component[uid="${uid}"]`);
156
+ if (!element) {
157
+ element = document.createElement("hamur-component");
158
+ element.setAttribute("name", name);
159
+ element.setAttribute("uid", uid);
160
+ for (const [key, value] of Object.entries(serverComponentAttributes(name)))
161
+ element.setAttribute(key, value);
162
+ if (initial !== undefined)
163
+ setServerHTML(element, initial);
164
+ instance.$host.appendChild(element);
165
+ }
166
+ const shown = element;
167
+ const sync = () => {
168
+ const text = textOf();
169
+ if (text === requested)
170
+ return;
171
+ requested = text;
172
+ controller?.abort();
173
+ const current = controller = new AbortController;
174
+ fetchServerComponent(app, name, text, current.signal).then((view) => {
175
+ if (current.signal.aborted)
176
+ return;
177
+ head?.dispose();
178
+ head = view.head ? app.head.push(view.head) : undefined;
179
+ setServerHTML(shown, view.html);
180
+ app.head.apply();
181
+ }).catch((error) => {
182
+ if (current.signal.aborted)
183
+ return;
184
+ queueMicrotask(() => {
185
+ throw error;
186
+ });
187
+ });
188
+ };
189
+ afterNextRender(() => {
190
+ mounted = true;
191
+ requested = initial === undefined ? undefined : textOf();
192
+ sync();
193
+ });
194
+ instance.$changed.add(() => {
195
+ if (mounted)
196
+ queueMicrotask(sync);
197
+ });
198
+ inject(DestroyRef).onDestroy(() => {
199
+ controller?.abort();
200
+ head?.dispose();
201
+ });
202
+ });
203
+ }
204
+
205
+ export { HamurApp, maskInPlace, boundaryKey, shownError, clientComponentOnServer, clientComponentOnClient, serverComponentOnServer, serverComponentOnClient };